@lvce-editor/find-widget-worker 1.11.0 → 1.12.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,25 @@ 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
  };
891
936
 
892
937
  const {
893
938
  get: get$1,
894
- set: set$1,
939
+ set: set$3,
895
940
  wrapCommand,
896
- dispose: dispose$1
941
+ dispose: dispose$2,
942
+ getCommandIds,
943
+ registerCommands
897
944
  } = create$2();
898
945
 
899
946
  const Script$1 = 2;
@@ -929,7 +976,7 @@ const create$1 = (uid, x, y, width, height, parentUid) => {
929
976
  editorHeight: height,
930
977
  inputSource: 0
931
978
  };
932
- set$1(uid, state, state);
979
+ set$3(uid, state, state);
933
980
  return state;
934
981
  };
935
982
 
@@ -991,8 +1038,8 @@ const diff2 = uid => {
991
1038
  return diffResult;
992
1039
  };
993
1040
 
994
- const dispose = uid => {
995
- return dispose$1(uid);
1041
+ const dispose$1 = uid => {
1042
+ return dispose$2(uid);
996
1043
  };
997
1044
 
998
1045
  const FocusFindWidgetCloseButton = 48;
@@ -1014,16 +1061,25 @@ const focusCloseButton = state => {
1014
1061
  return setFindWidgetFocus(state, FocusFindWidgetCloseButton);
1015
1062
  };
1016
1063
 
1064
+ const Button = 1;
1065
+ const Div = 4;
1066
+ const Text = 12;
1067
+ const TextArea = 62;
1068
+
1069
+ const EditorWorker$1 = 99;
1070
+
1071
+ const FocusSelector = 'Viewlet.focusSelector';
1072
+ const SetFocusContext = 'Viewlet.setFocusContext';
1073
+ const SetValueByName = 'Viewlet.setValueByName';
1074
+
1017
1075
  const rpcs = Object.create(null);
1018
- const set$g = (id, rpc) => {
1076
+ const set$2 = (id, rpc) => {
1019
1077
  rpcs[id] = rpc;
1020
1078
  };
1021
1079
  const get = id => {
1022
1080
  return rpcs[id];
1023
1081
  };
1024
1082
 
1025
- /* eslint-disable @typescript-eslint/explicit-function-return-type */
1026
-
1027
1083
  const create = rpcId => {
1028
1084
  return {
1029
1085
  // @ts-ignore
@@ -1039,7 +1095,7 @@ const create = rpcId => {
1039
1095
  return rpc.invokeAndTransfer(method, ...params);
1040
1096
  },
1041
1097
  set(rpc) {
1042
- set$g(rpcId, rpc);
1098
+ set$2(rpcId, rpc);
1043
1099
  },
1044
1100
  async dispose() {
1045
1101
  const rpc = get(rpcId);
@@ -1047,14 +1103,109 @@ const create = rpcId => {
1047
1103
  }
1048
1104
  };
1049
1105
  };
1050
- const EditorWorker$1 = 99;
1106
+
1051
1107
  const {
1052
- invoke: invoke$d,
1053
- set: set$c} = create(EditorWorker$1);
1108
+ invoke: invoke$1,
1109
+ invokeAndTransfer,
1110
+ set: set$1,
1111
+ dispose
1112
+ } = create(EditorWorker$1);
1113
+ const sendMessagePortToExtensionHostWorker = async port => {
1114
+ const command = 'HandleMessagePort.handleMessagePort2';
1115
+ await invokeAndTransfer(
1116
+ // @ts-ignore
1117
+ 'SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, 0);
1118
+ };
1119
+ // TODO add tests for this
1120
+ const activateByEvent = async event => {
1121
+ // @ts-ignore
1122
+ await invoke$1('ActivateByEvent.activateByEvent', event);
1123
+ };
1124
+ const applyEdit = async (editorUid, changes) => {
1125
+ // @ts-ignore
1126
+ await invoke$1('Editor.applyEdit2', editorUid, changes);
1127
+ };
1128
+ const applyWorkspaceEdit = async (editorUid, changes) => {
1129
+ // @ts-ignore
1130
+ await invoke$1('Editor.applyWorkspaceEdit', editorUid, changes);
1131
+ };
1132
+ const closeWidget = async (editorUid, widgetId, widgetName, focusId) => {
1133
+ // @ts-ignore
1134
+ await invoke$1('Editor.closeWidget2', editorUid, widgetId, widgetName, focusId);
1135
+ };
1136
+ const getWordAt = async (uid, rowIndex, columnIndex) => {
1137
+ // @ts-ignore
1138
+ const word = await invoke$1('Editor.getWordAt2', uid, rowIndex, columnIndex);
1139
+ return word;
1140
+ };
1141
+ const getLines$1 = async editorUid => {
1142
+ const lines = await invoke$1('Editor.getLines2', editorUid);
1143
+ return lines;
1144
+ };
1145
+ const getPositionAtCursor = async parentUid => {
1146
+ const position = await invoke$1('Editor.getPositionAtCursor', parentUid);
1147
+ return position;
1148
+ };
1149
+ const getOffsetAtCursor = async editorId => {
1150
+ // @ts-ignore
1151
+ return await invoke$1('Editor.getOffsetAtCursor', editorId);
1152
+ };
1153
+ const getSelections$1 = async editorUid => {
1154
+ const selections = await invoke$1('Editor.getSelections2', editorUid);
1155
+ return selections;
1156
+ };
1157
+ const getWordAtOffset2 = async editorUid => {
1158
+ return invoke$1('Editor.getWordAtOffset2', editorUid);
1159
+ };
1160
+ const getWordBefore = async (editorUid, rowIndex, columnIndex) => {
1161
+ return invoke$1('Editor.getWordBefore2', editorUid, rowIndex, columnIndex);
1162
+ };
1163
+ const updateDebugInfo = async info => {
1164
+ await invoke$1('Editor.updateDebugInfo', info);
1165
+ };
1166
+ const getUri = async editorUid => {
1167
+ // @ts-ignore
1168
+ return invoke$1('Editor.getUri', editorUid);
1169
+ };
1170
+ const getLanguageId = async editorUid => {
1171
+ // @ts-ignore
1172
+ return invoke$1('Editor.getLanguageId', editorUid);
1173
+ };
1174
+ const getProblems = async () => {
1175
+ // @ts-ignore
1176
+ return invoke$1('Editor.getProblems');
1177
+ };
1178
+ const registerMockRpc = commandMap => {
1179
+ const mockRpc = createMockRpc({
1180
+ commandMap
1181
+ });
1182
+ set$1(mockRpc);
1183
+ return mockRpc;
1184
+ };
1185
+
1054
1186
  const EditorWorker = {
1055
1187
  __proto__: null,
1056
- invoke: invoke$d,
1057
- set: set$c
1188
+ activateByEvent,
1189
+ applyEdit,
1190
+ applyWorkspaceEdit,
1191
+ closeWidget,
1192
+ dispose,
1193
+ getLanguageId,
1194
+ getLines: getLines$1,
1195
+ getOffsetAtCursor,
1196
+ getPositionAtCursor,
1197
+ getProblems,
1198
+ getSelections: getSelections$1,
1199
+ getUri,
1200
+ getWordAt,
1201
+ getWordAtOffset2,
1202
+ getWordBefore,
1203
+ invoke: invoke$1,
1204
+ invokeAndTransfer,
1205
+ registerMockRpc,
1206
+ sendMessagePortToExtensionHostWorker,
1207
+ set: set$1,
1208
+ updateDebugInfo
1058
1209
  };
1059
1210
 
1060
1211
  const {
@@ -1234,12 +1385,6 @@ const toggleReplace = state => {
1234
1385
  };
1235
1386
  };
1236
1387
 
1237
- const commandIds = ['handleSliderPointerDown', 'handleSliderPointerMove'];
1238
-
1239
- const getCommandIds = () => {
1240
- return commandIds;
1241
- };
1242
-
1243
1388
  const getFindWidgetPosition = (editorX, editorY, editorWidth) => {
1244
1389
  const width = 300;
1245
1390
  const height = 30;
@@ -1463,6 +1608,18 @@ const getFindWidgetButtonsEnabled = (matchCount, value) => {
1463
1608
  };
1464
1609
  };
1465
1610
 
1611
+ const mergeClassNames = (...classNames) => {
1612
+ return classNames.filter(Boolean).join(' ');
1613
+ };
1614
+
1615
+ const text = data => {
1616
+ return {
1617
+ type: Text,
1618
+ text: data,
1619
+ childCount: 0
1620
+ };
1621
+ };
1622
+
1466
1623
  const CheckBox = 'checkbox';
1467
1624
  const Group = 'group';
1468
1625
  const None = 'none';
@@ -1485,18 +1642,6 @@ const ViewletFind = 'ViewletFind';
1485
1642
  const FindWidget = 'FindWidget';
1486
1643
  const ViewletFindWidget = 'ViewletFindWidget';
1487
1644
 
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
1645
  const getFindMatchCountClassName = (matchCount, value) => {
1501
1646
  if (value && matchCount === 0) {
1502
1647
  return mergeClassNames(FindWidgetMatchCount, FindWidgetMatchCountEmpty);
@@ -1504,10 +1649,6 @@ const getFindMatchCountClassName = (matchCount, value) => {
1504
1649
  return FindWidgetMatchCount;
1505
1650
  };
1506
1651
 
1507
- const Button = 1;
1508
- const Div = 4;
1509
- const TextArea = 62;
1510
-
1511
1652
  const getIconVirtualDom = (icon, type = Div) => {
1512
1653
  return {
1513
1654
  type,
@@ -1740,13 +1881,13 @@ const renderFocus = (oldState, newState) => {
1740
1881
  const {
1741
1882
  uid
1742
1883
  } = newState;
1743
- return [/* method */'Viewlet.focusSelector', uid, `[name="search-value"]`];
1884
+ return [/* method */FocusSelector, uid, `[name="search-value"]`];
1744
1885
  };
1745
1886
 
1746
1887
  const FocusFindWidget = 16;
1747
1888
 
1748
1889
  const renderFocusContext = (oldState, newState) => {
1749
- return [/* method */'Viewlet.setFocusContext', FocusFindWidget];
1890
+ return [/* method */SetFocusContext, FocusFindWidget];
1750
1891
  };
1751
1892
 
1752
1893
  const renderUid = (oldState, newState) => {
@@ -1762,7 +1903,7 @@ const renderValue = (oldState, newState) => {
1762
1903
  uid,
1763
1904
  value
1764
1905
  } = newState;
1765
- return [/* method */'Viewlet.setValueByName', uid, SearchValue, value];
1906
+ return [/* method */SetValueByName, uid, SearchValue, value];
1766
1907
  };
1767
1908
 
1768
1909
  const getRenderer = diffType => {
@@ -1800,7 +1941,7 @@ const render2 = (uid, diffResult) => {
1800
1941
  oldState,
1801
1942
  newState
1802
1943
  } = get$1(uid);
1803
- set$1(uid, newState, newState);
1944
+ set$3(uid, newState, newState);
1804
1945
  const commands = applyRender(oldState, newState, diffResult);
1805
1946
  return commands;
1806
1947
  };
@@ -1812,7 +1953,7 @@ const terminate = () => {
1812
1953
  const commandMap = {
1813
1954
  'FindWidget.create': create$1,
1814
1955
  'FindWidget.diff2': diff2,
1815
- 'FindWidget.dispose': dispose,
1956
+ 'FindWidget.dispose': dispose$1,
1816
1957
  'FindWidget.focusCloseButton': wrapCommand(focusCloseButton),
1817
1958
  'FindWidget.focusFirst': wrapCommand(focusFirst),
1818
1959
  'FindWidget.focusIndex': wrapCommand(focusIndex),
@@ -1833,6 +1974,7 @@ const commandMap = {
1833
1974
  };
1834
1975
 
1835
1976
  const listen = async () => {
1977
+ registerCommands(commandMap);
1836
1978
  const rpc = await WebWorkerRpcClient.create({
1837
1979
  commandMap: commandMap
1838
1980
  });
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.12.0",
4
4
  "description": "Web Worker for the find widget in Lvce Editor",
5
5
  "repository": {
6
6
  "type": "git",