Skip to content

Commit a2d9b49

Browse files
committed
feat: always active edit mode when phoenix opens/reloads
1 parent 7e956d9 commit a2d9b49

File tree

3 files changed

+33
-20
lines changed

3 files changed

+33
-20
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,14 @@ function RemoteFunctions(config = {}) {
115115

116116
/**
117117
* This is a checker function for editable elements, it makes sure that the element satisfies all the required checks
118-
* - When onlyHighlight is false → config.isLPEditFeaturesActive must be true
119-
* - When onlyHighlight is true → config.isLPEditFeaturesActive can be true or false (doesn't matter)
118+
* - When onlyHighlight is false → config.isProUser must be true
119+
* - When onlyHighlight is true → config.isProUser can be true or false (doesn't matter)
120120
* @param {DOMElement} element
121-
* @param {boolean} [onlyHighlight=false] - If true, bypasses the isLPEditFeaturesActive check
121+
* @param {boolean} [onlyHighlight=false] - If true, bypasses the isProUser check
122122
* @returns {boolean} - True if the element is editable else false
123123
*/
124124
function isElementEditable(element, onlyHighlight = false) {
125-
if(!config.isLPEditFeaturesActive && !onlyHighlight) {
125+
if(!config.isProUser && !onlyHighlight) {
126126
return false;
127127
}
128128

@@ -1327,7 +1327,7 @@ function RemoteFunctions(config = {}) {
13271327
create: function() {
13281328
this.remove(); // remove existing box if already present
13291329

1330-
if(!config.isLPEditFeaturesActive) {
1330+
if(!config.isProUser) {
13311331
return;
13321332
}
13331333

@@ -1502,7 +1502,7 @@ function RemoteFunctions(config = {}) {
15021502

15031503
// get the ID and classes for that element, as we need to display it in the box
15041504
const id = this.element.id;
1505-
const classes = this.element.className ? this.element.className.split(/\s+/).filter(Boolean) : [];
1505+
const classes = Array.from(this.element.classList || []);
15061506

15071507
let content = ""; // this will hold the main content that will be displayed
15081508
content += "<div class='tag-name'>" + this.element.tagName.toLowerCase() + "</div>"; // add element tag name
@@ -1574,7 +1574,7 @@ function RemoteFunctions(config = {}) {
15741574
create: function() {
15751575
this.remove(); // remove existing box if already present
15761576

1577-
if(!config.isLPEditFeaturesActive) {
1577+
if(!config.isProUser) {
15781578
return;
15791579
}
15801580

@@ -2836,7 +2836,7 @@ function RemoteFunctions(config = {}) {
28362836
var oldConfig = config;
28372837
config = JSON.parse(newConfig);
28382838

2839-
if (config.highlight || (config.isLPEditFeaturesActive && shouldShowHighlightOnHover())) {
2839+
if (config.highlight || (config.isProUser && shouldShowHighlightOnHover())) {
28402840
// Add hover event listeners if highlight is enabled OR editHighlights is set to hover
28412841
window.document.removeEventListener("mouseover", onElementHover);
28422842
window.document.removeEventListener("mouseout", onElementHoverOut);
@@ -2881,7 +2881,7 @@ function RemoteFunctions(config = {}) {
28812881
}
28822882

28832883
// Re-setup event listeners based on new mode to ensure proper behavior
2884-
if (config.highlight && config.isLPEditFeaturesActive) {
2884+
if (config.highlight && config.isProUser) {
28852885
window.document.removeEventListener("mouseover", onElementHover);
28862886
window.document.removeEventListener("mouseout", onElementHoverOut);
28872887
window.document.addEventListener("mouseover", onElementHover);
@@ -3092,7 +3092,7 @@ function RemoteFunctions(config = {}) {
30923092
window.document.removeEventListener("dragleave", onDragLeave);
30933093
window.document.removeEventListener("keydown", onKeyDown);
30943094

3095-
if (config.isLPEditFeaturesActive) {
3095+
if (config.isProUser) {
30963096
// Initialize hover highlight with Chrome-like colors
30973097
_hoverHighlight = new Highlight("#c8f9c5", true); // Green similar to Chrome's padding color
30983098

src/LiveDevelopment/main.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ define(function main(require, exports, module) {
4848

4949
// this is responsible to make the advanced live preview features active or inactive
5050
// @abose (make the first value true when its a paid user, everything rest is handled automatically)
51-
let isLPEditFeaturesActive = window.KernalModeTrust ? false : false;
51+
let isProUser = window.KernalModeTrust ? true : false;
52+
// when isFreeTrialUser is true isProUser should also be true
53+
// when its false, isProUser can be true/false doesn't matter
54+
let isFreeTrialUser = true;
5255

5356
const EVENT_LIVE_HIGHLIGHT_PREF_CHANGED = "liveHighlightPrefChange";
5457

@@ -64,7 +67,7 @@ define(function main(require, exports, module) {
6467
paddingColor: {r: 147, g: 196, b: 125, a: 0.66},
6568
showInfo: true
6669
},
67-
isLPEditFeaturesActive: isLPEditFeaturesActive,
70+
isProUser: isProUser,
6871
elemHighlights: "hover", // default value, this will get updated when the extension loads
6972
// this strings are used in RemoteFunctions.js
7073
// we need to pass this through config as remoteFunctions runs in browser context and cannot
@@ -410,8 +413,8 @@ define(function main(require, exports, module) {
410413

411414
function setLivePreviewEditFeaturesActive(enabled) {
412415
// TODO: @abose here add kernal mode trust check
413-
isLPEditFeaturesActive = enabled;
414-
config.isLPEditFeaturesActive = enabled;
416+
isProUser = enabled;
417+
config.isProUser = enabled;
415418
if (MultiBrowserLiveDev && MultiBrowserLiveDev.status >= MultiBrowserLiveDev.STATUS_ACTIVE) {
416419
MultiBrowserLiveDev.updateConfig(JSON.stringify(config));
417420
MultiBrowserLiveDev.registerHandlers();
@@ -437,7 +440,8 @@ define(function main(require, exports, module) {
437440

438441
EventDispatcher.makeEventDispatcher(exports);
439442

440-
exports.isLPEditFeaturesActive = isLPEditFeaturesActive;
443+
exports.isProUser = isProUser;
444+
exports.isFreeTrialUser = isFreeTrialUser;
441445

442446
// public events
443447
exports.EVENT_OPEN_PREVIEW_URL = MultiBrowserLiveDev.EVENT_OPEN_PREVIEW_URL;

src/extensionsIntegrated/Phoenix-live-preview/main.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ define(function (require, exports, module) {
9494
* @returns {string} "highlight" if edit features inactive, "edit" if active
9595
*/
9696
function _getDefaultMode() {
97-
return LiveDevelopment.isLPEditFeaturesActive ? "edit" : "highlight";
97+
return LiveDevelopment.isProUser ? "edit" : "highlight";
9898
}
9999

100100
// define the live preview mode preference
@@ -256,8 +256,17 @@ define(function (require, exports, module) {
256256
* init live preview mode from saved preferences
257257
*/
258258
function _initializeMode() {
259+
// when user is on free trial we just push the edit mode to them every time they open/reload Phoenix
260+
if(LiveDevelopment.isFreeTrialUser) {
261+
PreferencesManager.set(PREFERENCE_LIVE_PREVIEW_MODE, "edit");
262+
_LPEditMode();
263+
$previewBtn.removeClass('selected');
264+
_updateModeButton("edit");
265+
return;
266+
}
267+
259268
const savedMode = PreferencesManager.get(PREFERENCE_LIVE_PREVIEW_MODE) || _getDefaultMode();
260-
const isEditFeaturesActive = LiveDevelopment.isLPEditFeaturesActive;
269+
const isEditFeaturesActive = LiveDevelopment.isProUser;
261270

262271
// If user has edit mode saved but edit features are not active, default to highlight
263272
let effectiveMode = savedMode;
@@ -283,7 +292,7 @@ define(function (require, exports, module) {
283292
}
284293

285294
function _showModeSelectionDropdown(event) {
286-
const isEditFeaturesActive = LiveDevelopment.isLPEditFeaturesActive;
295+
const isEditFeaturesActive = LiveDevelopment.isProUser;
287296
const items = [
288297
Strings.LIVE_PREVIEW_MODE_PREVIEW,
289298
Strings.LIVE_PREVIEW_MODE_HIGHLIGHT,
@@ -597,7 +606,7 @@ define(function (require, exports, module) {
597606
function _handlePreviewBtnClick() {
598607
if($previewBtn.hasClass('selected')) {
599608
$previewBtn.removeClass('selected');
600-
const isEditFeaturesActive = LiveDevelopment.isLPEditFeaturesActive;
609+
const isEditFeaturesActive = LiveDevelopment.isProUser;
601610
if(modeThatWasSelected) {
602611
if(modeThatWasSelected === 'edit' && !isEditFeaturesActive) {
603612
// we just set the preference as preference has change handlers that will update the config
@@ -1085,7 +1094,7 @@ define(function (require, exports, module) {
10851094
PreferencesManager.on("change", PREFERENCE_LIVE_PREVIEW_MODE, function () {
10861095
// Get the current preference value directly
10871096
const newMode = PreferencesManager.get(PREFERENCE_LIVE_PREVIEW_MODE);
1088-
const isEditFeaturesActive = LiveDevelopment.isLPEditFeaturesActive;
1097+
const isEditFeaturesActive = LiveDevelopment.isProUser;
10891098

10901099
// If user tries to set edit mode but edit features are not active, default to highlight
10911100
let effectiveMode = newMode;

0 commit comments

Comments
 (0)