@lvce-editor/completion-worker 1.20.0 → 1.22.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.
@@ -60,43 +60,51 @@ class AssertionError extends Error {
60
60
  this.name = 'AssertionError';
61
61
  }
62
62
  }
63
+ const Object$1 = 1;
64
+ const Number$1 = 2;
65
+ const Array$1 = 3;
66
+ const String = 4;
67
+ const Boolean$1 = 5;
68
+ const Function$1 = 6;
69
+ const Null = 7;
70
+ const Unknown = 8;
63
71
  const getType = value => {
64
72
  switch (typeof value) {
65
73
  case 'number':
66
- return 'number';
74
+ return Number$1;
67
75
  case 'function':
68
- return 'function';
76
+ return Function$1;
69
77
  case 'string':
70
- return 'string';
78
+ return String;
71
79
  case 'object':
72
80
  if (value === null) {
73
- return 'null';
81
+ return Null;
74
82
  }
75
83
  if (Array.isArray(value)) {
76
- return 'array';
84
+ return Array$1;
77
85
  }
78
- return 'object';
86
+ return Object$1;
79
87
  case 'boolean':
80
- return 'boolean';
88
+ return Boolean$1;
81
89
  default:
82
- return 'unknown';
90
+ return Unknown;
83
91
  }
84
92
  };
