@lvce-editor/completion-worker 1.21.0 → 1.23.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.
@@ -552,7 +552,7 @@ const registerPromise = () => {
552
552
  promise
553
553
  };
554
554
  };
555
- const create$2$2 = (method, params) => {
555
+ const create$2$1 = (method, params) => {
556
556
  const {
557
557
  id,
558
558
  promise
@@ -773,7 +773,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
773
773
  const errorProperty = getErrorProperty(error, prettyError);
774
774
  return create$1$1(id, errorProperty);
775
775
  };
776
- const create$5 = (message, result) => {
776
+ const create$6 = (message, result) => {
777
777
  return {
778
778
  jsonrpc: Two,
779
779
  id: message.id,
@@ -782,7 +782,7 @@ const create$5 = (message, result) => {
782
782
  };
783
783
  const getSuccessResponse = (message, result) => {
784
784
  const resultProperty = result ?? null;
785
- return create$5(message, resultProperty);
785
+ return create$6(message, resultProperty);
786
786
  };
787
787
  const getErrorResponseSimple = (id, error) => {
788
788
  return {
@@ -877,7 +877,7 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
877
877
  const {
878
878
  message,
879
879
  promise
880
- } = create$2$2(method, params);
880
+ } = create$2$1(method, params);
881
881
  if (useSendAndTransfer && ipc.sendAndTransfer) {
882
882
  ipc.sendAndTransfer(message);
883
883
  } else {
@@ -964,7 +964,7 @@ const listen$1 = async (module, options) => {
964
964
  const ipc = module.wrap(rawIpc);
965
965
  return ipc;
966
966
  };
967
- const create$3 = async ({
967
+ const create$5 = async ({
968
968
  commandMap,
969
969
  messagePort
970
970
  }) => {
@@ -980,18 +980,23 @@ const create$3 = async ({
980
980
  messagePort.start();
981
981
  return rpc;
982
982
  };
983
- const create$2$1 = async ({
983
+ const create$3 = async ({
984
984
  commandMap,
985
- messagePort
985
+ send
986
986
  }) => {
987
- return create$3({
987
+ const {
988
+ port1,
989
+ port2
990
+ } = new MessageChannel();
991
+ await send(port1);
992
+ return create$5({
988
993
  commandMap,
989
- messagePort
994
+ messagePort: port2
990
995
  });
991
996
  };
992
- const PlainMessagePortRpcParent = {
997
+ const TransferMessagePortRpcParent = {
993
998
  __proto__: null,
994
- create: create$2$1
999
+ create: create$3
995
1000
  };
996
1001
  const create$4 = async ({
997
1002
  commandMap
@@ -1008,6 +1013,90 @@ const WebWorkerRpcClient = {
1008
1013
  create: create$4
1009
1014
  };
1010
1015
 
1016
+ const toCommandId = key => {
1017
+ const dotIndex = key.indexOf('.');
1018
+ return key.slice(dotIndex + 1);
1019
+ };
1020
+ const create$2 = () => {
1021
+ const states = Object.create(null);
1022
+ const commandMapRef = {};
1023
+ return {
1024
+ get(uid) {
1025
+ return states[uid];
1026
+ },
1027
+ set(uid, oldState, newState) {
1028
+ states[uid] = {
1029
+ oldState,
1030
+ newState
1031
+ };
1032
+ },
1033
+ dispose(uid) {
1034
+ delete states[uid];
1035
+ },
1036
+ getKeys() {
1037
+ return Object.keys(states).map(key => {
1038
+ return Number.parseInt(key);
1039
+ });
1040
+ },
1041
+ clear() {
1042
+ for (const key of Object.keys(states)) {
1043
+ delete states[key];
1044
+ }
1045
+ },
1046
+ wrapCommand(fn) {
1047
+ const wrapped = async (uid, ...args) => {
1048
+ const {
1049
+ newState
1050
+ } = states[uid];
1051
+ const newerState = await fn(newState, ...args);
1052
+ if (newState === newerState) {
1053
+ return;
1054
+ }
1055
+ const latest = states[uid];
1056
+ states[uid] = {
1057
+ oldState: latest.oldState,
1058
+ newState: newerState
1059
+ };
1060
+ };
1061
+ return wrapped;
1062
+ },
1063
+ wrapGetter(fn) {
1064
+ const wrapped = (uid, ...args) => {
1065
+ const {
1066
+ newState
1067
+ } = states[uid];
1068
+ return fn(newState, ...args);
1069
+ };
1070
+ return wrapped;
1071
+ },
1072
+ diff(uid, modules, numbers) {
1073
+ const {
1074
+ oldState,
1075
+ newState
1076
+ } = states[uid];
1077
+ const diffResult = [];
1078
+ for (let i = 0; i < modules.length; i++) {
1079
+ const fn = modules[i];
1080
+ if (!fn(oldState, newState)) {
1081
+ diffResult.push(numbers[i]);
1082
+ }
1083
+ }
1084
+ return diffResult;
1085
+ },
1086
+ getCommandIds() {
1087
+ const keys = Object.keys(commandMapRef);
1088
+ const ids = keys.map(toCommandId);
1089
+ return ids;
1090
+ },
1091
+ registerCommands(commandMap) {
1092
+ Object.assign(commandMapRef, commandMap);
1093
+ }
1094
+ };
1095
+ };
1096
+ const terminate = () => {
1097
+ globalThis.close();
1098
+ };
1099
+
1011
1100
  const rpcs = Object.create(null);
1012
1101
  const set$g = (id, rpc) => {
1013
1102
  rpcs[id] = rpc;
@@ -1018,7 +1107,7 @@ const get$1 = id => {
1018
1107
 
1019
1108
  /* eslint-disable @typescript-eslint/explicit-function-return-type */
1020
1109
 
1021
- const create$2 = rpcId => {
1110
+ const create$1 = rpcId => {
1022
1111
  return {
1023
1112
  // @ts-ignore
1024
1113
  invoke(method, ...params) {
@@ -1041,21 +1130,78 @@ const create$2 = rpcId => {
1041
1130
  }
1042
1131
  };
1043
1132
  };
1044
- const EditorWorker$1 = 99;
1133
+ const EditorWorker$2 = 99;
1045
1134
  const ExtensionHostWorker = 44;
1046
1135
  const {
1047
1136
  invoke: invoke$d,
1048
1137
  invokeAndTransfer: invokeAndTransfer$c,
1049
- set: set$c} = create$2(EditorWorker$1);
1050
- const EditorWorker = {
1138
+ set: set$c,
1139
+ dispose: dispose$c
1140
+ } = create$1(EditorWorker$2);
1141
+ const sendMessagePortToExtensionHostWorker$1$1 = async port => {
1142
+ const command = 'HandleMessagePort.handleMessagePort2';
1143
+ await invokeAndTransfer$c(
1144
+ // @ts-ignore
1145
+ 'SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, 0 // TODO
1146
+ );
1147
+ };
1148
+
1149
+ // TODO add tests for this
1150
+ const activateByEvent$1$1 = async event => {
1151
+ // @ts-ignore
1152
+ await invoke$d('ActivateByEvent.activateByEvent', event);
1153
+ };
1154
+ const applyEdit$2 = async (editorUid, changes) => {
1155
+ // @ts-ignore
1156
+ await EditorWorker.invoke('Editor.applyEdit2', editorUid, changes);
1157
+ };
1158
+ const closeWidget$1 = async (editorUid, widgetId, widgetName, focusId) => {
1159
+ // @ts-ignore
1160
+ await invoke$d('Editor.closeWidget2', editorUid, widgetId, widgetName, focusId);
1161
+ };
1162
+ const getWordAt$1 = async (uid, rowIndex, columnIndex) => {
1163
+ // @ts-ignore
1164
+ const word = await invoke$d('Editor.getWordAt2', uid, rowIndex, columnIndex);
1165
+ return word;
1166
+ };
1167
+ const getLines$2 = async editorUid => {
1168
+ const lines = await invoke$d('Editor.getLines2', editorUid);
1169
+ return lines;
1170
+ };
1171
+ const getPositionAtCursor$2 = async parentUid => {
1172
+ const position = await invoke$d('Editor.getPositionAtCursor', parentUid);
1173
+ return position;
1174
+ };
1175
+ const getSelections$2 = async editorUid => {
1176
+ const selections = await invoke$d('Editor.getSelections2', editorUid);
1177
+ return selections;
1178
+ };
1179
+ const getWordAtOffset2$1 = async editorUid => {
1180
+ return invoke$d('Editor.getWordAtOffset2', editorUid);
1181
+ };
1182
+ const getWordBefore$2 = async (editorUid, rowIndex, columnIndex) => {
1183
+ return invoke$d('Editor.getWordBefore2', editorUid, rowIndex, columnIndex);
1184
+ };
1185
+ const EditorWorker$1$1 = {
1051
1186
  __proto__: null,
1187
+ activateByEvent: activateByEvent$1$1,
1188
+ applyEdit: applyEdit$2,
1189
+ closeWidget: closeWidget$1,
1190
+ dispose: dispose$c,
1191
+ getLines: getLines$2,
1192
+ getPositionAtCursor: getPositionAtCursor$2,
1193
+ getSelections: getSelections$2,
1194
+ getWordAt: getWordAt$1,
1195
+ getWordAtOffset2: getWordAtOffset2$1,
1196
+ getWordBefore: getWordBefore$2,
1052
1197
  invoke: invoke$d,
1053
1198
  invokeAndTransfer: invokeAndTransfer$c,
1199
+ sendMessagePortToExtensionHostWorker: sendMessagePortToExtensionHostWorker$1$1,
1054
1200
  set: set$c
1055
1201
  };
1056
1202
  const {
1057
1203
  invoke: invoke$a,
1058
- set: set$9} = create$2(ExtensionHostWorker);
1204
+ set: set$9} = create$1(ExtensionHostWorker);
1059
1205
  const ExtensionHost = {
1060
1206
  __proto__: null,
1061
1207
  invoke: invoke$a,
@@ -1065,7 +1211,37 @@ const ExtensionHost = {
1065
1211
  const {
1066
1212
  invoke: invoke$1,
1067
1213
  set: set$2,
1068
- invokeAndTransfer} = EditorWorker;
1214
+ dispose: dispose$2,
1215
+ sendMessagePortToExtensionHostWorker: sendMessagePortToExtensionHostWorker$1,
1216
+ activateByEvent: activateByEvent$1,
1217
+ applyEdit: applyEdit$1,
1218
+ closeWidget,
1219
+ getLines: getLines$1,
1220
+ getPositionAtCursor: getPositionAtCursor$1,
1221
+ getSelections: getSelections$1,
1222
+ getWordAt,
1223
+ getWordAtOffset2,
1224
+ getWordBefore: getWordBefore$1,
1225
+ invokeAndTransfer
1226
+ } = EditorWorker$1$1;
1227
+
1228
+ const EditorWorker$1 = {
1229
+ __proto__: null,
1230
+ activateByEvent: activateByEvent$1,
1231
+ applyEdit: applyEdit$1,
1232
+ closeWidget,
1233
+ dispose: dispose$2,
1234
+ getLines: getLines$1,
1235
+ getPositionAtCursor: getPositionAtCursor$1,
1236
+ getSelections: getSelections$1,
1237
+ getWordAt,
1238
+ getWordAtOffset2,
1239
+ getWordBefore: getWordBefore$1,
1240
+ invoke: invoke$1,
1241
+ invokeAndTransfer,
1242
+ sendMessagePortToExtensionHostWorker: sendMessagePortToExtensionHostWorker$1,
1243
+ set: set$2
1244
+ };
1069
1245
 
1070
1246
  const FocusEditorCompletions = 9;
1071
1247
  const FocusEditorRename = 11;
@@ -1076,76 +1252,16 @@ const close = async state => {
1076
1252
  const {
1077
1253
  editorUid
1078
1254
  } = state;
1079
- // @ts-ignore
1080
- await invoke$1('Editor.closeWidget2', editorUid, Completion, 'Completions', FocusEditorCompletions);
1255
+ await closeWidget(editorUid, Completion, 'Completions', FocusEditorCompletions);
1081
1256
  return state;
1082
1257
  };
1083
1258
 
1084
- const create$1 = () => {
1085
- const states = Object.create(null);
1086
- return {
1087
- get(uid) {
1088
- return states[uid];
1089
- },
1090
- set(uid, oldState, newState) {
1091
- states[uid] = {
1092
- oldState,
1093
- newState
1094
- };
1095
- },
1096
- dispose(uid) {
1097
- delete states[uid];
1098
- },
1099
- getKeys() {
1100
- return Object.keys(states).map(key => {
1101
- return Number.parseInt(key);
1102
- });
1103
- },
1104
- clear() {
1105
- for (const key of Object.keys(states)) {
1106
- delete states[key];
1107
- }
1108
- },
1109
- wrapCommand(fn) {
1110
- const wrapped = async (uid, ...args) => {
1111
- const {
1112
- newState
1113
- } = states[uid];
1114
- const newerState = await fn(newState, ...args);
1115
- if (newState === newerState) {
1116
- return;
1117
- }
1118
- const latest = states[uid];
1119
- states[uid] = {
1120
- oldState: latest.oldState,
1121
- newState: newerState
1122
- };
1123
- };
1124
- return wrapped;
1125
- },
1126
- diff(uid, modules, numbers) {
1127
- const {
1128
- oldState,
1129
- newState
1130
- } = states[uid];
1131
- const diffResult = [];
1132
- for (let i = 0; i < modules.length; i++) {
1133
- const fn = modules[i];
1134
- if (!fn(oldState, newState)) {
1135
- diffResult.push(numbers[i]);
1136
- }
1137
- }
1138
- return diffResult;
1139
- }
1140
- };
1141
- };
1142
-
1143
1259
  const {
1144
1260
  get,
1145
1261
  set: set$1,
1146
1262
  wrapCommand,
1147
1263
  dispose: dispose$1
1148
- } = create$1();
1264
+ } = create$2();
1149
1265
 
1150
1266
  const create = (uid, x, y, width, height, editorUid, editorLanguageId) => {
1151
1267
  const state = {
@@ -1265,15 +1381,13 @@ const applyEdit = async (editorUid, changes) => {
1265
1381
  await invoke$1('Editor.applyEdit2', editorUid, changes);
1266
1382
  };
1267
1383
 
1268
- const getLines = async editorUid => {
1269
- const lines = await invoke$1('Editor.getLines2', editorUid);
1270
- return lines;
1271
- };
1384
+ const {
1385
+ getLines
1386
+ } = EditorWorker$1;
1272
1387
 
1273
- const getSelections = async editorUid => {
1274
- const selections = await invoke$1('Editor.getSelections2', editorUid);
1275
- return selections;
1276
- };
1388
+ const {
1389
+ getSelections
1390
+ } = EditorWorker$1;
1277
1391
 
1278
1392
  const getSelectionPairs = (selections, i) => {
1279
1393
  const first = selections[i];
@@ -1331,11 +1445,9 @@ const OnCompletion = 'onCompletion';
1331
1445
  const CompletionExecute = 'ExtensionHostCompletion.execute';
1332
1446
  const CompletionResolveExecute = 'ExtensionHostCompletion.executeResolve';
1333
1447
 
1334
- // TODO add tests for this
1335
- const activateByEvent = async event => {
1336
- // @ts-ignore
1337
- await invoke$1('ActivateByEvent.activateByEvent', event);
1338
- };
1448
+ const {
1449
+ activateByEvent
1450
+ } = EditorWorker$1;
1339
1451
 
1340
1452
  const {
1341
1453
  invoke,
@@ -1732,14 +1844,11 @@ const getListHeight = (itemsLength, itemHeight, maxHeight) => {
1732
1844
  return Math.min(totalHeight, maxHeight);
1733
1845
  };
1734
1846
 
1735
- const getPositionAtCursor = async parentUid => {
1736
- const position = await invoke$1('Editor.getPositionAtCursor', parentUid);
1737
- return position;
1738
- };
1847
+ const {
1848
+ getPositionAtCursor
1849
+ } = EditorWorker$1;
1739
1850
 
1740
- const getWordAtOffset = async editorUid => {
1741
- return invoke$1('Editor.getWordAtOffset2', editorUid);
1742
- };
1851
+ const getWordAtOffset = getWordAtOffset2;
1743
1852
 
1744
1853
  const handleEditorDeleteLeft = async state => {
1745
1854
  const {
@@ -1774,9 +1883,9 @@ const handleEditorDeleteLeft = async state => {
1774
1883
  };
1775
1884
  };
1776
1885
 
1777
- const getWordBefore = async (editorUid, rowIndex, columnIndex) => {
1778
- return invoke$1('Editor.getWordBefore2', editorUid, rowIndex, columnIndex);
1779
- };
1886
+ const {
1887
+ getWordBefore
1888
+ } = EditorWorker$1;
1780
1889
 
1781
1890
  const handleEditorType = async state => {
1782
1891
  const {
@@ -1880,36 +1989,15 @@ const handleWheel = (state, deltaMode, deltaY) => {
1880
1989
  return setDeltaY(state, state.deltaY + deltaY);
1881
1990
  };
1882
1991
 
1883
- const getPortTuple = () => {
1884
- const {
1885
- port1,
1886
- port2
1887
- } = new MessageChannel();
1888
- return {
1889
- port1,
1890
- port2
1891
- };
1892
- };
1893
-
1894
- const sendMessagePortToExtensionHostWorker = async port => {
1895
- const command = 'HandleMessagePort.handleMessagePort2';
1896
- // @ts-ignore
1897
- await invokeAndTransfer(
1898
- // @ts-ignore
1899
- 'SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, 0 // TODO
1900
- );
1901
- };
1992
+ const {
1993
+ sendMessagePortToExtensionHostWorker
1994
+ } = EditorWorker$1;
1902
1995
 
1903
1996
  const createExtensionHostRpc = async () => {
1904
1997
  try {
1905
- const {
1906
- port1,
1907
- port2
1908
- } = getPortTuple();
1909
- await sendMessagePortToExtensionHostWorker(port2);
1910
- const rpc = await PlainMessagePortRpcParent.create({
1998
+ const rpc = await TransferMessagePortRpcParent.create({
1911
1999
  commandMap: {},
1912
- messagePort: port1
2000
+ send: sendMessagePortToExtensionHostWorker
1913
2001
  });
1914
2002
  return rpc;
1915
2003
  } catch (error) {
@@ -1924,6 +2012,7 @@ const initialize = async () => {
1924
2012
 
1925
2013
  const error = message => {
1926
2014
  // TODO send this to error worker for logging
2015
+ // @ts-ignore
1927
2016
  console.error(message);
1928
2017
  };
1929
2018
 
@@ -2395,10 +2484,6 @@ const render2 = (uid, diffResult) => {
2395
2484
  return commands;
2396
2485
  };
2397
2486
 
2398
- const terminate = () => {
2399
- globalThis.close();
2400
- };
2401
-
2402
2487
  const commandMap = {
2403
2488
  'Completions.close': wrapCommand(close),
2404
2489
  'Completions.create': create,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/completion-worker",
3
- "version": "1.21.0",
3
+ "version": "1.23.0",
4
4
  "description": "Web Worker for the find widget in Lvce Editor",
5
5
  "repository": {
6
6
  "type": "git",