@lvce-editor/menu-worker 1.3.0 → 1.6.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.
@@ -785,10 +785,10 @@ const send = (transport, method, ...params) => {
785
785
  const message = create$4(method, params);
786
786
  transport.send(message);
787
787
  };
788
- const invoke$3 = (ipc, method, ...params) => {
788
+ const invoke$2 = (ipc, method, ...params) => {
789
789
  return invokeHelper(ipc, method, params, false);
790
790
  };
791
- const invokeAndTransfer$1 = (ipc, method, ...params) => {
791
+ const invokeAndTransfer = (ipc, method, ...params) => {
792
792
  return invokeHelper(ipc, method, params, true);
793
793
  };
794
794
 
@@ -824,10 +824,10 @@ const createRpc = ipc => {
824
824
  send(ipc, method, ...params);
825
825
  },
826
826
  invoke(method, ...params) {
827
- return invoke$3(ipc, method, ...params);
827
+ return invoke$2(ipc, method, ...params);
828
828
  },
829
829
  invokeAndTransfer(method, ...params) {
830
- return invokeAndTransfer$1(ipc, method, ...params);
830
+ return invokeAndTransfer(ipc, method, ...params);
831
831
  },
832
832
  async dispose() {
833
833
  await ipc?.dispose();
@@ -879,430 +879,328 @@ const WebWorkerRpcClient = {
879
879
  __proto__: null,
880
880
  create: create$2
881
881
  };
882
- const createMockRpc = ({
883
- commandMap
884
- }) => {
885
- const invocations = [];
886
- const invoke = (method, ...params) => {
887
- invocations.push([method, ...params]);
888
- const command = commandMap[method];
889
- if (!command) {
890
- throw new Error(`command ${method} not found`);
891
- }
892
- return command(...params);
893
- };
894
- const mockRpc = {
895
- invoke,
896
- invokeAndTransfer: invoke,
897
- invocations
898
- };
899
- return mockRpc;
900
- };
901
882
 
902
883
  const Text = 12;
903
884
 
904
- const Escape$2 = 8;
905
- const Space$2 = 9;
906
- const End$2 = 255;
907
- const Home$2 = 12;
908
- const LeftArrow$2 = 13;
909
- const UpArrow$2 = 14;
910
- const RightArrow$2 = 15;
911
- const DownArrow$2 = 16;
912
-
913
- const CtrlCmd = 1 << 11 >>> 0;
914
- const Shift = 1 << 10 >>> 0;
915
-
916
- const DebugWorker = 55;
917
- const RendererWorker$1 = 1;
918
-
919
- const rpcs = Object.create(null);
920
- const set$2 = (id, rpc) => {
921
- rpcs[id] = rpc;
922
- };
923
- const get$1 = id => {
924
- return rpcs[id];
925
- };
885
+ const Backspace$1 = 1;
886
+ const Tab$1 = 2;
887
+ const Enter$1 = 3;
888
+ const Escape$1 = 8;
889
+ const Space$1 = 9;
890
+ const PageUp$1 = 10;
891
+ const PageDown$1 = 11;
892
+ const End$1 = 255;
893
+ const Home$1 = 12;
894
+ const LeftArrow$1 = 13;
895
+ const UpArrow$1 = 14;
896
+ const RightArrow$1 = 15;
897
+ const DownArrow$1 = 16;
898
+ const Insert$1 = 17;
899
+ const Delete$1 = 18;
900
+ const Digit0$1 = 19;
901
+ const Digit1$1 = 20;
902
+ const Digit2$1 = 21;
903
+ const Digit3$1 = 22;
904
+ const Digit4$1 = 23;
905
+ const Digit5$1 = 24;
906
+ const Digit6$1 = 25;
907
+ const Digit7$1 = 26;
908
+ const Digit8$1 = 27;
909
+ const Digit9$1 = 28;
910
+ const KeyA$1 = 29;
911
+ const KeyB$1 = 30;
912
+ const KeyC$1 = 31;
913
+ const KeyD$1 = 32;
914
+ const KeyE$1 = 33;
915
+ const KeyF$1 = 34;
916
+ const KeyG$1 = 35;
917
+ const KeyH$1 = 36;
918
+ const KeyI$1 = 37;
919
+ const KeyJ$1 = 38;
920
+ const KeyK$1 = 39;
921
+ const KeyL$1 = 40;
922
+ const KeyM$1 = 41;
923
+ const KeyN$1 = 42;
924
+ const KeyO$1 = 43;
925
+ const KeyP$1 = 44;
926
+ const KeyQ$1 = 45;
927
+ const KeyR$1 = 46;
928
+ const KeyS$1 = 47;
929
+ const KeyT$1 = 48;
930
+ const KeyU$1 = 49;
931
+ const KeyV$1 = 50;
932
+ const KeyW$1 = 51;
933
+ const KeyX$1 = 52;
934
+ const KeyY$1 = 53;
935
+ const KeyZ$1 = 54;
936
+ const F1$1 = 57;
937
+ const F2$1 = 58;
938
+ const F3$1 = 59;
939
+ const F4$1 = 60;
940
+ const F5$1 = 61;
941
+ const F6$1 = 62;
942
+ const Equal$1 = 84;
943
+ const Comma$1 = 85;
944
+ const Minus$1 = 86;
945
+ const Backquote$1 = 89;
946
+ const Backslash$1 = 91;
947
+ const Star$1 = 131;
948
+ const Plus$1 = 132;
926
949
 
927
- const create$1 = rpcId => {
928
- return {
929
- // @ts-ignore
930
- invoke(method, ...params) {
931
- const rpc = get$1(rpcId);
932
- // @ts-ignore
933
- return rpc.invoke(method, ...params);
934
- },
935
- // @ts-ignore
936
- invokeAndTransfer(method, ...params) {
937
- const rpc = get$1(rpcId);
938
- // @ts-ignore
939
- return rpc.invokeAndTransfer(method, ...params);
940
- },
941
- set(rpc) {
942
- set$2(rpcId, rpc);
943
- },
944
- async dispose() {
945
- const rpc = get$1(rpcId);
946
- await rpc.dispose();
947
- }
948
- };
949
- };
950
+ const Unknown = 'Unknown';
951
+ const Backspace = 'Backspace';
952
+ const Tab = 'Tab';
953
+ const Enter = 'Enter';
954
+ const Escape = 'Escape';
955
+ const Space = 'Space';
956
+ const PageUp = 'PageUp';
957
+ const PageDown = 'PageDown';
958
+ const End = 'End';
959
+ const Home = 'Home';
960
+ const LeftArrow = 'LeftArrow';
961
+ const UpArrow = 'UpArrow';
962
+ const RightArrow = 'RightArrow';
963
+ const DownArrow = 'DownArrow';
964
+ const Insert = 'Insert';
965
+ const Delete = 'Delete';
966
+ const Digit0 = '0';
967
+ const Digit1 = '1';
968
+ const Digit2 = '2';
969
+ const Digit3 = '3';
970
+ const Digit4 = '4';
971
+ const Digit5 = '5';
972
+ const Digit6 = '6';
973
+ const Digit7 = '7';
974
+ const Digit8 = '8';
975
+ const Digit9 = '9';
976
+ const KeyA = 'a';
977
+ const KeyB = 'b';
978
+ const KeyC = 'c';
979
+ const KeyD = 'd';
980
+ const KeyE = 'e';
981
+ const KeyF = 'f';
982
+ const KeyG = 'g';
983
+ const KeyH = 'h';
984
+ const KeyI = 'i';
985
+ const KeyJ = 'j';
986
+ const KeyK = 'k';
987
+ const KeyL = 'l';
988
+ const KeyM = 'm';
989
+ const KeyN = 'n';
990
+ const KeyO = 'o';
991
+ const KeyP = 'p';
992
+ const KeyQ = 'q';
993
+ const KeyR = 'r';
994
+ const KeyS = 's';
995
+ const KeyT = 't';
996
+ const KeyU = 'u';
997
+ const KeyV = 'v';
998
+ const KeyW = 'w';
999
+ const KeyX = 'x';
1000
+ const KeyY = 'y';
1001
+ const KeyZ = 'z';
1002
+ const F1 = 'F1';
1003
+ const F2 = 'F2';
1004
+ const F3 = 'F3';
1005
+ const F4 = 'F4';
1006
+ const F5 = 'F5';
1007
+ const F6 = 'F6';
1008
+ const Equal = '=';
1009
+ const Comma = ',';
1010
+ const Minus = 'Minus';
1011
+ const Backquote = 'Backquote';
1012
+ const Backslash = 'Backslash';
1013
+ const Star = '*';
1014
+ const Plus = '+';
950
1015
 
951
- const {
952
- invoke: invoke$2,
953
- invokeAndTransfer,
954
- set: set$1,
955
- dispose
956
- } = create$1(RendererWorker$1);
957
- const searchFileHtml = async uri => {
958
- return invoke$2('ExtensionHost.searchFileWithHtml', uri);
959
- };
960
- const getFilePathElectron = async file => {
961
- return invoke$2('FileSystemHandle.getFilePathElectron', file);
962
- };
963
- const showContextMenu = async (x, y, id, ...args) => {
964
- return invoke$2('ContextMenu.show', x, y, id, ...args);
965
- };
966
- const getElectronVersion = async () => {
967
- return invoke$2('Process.getElectronVersion');
968
- };
969
- const applyBulkReplacement = async bulkEdits => {
970
- await invoke$2('BulkReplacement.applyBulkReplacement', bulkEdits);
971
- };
972
- const setColorTheme = async id => {
973
- // @ts-ignore
974
- return invoke$2(/* ColorTheme.setColorTheme */'ColorTheme.setColorTheme', /* colorThemeId */id);
975
- };
976
- const getNodeVersion = async () => {
977
- return invoke$2('Process.getNodeVersion');
978
- };
979
- const getChromeVersion = async () => {
980
- return invoke$2('Process.getChromeVersion');
981
- };
982
- const getV8Version = async () => {
983
- return invoke$2('Process.getV8Version');
984
- };
985
- const getFileHandles = async fileIds => {
986
- const files = await invoke$2('FileSystemHandle.getFileHandles', fileIds);
987
- return files;
988
- };
989
- const setWorkspacePath = async path => {
990
- await invoke$2('Workspace.setPath', path);
991
- };
992
- const registerWebViewInterceptor = async (id, port) => {
993
- await invokeAndTransfer('WebView.registerInterceptor', id, port);
994
- };
995
- const unregisterWebViewInterceptor = async id => {
996
- await invoke$2('WebView.unregisterInterceptor', id);
997
- };
998
- const sendMessagePortToEditorWorker = async (port, rpcId) => {
999
- const command = 'HandleMessagePort.handleMessagePort';
1000
- // @ts-ignore
1001
- await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToEditorWorker', port, command, rpcId);
1002
- };
1003
- const sendMessagePortToErrorWorker = async (port, rpcId) => {
1004
- const command = 'Errors.handleMessagePort';
1005
- // @ts-ignore
1006
- await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToErrorWorker', port, command, rpcId);
1007
- };
1008
- const sendMessagePortToMarkdownWorker = async (port, rpcId) => {
1009
- const command = 'Markdown.handleMessagePort';
1010
- // @ts-ignore
1011
- await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToMarkdownWorker', port, command, rpcId);
1012
- };
1013
- const sendMessagePortToIconThemeWorker = async (port, rpcId) => {
1014
- const command = 'IconTheme.handleMessagePort';
1015
- // @ts-ignore
1016
- await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToIconThemeWorker', port, command, rpcId);
1017
- };
1018
- const sendMessagePortToFileSystemWorker = async (port, rpcId) => {
1019
- const command = 'FileSystem.handleMessagePort';
1020
- // @ts-ignore
1021
- await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToFileSystemWorker', port, command, rpcId);
1022
- };
1023
- const readFile = async uri => {
1024
- return invoke$2('FileSystem.readFile', uri);
1025
- };
1026
- const getWebViewSecret = async key => {
1027
- // @ts-ignore
1028
- return invoke$2('WebView.getSecret', key);
1029
- };
1030
- const setWebViewPort = async (uid, port, origin, portType) => {
1031
- return invokeAndTransfer('WebView.setPort', uid, port, origin, portType);
1032
- };
1033
- const setFocus = key => {
1034
- return invoke$2('Focus.setFocus', key);
1035
- };
1036
- const getFileIcon = async options => {
1037
- return invoke$2('IconTheme.getFileIcon', options);
1038
- };
1039
- const getColorThemeNames = async () => {
1040
- return invoke$2('ColorTheme.getColorThemeNames');
1041
- };
1042
- const disableExtension = async id => {
1043
- // @ts-ignore
1044
- return invoke$2('ExtensionManagement.disable', id);
1045
- };
1046
- const enableExtension = async id => {
1047
- // @ts-ignore
1048
- return invoke$2('ExtensionManagement.enable', id);
1049
- };
1050
- const handleDebugChange = async params => {
1051
- // @ts-ignore
1052
- return invoke$2('Run And Debug.handleChange', params);
1053
- };
1054
- const getFolderIcon = async options => {
1055
- return invoke$2('IconTheme.getFolderIcon', options);
1056
- };
1057
- const closeWidget = async widgetId => {
1058
- return invoke$2('Viewlet.closeWidget', widgetId);
1059
- };
1060
- const sendMessagePortToExtensionHostWorker = async (port, rpcId = 0) => {
1061
- const command = 'HandleMessagePort.handleMessagePort2';
1062
- await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, rpcId);
1063
- };
1064
- const sendMessagePortToSearchProcess = async port => {
1065
- await invokeAndTransfer('SendMessagePortToElectron.sendMessagePortToElectron', port, 'HandleMessagePortForSearchProcess.handleMessagePortForSearchProcess');
1066
- };
1067
- const confirm = async (message, options) => {
1068
- // @ts-ignore
1069
- const result = await invoke$2('ConfirmPrompt.prompt', message, options);
1070
- return result;
1071
- };
1072
- const getRecentlyOpened$1 = async () => {
1073
- return invoke$2(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
1074
- };
1075
- const getKeyBindings$1 = async () => {
1076
- return invoke$2('KeyBindingsInitial.getKeyBindings');
1077
- };
1078
- const writeClipBoardText = async text => {
1079
- await invoke$2('ClipBoard.writeText', /* text */text);
1080
- };
1081
- const writeClipBoardImage = async blob => {
1082
- // @ts-ignore
1083
- await invoke$2('ClipBoard.writeImage', /* text */blob);
1084
- };
1085
- const searchFileMemory = async uri => {
1086
- // @ts-ignore
1087
- return invoke$2('ExtensionHost.searchFileWithMemory', uri);
1088
- };
1089
- const searchFileFetch = async uri => {
1090
- return invoke$2('ExtensionHost.searchFileWithFetch', uri);
1091
- };
1092
- const showMessageBox = async options => {
1093
- return invoke$2('ElectronDialog.showMessageBox', options);
1094
- };
1095
- const handleDebugResumed = async params => {
1096
- await invoke$2('Run And Debug.handleResumed', params);
1097
- };
1098
- const openWidget = async name => {
1099
- await invoke$2('Viewlet.openWidget', name);
1100
- };
1101
- const getIcons = async requests => {
1102
- const icons = await invoke$2('IconTheme.getIcons', requests);
1103
- return icons;
1104
- };
1105
- const activateByEvent = event => {
1106
- return invoke$2('ExtensionHostManagement.activateByEvent', event);
1107
- };
1108
- const setAdditionalFocus = focusKey => {
1109
- // @ts-ignore
1110
- return invoke$2('Focus.setAdditionalFocus', focusKey);
1111
- };
1112
- const getActiveEditorId = () => {
1113
- // @ts-ignore
1114
- return invoke$2('GetActiveEditor.getActiveEditorId');
1115
- };
1116
- const getWorkspacePath = () => {
1117
- return invoke$2('Workspace.getPath');
1118
- };
1119
- const sendMessagePortToRendererProcess = async port => {
1120
- const command = 'HandleMessagePort.handleMessagePort';
1121
- // @ts-ignore
1122
- await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToRendererProcess', port, command, DebugWorker);
1123
- };
1124
- const getPreference = async key => {
1125
- return await invoke$2('Preferences.get', key);
1126
- };
1127
- const getAllExtensions = async () => {
1128
- return invoke$2('ExtensionManagement.getAllExtensions');
1129
- };
1130
- const rerenderEditor = async key => {
1131
- // @ts-ignore
1132
- return invoke$2('Editor.rerender', key);
1133
- };
1134
- const handleDebugPaused = async params => {
1135
- await invoke$2('Run And Debug.handlePaused', params);
1136
- };
1137
- const openUri = async (uri, focus, options) => {
1138
- await invoke$2('Main.openUri', uri, focus, options);
1139
- };
1140
- const sendMessagePortToSyntaxHighlightingWorker = async port => {
1141
- await invokeAndTransfer(
1142
- // @ts-ignore
1143
- 'SendMessagePortToSyntaxHighlightingWorker.sendMessagePortToSyntaxHighlightingWorker', port, 'HandleMessagePort.handleMessagePort2');
1144
- };
1145
- const handleDebugScriptParsed = async script => {
1146
- await invoke$2('Run And Debug.handleScriptParsed', script);
1147
- };
1148
- const getWindowId = async () => {
1149
- return invoke$2('GetWindowId.getWindowId');
1150
- };
1151
- const getBlob = async uri => {
1152
- // @ts-ignore
1153
- return invoke$2('FileSystem.getBlob', uri);
1154
- };
1155
- const getExtensionCommands = async () => {
1156
- return invoke$2('ExtensionHost.getCommands');
1157
- };
1158
- const showErrorDialog = async errorInfo => {
1159
- // @ts-ignore
1160
- await invoke$2('ErrorHandling.showErrorDialog', errorInfo);
1161
- };
1162
- const getFolderSize = async uri => {
1163
- // @ts-ignore
1164
- return await invoke$2('FileSystem.getFolderSize', uri);
1165
- };
1166
- const getExtension = async id => {
1167
- // @ts-ignore
1168
- return invoke$2('ExtensionManagement.getExtension', id);
1169
- };
1170
- const getMarkdownDom = async html => {
1171
- // @ts-ignore
1172
- return invoke$2('Markdown.getVirtualDom', html);
1173
- };
1174
- const renderMarkdown = async (markdown, options) => {
1175
- // @ts-ignore
1176
- return invoke$2('Markdown.renderMarkdown', markdown, options);
1177
- };
1178
- const openNativeFolder = async uri => {
1179
- // @ts-ignore
1180
- await invoke$2('OpenNativeFolder.openNativeFolder', uri);
1181
- };
1182
- const uninstallExtension = async id => {
1183
- return invoke$2('ExtensionManagement.uninstall', id);
1184
- };
1185
- const installExtension = async id => {
1186
- // @ts-ignore
1187
- return invoke$2('ExtensionManagement.install', id);
1188
- };
1189
- const openExtensionSearch = async () => {
1190
- // @ts-ignore
1191
- return invoke$2('SideBar.openViewlet', 'Extensions');
1192
- };
1193
- const setExtensionsSearchValue = async searchValue => {
1194
- // @ts-ignore
1195
- return invoke$2('Extensions.handleInput', searchValue);
1196
- };
1197
- const openExternal = async uri => {
1198
- // @ts-ignore
1199
- await invoke$2('Open.openExternal', uri);
1200
- };
1201
- const openUrl = async uri => {
1202
- // @ts-ignore
1203
- await invoke$2('Open.openUrl', uri);
1204
- };
1205
- const getAllPreferences = async () => {
1206
- // @ts-ignore
1207
- return invoke$2('Preferences.getAll');
1016
+ const getKeyCodeString = keyCode => {
1017
+ switch (keyCode) {
1018
+ case Backspace$1:
1019
+ return Backspace;
1020
+ case Tab$1:
1021
+ return Tab;
1022
+ case Escape$1:
1023
+ return Escape;
1024
+ case Enter$1:
1025
+ return Enter;
1026
+ case Space$1:
1027
+ return Space;
1028
+ case PageUp$1:
1029
+ return PageUp;
1030
+ case PageDown$1:
1031
+ return PageDown;
1032
+ case End$1:
1033
+ return End;
1034
+ case Home$1:
1035
+ return Home;
1036
+ case LeftArrow$1:
1037
+ return LeftArrow;
1038
+ case UpArrow$1:
1039
+ return UpArrow;
1040
+ case RightArrow$1:
1041
+ return RightArrow;
1042
+ case DownArrow$1:
1043
+ return DownArrow;
1044
+ case Insert$1:
1045
+ return Insert;
1046
+ case Delete$1:
1047
+ return Delete;
1048
+ case Digit0$1:
1049
+ return Digit0;
1050
+ case Digit1$1:
1051
+ return Digit1;
1052
+ case Digit2$1:
1053
+ return Digit2;
1054
+ case Digit3$1:
1055
+ return Digit3;
1056
+ case Digit4$1:
1057
+ return Digit4;
1058
+ case Digit5$1:
1059
+ return Digit5;
1060
+ case Digit6$1:
1061
+ return Digit6;
1062
+ case Digit7$1:
1063
+ return Digit7;
1064
+ case Digit8$1:
1065
+ return Digit8;
1066
+ case Digit9$1:
1067
+ return Digit9;
1068
+ case KeyA$1:
1069
+ return KeyA;
1070
+ case KeyB$1:
1071
+ return KeyB;
1072
+ case KeyC$1:
1073
+ return KeyC;
1074
+ case KeyD$1:
1075
+ return KeyD;
1076
+ case KeyE$1:
1077
+ return KeyE;
1078
+ case KeyF$1:
1079
+ return KeyF;
1080
+ case KeyG$1:
1081
+ return KeyG;
1082
+ case KeyH$1:
1083
+ return KeyH;
1084
+ case KeyI$1:
1085
+ return KeyI;
1086
+ case KeyJ$1:
1087
+ return KeyJ;
1088
+ case KeyK$1:
1089
+ return KeyK;
1090
+ case KeyL$1:
1091
+ return KeyL;
1092
+ case KeyM$1:
1093
+ return KeyM;
1094
+ case KeyN$1:
1095
+ return KeyN;
1096
+ case KeyO$1:
1097
+ return KeyO;
1098
+ case KeyP$1:
1099
+ return KeyP;
1100
+ case KeyQ$1:
1101
+ return KeyQ;
1102
+ case KeyR$1:
1103
+ return KeyR;
1104
+ case KeyS$1:
1105
+ return KeyS;
1106
+ case KeyT$1:
1107
+ return KeyT;
1108
+ case KeyU$1:
1109
+ return KeyU;
1110
+ case KeyV$1:
1111
+ return KeyV;
1112
+ case KeyW$1:
1113
+ return KeyW;
1114
+ case KeyX$1:
1115
+ return KeyX;
1116
+ case KeyY$1:
1117
+ return KeyY;
1118
+ case KeyZ$1:
1119
+ return KeyZ;
1120
+ case F1$1:
1121
+ return F1;
1122
+ case F2$1:
1123
+ return F2;
1124
+ case F3$1:
1125
+ return F3;
1126
+ case F4$1:
1127
+ return F4;
1128
+ case F5$1:
1129
+ return F5;
1130
+ case F6$1:
1131
+ return F6;
1132
+ case Backslash$1:
1133
+ return Backslash;
1134
+ case Equal$1:
1135
+ return Equal;
1136
+ case Comma$1:
1137
+ return Comma;
1138
+ case Backquote$1:
1139
+ return Backquote;
1140
+ case Plus$1:
1141
+ return Plus;
1142
+ case Star$1:
1143
+ return Star;
1144
+ case Minus$1:
1145
+ return Minus;
1146
+ default:
1147
+ return Unknown;
1148
+ }
1208
1149
  };
1209
- const showSaveFilePicker = async () => {
1210
- // @ts-ignore
1211
- return invoke$2('FilePicker.showSaveFilePicker');
1150
+
1151
+ const CtrlCmd = 1 << 11 >>> 0;
1152
+ const Shift = 1 << 10 >>> 0;
1153
+
1154
+ const parseKey = rawKey => {
1155
+ const isCtrl = Boolean(rawKey & CtrlCmd);
1156
+ const isShift = Boolean(rawKey & Shift);
1157
+ const keyCode = rawKey & 0x00_00_00_ff;
1158
+ const key = getKeyCodeString(keyCode);
1159
+ return {
1160
+ key,
1161
+ isCtrl,
1162
+ isShift
1163
+ };
1212
1164
  };
1213
- const getLogsDir = async () => {
1214
- // @ts-ignore
1215
- return invoke$2('PlatformPaths.getLogsDir');
1165
+
1166
+ const RendererWorker = 1;
1167
+
1168
+ const rpcs = Object.create(null);
1169
+ const set$2 = (id, rpc) => {
1170
+ rpcs[id] = rpc;
1216
1171
  };
1217
- const registerMockRpc = commandMap => {
1218
- const mockRpc = createMockRpc({
1219
- commandMap
1220
- });
1221
- set$1(mockRpc);
1222
- return mockRpc;
1172
+ const get$1 = id => {
1173
+ return rpcs[id];
1223
1174
  };
1224
1175
 
1225
- const RendererWorker = {
1226
- __proto__: null,
1227
- activateByEvent,
1228
- applyBulkReplacement,
1229
- closeWidget,
1230
- confirm,
1231
- disableExtension,
1232
- dispose,
1233
- enableExtension,
1234
- getActiveEditorId,
1235
- getAllExtensions,
1236
- getAllPreferences,
1237
- getBlob,
1238
- getChromeVersion,
1239
- getColorThemeNames,
1240
- getElectronVersion,
1241
- getExtension,
1242
- getExtensionCommands,
1243
- getFileHandles,
1244
- getFileIcon,
1245
- getFilePathElectron,
1246
- getFolderIcon,
1247
- getFolderSize,
1248
- getIcons,
1249
- getKeyBindings: getKeyBindings$1,
1250
- getLogsDir,
1251
- getMarkdownDom,
1252
- getNodeVersion,
1253
- getPreference,
1254
- getRecentlyOpened: getRecentlyOpened$1,
1255
- getV8Version,
1256
- getWebViewSecret,
1257
- getWindowId,
1258
- getWorkspacePath,
1259
- handleDebugChange,
1260
- handleDebugPaused,
1261
- handleDebugResumed,
1262
- handleDebugScriptParsed,
1263
- installExtension,
1264
- invoke: invoke$2,
1265
- invokeAndTransfer,
1266
- openExtensionSearch,
1267
- openExternal,
1268
- openNativeFolder,
1269
- openUri,
1270
- openUrl,
1271
- openWidget,
1272
- readFile,
1273
- registerMockRpc,
1274
- registerWebViewInterceptor,
1275
- renderMarkdown,
1276
- rerenderEditor,
1277
- searchFileFetch,
1278
- searchFileHtml,
1279
- searchFileMemory,
1280
- sendMessagePortToEditorWorker,
1281
- sendMessagePortToErrorWorker,
1282
- sendMessagePortToExtensionHostWorker,
1283
- sendMessagePortToFileSystemWorker,
1284
- sendMessagePortToIconThemeWorker,
1285
- sendMessagePortToMarkdownWorker,
1286
- sendMessagePortToRendererProcess,
1287
- sendMessagePortToSearchProcess,
1288
- sendMessagePortToSyntaxHighlightingWorker,
1289
- set: set$1,
1290
- setAdditionalFocus,
1291
- setColorTheme,
1292
- setExtensionsSearchValue,
1293
- setFocus,
1294
- setWebViewPort,
1295
- setWorkspacePath,
1296
- showContextMenu,
1297
- showErrorDialog,
1298
- showMessageBox,
1299
- showSaveFilePicker,
1300
- uninstallExtension,
1301
- unregisterWebViewInterceptor,
1302
- writeClipBoardImage,
1303
- writeClipBoardText
1176
+ const create$1 = rpcId => {
1177
+ return {
1178
+ // @ts-ignore
1179
+ invoke(method, ...params) {
1180
+ const rpc = get$1(rpcId);
1181
+ // @ts-ignore
1182
+ return rpc.invoke(method, ...params);
1183
+ },
1184
+ // @ts-ignore
1185
+ invokeAndTransfer(method, ...params) {
1186
+ const rpc = get$1(rpcId);
1187
+ // @ts-ignore
1188
+ return rpc.invokeAndTransfer(method, ...params);
1189
+ },
1190
+ set(rpc) {
1191
+ set$2(rpcId, rpc);
1192
+ },
1193
+ async dispose() {
1194
+ const rpc = get$1(rpcId);
1195
+ await rpc.dispose();
1196
+ }
1197
+ };
1304
1198
  };
1305
1199
 
1200
+ const {
1201
+ invoke: invoke$1,
1202
+ set: set$1} = create$1(RendererWorker);
1203
+
1306
1204
  const matchesArgs = (a, b) => {
1307
1205
  if (!a && !b) {
1308
1206
  return true;
@@ -1329,7 +1227,7 @@ const getCommandKeyBinding = (keyBindings, command, args) => {
1329
1227
  return undefined;
1330
1228
  };
1331
1229
 
1332
- const invoke$1 = async (method, ...params) => {
1230
+ const invoke = async (method, ...params) => {
1333
1231
  // TODO
1334
1232
  };
1335
1233
 
@@ -1642,7 +1540,7 @@ const MenuEntriesHelp = {
1642
1540
  };
1643
1541
 
1644
1542
  const getRecentlyOpened = () => {
1645
- return invoke$2(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
1543
+ return invoke$1(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
1646
1544
  };
1647
1545
 
1648
1546
  const File = 'file://';
@@ -1856,439 +1754,169 @@ const getMenuEntries$4 = () => {
1856
1754
  label: view(),
1857
1755
  flags: None
1858
1756
  }, {
1859
- id: Go$1,
1860
- label: go(),
1861
- flags: None
1862
- }, {
1863
- id: Help$1,
1864
- label: help(),
1865
- flags: None
1866
- }];
1867
- };
1868
-
1869
- const getFn = platform => {
1870
- switch (platform) {
1871
- case Web:
1872
- return getMenuEntries$4;
1873
- default:
1874
- return getMenuEntries$5;
1875
- }
1876
- };
1877
- const id$1 = TitleBar;
1878
- const getMenuEntries$3 = async platform => {
1879
- const fn = getFn(platform);
1880
- return fn();
1881
- };
1882
-
1883
- const MenuEntriesTitleBar = {
1884
- __proto__: null,
1885
- getMenuEntries: getMenuEntries$3,
1886
- id: id$1
1887
- };
1888
-
1889
- const id = View$1;
1890
- const getMenuEntries$2 = () => {
1891
- return [];
1892
- };
1893
-
1894
- const MenuEntriesView = {
1895
- __proto__: null,
1896
- getMenuEntries: getMenuEntries$2,
1897
- id
1898
- };
1899
-
1900
- const menus$1 = [MenuEntriesEdit, MenuEntriesFile, MenuEntriesGo, MenuEntriesHelp, MenuEntriesRun, MenuEntriesSelection, MenuEntriesTerminal, MenuEntriesTitleBar, MenuEntriesView, MenuEntriesOpenRecent];
1901
- const getMenus = () => {
1902
- return menus$1;
1903
- };
1904
- const getModule$1 = id => {
1905
- for (const module of menus$1) {
1906
- if (module.id === id) {
1907
- return module;
1908
- }
1909
- }
1910
- return undefined;
1911
- };
1912
- const getMenuEntries$1 = async (id, ...args) => {
1913
- try {
1914
- const module = getModule$1(id);
1915
- // @ts-ignore
1916
- const inject = module.inject || [];
1917
- // @ts-ignore
1918
- return module.getMenuEntries(...args);
1919
- } catch (error) {
1920
- throw new VError(error, `Failed to load menu entries for id ${id}`);
1921
- }
1922
- };
1923
-
1924
- const addKeyBindings = menuEntries => {
1925
- const keyBindings = state$1.matchingKeyBindings;
1926
- const newMenuEntries = [];
1927
- for (const menuEntry of menuEntries) {
1928
- const keyBinding = getCommandKeyBinding(keyBindings, menuEntry.command, menuEntry.args);
1929
- const key = keyBinding ? keyBinding.key : 0;
1930
- const newMenuEntry = {
1931
- ...menuEntry,
1932
- key
1933
- };
1934
- newMenuEntries.push(newMenuEntry);
1935
- }
1936
- return newMenuEntries;
1937
- };
1938
- const getMenuEntriesWithKeyBindings = async (id, ...args) => {
1939
- const menuEntries = await getMenuEntries$1(id, ...args);
1940
- const newMenuEntries = addKeyBindings(menuEntries);
1941
- return newMenuEntries;
1942
- };
1943
- const getMenuEntriesWithKeyBindings2 = async (uid, menuId, ...args) => {
1944
- // @ts-ignore
1945
- const menuEntries = await undefined(uid, menuId, ...args);
1946
- const newMenuEntries = addKeyBindings(menuEntries);
1947
- return newMenuEntries;
1948
- };
1949
-
1950
- const Menu$1 = 'menu';
1951
- const MenuItem$1 = 'menuitem';
1952
- const MenuItemCheckBox = 'menuitemcheckbox';
1953
- const Separator = 'separator';
1954
-
1955
- const MaskIconCheck = 'MaskIconCheck';
1956
- const Menu = 'Menu';
1957
- const MenuItem = 'MenuItem';
1958
- const MenuItemCheckMark = 'MenuItemCheckMark';
1959
- const MenuItemCheckmarkIcon = 'MenuItemCheckmarkIcon';
1960
- const MenuItemFocused = 'MenuItemFocused';
1961
- const MenuItemKeyBinding = 'MenuItemKeyBinding';
1962
- const MenuItemSeparator = 'MenuItemSeparator';
1963
- const MenuItemSeparatorLine = 'MenuItemSeparatorLine';
1964
- const MenuItemSubMenu = 'MenuItemSubMenu';
1965
- const MenuItemSubMenuArrowRight = 'MenuItemSubMenuArrowRight';
1966
-
1967
- const mergeClassNames = (...classNames) => {
1968
- return classNames.filter(Boolean).join(' ');
1969
- };
1970
-
1971
- const text = data => {
1972
- return {
1973
- type: Text,
1974
- text: data,
1975
- childCount: 0
1976
- };
1977
- };
1978
-
1979
- const Div = 4;
1980
- const Span = 8;
1981
-
1982
- const checkboxChecked = {
1983
- type: Div,
1984
- className: mergeClassNames(MenuItem, MenuItemCheckMark),
1985
- role: MenuItemCheckBox,
1986
- ariaChecked: true,
1987
- tabIndex: -1,
1988
- childCount: 2
1989
- };
1990
- const checkMark = {
1991
- type: Div,
1992
- className: mergeClassNames(MenuItemCheckmarkIcon, MaskIconCheck)
1993
- };
1994
- const getMenuItemCheckedDom = menuItem => {
1995
- const {
1996
- label
1997
- } = menuItem;
1998
- return [checkboxChecked, checkMark, text(label)];
1999
- };
2000
-
2001
- const getKeyBindingString = (key, altKey, ctrlKey, shiftKey, metaKey) => {
2002
- let string = '';
2003
- if (ctrlKey) {
2004
- string += 'Ctrl+';
2005
- }
2006
- if (shiftKey) {
2007
- string += 'Shift+';
2008
- }
2009
- string += key.toUpperCase();
2010
- return string;
2011
- };
2012
-
2013
- const Backspace$1 = 1;
2014
- const Tab$1 = 2;
2015
- const Enter$1 = 3;
2016
- const Escape$1 = 8;
2017
- const Space$1 = 9;
2018
- const PageUp$1 = 10;
2019
- const PageDown$1 = 11;
2020
- const End$1 = 255;
2021
- const Home$1 = 12;
2022
- const LeftArrow$1 = 13;
2023
- const UpArrow$1 = 14;
2024
- const RightArrow$1 = 15;
2025
- const DownArrow$1 = 16;
2026
- const Insert$1 = 17;
2027
- const Delete$1 = 18;
2028
- const Digit0$1 = 19;
2029
- const Digit1$1 = 20;
2030
- const Digit2$1 = 21;
2031
- const Digit3$1 = 22;
2032
- const Digit4$1 = 23;
2033
- const Digit5$1 = 24;
2034
- const Digit6$1 = 25;
2035
- const Digit7$1 = 26;
2036
- const Digit8$1 = 27;
2037
- const Digit9$1 = 28;
2038
- const KeyA$1 = 29;
2039
- const KeyB$1 = 30;
2040
- const KeyC$1 = 31;
2041
- const KeyD$1 = 32;
2042
- const KeyE$1 = 33;
2043
- const KeyF$1 = 34;
2044
- const KeyG$1 = 35;
2045
- const KeyH$1 = 36;
2046
- const KeyI$1 = 37;
2047
- const KeyJ$1 = 38;
2048
- const KeyK$1 = 39;
2049
- const KeyL$1 = 40;
2050
- const KeyM$1 = 41;
2051
- const KeyN$1 = 42;
2052
- const KeyO$1 = 43;
2053
- const KeyP$1 = 44;
2054
- const KeyQ$1 = 45;
2055
- const KeyR$1 = 46;
2056
- const KeyS$1 = 47;
2057
- const KeyT$1 = 48;
2058
- const KeyU$1 = 49;
2059
- const KeyV$1 = 50;
2060
- const KeyW$1 = 51;
2061
- const KeyX$1 = 52;
2062
- const KeyY$1 = 53;
2063
- const KeyZ$1 = 54;
2064
- const F1$1 = 57;
2065
- const F2$1 = 58;
2066
- const F3$1 = 59;
2067
- const F4$1 = 60;
2068
- const F5$1 = 61;
2069
- const F6$1 = 62;
2070
- const Equal$1 = 84;
2071
- const Comma$1 = 85;
2072
- const Minus$1 = 86;
2073
- const Backquote$1 = 89;
2074
- const Backslash$1 = 91;
2075
- const Star$1 = 131;
2076
- const Plus$1 = 132;
2077
-
2078
- const Unknown = 'Unknown';
2079
- const Backspace = 'Backspace';
2080
- const Tab = 'Tab';
2081
- const Enter = 'Enter';
2082
- const Escape = 'Escape';
2083
- const Space = 'Space';
2084
- const PageUp = 'PageUp';
2085
- const PageDown = 'PageDown';
2086
- const End = 'End';
2087
- const Home = 'Home';
2088
- const LeftArrow = 'LeftArrow';
2089
- const UpArrow = 'UpArrow';
2090
- const RightArrow = 'RightArrow';
2091
- const DownArrow = 'DownArrow';
2092
- const Insert = 'Insert';
2093
- const Delete = 'Delete';
2094
- const Digit0 = '0';
2095
- const Digit1 = '1';
2096
- const Digit2 = '2';
2097
- const Digit3 = '3';
2098
- const Digit4 = '4';
2099
- const Digit5 = '5';
2100
- const Digit6 = '6';
2101
- const Digit7 = '7';
2102
- const Digit8 = '8';
2103
- const Digit9 = '9';
2104
- const KeyA = 'a';
2105
- const KeyB = 'b';
2106
- const KeyC = 'c';
2107
- const KeyD = 'd';
2108
- const KeyE = 'e';
2109
- const KeyF = 'f';
2110
- const KeyG = 'g';
2111
- const KeyH = 'h';
2112
- const KeyI = 'i';
2113
- const KeyJ = 'j';
2114
- const KeyK = 'k';
2115
- const KeyL = 'l';
2116
- const KeyM = 'm';
2117
- const KeyN = 'n';
2118
- const KeyO = 'o';
2119
- const KeyP = 'p';
2120
- const KeyQ = 'q';
2121
- const KeyR = 'r';
2122
- const KeyS = 's';
2123
- const KeyT = 't';
2124
- const KeyU = 'u';
2125
- const KeyV = 'v';
2126
- const KeyW = 'w';
2127
- const KeyX = 'x';
2128
- const KeyY = 'y';
2129
- const KeyZ = 'z';
2130
- const F1 = 'F1';
2131
- const F2 = 'F2';
2132
- const F3 = 'F3';
2133
- const F4 = 'F4';
2134
- const F5 = 'F5';
2135
- const F6 = 'F6';
2136
- const Equal = '=';
2137
- const Comma = ',';
2138
- const Minus = 'Minus';
2139
- const Backquote = 'Backquote';
2140
- const Backslash = 'Backslash';
2141
- const Star = '*';
2142
- const Plus = '+';
2143
-
2144
- const getKeyCodeString = keyCode => {
2145
- switch (keyCode) {
2146
- case Backspace$1:
2147
- return Backspace;
2148
- case Tab$1:
2149
- return Tab;
2150
- case Escape$1:
2151
- return Escape;
2152
- case Enter$1:
2153
- return Enter;
2154
- case Space$1:
2155
- return Space;
2156
- case PageUp$1:
2157
- return PageUp;
2158
- case PageDown$1:
2159
- return PageDown;
2160
- case End$1:
2161
- return End;
2162
- case Home$1:
2163
- return Home;
2164
- case LeftArrow$1:
2165
- return LeftArrow;
2166
- case UpArrow$1:
2167
- return UpArrow;
2168
- case RightArrow$1:
2169
- return RightArrow;
2170
- case DownArrow$1:
2171
- return DownArrow;
2172
- case Insert$1:
2173
- return Insert;
2174
- case Delete$1:
2175
- return Delete;
2176
- case Digit0$1:
2177
- return Digit0;
2178
- case Digit1$1:
2179
- return Digit1;
2180
- case Digit2$1:
2181
- return Digit2;
2182
- case Digit3$1:
2183
- return Digit3;
2184
- case Digit4$1:
2185
- return Digit4;
2186
- case Digit5$1:
2187
- return Digit5;
2188
- case Digit6$1:
2189
- return Digit6;
2190
- case Digit7$1:
2191
- return Digit7;
2192
- case Digit8$1:
2193
- return Digit8;
2194
- case Digit9$1:
2195
- return Digit9;
2196
- case KeyA$1:
2197
- return KeyA;
2198
- case KeyB$1:
2199
- return KeyB;
2200
- case KeyC$1:
2201
- return KeyC;
2202
- case KeyD$1:
2203
- return KeyD;
2204
- case KeyE$1:
2205
- return KeyE;
2206
- case KeyF$1:
2207
- return KeyF;
2208
- case KeyG$1:
2209
- return KeyG;
2210
- case KeyH$1:
2211
- return KeyH;
2212
- case KeyI$1:
2213
- return KeyI;
2214
- case KeyJ$1:
2215
- return KeyJ;
2216
- case KeyK$1:
2217
- return KeyK;
2218
- case KeyL$1:
2219
- return KeyL;
2220
- case KeyM$1:
2221
- return KeyM;
2222
- case KeyN$1:
2223
- return KeyN;
2224
- case KeyO$1:
2225
- return KeyO;
2226
- case KeyP$1:
2227
- return KeyP;
2228
- case KeyQ$1:
2229
- return KeyQ;
2230
- case KeyR$1:
2231
- return KeyR;
2232
- case KeyS$1:
2233
- return KeyS;
2234
- case KeyT$1:
2235
- return KeyT;
2236
- case KeyU$1:
2237
- return KeyU;
2238
- case KeyV$1:
2239
- return KeyV;
2240
- case KeyW$1:
2241
- return KeyW;
2242
- case KeyX$1:
2243
- return KeyX;
2244
- case KeyY$1:
2245
- return KeyY;
2246
- case KeyZ$1:
2247
- return KeyZ;
2248
- case F1$1:
2249
- return F1;
2250
- case F2$1:
2251
- return F2;
2252
- case F3$1:
2253
- return F3;
2254
- case F4$1:
2255
- return F4;
2256
- case F5$1:
2257
- return F5;
2258
- case F6$1:
2259
- return F6;
2260
- case Backslash$1:
2261
- return Backslash;
2262
- case Equal$1:
2263
- return Equal;
2264
- case Comma$1:
2265
- return Comma;
2266
- case Backquote$1:
2267
- return Backquote;
2268
- case Plus$1:
2269
- return Plus;
2270
- case Star$1:
2271
- return Star;
2272
- case Minus$1:
2273
- return Minus;
1757
+ id: Go$1,
1758
+ label: go(),
1759
+ flags: None
1760
+ }, {
1761
+ id: Help$1,
1762
+ label: help(),
1763
+ flags: None
1764
+ }];
1765
+ };
1766
+
1767
+ const getFn = platform => {
1768
+ switch (platform) {
1769
+ case Web:
1770
+ return getMenuEntries$4;
2274
1771
  default:
2275
- return Unknown;
1772
+ return getMenuEntries$5;
2276
1773
  }
2277
1774
  };
1775
+ const id$1 = TitleBar;
1776
+ const getMenuEntries$3 = async platform => {
1777
+ const fn = getFn(platform);
1778
+ return fn();
1779
+ };
2278
1780
 
2279
- const parseKey = rawKey => {
2280
- number(rawKey);
2281
- const isCtrl = Boolean(rawKey & CtrlCmd);
2282
- const isShift = Boolean(rawKey & Shift);
2283
- const keyCode = rawKey & 0x00_00_00_ff;
2284
- const key = getKeyCodeString(keyCode);
1781
+ const MenuEntriesTitleBar = {
1782
+ __proto__: null,
1783
+ getMenuEntries: getMenuEntries$3,
1784
+ id: id$1
1785
+ };
1786
+
1787
+ const id = View$1;
1788
+ const getMenuEntries$2 = () => {
1789
+ return [];
1790
+ };
1791
+
1792
+ const MenuEntriesView = {
1793
+ __proto__: null,
1794
+ getMenuEntries: getMenuEntries$2,
1795
+ id
1796
+ };
1797
+
1798
+ const menus$1 = [MenuEntriesEdit, MenuEntriesFile, MenuEntriesGo, MenuEntriesHelp, MenuEntriesRun, MenuEntriesSelection, MenuEntriesTerminal, MenuEntriesTitleBar, MenuEntriesView, MenuEntriesOpenRecent];
1799
+ const getMenus = () => {
1800
+ return menus$1;
1801
+ };
1802
+ const getModule$1 = id => {
1803
+ for (const module of menus$1) {
1804
+ if (module.id === id) {
1805
+ return module;
1806
+ }
1807
+ }
1808
+ return undefined;
1809
+ };
1810
+ const getMenuEntries$1 = async (id, ...args) => {
1811
+ try {
1812
+ const module = getModule$1(id);
1813
+ // @ts-ignore
1814
+ const inject = module.inject || [];
1815
+ // @ts-ignore
1816
+ return module.getMenuEntries(...args);
1817
+ } catch (error) {
1818
+ throw new VError(error, `Failed to load menu entries for id ${id}`);
1819
+ }
1820
+ };
1821
+ const getMenuEntries2 = async (uid, menuId, ...args) => {
1822
+ try {
1823
+ const module = await getModule$1(menuId);
1824
+ // @ts-ignore
1825
+ return module.getMenuEntries(uid, ...args);
1826
+ } catch (error) {
1827
+ throw new VError(error, `Failed to load menu entries for id ${menuId}`);
1828
+ }
1829
+ };
1830
+
1831
+ const addKeyBindings = menuEntries => {
1832
+ const keyBindings = state$1.matchingKeyBindings;
1833
+ const newMenuEntries = [];
1834
+ for (const menuEntry of menuEntries) {
1835
+ const keyBinding = getCommandKeyBinding(keyBindings, menuEntry.command, menuEntry.args);
1836
+ const key = keyBinding ? keyBinding.key : 0;
1837
+ const newMenuEntry = {
1838
+ ...menuEntry,
1839
+ key
1840
+ };
1841
+ newMenuEntries.push(newMenuEntry);
1842
+ }
1843
+ return newMenuEntries;
1844
+ };
1845
+ const getMenuEntriesWithKeyBindings = async (id, ...args) => {
1846
+ const menuEntries = await getMenuEntries$1(id, ...args);
1847
+ const newMenuEntries = addKeyBindings(menuEntries);
1848
+ return newMenuEntries;
1849
+ };
1850
+ const getMenuEntriesWithKeyBindings2 = async (uid, menuId, ...args) => {
1851
+ // @ts-ignore
1852
+ const menuEntries = await getMenuEntries2(uid, menuId, ...args);
1853
+ const newMenuEntries = addKeyBindings(menuEntries);
1854
+ return newMenuEntries;
1855
+ };
1856
+
1857
+ const Menu$1 = 'menu';
1858
+ const MenuItem$1 = 'menuitem';
1859
+ const MenuItemCheckBox = 'menuitemcheckbox';
1860
+ const Separator = 'separator';
1861
+
1862
+ const MaskIconCheck = 'MaskIconCheck';
1863
+ const Menu = 'Menu';
1864
+ const MenuItem = 'MenuItem';
1865
+ const MenuItemCheckMark = 'MenuItemCheckMark';
1866
+ const MenuItemCheckmarkIcon = 'MenuItemCheckmarkIcon';
1867
+ const MenuItemFocused = 'MenuItemFocused';
1868
+ const MenuItemKeyBinding = 'MenuItemKeyBinding';
1869
+ const MenuItemSeparator = 'MenuItemSeparator';
1870
+ const MenuItemSeparatorLine = 'MenuItemSeparatorLine';
1871
+ const MenuItemSubMenu = 'MenuItemSubMenu';
1872
+ const MenuItemSubMenuArrowRight = 'MenuItemSubMenuArrowRight';
1873
+
1874
+ const mergeClassNames = (...classNames) => {
1875
+ return classNames.filter(Boolean).join(' ');
1876
+ };
1877
+
1878
+ const text = data => {
2285
1879
  return {
2286
- key,
2287
- isCtrl,
2288
- isShift
1880
+ type: Text,
1881
+ text: data,
1882
+ childCount: 0
2289
1883
  };
2290
1884
  };
2291
1885
 
1886
+ const Div = 4;
1887
+ const Span = 8;
1888
+
1889
+ const checkboxChecked = {
1890
+ type: Div,
1891
+ className: mergeClassNames(MenuItem, MenuItemCheckMark),
1892
+ role: MenuItemCheckBox,
1893
+ ariaChecked: true,
1894
+ tabIndex: -1,
1895
+ childCount: 2
1896
+ };
1897
+ const checkMark = {
1898
+ type: Div,
1899
+ className: mergeClassNames(MenuItemCheckmarkIcon, MaskIconCheck)
1900
+ };
1901
+ const getMenuItemCheckedDom = menuItem => {
1902
+ const {
1903
+ label
1904
+ } = menuItem;
1905
+ return [checkboxChecked, checkMark, text(label)];
1906
+ };
1907
+
1908
+ const getKeyBindingString = (key, altKey, ctrlKey, shiftKey, metaKey) => {
1909
+ let string = '';
1910
+ if (ctrlKey) {
1911
+ string += 'Ctrl+';
1912
+ }
1913
+ if (shiftKey) {
1914
+ string += 'Shift+';
1915
+ }
1916
+ string += key.toUpperCase();
1917
+ return string;
1918
+ };
1919
+
2292
1920
  const getMenuItemDefaultDom = menuItem => {
2293
1921
  const {
2294
1922
  label,
@@ -2457,8 +2085,15 @@ const getVisible = (items, focusedIndex, expanded, level) => {
2457
2085
  return visibleItems;
2458
2086
  };
2459
2087
 
2088
+ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
2460
2089
  // TODO lazyload menuEntries and use Command.execute (maybe)
2461
- const CONTEXT_MENU_WIDTH = 250;
2090
+
2091
+ // TODO difference between focusing with mouse or keyboard
2092
+ // with mouse -> open submenu
2093
+ // with keyboard -> don't open submenu, only focus
2094
+
2095
+ // TODO this code seems a bit too complicated, maybe it can be simplified
2096
+
2462
2097
  const state = {
2463
2098
  menus: []};
2464
2099
  const addMenuInternal = menu => {
@@ -2468,6 +2103,18 @@ const addMenuInternal = menu => {
2468
2103
  state.menus.push(menu);
2469
2104
  return menu;
2470
2105
  };
2106
+ const getCount = () => {
2107
+ return state.menus.length;
2108
+ };
2109
+ const reset = () => {
2110
+ state.menus = [];
2111
+ };
2112
+ const getAll = () => {
2113
+ return state.menus;
2114
+ };
2115
+
2116
+ // TODO lazyload menuEntries and use Command.execute (maybe)
2117
+ const CONTEXT_MENU_WIDTH$1 = 250;
2471
2118
 
2472
2119
  // TODO handle printable letter and focus item that starts with that letter
2473
2120
 
@@ -2475,26 +2122,26 @@ const addMenuInternal = menu => {
2475
2122
 
2476
2123
  // TODO more tests
2477
2124
 
2478
- const CONTEXT_MENU_ITEM_HEIGHT = 26;
2479
- const CONTEXT_MENU_SEPARATOR_HEIGHT = 11;
2480
- const CONTEXT_MENU_PADDING = 8;
2481
- const getMenuHeight = items => {
2482
- let height = CONTEXT_MENU_PADDING;
2125
+ const CONTEXT_MENU_ITEM_HEIGHT$1 = 26;
2126
+ const CONTEXT_MENU_SEPARATOR_HEIGHT$1 = 11;
2127
+ const CONTEXT_MENU_PADDING$1 = 8;
2128
+ const getMenuHeight$1 = items => {
2129
+ let height = CONTEXT_MENU_PADDING$1;
2483
2130
  for (const item of items) {
2484
2131
  switch (item.flags) {
2485
2132
  case Separator$1:
2486
- height += CONTEXT_MENU_SEPARATOR_HEIGHT;
2133
+ height += CONTEXT_MENU_SEPARATOR_HEIGHT$1;
2487
2134
  break;
2488
2135
  default:
2489
- height += CONTEXT_MENU_ITEM_HEIGHT;
2136
+ height += CONTEXT_MENU_ITEM_HEIGHT$1;
2490
2137
  break;
2491
2138
  }
2492
2139
  }
2493
2140
  return height;
2494
2141
  };
2495
- const getMenuBounds = (x, y, items) => {
2496
- const menuWidth = CONTEXT_MENU_WIDTH;
2497
- const menuHeight = getMenuHeight(items);
2142
+ const getMenuBounds$1 = (x, y, items) => {
2143
+ const menuWidth = CONTEXT_MENU_WIDTH$1;
2144
+ const menuHeight = getMenuHeight$1(items);
2498
2145
  const layoutState = {
2499
2146
  points: [0, 0]
2500
2147
  };
@@ -2518,40 +2165,40 @@ const getMenuBounds = (x, y, items) => {
2518
2165
  };
2519
2166
  const show$2 = async (x, y, id, mouseBlocking = false, ...args) => {
2520
2167
  const items = await getMenuEntriesWithKeyBindings(id, ...args);
2521
- const bounds = getMenuBounds(x, y, items);
2168
+ const bounds = getMenuBounds$1(x, y, items);
2522
2169
  const menu = addMenuInternal({
2523
2170
  id,
2524
2171
  items,
2525
2172
  focusedIndex: -1,
2526
- level: state.menus.length,
2173
+ level: getCount(),
2527
2174
  x: bounds.x,
2528
2175
  y: bounds.y
2529
2176
  });
2530
2177
  const visible = getVisible(menu.items, -1, false, menu.level);
2531
2178
  const dom = getMenuVirtualDom(visible).slice(1);
2532
- await invoke$1(/* Menu.show */'Menu.showMenu', /* x */bounds.x, /* y */bounds.y, /* width */bounds.width, /* height */bounds.height, /* items */menu.items, /* level */menu.level, /* parentIndex */-1, /* dom */dom, /* mouseBlocking */mouseBlocking);
2179
+ await invoke(/* Menu.show */'Menu.showMenu', /* x */bounds.x, /* y */bounds.y, /* width */bounds.width, /* height */bounds.height, /* items */menu.items, /* level */menu.level, /* parentIndex */-1, /* dom */dom, /* mouseBlocking */mouseBlocking);
2533
2180
  };
2534
2181
  const show2$2 = async (uid, menuId, x, y, mouseBlocking = false, ...args) => {
2535
2182
  const items = await getMenuEntriesWithKeyBindings2(uid, menuId, ...args);
2536
- const bounds = getMenuBounds(x, y, items);
2183
+ const bounds = getMenuBounds$1(x, y, items);
2537
2184
  const menu = addMenuInternal({
2538
2185
  id: menuId,
2539
2186
  items,
2540
2187
  focusedIndex: -1,
2541
- level: state.menus.length,
2188
+ level: getCount(),
2542
2189
  x: bounds.x,
2543
2190
  y: bounds.y
2544
2191
  });
2545
2192
  const visible = getVisible(menu.items, -1, false, menu.level);
2546
2193
  const dom = getMenuVirtualDom(visible).slice(1);
2547
- await invoke$1(/* Menu.show */'Menu.showMenu', /* x */bounds.x, /* y */bounds.y, /* width */bounds.width, /* height */bounds.height, /* items */menu.items, /* level */menu.level, /* parentIndex */-1, /* dom */dom, /* mouseBlocking */mouseBlocking);
2194
+ await invoke(/* Menu.show */'Menu.showMenu', /* x */bounds.x, /* y */bounds.y, /* width */bounds.width, /* height */bounds.height, /* items */menu.items, /* level */menu.level, /* parentIndex */-1, /* dom */dom, /* mouseBlocking */mouseBlocking);
2548
2195
  };
2549
2196
  const hide = async (restoreFocus = true) => {
2550
- if (state.menus.length === 0) {
2197
+ if (getCount() === 0) {
2551
2198
  return;
2552
2199
  }
2553
- state.menus = [];
2554
- await invoke$1(/* Menu.hide */'Menu.hide', /* restoreFocus */restoreFocus);
2200
+ reset();
2201
+ await invoke(/* Menu.hide */'Menu.hide', /* restoreFocus */restoreFocus);
2555
2202
  };
2556
2203
 
2557
2204
  const show$1 = async (x, y, id, ...args) => {
@@ -2670,40 +2317,54 @@ const FocusTitleBarMenuBar = 26;
2670
2317
 
2671
2318
  const getKeyBindings = () => {
2672
2319
  return [{
2673
- key: DownArrow$2,
2320
+ key: DownArrow$1,
2674
2321
  command: 'TitleBarMenuBar.handleKeyArrowDown',
2675
2322
  when: FocusTitleBarMenuBar
2676
2323
  }, {
2677
- key: UpArrow$2,
2324
+ key: UpArrow$1,
2678
2325
  command: 'TitleBarMenuBar.handleKeyArrowUp',
2679
2326
  when: FocusTitleBarMenuBar
2680
2327
  }, {
2681
- key: RightArrow$2,
2328
+ key: RightArrow$1,
2682
2329
  command: 'TitleBarMenuBar.handleKeyArrowRight',
2683
2330
  when: FocusTitleBarMenuBar
2684
2331
  }, {
2685
- key: LeftArrow$2,
2332
+ key: LeftArrow$1,
2686
2333
  command: 'TitleBarMenuBar.handleKeyArrowLeft',
2687
2334
  when: FocusTitleBarMenuBar
2688
2335
  }, {
2689
- key: Space$2,
2336
+ key: Space$1,
2690
2337
  command: 'TitleBarMenuBar.handleKeySpace',
2691
2338
  when: FocusTitleBarMenuBar
2692
2339
  }, {
2693
- key: Home$2,
2340
+ key: Home$1,
2694
2341
  command: 'TitleBarMenuBar.handleKeyHome',
2695
2342
  when: FocusTitleBarMenuBar
2696
2343
  }, {
2697
- key: End$2,
2344
+ key: End$1,
2698
2345
  command: 'TitleBarMenuBar.handleKeyEnd',
2699
2346
  when: FocusTitleBarMenuBar
2700
2347
  }, {
2701
- key: Escape$2,
2348
+ key: Escape$1,
2702
2349
  command: 'TitleBarMenuBar.handleKeyEscape',
2703
2350
  when: FocusTitleBarMenuBar
2704
2351
  }];
2705
2352
  };
2706
2353
 
2354
+ const getMenuHideCommands = async (restoreFocus = true) => {
2355
+ if (getCount() === 0) {
2356
+ return {
2357
+ newMenus: [],
2358
+ commands: []
2359
+ };
2360
+ }
2361
+ reset();
2362
+ return {
2363
+ commands: [/* Menu.hide */'Menu.hide', /* restoreFocus */restoreFocus],
2364
+ newMenus: []
2365
+ };
2366
+ };
2367
+
2707
2368
  const menus = [MenuEntriesEdit, MenuEntriesFile, MenuEntriesGo, MenuEntriesHelp, MenuEntriesRun, MenuEntriesSelection, MenuEntriesTerminal, MenuEntriesTitleBar, MenuEntriesView, MenuEntriesOpenRecent];
2708
2369
 
2709
2370
  const getMenuIds = () => {
@@ -2717,46 +2378,79 @@ const getMenuEntries = (id, platform) => {
2717
2378
  return menu.getMenuEntries(platform);
2718
2379
  };
2719
2380
 
2720
- const {
2721
- invoke} = RendererWorker;
2381
+ // TODO lazyload menuEntries and use Command.execute (maybe)
2382
+ const CONTEXT_MENU_WIDTH = 250;
2722
2383
 
2723
- const maximize = async () => {
2724
- await invoke('ElectronWindow.maximize');
2725
- };
2726
- const minimize = async () => {
2727
- await invoke('ElectronWindow.minimize');
2728
- };
2729
- const close = async () => {
2730
- await invoke('ElectronWindow.close');
2731
- };
2384
+ // TODO difference between focusing with mouse or keyboard
2385
+ // with mouse -> open submenu
2386
+ // with keyboard -> don't open submenu, only focus
2732
2387
 
2733
- const handleClickClose = async state => {
2734
- await close();
2735
- return state;
2736
- };
2388
+ // TODO this code seems a bit too complicated, maybe it can be simplified
2737
2389
 
2738
- const handleClickMinimize = async state => {
2739
- await minimize();
2740
- return state;
2741
- };
2390
+ // TODO handle printable letter and focus item that starts with that letter
2742
2391
 
2743
- const handleClickToggleMaximize = async state => {
2744
- const fn = maximize;
2745
- await fn();
2746
- return state;
2747
- };
2392
+ // TODO pageup / pagedown keys
2393
+
2394
+ // TODO more tests
2748
2395
 
2749
- const handleClick = (state, className) => {
2750
- if (className.includes('Minimize')) {
2751
- return handleClickMinimize(state);
2396
+ const CONTEXT_MENU_ITEM_HEIGHT = 26;
2397
+ const CONTEXT_MENU_SEPARATOR_HEIGHT = 11;
2398
+ const CONTEXT_MENU_PADDING = 8;
2399
+ const getMenuHeight = items => {
2400
+ let height = CONTEXT_MENU_PADDING;
2401
+ for (const item of items) {
2402
+ switch (item.flags) {
2403
+ case Separator$1:
2404
+ height += CONTEXT_MENU_SEPARATOR_HEIGHT;
2405
+ break;
2406
+ default:
2407
+ height += CONTEXT_MENU_ITEM_HEIGHT;
2408
+ break;
2409
+ }
2752
2410
  }
2753
- if (className.includes('Maximize') || className.includes('Restore')) {
2754
- return handleClickToggleMaximize(state);
2411
+ return height;
2412
+ };
2413
+ const getMenuBounds = (x, y, items) => {
2414
+ const menuWidth = CONTEXT_MENU_WIDTH;
2415
+ const menuHeight = getMenuHeight(items);
2416
+ const layoutState = {
2417
+ points: [0, 0]
2418
+ };
2419
+ const windowWidth = layoutState.points[0];
2420
+ const windowHeight = layoutState.points[1];
2421
+ // TODO maybe only send labels and keybindings to ui (id not needed on ui)
2422
+ // TODO what about separators?
2423
+
2424
+ if (x + menuWidth > windowWidth) {
2425
+ x -= menuWidth;
2755
2426
  }
2756
- if (className.includes('Close')) {
2757
- return handleClickClose(state);
2427
+ if (y + menuHeight > windowHeight) {
2428
+ y -= menuHeight;
2758
2429
  }
2759
- return state;
2430
+ return {
2431
+ x,
2432
+ y,
2433
+ width: menuWidth,
2434
+ height: menuHeight
2435
+ };
2436
+ };
2437
+ const getMenuShowCommands = async (items, menuId, x, y, mouseBlocking = false) => {
2438
+ const bounds = getMenuBounds(x, y, items);
2439
+ const menu = addMenuInternal({
2440
+ id: menuId,
2441
+ items,
2442
+ focusedIndex: -1,
2443
+ level: getCount(),
2444
+ x: bounds.x,
2445
+ y: bounds.y
2446
+ });
2447
+ const visible = getVisible(menu.items, -1, false, menu.level);
2448
+ const dom = getMenuVirtualDom(visible).slice(1);
2449
+ return {
2450
+ menus: getAll(),
2451
+ menu,
2452
+ commands: [/* Menu.show */'Menu.showMenu', /* x */bounds.x, /* y */bounds.y, /* width */bounds.width, /* height */bounds.height, /* items */menu.items, /* level */menu.level, /* parentIndex */-1, /* dom */dom, /* mouseBlocking */mouseBlocking]
2453
+ };
2760
2454
  };
2761
2455
 
2762
2456
  const handleContextMenu = state => {
@@ -2892,7 +2586,6 @@ const wrapCommand = fn => {
2892
2586
  const commandMap = {
2893
2587
  'Menu.getMenuEntries': getMenuEntries,
2894
2588
  'Menu.getMenuIds': getMenuIds,
2895
- 'Menu.handleButtonsClick': handleClick,
2896
2589
  'Menu.handleContextMenu': handleContextMenu,
2897
2590
  'Menu.renderEventListeners': renderEventListeners,
2898
2591
  'Menu.diff2': diff2,
@@ -2903,7 +2596,9 @@ const commandMap = {
2903
2596
  'Menu.render2': render2,
2904
2597
  'Menu.saveState': saveState,
2905
2598
  'Menu.show': show,
2906
- 'Menu.show2': show2
2599
+ 'Menu.show2': show2,
2600
+ 'Menu.getShowCommands': getMenuShowCommands,
2601
+ 'Menu.getHideCommands': getMenuHideCommands
2907
2602
  };
2908
2603
 
2909
2604
  const listen = async () => {