@lvce-editor/title-bar-worker 2.15.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,1915 +1262,1905 @@ 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;
1273
-
1274
- const CtrlCmd = 1 << 11 >>> 0;
1275
- const Shift = 1 << 10 >>> 0;
1276
-
1277
- const TitleBar$1 = 15;
1278
-
1279
- const DebugWorker = 55;
1280
- const RendererWorker$1 = 1;
1281
-
1282
- const mergeClassNames = (...classNames) => {
1283
- return classNames.filter(Boolean).join(' ');
1284
- };
1285
-
1286
- const px = value => {
1287
- return `${value}px`;
1288
- };
1289
-
1290
- const text = data => {
1291
- return {
1292
- type: Text,
1293
- text: data,
1294
- childCount: 0
1295
- };
1296
- };
1297
-
1298
- const FocusTitleBarMenuBar = 26;
1299
-
1300
- const getKeyBindings$1 = () => {
1301
- return [{
1302
- key: DownArrow$2,
1303
- command: 'TitleBar.handleKeyArrowDown',
1304
- when: FocusTitleBarMenuBar
1305
- }, {
1306
- key: UpArrow$2,
1307
- command: 'TitleBar.handleKeyArrowUp',
1308
- when: FocusTitleBarMenuBar
1309
- }, {
1310
- key: RightArrow$2,
1311
- command: 'TitleBar.handleKeyArrowRight',
1312
- when: FocusTitleBarMenuBar
1313
- }, {
1314
- key: LeftArrow$2,
1315
- command: 'TitleBar.handleKeyArrowLeft',
1316
- when: FocusTitleBarMenuBar
1317
- }, {
1318
- key: Space$2,
1319
- command: 'TitleBar.handleKeySpace',
1320
- when: FocusTitleBarMenuBar
1321
- }, {
1322
- key: Home$2,
1323
- command: 'TitleBar.handleKeyHome',
1324
- when: FocusTitleBarMenuBar
1325
- }, {
1326
- key: End$2,
1327
- command: 'TitleBar.handleKeyEnd',
1328
- when: FocusTitleBarMenuBar
1329
- }, {
1330
- key: Escape$2,
1331
- command: 'TitleBar.handleKeyEscape',
1332
- when: FocusTitleBarMenuBar
1333
- }];
1334
- };
1335
-
1336
- /**
1337
- * @enum {string}
1338
- */
1339
- const UiStrings$1 = {
1340
- Copy: 'Copy',
1341
- CopyLineDown: 'Copy Line Down',
1342
- CopyLineUp: 'Copy Line Up',
1343
- Cut: 'Cut',
1344
- MoveLineDown: 'Move Line Down',
1345
- MoveLineUp: 'Move Line Up',
1346
- Paste: 'Paste',
1347
- Redo: 'Redo',
1348
- SelectAll: 'Select All',
1349
- ToggleBlockComment: 'Toggle Block Comment',
1350
- ToggleLineComment: 'Toggle Line Comment',
1351
- Undo: 'Undo'};
1352
- const cut = () => {
1353
- return i18nString(UiStrings$1.Cut);
1354
- };
1355
- const copy = () => {
1356
- return i18nString(UiStrings$1.Copy);
1357
- };
1358
- const paste = () => {
1359
- return i18nString(UiStrings$1.Paste);
1360
- };
1361
- const undo = () => {
1362
- return i18nString(UiStrings$1.Undo);
1363
- };
1364
- const redo = () => {
1365
- return i18nString(UiStrings$1.Redo);
1366
- };
1367
- const toggleLineComment = () => {
1368
- return i18nString(UiStrings$1.ToggleLineComment);
1369
- };
1370
- const toggleBlockComment = () => {
1371
- return i18nString(UiStrings$1.ToggleBlockComment);
1372
- };
1373
- const selectAll = () => {
1374
- return i18nString(UiStrings$1.SelectAll);
1375
- };
1376
- const copyLineUp = () => {
1377
- return i18nString(UiStrings$1.CopyLineUp);
1378
- };
1379
- const copyLineDown = () => {
1380
- return i18nString(UiStrings$1.CopyLineDown);
1381
- };
1382
- const moveLineUp = () => {
1383
- return i18nString(UiStrings$1.MoveLineUp);
1384
- };
1385
- const moveLineDown = () => {
1386
- return i18nString(UiStrings$1.MoveLineDown);
1387
- };
1388
-
1389
- const Edit = 2;
1390
- const File$1 = 5;
1391
- const Go = 6;
1392
- const Help = 7;
1393
- const OpenRecent = 9;
1394
- const Run = 10;
1395
- const Selection = 11;
1396
- const Terminal = 14;
1397
- const TitleBar = 15;
1398
- const View = 16;
1399
-
1400
- const Separator = 1;
1401
- const None = 0;
1402
- const SubMenu = 4;
1403
- const Checked = 2;
1404
- const Unchecked = 3;
1405
- const Disabled = 5;
1406
- const RestoreFocus = 6;
1407
- const Ignore = 7;
1408
-
1409
- const menuEntrySeparator = {
1410
- id: 'separator',
1411
- label: '',
1412
- flags: Separator,
1413
- command: ''
1414
- };
1415
-
1416
- const id$9 = Edit;
1417
- const getMenuEntries$d = () => {
1418
- return [{
1419
- id: 'undo',
1420
- label: undo(),
1421
- flags: Disabled,
1422
- command: /* TODO */'-1'
1423
- }, {
1424
- id: 'redo',
1425
- label: redo(),
1426
- flags: Disabled,
1427
- command: /* TODO */'-1'
1428
- }, menuEntrySeparator, {
1429
- id: 'cut',
1430
- label: cut(),
1431
- flags: None,
1432
- command: /* Editor.cut */'Editor.cut'
1433
- }, {
1434
- id: 'copy',
1435
- label: copy(),
1436
- flags: None,
1437
- command: /* Editor.copy */'Editor.copy'
1438
- }, {
1439
- id: 'paste',
1440
- label: paste(),
1441
- flags: None,
1442
- command: /* Editor.paste */'Editor.paste'
1443
- }, menuEntrySeparator, {
1444
- id: 'toggle-line-comment',
1445
- label: toggleLineComment(),
1446
- flags: None,
1447
- command: /* Editor.toggleLineComment */'Editor.toggleLineComment'
1448
- }, {
1449
- id: 'toggle-block-comment',
1450
- label: toggleBlockComment(),
1451
- flags: None,
1452
- command: /* Editor.toggleBlockComment */'Editor.toggleBlockComment'
1453
- }];
1454
- };
1455
-
1456
- const MenuEntriesEdit = {
1457
- __proto__: null,
1458
- getMenuEntries: getMenuEntries$d,
1459
- id: id$9
1460
- };
1461
-
1462
- /**
1463
- * @enum {string}
1464
- */
1465
- const UiStrings = {
1466
- NewFile: 'New File',
1467
- NewWindow: 'New Window',
1468
- OpenFile: 'Open File',
1469
- OpenFolder: 'Open Folder',
1470
- OpenRecent: 'Open Recent',
1471
- Exit: 'Exit',
1472
- Save: 'Save',
1473
- SaveAll: 'Save All'
1474
- };
1475
- const newFile = () => {
1476
- return i18nString(UiStrings.NewFile);
1477
- };
1478
- const newWindow = () => {
1479
- return i18nString(UiStrings.NewWindow);
1480
- };
1481
- const openFile = () => {
1482
- return i18nString(UiStrings.OpenFile);
1483
- };
1484
- const openFolder = () => {
1485
- return i18nString(UiStrings.OpenFolder);
1486
- };
1487
- const openRecent = () => {
1488
- return i18nString(UiStrings.OpenRecent);
1489
- };
1490
- const save = () => {
1491
- return i18nString(UiStrings.Save);
1492
- };
1493
- const saveAll = () => {
1494
- return i18nString(UiStrings.SaveAll);
1495
- };
1496
- const exit = () => {
1497
- return i18nString(UiStrings.Exit);
1498
- };
1499
-
1500
- const id$8 = File$1;
1501
- const getMenuEntries$c = platform => {
1502
- const entries = [{
1503
- id: 'newFile',
1504
- label: newFile(),
1505
- flags: None,
1506
- command: '-1'
1507
- }, {
1508
- id: 'newWindow',
1509
- label: newWindow(),
1510
- flags: None,
1511
- command: /* Window.openNew */'Window.openNew'
1512
- }, menuEntrySeparator, {
1513
- id: 'openFile',
1514
- label: openFile(),
1515
- flags: None,
1516
- command: 'Dialog.openFile'
1517
- }, {
1518
- id: 'openFolder',
1519
- label: openFolder(),
1520
- flags: RestoreFocus,
1521
- command: 'Dialog.openFolder'
1522
- }, {
1523
- id: OpenRecent,
1524
- label: openRecent(),
1525
- flags: SubMenu,
1526
- command: ''
1527
- }, menuEntrySeparator, {
1528
- id: 'save',
1529
- label: save(),
1530
- flags: None,
1531
- command: 'Main.save'
1532
- }, {
1533
- id: 'saveAll',
1534
- label: saveAll(),
1535
- flags: None,
1536
- command: 'Main.saveAll'
1537
- }];
1538
- if (platform === Electron) {
1539
- entries.push(menuEntrySeparator, {
1540
- id: 'exit',
1541
- label: exit(),
1542
- flags: Ignore,
1543
- command: 'Chrome.exit'
1544
- });
1545
- }
1546
- return entries;
1547
- };
1548
-
1549
- const MenuEntriesFile = {
1550
- __proto__: null,
1551
- getMenuEntries: getMenuEntries$c,
1552
- id: id$8
1553
- };
1554
-
1555
- const id$7 = Go;
1556
- const getMenuEntries$b = () => {
1557
- return [];
1558
- };
1559
-
1560
- const MenuEntriesGo = {
1561
- __proto__: null,
1562
- getMenuEntries: getMenuEntries$b,
1563
- id: id$7
1564
- };
1565
-
1566
- const toggleDeveloperTools = () => {
1567
- return i18nString(ToggleDeveloperTools);
1568
- };
1569
- const openProcessExplorer = () => {
1570
- return i18nString(OpenProcessExplorer);
1571
- };
1572
- const checkForUpdates = () => {
1573
- return i18nString(CheckForUpdates);
1574
- };
1575
- const about = () => {
1576
- return i18nString(About);
1577
- };
1578
-
1579
- const isAutoUpdateSupported = platform => {
1580
- if (platform !== Electron) {
1581
- return false;
1582
- }
1583
- return false;
1584
- };
1585
-
1586
- const id$6 = Help;
1587
- const getMenuEntries$a = async platform => {
1588
- const autoUpdateSupported = isAutoUpdateSupported(platform);
1589
- const entries = [];
1590
- if (platform !== Web) {
1591
- entries.push({
1592
- id: 'toggleDeveloperTools',
1593
- label: toggleDeveloperTools(),
1594
- flags: None,
1595
- command: 'Developer.toggleDeveloperTools'
1596
- }, {
1597
- id: 'openProcessExplorer',
1598
- label: openProcessExplorer(),
1599
- flags: RestoreFocus,
1600
- command: 'Developer.openProcessExplorer'
1601
- });
1602
- }
1603
- if (autoUpdateSupported) {
1604
- 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
- };
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;
1628
1329
 
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
- };
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 = '+';
1636
1395
 
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
- };
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
+ }
1659
1529
  };
