@lvce-editor/editor-worker 3.10.0 → 3.12.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.
@@ -121,7 +121,7 @@ const IconButtonDisabled = 'IconButtonDisabled';
121
121
  const IconButton = 'IconButton';
122
122
  const CompletionDetailContent = 'CompletionDetailContent';
123
123
  const Diagnostic = 'Diagnostic';
124
- const FindWidgetReplace = 'FindWidgetReplace';
124
+ const FindWidgetReplace$1 = 'FindWidgetReplace';
125
125
  const FindWidgetFind = 'FindWidgetFind';
126
126
  const FindWidgetMatchCount = 'FindWidgetMatchCount';
127
127
  const FindWidgetRight = 'FindWidgetRight';
@@ -2503,6 +2503,11 @@ const ColorPicker = 41;
2503
2503
  const FindWidget = 16;
2504
2504
  const EditorCompletion = 9;
2505
2505
  const CompletionDetail = 999;
2506
+ const Empty = 0;
2507
+ const FindWidgetToggleReplace = 42;
2508
+ const FindWidgetReplace = 43;
2509
+ const FindWidgetReplaceAll = 46;
2510
+ const FindWidgetClose = 47;
2506
2511
 
2507
2512
  const newStateGenerator = state => {
2508
2513
  return loadContent$3(state);
@@ -5068,6 +5073,10 @@ const openCompletion = async editor => {
5068
5073
  };
5069
5074
  };
5070
5075
 
