@lvce-editor/editor-worker 3.6.0 → 3.7.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.
@@ -513,7 +513,6 @@ const offsetAt = (textDocument, positionRowIndex, positionColumnIndex) => {
513
513
  return offset;
514
514
  };
515
515
  const positionAt = (textDocument, offset) => {
516
- // console.log({ textDocument, offset })
517
516
  let rowIndex = 0;
518
517
  let columnIndex = 0;
519
518
  let currentOffset = 0;
@@ -2012,7 +2011,6 @@ const createEditor = async ({
2012
2011
  ...newEditor3,
2013
2012
  focused: true
2014
2013
  };
2015
- // console.log({ newEditor })
2016
2014
  set$7(id, emptyEditor, newEditor4);
2017
2015
  await invoke$2(TextDocumentSyncFull, uri, id, languageId, content);
2018
2016
  };
@@ -2503,7 +2501,7 @@ const create$3 = () => {
2503
2501
  };
2504
2502
 
2505
2503
  const ColorPicker = 41;
2506
- const FindWidget$1 = 16;
2504
+ const FindWidget = 16;
2507
2505
  const EditorCompletion = 9;
2508
2506
  const CompletionDetail = 999;
2509
2507
 
@@ -3646,7 +3644,7 @@ const state$5 = {
3646
3644
  columnIndex: 0
3647
3645
  }
3648
3646
  };
