@lvce-editor/editor-worker 18.12.0 → 18.13.0

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.
@@ -1229,7 +1229,6 @@ const SetFocusContext$1 = 'Viewlet.setFocusContext';
1229
1229
  const SetPatches = 'Viewlet.setPatches';
1230
1230
 
1231
1231
  const FocusEditorText$1 = 12;
1232
- const FocusExplorer = 13;
1233
1232
 
1234
1233
  const {
1235
1234
  invoke: invoke$f,
@@ -1572,7 +1571,6 @@ const editorStates = create$9();
1572
1571
  const {
1573
1572
  getCommandIds,
1574
1573
  registerCommands,
1575
- wrapCommand,
1576
1574
  wrapGetter
1577
1575
  } = editorStates;
1578
1576
  const get$6 = id => {
@@ -1607,6 +1605,7 @@ const createEditor2 = (id, uri, x, y, width, height, platform, assetDir) => {
1607
1605
  completionState: '',
1608
1606
  completionTriggerCharacters: [],
1609
1607
  completionUid: 0,
1608
+ cursorInfos: [],
1610
1609
  cursorWidth: 2,
1611
1610
  debugEnabled: false,
1612
1611
  decorations: [],
@@ -1655,6 +1654,7 @@ const createEditor2 = (id, uri, x, y, width, height, platform, assetDir) => {
1655
1654
  savedSelections: [],
1656
1655
  scrollBarHeight: 0,
1657
1656
  scrollBarWidth: 0,
1657
+ selectionInfos: [],
1658
1658
  selections: new Uint32Array(),
1659
1659
  tabSize: 0,
1660
1660
  textInfos: [],
@@ -3666,6 +3666,7 @@ const setText$1 = (editor, text) => {
3666
3666
  };
3667
3667
 
3668
3668
  const emptyEditor = {
3669
+ cursorInfos: [],
3669
3670
  debugEnabled: false,
3670
3671
  decorations: [],
3671
3672
  deltaX: 0,
@@ -3685,6 +3686,7 @@ const emptyEditor = {
3685
3686
  maxLineY: 0,
3686
3687
  minLineY: 0,
3687
3688
  scrollBarHeight: 0,
3689
+ selectionInfos: [],
3688
3690
  selections: new Uint32Array(),
3689
3691
  textInfos: [],
3690
3692
  tokenizerId: 0,
@@ -3973,6 +3975,7 @@ const createEditor = async ({
3973
3975
  completionState: '',
3974
3976
  completionTriggerCharacters,
3975
3977
  completionUid: 0,
3978
+ cursorInfos: [],
3976
3979
  cursorWidth: 2,
3977
3980
  decorations: [],
3978
3981
  deltaX: 0,
@@ -4016,6 +4019,7 @@ const createEditor = async ({
4016
4019
  savedSelections,
4017
4020
  scrollBarHeight: 0,
4018
4021
  scrollBarWidth: 0,
4022
+ selectionInfos: [],
4019
4023
  selections: new Uint32Array(),
4020
4024
  tabSize,
4021
4025
  textInfos: [],
@@ -4089,7 +4093,7 @@ const isEqual$1 = (oldState, newState) => {
4089
4093
  };
4090
4094
 
4091
4095
  const isEqual = (oldState, newState) => {
4092
- return oldState.lines === newState.lines && oldState.textInfos === newState.textInfos && oldState.differences === newState.differences && oldState.initial === newState.initial;
4096
+ return oldState.lines === newState.lines && oldState.textInfos === newState.textInfos && oldState.differences === newState.differences && oldState.initial === newState.initial && oldState.selections === newState.selections;
4093
4097
  };
4094
4098
 
4095
4099
  const RenderFocus = 6;
@@ -6337,6 +6341,22 @@ const handlePointerCaptureLost = editor => {
6337
6341
  return editor;
6338
6342
  };
6339
6343
 
6344
+ const handlePointerDown$1 = (state, button, altKey, ctrlKey, x, y, detail) => {
6345
+ const modifier = 0;
6346
+ const clickDetail = Single; // TODO
6347
+ // console.log({ detail })
6348
+ switch (clickDetail) {
6349
+ case Double:
6350
+ return handleDoubleClick(state, modifier, x, y);
6351
+ case Single:
6352
+ return handleSingleClick(state, modifier, x, y);
6353
+ case Triple:
6354
+ return handleTripleClick(state, modifier, x, y);
6355
+ default:
6356
+ return state;
6357
+ }
6358
+ };
6359
+
6340
6360
  const moveRectangleSelection = (editor, position) => {
6341
6361
  // @ts-ignore
6342
6362
  // const anchor = EditorMoveSelection.state.position
@@ -9531,29 +9551,28 @@ const InputBox = 'InputBox';
9531
9551
  const MaskIcon = 'MaskIcon';
9532
9552
  const Viewlet = 'Viewlet';
9533
9553
 
9534
- const HandleBeforeInput = 'handleBeforeInput';
9535
- const HandleBlur = 'handleBlur';
9536
- const HandleClose = 'handleClose';
9537
- const HandleCompositionEnd = 'handleCompositionEnd';
9538
- const HandleCompositionStart = 'handleCompositionStart';
9539
- const HandleCompositionUpdate = 'handleCompositionUpdate';
9540
- const HandleContextMenu = 'handleContextMenu';
9541
- const HandleCut = 'handleCut';
9542
- const HandleFocus = 'handleFocus';
9543
- const HandleMouseDown = 'handleMouseDown';
9544
- const HandleMouseMove = 'handleMouseMove';
9545
- const HandlePaste = 'handlePaste';
9546
- const HandlePointerDown = 'handlePointerDown';
9547
- const HandlePointerMove = 'handlePointerMove';
9548
- const HandlePointerUp = 'handlePointerUp';
9549
- const HandleSashPointerDown = 'handleSashPointerDown';
9550
- const HandleScrollBarHorizontalPointerDown = 'handleScrollBarHorizontalPointerDown';
9551
- const HandleScrollBarHorizontalPointerMove = 'handleScrollBarHorizontalPointerMove';
9552
- const HandleScrollBarHorizontalPointerUp = 'handleScrollBarHorizontalPointerUp';
9553
- const HandleScrollBarVerticalPointerDown = 'handleScrollBarVerticalPointerDown';
9554
- const HandleScrollBarVerticalPointerMove = 'handleScrollBarVerticalPointerMove';
9555
- const HandleScrollBarVerticalPointerUp = 'handleScrollBarVerticalPointerUp';
9556
- const HandleWheel = 'handleWheel';
9554
+ const HandleBeforeInput = 1;
9555
+ const HandleBlur = 2;
9556
+ const HandleClose = 9;
9557
+ const HandleCompositionEnd = 10;
9558
+ const HandleCompositionStart = 11;
9559
+ const HandleCompositionUpdate = 12;
9560
+ const HandleContextMenu = 13;
9561
+ const HandleCut = 14;
9562
+ const HandleFocus = 15;
9563
+ const HandleMouseMove = 19;
9564
+ const HandlePaste = 20;
9565
+ const HandlePointerDown = 21;
9566
+ const HandlePointerMove = 22;
9567
+ const HandlePointerUp = 23;
9568
+ const HandleSashPointerDown = 26;
9569
+ const HandleScrollBarHorizontalPointerDown = 27;
9570
+ const HandleScrollBarHorizontalPointerMove = 28;
9571
+ const HandleScrollBarHorizontalPointerUp = 29;
9572
+ const HandleScrollBarVerticalPointerDown = 30;
9573
+ const HandleScrollBarVerticalPointerMove = 31;
9574
+ const HandleScrollBarVerticalPointerUp = 32;
9575
+ const HandleWheel = 33;
9557
9576
 
9558
9577
  const Div = 4;
9559
9578
  const Input = 6;
@@ -9878,6 +9897,24 @@ const unsetAdditionalFocus = async focusKey => {
9878
9897
  await invoke$c('Focus.removeAdditionalFocus', focusKey);
9879
9898
  };
9880
9899
 
9900
+ const shouldUpdateSelectionData = (oldState, newState) => {
9901
+ return oldState.selections !== newState.selections || oldState.focused !== newState.focused || oldState.minLineY !== newState.minLineY || oldState.maxLineY !== newState.maxLineY || oldState.differences !== newState.differences || oldState.charWidth !== newState.charWidth || oldState.cursorWidth !== newState.cursorWidth || oldState.fontFamily !== newState.fontFamily || oldState.fontSize !== newState.fontSize || oldState.fontWeight !== newState.fontWeight || oldState.isMonospaceFont !== newState.isMonospaceFont || oldState.letterSpacing !== newState.letterSpacing || oldState.lines !== newState.lines || oldState.rowHeight !== newState.rowHeight || oldState.tabSize !== newState.tabSize || oldState.width !== newState.width;
9902
+ };
9903
+ const updateDerivedState = async (oldState, newState) => {
9904
+ if (!shouldUpdateSelectionData(oldState, newState)) {
9905
+ return newState;
9906
+ }
9907
+ const {
9908
+ cursorInfos,
9909
+ selectionInfos
9910
+ } = await getVisible(newState);
9911
+ return {
9912
+ ...newState,
9913
+ cursorInfos,
9914
+ selectionInfos
9915
+ };
9916
+ };
9917
+
9881
9918
  const FocusEditor = 12;
9882
9919
  const FocusEditorCompletions = 9;
9883
9920
  const FocusEditorRename = 11;
@@ -9939,13 +9976,14 @@ const getSelections2 = editorUid => {
9939
9976
  } = editor;
9940
9977
  return selections;
9941
9978
  };
9942
- const setSelections2 = (editorUid, selections) => {
9979
+ const setSelections2 = async (editorUid, selections) => {
9943
9980
  const editor = getEditor(editorUid);
9944
9981
  const newEditor = {
9945
9982
  ...editor,
9946
9983
  selections
9947
9984
  };
9948
- set$7(editorUid, editor, newEditor);
9985
+ const newEditorWithDerivedState = await updateDerivedState(editor, newEditor);
9986
+ set$7(editorUid, editor, newEditorWithDerivedState);
9949
9987
  };
9950
9988
  const closeWidget2 = async (editorUid, widgetId, widgetName, unsetAdditionalFocus$1) => {
9951
9989
  const editor = getEditor(editorUid);
@@ -9964,7 +10002,8 @@ const closeWidget2 = async (editorUid, widgetId, widgetName, unsetAdditionalFocu
9964
10002
  focused: true,
9965
10003
  widgets: newWidgets
9966
10004
  };
9967
- set$7(editorUid, editor, newEditor);
10005
+ const newEditorWithDerivedState = await updateDerivedState(editor, newEditor);
10006
+ set$7(editorUid, editor, newEditorWithDerivedState);
9968
10007
  await setFocus(FocusEditorText);
9969
10008
  if (unsetAdditionalFocus$1) {
9970
10009
  await unsetAdditionalFocus(unsetAdditionalFocus$1);
@@ -9976,7 +10015,8 @@ const closeFind2 = async editorUid => {
9976
10015
  const applyEdits2 = async (editorUid, edits) => {
9977
10016
  const editor = getEditor(editorUid);
9978
10017
  const newEditor = await applyEdit(editor, edits);
9979
- set$7(editorUid, editor, newEditor);
10018
+ const newEditorWithDerivedState = await updateDerivedState(editor, newEditor);
10019
+ set$7(editorUid, editor, newEditorWithDerivedState);
9980
10020
  };
9981
10021
  const getSourceActions = async editorUid => {
9982
10022
  const actions = await getEditorSourceActions(editorUid);
@@ -11049,7 +11089,7 @@ const renderFocus$2 = (oldState, newState) => {
11049
11089
  };
11050
11090
 
11051
11091
  const renderFocusContext$1 = (oldState, newState) => {
11052
- return [SetFocusContext$1, newState.uid, FocusExplorer];
11092
+ return [SetFocusContext$1, newState.uid, FocusEditorText$1];
11053
11093
  };
11054
11094
 
11055
11095
  const SetText = 1;
@@ -11548,7 +11588,7 @@ const getEditorVirtualDom = ({
11548
11588
  }, ...selectionsDom, {
11549
11589
  childCount: textInfos.length,
11550
11590
  className: 'EditorRows',
11551
- onMouseDown: HandleMouseDown,
11591
+ // onMouseDown: DomEventListenerFunctions.HandleMouseDown,
11552
11592
  onPointerDown: HandlePointerDown,
11553
11593
  type: Div
11554
11594
  }, ...rowsDom, {
@@ -11668,17 +11708,17 @@ const renderLines = {
11668
11708
  }
11669
11709
  };
11670
11710
  const renderSelections = {
11671
- apply: async (oldState, newState) => {
11711
+ apply: (oldState, newState) => {
11672
11712
  const {
11673
- cursorInfos,
11674
- selectionInfos
11675
- } = await getVisible(newState);
11713
+ cursorInfos = [],
11714
+ selectionInfos = []
11715
+ } = newState;
11676
11716
  const cursorsDom = getCursorsVirtualDom(cursorInfos);
11677
11717
  const selectionsDom = getSelectionsVirtualDom(selectionInfos);
11678
11718
  return [/* method */'setSelections', cursorsDom, selectionsDom];
11679
11719
  },
11680
11720
  isEqual(oldState, newState) {
11681
- return oldState.selections === newState.selections && oldState.focused === newState.focused && oldState.minLineY === newState.minLineY && oldState.deltaX === newState.deltaX;
11721
+ return oldState.cursorInfos === newState.cursorInfos && oldState.selectionInfos === newState.selectionInfos;
11682
11722
  }
11683
11723
  };
11684
11724
  const renderScrollBarY = {
@@ -11872,12 +11912,9 @@ const renderEventListeners = () => {
11872
11912
  name: HandlePaste,
11873
11913
  params: ['paste', 'event.clipboardData ? event.clipboardData.getData("text/plain") : ""'],
11874
11914
  preventDefault: true
11875
- }, {
11876
- name: HandleMouseDown,
11877
- params: ['handleMouseDown', 'event.button === 2 ? -1 : (((event.metaKey || event.ctrlKey) ? 2048 : 0) | (event.shiftKey ? 1024 : 0) | (event.altKey ? 512 : 0))', ClientX, ClientY, 'event.button === 2 ? 0 : event.detail']
11878
11915
  }, {
11879
11916
  name: HandlePointerDown,
11880
- params: [],
11917
+ params: ['handlePointerDown', 'event.button', 'event.altKey', 'event.ctrlKey', ClientX, ClientY],
11881
11918
  trackPointerEvents: [HandlePointerMove, HandlePointerUp]
11882
11919
  }, {
11883
11920
  name: HandlePointerMove,
@@ -11974,6 +12011,25 @@ const updateDebugInfo = async debugId => {
11974
12011
  await invoke$c('Editor.rerender', key);
11975
12012
  };
11976
12013
 
12014
+ // TODO wrap commands globally, not per editor
12015
+ // TODO only store editor state in editor worker, not in renderer worker also
12016
+
12017
+ const wrapCommand = fn => async (editorUid, ...args) => {
12018
+ const oldInstance = get$6(editorUid);
12019
+ const state = oldInstance.newState;
12020
+ const newEditor = await fn(state, ...args);
12021
+ if (state === newEditor) {
12022
+ return newEditor;
12023
+ }
12024
+ const newEditorWithDerivedState = await updateDerivedState(state, newEditor);
12025
+ // TODO if editor did not change, no need to update furthur
12026
+
12027
+ // TODO combine neweditor with latest editor?
12028
+
12029
+ set$7(editorUid, state, newEditorWithDerivedState);
12030
+ return newEditorWithDerivedState;
12031
+ };
12032
+
11977
12033
  const wrapCommandOld = wrapCommand;
11978
12034
  const commandMap = {
11979
12035
  'ActivateByEvent.activateByEvent': activateByEvent,
@@ -12060,7 +12116,7 @@ const commandMap = {
12060
12116
  'Editor.handleBeforeInput': wrapCommandOld(handleBeforeInput),
12061
12117
  'Editor.handleBeforeInputFromContentEditable': wrapCommandOld(handleBeforeInputFromContentEditable),
12062
12118
  'Editor.handleBlur': wrapCommandOld(handleBlur$1),
12063
- 'Editor.handleClickAtPosition': handleClickAtPosition,
12119
+ 'Editor.handleClickAtPosition': wrapCommandOld(handleClickAtPosition),
12064
12120
  'Editor.handleContextMenu': wrapCommandOld(handleContextMenu),
12065
12121
  'Editor.handleDoubleClick': wrapCommandOld(handleDoubleClick),
12066
12122
  'Editor.handleFocus': wrapCommandOld(handleFocus$1),
@@ -12069,6 +12125,7 @@ const commandMap = {
12069
12125
  'Editor.handleMouseMoveWithAltKey': wrapCommandOld(handleMouseMoveWithAltKey),
12070
12126
  'Editor.handleNativeSelectionChange': editorHandleNativeSelectionChange,
12071
12127
  'Editor.handlePointerCaptureLost': wrapCommandOld(handlePointerCaptureLost),
12128
+ 'Editor.handlePointerDown': wrapCommandOld(handlePointerDown$1),
12072
12129
  'Editor.handlePointerMove': wrapCommandOld(handlePointerMove),
12073
12130
  'Editor.handlePointerUp': wrapCommandOld(handlePointerUp),
12074
12131
  'Editor.handleScrollBarClick': handleScrollBarPointerDown,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "18.12.0",
3
+ "version": "18.13.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"