@lvce-editor/running-extensions-view 1.12.0 → 1.13.1

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.
@@ -1117,7 +1117,7 @@ const createMockRpc = ({
1117
1117
  };
1118
1118
 
1119
1119
  const rpcs = Object.create(null);
1120
- const set$6 = (id, rpc) => {
1120
+ const set$5 = (id, rpc) => {
1121
1121
  rpcs[id] = rpc;
1122
1122
  };
1123
1123
  const get$1 = id => {
@@ -1150,7 +1150,7 @@ const create$2 = rpcId => {
1150
1150
  const mockRpc = createMockRpc({
1151
1151
  commandMap
1152
1152
  });
1153
- set$6(rpcId, mockRpc);
1153
+ set$5(rpcId, mockRpc);
1154
1154
  // @ts-ignore
1155
1155
  mockRpc[Symbol.dispose] = () => {
1156
1156
  remove(rpcId);
@@ -1159,7 +1159,7 @@ const create$2 = rpcId => {
1159
1159
  return mockRpc;
1160
1160
  },
1161
1161
  set(rpc) {
1162
- set$6(rpcId, rpc);
1162
+ set$5(rpcId, rpc);
1163
1163
  }
1164
1164
  };
1165
1165
  };
@@ -1345,14 +1345,14 @@ const ClipBoardWorker = 3400;
1345
1345
  const ExtensionManagementWorker = 9006;
1346
1346
  const MainProcess = -5;
1347
1347
  const RendererWorker = 1;
1348
- const SharedProcess = 1492;
1349
1348
 
1350
1349
  const SetCss = 'Viewlet.setCss';
1351
1350
  const SetDom2 = 'Viewlet.setDom2';
1351
+ const SetPatches = 'Viewlet.setPatches';
1352
1352
 
1353
1353
  const {
1354
1354
  invoke: invoke$3,
1355
- set: set$5
1355
+ set: set$4
1356
1356
  } = create$2(ClipBoardWorker);
1357
1357
  const writeText = async text => {
1358
1358
  return invoke$3('ClipBoard.writeText', text);
@@ -1360,7 +1360,7 @@ const writeText = async text => {
1360
1360
 
1361
1361
  const {
1362
1362
  invoke: invoke$2,
1363
- set: set$4
1363
+ set: set$3
1364
1364
  } = create$2(ExtensionManagementWorker);
1365
1365
  const disable2 = (id, platform) => {
1366
1366
  return invoke$2(`Extensions.disable2`, id, platform);
@@ -1368,13 +1368,13 @@ const disable2 = (id, platform) => {
1368
1368
 
1369
1369
  const {
1370
1370
  invoke: invoke$1,
1371
- set: set$3
1371
+ set: set$2
1372
1372
  } = create$2(MainProcess);
1373
1373
 
1374
1374
  const {
1375
1375
  invoke,
1376
- invokeAndTransfer: invokeAndTransfer$1,
1377
- set: set$2
1376
+ invokeAndTransfer,
1377
+ set: set$1
1378
1378
  } = create$2(RendererWorker);
1379
1379
  const showContextMenu2 = async (uid, menuId, x, y, args) => {
1380
1380
  number(uid);
@@ -1385,19 +1385,15 @@ const showContextMenu2 = async (uid, menuId, x, y, args) => {
1385
1385
  };
1386
1386
  const sendMessagePortToClipBoardWorker = async (port, rpcId) => {
1387
1387
  const command = 'ClipBoard.handleMessagePort';
1388
- await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToClipBoardWorker', port, command, rpcId);
1388
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToClipBoardWorker', port, command, rpcId);
1389
1389
  };
1390
1390
  const confirm = async (message, options) => {
1391
1391
  const result = await invoke('ConfirmPrompt.prompt', message, options);
1392
1392
  return result;
1393
1393
  };
1394
- const sendMessagePortToSharedProcess = async port => {
1395
- const command = 'HandleElectronMessagePort.handleElectronMessagePort';
1396
- await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToSharedProcess', port, command, 0);
1397
- };
1398
1394
  const sendMessagePortToExtensionManagementWorker = async (port, rpcId) => {
1399
1395
  const command = 'Extensions.handleMessagePort';
1400
- await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionManagementWorker', port, command, rpcId);
1396
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionManagementWorker', port, command, rpcId);
1401
1397
  };
1402
1398
  const getWindowId = async () => {
1403
1399
  return invoke('GetWindowId.getWindowId');
@@ -1409,11 +1405,6 @@ const openUrl = async uri => {
1409
1405
  await invoke('Open.openUrl', uri);
1410
1406
  };
1411
1407
 
1412
- const {
1413
- invokeAndTransfer,
1414
- set: set$1
1415
- } = create$2(SharedProcess);
1416
-
1417
1408
  const copyId$1 = async (state, index) => {
1418
1409
  const {
1419
1410
  extensions
@@ -1708,9 +1699,14 @@ const isCssEqual = (oldState, newState) => {
1708
1699
 
1709
1700
  const RenderDom = 1;
1710
1701
  const RenderCss = 2;
1702
+ const RenderIncremental = 3;
1711
1703
 
1712
1704
  const diff2 = uid => {
1713
- return diff(uid, [isDomEqual, isCssEqual], [RenderDom, RenderCss]);
1705
+ const {
1706
+ oldState
1707
+ } = get(uid);
1708
+ const domDiffType = oldState.loaded ? RenderIncremental : RenderDom;
1709
+ return diff(uid, [isDomEqual, isCssEqual], [domDiffType, RenderCss]);
1714
1710
  };
1715
1711
 
1716
1712
  const disable$1 = async (state, index) => {
@@ -1892,21 +1888,15 @@ const handleBlur = state => {
1892
1888
  };
1893
1889
  };
1894
1890
 
1895
- const getIndex = (eventY, y, itemHeight) => {
1896
- const index = Math.floor((eventY - y) / itemHeight);
1897
- return index;
1898
- };
1899
- const handleClickAt = (state, eventY) => {
1891
+ const handleClickAt = (state, index) => {
1900
1892
  const {
1901
- extensions,
1902
- itemHeight,
1903
- y
1893
+ extensions
1904
1894
  } = state;
1905
- const index = getIndex(eventY, y, itemHeight);
1895
+ const selectedIndex = Number(index);
1906
1896
  return {
1907
1897
  ...state,
1908
1898
  focusOutline: false,
1909
- selectedIndex: extensions[index] ? index : -1
1899
+ selectedIndex: extensions[selectedIndex] ? selectedIndex : -1
1910
1900
  };
1911
1901
  };
1912
1902
 
@@ -1981,6 +1971,264 @@ const text = data => {
1981
1971
 
1982
1972
  new Set(Object.values(VirtualDomElements));
1983
1973
 
1974
+ const SetText = 1;
1975
+ const Replace = 2;
1976
+ const SetAttribute = 3;
1977
+ const RemoveAttribute = 4;
1978
+ const Add = 6;
1979
+ const NavigateChild = 7;
1980
+ const NavigateParent = 8;
1981
+ const RemoveChild = 9;
1982
+ const NavigateSibling = 10;
1983
+ const SetReferenceNodeUid = 11;
1984
+
1985
+ const isKey = key => {
1986
+ return key !== 'type' && key !== 'childCount';
1987
+ };
1988
+
1989
+ const getKeys = node => {
1990
+ const keys = Object.keys(node).filter(isKey);
1991
+ return keys;
1992
+ };
1993
+
1994
+ const arrayToTree = nodes => {
1995
+ const result = [];
1996
+ let i = 0;
1997
+ while (i < nodes.length) {
1998
+ const node = nodes[i];
1999
+ const {
2000
+ children,
2001
+ nodesConsumed
2002
+ } = getChildrenWithCount(nodes, i + 1, node.childCount || 0);
2003
+ result.push({
2004
+ node,
2005
+ children
2006
+ });
2007
+ i += 1 + nodesConsumed;
2008
+ }
2009
+ return result;
2010
+ };
2011
+ const getChildrenWithCount = (nodes, startIndex, childCount) => {
2012
+ if (childCount === 0) {
2013
+ return {
2014
+ children: [],
2015
+ nodesConsumed: 0
2016
+ };
2017
+ }
2018
+ const children = [];
2019
+ let i = startIndex;
2020
+ let remaining = childCount;
2021
+ let totalConsumed = 0;
2022
+ while (remaining > 0 && i < nodes.length) {
2023
+ const node = nodes[i];
2024
+ const nodeChildCount = node.childCount || 0;
2025
+ const {
2026
+ children: nodeChildren,
2027
+ nodesConsumed
2028
+ } = getChildrenWithCount(nodes, i + 1, nodeChildCount);
2029
+ children.push({
2030
+ node,
2031
+ children: nodeChildren
2032
+ });
2033
+ const nodeSize = 1 + nodesConsumed;
2034
+ i += nodeSize;
2035
+ totalConsumed += nodeSize;
2036
+ remaining--;
2037
+ }
2038
+ return {
2039
+ children,
2040
+ nodesConsumed: totalConsumed
2041
+ };
2042
+ };
2043
+
2044
+ const compareNodes = (oldNode, newNode) => {
2045
+ // Check if node type changed - return null to signal incompatible nodes
2046
+ // (caller should handle this with a Replace operation)
2047
+ if (oldNode.type !== newNode.type) {
2048
+ return null;
2049
+ }
2050
+ const patches = [];
2051
+ // Handle reference nodes - special handling for uid changes
2052
+ if (oldNode.type === Reference) {
2053
+ if (oldNode.uid !== newNode.uid) {
2054
+ patches.push({
2055
+ type: SetReferenceNodeUid,
2056
+ uid: newNode.uid
2057
+ });
2058
+ }
2059
+ return patches;
2060
+ }
2061
+ // Handle text nodes
2062
+ if (oldNode.type === Text && newNode.type === Text) {
2063
+ if (oldNode.text !== newNode.text) {
2064
+ patches.push({
2065
+ type: SetText,
2066
+ value: newNode.text
2067
+ });
2068
+ }
2069
+ return patches;
2070
+ }
2071
+ // Compare attributes
2072
+ const oldKeys = getKeys(oldNode);
2073
+ const newKeys = getKeys(newNode);
2074
+ // Check for attribute changes
2075
+ for (const key of newKeys) {
2076
+ if (oldNode[key] !== newNode[key]) {
2077
+ patches.push({
2078
+ type: SetAttribute,
2079
+ key,
2080
+ value: newNode[key]
2081
+ });
2082
+ }
2083
+ }
2084
+ // Check for removed attributes
2085
+ for (const key of oldKeys) {
2086
+ if (!Object.hasOwn(newNode, key)) {
2087
+ patches.push({
2088
+ type: RemoveAttribute,
2089
+ key
2090
+ });
2091
+ }
2092
+ }
2093
+ return patches;
2094
+ };
2095
+
2096
+ const treeToArray = node => {
2097
+ const result = [node.node];
2098
+ for (const child of node.children) {
2099
+ result.push(...treeToArray(child));
2100
+ }
2101
+ return result;
2102
+ };
2103
+
2104
+ const navigateToChild = (patches, currentChildIndex, index) => {
2105
+ if (currentChildIndex === -1) {
2106
+ patches.push({
2107
+ type: NavigateChild,
2108
+ index
2109
+ });
2110
+ return index;
2111
+ }
2112
+ if (currentChildIndex !== index) {
2113
+ patches.push({
2114
+ type: NavigateSibling,
2115
+ index
2116
+ });
2117
+ }
2118
+ return index;
2119
+ };
2120
+ const navigateToParent = (patches, currentChildIndex) => {
2121
+ if (currentChildIndex >= 0) {
2122
+ patches.push({
2123
+ type: NavigateParent
2124
+ });
2125
+ }
2126
+ return -1;
2127
+ };
2128
+ const addTree = (newNode, patches) => {
2129
+ patches.push({
2130
+ type: Add,
2131
+ nodes: treeToArray(newNode)
2132
+ });
2133
+ };
2134
+ const replaceTree = (newNode, patches) => {
2135
+ patches.push({
2136
+ type: Replace,
2137
+ nodes: treeToArray(newNode)
2138
+ });
2139
+ };
2140
+ const diffExistingChild = (oldNode, newNode, patches, currentChildIndex, index) => {
2141
+ const nodePatches = compareNodes(oldNode.node, newNode.node);
2142
+ if (nodePatches === null) {
2143
+ const nextChildIndex = navigateToChild(patches, currentChildIndex, index);
2144
+ replaceTree(newNode, patches);
2145
+ return nextChildIndex;
2146
+ }
2147
+ const hasChildrenToCompare = oldNode.children.length > 0 || newNode.children.length > 0;
2148
+ if (nodePatches.length === 0 && !hasChildrenToCompare) {
2149
+ return currentChildIndex;
2150
+ }
2151
+ const nextChildIndex = navigateToChild(patches, currentChildIndex, index);
2152
+ if (nodePatches.length > 0) {
2153
+ patches.push(...nodePatches);
2154
+ }
2155
+ if (hasChildrenToCompare) {
2156
+ diffChildren(oldNode.children, newNode.children, patches);
2157
+ }
2158
+ return nextChildIndex;
2159
+ };
2160
+ const diffRootNode = (oldNode, newNode, patches) => {
2161
+ const nodePatches = compareNodes(oldNode.node, newNode.node);
2162
+ if (nodePatches === null) {
2163
+ replaceTree(newNode, patches);
2164
+ return;
2165
+ }
2166
+ if (nodePatches.length > 0) {
2167
+ patches.push(...nodePatches);
2168
+ }
2169
+ if (oldNode.children.length > 0 || newNode.children.length > 0) {
2170
+ diffChildren(oldNode.children, newNode.children, patches);
2171
+ }
2172
+ };
2173
+ const diffChildren = (oldChildren, newChildren, patches) => {
2174
+ const maxLength = Math.max(oldChildren.length, newChildren.length);
2175
+ let currentChildIndex = -1;
2176
+ const indicesToRemove = [];
2177
+ for (let i = 0; i < maxLength; i++) {
2178
+ const oldNode = oldChildren[i];
2179
+ const newNode = newChildren[i];
2180
+ if (!oldNode && !newNode) {
2181
+ continue;
2182
+ }
2183
+ if (!oldNode) {
2184
+ currentChildIndex = navigateToParent(patches, currentChildIndex);
2185
+ addTree(newNode, patches);
2186
+ continue;
2187
+ }
2188
+ if (!newNode) {
2189
+ indicesToRemove.push(i);
2190
+ continue;
2191
+ }
2192
+ currentChildIndex = diffExistingChild(oldNode, newNode, patches, currentChildIndex, i);
2193
+ }
2194
+ navigateToParent(patches, currentChildIndex);
2195
+ for (let j = indicesToRemove.length - 1; j >= 0; j--) {
2196
+ patches.push({
2197
+ type: RemoveChild,
2198
+ index: indicesToRemove[j]
2199
+ });
2200
+ }
2201
+ };
2202
+ const diffTrees = (oldTree, newTree, patches, path) => {
2203
+ if (path.length === 0 && oldTree.length === 1 && newTree.length === 1) {
2204
+ diffRootNode(oldTree[0], newTree[0], patches);
2205
+ return;
2206
+ }
2207
+ diffChildren(oldTree, newTree, patches);
2208
+ };
2209
+
2210
+ const removeTrailingNavigationPatches = patches => {
2211
+ while (patches.length > 0) {
2212
+ const patch = patches.at(-1);
2213
+ if (patch.type !== NavigateChild && patch.type !== NavigateParent && patch.type !== NavigateSibling) {
2214
+ break;
2215
+ }
2216
+ patches.pop();
2217
+ }
2218
+ return patches;
2219
+ };
2220
+
2221
+ const diffTree = (oldNodes, newNodes) => {
2222
+ // Step 1: Convert flat arrays to tree structures
2223
+ const oldTree = arrayToTree(oldNodes);
2224
+ const newTree = arrayToTree(newNodes);
2225
+ // Step 3: Compare the trees
2226
+ const patches = [];
2227
+ diffTrees(oldTree, newTree, patches, []);
2228
+ // Remove trailing navigation patches since they serve no purpose
2229
+ return removeTrailingNavigationPatches(patches);
2230
+ };
2231
+
1984
2232
  const List = 'list';
1985
2233
  const ListItem = 'listitem';
1986
2234
  const None = 'none';
@@ -2153,16 +2401,24 @@ const getRunningExtensionsVirtualDom = (extensions, loaded, focusedIndex = -1, s
2153
2401
  };
2154
2402
 
2155
2403
  const renderDom = (oldState, newState) => {
2156
- // TODO incremental rendering
2157
2404
  return [SetDom2, newState.uid, getRunningExtensionsVirtualDom(newState.extensions, newState.loaded, newState.focusedIndex, newState.selectedIndex, newState.focusOutline)];
2158
2405
  };
2159
2406
 
2407
+ const renderIncremental = (oldState, newState) => {
2408
+ const oldDom = getRunningExtensionsVirtualDom(oldState.extensions, oldState.loaded, oldState.focusedIndex, oldState.selectedIndex, oldState.focusOutline);
2409
+ const newDom = getRunningExtensionsVirtualDom(newState.extensions, newState.loaded, newState.focusedIndex, newState.selectedIndex, newState.focusOutline);
2410
+ const patches = diffTree(oldDom, newDom);
2411
+ return [SetPatches, newState.uid, patches];
2412
+ };
2413
+
2160
2414
  const getRenderer = diffType => {
2161
2415
  switch (diffType) {
2162
2416
  case RenderCss:
2163
2417
  return renderCss;
2164
2418
  case RenderDom:
2165
2419
  return renderDom;
2420
+ case RenderIncremental:
2421
+ return renderIncremental;
2166
2422
  default:
2167
2423
  throw new Error(`Unknown diff type ${diffType}`);
2168
2424
  }
@@ -2183,7 +2439,7 @@ const renderEventListeners = () => {
2183
2439
  preventDefault: true
2184
2440
  }, {
2185
2441
  name: HandleClick,
2186
- params: ['handleClickAt', ClientY],
2442
+ params: ['handleClickAt', 'event.target.dataset.index'],
2187
2443
  preventDefault: true
2188
2444
  }, {
2189
2445
  name: HandleBlur,
@@ -2216,6 +2472,23 @@ const getIssuesUrl = repository => {
2216
2472
  return `https://github.com/${owner}/${repositoryName}/issues`;
2217
2473
  };
2218
2474
 
2475
+ const OpenCommand = {
2476
+ External: 1,
2477
+ Url: 2
2478
+ };
2479
+ const getOpenCommand = platform => {
2480
+ if (platform === Electron) {
2481
+ return OpenCommand.External;
2482
+ }
2483
+ return OpenCommand.Url;
2484
+ };
2485
+ const applyOpenCommand = async (cmd, issuesUrl) => {
2486
+ if (cmd === OpenCommand.External) {
2487
+ await openExternal(issuesUrl);
2488
+ } else {
2489
+ await openUrl(issuesUrl);
2490
+ }
2491
+ };
2219
2492
  const reportIssue = async (state, index) => {
2220
2493
  const {
2221
2494
  extensions,
@@ -2226,11 +2499,8 @@ const reportIssue = async (state, index) => {
2226
2499
  await confirm(reportingIssuesNotSupported());
2227
2500
  return state;
2228
2501
  }
2229
- if (platform === Electron) {
2230
- await openExternal(issuesUrl);
2231
- } else {
2232
- await openUrl(issuesUrl);
2233
- }
2502
+ const cmd = getOpenCommand(platform);
2503
+ await applyOpenCommand(cmd, issuesUrl);
2234
2504
  return state;
2235
2505
  };
2236
2506
 
@@ -2301,21 +2571,10 @@ const commandMap = {
2301
2571
  'RunningExtensions.takeHeapSnapshot': wrapCommand(takeHeapSnapshot)
2302
2572
  };
2303
2573
 
2304
- const send$3 = async port => {
2574
+ const send$2 = async port => {
2305
2575
  await sendMessagePortToClipBoardWorker(port, 0);
2306
2576
  };
2307
2577
  const initializeClipBoardWorker = async () => {
2308
- const rpc = await create$4({
2309
- commandMap: {},
2310
- send: send$3
2311
- });
2312
- set$5(rpc);
2313
- };
2314
-
2315
- const send$2 = async port => {
2316
- await sendMessagePortToExtensionManagementWorker(port, 0);
2317
- };
2318
- const initializeExtensionManagementWorker = async () => {
2319
2578
  const rpc = await create$4({
2320
2579
  commandMap: {},
2321
2580
  send: send$2
@@ -2324,9 +2583,9 @@ const initializeExtensionManagementWorker = async () => {
2324
2583
  };
2325
2584
 
2326
2585
  const send$1 = async port => {
2327
- await invokeAndTransfer('TemporaryMessagePort.sendToElectron', port, MainProcess, 0);
2586
+ await sendMessagePortToExtensionManagementWorker(port, 0);
2328
2587
  };
2329
- const initializeMainProcess = async () => {
2588
+ const initializeExtensionManagementWorker = async () => {
2330
2589
  const rpc = await create$4({
2331
2590
  commandMap: {},
2332
2591
  send: send$1
@@ -2335,23 +2594,26 @@ const initializeMainProcess = async () => {
2335
2594
  };
2336
2595
 
2337
2596
  const send = async port => {
2338
- await sendMessagePortToSharedProcess(port);
2597
+ await invokeAndTransfer('SendMessagePortToMainProcess.sendMessagePortToMainProcess', port, 'HandleElectronMessagePort.handleElectronMessagePort', 0);
2339
2598
  };
2340
- const initializeSharedProcess = async () => {
2599
+ const initializeMainProcess = async () => {
2341
2600
  const rpc = await create$4({
2342
2601
  commandMap: {},
2343
2602
  send
2344
2603
  });
2345
- set$1(rpc);
2604
+ set$2(rpc);
2346
2605
  };
2347
2606
 
2348
- const listen = async () => {
2349
- registerCommands(commandMap);
2607
+ const initializeRendererWorker = async () => {
2350
2608
  const rpc = await create$3({
2351
2609
  commandMap: commandMap
2352
2610
  });
2353
- set$2(rpc);
2354
- await Promise.all([initializeClipBoardWorker(), initializeExtensionManagementWorker(), initializeMainProcess(), initializeSharedProcess()]);
2611
+ set$1(rpc);
2612
+ };
2613
+
2614
+ const listen = async () => {
2615
+ registerCommands(commandMap);
2616
+ await Promise.all([initializeRendererWorker(), initializeClipBoardWorker(), initializeExtensionManagementWorker(), initializeMainProcess()]);
2355
2617
  };
2356
2618
 
2357
2619
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/running-extensions-view",
3
- "version": "1.12.0",
3
+ "version": "1.13.1",
4
4
  "description": "Running Extensions View Worker",
5
5
  "repository": {
6
6
  "type": "git",