@lvce-editor/find-widget-worker 3.2.0 → 3.3.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.
@@ -374,7 +374,7 @@ const callbacks = Object.create(null);
374
374
  const get$2 = id => {
375
375
  return callbacks[id];
376
376
  };
377
- const remove = id => {
377
+ const remove$1 = id => {
378
378
  delete callbacks[id];
379
379
  };
380
380
  class JsonRpcError extends Error {
@@ -527,7 +527,7 @@ const resolve = (id, response) => {
527
527
  return;
528
528
  }
529
529
  fn(response);
530
- remove(id);
530
+ remove$1(id);
531
531
  };
532
532
  const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
533
533
  const getErrorType = prettyError => {
@@ -834,6 +834,34 @@ const WebWorkerRpcClient = {
834
834
  __proto__: null,
835
835
  create: create$1$1
836
836
  };
837
+ const createMockRpc = ({
838
+ commandMap
839
+ }) => {
840
+ const invocations = [];
841
+ const invoke = (method, ...params) => {
842
+ invocations.push([method, ...params]);
843
+ const command = commandMap[method];
844
+ if (!command) {
845
+ throw new Error(`command ${method} not found`);
846
+ }
847
+ return command(...params);
848
+ };
849
+ const mockRpc = {
850
+ invocations,
851
+ invoke,
852
+ invokeAndTransfer: invoke
853
+ };
854
+ return mockRpc;
855
+ };
856
+
857
+ const CheckBox = 'checkbox';
858
+ const Group = 'group';
859
+ const None = 'none';
860
+
861
+ const Button = 1;
862
+ const Div = 4;
863
+ const Text = 12;
864
+ const TextArea = 62;
837
865
 
838
866
  const ClientX = 'event.clientX';
839
867
  const ClientY = 'event.clientY';
@@ -887,7 +915,11 @@ const set$2 = (id, rpc) => {
887
915
  const get$1 = id => {
888
916
  return rpcs[id];
889
917
  };
918
+ const remove = id => {
919
+ delete rpcs[id];
920
+ };
890
921
 
922
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
891
923
  const create$2 = rpcId => {
892
924
  return {
893
925
  async dispose() {
@@ -906,6 +938,18 @@ const create$2 = rpcId => {
906
938
  // @ts-ignore
907
939
  return rpc.invokeAndTransfer(method, ...params);
908
940
  },
941
+ registerMockRpc(commandMap) {
942
+ const mockRpc = createMockRpc({
943
+ commandMap
944
+ });
945
+ set$2(rpcId, mockRpc);
946
+ // @ts-ignore
947
+ mockRpc[Symbol.dispose] = () => {
948
+ remove(rpcId);
949
+ };
950
+ // @ts-ignore
951
+ return mockRpc;
952
+ },
909
953
  set(rpc) {
910
954
  set$2(rpcId, rpc);
911
955
  }
@@ -1293,11 +1337,12 @@ const findRegexMatches = (lines, regex) => {
1293
1337
  return new Uint32Array(matches);
1294
1338
  };
1295
1339
 
1340
+ const emptyMatches$1 = new Uint32Array([]);
1296
1341
  const findMatches = (lines, searchString, options) => {
1297
1342
  if (searchString.length === 0) {
1298
1343
  return {
1299
1344
  error: '',
1300
- matches: new Uint32Array([])
1345
+ matches: emptyMatches$1
1301
1346
  };
1302
1347
  }
1303
1348
  const {
@@ -1307,7 +1352,7 @@ const findMatches = (lines, searchString, options) => {
1307
1352
  if (error) {
1308
1353
  return {
1309
1354
  error,
1310
- matches: new Uint32Array([])
1355
+ matches: emptyMatches$1
1311
1356
  };
1312
1357
  }
1313
1358
  const matches = findRegexMatches(lines, regex);
@@ -1602,6 +1647,43 @@ const getEdits = (matches, value, replacement, startIndex, replaceAll, lines, pr
1602
1647
  return edits;
1603
1648
  };
1604
1649
 
1650
+ const getLines = async editorUid => {
1651
+ const lines = await getLines$1(editorUid);
1652
+ return lines;
1653
+ };
1654
+
1655
+ const updateAfterReplace = async (state, matchIndex) => {
1656
+ const {
1657
+ editorUid,
1658
+ matchCase,
1659
+ matchWholeWord,
1660
+ useRegularExpression,
1661
+ value
1662
+ } = state;
1663
+ const options = {
1664
+ matchCase,
1665
+ matchWholeWord,
1666
+ useRegularExpression
1667
+ };
1668
+ const newLines = await getLines(editorUid);
1669
+ const {
1670
+ error,
1671
+ matches: newMatches
1672
+ } = findMatches(newLines, value, options);
1673
+ const newMatchCount = getMatchCount(newMatches);
1674
+
1675
+ // Keep matchIndex in bounds, or reset to 0 if no matches remain
1676
+ const newMatchIndex = newMatchCount === 0 ? 0 : Math.min(matchIndex, newMatchCount - 1);
1677
+ return {
1678
+ ...state,
1679
+ inputErrorMessage: error,
1680
+ lines: newLines,
1681
+ matchCount: newMatchCount,
1682
+ matches: newMatches,
1683
+ matchIndex: newMatchIndex
1684
+ };
1685
+ };
1686
+
1605
1687
  const replace$1 = async state => {
1606
1688
  const {
1607
1689
  editorUid,
@@ -1622,12 +1704,10 @@ const replace$1 = async state => {
1622
1704
  };
1623
1705
  const edits = getEdits(matches, value, replacement, matchIndex, false, lines, preserveCase, options);
1624
1706
  await applyEdits(editorUid, edits);
1625
- return {
1626
- ...state
1627
- };
1707
+ return updateAfterReplace(state, matchIndex);
1628
1708
  };
1629
1709
 
1630
- const replaceAll$1 = state => {
1710
+ const replaceAll$1 = async state => {
1631
1711
  const {
1632
1712
  editorUid,
1633
1713
  lines,
@@ -1645,10 +1725,8 @@ const replaceAll$1 = state => {
1645
1725
  useRegularExpression
1646
1726
  };
1647
1727
  const edits = getEdits(matches, value, replacement, 0, true, lines, preserveCase, options);
1648
- void applyEdits(editorUid, edits);
1649
- return {
1650
- ...state
1651
- };
1728
+ await applyEdits(editorUid, edits);
1729
+ return updateAfterReplace(state, 0);
1652
1730
  };
1653
1731
 
1654
1732
  const getClickHandler = name => {
@@ -1993,11 +2071,6 @@ const getFindWidgetPosition = (editorX, editorY, editorWidth) => {
1993
2071
  };
1994
2072
  };
1995
2073
 
1996
- const getLines = async editorUid => {
1997
- const lines = await getLines$1(editorUid);
1998
- return lines;
1999
- };
2000
-
2001
2074
  const getSelectedText = (lines, selections) => {
2002
2075
  if (selections.length === 0) {
2003
2076
  return '';
@@ -2284,24 +2357,15 @@ const getFindWidgetButtonsEnabled = (matchCount, value) => {
2284
2357
  };
2285
2358
  };
2286
2359
 
2287
- const CheckBox = 'checkbox';
2288
- const Group = 'group';
2289
- const None = 'none';
2290
-
2291
- const Button = 1;
2292
- const Div = 4;
2293
- const Text = 12;
2294
- const TextArea = 62;
2295
-
2296
2360
  const mergeClassNames = (...classNames) => {
2297
2361
  return classNames.filter(Boolean).join(' ');
2298
2362
  };
2299
2363
 
2300
2364
  const text = data => {
2301
2365
  return {
2302
- type: Text,
2366
+ childCount: 0,
2303
2367
  text: data,
2304
- childCount: 0
2368
+ type: Text
2305
2369
  };
2306
2370
  };
2307
2371
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/find-widget-worker",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "description": "Web Worker for the find widget in Lvce Editor",
5
5
  "repository": {
6
6
  "type": "git",