5076
+ const User = 1;
5077
+ const Script = 2;
5078
+ const Unknown$1 = 0;
5079
+
5071
5080
  const create$1 = () => {
5072
5081
  const uid = create$4();
5073
5082
  const widget = {
@@ -5089,7 +5098,9 @@ const create$1 = () => {
5089
5098
  y: 0,
5090
5099
  width: 0,
5091
5100
  height: 0,
5092
- focused: false
5101
+ focused: false,
5102
+ focusSource: Unknown$1,
5103
+ focus: 0
5093
5104
  },
5094
5105
  newState: {
5095
5106
  value: '',
@@ -5108,7 +5119,9 @@ const create$1 = () => {
5108
5119
  y: 0,
5109
5120
  width: 0,
5110
5121
  height: 0,
5111
- focused: true
5122
+ focused: true,
5123
+ focusSource: Unknown$1,
5124
+ focus: 0
5112
5125
  }
5113
5126
  };
5114
5127
  return widget;
@@ -5128,6 +5141,9 @@ const getSearchRegex = searchString => {
5128
5141
  };
5129
5142
 
5130
5143
  const findRegexMatches = (lines, regex) => {
5144
+ if (!regex.global) {
5145
+ throw new Error(`regex must be global`);
5146
+ }
5131
5147
  const {
5132
5148
  length
5133
5149
  } = lines;
@@ -5154,10 +5170,21 @@ const findMatchesCaseInsensitive = (lines, searchString) => {
5154
5170
  return findRegexMatches(lines, regex);
5155
5171
  };
5156
5172
 
5173
+ const getFindWidgetHeight = replaceExpanded => {
5174
+ const collapsedHeight = 30;
5175
+ const expandedHeight = 60;
5176
+ const newHeight = replaceExpanded ? expandedHeight : collapsedHeight;
5177
+ return newHeight;
5178
+ };
5179
+
5157
5180
  const getMatchCount = matches => {
5158
5181
  return matches.length / 2;
5159
5182
  };
5160
5183
 
5184
+ const setFocus = async focusKey => {
5185
+ await invoke$3('Focus.setFocus', focusKey);
5186
+ };
5187
+
5161
5188
  const getPosition = editor => {
5162
5189
  const width = 300;
5163
5190
  const height = 30;
@@ -5217,20 +5244,22 @@ const handleInput = (state, value) => {
5217
5244
  return refresh(state, value);
5218
5245
  };
5219
5246
  const handleFocus = async state => {
5220
- const FindWidget = 16;
5221
- await invoke$3('Focus.setFocus', FindWidget);
5222
- return state;
5247
+ if (state.focus === FindWidget) {
5248
+ return state;
5249
+ }
5250
+ await setFocus(FindWidget);
5251
+ return {
5252
+ ...state,
5253
+ focus: FindWidget
5254
+ };
5223
5255
  };
5224
5256
  const handleBlur = async state => {
5225
- const Empty = 0;
5226
- await invoke$3('Focus.setFocus', Empty);
5257
+ await setFocus(Empty);
5227
5258
  return state;
5228
5259
  };
5229
5260
  const toggleReplace = state => {
5230
5261
  const newExpanded = !state.replaceExpanded;
5231
- const collapsedHeight = 30;
5232
- const expandedHeight = 60;
5233
- const newHeight = newExpanded ? expandedHeight : collapsedHeight;
5262
+ const newHeight = getFindWidgetHeight(newExpanded);
5234
5263
  return {
5235
5264
  ...state,
5236
5265
  replaceExpanded: !state.replaceExpanded,
@@ -5298,6 +5327,65 @@ const close$1 = async state => {
5298
5327
  disposed: true
5299
5328
  };
5300
5329
  };
5330
+ const handleToggleReplaceFocus = async state => {
5331
+ if (state.focus === FindWidgetToggleReplace) {
5332
+ return state;
5333
+ }
5334
+ await setFocus(FindWidgetToggleReplace);
5335
+ return {
5336
+ ...state,
5337
+ focus: FindWidgetToggleReplace
5338
+ };
5339
+ };
5340
+ const handleReplaceFocus = async state => {
5341
+ if (state.focus === FindWidgetReplace) {
5342
+ return state;
5343
+ }
5344
+ await setFocus(FindWidgetReplace);
5345
+ return {
5346
+ ...state,
5347
+ focus: FindWidgetReplace,
5348
+ focusSource: User
5349
+ };
5350
+ };
5351
+ const focusReplace = state => {
5352
+ // TODO
5353
+ return {
5354
+ ...state,
5355
+ focus: FindWidgetReplace,
5356
+ focusSource: Script
5357
+ };
5358
+ };
5359
+ const focusFind = state => {
5360
+ // TODO
5361
+ return {
5362
+ ...state,
5363
+ focus: FindWidget,
5364
+ focusSource: Script
5365
+ };
5366
+ };
5367
+ const handleReplaceInput = state => {
5368
+ // TODO
5369
+ return state;
5370
+ };
5371
+ const focusToggleReplace = async state => {
5372
+ await setFocus(FindWidgetToggleReplace);
5373
+ return {
5374
+ ...state,
5375
+ focus: FindWidgetToggleReplace,
5376
+ focusSource: Script
5377
+ };
5378
+ };
5379
+ const handleReplaceAllFocus = async state => {
5380
+ if (state.focus === FindWidgetReplaceAll) {
5381
+ return state;
5382
+ }
5383
+ await setFocus(FindWidgetReplaceAll);
5384
+ return {
5385
+ ...state,
5386
+ focus: FindWidgetReplaceAll
5387
+ };
5388
+ };
5301
5389
 
5302
5390
  const openFind2 = async editor => {
5303
5391
  const newStateGenerator = async state => {
@@ -5323,7 +5411,9 @@ const openFind2 = async editor => {
5323
5411
  y,
5324
5412
  width,
5325
5413
  height,
5326
- editorUid: editor.uid || editor.id
5414
+ editorUid: editor.uid || editor.id,
5415
+ focusSource: Script,
5416
+ focus: FindWidget
5327
5417
  };
5328
5418
  return latestState;
5329
5419
  };
@@ -8628,7 +8718,10 @@ const widgetCommands = {
8628
8718
  'FindWidget.handleToggleReplaceFocus': Find,
8629
8719
  'FindWidget.handleInput': Find,
8630
8720
  'FindWidget.handleReplaceInput': Find,
8631
- 'FindWidget.handleReplaceFocus': Find
8721
+ 'FindWidget.handleReplaceFocus': Find,
8722
+ 'FindWidget.focusFind': Find,
8723
+ 'FindWidget.focusToggleReplace': Find,
8724
+ 'FindWidget.focusReplace': Find
8632
8725
  };
8633
8726
 
8634
8727
  // TODO wrap commands globally, not per editor
@@ -8797,17 +8890,24 @@ const commandMap = {
8797
8890
  'EditorCompletion.selectCurrent': selectCurrent,
8798
8891
  'EditorCompletion.selectIndex': selectIndex,
8799
8892
  'EditorCompletion.toggleDetails': toggleDetails,
8893
+ 'FindWidget.close': close$1,
8894
+ 'FindWidget.focusFind': focusFind,
8800
8895
  'FindWidget.focusFirst': focusFirst$1,
8801
8896
  'FindWidget.focusIndex': focusIndex$1,
8802
8897
  'FindWidget.focusLast': focusLast,
8803
8898
  'FindWidget.focusNext': focusNext$1,
8804
8899
  'FindWidget.focusPrevious': focusPrevious$1,
8805
- 'FindWidget.handleInput': handleInput,
8806
- 'FindWidget.handleFocus': handleFocus,
8900
+ 'FindWidget.focusReplace': focusReplace,
8901
+ 'FindWidget.focusToggleReplace': focusToggleReplace,
8807
8902
  'FindWidget.handleBlur': handleBlur,
8808
- 'FindWidget.toggleReplace': toggleReplace,
8809
- 'FindWidget.close': close$1,
8903
+ 'FindWidget.handleFocus': handleFocus,
8904
+ 'FindWidget.handleInput': handleInput,
8905
+ 'FindWidget.handleReplaceFocus': handleReplaceFocus,
8906
+ 'FindWidget.handleReplaceInput': handleReplaceInput,
8810
8907
  'FindWidget.loadContent': loadContent$1,
8908
+ 'FindWidget.toggleReplace': toggleReplace,
8909
+ 'FindWidget.handleToggleReplaceFocus': handleToggleReplaceFocus,
8910
+ 'FindWidget.handleReplaceAllFocus': handleReplaceAllFocus,
8811
8911
  'Font.ensure': ensure,
8812
8912
  'Hover.getHoverInfo': getEditorHoverInfo,
8813
8913
  'Hover.handleSashPointerDown': handleSashPointerDown,
@@ -9881,6 +9981,24 @@ const replaceAll = () => {
9881
9981
  return i18nString(UiStrings.ReplaceAll);
9882
9982
  };
9883
9983
 
9984
+ // TODO always focus element by name
9985
+ const getFindWidgetFocusSelector = focus => {
9986
+ switch (focus) {
9987
+ case FindWidget:
9988
+ return `[name="search-value"]`;
9989
+ case FindWidgetReplace:
9990
+ return '[name="replace-value"]';
9991
+ case FindWidgetReplaceAll:
9992
+ return `[name="replaceAll"]`;
9993
+ case FindWidgetClose:
9994
+ return `[name="close"]`;
9995
+ case FindWidgetToggleReplace:
9996
+ return `[name="ToggleReplace"]`;
9997
+ default:
9998
+ return '';
9999
+ }
10000
+ };
10001
+
9884
10002
  const getIconVirtualDom = (icon, type = Div) => {
9885
10003
  return {
9886
10004
  type,
@@ -9981,7 +10099,7 @@ const getFindWidgetReplaceVirtualDom = (replaceExpanded, replaceButtons) => {
9981
10099
  if (replaceExpanded) {
9982
10100
  dom.push({
9983
10101
  type: Div,
9984
- className: FindWidgetReplace,
10102
+ className: FindWidgetReplace$1,
9985
10103
  childCount: 1 + replaceButtons.length
9986
10104
  }, ...getSearchFieldVirtualDom('replace-value', replace(), 'handleReplaceInput', [], [], 'handleReplaceFocus'), ...replaceButtons.flatMap(getIconButtonVirtualDom));
9987
10105
  }
@@ -9995,9 +10113,11 @@ const getSearchToggleButtonVirtualDom = (replaceExpanded, onClick = '') => {
9995
10113
  title: 'Toggle Replace',
9996
10114
  ariaLabel: 'Toggle Replace',
9997
10115
  ariaExpanded: replaceExpanded,
10116
+ name: 'ToggleReplace',
9998
10117
  childCount: 1,
9999
10118
  'data-command': 'toggleReplace',
10000
- onClick
10119
+ onClick,
10120
+ onFocus: 'handleToggleReplaceFocus'
10001
10121
  }, {
10002
10122
  type: Div,
10003
10123
  className: `MaskIcon ${replaceExpanded ? 'MaskIconChevronDown' : 'MaskIconChevronRight'}`,
@@ -10101,10 +10221,11 @@ const renderBounds = {
10101
10221
  };
10102
10222
  const renderFocus = {
10103
10223
  isEqual(oldState, newState) {
10104
- return oldState.focused === newState.focused;
10224
+ return oldState.focused === newState.focused && oldState.focus === newState.focus && oldState.focusSource === newState.focusSource;
10105
10225
  },
10106
10226
  apply(oldState, newState) {
10107
- return ['focus', newState.focused];
10227
+ const key = getFindWidgetFocusSelector(newState.focus);
10228
+ return ['focus', key, newState.focusSource];
10108
10229
  }
10109
10230
  };
10110
10231
  // const getAriaLabel = (state: FindWidgetState) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "3.10.0",
3
+ "version": "3.12.0",
4
4
  "description": "",
5
5
  "main": "dist/testWorkerMain.js",
6
6
  "type": "module",