3649
- const getPosition$1 = () => {
3647
+ const getPosition$2 = () => {
3650
3648
  return state$5.position;
3651
3649
  };
3652
3650
 
@@ -3871,13 +3869,6 @@ const handleMouseMoveWithAltKey = async (editor, x, y) => {
3871
3869
  // const definitionRelativeY = definitionStartPosition.rowIndex - editor.minLineY
3872
3870
 
3873
3871
  const lineTokenMap = editor.lineCache[definitionStartPosition.rowIndex + 1];
3874
- console.log({
3875
- tokenMap: lineTokenMap
3876
- });
3877
- console.log({
3878
- lineCache: editor.lineCache,
3879
- rowIndex: definitionStartPosition.rowIndex
3880
- });
3881
3872
  if (!lineTokenMap) {
3882
3873
  return editor;
3883
3874
  }
@@ -3885,9 +3876,6 @@ const handleMouseMoveWithAltKey = async (editor, x, y) => {
3885
3876
  if (tokenIndex === -1) {
3886
3877
  return editor;
3887
3878
  }
3888
- console.log({
3889
- token: tokenIndex
3890
- });
3891
3879
  // .tokens
3892
3880
  // await RendererProcess.invoke(
3893
3881
  // /* Viewlet.invoke */ 'Viewlet.send',
@@ -3896,9 +3884,6 @@ const handleMouseMoveWithAltKey = async (editor, x, y) => {
3896
3884
  // /* relativeY */ definitionRelativeY,
3897
3885
  // /* tokenIndex */ tokenIndex,
3898
3886
  // )
3899
- console.log({
3900
- definition
3901
- });
3902
3887
  return editor;
3903
3888
  } catch (error) {
3904
3889
  // @ts-ignore
@@ -3979,7 +3964,7 @@ const setPosition = position => {
3979
3964
  const getEditor$1 = () => {
3980
3965
  return state$3.currentEditor;
3981
3966
  };
3982
- const getPosition = () => {
3967
+ const getPosition$1 = () => {
3983
3968
  return state$3.position;
3984
3969
  };
3985
3970
  const hasListener = () => {
@@ -4224,7 +4209,7 @@ const getNewSelections$5 = (anchor, position) => {
4224
4209
 
4225
4210
  // @ts-ignore
4226
4211
  const editorMoveSelection = (editor, position) => {
4227
- const anchor = getPosition$1();
4212
+ const anchor = getPosition$2();
4228
4213
  const newSelections = getNewSelections$5(anchor, position);
4229
4214
  // TODO if selection equals previous selection -> do nothing
4230
4215
  return scheduleSelections(editor, newSelections);
@@ -4511,7 +4496,7 @@ const getNewEditor$1 = (editor, position) => {
4511
4496
  const newMinLineY = position.rowIndex;
4512
4497
  const newMaxLineY = position.rowIndex + diff;
4513
4498
  const newDeltaY = position.rowIndex * rowHeight;
4514
- const anchor = getPosition$1();
4499
+ const anchor = getPosition$2();
4515
4500
  const newSelections = new Uint32Array([position.rowIndex - 1, position.columnIndex, anchor.rowIndex, anchor.columnIndex]);
4516
4501
  return {
4517
4502
  ...editor,
@@ -4526,7 +4511,7 @@ const getNewEditor$1 = (editor, position) => {
4526
4511
  const newMinLineY = position.rowIndex - diff;
4527
4512
  const newMaxLineY = position.rowIndex;
4528
4513
  const newDeltaY = newMinLineY * rowHeight;
4529
- const anchor = getPosition$1();
4514
+ const anchor = getPosition$2();
4530
4515
  const newSelections = new Uint32Array([anchor.rowIndex, anchor.columnIndex, position.rowIndex + 1, position.columnIndex]);
4531
4516
  return {
4532
4517
  ...editor,
@@ -4543,7 +4528,7 @@ const continueScrollingAndMovingSelection = async () => {
4543
4528
  if (!editor) {
4544
4529
  return;
4545
4530
  }
4546
- const position = getPosition();
4531
+ const position = getPosition$1();
4547
4532
  if (position.rowIndex === 0) {
4548
4533
  return;
4549
4534
  }
@@ -5087,12 +5072,6 @@ const openCompletion = async editor => {
5087
5072
  };
5088
5073
  };
5089
5074
 
5090
- const FindWidget = 'FindWidget';
5091
- const openFind = async state => {
5092
- await invoke$3('Viewlet.openWidget', FindWidget);
5093
- return state;
5094
- };
5095
-
5096
5075
  const create$1 = () => {
5097
5076
  const uid = create$4();
5098
5077
  const widget = {
@@ -5109,7 +5088,12 @@ const create$1 = () => {
5109
5088
  matchCase: false,
5110
5089
  matchWholeWord: false,
5111
5090
  replacement: '',
5112
- editorUid: 0
5091
+ editorUid: 0,
5092
+ x: 0,
5093
+ y: 0,
5094
+ width: 0,
5095
+ height: 0,
5096
+ focused: false
5113
5097
  },
5114
5098
  newState: {
5115
5099
  value: '',
@@ -5123,7 +5107,12 @@ const create$1 = () => {
5123
5107
  matchCase: false,
5124
5108
  matchWholeWord: false,
5125
5109
  replacement: '',
5126
- editorUid: 0
5110
+ editorUid: 0,
5111
+ x: 0,
5112
+ y: 0,
5113
+ width: 0,
5114
+ height: 0,
5115
+ focused: true
5127
5116
  }
5128
5117
  };
5129
5118
  return widget;
@@ -5173,6 +5162,20 @@ const getMatchCount = matches => {
5173
5162
  return matches.length / 2;
5174
5163
  };
5175
5164
 
5165
+ const getPosition = editor => {
5166
+ const width = 300;
5167
+ const height = 30;
5168
+ const paddingTop = 10;
5169
+ const paddingRight = 20;
5170
+ const x = editor.x + editor.width - width - paddingRight;
5171
+ const y = editor.y + paddingTop;
5172
+ return {
5173
+ y,
5174
+ x,
5175
+ width,
5176
+ height
5177
+ };
5178
+ };
5176
5179
  const loadContent$1 = editorId => {
5177
5180
  const editor = getEditor(editorId);
5178
5181
  const {
@@ -5278,24 +5281,35 @@ const openFind2 = async editor => {
5278
5281
  matchCount,
5279
5282
  matchIndex
5280
5283
  } = await loadContent$1(editor.uid);
5284
+ const {
5285
+ x,
5286
+ y,
5287
+ width,
5288
+ height
5289
+ } = getPosition(editor);
5281
5290
  const latestState = {
5282
5291
  ...state,
5283
5292
  value,
5284
5293
  matches,
5285
5294
  matchCount,
5286
- matchIndex
5295
+ matchIndex,
5296
+ x,
5297
+ y,
5298
+ width,
5299
+ height
5287
5300
  };
5288
5301
  return latestState;
5289
5302
  };
5290
- return addWidgetToEditor(Find, FindWidget$1, editor, create$1, newStateGenerator);
5303
+ return addWidgetToEditor(Find, FindWidget, editor, create$1, newStateGenerator);
5304
+ };
5305
+
5306
+ const openFind = async state => {
5307
+ return openFind2(state);
5291
5308
  };
5292
5309
 
5293
5310
  const organizeImports = async editor => {
5294
5311
  // TODO ask extension host worker directly
5295
5312
  const edits = await invoke$3('ExtensionHostOrganizeImports.organizeImports', editor);
5296
- console.log({
5297
- edits
5298
- });
5299
5313
  return applyDocumentEdits(editor, edits);
5300
5314
  };
5301
5315
 
@@ -6786,9 +6800,6 @@ const typeWithAutoClosing = async (editor, text) => {
6786
6800
  case DoubleQuote:
6787
6801
  case SingleQuote:
6788
6802
  case BackTick:
6789
- console.log({
6790
- auto: editor
6791
- });
6792
6803
  if (isAutoClosingQuotesEnabled) {
6793
6804
  return typeWithAutoClosingQuote(editor, text);
6794
6805
  }
@@ -7539,7 +7550,7 @@ const renderHoverDom = {
7539
7550
  return [/* method */'Viewlet.setDom2', dom];
7540
7551
  }
7541
7552
  };
7542
- const renderBounds$3 = {
7553
+ const renderBounds$4 = {
7543
7554
  isEqual(oldState, newState) {
7544
7555
  return oldState.x === newState.x && oldState.y === newState.y && oldState.resizedWidth === newState.resizedWidth;
7545
7556
  },
@@ -7557,7 +7568,7 @@ const renderBounds$3 = {
7557
7568
  return [SetBounds, x, y, resizedWidth, height];
7558
7569
  }
7559
7570
  };
7560
- const render$9 = [renderHoverDom, renderBounds$3];
7571
+ const render$9 = [renderHoverDom, renderBounds$4];
7561
7572
  const renderHover = async (oldState, newState) => {
7562
7573
  const commands = [];
7563
7574
  for (const item of render$9) {
@@ -8171,7 +8182,6 @@ const getLineInfosViewport = (editor, tokens, embeddedResults, minLineY, maxLine
8171
8182
  };
8172
8183
  };
8173
8184
  const getVisible = async (editor, syncIncremental) => {
8174
- // console.log({ editor })
8175
8185
  // TODO should separate rendering from business logic somehow
8176
8186
  // currently hard to test because need to mock editor height, top, left,
8177
8187
  // invalidStartIndex, lineCache, etc. just for testing editorType
@@ -8421,7 +8431,7 @@ const renderScrollBarX = {
8421
8431
  return [/* method */'setScrollBarHorizontal', /* scrollBarX */scrollBarX, /* scrollBarWidth */scrollBarWidth, /* deltaX */newState.deltaX];
8422
8432
  }
8423
8433
  };
8424
- const renderFocus = {
8434
+ const renderFocus$1 = {
8425
8435
  isEqual(oldState, newState) {
8426
8436
  return oldState.focused === newState.focused;
8427
8437
  },
@@ -8519,7 +8529,7 @@ const renderWidgets = {
8519
8529
  },
8520
8530
  multiple: true
8521
8531
  };
8522
- const render$8 = [renderLines, renderSelections, renderScrollBarX, renderScrollBarY, renderFocus, renderDecorations, renderGutterInfo, renderWidgets];
8532
+ const render$8 = [renderLines, renderSelections, renderScrollBarX, renderScrollBarY, renderFocus$1, renderDecorations, renderGutterInfo, renderWidgets];
8523
8533
  const renderEditor = async id => {
8524
8534
  const instance = get$7(id);
8525
8535
  if (!instance) {
@@ -8551,16 +8561,7 @@ const keep = [
8551
8561
  // 'ColorPicker.loadContent',
8552
8562
  'Editor.create', 'Editor.getWordAt', 'Editor.getWordBefore', 'Editor.offsetAt', 'Editor.render',
8553
8563
  // 'ColorPicker.render',
8554
- 'Editor.getText', 'Editor.getSelections',
8555
- // 'EditorCompletion.advance',
8556
- // 'EditorCompletion.handleEditorBlur',
8557
- // 'EditorCompletion.handleEditorClick',
8558
- // 'EditorCompletion.handleEditorDeleteLeft',
8559
- // 'EditorCompletion.handleEditorType',
8560
- // 'EditorCompletion.loadContent',
8561
- // 'EditorCompletion.selectCurrent',
8562
- // 'EditorCompletion.selectIndex',
8563
- 'FindWidget.focusFirst', 'FindWidget.focusIndex', 'FindWidget.focusLast', 'FindWidget.focusNext', 'FindWidget.focusPrevious', 'FindWidget.handleInput', 'FindWidget.loadContent', 'Font.ensure', 'Hover.getHoverInfo', 'Hover.handleSashPointerDown', 'Hover.handleSashPointerMove', 'Hover.handleSashPointerUp', 'Hover.loadContent', 'Hover.render', 'Initialize.initialize'];
8564
+ 'Editor.getText', 'Editor.getSelections', 'Font.ensure', 'Hover.getHoverInfo', 'Hover.handleSashPointerDown', 'Hover.handleSashPointerMove', 'Hover.handleSashPointerUp', 'Hover.loadContent', 'Hover.render', 'Initialize.initialize'];
8564
8565
 
8565
8566
  const wrapWidgetCommand = (widgetId, fn) => {
8566
8567
  const isWidget = widget => {
@@ -8587,7 +8588,13 @@ const wrapWidgetCommand = (widgetId, fn) => {
8587
8588
 
8588
8589
  const widgetCommands = {
8589
8590
  'ColorPicker.handleSliderPointerDown': ColorPicker$1,
8590
- 'ColorPicker.handleSliderPointerMove': ColorPicker$1
8591
+ 'ColorPicker.handleSliderPointerMove': ColorPicker$1,
8592
+ 'FindWidget.focusNext': Find,
8593
+ 'FindWidget.focusPrevious': Find,
8594
+ 'FindWidget.close': Find,
8595
+ 'FindWidget.focusIndex': Find,
8596
+ 'FindWidget.focusFirst': Find,
8597
+ 'FindWidget.focusLast': Find
8591
8598
  };
8592
8599
 
8593
8600
  // TODO wrap commands globally, not per editor
@@ -8775,6 +8782,7 @@ const commandMap = {
8775
8782
  wrapCommands(commandMap);
8776
8783
 
8777
8784
  const CheckBox = 'checkbox';
8785
+ const Group = 'group';
8778
8786
  const None = 'none';
8779
8787
  const Option = 'option';
8780
8788
 
@@ -8975,7 +8983,7 @@ const renderItems = {
8975
8983
  return ['setDom', dom];
8976
8984
  }
8977
8985
  };
8978
- const renderBounds$2 = {
8986
+ const renderBounds$3 = {
8979
8987
  isEqual(oldState, newState) {
8980
8988
  return oldState.items === newState.items && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.x === newState.x && oldState.y === newState.y;
8981
8989
  },
@@ -9021,7 +9029,7 @@ const renderScrollBar = {
9021
9029
  return [/* method */SetScrollBar, /* scrollBarY */scrollBarY, /* scrollBarHeight */scrollBarHeight];
9022
9030
  }
9023
9031
  };
9024
- const render$7 = [renderItems, renderBounds$2, renderHeight, renderNegativeMargin, renderScrollBar];
9032
+ const render$7 = [renderItems, renderBounds$3, renderHeight, renderNegativeMargin, renderScrollBar];
9025
9033
  const renderCompletion = (oldState, newState) => {
9026
9034
  const commands = [];
9027
9035
  for (const item of render$7) {
@@ -9624,6 +9632,17 @@ const addWidget = (widget, id, render) => {
9624
9632
  allCommands.push(['Viewlet.createFunctionalRoot', id, uid]);
9625
9633
  allCommands.push(...commands);
9626
9634
  allCommands.push(['Viewlet.send', uid, 'appendWidget']);
9635
+ const focusCommandIndex = allCommands.findIndex(command => command[2] === 'focus');
9636
+ // TODO have separate rendering functions, e.g.
9637
+ // 1. renderDom
9638
+ // 2. renderAriaAnnouncement
9639
+ // 3. renderFocus
9640
+ // to ensure that focus is always after the element is added to the dom
9641
+ if (focusCommandIndex !== -1) {
9642
+ const command = allCommands[focusCommandIndex];
9643
+ allCommands.splice(focusCommandIndex, 1);
9644
+ allCommands.push(command);
9645
+ }
9627
9646
  return allCommands;
9628
9647
  };
9629
9648
 
@@ -9652,7 +9671,7 @@ const renderContent$1 = {
9652
9671
  return ['Viewlet.setDom2', newState.uid, dom];
9653
9672
  }
9654
9673
  };
9655
- const renderBounds$1 = {
9674
+ const renderBounds$2 = {
9656
9675
  isEqual(oldState, newState) {
9657
9676
  return oldState.x === newState.x && oldState.y === newState.y && oldState.width === newState.width && oldState.height === newState.height;
9658
9677
  },
@@ -9666,7 +9685,7 @@ const renderBounds$1 = {
9666
9685
  return [/* method */SetBounds, /* x */x, /* y */y, /* width */width, /* height */height];
9667
9686
  }
9668
9687
  };
9669
- const render$5 = [renderContent$1, renderBounds$1, renderColor, renderOffsetX];
9688
+ const render$5 = [renderContent$1, renderBounds$2, renderColor, renderOffsetX];
9670
9689
  const renderFull$1 = (oldState, newState) => {
9671
9690
  const commands = [];
9672
9691
  for (const item of render$5) {
@@ -9733,7 +9752,7 @@ const renderContent = {
9733
9752
  return ['Viewlet.setDom2', newState.uid, dom];
9734
9753
  }
9735
9754
  };
9736
- const renderBounds = {
9755
+ const renderBounds$1 = {
9737
9756
  isEqual(oldState, newState) {
9738
9757
  return oldState.x === newState.x && oldState.y === newState.y && oldState.width === newState.width && oldState.height === newState.height;
9739
9758
  },
@@ -9747,7 +9766,7 @@ const renderBounds = {
9747
9766
  return [/* method */SetBounds, /* x */x, /* y */y, /* width */width, /* height */height];
9748
9767
  }
9749
9768
  };
9750
- const render$3 = [renderContent, renderBounds];
9769
+ const render$3 = [renderContent, renderBounds$1];
9751
9770
  const renderFull = (oldState, newState) => {
9752
9771
  return renderParts(render$3, oldState, newState);
9753
9772
  };
@@ -9903,7 +9922,7 @@ const getIconButtonVirtualDom = iconButton => {
9903
9922
  type: Button,
9904
9923
  className,
9905
9924
  title: label,
9906
- ariaLaBel: label,
9925
+ ariaLabel: label,
9907
9926
  childCount: 1,
9908
9927
  disabled: disabled ? true : undefined
9909
9928
  }, getIconVirtualDom(icon)];
@@ -9912,8 +9931,9 @@ const getFindWidgetVirtualDom = (matchCountText, replaceExpanded, buttons, match
9912
9931
  const dom = [];
9913
9932
  dom.push({
9914
9933
  type: Div,
9915
- className: 'Viewlet ViewletFind',
9916
- childCount: 2
9934
+ className: 'Viewlet ViewletFind ViewletFindWidget FindWidget',
9935
+ childCount: 2,
9936
+ role: Group
9917
9937
  });
9918
9938
  dom.push(...getSearchToggleButtonVirtualDom(replaceExpanded, 'handleClick'));
9919
9939
  dom.push({
@@ -9985,7 +10005,28 @@ const renderDetails = {
9985
10005
  return ['Viewlet.setDom2', dom];
9986
10006
  }
9987
10007
  };
9988
-
10008
+ const renderBounds = {
10009
+ isEqual(oldState, newState) {
10010
+ return oldState.x === newState.x && oldState.y === newState.y && oldState.width === newState.width && oldState.height === newState.height;
10011
+ },
10012
+ apply(oldState, newState) {
10013
+ const {
10014
+ x,
10015
+ y,
10016
+ width,
10017
+ height
10018
+ } = newState;
10019
+ return [/* method */SetBounds, /* x */x, /* y */y, /* width */width, /* height */height];
10020
+ }
10021
+ };
10022
+ const renderFocus = {
10023
+ isEqual(oldState, newState) {
10024
+ return oldState.focused === newState.focused;
10025
+ },
10026
+ apply(oldState, newState) {
10027
+ return ['focus', newState.focused];
10028
+ }
10029
+ };
9989
10030
  // const getAriaLabel = (state: FindWidgetState) => {
9990
10031
  // const { matchIndex, matchCount, value } = state
9991
10032
  // return FindStrings.matchesFoundFor(matchIndex, matchCount, value)
@@ -10006,9 +10047,7 @@ const renderDetails = {
10006
10047
  // },
10007
10048
  // }
10008
10049
 
10009
- const render$1 = [
10010
- // renderAriaAnnouncement,
10011
- renderDetails, renderValue];
10050
+ const render$1 = [renderDetails, renderBounds, renderValue, renderFocus];
10012
10051
  const apply = (oldState, newState) => {
10013
10052
  return renderParts(render$1, oldState, newState);
10014
10053
  };
@@ -10019,7 +10058,7 @@ const render = widget => {
10019
10058
  const uid = widget.newState.uid;
10020
10059
  for (const command of commands) {
10021
10060
  if (command[0] === 'Viewlet.setDom2') {
10022
- wrappedCommands.push(command);
10061
+ wrappedCommands.push([command[0], uid, ...command.slice(1)]);
10023
10062
  } else {
10024
10063
  wrappedCommands.push(['Viewlet.send', uid, ...command]);
10025
10064
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "3.6.0",
3
+ "version": "3.7.0",
4
4
  "description": "",
5
5
  "main": "dist/testWorkerMain.js",
6
6
  "type": "module",