@lvce-editor/title-bar-worker 2.16.0 → 2.17.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.
@@ -1262,20 +1262,289 @@ const Button = 'event.button';
1262
1262
  const ClientX = 'event.clientX';
1263
1263
  const ClientY = 'event.clientY';
1264
1264
 
1265
- const Escape$2 = 8;
1266
- const Space$2 = 9;
1267
- const End$2 = 255;
1268
- const Home$2 = 12;
1269
- const LeftArrow$2 = 13;
1270
- const UpArrow$2 = 14;
1271
- const RightArrow$2 = 15;
1272
- const DownArrow$2 = 16;
1265
+ const Backspace$1 = 1;
1266
+ const Tab$1 = 2;
1267
+ const Enter$1 = 3;
1268
+ const Escape$1 = 8;
1269
+ const Space$1 = 9;
1270
+ const PageUp$1 = 10;
1271
+ const PageDown$1 = 11;
1272
+ const End$1 = 255;
1273
+ const Home$1 = 12;
1274
+ const LeftArrow$1 = 13;
1275
+ const UpArrow$1 = 14;
1276
+ const RightArrow$1 = 15;
1277
+ const DownArrow$1 = 16;
1278
+ const Insert$1 = 17;
1279
+ const Delete$1 = 18;
1280
+ const Digit0$1 = 19;
1281
+ const Digit1$1 = 20;
1282
+ const Digit2$1 = 21;
1283
+ const Digit3$1 = 22;
1284
+ const Digit4$1 = 23;
1285
+ const Digit5$1 = 24;
1286
+ const Digit6$1 = 25;
1287
+ const Digit7$1 = 26;
1288
+ const Digit8$1 = 27;
1289
+ const Digit9$1 = 28;
1290
+ const KeyA$1 = 29;
1291
+ const KeyB$1 = 30;
1292
+ const KeyC$1 = 31;
1293
+ const KeyD$1 = 32;
1294
+ const KeyE$1 = 33;
1295
+ const KeyF$1 = 34;
1296
+ const KeyG$1 = 35;
1297
+ const KeyH$1 = 36;
1298
+ const KeyI$1 = 37;
1299
+ const KeyJ$1 = 38;
1300
+ const KeyK$1 = 39;
1301
+ const KeyL$1 = 40;
1302
+ const KeyM$1 = 41;
1303
+ const KeyN$1 = 42;
1304
+ const KeyO$1 = 43;
1305
+ const KeyP$1 = 44;
1306
+ const KeyQ$1 = 45;
1307
+ const KeyR$1 = 46;
1308
+ const KeyS$1 = 47;
1309
+ const KeyT$1 = 48;
1310
+ const KeyU$1 = 49;
1311
+ const KeyV$1 = 50;
1312
+ const KeyW$1 = 51;
1313
+ const KeyX$1 = 52;
1314
+ const KeyY$1 = 53;
1315
+ const KeyZ$1 = 54;
1316
+ const F1$1 = 57;
1317
+ const F2$1 = 58;
1318
+ const F3$1 = 59;
1319
+ const F4$1 = 60;
1320
+ const F5$1 = 61;
1321
+ const F6$1 = 62;
1322
+ const Equal$1 = 84;
1323
+ const Comma$1 = 85;
1324
+ const Minus$1 = 86;
1325
+ const Backquote$1 = 89;
1326
+ const Backslash$1 = 91;
1327
+ const Star$1 = 131;
1328
+ const Plus$1 = 132;
1329
+
1330
+ const Unknown = 'Unknown';
1331
+ const Backspace = 'Backspace';
1332
+ const Tab = 'Tab';
1333
+ const Enter = 'Enter';
1334
+ const Escape = 'Escape';
1335
+ const Space = 'Space';
1336
+ const PageUp = 'PageUp';
1337
+ const PageDown = 'PageDown';
1338
+ const End = 'End';
1339
+ const Home = 'Home';
1340
+ const LeftArrow = 'LeftArrow';
1341
+ const UpArrow = 'UpArrow';
1342
+ const RightArrow = 'RightArrow';
1343
+ const DownArrow = 'DownArrow';
1344
+ const Insert = 'Insert';
1345
+ const Delete = 'Delete';
1346
+ const Digit0 = '0';
1347
+ const Digit1 = '1';
1348
+ const Digit2 = '2';
1349
+ const Digit3 = '3';
1350
+ const Digit4 = '4';
1351
+ const Digit5 = '5';
1352
+ const Digit6 = '6';
1353
+ const Digit7 = '7';
1354
+ const Digit8 = '8';
1355
+ const Digit9 = '9';
1356
+ const KeyA = 'a';
1357
+ const KeyB = 'b';
1358
+ const KeyC = 'c';
1359
+ const KeyD = 'd';
1360
+ const KeyE = 'e';
1361
+ const KeyF = 'f';
1362
+ const KeyG = 'g';
1363
+ const KeyH = 'h';
1364
+ const KeyI = 'i';
1365
+ const KeyJ = 'j';
1366
+ const KeyK = 'k';
1367
+ const KeyL = 'l';
1368
+ const KeyM = 'm';
1369
+ const KeyN = 'n';
1370
+ const KeyO = 'o';
1371
+ const KeyP = 'p';
1372
+ const KeyQ = 'q';
1373
+ const KeyR = 'r';
1374
+ const KeyS = 's';
1375
+ const KeyT = 't';
1376
+ const KeyU = 'u';
1377
+ const KeyV = 'v';
1378
+ const KeyW = 'w';
1379
+ const KeyX = 'x';
1380
+ const KeyY = 'y';
1381
+ const KeyZ = 'z';
1382
+ const F1 = 'F1';
1383
+ const F2 = 'F2';
1384
+ const F3 = 'F3';
1385
+ const F4 = 'F4';
1386
+ const F5 = 'F5';
1387
+ const F6 = 'F6';
1388
+ const Equal = '=';
1389
+ const Comma = ',';
1390
+ const Minus = 'Minus';
1391
+ const Backquote = 'Backquote';
1392
+ const Backslash = 'Backslash';
1393
+ const Star = '*';
1394
+ const Plus = '+';
1395
+
1396
+ const getKeyCodeString = keyCode => {
1397
+ switch (keyCode) {
1398
+ case Backspace$1:
1399
+ return Backspace;
1400
+ case Tab$1:
1401
+ return Tab;
1402
+ case Escape$1:
1403
+ return Escape;
1404
+ case Enter$1:
1405
+ return Enter;
1406
+ case Space$1:
1407
+ return Space;
1408
+ case PageUp$1:
1409
+ return PageUp;
1410
+ case PageDown$1:
1411
+ return PageDown;
1412
+ case End$1:
1413
+ return End;
1414
+ case Home$1:
1415
+ return Home;
1416
+ case LeftArrow$1:
1417
+ return LeftArrow;
1418
+ case UpArrow$1:
1419
+ return UpArrow;
1420
+ case RightArrow$1:
1421
+ return RightArrow;
1422
+ case DownArrow$1:
1423
+ return DownArrow;
1424
+ case Insert$1:
1425
+ return Insert;
1426
+ case Delete$1:
1427
+ return Delete;
1428
+ case Digit0$1:
1429
+ return Digit0;
1430
+ case Digit1$1:
1431
+ return Digit1;
1432
+ case Digit2$1:
1433
+ return Digit2;
1434
+ case Digit3$1:
1435
+ return Digit3;
1436
+ case Digit4$1:
1437
+ return Digit4;
1438
+ case Digit5$1:
1439
+ return Digit5;
1440
+ case Digit6$1:
1441
+ return Digit6;
1442
+ case Digit7$1:
1443
+ return Digit7;
1444
+ case Digit8$1:
1445
+ return Digit8;
1446
+ case Digit9$1:
1447
+ return Digit9;
1448
+ case KeyA$1:
1449
+ return KeyA;
1450
+ case KeyB$1:
1451
+ return KeyB;
1452
+ case KeyC$1:
1453
+ return KeyC;
1454
+ case KeyD$1:
1455
+ return KeyD;
1456
+ case KeyE$1:
1457
+ return KeyE;
1458
+ case KeyF$1:
1459
+ return KeyF;
1460
+ case KeyG$1:
1461
+ return KeyG;
1462
+ case KeyH$1:
1463
+ return KeyH;
1464
+ case KeyI$1:
1465
+ return KeyI;
1466
+ case KeyJ$1:
1467
+ return KeyJ;
1468
+ case KeyK$1:
1469
+ return KeyK;
1470
+ case KeyL$1:
1471
+ return KeyL;
1472
+ case KeyM$1:
1473
+ return KeyM;
1474
+ case KeyN$1:
1475
+ return KeyN;
1476
+ case KeyO$1:
1477
+ return KeyO;
1478
+ case KeyP$1:
1479
+ return KeyP;
1480
+ case KeyQ$1:
1481
+ return KeyQ;
1482
+ case KeyR$1:
1483
+ return KeyR;
1484
+ case KeyS$1:
1485
+ return KeyS;
1486
+ case KeyT$1:
1487
+ return KeyT;
1488
+ case KeyU$1:
1489
+ return KeyU;
1490
+ case KeyV$1:
1491
+ return KeyV;
1492
+ case KeyW$1:
1493
+ return KeyW;
1494
+ case KeyX$1:
1495
+ return KeyX;
1496
+ case KeyY$1:
1497
+ return KeyY;
1498
+ case KeyZ$1:
1499
+ return KeyZ;
1500
+ case F1$1:
1501
+ return F1;
1502
+ case F2$1:
1503
+ return F2;
1504
+ case F3$1:
1505
+ return F3;
1506
+ case F4$1:
1507
+ return F4;
1508
+ case F5$1:
1509
+ return F5;
1510
+ case F6$1:
1511
+ return F6;
1512
+ case Backslash$1:
1513
+ return Backslash;
1514
+ case Equal$1:
1515
+ return Equal;
1516
+ case Comma$1:
1517
+ return Comma;
1518
+ case Backquote$1:
1519
+ return Backquote;
1520
+ case Plus$1:
1521
+ return Plus;
1522
+ case Star$1:
1523
+ return Star;
1524
+ case Minus$1:
1525
+ return Minus;
1526
+ default:
1527
+ return Unknown;
1528
+ }
1529
+ };
1273
1530
 
1274
1531
  const CtrlCmd = 1 << 11 >>> 0;
1275
1532
  const Shift = 1 << 10 >>> 0;
1276
1533
 
1277
1534
  const TitleBar$1 = 15;
1278
1535
 
1536
+ const parseKey = rawKey => {
1537
+ const isCtrl = Boolean(rawKey & CtrlCmd);
1538
+ const isShift = Boolean(rawKey & Shift);
1539
+ const keyCode = rawKey & 0x00_00_00_ff;
1540
+ const key = getKeyCodeString(keyCode);
1541
+ return {
1542
+ key,
1543
+ isCtrl,
1544
+ isShift
1545
+ };
1546
+ };
1547
+
1279
1548
  const DebugWorker = 55;
1280
1549
  const RendererWorker$1 = 1;
1281
1550
 
@@ -1299,35 +1568,35 @@ const FocusTitleBarMenuBar = 26;
1299
1568
 
