@lvce-editor/find-widget-worker 1.5.0 → 1.6.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.
@@ -862,6 +862,7 @@ const {
862
862
  wrapCommand
863
863
  } = create$2();
864
864
 
865
+ const Script$1 = 2;
865
866
  const Unknown = 0;
866
867
 
867
868
  const create$1 = (uid, x, y, width, height, parentUid) => {
@@ -891,29 +892,30 @@ const create$1 = (uid, x, y, width, height, parentUid) => {
891
892
  editorX: x,
892
893
  editorY: y,
893
894
  editorWidth: width,
894
- editorHeight: height
895
+ editorHeight: height,
896
+ inputSource: 0
895
897
  };
896
898
  set$1(uid, state, state);
897
899
  return state;
898
900
  };
899
901
 
900
- const isEqual$4 = (oldState, newState) => {
902
+ const isEqual$5 = (oldState, newState) => {
901
903
  return oldState.x === newState.x && oldState.y === newState.y && oldState.width === newState.width && oldState.height === newState.height;
902
904
  };
903
905
 
904
- const isEqual$3 = (oldState, newState) => {
906
+ const isEqual$4 = (oldState, newState) => {
905
907
  return oldState.version === newState.version;
906
908
  };
907
909
 
908
- const isEqual$2 = (oldState, newState) => {
910
+ const isEqual$3 = (oldState, newState) => {
909
911
  return oldState.focused === newState.focused;
910
912
  };
911
913
 
912
- const isEqual$1 = (oldState, newState) => {
914
+ const isEqual$2 = (oldState, newState) => {
913
915
  return oldState.version === newState.version && oldState.replaceExpanded === newState.replaceExpanded && oldState.matchCount === newState.matchCount && oldState.matchIndex === newState.matchIndex;
914
916
  };
915
917
 
916
- const isEqual = (oldState, newState) => {
918
+ const isEqual$1 = (oldState, newState) => {
917
919
  return oldState.version === newState.version;
918
920
  };
919
921
 
@@ -923,9 +925,17 @@ const RenderUid = 12;
923
925
  const RenderContent = 13;
924
926
  const RenderFocusContext = 14;
925
927
  const RenderFocus = 15;
928
+ const RenderValue = 16;
929
+
930
+ const Script = 1;
931
+ const User = 2;
932
+
933
+ const isEqual = (oldState, newState) => {
934
+ return newState.inputSource === User || oldState.value === newState.value;
935
+ };
926
936
 
927
- const modules = [isEqual$3, isEqual$1, isEqual$4, isEqual, isEqual$2, isEqual$2];
928
- const numbers = [RenderEventListeners, RenderContent, RenderBounds, RenderUid, RenderFocusContext, RenderFocus];
937
+ const modules = [isEqual$4, isEqual$2, isEqual$5, isEqual$1, isEqual$3, isEqual$3, isEqual];
938
+ const numbers = [RenderEventListeners, RenderContent, RenderBounds, RenderUid, RenderFocusContext, RenderFocus, RenderValue];
929
939
 
930
940
  const diff = (oldState, newState) => {
931
941
  const diffResult = [];
@@ -947,6 +957,25 @@ const diff2 = uid => {
947
957
  return diffResult;
948
958
  };
949
959
 
960
+ const FocusFindWidgetCloseButton = 48;
961
+ const FocusFindWidgetReplace = 43;
962
+ const FocusFindWidgetReplaceAllButton = 47;
963
+
964
+ const setFindWidgetFocus = (state, focusKey) => {
965
+ if (state.focus === focusKey) {
966
+ return state;
967
+ }
968
+ return {
969
+ ...state,
970
+ focus: focusKey,
971
+ focusSource: Script$1
972
+ };
973
+ };
974
+
975
+ const focusCloseButton = state => {
976
+ return setFindWidgetFocus(state, FocusFindWidgetCloseButton);
977
+ };
978
+
950
979
  // TODO don't call renderer worker, set editor state
951
980
  // TODO this function should be synchronous
952
981
  const focusIndex = (state, index) => {
@@ -1008,6 +1037,14 @@ const focusPrevious = state => {
1008
1037
  return focusIndex(state, matchIndex - 1);
1009
1038
  };
1010
1039
 
1040
+ const focusReplace = state => {
1041
+ return setFindWidgetFocus(state, FocusFindWidgetReplace);
1042
+ };
1043
+
1044
+ const focusReplaceAllButton = state => {
1045
+ return setFindWidgetFocus(state, FocusFindWidgetReplaceAllButton);
1046
+ };
1047
+
1011
1048
  const handleBlur = async state => {
1012
1049
  return {
1013
1050
  ...state,
@@ -1079,7 +1116,8 @@ const refresh$1 = (state, value) => {
1079
1116
  matches,
1080
1117
  matchIndex: 0,
1081
1118
  matchCount,
1082
- value
1119
+ value,
1120
+ inputSource: User
1083
1121
  };
1084
1122
  };
1085
1123
 
@@ -1183,6 +1221,15 @@ const getLines = async editorUid => {
1183
1221
  return lines;
1184
1222
  };
1185
1223
 
1224
+ const getSelectedText = (lines, selections) => {
1225
+ const startRowIndex = selections[0];
1226
+ const startColumnIndex = selections[1];
1227
+ const endColumnIndex = selections[3];
1228
+ const line = lines[startRowIndex];
1229
+ const value = line.slice(startColumnIndex, endColumnIndex);
1230
+ return value;
1231
+ };
1232
+
1186
1233
  const getSelections = async editorUid => {
1187
1234
  // @ts-ignore
1188
1235
  const selections = await invoke('Editor.getSelections2', editorUid);
@@ -1208,11 +1255,7 @@ const loadContent = async state => {
1208
1255
  if (lines.length === 0) {
1209
1256
  return state;
1210
1257
  }
1211
- const startRowIndex = selections[0];
1212
- const startColumnIndex = selections[1];
1213
- const endColumnIndex = selections[3];
1214
- const line = lines[startRowIndex];
1215
- const value = line.slice(startColumnIndex, endColumnIndex);
1258
+ const value = getSelectedText(lines, selections);
1216
1259
  const matches = findMatchesCaseInsensitive(lines, value);
1217
1260
  const matchCount = getMatchCount(matches);
1218
1261
  return {
@@ -1228,7 +1271,8 @@ const loadContent = async state => {
1228
1271
  height,
1229
1272
  lines,
1230
1273
  selections,
1231
- focused: true
1274
+ focused: true,
1275
+ inputSource: Script
1232
1276
  };
1233
1277
  };
1234
1278
 
@@ -1318,6 +1362,9 @@ const Close$1 = 'Close';
1318
1362
  const Replace$1 = 'Replace';
1319
1363
  const ReplaceAll$1 = 'ReplaceAll';
1320
1364
 
1365
+ const ToggleReplace = 'ToggleReplace';
1366
+ const SearchValue = 'search-value';
1367
+ const ReplaceValue = 'replace-value';
1321
1368
  const ReplaceAll = 'ReplaceAll';
1322
1369
  const Close = 'Close';
1323
1370
  const FocusNext = 'FocusNext';
@@ -1389,6 +1436,10 @@ const SearchField = 'SearchField';
1389
1436
  const SearchFieldButton = 'SearchFieldButton';
1390
1437
  const SearchFieldButtonChecked = 'SearchFieldButtonChecked';
1391
1438
  const SearchFieldButtons = 'SearchFieldButtons';
1439
+ const Viewlet = 'Viewlet';
1440
+ const ViewletFind = 'ViewletFind';
1441
+ const FindWidget = 'FindWidget';
1442
+ const ViewletFindWidget = 'ViewletFindWidget';
1392
1443
 
1393
1444
  const mergeClassNames = (...classNames) => {
1394
1445
  return classNames.filter(Boolean).join(' ');
@@ -1519,13 +1570,11 @@ const getFindWidgetReplaceVirtualDom = (replaceExpanded, replaceButtons) => {
1519
1570
  type: Div,
1520
1571
  className: FindWidgetReplace,
1521
1572
  childCount: 1 + replaceButtons.length
1522
- }, ...getSearchFieldVirtualDom('replace-value', replace(), HandleReplaceInput, [], [], HandleReplaceFocus), ...replaceButtons.flatMap(getIconButtonVirtualDom));
1573
+ }, ...getSearchFieldVirtualDom(ReplaceValue, replace(), HandleReplaceInput, [], [], HandleReplaceFocus), ...replaceButtons.flatMap(getIconButtonVirtualDom));
1523
1574
  }
1524
1575
  return dom;
1525
1576
  };
1526
1577
 
1527
- const ToggleReplace = 'ToggleReplace';
1528
-
1529
1578
  const getSearchToggleButtonVirtualDom = (replaceExpanded, onClick = '') => {
1530
1579
  return [{
1531
1580
  type: Button,
@@ -1549,7 +1598,7 @@ const getFindWidgetVirtualDom = (matchCountText, replaceExpanded, findButtons, r
1549
1598
  const dom = [];
1550
1599
  dom.push({
1551
1600
  type: Div,
1552
- className: 'Viewlet ViewletFind ViewletFindWidget FindWidget',
1601
+ className: mergeClassNames(Viewlet, ViewletFind, ViewletFindWidget, FindWidget),
1553
1602
  childCount: 2,
1554
1603
  role: Group
1555
1604
  });
@@ -1664,6 +1713,14 @@ const renderUid = (oldState, newState) => {
1664
1713
  return [SetUid, uid, editorUid];
1665
1714
  };
1666
1715
 
1716
+ const renderValue = (oldState, newState) => {
1717
+ const {
1718
+ uid,
1719
+ value
1720
+ } = newState;
1721
+ return [/* method */'Viewlet.setValueByName', uid, SearchValue, value];
1722
+ };
1723
+
1667
1724
  const getRenderer = diffType => {
1668
1725
  switch (diffType) {
1669
1726
  case RenderContent:
@@ -1678,6 +1735,8 @@ const getRenderer = diffType => {
1678
1735
  return renderFocusContext;
1679
1736
  case RenderFocus:
1680
1737
  return renderFocus;
1738
+ case RenderValue:
1739
+ return renderValue;
1681
1740
  default:
1682
1741
  throw new Error('unknown renderer');
1683
1742
  }
@@ -1709,11 +1768,14 @@ const terminate = () => {
1709
1768
  const commandMap = {
1710
1769
  'FindWidget.create': create$1,
1711
1770
  'FindWidget.diff2': diff2,
1771
+ 'FindWidget.focusCloseButton': wrapCommand(focusCloseButton),
1712
1772
  'FindWidget.focusFirst': wrapCommand(focusFirst),
1713
1773
  'FindWidget.focusIndex': wrapCommand(focusIndex),
1714
1774
  'FindWidget.focusLast': wrapCommand(focusLast),
1715
1775
  'FindWidget.focusNext': wrapCommand(focusNext),
1716
1776
  'FindWidget.focusPrevious': wrapCommand(focusPrevious),
1777
+ 'FindWidget.focusReplace': wrapCommand(focusReplace),
1778
+ 'FindWidget.focusReplaceAllButton': wrapCommand(focusReplaceAllButton),
1717
1779
  'FindWidget.getCommandIds': getCommandIds,
1718
1780
  'FindWidget.handleBlur': wrapCommand(handleBlur),
1719
1781
  'FindWidget.handleClickClose': wrapCommand(handleClickClose),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/find-widget-worker",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "Web Worker for the find widget in Lvce Editor",
5
5
  "repository": {
6
6
  "type": "git",