@lvce-editor/running-extensions-view 1.2.0 → 1.3.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 = 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;
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,12 +1142,12 @@ 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';
1150
+ const None$1 = 'none';
1108
1151
 
1109
1152
  const Audio = 0;
1110
1153
  const Button = 1;
@@ -1275,6 +1318,13 @@ const VirtualDomElements = {
1275
1318
  Video
1276
1319
  };
1277
1320
 
1321
+ const ClientX = 'event.clientX';
1322
+ const ClientY = 'event.clientY';
1323
+
1324
+ const Separator = 1;
1325
+ const None = 0;
1326
+
1327
+ const ClipBoardWorker = 3400;
1278
1328
  const ExtensionManagementWorker = 9006;
1279
1329
  const RendererWorker = 1;
1280
1330
 
@@ -1282,26 +1332,78 @@ 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
  };
1297
1371
 
1372
+ const copyId = async (state, index) => {
1373
+ const extension = state.extensions[index];
1374
+ if (extension) {
1375
+ await writeText(extension.id);
1376
+ }
1377
+ return state;
1378
+ };
1379
+
1298
1380
  const toCommandId = key => {
1299
1381
  const dotIndex = key.indexOf('.');
1300
1382
  return key.slice(dotIndex + 1);
1301
1383
  };
