@lvce-editor/editor-worker 3.12.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,8 +2514,11 @@ const CompletionDetail = 999;
2506
2514
  const Empty = 0;
2507
2515
  const FindWidgetToggleReplace = 42;
2508
2516
  const FindWidgetReplace = 43;
2509
- const FindWidgetReplaceAll = 46;
2510
- const FindWidgetClose = 47;
2517
+ const FindWidgetReplaceButton = 46;
2518
+ const FindWidgetReplaceAllButton = 47;
2519
+ const FindWidgetCloseButton = 48;
2520
+ const FindWidgetFocusNext = 49;
2521
+ const FindWidgetFocusPrevious = 50;
2511
2522
 
2512
2523
  const newStateGenerator = state => {
2513
2524
  return loadContent$3(state);
@@ -5181,8 +5192,16 @@ const getMatchCount = matches => {
5181
5192
  return matches.length / 2;
5182
5193
  };
5183
5194
 
5184
- const setFocus = async focusKey => {
5185
- 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
+ };
5186
5205
  };
5187
5206
 
5188
5207
  const getPosition = editor => {
@@ -5349,43 +5368,35 @@ const handleReplaceFocus = async state => {
5349
5368
  };
5350
5369
  };
5351
5370
  const focusReplace = state => {
5352
- // TODO
5353
- return {
5354
- ...state,
5355
- focus: FindWidgetReplace,
5356
- focusSource: Script
5357
- };
5371
+ return setFindWidgetFocus(state, FindWidgetReplace);
5358
5372
  };
5359
5373
  const focusFind = state => {
5360
- // TODO
5361
- return {
5362
- ...state,
5363
- focus: FindWidget,
5364
- focusSource: Script
5365
- };
5374
+ return setFindWidgetFocus(state, FindWidget);
5366
5375
  };
5367
5376
  const handleReplaceInput = state => {
5368
5377
  // TODO
5369
5378
  return state;
5370
5379
  };
5371
5380
  const focusToggleReplace = async state => {
5372
- await setFocus(FindWidgetToggleReplace);
5373
- return {
5374
- ...state,
5375
- focus: FindWidgetToggleReplace,
5376
- focusSource: Script
5377
- };
5381
+ return setFindWidgetFocus(state, FindWidgetToggleReplace);
5378
5382
  };
