@lvce-editor/editor-worker 3.14.0 → 3.16.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.
@@ -2431,6 +2431,9 @@ const setAdditionalFocus = async focusKey => {
2431
2431
  };
2432
2432
 
2433
2433
  const setFocus = async focusKey => {
2434
+ if (!focusKey) {
2435
+ return;
2436
+ }
2434
2437
  await invoke$3('Focus.setFocus', focusKey);
2435
2438
  };
2436
2439
 
@@ -3627,7 +3630,7 @@ const handleDoubleClick = (editor, modifier, x, y) => {
3627
3630
  };
3628
3631
 
3629
3632
  const WhenExpressionEditorText = 12;
3630
- const handleFocus$1 = editor => {
3633
+ const handleFocus = editor => {
3631
3634
  // TODO make change events functional,
3632
3635
  // when rendering, send focus changes to renderer worker
3633
3636
  invoke$3('Focus.setFocus', WhenExpressionEditorText);
@@ -3644,7 +3647,7 @@ const state$5 = {
3644
3647
  columnIndex: 0
3645
3648
  }
3646
3649
  };
3647
- const getPosition$2 = () => {
3650
+ const getPosition$1 = () => {
3648
3651
  return state$5.position;
3649
3652
  };
3650
3653
 
@@ -3964,7 +3967,7 @@ const setPosition = position => {
3964
3967
  const getEditor$1 = () => {
3965
3968
  return state$3.currentEditor;
3966
3969
  };
3967
- const getPosition$1 = () => {
3970
+ const getPosition = () => {
3968
3971
  return state$3.position;
3969
3972
  };
3970
3973
  const hasListener = () => {
@@ -4209,7 +4212,7 @@ const getNewSelections$5 = (anchor, position) => {
4209
4212
 
4210
4213
  // @ts-ignore
4211
4214
  const editorMoveSelection = (editor, position) => {
4212
- const anchor = getPosition$2();
4215
+ const anchor = getPosition$1();
4213
4216
  const newSelections = getNewSelections$5(anchor, position);
4214
4217
  // TODO if selection equals previous selection -> do nothing
4215
4218
  return scheduleSelections(editor, newSelections);
@@ -4496,7 +4499,7 @@ const getNewEditor$1 = (editor, position) => {
4496
4499
  const newMinLineY = position.rowIndex;
4497
4500
  const newMaxLineY = position.rowIndex + diff;
4498
4501
  const newDeltaY = position.rowIndex * rowHeight;
4499
- const anchor = getPosition$2();
4502
+ const anchor = getPosition$1();
4500
4503
  const newSelections = new Uint32Array([position.rowIndex - 1, position.columnIndex, anchor.rowIndex, anchor.columnIndex]);
4501
4504
  return {
4502
4505
  ...editor,
@@ -4511,7 +4514,7 @@ const getNewEditor$1 = (editor, position) => {
4511
4514
  const newMinLineY = position.rowIndex - diff;
4512
4515
  const newMaxLineY = position.rowIndex;
4513
4516
  const newDeltaY = newMinLineY * rowHeight;
4514
- const anchor = getPosition$2();
4517
+ const anchor = getPosition$1();
4515
4518
  const newSelections = new Uint32Array([anchor.rowIndex, anchor.columnIndex, position.rowIndex + 1, position.columnIndex]);
4516
4519
  return {
4517
4520
  ...editor,
@@ -4528,7 +4531,7 @@ const continueScrollingAndMovingSelection = async () => {
4528
4531
  if (!editor) {
4529
4532
  return;
4530
4533
  }
4531
- const position = getPosition$1();
4534
+ const position = getPosition();
4532
4535
  if (position.rowIndex === 0) {
4533
4536
  return;
4534
4537
  }
@@ -5169,22 +5172,14 @@ const findMatchesCaseInsensitive = (lines, searchString) => {
5169
5172
  return findRegexMatches(lines, regex);
5170
5173
  };
5171
5174
 
5172
- const getFindWidgetHeight = replaceExpanded => {
5173
- const collapsedHeight = 30;
5174
- const expandedHeight = 60;
5175
- const newHeight = replaceExpanded ? expandedHeight : collapsedHeight;
5176
- return newHeight;
5177
- };
5178
-
5179
5175
  const getMatchCount = matches => {
5180
5176
  return matches.length / 2;
5181
5177
  };
5182
5178
 
5183
- const setFindWidgetFocus = async (state, focusKey) => {
5179
+ const setFindWidgetFocus = (state, focusKey) => {
5184
5180
  if (state.focus === focusKey) {
5185
5181
  return state;
5186
5182
  }
5187
- await setFocus(focusKey);
5188
5183
  return {
5189
5184
  ...state,
5190
5185
  focus: focusKey,
@@ -5192,20 +5187,183 @@ const setFindWidgetFocus = async (state, focusKey) => {
5192
5187
  };
5193
5188
  };
5194
5189
 
5195
- const getPosition = editor => {
5196
- const width = 300;
5197
- const height = 30;
5198
- const paddingTop = 10;
5199
- const paddingRight = 20;
5200
- const x = editor.x + editor.width - width - paddingRight;
5201
- const y = editor.y + paddingTop;
5190
+ const focusCloseButton = state => {
5191
+ return setFindWidgetFocus(state, FocusFindWidgetCloseButton);
5192
+ };
5193
+
5194
+ const focusFind = state => {
5195
+ return setFindWidgetFocus(state, FindWidget);
5196
+ };
5197
+
5198
+ const getWidgetState = (editor, id) => {
5199
+ const {
5200
+ widgets
5201
+ } = editor;
5202
+ for (const widget of widgets) {
5203
+ if (widget.id === id) {
5204
+ return widget.newState;
5205
+ }
5206
+ }
5207
+ return undefined;
5208
+ };
5209
+
5210
+ const getFindState = editor => {
5211
+ return getWidgetState(editor, Find);
5212
+ };
5213
+
5214
+ const isFind = widget => {
5215
+ return widget.id === Find;
5216
+ };
5217
+ // TODO don't call renderer worker, set editor state
5218
+ // TODO this function should be synchronous
5219
+ const focusIndex$1 = (editor, index) => {
5220
+ const findState = getFindState(editor);
5221
+ if (!findState) {
5222
+ return editor;
5223
+ }
5224
+ const {
5225
+ value,
5226
+ matches,
5227
+ matchIndex
5228
+ } = findState;
5229
+ if (index === matchIndex) {
5230
+ return editor;
5231
+ }
5232
+ const {
5233
+ widgets
5234
+ } = editor;
5235
+ const childIndex = widgets.findIndex(isFind);
5236
+ const childWidget = widgets[childIndex];
5237
+
5238
+ // TODO find next match and highlight it
5239
+ const matchRowIndex = matches[index * 2];
5240
+ const matchColumnIndex = matches[index * 2 + 1];
5241
+ const newSelections = new Uint32Array([matchRowIndex, matchColumnIndex, matchRowIndex, matchColumnIndex + value.length]);
5242
+ const newState = {
5243
+ ...findState,
5244
+ matchIndex: index
5245
+ };
5246
+ const newWidget = {
5247
+ ...childWidget,
5248
+ newState
5249
+ };
5250
+ const newWidgets = [...widgets.slice(0, childIndex), newWidget, ...widgets.slice(childIndex + 1)];
5202
5251
  return {
5203
- y,
5204
- x,
5205
- width,
5206
- height
5252
+ ...editor,
5253
+ selections: newSelections,
5254
+ widgets: newWidgets
5207
5255
  };
5208
5256
  };
5257
+ const focusFirst$1 = editor => {
5258
+ const findState = getFindState(editor);
5259
+ if (!findState) {
5260
+ return editor;
5261
+ }
5262
+ return focusIndex$1(editor, 0);
5263
+ };
5264
+ const focusLast = editor => {
5265
+ const findState = getFindState(editor);
5266
+ if (!findState) {
5267
+ return editor;
5268
+ }
5269
+ const {
5270
+ matchCount
5271
+ } = findState;
5272
+ return focusIndex$1(editor, matchCount - 1);
5273
+ };
5274
+ const focusNext$1 = editor => {
5275
+ const findState = getFindState(editor);
5276
+ if (!findState) {
5277
+ return editor;
5278
+ }
5279
+ const {
5280
+ matchIndex,
5281
+ matchCount
5282
+ } = findState;
5283
+ if (matchIndex === matchCount - 1) {
5284
+ return focusFirst$1(editor);
5285
+ }
5286
+ return focusIndex$1(editor, matchIndex + 1);
5287
+ };
5288
+ const focusPrevious$1 = editor => {
5289
+ const findState = getFindState(editor);
5290
+ if (!findState) {
5291
+ return editor;
5292
+ }
5293
+ const {
5294
+ matchIndex
5295
+ } = findState;
5296
+ if (matchIndex === 0) {
5297
+ return focusLast(editor);
5298
+ }
5299
+ return focusIndex$1(editor, matchIndex - 1);
5300
+ };
5301
+
5302
+ const focusNextMatchButton = state => {
5303
+ return setFindWidgetFocus(state, FocusFindWidgetNextMatchButton);
5304
+ };
5305
+
5306
+ const focusPreviousMatchButton = state => {
5307
+ return setFindWidgetFocus(state, FocusFindWidgetPreviousMatchButton);
5308
+ };
5309
+
5310
+ const focusReplace = state => {
5311
+ return setFindWidgetFocus(state, FocusFindWidgetReplace);
5312
+ };
5313
+
5314
+ const focusReplaceAllButton = state => {
5315
+ return setFindWidgetFocus(state, FocusFindWidgetReplaceAllButton);
5316
+ };
5317
+
5318
+ const focusReplaceButton = state => {
5319
+ return setFindWidgetFocus(state, FocusFindWidgetReplaceButton);
5320
+ };
5321
+
5322
+ const focusToggleReplaceButton = state => {
5323
+ return setFindWidgetFocus(state, FocusFindWidgetToggleReplace);
5324
+ };
5325
+
5326
+ const handleBlur = async state => {
5327
+ await setFocus(Empty);
5328
+ return state;
5329
+ };
5330
+
5331
+ const handleFindWidgetFocus = (state, focusKey) => {
5332
+ if (state.focus === focusKey) {
5333
+ return state;
5334
+ }
5335
+ return {
5336
+ ...state,
5337
+ focus: focusKey,
5338
+ focusSource: User
5339
+ };
5340
+ };
5341
+
5342
+ const handleReplaceAllFocus = state => {
5343
+ return handleFindWidgetFocus(state, FocusFindWidgetReplaceAllButton);
5344
+ };
5345
+
5346
+ const handleReplaceFocus = state => {
5347
+ return handleFindWidgetFocus(state, FocusFindWidgetReplace);
5348
+ };
5349
+
5350
+ const getFindWidgetHeight = replaceExpanded => {
5351
+ const collapsedHeight = 30;
5352
+ const expandedHeight = 60;
5353
+ const newHeight = replaceExpanded ? expandedHeight : collapsedHeight;
5354
+ return newHeight;
5355
+ };
5356
+
5357
+ const toggleReplace = state => {
5358
+ const newExpanded = !state.replaceExpanded;
5359
+ const newHeight = getFindWidgetHeight(newExpanded);
5360
+ return {
5361
+ ...state,
5362
+ replaceExpanded: !state.replaceExpanded,
5363
+ height: newHeight
5364
+ };
5365
+ };
5366
+
5209
5367
  const loadContent$1 = editorId => {
5210
5368
  const editor = getEditor(editorId);
5211
5369
  const {
@@ -5250,82 +5408,6 @@ const refresh = (state, value = state.value) => {
5250
5408
  const handleInput = (state, value) => {
5251
5409
  return refresh(state, value);
5252
5410
  };
5253
- const handleFocus = async state => {
5254
- if (state.focus === FindWidget) {
5255
- return state;
5256
- }
5257
- await setFocus(FindWidget);
5258
- return {
5259
- ...state,
5260
- focus: FindWidget
5261
- };
5262
- };
5263
- const handleBlur = async state => {
5264
- await setFocus(Empty);
5265
- return state;
5266
- };
5267
- const toggleReplace = state => {
5268
- const newExpanded = !state.replaceExpanded;
5269
- const newHeight = getFindWidgetHeight(newExpanded);
5270
- return {
5271
- ...state,
5272
- replaceExpanded: !state.replaceExpanded,
5273
- height: newHeight
5274
- };
5275
- };
5276
-
5277
- // TODO this function should be synchronous
5278
- const focusIndex$1 = async (state, index) => {
5279
- const {
5280
- value,
5281
- matches,
5282
- matchIndex
5283
- } = state;
5284
- if (index === matchIndex) {
5285
- return state;
5286
- }
5287
- // TODO find next match and highlight it
5288
- const matchRowIndex = matches[index * 2];
5289
- const matchColumnIndex = matches[index * 2 + 1];
5290
- // @ts-ignore
5291
- const newSelections = new Uint32Array([matchRowIndex, matchColumnIndex, matchRowIndex, matchColumnIndex + value.length]);
5292
- // TODO set selections synchronously and render input match index,
5293
- // input value and new selections at the same time
5294
- // TODO
5295
- await invoke$3('Editor.setSelections', newSelections);
5296
- return {
5297
- ...state,
5298
- matchIndex: index
5299
- };
5300
- };
5301
- const focusFirst$1 = state => {
5302
- return focusIndex$1(state, 0);
5303
- };
5304
- const focusLast = state => {
5305
- const {
5306
- matchCount
5307
- } = state;
5308
- return focusIndex$1(state, matchCount - 1);
5309
- };
5310
- const focusNext$1 = state => {
5311
- const {
5312
- matchIndex,
5313
- matchCount
5314
- } = state;
5315
- if (matchIndex === matchCount - 1) {
5316
- return focusFirst$1(state);
5317
- }
5318
- return focusIndex$1(state, matchIndex + 1);
5319
- };
5320
- const focusPrevious$1 = state => {
5321
- const {
5322
- matchIndex
5323
- } = state;
5324
- if (matchIndex === 0) {
5325
- return focusLast(state);
5326
- }
5327
- return focusIndex$1(state, matchIndex - 1);
5328
- };
5329
5411
  const close$1 = async state => {
5330
5412
  // TODO
5331
5413
  // await Viewlet.closeWidget(uid)
@@ -5344,55 +5426,25 @@ const handleToggleReplaceFocus = async state => {
5344
5426
  focus: FocusFindWidgetToggleReplace
5345
5427
  };
5346
5428
  };
5347
- const handleReplaceFocus = async state => {
5348
- if (state.focus === FocusFindWidgetReplace) {
5349
- return state;
5350
- }
5351
- await setFocus(FocusFindWidgetReplace);
5352
- return {
5353
- ...state,
5354
- focus: FocusFindWidgetReplace,
5355
- focusSource: User
5356
- };
5357
- };
5358
- const focusReplace = state => {
5359
- return setFindWidgetFocus(state, FocusFindWidgetReplace);
5360
- };
5361
- const focusFind = state => {
5362
- return setFindWidgetFocus(state, FindWidget);
5363
- };
5364
5429
  const handleReplaceInput = state => {
5365
5430
  // TODO
5366
5431
  return state;
5367
5432
  };
5368
- const focusToggleReplace = async state => {
5369
- return setFindWidgetFocus(state, FocusFindWidgetToggleReplace);
5370
- };
5371
- const handleReplaceAllFocus = async state => {
5372
- if (state.focus === FocusFindWidgetReplaceAllButton) {
5373
- return state;
5374
- }
5375
- await setFocus(FocusFindWidgetReplaceAllButton);
5433
+
5434
+ const getFindWidgetPosition = editor => {
5435
+ const width = 300;
5436
+ const height = 30;
5437
+ const paddingTop = 10;
5438
+ const paddingRight = 20;
5439
+ const x = editor.x + editor.width - width - paddingRight;
5440
+ const y = editor.y + paddingTop;
5376
5441
  return {
5377
- ...state,
5378
- focus: FocusFindWidgetReplaceAllButton
5442
+ y,
5443
+ x,
5444
+ width,
5445
+ height
5379
5446
  };
5380
5447
  };
5381
- const focusReplaceButton = state => {
5382
- return setFindWidgetFocus(state, FocusFindWidgetReplaceButton);
5383
- };
5384
- const focusReplaceAllButton = state => {
5385
- return setFindWidgetFocus(state, FocusFindWidgetReplaceAllButton);
5386
- };
5387
- const focusPreviousMatchButton = state => {
5388
- return setFindWidgetFocus(state, FocusFindWidgetPreviousMatchButton);
5389
- };
5390
- const focusNextMatchButton = state => {
5391
- return setFindWidgetFocus(state, FocusFindWidgetNextMatchButton);
5392
- };
5393
- const focusCloseButton = state => {
5394
- return setFindWidgetFocus(state, FocusFindWidgetCloseButton);
5395
- };
5396
5448
 
5397
5449
  const openFind2 = async editor => {
5398
5450
  const newStateGenerator = async state => {
@@ -5407,7 +5459,7 @@ const openFind2 = async editor => {
5407
5459
  y,
5408
5460
  width,
5409
5461
  height
5410
- } = getPosition(editor);
5462
+ } = getFindWidgetPosition(editor);
5411
5463
  const latestState = {
5412
5464
  ...state,
5413
5465
  value,
@@ -7124,18 +7176,6 @@ const closeDetails = editor => {
7124
7176
  };
7125
7177
  };
7126
7178
 
7127
- const getWidgetState = (editor, id) => {
7128
- const {
7129
- widgets
7130
- } = editor;
7131
- for (const widget of widgets) {
7132
- if (widget.id === id) {
7133
- return widget.newState;
7134
- }
7135
- }
7136
- return undefined;
7137
- };
7138
-
7139
7179
  const getCompletionState = editor => {
7140
7180
  return getWidgetState(editor, Completion);
7141
7181
  };
@@ -8714,12 +8754,12 @@ const wrapWidgetCommand = (widgetId, fn) => {
8714
8754
  const widgetCommands = {
8715
8755
  'ColorPicker.handleSliderPointerDown': ColorPicker$1,
8716
8756
  'ColorPicker.handleSliderPointerMove': ColorPicker$1,
8717
- 'FindWidget.focusNext': Find,
8718
- 'FindWidget.focusPrevious': Find,
8757
+ // 'FindWidget.focusNext': WidgetId.Find,
8758
+ // 'FindWidget.focusPrevious': WidgetId.Find,
8719
8759
  'FindWidget.close': Find,
8720
- 'FindWidget.focusIndex': Find,
8721
- 'FindWidget.focusFirst': Find,
8722
- 'FindWidget.focusLast': Find,
8760
+ // 'FindWidget.focusIndex': WidgetId.Find,
8761
+ // 'FindWidget.focusFirst': WidgetId.Find,
8762
+ // 'FindWidget.focusLast': WidgetId.Find,
8723
8763
  'FindWidget.toggleReplace': Find,
8724
8764
  'FindWidget.handleFocus': Find,
8725
8765
  'FindWidget.handleBlur': Find,
@@ -8817,7 +8857,7 @@ const commandMap = {
8817
8857
  'Editor.handleBlur': handleBlur$1,
8818
8858
  'Editor.handleContextMenu': handleContextMenu,
8819
8859
  'Editor.handleDoubleClick': handleDoubleClick,
8820
- 'Editor.handleFocus': handleFocus$1,
8860
+ 'Editor.handleFocus': handleFocus,
8821
8861
  'Editor.handleMouseDown': handleMouseDown,
8822
8862
  'Editor.handleMouseMove': handleMouseMove,
8823
8863
  'Editor.handleMouseMoveWithAltKey': handleMouseMoveWithAltKey,
@@ -8915,9 +8955,9 @@ const commandMap = {
8915
8955
  'FindWidget.focusReplace': focusReplace,
8916
8956
  'FindWidget.focusReplaceAllButton': focusReplaceAllButton,
8917
8957
  'FindWidget.focusReplaceButton': focusReplaceButton,
8918
- 'FindWidget.focusToggleReplace': focusToggleReplace,
8958
+ 'FindWidget.focusToggleReplace': focusToggleReplaceButton,
8919
8959
  'FindWidget.handleBlur': handleBlur,
8920
- 'FindWidget.handleFocus': handleFocus,
8960
+ 'FindWidget.handleFocus': handleFindWidgetFocus,
8921
8961
  'FindWidget.handleInput': handleInput,
8922
8962
  'FindWidget.handleReplaceAllFocus': handleReplaceAllFocus,
8923
8963
  'FindWidget.handleReplaceFocus': handleReplaceFocus,
@@ -10302,6 +10342,10 @@ const renderFocus = {
10302
10342
 
10303
10343
  const render$1 = [renderDetails, renderBounds, renderValue, renderFocus];
10304
10344
  const apply = (oldState, newState) => {
10345
+ // TODO avoid side effect
10346
+ if (oldState.focus !== newState.focus) {
10347
+ setFocus(newState.focus);
10348
+ }
10305
10349
  return renderParts(render$1, oldState, newState);
10306
10350
  };
10307
10351
 
@@ -10329,7 +10373,7 @@ const Commands = {
10329
10373
  'FindWidget.focusIndex': focusIndex$1,
10330
10374
  'FindWidget.focusLast': focusLast,
10331
10375
  'FindWidget.toggleReplace': toggleReplace,
10332
- 'FindWidget.handleFocus': handleFocus,
10376
+ 'FindWidget.handleFocus': focusFind,
10333
10377
  'FindWidget.handleBlur': handleBlur
10334
10378
  };
10335
10379
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "3.14.0",
3
+ "version": "3.16.0",
4
4
  "description": "",
5
5
  "main": "dist/testWorkerMain.js",
6
6
  "type": "module",