85
93
  const object = value => {
86
94
  const type = getType(value);
87
- if (type !== 'object') {
95
+ if (type !== Object$1) {
88
96
  throw new AssertionError('expected value to be of type object');
89
97
  }
90
98
  };
91
99
  const number = value => {
92
100
  const type = getType(value);
93
- if (type !== 'number') {
101
+ if (type !== Number$1) {
94
102
  throw new AssertionError('expected value to be of type number');
95
103
  }
96
104
  };
97
105
  const string = value => {
98
106
  const type = getType(value);
99
- if (type !== 'string') {
107
+ if (type !== String) {
100
108
  throw new AssertionError('expected value to be of type string');
101
109
  }
102
110
  };
@@ -956,7 +964,7 @@ const listen$1 = async (module, options) => {
956
964
  const ipc = module.wrap(rawIpc);
957
965
  return ipc;
958
966
  };
959
- const create$3 = async ({
967
+ const create$4 = async ({
960
968
  commandMap,
961
969
  messagePort
962
970
  }) => {
@@ -974,18 +982,23 @@ const create$3 = async ({
974
982
  };
975
983
  const create$2$1 = async ({
976
984
  commandMap,
977
- messagePort
985
+ send
978
986
  }) => {
979
- return create$3({
987
+ const {
988
+ port1,
989
+ port2
990
+ } = new MessageChannel();
991
+ await send(port1);
992
+ return create$4({
980
993
  commandMap,
981
- messagePort
994
+ messagePort: port2
982
995
  });
983
996
  };
984
- const PlainMessagePortRpcParent = {
997
+ const TransferMessagePortRpcParent = {
985
998
  __proto__: null,
986
999
  create: create$2$1
987
1000
  };
988
- const create$4 = async ({
1001
+ const create$3 = async ({
989
1002
  commandMap
990
1003
  }) => {
991
1004
  // TODO create a commandMap per rpc instance
@@ -997,11 +1010,73 @@ const create$4 = async ({
997
1010
  };
998
1011
  const WebWorkerRpcClient = {
999
1012
  __proto__: null,
1000
- create: create$4
1013
+ create: create$3
1014
+ };
1015
+
1016
+ const create$2 = () => {
1017
+ const states = Object.create(null);
1018
+ return {
1019
+ get(uid) {
1020
+ return states[uid];
1021
+ },
1022
+ set(uid, oldState, newState) {
1023
+ states[uid] = {
1024
+ oldState,
1025
+ newState
1026
+ };
1027
+ },
1028
+ dispose(uid) {
1029
+ delete states[uid];
1030
+ },
1031
+ getKeys() {
1032
+ return Object.keys(states).map(key => {
1033
+ return Number.parseInt(key);
1034
+ });
1035
+ },
1036
+ clear() {
1037
+ for (const key of Object.keys(states)) {
1038
+ delete states[key];
1039
+ }
1040
+ },
1041
+ wrapCommand(fn) {
1042
+ const wrapped = async (uid, ...args) => {
1043
+ const {
1044
+ newState
1045
+ } = states[uid];
1046
+ const newerState = await fn(newState, ...args);
1047
+ if (newState === newerState) {
1048
+ return;
1049
+ }
1050
+ const latest = states[uid];
1051
+ states[uid] = {
1052
+ oldState: latest.oldState,
1053
+ newState: newerState
1054
+ };
1055
+ };
1056
+ return wrapped;
1057
+ },
1058
+ diff(uid, modules, numbers) {
1059
+ const {
1060
+ oldState,
1061
+ newState
1062
+ } = states[uid];
1063
+ const diffResult = [];
1064
+ for (let i = 0; i < modules.length; i++) {
1065
+ const fn = modules[i];
1066
+ if (!fn(oldState, newState)) {
1067
+ diffResult.push(numbers[i]);
1068
+ }
1069
+ }
1070
+ return diffResult;
1071
+ }
1072
+ };
1073
+ };
1074
+ const terminate = () => {
1075
+ globalThis.close();
1001
1076
  };
1002
1077
 
1003
1078
  const rpcs = Object.create(null);
1004
- const set$f = (id, rpc) => {
1079
+ const set$g = (id, rpc) => {
1005
1080
  rpcs[id] = rpc;
1006
1081
  };
1007
1082
  const get$1 = id => {
@@ -1010,7 +1085,7 @@ const get$1 = id => {
1010
1085
 
1011
1086
  /* eslint-disable @typescript-eslint/explicit-function-return-type */
1012
1087
 
1013
- const create$2 = rpcId => {
1088
+ const create$1 = rpcId => {
1014
1089
  return {
1015
1090
  // @ts-ignore
1016
1091
  invoke(method, ...params) {
@@ -1025,7 +1100,7 @@ const create$2 = rpcId => {
1025
1100
  return rpc.invokeAndTransfer(method, ...params);
1026
1101
  },
1027
1102
  set(rpc) {
1028
- set$f(rpcId, rpc);
1103
+ set$g(rpcId, rpc);
1029
1104
  },
1030
1105
  async dispose() {
1031
1106
  const rpc = get$1(rpcId);
@@ -1033,31 +1108,118 @@ const create$2 = rpcId => {
1033
1108
  }
1034
1109
  };
1035
1110
  };
1036
- const EditorWorker$1 = 99;
1111
+ const EditorWorker$2 = 99;
1037
1112
  const ExtensionHostWorker = 44;
1038
1113
  const {
1039
- invoke: invoke$c,
1114
+ invoke: invoke$d,
1040
1115
  invokeAndTransfer: invokeAndTransfer$c,
1041
- set: set$c} = create$2(EditorWorker$1);
1042
- const EditorWorker = {
1116
+ set: set$c,
1117
+ dispose: dispose$c
1118
+ } = create$1(EditorWorker$2);
1119
+ const sendMessagePortToExtensionHostWorker$1$1 = async port => {
1120
+ const command = 'HandleMessagePort.handleMessagePort2';
1121
+ await invokeAndTransfer$c(
1122
+ // @ts-ignore
1123
+ 'SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, 0 // TODO
1124
+ );
1125
+ };
1126
+
1127
+ // TODO add tests for this
1128
+ const activateByEvent$1$1 = async event => {
1129
+ // @ts-ignore
1130
+ await invoke$d('ActivateByEvent.activateByEvent', event);
1131
+ };
1132
+ const applyEdit$2 = async (editorUid, changes) => {
1133
+ // @ts-ignore
1134
+ await EditorWorker.invoke('Editor.applyEdit2', editorUid, changes);
1135
+ };
1136
+ const closeWidget$1 = async (editorUid, widgetId, widgetName, focusId) => {
1137
+ // @ts-ignore
1138
+ await invoke$d('Editor.closeWidget2', editorUid, widgetId, widgetName, focusId);
1139
+ };
1140
+ const getWordAt$1 = async (uid, rowIndex, columnIndex) => {
1141
+ // @ts-ignore
1142
+ const word = await invoke$d('Editor.getWordAt2', uid, rowIndex, columnIndex);
1143
+ return word;
1144
+ };
1145
+ const getLines$2 = async editorUid => {
1146
+ const lines = await invoke$d('Editor.getLines2', editorUid);
1147
+ return lines;
1148
+ };
1149
+ const getPositionAtCursor$2 = async parentUid => {
1150
+ const position = await invoke$d('Editor.getPositionAtCursor', parentUid);
1151
+ return position;
1152
+ };
1153
+ const getSelections$2 = async editorUid => {
1154
+ const selections = await invoke$d('Editor.getSelections2', editorUid);
1155
+ return selections;
1156
+ };
1157
+ const getWordAtOffset2$1 = async editorUid => {
1158
+ return invoke$d('Editor.getWordAtOffset2', editorUid);
1159
+ };
1160
+ const getWordBefore$2 = async (editorUid, rowIndex, columnIndex) => {
1161
+ return invoke$d('Editor.getWordBefore2', editorUid, rowIndex, columnIndex);
1162
+ };
1163
+ const EditorWorker$1$1 = {
1043
1164
  __proto__: null,
1044
- invoke: invoke$c,
1165
+ activateByEvent: activateByEvent$1$1,
1166
+ applyEdit: applyEdit$2,
1167
+ closeWidget: closeWidget$1,
1168
+ dispose: dispose$c,
1169
+ getLines: getLines$2,
1170
+ getPositionAtCursor: getPositionAtCursor$2,
1171
+ getSelections: getSelections$2,
1172
+ getWordAt: getWordAt$1,
1173
+ getWordAtOffset2: getWordAtOffset2$1,
1174
+ getWordBefore: getWordBefore$2,
1175
+ invoke: invoke$d,
1045
1176
  invokeAndTransfer: invokeAndTransfer$c,
1177
+ sendMessagePortToExtensionHostWorker: sendMessagePortToExtensionHostWorker$1$1,
1046
1178
  set: set$c
1047
1179
  };
1048
1180
  const {
1049
- invoke: invoke$9,
1050
- set: set$9} = create$2(ExtensionHostWorker);
1181
+ invoke: invoke$a,
1182
+ set: set$9} = create$1(ExtensionHostWorker);
1051
1183
  const ExtensionHost = {
1052
1184
  __proto__: null,
1053
- invoke: invoke$9,
1185
+ invoke: invoke$a,
1054
1186
  set: set$9
1055
1187
  };
1056
1188
 
1057
1189
  const {
1058
1190
  invoke: invoke$1,
1059
1191
  set: set$2,
1060
- invokeAndTransfer} = EditorWorker;
1192
+ dispose: dispose$2,
1193
+ sendMessagePortToExtensionHostWorker: sendMessagePortToExtensionHostWorker$1,
1194
+ activateByEvent: activateByEvent$1,
1195
+ applyEdit: applyEdit$1,
1196
+ closeWidget,
1197
+ getLines: getLines$1,
1198
+ getPositionAtCursor: getPositionAtCursor$1,
1199
+ getSelections: getSelections$1,
1200
+ getWordAt,
1201
+ getWordAtOffset2,
1202
+ getWordBefore: getWordBefore$1,
1203
+ invokeAndTransfer
1204
+ } = EditorWorker$1$1;
1205
+
1206
+ const EditorWorker$1 = {
1207
+ __proto__: null,
1208
+ activateByEvent: activateByEvent$1,
1209
+ applyEdit: applyEdit$1,
1210
+ closeWidget,
1211
+ dispose: dispose$2,
1212
+ getLines: getLines$1,
1213
+ getPositionAtCursor: getPositionAtCursor$1,
1214
+ getSelections: getSelections$1,
1215
+ getWordAt,
1216
+ getWordAtOffset2,
1217
+ getWordBefore: getWordBefore$1,
1218
+ invoke: invoke$1,
1219
+ invokeAndTransfer,
1220
+ sendMessagePortToExtensionHostWorker: sendMessagePortToExtensionHostWorker$1,
1221
+ set: set$2
1222
+ };
1061
1223
 
1062
1224
  const FocusEditorCompletions = 9;
1063
1225
  const FocusEditorRename = 11;
@@ -1068,76 +1230,16 @@ const close = async state => {
1068
1230
  const {
1069
1231
  editorUid
1070
1232
  } = state;
1071
- // @ts-ignore
1072
- await invoke$1('Editor.closeWidget2', editorUid, Completion, 'Completions', FocusEditorCompletions);
1233
+ await closeWidget(editorUid, Completion, 'Completions', FocusEditorCompletions);
1073
1234
  return state;
1074
1235
  };
1075
1236
 
1076
- const create$1 = () => {
1077
- const states = Object.create(null);
1078
- return {
1079
- get(uid) {
1080
- return states[uid];
1081
- },
1082
- set(uid, oldState, newState) {
1083
- states[uid] = {
1084
- oldState,
1085
- newState
1086
- };
1087
- },
1088
- dispose(uid) {
1089
- delete states[uid];
1090
- },
1091
- getKeys() {
1092
- return Object.keys(states).map(key => {
1093
- return Number.parseInt(key);
1094
- });
1095
- },
1096
- clear() {
1097
- for (const key of Object.keys(states)) {
1098
- delete states[key];
1099
- }
1100
- },
1101
- wrapCommand(fn) {
1102
- const wrapped = async (uid, ...args) => {
1103
- const {
1104
- newState
1105
- } = states[uid];
1106
- const newerState = await fn(newState, ...args);
1107
- if (newState === newerState) {
1108
- return;
1109
- }
1110
- const latest = states[uid];
1111
- states[uid] = {
1112
- oldState: latest.oldState,
1113
- newState: newerState
1114
- };
1115
- };
1116
- return wrapped;
1117
- },
1118
- diff(uid, modules, numbers) {
1119
- const {
1120
- oldState,
1121
- newState
1122
- } = states[uid];
1123
- const diffResult = [];
1124
- for (let i = 0; i < modules.length; i++) {
1125
- const fn = modules[i];
1126
- if (!fn(oldState, newState)) {
1127
- diffResult.push(numbers[i]);
1128
- }
1129
- }
1130
- return diffResult;
1131
- }
1132
- };
1133
- };
1134
-
1135
1237
  const {
1136
1238
  get,
1137
1239
  set: set$1,
1138
1240
  wrapCommand,
1139
1241
  dispose: dispose$1
1140
- } = create$1();
1242
+ } = create$2();
1141
1243
 
1142
1244
  const create = (uid, x, y, width, height, editorUid, editorLanguageId) => {
1143
1245
  const state = {
@@ -1257,15 +1359,13 @@ const applyEdit = async (editorUid, changes) => {
1257
1359
  await invoke$1('Editor.applyEdit2', editorUid, changes);
1258
1360
  };
1259
1361
 
1260
- const getLines = async editorUid => {
1261
- const lines = await invoke$1('Editor.getLines2', editorUid);
1262
- return lines;
1263
- };
1362
+ const {
1363
+ getLines
1364
+ } = EditorWorker$1;
1264
1365
 
1265
- const getSelections = async editorUid => {
1266
- const selections = await invoke$1('Editor.getSelections2', editorUid);
1267
- return selections;
1268
- };
1366
+ const {
1367
+ getSelections
1368
+ } = EditorWorker$1;
1269
1369
 
1270
1370
  const getSelectionPairs = (selections, i) => {
1271
1371
  const first = selections[i];
@@ -1323,11 +1423,9 @@ const OnCompletion = 'onCompletion';
1323
1423
  const CompletionExecute = 'ExtensionHostCompletion.execute';
1324
1424
  const CompletionResolveExecute = 'ExtensionHostCompletion.executeResolve';
1325
1425
 
1326
- // TODO add tests for this
1327
- const activateByEvent = async event => {
1328
- // @ts-ignore
1329
- await invoke$1('ActivateByEvent.activateByEvent', event);
1330
- };
1426
+ const {
1427
+ activateByEvent
1428
+ } = EditorWorker$1;
1331
1429
 
1332
1430
  const {
1333
1431
  invoke,
@@ -1724,14 +1822,11 @@ const getListHeight = (itemsLength, itemHeight, maxHeight) => {
1724
1822
  return Math.min(totalHeight, maxHeight);
1725
1823
  };
1726
1824
 
1727
- const getPositionAtCursor = async parentUid => {
1728
- const position = await invoke$1('Editor.getPositionAtCursor', parentUid);
1729
- return position;
1730
- };
1825
+ const {
1826
+ getPositionAtCursor
1827
+ } = EditorWorker$1;
1731
1828
 
1732
- const getWordAtOffset = async editorUid => {
1733
- return invoke$1('Editor.getWordAtOffset2', editorUid);
1734
- };
1829
+ const getWordAtOffset = getWordAtOffset2;
1735
1830
 
1736
1831
  const handleEditorDeleteLeft = async state => {
1737
1832
  const {
@@ -1766,9 +1861,9 @@ const handleEditorDeleteLeft = async state => {
1766
1861
  };
1767
1862
  };
1768
1863
 
1769
- const getWordBefore = async (editorUid, rowIndex, columnIndex) => {
1770
- return invoke$1('Editor.getWordBefore2', editorUid, rowIndex, columnIndex);
1771
- };
1864
+ const {
1865
+ getWordBefore
1866
+ } = EditorWorker$1;
1772
1867
 
1773
1868
  const handleEditorType = async state => {
1774
1869
  const {
@@ -1872,36 +1967,15 @@ const handleWheel = (state, deltaMode, deltaY) => {
1872
1967
  return setDeltaY(state, state.deltaY + deltaY);
1873
1968
  };
1874
1969
 
1875
- const getPortTuple = () => {
1876
- const {
1877
- port1,
1878
- port2
1879
- } = new MessageChannel();
1880
- return {
1881
- port1,
1882
- port2
1883
- };
1884
- };
1885
-
1886
- const sendMessagePortToExtensionHostWorker = async port => {
1887
- const command = 'HandleMessagePort.handleMessagePort2';
1888
- // @ts-ignore
1889
- await invokeAndTransfer(
1890
- // @ts-ignore
1891
- 'SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, 0 // TODO
1892
- );
1893
- };
1970
+ const {
1971
+ sendMessagePortToExtensionHostWorker
1972
+ } = EditorWorker$1;
1894
1973
 
1895
1974
  const createExtensionHostRpc = async () => {
1896
1975
  try {
1897
- const {
1898
- port1,
1899
- port2
1900
- } = getPortTuple();
1901
- await sendMessagePortToExtensionHostWorker(port2);
1902
- const rpc = await PlainMessagePortRpcParent.create({
1976
+ const rpc = await TransferMessagePortRpcParent.create({
1903
1977
  commandMap: {},
1904
- messagePort: port1
1978
+ send: sendMessagePortToExtensionHostWorker
1905
1979
  });
1906
1980
  return rpc;
1907
1981
  } catch (error) {
@@ -1916,6 +1990,7 @@ const initialize = async () => {
1916
1990
 
1917
1991
  const error = message => {
1918
1992
  // TODO send this to error worker for logging
1993
+ // @ts-ignore
1919
1994
  console.error(message);
1920
1995
  };
1921
1996
 
@@ -2387,10 +2462,6 @@ const render2 = (uid, diffResult) => {
2387
2462
  return commands;
2388
2463
  };
2389
2464
 
2390
- const terminate = () => {
2391
- globalThis.close();
2392
- };
2393
-
2394
2465
  const commandMap = {
2395
2466
  'Completions.close': wrapCommand(close),
2396
2467
  'Completions.create': create,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/completion-worker",
3
- "version": "1.20.0",
3
+ "version": "1.22.0",
4
4
  "description": "Web Worker for the find widget in Lvce Editor",
5
5
  "repository": {
6
6
  "type": "git",