@@ -25,23 +25,23 @@ const App = {
2525
2626 // Check for shared snippet
2727 if ( window . location . hash . startsWith ( '#share=' ) ) {
28- const payload = window . location . hash . substring ( 7 ) ; // Remove '#share='
29- if ( window . ShareUtils && window . App ) {
30- try {
31- const stateStr = await ShareUtils . decompress ( payload ) ;
32- const state = JSON . parse ( stateStr ) ;
33-
34- // Directly load the parsed workspace object
35- this . loadWorkspaceState ( state ) ;
36-
37- App . showToast ( 'Shared workspace loaded successfully!' , 'success' ) ;
38- // Clean up URL to avoid reloading later
39- history . replaceState ( null , '' , window . location . pathname + window . location . search ) ;
40- } catch ( e ) {
41- console . error ( "Failed to load shared workspace" , e ) ;
42- App . showToast ( 'Failed to load shared workspace: ' + e . message , 'error' ) ;
43- }
28+ const payload = window . location . hash . substring ( 7 ) ; // Remove '#share='
29+ if ( window . ShareUtils && window . App ) {
30+ try {
31+ const stateStr = await ShareUtils . decompress ( payload ) ;
32+ const state = JSON . parse ( stateStr ) ;
33+
34+ // Directly load the parsed workspace object
35+ this . loadWorkspaceState ( state ) ;
36+
37+ App . showToast ( 'Shared workspace loaded successfully!' , 'success' ) ;
38+ // Clean up URL to avoid reloading later
39+ history . replaceState ( null , '' , window . location . pathname + window . location . search ) ;
40+ } catch ( e ) {
41+ console . error ( 'Failed to load shared workspace' , e ) ;
42+ App . showToast ( 'Failed to load shared workspace: ' + e . message , 'error' ) ;
4443 }
44+ }
4545 }
4646
4747 console . log ( 'JSON Editor initialized' ) ;
@@ -89,25 +89,25 @@ const App = {
8989
9090 // Setup default content ONLY if no saved content exists
9191 if ( window . StorageUtils ) {
92- const leftSaved = await StorageUtils . loadFromIndexedDB ( StorageUtils . KEYS . WORKSPACE_CONTENT + 'left' ) ;
92+ const leftSaved = await StorageUtils . loadFromIndexedDB (
93+ StorageUtils . KEYS . WORKSPACE_CONTENT + 'left'
94+ ) ;
9395 if ( ! leftSaved ) {
9496 leftEditor . setValue ( TextEditor . getDefaultJson ( ) ) ;
9597 // Sync to right only if both are empty
96- const rightSaved = await StorageUtils . loadFromIndexedDB ( StorageUtils . KEYS . WORKSPACE_CONTENT + 'right' ) ;
98+ const rightSaved = await StorageUtils . loadFromIndexedDB (
99+ StorageUtils . KEYS . WORKSPACE_CONTENT + 'right'
100+ ) ;
97101 if ( ! rightSaved ) {
98102 rightEditor . setValue ( leftEditor . getValue ( ) ) ;
99103 }
100104 }
101105 }
102106
103107 // --- Custom Features --- //
104-
105- // Add "Copy to Right" arrow to Left Editor Primary Toolbar
106- // Position: Right (Extreme Right)
107108 this . copyToRightBtn = leftEditor . addPrimaryButton ( {
108109 icon : 'arrow-right' ,
109110 title : 'Copy content to Right Editor' ,
110- // label: 'To Right', // Removed label per "keep arrow icons" request
111111 className : 'btn-copy-right' ,
112112 position : 'right' , // Goes to right group
113113 onClick : ( ) => {
@@ -117,13 +117,10 @@ const App = {
117117 } ,
118118 } ) ;
119119
120- // Add "Copy to Left" arrow to Right Editor Primary Toolbar
121- // Position: Left (Extreme Left)
122120 rightEditor . addPrimaryButton ( {
123121 icon : 'arrow-left' ,
124122 title : 'Copy content to Left Editor' ,
125- // label: 'To Left',
126- position : 'left' , // Goes to left group (prepended)
123+ position : 'left' ,
127124 onClick : ( ) => {
128125 const content = rightEditor . getValue ( ) ;
129126 leftEditor . setValue ( content ) ;
@@ -132,7 +129,9 @@ const App = {
132129 } ) ;
133130
134131 // Default View: Load from storage or default to normal
135- const savedGlobalMode = window . StorageUtils ? StorageUtils . load ( StorageUtils . KEYS . GLOBAL_VIEW_MODE , 'normal' ) : 'normal' ;
132+ const savedGlobalMode = window . StorageUtils
133+ ? StorageUtils . load ( StorageUtils . KEYS . GLOBAL_VIEW_MODE , 'normal' )
134+ : 'normal' ;
136135 this . switchGlobalMode ( savedGlobalMode ) ;
137136
138137 // Initialize Split Resizer
@@ -144,7 +143,6 @@ const App = {
144143 */
145144 setActiveEditor ( editor ) {
146145 this . activeEditor = editor ;
147- // Visual feedback? maybe border highlight?
148146 document
149147 . querySelectorAll ( '.editor-wrapper' )
150148 . forEach ( ( el ) => el . classList . remove ( 'active-wrapper' ) ) ;
@@ -210,17 +208,17 @@ const App = {
210208 } ) ;
211209
212210 document . getElementById ( 'btn-share-global' ) ?. addEventListener ( 'click' , async ( ) => {
213- if ( window . ShareUtils ) {
214- try {
215- const state = this . getWorkspaceState ( ) ;
216- const url = await ShareUtils . generateShareUrl ( JSON . stringify ( state ) ) ;
217- await navigator . clipboard . writeText ( url ) ;
218- this . showToast ( 'Workspace URL copied to clipboard!' , 'success' ) ;
219- } catch ( e ) {
220- console . error ( 'Error generating share URL:' , e ) ;
221- this . showToast ( 'Error creating snippet: ' + e . message , 'error' ) ;
222- }
211+ if ( window . ShareUtils ) {
212+ try {
213+ const state = this . getWorkspaceState ( ) ;
214+ const url = await ShareUtils . generateShareUrl ( JSON . stringify ( state ) ) ;
215+ await navigator . clipboard . writeText ( url ) ;
216+ this . showToast ( 'Workspace URL copied to clipboard!' , 'success' ) ;
217+ } catch ( e ) {
218+ console . error ( 'Error generating share URL:' , e ) ;
219+ this . showToast ( 'Error creating snippet: ' + e . message , 'error' ) ;
223220 }
221+ }
224222 } ) ;
225223
226224 // Global Keyboard Shortcuts
@@ -286,7 +284,7 @@ const App = {
286284 }
287285
288286 // Apply result is now live on input change
289-
287+
290288 // Shortcuts Popover
291289 this . initShortcutsPopover ( ) ;
292290 } ,
@@ -302,15 +300,19 @@ const App = {
302300 btn . addEventListener ( 'click' , ( e ) => {
303301 e . stopPropagation ( ) ;
304302 popover . classList . toggle ( 'hidden' ) ;
305-
303+
306304 // Re-initialize icons if they haven't been transformed yet or to be safe
307305 if ( window . lucide && ! popover . classList . contains ( 'hidden' ) ) {
308306 lucide . createIcons ( { root : popover } ) ;
309307 }
310308 } ) ;
311309
312310 document . addEventListener ( 'click' , ( e ) => {
313- if ( ! popover . classList . contains ( 'hidden' ) && ! popover . contains ( e . target ) && e . target !== btn ) {
311+ if (
312+ ! popover . classList . contains ( 'hidden' ) &&
313+ ! popover . contains ( e . target ) &&
314+ e . target !== btn
315+ ) {
314316 popover . classList . add ( 'hidden' ) ;
315317 }
316318 } ) ;
@@ -522,8 +524,6 @@ const App = {
522524 ? this . activeEditor . getValue ( )
523525 : this . editors [ 0 ] . getValue ( ) ;
524526 this . queryInputEditor . setValue ( currentContent ) ;
525- // Also run query if input has value?
526- // this.runQuery();
527527 }
528528 } ,
529529
@@ -532,7 +532,8 @@ const App = {
532532 */
533533 runQuery ( ) {
534534 const query = document . getElementById ( 'query-input' ) . value ;
535- const engine = document . querySelector ( 'input[name="query-engine"]:checked' ) ?. value || 'jsonpath' ;
535+ const engine =
536+ document . querySelector ( 'input[name="query-engine"]:checked' ) ?. value || 'jsonpath' ;
536537 const dataStr = this . queryInputEditor ? this . queryInputEditor . getValue ( ) : '{}' ;
537538
538539 try {
@@ -563,7 +564,6 @@ const App = {
563564 }
564565 } ,
565566
566-
567567 /**
568568 * Update theme for all editors
569569 */
@@ -631,8 +631,6 @@ const App = {
631631 const rightEditor = this . editors . find ( ( e ) => e . id === 'right' ) ;
632632 if ( rightEditor ) {
633633 rightEditor . setValue ( valueToSet ) ;
634- // Ensure it is in Tree mode? It should be by default config.
635- // rightEditor.switchMode('tree');
636634 }
637635 }
638636
@@ -694,14 +692,6 @@ const App = {
694692 } ,
695693
696694 updatePathDisplay ( jsPath , JSONPointer ) {
697- // Find existing global or delegate.
698- // We removed global status bar from index.html (implied by "independent status bars").
699- // But App.js had `updatePathDisplay` targeting `#status-path`.
700- // Now each editor has its own status bar.
701- // The `JsonEditor.updateStatusBar` handles parsing info.
702- // But `TextEditor` and `TreeView` call `App.updatePathDisplay` for the path (cursor/click).
703- // Pass this back to the active editor's status bar.
704-
705695 if ( this . activeEditor && this . activeEditor . statusBar ) {
706696 const pathEl = this . activeEditor . statusBar . querySelector ( '.status-path' ) ;
707697 if ( pathEl ) {
@@ -715,7 +705,7 @@ const App = {
715705 <span class="path-separator"> | </span>
716706 <span class="path-display" title="Click to copy JSONPointer">JSONPointer: <code>${ JSONPointer } </code></span>
717707 ` ;
718- // Add copy listeners... (simplified for brevity, can reuse logic)
708+
719709 pathEl . querySelectorAll ( '.path-display' ) . forEach ( ( el ) => {
720710 el . onclick = ( ) => {
721711 const code = el . querySelector ( 'code' ) . textContent ;
@@ -727,11 +717,7 @@ const App = {
727717 }
728718 } ,
729719
730- // We need to implement onContentChange if TextEditor calls it?
731- // JsonEditor handles it internally now.
732- onContentChange ( ) {
733- // No-op or global sync logic if needed
734- } ,
720+ onContentChange ( ) { } ,
735721
736722 showToast ( message , type = 'info' ) {
737723 const existing = document . querySelector ( '.toast' ) ;
@@ -748,15 +734,17 @@ const App = {
748734 */
749735 getWorkspaceState ( ) {
750736 const state = {
751- m : document . querySelector ( '.header-actions .btn.active' ) ?. id . replace ( 'btn-mode-' , '' ) || 'normal' , // global mode
737+ m :
738+ document . querySelector ( '.header-actions .btn.active' ) ?. id . replace ( 'btn-mode-' , '' ) ||
739+ 'normal' , // global mode
752740 l : { c : this . editors [ 0 ] . getValue ( ) , m : this . editors [ 0 ] . mode } ,
753- r : { c : this . editors [ 1 ] . getValue ( ) , m : this . editors [ 1 ] . mode }
741+ r : { c : this . editors [ 1 ] . getValue ( ) , m : this . editors [ 1 ] . mode } ,
754742 } ;
755-
743+
756744 if ( state . m === 'query' ) {
757- const queryInput = document . getElementById ( 'query-input' ) ;
758- const engine = document . querySelector ( 'input[name="query-engine"]:checked' ) ;
759- if ( queryInput ) state . q = { i : queryInput . value , e : engine ? engine . value : 'jsonpath' } ;
745+ const queryInput = document . getElementById ( 'query-input' ) ;
746+ const engine = document . querySelector ( 'input[name="query-engine"]:checked' ) ;
747+ if ( queryInput ) state . q = { i : queryInput . value , e : engine ? engine . value : 'jsonpath' } ;
760748 }
761749 return state ;
762750 } ,
@@ -766,39 +754,41 @@ const App = {
766754 */
767755 loadWorkspaceState ( state ) {
768756 if ( ! state || typeof state !== 'object' ) return ;
769-
757+
770758 // 1. Restore contents and modes
771759 if ( state . l ) {
772- this . editors [ 0 ] . setValue ( state . l . c || '{}' ) ;
773- if ( state . l . m ) this . editors [ 0 ] . switchMode ( state . l . m ) ;
760+ this . editors [ 0 ] . setValue ( state . l . c || '{}' ) ;
761+ if ( state . l . m ) this . editors [ 0 ] . switchMode ( state . l . m ) ;
774762 }
775763 if ( state . r ) {
776- this . editors [ 1 ] . setValue ( state . r . c || '{}' ) ;
777- if ( state . r . m ) this . editors [ 1 ] . switchMode ( state . r . m ) ;
764+ this . editors [ 1 ] . setValue ( state . r . c || '{}' ) ;
765+ if ( state . r . m ) this . editors [ 1 ] . switchMode ( state . r . m ) ;
778766 }
779767
780768 // 2. Restore global mode
781769 if ( state . m ) {
782- this . switchGlobalMode ( state . m ) ;
770+ this . switchGlobalMode ( state . m ) ;
783771 }
784772
785773 // 3. Restore query state
786774 if ( state . m === 'query' && state . q ) {
787- const queryInput = document . getElementById ( 'query-input' ) ;
788- if ( queryInput ) queryInput . value = state . q . i || '' ;
789-
790- const engineRadio = document . querySelector ( `input[name="query-engine"][value="${ state . q . e } "]` ) ;
791- if ( engineRadio ) engineRadio . checked = true ;
792-
793- // Populate input editor internally
794- if ( this . queryInputEditor ) {
795- this . queryInputEditor . setValue ( state . l ?. c || '{}' ) ;
796- }
797-
798- // Execute query
799- setTimeout ( ( ) => this . runQuery ( ) , 100 ) ;
775+ const queryInput = document . getElementById ( 'query-input' ) ;
776+ if ( queryInput ) queryInput . value = state . q . i || '' ;
777+
778+ const engineRadio = document . querySelector (
779+ `input[name="query-engine"][value="${ state . q . e } "]`
780+ ) ;
781+ if ( engineRadio ) engineRadio . checked = true ;
782+
783+ // Populate input editor internally
784+ if ( this . queryInputEditor ) {
785+ this . queryInputEditor . setValue ( state . l ?. c || '{}' ) ;
786+ }
787+
788+ // Execute query
789+ setTimeout ( ( ) => this . runQuery ( ) , 100 ) ;
800790 }
801- }
791+ } ,
802792} ;
803793
804794document . addEventListener ( 'DOMContentLoaded' , ( ) => {
0 commit comments