@lvce-editor/running-extensions-view 1.12.0 → 1.13.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.
@@ -1349,6 +1349,7 @@ const SharedProcess = 1492;
1349
1349
 
1350
1350
  const SetCss = 'Viewlet.setCss';
1351
1351
  const SetDom2 = 'Viewlet.setDom2';
1352
+ const SetPatches = 'Viewlet.setPatches';
1352
1353
 
1353
1354
  const {
1354
1355
  invoke: invoke$3,
@@ -1708,9 +1709,14 @@ const isCssEqual = (oldState, newState) => {
1708
1709
 
1709
1710
  const RenderDom = 1;
1710
1711
  const RenderCss = 2;
1712
+ const RenderIncremental = 3;
1711
1713
 
1712
1714
  const diff2 = uid => {
1713
- return diff(uid, [isDomEqual, isCssEqual], [RenderDom, RenderCss]);
1715
+ const {
1716
+ oldState
1717
+ } = get(uid);
1718
+ const domDiffType = oldState.loaded ? RenderIncremental : RenderDom;
1719
+ return diff(uid, [isDomEqual, isCssEqual], [domDiffType, RenderCss]);
1714
1720
  };
1715
1721
 
1716
1722
  const disable$1 = async (state, index) => {
@@ -1892,21 +1898,15 @@ const handleBlur = state => {
1892
1898
  };
1893
1899
  };
1894
1900
 
1895
- const getIndex = (eventY, y, itemHeight) => {
1896
- const index = Math.floor((eventY - y) / itemHeight);
1897
- return index;
1898
- };
1899
- const handleClickAt = (state, eventY) => {
1901
+ const handleClickAt = (state, index) => {
1900
1902
  const {
1901
- extensions,
1902
- itemHeight,
1903
- y
1903
+ extensions
1904
1904
  } = state;
1905
- const index = getIndex(eventY, y, itemHeight);
1905
+ const selectedIndex = Number(index);
1906
1906
  return {
1907
1907
  ...state,
1908
1908
  focusOutline: false,
1909
- selectedIndex: extensions[index] ? index : -1
1909
+ selectedIndex: extensions[selectedIndex] ? selectedIndex : -1
1910
1910
  };
1911
1911
  };
1912
1912
 
@@ -1981,6 +1981,264 @@ const text = data => {
1981
1981
 
1982
1982
  new Set(Object.values(VirtualDomElements));
1983
1983
 
1984
+ const SetText = 1;
1985
+ const Replace = 2;
1986
+ const SetAttribute = 3;
1987
+ const RemoveAttribute = 4;
1988
+ const Add = 6;
1989
+ const NavigateChild = 7;
1990
+ const NavigateParent = 8;
1991
+ const RemoveChild = 9;
1992
+ const NavigateSibling = 10;
1993
+ const SetReferenceNodeUid = 11;
1994
+
1995
+ const isKey = key => {
1996
+ return key !== 'type' && key !== 'childCount';
1997
+ };
1998
+
1999
+ const getKeys = node => {
2000
+ const keys = Object.keys(node).filter(isKey);
2001
+ return keys;
2002
+ };
2003
+
2004
+ const arrayToTree = nodes => {
2005
+ const result = [];
2006
+ let i = 0;
2007
+ while (i < nodes.length) {
2008
+ const node = nodes[i];
2009
+ const {
2010
+ children,
2011
+ nodesConsumed
2012
+ } = getChildrenWithCount(nodes, i + 1, node.childCount || 0);
2013
+ result.push({
2014
+ node,
2015
+ children
2016
+ });
2017
+ i += 1 + nodesConsumed;
2018
+ }
2019
+ return result;
2020
+ };
2021
+ const getChildrenWithCount = (nodes, startIndex, childCount) => {
2022
+ if (childCount === 0) {
2023
+ return {
2024
+ children: [],
2025
+ nodesConsumed: 0
2026
+ };
2027
+ }
2028
+ const children = [];
2029
+ let i = startIndex;
2030
+ let remaining = childCount;
2031
+ let totalConsumed = 0;
2032
+ while (remaining > 0 && i < nodes.length) {
2033
+ const node = nodes[i];
2034
+ const nodeChildCount = node.childCount || 0;
2035
+ const {
2036
+ children: nodeChildren,
2037
+ nodesConsumed
2038
+ } = getChildrenWithCount(nodes, i + 1, nodeChildCount);
2039
+ children.push({
2040
+ node,
2041
+ children: nodeChildren
2042
+ });
2043
+ const nodeSize = 1 + nodesConsumed;
2044
+ i += nodeSize;
2045
+ totalConsumed += nodeSize;
2046
+ remaining--;
2047
+ }
2048
+ return {
2049
+ children,
2050
+ nodesConsumed: totalConsumed
2051
+ };
2052
+ };
2053
+
2054
+ const compareNodes = (oldNode, newNode) => {
2055
+ // Check if node type changed - return null to signal incompatible nodes
2056
+ // (caller should handle this with a Replace operation)
2057
+ if (oldNode.type !== newNode.type) {
2058
+ return null;
2059
+ }
2060
+ const patches = [];
2061
+ // Handle reference nodes - special handling for uid changes
2062
+ if (oldNode.type === Reference) {
2063
+ if (oldNode.uid !== newNode.uid) {
2064
+ patches.push({
2065
+ type: SetReferenceNodeUid,
2066
+ uid: newNode.uid
2067
+ });
2068
+ }
2069
+ return patches;
2070
+ }
2071
+ // Handle text nodes
2072
+ if (oldNode.type === Text && newNode.type === Text) {
2073
+ if (oldNode.text !== newNode.text) {
2074
+ patches.push({
2075
+ type: SetText,
2076
+ value: newNode.text
2077
+ });
2078
+ }
2079
+ return patches;
2080
+ }
2081
+ // Compare attributes
2082
+ const oldKeys = getKeys(oldNode);
2083
+ const newKeys = getKeys(newNode);
2084
+ // Check for attribute changes
2085
+ for (const key of newKeys) {
2086
+ if (oldNode[key] !== newNode[key]) {
2087
+ patches.push({
2088
+ type: SetAttribute,
2089
+ key,
2090
+ value: newNode[key]
2091
+ });
2092
+ }
2093
+ }
2094
+ // Check for removed attributes
2095
+ for (const key of oldKeys) {
2096
+ if (!Object.hasOwn(newNode, key)) {
2097
+ patches.push({
2098
+ type: RemoveAttribute,
2099
+ key
2100
+ });
2101
+ }
2102
+ }
2103
+ return patches;
2104
+ };
2105
+
2106
+ const treeToArray = node => {
2107
+ const result = [node.node];
2108
+ for (const child of node.children) {
2109
+ result.push(...treeToArray(child));
2110
+ }
2111
+ return result;
2112
+ };
2113
+
2114
+ const navigateToChild = (patches, currentChildIndex, index) => {
2115
+ if (currentChildIndex === -1) {
2116
+ patches.push({
2117
+ type: NavigateChild,
2118
+ index
2119
+ });
2120
+ return index;
2121
+ }
2122
+ if (currentChildIndex !== index) {
2123
+ patches.push({
2124
+ type: NavigateSibling,
2125
+ index
2126
+ });
2127
+ }
2128
+ return index;
2129
+ };
2130
+ const navigateToParent = (patches, currentChildIndex) => {
2131
+ if (currentChildIndex >= 0) {
2132
+ patches.push({
2133
+ type: NavigateParent
2134
+ });
2135
+ }
2136
+ return -1;
2137
+ };
2138
+ const addTree = (newNode, patches) => {
2139
+ patches.push({
2140
+ type: Add,
2141
+ nodes: treeToArray(newNode)
2142
+ });
2143
+ };
2144
+ const replaceTree = (newNode, patches) => {
2145
+ patches.push({
2146
+ type: Replace,
2147
+ nodes: treeToArray(newNode)
2148
+ });
2149
+ };
2150
+ const diffExistingChild = (oldNode, newNode, patches, currentChildIndex, index) => {
2151
+ const nodePatches = compareNodes(oldNode.node, newNode.node);
2152
+ if (nodePatches === null) {
2153
+ const nextChildIndex = navigateToChild(patches, currentChildIndex, index);
2154
+ replaceTree(newNode, patches);
2155
+ return nextChildIndex;
2156
+ }
2157
+ const hasChildrenToCompare = oldNode.children.length > 0 || newNode.children.length > 0;
2158
+ if (nodePatches.length === 0 && !hasChildrenToCompare) {
2159
+ return currentChildIndex;
2160
+ }
2161
+ const nextChildIndex = navigateToChild(patches, currentChildIndex, index);
2162
+ if (nodePatches.length > 0) {
2163
+ patches.push(...nodePatches);
2164
+ }
2165
+ if (hasChildrenToCompare) {
2166
+ diffChildren(oldNode.children, newNode.children, patches);
2167
+ }
2168
+ return nextChildIndex;
2169
+ };
2170
+ const diffRootNode = (oldNode, newNode, patches) => {
2171
+ const nodePatches = compareNodes(oldNode.node, newNode.node);
2172
+ if (nodePatches === null) {
2173
+ replaceTree(newNode, patches);
2174
+ return;
2175
+ }
2176
+ if (nodePatches.length > 0) {
2177
+ patches.push(...nodePatches);
2178
+ }
2179
+ if (oldNode.children.length > 0 || newNode.children.length > 0) {
2180
+ diffChildren(oldNode.children, newNode.children, patches);
2181
+ }
2182
+ };
2183
+ const diffChildren = (oldChildren, newChildren, patches) => {
2184
+ const maxLength = Math.max(oldChildren.length, newChildren.length);
2185
+ let currentChildIndex = -1;
2186
+ const indicesToRemove = [];
2187
+ for (let i = 0; i < maxLength; i++) {
2188
+ const oldNode = oldChildren[i];
2189
+ const newNode = newChildren[i];
2190
+ if (!oldNode && !newNode) {
2191
+ continue;
2192
+ }
2193
+ if (!oldNode) {
2194
+ currentChildIndex = navigateToParent(patches, currentChildIndex);
2195
+ addTree(newNode, patches);
2196
+ continue;
2197
+ }
2198
+ if (!newNode) {
2199
+ indicesToRemove.push(i);
2200
+ continue;
2201
+ }
2202
+ currentChildIndex = diffExistingChild(oldNode, newNode, patches, currentChildIndex, i);
2203
+ }
2204
+ navigateToParent(patches, currentChildIndex);
2205
+ for (let j = indicesToRemove.length - 1; j >= 0; j--) {
2206
+ patches.push({
2207
+ type: RemoveChild,
2208
+ index: indicesToRemove[j]
2209
+ });
2210
+ }
2211
+ };
2212
+ const diffTrees = (oldTree, newTree, patches, path) => {
2213
+ if (path.length === 0 && oldTree.length === 1 && newTree.length === 1) {
2214
+ diffRootNode(oldTree[0], newTree[0], patches);
2215
+ return;
2216
+ }
2217
+ diffChildren(oldTree, newTree, patches);
2218
+ };
2219
+
2220
+ const removeTrailingNavigationPatches = patches => {
2221
+ while (patches.length > 0) {
2222
+ const patch = patches.at(-1);
2223
+ if (patch.type !== NavigateChild && patch.type !== NavigateParent && patch.type !== NavigateSibling) {
2224
+ break;
2225
+ }
2226
+ patches.pop();
2227
+ }
2228
+ return patches;
2229
+ };
2230
+
2231
+ const diffTree = (oldNodes, newNodes) => {
2232
+ // Step 1: Convert flat arrays to tree structures
2233
+ const oldTree = arrayToTree(oldNodes);
2234
+ const newTree = arrayToTree(newNodes);
2235
+ // Step 3: Compare the trees
2236
+ const patches = [];
2237
+ diffTrees(oldTree, newTree, patches, []);
2238
+ // Remove trailing navigation patches since they serve no purpose
2239
+ return removeTrailingNavigationPatches(patches);
2240
+ };
2241
+
1984
2242
  const List = 'list';
1985
2243
  const ListItem = 'listitem';
1986
2244
  const None = 'none';
@@ -2153,16 +2411,24 @@ const getRunningExtensionsVirtualDom = (extensions, loaded, focusedIndex = -1, s
2153
2411
  };
2154
2412
 
2155
2413
  const renderDom = (oldState, newState) => {
2156
- // TODO incremental rendering
2157
2414
  return [SetDom2, newState.uid, getRunningExtensionsVirtualDom(newState.extensions, newState.loaded, newState.focusedIndex, newState.selectedIndex, newState.focusOutline)];
2158
2415
  };
2159
2416
 
2417
+ const renderIncremental = (oldState, newState) => {
2418
+ const oldDom = getRunningExtensionsVirtualDom(oldState.extensions, oldState.loaded, oldState.focusedIndex, oldState.selectedIndex, oldState.focusOutline);
2419
+ const newDom = getRunningExtensionsVirtualDom(newState.extensions, newState.loaded, newState.focusedIndex, newState.selectedIndex, newState.focusOutline);
2420
+ const patches = diffTree(oldDom, newDom);
2421
+ return [SetPatches, newState.uid, patches];
2422
+ };
2423
+
2160
2424
  const getRenderer = diffType => {
2161
2425
  switch (diffType) {
2162
2426
  case RenderCss:
2163
2427
  return renderCss;
2164
2428
  case RenderDom:
2165
2429
  return renderDom;
2430
+ case RenderIncremental:
2431
+ return renderIncremental;
2166
2432
  default:
2167
2433
  throw new Error(`Unknown diff type ${diffType}`);
2168
2434
  }
@@ -2183,7 +2449,7 @@ const renderEventListeners = () => {
2183
2449
  preventDefault: true
2184
2450
  }, {
2185
2451
  name: HandleClick,
2186
- params: ['handleClickAt', ClientY],
2452
+ params: ['handleClickAt', 'event.target.dataset.index'],
2187
2453
  preventDefault: true
2188
2454
  }, {
2189
2455
  name: HandleBlur,
@@ -2216,6 +2482,23 @@ const getIssuesUrl = repository => {
2216
2482
  return `https://github.com/${owner}/${repositoryName}/issues`;
2217
2483
  };
2218
2484
 
2485
+ const OpenCommand = {
2486
+ External: 1,
2487
+ Url: 2
2488
+ };
2489
+ const getOpenCommand = platform => {
2490
+ if (platform === Electron) {
2491
+ return OpenCommand.External;
2492
+ }
2493
+ return OpenCommand.Url;
2494
+ };
2495
+ const applyOpenCommand = async (cmd, issuesUrl) => {
2496
+ if (cmd === OpenCommand.External) {
2497
+ await openExternal(issuesUrl);
2498
+ } else {
2499
+ await openUrl(issuesUrl);
2500
+ }
2501
+ };
2219
2502
  const reportIssue = async (state, index) => {
2220
2503
  const {
2221
2504
  extensions,
@@ -2226,11 +2509,8 @@ const reportIssue = async (state, index) => {
2226
2509
  await confirm(reportingIssuesNotSupported());
2227
2510
  return state;
2228
2511
  }
2229
- if (platform === Electron) {
2230
- await openExternal(issuesUrl);
2231
- } else {
2232
- await openUrl(issuesUrl);
2233
- }
2512
+ const cmd = getOpenCommand(platform);
2513
+ await applyOpenCommand(cmd, issuesUrl);
2234
2514
  return state;
2235
2515
  };
2236
2516
 
@@ -2334,6 +2614,13 @@ const initializeMainProcess = async () => {
2334
2614
  set$3(rpc);
2335
2615
  };
2336
2616
 
2617
+ const initializeRendererWorker = async () => {
2618
+ const rpc = await create$3({
2619
+ commandMap: commandMap
2620
+ });
2621
+ set$2(rpc);
2622
+ };
2623
+
2337
2624
  const send = async port => {
2338
2625
  await sendMessagePortToSharedProcess(port);
2339
2626
  };
@@ -2347,11 +2634,7 @@ const initializeSharedProcess = async () => {
2347
2634
 
2348
2635
  const listen = async () => {
2349
2636
  registerCommands(commandMap);
2350
- const rpc = await create$3({
2351
- commandMap: commandMap
2352
- });
2353
- set$2(rpc);
2354
- await Promise.all([initializeClipBoardWorker(), initializeExtensionManagementWorker(), initializeMainProcess(), initializeSharedProcess()]);
2637
+ await Promise.all([initializeRendererWorker(), initializeClipBoardWorker(), initializeExtensionManagementWorker(), initializeMainProcess(), initializeSharedProcess()]);
2355
2638
  };
2356
2639
 
2357
2640
  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.0",
4
4
  "description": "Running Extensions View Worker",
5
5
  "repository": {
6
6
  "type": "git",