@lvce-editor/extension-search-view 1.2.0 → 1.4.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.
package/README.md CHANGED
@@ -1 +1,7 @@
1
- # extension-search-view
1
+ # Extension Search View
2
+
3
+ Webworker for the extension search view in Lvce Editor.
4
+
5
+ ## Gitpod
6
+
7
+ [![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/lvce-editor/extension-search-view)
@@ -1,11 +1,6 @@
1
1
  const commands = Object.create(null);
2
- const registerCommand = (key, fn) => {
3
- commands[key] = fn;
4
- };
5
2
  const register = commandMap => {
6
- for (const [key, value] of Object.entries(commandMap)) {
7
- registerCommand(key, value);
8
- }
3
+ Object.assign(commands, commandMap);
9
4
  };
10
5
  const getCommand = key => {
11
6
  return commands[key];
@@ -74,13 +69,13 @@ const getFinalDeltaY = (height, itemHeight, itemsLength) => {
74
69
  return finalDeltaY;
75
70
  };
76
71
 
77
- let AssertionError$1 = class AssertionError extends Error {
72
+ class AssertionError extends Error {
78
73
  constructor(message) {
79
74
  super(message);
80
75
  this.name = 'AssertionError';
81
76
  }
82
- };
83
- const getType$2 = value => {
77
+ }
78
+ const getType = value => {
84
79
  switch (typeof value) {
85
80
  case 'number':
86
81
  return 'number';
@@ -102,17 +97,17 @@ const getType$2 = value => {
102
97
  return 'unknown';
103
98
  }
104
99
  };
105
- const number$1 = value => {
106
- const type = getType$2(value);
100
+ const number = value => {
101
+ const type = getType(value);
107
102
  if (type !== 'number') {
108
- throw new AssertionError$1('expected value to be of type number');
103
+ throw new AssertionError('expected value to be of type number');
109
104
  }
110
105
  };
111
106
 
112
107
  const getListHeight$1 = (itemsLength, itemHeight, maxHeight) => {
113
- number$1(itemsLength);
114
- number$1(itemHeight);
115
- number$1(maxHeight);
108
+ number(itemsLength);
109
+ number(itemHeight);
110
+ number(maxHeight);
116
111
  if (itemsLength === 0) {
117
112
  return itemHeight;
118
113
  }
@@ -196,6 +191,46 @@ const parseValue = value => {
196
191
 
197
192
  const assetDir = '';
198
193
 
194
+ const Web = 1;
195
+ const Electron = 2;
196
+ const Remote = 3;
197
+ const Test = 4;
198
+
199
+ // TODO treeshake this function out
200
+
201
+ /**
202
+ * @returns {number}
203
+ */
204
+ const getPlatform = () => {
205
+ // @ts-ignore
206
+ if (typeof PLATFORM !== 'undefined') {
207
+ // @ts-ignore
208
+ return PLATFORM;
209
+ }
210
+ if (typeof process !== 'undefined' && process.env.NODE_ENV === 'test') {
211
+ return Test;
212
+ }
213
+ // TODO find a better way to pass runtime environment
214
+ if (typeof name !== 'undefined' && name.endsWith('(Electron)')) {
215
+ return Electron;
216
+ }
217
+ if (typeof name !== 'undefined' && name.endsWith('(Web)')) {
218
+ return Web;
219
+ }
220
+ return Remote;
221
+ };
222
+ const platform = getPlatform();
223
+
224
+ const getRemoteUrl = extension => {
225
+ if (platform === Remote || platform === Electron) {
226
+ if (extension.builtin) {
227
+ return `${assetDir}/extensions/${extension.id}/${extension.icon}`;
228
+ }
229
+ return `/remote/${extension.path}/${extension.icon}`; // TODO support windows paths
230
+ }
231
+ return '';
232
+ };
233
+
199
234
  const ExtensionDefaultIcon = `${assetDir}/icons/extensionDefaultIcon.png`;
200
235
  const ExtensionLanguageBasics = `${assetDir}/icons/language-icon.svg`;
201
236
  const ExtensionTheme = `${assetDir}/icons/theme-icon.png`;
@@ -219,7 +254,7 @@ const getIcon = extension => {
219
254
  }
220
255
  return ExtensionDefaultIcon;
221
256
  }
222
- return '';
257
+ return getRemoteUrl(extension);
223
258
  };
224
259
  const RE_PUBLISHER = /^[a-z\d\-]+/;
225
260
 
@@ -300,10 +335,10 @@ const getExtensions = async (extensions, parsedValue) => {
300
335
 
301
336
  const normalizeLine$1 = line => {
302
337
  if (line.startsWith('Error: ')) {
303
- return line.slice(`Error: `.length);
338
+ return line.slice('Error: '.length);
304
339
  }
305
340
  if (line.startsWith('VError: ')) {
306
- return line.slice(`VError: `.length);
341
+ return line.slice('VError: '.length);
307
342
  }
308
343
  return line;
309
344
  };
@@ -429,6 +464,63 @@ const clearSearchResults = state => {
429
464
  return handleInput(state, '');
430
465
  };
431
466
 
467
+ const Enter = 3;
468
+ const Space = 9;
469
+ const PageUp = 10;
470
+ const PageDown = 11;
471
+ const End = 255;
472
+ const Home = 12;
473
+ const UpArrow = 14;
474
+ const DownArrow = 16;
475
+
476
+ const CtrlCmd = 1 << 11 >>> 0;
477
+
478
+ const FocusExtensions = 15;
479
+
480
+ const getKeyBindings = () => {
481
+ return [{
482
+ key: Home,
483
+ command: 'Extensions.focusFirst',
484
+ when: FocusExtensions
485
+ }, {
486
+ key: End,
487
+ command: 'Extensions.focusLast',
488
+ when: FocusExtensions
489
+ }, {
490
+ key: PageUp,
491
+ command: 'Extensions.focusPreviousPage',
492
+ when: FocusExtensions
493
+ }, {
494
+ key: PageDown,
495
+ command: 'Extensions.focusNextPage',
496
+ when: FocusExtensions
497
+ }, {
498
+ key: UpArrow,
499
+ command: 'Extensions.focusPrevious',
500
+ when: FocusExtensions
501
+ }, {
502
+ key: DownArrow,
503
+ command: 'Extensions.focusNext',
504
+ when: FocusExtensions
505
+ }, {
506
+ key: Space,
507
+ command: 'Extensions.handleClickCurrentButKeepFocus',
508
+ when: FocusExtensions
509
+ }, {
510
+ key: Enter,
511
+ command: 'Extensions.handleClickCurrent',
512
+ when: FocusExtensions
513
+ }, {
514
+ key: CtrlCmd | Space,
515
+ command: 'Extensions.toggleSuggest',
516
+ when: FocusExtensions
517
+ }, {
518
+ key: CtrlCmd | DownArrow,
519
+ command: 'Extensions.scrollDown',
520
+ when: FocusExtensions
521
+ }];
522
+ };
523
+
432
524
  const Button = 1;
433
525
 
434
526
  const ExtensionActions = 'ExtensionActions';
@@ -750,67 +842,33 @@ const doRender = (oldState, newState) => {
750
842
  };
751
843
 
752
844
  const commandMap = {
753
- 'SearchExtensions.searchExtensions': searchExtensions,
845
+ 'SearchExtensions.clearSearchResults': clearSearchResults,
846
+ 'SearchExtensions.getKeyBindings': getKeyBindings,
754
847
  'SearchExtensions.render': doRender,
755
- 'SearchExtensions.clearSearchResults': clearSearchResults
848
+ 'SearchExtensions.searchExtensions': searchExtensions
756
849
  };
757
850
 
758
851
  const Two = '2.0';
759
- class AssertionError extends Error {
760
- constructor(message) {
761
- super(message);
762
- this.name = 'AssertionError';
763
- }
764
- }
765
- const getType$1 = value => {
766
- switch (typeof value) {
767
- case 'number':
768
- return 'number';
769
- case 'function':
770
- return 'function';
771
- case 'string':
772
- return 'string';
773
- case 'object':
774
- if (value === null) {
775
- return 'null';
776
- }
777
- if (Array.isArray(value)) {
778
- return 'array';
779
- }
780
- return 'object';
781
- case 'boolean':
782
- return 'boolean';
783
- default:
784
- return 'unknown';
785
- }
786
- };
787
- const number = value => {
788
- const type = getType$1(value);
789
- if (type !== 'number') {
790
- throw new AssertionError('expected value to be of type number');
791
- }
792
- };
793
- const state$1 = {
852
+ const state = {
794
853
  callbacks: Object.create(null)
795
854
  };
796
855
  const get = id => {
797
- return state$1.callbacks[id];
856
+ return state.callbacks[id];
798
857
  };
799
858
  const remove = id => {
800
- delete state$1.callbacks[id];
859
+ delete state.callbacks[id];
801
860
  };
802
861
  const warn = (...args) => {
803
862
  console.warn(...args);
804
863
  };
805
- const resolve = (id, args) => {
806
- number(id);
864
+ const resolve = (id, response) => {
807
865
  const fn = get(id);
808
866
  if (!fn) {
809
- console.log(args);
867
+ console.log(response);
810
868
  warn(`callback ${id} may already be disposed`);
811
869
  return;
812
870
  }
813
- fn(args);
871
+ fn(response);
814
872
  remove(id);
815
873
  };
816
874
  class JsonRpcError extends Error {
@@ -822,7 +880,7 @@ class JsonRpcError extends Error {
822
880
  const MethodNotFound = -32601;
823
881
  const Custom = -32001;
824
882
  const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
825
- const getType = prettyError => {
883
+ const getErrorType = prettyError => {
826
884
  if (prettyError && prettyError.type) {
827
885
  return prettyError.type;
828
886
  }
@@ -845,7 +903,7 @@ const getErrorProperty = (error, prettyError) => {
845
903
  data: {
846
904
  stack: prettyError.stack,
847
905
  codeFrame: prettyError.codeFrame,
848
- type: getType(prettyError),
906
+ type: getErrorType(prettyError),
849
907
  code: prettyError.code,
850
908
  name: prettyError.name
851
909
  }
@@ -893,32 +951,42 @@ const defaultRequiresSocket = () => {
893
951
  return false;
894
952
  };
895
953
  const defaultResolve = resolve;
896
- const handleJsonRpcMessage = async (...args) => {
897
- let message;
898
- let ipc;
899
- let execute;
900
- let preparePrettyError;
901
- let logError;
902
- let resolve;
903
- let requiresSocket;
954
+
955
+ // TODO maybe remove this in v6 or v7, only accept options object to simplify the code
956
+ const normalizeParams = args => {
904
957
  if (args.length === 1) {
905
- const arg = args[0];
906
- message = arg.message;
907
- ipc = arg.ipc;
908
- execute = arg.execute;
909
- preparePrettyError = arg.preparePrettyError || defaultPreparePrettyError;
910
- logError = arg.logError || defaultLogError;
911
- requiresSocket = arg.requiresSocket || defaultRequiresSocket;
912
- resolve = arg.resolve || defaultResolve;
913
- } else {
914
- ipc = args[0];
915
- message = args[1];
916
- execute = args[2];
917
- resolve = args[3];
918
- preparePrettyError = args[4];
919
- logError = args[5];
920
- requiresSocket = args[6];
958
+ const options = args[0];
959
+ return {
960
+ ipc: options.ipc,
961
+ message: options.message,
962
+ execute: options.execute,
963
+ resolve: options.resolve || defaultResolve,
964
+ preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
965
+ logError: options.logError || defaultLogError,
966
+ requiresSocket: options.requiresSocket || defaultRequiresSocket
967
+ };
921
968
  }
969
+ return {
970
+ ipc: args[0],
971
+ message: args[1],
972
+ execute: args[2],
973
+ resolve: args[3],
974
+ preparePrettyError: args[4],
975
+ logError: args[5],
976
+ requiresSocket: args[6]
977
+ };
978
+ };
979
+ const handleJsonRpcMessage = async (...args) => {
980
+ const options = normalizeParams(args);
981
+ const {
982
+ message,
983
+ ipc,
984
+ execute,
985
+ resolve,
986
+ preparePrettyError,
987
+ logError,
988
+ requiresSocket
989
+ } = options;
922
990
  if ('id' in message) {
923
991
  if ('method' in message) {
924
992
  const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
@@ -976,6 +1044,27 @@ const Auto = () => {
976
1044
  const getData$1 = event => {
977
1045
  return event.data;
978
1046
  };
1047
+ const attachEvents = that => {
1048
+ const handleMessage = (...args) => {
1049
+ const data = that.getData(...args);
1050
+ that.dispatchEvent(new MessageEvent('message', {
1051
+ data
1052
+ }));
1053
+ };
1054
+ that.onMessage(handleMessage);
1055
+ const handleClose = event => {
1056
+ that.dispatchEvent(new Event('close'));
1057
+ };
1058
+ that.onClose(handleClose);
1059
+ };
1060
+ class Ipc extends EventTarget {
1061
+ constructor(rawIpc) {
1062
+ super();
1063
+ this._rawIpc = rawIpc;
1064
+ attachEvents(this);
1065
+ }
1066
+ }
1067
+ const readyMessage = 'ready';
979
1068
  const walkValue = (value, transferrables, isTransferrable) => {
980
1069
  if (!value) {
981
1070
  return;
@@ -1026,35 +1115,14 @@ const getTransferrables = value => {
1026
1115
  walkValue(value, transferrables, isTransferrable);
1027
1116
  return transferrables;
1028
1117
  };
1029
- const attachEvents = that => {
1030
- const handleMessage = (...args) => {
1031
- const data = that.getData(...args);
1032
- that.dispatchEvent(new MessageEvent('message', {
1033
- data
1034
- }));
1035
- };
1036
- that.onMessage(handleMessage);
1037
- const handleClose = event => {
1038
- that.dispatchEvent(new Event('close'));
1039
- };
1040
- that.onClose(handleClose);
1041
- };
1042
- class Ipc extends EventTarget {
1043
- constructor(rawIpc) {
1044
- super();
1045
- this._rawIpc = rawIpc;
1046
- attachEvents(this);
1047
- }
1048
- }
1049
- const readyMessage = 'ready';
1050
- const listen$4 = () => {
1118
+ const listen$2 = () => {
1051
1119
  // @ts-ignore
1052
1120
  if (typeof WorkerGlobalScope === 'undefined') {
1053
1121
  throw new TypeError('module is not in web worker scope');
1054
1122
  }
1055
1123
  return globalThis;
1056
1124
  };
1057
- const signal$3 = global => {
1125
+ const signal$2 = global => {
1058
1126
  global.postMessage(readyMessage);
1059
1127
  };
1060
1128
  class IpcChildWithModuleWorker extends Ipc {
@@ -1080,14 +1148,14 @@ class IpcChildWithModuleWorker extends Ipc {
1080
1148
  this._rawIpc.addEventListener('message', callback);
1081
1149
  }
1082
1150
  }
1083
- const wrap$6 = global => {
1151
+ const wrap$5 = global => {
1084
1152
  return new IpcChildWithModuleWorker(global);
1085
1153
  };
1086
1154
  const IpcChildWithModuleWorker$1 = {
1087
1155
  __proto__: null,
1088
- listen: listen$4,
1089
- signal: signal$3,
1090
- wrap: wrap$6
1156
+ listen: listen$2,
1157
+ signal: signal$2,
1158
+ wrap: wrap$5
1091
1159
  };
1092
1160
  const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
1093
1161
  const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
@@ -1204,10 +1272,10 @@ const getHelpfulChildProcessError = (stdout, stderr) => {
1204
1272
  };
1205
1273
  const normalizeLine = line => {
1206
1274
  if (line.startsWith('Error: ')) {
1207
- return line.slice(`Error: `.length);
1275
+ return line.slice('Error: '.length);
1208
1276
  }
1209
1277
  if (line.startsWith('VError: ')) {
1210
- return line.slice(`VError: `.length);
1278
+ return line.slice('VError: '.length);
1211
1279
  }
1212
1280
  return line;
1213
1281
  };
@@ -1305,10 +1373,10 @@ const waitForFirstMessage = async port => {
1305
1373
  // @ts-ignore
1306
1374
  return event.data;
1307
1375
  };
1308
- const listen$3 = async () => {
1309
- const parentIpcRaw = listen$4();
1310
- signal$3(parentIpcRaw);
1311
- const parentIpc = wrap$6(parentIpcRaw);
1376
+ const listen$1$1 = async () => {
1377
+ const parentIpcRaw = listen$2();
1378
+ signal$2(parentIpcRaw);
1379
+ const parentIpc = wrap$5(parentIpcRaw);
1312
1380
  const firstMessage = await waitForFirstMessage(parentIpc);
1313
1381
  if (firstMessage.method !== 'initialize') {
1314
1382
  throw new IpcError('unexpected first message');
@@ -1353,13 +1421,13 @@ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
1353
1421
  this._rawIpc.start();
1354
1422
  }
1355
1423
  }
1356
- const wrap$5 = port => {
1424
+ const wrap$4 = port => {
1357
1425
  return new IpcChildWithModuleWorkerAndMessagePort(port);
1358
1426
  };
1359
1427
  const IpcChildWithModuleWorkerAndMessagePort$1 = {
1360
1428
  __proto__: null,
1361
- listen: listen$3,
1362
- wrap: wrap$5
1429
+ listen: listen$1$1,
1430
+ wrap: wrap$4
1363
1431
  };
1364
1432
 
1365
1433
  const getModule = method => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-search-view",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "description": "",
5
5
  "main": "dist/extensionSearchViewWorkerMain.js",
6
6
  "type": "module",