@lvce-editor/running-extensions-view 1.2.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -54,6 +54,49 @@ class VError extends Error {
54
54
  }
55
55
  }
56
56
 
57
+ class AssertionError extends Error {
58
+ constructor(message) {
59
+ super(message);
60
+ this.name = 'AssertionError';
61
+ }
62
+ }
63
+ const Object$1 = 1;
64
+ const Number$1 = 2;
65
+ const Array$1 = 3;
66
+ const String = 4;
67
+ const Boolean$1 = 5;
68
+ const Function = 6;
69
+ const Null = 7;
70
+ const Unknown = 8;
71
+ const getType = value => {
72
+ switch (typeof value) {
73
+ case 'number':
74
+ return Number$1;
75
+ case 'function':
76
+ return Function;
77
+ case 'string':
78
+ return String;
79
+ case 'object':
80
+ if (value === null) {
81
+ return Null;
82
+ }
83
+ if (Array.isArray(value)) {
84
+ return Array$1;
85
+ }
86
+ return Object$1;
87
+ case 'boolean':
88
+ return Boolean$1;
89
+ default:
90
+ return Unknown;
91
+ }
92
+ };
93
+ const number = value => {
94
+ const type = getType(value);
95
+ if (type !== Number$1) {
96
+ throw new AssertionError('expected value to be of type number');
97
+ }
98
+ };
99
+
57
100
  const isMessagePort = value => {
58
101
  return value && value instanceof MessagePort;
59
102
  };
