@lvce-editor/editor-worker 18.15.0 → 18.17.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.
@@ -4093,7 +4093,7 @@ const isEqual$1 = (oldState, newState) => {
4093
4093
  };
4094
4094
 
4095
4095
  const isEqual = (oldState, newState) => {
4096
- return oldState.lines === newState.lines && oldState.textInfos === newState.textInfos && oldState.differences === newState.differences && oldState.initial === newState.initial && oldState.selections === newState.selections;
4096
+ return oldState.cursorInfos === newState.cursorInfos && oldState.diagnostics === newState.diagnostics && oldState.highlightedLine === newState.highlightedLine && oldState.lineNumbers === newState.lineNumbers && oldState.textInfos === newState.textInfos && oldState.differences === newState.differences && oldState.initial === newState.initial && oldState.scrollBarHeight === newState.scrollBarHeight && oldState.scrollBarWidth === newState.scrollBarWidth && oldState.selectionInfos === newState.selectionInfos;
4097
4097
  };
4098
4098
 
4099
4099
  const RenderFocus = 6;
@@ -6351,8 +6351,8 @@ const handlePointerCaptureLost = editor => {
6351
6351
  return editor;
6352
6352
  };
6353
6353
 
6354
- const handlePointerDown$1 = state => {
6355
- return state;
6354
+ const handlePointerDown$1 = (state, button, altKey, ctrlKey, x, y, detail) => {
6355
+ return handleMouseDown(state, button, altKey, ctrlKey, x, y, detail);
6356
6356
  };
6357
6357
 
6358
6358
  const moveRectangleSelection = (editor, position) => {
@@ -6532,7 +6532,7 @@ const moveSelectionPx = async (editor, x, y) => {
6532
6532
  return editorMoveSelection(editor, position);
6533
6533
  };
6534
6534
 
6535
- const handlePointerMove = (editor, x, y, altKey) => {
6535
+ const handlePointerMove = async (editor, x, y, altKey) => {
6536
6536
  if (altKey) {
6537
6537
  return moveRectangleSelectionPx(editor, x, y);
6538
6538
  }
@@ -6540,6 +6540,7 @@ const handlePointerMove = (editor, x, y, altKey) => {
6540
6540
  };
6541
6541
 
6542
6542
  const handlePointerUp = editor => {
6543
+ clearEditor();
6543
6544
  return editor;
6544
6545
  };
6545
6546
 
@@ -9899,16 +9900,35 @@ const unsetAdditionalFocus = async focusKey => {
9899
9900
  const shouldUpdateSelectionData = (oldState, newState) => {
9900
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;
9901
9902
  };
9903
+ const shouldUpdateVisibleTextData = (oldState, newState) => {
9904
+ if (oldState.textInfos !== newState.textInfos || oldState.differences !== newState.differences) {
9905
+ return false;
9906
+ }
9907
+ return oldState.lines !== newState.lines || oldState.tokenizerId !== newState.tokenizerId || oldState.minLineY !== newState.minLineY || oldState.maxLineY !== newState.maxLineY || oldState.decorations !== newState.decorations || oldState.embeds !== newState.embeds || oldState.deltaX !== newState.deltaX || oldState.width !== newState.width || oldState.highlightedLine !== newState.highlightedLine || oldState.debugEnabled !== newState.debugEnabled;
9908
+ };
9902
9909
  const updateDerivedState = async (oldState, newState) => {
9910
+ let finalState = newState;
9911
+ if (shouldUpdateVisibleTextData(oldState, newState)) {
9912
+ const syncIncremental = getEnabled();
9913
+ const {
9914
+ differences,
9915
+ textInfos
9916
+ } = await getVisible$1(newState, syncIncremental);
9917
+ finalState = {
9918
+ ...newState,
9919
+ differences,
9920
+ textInfos
9921
+ };
9922
+ }
9903
9923
  if (!shouldUpdateSelectionData(oldState, newState)) {
9904
- return newState;
9924
+ return finalState;
9905
9925
  }
9906
9926
  const {
9907
9927
  cursorInfos,
9908
9928
  selectionInfos
9909
- } = await getVisible(newState);
9929
+ } = await getVisible(finalState);
9910
9930
  return {
9911
- ...newState,
9931
+ ...finalState,
9912
9932
  cursorInfos,
9913
9933
  selectionInfos
9914
9934
  };
@@ -11380,10 +11400,37 @@ const diffTree = (oldNodes, newNodes) => {
11380
11400
  return removeTrailingNavigationPatches(patches);
11381
11401
  };
11382
11402
 
11403
+ const getEditorInputVirtualDom = () => {
11404
+ return [{
11405
+ ariaAutoComplete: 'list',
11406
+ ariaMultiLine: 'true',
11407
+ ariaRoleDescription: 'editor',
11408
+ autocapitalize: 'off',
11409
+ autocomplete: 'off',
11410
+ autocorrect: 'off',
11411
+ childCount: 0,
11412
+ className: 'EditorInput',
11413
+ name: 'editor',
11414
+ onBeforeInput: HandleBeforeInput,
11415
+ onBlur: HandleBlur,
11416
+ onCompositionEnd: HandleCompositionEnd,
11417
+ onCompositionStart: HandleCompositionStart,
11418
+ onCompositionUpdate: HandleCompositionUpdate,
11419
+ onCut: HandleCut,
11420
+ onFocus: HandleFocus,
11421
+ onPaste: HandlePaste,
11422
+ role: 'textbox',
11423
+ spellcheck: false,
11424
+ type: TextArea,
11425
+ wrap: 'off'
11426
+ }];
11427
+ };
11428
+
11383
11429
  const getCursorsVirtualDom = cursors => {
11384
11430
  const dom = [];
11385
11431
  for (const translate of cursors) {
11386
11432
  dom.push({
11433
+ childCount: 0,
11387
11434
  className: EditorCursor,
11388
11435
  translate,
11389
11436
  type: Div
@@ -11392,6 +11439,15 @@ const getCursorsVirtualDom = cursors => {
11392
11439
  return dom;
11393
11440
  };
11394
11441
 
11442
+ const getEditorCursorsVirtualDom = cursorInfos => {
11443
+ const cursorsDom = getCursorsVirtualDom([...cursorInfos]);
11444
+ return [{
11445
+ childCount: cursorInfos.length,
11446
+ className: 'LayerCursor',
11447
+ type: Div
11448
+ }, ...cursorsDom];
11449
+ };
11450
+
11395
11451
  // TODO use numeric value
11396
11452
  const Error$1 = 'error';
11397
11453
  const Warning = 'warning';
@@ -11436,19 +11492,16 @@ const getDiagnosticsVirtualDom = diagnostics => {
11436
11492
  return dom;
11437
11493
  };
11438
11494
 
11439
- const getGutterInfoVirtualDom = gutterInfo => {
11495
+ const getEditorDiagnosticsVirtualDom = diagnostics => {
11496
+ const diagnosticsDom = getDiagnosticsVirtualDom([...diagnostics]);
11440
11497
  return [{
11441
- childCount: 1,
11442
- className: 'LineNumber',
11443
- type: Span
11444
- }, text(gutterInfo)];
11445
- };
11446
- const getEditorGutterVirtualDom = gutterInfos => {
11447
- const dom = gutterInfos.flatMap(getGutterInfoVirtualDom);
11448
- return dom;
11498
+ childCount: diagnostics.length,
11499
+ className: 'LayerDiagnostics',
11500
+ type: Div
11501
+ }, ...diagnosticsDom];
11449
11502
  };
11450
11503
 
11451
- const getEditorRowsVirtualDom = (textInfos, differences, lineNumbers = true, highlightedLine = -1) => {
11504
+ const getEditorRowsVirtualDom$1 = (textInfos, differences, lineNumbers = true, highlightedLine = -1) => {
11452
11505
  const dom = [];
11453
11506
  for (let i = 0; i < textInfos.length; i++) {
11454
11507
  const textInfo = textInfos[i];
@@ -11476,6 +11529,62 @@ const getEditorRowsVirtualDom = (textInfos, differences, lineNumbers = true, hig
11476
11529
  return dom;
11477
11530
  };
11478
11531
 
11532
+ const getEditorRowsVirtualDom = (textInfos, differences, lineNumbers = true, highlightedLine = -1) => {
11533
+ const rowsDom = getEditorRowsVirtualDom$1(textInfos, differences, lineNumbers, highlightedLine);
11534
+ return [{
11535
+ childCount: textInfos.length,
11536
+ className: 'EditorRows',
11537
+ onMouseDown: HandleMouseDown,
11538
+ onPointerDown: HandlePointerDown,
11539
+ type: Div
11540
+ }, ...rowsDom];
11541
+ };
11542
+
11543
+ const getSelectionsVirtualDom = selections => {
11544
+ const dom = [];
11545
+ for (let i = 0; i < selections.length; i += 4) {
11546
+ const x = selections[i];
11547
+ const y = selections[i + 1];
11548
+ const width = selections[i + 2];
11549
+ const height = selections[i + 3];
11550
+ dom.push({
11551
+ childCount: 0,
11552
+ className: EditorSelection,
11553
+ height,
11554
+ left: x,
11555
+ top: y,
11556
+ type: Div,
11557
+ width
11558
+ });
11559
+ }
11560
+ return dom;
11561
+ };
11562
+
11563
+ const getEditorSelectionsVirtualDom = selectionInfos => {
11564
+ const selectionsDom = getSelectionsVirtualDom(selectionInfos);
11565
+ return [{
11566
+ childCount: selectionInfos.length / 4,
11567
+ className: 'Selections',
11568
+ type: Div
11569
+ }, ...selectionsDom];
11570
+ };
11571
+
11572
+ const getEditorLayersVirtualDom = (selectionInfos, textInfos, differences, lineNumbers = true, highlightedLine = -1, cursorInfos = [], diagnostics = []) => {
11573
+ return [{
11574
+ childCount: 4,
11575
+ className: 'EditorLayers',
11576
+ type: Div
11577
+ }, ...getEditorSelectionsVirtualDom(selectionInfos), ...getEditorRowsVirtualDom(textInfos, differences, lineNumbers, highlightedLine), ...getEditorCursorsVirtualDom(cursorInfos), ...getEditorDiagnosticsVirtualDom(diagnostics)];
11578
+ };
11579
+
11580
+ const getEditorScrollBarDiagnosticsVirtualDom = scrollBarDiagnostics => {
11581
+ return [{
11582
+ childCount: scrollBarDiagnostics.length,
11583
+ className: 'EditorScrollBarDiagnostics',
11584
+ type: Div
11585
+ }, ...getDiagnosticsVirtualDom([...scrollBarDiagnostics])];
11586
+ };
11587
+
11479
11588
  const getScrollBarVirtualDom = () => {
11480
11589
  return [{
11481
11590
  childCount: 1,
@@ -11499,25 +11608,45 @@ const getScrollBarVirtualDom = () => {
11499
11608
  }];
11500
11609
  };
11501
11610
 
11502
- const getSelectionsVirtualDom = selections => {
11503
- const dom = [];
11504
- for (let i = 0; i < selections.length; i += 4) {
11505
- const x = selections[i];
11506
- const y = selections[i + 1];
11507
- const width = selections[i + 2];
11508
- const height = selections[i + 3];
11509
- dom.push({
11510
- className: EditorSelection,
11511
- height,
11512
- left: x,
11513
- top: y,
11514
- type: Div,
11515
- width
11516
- });
11517
- }
11611
+ const getEditorContentVirtualDom = ({
11612
+ cursorInfos = [],
11613
+ diagnostics = [],
11614
+ differences,
11615
+ highlightedLine = -1,
11616
+ lineNumbers = true,
11617
+ scrollBarDiagnostics = [],
11618
+ selectionInfos = [],
11619
+ textInfos
11620
+ }) => {
11621
+ return [{
11622
+ childCount: 5,
11623
+ className: 'EditorContent',
11624
+ onMouseMove: HandleMouseMove,
11625
+ type: Div
11626
+ }, ...getEditorInputVirtualDom(), ...getEditorLayersVirtualDom(selectionInfos, textInfos, differences, lineNumbers, highlightedLine, cursorInfos, diagnostics), ...getEditorScrollBarDiagnosticsVirtualDom(scrollBarDiagnostics), ...getScrollBarVirtualDom()];
11627
+ };
11628
+
11629
+ const getGutterInfoVirtualDom = gutterInfo => {
11630
+ return [{
11631
+ childCount: 1,
11632
+ className: 'LineNumber',
11633
+ type: Span
11634
+ }, text(gutterInfo)];
11635
+ };
11636
+ const getEditorGutterVirtualDom$1 = gutterInfos => {
11637
+ const dom = gutterInfos.flatMap(getGutterInfoVirtualDom);
11518
11638
  return dom;
11519
11639
  };
11520
11640
 
11641
+ const getEditorGutterVirtualDom = gutterInfos => {
11642
+ const gutterDom = getEditorGutterVirtualDom$1([...gutterInfos]);
11643
+ return [{
11644
+ childCount: gutterInfos.length,
11645
+ className: 'Gutter',
11646
+ type: Div
11647
+ }, ...gutterDom];
11648
+ };
11649
+
11521
11650
  const getEditorVirtualDom = ({
11522
11651
  cursorInfos = [],
11523
11652
  diagnostics = [],
@@ -11529,17 +11658,6 @@ const getEditorVirtualDom = ({
11529
11658
  selectionInfos = [],
11530
11659
  textInfos
11531
11660
  }) => {
11532
- const cursorInfosArray = [...cursorInfos];
11533
- const diagnosticsArray = [...diagnostics];
11534
- const gutterInfosArray = [...gutterInfos];
11535
- const scrollBarDiagnosticsArray = [...scrollBarDiagnostics];
11536
- const rowsDom = getEditorRowsVirtualDom(textInfos, differences, lineNumbers, highlightedLine);
11537
- const cursorsDom = getCursorsVirtualDom(cursorInfosArray);
11538
- const selectionsDom = getSelectionsVirtualDom(selectionInfos);
11539
- const diagnosticsDom = getDiagnosticsVirtualDom(diagnosticsArray);
11540
- const gutterDom = getEditorGutterVirtualDom(gutterInfosArray);
11541
- const scrollBarDiagnosticsDom = getDiagnosticsVirtualDom(scrollBarDiagnosticsArray);
11542
- const scrollBarDom = getScrollBarVirtualDom();
11543
11661
  return [{
11544
11662
  childCount: 2,
11545
11663
  className: 'Viewlet Editor',
@@ -11547,64 +11665,16 @@ const getEditorVirtualDom = ({
11547
11665
  onWheel: HandleWheel,
11548
11666
  role: 'code',
11549
11667
  type: Div
11550
- }, {
11551
- childCount: gutterInfosArray.length,
11552
- className: 'Gutter',
11553
- type: Div
11554
- }, ...gutterDom, {
11555
- childCount: 5,
11556
- className: 'EditorContent',
11557
- onMouseMove: HandleMouseMove,
11558
- type: Div
11559
- }, {
11560
- ariaAutoComplete: 'list',
11561
- ariaMultiLine: 'true',
11562
- ariaRoleDescription: 'editor',
11563
- autocapitalize: 'off',
11564
- autocomplete: 'off',
11565
- autocorrect: 'off',
11566
- childCount: 0,
11567
- className: 'EditorInput',
11568
- name: 'editor',
11569
- onBeforeInput: HandleBeforeInput,
11570
- onBlur: HandleBlur,
11571
- onCompositionEnd: HandleCompositionEnd,
11572
- onCompositionStart: HandleCompositionStart,
11573
- onCompositionUpdate: HandleCompositionUpdate,
11574
- onCut: HandleCut,
11575
- onFocus: HandleFocus,
11576
- onPaste: HandlePaste,
11577
- role: 'textbox',
11578
- spellcheck: false,
11579
- type: TextArea,
11580
- wrap: 'off'
11581
- }, {
11582
- childCount: 4,
11583
- className: 'EditorLayers',
11584
- type: Div
11585
- }, {
11586
- childCount: selectionsDom.length,
11587
- className: 'Selections',
11588
- type: Div
11589
- }, ...selectionsDom, {
11590
- childCount: textInfos.length,
11591
- className: 'EditorRows',
11592
- onMouseDown: HandleMouseDown,
11593
- onPointerDown: HandlePointerDown,
11594
- type: Div
11595
- }, ...rowsDom, {
11596
- childCount: cursorsDom.length,
11597
- className: 'LayerCursor',
11598
- type: Div
11599
- }, ...cursorsDom, {
11600
- childCount: diagnosticsDom.length,
11601
- className: 'LayerDiagnostics',
11602
- type: Div
11603
- }, ...diagnosticsDom, {
11604
- childCount: scrollBarDiagnosticsDom.length,
11605
- className: 'EditorScrollBarDiagnostics',
11606
- type: Div
11607
- }, ...scrollBarDiagnosticsDom, ...scrollBarDom];
11668
+ }, ...getEditorGutterVirtualDom(gutterInfos), ...getEditorContentVirtualDom({
11669
+ cursorInfos,
11670
+ diagnostics,
11671
+ differences,
11672
+ highlightedLine,
11673
+ lineNumbers,
11674
+ scrollBarDiagnostics,
11675
+ selectionInfos,
11676
+ textInfos
11677
+ })];
11608
11678
  };
11609
11679
 
11610
11680
  const getDom = state => {
@@ -11701,7 +11771,7 @@ const renderLines = {
11701
11771
  minLineY
11702
11772
  } = newState;
11703
11773
  const relativeLine = highlightedLine - minLineY;
11704
- const dom = getEditorRowsVirtualDom(textInfos, differences, true, relativeLine);
11774
+ const dom = getEditorRowsVirtualDom$1(textInfos, differences, true, relativeLine);
11705
11775
  return [/* method */'setText', dom];
11706
11776
  },
11707
11777
  isEqual(oldState, newState) {
@@ -11792,7 +11862,7 @@ const renderGutterInfo = {
11792
11862
  gutterInfos.push(i + 1);
11793
11863
  }
11794
11864
  }
11795
- const dom = getEditorGutterVirtualDom(gutterInfos);
11865
+ const dom = getEditorGutterVirtualDom$1(gutterInfos);
11796
11866
  return ['renderGutter', dom];
11797
11867
  },
11798
11868
  isEqual(oldState, newState) {
@@ -12026,6 +12096,7 @@ const wrapCommand = fn => async (editorUid, ...args) => {
12026
12096
  return newEditor;
12027
12097
  }
12028
12098
  const newEditorWithDerivedState = await updateDerivedState(state, newEditor);
12099
+
12029
12100
  // TODO if editor did not change, no need to update furthur
12030
12101
 
12031
12102
  // TODO combine neweditor with latest editor?
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "18.15.0",
3
+ "version": "18.17.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"