@lvce-editor/find-widget-worker 1.11.0 → 1.13.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.
@@ -378,7 +378,7 @@ const create$4 = (method, params) => {
378
378
  };
379
379
  };
380
380
  const callbacks = Object.create(null);
381
- const set$2 = (id, fn) => {
381
+ const set$4 = (id, fn) => {
382
382
  callbacks[id] = fn;
383
383
  };
384
384
  const get$2 = id => {
@@ -397,7 +397,7 @@ const registerPromise = () => {
397
397
  resolve,
398
398
  promise
399
399
  } = Promise.withResolvers();
400
- set$2(id, resolve);
400
+ set$4(id, resolve);
401
401
  return {
402
402
  id,
403
403
  promise
@@ -477,7 +477,8 @@ const splitLines = lines => {
477
477
  return lines.split(NewLine);
478
478
  };
479
479
  const getCurrentStack = () => {
480
- const currentStack = joinLines(splitLines(new Error().stack || '').slice(2));
480
+ const stackLinesToSkip = 3;
481
+ const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
481
482
  return currentStack;
482
483
  };
483
484
  const getNewLineIndex = (string, startIndex = undefined) => {
@@ -741,13 +742,19 @@ const send = (transport, method, ...params) => {
741
742
  const message = create$4(method, params);
742
743
  transport.send(message);
743
744
  };
744
- const invoke$1 = (ipc, method, ...params) => {
745
+ const invoke$2 = (ipc, method, ...params) => {
745
746
  return invokeHelper(ipc, method, params, false);
746
747
  };
747
- const invokeAndTransfer = (ipc, method, ...params) => {
748
+ const invokeAndTransfer$1 = (ipc, method, ...params) => {
748
749
  return invokeHelper(ipc, method, params, true);
749
750
  };
750
751
 
752
+ class CommandNotFoundError extends Error {
753
+ constructor(command) {
754
+ super(`Command not found ${command}`);
755
+ this.name = 'CommandNotFoundError';
756
+ }
757
+ }
751
758
  const commands = Object.create(null);
752
759
  const register = commandMap => {
753
760
  Object.assign(commands, commandMap);
@@ -758,7 +765,7 @@ const getCommand = key => {
758
765
  const execute = (command, ...args) => {
759
766
  const fn = getCommand(command);
760
767
  if (!fn) {
761
- throw new Error(`command not found ${command}`);
768
+ throw new CommandNotFoundError(command);
762
769
  }
763
770
  return fn(...args);
764
771
  };
@@ -774,10 +781,10 @@ const createRpc = ipc => {
774
781
  send(ipc, method, ...params);
775
782
  },
776
783
  invoke(method, ...params) {
777
- return invoke$1(ipc, method, ...params);
784
+ return invoke$2(ipc, method, ...params);
778
785
  },
779
786
  invokeAndTransfer(method, ...params) {
780
- return invokeAndTransfer(ipc, method, ...params);
787
+ return invokeAndTransfer$1(ipc, method, ...params);
781
788
  },
782
789
  async dispose() {
783
790
  await ipc?.dispose();
@@ -829,9 +836,30 @@ const WebWorkerRpcClient = {
829
836
  __proto__: null,
830
837
  create: create$3
831
838
  };
839
+ const createMockRpc = ({
840
+ commandMap
841
+ }) => {
842
+ const invocations = [];
843
+ const invoke = (method, ...params) => {
844
+ invocations.push([method, ...params]);
845
+ const command = commandMap[method];
846
+ return command(...params);
847
+ };
848
+ const mockRpc = {
849
+ invoke,
850
+ invokeAndTransfer: invoke,
851
+ invocations
852
+ };
853
+ return mockRpc;
854
+ };
832
855
 
856
+ const toCommandId = key => {
857
+ const dotIndex = key.indexOf('.');
858
+ return key.slice(dotIndex + 1);
859
+ };
833
860
  const create$2 = () => {
834
861
  const states = Object.create(null);
862
+ const commandMapRef = {};
835
863
  return {
836
864
  get(uid) {
837
865
  return states[uid];
@@ -872,6 +900,15 @@ const create$2 = () => {
872
900
  };
873
901
  return wrapped;
874
902
  },
903
+ wrapGetter(fn) {
904
+ const wrapped = (uid, ...args) => {
905
+ const {
906
+ newState
907
+ } = states[uid];
908
+ return fn(newState, ...args);
909
+ };
910
+ return wrapped;
911
+ },
875
912
  diff(uid, modules, numbers) {
876
913
  const {
877
914
  oldState,
@@ -885,15 +922,28 @@ const create$2 = () => {
885
922
  }
886
923
  }
887
924
  return diffResult;
925
+ },
926
+ getCommandIds() {
927
+ const keys = Object.keys(commandMapRef);
928
+ const ids = keys.map(toCommandId);
929
+ return ids;
930
+ },
931
+ registerCommands(commandMap) {
932
+ Object.assign(commandMapRef, commandMap);
888
933
  }
889
934
  };
890
935
  };
936
+ const terminate = () => {
937
+ globalThis.close();
938
+ };
891
939
 
892
940
  const {
893
941
  get: get$1,
894
- set: set$1,
942
+ set: set$3,
895
943
  wrapCommand,
896
- dispose: dispose$1
944
+ dispose: dispose$2,
945
+ getCommandIds,
946
+ registerCommands
897
947
  } = create$2();
898
948
 
899
949
  const Script$1 = 2;
@@ -929,7 +979,7 @@ const create$1 = (uid, x, y, width, height, parentUid) => {
929
979
  editorHeight: height,
930
980
  inputSource: 0
931
981
  };
932
- set$1(uid, state, state);
982
+ set$3(uid, state, state);
933
983
  return state;
934
984
  };
935
985
 
@@ -961,8 +1011,19 @@ const RenderFocusContext = 14;
961
1011
  const RenderFocus = 15;
962
1012
  const RenderValue = 16;
963
1013
 
1014
+ const Button = 1;
1015
+ const Div = 4;
1016
+ const Text = 12;
1017
+ const TextArea = 62;
1018
+
1019
+ const User = 1;
964
1020
  const Script = 1;
965
- const User = 2;
1021
+
1022
+ const EditorWorker$1 = 99;
1023
+
1024
+ const FocusSelector = 'Viewlet.focusSelector';
1025
+ const SetFocusContext = 'Viewlet.setFocusContext';
1026
+ const SetValueByName = 'Viewlet.setValueByName';
966
1027
 
967
1028
  const isEqual = (oldState, newState) => {
968
1029
  return newState.inputSource === User || oldState.value === newState.value;
@@ -991,8 +1052,8 @@ const diff2 = uid => {
991
1052
  return diffResult;
992
1053
  };
993
1054
 
994
- const dispose = uid => {
995
- return dispose$1(uid);
1055
+ const dispose$1 = uid => {
1056
+ return dispose$2(uid);
996
1057
  };
997
1058
 
998
1059
  const FocusFindWidgetCloseButton = 48;
@@ -1015,15 +1076,13 @@ const focusCloseButton = state => {
1015
1076
  };
1016
1077
 
1017
1078
  const rpcs = Object.create(null);
1018
- const set$g = (id, rpc) => {
1079
+ const set$2 = (id, rpc) => {
1019
1080
  rpcs[id] = rpc;
1020
1081
  };
1021
1082
  const get = id => {
1022
1083
  return rpcs[id];
1023
1084
  };
1024
1085
 
1025
- /* eslint-disable @typescript-eslint/explicit-function-return-type */
1026
-
1027
1086
  const create = rpcId => {
1028
1087
  return {
1029
1088
  // @ts-ignore
@@ -1039,7 +1098,7 @@ const create = rpcId => {
1039
1098
  return rpc.invokeAndTransfer(method, ...params);
1040
1099
  },
1041
1100
  set(rpc) {
1042
- set$g(rpcId, rpc);
1101
+ set$2(rpcId, rpc);
1043
1102
  },
1044
1103
  async dispose() {
1045
1104
  const rpc = get(rpcId);
@@ -1047,14 +1106,109 @@ const create = rpcId => {
1047
1106
  }
1048
1107
  };
1049
1108
  };
1050
- const EditorWorker$1 = 99;
1109
+
1051
1110
  const {
1052
- invoke: invoke$d,
1053
- set: set$c} = create(EditorWorker$1);
1111
+ invoke: invoke$1,
1112
+ invokeAndTransfer,
1113
+ set: set$1,
1114
+ dispose
1115
+ } = create(EditorWorker$1);
1116
+ const sendMessagePortToExtensionHostWorker = async port => {
1117
+ const command = 'HandleMessagePort.handleMessagePort2';
1118
+ await invokeAndTransfer(
1119
+ // @ts-ignore
1120
+ 'SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, 0);
1121
+ };
1122
+ // TODO add tests for this
1123
+ const activateByEvent = async event => {
1124
+ // @ts-ignore
1125
+ await invoke$1('ActivateByEvent.activateByEvent', event);
1126
+ };
1127
+ const applyEdit = async (editorUid, changes) => {
1128
+ // @ts-ignore
1129
+ await invoke$1('Editor.applyEdit2', editorUid, changes);
1130
+ };
1131
+ const applyWorkspaceEdit = async (editorUid, changes) => {
1132
+ // @ts-ignore
1133
+ await invoke$1('Editor.applyWorkspaceEdit', editorUid, changes);
1134
+ };
1135
+ const closeWidget = async (editorUid, widgetId, widgetName, focusId) => {
1136
+ // @ts-ignore
1137
+ await invoke$1('Editor.closeWidget2', editorUid, widgetId, widgetName, focusId);
1138
+ };
1139
+ const getWordAt = async (uid, rowIndex, columnIndex) => {
1140
+ // @ts-ignore
1141
+ const word = await invoke$1('Editor.getWordAt2', uid, rowIndex, columnIndex);
1142
+ return word;
1143
+ };
1144
+ const getLines$1 = async editorUid => {
1145
+ const lines = await invoke$1('Editor.getLines2', editorUid);
1146
+ return lines;
1147
+ };
1148
+ const getPositionAtCursor = async parentUid => {
1149
+ const position = await invoke$1('Editor.getPositionAtCursor', parentUid);
1150
+ return position;
1151
+ };
1152
+ const getOffsetAtCursor = async editorId => {
1153
+ // @ts-ignore
1154
+ return await invoke$1('Editor.getOffsetAtCursor', editorId);
1155
+ };
1156
+ const getSelections$1 = async editorUid => {
1157
+ const selections = await invoke$1('Editor.getSelections2', editorUid);
1158
+ return selections;
1159
+ };
1160
+ const getWordAtOffset2 = async editorUid => {
1161
+ return invoke$1('Editor.getWordAtOffset2', editorUid);
1162
+ };
1163
+ const getWordBefore = async (editorUid, rowIndex, columnIndex) => {
1164
+ return invoke$1('Editor.getWordBefore2', editorUid, rowIndex, columnIndex);
1165
+ };
1166
+ const updateDebugInfo = async info => {
1167
+ await invoke$1('Editor.updateDebugInfo', info);
1168
+ };
1169
+ const getUri = async editorUid => {
1170
+ // @ts-ignore
1171
+ return invoke$1('Editor.getUri', editorUid);
1172
+ };
1173
+ const getLanguageId = async editorUid => {
1174
+ // @ts-ignore
1175
+ return invoke$1('Editor.getLanguageId', editorUid);
1176
+ };
1177
+ const getProblems = async () => {
1178
+ // @ts-ignore
1179
+ return invoke$1('Editor.getProblems');
1180
+ };
1181
+ const registerMockRpc = commandMap => {
1182
+ const mockRpc = createMockRpc({
1183
+ commandMap
1184
+ });
1185
+ set$1(mockRpc);
1186
+ return mockRpc;
1187
+ };
1188
+
1054
1189
  const EditorWorker = {
1055
1190
  __proto__: null,
1056
- invoke: invoke$d,
1057
- set: set$c
1191
+ activateByEvent,
1192
+ applyEdit,
1193
+ applyWorkspaceEdit,
1194
+ closeWidget,
1195
+ dispose,
1196
+ getLanguageId,
1197
+ getLines: getLines$1,
1198
+ getOffsetAtCursor,
1199
+ getPositionAtCursor,
1200
+ getProblems,
1201
+ getSelections: getSelections$1,
1202
+ getUri,
1203
+ getWordAt,
1204
+ getWordAtOffset2,
1205
+ getWordBefore,
1206
+ invoke: invoke$1,
1207
+ invokeAndTransfer,
1208
+ registerMockRpc,
1209
+ sendMessagePortToExtensionHostWorker,
1210
+ set: set$1,
1211
+ updateDebugInfo
1058
1212
  };
1059
1213
 
1060
1214
  const {
@@ -1190,7 +1344,7 @@ const getMatchCount = matches => {
1190
1344
  return matches.length / 2;
1191
1345
  };
1192
1346
 
1193
- const refresh$1 = (state, value) => {
1347
+ const refresh$1 = (state, value, inputSource) => {
1194
1348
  const {
1195
1349
  lines
1196
1350
  } = state;
@@ -1202,16 +1356,16 @@ const refresh$1 = (state, value) => {
1202
1356
  matchIndex: 0,
1203
1357
  matchCount,
1204
1358
  value,
1205
- inputSource: User
1359
+ inputSource
1206
1360
  };
1207
1361
  };
1208
1362
 
1209
- const refresh = (state, value = state.value) => {
1210
- return refresh$1(state, value);
1363
+ const refresh = (state, value = state.value, inputSource = User) => {
1364
+ return refresh$1(state, value, inputSource);
1211
1365
  };
1212
1366
 
1213
- const handleInput = (state, value) => {
1214
- return refresh(state, value);
1367
+ const handleInput = (state, value, inputSource = User) => {
1368
+ return refresh(state, value, inputSource);
1215
1369
  };
1216
1370
 
1217
1371
  const getFindWidgetHeight = replaceExpanded => {
@@ -1234,12 +1388,6 @@ const toggleReplace = state => {
1234
1388
  };
1235
1389
  };
1236
1390
 
1237
- const commandIds = ['handleSliderPointerDown', 'handleSliderPointerMove'];
1238
-
1239
- const getCommandIds = () => {
1240
- return commandIds;
1241
- };
1242
-
1243
1391
  const getFindWidgetPosition = (editorX, editorY, editorWidth) => {
1244
1392
  const width = 300;
1245
1393
  const height = 30;
@@ -1463,6 +1611,18 @@ const getFindWidgetButtonsEnabled = (matchCount, value) => {
1463
1611
  };
1464
1612
  };
1465
1613
 
1614
+ const mergeClassNames = (...classNames) => {
1615
+ return classNames.filter(Boolean).join(' ');
1616
+ };
1617
+
1618
+ const text = data => {
1619
+ return {
1620
+ type: Text,
1621
+ text: data,
1622
+ childCount: 0
1623
+ };
1624
+ };
1625
+
1466
1626
  const CheckBox = 'checkbox';
1467
1627
  const Group = 'group';
1468
1628
  const None = 'none';
@@ -1485,18 +1645,6 @@ const ViewletFind = 'ViewletFind';
1485
1645
  const FindWidget = 'FindWidget';
1486
1646
  const ViewletFindWidget = 'ViewletFindWidget';
1487
1647
 
1488
- const mergeClassNames = (...classNames) => {
1489
- return classNames.filter(Boolean).join(' ');
1490
- };
1491
- const Text = 12;
1492
- const text = data => {
1493
- return {
1494
- type: Text,
1495
- text: data,
1496
- childCount: 0
1497
- };
1498
- };
1499
-
1500
1648
  const getFindMatchCountClassName = (matchCount, value) => {
1501
1649
  if (value && matchCount === 0) {
1502
1650
  return mergeClassNames(FindWidgetMatchCount, FindWidgetMatchCountEmpty);
@@ -1504,10 +1652,6 @@ const getFindMatchCountClassName = (matchCount, value) => {
1504
1652
  return FindWidgetMatchCount;
1505
1653
  };
1506
1654
 
1507
- const Button = 1;
1508
- const Div = 4;
1509
- const TextArea = 62;
1510
-
1511
1655
  const getIconVirtualDom = (icon, type = Div) => {
1512
1656
  return {
1513
1657
  type,
@@ -1740,13 +1884,13 @@ const renderFocus = (oldState, newState) => {
1740
1884
  const {
1741
1885
  uid
1742
1886
  } = newState;
1743
- return [/* method */'Viewlet.focusSelector', uid, `[name="search-value"]`];
1887
+ return [/* method */FocusSelector, uid, `[name="search-value"]`];
1744
1888
  };
1745
1889
 
1746
1890
  const FocusFindWidget = 16;
1747
1891
 
1748
1892
  const renderFocusContext = (oldState, newState) => {
1749
- return [/* method */'Viewlet.setFocusContext', FocusFindWidget];
1893
+ return [/* method */SetFocusContext, FocusFindWidget];
1750
1894
  };
1751
1895
 
1752
1896
  const renderUid = (oldState, newState) => {
@@ -1762,7 +1906,7 @@ const renderValue = (oldState, newState) => {
1762
1906
  uid,
1763
1907
  value
1764
1908
  } = newState;
1765
- return [/* method */'Viewlet.setValueByName', uid, SearchValue, value];
1909
+ return [SetValueByName, uid, SearchValue, value];
1766
1910
  };
1767
1911
 
1768
1912
  const getRenderer = diffType => {
@@ -1800,19 +1944,15 @@ const render2 = (uid, diffResult) => {
1800
1944
  oldState,
1801
1945
  newState
1802
1946
  } = get$1(uid);
1803
- set$1(uid, newState, newState);
1947
+ set$3(uid, newState, newState);
1804
1948
  const commands = applyRender(oldState, newState, diffResult);
1805
1949
  return commands;
1806
1950
  };
1807
1951
 
1808
- const terminate = () => {
1809
- globalThis.close();
1810
- };
1811
-
1812
1952
  const commandMap = {
1813
1953
  'FindWidget.create': create$1,
1814
1954
  'FindWidget.diff2': diff2,
1815
- 'FindWidget.dispose': dispose,
1955
+ 'FindWidget.dispose': dispose$1,
1816
1956
  'FindWidget.focusCloseButton': wrapCommand(focusCloseButton),
1817
1957
  'FindWidget.focusFirst': wrapCommand(focusFirst),
1818
1958
  'FindWidget.focusIndex': wrapCommand(focusIndex),
@@ -1833,6 +1973,7 @@ const commandMap = {
1833
1973
  };
1834
1974
 
1835
1975
  const listen = async () => {
1976
+ registerCommands(commandMap);
1836
1977
  const rpc = await WebWorkerRpcClient.create({
1837
1978
  commandMap: commandMap
1838
1979
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/find-widget-worker",
3
- "version": "1.11.0",
3
+ "version": "1.13.0",
4
4
  "description": "Web Worker for the find widget in Lvce Editor",
5
5
  "repository": {
6
6
  "type": "git",