@lvce-editor/editor-worker 19.29.5 → 19.29.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1909,12 +1909,12 @@ const launchColorPickerWorker = async () => {
1909
1909
  return launchWorker(name, url);
1910
1910
  };
1911
1911
 
1912
- const state$c = {};
1912
+ const state$d = {};
1913
1913
  const getOrCreate$3 = () => {
1914
- if (!state$c.workerPromise) {
1915
- state$c.workerPromise = launchColorPickerWorker();
1914
+ if (!state$d.workerPromise) {
1915
+ state$d.workerPromise = launchColorPickerWorker();
1916
1916
  }
1917
- return state$c.workerPromise;
1917
+ return state$d.workerPromise;
1918
1918
  };
1919
1919
  const invoke$8 = async (method, ...params) => {
1920
1920
  const worker = await getOrCreate$3();
@@ -1941,7 +1941,7 @@ const loadContent$3 = async (state, parentUid) => {
1941
1941
 
1942
1942
  const editorStates = create$9();
1943
1943
  const {
1944
- dispose: dispose$2,
1944
+ dispose: dispose$3,
1945
1945
  getCommandIds,
1946
1946
  registerCommands,
1947
1947
  wrapGetter
@@ -2115,17 +2115,17 @@ const applyWidgetChange = async (editor, widget, changes) => {
2115
2115
  ...newState
2116
2116
  };
2117
2117
  }
2118
- return widget;
2118
+ return editor;
2119
2119
  };
2120
2120
 
2121
2121
  const applyWidgetChanges = async (editor, changes) => {
2122
2122
  const widgets = editor.widgets || [];
2123
2123
  if (widgets.length === 0) {
2124
- return widgets;
2124
+ return editor;
2125
2125
  }
2126
2126
  let latestEditor = editor;
2127
2127
  for (const widget of widgets) {
2128
- latestEditor = await applyWidgetChange(editor, widget, changes);
2128
+ latestEditor = await applyWidgetChange(latestEditor, widget, changes);
2129
2129
  }
2130
2130
  return latestEditor;
2131
2131
  };
@@ -2476,7 +2476,7 @@ const getInitialLineState = initialLineState => {
2476
2476
  return deepCopy(initialLineState);
2477
2477
  };
2478
2478
 
2479
- const state$b = {
2479
+ const state$c = {
2480
2480
  warned: []
2481
2481
  };
2482
2482
  const flattenTokensArray = tokens => {
@@ -2488,10 +2488,10 @@ const flattenTokensArray = tokens => {
2488
2488
  return flattened;
2489
2489
  };
2490
2490
  const warnDeprecatedArrayReturn = (languageId, fn) => {
2491
- if (state$b.warned.includes(fn)) {
2491
+ if (state$c.warned.includes(fn)) {
2492
2492
  return;
2493
2493
  }
2494
- state$b.warned.push(fn);
2494
+ state$c.warned.push(fn);
2495
2495
  console.warn(`tokenizers without hasArrayReturn=false are deprecated (language ${languageId})`);
2496
2496
  };
2497
2497
  const safeTokenizeLine = (languageId, tokenizeLine, line, lineStateAtStart, hasArrayReturn) => {
@@ -2552,14 +2552,14 @@ const TokenizePlainText = {
2552
2552
  tokenizeLine
2553
2553
  };
2554
2554
 
2555
- const state$a = {
2555
+ const state$b = {
2556
2556
  enabled: false
2557
2557
  };
2558
2558
  const setEnabled$1 = value => {
2559
- state$a.enabled = value;
2559
+ state$b.enabled = value;
2560
2560
  };
2561
2561
  const getEnabled$1 = () => {
2562
- return state$a.enabled;
2562
+ return state$b.enabled;
2563
2563
  };
2564
2564
 
2565
2565
  const {
@@ -2567,25 +2567,25 @@ const {
2567
2567
  set: set$6
2568
2568
  } = SyntaxHighlightingWorker;
2569
2569
 
2570
- const state$9 = {
2570
+ const state$a = {
2571
2571
  pending: Object.create(null),
2572
2572
  tokenizePaths: Object.create(null),
2573
2573
  tokenizers: Object.create(null)
2574
2574
  };
2575
2575
  const has = languageId => {
2576
- return Object.hasOwn(state$9.tokenizers, languageId);
2576
+ return Object.hasOwn(state$a.tokenizers, languageId);
2577
2577
  };
2578
2578
  const set$5 = (languageId, tokenizer) => {
2579
- state$9.tokenizers[languageId] = tokenizer;
2579
+ state$a.tokenizers[languageId] = tokenizer;
2580
2580
  };
2581
2581
  const get$6 = languageId => {
2582
- return state$9.tokenizers[languageId];
2582
+ return state$a.tokenizers[languageId];
2583
2583
  };
2584
2584
  const setTokenizePath = (languageId, tokenizePath) => {
2585
- state$9.tokenizePaths[languageId] = tokenizePath;
2585
+ state$a.tokenizePaths[languageId] = tokenizePath;
2586
2586
  };
2587
2587
  const getTokenizePath$1 = languageId => {
2588
- return state$9.tokenizePaths[languageId] || '';
2588
+ return state$a.tokenizePaths[languageId] || '';
2589
2589
  };
2590
2590
  const setTokenizePaths = languages => {
2591
2591
  for (const language of languages) {
@@ -2595,7 +2595,7 @@ const setTokenizePaths = languages => {
2595
2595
  }
2596
2596
  };
2597
2597
  const isPending = languageId => {
2598
- return Object.hasOwn(state$9.pending, languageId);
2598
+ return Object.hasOwn(state$a.pending, languageId);
2599
2599
  };
2600
2600
 
2601
2601
  const tokenMaps = Object.create(null);
@@ -3391,14 +3391,14 @@ const getVisible$1 = async (editor, syncIncremental) => {
3391
3391
  };
3392
3392
  };
3393
3393
 
3394
- const state$8 = {
3394
+ const state$9 = {
3395
3395
  enabled: false
3396
3396
  };
3397
3397
  const setEnabled = value => {
3398
- state$8.enabled = value;
3398
+ state$9.enabled = value;
3399
3399
  };
3400
3400
  const getEnabled = () => {
3401
- return state$8.enabled;
3401
+ return state$9.enabled;
3402
3402
  };
3403
3403
 
3404
3404
  // TODO this should be in a separate scrolling module
@@ -3623,7 +3623,7 @@ const getUrlAtOffset = (editor, offset) => {
3623
3623
 
3624
3624
  const EditorChange = 1;
3625
3625
 
3626
- const state$7 = Object.create(null);
3626
+ const state$8 = Object.create(null);
3627
3627
 
3628
3628
  /**
3629
3629
  * Register a listener for a specific event type
@@ -3633,13 +3633,13 @@ const state$7 = Object.create(null);
3633
3633
  const registerListener$1 = (listenerType, rpcId) => {
3634
3634
  number(listenerType);
3635
3635
  number(rpcId);
3636
- if (!Object.hasOwn(state$7, listenerType)) {
3637
- state$7[listenerType] = [];
3636
+ if (!Object.hasOwn(state$8, listenerType)) {
3637
+ state$8[listenerType] = [];
3638
3638
  }
3639
3639
 
3640
3640
  // Avoid duplicate registrations
3641
- if (!state$7[listenerType].includes(rpcId)) {
3642
- state$7[listenerType].push(rpcId);
3641
+ if (!state$8[listenerType].includes(rpcId)) {
3642
+ state$8[listenerType].push(rpcId);
3643
3643
  }
3644
3644
  };
3645
3645
 
@@ -3651,10 +3651,10 @@ const registerListener$1 = (listenerType, rpcId) => {
3651
3651
  const unregisterListener$1 = (listenerType, rpcId) => {
3652
3652
  number(listenerType);
3653
3653
  number(rpcId);
3654
- if (Object.hasOwn(state$7, listenerType)) {
3655
- const index = state$7[listenerType].indexOf(rpcId);
3654
+ if (Object.hasOwn(state$8, listenerType)) {
3655
+ const index = state$8[listenerType].indexOf(rpcId);
3656
3656
  if (index !== -1) {
3657
- state$7[listenerType].splice(index, 1);
3657
+ state$8[listenerType].splice(index, 1);
3658
3658
  }
3659
3659
  }
3660
3660
  };
@@ -3666,7 +3666,7 @@ const unregisterListener$1 = (listenerType, rpcId) => {
3666
3666
  */
3667
3667
  const getListeners = listenerType => {
3668
3668
  number(listenerType);
3669
- return state$7[listenerType] || [];
3669
+ return state$8[listenerType] || [];
3670
3670
  };
3671
3671
 
3672
3672
  /**
@@ -4782,6 +4782,44 @@ const diff2 = uid => {
4782
4782
  return result;
4783
4783
  };
4784
4784
 
4785
+ const autoSaveDelay = 1000;
4786
+ const pendingSaves = new Map();
4787
+ const state$7 = {
4788
+ nextToken: 0
4789
+ };
4790
+ const run = async (uid, token, save) => {
4791
+ if (!isLatest(uid, token)) {
4792
+ return;
4793
+ }
4794
+ await save(token);
4795
+ };
4796
+ const schedule = (uid, save) => {
4797
+ dispose$2(uid);
4798
+ const token = ++state$7.nextToken;
4799
+ const timeout = setTimeout(run, autoSaveDelay, uid, token, save);
4800
+ pendingSaves.set(uid, {
4801
+ timeout,
4802
+ token
4803
+ });
4804
+ };
4805
+ const isLatest = (uid, token) => {
4806
+ return pendingSaves.get(uid)?.token === token;
4807
+ };
4808
+ const consume = (uid, token) => {
4809
+ if (!isLatest(uid, token)) {
4810
+ return;
4811
+ }
4812
+ dispose$2(uid);
4813
+ };
4814
+ const dispose$2 = uid => {
4815
+ const pendingSave = pendingSaves.get(uid);
4816
+ if (!pendingSave) {
4817
+ return;
4818
+ }
4819
+ clearTimeout(pendingSave.timeout);
4820
+ pendingSaves.delete(uid);
4821
+ };
4822
+
4785
4823
  const addWidget$1 = widget => {
4786
4824
  const module = get$7(widget.id);
4787
4825
  if (!module) {
@@ -4874,6 +4912,7 @@ const disposeEditor = async editorUid => {
4874
4912
  });
4875
4913
  dispose$1(editorUid);
4876
4914
  dispose$2(editorUid);
4915
+ dispose$3(editorUid);
4877
4916
  return commands;
4878
4917
  };
4879
4918
 
@@ -8898,6 +8937,7 @@ const createFn = (key, name, widgetId) => {
8898
8937
  const latestAfterInvoke = get$8(editor.uid).newState;
8899
8938
  const latestChildIndex = latestAfterInvoke.widgets.findIndex(isWidget);
8900
8939
  if (latestChildIndex === -1) {
8940
+ set$8(editor.uid, editor, latestAfterInvoke);
8901
8941
  return latestAfterInvoke;
8902
8942
  }
8903
8943
  const diff = await invoke(`${name}.diff2`, uid);
@@ -9972,6 +10012,7 @@ const create = () => {
9972
10012
  id: SourceAction$1,
9973
10013
  newState: {
9974
10014
  commands: [],
10015
+ editorUid: 0,
9975
10016
  focusedIndex: 0,
9976
10017
  height: 0,
9977
10018
  maxHeight: 0,
@@ -9983,6 +10024,7 @@ const create = () => {
9983
10024
  },
9984
10025
  oldState: {
9985
10026
  commands: [],
10027
+ editorUid: 0,
9986
10028
  focusedIndex: 0,
9987
10029
  height: 0,
9988
10030
  maxHeight: 0,
@@ -11173,10 +11215,13 @@ const render$8 = widget => {
11173
11215
  const commands = renderFull$3(widget.oldState, widget.newState);
11174
11216
  const wrappedCommands = [];
11175
11217
  const {
11218
+ editorUid,
11176
11219
  uid
11177
11220
  } = widget.newState;
11178
11221
  for (const command of commands) {
11179
- if (commandsToForward$2.includes(command[0])) {
11222
+ if (command[0] === SetFocusContext) {
11223
+ wrappedCommands.push([command[0], editorUid, ...command.slice(1)]);
11224
+ } else if (commandsToForward$2.includes(command[0])) {
11180
11225
  wrappedCommands.push(command);
11181
11226
  } else {
11182
11227
  wrappedCommands.push(['Viewlet.send', uid, ...command]);
@@ -11417,23 +11462,23 @@ const getKeyBindings = () => {
11417
11462
  key: Escape,
11418
11463
  when: FocusSourceActions
11419
11464
  }, {
11420
- command: 'EditorSourceActions.focusNext',
11465
+ command: 'EditorSourceAction.focusNext',
11421
11466
  key: DownArrow,
11422
11467
  when: FocusSourceActions
11423
11468
  }, {
11424
- command: 'EditorSourceActions.focusPrevious',
11469
+ command: 'EditorSourceAction.focusPrevious',
11425
11470
  key: UpArrow,
11426
11471
  when: FocusSourceActions
11427
11472
  }, {
11428
- command: 'EditorSourceActions.focusFirst',
11473
+ command: 'EditorSourceAction.focusFirst',
11429
11474
  key: Home,
11430
11475
  when: FocusSourceActions
11431
11476
  }, {
11432
- command: 'EditorSourceActions.focusLast',
11477
+ command: 'EditorSourceAction.focusLast',
11433
11478
  key: End,
11434
11479
  when: FocusSourceActions
11435
11480
  }, {
11436
- command: 'EditorSourceActions.selectCurrent',
11481
+ command: 'EditorSourceAction.selectCurrent',
11437
11482
  key: Enter,
11438
11483
  when: FocusSourceActions
11439
11484
  }, {
@@ -13647,6 +13692,30 @@ const editorDiagnosticEffect = {
13647
13692
  };
13648
13693
 
13649
13694
  const queues = {};
13695
+ const saveAfterDelay = async (uid, token) => {
13696
+ if (!get$8(uid)) {
13697
+ consume(uid, token);
13698
+ return;
13699
+ }
13700
+ let didSave = false;
13701
+ const save$1 = wrapCommand(async editor => {
13702
+ if (!isLatest(uid, token)) {
13703
+ return editor;
13704
+ }
13705
+ consume(uid, token);
13706
+ const autoSave = await get$3('files.autoSave');
13707
+ if (autoSave !== 'afterDelay') {
13708
+ return editor;
13709
+ }
13710
+ const savedEditor = await save(editor);
13711
+ didSave = savedEditor !== editor;
13712
+ return savedEditor;
13713
+ });
13714
+ await save$1(uid);
13715
+ if (didSave) {
13716
+ await invoke$a('Editor.renderPending', uid);
13717
+ }
13718
+ };
13650
13719
 
13651
13720
  // TODO wrap commands globally, not per editor
13652
13721
  // TODO only store editor state in editor worker, not in renderer worker also
@@ -13711,6 +13780,11 @@ const wrapCommand = fn => async (uid, ...args) => {
13711
13780
  set$8(otherUid, instance.oldState, synchronizedEditor);
13712
13781
  }
13713
13782
  }
13783
+ if (lines !== finalEditor.lines) {
13784
+ schedule(uid, token => saveAfterDelay(uid, token));
13785
+ } else if (modified && !finalEditor.modified) {
13786
+ dispose$2(uid);
13787
+ }
13714
13788
  return finalEditor;
13715
13789
  } finally {
13716
13790
  resolve();
@@ -13837,6 +13911,7 @@ const commandMap = {
13837
13911
  'Editor.handleScrollBarVerticalPointerMove': wrapCommand(handleScrollBarVerticalPointerMove),
13838
13912
  'Editor.handleSettingsChanged': wrapCommand(handleSettingsChanged),
13839
13913
  'Editor.handleSingleClick': wrapCommand(handleSingleClick),
13914
+ 'Editor.handleSourceActionClick': selectItem,
13840
13915
  'Editor.handleTab': wrapCommand(handleTab),
13841
13916
  'Editor.handleTouchEnd': wrapCommand(handleTouchEnd),
13842
13917
  'Editor.handleTouchMove': wrapCommand(handleTouchMove),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "19.29.5",
3
+ "version": "19.29.7",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"