Skip to content

Commit 4ac5b10

Browse files
committed
feat: add live preview mode settings to preferences
1 parent 79ca0c5 commit 4ac5b10

File tree

3 files changed

+71
-9
lines changed

3 files changed

+71
-9
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2830,7 +2830,7 @@ function RemoteFunctions(config) {
28302830
* @return {boolean} true if any boxes are visible, false otherwise
28312831
*/
28322832
function hasVisibleLivePreviewBoxes() {
2833-
return _nodeMoreOptionsBox !== null || _nodeInfoBox !== null || previouslyClickedElement !== null;
2833+
return _nodeMoreOptionsBox !== null || _nodeInfoBox !== null || _aiPromptBox !== null || previouslyClickedElement !== null;
28342834
}
28352835

28362836
/**
@@ -3058,6 +3058,7 @@ function RemoteFunctions(config) {
30583058
"startEditing" : startEditing,
30593059
"finishEditing" : finishEditing,
30603060
"hasVisibleLivePreviewBoxes" : hasVisibleLivePreviewBoxes,
3061+
"dismissUIAndCleanupState" : dismissUIAndCleanupState,
30613062
"registerHandlers" : registerHandlers
30623063
};
30633064
}

src/LiveDevelopment/LiveDevMultiBrowser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,11 +710,11 @@ define(function (require, exports, module) {
710710
}
711711

712712
/**
713-
* Dismiss live preview more options box and info box
713+
* Dismiss live preview boxes like info box, options box, AI box
714714
*/
715715
function dismissLivePreviewBoxes() {
716716
if (_protocol) {
717-
_protocol.evaluate("_LD.dismissMoreOptionsBox()");
717+
_protocol.evaluate("_LD.dismissUIAndCleanupState()");
718718
}
719719
}
720720

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

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ define(function (require, exports, module) {
8686
const PREVIEW_TRUSTED_PROJECT_KEY = "preview_trusted";
8787
const PREVIEW_PROJECT_README_KEY = "preview_readme";
8888

89+
// live preview mode pref
90+
const PREFERENCE_LIVE_PREVIEW_MODE = "livePreviewMode";
91+
const DEFAULT_LIVE_PREVIEW_MODE = "preview"; // preview, inspect or edit
92+
// define the live preview mode preference
93+
PreferencesManager.definePreference(PREFERENCE_LIVE_PREVIEW_MODE, "string", DEFAULT_LIVE_PREVIEW_MODE, {
94+
description: "Default live preview mode on startup (preview, inspect, edit)",
95+
values: ["preview", "inspect", "edit"]
96+
});
97+
8998
const LIVE_PREVIEW_PANEL_ID = "live-preview-panel";
9099
const LIVE_PREVIEW_IFRAME_ID = "panel-live-preview-frame";
91100
const LIVE_PREVIEW_IFRAME_HTML = `
@@ -179,6 +188,40 @@ define(function (require, exports, module) {
179188
}
180189
}
181190

191+
/**
192+
* update the mode button text in the live preview toolbar UI based on the current mode
193+
* @param {String} mode - The current mode ("preview", "inspect", or "edit")
194+
*/
195+
function _updateModeButton(mode) {
196+
if ($modeBtn) {
197+
if (mode === "inspect") {
198+
$modeBtn[0].textContent = "Inspect Mode";
199+
} else if (mode === "edit") {
200+
$modeBtn[0].textContent = "Edit Mode";
201+
} else {
202+
$modeBtn[0].textContent = "Preview Mode";
203+
}
204+
}
205+
}
206+
207+
/**
208+
* init live preview mode from saved preferences
209+
*/
210+
function _initializeMode() {
211+
const savedMode = PreferencesManager.get(PREFERENCE_LIVE_PREVIEW_MODE) || "preview";
212+
213+
// apply the saved
214+
if (savedMode === "inspect") {
215+
_LPInspectMode();
216+
} else if (savedMode === "edit") {
217+
_LPEditMode();
218+
} else {
219+
_LPPreviewMode();
220+
}
221+
222+
_updateModeButton(savedMode);
223+
}
224+
182225
function _showModeSelectionDropdown(event) {
183226
const items = ["Preview Mode", "Inspect Mode", "Edit Mode"];
184227

@@ -204,20 +247,19 @@ define(function (require, exports, module) {
204247

205248
// handle the option selection
206249
dropdown.on("select", function (e, item, index) {
250+
// here we just set the preference
251+
// as the preferences listener will automatically handle the required changes
207252
if (index === 0) {
208-
_LPPreviewMode();
253+
PreferencesManager.set(PREFERENCE_LIVE_PREVIEW_MODE, "preview");
209254
} else if (index === 1) {
210-
_LPInspectMode();
255+
PreferencesManager.set(PREFERENCE_LIVE_PREVIEW_MODE, "inspect");
211256
} else if (index === 2) {
212-
_LPEditMode();
257+
PreferencesManager.set(PREFERENCE_LIVE_PREVIEW_MODE, "edit");
213258
}
214259

215260
// need to dismiss the previous highlighting and stuff
216261
LiveDevelopment.hideHighlight();
217262
LiveDevelopment.dismissLivePreviewBoxes();
218-
if($modeBtn) {
219-
$modeBtn[0].textContent = item;
220-
}
221263
});
222264

223265
// Remove the button after the dropdown is hidden
@@ -897,6 +939,25 @@ define(function (require, exports, module) {
897939
fileMenu.addMenuItem(Commands.FILE_LIVE_FILE_PREVIEW_SETTINGS, "",
898940
Menus.AFTER, Commands.FILE_LIVE_FILE_PREVIEW);
899941
fileMenu.addMenuDivider(Menus.BEFORE, Commands.FILE_LIVE_FILE_PREVIEW);
942+
943+
// init live preview mode from saved preferences
944+
_initializeMode();
945+
// listen for pref changes
946+
PreferencesManager.on("change", PREFERENCE_LIVE_PREVIEW_MODE, function () {
947+
// Get the current preference value directly
948+
const newMode = PreferencesManager.get(PREFERENCE_LIVE_PREVIEW_MODE);
949+
950+
if (newMode === "inspect") {
951+
_LPInspectMode();
952+
} else if (newMode === "edit") {
953+
_LPEditMode();
954+
} else {
955+
_LPPreviewMode();
956+
}
957+
958+
_updateModeButton(newMode);
959+
});
960+
900961
LiveDevelopment.openLivePreview();
901962
LiveDevelopment.on(LiveDevelopment.EVENT_OPEN_PREVIEW_URL, _openLivePreviewURL);
902963
LiveDevelopment.on(LiveDevelopment.EVENT_LIVE_PREVIEW_RELOAD, ()=>{

0 commit comments

Comments
 (0)