@lvce-editor/find-widget-worker 1.18.0 → 1.20.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: 400
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
  };
@@ -1797,17 +1805,24 @@ const i18nString = (key, placeholders = emptyObject) => {
1797
1805
 
1798
1806
  const MatchOf = '{PH1} of {PH2}';
1799
1807
  const NoResults = 'No Results';
1808
+ const PreserveCase = 'Preserve Case';
1800
1809
  const Close$1 = 'Close';
1801
1810
  const PreviousMatch = 'Previous Match';
1802
1811
  const NextMatch = 'Next Match';
1803
1812
  const Find$1 = 'Find';
1804
1813
  const Replace$1 = 'Replace';
1805
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';
1806
1818
  const ToggleReplace = 'Toggle Replace';
1807
1819
 
1808
1820
  const noResults = () => {
1809
1821
  return i18nString(NoResults);
1810
1822
  };
1823
+ const preserveCase = () => {
1824
+ return i18nString(PreserveCase);
1825
+ };
1811
1826
  const matchOf = (matchIndex, matchCount) => {
1812
1827
  return i18nString(MatchOf, {
1813
1828
  PH1: matchIndex,
@@ -1832,6 +1847,15 @@ const replace = () => {
1832
1847
  const replaceAll = () => {
1833
1848
  return i18nString(ReplaceAll$1);
1834
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
+ };
1835
1859
  const toggleReplace = () => {
1836
1860
  return i18nString(ToggleReplace);
1837
1861
  };
@@ -1845,7 +1869,33 @@ const Close = 'Close';
1845
1869
  const Replace = 'Replace';
1846
1870
  const ReplaceAll = 'ReplaceAll';
1847
1871
 
1848
- 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
+ }];
1849
1899
  const findButtons = [{
1850
1900
  label: previousMatch(),
1851
1901
  icon: ArrowUp,
@@ -1869,18 +1919,20 @@ const getFindWidgetButtons = (findButtonsEnabled, replaceButtonsEnabled) => {
1869
1919
  label: replace(),
1870
1920
  icon: Replace,
1871
1921
  disabled: !replaceButtonsEnabled,
1872
- onClick: HandleClickReplace,
1922
+ onClick: HandleClickButton,
1873
1923
  name: Replace$2
1874
1924
  }, {
1875
1925
  label: replaceAll(),
1876
1926
  icon: ReplaceAll,
1877
1927
  disabled: !replaceButtonsEnabled,
1878
- onClick: HandleClickReplaceAll,
1928
+ onClick: HandleClickButton,
1879
1929
  name: ReplaceAll$2
1880
1930
  }];
1881
1931
  return {
1882
1932
  findButtons,
1883
- replaceButtons
1933
+ findFieldButtons,
1934
+ replaceButtons,
1935
+ replaceFieldButtons
1884
1936
  };
1885
1937
  };
1886
1938
 
@@ -1922,28 +1974,12 @@ const Viewlet = 'Viewlet';
1922
1974
  const ViewletFind = 'ViewletFind';
1923
1975
  const FindWidget = 'FindWidget';
1924
1976
  const ViewletFindWidget = 'ViewletFindWidget';
1925
-
1926
- const getFindButtons = () => {
1927
- return [{
1928
- checked: false,
1929
- icon: MatchCase,
1930
- title: 'Match Case',
1931
- name: MatchCase$1,
1932
- onClick: HandleClickButton
1933
- }, {
1934
- checked: false,
1935
- icon: MatchWholeWord,
1936
- title: 'Match Whole Word',
1937
- name: MatchWholeWord$1,
1938
- onClick: HandleClickButton
1939
- }, {
1940
- checked: false,
1941
- icon: UseRegularExpression,
1942
- title: 'Use Regular Expression',
1943
- name: UseRegularExpression$1,
1944
- onClick: HandleClickButton
1945
- }];
1946
- };
1977
+ const Resizer = 'Resizer';
1978
+ const ResizerHighlight = 'ResizerHighlight';
1979
+ const SearchToggleButton = 'SearchToggleButton';
1980
+ const SearchToggleButtonExpanded = 'SearchToggleButtonExpanded';
1981
+ const MaskIconChevronDown = 'MaskIconChevronDown';
1982
+ const MaskIconChevronRight = 'MaskIconChevronRight';
1947
1983
 
1948
1984
  const getFindMatchCountClassName = (matchCount, value) => {
1949
1985
  if (value && matchCount === 0) {
@@ -1955,7 +1991,7 @@ const getFindMatchCountClassName = (matchCount, value) => {
1955
1991
  const getIconVirtualDom = (icon, type = Div) => {
1956
1992
  return {
1957
1993
  type,
1958
- className: `MaskIcon MaskIcon${icon}`,
1994
+ className: `${MaskIcon} MaskIcon${icon}`,
1959
1995
  role: None,
1960
1996
  childCount: 0
1961
1997
  };
@@ -1980,11 +2016,13 @@ const getIconButtonVirtualDom = iconButton => {
1980
2016
  ariaLabel: label,
1981
2017
  childCount: 1,
1982
2018
  disabled: disabled ? true : undefined,
1983
- onClick: onClick,
1984
- name: name
2019
+ onClick,
2020
+ name
1985
2021
  }, getIconVirtualDom(icon)];
1986
2022
  };
1987
2023
 
2024
+ const checkedClassName = mergeClassNames(SearchFieldButton, SearchFieldButtonChecked);
2025
+ const unCheckedClassName = SearchFieldButton;
1988
2026
  const getSearchFieldButtonVirtualDom = button => {
1989
2027
  const {
1990
2028
  icon,
@@ -1994,9 +2032,9 @@ const getSearchFieldButtonVirtualDom = button => {
1994
2032
  onClick
1995
2033
  } = button;
1996
2034
  return [{
1997
- type: Div,
2035
+ type: Button,
1998
2036
  ariaChecked: checked,
1999
- className: mergeClassNames(SearchFieldButton, checked ? SearchFieldButtonChecked : ''),
2037
+ className: checked ? checkedClassName : unCheckedClassName,
2000
2038
  name,
2001
2039
  role: CheckBox,
2002
2040
  tabIndex: 0,
@@ -2038,44 +2076,38 @@ const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, out
2038
2076
  return dom;
2039
2077
  };
2040
2078
 
2041
- const getFindWidgetFindVirtualDom = (matchCountText, buttons, matchCount, value) => {
2042
- const dom = [];
2043
- dom.push({
2079
+ const getFindWidgetFindVirtualDom = (matchCountText, buttons, fieldButtons, matchCount, value) => {
2080
+ return [{
2044
2081
  type: Div,
2045
2082
  className: FindWidgetFind,
2046
2083
  childCount: 5
2047
- });
2048
- dom.push(...getSearchFieldVirtualDom(SearchValue, find(), HandleInput, getFindButtons(), [], HandleFocus));
2049
- const findClassName = getFindMatchCountClassName(matchCount, value);
2050
- dom.push({
2084
+ }, ...getSearchFieldVirtualDom(SearchValue, find(), HandleInput, fieldButtons, [], HandleFocus), {
2051
2085
  type: Div,
2052
- className: findClassName,
2086
+ className: getFindMatchCountClassName(matchCount, value),
2053
2087
  childCount: 1
2054
- }, text(matchCountText), ...buttons.flatMap(getIconButtonVirtualDom));
2055
- return dom;
2088
+ }, text(matchCountText), ...buttons.flatMap(getIconButtonVirtualDom)];
2056
2089
  };
2057
2090
 
2058
- const getFindWidgetReplaceVirtualDom = (replaceExpanded, replaceButtons) => {
2059
- const dom = [];
2060
- if (replaceExpanded) {
2061
- dom.push({
2062
- type: Div,
2063
- className: FindWidgetReplace,
2064
- childCount: 1 + replaceButtons.length
2065
- }, ...getSearchFieldVirtualDom(ReplaceValue, replace(), HandleReplaceInput, [], [], HandleReplaceFocus), ...replaceButtons.flatMap(getIconButtonVirtualDom));
2091
+ const getFindWidgetReplaceVirtualDom = (replaceExpanded, replaceButtons, replaceFieldButtons) => {
2092
+ if (!replaceExpanded) {
2093
+ return [];
2066
2094
  }
2067
- return dom;
2095
+ return [{
2096
+ type: Div,
2097
+ className: FindWidgetReplace,
2098
+ childCount: 1 + replaceButtons.length
2099
+ }, ...getSearchFieldVirtualDom(ReplaceValue, replace(), HandleReplaceInput, [], [], HandleReplaceFocus), ...replaceButtons.flatMap(getIconButtonVirtualDom)];
2068
2100
  };
2069
2101
 
2070
2102
  const getResizerVirtualDom = () => {
2071
2103
  return [{
2072
2104
  type: Div,
2073
- className: 'Resizer',
2105
+ className: Resizer,
2074
2106
  childCount: 1,
2075
2107
  onPointerDown: HandleResizerPointerDown
2076
2108
  }, {
2077
2109
  type: Div,
2078
- className: 'ResizerHighlight',
2110
+ className: ResizerHighlight,
2079
2111
  childCount: 0
2080
2112
  }];
2081
2113
  };
@@ -2084,7 +2116,7 @@ const getSearchToggleButtonVirtualDom = (replaceExpanded, onClick = '') => {
2084
2116
  const title = toggleReplace();
2085
2117
  return [{
2086
2118
  type: Button,
2087
- className: `IconButton SearchToggleButton ${replaceExpanded ? 'SearchToggleButtonExpanded' : ''}`,
2119
+ className: mergeClassNames(IconButton, SearchToggleButton, replaceExpanded ? SearchToggleButtonExpanded : ''),
2088
2120
  title,
2089
2121
  ariaLabel: title,
2090
2122
  ariaExpanded: replaceExpanded,
@@ -2095,31 +2127,23 @@ const getSearchToggleButtonVirtualDom = (replaceExpanded, onClick = '') => {
2095
2127
  onFocus: HandleToggleReplaceFocus
2096
2128
  }, {
2097
2129
  type: Div,
2098
- className: `MaskIcon ${replaceExpanded ? 'MaskIconChevronDown' : 'MaskIconChevronRight'}`,
2130
+ className: mergeClassNames(MaskIcon, replaceExpanded ? MaskIconChevronDown : MaskIconChevronRight),
2099
2131
  childCount: 0
2100
2132
  }];
2101
2133
  };
2102
2134
 
2103
- const getFindWidgetVirtualDom = (matchCountText, replaceExpanded, findButtons, replaceButtons, matchCase, matchWholeWord, useRegularExpression, matchCount, value) => {
2104
- const dom = [];
2105
- dom.push({
2106
- type: Div,
2107
- className: mergeClassNames(Viewlet, ViewletFind, ViewletFindWidget, FindWidget),
2108
- childCount: 3,
2109
- role: Group
2110
- });
2111
- dom.push(...getResizerVirtualDom());
2112
- dom.push(...getSearchToggleButtonVirtualDom(replaceExpanded, 'handleClickToggleReplace'));
2113
- 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'), {
2114
2143
  type: Div,
2115
2144
  className: FindWidgetRight,
2116
2145
  childCount: replaceExpanded ? 2 : 1
2117
- });
2118
- dom.push(...getFindWidgetFindVirtualDom(matchCountText, findButtons, matchCount, value));
2119
- if (replaceExpanded) {
2120
- dom.push(...getFindWidgetReplaceVirtualDom(replaceExpanded, replaceButtons));
2121
- }
2122
- return dom;
2146
+ }, ...getFindWidgetFindVirtualDom(matchCountText, findButtons, findFieldButtons, matchCount, value), ...getFindWidgetReplaceVirtualDom(replaceExpanded, replaceButtons)];
2123
2147
  };
2124
2148
 
2125
2149
  const getMatchCountText = (matchIndex, matchCount) => {
@@ -2131,18 +2155,27 @@ const getMatchCountText = (matchIndex, matchCount) => {
2131
2155
 
2132
2156
  const renderContent = (oldState, newState) => {
2133
2157
  const {
2134
- uid
2158
+ uid,
2159
+ matchCount,
2160
+ value,
2161
+ replaceExpanded,
2162
+ matchCase,
2163
+ matchWholeWord,
2164
+ useRegularExpression,
2165
+ preserveCase
2135
2166
  } = newState;
2136
2167
  const matchCountText = getMatchCountText(newState.matchIndex, newState.matchCount);
2137
2168
  const {
2138
2169
  findButtonsEnabled,
2139
2170
  replaceButtonsEnabled
2140
- } = getFindWidgetButtonsEnabled(newState.matchCount, newState.value);
2171
+ } = getFindWidgetButtonsEnabled(matchCount, value);
2141
2172
  const {
2142
2173
  findButtons,
2143
- replaceButtons
2144
- } = getFindWidgetButtons(findButtonsEnabled, replaceButtonsEnabled);
2145
- 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);
2146
2179
  return [SetDom2, uid, dom];
2147
2180
  };
2148
2181
 
@@ -2205,7 +2238,7 @@ const getEventListeners = (uid, widgetId) => {
2205
2238
  params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleClickReplaceAll', 0, widgetId]
2206
2239
  }, {
2207
2240
  name: HandleClickButton,
2208
- params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleClickButton', 0, widgetId, `event.target.name`]
2241
+ params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleClickButton', 0, widgetId, TargetName]
2209
2242
  }, {
2210
2243
  name: HandleResizerPointerDown,
2211
2244
  params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleResizerPointerDown', 0, widgetId, ClientX, ClientY],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/find-widget-worker",
3
- "version": "1.18.0",
3
+ "version": "1.20.0",
4
4
  "description": "Web Worker for the find widget in Lvce Editor",
5
5
  "repository": {
6
6
  "type": "git",