1660
1530
 
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);
1849
- };
1850
- const sendMessagePortToSyntaxHighlightingWorker = async port => {
1851
- await invokeAndTransfer(
1852
- // @ts-ignore
1853
- 'SendMessagePortToSyntaxHighlightingWorker.sendMessagePortToSyntaxHighlightingWorker', port, 'HandleMessagePort.handleMessagePort2');
1854
- };
1855
- const handleDebugScriptParsed = async script => {
1856
- await invoke$1('Run And Debug.handleScriptParsed', script);
1857
- };
1858
- const getWindowId = async () => {
1859
- return invoke$1('GetWindowId.getWindowId');
1860
- };
1861
- const getBlob = async uri => {
1862
- // @ts-ignore
1863
- return invoke$1('FileSystem.getBlob', uri);
1864
- };
1865
- const getExtensionCommands = async () => {
1866
- return invoke$1('ExtensionHost.getCommands');
1867
- };
1868
- const showErrorDialog = async errorInfo => {
1869
- // @ts-ignore
1870
- await invoke$1('ErrorHandling.showErrorDialog', errorInfo);
1871
- };
1872
- const getFolderSize = async uri => {
1873
- // @ts-ignore
1874
- return await invoke$1('FileSystem.getFolderSize', uri);
1875
- };
1876
- const getExtension = async id => {
1877
- // @ts-ignore
1878
- return invoke$1('ExtensionManagement.getExtension', id);
1879
- };
1880
- const getMarkdownDom = async html => {
1881
- // @ts-ignore
1882
- return invoke$1('Markdown.getVirtualDom', html);
1883
- };
1884
- const renderMarkdown = async (markdown, options) => {
1885
- // @ts-ignore
1886
- return invoke$1('Markdown.renderMarkdown', markdown, options);
1887
- };
1888
- const openNativeFolder = async uri => {
1889
- // @ts-ignore
1890
- await invoke$1('OpenNativeFolder.openNativeFolder', uri);
1891
- };
1892
- const uninstallExtension = async id => {
1893
- return invoke$1('ExtensionManagement.uninstall', id);
1894
- };
1895
- const installExtension = async id => {
1896
- // @ts-ignore
1897
- return invoke$1('ExtensionManagement.install', id);
1531
+ const CtrlCmd = 1 << 11 >>> 0;
1532
+ const Shift = 1 << 10 >>> 0;
1533
+
1534
+ const TitleBar$1 = 15;
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
+ };
1898
1546
  };
