@lvce-editor/find-widget-worker 1.13.0 → 1.14.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.
@@ -977,7 +977,8 @@ const create$1 = (uid, x, y, width, height, parentUid) => {
977
977
  editorY: y,
978
978
  editorWidth: width,
979
979
  editorHeight: height,
980
- inputSource: 0
980
+ inputSource: 0,
981
+ preserveCase: false
981
982
  };
982
983
  set$3(uid, state, state);
983
984
  return state;
@@ -1010,6 +1011,7 @@ const RenderContent = 13;
1010
1011
  const RenderFocusContext = 14;
1011
1012
  const RenderFocus = 15;
1012
1013
  const RenderValue = 16;
1014
+ const RenderReplaceValue = 17;
1013
1015
 
1014
1016
  const Button = 1;
1015
1017
  const Div = 4;
@@ -1124,7 +1126,7 @@ const activateByEvent = async event => {
1124
1126
  // @ts-ignore
1125
1127
  await invoke$1('ActivateByEvent.activateByEvent', event);
1126
1128
  };
1127
- const applyEdit = async (editorUid, changes) => {
1129
+ const applyEdit$1 = async (editorUid, changes) => {
1128
1130
  // @ts-ignore
1129
1131
  await invoke$1('Editor.applyEdit2', editorUid, changes);
1130
1132
  };
@@ -1189,7 +1191,7 @@ const registerMockRpc = commandMap => {
1189
1191
  const EditorWorker = {
1190
1192
  __proto__: null,
1191
1193
  activateByEvent,
1192
- applyEdit,
1194
+ applyEdit: applyEdit$1,
1193
1195
  applyWorkspaceEdit,
1194
1196
  closeWidget,
1195
1197
  dispose,
@@ -1213,7 +1215,9 @@ const EditorWorker = {
1213
1215
 
1214
1216
  const {
1215
1217
  invoke,
1216
- set} = EditorWorker;
1218
+ set,
1219
+ applyEdit
1220
+ } = EditorWorker;
1217
1221
 
1218
1222
  const setSelections = async (editorUid, selections) => {
1219
1223
  // @ts-ignore
@@ -1286,6 +1290,10 @@ const handleBlur = async state => {
1286
1290
  };
1287
1291
  };
1288
1292
 
1293
+ const handleClickButton = async (state, name) => {
1294
+ return state;
1295
+ };
1296
+
1289
1297
  const close$1 = async state => {
1290
1298
  const {
1291
1299
  editorUid
@@ -1368,6 +1376,17 @@ const handleInput = (state, value, inputSource = User) => {
1368
1376
  return refresh(state, value, inputSource);
1369
1377
  };
1370
1378
 
1379
+ const toggleMatchCase = state => {
1380
+ const {
1381
+ matchCase
1382
+ } = state;
1383
+ // TODO update search results
1384
+ return {
1385
+ ...state,
1386
+ matchCase: !matchCase
1387
+ };
1388
+ };
1389
+
1371
1390
  const getFindWidgetHeight = replaceExpanded => {
1372
1391
  const collapsedHeight = 30;
1373
1392
  const expandedHeight = 60;
@@ -1388,6 +1407,24 @@ const toggleReplace = state => {
1388
1407
  };
1389
1408
  };
1390
1409
 
1410
+ const toggleUseRegularExpression = state => {
1411
+ const {
1412
+ useRegularExpression
1413
+ } = state;
1414
+ return {
1415
+ ...state,
1416
+ useRegularExpression: !useRegularExpression
1417
+ };
1418
+ };
1419
+
1420
+ const handleReplaceInput = (state, value, inputSource = User) => {
1421
+ return {
1422
+ ...state,
1423
+ replacement: value,
1424
+ inputSource
1425
+ };
1426
+ };
1427
+
1391
1428
  const getFindWidgetPosition = (editorX, editorY, editorWidth) => {
1392
1429
  const width = 300;
1393
1430
  const height = 30;
@@ -1492,6 +1529,7 @@ const HandleClickPreviousMatch = 'handleClickPreviousMatch';
1492
1529
  const HandleClickReplace = 'handleClickReplace';
1493
1530
  const HandleClickToggleReplace = 'handleClickToggleReplace';
1494
1531
  const HandleClickReplaceAll = 'handleClickReplaceAll';
1532
+ const HandleClickButton = 'handleClickButton';
1495
1533
  const HandleFocus = 'handleFocus';
1496
1534
  const HandleInput = 'handleInput';
1497
1535
  const HandleReplaceFocus = 'handleReplaceFocus';
@@ -1541,27 +1579,33 @@ const close = () => {
1541
1579
  const find = () => {
1542
1580
  return i18nString(Find$1);
1543
1581
  };
1544
- const replace = () => {
1582
+ const replace$1 = () => {
1545
1583
  return i18nString(Replace$2);
1546
1584
  };
1547
- const replaceAll = () => {
1585
+ const replaceAll$1 = () => {
1548
1586
  return i18nString(ReplaceAll$2);
1549
1587
  };
1550
1588
 
1589
+ const MatchCase$1 = 'CaseSensitive';
1590
+ const UseRegularExpression$1 = 'Regex';
1591
+ const MatchWholeWord$1 = 'WholeWord';
1551
1592
  const ArrowDown = 'ArrowDown';
1552
1593
  const ArrowUp = 'ArrowUp';
1553
1594
  const Close$1 = 'Close';
1554
1595
  const Replace$1 = 'Replace';
1555
1596
  const ReplaceAll$1 = 'ReplaceAll';
1556
1597
 
1557
- const ToggleReplace = 'ToggleReplace';
1558
- const SearchValue = 'search-value';
1559
- const ReplaceValue = 'replace-value';
1560
- const ReplaceAll = 'ReplaceAll';
1561
1598
  const Close = 'Close';
1562
1599
  const FocusNext = 'FocusNext';
1563
1600
  const FocusPrevious = 'FocusPrevious';
1601
+ const MatchCase = 'MatchCase';
1602
+ const MatchWholeWord = 'MatchWholeWord';
1564
1603
  const Replace = 'Replace';
1604
+ const ReplaceAll = 'ReplaceAll';
1605
+ const ReplaceValue = 'replace-value';
1606
+ const SearchValue = 'search-value';
1607
+ const ToggleReplace = 'ToggleReplace';
1608
+ const UseRegularExpression = 'UseRegularExpression';
1565
1609
 
1566
1610
  const getFindWidgetButtons = (findButtonsEnabled, replaceButtonsEnabled) => {
1567
1611
  const findButtons = [{
@@ -1584,13 +1628,13 @@ const getFindWidgetButtons = (findButtonsEnabled, replaceButtonsEnabled) => {
1584
1628
  name: Close
1585
1629
  }];
1586
1630
  const replaceButtons = [{
1587
- label: replace(),
1631
+ label: replace$1(),
1588
1632
  icon: Replace$1,
1589
1633
  disabled: !replaceButtonsEnabled,
1590
1634
  onClick: HandleClickReplace,
1591
1635
  name: Replace
1592
1636
  }, {
1593
- label: replaceAll(),
1637
+ label: replaceAll$1(),
1594
1638
  icon: ReplaceAll$1,
1595
1639
  disabled: !replaceButtonsEnabled,
1596
1640
  onClick: HandleClickReplaceAll,
@@ -1645,6 +1689,25 @@ const ViewletFind = 'ViewletFind';
1645
1689
  const FindWidget = 'FindWidget';
1646
1690
  const ViewletFindWidget = 'ViewletFindWidget';
1647
1691
 
1692
+ const getFindButtons = () => {
1693
+ return [{
1694
+ checked: false,
1695
+ icon: MatchCase$1,
1696
+ title: 'Match Case',
1697
+ name: MatchCase
1698
+ }, {
1699
+ checked: false,
1700
+ icon: MatchWholeWord$1,
1701
+ title: 'Match Whole Word',
1702
+ name: MatchWholeWord
1703
+ }, {
1704
+ checked: false,
1705
+ icon: UseRegularExpression$1,
1706
+ title: 'Use Regular Expression',
1707
+ name: UseRegularExpression
1708
+ }];
1709
+ };
1710
+
1648
1711
  const getFindMatchCountClassName = (matchCount, value) => {
1649
1712
  if (value && matchCount === 0) {
1650
1713
  return mergeClassNames(FindWidgetMatchCount, FindWidgetMatchCountEmpty);
@@ -1701,7 +1764,7 @@ const getSearchFieldButtonVirtualDom = button => {
1701
1764
  childCount: 1
1702
1765
  }, {
1703
1766
  type: Div,
1704
- className: mergeClassNames(MaskIcon, icon),
1767
+ className: mergeClassNames(MaskIcon, `MaskIcon${icon}`),
1705
1768
  childCount: 0
1706
1769
  }];
1707
1770
  };
@@ -1741,7 +1804,7 @@ const getFindWidgetFindVirtualDom = (matchCountText, buttons, matchCount, value)
1741
1804
  className: FindWidgetFind,
1742
1805
  childCount: 5
1743
1806
  });
1744
- dom.push(...getSearchFieldVirtualDom('search-value', find(), HandleInput, [], [], HandleFocus));
1807
+ dom.push(...getSearchFieldVirtualDom(SearchValue, find(), HandleInput, getFindButtons(), [], HandleFocus));
1745
1808
  const findClassName = getFindMatchCountClassName(matchCount, value);
1746
1809
  dom.push({
1747
1810
  type: Div,
@@ -1758,7 +1821,7 @@ const getFindWidgetReplaceVirtualDom = (replaceExpanded, replaceButtons) => {
1758
1821
  type: Div,
1759
1822
  className: FindWidgetReplace,
1760
1823
  childCount: 1 + replaceButtons.length
1761
- }, ...getSearchFieldVirtualDom(ReplaceValue, replace(), HandleReplaceInput, [], [], HandleReplaceFocus), ...replaceButtons.flatMap(getIconButtonVirtualDom));
1824
+ }, ...getSearchFieldVirtualDom(ReplaceValue, replace$1(), HandleReplaceInput, [], [], HandleReplaceFocus), ...replaceButtons.flatMap(getIconButtonVirtualDom));
1762
1825
  }
1763
1826
  return dom;
1764
1827
  };
@@ -1867,6 +1930,9 @@ const getEventListeners = (uid, widgetId) => {
1867
1930
  }, {
1868
1931
  name: HandleClickReplaceAll,
1869
1932
  params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleClickReplaceAll', 0, widgetId]
1933
+ }, {
1934
+ name: HandleClickButton,
1935
+ params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleClickButton', 0, widgetId, `event.target.name`]
1870
1936
  }];
1871
1937
  };
1872
1938
 
@@ -1893,6 +1959,14 @@ const renderFocusContext = (oldState, newState) => {
1893
1959
  return [/* method */SetFocusContext, FocusFindWidget];
1894
1960
  };
1895
1961
 
1962
+ const renderReplaceValue = (oldState, newState) => {
1963
+ const {
1964
+ uid,
1965
+ replacement
1966
+ } = newState;
1967
+ return [SetValueByName, uid, Replace, replacement];
1968
+ };
1969
+
1896
1970
  const renderUid = (oldState, newState) => {
1897
1971
  const {
1898
1972
  uid,
@@ -1925,6 +1999,8 @@ const getRenderer = diffType => {
1925
1999
  return renderFocus;
1926
2000
  case RenderValue:
1927
2001
  return renderValue;
2002
+ case RenderReplaceValue:
2003
+ return renderReplaceValue;
1928
2004
  default:
1929
2005
  throw new Error('unknown renderer');
1930
2006
  }
@@ -1949,6 +2025,63 @@ const render2 = (uid, diffResult) => {
1949
2025
  return commands;
1950
2026
  };
1951
2027
 
2028
+ const applyEdits = async (editorId, edits) => {
2029
+ await applyEdit(editorId, edits);
2030
+ };
2031
+
2032
+ const getEdits = (matches, value, replacement, startIndex, replaceAll) => {
2033
+ if (value.length === 0 || matches.length === 0) {
2034
+ return [];
2035
+ }
2036
+ const edits = [];
2037
+ const totalMatches = Math.floor(matches.length / 2);
2038
+ const fromIndex = replaceAll ? 0 : Math.max(0, startIndex);
2039
+ const toIndex = replaceAll ? totalMatches : Math.min(totalMatches, fromIndex + 1);
2040
+ for (let i = fromIndex; i < toIndex; i++) {
2041
+ const rowIndex = matches[i * 2];
2042
+ const startColumnIndex = matches[i * 2 + 1];
2043
+ const endColumnIndex = startColumnIndex + value.length;
2044
+ edits.push({
2045
+ rowIndex,
2046
+ startColumnIndex,
2047
+ endColumnIndex,
2048
+ newText: replacement
2049
+ });
2050
+ }
2051
+ return edits;
2052
+ };
2053
+
2054
+ const replace = async state => {
2055
+ const {
2056
+ matches,
2057
+ value,
2058
+ replacement,
2059
+ matchIndex,
2060
+ editorUid
2061
+ } = state;
2062
+ const edits = getEdits(matches, value, replacement, matchIndex, false);
2063
+ await applyEdits(editorUid, edits);
2064
+ // TODO ask editor worker to apply edit
2065
+ // TODO ask editor worker for new lines?
2066
+ return {
2067
+ ...state
2068
+ };
2069
+ };
2070
+
2071
+ const replaceAll = state => {
2072
+ const {
2073
+ matches,
2074
+ value,
2075
+ replacement,
2076
+ editorUid
2077
+ } = state;
2078
+ const edits = getEdits(matches, value, replacement, 0, true);
2079
+ void applyEdits(editorUid, edits);
2080
+ return {
2081
+ ...state
2082
+ };
2083
+ };
2084
+
1952
2085
  const commandMap = {
1953
2086
  'FindWidget.create': create$1,
1954
2087
  'FindWidget.diff2': diff2,
@@ -1957,6 +2090,7 @@ const commandMap = {
1957
2090
  'FindWidget.focusFirst': wrapCommand(focusFirst),
1958
2091
  'FindWidget.focusIndex': wrapCommand(focusIndex),
1959
2092
  'FindWidget.focusLast': wrapCommand(focusLast),
2093
+ 'FindWidget.toggleMatchCase': wrapCommand(toggleMatchCase),
1960
2094
  'FindWidget.focusNext': wrapCommand(focusNext),
1961
2095
  'FindWidget.focusPrevious': wrapCommand(focusPrevious),
1962
2096
  'FindWidget.focusReplace': wrapCommand(focusReplace),
@@ -1965,11 +2099,16 @@ const commandMap = {
1965
2099
  'FindWidget.handleBlur': wrapCommand(handleBlur),
1966
2100
  'FindWidget.handleClickClose': wrapCommand(handleClickClose),
1967
2101
  'FindWidget.handleInput': wrapCommand(handleInput),
2102
+ 'FindWidget.handleReplaceInput': wrapCommand(handleReplaceInput),
1968
2103
  'FindWidget.loadContent': wrapCommand(loadContent),
1969
2104
  'FindWidget.preventDefaultBrowserFind': wrapCommand(preventDefaultBrowserFind),
1970
2105
  'FindWidget.render2': render2,
1971
2106
  'FindWidget.terminate': terminate,
1972
- 'FindWidget.toggleReplace': wrapCommand(toggleReplace)
2107
+ 'FindWidget.toggleReplace': wrapCommand(toggleReplace),
2108
+ 'FindWidget.replace': wrapCommand(replace),
2109
+ 'FindWidget.replaceAll': wrapCommand(replaceAll),
2110
+ 'FindWidget.handleClickButton': wrapCommand(handleClickButton),
2111
+ 'FindWidget.toggleUseRegularExpression': wrapCommand(toggleUseRegularExpression)
1973
2112
  };
1974
2113
 
1975
2114
  const listen = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/find-widget-worker",
3
- "version": "1.13.0",
3
+ "version": "1.14.0",
4
4
  "description": "Web Worker for the find widget in Lvce Editor",
5
5
  "repository": {
6
6
  "type": "git",