@lvce-editor/panel-worker 2.13.5 → 2.14.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.
@@ -657,6 +657,9 @@ const restoreExistingError = (error, currentStack) => {
657
657
  };
658
658
  const restoreMethodNotFoundError = (error, currentStack) => {
659
659
  const restoredError = new JsonRpcError(error.message);
660
+ Object.assign(restoredError, {
661
+ code: error.code
662
+ });
660
663
  const parentStack = getParentStack(error);
661
664
  setStack(restoredError, `${parentStack}${NewLine}${currentStack}`);
662
665
  return restoredError;
@@ -676,9 +679,13 @@ const applyDataProperties = (restoredError, error) => {
676
679
  // @ts-ignore
677
680
  restoredError.codeFrame = error.data.codeFrame;
678
681
  }
679
- if (error.data.code) {
682
+ if (typeof error.data.code === 'string' || typeof error.data.code === 'number') {
680
683
  // @ts-ignore
681
- restoredError.code = error.data.code;
684
+ Object.defineProperty(restoredError, 'code', {
685
+ configurable: true,
686
+ value: error.data.code,
687
+ writable: true
688
+ });
682
689
  }
683
690
  if (error.data.type) {
684
691
  // @ts-ignore
@@ -699,7 +706,14 @@ const applyDirectProperties = (restoredError, error) => {
699
706
  }
700
707
  };
701
708
  const restoreMessageError = (error, _currentStack) => {
702
- const restoredError = constructError(error.message, error.type, error.name);
709
+ const restoredError = constructError(error.message, error.type || error.data?.type, error.name);
710
+ if (typeof error.code === 'string' || typeof error.code === 'number') {
711
+ Object.defineProperty(restoredError, 'code', {
712
+ configurable: true,
713
+ value: error.code,
714
+ writable: true
715
+ });
716
+ }
703
717
  if (error.data) {
704
718
  applyDataProperties(restoredError, error);
705
719
  } else {
@@ -707,6 +721,23 @@ const restoreMessageError = (error, _currentStack) => {
707
721
  }
708
722
  return restoredError;
709
723
  };
724
+ const getFallbackMessage = error => {
725
+ if (error && typeof error.message === 'string' && error.message) {
726
+ return error.message;
727
+ }
728
+ if (error && error.data) {
729
+ return getFallbackMessage(error.data);
730
+ }
731
+ const stringified = String(error);
732
+ if (stringified !== '[object Object]') {
733
+ return stringified;
734
+ }
735
+ try {
736
+ return JSON.stringify(error);
737
+ } catch {
738
+ return stringified;
739
+ }
740
+ };
710
741
  const restoreJsonRpcError = error => {
711
742
  const currentStack = getCurrentStack();
712
743
  if (error && error instanceof Error) {
@@ -715,13 +746,13 @@ const restoreJsonRpcError = error => {
715
746
  if (error && error.code && error.code === MethodNotFound) {
716
747
  return restoreMethodNotFoundError(error, currentStack);
717
748
  }
749
+ if (error && error.error) {
750
+ return restoreJsonRpcError(error.error);
751
+ }
718
752
  if (error && error.message) {
719
753
  return restoreMessageError(error);
720
754
  }
721
- if (typeof error === 'string') {
722
- return new Error(`JsonRpc Error: ${error}`);
723
- }
724
- return new Error(`JsonRpc Error: ${error}`);
755
+ return new Error(`JsonRpc Error: ${getFallbackMessage(error)}`);
725
756
  };
726
757
  const unwrapJsonRpcResult = responseMessage => {
727
758
  if ('error' in responseMessage) {
@@ -778,9 +809,9 @@ const getErrorProperty = (error, prettyError) => {
778
809
  return {
779
810
  code: Custom,
780
811
  data: {
781
- code: prettyError.code,
812
+ code: prettyError.code ?? error?.code,
782
813
  codeFrame: prettyError.codeFrame,
783
- name: prettyError.name,
814
+ name: prettyError.name ?? error?.name,
784
815
  stack: getStack(prettyError),
785
816
  type: getErrorType(prettyError)
786
817
  },
@@ -815,7 +846,12 @@ const getErrorResponseSimple = (id, error) => {
815
846
  return {
816
847
  error: {
817
848
  code: Custom,
818
- data: error,
849
+ data: error instanceof Error ? {
850
+ ...error,
851
+ code: 'code' in error ? error.code : undefined,
852
+ stack: error.stack,
853
+ type: error.name
854
+ } : error,
819
855
  // @ts-ignore
820
856
  message: error.message
821
857
  },
@@ -997,6 +1033,9 @@ const logError = () => {
997
1033
  // handled by renderer worker
998
1034
  };
999
1035
  const handleMessage = event => {
1036
+ if (event.data === 'ready') {
1037
+ return Promise.resolve();
1038
+ }
1000
1039
  const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
1001
1040
  const actualExecute = event?.target?.execute || execute;
1002
1041
  return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
@@ -1121,175 +1160,11 @@ const Tab$1 = 'tab';
1121
1160
  const TabList = 'tablist';
1122
1161
  const ToolBar = 'toolbar';
1123
1162
 
1124
- const Audio = 0;
1125
1163
  const Button$1 = 1;
1126
- const Col = 2;
1127
- const ColGroup = 3;
1128
1164
  const Div = 4;
1129
- const H1 = 5;
1130
- const Input = 6;
1131
- const Kbd = 7;
1132
- const Span = 8;
1133
- const Table = 9;
1134
- const TBody = 10;
1135
- const Td = 11;
1136
1165
  const Text = 12;
1137
- const Th = 13;
1138
- const THead = 14;
1139
- const Tr = 15;
1140
- const I = 16;
1141
- const Img = 17;
1142
- const Root = 0;
1143
- const Ins = 20;
1144
- const Del = 21;
1145
- const H2 = 22;
1146
- const H3 = 23;
1147
- const H4 = 24;
1148
- const H5 = 25;
1149
- const H6 = 26;
1150
- const Article = 27;
1151
- const Aside = 28;
1152
- const Footer = 29;
1153
- const Header = 30;
1154
- const Nav = 40;
1155
- const Section = 41;
1156
- const Search = 42;
1157
- const Dd = 43;
1158
- const Dl = 44;
1159
- const Figcaption = 45;
1160
- const Figure = 46;
1161
- const Hr = 47;
1162
- const Li = 48;
1163
- const Ol = 49;
1164
- const P = 50;
1165
- const Pre = 51;
1166
- const A = 53;
1167
- const Abbr = 54;
1168
- const Br = 55;
1169
- const Cite = 56;
1170
- const Data = 57;
1171
- const Time = 58;
1172
- const Tfoot = 59;
1173
- const Ul = 60;
1174
- const Video = 61;
1175
- const TextArea = 62;
1176
- const Select = 63;
1177
- const Option = 64;
1178
- const Code = 65;
1179
- const Label = 66;
1180
- const Dt = 67;
1181
- const Iframe = 68;
1182
- const Main = 69;
1183
- const Strong = 70;
1184
- const Em = 71;
1185
- const Style = 72;
1186
- const Html = 73;
1187
- const Head = 74;
1188
- const Title = 75;
1189
- const Meta = 76;
1190
- const Canvas = 77;
1191
- const Form = 78;
1192
- const BlockQuote = 79;
1193
- const Quote = 80;
1194
- const Circle = 81;
1195
- const Defs = 82;
1196
- const Ellipse = 83;
1197
- const G = 84;
1198
- const Line = 85;
1199
- const Path = 86;
1200
- const Polygon = 87;
1201
- const Polyline = 88;
1202
- const Rect = 89;
1203
- const Svg = 90;
1204
- const Use = 91;
1205
1166
  const Reference = 100;
1206
1167
 
1207
- const VirtualDomElements = {
1208
- __proto__: null,
1209
- A,
1210
- Abbr,
1211
- Article,
1212
- Aside,
1213
- Audio,
1214
- BlockQuote,
1215
- Br,
1216
- Button: Button$1,
1217
- Canvas,
1218
- Circle,
1219
- Cite,
1220
- Code,
1221
- Col,
1222
- ColGroup,
1223
- Data,
1224
- Dd,
1225
- Defs,
1226
- Del,
1227
- Div,
1228
- Dl,
1229
- Dt,
1230
- Ellipse,
1231
- Em,
1232
- Figcaption,
1233
- Figure,
1234
- Footer,
1235
- Form,
1236
- G,
1237
- H1,
1238
- H2,
1239
- H3,
1240
- H4,
1241
- H5,
1242
- H6,
1243
- Head,
1244
- Header,
1245
- Hr,
1246
- Html,
1247
- I,
1248
- Iframe,
1249
- Img,
1250
- Input,
1251
- Ins,
1252
- Kbd,
1253
- Label,
1254
- Li,
1255
- Line,
1256
- Main,
1257
- Meta,
1258
- Nav,
1259
- Ol,
1260
- Option,
1261
- P,
1262
- Path,
1263
- Polygon,
1264
- Polyline,
1265
- Pre,
1266
- Quote,
1267
- Rect,
1268
- Reference,
1269
- Root,
1270
- Search,
1271
- Section,
1272
- Select,
1273
- Span,
1274
- Strong,
1275
- Style,
1276
- Svg,
1277
- TBody,
1278
- THead,
1279
- Table,
1280
- Td,
1281
- Text,
1282
- TextArea,
1283
- Tfoot,
1284
- Th,
1285
- Time,
1286
- Title,
1287
- Tr,
1288
- Ul,
1289
- Use,
1290
- Video
1291
- };
1292
-
1293
1168
  const Button = 'event.button';
1294
1169
  const ClientX = 'event.clientX';
1295
1170
  const ClientY = 'event.clientY';
@@ -1332,7 +1207,8 @@ const create$1 = () => {
1332
1207
  const commandQueues = new Map();
1333
1208
  const generations = Object.create(null);
1334
1209
  const states = Object.create(null);
1335
- const commandMapRef = {};
1210
+ const commandMapRef = Object.create(null);
1211
+ const commandsById = Object.create(null);
1336
1212
  const getGeneration = uid => generations[uid] || 0;
1337
1213
  const isCurrentGeneration = (uid, generation) => {
1338
1214
  return states[uid] !== undefined && getGeneration(uid) === generation;
@@ -1394,6 +1270,18 @@ const create$1 = () => {
1394
1270
  delete states[key];
1395
1271
  }
1396
1272
  },
1273
+ createDirectEventCommandMap(requestRender) {
1274
+ return {
1275
+ async 'Viewlet.executeViewletCommand'(uid, command, ...args) {
1276
+ const fn = commandsById[command];
1277
+ if (!fn) {
1278
+ throw new Error(`Viewlet command not found: ${command}`);
1279
+ }
1280
+ await fn(uid, ...args);
1281
+ await requestRender(uid);
1282
+ }
1283
+ };
1284
+ },
1397
1285
  diff(uid, modules, numbers) {
1398
1286
  const {
1399
1287
  oldState,
@@ -1425,6 +1313,9 @@ const create$1 = () => {
1425
1313
  },
1426
1314
  registerCommands(commandMap) {
1427
1315
  Object.assign(commandMapRef, commandMap);
1316
+ for (const [key, fn] of Object.entries(commandMap)) {
1317
+ commandsById[toCommandId(key)] = fn;
1318
+ }
1428
1319
  },
1429
1320
  set(uid, oldState, newState, scheduledState) {
1430
1321
  const current = states[uid];
@@ -1852,9 +1743,10 @@ const handleFilterInput = async (state, value) => {
1852
1743
 
1853
1744
  const remoteSshWorkspacePrefix = 'remote-ssh://';
1854
1745
  const devContainerWorkspacePrefix = 'devcontainers:///';
1746
+ const codespacesWorkspacePrefix = 'codespaces://';
1855
1747
  const getPanelViews = (workspaceUri = '') => {
1856
1748
  const views = [Problems, Output, DebugConsole, Terminals];
1857
- if (workspaceUri.startsWith(remoteSshWorkspacePrefix) || workspaceUri.startsWith(devContainerWorkspacePrefix)) {
1749
+ if (workspaceUri.startsWith(remoteSshWorkspacePrefix) || workspaceUri.startsWith(devContainerWorkspacePrefix) || workspaceUri.startsWith(codespacesWorkspacePrefix)) {
1858
1750
  views.push(Ports);
1859
1751
  }
1860
1752
  return views;
@@ -1952,11 +1844,12 @@ const openViewlet = async (state, id, focus = false, uri = '') => {
1952
1844
 
1953
1845
  const loadContent = (state, savedState, workspaceUri = '') => {
1954
1846
  const {
1955
- currentViewletId: activeViewletId
1847
+ currentViewletId: activeViewletId,
1848
+ hiddenViews: activeHiddenViews
1956
1849
  } = state;
1957
- const savedViewletId = getSavedViewletId(savedState);
1850
+ const savedViewletId = savedState?.currentViewletId || activeViewletId || getSavedViewletId(savedState);
1958
1851
  const availableViews = getPanelViews(workspaceUri);
1959
- const hiddenViews = (savedState?.hiddenViews || []).filter(view => availableViews.includes(view));
1852
+ const hiddenViews = (savedState?.hiddenViews || activeHiddenViews || []).filter(view => availableViews.includes(view));
1960
1853
  let views = availableViews.filter(view => !hiddenViews.includes(view));
1961
1854
  if (views.length === 0 && availableViews.length > 0) {
1962
1855
  views = [availableViews[0]];
@@ -2035,8 +1928,6 @@ const text = data => {
2035
1928
  };
2036
1929
  };
2037
1930
 
2038
- new Set(Object.values(VirtualDomElements));
2039
-
2040
1931
  const SetText = 1;
2041
1932
  const Replace = 2;
2042
1933
  const SetAttribute = 3;
@@ -2047,6 +1938,7 @@ const NavigateParent = 8;
2047
1938
  const RemoveChild = 9;
2048
1939
  const NavigateSibling = 10;
2049
1940
  const SetReferenceNodeUid = 11;
1941
+ const MultiNavigation = 18;
2050
1942
 
2051
1943
  const isKey = key => {
2052
1944
  return key !== 'type' && key !== 'childCount';
@@ -2107,6 +1999,55 @@ const getChildrenWithCount = (nodes, startIndex, childCount) => {
2107
1999
  };
2108
2000
  };
2109
2001
 
2002
+ const isNavigationPatch = patch => {
2003
+ switch (patch.type) {
2004
+ case NavigateChild:
2005
+ case NavigateParent:
2006
+ case NavigateSibling:
2007
+ return true;
2008
+ default:
2009
+ return false;
2010
+ }
2011
+ };
2012
+ const getNavigationIndex = patch => {
2013
+ switch (patch.type) {
2014
+ case NavigateChild:
2015
+ case NavigateSibling:
2016
+ return patch.index;
2017
+ default:
2018
+ return 0;
2019
+ }
2020
+ };
2021
+ const appendNavigationPatch = (patches, type, index) => {
2022
+ const previousPatch = patches.at(-1);
2023
+ if (!previousPatch) {
2024
+ patches.push(type === NavigateParent ? {
2025
+ type
2026
+ } : {
2027
+ index,
2028
+ type
2029
+ });
2030
+ return;
2031
+ }
2032
+ if (previousPatch.type === MultiNavigation) {
2033
+ previousPatch.navigations.push(type, index);
2034
+ return;
2035
+ }
2036
+ if (isNavigationPatch(previousPatch)) {
2037
+ patches[patches.length - 1] = {
2038
+ navigations: [previousPatch.type, getNavigationIndex(previousPatch), type, index],
2039
+ type: MultiNavigation
2040
+ };
2041
+ return;
2042
+ }
2043
+ patches.push(type === NavigateParent ? {
2044
+ type
2045
+ } : {
2046
+ index,
2047
+ type
2048
+ });
2049
+ };
2050
+
2110
2051
  const compareNodes = (oldNode, newNode) => {
2111
2052
  // Check if node type changed - return null to signal incompatible nodes
2112
2053
  // (caller should handle this with a Replace operation)
@@ -2157,34 +2098,31 @@ const compareNodes = (oldNode, newNode) => {
2157
2098
  };
2158
2099
 
2159
2100
  const treeToArray = node => {
2160
- const result = [node.node];
2161
- for (const child of node.children) {
2162
- result.push(...treeToArray(child));
2101
+ const result = [];
2102
+ const stack = [node];
2103
+ while (stack.length > 0) {
2104
+ const current = stack.pop();
2105
+ result.push(current.node);
2106
+ for (let i = current.children.length - 1; i >= 0; i--) {
2107
+ stack.push(current.children[i]);
2108
+ }
2163
2109
  }
2164
2110
  return result;
2165
2111
  };
2166
2112
 
2167
2113
  const navigateToChild = (patches, currentChildIndex, index) => {
2168
2114
  if (currentChildIndex === -1) {
2169
- patches.push({
2170
- type: NavigateChild,
2171
- index
2172
- });
2115
+ appendNavigationPatch(patches, NavigateChild, index);
2173
2116
  return index;
2174
2117
  }
2175
2118
  if (currentChildIndex !== index) {
2176
- patches.push({
2177
- type: NavigateSibling,
2178
- index
2179
- });
2119
+ appendNavigationPatch(patches, NavigateSibling, index);
2180
2120
  }
2181
2121
  return index;
2182
2122
  };
2183
2123
  const navigateToParent = (patches, currentChildIndex) => {
2184
2124
  if (currentChildIndex >= 0) {
2185
- patches.push({
2186
- type: NavigateParent
2187
- });
2125
+ appendNavigationPatch(patches, NavigateParent, 0);
2188
2126
  }
2189
2127
  return -1;
2190
2128
  };
@@ -2200,6 +2138,29 @@ const replaceTree = (newNode, patches) => {
2200
2138
  nodes: treeToArray(newNode)
2201
2139
  });
2202
2140
  };
2141
+ const appendPatch = (patches, patch) => {
2142
+ switch (patch.type) {
2143
+ case MultiNavigation:
2144
+ for (let i = 0; i < patch.navigations.length; i += 2) {
2145
+ appendNavigationPatch(patches, patch.navigations[i], patch.navigations[i + 1]);
2146
+ }
2147
+ return;
2148
+ case NavigateChild:
2149
+ case NavigateSibling:
2150
+ appendNavigationPatch(patches, patch.type, patch.index);
2151
+ return;
2152
+ case NavigateParent:
2153
+ appendNavigationPatch(patches, patch.type, 0);
2154
+ return;
2155
+ default:
2156
+ patches.push(patch);
2157
+ }
2158
+ };
2159
+ const appendPatches = (patches, newPatches) => {
2160
+ for (const patch of newPatches) {
2161
+ appendPatch(patches, patch);
2162
+ }
2163
+ };
2203
2164
  const diffExistingChild = (oldNode, newNode, patches, currentChildIndex, index) => {
2204
2165
  const nodePatches = compareNodes(oldNode.node, newNode.node);
2205
2166
  if (nodePatches === null) {
@@ -2208,16 +2169,16 @@ const diffExistingChild = (oldNode, newNode, patches, currentChildIndex, index)
2208
2169
  return nextChildIndex;
2209
2170
  }
2210
2171
  const hasChildrenToCompare = oldNode.children.length > 0 || newNode.children.length > 0;
2211
- if (nodePatches.length === 0 && !hasChildrenToCompare) {
2172
+ const childPatches = [];
2173
+ if (hasChildrenToCompare) {
2174
+ diffChildren(oldNode.children, newNode.children, childPatches);
2175
+ }
2176
+ if (nodePatches.length === 0 && childPatches.length === 0) {
2212
2177
  return currentChildIndex;
2213
2178
  }
2214
2179
  const nextChildIndex = navigateToChild(patches, currentChildIndex, index);
2215
- if (nodePatches.length > 0) {
2216
- patches.push(...nodePatches);
2217
- }
2218
- if (hasChildrenToCompare) {
2219
- diffChildren(oldNode.children, newNode.children, patches);
2220
- }
2180
+ patches.push(...nodePatches);
2181
+ appendPatches(patches, childPatches);
2221
2182
  return nextChildIndex;
2222
2183
  };
2223
2184
  const diffRootNode = (oldNode, newNode, patches) => {
@@ -2273,7 +2234,7 @@ const diffTrees = (oldTree, newTree, patches, path) => {
2273
2234
  const removeTrailingNavigationPatches = patches => {
2274
2235
  while (patches.length > 0) {
2275
2236
  const patch = patches.at(-1);
2276
- if (patch.type !== NavigateChild && patch.type !== NavigateParent && patch.type !== NavigateSibling) {
2237
+ if (patch.type !== NavigateChild && patch.type !== NavigateParent && patch.type !== NavigateSibling && patch.type !== MultiNavigation) {
2277
2238
  break;
2278
2239
  }
2279
2240
  patches.pop();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/panel-worker",
3
- "version": "2.13.5",
3
+ "version": "2.14.1",
4
4
  "description": "Panel Worker",
5
5
  "repository": {
6
6
  "type": "git",