@lvce-editor/process-explorer-worker 3.10.0 → 3.12.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.
Files changed (2) hide show
  1. package/index.js +285 -39
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -3,8 +3,28 @@ const toCommandId = key => {
3
3
  return key.slice(dotIndex + 1);
4
4
  };
5
5
  const create$e = () => {
6
+ const generations = Object.create(null);
6
7
  const states = Object.create(null);
7
8
  const commandMapRef = {};
9
+ const getGeneration = uid => generations[uid] || 0;
10
+ const isCurrentGeneration = (uid, generation) => {
11
+ return states[uid] !== undefined && getGeneration(uid) === generation;
12
+ };
13
+ const updateState = (uid, generation, fallbackState, updater) => {
14
+ if (!isCurrentGeneration(uid, generation)) {
15
+ return Promise.resolve(fallbackState);
16
+ }
17
+ const current = states[uid];
18
+ const updatedState = updater(current.newState);
19
+ if (updatedState !== current.newState) {
20
+ states[uid] = {
21
+ newState: updatedState,
22
+ oldState: current.oldState,
23
+ scheduledState: updatedState
24
+ };
25
+ }
26
+ return Promise.resolve(updatedState);
27
+ };
8
28
  return {
9
29
  clear() {
10
30
  for (const key of Object.keys(states)) {
@@ -43,14 +63,39 @@ const create$e = () => {
43
63
  Object.assign(commandMapRef, commandMap);
44
64
  },
45
65
  set(uid, oldState, newState, scheduledState) {
66
+ const current = states[uid];
67
+ if (!current || oldState === newState && newState !== current.newState) {
68
+ generations[uid] = getGeneration(uid) + 1;
69
+ }
46
70
  states[uid] = {
47
71
  newState,
48
72
  oldState,
49
73
  scheduledState: scheduledState ?? newState
50
74
  };
51
75
  },
76
+ wrapAsyncCommand(fn) {
77
+ const wrapped = async (uid, ...args) => {
78
+ const generation = getGeneration(uid);
79
+ let latestState = states[uid].newState;
80
+ const context = {
81
+ getState: () => {
82
+ if (isCurrentGeneration(uid, generation)) {
83
+ latestState = states[uid].newState;
84
+ }
85
+ return latestState;
86
+ },
87
+ updateState: async updater => {
88
+ latestState = await updateState(uid, generation, latestState, updater);
89
+ return latestState;
90
+ }
91
+ };
92
+ await fn(context, ...args);
93
+ };
94
+ return wrapped;
95
+ },
52
96
  wrapCommand(fn) {
53
97
  const wrapped = async (uid, ...args) => {
98
+ const generation = getGeneration(uid);
54
99
  const {
55
100
  newState,
56
101
  oldState
@@ -59,6 +104,9 @@ const create$e = () => {
59
104
  if (oldState === newerState || newState === newerState) {
60
105
  return;
61
106
  }
107
+ if (!isCurrentGeneration(uid, generation)) {
108
+ return;
109
+ }
62
110
  const latestOld = states[uid];
63
111
  const latestNew = {
64
112
  ...latestOld.newState,
@@ -83,6 +131,7 @@ const create$e = () => {
83
131
  },
84
132
  wrapLoadContent(fn) {
85
133
  const wrapped = async (uid, ...args) => {
134
+ const generation = getGeneration(uid);
86
135
  const {
87
136
  newState,
88
137
  oldState
@@ -97,6 +146,11 @@ const create$e = () => {
97
146
  error
98
147
  };
99
148
  }
149
+ if (!isCurrentGeneration(uid, generation)) {
150
+ return {
151
+ error
152
+ };
153
+ }
100
154
  const latestOld = states[uid];
101
155
  const latestNew = {
102
156
  ...latestOld.newState,
@@ -380,7 +434,6 @@ const walkValue = (value, transferrables, isTransferrable) => {
380
434
  for (const property of Object.values(value)) {
381
435
  walkValue(property, transferrables, isTransferrable);
382
436
  }
383
- return;
384
437
  }
385
438
  };
386
439
  const getTransferrables = value => {
@@ -534,7 +587,14 @@ class IpcError extends VError {
534
587
  const cause = new Error(message);
535
588
  // @ts-ignore
536
589
  cause.code = code;
537
- cause.stack = stack;
590
+ if (stack) {
591
+ Object.defineProperty(cause, 'stack', {
592
+ configurable: true,
593
+ enumerable: false,
594
+ value: stack,
595
+ writable: true
596
+ });
597
+ }
538
598
  super(cause, betterMessage);
539
599
  } else {
540
600
  super(betterMessage);
@@ -1392,9 +1452,14 @@ const create$4 = async ({
1392
1452
  }) => {
1393
1453
  // TODO create a commandMap per rpc instance
1394
1454
  register(commandMap);
1395
- const rawIpc = await IpcParentWithWebSocket$1.create({
1396
- webSocket
1397
- });
1455
+ let rawIpc;
1456
+ try {
1457
+ rawIpc = await IpcParentWithWebSocket$1.create({
1458
+ webSocket
1459
+ });
1460
+ } catch (error) {
1461
+ throw new VError(error, 'Failed to create rpc connection');
1462
+ }
1398
1463
  const ipc = IpcParentWithWebSocket$1.wrap(rawIpc);
1399
1464
  handleIpc(ipc);
1400
1465
  const rpc = createRpc(ipc);
@@ -1507,7 +1572,15 @@ const create = rpcId => {
1507
1572
  };
1508
1573
  };
1509
1574
 
1575
+ const Audio = 0;
1576
+ const Button = 1;
1577
+ const Col = 2;
1578
+ const ColGroup = 3;
1510
1579
  const Div = 4;
1580
+ const H1 = 5;
1581
+ const Input = 6;
1582
+ const Kbd = 7;
1583
+ const Span = 8;
1511
1584
  const Table$1 = 9;
1512
1585
  const TBody = 10;
1513
1586
  const Td = 11;
@@ -1515,9 +1588,159 @@ const Text = 12;
1515
1588
  const Th = 13;
1516
1589
  const THead = 14;
1517
1590
  const Tr = 15;
1591
+ const I = 16;
1592
+ const Img = 17;
1593
+ const Root = 0;
1594
+ const Ins = 20;
1595
+ const Del = 21;
1596
+ const H2 = 22;
1597
+ const H3 = 23;
1598
+ const H4 = 24;
1599
+ const H5 = 25;
1600
+ const H6 = 26;
1601
+ const Article = 27;
1602
+ const Aside = 28;
1603
+ const Footer = 29;
1604
+ const Header = 30;
1605
+ const Nav = 40;
1606
+ const Section = 41;
1607
+ const Search = 42;
1608
+ const Dd = 43;
1609
+ const Dl = 44;
1610
+ const Figcaption = 45;
1611
+ const Figure = 46;
1612
+ const Hr = 47;
1613
+ const Li = 48;
1614
+ const Ol = 49;
1615
+ const P = 50;
1518
1616
  const Pre = 51;
1617
+ const A = 53;
1618
+ const Abbr = 54;
1619
+ const Br = 55;
1620
+ const Cite = 56;
1621
+ const Data = 57;
1622
+ const Time = 58;
1623
+ const Tfoot = 59;
1624
+ const Ul = 60;
1625
+ const Video = 61;
1626
+ const TextArea = 62;
1627
+ const Select = 63;
1628
+ const Option = 64;
1629
+ const Code = 65;
1630
+ const Label = 66;
1631
+ const Dt = 67;
1632
+ const Iframe = 68;
1633
+ const Main = 69;
1634
+ const Strong = 70;
1635
+ const Em = 71;
1636
+ const Style = 72;
1637
+ const Html = 73;
1638
+ const Head = 74;
1639
+ const Title = 75;
1640
+ const Meta = 76;
1641
+ const Canvas = 77;
1642
+ const Form = 78;
1643
+ const BlockQuote = 79;
1644
+ const Quote = 80;
1645
+ const Circle = 81;
1646
+ const Defs = 82;
1647
+ const Ellipse = 83;
1648
+ const G = 84;
1649
+ const Line = 85;
1650
+ const Path = 86;
1651
+ const Polygon = 87;
1652
+ const Polyline = 88;
1653
+ const Rect = 89;
1654
+ const Svg = 90;
1655
+ const Use = 91;
1519
1656
  const Reference = 100;
1520
1657
 
1658
+ const VirtualDomElements = {
1659
+ __proto__: null,
1660
+ A,
1661
+ Abbr,
1662
+ Article,
1663
+ Aside,
1664
+ Audio,
1665
+ BlockQuote,
1666
+ Br,
1667
+ Button,
1668
+ Canvas,
1669
+ Circle,
1670
+ Cite,
1671
+ Code,
1672
+ Col,
1673
+ ColGroup,
1674
+ Data,
1675
+ Dd,
1676
+ Defs,
1677
+ Del,
1678
+ Div,
1679
+ Dl,
1680
+ Dt,
1681
+ Ellipse,
1682
+ Em,
1683
+ Figcaption,
1684
+ Figure,
1685
+ Footer,
1686
+ Form,
1687
+ G,
1688
+ H1,
1689
+ H2,
1690
+ H3,
1691
+ H4,
1692
+ H5,
1693
+ H6,
1694
+ Head,
1695
+ Header,
1696
+ Hr,
1697
+ Html,
1698
+ I,
1699
+ Iframe,
1700
+ Img,
1701
+ Input,
1702
+ Ins,
1703
+ Kbd,
1704
+ Label,
1705
+ Li,
1706
+ Line,
1707
+ Main,
1708
+ Meta,
1709
+ Nav,
1710
+ Ol,
1711
+ Option,
1712
+ P,
1713
+ Path,
1714
+ Polygon,
1715
+ Polyline,
1716
+ Pre,
1717
+ Quote,
1718
+ Rect,
1719
+ Reference,
1720
+ Root,
1721
+ Search,
1722
+ Section,
1723
+ Select,
1724
+ Span,
1725
+ Strong,
1726
+ Style,
1727
+ Svg,
1728
+ TBody,
1729
+ THead,
1730
+ Table: Table$1,
1731
+ Td,
1732
+ Text,
1733
+ TextArea,
1734
+ Tfoot,
1735
+ Th,
1736
+ Time,
1737
+ Title,
1738
+ Tr,
1739
+ Ul,
1740
+ Use,
1741
+ Video
1742
+ };
1743
+
1521
1744
  const ClientX = 'event.clientX';
1522
1745
  const ClientY = 'event.clientY';
1523
1746
 
@@ -1541,6 +1764,7 @@ const Remote = 3;
1541
1764
 
1542
1765
  const ErrorWorker = 3308;
1543
1766
  const FileSystemWorker$1 = 209;
1767
+ const ProcessExplorerRenderer = 33;
1544
1768
  const RendererWorker = 1;
1545
1769
 
1546
1770
  const FocusSelector = 'Viewlet.focusSelector';
@@ -1588,10 +1812,6 @@ const sendMessagePortToFileSystemWorker$1 = async (port, rpcId) => {
1588
1812
  const command = 'FileSystem.handleMessagePort';
1589
1813
  await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToFileSystemWorker', port, command, rpcId);
1590
1814
  };
1591
- const sendMessagePortToProcessExplorer$1 = async port => {
1592
- const command = 'ProcessExplorer.handleMessagePort';
1593
- await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToProcessExplorer', port, command, 0);
1594
- };
1595
1815
 
1596
1816
  const debugProcess = async (state, index = state.focusedIndex) => {
1597
1817
  const process = state.visibleProcesses[index];
@@ -1678,15 +1898,15 @@ const restart = (uid, interval) => {
1678
1898
  start(uid, interval);
1679
1899
  };
1680
1900
 
1681
- const sendMessagePortToProcessExplorer = async port => {
1682
- await sendMessagePortToProcessExplorer$1(port);
1901
+ const sendMessagePortToMainProcess = async port => {
1902
+ await invokeAndTransfer('SendMessagePortToMainProcess.sendMessagePortToMainProcess', port, 'HandleElectronMessagePort.handleElectronMessagePort', ProcessExplorerRenderer);
1683
1903
  };
1684
1904
 
1685
1905
  const launchProcessExplorerElectron = async () => {
1686
1906
  try {
1687
1907
  const rpc = await create$5({
1688
1908
  commandMap: {},
1689
- send: sendMessagePortToProcessExplorer
1909
+ send: sendMessagePortToMainProcess
1690
1910
  });
1691
1911
  return rpc;
1692
1912
  } catch (error) {
@@ -2205,6 +2425,10 @@ const renderFocusContext = (oldState, newState) => {
2205
2425
  return [SetFocusContext, newState.uid, newState.focused ? FocusExplorer : Empty];
2206
2426
  };
2207
2427
 
2428
+ const mergeClassNames = (...classNames) => {
2429
+ return classNames.filter(Boolean).join(' ');
2430
+ };
2431
+
2208
2432
  const text = data => {
2209
2433
  return {
2210
2434
  childCount: 0,
@@ -2213,6 +2437,8 @@ const text = data => {
2213
2437
  };
2214
2438
  };
2215
2439
 
2440
+ new Set(Object.values(VirtualDomElements));
2441
+
2216
2442
  const SetText = 1;
2217
2443
  const Replace = 2;
2218
2444
  const SetAttribute = 3;
@@ -2515,9 +2741,28 @@ const formatMemory = memory => {
2515
2741
  return `${(memory / 1000 ** 4).toFixed(1)} TB`;
2516
2742
  };
2517
2743
 
2744
+ const Focusable = 0;
2745
+
2746
+ const tableHeadNode = {
2747
+ childCount: 1,
2748
+ className: TableHead,
2749
+ role: RowGroup,
2750
+ type: THead
2751
+ };
2752
+ const headerRowNode = {
2753
+ childCount: 3,
2754
+ className: Row,
2755
+ role: Row$1,
2756
+ type: Tr
2757
+ };
2758
+ const headerCellNode = {
2759
+ childCount: 1,
2760
+ className: HeaderCell,
2761
+ type: Th
2762
+ };
2518
2763
  const getRowClassName = focused => {
2519
2764
  if (focused) {
2520
- return `${Row} ${RowFocused}`;
2765
+ return mergeClassNames(Row, RowFocused);
2521
2766
  }
2522
2767
  return Row;
2523
2768
  };
@@ -2551,25 +2796,10 @@ const getCellDom = (className, value, index, paddingLeft) => {
2551
2796
  }, text(value)];
2552
2797
  };
2553
2798
  const getHeaderDom = () => {
2554
- return [{
2555
- childCount: 1,
2556
- className: TableHead,
2557
- role: RowGroup,
2558
- type: THead
2559
- }, {
2560
- childCount: 3,
2561
- className: Row,
2562
- role: Row$1,
2563
- type: Tr
2564
- }, ...['Name', 'PID', 'Memory'].flatMap(label => [{
2565
- childCount: 1,
2566
- className: HeaderCell,
2567
- type: Th
2568
- }, text(label)])];
2799
+ return [tableHeadNode, headerRowNode, ...['Name', 'PID', 'Memory'].flatMap(label => [headerCellNode, text(label)])];
2569
2800
  };
2570
2801
  const getRowDom = (process, index, focused) => {
2571
2802
  return [{
2572
- ariaDescription: '',
2573
2803
  ariaExpanded: getAriaExpanded(process),
2574
2804
  ariaLevel: process.depth,
2575
2805
  childCount: 3,
@@ -2580,7 +2810,7 @@ const getRowDom = (process, index, focused) => {
2580
2810
  tabIndex: focused ? 0 : -1,
2581
2811
  title: process.cmd,
2582
2812
  type: Tr
2583
- }, ...getCellDom(`${Cell} ${NameCell}`, process.name, index, getPaddingLeft(process)), ...getCellDom(Cell, String(process.pid), index), ...getCellDom(Cell, formatMemory(process.memory), index)];
2813
+ }, ...getCellDom(mergeClassNames(Cell, NameCell), process.name, index, getPaddingLeft(process)), ...getCellDom(Cell, String(process.pid), index), ...getCellDom(Cell, formatMemory(process.memory), index)];
2584
2814
  };
2585
2815
  const getBodyDom = state => {
2586
2816
  const {
@@ -2604,16 +2834,26 @@ const getErrorSectionDom = (value, type) => {
2604
2834
  }, text(value)];
2605
2835
  };
2606
2836
  const hasError = state => {
2607
- return Boolean(state.errorMessage || state.errorCodeFrame || state.errorStack);
2837
+ const {
2838
+ errorCodeFrame,
2839
+ errorMessage,
2840
+ errorStack
2841
+ } = state;
2842
+ return Boolean(errorMessage || errorCodeFrame || errorStack);
2608
2843
  };
2609
2844
  const getErrorDom = state => {
2610
- const messageDom = getErrorSectionDom(state.errorMessage, Div);
2611
- const codeFrameDom = getErrorSectionDom(state.errorCodeFrame, Pre);
2612
- const stackDom = getErrorSectionDom(state.errorStack, Pre);
2845
+ const {
2846
+ errorCodeFrame,
2847
+ errorMessage,
2848
+ errorStack
2849
+ } = state;
2850
+ const messageDom = getErrorSectionDom(errorMessage, Div);
2851
+ const codeFrameDom = getErrorSectionDom(errorCodeFrame, Pre);
2852
+ const stackDom = getErrorSectionDom(errorStack, Pre);
2613
2853
  const childCount = messageDom.length / 2 + codeFrameDom.length / 2 + stackDom.length / 2;
2614
2854
  return [{
2615
2855
  childCount: 1,
2616
- className: `${Viewlet} ${ProcessExplorer}`,
2856
+ className: mergeClassNames(Viewlet, ProcessExplorer),
2617
2857
  role: None,
2618
2858
  type: Div
2619
2859
  }, {
@@ -2623,14 +2863,17 @@ const getErrorDom = state => {
2623
2863
  }, ...messageDom, ...codeFrameDom, ...stackDom];
2624
2864
  };
2625
2865
  const getTableDom = state => {
2866
+ const {
2867
+ visibleProcesses
2868
+ } = state;
2626
2869
  return [{
2627
2870
  childCount: 1,
2628
- className: `${Viewlet} ${ProcessExplorer}`,
2871
+ className: mergeClassNames(Viewlet, ProcessExplorer),
2629
2872
  role: None,
2630
2873
  type: Div
2631
2874
  }, {
2632
2875
  ariaLabel: 'Process Explorer',
2633
- ariaRowCount: state.visibleProcesses.length + 1,
2876
+ ariaRowCount: visibleProcesses.length + 1,
2634
2877
  childCount: 2,
2635
2878
  className: Table,
2636
2879
  onBlur: HandleBlur,
@@ -2640,12 +2883,15 @@ const getTableDom = state => {
2640
2883
  onFocus: HandleFocus,
2641
2884
  onPointerDown: HandlePointerDown,
2642
2885
  role: Grid,
2643
- tabIndex: 0,
2886
+ tabIndex: Focusable,
2644
2887
  type: Table$1
2645
2888
  }, ...getHeaderDom(), ...getBodyDom(state)];
2646
2889
  };
2647
2890
  const getDom = state => {
2648
- if (state.initial) {
2891
+ const {
2892
+ initial
2893
+ } = state;
2894
+ if (initial) {
2649
2895
  return [];
2650
2896
  }
2651
2897
  if (hasError(state)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/process-explorer-worker",
3
- "version": "3.10.0",
3
+ "version": "3.12.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",