3232define ( function main ( require , exports , module ) {
3333
3434
35- const Commands = require ( "command/Commands" ) ,
35+ const CONSTANTS = require ( "LiveDevelopment/LivePreviewConstants" ) ,
36+ Commands = require ( "command/Commands" ) ,
3637 AppInit = require ( "utils/AppInit" ) ,
3738 MultiBrowserLiveDev = require ( "LiveDevelopment/LiveDevMultiBrowser" ) ,
3839 LivePreviewTransport = require ( "LiveDevelopment/MultiBrowserImpl/transports/LivePreviewTransport" ) ,
@@ -48,13 +49,15 @@ define(function main(require, exports, module) {
4849
4950
5051 const KernalModeTrust = window . KernalModeTrust ;
52+ const LIVE_PREVIEW_MODE = CONSTANTS . LIVE_PREVIEW_MODE ,
53+ LIVE_HIGHLIGHT_MODE = CONSTANTS . LIVE_HIGHLIGHT_MODE ,
54+ LIVE_EDIT_MODE = CONSTANTS . LIVE_EDIT_MODE ;
5155
5256 // this will later be assigned its correct values once entitlementsManager loads
5357 let isProUser = false ;
5458 let isFreeTrialUser = false ;
5559
56- const EVENT_LIVE_HIGHLIGHT_PREF_CHANGED = "liveHighlightPrefChange" ;
57- const PREFERENCE_LIVE_PREVIEW_MODE = "livePreviewMode" ;
60+ const PREFERENCE_LIVE_PREVIEW_MODE = CONSTANTS . PREFERENCE_LIVE_PREVIEW_MODE ;
5861
5962 // state manager key to track image gallery selected state, by default we keep this as selected
6063 // if this is true we show the image gallery when an image element is clicked
@@ -85,7 +88,6 @@ define(function main(require, exports, module) {
8588
8689 var params = new UrlParams ( ) ;
8790 var config = {
88- highlight : true , // enable highlighting?
8991 mode : _getDefaultMode ( ) , // 'edit', 'highlight', or 'preview' - will be updated when preference loads
9092 elemHighlights : "hover" , // default value, this will get updated when the extension loads
9193 showRulerLines : false , // default value, this will get updated when the extension loads
@@ -101,7 +103,7 @@ define(function main(require, exports, module) {
101103 var prefs = PreferencesManager . getExtensionPrefs ( "livedev" ) ;
102104
103105 // "livedev.remoteHighlight" preference
104- var PREF_REMOTEHIGHLIGHT = "remoteHighlight" ;
106+ var PREF_REMOTEHIGHLIGHT = "remoteHighlight" ; // todo remove this and put it inside remotefn itself
105107 var remoteHighlightPref = prefs . definePreference ( PREF_REMOTEHIGHLIGHT , "object" , {
106108 animateStartValue : {
107109 "background-color" : "rgba(0, 162, 255, 0.5)" ,
@@ -237,27 +239,9 @@ define(function main(require, exports, module) {
237239 // Add checkmark when status is STATUS_ACTIVE; otherwise remove it
238240 CommandManager . get ( Commands . FILE_LIVE_FILE_PREVIEW )
239241 . setChecked ( status === MultiBrowserLiveDev . STATUS_ACTIVE ) ;
240- CommandManager . get ( Commands . FILE_LIVE_HIGHLIGHT )
241- . setEnabled ( status === MultiBrowserLiveDev . STATUS_ACTIVE ) ;
242242 } ) ;
243243 }
244244
245- function _updateHighlightCheckmark ( ) {
246- CommandManager . get ( Commands . FILE_LIVE_HIGHLIGHT ) . setChecked ( config . highlight ) ;
247- exports . trigger ( EVENT_LIVE_HIGHLIGHT_PREF_CHANGED , config . highlight ) ;
248- }
249-
250- function togglePreviewHighlight ( ) {
251- config . highlight = ! config . highlight ;
252- _updateHighlightCheckmark ( ) ;
253- if ( config . highlight ) {
254- MultiBrowserLiveDev . showHighlight ( ) ;
255- } else {
256- MultiBrowserLiveDev . hideHighlight ( ) ;
257- }
258- PreferencesManager . setViewState ( "livedevHighlight" , config . highlight ) ;
259- }
260-
261245 /** force reload the live preview currently only with shortcut ctrl-shift-R */
262246 function _handleReloadLivePreviewCommand ( ) {
263247 if ( MultiBrowserLiveDev . status >= MultiBrowserLiveDev . STATUS_ACTIVE ) {
@@ -281,22 +265,22 @@ define(function main(require, exports, module) {
281265 // default mode means on first load for pro user we have edit mode
282266 // for free user we have highlight mode
283267 function _getDefaultMode ( ) {
284- return isProUser ? "edit" : "highlight" ;
268+ return isProUser ? LIVE_EDIT_MODE : LIVE_HIGHLIGHT_MODE ;
285269 }
286270
287271 // to set that mode in the preferences
288272 function _initializeMode ( ) {
289273 if ( isFreeTrialUser ) {
290- PreferencesManager . set ( PREFERENCE_LIVE_PREVIEW_MODE , "edit" ) ;
274+ PreferencesManager . set ( PREFERENCE_LIVE_PREVIEW_MODE , LIVE_EDIT_MODE ) ;
291275 return ;
292276 }
293277
294278 const savedMode = PreferencesManager . get ( PREFERENCE_LIVE_PREVIEW_MODE ) || _getDefaultMode ( ) ;
295279
296- if ( savedMode === "highlight" && isProUser ) {
297- PreferencesManager . set ( PREFERENCE_LIVE_PREVIEW_MODE , "edit" ) ;
298- } else if ( savedMode === "edit" && ! isProUser ) {
299- PreferencesManager . set ( PREFERENCE_LIVE_PREVIEW_MODE , "highlight" ) ;
280+ if ( savedMode === LIVE_HIGHLIGHT_MODE && isProUser ) {
281+ PreferencesManager . set ( PREFERENCE_LIVE_PREVIEW_MODE , LIVE_EDIT_MODE ) ;
282+ } else if ( savedMode === LIVE_EDIT_MODE && ! isProUser ) {
283+ PreferencesManager . set ( PREFERENCE_LIVE_PREVIEW_MODE , LIVE_HIGHLIGHT_MODE ) ;
300284 }
301285 }
302286
@@ -329,7 +313,7 @@ define(function main(require, exports, module) {
329313 }
330314
331315 function setMode ( mode ) {
332- if ( mode === "edit" && ! exports . isProUser ) {
316+ if ( mode === LIVE_EDIT_MODE && ! exports . isProUser ) {
333317 return false ;
334318 }
335319 PreferencesManager . set ( PREFERENCE_LIVE_PREVIEW_MODE , mode ) ;
@@ -340,6 +324,10 @@ define(function main(require, exports, module) {
340324 return PreferencesManager . get ( PREFERENCE_LIVE_PREVIEW_MODE ) || _getDefaultMode ( ) ;
341325 }
342326
327+ function isInPreviewMode ( ) {
328+ return getCurrentMode ( ) === LIVE_PREVIEW_MODE ;
329+ }
330+
343331 /** Initialize LiveDevelopment */
344332 AppInit . appReady ( function ( ) {
345333 params . parse ( ) ;
@@ -353,7 +341,6 @@ define(function main(require, exports, module) {
353341 MultiBrowserLiveDev . init ( config ) ;
354342
355343 _loadStyles ( ) ;
356- _updateHighlightCheckmark ( ) ;
357344
358345 // init pro user status and listen for changes
359346 if ( KernalModeTrust ) {
@@ -405,16 +392,6 @@ define(function main(require, exports, module) {
405392 WorkspaceManager . addEscapeKeyEventHandler ( "livePreview" , _handleLivePreviewEscapeKey ) ;
406393 } ) ;
407394
408- // init prefs
409- PreferencesManager . stateManager . definePreference ( "livedevHighlight" , "boolean" , true )
410- . on ( "change" , function ( ) {
411- config . highlight = PreferencesManager . getViewState ( "livedevHighlight" ) ;
412- _updateHighlightCheckmark ( ) ;
413- if ( MultiBrowserLiveDev && MultiBrowserLiveDev . status >= MultiBrowserLiveDev . STATUS_ACTIVE ) {
414- MultiBrowserLiveDev . updateConfig ( JSON . stringify ( config ) ) ;
415- }
416- } ) ;
417-
418395 function _updateConfigMode ( ) {
419396 const currentMode = getCurrentMode ( ) ;
420397 config . mode = currentMode ;
@@ -425,15 +402,14 @@ define(function main(require, exports, module) {
425402 }
426403
427404 PreferencesManager . definePreference ( PREFERENCE_LIVE_PREVIEW_MODE , "string" , _getDefaultMode ( ) , {
428- description : StringUtils . format ( Strings . LIVE_PREVIEW_MODE_PREFERENCE , "'preview'" , "'highlight'" , "'edit'" ) ,
429- values : [ "preview" , "highlight" , "edit" ]
405+ description : StringUtils . format (
406+ Strings . LIVE_PREVIEW_MODE_PREFERENCE , LIVE_PREVIEW_MODE , LIVE_HIGHLIGHT_MODE , LIVE_EDIT_MODE ) ,
407+ values : [ LIVE_PREVIEW_MODE , LIVE_HIGHLIGHT_MODE , LIVE_EDIT_MODE ]
430408 } ) . on ( "change" , function ( ) {
431409 // when mode changes we update the config mode and notify remoteFunctions so that it can get updated
432410 _updateConfigMode ( ) ;
433411 } ) ;
434412
435- config . highlight = PreferencesManager . getViewState ( "livedevHighlight" ) ;
436-
437413 // this function is responsible to update element highlight config
438414 // called from live preview extension when preference changes
439415 function updateElementHighlightConfig ( ) {
@@ -453,11 +429,8 @@ define(function main(require, exports, module) {
453429 }
454430
455431 // init commands
456- CommandManager . register ( Strings . CMD_LIVE_HIGHLIGHT , Commands . FILE_LIVE_HIGHLIGHT , togglePreviewHighlight ) ;
457432 CommandManager . register ( Strings . CMD_RELOAD_LIVE_PREVIEW , Commands . CMD_RELOAD_LIVE_PREVIEW , _handleReloadLivePreviewCommand ) ;
458433
459- CommandManager . get ( Commands . FILE_LIVE_HIGHLIGHT ) . setEnabled ( false ) ;
460-
461434 EventDispatcher . makeEventDispatcher ( exports ) ;
462435
463436 exports . isProUser = isProUser ;
@@ -468,7 +441,6 @@ define(function main(require, exports, module) {
468441 exports . EVENT_CONNECTION_CLOSE = MultiBrowserLiveDev . EVENT_CONNECTION_CLOSE ;
469442 exports . EVENT_LIVE_PREVIEW_CLICKED = MultiBrowserLiveDev . EVENT_LIVE_PREVIEW_CLICKED ;
470443 exports . EVENT_LIVE_PREVIEW_RELOAD = MultiBrowserLiveDev . EVENT_LIVE_PREVIEW_RELOAD ;
471- exports . EVENT_LIVE_HIGHLIGHT_PREF_CHANGED = EVENT_LIVE_HIGHLIGHT_PREF_CHANGED ;
472444
473445 // Export public functions
474446 exports . openLivePreview = openLivePreview ;
@@ -477,7 +449,6 @@ define(function main(require, exports, module) {
477449 exports . isActive = isActive ;
478450 exports . setLivePreviewPinned = setLivePreviewPinned ;
479451 exports . setLivePreviewTransportBridge = setLivePreviewTransportBridge ;
480- exports . togglePreviewHighlight = togglePreviewHighlight ;
481452 exports . setImageGalleryState = setImageGalleryState ;
482453 exports . updateElementHighlightConfig = updateElementHighlightConfig ;
483454 exports . updateRulerLinesConfig = updateRulerLinesConfig ;
@@ -487,4 +458,5 @@ define(function main(require, exports, module) {
487458 exports . dismissLivePreviewBoxes = MultiBrowserLiveDev . dismissLivePreviewBoxes ;
488459 exports . setMode = setMode ;
489460 exports . getCurrentMode = getCurrentMode ;
461+ exports . isInPreviewMode = isInPreviewMode ;
490462} ) ;
0 commit comments