1899
- const openExtensionSearch = async () => {
1900
- // @ts-ignore
1901
- return invoke$1('SideBar.openViewlet', 'Extensions');
1547
+
1548
+ const DebugWorker = 55;
1549
+ const RendererWorker$1 = 1;
1550
+
1551
+ const mergeClassNames = (...classNames) => {
1552
+ return classNames.filter(Boolean).join(' ');
1902
1553
  };
1903
- const setExtensionsSearchValue = async searchValue => {
1904
- // @ts-ignore
1905
- return invoke$1('Extensions.handleInput', searchValue);
1554
+
1555
+ const px = value => {
1556
+ return `${value}px`;
1906
1557
  };
1907
- const openExternal = async uri => {
1908
- // @ts-ignore
1909
- await invoke$1('Open.openExternal', uri);
1558
+
1559
+ const text = data => {
1560
+ return {
1561
+ type: Text,
1562
+ text: data,
1563
+ childCount: 0
1564
+ };
1910
1565
  };
1911
- const openUrl = async uri => {
1912
- // @ts-ignore
1913
- await invoke$1('Open.openUrl', uri);
1566
+
1567
+ const FocusTitleBarMenuBar = 26;
1568
+
1569
+ const getKeyBindings$1 = () => {
1570
+ return [{
1571
+ key: DownArrow$1,
1572
+ command: 'TitleBar.handleKeyArrowDown',
1573
+ when: FocusTitleBarMenuBar
1574
+ }, {
1575
+ key: UpArrow$1,
1576
+ command: 'TitleBar.handleKeyArrowUp',
1577
+ when: FocusTitleBarMenuBar
1578
+ }, {
1579
+ key: RightArrow$1,
1580
+ command: 'TitleBar.handleKeyArrowRight',
1581
+ when: FocusTitleBarMenuBar
1582
+ }, {
1583
+ key: LeftArrow$1,
1584
+ command: 'TitleBar.handleKeyArrowLeft',
1585
+ when: FocusTitleBarMenuBar
1586
+ }, {
1587
+ key: Space$1,
1588
+ command: 'TitleBar.handleKeySpace',
1589
+ when: FocusTitleBarMenuBar
1590
+ }, {
1591
+ key: Home$1,
1592
+ command: 'TitleBar.handleKeyHome',
1593
+ when: FocusTitleBarMenuBar
1594
+ }, {
1595
+ key: End$1,
1596
+ command: 'TitleBar.handleKeyEnd',
1597
+ when: FocusTitleBarMenuBar
1598
+ }, {
1599
+ key: Escape$1,
1600
+ command: 'TitleBar.handleKeyEscape',
1601
+ when: FocusTitleBarMenuBar
1602
+ }];
1914
1603
  };
1915
- const getAllPreferences = async () => {
1916
- // @ts-ignore
1917
- return invoke$1('Preferences.getAll');
1604
+
1605
+ /**
1606
+ * @enum {string}
1607
+ */
1608
+ const UiStrings$1 = {
1609
+ Copy: 'Copy',
1610
+ CopyLineDown: 'Copy Line Down',
1611
+ CopyLineUp: 'Copy Line Up',
1612
+ Cut: 'Cut',
1613
+ MoveLineDown: 'Move Line Down',
1614
+ MoveLineUp: 'Move Line Up',
1615
+ Paste: 'Paste',
1616
+ Redo: 'Redo',
1617
+ SelectAll: 'Select All',
1618
+ ToggleBlockComment: 'Toggle Block Comment',
1619
+ ToggleLineComment: 'Toggle Line Comment',
1620
+ Undo: 'Undo'};
1621
+ const cut = () => {
1622
+ return i18nString(UiStrings$1.Cut);
1918
1623
  };
1919
- const showSaveFilePicker = async () => {
1920
- // @ts-ignore
1921
- return invoke$1('FilePicker.showSaveFilePicker');
1624
+ const copy = () => {
1625
+ return i18nString(UiStrings$1.Copy);
1922
1626
  };
1923
- const getLogsDir = async () => {
1924
- // @ts-ignore
1925
- return invoke$1('PlatformPaths.getLogsDir');
1627
+ const paste = () => {
1628
+ return i18nString(UiStrings$1.Paste);
1926
1629
  };
1927
- const registerMockRpc = commandMap => {
1928
- const mockRpc = createMockRpc({
1929
- commandMap
1930
- });
1931
- set$1(mockRpc);
1932
- return mockRpc;
1630
+ const undo = () => {
1631
+ return i18nString(UiStrings$1.Undo);
1933
1632
  };
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
1633
+ const redo = () => {
1634
+ return i18nString(UiStrings$1.Redo);
2014
1635
  };
2015
-
2016
- const {
2017
- invoke,
2018
- set
2019
- } = RendererWorker;
2020
-
2021
- const getRecentlyOpened = () => {
2022
- return invoke(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
1636
+ const toggleLineComment = () => {
1637
+ return i18nString(UiStrings$1.ToggleLineComment);
2023
1638
  };
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;
1639
+ const toggleBlockComment = () => {
1640
+ return i18nString(UiStrings$1.ToggleBlockComment);
2035
1641
  };
2036
-
2037
- const moreDot = () => {
2038
- return i18nString(MoreDot);
1642
+ const selectAll = () => {
1643
+ return i18nString(UiStrings$1.SelectAll);
2039
1644
  };
2040
- const clearRecentlyOpened = () => {
2041
- return i18nString(ClearRecentlyOpened);
1645
+ const copyLineUp = () => {
1646
+ return i18nString(UiStrings$1.CopyLineUp);
2042
1647
  };
2043
-
2044
- const getHomeDir = () => {
2045
- return '';
1648
+ const copyLineDown = () => {
1649
+ return i18nString(UiStrings$1.CopyLineDown);
2046
1650
  };
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
- };
1651
+ const moveLineUp = () => {
1652
+ return i18nString(UiStrings$1.MoveLineUp);
2058
1653
  };
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;
1654
+ const moveLineDown = () => {
1655
+ return i18nString(UiStrings$1.MoveLineDown);
2079
1656
  };
2080
1657
 
2081
- const MenuEntriesOpenRecent = {
2082
- __proto__: null,
2083
- getMenuEntries: getMenuEntries$9,
2084
- id: id$5
2085
- };
1658
+ const Edit = 2;
1659
+ const File$1 = 5;
1660
+ const Go = 6;
1661
+ const Help = 7;
1662
+ const OpenRecent = 9;
1663
+ const Run = 10;
1664
+ const Selection = 11;
1665
+ const Terminal = 14;
1666
+ const TitleBar = 15;
1667
+ const View = 16;
2086
1668
 
2087
- const id$4 = Run;
2088
- const getMenuEntries$8 = () => {
2089
- return [];
2090
- };
1669
+ const Separator = 1;
1670
+ const None = 0;
1671
+ const SubMenu = 4;
1672
+ const Checked = 2;
1673
+ const Unchecked = 3;
1674
+ const Disabled = 5;
1675
+ const RestoreFocus = 6;
1676
+ const Ignore = 7;
2091
1677
 
2092
- const MenuEntriesRun = {
2093
- __proto__: null,
2094
- getMenuEntries: getMenuEntries$8,
2095
- id: id$4
1678
+ const menuEntrySeparator = {
1679
+ id: 'separator',
1680
+ label: '',
1681
+ flags: Separator,
1682
+ command: ''
2096
1683
  };
2097
1684
 
2098
- const id$3 = Selection;
2099
- const getMenuEntries$7 = () => {
1685
+ const id$9 = Edit;
1686
+ const getMenuEntries$d = () => {
2100
1687
  return [{
2101
- id: 'selectAll',
2102
- label: selectAll(),
2103
- flags: None,
2104
- command: 'Editor.selectAll'
1688
+ id: 'undo',
1689
+ label: undo(),
1690
+ flags: Disabled,
1691
+ command: /* TODO */'-1'
2105
1692
  }, {
2106
- id: 'copyLineUp',
2107
- label: copyLineUp(),
1693
+ id: 'redo',
1694
+ label: redo(),
1695
+ flags: Disabled,
1696
+ command: /* TODO */'-1'
1697
+ }, menuEntrySeparator, {
1698
+ id: 'cut',
1699
+ label: cut(),
2108
1700
  flags: None,
2109
- command: 'Editor.copyLineUp'
1701
+ command: /* Editor.cut */'Editor.cut'
2110
1702
  }, {
2111
- id: 'copyLineDown',
2112
- label: copyLineDown(),
1703
+ id: 'copy',
1704
+ label: copy(),
2113
1705
  flags: None,
2114
- command: 'Editor.copyLineDown'
1706
+ command: /* Editor.copy */'Editor.copy'
2115
1707
  }, {
2116
- id: 'moveLineUp',
2117
- label: moveLineUp(),
2118
- flags: Disabled,
2119
- command: 'Editor.moveLineUp'
1708
+ id: 'paste',
1709
+ label: paste(),
1710
+ flags: None,
1711
+ command: /* Editor.paste */'Editor.paste'
1712
+ }, menuEntrySeparator, {
1713
+ id: 'toggle-line-comment',
1714
+ label: toggleLineComment(),
1715
+ flags: None,
1716
+ command: /* Editor.toggleLineComment */'Editor.toggleLineComment'
2120
1717
  }, {
2121
- id: 'moveLineDown',
2122
- label: moveLineDown(),
2123
- flags: Disabled,
2124
- command: 'Editor.moveLineDown'
1718
+ id: 'toggle-block-comment',
1719
+ label: toggleBlockComment(),
1720
+ flags: None,
1721
+ command: /* Editor.toggleBlockComment */'Editor.toggleBlockComment'
2125
1722
  }];
2126
1723
  };
2127
1724
 
2128
- const MenuEntriesSelection = {
1725
+ const MenuEntriesEdit = {
2129
1726
  __proto__: null,
2130
- getMenuEntries: getMenuEntries$7,
2131
- id: id$3
1727
+ getMenuEntries: getMenuEntries$d,
1728
+ id: id$9
2132
1729
  };
2133
1730
 
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
- }];
1731
+ /**
1732
+ * @enum {string}
1733
+ */
1734
+ const UiStrings = {
1735
+ NewFile: 'New File',
1736
+ NewWindow: 'New Window',
1737
+ OpenFile: 'Open File',
1738
+ OpenFolder: 'Open Folder',
1739
+ OpenRecent: 'Open Recent',
1740
+ Exit: 'Exit',
1741
+ Save: 'Save',
1742
+ SaveAll: 'Save All'
2143
1743
  };
2144
-
2145
- const MenuEntriesTerminal = {
2146
- __proto__: null,
2147
- getMenuEntries: getMenuEntries$6,
2148
- id: id$2
1744
+ const newFile = () => {
1745
+ return i18nString(UiStrings.NewFile);
2149
1746
  };
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
- }];
1747
+ const newWindow = () => {
1748
+ return i18nString(UiStrings.NewWindow);
1749
+ };
1750
+ const openFile = () => {
1751
+ return i18nString(UiStrings.OpenFile);
1752
+ };
1753
+ const openFolder = () => {
1754
+ return i18nString(UiStrings.OpenFolder);
1755
+ };
1756
+ const openRecent = () => {
1757
+ return i18nString(UiStrings.OpenRecent);
1758
+ };
1759
+ const save = () => {
1760
+ return i18nString(UiStrings.Save);
1761
+ };
1762
+ const saveAll = () => {
1763
+ return i18nString(UiStrings.SaveAll);
1764
+ };
1765
+ const exit = () => {
1766
+ return i18nString(UiStrings.Exit);
2188
1767
  };
2189
1768
 
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
1769
+ const id$8 = File$1;
1770
+ const getMenuEntries$c = platform => {
1771
+ const entries = [{
1772
+ id: 'newFile',
1773
+ label: newFile(),
1774
+ flags: None,
1775
+ command: '-1'
2199
1776
  }, {
2200
- id: Selection,
2201
- label: selection(),
2202
- flags: None
1777
+ id: 'newWindow',
1778
+ label: newWindow(),
1779
+ flags: None,
1780
+ command: /* Window.openNew */'Window.openNew'
1781
+ }, menuEntrySeparator, {
1782
+ id: 'openFile',
1783
+ label: openFile(),
1784
+ flags: None,
1785
+ command: 'Dialog.openFile'
2203
1786
  }, {
2204
- id: View,
2205
- label: view(),
2206
- flags: None
1787
+ id: 'openFolder',
1788
+ label: openFolder(),
1789
+ flags: RestoreFocus,
1790
+ command: 'Dialog.openFolder'
2207
1791
  }, {
2208
- id: Go,
2209
- label: go(),
2210
- flags: None
1792
+ id: OpenRecent,
1793
+ label: openRecent(),
1794
+ flags: SubMenu,
1795
+ command: ''
1796
+ }, menuEntrySeparator, {
1797
+ id: 'save',
1798
+ label: save(),
1799
+ flags: None,
1800
+ command: 'Main.save'
2211
1801
  }, {
2212
- id: Help,
2213
- label: help(),
2214
- flags: None
1802
+ id: 'saveAll',
1803
+ label: saveAll(),
1804
+ flags: None,
1805
+ command: 'Main.saveAll'
2215
1806
  }];
2216
- };
2217
-
2218
- const getFn = platform => {
2219
- switch (platform) {
2220
- case Web:
2221
- return getMenuEntries$4;
2222
- default:
2223
- return getMenuEntries$5;
1807
+ if (platform === Electron) {
1808
+ entries.push(menuEntrySeparator, {
1809
+ id: 'exit',
1810
+ label: exit(),
1811
+ flags: Ignore,
1812
+ command: 'Chrome.exit'
1813
+ });
2224
1814
  }
2225
- };
2226
- const id$1 = TitleBar;
2227
- const getMenuEntries$3 = async platform => {
2228
- const fn = getFn(platform);
2229
- return fn();
1815
+ return entries;
2230
1816
  };
2231
1817
 
2232
- const MenuEntriesTitleBar = {
1818
+ const MenuEntriesFile = {
2233
1819
  __proto__: null,
2234
- getMenuEntries: getMenuEntries$3,
2235
- id: id$1
1820
+ getMenuEntries: getMenuEntries$c,
1821
+ id: id$8
2236
1822
  };
2237
1823
 
2238
- const id = View;
2239
- const getMenuEntries$2 = () => {
1824
+ const id$7 = Go;
1825
+ const getMenuEntries$b = () => {
2240
1826
  return [];
2241
1827
  };
2242
1828
 
2243
- const MenuEntriesView = {
1829
+ const MenuEntriesGo = {
2244
1830
  __proto__: null,
2245
- getMenuEntries: getMenuEntries$2,
2246
- id
1831
+ getMenuEntries: getMenuEntries$b,
1832
+ id: id$7
2247
1833
  };
2248
1834
 
2249
- const menus$1 = [MenuEntriesEdit, MenuEntriesFile, MenuEntriesGo, MenuEntriesHelp, MenuEntriesRun, MenuEntriesSelection, MenuEntriesTerminal, MenuEntriesTitleBar, MenuEntriesView, MenuEntriesOpenRecent];
1835
+ const toggleDeveloperTools = () => {
1836
+ return i18nString(ToggleDeveloperTools);
1837
+ };
1838
+ const openProcessExplorer = () => {
1839
+ return i18nString(OpenProcessExplorer);
1840
+ };
1841
+ const checkForUpdates = () => {
1842
+ return i18nString(CheckForUpdates);
1843
+ };
1844
+ const about = () => {
1845
+ return i18nString(About);
1846
+ };
2250
1847
 
2251
- const getMenuIds = () => {
2252
- return menus$1.map(menu => menu.id);
1848
+ const isAutoUpdateSupported = platform => {
1849
+ if (platform !== Electron) {
1850
+ return false;
1851
+ }
1852
+ return false;
2253
1853
  };
2254
- const getMenuEntries$1 = (id, platform) => {
2255
- const menu = menus$1.find(item => item.id === id);
2256
- if (!menu) {
2257
- return [];
1854
+
1855
+ const id$6 = Help;
1856
+ const getMenuEntries$a = async platform => {
1857
+ const autoUpdateSupported = isAutoUpdateSupported(platform);
1858
+ const entries = [];
1859
+ if (platform !== Web) {
1860
+ entries.push({
1861
+ id: 'toggleDeveloperTools',
1862
+ label: toggleDeveloperTools(),
1863
+ flags: None,
1864
+ command: 'Developer.toggleDeveloperTools'
1865
+ }, {
1866
+ id: 'openProcessExplorer',
1867
+ label: openProcessExplorer(),
1868
+ flags: RestoreFocus,
1869
+ command: 'Developer.openProcessExplorer'
1870
+ });
2258
1871
  }
2259
- return menu.getMenuEntries(platform);
1872
+ if (autoUpdateSupported) {
1873
+ entries.push(menuEntrySeparator, {
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;
2260
1890
  };
2261
1891
 
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';
1892
+ const MenuEntriesHelp = {
1893
+ __proto__: null,
1894
+ getMenuEntries: getMenuEntries$a,
1895
+ id: id$6
1896
+ };
2281
1897
 
2282
- const getIconVirtualDom = (icon, type = Div) => {
1898
+ const rpcs = Object.create(null);
1899
+ const set$2 = (id, rpc) => {
1900
+ rpcs[id] = rpc;
1901
+ };
1902
+ const get = id => {
1903
+ return rpcs[id];
1904
+ };
1905
+
1906
+ const create$1 = rpcId => {
2283
1907
  return {
2284
- type,
2285
- className: `MaskIcon MaskIcon${icon}`,
2286
- role: None$1,
2287
- childCount: 0
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
+ }
2288
1927
  };
2289
1928
  };
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;
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);
1938
+ };
1939
+ const getFilePathElectron = async file => {
1940
+ return invoke$1('FileSystemHandle.getFilePathElectron', file);
1941
+ };
1942
+ const showContextMenu = async (x, y, id, ...args) => {
1943
+ return invoke$1('ContextMenu.show', x, y, id, ...args);
1944
+ };
1945
+ const getElectronVersion = async () => {
1946
+ return invoke$1('Process.getElectronVersion');
1947
+ };
1948
+ const applyBulkReplacement = async bulkEdits => {
1949
+ await invoke$1('BulkReplacement.applyBulkReplacement', bulkEdits);
1950
+ };
1951
+ const setColorTheme = async id => {
1952
+ // @ts-ignore
1953
+ return invoke$1(/* ColorTheme.setColorTheme */'ColorTheme.setColorTheme', /* colorThemeId */id);
1954
+ };
1955
+ const getNodeVersion = async () => {
1956
+ return invoke$1('Process.getNodeVersion');
1957
+ };
1958
+ const getChromeVersion = async () => {
1959
+ return invoke$1('Process.getChromeVersion');
1960
+ };
1961
+ const getV8Version = async () => {
1962
+ return invoke$1('Process.getV8Version');
1963
+ };
1964
+ const getFileHandles = async fileIds => {
1965
+ const files = await invoke$1('FileSystemHandle.getFileHandles', fileIds);
1966
+ return files;
1967
+ };
1968
+ const setWorkspacePath = async path => {
1969
+ await invoke$1('Workspace.setPath', path);
1970
+ };
1971
+ const registerWebViewInterceptor = async (id, port) => {
1972
+ await invokeAndTransfer('WebView.registerInterceptor', id, port);
1973
+ };
1974
+ const unregisterWebViewInterceptor = async id => {
1975
+ await invoke$1('WebView.unregisterInterceptor', id);
1976
+ };
1977
+ const sendMessagePortToEditorWorker = async (port, rpcId) => {
1978
+ const command = 'HandleMessagePort.handleMessagePort';
1979
+ // @ts-ignore
1980
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToEditorWorker', port, command, rpcId);
1981
+ };
1982
+ const sendMessagePortToErrorWorker = async (port, rpcId) => {
1983
+ const command = 'Errors.handleMessagePort';
1984
+ // @ts-ignore
1985
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToErrorWorker', port, command, rpcId);
1986
+ };
1987
+ const sendMessagePortToMarkdownWorker = async (port, rpcId) => {
1988
+ const command = 'Markdown.handleMessagePort';
1989
+ // @ts-ignore
1990
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToMarkdownWorker', port, command, rpcId);
1991
+ };
1992
+ const sendMessagePortToIconThemeWorker = async (port, rpcId) => {
1993
+ const command = 'IconTheme.handleMessagePort';
1994
+ // @ts-ignore
1995
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToIconThemeWorker', port, command, rpcId);
1996
+ };
1997
+ const sendMessagePortToFileSystemWorker = async (port, rpcId) => {
1998
+ const command = 'FileSystem.handleMessagePort';
1999
+ // @ts-ignore
2000
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToFileSystemWorker', port, command, rpcId);
2001
+ };
2002
+ const readFile = async uri => {
2003
+ return invoke$1('FileSystem.readFile', uri);
2004
+ };
2005
+ const getWebViewSecret = async key => {
2006
+ // @ts-ignore
2007
+ return invoke$1('WebView.getSecret', key);
2008
+ };
2009
+ const setWebViewPort = async (uid, port, origin, portType) => {
2010
+ return invokeAndTransfer('WebView.setPort', uid, port, origin, portType);
2011
+ };
2012
+ const setFocus$1 = key => {
2013
+ return invoke$1('Focus.setFocus', key);
2014
+ };
2015
+ const getFileIcon = async options => {
2016
+ return invoke$1('IconTheme.getFileIcon', options);
2017
+ };
2018
+ const getColorThemeNames = async () => {
2019
+ return invoke$1('ColorTheme.getColorThemeNames');
2020
+ };
2021
+ const disableExtension = async id => {
2022
+ // @ts-ignore
2023
+ return invoke$1('ExtensionManagement.disable', id);
2024
+ };
2025
+ const enableExtension = async id => {
2026
+ // @ts-ignore
2027
+ return invoke$1('ExtensionManagement.enable', id);
2028
+ };
2029
+ const handleDebugChange = async params => {
2030
+ // @ts-ignore
2031
+ return invoke$1('Run And Debug.handleChange', params);
2032
+ };
2033
+ const getFolderIcon = async options => {
2034
+ return invoke$1('IconTheme.getFolderIcon', options);
2035
+ };
2036
+ const closeWidget = async widgetId => {
2037
+ return invoke$1('Viewlet.closeWidget', widgetId);
2038
+ };
2039
+ const sendMessagePortToExtensionHostWorker = async (port, rpcId = 0) => {
2040
+ const command = 'HandleMessagePort.handleMessagePort2';
2041
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, rpcId);
2042
+ };
2043
+ const sendMessagePortToSearchProcess = async port => {
2044
+ await invokeAndTransfer('SendMessagePortToElectron.sendMessagePortToElectron', port, 'HandleMessagePortForSearchProcess.handleMessagePortForSearchProcess');
2045
+ };
2046
+ const confirm = async (message, options) => {
2047
+ // @ts-ignore
2048
+ const result = await invoke$1('ConfirmPrompt.prompt', message, options);
2049
+ return result;
2050
+ };
2051
+ const getRecentlyOpened$1 = async () => {
2052
+ return invoke$1(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
2053
+ };
2054
+ const getKeyBindings = async () => {
2055
+ return invoke$1('KeyBindingsInitial.getKeyBindings');
2306
2056
  };
2307
-
2308
- const getTitleBarButtonsVirtualDom = buttons => {
2309
- return [{
2310
- type: Div,
2311
- className: mergeClassNames(Viewlet, TitleBarButtons),
2312
- childCount: buttons.length
2313
- }, ...buttons.flatMap(createTitleBarButton)];
2057
+ const writeClipBoardText = async text => {
2058
+ await invoke$1('ClipBoard.writeText', /* text */text);
2314
2059
  };
2315
-
2316
- const parentNode$1 = {
2317
- type: Div,
2318
- className: mergeClassNames(Viewlet, TitleBarIcon),
2319
- childCount: 1
2060
+ const writeClipBoardImage = async blob => {
2061
+ // @ts-ignore
2062
+ await invoke$1('ClipBoard.writeImage', /* text */blob);
2320
2063
  };
2321
- const getTitleBarIconVirtualDom = iconSrc => {
2322
- return [parentNode$1, {
2323
- type: Img,
2324
- className: TitleBarIconIcon,
2325
- src: iconSrc,
2326
- alt: '',
2327
- childCount: 0
2328
- }];
2064
+ const searchFileMemory = async uri => {
2065
+ // @ts-ignore
2066
+ return invoke$1('ExtensionHost.searchFileWithMemory', uri);
2329
2067
  };
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 => {
2068
+ const searchFileFetch = async uri => {
2069
+ return invoke$1('ExtensionHost.searchFileWithFetch', uri);
2070
+ };
2071
+ const showMessageBox = async options => {
2072
+ return invoke$1('ElectronDialog.showMessageBox', options);
2073
+ };
2074
+ const handleDebugResumed = async params => {
2075
+ await invoke$1('Run And Debug.handleResumed', params);
2076
+ };
2077
+ const openWidget = async name => {
2078
+ await invoke$1('Viewlet.openWidget', name);
2079
+ };
2080
+ const getIcons = async requests => {
2081
+ const icons = await invoke$1('IconTheme.getIcons', requests);
2082
+ return icons;
2083
+ };
2084
+ const activateByEvent = event => {
2085
+ return invoke$1('ExtensionHostManagement.activateByEvent', event);
2086
+ };
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);
2476
2144
  };
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;
2145
+ const getExtension = async id => {
2146
+ // @ts-ignore
2147
+ return invoke$1('ExtensionManagement.getExtension', id);
2495
2148
  };
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;
2149
+ const getMarkdownDom = async html => {
2150
+ // @ts-ignore
2151
+ return invoke$1('Markdown.getVirtualDom', html);
2502
2152
  };
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;
2153
+ const renderMarkdown = async (markdown, options) => {
2154
+ // @ts-ignore
2155
+ return invoke$1('Markdown.renderMarkdown', markdown, options);
2517
2156
  };
2518
- const getIndexToFocusFirst = items => {
2519
- return getIndexToFocusNextStartingAt(items, 0);
2157
+ const openNativeFolder = async uri => {
2158
+ // @ts-ignore
2159
+ await invoke$1('OpenNativeFolder.openNativeFolder', uri);
2520
2160
  };
2521
- const getIndexToFocusLast = items => {
2522
- return getIndexToFocusPreviousStartingAt(items, items.length - 1);
2161
+ const uninstallExtension = async id => {
2162
+ return invoke$1('ExtensionManagement.uninstall', id);
2523
2163
  };
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;
2164
+ const installExtension = async id => {
2165
+ // @ts-ignore
2166
+ return invoke$1('ExtensionManagement.install', id);
2535
2167
  };
2536
- const getIndexToFocusPrevious = menu => {
2537
- const startIndex = menu.focusedIndex === -1 ? menu.items.length - 1 : menu.focusedIndex - 1;
2538
- return getIndexToFocusPreviousStartingAt(menu.items, startIndex);
2168
+ const openExtensionSearch = async () => {
2169
+ // @ts-ignore
2170
+ return invoke$1('SideBar.openViewlet', 'Extensions');
2539
2171
  };
2540
- const canBeFocused = item => {
2541
- switch (item.flags) {
2542
- case Separator:
2543
- case Disabled:
2544
- return false;
2545
- default:
2546
- return true;
2547
- }
2172
+ const setExtensionsSearchValue = async searchValue => {
2173
+ // @ts-ignore
2174
+ return invoke$1('Extensions.handleInput', searchValue);
2548
2175
  };
2549
- const getIndexToFocusNext = menu => {
2550
- const startIndex = menu.focusedIndex + 1;
2551
- return getIndexToFocusNextStartingAt(menu.items, startIndex);
2176
+ const openExternal = async uri => {
2177
+ // @ts-ignore
2178
+ await invoke$1('Open.openExternal', uri);
2552
2179
  };
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;
2180
+ const openUrl = async uri => {
2181
+ // @ts-ignore
2182
+ await invoke$1('Open.openUrl', uri);
2563
2183
  };
2564
- const getModule = id => {
2565
- for (const module of menus) {
2566
- if (module.id === id) {
2567
- return module;
2568
- }
2569
- }
2570
- return undefined;
2184
+ const getAllPreferences = async () => {
2185
+ // @ts-ignore
2186
+ return invoke$1('Preferences.getAll');
2571
2187
  };
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
- }
2188
+ const showSaveFilePicker = async () => {
2189
+ // @ts-ignore
2190
+ return invoke$1('FilePicker.showSaveFilePicker');
2191
+ };
2192
+ const getLogsDir = async () => {
2193
+ // @ts-ignore
2194
+ return invoke$1('PlatformPaths.getLogsDir');
2195
+ };
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
2604
-
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
- };
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
2627
2283
  };
2628
2284
 
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;
2285
+ const {
2286
+ invoke,
2287
+ set
2288
+ } = RendererWorker;
2289
+
2290
+ const getRecentlyOpened = () => {
2291
+ return invoke(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
2292
+ };
2293
+
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();
2499
+ };
2500
+
2501
+ const MenuEntriesTitleBar = {
2502
+ __proto__: null,
2503
+ getMenuEntries: getMenuEntries$3,
2504
+ id: id$1
2505
+ };
2506
+
2507
+ const id = View;
2508
+ const getMenuEntries$2 = () => {
2509
+ return [];
2721
2510
  };
2722
2511
 
2723
- const getFontString = (fontWeight, fontSize, fontFamily) => {
2724
- return `${fontWeight} ${fontSize}px ${fontFamily}`;
2512
+ const MenuEntriesView = {
2513
+ __proto__: null,
2514
+ getMenuEntries: getMenuEntries$2,
2515
+ id
2725
2516
  };
2726
2517
 
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;
2743
- };
2518
+ const menus$1 = [MenuEntriesEdit, MenuEntriesFile, MenuEntriesGo, MenuEntriesHelp, MenuEntriesRun, MenuEntriesSelection, MenuEntriesTerminal, MenuEntriesTitleBar, MenuEntriesView, MenuEntriesOpenRecent];
2744
2519
 
2745
- const getLabel = entry => {
2746
- return entry.label;
2520
+ const getMenuIds = () => {
2521
+ return menus$1.map(menu => menu.id);
2747
2522
  };
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
- });
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)];
2676
+ };
2677
+
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');
2849
2686
  };
2850
2687
 
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];
2688
+ const handleClickClose = async state => {
2689
+ await close();
2690
+ return state;
2855
2691
  };
2856
2692
 
2857
- const renderFocusedIndex = (oldState, newState) => {
2858
- if (newState.focusedIndex === -1) {
2859
- return [];
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);
2910
+ }
2911
+ return {
2912
+ ...state,
2913
+ focusedIndex: index
2914
+ };
2915
+ };
2916
+
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;
3158
2950
  }
2951
+ return handleMouseOut(state);
3159
2952
  };
3160
2953
 
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);
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);
@@ -3527,6 +3517,29 @@ const renderEventListeners = () => {
3527
3517
  }];
3528
3518
  };
3529
3519
 
3520
+ const getTitleBarMenuBarWidth = (width, menuBarX, titleBarButtonsWidth) => {
3521
+ const remainingWidth = width - menuBarX - titleBarButtonsWidth;
3522
+ return remainingWidth;
3523
+ };
3524
+ const resize = async (state, dimensions) => {
3525
+ const {
3526
+ titleBarIconWidth,
3527
+ titleBarButtonsWidth
3528
+ } = state;
3529
+ const menuBarX = dimensions.x + titleBarIconWidth;
3530
+ const menuBarY = dimensions.y;
3531
+ const menuBarWidth = getTitleBarMenuBarWidth(dimensions.width, menuBarX, titleBarButtonsWidth);
3532
+ const menuBarHeight = dimensions.height;
3533
+ return {
3534
+ ...state,
3535
+ ...dimensions,
3536
+ x: menuBarX,
3537
+ y: menuBarY,
3538
+ width: menuBarWidth,
3539
+ height: menuBarHeight
3540
+ };
3541
+ };
3542
+
3530
3543
  const saveState = uid => {
3531
3544
  return {
3532
3545
  x: 1
@@ -4095,6 +4108,7 @@ const commandMap = {
4095
4108
  'TitleBar.render2': render2,
4096
4109
  'TitleBar.render3': render3,
4097
4110
  'TitleBar.renderEventListeners': renderEventListeners,
4111
+ 'TitleBar.resize': wrapCommand(resize),
4098
4112
  'TitleBar.saveState': saveState,
4099
4113
  'TitleBar.terminate': terminate,
4100
4114
  'TitleBar.toggleIndex': wrapCommand(toggleIndex),