@lvce-editor/menu-worker 1.7.0 → 2.1.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$2 = (ipc, method, ...params) => {
788
+ const invoke$4 = (ipc, method, ...params) => {
789
789
  return invokeHelper(ipc, method, params, false);
790
790
  };
791
- const invokeAndTransfer = (ipc, method, ...params) => {
791
+ const invokeAndTransfer$1 = (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$2(ipc, method, ...params);
827
+ return invoke$4(ipc, method, ...params);
828
828
  },
829
829
  invokeAndTransfer(method, ...params) {
830
- return invokeAndTransfer(ipc, method, ...params);
830
+ return invokeAndTransfer$1(ipc, method, ...params);
831
831
  },
832
832
  async dispose() {
833
833
  await ipc?.dispose();
@@ -879,6 +879,25 @@ 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
+ };
882
901
 
883
902
  const Text = 12;
884
903
 
@@ -1148,11 +1167,17 @@ const getKeyCodeString = keyCode => {
1148
1167
  }
1149
1168
  };
1150
1169
 
1170
+ const Script = 2;
1171
+
1151
1172
  const CtrlCmd = 1 << 11 >>> 0;
1152
1173
  const Shift = 1 << 10 >>> 0;
1153
1174
 
1154
1175
  const Separator$2 = 1;
1176
+ const None$1 = 0;
1177
+ const SubMenu$1 = 4;
1155
1178
  const Disabled$1 = 5;
1179
+ const RestoreFocus$1 = 6;
1180
+ const Ignore$1 = 7;
1156
1181
 
1157
1182
  const parseKey = rawKey => {
1158
1183
  const isCtrl = Boolean(rawKey & CtrlCmd);
@@ -1166,7 +1191,9 @@ const parseKey = rawKey => {
1166
1191
  };
1167
1192
  };
1168
1193
 
1169
- const RendererWorker = 1;
1194
+ const DebugWorker = 55;
1195
+ const RendererProcess = 1670;
1196
+ const RendererWorker$1 = 1;
1170
1197
 
1171
1198
  const rpcs = Object.create(null);
1172
1199
  const set$3 = (id, rpc) => {
@@ -1201,8 +1228,435 @@ const create$1 = rpcId => {
1201
1228
  };
1202
1229
 
1203
1230
  const {
1204
- invoke: invoke$1,
1205
- set: set$2} = create$1(RendererWorker);
1231
+ invoke: invoke$3} = create$1(RendererProcess);
1232
+
1233
+ const {
1234
+ invoke: invoke$2,
1235
+ invokeAndTransfer,
1236
+ set: set$2,
1237
+ dispose
1238
+ } = create$1(RendererWorker$1);
1239
+ const searchFileHtml = async uri => {
1240
+ return invoke$2('ExtensionHost.searchFileWithHtml', uri);
1241
+ };
1242
+ const getFilePathElectron = async file => {
1243
+ return invoke$2('FileSystemHandle.getFilePathElectron', file);
1244
+ };
1245
+ const showContextMenu = async (x, y, id, ...args) => {
1246
+ return invoke$2('ContextMenu.show', x, y, id, ...args);
1247
+ };
1248
+ const showContextMenu2 = async (uid, menuId, x, y, args) => {
1249
+ number(uid);
1250
+ number(menuId);
1251
+ number(x);
1252
+ number(y);
1253
+ // @ts-ignore
1254
+ await invoke$2('ContextMenu.show2', uid, menuId, x, y, args);
1255
+ };
1256
+ const getElectronVersion = async () => {
1257
+ return invoke$2('Process.getElectronVersion');
1258
+ };
1259
+ const applyBulkReplacement = async bulkEdits => {
1260
+ await invoke$2('BulkReplacement.applyBulkReplacement', bulkEdits);
1261
+ };
1262
+ const setColorTheme = async id => {
1263
+ // @ts-ignore
1264
+ return invoke$2(/* ColorTheme.setColorTheme */'ColorTheme.setColorTheme', /* colorThemeId */id);
1265
+ };
1266
+ const getNodeVersion = async () => {
1267
+ return invoke$2('Process.getNodeVersion');
1268
+ };
1269
+ const getChromeVersion = async () => {
1270
+ return invoke$2('Process.getChromeVersion');
1271
+ };
1272
+ const getV8Version = async () => {
1273
+ return invoke$2('Process.getV8Version');
1274
+ };
1275
+ const getFileHandles = async fileIds => {
1276
+ const files = await invoke$2('FileSystemHandle.getFileHandles', fileIds);
1277
+ return files;
1278
+ };
1279
+ const setWorkspacePath = async path => {
1280
+ await invoke$2('Workspace.setPath', path);
1281
+ };
1282
+ const registerWebViewInterceptor = async (id, port) => {
1283
+ await invokeAndTransfer('WebView.registerInterceptor', id, port);
1284
+ };
1285
+ const unregisterWebViewInterceptor = async id => {
1286
+ await invoke$2('WebView.unregisterInterceptor', id);
1287
+ };
1288
+ const sendMessagePortToEditorWorker = async (port, rpcId) => {
1289
+ const command = 'HandleMessagePort.handleMessagePort';
1290
+ // @ts-ignore
1291
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToEditorWorker', port, command, rpcId);
1292
+ };
1293
+ const sendMessagePortToErrorWorker = async (port, rpcId) => {
1294
+ const command = 'Errors.handleMessagePort';
1295
+ // @ts-ignore
1296
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToErrorWorker', port, command, rpcId);
1297
+ };
1298
+ const sendMessagePortToMarkdownWorker = async (port, rpcId) => {
1299
+ const command = 'Markdown.handleMessagePort';
1300
+ // @ts-ignore
1301
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToMarkdownWorker', port, command, rpcId);
1302
+ };
1303
+ const sendMessagePortToIconThemeWorker = async (port, rpcId) => {
1304
+ const command = 'IconTheme.handleMessagePort';
1305
+ // @ts-ignore
1306
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToIconThemeWorker', port, command, rpcId);
1307
+ };
1308
+ const sendMessagePortToFileSystemWorker = async (port, rpcId) => {
1309
+ const command = 'FileSystem.handleMessagePort';
1310
+ // @ts-ignore
1311
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToFileSystemWorker', port, command, rpcId);
1312
+ };
1313
+ const readFile = async uri => {
1314
+ return invoke$2('FileSystem.readFile', uri);
1315
+ };
1316
+ const getWebViewSecret = async key => {
1317
+ // @ts-ignore
1318
+ return invoke$2('WebView.getSecret', key);
1319
+ };
1320
+ const setWebViewPort = async (uid, port, origin, portType) => {
1321
+ return invokeAndTransfer('WebView.setPort', uid, port, origin, portType);
1322
+ };
1323
+ const setFocus = key => {
1324
+ return invoke$2('Focus.setFocus', key);
1325
+ };
1326
+ const getFileIcon = async options => {
1327
+ return invoke$2('IconTheme.getFileIcon', options);
1328
+ };
1329
+ const getColorThemeNames = async () => {
1330
+ return invoke$2('ColorTheme.getColorThemeNames');
1331
+ };
1332
+ const disableExtension = async id => {
1333
+ // @ts-ignore
1334
+ return invoke$2('ExtensionManagement.disable', id);
1335
+ };
1336
+ const enableExtension = async id => {
1337
+ // @ts-ignore
1338
+ return invoke$2('ExtensionManagement.enable', id);
1339
+ };
1340
+ const handleDebugChange = async params => {
1341
+ // @ts-ignore
1342
+ return invoke$2('Run And Debug.handleChange', params);
1343
+ };
1344
+ const getFolderIcon = async options => {
1345
+ return invoke$2('IconTheme.getFolderIcon', options);
1346
+ };
1347
+ const closeWidget = async widgetId => {
1348
+ return invoke$2('Viewlet.closeWidget', widgetId);
1349
+ };
1350
+ const sendMessagePortToExtensionHostWorker = async (port, rpcId = 0) => {
1351
+ const command = 'HandleMessagePort.handleMessagePort2';
1352
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, rpcId);
1353
+ };
1354
+ const sendMessagePortToSearchProcess = async port => {
1355
+ await invokeAndTransfer('SendMessagePortToElectron.sendMessagePortToElectron', port, 'HandleMessagePortForSearchProcess.handleMessagePortForSearchProcess');
1356
+ };
1357
+ const confirm = async (message, options) => {
1358
+ // @ts-ignore
1359
+ const result = await invoke$2('ConfirmPrompt.prompt', message, options);
1360
+ return result;
1361
+ };
1362
+ const getRecentlyOpened$1 = async () => {
1363
+ return invoke$2(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
1364
+ };
1365
+ const getKeyBindings$1 = async () => {
1366
+ return invoke$2('KeyBindingsInitial.getKeyBindings');
1367
+ };
1368
+ const writeClipBoardText = async text => {
1369
+ await invoke$2('ClipBoard.writeText', /* text */text);
1370
+ };
1371
+ const readClipBoardText = async () => {
1372
+ return invoke$2('ClipBoard.readText');
1373
+ };
1374
+ const writeClipBoardImage = async blob => {
1375
+ // @ts-ignore
1376
+ await invoke$2('ClipBoard.writeImage', /* text */blob);
1377
+ };
1378
+ const searchFileMemory = async uri => {
1379
+ // @ts-ignore
1380
+ return invoke$2('ExtensionHost.searchFileWithMemory', uri);
1381
+ };
1382
+ const searchFileFetch = async uri => {
1383
+ return invoke$2('ExtensionHost.searchFileWithFetch', uri);
1384
+ };
1385
+ const showMessageBox = async options => {
1386
+ return invoke$2('ElectronDialog.showMessageBox', options);
1387
+ };
1388
+ const handleDebugResumed = async params => {
1389
+ await invoke$2('Run And Debug.handleResumed', params);
1390
+ };
1391
+ const openWidget = async name => {
1392
+ await invoke$2('Viewlet.openWidget', name);
1393
+ };
1394
+ const getIcons = async requests => {
1395
+ const icons = await invoke$2('IconTheme.getIcons', requests);
1396
+ return icons;
1397
+ };
1398
+ const activateByEvent = event => {
1399
+ return invoke$2('ExtensionHostManagement.activateByEvent', event);
1400
+ };
1401
+ const setAdditionalFocus = focusKey => {
1402
+ // @ts-ignore
1403
+ return invoke$2('Focus.setAdditionalFocus', focusKey);
1404
+ };
1405
+ const getActiveEditorId = () => {
1406
+ // @ts-ignore
1407
+ return invoke$2('GetActiveEditor.getActiveEditorId');
1408
+ };
1409
+ const getWorkspacePath = () => {
1410
+ return invoke$2('Workspace.getPath');
1411
+ };
1412
+ const sendMessagePortToRendererProcess = async port => {
1413
+ const command = 'HandleMessagePort.handleMessagePort';
1414
+ // @ts-ignore
1415
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToRendererProcess', port, command, DebugWorker);
1416
+ };
1417
+ const sendMessagePortToTextMeasurementWorker = async port => {
1418
+ const command = 'TextMeasurement.handleMessagePort';
1419
+ // @ts-ignore
1420
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToTextMeasurementWorker', port, command, 0);
1421
+ };
1422
+ const sendMessagePortToSourceControlWorker = async port => {
1423
+ const command = 'SourceControl.handleMessagePort';
1424
+ // @ts-ignore
1425
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToSourceControlWorker', port, command, 0);
1426
+ };
1427
+ const getPreference = async key => {
1428
+ return await invoke$2('Preferences.get', key);
1429
+ };
1430
+ const getAllExtensions = async () => {
1431
+ return invoke$2('ExtensionManagement.getAllExtensions');
1432
+ };
1433
+ const rerenderEditor = async key => {
1434
+ // @ts-ignore
1435
+ return invoke$2('Editor.rerender', key);
1436
+ };
1437
+ const handleDebugPaused = async params => {
1438
+ await invoke$2('Run And Debug.handlePaused', params);
1439
+ };
1440
+ const openUri = async (uri, focus, options) => {
1441
+ await invoke$2('Main.openUri', uri, focus, options);
1442
+ };
1443
+ const sendMessagePortToSyntaxHighlightingWorker = async port => {
1444
+ await invokeAndTransfer(
1445
+ // @ts-ignore
1446
+ 'SendMessagePortToSyntaxHighlightingWorker.sendMessagePortToSyntaxHighlightingWorker', port, 'HandleMessagePort.handleMessagePort2');
1447
+ };
1448
+ const handleDebugScriptParsed = async script => {
1449
+ await invoke$2('Run And Debug.handleScriptParsed', script);
1450
+ };
1451
+ const getWindowId = async () => {
1452
+ return invoke$2('GetWindowId.getWindowId');
1453
+ };
1454
+ const getBlob = async uri => {
1455
+ // @ts-ignore
1456
+ return invoke$2('FileSystem.getBlob', uri);
1457
+ };
1458
+ const getExtensionCommands = async () => {
1459
+ return invoke$2('ExtensionHost.getCommands');
1460
+ };
1461
+ const showErrorDialog = async errorInfo => {
1462
+ // @ts-ignore
1463
+ await invoke$2('ErrorHandling.showErrorDialog', errorInfo);
1464
+ };
1465
+ const getFolderSize = async uri => {
1466
+ // @ts-ignore
1467
+ return await invoke$2('FileSystem.getFolderSize', uri);
1468
+ };
1469
+ const getExtension = async id => {
1470
+ // @ts-ignore
1471
+ return invoke$2('ExtensionManagement.getExtension', id);
1472
+ };
1473
+ const getMarkdownDom = async html => {
1474
+ // @ts-ignore
1475
+ return invoke$2('Markdown.getVirtualDom', html);
1476
+ };
1477
+ const renderMarkdown = async (markdown, options) => {
1478
+ // @ts-ignore
1479
+ return invoke$2('Markdown.renderMarkdown', markdown, options);
1480
+ };
1481
+ const openNativeFolder = async uri => {
1482
+ // @ts-ignore
1483
+ await invoke$2('OpenNativeFolder.openNativeFolder', uri);
1484
+ };
1485
+ const uninstallExtension = async id => {
1486
+ return invoke$2('ExtensionManagement.uninstall', id);
1487
+ };
1488
+ const installExtension = async id => {
1489
+ // @ts-ignore
1490
+ return invoke$2('ExtensionManagement.install', id);
1491
+ };
1492
+ const openExtensionSearch = async () => {
1493
+ // @ts-ignore
1494
+ return invoke$2('SideBar.openViewlet', 'Extensions');
1495
+ };
1496
+ const setExtensionsSearchValue = async searchValue => {
1497
+ // @ts-ignore
1498
+ return invoke$2('Extensions.handleInput', searchValue, Script);
1499
+ };
1500
+ const openExternal = async uri => {
1501
+ // @ts-ignore
1502
+ await invoke$2('Open.openExternal', uri);
1503
+ };
1504
+ const openUrl = async uri => {
1505
+ // @ts-ignore
1506
+ await invoke$2('Open.openUrl', uri);
1507
+ };
1508
+ const getAllPreferences = async () => {
1509
+ // @ts-ignore
1510
+ return invoke$2('Preferences.getAll');
1511
+ };
1512
+ const showSaveFilePicker = async () => {
1513
+ // @ts-ignore
1514
+ return invoke$2('FilePicker.showSaveFilePicker');
1515
+ };
1516
+ const getLogsDir = async () => {
1517
+ // @ts-ignore
1518
+ return invoke$2('PlatformPaths.getLogsDir');
1519
+ };
1520
+ const registerMockRpc = commandMap => {
1521
+ const mockRpc = createMockRpc({
1522
+ commandMap
1523
+ });
1524
+ set$2(mockRpc);
1525
+ return mockRpc;
1526
+ };
1527
+
1528
+ const RendererWorker = {
1529
+ __proto__: null,
1530
+ activateByEvent,
1531
+ applyBulkReplacement,
1532
+ closeWidget,
1533
+ confirm,
1534
+ disableExtension,
1535
+ dispose,
1536
+ enableExtension,
1537
+ getActiveEditorId,
1538
+ getAllExtensions,
1539
+ getAllPreferences,
1540
+ getBlob,
1541
+ getChromeVersion,
1542
+ getColorThemeNames,
1543
+ getElectronVersion,
1544
+ getExtension,
1545
+ getExtensionCommands,
1546
+ getFileHandles,
1547
+ getFileIcon,
1548
+ getFilePathElectron,
1549
+ getFolderIcon,
1550
+ getFolderSize,
1551
+ getIcons,
1552
+ getKeyBindings: getKeyBindings$1,
1553
+ getLogsDir,
1554
+ getMarkdownDom,
1555
+ getNodeVersion,
1556
+ getPreference,
1557
+ getRecentlyOpened: getRecentlyOpened$1,
1558
+ getV8Version,
1559
+ getWebViewSecret,
1560
+ getWindowId,
1561
+ getWorkspacePath,
1562
+ handleDebugChange,
1563
+ handleDebugPaused,
1564
+ handleDebugResumed,
1565
+ handleDebugScriptParsed,
1566
+ installExtension,
1567
+ invoke: invoke$2,
1568
+ invokeAndTransfer,
1569
+ openExtensionSearch,
1570
+ openExternal,
1571
+ openNativeFolder,
1572
+ openUri,
1573
+ openUrl,
1574
+ openWidget,
1575
+ readClipBoardText,
1576
+ readFile,
1577
+ registerMockRpc,
1578
+ registerWebViewInterceptor,
1579
+ renderMarkdown,
1580
+ rerenderEditor,
1581
+ searchFileFetch,
1582
+ searchFileHtml,
1583
+ searchFileMemory,
1584
+ sendMessagePortToEditorWorker,
1585
+ sendMessagePortToErrorWorker,
1586
+ sendMessagePortToExtensionHostWorker,
1587
+ sendMessagePortToFileSystemWorker,
1588
+ sendMessagePortToIconThemeWorker,
1589
+ sendMessagePortToMarkdownWorker,
1590
+ sendMessagePortToRendererProcess,
1591
+ sendMessagePortToSearchProcess,
1592
+ sendMessagePortToSourceControlWorker,
1593
+ sendMessagePortToSyntaxHighlightingWorker,
1594
+ sendMessagePortToTextMeasurementWorker,
1595
+ set: set$2,
1596
+ setAdditionalFocus,
1597
+ setColorTheme,
1598
+ setExtensionsSearchValue,
1599
+ setFocus,
1600
+ setWebViewPort,
1601
+ setWorkspacePath,
1602
+ showContextMenu,
1603
+ showContextMenu2,
1604
+ showErrorDialog,
1605
+ showMessageBox,
1606
+ showSaveFilePicker,
1607
+ uninstallExtension,
1608
+ unregisterWebViewInterceptor,
1609
+ writeClipBoardImage,
1610
+ writeClipBoardText
1611
+ };
1612
+
1613
+ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
1614
+ // TODO lazyload menuEntries and use Command.execute (maybe)
1615
+
1616
+ // TODO difference between focusing with mouse or keyboard
1617
+ // with mouse -> open submenu
1618
+ // with keyboard -> don't open submenu, only focus
1619
+
1620
+ // TODO this code seems a bit too complicated, maybe it can be simplified
1621
+
1622
+ const state$1 = {
1623
+ menus: [],
1624
+ latestTimeStamp: 0};
1625
+ const addMenuInternal = menu => {
1626
+ if (state$1.menus.length > 5) {
1627
+ throw new Error('too many menus');
1628
+ }
1629
+ state$1.menus.push(menu);
1630
+ return menu;
1631
+ };
1632
+ const getCount = () => {
1633
+ return state$1.menus.length;
1634
+ };
1635
+ const reset = () => {
1636
+ state$1.menus = [];
1637
+ };
1638
+ const get$1 = index => {
1639
+ return state$1.menus[index];
1640
+ };
1641
+ const set$1 = menus => {
1642
+ state$1.menus = menus;
1643
+ };
1644
+ const getAll = () => {
1645
+ return state$1.menus;
1646
+ };
1647
+ const setTimestamp = timestamp => {
1648
+ state$1.latestTimeStamp = timestamp;
1649
+ };
1650
+ const getLatestTimestamp = () => {
1651
+ return state$1.latestTimeStamp;
1652
+ };
1653
+
1654
+ const closeSubMenu = async () => {
1655
+ const menus = getAll();
1656
+ const parentMenu = menus.at(-1);
1657
+ // @ts-ignore
1658
+ await invoke$3(/* Menu.hideSubMenu */7903, /* parentIndex */parentMenu.focusedIndex);
1659
+ };
1206
1660
 
1207
1661
  const matchesArgs = (a, b) => {
1208
1662
  if (!a && !b) {
@@ -1235,11 +1689,12 @@ const warn = (...args) => {
1235
1689
  console.warn(...args);
1236
1690
  };
1237
1691
 
1238
- const invoke = async (method, ...params) => {
1239
- // TODO
1692
+ const invoke$1 = async (method, ...params) => {
1693
+ // @ts-ignore
1694
+ await invoke$2('WebView.compatRendererProcessInvoke', method, ...params);
1240
1695
  };
1241
1696
 
1242
- const state$1 = {
1697
+ const state = {
1243
1698
  /**
1244
1699
  * @type {any}
1245
1700
  */
@@ -1322,6 +1777,13 @@ const Terminal$1 = 14;
1322
1777
  const TitleBar = 15;
1323
1778
  const View$1 = 16;
1324
1779
 
1780
+ const menuEntrySeparator = {
1781
+ id: 'separator',
1782
+ label: '',
1783
+ flags: Separator$2,
1784
+ command: ''
1785
+ };
1786
+
1325
1787
  const Separator$1 = 1;
1326
1788
  const None = 0;
1327
1789
  const SubMenu = 4;
@@ -1331,13 +1793,6 @@ const Disabled = 5;
1331
1793
  const RestoreFocus = 6;
1332
1794
  const Ignore = 7;
1333
1795
 
1334
- const menuEntrySeparator = {
1335
- id: 'separator',
1336
- label: '',
1337
- flags: Separator$1,
1338
- command: ''
1339
- };
1340
-
1341
1796
  const id$9 = Edit$1;
1342
1797
  const getMenuEntries$d = () => {
1343
1798
  return [{
@@ -1548,7 +2003,7 @@ const MenuEntriesHelp = {
1548
2003
  };
1549
2004
 
1550
2005
  const getRecentlyOpened = () => {
1551
- return invoke$1(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
2006
+ return invoke$2(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
1552
2007
  };
1553
2008
 
1554
2009
  const File = 'file://';
@@ -1807,37 +2262,17 @@ const menus$1 = [MenuEntriesEdit, MenuEntriesFile, MenuEntriesGo, MenuEntriesHel
1807
2262
  const getMenus = () => {
1808
2263
  return menus$1;
1809
2264
  };
1810
- const getModule$1 = id => {
1811
- for (const module of menus$1) {
1812
- if (module.id === id) {
1813
- return module;
1814
- }
1815
- }
1816
- return undefined;
1817
- };
1818
2265
  const getMenuEntries$1 = async (id, ...args) => {
1819
- try {
1820
- const module = getModule$1(id);
1821
- // @ts-ignore
1822
- const inject = module.inject || [];
1823
- // @ts-ignore
1824
- return module.getMenuEntries(...args);
1825
- } catch (error) {
1826
- throw new VError(error, `Failed to load menu entries for id ${id}`);
1827
- }
2266
+ // @ts-ignore
2267
+ return invoke$2('Menu.getMenuEntries', id, ...args);
1828
2268
  };
1829
2269
  const getMenuEntries2 = async (uid, menuId, ...args) => {
1830
- try {
1831
- const module = await getModule$1(menuId);
1832
- // @ts-ignore
1833
- return module.getMenuEntries(uid, ...args);
1834
- } catch (error) {
1835
- throw new VError(error, `Failed to load menu entries for id ${menuId}`);
1836
- }
2270
+ // @ts-ignore
2271
+ return invoke$2('Menu.getMenuEntries2', uid, menuId, ...args);
1837
2272
  };
1838
2273
 
1839
2274
  const addKeyBindings = menuEntries => {
1840
- const keyBindings = state$1.matchingKeyBindings;
2275
+ const keyBindings = state.matchingKeyBindings;
1841
2276
  const newMenuEntries = [];
1842
2277
  for (const menuEntry of menuEntries) {
1843
2278
  const keyBinding = getCommandKeyBinding(keyBindings, menuEntry.command, menuEntry.args);
@@ -2093,47 +2528,6 @@ const getVisible = (items, focusedIndex, expanded, level) => {
2093
2528
  return visibleItems;
2094
2529
  };
2095
2530
 
2096
- /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
2097
- // TODO lazyload menuEntries and use Command.execute (maybe)
2098
-
2099
- // TODO difference between focusing with mouse or keyboard
2100
- // with mouse -> open submenu
2101
- // with keyboard -> don't open submenu, only focus
2102
-
2103
- // TODO this code seems a bit too complicated, maybe it can be simplified
2104
-
2105
- const state = {
2106
- menus: [],
2107
- latestTimeStamp: 0};
2108
- const addMenuInternal = menu => {
2109
- if (state.menus.length > 5) {
2110
- throw new Error('too many menus');
2111
- }
2112
- state.menus.push(menu);
2113
- return menu;
2114
- };
2115
- const getCount = () => {
2116
- return state.menus.length;
2117
- };
2118
- const reset = () => {
2119
- state.menus = [];
2120
- };
2121
- const get$1 = index => {
2122
- return state.menus[index];
2123
- };
2124
- const set$1 = menus => {
2125
- state.menus = menus;
2126
- };
2127
- const getAll = () => {
2128
- return state.menus;
2129
- };
2130
- const setTimestamp = timestamp => {
2131
- state.latestTimeStamp = timestamp;
2132
- };
2133
- const getLatestTimestamp = () => {
2134
- return state.latestTimeStamp;
2135
- };
2136
-
2137
2531
  // TODO lazyload menuEntries and use Command.execute (maybe)
2138
2532
  const CONTEXT_MENU_ITEM_HEIGHT$2 = 26;
2139
2533
  const CONTEXT_MENU_SEPARATOR_HEIGHT$2 = 11;
@@ -2160,6 +2554,10 @@ const getMenuWidth = () => {
2160
2554
  return CONTEXT_MENU_WIDTH$1;
2161
2555
  };
2162
2556
 
2557
+ // TODO difference between focusing with mouse or keyboard
2558
+ // with mouse -> open submenu
2559
+ // with keyboard -> don't open submenu, only focus
2560
+
2163
2561
  // TODO handle printable letter and focus item that starts with that letter
2164
2562
 
2165
2563
  // TODO pageup / pagedown keys
@@ -2220,7 +2618,7 @@ const show$2 = async (x, y, id, mouseBlocking = false, ...args) => {
2220
2618
  });
2221
2619
  const visible = getVisible(menu.items, -1, false, menu.level);
2222
2620
  const dom = getMenuVirtualDom(visible).slice(1);
2223
- 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);
2621
+ 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);
2224
2622
  };
2225
2623
  const show2$2 = async (uid, menuId, x, y, mouseBlocking = false, ...args) => {
2226
2624
  const items = await getMenuEntriesWithKeyBindings2(uid, menuId, ...args);
@@ -2235,19 +2633,19 @@ const show2$2 = async (uid, menuId, x, y, mouseBlocking = false, ...args) => {
2235
2633
  });
2236
2634
  const visible = getVisible(menu.items, -1, false, menu.level);
2237
2635
  const dom = getMenuVirtualDom(visible).slice(1);
2238
- 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);
2636
+ 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);
2239
2637
  };
2240
- const hide = async (restoreFocus = true) => {
2638
+ const hide$1 = async (restoreFocus = true) => {
2241
2639
  if (getCount() === 0) {
2242
2640
  return;
2243
2641
  }
2244
2642
  reset();
2245
- await invoke(/* Menu.hide */'Menu.hide', /* restoreFocus */restoreFocus);
2643
+ await invoke$1(/* Menu.hide */'Menu.hide', /* restoreFocus */restoreFocus);
2246
2644
  };
2247
2645
 
2248
2646
  const show$1 = async (x, y, id, ...args) => {
2249
2647
  // @ts-ignore
2250
- await hide();
2648
+ await hide$1();
2251
2649
  // TODO handle error
2252
2650
  // TODO race condition
2253
2651
  await show$2(x, y, id, /* mouseBlocking */true, ...args);
@@ -2256,7 +2654,7 @@ const show$1 = async (x, y, id, ...args) => {
2256
2654
  };
2257
2655
  const show2$1 = async (uid, menuId, x, y, ...args) => {
2258
2656
  // @ts-ignore
2259
- await hide();
2657
+ await hide$1();
2260
2658
  // TODO handle error
2261
2659
  // TODO race condition
2262
2660
  await show2$2(uid, menuId, x, y, /* mouseBlocking */true, ...args);
@@ -2401,6 +2799,22 @@ const focusFirst = async () => {
2401
2799
  await focusIndex(menu, indexToFocus);
2402
2800
  };
2403
2801
 
2802
+ const getIndexToFocusPreviousStartingAt$1 = (items, startIndex) => {
2803
+ for (let i = startIndex; i > startIndex - items.length; i--) {
2804
+ const index = (i + items.length) % items.length;
2805
+ const item = items[index];
2806
+ if (canBeFocused(item)) {
2807
+ return index;
2808
+ }
2809
+ }
2810
+ return -1;
2811
+ };
2812
+ const focusLast = async () => {
2813
+ const menu = getCurrentMenu();
2814
+ const indexToFocus = getIndexToFocusPreviousStartingAt$1(menu.items, menu.items.length - 1);
2815
+ await focusIndex(menu, indexToFocus);
2816
+ };
2817
+
2404
2818
  const getIndexToFocusNext = menu => {
2405
2819
  const startIndex = menu.focusedIndex + 1;
2406
2820
  return getIndexToFocusNextStartingAt(menu.items, startIndex);
@@ -2414,6 +2828,30 @@ const focusNext = async () => {
2414
2828
  await focusIndex(menu, indexToFocus);
2415
2829
  };
2416
2830
 
2831
+ // TODO this code seems a bit too complicated, maybe it can be simplified
2832
+ const getIndexToFocusPreviousStartingAt = (items, startIndex) => {
2833
+ for (let i = startIndex; i > startIndex - items.length; i--) {
2834
+ const index = (i + items.length) % items.length;
2835
+ const item = items[index];
2836
+ if (canBeFocused(item)) {
2837
+ return index;
2838
+ }
2839
+ }
2840
+ return -1;
2841
+ };
2842
+ const getIndexToFocusPrevious = menu => {
2843
+ const startIndex = menu.focusedIndex === -1 ? menu.items.length - 1 : menu.focusedIndex - 1;
2844
+ return getIndexToFocusPreviousStartingAt(menu.items, startIndex);
2845
+ };
2846
+ const focusPrevious = async () => {
2847
+ const menu = getCurrentMenu();
2848
+ if (menu.items.length === 0) {
2849
+ return;
2850
+ }
2851
+ const indexToFocus = getIndexToFocusPrevious(menu);
2852
+ await focusIndex(menu, indexToFocus);
2853
+ };
2854
+
2417
2855
  const commandsIds = ['closeMenu', 'handleClickAt', 'focus', 'focusFirst', 'focusIndex', 'focusLast', 'focusNext', 'focusPrevious', 'handleClick', 'handleFocus', 'handleFocusOut', 'handleKeyArrowDown', 'handleKeyArrowLeft', 'handleKeyArrowRight', 'handleKeyArrowUp', 'handleKeyEnd', 'handleKeyEnter', 'handleKeyEscape', 'handleKeyHome', 'handleKeySpace', 'handleMenuClick', 'handleMenuMouseOver', 'handleMouseOut', 'handleMouseOver', 'handlePointerOver', 'handlePointerOut', 'toggleIndex', 'toggleMenu'];
2418
2856
 
2419
2857
  const getCommandIds = () => {
@@ -2530,9 +2968,11 @@ const getMenuBounds = (x, y, items) => {
2530
2968
 
2531
2969
  if (x + menuWidth > windowWidth) {
2532
2970
  x -= menuWidth;
2971
+ x = Math.max(x, 0);
2533
2972
  }
2534
2973
  if (y + menuHeight > windowHeight) {
2535
2974
  y -= menuHeight;
2975
+ y = Math.max(y, 0);
2536
2976
  }
2537
2977
  return {
2538
2978
  x,
@@ -2574,6 +3014,12 @@ const hideSubMenus = async level => {
2574
3014
  }
2575
3015
  };
2576
3016
 
3017
+ /* eslint-disable @typescript-eslint/no-implied-eval */
3018
+ const MENU_DELAY_TRIANGLE = 300;
3019
+ const resolveAfterTimeout = fn => {
3020
+ setTimeout(fn, MENU_DELAY_TRIANGLE);
3021
+ };
3022
+
2577
3023
  const showSubMenuAtEnter = async (level, index, enterX, enterY) => {
2578
3024
  // TODO delete old menus
2579
3025
  set$1(getAll().slice(0, level + 1));
@@ -2603,11 +3049,6 @@ const showSubMenu = async (level, index) => {
2603
3049
  return showSubMenuAtEnter(level, index, -1, -1);
2604
3050
  };
2605
3051
 
2606
- /* eslint-disable @typescript-eslint/no-implied-eval */
2607
- const MENU_DELAY_TRIANGLE = 300;
2608
- const resolveAfterTimeout = fn => {
2609
- setTimeout(fn, MENU_DELAY_TRIANGLE);
2610
- };
2611
3052
  const handleMouseEnter = async (level, index, enterX, enterY, enterTimeStamp) => {
2612
3053
  setTimestamp(enterTimeStamp);
2613
3054
  if (level >= getCount()) {
@@ -2764,6 +3205,75 @@ const saveState = uid => {
2764
3205
  };
2765
3206
  };
2766
3207
 
3208
+ const {
3209
+ invoke} = RendererWorker;
3210
+
3211
+ const executeMenuItemCommand = async item => {
3212
+ await invoke(item.command, ...(item.args || []));
3213
+ };
3214
+
3215
+ const hide = async (restoreFocus = true) => {
3216
+ const {
3217
+ commands
3218
+ } = await getMenuHideCommands(restoreFocus);
3219
+ if (commands.length > 0) {
3220
+ // @ts-ignore
3221
+ await invoke$2(...commands);
3222
+ }
3223
+ };
3224
+
3225
+ const selectIndexNone = async (menu, item) => {
3226
+ await Promise.all([hide(/* restoreFocus */false), executeMenuItemCommand(item)]);
3227
+ };
3228
+ const selectIndexRestoreFocus = async (menu, item) => {
3229
+ await Promise.all([hide(/* restoreFocus */true), executeMenuItemCommand(item)]);
3230
+ };
3231
+ const selectIndexSubMenu = async (menu, item, index) => {
3232
+ if (menu.focusedIndex === index) {
3233
+ return;
3234
+ }
3235
+ await showSubMenu(menu.level, menu.focusedIndex);
3236
+ };
3237
+ const selectIndexDefault = async () => {};
3238
+ const selectIndexIgnore = async (menu, item) => {
3239
+ await executeMenuItemCommand(item);
3240
+ };
3241
+ const getSelectIndexFunction = flags => {
3242
+ switch (flags) {
3243
+ case None$1:
3244
+ return selectIndexNone;
3245
+ case SubMenu$1:
3246
+ return selectIndexSubMenu;
3247
+ case RestoreFocus$1:
3248
+ return selectIndexRestoreFocus;
3249
+ case Ignore$1:
3250
+ return selectIndexIgnore;
3251
+ default:
3252
+ return selectIndexDefault;
3253
+ }
3254
+ };
3255
+ const selectIndex = async (level, index) => {
3256
+ const menu = get$1(level);
3257
+ // TODO avoid assignment
3258
+ menu.focusedIndex = index;
3259
+ const item = menu.items[menu.focusedIndex];
3260
+ const fn = getSelectIndexFunction(item.flags);
3261
+ await fn(menu, item, index);
3262
+ };
3263
+
3264
+ const selectItem = async text => {
3265
+ for (let level = 0; level < getCount(); level++) {
3266
+ const menu = get$1(level);
3267
+ for (let i = 0; i < menu.items.length; i++) {
3268
+ const item = menu.items[i];
3269
+ if (item.label === text) {
3270
+ return selectIndex(level, i);
3271
+ }
3272
+ }
3273
+ }
3274
+ throw new Error(`menu item not found: ${text}`);
3275
+ };
3276
+
2767
3277
  const wrapCommand = fn => {
2768
3278
  const wrapped = async (uid, ...args) => {
2769
3279
  const {
@@ -2781,7 +3291,11 @@ const wrapCommand = fn => {
2781
3291
 
2782
3292
  const commandMap = {
2783
3293
  'Menu.diff2': diff2,
3294
+ 'Menu.focusPrevious': focusPrevious,
2784
3295
  'Menu.focusFirst': focusFirst,
3296
+ 'Menu.focusIndex': focusIndex,
3297
+ 'Menu.focusLast': focusLast,
3298
+ 'Menu.closeSubMenu': closeSubMenu,
2785
3299
  'Menu.focusNext': focusNext,
2786
3300
  'Menu.getCommands': getCommandIds,
2787
3301
  'Menu.getHideCommands': getMenuHideCommands,
@@ -2798,6 +3312,7 @@ const commandMap = {
2798
3312
  'Menu.render2': render2,
2799
3313
  'Menu.renderEventListeners': renderEventListeners,
2800
3314
  'Menu.saveState': saveState,
3315
+ 'Menu.selectItem': selectItem,
2801
3316
  'Menu.show': show,
2802
3317
  'Menu.show2': show2,
2803
3318
  'Menu.showSubMenu': showSubMenu
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/menu-worker",
3
- "version": "1.7.0",
3
+ "version": "2.1.0",
4
4
  "description": "Menu Worker",
5
5
  "repository": {
6
6
  "type": "git",