1300
1569
  const getKeyBindings$1 = () => {
1301
1570
  return [{
1302
- key: DownArrow$2,
1571
+ key: DownArrow$1,
1303
1572
  command: 'TitleBar.handleKeyArrowDown',
1304
1573
  when: FocusTitleBarMenuBar
1305
1574
  }, {
1306
- key: UpArrow$2,
1575
+ key: UpArrow$1,
1307
1576
  command: 'TitleBar.handleKeyArrowUp',
1308
1577
  when: FocusTitleBarMenuBar
1309
1578
  }, {
1310
- key: RightArrow$2,
1579
+ key: RightArrow$1,
1311
1580
  command: 'TitleBar.handleKeyArrowRight',
1312
1581
  when: FocusTitleBarMenuBar
1313
1582
  }, {
1314
- key: LeftArrow$2,
1583
+ key: LeftArrow$1,
1315
1584
  command: 'TitleBar.handleKeyArrowLeft',
1316
1585
  when: FocusTitleBarMenuBar
1317
1586
  }, {
1318
- key: Space$2,
1587
+ key: Space$1,
1319
1588
  command: 'TitleBar.handleKeySpace',
1320
1589
  when: FocusTitleBarMenuBar
1321
1590
  }, {
1322
- key: Home$2,
1591
+ key: Home$1,
1323
1592
  command: 'TitleBar.handleKeyHome',
1324
1593
  when: FocusTitleBarMenuBar
1325
1594
  }, {
1326
- key: End$2,
1595
+ key: End$1,
1327
1596
  command: 'TitleBar.handleKeyEnd',
1328
1597
  when: FocusTitleBarMenuBar
1329
1598
  }, {
1330
- key: Escape$2,
1599
+ key: Escape$1,
1331
1600
  command: 'TitleBar.handleKeyEscape',
1332
1601
  when: FocusTitleBarMenuBar
1333
1602
  }];
@@ -1602,1575 +1871,1296 @@ const getMenuEntries$a = async platform => {
1602
1871
  }
1603
1872
  if (autoUpdateSupported) {
1604
1873
  entries.push(menuEntrySeparator, {
1605
- id: 'checkForUpdates',
1606
- label: checkForUpdates(),
1607
- flags: RestoreFocus,
1608
- command: 'AutoUpdater.checkForUpdates'
1609
- });
1610
- }
1611
- if (entries.length > 0) {
1612
- entries.push(menuEntrySeparator);
1613
- }
1614
- entries.push({
1615
- id: 'about',
1616
- label: about(),
1617
- flags: None,
1618
- command: 'About.showAbout'
1619
- });
1620
- return entries;
1621
- };
1622
-
1623
- const MenuEntriesHelp = {
1624
- __proto__: null,
1625
- getMenuEntries: getMenuEntries$a,
1626
- id: id$6
1627
- };
1628
-
1629
- const rpcs = Object.create(null);
1630
- const set$2 = (id, rpc) => {
1631
- rpcs[id] = rpc;
1632
- };
1633
- const get = id => {
1634
- return rpcs[id];
1635
- };
1636
-
1637
- const create$1 = rpcId => {
1638
- return {
1639
- // @ts-ignore
1640
- invoke(method, ...params) {
1641
- const rpc = get(rpcId);
1642
- // @ts-ignore
1643
- return rpc.invoke(method, ...params);
1644
- },
1645
- // @ts-ignore
1646
- invokeAndTransfer(method, ...params) {
1647
- const rpc = get(rpcId);
1648
- // @ts-ignore
1649
- return rpc.invokeAndTransfer(method, ...params);
1650
- },
1651
- set(rpc) {
1652
- set$2(rpcId, rpc);
1653
- },
1654
- async dispose() {
1655
- const rpc = get(rpcId);
1656
- await rpc.dispose();
1657
- }
1658
- };
1659
- };
1660
-
1661
- const {
1662
- invoke: invoke$1,
1663
- invokeAndTransfer,
1664
- set: set$1,
1665
- dispose
1666
- } = create$1(RendererWorker$1);
1667
- const searchFileHtml = async uri => {
1668
- return invoke$1('ExtensionHost.searchFileWithHtml', uri);
1669
- };
1670
- const getFilePathElectron = async file => {
1671
- return invoke$1('FileSystemHandle.getFilePathElectron', file);
1672
- };
1673
- const showContextMenu = async (x, y, id, ...args) => {
1674
- return invoke$1('ContextMenu.show', x, y, id, ...args);
1675
- };
1676
- const getElectronVersion = async () => {
1677
- return invoke$1('Process.getElectronVersion');
1678
- };
1679
- const applyBulkReplacement = async bulkEdits => {
1680
- await invoke$1('BulkReplacement.applyBulkReplacement', bulkEdits);
1681
- };
1682
- const setColorTheme = async id => {
1683
- // @ts-ignore
1684
- return invoke$1(/* ColorTheme.setColorTheme */'ColorTheme.setColorTheme', /* colorThemeId */id);
1685
- };
1686
- const getNodeVersion = async () => {
1687
- return invoke$1('Process.getNodeVersion');
1688
- };
1689
- const getChromeVersion = async () => {
1690
- return invoke$1('Process.getChromeVersion');
1691
- };
1692
- const getV8Version = async () => {
1693
- return invoke$1('Process.getV8Version');
1694
- };
1695
- const getFileHandles = async fileIds => {
1696
- const files = await invoke$1('FileSystemHandle.getFileHandles', fileIds);
1697
- return files;
1698
- };
1699
- const setWorkspacePath = async path => {
1700
- await invoke$1('Workspace.setPath', path);
1701
- };
1702
- const registerWebViewInterceptor = async (id, port) => {
1703
- await invokeAndTransfer('WebView.registerInterceptor', id, port);
1704
- };
1705
- const unregisterWebViewInterceptor = async id => {
1706
- await invoke$1('WebView.unregisterInterceptor', id);
1707
- };
1708
- const sendMessagePortToEditorWorker = async (port, rpcId) => {
1709
- const command = 'HandleMessagePort.handleMessagePort';
1710
- // @ts-ignore
1711
- await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToEditorWorker', port, command, rpcId);
1712
- };
1713
- const sendMessagePortToErrorWorker = async (port, rpcId) => {
1714
- const command = 'Errors.handleMessagePort';
1715
- // @ts-ignore
1716
- await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToErrorWorker', port, command, rpcId);
1717
- };
1718
- const sendMessagePortToMarkdownWorker = async (port, rpcId) => {
1719
- const command = 'Markdown.handleMessagePort';
1720
- // @ts-ignore
1721
- await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToMarkdownWorker', port, command, rpcId);
1722
- };
1723
- const sendMessagePortToIconThemeWorker = async (port, rpcId) => {
1724
- const command = 'IconTheme.handleMessagePort';
1725
- // @ts-ignore
1726
- await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToIconThemeWorker', port, command, rpcId);
1727
- };
1728
- const sendMessagePortToFileSystemWorker = async (port, rpcId) => {
1729
- const command = 'FileSystem.handleMessagePort';
1730
- // @ts-ignore
1731
- await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToFileSystemWorker', port, command, rpcId);
1732
- };
1733
- const readFile = async uri => {
1734
- return invoke$1('FileSystem.readFile', uri);
1735
- };
1736
- const getWebViewSecret = async key => {
1737
- // @ts-ignore
1738
- return invoke$1('WebView.getSecret', key);
1739
- };
1740
- const setWebViewPort = async (uid, port, origin, portType) => {
1741
- return invokeAndTransfer('WebView.setPort', uid, port, origin, portType);
1742
- };
1743
- const setFocus$1 = key => {
1744
- return invoke$1('Focus.setFocus', key);
1745
- };
1746
- const getFileIcon = async options => {
1747
- return invoke$1('IconTheme.getFileIcon', options);
1748
- };
1749
- const getColorThemeNames = async () => {
1750
- return invoke$1('ColorTheme.getColorThemeNames');
1751
- };
1752
- const disableExtension = async id => {
1753
- // @ts-ignore
1754
- return invoke$1('ExtensionManagement.disable', id);
1755
- };
1756
- const enableExtension = async id => {
1757
- // @ts-ignore
1758
- return invoke$1('ExtensionManagement.enable', id);
1759
- };
1760
- const handleDebugChange = async params => {
1761
- // @ts-ignore
1762
- return invoke$1('Run And Debug.handleChange', params);
1763
- };
1764
- const getFolderIcon = async options => {
1765
- return invoke$1('IconTheme.getFolderIcon', options);
1766
- };
1767
- const closeWidget = async widgetId => {
1768
- return invoke$1('Viewlet.closeWidget', widgetId);
1769
- };
1770
- const sendMessagePortToExtensionHostWorker = async (port, rpcId = 0) => {
1771
- const command = 'HandleMessagePort.handleMessagePort2';
1772
- await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, rpcId);
1773
- };
1774
- const sendMessagePortToSearchProcess = async port => {
1775
- await invokeAndTransfer('SendMessagePortToElectron.sendMessagePortToElectron', port, 'HandleMessagePortForSearchProcess.handleMessagePortForSearchProcess');
1776
- };
1777
- const confirm = async (message, options) => {
1778
- // @ts-ignore
1779
- const result = await invoke$1('ConfirmPrompt.prompt', message, options);
1780
- return result;
1781
- };
1782
- const getRecentlyOpened$1 = async () => {
1783
- return invoke$1(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
1784
- };
1785
- const getKeyBindings = async () => {
1786
- return invoke$1('KeyBindingsInitial.getKeyBindings');
1787
- };
1788
- const writeClipBoardText = async text => {
1789
- await invoke$1('ClipBoard.writeText', /* text */text);
1790
- };
1791
- const writeClipBoardImage = async blob => {
1792
- // @ts-ignore
1793
- await invoke$1('ClipBoard.writeImage', /* text */blob);
1794
- };
1795
- const searchFileMemory = async uri => {
1796
- // @ts-ignore
1797
- return invoke$1('ExtensionHost.searchFileWithMemory', uri);
1798
- };
1799
- const searchFileFetch = async uri => {
1800
- return invoke$1('ExtensionHost.searchFileWithFetch', uri);
1801
- };
1802
- const showMessageBox = async options => {
1803
- return invoke$1('ElectronDialog.showMessageBox', options);
1804
- };
1805
- const handleDebugResumed = async params => {
1806
- await invoke$1('Run And Debug.handleResumed', params);
1807
- };
1808
- const openWidget = async name => {
1809
- await invoke$1('Viewlet.openWidget', name);
1810
- };
1811
- const getIcons = async requests => {
1812
- const icons = await invoke$1('IconTheme.getIcons', requests);
1813
- return icons;
1814
- };
1815
- const activateByEvent = event => {
1816
- return invoke$1('ExtensionHostManagement.activateByEvent', event);
1817
- };
1818
- const setAdditionalFocus = focusKey => {
1819
- // @ts-ignore
1820
- return invoke$1('Focus.setAdditionalFocus', focusKey);
1821
- };
1822
- const getActiveEditorId = () => {
1823
- // @ts-ignore
1824
- return invoke$1('GetActiveEditor.getActiveEditorId');
1825
- };
1826
- const getWorkspacePath = () => {
1827
- return invoke$1('Workspace.getPath');
1828
- };
1829
- const sendMessagePortToRendererProcess = async port => {
1830
- const command = 'HandleMessagePort.handleMessagePort';
1831
- // @ts-ignore
1832
- await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToRendererProcess', port, command, DebugWorker);
1833
- };
1834
- const getPreference = async key => {
1835
- return await invoke$1('Preferences.get', key);
1836
- };
1837
- const getAllExtensions = async () => {
1838
- return invoke$1('ExtensionManagement.getAllExtensions');
1839
- };
1840
- const rerenderEditor = async key => {
1841
- // @ts-ignore
1842
- return invoke$1('Editor.rerender', key);
1843
- };
1844
- const handleDebugPaused = async params => {
1845
- await invoke$1('Run And Debug.handlePaused', params);
1846
- };
1847
- const openUri = async (uri, focus, options) => {
1848
- await invoke$1('Main.openUri', uri, focus, options);
1874
+ id: 'checkForUpdates',
1875
+ label: checkForUpdates(),
1876
+ flags: RestoreFocus,
1877
+ command: 'AutoUpdater.checkForUpdates'
1878
+ });
1879
+ }
1880
+ if (entries.length > 0) {
1881
+ entries.push(menuEntrySeparator);
1882
+ }
1883
+ entries.push({
1884
+ id: 'about',
1885
+ label: about(),
1886
+ flags: None,
1887
+ command: 'About.showAbout'
1888
+ });
1889
+ return entries;
1849
1890
  };