1302
1384
  const create$1 = () => {
1385
+ const generations = Object.create(null);
1303
1386
  const states = Object.create(null);
1304
1387
  const commandMapRef = {};
1388
+ const getGeneration = uid => generations[uid] || 0;
1389
+ const isCurrentGeneration = (uid, generation) => {
1390
+ return states[uid] !== undefined && getGeneration(uid) === generation;
1391
+ };
1392
+ const updateState = (uid, generation, fallbackState, updater) => {
1393
+ if (!isCurrentGeneration(uid, generation)) {
1394
+ return Promise.resolve(fallbackState);
1395
+ }
1396
+ const current = states[uid];
1397
+ const updatedState = updater(current.newState);
1398
+ if (updatedState !== current.newState) {
1399
+ states[uid] = {
1400
+ newState: updatedState,
1401
+ oldState: current.oldState,
1402
+ scheduledState: updatedState
1403
+ };
1404
+ }
1405
+ return Promise.resolve(updatedState);
1406
+ };
1305
1407
  return {
1306
1408
  clear() {
1307
1409
  for (const key of Object.keys(states)) {
@@ -1340,14 +1442,39 @@ const create$1 = () => {
1340
1442
  Object.assign(commandMapRef, commandMap);
1341
1443
  },
1342
1444
  set(uid, oldState, newState, scheduledState) {
1445
+ const current = states[uid];
1446
+ if (!current || oldState === newState && newState !== current.newState) {
1447
+ generations[uid] = getGeneration(uid) + 1;
1448
+ }
1343
1449
  states[uid] = {
1344
1450
  newState,
1345
1451
  oldState,
1346
1452
  scheduledState: scheduledState ?? newState
1347
1453
  };
1348
1454
  },
1455
+ wrapAsyncCommand(fn) {
1456
+ const wrapped = async (uid, ...args) => {
1457
+ const generation = getGeneration(uid);
1458
+ let latestState = states[uid].newState;
1459
+ const context = {
1460
+ getState: () => {
1461
+ if (isCurrentGeneration(uid, generation)) {
1462
+ latestState = states[uid].newState;
1463
+ }
1464
+ return latestState;
1465
+ },
1466
+ updateState: async updater => {
1467
+ latestState = await updateState(uid, generation, latestState, updater);
1468
+ return latestState;
1469
+ }
1470
+ };
1471
+ await fn(context, ...args);
1472
+ };
1473
+ return wrapped;
1474
+ },
1349
1475
  wrapCommand(fn) {
1350
1476
  const wrapped = async (uid, ...args) => {
1477
+ const generation = getGeneration(uid);
1351
1478
  const {
1352
1479
  newState,
1353
1480
  oldState
@@ -1356,6 +1483,9 @@ const create$1 = () => {
1356
1483
  if (oldState === newerState || newState === newerState) {
1357
1484
  return;
1358
1485
  }
1486
+ if (!isCurrentGeneration(uid, generation)) {
1487
+ return;
1488
+ }
1359
1489
  const latestOld = states[uid];
1360
1490
  const latestNew = {
1361
1491
  ...latestOld.newState,
@@ -1380,6 +1510,7 @@ const create$1 = () => {
1380
1510
  },
1381
1511
  wrapLoadContent(fn) {
1382
1512
  const wrapped = async (uid, ...args) => {
1513
+ const generation = getGeneration(uid);
1383
1514
  const {
1384
1515
  newState,
1385
1516
  oldState
@@ -1394,6 +1525,11 @@ const create$1 = () => {
1394
1525
  error
1395
1526
  };
1396
1527
  }
1528
+ if (!isCurrentGeneration(uid, generation)) {
1529
+ return {
1530
+ error
1531
+ };
1532
+ }
1397
1533
  const latestOld = states[uid];
1398
1534
  const latestNew = {
1399
1535
  ...latestOld.newState,
@@ -1420,13 +1556,15 @@ const {
1420
1556
  getCommandIds,
1421
1557
  registerCommands,
1422
1558
  set,
1423
- wrapCommand
1559
+ wrapCommand,
1560
+ wrapGetter
1424
1561
  } = create$1();
1425
1562
 
1426
1563
  const create = (uid, uri, x, y, width, height, platform, assetDir) => {
1427
1564
  const state = {
1428
1565
  assetDir,
1429
1566
  extensions: [],
1567
+ focusedIndex: -1,
1430
1568
  height,
1431
1569
  loaded: false,
1432
1570
  platform,
@@ -1452,8 +1590,98 @@ const diff2 = uid => {
1452
1590
  return diff(uid, [isDomEqual, isCssEqual], [RenderDom, RenderCss]);
1453
1591
  };
1454
1592
 
1593
+ const disable = async (state, index) => {
1594
+ const extension = state.extensions[index];
1595
+ if (extension) {
1596
+ await invoke$1('Extensions.disable2', extension.id, state.platform);
1597
+ }
1598
+ return state;
1599
+ };
1600
+
1601
+ const disableWorkspace = async (state, index) => {
1602
+ const extension = state.extensions[index];
1603
+ if (extension) {
1604
+ await invoke$1('Extensions.disableWorkspace', extension.id);
1605
+ }
1606
+ return state;
1607
+ };
1608
+
1609
+ const getMenuEntries = state => {
1610
+ const extension = state.extensions[state.focusedIndex];
1611
+ if (!extension) {
1612
+ return [];
1613
+ }
1614
+ const args = [state.focusedIndex];
1615
+ return [{
1616
+ args,
1617
+ command: 'RunningExtensions.copyId',
1618
+ flags: None,
1619
+ id: 'copyId',
1620
+ label: `Copy id (${extension.id})`
1621
+ }, {
1622
+ args,
1623
+ command: 'RunningExtensions.reportIssue',
1624
+ flags: None,
1625
+ id: 'reportIssue',
1626
+ label: 'Report Issue'
1627
+ }, {
1628
+ command: '',
1629
+ flags: Separator,
1630
+ id: 'separator1',
1631
+ label: ''
1632
+ }, {
1633
+ args,
1634
+ command: 'RunningExtensions.disableWorkspace',
1635
+ flags: None,
1636
+ id: 'disableWorkspace',
1637
+ label: 'Disable (Workspace)'
1638
+ }, {
1639
+ args,
1640
+ command: 'RunningExtensions.disable',
1641
+ flags: None,
1642
+ id: 'disable',
1643
+ label: 'Disable'
1644
+ }, {
1645
+ command: '',
1646
+ flags: Separator,
1647
+ id: 'separator2',
1648
+ label: ''
1649
+ }, {
1650
+ command: 'RunningExtensions.startProfile',
1651
+ flags: None,
1652
+ id: 'startProfile',
1653
+ label: 'Start Extension Host Profile'
1654
+ }];
1655
+ };
1656
+
1657
+ const RunningExtensions = 32;
1658
+
1659
+ const getMenuEntryIds = () => {
1660
+ return [RunningExtensions];
1661
+ };
1662
+
1663
+ const show = async (uid, menuId, x, y, args) => {
1664
+ await showContextMenu2(uid, menuId, x, y, args);
1665
+ };
1666
+
1667
+ const handleContextMenu = async (state, index, x = 0, y = 0) => {
1668
+ const focusedIndex = Number(index);
1669
+ if (!state.extensions[focusedIndex]) {
1670
+ return state;
1671
+ }
1672
+ const newState = {
1673
+ ...state,
1674
+ focusedIndex
1675
+ };
1676
+ set(state.uid, state, newState);
1677
+ await show(state.uid, RunningExtensions, x, y, {
1678
+ menuId: RunningExtensions
1679
+ });
1680
+ return newState;
1681
+ };
1682
+
1455
1683
  const getRunningExtensions = async (assetDir, platform) => {
1456
- return invoke('Extensions.getRunningExtensions', assetDir, platform);
1684
+ return invoke$1('Extensions.getRunningExtensions', assetDir, platform);
1457
1685
  };
1458
1686
 
1459
1687
  const loadContent = async state => {
@@ -1488,11 +1716,12 @@ const text = data => {
1488
1716
 
1489
1717
  new Set(Object.values(VirtualDomElements));
1490
1718
 
1491
- const getIconVirtualDom = extension => {
1719
+ const getIconVirtualDom = (extension, index) => {
1492
1720
  if (extension.icon) {
1493
1721
  return [{
1494
1722
  childCount: 0,
1495
1723
  className: 'RunningExtensionIcon',
1724
+ 'data-index': index,
1496
1725
  src: extension.icon,
1497
1726
  type: Img
1498
1727
  }];
@@ -1500,41 +1729,49 @@ const getIconVirtualDom = extension => {
1500
1729
  return [{
1501
1730
  childCount: 0,
1502
1731
  className: 'RunningExtensionIcon RunningExtensionDefaultIcon MaskIcon MaskIconExtensions',
1503
- role: None,
1732
+ 'data-index': index,
1733
+ role: None$1,
1504
1734
  type: Div
1505
1735
  }];
1506
1736
  };
1507
1737
 
1508
- const getExtensionVirtualDom = extension => {
1738
+ const getExtensionVirtualDom = (extension, index) => {
1509
1739
  const displayName = extension.name || extension.id;
1510
1740
  return [{
1511
1741
  childCount: 3,
1512
1742
  className: 'RunningExtension',
1743
+ 'data-index': index,
1513
1744
  role: 'listitem',
1514
1745
  type: Div
1515
- }, ...getIconVirtualDom(extension), {
1746
+ }, ...getIconVirtualDom(extension, index), {
1516
1747
  childCount: 2,
1517
1748
  className: 'RunningExtensionDetails',
1749
+ 'data-index': index,
1518
1750
  type: Div
1519
1751
  }, {
1520
1752
  childCount: 2,
1521
1753
  className: 'RunningExtensionTitle',
1754
+ 'data-index': index,
1522
1755
  type: Div
1523
1756
  }, {
1524
1757
  childCount: 1,
1525
1758
  className: 'RunningExtensionName',
1759
+ 'data-index': index,
1526
1760
  type: Strong
1527
1761
  }, text(displayName), {
1528
1762
  childCount: 1,
1529
1763
  className: 'RunningExtensionVersion',
1764
+ 'data-index': index,
1530
1765
  type: Span
1531
1766
  }, text(extension.version), {
1532
1767
  childCount: 1,
1533
1768
  className: 'RunningExtensionId',
1769
+ 'data-index': index,
1534
1770
  type: Div
1535
1771
  }, text(extension.id), {
1536
1772
  childCount: 1,
1537
1773
  className: 'RunningExtensionActivationTime',
1774
+ 'data-index': index,
1538
1775
  type: Div
1539
1776
  }, text(`Activation: ${Math.round(extension.activationTime)}ms`)];
1540
1777
  };
@@ -1578,7 +1815,16 @@ const render2 = (uid, diffResult) => {
1578
1815
  };
1579
1816
 
1580
1817
  const renderEventListeners = () => {
1581
- return [];
1818
+ return [{
1819
+ name: 3,
1820
+ params: ['handleContextMenu', 'event.target.dataset.index', ClientX, ClientY],
1821
+ preventDefault: true
1822
+ }];
1823
+ };
1824
+
1825
+ const reportIssue = async state => {
1826
+ await confirm('Reporting issues for running extensions is not available yet.');
1827
+ return state;
1582
1828
  };
1583
1829
 
1584
1830
  const resize = (state, dimensions) => {
@@ -1588,15 +1834,39 @@ const resize = (state, dimensions) => {
1588
1834
  };
1589
1835
  };
1590
1836
 
1837
+ const startProfile = async state => {
1838
+ await confirm('Extension host profiling is not available yet.');
1839
+ return state;
1840
+ };
1841
+
1591
1842
  const commandMap = {
1843
+ 'RunningExtensions.copyId': wrapCommand(copyId),
1592
1844
  'RunningExtensions.create': create,
1593
1845
  'RunningExtensions.diff2': diff2,
1846
+ 'RunningExtensions.disable': wrapCommand(disable),
1847
+ 'RunningExtensions.disableWorkspace': wrapCommand(disableWorkspace),
1594
1848
  'RunningExtensions.dispose': dispose,
1595
1849
  'RunningExtensions.getCommandIds': getCommandIds,
1850
+ 'RunningExtensions.getMenuEntries': wrapGetter(getMenuEntries),
1851
+ 'RunningExtensions.getMenuEntryIds': getMenuEntryIds,
1852
+ 'RunningExtensions.handleContextMenu': wrapCommand(handleContextMenu),
1596
1853
  'RunningExtensions.loadContent': wrapCommand(loadContent),
1597
1854
  'RunningExtensions.render2': render2,
1598
1855
  'RunningExtensions.renderEventListeners': renderEventListeners,
1599
- 'RunningExtensions.resize': wrapCommand(resize)
1856
+ 'RunningExtensions.reportIssue': wrapCommand(reportIssue),
1857
+ 'RunningExtensions.resize': wrapCommand(resize),
1858
+ 'RunningExtensions.startProfile': wrapCommand(startProfile)
1859
+ };
1860
+
1861
+ const send$1 = async port => {
1862
+ await sendMessagePortToClipBoardWorker(port, 0);
1863
+ };
1864
+ const initializeClipBoardWorker = async () => {
1865
+ const rpc = await create$4({
1866
+ commandMap: {},
1867
+ send: send$1
1868
+ });
1869
+ set$3(rpc);
1600
1870
  };
1601
1871
 
1602
1872
  const send = async port => {
@@ -1616,7 +1886,7 @@ const listen = async () => {
1616
1886
  commandMap: commandMap
1617
1887
  });
1618
1888
  set$1(rpc);
1619
- await initializeExtensionManagementWorker();
1889
+ await Promise.all([initializeClipBoardWorker(), initializeExtensionManagementWorker()]);
1620
1890
  };
1621
1891
 
1622
1892
  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.3.0",
4
4
  "description": "Running Extensions View Worker",
5
5
  "repository": {
6
6
  "type": "git",