@lvce-editor/title-bar-worker 2.2.0 → 2.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.
@@ -60,55 +60,63 @@ class AssertionError extends Error {
60
60
  this.name = 'AssertionError';
61
61
  }
62
62
  }
63
+ const Object$1 = 1;
64
+ const Number = 2;
65
+ const Array$1 = 3;
66
+ const String = 4;
67
+ const Boolean$1 = 5;
68
+ const Function = 6;
69
+ const Null = 7;
70
+ const Unknown$1 = 8;
63
71
  const getType = value => {
64
72
  switch (typeof value) {
65
73
  case 'number':
66
- return 'number';
74
+ return Number;
67
75
  case 'function':
68
- return 'function';
76
+ return Function;
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$1;
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) {
94
102
  throw new AssertionError('expected value to be of type number');
95
103
  }
96
104
  };
97
105
  const array = value => {
98
106
  const type = getType(value);
99
- if (type !== 'array') {
107
+ if (type !== Array$1) {
100
108
  throw new AssertionError('expected value to be of type array');
101
109
  }
102
110
  };
103
111
  const string = value => {
104
112
  const type = getType(value);
105
- if (type !== 'string') {
113
+ if (type !== String) {
106
114
  throw new AssertionError('expected value to be of type string');
107
115
  }
108
116
  };
109
117
  const boolean = value => {
110
118
  const type = getType(value);
111
- if (type !== 'boolean') {
119
+ if (type !== Boolean$1) {
112
120
  throw new AssertionError('expected value to be of type boolean');
113
121
  }
114
122
  };
@@ -362,22 +370,11 @@ class IpcChildWithModuleWorker extends Ipc {
362
370
  const wrap$f = global => {
363
371
  return new IpcChildWithModuleWorker(global);
364
372
  };
365
- const withResolvers = () => {
366
- let _resolve;
367
- const promise = new Promise(resolve => {
368
- _resolve = resolve;
369
- });
370
- return {
371
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
372
- resolve: _resolve,
373
- promise
374
- };
375
- };
376
373
  const waitForFirstMessage = async port => {
377
374
  const {
378
375
  resolve,
379
376
  promise
380
- } = withResolvers();
377
+ } = Promise.withResolvers();
381
378
  port.addEventListener('message', resolve, {
382
379
  once: true
383
380
  });
@@ -448,26 +445,26 @@ const create$4 = (method, params) => {
448
445
  };
449
446
  };
450
447
  const callbacks = Object.create(null);
451
- const set$1 = (id, fn) => {
448
+ const set$4 = (id, fn) => {
452
449
  callbacks[id] = fn;
453
450
  };
454
- const get$1 = id => {
451
+ const get$2 = id => {
455
452
  return callbacks[id];
456
453
  };
457
454
  const remove = id => {
458
455
  delete callbacks[id];
459
456
  };
460
457
  let id$a = 0;
461
- const create$3 = () => {
458
+ const create$3$1 = () => {
462
459
  return ++id$a;
463
460
  };
464
461
  const registerPromise = () => {
465
- const id = create$3();
462
+ const id = create$3$1();
466
463
  const {
467
464
  resolve,
468
465
  promise
469
466
  } = Promise.withResolvers();
470
- set$1(id, resolve);
467
+ set$4(id, resolve);
471
468
  return {
472
469
  id,
473
470
  promise
@@ -540,6 +537,17 @@ const constructError = (message, type, name) => {
540
537
  }
541
538
  return new ErrorConstructor(message);
542
539
  };
540
+ const joinLines = lines => {
541
+ return lines.join(NewLine);
542
+ };
543
+ const splitLines = lines => {
544
+ return lines.split(NewLine);
545
+ };
546
+ const getCurrentStack = () => {
547
+ const stackLinesToSkip = 3;
548
+ const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
549
+ return currentStack;
550
+ };
543
551
  const getNewLineIndex = (string, startIndex = undefined) => {
544
552
  return string.indexOf(NewLine, startIndex);
545
553
  };
@@ -550,19 +558,16 @@ const getParentStack = error => {
550
558
  }
551
559
  return parentStack;
552
560
  };
553
- const joinLines = lines => {
554
- return lines.join(NewLine);
555
- };
556
561
  const MethodNotFound = -32601;
557
562
  const Custom = -32001;
558
- const splitLines = lines => {
559
- return lines.split(NewLine);
560
- };
561
563
  const restoreJsonRpcError = error => {
564
+ const currentStack = getCurrentStack();
562
565
  if (error && error instanceof Error) {
566
+ if (typeof error.stack === 'string') {
567
+ error.stack = error.stack + NewLine + currentStack;
568
+ }
563
569
  return error;
564
570
  }
565
- const currentStack = joinLines(splitLines(new Error().stack || '').slice(1));
566
571
  if (error && error.code && error.code === MethodNotFound) {
567
572
  const restoredError = new JsonRpcError(error.message);
568
573
  const parentStack = getParentStack(error);
@@ -624,7 +629,7 @@ const warn = (...args) => {
624
629
  console.warn(...args);
625
630
  };
626
631
  const resolve = (id, response) => {
627
- const fn = get$1(id);
632
+ const fn = get$2(id);
628
633
  if (!fn) {
629
634
  console.log(response);
630
635
  warn(`callback ${id} may already be disposed`);
@@ -643,6 +648,17 @@ const getErrorType = prettyError => {
643
648
  }
644
649
  return undefined;
645
650
  };
651
+ const isAlreadyStack = line => {
652
+ return line.trim().startsWith('at ');
653
+ };
654
+ const getStack = prettyError => {
655
+ const stackString = prettyError.stack || '';
656
+ const newLineIndex = stackString.indexOf('\n');
657
+ if (newLineIndex !== -1 && !isAlreadyStack(stackString.slice(0, newLineIndex))) {
658
+ return stackString.slice(newLineIndex + 1);
659
+ }
660
+ return stackString;
661
+ };
646
662
  const getErrorProperty = (error, prettyError) => {
647
663
  if (error && error.code === E_COMMAND_NOT_FOUND) {
648
664
  return {
@@ -655,7 +671,7 @@ const getErrorProperty = (error, prettyError) => {
655
671
  code: Custom,
656
672
  message: prettyError.message,
657
673
  data: {
658
- stack: prettyError.stack,
674
+ stack: getStack(prettyError),
659
675
  codeFrame: prettyError.codeFrame,
660
676
  type: getErrorType(prettyError),
661
677
  code: prettyError.code,
@@ -663,18 +679,18 @@ const getErrorProperty = (error, prettyError) => {
663
679
  }
664
680
  };
665
681
  };
666
- const create$1$1 = (message, error) => {
682
+ const create$1$1 = (id, error) => {
667
683
  return {
668
684
  jsonrpc: Two,
669
- id: message.id,
685
+ id,
670
686
  error
671
687
  };
672
688
  };
673
- const getErrorResponse = (message, error, preparePrettyError, logError) => {
689
+ const getErrorResponse = (id, error, preparePrettyError, logError) => {
674
690
  const prettyError = preparePrettyError(error);
675
691
  logError(error, prettyError);
676
692
  const errorProperty = getErrorProperty(error, prettyError);
677
- return create$1$1(message, errorProperty);
693
+ return create$1$1(id, errorProperty);
678
694
  };
679
695
  const create$5 = (message, result) => {
680
696
  return {
@@ -687,12 +703,27 @@ const getSuccessResponse = (message, result) => {
687
703
  const resultProperty = result ?? null;
688
704
  return create$5(message, resultProperty);
689
705
  };
706
+ const getErrorResponseSimple = (id, error) => {
707
+ return {
708
+ jsonrpc: Two,
709
+ id,
710
+ error: {
711
+ code: Custom,
712
+ // @ts-ignore
713
+ message: error.message,
714
+ data: error
715
+ }
716
+ };
717
+ };
690
718
  const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
691
719
  try {
692
720
  const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
693
721
  return getSuccessResponse(message, result);
694
722
  } catch (error) {
695
- return getErrorResponse(message, error, preparePrettyError, logError);
723
+ if (ipc.canUseSimpleErrorResponse) {
724
+ return getErrorResponseSimple(message.id, error);
725
+ }
726
+ return getErrorResponse(message.id, error, preparePrettyError, logError);
696
727
  }
697
728
  };
698
729
  const defaultPreparePrettyError = error => {
@@ -747,7 +778,7 @@ const handleJsonRpcMessage = async (...args) => {
747
778
  try {
748
779
  ipc.send(response);
749
780
  } catch (error) {
750
- const errorResponse = getErrorResponse(message, error, preparePrettyError, logError);
781
+ const errorResponse = getErrorResponse(message.id, error, preparePrettyError, logError);
751
782
  ipc.send(errorResponse);
752
783
  }
753
784
  return;
@@ -778,13 +809,19 @@ const send = (transport, method, ...params) => {
778
809
  const message = create$4(method, params);
779
810
  transport.send(message);
780
811
  };
781
- const invoke$1 = (ipc, method, ...params) => {
812
+ const invoke$2 = (ipc, method, ...params) => {
782
813
  return invokeHelper(ipc, method, params, false);
783
814
  };
784
- const invokeAndTransfer = (ipc, method, ...params) => {
815
+ const invokeAndTransfer$1 = (ipc, method, ...params) => {
785
816
  return invokeHelper(ipc, method, params, true);
786
817
  };
787
818
 
819
+ class CommandNotFoundError extends Error {
820
+ constructor(command) {
821
+ super(`Command not found ${command}`);
822
+ this.name = 'CommandNotFoundError';
823
+ }
824
+ }
788
825
  const commands = Object.create(null);
789
826
  const register = commandMap => {
790
827
  Object.assign(commands, commandMap);
@@ -795,7 +832,7 @@ const getCommand = key => {
795
832
  const execute = (command, ...args) => {
796
833
  const fn = getCommand(command);
797
834
  if (!fn) {
798
- throw new Error(`command not found ${command}`);
835
+ throw new CommandNotFoundError(command);
799
836
  }
800
837
  return fn(...args);
801
838
  };
@@ -811,10 +848,10 @@ const createRpc = ipc => {
811
848
  send(ipc, method, ...params);
812
849
  },
813
850
  invoke(method, ...params) {
814
- return invoke$1(ipc, method, ...params);
851
+ return invoke$2(ipc, method, ...params);
815
852
  },
816
853
  invokeAndTransfer(method, ...params) {
817
- return invokeAndTransfer(ipc, method, ...params);
854
+ return invokeAndTransfer$1(ipc, method, ...params);
818
855
  },
819
856
  async dispose() {
820
857
  await ipc?.dispose();
@@ -852,7 +889,7 @@ const listen$1 = async (module, options) => {
852
889
  const ipc = module.wrap(rawIpc);
853
890
  return ipc;
854
891
  };
855
- const create$2 = async ({
892
+ const create$3 = async ({
856
893
  commandMap
857
894
  }) => {
858
895
  // TODO create a commandMap per rpc instance
@@ -864,7 +901,7 @@ const create$2 = async ({
864
901
  };
865
902
  const WebWorkerRpcClient = {
866
903
  __proto__: null,
867
- create: create$2
904
+ create: create$3
868
905
  };
869
906
 
870
907
  const RenderEntries = 1;
@@ -900,7 +937,7 @@ const diff = (oldState, newState) => {
900
937
  return diffResult;
901
938
  };
902
939
 
903
- const create$1 = () => {
940
+ const create$2 = () => {
904
941
  const states = Object.create(null);
905
942
  return {
906
943
  get(uid) {
@@ -916,15 +953,15 @@ const create$1 = () => {
916
953
  };
917
954
 
918
955
  const {
919
- get,
920
- set
921
- } = create$1();
956
+ get: get$1,
957
+ set: set$3
958
+ } = create$2();
922
959
 
923
960
  const diff2 = uid => {
924
961
  const {
925
962
  oldState,
926
963
  newState
927
- } = get(uid);
964
+ } = get$1(uid);
928
965
  return diff(oldState, newState);
929
966
  };
930
967
 
@@ -934,104 +971,68 @@ const getCommandIds = () => {
934
971
  return commandsIds;
935
972
  };
936
973
 
937
- const Backspace$1 = 1;
938
- const Tab$1 = 2;
939
- const Enter$1 = 3;
940
- const Escape$1 = 8;
941
- const Space$1 = 9;
942
- const PageUp$1 = 10;
943
- const PageDown$1 = 11;
944
- const End$1 = 255;
945
- const Home$1 = 12;
946
- const LeftArrow$1 = 13;
947
- const UpArrow$1 = 14;
948
- const RightArrow$1 = 15;
949
- const DownArrow$1 = 16;
950
- const Insert$1 = 17;
951
- const Delete$1 = 18;
952
- const Digit0$1 = 19;
953
- const Digit1$1 = 20;
954
- const Digit2$1 = 21;
955
- const Digit3$1 = 22;
956
- const Digit4$1 = 23;
957
- const Digit5$1 = 24;
958
- const Digit6$1 = 25;
959
- const Digit7$1 = 26;
960
- const Digit8$1 = 27;
961
- const Digit9$1 = 28;
962
- const KeyA$1 = 29;
963
- const KeyB$1 = 30;
964
- const KeyC$1 = 31;
965
- const KeyD$1 = 32;
966
- const KeyE$1 = 33;
967
- const KeyF$1 = 34;
968
- const KeyG$1 = 35;
969
- const KeyH$1 = 36;
970
- const KeyI$1 = 37;
971
- const KeyJ$1 = 38;
972
- const KeyK$1 = 39;
973
- const KeyL$1 = 40;
974
- const KeyM$1 = 41;
975
- const KeyN$1 = 42;
976
- const KeyO$1 = 43;
977
- const KeyP$1 = 44;
978
- const KeyQ$1 = 45;
979
- const KeyR$1 = 46;
980
- const KeyS$1 = 47;
981
- const KeyT$1 = 48;
982
- const KeyU$1 = 49;
983
- const KeyV$1 = 50;
984
- const KeyW$1 = 51;
985
- const KeyX$1 = 52;
986
- const KeyY$1 = 53;
987
- const KeyZ$1 = 54;
988
- const F1$1 = 57;
989
- const F2$1 = 58;
990
- const F3$1 = 59;
991
- const F4$1 = 60;
992
- const F5$1 = 61;
993
- const F6$1 = 62;
994
- const Equal$1 = 84;
995
- const Comma$1 = 85;
996
- const Minus$1 = 86;
997
- const Backquote$1 = 89;
998
- const Backslash$1 = 91;
999
- const Star$1 = 131;
1000
- const Plus$1 = 132;
974
+ const Text = 12;
975
+
976
+ const Escape$2 = 8;
977
+ const Space$2 = 9;
978
+ const End$2 = 255;
979
+ const Home$2 = 12;
980
+ const LeftArrow$2 = 13;
981
+ const UpArrow$2 = 14;
982
+ const RightArrow$2 = 15;
983
+ const DownArrow$2 = 16;
984
+
985
+ const CtrlCmd = 1 << 11 >>> 0;
986
+ const Shift = 1 << 10 >>> 0;
987
+
988
+ const DebugWorker = 55;
989
+ const RendererWorker$1 = 1;
990
+
991
+ const mergeClassNames = (...classNames) => {
992
+ return classNames.filter(Boolean).join(' ');
993
+ };
994
+
995
+ const text = data => {
996
+ return {
997
+ type: Text,
998
+ text: data,
999
+ childCount: 0
1000
+ };
1001
+ };
1001
1002
 
1002
1003
  const FocusTitleBarMenuBar = 26;
1003
1004
 
1004
- const getKeyBindings = () => {
1005
+ const getKeyBindings$1 = () => {
1005
1006
  return [{
1006
- key: DownArrow$1,
1007
+ key: DownArrow$2,
1007
1008
  command: 'TitleBarMenuBar.handleKeyArrowDown',
1008
1009
  when: FocusTitleBarMenuBar
1009
1010
  }, {
1010
- key: UpArrow$1,
1011
+ key: UpArrow$2,
1011
1012
  command: 'TitleBarMenuBar.handleKeyArrowUp',
1012
1013
  when: FocusTitleBarMenuBar
1013
1014
  }, {
1014
- key: RightArrow$1,
1015
+ key: RightArrow$2,
1015
1016
  command: 'TitleBarMenuBar.handleKeyArrowRight',
1016
1017
  when: FocusTitleBarMenuBar
1017
1018
  }, {
1018
- key: LeftArrow$1,
1019
+ key: LeftArrow$2,
1019
1020
  command: 'TitleBarMenuBar.handleKeyArrowLeft',
1020
1021
  when: FocusTitleBarMenuBar
1021
1022
  }, {
1022
- key: Space$1,
1023
+ key: Space$2,
1023
1024
  command: 'TitleBarMenuBar.handleKeySpace',
1024
1025
  when: FocusTitleBarMenuBar
1025
1026
  }, {
1026
- key: Home$1,
1027
+ key: Home$2,
1027
1028
  command: 'TitleBarMenuBar.handleKeyHome',
1028
1029
  when: FocusTitleBarMenuBar
1029
1030
  }, {
1030
- key: End$1,
1031
+ key: End$2,
1031
1032
  command: 'TitleBarMenuBar.handleKeyEnd',
1032
1033
  when: FocusTitleBarMenuBar
1033
1034
  }, {
1034
- key: Escape$1,
1035
+ key: Escape$2,
1035
1036
  command: 'TitleBarMenuBar.handleKeyEscape',
1036
1037
  when: FocusTitleBarMenuBar
1037
1038
  }];
@@ -1103,7 +1104,7 @@ const moveLineDown = () => {
1103
1104
  };
1104
1105
 
1105
1106
  const Edit$1 = 2;
1106
- const File$1 = 5;
1107
+ const File$2 = 5;
1107
1108
  const Go$1 = 6;
1108
1109
  const Help$1 = 7;
1109
1110
  const OpenRecent = 9;
@@ -1217,7 +1218,7 @@ const Web = 1;
1217
1218
  const Electron = 2;
1218
1219
  const Remote = 3;
1219
1220
 
1220
- const id$8 = File$1;
1221
+ const id$8 = File$2;
1221
1222
  const getMenuEntries$c = platform => {
1222
1223
  const entries = [{
1223
1224
  id: 'newFile',
@@ -1288,7 +1289,7 @@ const CheckForUpdates = 'Check For Updates';
1288
1289
  const ClearRecentlyOpened = 'Clear Recently Opened';
1289
1290
  const Close = 'Close';
1290
1291
  const Edit = 'Edit';
1291
- const File = 'File';
1292
+ const File$1 = 'File';
1292
1293
  const Go = 'Go';
1293
1294
  const Help = 'Help';
1294
1295
  const Maximize = 'Maximize';
@@ -1352,7 +1353,7 @@ const getMenuEntries$a = async platform => {
1352
1353
  entries.push({
1353
1354
  id: 'about',
1354
1355
  label: about(),
1355
- flags: RestoreFocus,
1356
+ flags: None$1,
1356
1357
  command: 'About.showAbout'
1357
1358
  });
1358
1359
  return entries;
@@ -1364,28 +1365,397 @@ const MenuEntriesHelp = {
1364
1365
  id: id$6
1365
1366
  };
1366
1367
 
1367
- const state$1 = {
1368
- rpc: undefined
1368
+ const rpcs = Object.create(null);
1369
+ const set$2 = (id, rpc) => {
1370
+ rpcs[id] = rpc;
1369
1371
  };
1370
- const invoke = (method, ...params) => {
1371
- const {
1372
- rpc
1373
- } = state$1;
1372
+ const get = id => {
1373
+ return rpcs[id];
1374
+ };
1375
+
1376
+ const create$1 = rpcId => {
1377
+ return {
1378
+ // @ts-ignore
1379
+ invoke(method, ...params) {
1380
+ const rpc = get(rpcId);
1381
+ // @ts-ignore
1382
+ return rpc.invoke(method, ...params);
1383
+ },
1384
+ // @ts-ignore
1385
+ invokeAndTransfer(method, ...params) {
1386
+ const rpc = get(rpcId);
1387
+ // @ts-ignore
1388
+ return rpc.invokeAndTransfer(method, ...params);
1389
+ },
1390
+ set(rpc) {
1391
+ set$2(rpcId, rpc);
1392
+ },
1393
+ async dispose() {
1394
+ const rpc = get(rpcId);
1395
+ await rpc.dispose();
1396
+ }
1397
+ };
1398
+ };
1399
+
1400
+ const {
1401
+ invoke: invoke$1,
1402
+ invokeAndTransfer,
1403
+ set: set$1,
1404
+ dispose
1405
+ } = create$1(RendererWorker$1);
1406
+ const searchFileHtml = async uri => {
1407
+ return invoke$1('ExtensionHost.searchFileWithHtml', uri);
1408
+ };
1409
+ const getFilePathElectron = async file => {
1410
+ return invoke$1('FileSystemHandle.getFilePathElectron', file);
1411
+ };
1412
+ const showContextMenu = async (x, y, id, ...args) => {
1413
+ return invoke$1('ContextMenu.show', x, y, id, ...args);
1414
+ };
1415
+ const getElectronVersion = async () => {
1416
+ return invoke$1('Process.getElectronVersion');
1417
+ };
1418
+ const applyBulkReplacement = async bulkEdits => {
1419
+ await invoke$1('BulkReplacement.applyBulkReplacement', bulkEdits);
1420
+ };
1421
+ const setColorTheme = async id => {
1422
+ // @ts-ignore
1423
+ return invoke$1(/* ColorTheme.setColorTheme */'ColorTheme.setColorTheme', /* colorThemeId */id);
1424
+ };
1425
+ const getNodeVersion = async () => {
1426
+ return invoke$1('Process.getNodeVersion');
1427
+ };
1428
+ const getChromeVersion = async () => {
1429
+ return invoke$1('Process.getChromeVersion');
1430
+ };
1431
+ const getV8Version = async () => {
1432
+ return invoke$1('Process.getV8Version');
1433
+ };
1434
+ const getFileHandles = async fileIds => {
1435
+ const files = await invoke$1('FileSystemHandle.getFileHandles', fileIds);
1436
+ return files;
1437
+ };
1438
+ const setWorkspacePath = async path => {
1439
+ await invoke$1('Workspace.setPath', path);
1440
+ };
1441
+ const registerWebViewInterceptor = async (id, port) => {
1442
+ await invokeAndTransfer('WebView.registerInterceptor', id, port);
1443
+ };
1444
+ const unregisterWebViewInterceptor = async id => {
1445
+ await invoke$1('WebView.unregisterInterceptor', id);
1446
+ };
1447
+ const sendMessagePortToEditorWorker = async (port, rpcId) => {
1448
+ const command = 'HandleMessagePort.handleMessagePort';
1449
+ // @ts-ignore
1450
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToEditorWorker', port, command, rpcId);
1451
+ };
1452
+ const sendMessagePortToErrorWorker = async (port, rpcId) => {
1453
+ const command = 'Errors.handleMessagePort';
1454
+ // @ts-ignore
1455
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToErrorWorker', port, command, rpcId);
1456
+ };
1457
+ const sendMessagePortToMarkdownWorker = async (port, rpcId) => {
1458
+ const command = 'Markdown.handleMessagePort';
1459
+ // @ts-ignore
1460
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToMarkdownWorker', port, command, rpcId);
1461
+ };
1462
+ const sendMessagePortToFileSystemWorker = async (port, rpcId) => {
1463
+ const command = 'FileSystem.handleMessagePort';
1464
+ // @ts-ignore
1465
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToFileSystemWorker', port, command, rpcId);
1466
+ };
1467
+ const readFile = async uri => {
1468
+ return invoke$1('FileSystem.readFile', uri);
1469
+ };
1470
+ const getWebViewSecret = async key => {
1471
+ // @ts-ignore
1472
+ return invoke$1('WebView.getSecret', key);
1473
+ };
1474
+ const setWebViewPort = async (uid, port, origin, portType) => {
1475
+ return invokeAndTransfer('WebView.setPort', uid, port, origin, portType);
1476
+ };
1477
+ const setFocus$1 = key => {
1478
+ return invoke$1('Focus.setFocus', key);
1479
+ };
1480
+ const getFileIcon = async options => {
1481
+ return invoke$1('IconTheme.getFileIcon', options);
1482
+ };
1483
+ const getColorThemeNames = async () => {
1484
+ return invoke$1('ColorTheme.getColorThemeNames');
1485
+ };
1486
+ const disableExtension = async id => {
1487
+ // @ts-ignore
1488
+ return invoke$1('ExtensionManagement.disable', id);
1489
+ };
1490
+ const enableExtension = async id => {
1491
+ // @ts-ignore
1492
+ return invoke$1('ExtensionManagement.enable', id);
1493
+ };
1494
+ const handleDebugChange = async params => {
1495
+ // @ts-ignore
1496
+ return invoke$1('Run And Debug.handleChange', params);
1497
+ };
1498
+ const getFolderIcon = async options => {
1499
+ return invoke$1('IconTheme.getFolderIcon', options);
1500
+ };
1501
+ const closeWidget = async widgetId => {
1502
+ return invoke$1('Viewlet.closeWidget', widgetId);
1503
+ };
1504
+ const sendMessagePortToExtensionHostWorker = async (port, rpcId = 0) => {
1505
+ const command = 'HandleMessagePort.handleMessagePort2';
1506
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, rpcId);
1507
+ };
1508
+ const sendMessagePortToSearchProcess = async port => {
1509
+ await invokeAndTransfer('SendMessagePortToElectron.sendMessagePortToElectron', port, 'HandleMessagePortForSearchProcess.handleMessagePortForSearchProcess');
1510
+ };
1511
+ const confirm = async (message, options) => {
1512
+ // @ts-ignore
1513
+ const result = await invoke$1('ConfirmPrompt.prompt', message, options);
1514
+ return result;
1515
+ };
1516
+ const getRecentlyOpened$1 = async () => {
1517
+ return invoke$1(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
1518
+ };
1519
+ const getKeyBindings = async () => {
1520
+ return invoke$1('KeyBindingsInitial.getKeyBindings');
1521
+ };
1522
+ const writeClipBoardText = async text => {
1523
+ await invoke$1('ClipBoard.writeText', /* text */text);
1524
+ };
1525
+ const writeClipBoardImage = async blob => {
1526
+ // @ts-ignore
1527
+ await invoke$1('ClipBoard.writeImage', /* text */blob);
1528
+ };
1529
+ const searchFileMemory = async uri => {
1530
+ // @ts-ignore
1531
+ return invoke$1('ExtensionHost.searchFileWithMemory', uri);
1532
+ };
1533
+ const searchFileFetch = async uri => {
1534
+ return invoke$1('ExtensionHost.searchFileWithFetch', uri);
1535
+ };
1536
+ const showMessageBox = async options => {
1537
+ return invoke$1('ElectronDialog.showMessageBox', options);
1538
+ };
1539
+ const handleDebugResumed = async params => {
1540
+ await invoke$1('Run And Debug.handleResumed', params);
1541
+ };
1542
+ const openWidget = async name => {
1543
+ await invoke$1('Viewlet.openWidget', name);
1544
+ };
1545
+ const getIcons = async requests => {
1546
+ const icons = await invoke$1('IconTheme.getIcons', requests);
1547
+ return icons;
1548
+ };
1549
+ const activateByEvent = event => {
1550
+ return invoke$1('ExtensionHostManagement.activateByEvent', event);
1551
+ };
1552
+ const setAdditionalFocus = focusKey => {
1553
+ // @ts-ignore
1554
+ return invoke$1('Focus.setAdditionalFocus', focusKey);
1555
+ };
1556
+ const getActiveEditorId = () => {
1557
+ // @ts-ignore
1558
+ return invoke$1('GetActiveEditor.getActiveEditorId');
1559
+ };
1560
+ const getWorkspacePath = () => {
1561
+ return invoke$1('Workspace.getPath');
1562
+ };
1563
+ const sendMessagePortToRendererProcess = async port => {
1564
+ const command = 'HandleMessagePort.handleMessagePort';
1565
+ // @ts-ignore
1566
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToRendererProcess', port, command, DebugWorker);
1567
+ };
1568
+ const getPreference = async key => {
1569
+ return await invoke$1('Preferences.get', key);
1570
+ };
1571
+ const getAllExtensions = async () => {
1572
+ return invoke$1('ExtensionManagement.getAllExtensions');
1573
+ };
1574
+ const rerenderEditor = async key => {
1575
+ // @ts-ignore
1576
+ return invoke$1('Editor.rerender', key);
1577
+ };
1578
+ const handleDebugPaused = async params => {
1579
+ await invoke$1('Run And Debug.handlePaused', params);
1580
+ };
1581
+ const openUri = async (uri, focus, options) => {
1582
+ await invoke$1('Main.openUri', uri, focus, options);
1583
+ };
1584
+ const sendMessagePortToSyntaxHighlightingWorker = async port => {
1585
+ await invokeAndTransfer(
1586
+ // @ts-ignore
1587
+ 'SendMessagePortToSyntaxHighlightingWorker.sendMessagePortToSyntaxHighlightingWorker', port, 'HandleMessagePort.handleMessagePort2');
1588
+ };
1589
+ const handleDebugScriptParsed = async script => {
1590
+ await invoke$1('Run And Debug.handleScriptParsed', script);
1591
+ };
1592
+ const getWindowId = async () => {
1593
+ return invoke$1('GetWindowId.getWindowId');
1594
+ };
1595
+ const getBlob = async uri => {
1596
+ // @ts-ignore
1597
+ return invoke$1('FileSystem.getBlob', uri);
1598
+ };
1599
+ const getExtensionCommands = async () => {
1600
+ return invoke$1('ExtensionHost.getCommands');
1601
+ };
1602
+ const showErrorDialog = async errorInfo => {
1603
+ // @ts-ignore
1604
+ await invoke$1('ErrorHandling.showErrorDialog', errorInfo);
1605
+ };
1606
+ const getFolderSize = async uri => {
1607
+ // @ts-ignore
1608
+ return await invoke$1('FileSystem.getFolderSize', uri);
1609
+ };
1610
+ const getExtension = async id => {
1611
+ // @ts-ignore
1612
+ return invoke$1('ExtensionManagement.getExtension', id);
1613
+ };
1614
+ const getMarkdownDom = async html => {
1615
+ // @ts-ignore
1616
+ return invoke$1('Markdown.getVirtualDom', html);
1617
+ };
1618
+ const renderMarkdown = async (markdown, options) => {
1619
+ // @ts-ignore
1620
+ return invoke$1('Markdown.renderMarkdown', markdown, options);
1621
+ };
1622
+ const openNativeFolder = async uri => {
1623
+ // @ts-ignore
1624
+ await invoke$1('OpenNativeFolder.openNativeFolder', uri);
1625
+ };
1626
+ const uninstallExtension = async id => {
1627
+ return invoke$1('ExtensionManagement.uninstall', id);
1628
+ };
1629
+ const installExtension = async id => {
1630
+ // @ts-ignore
1631
+ return invoke$1('ExtensionManagement.install', id);
1632
+ };
1633
+ const openExtensionSearch = async () => {
1634
+ // @ts-ignore
1635
+ return invoke$1('SideBar.openViewlet', 'Extensions');
1636
+ };
1637
+ const setExtensionsSearchValue = async searchValue => {
1638
+ // @ts-ignore
1639
+ return invoke$1('Extensions.handleInput', searchValue);
1640
+ };
1641
+ const openExternal = async uri => {
1374
1642
  // @ts-ignore
1375
- return rpc.invoke(method, ...params);
1643
+ await invoke$1('Open.openExternal', uri);
1376
1644
  };
1377
- const setRpc = rpc => {
1378
- state$1.rpc = rpc;
1645
+ const openUrl = async uri => {
1646
+ // @ts-ignore
1647
+ await invoke$1('Open.openUrl', uri);
1648
+ };
1649
+ const getAllPreferences = async () => {
1650
+ // @ts-ignore
1651
+ return invoke$1('Preferences.getAll');
1652
+ };
1653
+ const showSaveFilePicker = async () => {
1654
+ // @ts-ignore
1655
+ return invoke$1('FilePicker.showSaveFilePicker');
1656
+ };
1657
+ const getLogsDir = async () => {
1658
+ // @ts-ignore
1659
+ return invoke$1('PlatformPaths.getLogsDir');
1379
1660
  };
1380
1661
 
1662
+ const RendererWorker = {
1663
+ __proto__: null,
1664
+ activateByEvent,
1665
+ applyBulkReplacement,
1666
+ closeWidget,
1667
+ confirm,
1668
+ disableExtension,
1669
+ dispose,
1670
+ enableExtension,
1671
+ getActiveEditorId,
1672
+ getAllExtensions,
1673
+ getAllPreferences,
1674
+ getBlob,
1675
+ getChromeVersion,
1676
+ getColorThemeNames,
1677
+ getElectronVersion,
1678
+ getExtension,
1679
+ getExtensionCommands,
1680
+ getFileHandles,
1681
+ getFileIcon,
1682
+ getFilePathElectron,
1683
+ getFolderIcon,
1684
+ getFolderSize,
1685
+ getIcons,
1686
+ getKeyBindings,
1687
+ getLogsDir,
1688
+ getMarkdownDom,
1689
+ getNodeVersion,
1690
+ getPreference,
1691
+ getRecentlyOpened: getRecentlyOpened$1,
1692
+ getV8Version,
1693
+ getWebViewSecret,
1694
+ getWindowId,
1695
+ getWorkspacePath,
1696
+ handleDebugChange,
1697
+ handleDebugPaused,
1698
+ handleDebugResumed,
1699
+ handleDebugScriptParsed,
1700
+ installExtension,
1701
+ invoke: invoke$1,
1702
+ invokeAndTransfer,
1703
+ openExtensionSearch,
1704
+ openExternal,
1705
+ openNativeFolder,
1706
+ openUri,
1707
+ openUrl,
1708
+ openWidget,
1709
+ readFile,
1710
+ registerWebViewInterceptor,
1711
+ renderMarkdown,
1712
+ rerenderEditor,
1713
+ searchFileFetch,
1714
+ searchFileHtml,
1715
+ searchFileMemory,
1716
+ sendMessagePortToEditorWorker,
1717
+ sendMessagePortToErrorWorker,
1718
+ sendMessagePortToExtensionHostWorker,
1719
+ sendMessagePortToFileSystemWorker,
1720
+ sendMessagePortToMarkdownWorker,
1721
+ sendMessagePortToRendererProcess,
1722
+ sendMessagePortToSearchProcess,
1723
+ sendMessagePortToSyntaxHighlightingWorker,
1724
+ set: set$1,
1725
+ setAdditionalFocus,
1726
+ setColorTheme,
1727
+ setExtensionsSearchValue,
1728
+ setFocus: setFocus$1,
1729
+ setWebViewPort,
1730
+ setWorkspacePath,
1731
+ showContextMenu,
1732
+ showErrorDialog,
1733
+ showMessageBox,
1734
+ showSaveFilePicker,
1735
+ uninstallExtension,
1736
+ unregisterWebViewInterceptor,
1737
+ writeClipBoardImage,
1738
+ writeClipBoardText
1739
+ };
1740
+
1741
+ const {
1742
+ invoke,
1743
+ set
1744
+ } = RendererWorker;
1745
+
1381
1746
  const getRecentlyOpened = () => {
1382
1747
  return invoke(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
1383
1748
  };
1384
1749
 
1385
- const getTitle = uri => {
1750
+ const File = 'file://';
1751
+
1752
+ const getTitle = (homeDir, uri) => {
1386
1753
  if (!uri) {
1387
1754
  return '';
1388
1755
  }
1756
+ if (uri.startsWith(File)) {
1757
+ return uri.slice(File.length);
1758
+ }
1389
1759
  return uri;
1390
1760
  };
1391
1761
 
@@ -1396,9 +1766,14 @@ const clearRecentlyOpened = () => {
1396
1766
  return i18nString(ClearRecentlyOpened);
1397
1767
  };
1398
1768
 
1769
+ const getHomeDir = () => {
1770
+ return '';
1771
+ };
1772
+
1399
1773
  const MAX_MENU_RECENT_ENTRIES = 10;
1400
1774
  const toMenuItem = folder => {
1401
- const label = getTitle(folder);
1775
+ const homeDir = getHomeDir();
1776
+ const label = getTitle(homeDir, folder);
1402
1777
  return {
1403
1778
  label,
1404
1779
  flags: None$1,
@@ -1509,7 +1884,7 @@ const MenuEntriesTerminal = {
1509
1884
  };
1510
1885
 
1511
1886
  const file = () => {
1512
- return i18nString(File);
1887
+ return i18nString(File$1);
1513
1888
  };
1514
1889
  const edit = () => {
1515
1890
  return i18nString(Edit);
@@ -1544,7 +1919,7 @@ const close$1 = () => {
1544
1919
 
1545
1920
  const getMenuEntries$5 = () => {
1546
1921
  return [{
1547
- id: File$1,
1922
+ id: File$2,
1548
1923
  label: file(),
1549
1924
  flags: SubMenu
1550
1925
  }, {
@@ -1583,7 +1958,7 @@ const getMenuEntries$5 = () => {
1583
1958
 
1584
1959
  const getMenuEntries$4 = () => {
1585
1960
  return [{
1586
- id: File$1,
1961
+ id: File$2,
1587
1962
  label: file(),
1588
1963
  flags: None$1
1589
1964
  }, {
@@ -1756,18 +2131,6 @@ const createTitleBarButton = button => {
1756
2131
  return dom;
1757
2132
  };
1758
2133
 
1759
- const mergeClassNames = (...classNames) => {
1760
- return classNames.filter(Boolean).join(' ');
1761
- };
1762
- const Text = 12;
1763
- const text = data => {
1764
- return {
1765
- type: Text,
1766
- text: data,
1767
- childCount: 0
1768
- };
1769
- };
1770
-
1771
2134
  const getTitleBarButtonsVirtualDom = buttons => {
1772
2135
  const dom = [{
1773
2136
  type: Div,
@@ -1864,7 +2227,7 @@ const getTitleVirtualDom = title => {
1864
2227
  };
1865
2228
 
1866
2229
  const maximize = async () => {
1867
- await invoke('ElectronWindow.unmaximize');
2230
+ await invoke('ElectronWindow.maximize');
1868
2231
  };
1869
2232
  const minimize = async () => {
1870
2233
  await invoke('ElectronWindow.minimize');
@@ -2324,6 +2687,71 @@ const getKeyBindingString = (key, altKey, ctrlKey, shiftKey, metaKey) => {
2324
2687
  return string;
2325
2688
  };
2326
2689
 
2690
+ const Backspace$1 = 1;
2691
+ const Tab$1 = 2;
2692
+ const Enter$1 = 3;
2693
+ const Escape$1 = 8;
2694
+ const Space$1 = 9;
2695
+ const PageUp$1 = 10;
2696
+ const PageDown$1 = 11;
2697
+ const End$1 = 255;
2698
+ const Home$1 = 12;
2699
+ const LeftArrow$1 = 13;
2700
+ const UpArrow$1 = 14;
2701
+ const RightArrow$1 = 15;
2702
+ const DownArrow$1 = 16;
2703
+ const Insert$1 = 17;
2704
+ const Delete$1 = 18;
2705
+ const Digit0$1 = 19;
2706
+ const Digit1$1 = 20;
2707
+ const Digit2$1 = 21;
2708
+ const Digit3$1 = 22;
2709
+ const Digit4$1 = 23;
2710
+ const Digit5$1 = 24;
2711
+ const Digit6$1 = 25;
2712
+ const Digit7$1 = 26;
2713
+ const Digit8$1 = 27;
2714
+ const Digit9$1 = 28;
2715
+ const KeyA$1 = 29;
2716
+ const KeyB$1 = 30;
2717
+ const KeyC$1 = 31;
2718
+ const KeyD$1 = 32;
2719
+ const KeyE$1 = 33;
2720
+ const KeyF$1 = 34;
2721
+ const KeyG$1 = 35;
2722
+ const KeyH$1 = 36;
2723
+ const KeyI$1 = 37;
2724
+ const KeyJ$1 = 38;
2725
+ const KeyK$1 = 39;
2726
+ const KeyL$1 = 40;
2727
+ const KeyM$1 = 41;
2728
+ const KeyN$1 = 42;
2729
+ const KeyO$1 = 43;
2730
+ const KeyP$1 = 44;
2731
+ const KeyQ$1 = 45;
2732
+ const KeyR$1 = 46;
2733
+ const KeyS$1 = 47;
2734
+ const KeyT$1 = 48;
2735
+ const KeyU$1 = 49;
2736
+ const KeyV$1 = 50;
2737
+ const KeyW$1 = 51;
2738
+ const KeyX$1 = 52;
2739
+ const KeyY$1 = 53;
2740
+ const KeyZ$1 = 54;
2741
+ const F1$1 = 57;
2742
+ const F2$1 = 58;
2743
+ const F3$1 = 59;
2744
+ const F4$1 = 60;
2745
+ const F5$1 = 61;
2746
+ const F6$1 = 62;
2747
+ const Equal$1 = 84;
2748
+ const Comma$1 = 85;
2749
+ const Minus$1 = 86;
2750
+ const Backquote$1 = 89;
2751
+ const Backslash$1 = 91;
2752
+ const Star$1 = 131;
2753
+ const Plus$1 = 132;
2754
+
2327
2755
  const Unknown = 'Unknown';
2328
2756
  const Backspace = 'Backspace';
2329
2757
  const Tab = 'Tab';
@@ -2525,9 +2953,6 @@ const getKeyCodeString = keyCode => {
2525
2953
  }
2526
2954
  };
2527
2955
 
2528
- const CtrlCmd = 1 << 11 >>> 0;
2529
- const Shift = 1 << 10 >>> 0;
2530
-
2531
2956
  const parseKey = rawKey => {
2532
2957
  number(rawKey);
2533
2958
  const isCtrl = Boolean(rawKey & CtrlCmd);
@@ -2769,8 +3194,8 @@ const render2 = async (uid, diffResult) => {
2769
3194
  const {
2770
3195
  oldState,
2771
3196
  newState
2772
- } = get(uid);
2773
- set(uid, newState, newState);
3197
+ } = get$1(uid);
3198
+ set$3(uid, newState, newState);
2774
3199
  const commands = applyRender(oldState, newState, diffResult);
2775
3200
  return commands;
2776
3201
  };
@@ -2837,7 +3262,7 @@ const create = (id, uri, x, y, width, height) => {
2837
3262
  width,
2838
3263
  height
2839
3264
  };
2840
- set(id, state, state);
3265
+ set$3(id, state, state);
2841
3266
  return state;
2842
3267
  };
2843
3268
 
@@ -3171,7 +3596,8 @@ const selectIndexNone = async (state, item) => {
3171
3596
  return {
3172
3597
  ...state,
3173
3598
  menus: [],
3174
- isMenuOpen: false
3599
+ isMenuOpen: false,
3600
+ focusedIndex: -1
3175
3601
  };
3176
3602
  };
3177
3603
 
@@ -3326,13 +3752,13 @@ const wrapCommand = fn => {
3326
3752
  const wrapped = async (uid, ...args) => {
3327
3753
  const {
3328
3754
  newState
3329
- } = get(uid);
3755
+ } = get$1(uid);
3330
3756
  const newerState = await fn(newState, ...args);
3331
3757
  if (newState === newerState) {
3332
3758
  return;
3333
3759
  }
3334
- const latest = get(uid);
3335
- set(uid, latest.oldState, newerState);
3760
+ const latest = get$1(uid);
3761
+ set$3(uid, latest.oldState, newerState);
3336
3762
  };
3337
3763
  return wrapped;
3338
3764
  };
@@ -3356,11 +3782,11 @@ const commandMap = {
3356
3782
  'TitleBarMenuBar.focusNext': wrapCommand(focusNext),
3357
3783
  'TitleBarMenuBar.focusPrevious': wrapCommand(focusPrevious),
3358
3784
  'TitleBarMenuBar.getCommands': getCommandIds,
3359
- 'TitleBarMenuBar.getKeyBindings': getKeyBindings,
3785
+ 'TitleBarMenuBar.getKeyBindings': getKeyBindings$1,
3360
3786
  'TitleBarMenuBar.getMenus': getMenus,
3787
+ 'TitleBarMenuBar.getTitleBarButtons': getTitleBarButtons,
3361
3788
  'TitleBarMenuBar.getVirtualDom': getTitleBarMenuBarVirtualDom,
3362
3789
  'TitleBarMenuBar.handleClick': wrapCommand(handleClick),
3363
- 'TitleBarMenuBar.getTitleBarButtons': getTitleBarButtons,
3364
3790
  'TitleBarMenuBar.handleClickAt': wrapCommand(handleClickAt),
3365
3791
  'TitleBarMenuBar.handleFocus': wrapCommand(handleFocus),
3366
3792
  'TitleBarMenuBar.handleFocusOut': wrapCommand(handleFocusOut),
@@ -3391,7 +3817,7 @@ const listen = async () => {
3391
3817
  const rpc = await WebWorkerRpcClient.create({
3392
3818
  commandMap: commandMap
3393
3819
  });
3394
- setRpc(rpc);
3820
+ set(rpc);
3395
3821
  };
3396
3822
 
3397
3823
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/title-bar-worker",
3
- "version": "2.2.0",
3
+ "version": "2.4.0",
4
4
  "description": "Title Bar Worker",
5
5
  "repository": {
6
6
  "type": "git",