1850
- const sendMessagePortToSyntaxHighlightingWorker = async port => {
1851
- await invokeAndTransfer(
1852
- // @ts-ignore
1853
- 'SendMessagePortToSyntaxHighlightingWorker.sendMessagePortToSyntaxHighlightingWorker', port, 'HandleMessagePort.handleMessagePort2');
1891
+
1892
+ const MenuEntriesHelp = {
1893
+ __proto__: null,
1894
+ getMenuEntries: getMenuEntries$a,
1895
+ id: id$6
1854
1896
  };
1855
- const handleDebugScriptParsed = async script => {
1856
- await invoke$1('Run And Debug.handleScriptParsed', script);
1897
+
1898
+ const rpcs = Object.create(null);
1899
+ const set$2 = (id, rpc) => {
1900
+ rpcs[id] = rpc;
1857
1901
  };
1858
- const getWindowId = async () => {
1859
- return invoke$1('GetWindowId.getWindowId');
1902
+ const get = id => {
1903
+ return rpcs[id];
1860
1904
  };
1861
- const getBlob = async uri => {
1862
- // @ts-ignore
1863
- return invoke$1('FileSystem.getBlob', uri);
1905
+
1906
+ const create$1 = rpcId => {
1907
+ return {
1908
+ // @ts-ignore
1909
+ invoke(method, ...params) {
1910
+ const rpc = get(rpcId);
1911
+ // @ts-ignore
1912
+ return rpc.invoke(method, ...params);
1913
+ },
1914
+ // @ts-ignore
1915
+ invokeAndTransfer(method, ...params) {
1916
+ const rpc = get(rpcId);
1917
+ // @ts-ignore
1918
+ return rpc.invokeAndTransfer(method, ...params);
1919
+ },
1920
+ set(rpc) {
1921
+ set$2(rpcId, rpc);
1922
+ },
1923
+ async dispose() {
1924
+ const rpc = get(rpcId);
1925
+ await rpc.dispose();
1926
+ }
1927
+ };
1864
1928
  };
1865
- const getExtensionCommands = async () => {
1866
- return invoke$1('ExtensionHost.getCommands');
1929
+
1930
+ const {
1931
+ invoke: invoke$1,
1932
+ invokeAndTransfer,
1933
+ set: set$1,
1934
+ dispose
1935
+ } = create$1(RendererWorker$1);
1936
+ const searchFileHtml = async uri => {
1937
+ return invoke$1('ExtensionHost.searchFileWithHtml', uri);
1867
1938
  };
1868
- const showErrorDialog = async errorInfo => {
1869
- // @ts-ignore
1870
- await invoke$1('ErrorHandling.showErrorDialog', errorInfo);
1939
+ const getFilePathElectron = async file => {
1940
+ return invoke$1('FileSystemHandle.getFilePathElectron', file);
1871
1941
  };
1872
- const getFolderSize = async uri => {
1873
- // @ts-ignore
1874
- return await invoke$1('FileSystem.getFolderSize', uri);
1942
+ const showContextMenu = async (x, y, id, ...args) => {
1943
+ return invoke$1('ContextMenu.show', x, y, id, ...args);
1875
1944
  };
1876
- const getExtension = async id => {
1877
- // @ts-ignore
1878
- return invoke$1('ExtensionManagement.getExtension', id);
1945
+ const getElectronVersion = async () => {
1946
+ return invoke$1('Process.getElectronVersion');
1879
1947
  };
1880
- const getMarkdownDom = async html => {
1881
- // @ts-ignore
1882
- return invoke$1('Markdown.getVirtualDom', html);
1948
+ const applyBulkReplacement = async bulkEdits => {
1949
+ await invoke$1('BulkReplacement.applyBulkReplacement', bulkEdits);
1883
1950
  };
1884
- const renderMarkdown = async (markdown, options) => {
1951
+ const setColorTheme = async id => {
1885
1952
  // @ts-ignore
1886
- return invoke$1('Markdown.renderMarkdown', markdown, options);
1953
+ return invoke$1(/* ColorTheme.setColorTheme */'ColorTheme.setColorTheme', /* colorThemeId */id);
1887
1954
  };
1888
- const openNativeFolder = async uri => {
1889
- // @ts-ignore
1890
- await invoke$1('OpenNativeFolder.openNativeFolder', uri);
1955
+ const getNodeVersion = async () => {
1956
+ return invoke$1('Process.getNodeVersion');
1891
1957
  };
1892
- const uninstallExtension = async id => {
1893
- return invoke$1('ExtensionManagement.uninstall', id);
1958
+ const getChromeVersion = async () => {
1959
+ return invoke$1('Process.getChromeVersion');
1894
1960
  };
1895
- const installExtension = async id => {
1896
- // @ts-ignore
1897
- return invoke$1('ExtensionManagement.install', id);
1961
+ const getV8Version = async () => {
1962
+ return invoke$1('Process.getV8Version');
1898
1963
  };
1899
- const openExtensionSearch = async () => {
1900
- // @ts-ignore
1901
- return invoke$1('SideBar.openViewlet', 'Extensions');
1964
+ const getFileHandles = async fileIds => {
1965
+ const files = await invoke$1('FileSystemHandle.getFileHandles', fileIds);
1966
+ return files;
1902
1967
  };
1903
- const setExtensionsSearchValue = async searchValue => {
1904
- // @ts-ignore
1905
- return invoke$1('Extensions.handleInput', searchValue);
1968
+ const setWorkspacePath = async path => {
1969
+ await invoke$1('Workspace.setPath', path);
1906
1970
  };
1907
- const openExternal = async uri => {
1908
- // @ts-ignore
1909
- await invoke$1('Open.openExternal', uri);
1971
+ const registerWebViewInterceptor = async (id, port) => {
1972
+ await invokeAndTransfer('WebView.registerInterceptor', id, port);
1910
1973
  };
1911
- const openUrl = async uri => {
1912
- // @ts-ignore
1913
- await invoke$1('Open.openUrl', uri);
1974
+ const unregisterWebViewInterceptor = async id => {
1975
+ await invoke$1('WebView.unregisterInterceptor', id);
1914
1976
  };
1915
- const getAllPreferences = async () => {
1977
+ const sendMessagePortToEditorWorker = async (port, rpcId) => {
1978
+ const command = 'HandleMessagePort.handleMessagePort';
1916
1979
  // @ts-ignore
1917
- return invoke$1('Preferences.getAll');
1980
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToEditorWorker', port, command, rpcId);
1918
1981
  };
1919
- const showSaveFilePicker = async () => {
1982
+ const sendMessagePortToErrorWorker = async (port, rpcId) => {
1983
+ const command = 'Errors.handleMessagePort';
1920
1984
  // @ts-ignore
1921
- return invoke$1('FilePicker.showSaveFilePicker');
1985
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToErrorWorker', port, command, rpcId);
1922
1986
  };
1923
- const getLogsDir = async () => {
1987
+ const sendMessagePortToMarkdownWorker = async (port, rpcId) => {
1988
+ const command = 'Markdown.handleMessagePort';
1924
1989
  // @ts-ignore
1925
- return invoke$1('PlatformPaths.getLogsDir');
1926
- };
1927
- const registerMockRpc = commandMap => {
1928
- const mockRpc = createMockRpc({
1929
- commandMap
1930
- });
1931
- set$1(mockRpc);
1932
- return mockRpc;
1933
- };
1934
-
1935
- const RendererWorker = {
1936
- __proto__: null,
1937
- activateByEvent,
1938
- applyBulkReplacement,
1939
- closeWidget,
1940
- confirm,
1941
- disableExtension,
1942
- dispose,
1943
- enableExtension,
1944
- getActiveEditorId,
1945
- getAllExtensions,
1946
- getAllPreferences,
1947
- getBlob,
1948
- getChromeVersion,
1949
- getColorThemeNames,
1950
- getElectronVersion,
1951
- getExtension,
1952
- getExtensionCommands,
1953
- getFileHandles,
1954
- getFileIcon,
1955
- getFilePathElectron,
1956
- getFolderIcon,
1957
- getFolderSize,
1958
- getIcons,
1959
- getKeyBindings,
1960
- getLogsDir,
1961
- getMarkdownDom,
1962
- getNodeVersion,
1963
- getPreference,
1964
- getRecentlyOpened: getRecentlyOpened$1,
1965
- getV8Version,
1966
- getWebViewSecret,
1967
- getWindowId,
1968
- getWorkspacePath,
1969
- handleDebugChange,
1970
- handleDebugPaused,
1971
- handleDebugResumed,
1972
- handleDebugScriptParsed,
1973
- installExtension,
1974
- invoke: invoke$1,
1975
- invokeAndTransfer,
1976
- openExtensionSearch,
1977
- openExternal,
1978
- openNativeFolder,
1979
- openUri,
1980
- openUrl,
1981
- openWidget,
1982
- readFile,
1983
- registerMockRpc,
1984
- registerWebViewInterceptor,
1985
- renderMarkdown,
1986
- rerenderEditor,
1987
- searchFileFetch,
1988
- searchFileHtml,
1989
- searchFileMemory,
1990
- sendMessagePortToEditorWorker,
1991
- sendMessagePortToErrorWorker,
1992
- sendMessagePortToExtensionHostWorker,
1993
- sendMessagePortToFileSystemWorker,
1994
- sendMessagePortToIconThemeWorker,
1995
- sendMessagePortToMarkdownWorker,
1996
- sendMessagePortToRendererProcess,
1997
- sendMessagePortToSearchProcess,
1998
- sendMessagePortToSyntaxHighlightingWorker,
1999
- set: set$1,
2000
- setAdditionalFocus,
2001
- setColorTheme,
2002
- setExtensionsSearchValue,
2003
- setFocus: setFocus$1,
2004
- setWebViewPort,
2005
- setWorkspacePath,
2006
- showContextMenu,
2007
- showErrorDialog,
2008
- showMessageBox,
2009
- showSaveFilePicker,
2010
- uninstallExtension,
2011
- unregisterWebViewInterceptor,
2012
- writeClipBoardImage,
2013
- writeClipBoardText
2014
- };
2015
-
2016
- const {
2017
- invoke,
2018
- set
2019
- } = RendererWorker;
2020
-
2021
- const getRecentlyOpened = () => {
2022
- return invoke(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
1990
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToMarkdownWorker', port, command, rpcId);
2023
1991
  };
2024
-
2025
- const File = 'file://';
2026
-
2027
- const getTitle = (homeDir, uri) => {
2028
- if (!uri) {
2029
- return '';
2030
- }
2031
- if (uri.startsWith(File)) {
2032
- return uri.slice(File.length);
2033
- }
2034
- return uri;
1992
+ const sendMessagePortToIconThemeWorker = async (port, rpcId) => {
1993
+ const command = 'IconTheme.handleMessagePort';
1994
+ // @ts-ignore
1995
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToIconThemeWorker', port, command, rpcId);
2035
1996
  };
2036
-
2037
- const moreDot = () => {
2038
- return i18nString(MoreDot);
1997
+ const sendMessagePortToFileSystemWorker = async (port, rpcId) => {
1998
+ const command = 'FileSystem.handleMessagePort';
1999
+ // @ts-ignore
2000
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToFileSystemWorker', port, command, rpcId);
2039
2001
  };
2040
- const clearRecentlyOpened = () => {
2041
- return i18nString(ClearRecentlyOpened);
2002
+ const readFile = async uri => {
2003
+ return invoke$1('FileSystem.readFile', uri);
2042
2004
  };
2043
-
2044
- const getHomeDir = () => {
2045
- return '';
2005
+ const getWebViewSecret = async key => {
2006
+ // @ts-ignore
2007
+ return invoke$1('WebView.getSecret', key);
2046
2008
  };
2047
-
2048
- const MAX_MENU_RECENT_ENTRIES = 10;
2049
- const toMenuItem = folder => {
2050
- const homeDir = getHomeDir();
2051
- const label = getTitle(homeDir, folder);
2052
- return {
2053
- label,
2054
- flags: None,
2055
- command: 'Workspace.setPath',
2056
- args: [folder]
2057
- };
2009
+ const setWebViewPort = async (uid, port, origin, portType) => {
2010
+ return invokeAndTransfer('WebView.setPort', uid, port, origin, portType);
2058
2011
  };
2059
- const id$5 = OpenRecent;
2060
- const getMenuEntries$9 = async () => {
2061
- const allItems = await getRecentlyOpened();
2062
- const itemsToShow = allItems.slice(0, MAX_MENU_RECENT_ENTRIES);
2063
- const items = [];
2064
- if (itemsToShow.length > 0) {
2065
- items.push(...itemsToShow.map(toMenuItem), menuEntrySeparator);
2066
- }
2067
- items.push({
2068
- id: 'more',
2069
- label: moreDot(),
2070
- flags: None,
2071
- command: 'QuickPick.showRecent'
2072
- }, menuEntrySeparator, {
2073
- id: 'clearRecentlyOpened',
2074
- label: clearRecentlyOpened(),
2075
- flags: None,
2076
- command: 'RecentlyOpened.clearRecentlyOpened'
2077
- });
2078
- return items;
2012
+ const setFocus$1 = key => {
2013
+ return invoke$1('Focus.setFocus', key);
2079
2014
  };
2080
-
2081
- const MenuEntriesOpenRecent = {
2082
- __proto__: null,
2083
- getMenuEntries: getMenuEntries$9,
2084
- id: id$5
2015
+ const getFileIcon = async options => {
2016
+ return invoke$1('IconTheme.getFileIcon', options);
2085
2017
  };
2086
-
2087
- const id$4 = Run;
2088
- const getMenuEntries$8 = () => {
2089
- return [];
2018
+ const getColorThemeNames = async () => {
2019
+ return invoke$1('ColorTheme.getColorThemeNames');
2090
2020
  };
2091
-
2092
- const MenuEntriesRun = {
2093
- __proto__: null,
2094
- getMenuEntries: getMenuEntries$8,
2095
- id: id$4
2021
+ const disableExtension = async id => {
2022
+ // @ts-ignore
2023
+ return invoke$1('ExtensionManagement.disable', id);
2096
2024
  };
2097
-
2098
- const id$3 = Selection;
2099
- const getMenuEntries$7 = () => {
2100
- return [{
2101
- id: 'selectAll',
2102
- label: selectAll(),
2103
- flags: None,
2104
- command: 'Editor.selectAll'
2105
- }, {
2106
- id: 'copyLineUp',
2107
- label: copyLineUp(),
2108
- flags: None,
2109
- command: 'Editor.copyLineUp'
2110
- }, {
2111
- id: 'copyLineDown',
2112
- label: copyLineDown(),
2113
- flags: None,
2114
- command: 'Editor.copyLineDown'
2115
- }, {
2116
- id: 'moveLineUp',
2117
- label: moveLineUp(),
2118
- flags: Disabled,
2119
- command: 'Editor.moveLineUp'
2120
- }, {
2121
- id: 'moveLineDown',
2122
- label: moveLineDown(),
2123
- flags: Disabled,
2124
- command: 'Editor.moveLineDown'
2125
- }];
2025
+ const enableExtension = async id => {
2026
+ // @ts-ignore
2027
+ return invoke$1('ExtensionManagement.enable', id);
2126
2028
  };
2127
-
2128
- const MenuEntriesSelection = {
2129
- __proto__: null,
2130
- getMenuEntries: getMenuEntries$7,
2131
- id: id$3
2029
+ const handleDebugChange = async params => {
2030
+ // @ts-ignore
2031
+ return invoke$1('Run And Debug.handleChange', params);
2132
2032
  };
2133
-
2134
- const id$2 = Terminal;
2135
- const getMenuEntries$6 = () => {
2136
- return [{
2137
- id: 'newTerminal',
2138
- label: i18nString(NewTerminal),
2139
- flags: None,
2140
- command: 'Layout.togglePanel',
2141
- args: ['Terminal']
2142
- }];
2033
+ const getFolderIcon = async options => {
2034
+ return invoke$1('IconTheme.getFolderIcon', options);
2143
2035
  };
2144
-
2145
- const MenuEntriesTerminal = {
2146
- __proto__: null,
2147
- getMenuEntries: getMenuEntries$6,
2148
- id: id$2
2036
+ const closeWidget = async widgetId => {
2037
+ return invoke$1('Viewlet.closeWidget', widgetId);
2149
2038
  };
2150
-
2151
- const getMenuEntries$5 = () => {
2152
- return [{
2153
- id: File$1,
2154
- label: file(),
2155
- flags: SubMenu
2156
- }, {
2157
- id: Edit,
2158
- label: edit(),
2159
- flags: SubMenu
2160
- }, {
2161
- id: Selection,
2162
- label: selection(),
2163
- flags: SubMenu
2164
- }, {
2165
- id: View,
2166
- label: view(),
2167
- flags: SubMenu
2168
- }, {
2169
- id: Go,
2170
- label: go(),
2171
- flags: SubMenu
2172
- }, {
2173
- id: Run,
2174
- label: run(),
2175
- keyboardShortCut: 'Alt+r',
2176
- flags: SubMenu
2177
- }, {
2178
- id: Terminal,
2179
- label: terminal(),
2180
- keyboardShortCut: 'Alt+t',
2181
- flags: SubMenu
2182
- }, {
2183
- id: Help,
2184
- label: help(),
2185
- keyboardShortCut: 'Alt+h',
2186
- flags: SubMenu
2187
- }];
2039
+ const sendMessagePortToExtensionHostWorker = async (port, rpcId = 0) => {
2040
+ const command = 'HandleMessagePort.handleMessagePort2';
2041
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, rpcId);
2188
2042
  };
2189
-
2190
- const getMenuEntries$4 = () => {
2191
- return [{
2192
- id: File$1,
2193
- label: file(),
2194
- flags: None
2195
- }, {
2196
- id: Edit,
2197
- label: edit(),
2198
- flags: None
2199
- }, {
2200
- id: Selection,
2201
- label: selection(),
2202
- flags: None
2203
- }, {
2204
- id: View,
2205
- label: view(),
2206
- flags: None
2207
- }, {
2208
- id: Go,
2209
- label: go(),
2210
- flags: None
2211
- }, {
2212
- id: Help,
2213
- label: help(),
2214
- flags: None
2215
- }];
2043
+ const sendMessagePortToSearchProcess = async port => {
2044
+ await invokeAndTransfer('SendMessagePortToElectron.sendMessagePortToElectron', port, 'HandleMessagePortForSearchProcess.handleMessagePortForSearchProcess');
2216
2045
  };
2217
-
2218
- const getFn = platform => {
2219
- switch (platform) {
2220
- case Web:
2221
- return getMenuEntries$4;
2222
- default:
2223
- return getMenuEntries$5;
2224
- }
2046
+ const confirm = async (message, options) => {
2047
+ // @ts-ignore
2048
+ const result = await invoke$1('ConfirmPrompt.prompt', message, options);
2049
+ return result;
2225
2050
  };
2226
- const id$1 = TitleBar;
2227
- const getMenuEntries$3 = async platform => {
2228
- const fn = getFn(platform);
2229
- return fn();
2051
+ const getRecentlyOpened$1 = async () => {
2052
+ return invoke$1(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
2230
2053
  };
2231
-
2232
- const MenuEntriesTitleBar = {
2233
- __proto__: null,
2234
- getMenuEntries: getMenuEntries$3,
2235
- id: id$1
2054
+ const getKeyBindings = async () => {
2055
+ return invoke$1('KeyBindingsInitial.getKeyBindings');
2236
2056
  };
2237
-
2238
- const id = View;
2239
- const getMenuEntries$2 = () => {
2240
- return [];
2057
+ const writeClipBoardText = async text => {
2058
+ await invoke$1('ClipBoard.writeText', /* text */text);
2241
2059
  };
2242
-
2243
- const MenuEntriesView = {
2244
- __proto__: null,
2245
- getMenuEntries: getMenuEntries$2,
2246
- id
2060
+ const writeClipBoardImage = async blob => {
2061
+ // @ts-ignore
2062
+ await invoke$1('ClipBoard.writeImage', /* text */blob);
2247
2063
  };
2248
-
2249
- const menus$1 = [MenuEntriesEdit, MenuEntriesFile, MenuEntriesGo, MenuEntriesHelp, MenuEntriesRun, MenuEntriesSelection, MenuEntriesTerminal, MenuEntriesTitleBar, MenuEntriesView, MenuEntriesOpenRecent];
2250
-
2251
- const getMenuIds = () => {
2252
- return menus$1.map(menu => menu.id);
2064
+ const searchFileMemory = async uri => {
2065
+ // @ts-ignore
2066
+ return invoke$1('ExtensionHost.searchFileWithMemory', uri);
2253
2067
  };
2254
- const getMenuEntries$1 = (id, platform) => {
2255
- const menu = menus$1.find(item => item.id === id);
2256
- if (!menu) {
2257
- return [];
2258
- }
2259
- return menu.getMenuEntries(platform);
2068
+ const searchFileFetch = async uri => {
2069
+ return invoke$1('ExtensionHost.searchFileWithFetch', uri);
2260
2070
  };
2261
-
2262
- const MaskIconCheck = 'MaskIconCheck';
2263
- const Menu = 'Menu';
2264
- const MenuItem = 'MenuItem';
2265
- const MenuItemCheckMark = 'MenuItemCheckMark';
2266
- const MenuItemCheckmarkIcon = 'MenuItemCheckmarkIcon';
2267
- const MenuItemFocused = 'MenuItemFocused';
2268
- const MenuItemKeyBinding = 'MenuItemKeyBinding';
2269
- const MenuItemSeparator = 'MenuItemSeparator';
2270
- const MenuItemSeparatorLine = 'MenuItemSeparatorLine';
2271
- const MenuItemSubMenu = 'MenuItemSubMenu';
2272
- const MenuItemSubMenuArrowRight = 'MenuItemSubMenuArrowRight';
2273
- const TitleBarButtons = 'TitleBarButtons';
2274
- const TitleBarEntryActive = 'TitleBarEntryActive';
2275
- const TitleBarIcon = 'TitleBarIcon';
2276
- const TitleBarIconIcon = 'TitleBarIconIcon';
2277
- const TitleBarMenuBar$1 = 'TitleBarMenuBar';
2278
- const TitleBarTopLevelEntry = 'TitleBarTopLevelEntry';
2279
- const TitleBarTopLevelEntryLabel = 'TitleBarTopLevelEntryLabel';
2280
- const Viewlet = 'Viewlet';
2281
-
2282
- const getIconVirtualDom = (icon, type = Div) => {
2283
- return {
2284
- type,
2285
- className: `MaskIcon MaskIcon${icon}`,
2286
- role: None$1,
2287
- childCount: 0
2288
- };
2071
+ const showMessageBox = async options => {
2072
+ return invoke$1('ElectronDialog.showMessageBox', options);
2289
2073
  };
2290
-
2291
- const createTitleBarButton = button => {
2292
- const {
2293
- id,
2294
- icon,
2295
- label,
2296
- onClick
2297
- } = button;
2298
- const dom = [{
2299
- type: Button$1,
2300
- className: `TitleBarButton TitleBarButton${id}`,
2301
- ariaLabel: label,
2302
- childCount: 1,
2303
- onClick
2304
- }, getIconVirtualDom(icon, I)];
2305
- return dom;
2074
+ const handleDebugResumed = async params => {
2075
+ await invoke$1('Run And Debug.handleResumed', params);
2306
2076
  };
2307
-
2308
- const getTitleBarButtonsVirtualDom = buttons => {
2309
- return [{
2310
- type: Div,
2311
- className: mergeClassNames(Viewlet, TitleBarButtons),
2312
- childCount: buttons.length
2313
- }, ...buttons.flatMap(createTitleBarButton)];
2077
+ const openWidget = async name => {
2078
+ await invoke$1('Viewlet.openWidget', name);
2314
2079
  };
2315
-
2316
- const parentNode$1 = {
2317
- type: Div,
2318
- className: mergeClassNames(Viewlet, TitleBarIcon),
2319
- childCount: 1
2080
+ const getIcons = async requests => {
2081
+ const icons = await invoke$1('IconTheme.getIcons', requests);
2082
+ return icons;
2320
2083
  };
2321
- const getTitleBarIconVirtualDom = iconSrc => {
2322
- return [parentNode$1, {
2323
- type: Img,
2324
- className: TitleBarIconIcon,
2325
- src: iconSrc,
2326
- alt: '',
2327
- childCount: 0
2328
- }];
2084
+ const activateByEvent = event => {
2085
+ return invoke$1('ExtensionHostManagement.activateByEvent', event);
2329
2086
  };
2330
-
2331
- const HandleClick = 1;
2332
- const HandleClickMinimize = 2;
2333
- const HandleClickToggleClose = 3;
2334
- const HandleClickToggleMaximize = 4;
2335
- const HandleFocusIn = 5;
2336
- const HandleFocusOut = 6;
2337
- const HandlePointerOut = 7;
2338
- const HandlePointerOver = 8;
2339
- const HandleMenuClick = 9;
2340
- const HandleMenuMouseOver = 10;
2341
-
2342
- const getItemVirtualDom = item => {
2087
+ const setAdditionalFocus = focusKey => {
2343
2088
  // @ts-ignore
2344
- const {
2345
- keyboardShortCut,
2346
- label,
2347
- isOpen,
2348
- isFocused
2349
- } = item;
2350
- // TODO avoid mutation
2351
- const dom = [];
2352
- dom.push({
2353
- type: Div,
2354
- className: TitleBarTopLevelEntry,
2355
- ariaHasPopup: true,
2356
- ariaExpanded: isOpen,
2357
- role: MenuItem$1,
2358
- childCount: 1,
2359
- ariaKeyShortcuts: keyboardShortCut
2360
- });
2361
- if (isOpen) {
2362
- // @ts-ignore
2363
- dom[0].ariaOwns = 'Menu-0';
2364
- }
2365
- if (isFocused) {
2366
- dom[0].className += ' ' + TitleBarEntryActive;
2367
- // @ts-ignore
2368
- dom[0].id = 'TitleBarEntryActive';
2369
- dom.push({
2370
- type: Div,
2371
- className: TitleBarTopLevelEntryLabel,
2372
- childCount: 1
2373
- });
2374
- }
2375
- dom.push(text(label));
2376
- return dom;
2089
+ return invoke$1('Focus.setAdditionalFocus', focusKey);
2377
2090
  };
2378
- const getTitleBarMenuBarItemsVirtualDom = visibleItems => {
2379
- const dom = visibleItems.flatMap(getItemVirtualDom);
2380
- return dom;
2091
+ const getActiveEditorId = () => {
2092
+ // @ts-ignore
2093
+ return invoke$1('GetActiveEditor.getActiveEditorId');
2381
2094
  };
2382
-
2383
- const activeId = 'TitleBarEntryActive';
2384
- const getTitleBarMenuBarVirtualDom = (visibleItems, focusedIndex) => {
2385
- return [{
2386
- type: Div,
2387
- className: mergeClassNames(Viewlet, TitleBarMenuBar$1),
2388
- role: MenuBar,
2389
- tabIndex: 0,
2390
- childCount: visibleItems.length,
2391
- onMouseDown: HandleClick,
2392
- onFocusOut: HandleFocusOut,
2393
- onFocusIn: HandleFocusIn,
2394
- onPointerOver: HandlePointerOver,
2395
- onPointerOut: HandlePointerOut,
2396
- ariaActivedescendant: focusedIndex === -1 ? '' : activeId
2397
- }, ...getTitleBarMenuBarItemsVirtualDom(visibleItems)];
2095
+ const getWorkspacePath = () => {
2096
+ return invoke$1('Workspace.getPath');
2398
2097
  };
2399
-
2400
- const parentNode = {
2401
- type: Div,
2402
- className: 'TitleBarTitle',
2403
- childCount: 1
2098
+ const sendMessagePortToRendererProcess = async port => {
2099
+ const command = 'HandleMessagePort.handleMessagePort';
2100
+ // @ts-ignore
2101
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToRendererProcess', port, command, DebugWorker);
2404
2102
  };
2405
- const getTitleVirtualDom = title => {
2406
- return [parentNode, text(title)];
2103
+ const getPreference = async key => {
2104
+ return await invoke$1('Preferences.get', key);
2407
2105
  };
2408
-
2409
- const maximize = async () => {
2410
- await invoke('ElectronWindow.maximize');
2106
+ const getAllExtensions = async () => {
2107
+ return invoke$1('ExtensionManagement.getAllExtensions');
2411
2108
  };
2412
- const minimize = async () => {
2413
- await invoke('ElectronWindow.minimize');
2109
+ const rerenderEditor = async key => {
2110
+ // @ts-ignore
2111
+ return invoke$1('Editor.rerender', key);
2414
2112
  };
2415
- const close = async () => {
2416
- await invoke('ElectronWindow.close');
2113
+ const handleDebugPaused = async params => {
2114
+ await invoke$1('Run And Debug.handlePaused', params);
2417
2115
  };
2418
-
2419
- const handleClickClose = async state => {
2420
- await close();
2421
- return state;
2116
+ const openUri = async (uri, focus, options) => {
2117
+ await invoke$1('Main.openUri', uri, focus, options);
2422
2118
  };
2423
-
2424
- const handleClickMinimize = async state => {
2425
- await minimize();
2426
- return state;
2119
+ const sendMessagePortToSyntaxHighlightingWorker = async port => {
2120
+ await invokeAndTransfer(
2121
+ // @ts-ignore
2122
+ 'SendMessagePortToSyntaxHighlightingWorker.sendMessagePortToSyntaxHighlightingWorker', port, 'HandleMessagePort.handleMessagePort2');
2427
2123
  };
2428
-
2429
- const handleClickToggleMaximize = async state => {
2430
- const fn = maximize;
2431
- await fn();
2432
- return state;
2124
+ const handleDebugScriptParsed = async script => {
2125
+ await invoke$1('Run And Debug.handleScriptParsed', script);
2433
2126
  };
2434
-
2435
- // TODO use button name property
2436
- const handleClick$1 = async (state, className) => {
2437
- if (className.includes('Minimize')) {
2438
- return handleClickMinimize(state);
2439
- }
2440
- if (className.includes('Maximize') || className.includes('Restore')) {
2441
- return handleClickToggleMaximize(state);
2442
- }
2443
- if (className.includes('Close')) {
2444
- return handleClickClose(state);
2445
- }
2446
- return state;
2127
+ const getWindowId = async () => {
2128
+ return invoke$1('GetWindowId.getWindowId');
2447
2129
  };
2448
-
2449
- const handleContextMenu = state => {
2450
- return state;
2130
+ const getBlob = async uri => {
2131
+ // @ts-ignore
2132
+ return invoke$1('FileSystem.getBlob', uri);
2451
2133
  };
2452
-
2453
- const getMenuOffset = (x, clientX, iconWidth) => {
2454
- return clientX - x - iconWidth;
2134
+ const getExtensionCommands = async () => {
2135
+ return invoke$1('ExtensionHost.getCommands');
2455
2136
  };
2456
-
2457
- const getTitleBarIndexFromPosition = (titleBarEntries, x, y) => {
2458
- let currentX = 0;
2459
- for (let i = 0; i < titleBarEntries.length; i++) {
2460
- const entry = titleBarEntries[i];
2461
- const entryWidth = entry.width;
2462
- if (x >= currentX && x < currentX + entryWidth) {
2463
- return i;
2464
- }
2465
- currentX += entryWidth;
2466
- }
2467
- return -1;
2137
+ const showErrorDialog = async errorInfo => {
2138
+ // @ts-ignore
2139
+ await invoke$1('ErrorHandling.showErrorDialog', errorInfo);
2468
2140
  };
2469
-
2470
- const getTotalWidth = entries => {
2471
- let total = 0;
2472
- for (const entry of entries) {
2473
- total += entry.width;
2474
- }
2475
- return total;
2141
+ const getFolderSize = async uri => {
2142
+ // @ts-ignore
2143
+ return await invoke$1('FileSystem.getFolderSize', uri);
2144
+ };
2145
+ const getExtension = async id => {
2146
+ // @ts-ignore
2147
+ return invoke$1('ExtensionManagement.getExtension', id);
2148
+ };
2149
+ const getMarkdownDom = async html => {
2150
+ // @ts-ignore
2151
+ return invoke$1('Markdown.getVirtualDom', html);
2476
2152
  };
2477
-
2478
- // TODO lazyload menuEntries and use Command.execute (maybe)
2479
- const CONTEXT_MENU_ITEM_HEIGHT = 26;
2480
- const CONTEXT_MENU_SEPARATOR_HEIGHT = 11;
2481
- const CONTEXT_MENU_PADDING = 8;
2482
- const getMenuHeight = items => {
2483
- let height = CONTEXT_MENU_PADDING;
2484
- for (const item of items) {
2485
- switch (item.flags) {
2486
- case Separator:
2487
- height += CONTEXT_MENU_SEPARATOR_HEIGHT;
2488
- break;
2489
- default:
2490
- height += CONTEXT_MENU_ITEM_HEIGHT;
2491
- break;
2492
- }
2493
- }
2494
- return height;
2153
+ const renderMarkdown = async (markdown, options) => {
2154
+ // @ts-ignore
2155
+ return invoke$1('Markdown.renderMarkdown', markdown, options);
2495
2156
  };
2496
-
2497
- // TODO lazyload menuEntries and use Command.execute (maybe)
2498
- const MENU_WIDTH = 150;
2499
- const CONTEXT_MENU_WIDTH = 250;
2500
- const getMenuWidth = () => {
2501
- return CONTEXT_MENU_WIDTH;
2157
+ const openNativeFolder = async uri => {
2158
+ // @ts-ignore
2159
+ await invoke$1('OpenNativeFolder.openNativeFolder', uri);
2502
2160
  };
2503
-
2504
- // TODO difference between focusing with mouse or keyboard
2505
- // with mouse -> open submenu
2506
- // with keyboard -> don't open submenu, only focus
2507
-
2508
- const getIndexToFocusNextStartingAt = (items, startIndex) => {
2509
- for (let i = startIndex; i < startIndex + items.length; i++) {
2510
- const index = i % items.length;
2511
- const item = items[index];
2512
- if (canBeFocused(item)) {
2513
- return index;
2514
- }
2515
- }
2516
- return -1;
2161
+ const uninstallExtension = async id => {
2162
+ return invoke$1('ExtensionManagement.uninstall', id);
2517
2163
  };
2518
- const getIndexToFocusFirst = items => {
2519
- return getIndexToFocusNextStartingAt(items, 0);
2164
+ const installExtension = async id => {
2165
+ // @ts-ignore
2166
+ return invoke$1('ExtensionManagement.install', id);
2520
2167
  };
2521
- const getIndexToFocusLast = items => {
2522
- return getIndexToFocusPreviousStartingAt(items, items.length - 1);
2168
+ const openExtensionSearch = async () => {
2169
+ // @ts-ignore
2170
+ return invoke$1('SideBar.openViewlet', 'Extensions');
2523
2171
  };
2524
-
2525
- // TODO this code seems a bit too complicated, maybe it can be simplified
2526
- const getIndexToFocusPreviousStartingAt = (items, startIndex) => {
2527
- for (let i = startIndex; i > startIndex - items.length; i--) {
2528
- const index = (i + items.length) % items.length;
2529
- const item = items[index];
2530
- if (canBeFocused(item)) {
2531
- return index;
2532
- }
2533
- }
2534
- return -1;
2172
+ const setExtensionsSearchValue = async searchValue => {
2173
+ // @ts-ignore
2174
+ return invoke$1('Extensions.handleInput', searchValue);
2535
2175
  };
2536
- const getIndexToFocusPrevious = menu => {
2537
- const startIndex = menu.focusedIndex === -1 ? menu.items.length - 1 : menu.focusedIndex - 1;
2538
- return getIndexToFocusPreviousStartingAt(menu.items, startIndex);
2176
+ const openExternal = async uri => {
2177
+ // @ts-ignore
2178
+ await invoke$1('Open.openExternal', uri);
2539
2179
  };
2540
- const canBeFocused = item => {
2541
- switch (item.flags) {
2542
- case Separator:
2543
- case Disabled:
2544
- return false;
2545
- default:
2546
- return true;
2547
- }
2180
+ const openUrl = async uri => {
2181
+ // @ts-ignore
2182
+ await invoke$1('Open.openUrl', uri);
2548
2183
  };
2549
- const getIndexToFocusNext = menu => {
2550
- const startIndex = menu.focusedIndex + 1;
2551
- return getIndexToFocusNextStartingAt(menu.items, startIndex);
2184
+ const getAllPreferences = async () => {
2185
+ // @ts-ignore
2186
+ return invoke$1('Preferences.getAll');
2552
2187
  };
2553
-
2554
- // TODO handle printable letter and focus item that starts with that letter
2555
-
2556
- // TODO pageup / pagedown keys
2557
-
2558
- // TODO more tests
2559
-
2560
- const menus = [MenuEntriesEdit, MenuEntriesFile, MenuEntriesGo, MenuEntriesHelp, MenuEntriesRun, MenuEntriesSelection, MenuEntriesTerminal, MenuEntriesTitleBar, MenuEntriesView, MenuEntriesOpenRecent];
2561
- const getMenus = () => {
2562
- return menus;
2188
+ const showSaveFilePicker = async () => {
2189
+ // @ts-ignore
2190
+ return invoke$1('FilePicker.showSaveFilePicker');
2563
2191
  };
2564
- const getModule = id => {
2565
- for (const module of menus) {
2566
- if (module.id === id) {
2567
- return module;
2568
- }
2569
- }
2570
- return undefined;
2192
+ const getLogsDir = async () => {
2193
+ // @ts-ignore
2194
+ return invoke$1('PlatformPaths.getLogsDir');
2571
2195
  };
2572
- const getMenuEntries = async (id, ...args) => {
2573
- try {
2574
- const module = getModule(id);
2575
- // @ts-ignore
2576
- const inject = module.inject || [];
2577
- // @ts-ignore
2578
- return module.getMenuEntries(...args);
2579
- } catch (error) {
2580
- throw new VError(error, `Failed to load menu entries for id ${id}`);
2581
- }
2196
+ const registerMockRpc = commandMap => {
2197
+ const mockRpc = createMockRpc({
2198
+ commandMap
2199
+ });
2200
+ set$1(mockRpc);
2201
+ return mockRpc;
2582
2202
  };
2583
2203
 
2584
- const openMenuAtIndex = async (state, index, shouldBeFocused) => {
2585
- const {
2586
- titleBarEntries,
2587
- titleBarHeight,
2588
- x,
2589
- iconWidth
2590
- } = state;
2591
- // TODO race conditions
2592
- // TODO send renderer process
2593
- // 1. open menu, items to show
2594
- // 2. focus menu
2595
- const titleBarEntry = titleBarEntries[index];
2596
- const {
2597
- id
2598
- } = titleBarEntry;
2599
- const items = await getMenuEntries(id);
2600
- const relevantEntries = titleBarEntries.slice(0, index);
2601
- const totalWidths = getTotalWidth(relevantEntries);
2602
- const offset = totalWidths;
2603
- // TODO race condition: another menu might already be open at this point
2204
+ const RendererWorker = {
2205
+ __proto__: null,
2206
+ activateByEvent,
2207
+ applyBulkReplacement,
2208
+ closeWidget,
2209
+ confirm,
2210
+ disableExtension,
2211
+ dispose,
2212
+ enableExtension,
2213
+ getActiveEditorId,
2214
+ getAllExtensions,
2215
+ getAllPreferences,
2216
+ getBlob,
2217
+ getChromeVersion,
2218
+ getColorThemeNames,
2219
+ getElectronVersion,
2220
+ getExtension,
2221
+ getExtensionCommands,
2222
+ getFileHandles,
2223
+ getFileIcon,
2224
+ getFilePathElectron,
2225
+ getFolderIcon,
2226
+ getFolderSize,
2227
+ getIcons,
2228
+ getKeyBindings,
2229
+ getLogsDir,
2230
+ getMarkdownDom,
2231
+ getNodeVersion,
2232
+ getPreference,
2233
+ getRecentlyOpened: getRecentlyOpened$1,
2234
+ getV8Version,
2235
+ getWebViewSecret,
2236
+ getWindowId,
2237
+ getWorkspacePath,
2238
+ handleDebugChange,
2239
+ handleDebugPaused,
2240
+ handleDebugResumed,
2241
+ handleDebugScriptParsed,
2242
+ installExtension,
2243
+ invoke: invoke$1,
2244
+ invokeAndTransfer,
2245
+ openExtensionSearch,
2246
+ openExternal,
2247
+ openNativeFolder,
2248
+ openUri,
2249
+ openUrl,
2250
+ openWidget,
2251
+ readFile,
2252
+ registerMockRpc,
2253
+ registerWebViewInterceptor,
2254
+ renderMarkdown,
2255
+ rerenderEditor,
2256
+ searchFileFetch,
2257
+ searchFileHtml,
2258
+ searchFileMemory,
2259
+ sendMessagePortToEditorWorker,
2260
+ sendMessagePortToErrorWorker,
2261
+ sendMessagePortToExtensionHostWorker,
2262
+ sendMessagePortToFileSystemWorker,
2263
+ sendMessagePortToIconThemeWorker,
2264
+ sendMessagePortToMarkdownWorker,
2265
+ sendMessagePortToRendererProcess,
2266
+ sendMessagePortToSearchProcess,
2267
+ sendMessagePortToSyntaxHighlightingWorker,
2268
+ set: set$1,
2269
+ setAdditionalFocus,
2270
+ setColorTheme,
2271
+ setExtensionsSearchValue,
2272
+ setFocus: setFocus$1,
2273
+ setWebViewPort,
2274
+ setWorkspacePath,
2275
+ showContextMenu,
2276
+ showErrorDialog,
2277
+ showMessageBox,
2278
+ showSaveFilePicker,
2279
+ uninstallExtension,
2280
+ unregisterWebViewInterceptor,
2281
+ writeClipBoardImage,
2282
+ writeClipBoardText
2283
+ };
2604
2284
 
2605
- const menuX = x + offset + iconWidth;
2606
- const menuY = titleBarHeight;
2607
- const width = getMenuWidth();
2608
- const height = getMenuHeight(items);
2609
- const menuFocusedIndex = shouldBeFocused ? getIndexToFocusNextStartingAt(items, 0) : -1;
2610
- const menu = {
2611
- id,
2612
- items,
2613
- focusedIndex: menuFocusedIndex,
2614
- level: 0,
2615
- x: menuX,
2616
- y: menuY,
2617
- width,
2618
- height
2619
- };
2620
- const menus = [menu];
2621
- return {
2622
- ...state,
2623
- isMenuOpen: true,
2624
- focusedIndex: index,
2625
- menus
2626
- };
2285
+ const {
2286
+ invoke,
2287
+ set
2288
+ } = RendererWorker;
2289
+
2290
+ const getRecentlyOpened = () => {
2291
+ return invoke(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
2627
2292
  };
2628
2293
 
2629
- const focusIndex = async (state, index) => {
2630
- object(state);
2631
- number(index);
2632
- const {
2633
- isMenuOpen,
2634
- focusedIndex
2635
- } = state;
2636
- if (index === focusedIndex) {
2637
- return state;
2294
+ const File = 'file://';
2295
+
2296
+ const getTitle = (homeDir, uri) => {
2297
+ if (!uri) {
2298
+ return '';
2638
2299
  }
2639
- if (isMenuOpen) {
2640
- return openMenuAtIndex(state, index, /* focus */false);
2300
+ if (uri.startsWith(File)) {
2301
+ return uri.slice(File.length);
2641
2302
  }
2303
+ return uri;
2304
+ };
2305
+
2306
+ const moreDot = () => {
2307
+ return i18nString(MoreDot);
2308
+ };
2309
+ const clearRecentlyOpened = () => {
2310
+ return i18nString(ClearRecentlyOpened);
2311
+ };
2312
+
2313
+ const getHomeDir = () => {
2314
+ return '';
2315
+ };
2316
+
2317
+ const MAX_MENU_RECENT_ENTRIES = 10;
2318
+ const toMenuItem = folder => {
2319
+ const homeDir = getHomeDir();
2320
+ const label = getTitle(homeDir, folder);
2642
2321
  return {
2643
- ...state,
2644
- focusedIndex: index
2322
+ label,
2323
+ flags: None,
2324
+ command: 'Workspace.setPath',
2325
+ args: [folder]
2645
2326
  };
2646
2327
  };
2328
+ const id$5 = OpenRecent;
2329
+ const getMenuEntries$9 = async () => {
2330
+ const allItems = await getRecentlyOpened();
2331
+ const itemsToShow = allItems.slice(0, MAX_MENU_RECENT_ENTRIES);
2332
+ const items = [];
2333
+ if (itemsToShow.length > 0) {
2334
+ items.push(...itemsToShow.map(toMenuItem), menuEntrySeparator);
2335
+ }
2336
+ items.push({
2337
+ id: 'more',
2338
+ label: moreDot(),
2339
+ flags: None,
2340
+ command: 'QuickPick.showRecent'
2341
+ }, menuEntrySeparator, {
2342
+ id: 'clearRecentlyOpened',
2343
+ label: clearRecentlyOpened(),
2344
+ flags: None,
2345
+ command: 'RecentlyOpened.clearRecentlyOpened'
2346
+ });
2347
+ return items;
2348
+ };
2647
2349
 
2648
- const handleMouseOutMenuClosed = state => {
2649
- return focusIndex(state, -1);
2350
+ const MenuEntriesOpenRecent = {
2351
+ __proto__: null,
2352
+ getMenuEntries: getMenuEntries$9,
2353
+ id: id$5
2650
2354
  };
2651
2355
 
2652
- const handleMouseOutMenuOpen = state => {
2653
- return state;
2356
+ const id$4 = Run;
2357
+ const getMenuEntries$8 = () => {
2358
+ return [];
2654
2359
  };
2655
2360
 
2656
- const ifElse = (menuOpenFunction, menuClosedFunction) => {
2657
- const ifElseFunction = (state, ...args) => {
2658
- const {
2659
- isMenuOpen
2660
- } = state;
2661
- if (isMenuOpen) {
2662
- return menuOpenFunction(state, ...args);
2663
- }
2664
- return menuClosedFunction(state, ...args);
2665
- };
2666
- return ifElseFunction;
2361
+ const MenuEntriesRun = {
2362
+ __proto__: null,
2363
+ getMenuEntries: getMenuEntries$8,
2364
+ id: id$4
2667
2365
  };
2668
2366
 
2669
- const handleMouseOut = ifElse(handleMouseOutMenuOpen, handleMouseOutMenuClosed);
2367
+ const id$3 = Selection;
2368
+ const getMenuEntries$7 = () => {
2369
+ return [{
2370
+ id: 'selectAll',
2371
+ label: selectAll(),
2372
+ flags: None,
2373
+ command: 'Editor.selectAll'
2374
+ }, {
2375
+ id: 'copyLineUp',
2376
+ label: copyLineUp(),
2377
+ flags: None,
2378
+ command: 'Editor.copyLineUp'
2379
+ }, {
2380
+ id: 'copyLineDown',
2381
+ label: copyLineDown(),
2382
+ flags: None,
2383
+ command: 'Editor.copyLineDown'
2384
+ }, {
2385
+ id: 'moveLineUp',
2386
+ label: moveLineUp(),
2387
+ flags: Disabled,
2388
+ command: 'Editor.moveLineUp'
2389
+ }, {
2390
+ id: 'moveLineDown',
2391
+ label: moveLineDown(),
2392
+ flags: Disabled,
2393
+ command: 'Editor.moveLineDown'
2394
+ }];
2395
+ };
2670
2396
 
2671
- const handlePointerOut = (state, clientX, clientY) => {
2672
- const {
2673
- x,
2674
- iconWidth,
2675
- titleBarEntries
2676
- } = state;
2677
- const menuX = getMenuOffset(x, clientX, iconWidth);
2678
- const index = getTitleBarIndexFromPosition(titleBarEntries, menuX);
2679
- if (index === -1) {
2680
- return state;
2681
- }
2682
- return handleMouseOut(state);
2397
+ const MenuEntriesSelection = {
2398
+ __proto__: null,
2399
+ getMenuEntries: getMenuEntries$7,
2400
+ id: id$3
2683
2401
  };
2684
2402
 
2685
- const handleMouseOverMenuClosed = (state, index) => {
2686
- return focusIndex(state, index);
2403
+ const id$2 = Terminal;
2404
+ const getMenuEntries$6 = () => {
2405
+ return [{
2406
+ id: 'newTerminal',
2407
+ label: i18nString(NewTerminal),
2408
+ flags: None,
2409
+ command: 'Layout.togglePanel',
2410
+ args: ['Terminal']
2411
+ }];
2687
2412
  };
2688
2413
 
2689
- const handleMouseOverMenuOpen = async (state, index) => {
2690
- if (index === -1) {
2691
- return state;
2692
- }
2693
- return focusIndex(state, index);
2414
+ const MenuEntriesTerminal = {
2415
+ __proto__: null,
2416
+ getMenuEntries: getMenuEntries$6,
2417
+ id: id$2
2694
2418
  };
2695
2419
 
2696
- const handleMouseOver = ifElse(handleMouseOverMenuOpen, handleMouseOverMenuClosed);
2420
+ const getMenuEntries$5 = () => {
2421
+ return [{
2422
+ id: File$1,
2423
+ label: file(),
2424
+ flags: SubMenu
2425
+ }, {
2426
+ id: Edit,
2427
+ label: edit(),
2428
+ flags: SubMenu
2429
+ }, {
2430
+ id: Selection,
2431
+ label: selection(),
2432
+ flags: SubMenu
2433
+ }, {
2434
+ id: View,
2435
+ label: view(),
2436
+ flags: SubMenu
2437
+ }, {
2438
+ id: Go,
2439
+ label: go(),
2440
+ flags: SubMenu
2441
+ }, {
2442
+ id: Run,
2443
+ label: run(),
2444
+ keyboardShortCut: 'Alt+r',
2445
+ flags: SubMenu
2446
+ }, {
2447
+ id: Terminal,
2448
+ label: terminal(),
2449
+ keyboardShortCut: 'Alt+t',
2450
+ flags: SubMenu
2451
+ }, {
2452
+ id: Help,
2453
+ label: help(),
2454
+ keyboardShortCut: 'Alt+h',
2455
+ flags: SubMenu
2456
+ }];
2457
+ };
2697
2458
 
2698
- const handlePointerOver = (state, clientX, clientY) => {
2699
- const {
2700
- titleBarEntries,
2701
- x,
2702
- iconWidth
2703
- } = state;
2704
- const menuOffset = getMenuOffset(x, clientX, iconWidth);
2705
- const index = getTitleBarIndexFromPosition(titleBarEntries, menuOffset);
2706
- if (index === -1) {
2707
- return state;
2708
- }
2709
- return handleMouseOver(state, index);
2459
+ const getMenuEntries$4 = () => {
2460
+ return [{
2461
+ id: File$1,
2462
+ label: file(),
2463
+ flags: None
2464
+ }, {
2465
+ id: Edit,
2466
+ label: edit(),
2467
+ flags: None
2468
+ }, {
2469
+ id: Selection,
2470
+ label: selection(),
2471
+ flags: None
2472
+ }, {
2473
+ id: View,
2474
+ label: view(),
2475
+ flags: None
2476
+ }, {
2477
+ id: Go,
2478
+ label: go(),
2479
+ flags: None
2480
+ }, {
2481
+ id: Help,
2482
+ label: help(),
2483
+ flags: None
2484
+ }];
2710
2485
  };
2711
2486
 
2712
- const createTextMeasureContext = (letterSpacing, font) => {
2713
- const canvas = new OffscreenCanvas(0, 0);
2714
- const ctx = canvas.getContext('2d');
2715
- if (!ctx) {
2716
- throw new Error('Failed to get canvas context 2d');
2487
+ const getFn = platform => {
2488
+ switch (platform) {
2489
+ case Web:
2490
+ return getMenuEntries$4;
2491
+ default:
2492
+ return getMenuEntries$5;
2717
2493
  }
2718
- ctx.letterSpacing = letterSpacing;
2719
- ctx.font = font;
2720
- return ctx;
2494
+ };
2495
+ const id$1 = TitleBar;
2496
+ const getMenuEntries$3 = async platform => {
2497
+ const fn = getFn(platform);
2498
+ return fn();
2721
2499
  };
2722
2500
 
2723
- const getFontString = (fontWeight, fontSize, fontFamily) => {
2724
- return `${fontWeight} ${fontSize}px ${fontFamily}`;
2501
+ const MenuEntriesTitleBar = {
2502
+ __proto__: null,
2503
+ getMenuEntries: getMenuEntries$3,
2504
+ id: id$1
2725
2505
  };
2726
2506
 
2727
- const measureTextWidths = (texts, fontWeight, fontSize, fontFamily, letterSpacing) => {
2728
- if (typeof letterSpacing !== 'number') {
2729
- throw new TypeError('letterSpacing must be of type number');
2730
- }
2731
- const letterSpacingString = px(letterSpacing);
2732
- const fontString = getFontString(fontWeight, fontSize, fontFamily);
2733
- const ctx = createTextMeasureContext(letterSpacingString, fontString);
2734
- const widths = [];
2735
- for (const text of texts) {
2736
- const metrics = ctx.measureText(text);
2737
- const {
2738
- width
2739
- } = metrics;
2740
- widths.push(width);
2741
- }
2742
- return widths;
2507
+ const id = View;
2508
+ const getMenuEntries$2 = () => {
2509
+ return [];
2743
2510
  };
2744
2511
 
2745
- const getLabel = entry => {
2746
- return entry.label;
2512
+ const MenuEntriesView = {
2513
+ __proto__: null,
2514
+ getMenuEntries: getMenuEntries$2,
2515
+ id
2747
2516
  };
2748
- const addWidths = (entries, labelPadding, fontWeight, fontSize, fontFamily, letterSpacing) => {
2749
- const labels = entries.map(getLabel);
2750
- const widths = measureTextWidths(labels, fontWeight, fontSize, fontFamily, letterSpacing);
2751
- const withWidths = [];
2752
- for (let i = 0; i < entries.length; i++) {
2753
- const entry = entries[i];
2754
- const textWidth = widths[i];
2755
- const width = textWidth + labelPadding * 2;
2756
- withWidths.push({
2757
- ...entry,
2758
- width
2759
- });
2517
+
2518
+ const menus$1 = [MenuEntriesEdit, MenuEntriesFile, MenuEntriesGo, MenuEntriesHelp, MenuEntriesRun, MenuEntriesSelection, MenuEntriesTerminal, MenuEntriesTitleBar, MenuEntriesView, MenuEntriesOpenRecent];
2519
+
2520
+ const getMenuIds = () => {
2521
+ return menus$1.map(menu => menu.id);
2522
+ };
2523
+ const getMenuEntries$1 = async (id, platform) => {
2524
+ const menu = menus$1.find(item => item.id === id);
2525
+ if (!menu) {
2526
+ return [];
2760
2527
  }
2761
- return withWidths;
2528
+ return menu.getMenuEntries(platform);
2762
2529
  };
2763
2530
 
2764
- const loadContent2 = async state => {
2765
- const {
2766
- platform,
2767
- controlsOverlayEnabled,
2768
- titleBarStyleCustom,
2769
- labelFontFamily,
2770
- labelFontSize,
2771
- labelFontWeight,
2772
- labelLetterSpacing,
2773
- labelPadding
2774
- } = state;
2775
- const titleBarEntries = await getMenuEntries(TitleBar$1);
2776
- const withWidths = addWidths(titleBarEntries, labelPadding, labelFontWeight, labelFontSize, labelFontFamily, labelLetterSpacing);
2777
- const buttons = getTitleBarButtons(platform, controlsOverlayEnabled, titleBarStyleCustom);
2778
- const title = 'test';
2779
- const iconWidth = 30;
2531
+ const MaskIconCheck = 'MaskIconCheck';
2532
+ const Menu = 'Menu';
2533
+ const MenuItem = 'MenuItem';
2534
+ const MenuItemCheckMark = 'MenuItemCheckMark';
2535
+ const MenuItemCheckmarkIcon = 'MenuItemCheckmarkIcon';
2536
+ const MenuItemFocused = 'MenuItemFocused';
2537
+ const MenuItemKeyBinding = 'MenuItemKeyBinding';
2538
+ const MenuItemSeparator = 'MenuItemSeparator';
2539
+ const MenuItemSeparatorLine = 'MenuItemSeparatorLine';
2540
+ const MenuItemSubMenu = 'MenuItemSubMenu';
2541
+ const MenuItemSubMenuArrowRight = 'MenuItemSubMenuArrowRight';
2542
+ const TitleBarButtons = 'TitleBarButtons';
2543
+ const TitleBarEntryActive = 'TitleBarEntryActive';
2544
+ const TitleBarIcon = 'TitleBarIcon';
2545
+ const TitleBarIconIcon = 'TitleBarIconIcon';
2546
+ const TitleBarMenuBar$1 = 'TitleBarMenuBar';
2547
+ const TitleBarTopLevelEntry = 'TitleBarTopLevelEntry';
2548
+ const TitleBarTopLevelEntryLabel = 'TitleBarTopLevelEntryLabel';
2549
+ const Viewlet = 'Viewlet';
2550
+
2551
+ const getIconVirtualDom = (icon, type = Div) => {
2780
2552
  return {
2781
- ...state,
2782
- titleBarEntries: withWidths,
2783
- buttons,
2784
- title,
2785
- iconWidth
2553
+ type,
2554
+ className: `MaskIcon MaskIcon${icon}`,
2555
+ role: None$1,
2556
+ childCount: 0
2786
2557
  };
2787
2558
  };
2788
2559
 
2789
- const loadContent = async (state, titleBarEntries) => {
2560
+ const createTitleBarButton = button => {
2790
2561
  const {
2791
- platform,
2792
- controlsOverlayEnabled,
2793
- titleBarStyleCustom,
2794
- labelFontFamily,
2795
- labelFontSize,
2796
- labelFontWeight,
2797
- labelLetterSpacing,
2798
- labelPadding
2799
- } = state;
2800
- const withWidths = addWidths(titleBarEntries, labelPadding, labelFontWeight, labelFontSize, labelFontFamily, labelLetterSpacing);
2801
- const buttons = getTitleBarButtons(platform, controlsOverlayEnabled, titleBarStyleCustom);
2802
- const title = 'test';
2803
- return {
2804
- ...state,
2805
- titleBarEntries: withWidths,
2806
- buttons,
2807
- title
2808
- };
2562
+ id,
2563
+ icon,
2564
+ label,
2565
+ onClick
2566
+ } = button;
2567
+ const dom = [{
2568
+ type: Button$1,
2569
+ className: `TitleBarButton TitleBarButton${id}`,
2570
+ ariaLabel: label,
2571
+ childCount: 1,
2572
+ onClick
2573
+ }, getIconVirtualDom(icon, I)];
2574
+ return dom;
2809
2575
  };
2810
2576
 
2811
- const Ellipsis = 'Ellipsis';
2577
+ const getTitleBarButtonsVirtualDom = buttons => {
2578
+ return [{
2579
+ type: Div,
2580
+ className: mergeClassNames(Viewlet, TitleBarButtons),
2581
+ childCount: buttons.length
2582
+ }, ...buttons.flatMap(createTitleBarButton)];
2583
+ };
2812
2584
 
2813
- const getVisibleTitleBarEntries = (entries, width, focusedIndex, isMenuOpen) => {
2814
- array(entries);
2815
- number(width);
2816
- let total = 0;
2817
- const visible = [];
2818
- for (let i = 0; i < entries.length; i++) {
2819
- const entry = entries[i];
2820
- total += entry.width;
2821
- if (total >= width) {
2822
- break;
2823
- }
2824
- const isOpen = i === focusedIndex && isMenuOpen;
2825
- const isFocused = i === focusedIndex;
2826
- visible.push({
2827
- ...entry,
2828
- isOpen,
2829
- isFocused
2830
- });
2585
+ const parentNode$1 = {
2586
+ type: Div,
2587
+ className: mergeClassNames(Viewlet, TitleBarIcon),
2588
+ childCount: 1
2589
+ };
2590
+ const getTitleBarIconVirtualDom = iconSrc => {
2591
+ return [parentNode$1, {
2592
+ type: Img,
2593
+ className: TitleBarIconIcon,
2594
+ src: iconSrc,
2595
+ alt: '',
2596
+ childCount: 0
2597
+ }];
2598
+ };
2599
+
2600
+ const HandleClick = 1;
2601
+ const HandleClickMinimize = 2;
2602
+ const HandleClickToggleClose = 3;
2603
+ const HandleClickToggleMaximize = 4;
2604
+ const HandleFocusIn = 5;
2605
+ const HandleFocusOut = 6;
2606
+ const HandlePointerOut = 7;
2607
+ const HandlePointerOver = 8;
2608
+ const HandleMenuClick = 9;
2609
+ const HandleMenuMouseOver = 10;
2610
+
2611
+ const getItemVirtualDom = item => {
2612
+ // @ts-ignore
2613
+ const {
2614
+ keyboardShortCut,
2615
+ label,
2616
+ isOpen,
2617
+ isFocused
2618
+ } = item;
2619
+ // TODO avoid mutation
2620
+ const dom = [];
2621
+ dom.push({
2622
+ type: Div,
2623
+ className: TitleBarTopLevelEntry,
2624
+ ariaHasPopup: true,
2625
+ ariaExpanded: isOpen,
2626
+ role: MenuItem$1,
2627
+ childCount: 1,
2628
+ ariaKeyShortcuts: keyboardShortCut
2629
+ });
2630
+ if (isOpen) {
2631
+ // @ts-ignore
2632
+ dom[0].ariaOwns = 'Menu-0';
2831
2633
  }
2832
- const hasOverflow = visible.length < entries.length;
2833
- if (hasOverflow) {
2834
- const padding = 8;
2835
- const moreIconWidth = 22;
2836
- const totalPadding = padding * 2;
2837
- const hasStillOverflow = total + moreIconWidth + totalPadding > width;
2838
- if (hasStillOverflow) {
2839
- visible.pop();
2840
- }
2841
- visible.push({
2842
- ariaLabel: moreDot(),
2843
- icon: Ellipsis,
2844
- label: '',
2845
- width: moreIconWidth + totalPadding
2634
+ if (isFocused) {
2635
+ dom[0].className += ' ' + TitleBarEntryActive;
2636
+ // @ts-ignore
2637
+ dom[0].id = 'TitleBarEntryActive';
2638
+ dom.push({
2639
+ type: Div,
2640
+ className: TitleBarTopLevelEntryLabel,
2641
+ childCount: 1
2846
2642
  });
2847
2643
  }
2848
- return visible;
2644
+ dom.push(text(label));
2645
+ return dom;
2646
+ };
2647
+ const getTitleBarMenuBarItemsVirtualDom = visibleItems => {
2648
+ const dom = visibleItems.flatMap(getItemVirtualDom);
2649
+ return dom;
2650
+ };
2651
+
2652
+ const activeId = 'TitleBarEntryActive';
2653
+ const getTitleBarMenuBarVirtualDom = (visibleItems, focusedIndex) => {
2654
+ return [{
2655
+ type: Div,
2656
+ className: mergeClassNames(Viewlet, TitleBarMenuBar$1),
2657
+ role: MenuBar,
2658
+ tabIndex: 0,
2659
+ childCount: visibleItems.length,
2660
+ onMouseDown: HandleClick,
2661
+ onFocusOut: HandleFocusOut,
2662
+ onFocusIn: HandleFocusIn,
2663
+ onPointerOver: HandlePointerOver,
2664
+ onPointerOut: HandlePointerOut,
2665
+ ariaActivedescendant: focusedIndex === -1 ? '' : activeId
2666
+ }, ...getTitleBarMenuBarItemsVirtualDom(visibleItems)];
2667
+ };
2668
+
2669
+ const parentNode = {
2670
+ type: Div,
2671
+ className: 'TitleBarTitle',
2672
+ childCount: 1
2673
+ };
2674
+ const getTitleVirtualDom = title => {
2675
+ return [parentNode, text(title)];
2849
2676
  };
2850
2677
 
2851
- const renderEntries = (oldState, newState) => {
2852
- const visibleEntries = getVisibleTitleBarEntries(newState.titleBarEntries, newState.width, newState.focusedIndex, newState.isMenuOpen);
2853
- const dom = getTitleBarMenuBarVirtualDom(visibleEntries, newState.focusedIndex);
2854
- return ['Viewlet.setDom2', newState.uid, dom];
2678
+ const maximize = async () => {
2679
+ await invoke('ElectronWindow.maximize');
2680
+ };
2681
+ const minimize = async () => {
2682
+ await invoke('ElectronWindow.minimize');
2683
+ };
2684
+ const close = async () => {
2685
+ await invoke('ElectronWindow.close');
2855
2686
  };
2856
2687
 
2857
- const renderFocusedIndex = (oldState, newState) => {
2858
- if (newState.focusedIndex === -1) {
2859
- return [];
2688
+ const handleClickClose = async state => {
2689
+ await close();
2690
+ return state;
2691
+ };
2692
+
2693
+ const handleClickMinimize = async state => {
2694
+ await minimize();
2695
+ return state;
2696
+ };
2697
+
2698
+ const handleClickToggleMaximize = async state => {
2699
+ const fn = maximize;
2700
+ await fn();
2701
+ return state;
2702
+ };
2703
+
2704
+ // TODO use button name property
2705
+ const handleClick$1 = async (state, className) => {
2706
+ if (className.includes('Minimize')) {
2707
+ return handleClickMinimize(state);
2860
2708
  }
2861
- return ['Viewlet.focusSelector', '.ViewletTitleBarMenuBar'];
2709
+ if (className.includes('Maximize') || className.includes('Restore')) {
2710
+ return handleClickToggleMaximize(state);
2711
+ }
2712
+ if (className.includes('Close')) {
2713
+ return handleClickClose(state);
2714
+ }
2715
+ return state;
2862
2716
  };
2863
2717
 
2864
- const checkboxChecked = {
2865
- type: Div,
2866
- className: mergeClassNames(MenuItem, MenuItemCheckMark),
2867
- role: MenuItemCheckBox,
2868
- ariaChecked: true,
2869
- tabIndex: -1,
2870
- childCount: 2
2718
+ const handleContextMenu = state => {
2719
+ return state;
2871
2720
  };
2872
- const checkMark = {
2873
- type: Div,
2874
- className: mergeClassNames(MenuItemCheckmarkIcon, MaskIconCheck)
2721
+
2722
+ const getMenuOffset = (x, clientX, iconWidth) => {
2723
+ return clientX - x - iconWidth;
2875
2724
  };
2876
- const getMenuItemCheckedDom = menuItem => {
2877
- const {
2878
- label
2879
- } = menuItem;
2880
- return [checkboxChecked, checkMark, text(label)];
2725
+
2726
+ const getTitleBarIndexFromPosition = (titleBarEntries, x, y) => {
2727
+ let currentX = 0;
2728
+ for (let i = 0; i < titleBarEntries.length; i++) {
2729
+ const entry = titleBarEntries[i];
2730
+ const entryWidth = entry.width;
2731
+ if (x >= currentX && x < currentX + entryWidth) {
2732
+ return i;
2733
+ }
2734
+ currentX += entryWidth;
2735
+ }
2736
+ return -1;
2881
2737
  };
2882
2738
 
2883
- const getKeyBindingString = (key, altKey, ctrlKey, shiftKey, metaKey) => {
2884
- let string = '';
2885
- if (ctrlKey) {
2886
- string += 'Ctrl+';
2739
+ const getTotalWidth = entries => {
2740
+ let total = 0;
2741
+ for (const entry of entries) {
2742
+ total += entry.width;
2887
2743
  }
2888
- if (shiftKey) {
2889
- string += 'Shift+';
2744
+ return total;
2745
+ };
2746
+
2747
+ // TODO lazyload menuEntries and use Command.execute (maybe)
2748
+ const CONTEXT_MENU_ITEM_HEIGHT = 26;
2749
+ const CONTEXT_MENU_SEPARATOR_HEIGHT = 11;
2750
+ const CONTEXT_MENU_PADDING = 8;
2751
+ const getMenuHeight = items => {
2752
+ let height = CONTEXT_MENU_PADDING;
2753
+ for (const item of items) {
2754
+ switch (item.flags) {
2755
+ case Separator:
2756
+ height += CONTEXT_MENU_SEPARATOR_HEIGHT;
2757
+ break;
2758
+ default:
2759
+ height += CONTEXT_MENU_ITEM_HEIGHT;
2760
+ break;
2761
+ }
2890
2762
  }
2891
- string += key.toUpperCase();
2892
- return string;
2763
+ return height;
2893
2764
  };
2894
2765
 
2895
- const Backspace$1 = 1;
2896
- const Tab$1 = 2;
2897
- const Enter$1 = 3;
2898
- const Escape$1 = 8;
2899
- const Space$1 = 9;
2900
- const PageUp$1 = 10;
2901
- const PageDown$1 = 11;
2902
- const End$1 = 255;
2903
- const Home$1 = 12;
2904
- const LeftArrow$1 = 13;
2905
- const UpArrow$1 = 14;
2906
- const RightArrow$1 = 15;
2907
- const DownArrow$1 = 16;
2908
- const Insert$1 = 17;
2909
- const Delete$1 = 18;
2910
- const Digit0$1 = 19;
2911
- const Digit1$1 = 20;
2912
- const Digit2$1 = 21;
2913
- const Digit3$1 = 22;
2914
- const Digit4$1 = 23;
2915
- const Digit5$1 = 24;
2916
- const Digit6$1 = 25;
2917
- const Digit7$1 = 26;
2918
- const Digit8$1 = 27;
2919
- const Digit9$1 = 28;
2920
- const KeyA$1 = 29;
2921
- const KeyB$1 = 30;
2922
- const KeyC$1 = 31;
2923
- const KeyD$1 = 32;
2924
- const KeyE$1 = 33;
2925
- const KeyF$1 = 34;
2926
- const KeyG$1 = 35;
2927
- const KeyH$1 = 36;
2928
- const KeyI$1 = 37;
2929
- const KeyJ$1 = 38;
2930
- const KeyK$1 = 39;
2931
- const KeyL$1 = 40;
2932
- const KeyM$1 = 41;
2933
- const KeyN$1 = 42;
2934
- const KeyO$1 = 43;
2935
- const KeyP$1 = 44;
2936
- const KeyQ$1 = 45;
2937
- const KeyR$1 = 46;
2938
- const KeyS$1 = 47;
2939
- const KeyT$1 = 48;
2940
- const KeyU$1 = 49;
2941
- const KeyV$1 = 50;
2942
- const KeyW$1 = 51;
2943
- const KeyX$1 = 52;
2944
- const KeyY$1 = 53;
2945
- const KeyZ$1 = 54;
2946
- const F1$1 = 57;
2947
- const F2$1 = 58;
2948
- const F3$1 = 59;
2949
- const F4$1 = 60;
2950
- const F5$1 = 61;
2951
- const F6$1 = 62;
2952
- const Equal$1 = 84;
2953
- const Comma$1 = 85;
2954
- const Minus$1 = 86;
2955
- const Backquote$1 = 89;
2956
- const Backslash$1 = 91;
2957
- const Star$1 = 131;
2958
- const Plus$1 = 132;
2766
+ // TODO lazyload menuEntries and use Command.execute (maybe)
2767
+ const MENU_WIDTH = 150;
2768
+ const CONTEXT_MENU_WIDTH = 250;
2769
+ const getMenuWidth = () => {
2770
+ return CONTEXT_MENU_WIDTH;
2771
+ };
2959
2772
 
2960
- const Unknown = 'Unknown';
2961
- const Backspace = 'Backspace';
2962
- const Tab = 'Tab';
2963
- const Enter = 'Enter';
2964
- const Escape = 'Escape';
2965
- const Space = 'Space';
2966
- const PageUp = 'PageUp';
2967
- const PageDown = 'PageDown';
2968
- const End = 'End';
2969
- const Home = 'Home';
2970
- const LeftArrow = 'LeftArrow';
2971
- const UpArrow = 'UpArrow';
2972
- const RightArrow = 'RightArrow';
2973
- const DownArrow = 'DownArrow';
2974
- const Insert = 'Insert';
2975
- const Delete = 'Delete';
2976
- const Digit0 = '0';
2977
- const Digit1 = '1';
2978
- const Digit2 = '2';
2979
- const Digit3 = '3';
2980
- const Digit4 = '4';
2981
- const Digit5 = '5';
2982
- const Digit6 = '6';
2983
- const Digit7 = '7';
2984
- const Digit8 = '8';
2985
- const Digit9 = '9';
2986
- const KeyA = 'a';
2987
- const KeyB = 'b';
2988
- const KeyC = 'c';
2989
- const KeyD = 'd';
2990
- const KeyE = 'e';
2991
- const KeyF = 'f';
2992
- const KeyG = 'g';
2993
- const KeyH = 'h';
2994
- const KeyI = 'i';
2995
- const KeyJ = 'j';
2996
- const KeyK = 'k';
2997
- const KeyL = 'l';
2998
- const KeyM = 'm';
2999
- const KeyN = 'n';
3000
- const KeyO = 'o';
3001
- const KeyP = 'p';
3002
- const KeyQ = 'q';
3003
- const KeyR = 'r';
3004
- const KeyS = 's';
3005
- const KeyT = 't';
3006
- const KeyU = 'u';
3007
- const KeyV = 'v';
3008
- const KeyW = 'w';
3009
- const KeyX = 'x';
3010
- const KeyY = 'y';
3011
- const KeyZ = 'z';
3012
- const F1 = 'F1';
3013
- const F2 = 'F2';
3014
- const F3 = 'F3';
3015
- const F4 = 'F4';
3016
- const F5 = 'F5';
3017
- const F6 = 'F6';
3018
- const Equal = '=';
3019
- const Comma = ',';
3020
- const Minus = 'Minus';
3021
- const Backquote = 'Backquote';
3022
- const Backslash = 'Backslash';
3023
- const Star = '*';
3024
- const Plus = '+';
2773
+ // TODO difference between focusing with mouse or keyboard
2774
+ // with mouse -> open submenu
2775
+ // with keyboard -> don't open submenu, only focus
2776
+
2777
+ const getIndexToFocusNextStartingAt = (items, startIndex) => {
2778
+ for (let i = startIndex; i < startIndex + items.length; i++) {
2779
+ const index = i % items.length;
2780
+ const item = items[index];
2781
+ if (canBeFocused(item)) {
2782
+ return index;
2783
+ }
2784
+ }
2785
+ return -1;
2786
+ };
2787
+ const getIndexToFocusFirst = items => {
2788
+ return getIndexToFocusNextStartingAt(items, 0);
2789
+ };
2790
+ const getIndexToFocusLast = items => {
2791
+ return getIndexToFocusPreviousStartingAt(items, items.length - 1);
2792
+ };
3025
2793
 
3026
- const getKeyCodeString = keyCode => {
3027
- switch (keyCode) {
3028
- case Backspace$1:
3029
- return Backspace;
3030
- case Tab$1:
3031
- return Tab;
3032
- case Escape$1:
3033
- return Escape;
3034
- case Enter$1:
3035
- return Enter;
3036
- case Space$1:
3037
- return Space;
3038
- case PageUp$1:
3039
- return PageUp;
3040
- case PageDown$1:
3041
- return PageDown;
3042
- case End$1:
3043
- return End;
3044
- case Home$1:
3045
- return Home;
3046
- case LeftArrow$1:
3047
- return LeftArrow;
3048
- case UpArrow$1:
3049
- return UpArrow;
3050
- case RightArrow$1:
3051
- return RightArrow;
3052
- case DownArrow$1:
3053
- return DownArrow;
3054
- case Insert$1:
3055
- return Insert;
3056
- case Delete$1:
3057
- return Delete;
3058
- case Digit0$1:
3059
- return Digit0;
3060
- case Digit1$1:
3061
- return Digit1;
3062
- case Digit2$1:
3063
- return Digit2;
3064
- case Digit3$1:
3065
- return Digit3;
3066
- case Digit4$1:
3067
- return Digit4;
3068
- case Digit5$1:
3069
- return Digit5;
3070
- case Digit6$1:
3071
- return Digit6;
3072
- case Digit7$1:
3073
- return Digit7;
3074
- case Digit8$1:
3075
- return Digit8;
3076
- case Digit9$1:
3077
- return Digit9;
3078
- case KeyA$1:
3079
- return KeyA;
3080
- case KeyB$1:
3081
- return KeyB;
3082
- case KeyC$1:
3083
- return KeyC;
3084
- case KeyD$1:
3085
- return KeyD;
3086
- case KeyE$1:
3087
- return KeyE;
3088
- case KeyF$1:
3089
- return KeyF;
3090
- case KeyG$1:
3091
- return KeyG;
3092
- case KeyH$1:
3093
- return KeyH;
3094
- case KeyI$1:
3095
- return KeyI;
3096
- case KeyJ$1:
3097
- return KeyJ;
3098
- case KeyK$1:
3099
- return KeyK;
3100
- case KeyL$1:
3101
- return KeyL;
3102
- case KeyM$1:
3103
- return KeyM;
3104
- case KeyN$1:
3105
- return KeyN;
3106
- case KeyO$1:
3107
- return KeyO;
3108
- case KeyP$1:
3109
- return KeyP;
3110
- case KeyQ$1:
3111
- return KeyQ;
3112
- case KeyR$1:
3113
- return KeyR;
3114
- case KeyS$1:
3115
- return KeyS;
3116
- case KeyT$1:
3117
- return KeyT;
3118
- case KeyU$1:
3119
- return KeyU;
3120
- case KeyV$1:
3121
- return KeyV;
3122
- case KeyW$1:
3123
- return KeyW;
3124
- case KeyX$1:
3125
- return KeyX;
3126
- case KeyY$1:
3127
- return KeyY;
3128
- case KeyZ$1:
3129
- return KeyZ;
3130
- case F1$1:
3131
- return F1;
3132
- case F2$1:
3133
- return F2;
3134
- case F3$1:
3135
- return F3;
3136
- case F4$1:
3137
- return F4;
3138
- case F5$1:
3139
- return F5;
3140
- case F6$1:
3141
- return F6;
3142
- case Backslash$1:
3143
- return Backslash;
3144
- case Equal$1:
3145
- return Equal;
3146
- case Comma$1:
3147
- return Comma;
3148
- case Backquote$1:
3149
- return Backquote;
3150
- case Plus$1:
3151
- return Plus;
3152
- case Star$1:
3153
- return Star;
3154
- case Minus$1:
3155
- return Minus;
2794
+ // TODO this code seems a bit too complicated, maybe it can be simplified
2795
+ const getIndexToFocusPreviousStartingAt = (items, startIndex) => {
2796
+ for (let i = startIndex; i > startIndex - items.length; i--) {
2797
+ const index = (i + items.length) % items.length;
2798
+ const item = items[index];
2799
+ if (canBeFocused(item)) {
2800
+ return index;
2801
+ }
2802
+ }
2803
+ return -1;
2804
+ };
2805
+ const getIndexToFocusPrevious = menu => {
2806
+ const startIndex = menu.focusedIndex === -1 ? menu.items.length - 1 : menu.focusedIndex - 1;
2807
+ return getIndexToFocusPreviousStartingAt(menu.items, startIndex);
2808
+ };
2809
+ const canBeFocused = item => {
2810
+ switch (item.flags) {
2811
+ case Separator:
2812
+ case Disabled:
2813
+ return false;
3156
2814
  default:
3157
- return Unknown;
2815
+ return true;
2816
+ }
2817
+ };
2818
+ const getIndexToFocusNext = menu => {
2819
+ const startIndex = menu.focusedIndex + 1;
2820
+ return getIndexToFocusNextStartingAt(menu.items, startIndex);
2821
+ };
2822
+
2823
+ // TODO handle printable letter and focus item that starts with that letter
2824
+
2825
+ // TODO pageup / pagedown keys
2826
+
2827
+ // TODO more tests
2828
+
2829
+ const menus = [MenuEntriesEdit, MenuEntriesFile, MenuEntriesGo, MenuEntriesHelp, MenuEntriesRun, MenuEntriesSelection, MenuEntriesTerminal, MenuEntriesTitleBar, MenuEntriesView, MenuEntriesOpenRecent];
2830
+ const getMenus = () => {
2831
+ return menus;
2832
+ };
2833
+ const getModule = id => {
2834
+ for (const module of menus) {
2835
+ if (module.id === id) {
2836
+ return module;
2837
+ }
2838
+ }
2839
+ return undefined;
2840
+ };
2841
+ const getMenuEntries = async (id, ...args) => {
2842
+ try {
2843
+ const module = getModule(id);
2844
+ // @ts-ignore
2845
+ const inject = module.inject || [];
2846
+ // @ts-ignore
2847
+ return module.getMenuEntries(...args);
2848
+ } catch (error) {
2849
+ throw new VError(error, `Failed to load menu entries for id ${id}`);
2850
+ }
2851
+ };
2852
+
2853
+ const openMenuAtIndex = async (state, index, shouldBeFocused) => {
2854
+ const {
2855
+ titleBarEntries,
2856
+ titleBarHeight,
2857
+ x,
2858
+ iconWidth
2859
+ } = state;
2860
+ // TODO race conditions
2861
+ // TODO send renderer process
2862
+ // 1. open menu, items to show
2863
+ // 2. focus menu
2864
+ const titleBarEntry = titleBarEntries[index];
2865
+ const {
2866
+ id
2867
+ } = titleBarEntry;
2868
+ const items = await getMenuEntries(id);
2869
+ const relevantEntries = titleBarEntries.slice(0, index);
2870
+ const totalWidths = getTotalWidth(relevantEntries);
2871
+ const offset = totalWidths;
2872
+ // TODO race condition: another menu might already be open at this point
2873
+
2874
+ const menuX = x + offset + iconWidth;
2875
+ const menuY = titleBarHeight;
2876
+ const width = getMenuWidth();
2877
+ const height = getMenuHeight(items);
2878
+ const menuFocusedIndex = shouldBeFocused ? getIndexToFocusNextStartingAt(items, 0) : -1;
2879
+ const menu = {
2880
+ id,
2881
+ items,
2882
+ focusedIndex: menuFocusedIndex,
2883
+ level: 0,
2884
+ x: menuX,
2885
+ y: menuY,
2886
+ width,
2887
+ height
2888
+ };
2889
+ const menus = [menu];
2890
+ return {
2891
+ ...state,
2892
+ isMenuOpen: true,
2893
+ focusedIndex: index,
2894
+ menus
2895
+ };
2896
+ };
2897
+
2898
+ const focusIndex = async (state, index) => {
2899
+ object(state);
2900
+ number(index);
2901
+ const {
2902
+ isMenuOpen,
2903
+ focusedIndex
2904
+ } = state;
2905
+ if (index === focusedIndex) {
2906
+ return state;
2907
+ }
2908
+ if (isMenuOpen) {
2909
+ return openMenuAtIndex(state, index, /* focus */false);
3158
2910
  }
2911
+ return {
2912
+ ...state,
2913
+ focusedIndex: index
2914
+ };
3159
2915
  };
3160
2916
 
3161
- const parseKey = rawKey => {
3162
- number(rawKey);
3163
- const isCtrl = Boolean(rawKey & CtrlCmd);
3164
- const isShift = Boolean(rawKey & Shift);
3165
- const keyCode = rawKey & 0x00_00_00_ff;
3166
- const key = getKeyCodeString(keyCode);
2917
+ const handleMouseOutMenuClosed = state => {
2918
+ return focusIndex(state, -1);
2919
+ };
2920
+
2921
+ const handleMouseOutMenuOpen = state => {
2922
+ return state;
2923
+ };
2924
+
2925
+ const ifElse = (menuOpenFunction, menuClosedFunction) => {
2926
+ const ifElseFunction = (state, ...args) => {
2927
+ const {
2928
+ isMenuOpen
2929
+ } = state;
2930
+ if (isMenuOpen) {
2931
+ return menuOpenFunction(state, ...args);
2932
+ }
2933
+ return menuClosedFunction(state, ...args);
2934
+ };
2935
+ return ifElseFunction;
2936
+ };
2937
+
2938
+ const handleMouseOut = ifElse(handleMouseOutMenuOpen, handleMouseOutMenuClosed);
2939
+
2940
+ const handlePointerOut = (state, clientX, clientY) => {
2941
+ const {
2942
+ x,
2943
+ iconWidth,
2944
+ titleBarEntries
2945
+ } = state;
2946
+ const menuX = getMenuOffset(x, clientX, iconWidth);
2947
+ const index = getTitleBarIndexFromPosition(titleBarEntries, menuX);
2948
+ if (index === -1) {
2949
+ return state;
2950
+ }
2951
+ return handleMouseOut(state);
2952
+ };
2953
+
2954
+ const handleMouseOverMenuClosed = (state, index) => {
2955
+ return focusIndex(state, index);
2956
+ };
2957
+
2958
+ const handleMouseOverMenuOpen = async (state, index) => {
2959
+ if (index === -1) {
2960
+ return state;
2961
+ }
2962
+ return focusIndex(state, index);
2963
+ };
2964
+
2965
+ const handleMouseOver = ifElse(handleMouseOverMenuOpen, handleMouseOverMenuClosed);
2966
+
2967
+ const handlePointerOver = (state, clientX, clientY) => {
2968
+ const {
2969
+ titleBarEntries,
2970
+ x,
2971
+ iconWidth
2972
+ } = state;
2973
+ const menuOffset = getMenuOffset(x, clientX, iconWidth);
2974
+ const index = getTitleBarIndexFromPosition(titleBarEntries, menuOffset);
2975
+ if (index === -1) {
2976
+ return state;
2977
+ }
2978
+ return handleMouseOver(state, index);
2979
+ };
2980
+
2981
+ const createTextMeasureContext = (letterSpacing, font) => {
2982
+ const canvas = new OffscreenCanvas(0, 0);
2983
+ const ctx = canvas.getContext('2d');
2984
+ if (!ctx) {
2985
+ throw new Error('Failed to get canvas context 2d');
2986
+ }
2987
+ ctx.letterSpacing = letterSpacing;
2988
+ ctx.font = font;
2989
+ return ctx;
2990
+ };
2991
+
2992
+ const getFontString = (fontWeight, fontSize, fontFamily) => {
2993
+ return `${fontWeight} ${fontSize}px ${fontFamily}`;
2994
+ };
2995
+
2996
+ const measureTextWidths = (texts, fontWeight, fontSize, fontFamily, letterSpacing) => {
2997
+ if (typeof letterSpacing !== 'number') {
2998
+ throw new TypeError('letterSpacing must be of type number');
2999
+ }
3000
+ const letterSpacingString = px(letterSpacing);
3001
+ const fontString = getFontString(fontWeight, fontSize, fontFamily);
3002
+ const ctx = createTextMeasureContext(letterSpacingString, fontString);
3003
+ const widths = [];
3004
+ for (const text of texts) {
3005
+ const metrics = ctx.measureText(text);
3006
+ const {
3007
+ width
3008
+ } = metrics;
3009
+ widths.push(width);
3010
+ }
3011
+ return widths;
3012
+ };
3013
+
3014
+ const getLabel = entry => {
3015
+ return entry.label;
3016
+ };
3017
+ const addWidths = (entries, labelPadding, fontWeight, fontSize, fontFamily, letterSpacing) => {
3018
+ const labels = entries.map(getLabel);
3019
+ const widths = measureTextWidths(labels, fontWeight, fontSize, fontFamily, letterSpacing);
3020
+ const withWidths = [];
3021
+ for (let i = 0; i < entries.length; i++) {
3022
+ const entry = entries[i];
3023
+ const textWidth = widths[i];
3024
+ const width = textWidth + labelPadding * 2;
3025
+ withWidths.push({
3026
+ ...entry,
3027
+ width
3028
+ });
3029
+ }
3030
+ return withWidths;
3031
+ };
3032
+
3033
+ const loadContent2 = async state => {
3034
+ const {
3035
+ platform,
3036
+ controlsOverlayEnabled,
3037
+ titleBarStyleCustom,
3038
+ labelFontFamily,
3039
+ labelFontSize,
3040
+ labelFontWeight,
3041
+ labelLetterSpacing,
3042
+ labelPadding
3043
+ } = state;
3044
+ const titleBarEntries = await getMenuEntries(TitleBar$1);
3045
+ const withWidths = addWidths(titleBarEntries, labelPadding, labelFontWeight, labelFontSize, labelFontFamily, labelLetterSpacing);
3046
+ const buttons = getTitleBarButtons(platform, controlsOverlayEnabled, titleBarStyleCustom);
3047
+ const title = 'test';
3048
+ const iconWidth = 30;
3167
3049
  return {
3168
- key,
3169
- isCtrl,
3170
- isShift
3050
+ ...state,
3051
+ titleBarEntries: withWidths,
3052
+ buttons,
3053
+ title,
3054
+ iconWidth
3055
+ };
3056
+ };
3057
+
3058
+ const loadContent = async (state, titleBarEntries) => {
3059
+ const {
3060
+ platform,
3061
+ controlsOverlayEnabled,
3062
+ titleBarStyleCustom,
3063
+ labelFontFamily,
3064
+ labelFontSize,
3065
+ labelFontWeight,
3066
+ labelLetterSpacing,
3067
+ labelPadding
3068
+ } = state;
3069
+ const withWidths = addWidths(titleBarEntries, labelPadding, labelFontWeight, labelFontSize, labelFontFamily, labelLetterSpacing);
3070
+ const buttons = getTitleBarButtons(platform, controlsOverlayEnabled, titleBarStyleCustom);
3071
+ const title = 'test';
3072
+ return {
3073
+ ...state,
3074
+ titleBarEntries: withWidths,
3075
+ buttons,
3076
+ title
3171
3077
  };
3172
3078
  };
3173
3079
 
3080
+ const Ellipsis = 'Ellipsis';
3081
+
3082
+ const getVisibleTitleBarEntries = (entries, width, focusedIndex, isMenuOpen) => {
3083
+ array(entries);
3084
+ number(width);
3085
+ let total = 0;
3086
+ const visible = [];
3087
+ for (let i = 0; i < entries.length; i++) {
3088
+ const entry = entries[i];
3089
+ total += entry.width;
3090
+ if (total >= width) {
3091
+ break;
3092
+ }
3093
+ const isOpen = i === focusedIndex && isMenuOpen;
3094
+ const isFocused = i === focusedIndex;
3095
+ visible.push({
3096
+ ...entry,
3097
+ isOpen,
3098
+ isFocused
3099
+ });
3100
+ }
3101
+ const hasOverflow = visible.length < entries.length;
3102
+ if (hasOverflow) {
3103
+ const padding = 8;
3104
+ const moreIconWidth = 22;
3105
+ const totalPadding = padding * 2;
3106
+ const hasStillOverflow = total + moreIconWidth + totalPadding > width;
3107
+ if (hasStillOverflow) {
3108
+ visible.pop();
3109
+ }
3110
+ visible.push({
3111
+ ariaLabel: moreDot(),
3112
+ icon: Ellipsis,
3113
+ label: '',
3114
+ width: moreIconWidth + totalPadding
3115
+ });
3116
+ }
3117
+ return visible;
3118
+ };
3119
+
3120
+ const renderEntries = (oldState, newState) => {
3121
+ const visibleEntries = getVisibleTitleBarEntries(newState.titleBarEntries, newState.width, newState.focusedIndex, newState.isMenuOpen);
3122
+ const dom = getTitleBarMenuBarVirtualDom(visibleEntries, newState.focusedIndex);
3123
+ return ['Viewlet.setDom2', newState.uid, dom];
3124
+ };
3125
+
3126
+ const renderFocusedIndex = (oldState, newState) => {
3127
+ if (newState.focusedIndex === -1) {
3128
+ return [];
3129
+ }
3130
+ return ['Viewlet.focusSelector', '.ViewletTitleBarMenuBar'];
3131
+ };
3132
+
3133
+ const checkboxChecked = {
3134
+ type: Div,
3135
+ className: mergeClassNames(MenuItem, MenuItemCheckMark),
3136
+ role: MenuItemCheckBox,
3137
+ ariaChecked: true,
3138
+ tabIndex: -1,
3139
+ childCount: 2
3140
+ };
3141
+ const checkMark = {
3142
+ type: Div,
3143
+ className: mergeClassNames(MenuItemCheckmarkIcon, MaskIconCheck)
3144
+ };
3145
+ const getMenuItemCheckedDom = menuItem => {
3146
+ const {
3147
+ label
3148
+ } = menuItem;
3149
+ return [checkboxChecked, checkMark, text(label)];
3150
+ };
3151
+
3152
+ const getKeyBindingString = (key, altKey, ctrlKey, shiftKey, metaKey) => {
3153
+ let string = '';
3154
+ if (ctrlKey) {
3155
+ string += 'Ctrl+';
3156
+ }
3157
+ if (shiftKey) {
3158
+ string += 'Shift+';
3159
+ }
3160
+ string += key.toUpperCase();
3161
+ return string;
3162
+ };
3163
+
3174
3164
  const getKeyDom = key => {
3175
3165
  const parsedKey = parseKey(key);
3176
3166
  const keyBindingsString = getKeyBindingString(parsedKey.key, false, parsedKey.isCtrl, parsedKey.isShift);