@lvce-editor/completion-worker 1.7.0 → 1.8.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.
@@ -967,7 +967,79 @@ const WebWorkerRpcClient = {
967
967
  create: create$4
968
968
  };
969
969
 
970
- const create$2 = () => {
970
+ const rpcs = Object.create(null);
971
+ const set$a = (id, rpc) => {
972
+ rpcs[id] = rpc;
973
+ };
974
+ const get$1 = id => {
975
+ return rpcs[id];
976
+ };
977
+
978
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
979
+
980
+ const create$2 = rpcId => {
981
+ return {
982
+ // @ts-ignore
983
+ invoke(method, ...params) {
984
+ const rpc = get$1(rpcId);
985
+ // @ts-ignore
986
+ return rpc.invoke(method, ...params);
987
+ },
988
+ // @ts-ignore
989
+ invokeAndTransfer(method, ...params) {
990
+ const rpc = get$1(rpcId);
991
+ // @ts-ignore
992
+ return rpc.invokeAndTransfer(method, ...params);
993
+ },
994
+ set(rpc) {
995
+ set$a(rpcId, rpc);
996
+ }
997
+ };
998
+ };
999
+ const EditorWorker$1 = 99;
1000
+ const ExtensionHostWorker = 44;
1001
+ const {
1002
+ invoke: invoke$9,
1003
+ invokeAndTransfer: invokeAndTransfer$9,
1004
+ set: set$9
1005
+ } = create$2(EditorWorker$1);
1006
+ const EditorWorker = {
1007
+ __proto__: null,
1008
+ invoke: invoke$9,
1009
+ invokeAndTransfer: invokeAndTransfer$9,
1010
+ set: set$9
1011
+ };
1012
+ const {
1013
+ invoke: invoke$7,
1014
+ set: set$7
1015
+ } = create$2(ExtensionHostWorker);
1016
+ const ExtensionHost = {
1017
+ __proto__: null,
1018
+ invoke: invoke$7,
1019
+ set: set$7
1020
+ };
1021
+
1022
+ const {
1023
+ invoke: invoke$1,
1024
+ set: set$2,
1025
+ invokeAndTransfer
1026
+ } = EditorWorker;
1027
+
1028
+ const FocusEditorCompletions = 9;
1029
+ const FocusEditorRename = 11;
1030
+
1031
+ const Completion = 3;
1032
+
1033
+ const close = async state => {
1034
+ const {
1035
+ editorUid
1036
+ } = state;
1037
+ // @ts-ignore
1038
+ await invoke$1('Editor.closeWidget2', editorUid, Completion, 'Completions', FocusEditorCompletions);
1039
+ return state;
1040
+ };
1041
+
1042
+ const create$1 = () => {
971
1043
  const states = Object.create(null);
972
1044
  return {
973
1045
  get(uid) {
@@ -1027,13 +1099,13 @@ const create$2 = () => {
1027
1099
  };
1028
1100
 
1029
1101
  const {
1030
- get: get$1,
1031
- set: set$2,
1102
+ get,
1103
+ set: set$1,
1032
1104
  wrapCommand,
1033
1105
  dispose: dispose$1
1034
- } = create$2();
1106
+ } = create$1();
1035
1107
 
1036
- const create$1 = (uid, x, y, width, height, editorUid, editorLanguageId) => {
1108
+ const create = (uid, x, y, width, height, editorUid, editorLanguageId) => {
1037
1109
  const state = {
1038
1110
  uid,
1039
1111
  items: [],
@@ -1056,7 +1128,7 @@ const create$1 = (uid, x, y, width, height, editorUid, editorLanguageId) => {
1056
1128
  editorUid,
1057
1129
  editorLanguageId
1058
1130
  };
1059
- set$2(uid, state, state);
1131
+ set$1(uid, state, state);
1060
1132
  };
1061
1133
 
1062
1134
  const isEqual$4 = (oldState, newState) => {
@@ -1104,7 +1176,7 @@ const diff2 = uid => {
1104
1176
  const {
1105
1177
  oldState,
1106
1178
  newState
1107
- } = get$1(uid);
1179
+ } = get(uid);
1108
1180
  const diffResult = diff(oldState, newState);
1109
1181
  return diffResult;
1110
1182
  };
@@ -1145,64 +1217,11 @@ const openDetails = async state => {
1145
1217
  return state;
1146
1218
  };
1147
1219
 
1148
- const rpcs = Object.create(null);
1149
- const set$a = (id, rpc) => {
1150
- rpcs[id] = rpc;
1151
- };
1152
- const get = id => {
1153
- return rpcs[id];
1154
- };
1155
-
1156
- /* eslint-disable @typescript-eslint/explicit-function-return-type */
1157
-
1158
- const create = rpcId => {
1159
- return {
1160
- // @ts-ignore
1161
- invoke(method, ...params) {
1162
- const rpc = get(rpcId);
1163
- // @ts-ignore
1164
- return rpc.invoke(method, ...params);
1165
- },
1166
- // @ts-ignore
1167
- invokeAndTransfer(method, ...params) {
1168
- const rpc = get(rpcId);
1169
- // @ts-ignore
1170
- return rpc.invokeAndTransfer(method, ...params);
1171
- },
1172
- set(rpc) {
1173
- set$a(rpcId, rpc);
1174
- }
1175
- };
1176
- };
1177
- const EditorWorker$1 = 99;
1178
- const ExtensionHostWorker = 44;
1179
- const {
1180
- invoke: invoke$9,
1181
- invokeAndTransfer: invokeAndTransfer$9,
1182
- set: set$9
1183
- } = create(EditorWorker$1);
1184
- const EditorWorker = {
1185
- __proto__: null,
1186
- invoke: invoke$9,
1187
- invokeAndTransfer: invokeAndTransfer$9,
1188
- set: set$9
1189
- };
1190
- const {
1191
- invoke: invoke$7,
1192
- set: set$7
1193
- } = create(ExtensionHostWorker);
1194
- const ExtensionHost = {
1195
- __proto__: null,
1196
- invoke: invoke$7,
1197
- set: set$7
1220
+ const applyEdit = async (editorUid, changes) => {
1221
+ // @ts-ignore
1222
+ await invoke$1('Editor.applyEdit2', editorUid, changes);
1198
1223
  };
1199
1224
 
1200
- const {
1201
- invoke: invoke$1,
1202
- set: set$1,
1203
- invokeAndTransfer
1204
- } = EditorWorker;
1205
-
1206
1225
  const OnCompletion = 'onCompletion';
1207
1226
 
1208
1227
  const CompletionExecute = 'ExtensionHostCompletion.execute';
@@ -1344,22 +1363,14 @@ const getEdits = async (editorUid, leadingWord, completionItem) => {
1344
1363
  return changes;
1345
1364
  };
1346
1365
 
1347
- const Completion = 3;
1348
-
1349
1366
  const select = async (state, completionItem) => {
1350
1367
  const {
1351
1368
  editorUid,
1352
1369
  leadingWord
1353
1370
  } = state;
1354
1371
  const changes = await getEdits(editorUid, leadingWord, completionItem);
1355
- // @ts-ignore
1356
- await invoke$1('Editor.applyEdit2', editorUid, changes);
1357
- // @ts-ignore
1358
- await invoke$1('Editor.closeWidget2', editorUid, Completion, 'Completions');
1359
- // TODO remove completion widget from editor
1360
- return {
1361
- ...state
1362
- };
1372
+ await applyEdit(editorUid, changes);
1373
+ return close(state);
1363
1374
  };
1364
1375
 
1365
1376
  const selectIndex = async (state, index) => {
@@ -1391,6 +1402,7 @@ const getCommandIds = () => {
1391
1402
  };
1392
1403
 
1393
1404
  const Enter = 3;
1405
+ const Escape = 8;
1394
1406
  const Space$1 = 9;
1395
1407
  const End = 255;
1396
1408
  const Home = 12;
@@ -1399,9 +1411,6 @@ const DownArrow = 16;
1399
1411
 
1400
1412
  const CtrlCmd = 1 << 11 >>> 0;
1401
1413
 
1402
- const FocusEditorCompletions = 9;
1403
- const FocusEditorRename = 11;
1404
-
1405
1414
  const getCommand = shortId => {
1406
1415
  return {
1407
1416
  command: 'Editor.executeWidgetCommand',
@@ -1433,6 +1442,10 @@ const getKeyBindings = () => {
1433
1442
  key: CtrlCmd | Space$1,
1434
1443
  ...getCommand('toggleDetails'),
1435
1444
  when: FocusEditorCompletions
1445
+ }, {
1446
+ key: Escape,
1447
+ ...getCommand('close'),
1448
+ when: FocusEditorCompletions
1436
1449
  }];
1437
1450
  };
1438
1451
 
@@ -2199,8 +2212,8 @@ const render2 = (uid, diffResult) => {
2199
2212
  const {
2200
2213
  oldState,
2201
2214
  newState
2202
- } = get$1(uid);
2203
- set$2(uid, newState, newState);
2215
+ } = get(uid);
2216
+ set$1(uid, newState, newState);
2204
2217
  const commands = applyRender(oldState, newState, diffResult);
2205
2218
  return commands;
2206
2219
  };
@@ -2210,7 +2223,8 @@ const terminate = () => {
2210
2223
  };
2211
2224
 
2212
2225
  const commandMap = {
2213
- 'Completions.create': create$1,
2226
+ 'Completions.close': wrapCommand(close),
2227
+ 'Completions.create': create,
2214
2228
  'Completions.diff2': diff2,
2215
2229
  'Completions.dispose': dispose,
2216
2230
  'Completions.focusFirst': wrapCommand(focusFirst),
@@ -2224,18 +2238,18 @@ const commandMap = {
2224
2238
  'Completions.handleWheel': wrapCommand(handleWheel),
2225
2239
  'Completions.initialize': initialize,
2226
2240
  'Completions.loadContent': wrapCommand(loadContent),
2241
+ 'Completions.openDetails': wrapCommand(openDetails),
2227
2242
  'Completions.render2': render2,
2228
2243
  'Completions.selectCurrent': wrapCommand(selectCurrent),
2229
2244
  'Completions.selectIndex': wrapCommand(selectIndex),
2230
- 'Completions.terminate': terminate,
2231
- 'Completions.openDetails': wrapCommand(openDetails)
2245
+ 'Completions.terminate': terminate
2232
2246
  };
2233
2247
 
2234
2248
  const listen = async () => {
2235
2249
  const rpc = await WebWorkerRpcClient.create({
2236
2250
  commandMap: commandMap
2237
2251
  });
2238
- set$1(rpc);
2252
+ set$2(rpc);
2239
2253
  };
2240
2254
 
2241
2255
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/completion-worker",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "description": "Web Worker for the find widget in Lvce Editor",
5
5
  "repository": {
6
6
  "type": "git",