@lvce-editor/find-widget-worker 1.17.0 → 1.19.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.
@@ -982,7 +982,8 @@ const create$1 = (uid, x, y, width, height, parentUid) => {
982
982
  inputSource: 0,
983
983
  preserveCase: false,
984
984
  resizerPointerDown: false,
985
- minWidth: 300
985
+ minWidth: 400,
986
+ history: []
986
987
  };
987
988
  set$3(uid, state, state);
988
989
  return state;
@@ -1033,9 +1034,10 @@ const TextArea = 62;
1033
1034
 
1034
1035
  const ClientX = 'event.clientX';
1035
1036
  const ClientY = 'event.clientY';
1037
+ const TargetName = 'event.target.name';
1036
1038
 
1037
1039
  const User = 1;
1038
- const Script = 1;
1040
+ const Script = 2;
1039
1041
 
1040
1042
  const EditorWorker$1 = 99;
1041
1043
 
@@ -1431,15 +1433,15 @@ const toggleUseRegularExpression = state => {
1431
1433
  const Close$2 = 'Close';
1432
1434
  const FocusNext = 'FocusNext';
1433
1435
  const FocusPrevious = 'FocusPrevious';
1434
- const MatchCase$1 = 'MatchCase';
1435
- const MatchWholeWord$1 = 'MatchWholeWord';
1436
- const PreserveCase = 'PreserveCase';
1436
+ const MatchCase$2 = 'MatchCase';
1437
+ const MatchWholeWord$2 = 'MatchWholeWord';
1438
+ const PreserveCase$1 = 'PreserveCase';
1437
1439
  const Replace$2 = 'Replace';
1438
1440
  const ReplaceAll$2 = 'ReplaceAll';
1439
1441
  const ReplaceValue = 'replace-value';
1440
1442
  const SearchValue = 'search-value';
1441
1443
  const ToggleReplace$1 = 'ToggleReplace';
1442
- const UseRegularExpression$1 = 'UseRegularExpression';
1444
+ const UseRegularExpression$2 = 'UseRegularExpression';
1443
1445
 
1444
1446
  const applyEdits = async (editorId, edits) => {
1445
1447
  // @ts-ignore
@@ -1512,13 +1514,13 @@ const getClickHandler = name => {
1512
1514
  return replace$1;
1513
1515
  case ReplaceAll$2:
1514
1516
  return replaceAll$1;
1515
- case MatchCase$1:
1517
+ case MatchCase$2:
1516
1518
  return toggleMatchCase;
1517
- case MatchWholeWord$1:
1519
+ case MatchWholeWord$2:
1518
1520
  return toggleMatchWholeWord;
1519
- case UseRegularExpression$1:
1521
+ case UseRegularExpression$2:
1520
1522
  return toggleUseRegularExpression;
1521
- case PreserveCase:
1523
+ case PreserveCase$1:
1522
1524
  return togglePreserveCase;
1523
1525
  default:
1524
1526
  throw new Error(`unexpected click`);
@@ -1569,10 +1571,13 @@ const handleResizerPointerDown = async (state, eventX, eventY) => {
1569
1571
  };
1570
1572
  };
1571
1573
 
1572
- const getNewWidth = (oldWidth, oldX, eventX, minWidth) => {
1574
+ const getNewCoordinates = (oldWidth, oldX, eventX, minWidth) => {
1573
1575
  const oldXEnd = oldX + oldWidth;
1574
1576
  const newWidth = Math.max(oldXEnd - eventX, minWidth);
1575
- return newWidth;
1577
+ return {
1578
+ newWidth,
1579
+ newX: eventX
1580
+ };
1576
1581
  };
1577
1582
  const handleResizerPointerMove = async (state, eventX, eventY) => {
1578
1583
  const {
@@ -1584,10 +1589,13 @@ const handleResizerPointerMove = async (state, eventX, eventY) => {
1584
1589
  if (!resizerPointerDown) {
1585
1590
  return state;
1586
1591
  }
1587
- const newWidth = getNewWidth(width, x, eventX, minWidth);
1592
+ const {
1593
+ newWidth,
1594
+ newX
1595
+ } = getNewCoordinates(width, x, eventX, minWidth);
1588
1596
  return {
1589
1597
  ...state,
1590
- x: eventX,
1598
+ x: newX,
1591
1599
  width: newWidth
1592
1600
  };
1593
1601
  };
@@ -1679,13 +1687,38 @@ const getSelections = async editorUid => {
1679
1687
  return selections;
1680
1688
  };
1681
1689
 
1682
- const loadContent = async state => {
1690
+ const getSavedValue = savedState => {
1691
+ if (savedState && savedState.value) {
1692
+ return savedState.value;
1693
+ }
1694
+ return '';
1695
+ };
1696
+ const getSavedReplacement = savedState => {
1697
+ if (savedState && savedState.replacement) {
1698
+ return savedState.replacement;
1699
+ }
1700
+ return '';
1701
+ };
1702
+ const restoreState = savedState => {
1703
+ const value = getSavedValue(savedState);
1704
+ const replacement = getSavedReplacement(savedState);
1705
+ return {
1706
+ value,
1707
+ replacement
1708
+ };
1709
+ };
1710
+
1711
+ const loadContent = async (state, savedState) => {
1683
1712
  const {
1684
1713
  editorUid,
1685
1714
  editorWidth,
1686
1715
  editorX,
1687
1716
  editorY
1688
1717
  } = state;
1718
+ const {
1719
+ replacement,
1720
+ value
1721
+ } = restoreState(savedState);
1689
1722
  const lines = await getLines(editorUid);
1690
1723
  const selections = await getSelections(editorUid);
1691
1724
  const {
@@ -1697,24 +1730,25 @@ const loadContent = async state => {
1697
1730
  if (lines.length === 0) {
1698
1731
  return state;
1699
1732
  }
1700
- const value = getSelectedText(lines, selections);
1701
- const matches = findMatchesCaseInsensitive(lines, value);
1733
+ const actualValue = value || getSelectedText(lines, selections);
1734
+ const matches = findMatchesCaseInsensitive(lines, actualValue);
1702
1735
  const matchCount = getMatchCount(matches);
1703
1736
  return {
1704
1737
  ...state,
1705
- value,
1738
+ focused: true,
1739
+ height,
1740
+ inputSource: Script,
1741
+ lines,
1742
+ matchCount,
1706
1743
  matches,
1707
1744
  matchIndex: 0,
1708
- matchCount,
1745
+ replacement,
1746
+ selections,
1747
+ value: actualValue,
1709
1748
  version: 1,
1710
- x,
1711
- y,
1712
1749
  width,
1713
- height,
1714
- lines,
1715
- selections,
1716
- focused: true,
1717
- inputSource: Script
1750
+ x,
1751
+ y
1718
1752
  };
1719
1753
  };
1720
1754
 
@@ -1771,17 +1805,24 @@ const i18nString = (key, placeholders = emptyObject) => {
1771
1805
 
1772
1806
  const MatchOf = '{PH1} of {PH2}';
1773
1807
  const NoResults = 'No Results';
1808
+ const PreserveCase = 'Preserve Case';
1774
1809
  const Close$1 = 'Close';
1775
1810
  const PreviousMatch = 'Previous Match';
1776
1811
  const NextMatch = 'Next Match';
1777
1812
  const Find$1 = 'Find';
1778
1813
  const Replace$1 = 'Replace';
1779
1814
  const ReplaceAll$1 = 'Replace All';
1815
+ const MatchCase$1 = 'Match Case';
1816
+ const MatchWholeWord$1 = 'Match Whole Word';
1817
+ const UseRegularExpression$1 = 'Use Regular Expression';
1780
1818
  const ToggleReplace = 'Toggle Replace';
1781
1819
 
1782
1820
  const noResults = () => {
1783
1821
  return i18nString(NoResults);
1784
1822
  };
1823
+ const preserveCase = () => {
1824
+ return i18nString(PreserveCase);
1825
+ };
1785
1826
  const matchOf = (matchIndex, matchCount) => {
1786
1827
  return i18nString(MatchOf, {
1787
1828
  PH1: matchIndex,
@@ -1806,6 +1847,15 @@ const replace = () => {
1806
1847
  const replaceAll = () => {
1807
1848
  return i18nString(ReplaceAll$1);
1808
1849
  };
1850
+ const matchCase = () => {
1851
+ return i18nString(MatchCase$1);
1852
+ };
1853
+ const matchWholeWord = () => {
1854
+ return i18nString(MatchWholeWord$1);
1855
+ };
1856
+ const useRegularExpression = () => {
1857
+ return i18nString(UseRegularExpression$1);
1858
+ };
1809
1859
  const toggleReplace = () => {
1810
1860
  return i18nString(ToggleReplace);
1811
1861
  };
@@ -1819,7 +1869,33 @@ const Close = 'Close';
1819
1869
  const Replace = 'Replace';
1820
1870
  const ReplaceAll = 'ReplaceAll';
1821
1871
 
1822
- const getFindWidgetButtons = (findButtonsEnabled, replaceButtonsEnabled) => {
1872
+ const getFindWidgetButtons = (findButtonsEnabled, replaceButtonsEnabled, matchCase$1, matchWholeWord$1, useRegularExpression$1, preserveCase$1) => {
1873
+ const findFieldButtons = [{
1874
+ checked: matchCase$1,
1875
+ icon: MatchCase,
1876
+ title: matchCase(),
1877
+ name: MatchCase$2,
1878
+ onClick: HandleClickButton
1879
+ }, {
1880
+ checked: matchWholeWord$1,
1881
+ icon: MatchWholeWord,
1882
+ title: matchWholeWord(),
1883
+ name: MatchWholeWord$2,
1884
+ onClick: HandleClickButton
1885
+ }, {
1886
+ checked: useRegularExpression$1,
1887
+ icon: UseRegularExpression,
1888
+ title: useRegularExpression(),
1889
+ name: UseRegularExpression$2,
1890
+ onClick: HandleClickButton
1891
+ }];
1892
+ const replaceFieldButtons = [{
1893
+ checked: preserveCase$1,
1894
+ icon: 'PreserveCase',
1895
+ title: preserveCase(),
1896
+ name: PreserveCase$1,
1897
+ onClick: HandleClickButton
1898
+ }];
1823
1899
  const findButtons = [{
1824
1900
  label: previousMatch(),
1825
1901
  icon: ArrowUp,
@@ -1843,18 +1919,20 @@ const getFindWidgetButtons = (findButtonsEnabled, replaceButtonsEnabled) => {
1843
1919
  label: replace(),
1844
1920
  icon: Replace,
1845
1921
  disabled: !replaceButtonsEnabled,
1846
- onClick: HandleClickReplace,
1922
+ onClick: HandleClickButton,
1847
1923
  name: Replace$2
1848
1924
  }, {
1849
1925
  label: replaceAll(),
1850
1926
  icon: ReplaceAll,
1851
1927
  disabled: !replaceButtonsEnabled,
1852
- onClick: HandleClickReplaceAll,
1928
+ onClick: HandleClickButton,
1853
1929
  name: ReplaceAll$2
1854
1930
  }];
1855
1931
  return {
1856
1932
  findButtons,
1857
- replaceButtons
1933
+ findFieldButtons,
1934
+ replaceButtons,
1935
+ replaceFieldButtons
1858
1936
  };
1859
1937
  };
1860
1938
 
@@ -1896,28 +1974,12 @@ const Viewlet = 'Viewlet';
1896
1974
  const ViewletFind = 'ViewletFind';
1897
1975
  const FindWidget = 'FindWidget';
1898
1976
  const ViewletFindWidget = 'ViewletFindWidget';
1899
-
1900
- const getFindButtons = () => {
1901
- return [{
1902
- checked: false,
1903
- icon: MatchCase,
1904
- title: 'Match Case',
1905
- name: MatchCase$1,
1906
- onClick: HandleClickButton
1907
- }, {
1908
- checked: false,
1909
- icon: MatchWholeWord,
1910
- title: 'Match Whole Word',
1911
- name: MatchWholeWord$1,
1912
- onClick: HandleClickButton
1913
- }, {
1914
- checked: false,
1915
- icon: UseRegularExpression,
1916
- title: 'Use Regular Expression',
1917
- name: UseRegularExpression$1,
1918
- onClick: HandleClickButton
1919
- }];
1920
- };
1977
+ const Resizer = 'Resizer';
1978
+ const ResizerHighlight = 'ResizerHighlight';
1979
+ const SearchToggleButton = 'SearchToggleButton';
1980
+ const SearchToggleButtonExpanded = 'SearchToggleButtonExpanded';
1981
+ const MaskIconChevronDown = 'MaskIconChevronDown';
1982
+ const MaskIconChevronRight = 'MaskIconChevronRight';
1921
1983
 
1922
1984
  const getFindMatchCountClassName = (matchCount, value) => {
1923
1985
  if (value && matchCount === 0) {
@@ -1929,7 +1991,7 @@ const getFindMatchCountClassName = (matchCount, value) => {
1929
1991
  const getIconVirtualDom = (icon, type = Div) => {
1930
1992
  return {
1931
1993
  type,
1932
- className: `MaskIcon MaskIcon${icon}`,
1994
+ className: `${MaskIcon} MaskIcon${icon}`,
1933
1995
  role: None,
1934
1996
  childCount: 0
1935
1997
  };
@@ -1954,11 +2016,13 @@ const getIconButtonVirtualDom = iconButton => {
1954
2016
  ariaLabel: label,
1955
2017
  childCount: 1,
1956
2018
  disabled: disabled ? true : undefined,
1957
- onClick: onClick,
1958
- name: name
2019
+ onClick,
2020
+ name
1959
2021
  }, getIconVirtualDom(icon)];
1960
2022
  };
1961
2023
 
2024
+ const checkedClassName = mergeClassNames(SearchFieldButton, SearchFieldButtonChecked);
2025
+ const unCheckedClassName = SearchFieldButton;
1962
2026
  const getSearchFieldButtonVirtualDom = button => {
1963
2027
  const {
1964
2028
  icon,
@@ -1968,9 +2032,9 @@ const getSearchFieldButtonVirtualDom = button => {
1968
2032
  onClick
1969
2033
  } = button;
1970
2034
  return [{
1971
- type: Div,
2035
+ type: Button,
1972
2036
  ariaChecked: checked,
1973
- className: mergeClassNames(SearchFieldButton, checked ? SearchFieldButtonChecked : ''),
2037
+ className: checked ? checkedClassName : unCheckedClassName,
1974
2038
  name,
1975
2039
  role: CheckBox,
1976
2040
  tabIndex: 0,
@@ -2012,44 +2076,38 @@ const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, out
2012
2076
  return dom;
2013
2077
  };
2014
2078
 
2015
- const getFindWidgetFindVirtualDom = (matchCountText, buttons, matchCount, value) => {
2016
- const dom = [];
2017
- dom.push({
2079
+ const getFindWidgetFindVirtualDom = (matchCountText, buttons, fieldButtons, matchCount, value) => {
2080
+ return [{
2018
2081
  type: Div,
2019
2082
  className: FindWidgetFind,
2020
2083
  childCount: 5
2021
- });
2022
- dom.push(...getSearchFieldVirtualDom(SearchValue, find(), HandleInput, getFindButtons(), [], HandleFocus));
2023
- const findClassName = getFindMatchCountClassName(matchCount, value);
2024
- dom.push({
2084
+ }, ...getSearchFieldVirtualDom(SearchValue, find(), HandleInput, fieldButtons, [], HandleFocus), {
2025
2085
  type: Div,
2026
- className: findClassName,
2086
+ className: getFindMatchCountClassName(matchCount, value),
2027
2087
  childCount: 1
2028
- }, text(matchCountText), ...buttons.flatMap(getIconButtonVirtualDom));
2029
- return dom;
2088
+ }, text(matchCountText), ...buttons.flatMap(getIconButtonVirtualDom)];
2030
2089
  };
2031
2090
 
2032
- const getFindWidgetReplaceVirtualDom = (replaceExpanded, replaceButtons) => {
2033
- const dom = [];
2034
- if (replaceExpanded) {
2035
- dom.push({
2036
- type: Div,
2037
- className: FindWidgetReplace,
2038
- childCount: 1 + replaceButtons.length
2039
- }, ...getSearchFieldVirtualDom(ReplaceValue, replace(), HandleReplaceInput, [], [], HandleReplaceFocus), ...replaceButtons.flatMap(getIconButtonVirtualDom));
2091
+ const getFindWidgetReplaceVirtualDom = (replaceExpanded, replaceButtons, replaceFieldButtons) => {
2092
+ if (!replaceExpanded) {
2093
+ return [];
2040
2094
  }
2041
- return dom;
2095
+ return [{
2096
+ type: Div,
2097
+ className: FindWidgetReplace,
2098
+ childCount: 1 + replaceButtons.length
2099
+ }, ...getSearchFieldVirtualDom(ReplaceValue, replace(), HandleReplaceInput, [], [], HandleReplaceFocus), ...replaceButtons.flatMap(getIconButtonVirtualDom)];
2042
2100
  };
2043
2101
 
2044
2102
  const getResizerVirtualDom = () => {
2045
2103
  return [{
2046
2104
  type: Div,
2047
- className: 'Resizer',
2105
+ className: Resizer,
2048
2106
  childCount: 1,
2049
2107
  onPointerDown: HandleResizerPointerDown
2050
2108
  }, {
2051
2109
  type: Div,
2052
- className: 'ResizerHighlight',
2110
+ className: ResizerHighlight,
2053
2111
  childCount: 0
2054
2112
  }];
2055
2113
  };
@@ -2058,7 +2116,7 @@ const getSearchToggleButtonVirtualDom = (replaceExpanded, onClick = '') => {
2058
2116
  const title = toggleReplace();
2059
2117
  return [{
2060
2118
  type: Button,
2061
- className: `IconButton SearchToggleButton ${replaceExpanded ? 'SearchToggleButtonExpanded' : ''}`,
2119
+ className: mergeClassNames(IconButton, SearchToggleButton, replaceExpanded ? SearchToggleButtonExpanded : ''),
2062
2120
  title,
2063
2121
  ariaLabel: title,
2064
2122
  ariaExpanded: replaceExpanded,
@@ -2069,31 +2127,23 @@ const getSearchToggleButtonVirtualDom = (replaceExpanded, onClick = '') => {
2069
2127
  onFocus: HandleToggleReplaceFocus
2070
2128
  }, {
2071
2129
  type: Div,
2072
- className: `MaskIcon ${replaceExpanded ? 'MaskIconChevronDown' : 'MaskIconChevronRight'}`,
2130
+ className: mergeClassNames(MaskIcon, replaceExpanded ? MaskIconChevronDown : MaskIconChevronRight),
2073
2131
  childCount: 0
2074
2132
  }];
2075
2133
  };
2076
2134
 
2077
- const getFindWidgetVirtualDom = (matchCountText, replaceExpanded, findButtons, replaceButtons, matchCase, matchWholeWord, useRegularExpression, matchCount, value) => {
2078
- const dom = [];
2079
- dom.push({
2080
- type: Div,
2081
- className: mergeClassNames(Viewlet, ViewletFind, ViewletFindWidget, FindWidget),
2082
- childCount: 3,
2083
- role: Group
2084
- });
2085
- dom.push(...getResizerVirtualDom());
2086
- dom.push(...getSearchToggleButtonVirtualDom(replaceExpanded, 'handleClickToggleReplace'));
2087
- dom.push({
2135
+ const parentNode = {
2136
+ type: Div,
2137
+ className: mergeClassNames(Viewlet, ViewletFind, ViewletFindWidget, FindWidget),
2138
+ childCount: 3,
2139
+ role: Group
2140
+ };
2141
+ const getFindWidgetVirtualDom = (matchCountText, replaceExpanded, findButtons, findFieldButtons, replaceButtons, replaceFieldButtons, matchCount, value) => {
2142
+ return [parentNode, ...getResizerVirtualDom(), ...getSearchToggleButtonVirtualDom(replaceExpanded, 'handleClickToggleReplace'), {
2088
2143
  type: Div,
2089
2144
  className: FindWidgetRight,
2090
2145
  childCount: replaceExpanded ? 2 : 1
2091
- });
2092
- dom.push(...getFindWidgetFindVirtualDom(matchCountText, findButtons, matchCount, value));
2093
- if (replaceExpanded) {
2094
- dom.push(...getFindWidgetReplaceVirtualDom(replaceExpanded, replaceButtons));
2095
- }
2096
- return dom;
2146
+ }, ...getFindWidgetFindVirtualDom(matchCountText, findButtons, findFieldButtons, matchCount, value), ...getFindWidgetReplaceVirtualDom(replaceExpanded, replaceButtons)];
2097
2147
  };
2098
2148
 
2099
2149
  const getMatchCountText = (matchIndex, matchCount) => {
@@ -2105,18 +2155,27 @@ const getMatchCountText = (matchIndex, matchCount) => {
2105
2155
 
2106
2156
  const renderContent = (oldState, newState) => {
2107
2157
  const {
2108
- uid
2158
+ uid,
2159
+ matchCount,
2160
+ value,
2161
+ replaceExpanded,
2162
+ matchCase,
2163
+ matchWholeWord,
2164
+ useRegularExpression,
2165
+ preserveCase
2109
2166
  } = newState;
2110
2167
  const matchCountText = getMatchCountText(newState.matchIndex, newState.matchCount);
2111
2168
  const {
2112
2169
  findButtonsEnabled,
2113
2170
  replaceButtonsEnabled
2114
- } = getFindWidgetButtonsEnabled(newState.matchCount, newState.value);
2171
+ } = getFindWidgetButtonsEnabled(matchCount, value);
2115
2172
  const {
2116
2173
  findButtons,
2117
- replaceButtons
2118
- } = getFindWidgetButtons(findButtonsEnabled, replaceButtonsEnabled);
2119
- const dom = getFindWidgetVirtualDom(matchCountText, newState.replaceExpanded, findButtons, replaceButtons, newState.matchCase, newState.matchWholeWord, newState.useRegularExpression, newState.matchCount, newState.value);
2174
+ replaceButtons,
2175
+ findFieldButtons,
2176
+ replaceFieldButtons
2177
+ } = getFindWidgetButtons(findButtonsEnabled, replaceButtonsEnabled, matchCase, matchWholeWord, useRegularExpression, preserveCase);
2178
+ const dom = getFindWidgetVirtualDom(matchCountText, replaceExpanded, findButtons, findFieldButtons, replaceButtons, replaceFieldButtons, matchCount, value);
2120
2179
  return [SetDom2, uid, dom];
2121
2180
  };
2122
2181
 
@@ -2179,7 +2238,7 @@ const getEventListeners = (uid, widgetId) => {
2179
2238
  params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleClickReplaceAll', 0, widgetId]
2180
2239
  }, {
2181
2240
  name: HandleClickButton,
2182
- params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleClickButton', 0, widgetId, `event.target.name`]
2241
+ params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleClickButton', 0, widgetId, TargetName]
2183
2242
  }, {
2184
2243
  name: HandleResizerPointerDown,
2185
2244
  params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleResizerPointerDown', 0, widgetId, ClientX, ClientY],
@@ -2290,10 +2349,22 @@ const resize = async (state, dimensions) => {
2290
2349
 
2291
2350
  const saveState = state => {
2292
2351
  const {
2293
- width
2352
+ width,
2353
+ value,
2354
+ replacement,
2355
+ matchCase,
2356
+ matchWholeWord,
2357
+ useRegularExpression,
2358
+ replaceExpanded
2294
2359
  } = state;
2295
2360
  return {
2296
- width
2361
+ width,
2362
+ value,
2363
+ replacement,
2364
+ matchCase,
2365
+ matchWholeWord,
2366
+ useRegularExpression,
2367
+ replaceExpanded
2297
2368
  };
2298
2369
  };
2299
2370
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/find-widget-worker",
3
- "version": "1.17.0",
3
+ "version": "1.19.0",
4
4
  "description": "Web Worker for the find widget in Lvce Editor",
5
5
  "repository": {
6
6
  "type": "git",