@lvce-editor/editor-worker 4.3.0 → 4.5.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.
@@ -1739,6 +1739,22 @@ const HoverExecute = 'ExtensionHostHover.execute';
1739
1739
  const TabCompletionExecuteTabCompletionProvider = 'ExtensionHost.executeTabCompletionProvider';
1740
1740
  const TextDocumentSyncFull = 'ExtensionHostTextDocument.syncFull';
1741
1741
 
1742
+ const ColorPicker$2 = 41;
1743
+ const CompletionDetail$1 = 999;
1744
+ const EditorCompletion = 9;
1745
+ const Empty = 0;
1746
+ const FindWidget = 16;
1747
+ const FocusEditorHover = 51;
1748
+ const FocusEditorRename = 11;
1749
+ const FocusFindWidgetCloseButton = 48;
1750
+ const FocusFindWidgetNextMatchButton = 49;
1751
+ const FocusFindWidgetPreviousMatchButton = 50;
1752
+ const FocusFindWidgetReplace = 43;
1753
+ const FocusFindWidgetReplaceAllButton = 47;
1754
+ const FocusFindWidgetReplaceButton = 46;
1755
+ const FocusFindWidgetToggleReplace = 42;
1756
+ const SourceActions = 38;
1757
+
1742
1758
  const measureCharacterWidth = (fontWeight, fontSize, fontFamily, letterSpacing) => {
1743
1759
  return measureTextWidth('a', fontWeight, fontSize, fontFamily, letterSpacing, false, 0);
1744
1760
  };