@@ -1057,7 +1100,7 @@ const createMockRpc = ({
1057
1100
  };
1058
1101
 
1059
1102
  const rpcs = Object.create(null);
1060
- const set$3 = (id, rpc) => {
1103
+ const set$4 = (id, rpc) => {
1061
1104
  rpcs[id] = rpc;
1062
1105
  };
1063
1106
  const get$1 = id => {
@@ -1090,7 +1133,7 @@ const create$2 = rpcId => {
1090
1133
  const mockRpc = createMockRpc({
1091
1134
  commandMap
1092
1135
  });
1093
- set$3(rpcId, mockRpc);
1136
+ set$4(rpcId, mockRpc);
1094
1137
  // @ts-ignore
1095
1138
  mockRpc[Symbol.dispose] = () => {
1096
1139
  remove(rpcId);
@@ -1099,13 +1142,11 @@ const create$2 = rpcId => {
1099
1142
  return mockRpc;
1100
1143
  },
1101
1144
  set(rpc) {
1102
- set$3(rpcId, rpc);
1145
+ set$4(rpcId, rpc);
1103
1146
  }
1104
1147
  };
1105
1148
  };
1106
1149
 
1107
- const None = 'none';
1108
-
1109
1150
  const Audio = 0;
1110
1151
  const Button = 1;
1111
1152
  const Col = 2;
@@ -1275,6 +1316,15 @@ const VirtualDomElements = {
1275
1316
  Video
1276
1317
  };
1277
1318
 
1319
+ const ClientX = 'event.clientX';
1320
+ const ClientY = 'event.clientY';
1321
+
1322
+ const Separator = 1;
1323
+ const None$1 = 0;
1324
+
1325
+ const Electron = 2;
1326
+
1327
+ const ClipBoardWorker = 3400;
1278
1328
  const ExtensionManagementWorker = 9006;
1279
1329
  const RendererWorker = 1;
1280
1330
 
@@ -1282,26 +1332,84 @@ const SetCss = 'Viewlet.setCss';
1282
1332
  const SetDom2 = 'Viewlet.setDom2';
1283
1333
 
1284
1334
  const {
1285
- invoke,
1335
+ invoke: invoke$2,
1336
+ set: set$3
1337
+ } = create$2(ClipBoardWorker);
1338
+ const writeText = async text => {
1339
+ return invoke$2('ClipBoard.writeText', text);
1340
+ };
1341
+
1342
+ const {
1343
+ invoke: invoke$1,
1286
1344
  set: set$2
1287
1345
  } = create$2(ExtensionManagementWorker);
1288
1346
 
1289
1347
  const {
1348
+ invoke,
1290
1349
  invokeAndTransfer,
1291
1350
  set: set$1
1292
1351
  } = create$2(RendererWorker);
1352
+ const showContextMenu2 = async (uid, menuId, x, y, args) => {
1353
+ number(uid);
1354
+ number(menuId);
1355
+ number(x);
1356
+ number(y);
1357
+ await invoke('ContextMenu.show2', uid, menuId, x, y, args);
1358
+ };
1359
+ const sendMessagePortToClipBoardWorker = async (port, rpcId) => {
1360
+ const command = 'ClipBoard.handleMessagePort';
1361
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToClipBoardWorker', port, command, rpcId);
1362
+ };
1363
+ const confirm = async (message, options) => {
1364
+ const result = await invoke('ConfirmPrompt.prompt', message, options);
1365
+ return result;
1366
+ };
1293
1367
  const sendMessagePortToExtensionManagementWorker = async (port, rpcId) => {
1294
1368
  const command = 'Extensions.handleMessagePort';
1295
1369
  await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionManagementWorker', port, command, rpcId);
1296
1370
  };
1371
+ const getWindowId = async () => {
1372
+ return invoke('GetWindowId.getWindowId');
1373
+ };
1374
+
1375
+ const copyId = async (state, index) => {
1376
+ const {
1377
+ extensions
1378
+ } = state;
1379
+ const extension = extensions[index];
1380
+ if (extension) {
1381
+ await writeText(extension.id);
1382
+ }
1383
+ return state;
1384
+ };
1297
1385
 
1298
1386
  const toCommandId = key => {
1299
1387
  const dotIndex = key.indexOf('.');
1300
1388
  return key.slice(dotIndex + 1);
1301
1389
  };
1302
1390
  const create$1 = () => {
1391
+ const generations = Object.create(null);
1303
1392
  const states = Object.create(null);
1304
1393
  const commandMapRef = {};
1394
+ const getGeneration = uid => generations[uid] || 0;
1395
+ const isCurrentGeneration = (uid, generation) => {
1396
+ return states[uid] !== undefined && getGeneration(uid) === generation;
1397
+ };
1398
+ const updateState = (uid, generation, fallbackState, updater) => {
1399
+ if (!isCurrentGeneration(uid, generation)) {
1400
+ return Promise.resolve(fallbackState);
1401
+ }
1402
+ const current = states[uid];
1403
+ const updatedState = updater(current.newState);
1404
+ if (updatedState !== current.newState) {
1405
+ states[uid] = {
1406
+ newState: updatedState,
1407
+ oldState: current.oldState,
1408
+ scheduledState: updatedState
1409
+ };
1410
+ }
1411
+ return Promise.resolve(updatedState);
1412
+ };
1305
1413
  return {
1306
1414
  clear() {
1307
1415
  for (const key of Object.keys(states)) {
@@ -1340,14 +1448,39 @@ const create$1 = () => {
1340
1448
  Object.assign(commandMapRef, commandMap);
1341
1449
  },
1342
1450
  set(uid, oldState, newState, scheduledState) {
1451
+ const current = states[uid];
1452
+ if (!current || oldState === newState && newState !== current.newState) {
1453
+ generations[uid] = getGeneration(uid) + 1;
1454
+ }
1343
1455
  states[uid] = {
1344
1456
  newState,
1345
1457
  oldState,
1346
1458
  scheduledState: scheduledState ?? newState
1347
1459
  };
1348
1460
  },
1461
+ wrapAsyncCommand(fn) {
1462
+ const wrapped = async (uid, ...args) => {
1463
+ const generation = getGeneration(uid);
1464
+ let latestState = states[uid].newState;
1465
+ const context = {
1466
+ getState: () => {
1467
+ if (isCurrentGeneration(uid, generation)) {
1468
+ latestState = states[uid].newState;
1469
+ }
1470
+ return latestState;
1471
+ },
1472
+ updateState: async updater => {
1473
+ latestState = await updateState(uid, generation, latestState, updater);
1474
+ return latestState;
1475
+ }
1476
+ };
1477
+ await fn(context, ...args);
1478
+ };
1479
+ return wrapped;
1480
+ },
1349
1481
  wrapCommand(fn) {
1350
1482
  const wrapped = async (uid, ...args) => {
1483
+ const generation = getGeneration(uid);
1351
1484
  const {
1352
1485
  newState,
1353
1486
  oldState
@@ -1356,6 +1489,9 @@ const create$1 = () => {
1356
1489
  if (oldState === newerState || newState === newerState) {
1357
1490
  return;
1358
1491
  }
1492
+ if (!isCurrentGeneration(uid, generation)) {
1493
+ return;
1494
+ }
1359
1495
  const latestOld = states[uid];
1360
1496
  const latestNew = {
1361
1497
  ...latestOld.newState,
@@ -1380,6 +1516,7 @@ const create$1 = () => {
1380
1516
  },
1381
1517
  wrapLoadContent(fn) {
1382
1518
  const wrapped = async (uid, ...args) => {
1519
+ const generation = getGeneration(uid);
1383
1520
  const {
1384
1521
  newState,
1385
1522
  oldState
@@ -1394,6 +1531,11 @@ const create$1 = () => {
1394
1531
  error
1395
1532
  };
1396
1533
  }
1534
+ if (!isCurrentGeneration(uid, generation)) {
1535
+ return {
1536
+ error
1537
+ };
1538
+ }
1397
1539
  const latestOld = states[uid];
1398
1540
  const latestNew = {
1399
1541
  ...latestOld.newState,
@@ -1420,13 +1562,15 @@ const {
1420
1562
  getCommandIds,
1421
1563
  registerCommands,
1422
1564
  set,
1423
- wrapCommand
1565
+ wrapCommand,
1566
+ wrapGetter
1424
1567
  } = create$1();
1425
1568
 
1426
1569
  const create = (uid, uri, x, y, width, height, platform, assetDir) => {
1427
1570
  const state = {
1428
1571
  assetDir,
1429
1572
  extensions: [],
1573
+ focusedIndex: -1,
1430
1574
  height,
1431
1575
  loaded: false,
1432
1576
  platform,
@@ -1452,8 +1596,124 @@ const diff2 = uid => {
1452
1596
  return diff(uid, [isDomEqual, isCssEqual], [RenderDom, RenderCss]);
1453
1597
  };
1454
1598
 
1599
+ const disable = async (state, index) => {
1600
+ const {
1601
+ extensions,
1602
+ platform
1603
+ } = state;
1604
+ const extension = extensions[index];
1605
+ if (extension) {
1606
+ await invoke$1('Extensions.disable2', extension.id, platform);
1607
+ }
1608
+ return state;
1609
+ };
1610
+
1611
+ const disableWorkspace = async (state, index) => {
1612
+ const {
1613
+ extensions
1614
+ } = state;
1615
+ const extension = extensions[index];
1616
+ if (extension) {
1617
+ await invoke$1('Extensions.disableWorkspace', extension.id);
1618
+ }
1619
+ return state;
1620
+ };
1621
+
1622
+ const getMenuEntries = state => {
1623
+ const {
1624
+ extensions,
1625
+ focusedIndex,
1626
+ platform
1627
+ } = state;
1628
+ const extension = extensions[focusedIndex];
1629
+ if (!extension) {
1630
+ return [];
1631
+ }
1632
+ const args = [focusedIndex];
1633
+ const menuEntries = [{
1634
+ args,
1635
+ command: 'RunningExtensions.copyId',
1636
+ flags: None$1,
1637
+ id: 'copyId',
1638
+ label: `Copy id (${extension.id})`
1639
+ }, {
1640
+ args,
1641
+ command: 'RunningExtensions.reportIssue',
1642
+ flags: None$1,
1643
+ id: 'reportIssue',
1644
+ label: 'Report Issue'
1645
+ }, {
1646
+ command: '',
1647
+ flags: Separator,
1648
+ id: 'separator1',
1649
+ label: ''
1650
+ }, {
1651
+ args,
1652
+ command: 'RunningExtensions.disableWorkspace',
1653
+ flags: None$1,
1654
+ id: 'disableWorkspace',
1655
+ label: 'Disable (Workspace)'
1656
+ }, {
1657
+ args,
1658
+ command: 'RunningExtensions.disable',
1659
+ flags: None$1,
1660
+ id: 'disable',
1661
+ label: 'Disable'
1662
+ }, {
1663
+ command: '',
1664
+ flags: Separator,
1665
+ id: 'separator2',
1666
+ label: ''
1667
+ }, {
1668
+ command: 'RunningExtensions.startProfile',
1669
+ flags: None$1,
1670
+ id: 'startProfile',
1671
+ label: 'Start Extension Host Profile'
1672
+ }];
1673
+ if (platform === Electron && extension.isolated) {
1674
+ menuEntries.push({
1675
+ args,
1676
+ command: 'RunningExtensions.takeHeapSnapshot',
1677
+ flags: None$1,
1678
+ id: 'takeHeapSnapshot',
1679
+ label: 'Take Heap Snapshot'
1680
+ });
1681
+ }
1682
+ return menuEntries;
1683
+ };
1684
+
1685
+ const RunningExtensions = 32;
1686
+
1687
+ const getMenuEntryIds = () => {
1688
+ return [RunningExtensions];
1689
+ };
1690
+
1691
+ const show = async (uid, menuId, x, y, args) => {
1692
+ await showContextMenu2(uid, menuId, x, y, args);
1693
+ };
1694
+
1695
+ const handleContextMenu = async (state, index, x = 0, y = 0) => {
1696
+ const {
1697
+ extensions,
1698
+ uid
1699
+ } = state;
1700
+ const focusedIndex = Number(index);
1701
+ if (!extensions[focusedIndex]) {
1702
+ return state;
1703
+ }
1704
+ const newState = {
1705
+ ...state,
1706
+ focusedIndex
1707
+ };
1708
+ set(uid, state, newState);
1709
+ await show(uid, RunningExtensions, x, y, {
1710
+ menuId: RunningExtensions
1711
+ });
1712
+ return newState;
1713
+ };
1714
+
1455
1715
  const getRunningExtensions = async (assetDir, platform) => {
1456
- return invoke('Extensions.getRunningExtensions', assetDir, platform);
1716
+ return invoke$1('Extensions.getRunningExtensions', assetDir, platform);
1457
1717
  };
1458
1718
 
1459
1719
  const loadContent = async state => {
@@ -1478,6 +1738,10 @@ const renderCss = (oldState, newState) => {
1478
1738
  return [SetCss, newState.uid, css];
1479
1739
  };
1480
1740
 
1741
+ const mergeClassNames = (...classNames) => {
1742
+ return classNames.filter(Boolean).join(' ');
1743
+ };
1744
+
1481
1745
  const text = data => {
1482
1746
  return {
1483
1747
  childCount: 0,
@@ -1488,68 +1752,96 @@ const text = data => {
1488
1752
 
1489
1753
  new Set(Object.values(VirtualDomElements));
1490
1754
 
1491
- const getIconVirtualDom = extension => {
1755
+ const List = 'list';
1756
+ const ListItem = 'listitem';
1757
+ const None = 'none';
1758
+
1759
+ const HandleContextMenu = 3;
1760
+
1761
+ const getIconVirtualDom = (extension, index) => {
1492
1762
  if (extension.icon) {
1493
1763
  return [{
1494
1764
  childCount: 0,
1495
1765
  className: 'RunningExtensionIcon',
1766
+ 'data-index': index,
1496
1767
  src: extension.icon,
1497
1768
  type: Img
1498
1769
  }];
1499
1770
  }
1500
1771
  return [{
1501
1772
  childCount: 0,
1502
- className: 'RunningExtensionIcon RunningExtensionDefaultIcon MaskIcon MaskIconExtensions',
1773
+ className: mergeClassNames('RunningExtensionIcon', 'RunningExtensionDefaultIcon', 'MaskIcon', 'MaskIconExtensions'),
1774
+ 'data-index': index,
1503
1775
  role: None,
1504
1776
  type: Div
1505
1777
  }];
1506
1778
  };
1507
1779
 
1508
- const getExtensionVirtualDom = extension => {
1780
+ const getExtensionVirtualDom = (extension, index) => {
1509
1781
  const displayName = extension.name || extension.id;
1510
1782
  return [{
1511
1783
  childCount: 3,
1512
1784
  className: 'RunningExtension',
1513
- role: 'listitem',
1785
+ 'data-index': index,
1786
+ role: ListItem,
1514
1787
  type: Div
1515
- }, ...getIconVirtualDom(extension), {
1788
+ }, ...getIconVirtualDom(extension, index), {
1516
1789
  childCount: 2,
1517
1790
  className: 'RunningExtensionDetails',
1791
+ 'data-index': index,
1518
1792
  type: Div
1519
1793
  }, {
1520
1794
  childCount: 2,
1521
1795
  className: 'RunningExtensionTitle',
1796
+ 'data-index': index,
1522
1797
  type: Div
1523
1798
  }, {
1524
1799
  childCount: 1,
1525
1800
  className: 'RunningExtensionName',
1801
+ 'data-index': index,
1526
1802
  type: Strong
1527
1803
  }, text(displayName), {
1528
1804
  childCount: 1,
1529
1805
  className: 'RunningExtensionVersion',
1806
+ 'data-index': index,
1530
1807
  type: Span
1531
1808
  }, text(extension.version), {
1532
1809
  childCount: 1,
1533
1810
  className: 'RunningExtensionId',
1811
+ 'data-index': index,
1534
1812
  type: Div
1535
1813
  }, text(extension.id), {
1536
1814
  childCount: 1,
1537
1815
  className: 'RunningExtensionActivationTime',
1816
+ 'data-index': index,
1538
1817
  type: Div
1539
1818
  }, text(`Activation: ${Math.round(extension.activationTime)}ms`)];
1540
1819
  };
1541
1820
 
1542
- const getRunningExtensionsVirtualDom = (extensions, loaded) => {
1821
+ const getRunningExtensionsEmptyDom = loaded => {
1543
1822
  const message = loaded ? 'No running extensions' : 'Loading running extensions…';
1544
- const children = extensions.length === 0 ? [{
1823
+ return [{
1824
+ childCount: 1,
1825
+ className: 'RunningExtensions',
1826
+ onContextMenu: HandleContextMenu,
1827
+ role: List,
1828
+ type: Div
1829
+ }, {
1545
1830
  childCount: 1,
1546
1831
  className: 'RunningExtensionsEmpty',
1547
1832
  type: Div
1548
- }, text(message)] : extensions.flatMap(getExtensionVirtualDom);
1833
+ }, text(message)];
1834
+ };
1835
+ const getRunningExtensionsVirtualDom = (extensions, loaded) => {
1836
+ if (extensions.length === 0) {
1837
+ return getRunningExtensionsEmptyDom(loaded);
1838
+ }
1839
+ const children = extensions.flatMap(getExtensionVirtualDom);
1549
1840
  return [{
1550
- childCount: extensions.length === 0 ? 1 : extensions.length,
1841
+ childCount: extensions.length,
1551
1842
  className: 'RunningExtensions',
1552
- role: 'list',
1843
+ onContextMenu: HandleContextMenu,
1844
+ role: List,
1553
1845
  type: Div
1554
1846
  }, ...children];
1555
1847
  };
@@ -1578,7 +1870,16 @@ const render2 = (uid, diffResult) => {
1578
1870
  };
1579
1871
 
1580
1872
  const renderEventListeners = () => {
1581
- return [];
1873
+ return [{
1874
+ name: HandleContextMenu,
1875
+ params: ['handleContextMenu', 'event.target.dataset.index', ClientX, ClientY],
1876
+ preventDefault: true
1877
+ }];
1878
+ };
1879
+
1880
+ const reportIssue = async state => {
1881
+ await confirm('Reporting issues for running extensions is not available yet.');
1882
+ return state;
1582
1883
  };
1583
1884
 
1584
1885
  const resize = (state, dimensions) => {
@@ -1588,15 +1889,62 @@ const resize = (state, dimensions) => {
1588
1889
  };
1589
1890
  };
1590
1891
 
1892
+ const setExtensions = (state, extensions) => {
1893
+ return {
1894
+ ...state,
1895
+ extensions
1896
+ };
1897
+ };
1898
+
1899
+ const startProfile = async state => {
1900
+ await confirm('Extension host profiling is not available yet.');
1901
+ return state;
1902
+ };
1903
+
1904
+ const takeHeapSnapshot = async (state, index) => {
1905
+ const {
1906
+ extensions
1907
+ } = state;
1908
+ const extension = extensions[index];
1909
+ if (!extension) {
1910
+ return state;
1911
+ }
1912
+ const windowId = await getWindowId();
1913
+ const workerName = extension.workerName || `Extension API (Electron): ${extension.id}`;
1914
+ await invoke('Developer.takeWorkerHeapSnapshot', windowId, workerName);
1915
+ return state;
1916
+ };
1917
+
1591
1918
  const commandMap = {
1919
+ 'RunningExtensions.copyId': wrapCommand(copyId),
1592
1920
  'RunningExtensions.create': create,
1593
1921
  'RunningExtensions.diff2': diff2,
1922
+ 'RunningExtensions.disable': wrapCommand(disable),
1923
+ 'RunningExtensions.disableWorkspace': wrapCommand(disableWorkspace),
1594
1924
  'RunningExtensions.dispose': dispose,
1595
1925
  'RunningExtensions.getCommandIds': getCommandIds,
1926
+ 'RunningExtensions.getMenuEntries': wrapGetter(getMenuEntries),
1927
+ 'RunningExtensions.getMenuEntryIds': getMenuEntryIds,
1928
+ 'RunningExtensions.handleContextMenu': wrapCommand(handleContextMenu),
1596
1929
  'RunningExtensions.loadContent': wrapCommand(loadContent),
1597
1930
  'RunningExtensions.render2': render2,
1598
1931
  'RunningExtensions.renderEventListeners': renderEventListeners,
1599
- 'RunningExtensions.resize': wrapCommand(resize)
1932
+ 'RunningExtensions.reportIssue': wrapCommand(reportIssue),
1933
+ 'RunningExtensions.resize': wrapCommand(resize),
1934
+ 'RunningExtensions.setExtensions': wrapCommand(setExtensions),
1935
+ 'RunningExtensions.startProfile': wrapCommand(startProfile),
1936
+ 'RunningExtensions.takeHeapSnapshot': wrapCommand(takeHeapSnapshot)
1937
+ };
1938
+
1939
+ const send$1 = async port => {
1940
+ await sendMessagePortToClipBoardWorker(port, 0);
1941
+ };
1942
+ const initializeClipBoardWorker = async () => {
1943
+ const rpc = await create$4({
1944
+ commandMap: {},
1945
+ send: send$1
1946
+ });
1947
+ set$3(rpc);
1600
1948
  };
1601
1949
 
1602
1950
  const send = async port => {
@@ -1616,7 +1964,7 @@ const listen = async () => {
1616
1964
  commandMap: commandMap
1617
1965
  });
1618
1966
  set$1(rpc);
1619
- await initializeExtensionManagementWorker();
1967
+ await Promise.all([initializeClipBoardWorker(), initializeExtensionManagementWorker()]);
1620
1968
  };
1621
1969
 
1622
1970
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/running-extensions-view",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "description": "Running Extensions View Worker",
5
5
  "repository": {
6
6
  "type": "git",