@lvce-editor/editor-worker 3.11.0 → 3.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.
@@ -2442,7 +2442,11 @@ const setAdditionalFocus = async focusKey => {
2442
2442
  await invoke$3('Focus.setAdditionalFocus', focusKey);
2443
2443
  };
2444
2444
 
2445
- const addWidgetToEditor = async (widgetId, focusKey, editor, factory, newStateGenerator) => {
2445
+ const setFocus = async focusKey => {
2446
+ await invoke$3('Focus.setFocus', focusKey);
2447
+ };
2448
+
2449
+ const addWidgetToEditor = async (widgetId, focusKey, editor, factory, newStateGenerator, fullFocus) => {
2446
2450
  const {
2447
2451
  widgets
2448
2452
  } = editor;
@@ -2457,7 +2461,11 @@ const addWidgetToEditor = async (widgetId, focusKey, editor, factory, newStateGe
2457
2461
  };
2458
2462
  const newWidgets = [...widgets, latestWidget];
2459
2463
  // TODO avoid side effect, apply focus shift during render
2460
- await setAdditionalFocus(focusKey);
2464
+ if (fullFocus) {
2465
+ await setFocus(focusKey);
2466
+ } else {
2467
+ await setAdditionalFocus(focusKey);
2468
+ }
2461
2469
  const newEditor = {
2462
2470
  ...editor,
2463
2471
  widgets: newWidgets
@@ -2506,6 +2514,11 @@ const CompletionDetail = 999;
2506
2514
  const Empty = 0;
2507
2515
  const FindWidgetToggleReplace = 42;
2508
2516
  const FindWidgetReplace = 43;
2517
+ const FindWidgetReplaceButton = 46;
2518
+ const FindWidgetReplaceAllButton = 47;
2519
+ const FindWidgetCloseButton = 48;
2520
+ const FindWidgetFocusNext = 49;
2521
+ const FindWidgetFocusPrevious = 50;
2509
2522
 
2510
2523
  const newStateGenerator = state => {
2511
2524
  return loadContent$3(state);
@@ -5097,7 +5110,8 @@ const create$1 = () => {
5097
5110
  width: 0,
5098
5111
  height: 0,
5099
5112
  focused: false,
5100
- focusSource: Unknown$1
5113
+ focusSource: Unknown$1,
5114
+ focus: 0
5101
5115
  },
5102
5116
  newState: {
5103
5117
  value: '',
@@ -5117,7 +5131,8 @@ const create$1 = () => {
5117
5131
  width: 0,
5118
5132
  height: 0,
5119
5133
  focused: true,
5120
- focusSource: Unknown$1
5134
+ focusSource: Unknown$1,
5135
+ focus: 0
5121
5136
  }
5122
5137
  };
5123
5138
  return widget;
@@ -5137,6 +5152,9 @@ const getSearchRegex = searchString => {
5137
5152
  };
5138
5153
 
5139
5154
  const findRegexMatches = (lines, regex) => {
5155
+ if (!regex.global) {
5156
+ throw new Error(`regex must be global`);
5157
+ }
5140
5158
  const {
5141
5159
  length
5142
5160
  } = lines;
@@ -5163,12 +5181,27 @@ const findMatchesCaseInsensitive = (lines, searchString) => {
5163
5181
  return findRegexMatches(lines, regex);
5164
5182
  };
5165
5183
 
5184
+ const getFindWidgetHeight = replaceExpanded => {
5185
+ const collapsedHeight = 30;
5186
+ const expandedHeight = 60;
5187
+ const newHeight = replaceExpanded ? expandedHeight : collapsedHeight;
5188
+ return newHeight;
5189
+ };
5190
+
5166
5191
  const getMatchCount = matches => {
5167
5192
  return matches.length / 2;
5168
5193
  };
5169
5194
 
5170
- const setFocus = async focusKey => {
5171
- await invoke$3('Focus.setFocus', focusKey);
5195
+ const setFindWidgetFocus = async (state, focusKey) => {
5196
+ if (state.focus === focusKey) {
5197
+ return state;
5198
+ }
5199
+ await setFocus(focusKey);
5200
+ return {
5201
+ ...state,
5202
+ focus: focusKey,
5203
+ focusSource: Script
5204
+ };
5172
5205
  };
5173
5206
 
5174
5207
  const getPosition = editor => {
@@ -5230,28 +5263,22 @@ const handleInput = (state, value) => {
5230
5263
  return refresh(state, value);
5231
5264
  };
5232
5265
  const handleFocus = async state => {
5233
- if (state.focus === 'find') {
5266
+ if (state.focus === FindWidget) {
5234
5267
  return state;
5235
5268
  }
5236
5269
  await setFocus(FindWidget);
5237
5270
  return {
5238
5271
  ...state,
5239
- focus: 'find'
5272
+ focus: FindWidget
5240
5273
  };
5241
5274
  };
5242
5275
  const handleBlur = async state => {
5243
5276
  await setFocus(Empty);
5244
5277
  return state;
5245
5278
  };
5246
- const getHeight = replaceExpanded => {
5247
- const collapsedHeight = 30;
5248
- const expandedHeight = 60;
5249
- const newHeight = replaceExpanded ? expandedHeight : collapsedHeight;
5250
- return newHeight;
5251
- };
5252
5279
  const toggleReplace = state => {
5253
5280
  const newExpanded = !state.replaceExpanded;
5254
- const newHeight = getHeight(newExpanded);
5281
+ const newHeight = getFindWidgetHeight(newExpanded);
5255
5282
  return {
5256
5283
  ...state,
5257
5284
  replaceExpanded: !state.replaceExpanded,
@@ -5319,45 +5346,57 @@ const close$1 = async state => {
5319
5346
  disposed: true
5320
5347
  };
5321
5348
  };
5349
+ const handleToggleReplaceFocus = async state => {
5350
+ if (state.focus === FindWidgetToggleReplace) {
5351
+ return state;
5352
+ }
5353
+ await setFocus(FindWidgetToggleReplace);
5354
+ return {
5355
+ ...state,
5356
+ focus: FindWidgetToggleReplace
5357
+ };
5358
+ };
5322
5359
  const handleReplaceFocus = async state => {
5323
- if (state.focus === 'replaceInput') {
5360
+ if (state.focus === FindWidgetReplace) {
5324
5361
  return state;
5325
5362
  }
5326
5363
  await setFocus(FindWidgetReplace);
5327
5364
  return {
5328
5365
  ...state,
5329
- focus: 'replaceInput',
5366
+ focus: FindWidgetReplace,
5330
5367
  focusSource: User
5331
5368
  };
5332
5369
  };
5333
5370
  const focusReplace = state => {
5334
- // TODO
5335
- return {
5336
- ...state,
5337
- focus: 'replace',
5338
- focusSource: Script
5339
- };
5371
+ return setFindWidgetFocus(state, FindWidgetReplace);
5340
5372
  };
5341
5373
  const focusFind = state => {
5342
- // TODO
5343
- return {
5344
- ...state,
5345
- focus: 'find',
5346
- focusSource: Script
5347
- };
5374
+ return setFindWidgetFocus(state, FindWidget);
5348
5375
  };
5349
5376
  const handleReplaceInput = state => {
5350
5377
  // TODO
5351
5378
  return state;
5352
5379
  };
5353
5380
  const focusToggleReplace = async state => {
5354
- await setFocus(FindWidgetToggleReplace);
5381
+ return setFindWidgetFocus(state, FindWidgetToggleReplace);
5382
+ };
5383
+ const handleReplaceAllFocus = async state => {
5384
+ if (state.focus === FindWidgetReplaceAllButton) {
5385
+ return state;
5386
+ }
5387
+ await setFocus(FindWidgetReplaceAllButton);
5355
5388
  return {
5356
5389
  ...state,
5357
- focus: 'toggleReplace',
5358
- focusSource: Script
5390
+ focus: FindWidgetReplaceAllButton
5359
5391
  };
5360
5392
  };
5393
+ const focusReplaceButton = async state => {
5394
+ console.log('f replace button');
5395
+ return setFindWidgetFocus(state, FindWidgetReplaceButton);
5396
+ };
5397
+ const focusReplaceAllButton = async state => {
5398
+ return setFindWidgetFocus(state, FindWidgetReplaceAllButton);
5399
+ };
5361
5400
 
5362
5401
  const openFind2 = async editor => {
5363
5402
  const newStateGenerator = async state => {
@@ -5385,11 +5424,12 @@ const openFind2 = async editor => {
5385
5424
  height,
5386
5425
  editorUid: editor.uid || editor.id,
5387
5426
  focusSource: Script,
5388
- focus: 'find'
5427
+ focus: FindWidget
5389
5428
  };
5390
5429
  return latestState;
5391
5430
  };
5392
- return addWidgetToEditor(Find, FindWidget, editor, create$1, newStateGenerator);
5431
+ const fullFocus = true;
5432
+ return addWidgetToEditor(Find, FindWidget, editor, create$1, newStateGenerator, fullFocus);
5393
5433
  };
5394
5434
 
5395
5435
  const openFind = async state => {
@@ -8693,7 +8733,9 @@ const widgetCommands = {
8693
8733
  'FindWidget.handleReplaceFocus': Find,
8694
8734
  'FindWidget.focusFind': Find,
8695
8735
  'FindWidget.focusToggleReplace': Find,
8696
- 'FindWidget.focusReplace': Find
8736
+ 'FindWidget.focusReplace': Find,
8737
+ 'FindWidget.focusReplaceButton': Find,
8738
+ 'FindWidget.focusReplaceAllButton': Find
8697
8739
  };
8698
8740
 
8699
8741
  // TODO wrap commands globally, not per editor
@@ -8863,21 +8905,25 @@ const commandMap = {
8863
8905
  'EditorCompletion.selectIndex': selectIndex,
8864
8906
  'EditorCompletion.toggleDetails': toggleDetails,
8865
8907
  'FindWidget.close': close$1,
8908
+ 'FindWidget.focusFind': focusFind,
8866
8909
  'FindWidget.focusFirst': focusFirst$1,
8867
8910
  'FindWidget.focusIndex': focusIndex$1,
8868
8911
  'FindWidget.focusLast': focusLast,
8869
8912
  'FindWidget.focusNext': focusNext$1,
8870
8913
  'FindWidget.focusPrevious': focusPrevious$1,
8914
+ 'FindWidget.focusReplace': focusReplace,
8915
+ 'FindWidget.focusToggleReplace': focusToggleReplace,
8871
8916
  'FindWidget.handleBlur': handleBlur,
8872
8917
  'FindWidget.handleFocus': handleFocus,
8873
8918
  'FindWidget.handleInput': handleInput,
8874
8919
  'FindWidget.handleReplaceFocus': handleReplaceFocus,
8920
+ 'FindWidget.handleReplaceInput': handleReplaceInput,
8875
8921
  'FindWidget.loadContent': loadContent$1,
8876
8922
  'FindWidget.toggleReplace': toggleReplace,
8877
- 'FindWidget.focusReplace': focusReplace,
8878
- 'FindWidget.focusFind': focusFind,
8879
- 'FindWidget.handleReplaceInput': handleReplaceInput,
8880
- 'FindWidget.focusToggleReplace': focusToggleReplace,
8923
+ 'FindWidget.handleToggleReplaceFocus': handleToggleReplaceFocus,
8924
+ 'FindWidget.handleReplaceAllFocus': handleReplaceAllFocus,
8925
+ 'FindWidget.focusReplaceButton': focusReplaceButton,
8926
+ 'FindWidget.focusReplaceAllButton': focusReplaceAllButton,
8881
8927
  'Font.ensure': ensure,
8882
8928
  'Hover.getHoverInfo': getEditorHoverInfo,
8883
8929
  'Hover.handleSashPointerDown': handleSashPointerDown,
@@ -9951,6 +9997,84 @@ const replaceAll = () => {
9951
9997
  return i18nString(UiStrings.ReplaceAll);
9952
9998
  };
9953
9999
 
10000
+ const ArrowDown = 'ArrowDown';
10001
+ const ArrowUp = 'ArrowUp';
10002
+ const Close$1 = 'Close';
10003
+ const Replace$1 = 'Replace';
10004
+ const ReplaceAll$1 = 'ReplaceAll';
10005
+
10006
+ const SearchValue = 'search-value';
10007
+ const ReplaceValue = 'replace-value';
10008
+ const ReplaceAll = 'ReplaceAll';
10009
+ const Close = 'Close';
10010
+ const ToggleReplace = 'ToggleReplace';
10011
+ const FocusNext = 'FocusNext';
10012
+ const FocusPrevious = 'FocusPrevious';
10013
+ const Replace = 'Replace';
10014
+
10015
+ const getFindWidgetButtons = buttonsEnabled => {
10016
+ const findButtons = [{
10017
+ label: previousMatch(),
10018
+ icon: ArrowUp,
10019
+ disabled: !buttonsEnabled,
10020
+ onClick: 'handleClickPreviousMatch',
10021
+ name: FocusPrevious
10022
+ }, {
10023
+ label: nextMatch(),
10024
+ icon: ArrowDown,
10025
+ disabled: !buttonsEnabled,
10026
+ onClick: 'handleClickNextMatch',
10027
+ name: FocusNext
10028
+ }, {
10029
+ label: close(),
10030
+ icon: Close$1,
10031
+ disabled: false,
10032
+ onClick: 'handleClickClose',
10033
+ name: Close
10034
+ }];
10035
+ const replaceButtons = [{
10036
+ label: replace(),
10037
+ icon: Replace$1,
10038
+ disabled: !buttonsEnabled,
10039
+ onClick: 'handleClickReplace',
10040
+ name: Replace
10041
+ }, {
10042
+ label: replaceAll(),
10043
+ icon: ReplaceAll$1,
10044
+ disabled: !buttonsEnabled,
10045
+ onClick: 'handleClickReplaceAll',
10046
+ name: ReplaceAll
10047
+ }];
10048
+ return {
10049
+ findButtons,
10050
+ replaceButtons
10051
+ };
10052
+ };
10053
+
10054
+ // TODO always focus element by name
10055
+ const getFindWidgetFocusSelector = focus => {
10056
+ switch (focus) {
10057
+ case FindWidget:
10058
+ return `[name="${SearchValue}"]`;
10059
+ case FindWidgetReplace:
10060
+ return `[name="${ReplaceValue}"]`;
10061
+ case FindWidgetReplaceAllButton:
10062
+ return `[name="${ReplaceAll}"]`;
10063
+ case FindWidgetCloseButton:
10064
+ return `[name="${Close}"]`;
10065
+ case FindWidgetToggleReplace:
10066
+ return `[name="${ToggleReplace}"]`;
10067
+ case FindWidgetFocusNext:
10068
+ return `[name="${FocusNext}"]`;
10069
+ case FindWidgetFocusPrevious:
10070
+ return `[name="${FocusPrevious}"]`;
10071
+ case FindWidgetReplaceButton:
10072
+ return `[name="${Replace}"]`;
10073
+ default:
10074
+ return '';
10075
+ }
10076
+ };
10077
+
9954
10078
  const getIconVirtualDom = (icon, type = Div) => {
9955
10079
  return {
9956
10080
  type,
@@ -9964,7 +10088,9 @@ const getIconButtonVirtualDom = iconButton => {
9964
10088
  const {
9965
10089
  label,
9966
10090
  icon,
9967
- disabled
10091
+ disabled,
10092
+ name,
10093
+ onClick
9968
10094
  } = iconButton;
9969
10095
  let className = IconButton;
9970
10096
  if (disabled) {
@@ -9977,7 +10103,8 @@ const getIconButtonVirtualDom = iconButton => {
9977
10103
  ariaLabel: label,
9978
10104
  childCount: 1,
9979
10105
  disabled: disabled ? true : undefined,
9980
- onClick: iconButton.onClick
10106
+ onClick: onClick,
10107
+ name: name
9981
10108
  }, getIconVirtualDom(icon)];
9982
10109
  };
9983
10110
 
@@ -10068,7 +10195,8 @@ const getSearchToggleButtonVirtualDom = (replaceExpanded, onClick = '') => {
10068
10195
  name: 'ToggleReplace',
10069
10196
  childCount: 1,
10070
10197
  'data-command': 'toggleReplace',
10071
- onClick
10198
+ onClick,
10199
+ onFocus: 'handleToggleReplaceFocus'
10072
10200
  }, {
10073
10201
  type: Div,
10074
10202
  className: `MaskIcon ${replaceExpanded ? 'MaskIconChevronDown' : 'MaskIconChevronRight'}`,
@@ -10104,12 +10232,6 @@ const getMatchCountText = (matchIndex, matchCount) => {
10104
10232
  return matchOf(matchIndex + 1, matchCount);
10105
10233
  };
10106
10234
 
10107
- const ArrowDown = 'ArrowDown';
10108
- const ArrowUp = 'ArrowUp';
10109
- const Close = 'Close';
10110
- const Replace = 'Replace';
10111
- const ReplaceAll = 'ReplaceAll';
10112
-
10113
10235
  const renderValue = {
10114
10236
  isEqual(oldState, newState) {
10115
10237
  return oldState.value === newState.value;
@@ -10125,33 +10247,10 @@ const renderDetails = {
10125
10247
  apply(oldState, newState) {
10126
10248
  const matchCountText = getMatchCountText(newState.matchIndex, newState.matchCount);
10127
10249
  const buttonsEnabled = newState.matchCount > 0;
10128
- const findButtons = [{
10129
- label: previousMatch(),
10130
- icon: ArrowUp,
10131
- disabled: !buttonsEnabled,
10132
- onClick: 'handleClickPreviousMatch'
10133
- }, {
10134
- label: nextMatch(),
10135
- icon: ArrowDown,
10136
- disabled: !buttonsEnabled,
10137
- onClick: 'handleClickNextMatch'
10138
- }, {
10139
- label: close(),
10140
- icon: Close,
10141
- disabled: false,
10142
- onClick: 'handleClickClose'
10143
- }];
10144
- const replaceButtons = [{
10145
- label: replace(),
10146
- icon: Replace,
10147
- disabled: !buttonsEnabled,
10148
- onClick: 'handleClickReplace'
10149
- }, {
10150
- label: replaceAll(),
10151
- icon: ReplaceAll,
10152
- disabled: !buttonsEnabled,
10153
- onClick: 'handleClickReplaceAll'
10154
- }];
10250
+ const {
10251
+ findButtons,
10252
+ replaceButtons
10253
+ } = getFindWidgetButtons(buttonsEnabled);
10155
10254
  const dom = getFindWidgetVirtualDom(matchCountText, newState.replaceExpanded, findButtons, replaceButtons);
10156
10255
  return ['Viewlet.setDom2', dom];
10157
10256
  }
@@ -10170,27 +10269,12 @@ const renderBounds = {
10170
10269
  return [/* method */SetBounds, /* x */x, /* y */y, /* width */width, /* height */height];
10171
10270
  }
10172
10271
  };
10173
-
10174
- // TODO always focus element by name
10175
- // TODO use numeric key
10176
- const getKey = focus => {
10177
- switch (focus) {
10178
- case 'find':
10179
- return `[name="search-value"]`;
10180
- case 'replace':
10181
- return '[name="replace-value"]';
10182
- case 'toggleReplace':
10183
- return `[name="toggleReplace"]`;
10184
- default:
10185
- return '';
10186
- }
10187
- };
10188
10272
  const renderFocus = {
10189
10273
  isEqual(oldState, newState) {
10190
10274
  return oldState.focused === newState.focused && oldState.focus === newState.focus && oldState.focusSource === newState.focusSource;
10191
10275
  },
10192
10276
  apply(oldState, newState) {
10193
- const key = getKey(newState.focus || '');
10277
+ const key = getFindWidgetFocusSelector(newState.focus);
10194
10278
  return ['focus', key, newState.focusSource];
10195
10279
  }
10196
10280
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "3.11.0",
3
+ "version": "3.13.0",
4
4
  "description": "",
5
5
  "main": "dist/testWorkerMain.js",
6
6
  "type": "module",