@@ -1852,7 +1868,8 @@ const createEditor = async ({
1852
1868
  charWidth,
1853
1869
  uid: id,
1854
1870
  id,
1855
- widgets: []
1871
+ widgets: [],
1872
+ focusKey: Empty
1856
1873
  };
1857
1874
  // TODO avoid creating intermediate editors here
1858
1875
  const newEditor1 = setBounds(editor, x, y, width, height, 9);
@@ -1929,15 +1946,14 @@ const applyEdit = async (editor, changes) => {
1929
1946
  return scheduleDocumentAndCursorsSelections(editor, changes);
1930
1947
  };
1931
1948
 
1932
- const handleBlur$1 = editor => {
1933
- // for (const listener of state.blurListeners) {
1934
- // listener(editor)
1935
- // }
1936
- // TODO save on blur
1937
- // Command.execute(/* Main.save */ 89)
1949
+ const handleBlur$2 = editor => {
1950
+ if (editor.focusKey !== Empty) {
1951
+ return editor;
1952
+ }
1938
1953
  const newEditor = {
1939
1954
  ...editor,
1940
- focused: false
1955
+ focused: false,
1956
+ focusKey: Empty
1941
1957
  };
1942
1958
  return newEditor;
1943
1959
  };
@@ -2258,9 +2274,9 @@ const cancelSelection = editor => {
2258
2274
  };
2259
2275
 
2260
2276
  // TODO use numeric widget id
2261
- const ColorPicker$2 = 'colorPicker';
2277
+ const ColorPicker$1 = 'colorPicker';
2262
2278
  const Completion = 'completion';
2263
- const CompletionDetail$1 = 'completionDetail';
2279
+ const CompletionDetail = 'completionDetail';
2264
2280
  const Find = 'find';
2265
2281
  const Hover = 'hover';
2266
2282
  const Rename = 'rename';
@@ -2317,6 +2333,7 @@ const closeRename = editor => {
2317
2333
  const newWidgets = [...widgets.slice(0, renameWidgetIndex), ...widgets.slice(renameWidgetIndex + 1)];
2318
2334
  return {
2319
2335
  ...editor,
2336
+ focused: true,
2320
2337
  widgets: newWidgets
2321
2338
  };
2322
2339
  };
@@ -2383,9 +2400,12 @@ const addWidgetToEditor = async (widgetId, focusKey, editor, factory, newStateGe
2383
2400
  } else {
2384
2401
  await setAdditionalFocus(focusKey);
2385
2402
  }
2403
+ const newFocus = fullFocus ? false : true;
2386
2404
  const newEditor = {
2387
2405
  ...editor,
2388
- widgets: newWidgets
2406
+ widgets: newWidgets,
2407
+ focusKey,
2408
+ focused: newFocus
2389
2409
  };
2390
2410
  return newEditor;
2391
2411
  };
@@ -2397,7 +2417,7 @@ const create$7 = () => {
2397
2417
  const create$6 = () => {
2398
2418
  const completionUid = create$7();
2399
2419
  const widget = {
2400
- id: ColorPicker$2,
2420
+ id: ColorPicker$1,
2401
2421
  oldState: {
2402
2422
  color: '',
2403
2423
  offsetX: 0,
@@ -2424,26 +2444,11 @@ const create$6 = () => {
2424
2444
  return widget;
2425
2445
  };
2426
2446
 
2427
- const ColorPicker$1 = 41;
2428
- const CompletionDetail = 999;
2429
- const EditorCompletion = 9;
2430
- const Empty = 0;
2431
- const FindWidget = 16;
2432
- const FocusEditorHover = 51;
2433
- const FocusFindWidgetCloseButton = 48;
2434
- const FocusFindWidgetNextMatchButton = 49;
2435
- const FocusFindWidgetPreviousMatchButton = 50;
2436
- const FocusFindWidgetReplace = 43;
2437
- const FocusFindWidgetReplaceAllButton = 47;
2438
- const FocusFindWidgetReplaceButton = 46;
2439
- const FocusFindWidgetToggleReplace = 42;
2440
- const SourceActions = 38;
2441
-
2442
2447
  const newStateGenerator$1 = state => {
2443
2448
  return loadContent$3(state);
2444
2449
  };
2445
2450
  const openColorPicker = async editor => {
2446
- return addWidgetToEditor(ColorPicker$2, ColorPicker$1, editor, create$6, newStateGenerator$1);
2451
+ return addWidgetToEditor(ColorPicker$1, ColorPicker$2, editor, create$6, newStateGenerator$1);
2447
2452
  };
2448
2453
 
2449
2454
  const state$6 = {
@@ -4037,15 +4042,12 @@ const handleScrollBarMove = (state, eventY) => {
4037
4042
  };
4038
4043
  const handleScrollBarVerticalPointerMove = handleScrollBarMove;
4039
4044
 
4040
- // @ts-ignore
4041
-
4042
4045
  // TODO scrollbar position can be in interval [0, editor.height - editor.scrollBarHeight]
4043
4046
  // when clicked at y <= editor.scrollbarHeight/2, position is set to zero
4044
4047
  // when clicked at y >= editor.height - editor.scrollBarHeight/2, position is set to (editor.height - scrollBarHeight/2)
4045
4048
  // when clicked at y > editor.height - editor.scrollBarHeight/2, position scrollbar at (y - scrollbarHeight/2)
4046
4049
  // additionally, when clicked on scrollbar, scrollbar position shouldn't move
4047
4050
 
4048
- // @ts-ignore
4049
4051
  const handleScrollBarPointerDown = (state, eventY) => {
4050
4052
  const {
4051
4053
  y,
@@ -5183,7 +5185,7 @@ const isFind = widget => {
5183
5185
  };
5184
5186
  // TODO don't call renderer worker, set editor state
5185
5187
  // TODO this function should be synchronous
5186
- const focusIndex$1 = (editor, index) => {
5188
+ const focusIndex$2 = (editor, index) => {
5187
5189
  const findState = getFindState(editor);
5188
5190
  if (!findState) {
5189
5191
  return editor;
@@ -5226,7 +5228,7 @@ const focusFirst$1 = editor => {
5226
5228
  if (!findState) {
5227
5229
  return editor;
5228
5230
  }
5229
- return focusIndex$1(editor, 0);
5231
+ return focusIndex$2(editor, 0);
5230
5232
  };
5231
5233
  const focusLast = editor => {
5232
5234
  const findState = getFindState(editor);
@@ -5236,9 +5238,9 @@ const focusLast = editor => {
5236
5238
  const {
5237
5239
  matchCount
5238
5240
  } = findState;
5239
- return focusIndex$1(editor, matchCount - 1);
5241
+ return focusIndex$2(editor, matchCount - 1);
5240
5242
  };
5241
- const focusNext$1 = editor => {
5243
+ const focusNext$2 = editor => {
5242
5244
  const findState = getFindState(editor);
5243
5245
  if (!findState) {
5244
5246
  return editor;
@@ -5250,7 +5252,7 @@ const focusNext$1 = editor => {
5250
5252
  if (matchIndex === matchCount - 1) {
5251
5253
  return focusFirst$1(editor);
5252
5254
  }
5253
- return focusIndex$1(editor, matchIndex + 1);
5255
+ return focusIndex$2(editor, matchIndex + 1);
5254
5256
  };
5255
5257
  const focusPrevious$1 = editor => {
5256
5258
  const findState = getFindState(editor);
@@ -5263,7 +5265,7 @@ const focusPrevious$1 = editor => {
5263
5265
  if (matchIndex === 0) {
5264
5266
  return focusLast(editor);
5265
5267
  }
5266
- return focusIndex$1(editor, matchIndex - 1);
5268
+ return focusIndex$2(editor, matchIndex - 1);
5267
5269
  };
5268
5270
 
5269
5271
  const focusNextMatchButton = state => {
@@ -5290,7 +5292,7 @@ const focusToggleReplaceButton = state => {
5290
5292
  return setFindWidgetFocus(state, FocusFindWidgetToggleReplace);
5291
5293
  };
5292
5294
 
5293
- const handleBlur = async state => {
5295
+ const handleBlur$1 = async state => {
5294
5296
  await setFocus(Empty);
5295
5297
  return state;
5296
5298
  };
@@ -5535,7 +5537,7 @@ const openRename = async editor => {
5535
5537
  return latestState;
5536
5538
  };
5537
5539
  const fullFocus = true;
5538
- return addWidgetToEditor(Rename, undefined, editor, create$3, newStateGenerator, fullFocus);
5540
+ return addWidgetToEditor(Rename, FocusEditorRename, editor, create$3, newStateGenerator, fullFocus);
5539
5541
  };
5540
5542
 
5541
5543
  const organizeImports = async editor => {
@@ -7563,7 +7565,7 @@ const editorUnindent = editor => {
7563
7565
  // editor.lines //?
7564
7566
 
7565
7567
  const isCompletionDetailWidget = widget => {
7566
- return widget.id === CompletionDetail$1;
7568
+ return widget.id === CompletionDetail;
7567
7569
  };
7568
7570
  const closeDetails = editor => {
7569
7571
  const {
@@ -7580,7 +7582,7 @@ const closeDetails = editor => {
7580
7582
  };
7581
7583
  };
7582
7584
 
7583
- const focusIndex = (state, index) => {
7585
+ const focusIndex$1 = (state, index) => {
7584
7586
  const newState = {
7585
7587
  ...state,
7586
7588
  focusedIndex: index,
@@ -7591,17 +7593,17 @@ const focusIndex = (state, index) => {
7591
7593
 
7592
7594
  const focusFirst = state => {
7593
7595
  const firstIndex = 0;
7594
- return focusIndex(state, firstIndex);
7596
+ return focusIndex$1(state, firstIndex);
7595
7597
  };
7596
7598
 
7597
- const focusNext = state => {
7599
+ const focusNext$1 = state => {
7598
7600
  const nextIndex = state.focusedIndex + 1;
7599
- return focusIndex(state, nextIndex);
7601
+ return focusIndex$1(state, nextIndex);
7600
7602
  };
7601
7603
 
7602
7604
  const focusPrevious = state => {
7603
7605
  const previousIndex = state.focusedIndex - 1;
7604
- return focusIndex(state, previousIndex);
7606
+ return focusIndex$1(state, previousIndex);
7605
7607
  };
7606
7608
 
7607
7609
  // TODO optimize this function to return the minimum number
@@ -7651,7 +7653,7 @@ const handelWheel = (state, deltaMode, deltaY) => {
7651
7653
  const create = () => {
7652
7654
  const completionUid = create$7();
7653
7655
  const completionWidget = {
7654
- id: CompletionDetail$1,
7656
+ id: CompletionDetail,
7655
7657
  oldState: {
7656
7658
  content: '',
7657
7659
  uid: completionUid,
@@ -7702,7 +7704,7 @@ const openDetails = editor => {
7702
7704
  };
7703
7705
  return newestState;
7704
7706
  };
7705
- return addWidgetToEditor(CompletionDetail$1, CompletionDetail, editor, create, newStateGenerator);
7707
+ return addWidgetToEditor(CompletionDetail, CompletionDetail$1, editor, create, newStateGenerator);
7706
7708
  };
7707
7709
 
7708
7710
  const getEdits = async (editor, completionItem) => {
@@ -7783,7 +7785,7 @@ const selectCurrent = editor => {
7783
7785
  };
7784
7786
 
7785
7787
  const getCompletionDetailState = editor => {
7786
- return getWidgetState(editor, CompletionDetail$1);
7788
+ return getWidgetState(editor, CompletionDetail);
7787
7789
  };
7788
7790
 
7789
7791
  const toggleDetails = editor => {
@@ -8019,6 +8021,23 @@ const renderHover = (oldState, newState) => {
8019
8021
  return commands;
8020
8022
  };
8021
8023
 
8024
+ const handleBlur = editor => {
8025
+ return closeRename(editor);
8026
+ };
8027
+
8028
+ const focusIndex = (state, index) => {
8029
+ const newState = {
8030
+ ...state,
8031
+ focusedIndex: index
8032
+ };
8033
+ return newState;
8034
+ };
8035
+
8036
+ const focusNext = state => {
8037
+ const nextIndex = state.focusedIndex + 1;
8038
+ return focusIndex(state, nextIndex);
8039
+ };
8040
+
8022
8041
  const replaceTextOccurrences = (editor, matches, oldValue, newValue) => {
8023
8042
  const ranges = [];
8024
8043
  const oldValueLength = oldValue.length;
@@ -9074,8 +9093,8 @@ const wrapWidgetCommand = (widgetId, fn) => {
9074
9093
  };
9075
9094
 
9076
9095
  const widgetCommands = {
9077
- 'ColorPicker.handleSliderPointerDown': ColorPicker$2,
9078
- 'ColorPicker.handleSliderPointerMove': ColorPicker$2,
9096
+ 'ColorPicker.handleSliderPointerDown': ColorPicker$1,
9097
+ 'ColorPicker.handleSliderPointerMove': ColorPicker$1,
9079
9098
  // 'FindWidget.focusNext': WidgetId.Find,
9080
9099
  // 'FindWidget.focusPrevious': WidgetId.Find,
9081
9100
  'FindWidget.close': Find,
@@ -9184,7 +9203,7 @@ const commandMap = {
9184
9203
  'Editor.goToTypeDefinition': goToTypeDefinition,
9185
9204
  'Editor.handleBeforeInput': handleBeforeInput,
9186
9205
  'Editor.handleBeforeInputFromContentEditable': handleBeforeInputFromContentEditable,
9187
- 'Editor.handleBlur': handleBlur$1,
9206
+ 'Editor.handleBlur': handleBlur$2,
9188
9207
  'Editor.handleContextMenu': handleContextMenu,
9189
9208
  'Editor.handleDoubleClick': handleDoubleClick,
9190
9209
  'Editor.handleFocus': handleFocus,
@@ -9265,8 +9284,8 @@ const commandMap = {
9265
9284
  'EditorCompletion.advance': advance,
9266
9285
  'EditorCompletion.closeDetails': closeDetails,
9267
9286
  'EditorCompletion.focusFirst': focusFirst,
9268
- 'EditorCompletion.focusIndex': focusIndex,
9269
- 'EditorCompletion.focusNext': focusNext,
9287
+ 'EditorCompletion.focusIndex': focusIndex$1,
9288
+ 'EditorCompletion.focusNext': focusNext$1,
9270
9289
  'EditorCompletion.focusPrevious': focusPrevious,
9271
9290
  'EditorCompletion.handleEditorBlur': handleEditorBlur,
9272
9291
  'EditorCompletion.handleEditorClick': handleEditorClick,
@@ -9278,13 +9297,15 @@ const commandMap = {
9278
9297
  'EditorCompletion.selectCurrent': selectCurrent,
9279
9298
  'EditorCompletion.selectIndex': selectIndex,
9280
9299
  'EditorCompletion.toggleDetails': toggleDetails,
9300
+ 'EditorRename.handleBlur': handleBlur,
9301
+ 'EditorSourceActions.focusNext': focusNext,
9281
9302
  'FindWidget.close': close$1,
9282
9303
  'FindWidget.focusCloseButton': focusCloseButton,
9283
9304
  'FindWidget.focusFind': focusFind,
9284
9305
  'FindWidget.focusFirst': focusFirst$1,
9285
- 'FindWidget.focusIndex': focusIndex$1,
9306
+ 'FindWidget.focusIndex': focusIndex$2,
9286
9307
  'FindWidget.focusLast': focusLast,
9287
- 'FindWidget.focusNext': focusNext$1,
9308
+ 'FindWidget.focusNext': focusNext$2,
9288
9309
  'FindWidget.focusNextMatchButton': focusNextMatchButton,
9289
9310
  'FindWidget.focusPrevious': focusPrevious$1,
9290
9311
  'FindWidget.focusPreviousMatchButton': focusPreviousMatchButton,
@@ -9292,7 +9313,7 @@ const commandMap = {
9292
9313
  'FindWidget.focusReplaceAllButton': focusReplaceAllButton,
9293
9314
  'FindWidget.focusReplaceButton': focusReplaceButton,
9294
9315
  'FindWidget.focusToggleReplace': focusToggleReplaceButton,
9295
- 'FindWidget.handleBlur': handleBlur,
9316
+ 'FindWidget.handleBlur': handleBlur$1,
9296
9317
  'FindWidget.handleFocus': handleFindWidgetFocus,
9297
9318
  'FindWidget.handleInput': handleInput,
9298
9319
  'FindWidget.handleReplaceAllFocus': handleReplaceAllFocus,
@@ -10780,13 +10801,13 @@ const add$3 = widget => {
10780
10801
  const remove$3 = removeWidget;
10781
10802
  const Commands = {
10782
10803
  'FindWidget.close': close$1,
10783
- 'FindWidget.focusNext': focusNext$1,
10804
+ 'FindWidget.focusNext': focusNext$2,
10784
10805
  'FindWidget.focusPrevious': focusPrevious$1,
10785
- 'FindWidget.focusIndex': focusIndex$1,
10806
+ 'FindWidget.focusIndex': focusIndex$2,
10786
10807
  'FindWidget.focusLast': focusLast,
10787
10808
  'FindWidget.toggleReplace': toggleReplace,
10788
10809
  'FindWidget.handleFocus': focusFind,
10789
- 'FindWidget.handleBlur': handleBlur
10810
+ 'FindWidget.handleBlur': handleBlur$1
10790
10811
  };
10791
10812
 
10792
10813
  const EditorFindWidget = {
@@ -10831,7 +10852,8 @@ const getRenameVirtualDom = state => {
10831
10852
  type: Input,
10832
10853
  className: 'InputBox RenameInputBox',
10833
10854
  value: state.newValue,
10834
- childCount: 0
10855
+ childCount: 0,
10856
+ onBlur: 'handleBlur'
10835
10857
  }];
10836
10858
  };
10837
10859
 
@@ -11008,9 +11030,9 @@ const EditorSourceActionWidget = {
11008
11030
  };
11009
11031
 
11010
11032
  const registerWidgets = () => {
11011
- set$7(ColorPicker$2, EditorColorPickerWidget);
11033
+ set$7(ColorPicker$1, EditorColorPickerWidget);
11012
11034
  set$7(Completion, EditorCompletionWidget);
11013
- set$7(CompletionDetail$1, EditorCompletionDetailWidget);
11035
+ set$7(CompletionDetail, EditorCompletionDetailWidget);
11014
11036
  set$7(Find, EditorFindWidget);
11015
11037
  set$7(Hover, EditorHoverWidget);
11016
11038
  set$7(Rename, EditorRenameWidget);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "4.3.0",
3
+ "version": "4.5.0",
4
4
  "description": "",
5
5
  "main": "dist/editorWorkerMain.js",
6
6
  "type": "module",