5379
5383
  const handleReplaceAllFocus = async state => {
5380
- if (state.focus === FindWidgetReplaceAll) {
5384
+ if (state.focus === FindWidgetReplaceAllButton) {
5381
5385
  return state;
5382
5386
  }
5383
- await setFocus(FindWidgetReplaceAll);
5387
+ await setFocus(FindWidgetReplaceAllButton);
5384
5388
  return {
5385
5389
  ...state,
5386
- focus: FindWidgetReplaceAll
5390
+ focus: FindWidgetReplaceAllButton
5387
5391
  };
5388
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
+ };
5389
5400
 
5390
5401
  const openFind2 = async editor => {
5391
5402
  const newStateGenerator = async state => {
@@ -5417,7 +5428,8 @@ const openFind2 = async editor => {
5417
5428
  };
5418
5429
  return latestState;
5419
5430
  };
5420
- return addWidgetToEditor(Find, FindWidget, editor, create$1, newStateGenerator);
5431
+ const fullFocus = true;
5432
+ return addWidgetToEditor(Find, FindWidget, editor, create$1, newStateGenerator, fullFocus);
5421
5433
  };
5422
5434
 
5423
5435
  const openFind = async state => {
@@ -8721,7 +8733,9 @@ const widgetCommands = {
8721
8733
  'FindWidget.handleReplaceFocus': Find,
8722
8734
  'FindWidget.focusFind': Find,
8723
8735
  'FindWidget.focusToggleReplace': Find,
8724
- 'FindWidget.focusReplace': Find
8736
+ 'FindWidget.focusReplace': Find,
8737
+ 'FindWidget.focusReplaceButton': Find,
8738
+ 'FindWidget.focusReplaceAllButton': Find
8725
8739
  };
8726
8740
 
8727
8741
  // TODO wrap commands globally, not per editor
@@ -8908,6 +8922,8 @@ const commandMap = {
8908
8922
  'FindWidget.toggleReplace': toggleReplace,
8909
8923
  'FindWidget.handleToggleReplaceFocus': handleToggleReplaceFocus,
8910
8924
  'FindWidget.handleReplaceAllFocus': handleReplaceAllFocus,
8925
+ 'FindWidget.focusReplaceButton': focusReplaceButton,
8926
+ 'FindWidget.focusReplaceAllButton': focusReplaceAllButton,
8911
8927
  'Font.ensure': ensure,
8912
8928
  'Hover.getHoverInfo': getEditorHoverInfo,
8913
8929
  'Hover.handleSashPointerDown': handleSashPointerDown,
@@ -9981,19 +9997,79 @@ const replaceAll = () => {
9981
9997
  return i18nString(UiStrings.ReplaceAll);
9982
9998
  };
9983
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
+
9984
10054
  // TODO always focus element by name
9985
10055
  const getFindWidgetFocusSelector = focus => {
9986
10056
  switch (focus) {
9987
10057
  case FindWidget:
9988
- return `[name="search-value"]`;
10058
+ return `[name="${SearchValue}"]`;
9989
10059
  case FindWidgetReplace:
9990
- return '[name="replace-value"]';
9991
- case FindWidgetReplaceAll:
9992
- return `[name="replaceAll"]`;
9993
- case FindWidgetClose:
9994
- return `[name="close"]`;
10060
+ return `[name="${ReplaceValue}"]`;
10061
+ case FindWidgetReplaceAllButton:
10062
+ return `[name="${ReplaceAll}"]`;
10063
+ case FindWidgetCloseButton:
10064
+ return `[name="${Close}"]`;
9995
10065
  case FindWidgetToggleReplace:
9996
- return `[name="ToggleReplace"]`;
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}"]`;
9997
10073
  default:
9998
10074
  return '';
9999
10075
  }
@@ -10012,7 +10088,9 @@ const getIconButtonVirtualDom = iconButton => {
10012
10088
  const {
10013
10089
  label,
10014
10090
  icon,
10015
- disabled
10091
+ disabled,
10092
+ name,
10093
+ onClick
10016
10094
  } = iconButton;
10017
10095
  let className = IconButton;
10018
10096
  if (disabled) {
@@ -10025,7 +10103,8 @@ const getIconButtonVirtualDom = iconButton => {
10025
10103
  ariaLabel: label,
10026
10104
  childCount: 1,
10027
10105
  disabled: disabled ? true : undefined,
10028
- onClick: iconButton.onClick
10106
+ onClick: onClick,
10107
+ name: name
10029
10108
  }, getIconVirtualDom(icon)];
10030
10109
  };
10031
10110
 
@@ -10153,12 +10232,6 @@ const getMatchCountText = (matchIndex, matchCount) => {
10153
10232
  return matchOf(matchIndex + 1, matchCount);
10154
10233
  };
10155
10234
 
10156
- const ArrowDown = 'ArrowDown';
10157
- const ArrowUp = 'ArrowUp';
10158
- const Close = 'Close';
10159
- const Replace = 'Replace';
10160
- const ReplaceAll = 'ReplaceAll';
10161
-
10162
10235
  const renderValue = {
10163
10236
  isEqual(oldState, newState) {
10164
10237
  return oldState.value === newState.value;
@@ -10174,33 +10247,10 @@ const renderDetails = {
10174
10247
  apply(oldState, newState) {
10175
10248
  const matchCountText = getMatchCountText(newState.matchIndex, newState.matchCount);
10176
10249
  const buttonsEnabled = newState.matchCount > 0;
10177
- const findButtons = [{
10178
- label: previousMatch(),
10179
- icon: ArrowUp,
10180
- disabled: !buttonsEnabled,
10181
- onClick: 'handleClickPreviousMatch'
10182
- }, {
10183
- label: nextMatch(),
10184
- icon: ArrowDown,
10185
- disabled: !buttonsEnabled,
10186
- onClick: 'handleClickNextMatch'
10187
- }, {
10188
- label: close(),
10189
- icon: Close,
10190
- disabled: false,
10191
- onClick: 'handleClickClose'
10192
- }];
10193
- const replaceButtons = [{
10194
- label: replace(),
10195
- icon: Replace,
10196
- disabled: !buttonsEnabled,
10197
- onClick: 'handleClickReplace'
10198
- }, {
10199
- label: replaceAll(),
10200
- icon: ReplaceAll,
10201
- disabled: !buttonsEnabled,
10202
- onClick: 'handleClickReplaceAll'
10203
- }];
10250
+ const {
10251
+ findButtons,
10252
+ replaceButtons
10253
+ } = getFindWidgetButtons(buttonsEnabled);
10204
10254
  const dom = getFindWidgetVirtualDom(matchCountText, newState.replaceExpanded, findButtons, replaceButtons);
10205
10255
  return ['Viewlet.setDom2', dom];
10206
10256
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "3.12.0",
3
+ "version": "3.13.0",
4
4
  "description": "",
5
5
  "main": "dist/testWorkerMain.js",
6
6
  "type": "module",