@lvce-editor/activity-bar-worker 7.1.0 → 7.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.
@@ -13,13 +13,13 @@ const create$a = () => {
13
13
  },
14
14
  diff(uid, modules, numbers) {
15
15
  const {
16
- newState,
17
- oldState
16
+ oldState,
17
+ scheduledState
18
18
  } = states[uid];
19
19
  const diffResult = [];
20
20
  for (let i = 0; i < modules.length; i++) {
21
21
  const fn = modules[i];
22
- if (!fn(oldState, newState)) {
22
+ if (!fn(oldState, scheduledState)) {
23
23
  diffResult.push(numbers[i]);
24
24
  }
25
25
  }
@@ -37,17 +37,16 @@ const create$a = () => {
37
37
  return ids;
38
38
  },
39
39
  getKeys() {
40
- return Object.keys(states).map(key => {
41
- return Number.parseFloat(key);
42
- });
40
+ return Object.keys(states).map(Number);
43
41
  },
44
42
  registerCommands(commandMap) {
45
43
  Object.assign(commandMapRef, commandMap);
46
44
  },
47
- set(uid, oldState, newState) {
45
+ set(uid, oldState, newState, scheduledState) {
48
46
  states[uid] = {
49
47
  newState,
50
- oldState
48
+ oldState,
49
+ scheduledState: scheduledState ?? newState
51
50
  };
52
51
  },
53
52
  wrapCommand(fn) {
@@ -67,7 +66,8 @@ const create$a = () => {
67
66
  };
68
67
  states[uid] = {
69
68
  newState: latestNew,
70
- oldState: latestOld.oldState
69
+ oldState: latestOld.oldState,
70
+ scheduledState: latestNew
71
71
  };
72
72
  };
73
73
  return wrapped;
@@ -104,7 +104,8 @@ const create$a = () => {
104
104
  };
105
105
  states[uid] = {
106
106
  newState: latestNew,
107
- oldState: latestOld.oldState
107
+ oldState: latestOld.oldState,
108
+ scheduledState: latestNew
108
109
  };
109
110
  return {
110
111
  error
@@ -159,8 +160,17 @@ const create$9 = (id, uri, x, y, width, height, args, parentUid, platform = 0) =
159
160
  return state;
160
161
  };
161
162
 
163
+ const getCustomIconSignature = items => {
164
+ return items.map(item => {
165
+ if (!item.customIconClass || !item.customIconUrl) {
166
+ return '';
167
+ }
168
+ return `${item.customIconClass}\n${item.customIconUrl}`;
169
+ }).filter(Boolean).join('\n');
170
+ };
171
+
162
172
  const isEqual$2 = (oldState, newState) => {
163
- return oldState.itemHeight === newState.itemHeight;
173
+ return oldState.itemHeight === newState.itemHeight && getCustomIconSignature(oldState.filteredItems) === getCustomIconSignature(newState.filteredItems);
164
174
  };
165
175
 
166
176
  const isEqual$1 = (oldState, newState) => {
@@ -481,7 +491,7 @@ const getMenuEntriesActivityBar = state => {
481
491
  } = state;
482
492
  const topItems = activityBarItems.filter(item => !(item.flags & Button));
483
493
  const bottomItems = activityBarItems.filter(item => item.flags & Button);
484
- const entries = [...topItems.map(toContextMenuItem$1)];
494
+ const entries = topItems.map(toContextMenuItem$1);
485
495
  if (bottomItems.length > 0) {
486
496
  entries.push(menuEntrySeparator, ...bottomItems.map(toContextMenuItem$1));
487
497
  }
@@ -628,7 +638,7 @@ class AssertionError extends Error {
628
638
  const Object$1 = 1;
629
639
  const Number$1 = 2;
630
640
  const Array$1 = 3;
631
- const String = 4;
641
+ const String$1 = 4;
632
642
  const Boolean$1 = 5;
633
643
  const Function = 6;
634
644
  const Null = 7;
@@ -640,7 +650,7 @@ const getType = value => {
640
650
  case 'function':
641
651
  return Function;
642
652
  case 'string':
643
- return String;
653
+ return String$1;
644
654
  case 'object':
645
655
  if (value === null) {
646
656
  return Null;
@@ -1162,8 +1172,10 @@ const getCurrentStack = () => {
1162
1172
  const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
1163
1173
  return currentStack;
1164
1174
  };
1165
- const getNewLineIndex = (string, startIndex = undefined) => {
1166
- return string.indexOf(NewLine, startIndex);
1175
+ const getNewLineIndex = (string, startIndex) => {
1176
+ {
1177
+ return string.indexOf(NewLine);
1178
+ }
1167
1179
  };
1168
1180
  const getParentStack = error => {
1169
1181
  let parentStack = error.stack || error.data || error.message || '';
@@ -1174,55 +1186,77 @@ const getParentStack = error => {
1174
1186
  };
1175
1187
  const MethodNotFound = -32601;
1176
1188
  const Custom = -32001;
1189
+ const restoreExistingError = (error, currentStack) => {
1190
+ if (typeof error.stack === 'string') {
1191
+ error.stack = error.stack + NewLine + currentStack;
1192
+ }
1193
+ return error;
1194
+ };
1195
+ const restoreMethodNotFoundError = (error, currentStack) => {
1196
+ const restoredError = new JsonRpcError(error.message);
1197
+ const parentStack = getParentStack(error);
1198
+ restoredError.stack = parentStack + NewLine + currentStack;
1199
+ return restoredError;
1200
+ };
1201
+ const restoreStackFromData = (restoredError, error, currentStack) => {
1202
+ if (error.data.stack && error.data.type && error.message) {
1203
+ restoredError.stack = error.data.type + ': ' + error.message + NewLine + error.data.stack + NewLine + currentStack;
1204
+ return;
1205
+ }
1206
+ if (error.data.stack) {
1207
+ restoredError.stack = error.data.stack;
1208
+ }
1209
+ };
1210
+ const applyDataProperties = (restoredError, error) => {
1211
+ if (!error.data) {
1212
+ return;
1213
+ }
1214
+ restoreStackFromData(restoredError, error, getCurrentStack());
1215
+ if (error.data.codeFrame) {
1216
+ // @ts-ignore
1217
+ restoredError.codeFrame = error.data.codeFrame;
1218
+ }
1219
+ if (error.data.code) {
1220
+ // @ts-ignore
1221
+ restoredError.code = error.data.code;
1222
+ }
1223
+ if (error.data.type) {
1224
+ // @ts-ignore
1225
+ restoredError.name = error.data.type;
1226
+ }
1227
+ };
1228
+ const applyDirectProperties = (restoredError, error) => {
1229
+ if (error.stack) {
1230
+ const lowerStack = restoredError.stack || '';
1231
+ const indexNewLine = getNewLineIndex(lowerStack);
1232
+ const parentStack = getParentStack(error);
1233
+ // @ts-ignore
1234
+ restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
1235
+ }
1236
+ if (error.codeFrame) {
1237
+ // @ts-ignore
1238
+ restoredError.codeFrame = error.codeFrame;
1239
+ }
1240
+ };
1241
+ const restoreMessageError = (error, _currentStack) => {
1242
+ const restoredError = constructError(error.message, error.type, error.name);
1243
+ if (error.data) {
1244
+ applyDataProperties(restoredError, error);
1245
+ } else {
1246
+ applyDirectProperties(restoredError, error);
1247
+ }
1248
+ return restoredError;
1249
+ };
1177
1250
  const restoreJsonRpcError = error => {
1178
1251
  const currentStack = getCurrentStack();
1179
1252
  if (error && error instanceof Error) {
1180
- if (typeof error.stack === 'string') {
1181
- error.stack = error.stack + NewLine + currentStack;
1182
- }
1183
- return error;
1253
+ return restoreExistingError(error, currentStack);
1184
1254
  }
1185
1255
  if (error && error.code && error.code === MethodNotFound) {
1186
- const restoredError = new JsonRpcError(error.message);
1187
- const parentStack = getParentStack(error);
1188
- restoredError.stack = parentStack + NewLine + currentStack;
1189
- return restoredError;
1256
+ return restoreMethodNotFoundError(error, currentStack);
1190
1257
  }
1191
1258
  if (error && error.message) {
1192
- const restoredError = constructError(error.message, error.type, error.name);
1193
- if (error.data) {
1194
- if (error.data.stack && error.data.type && error.message) {
1195
- restoredError.stack = error.data.type + ': ' + error.message + NewLine + error.data.stack + NewLine + currentStack;
1196
- } else if (error.data.stack) {
1197
- restoredError.stack = error.data.stack;
1198
- }
1199
- if (error.data.codeFrame) {
1200
- // @ts-ignore
1201
- restoredError.codeFrame = error.data.codeFrame;
1202
- }
1203
- if (error.data.code) {
1204
- // @ts-ignore
1205
- restoredError.code = error.data.code;
1206
- }
1207
- if (error.data.type) {
1208
- // @ts-ignore
1209
- restoredError.name = error.data.type;
1210
- }
1211
- } else {
1212
- if (error.stack) {
1213
- const lowerStack = restoredError.stack || '';
1214
- // @ts-ignore
1215
- const indexNewLine = getNewLineIndex(lowerStack);
1216
- const parentStack = getParentStack(error);
1217
- // @ts-ignore
1218
- restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
1219
- }
1220
- if (error.codeFrame) {
1221
- // @ts-ignore
1222
- restoredError.codeFrame = error.codeFrame;
1223
- }
1224
- }
1225
- return restoredError;
1259
+ return restoreMessageError(error);
1226
1260
  }
1227
1261
  if (typeof error === 'string') {
1228
1262
  return new Error(`JsonRpc Error: ${error}`);
@@ -1754,7 +1788,7 @@ const updateItemsWithBadgeCount = async items => {
1754
1788
  const badgeCounts = await invoke('Layout.getBadgeCounts');
1755
1789
  const newItems = items.map(item => {
1756
1790
  const badgeCount = badgeCounts[item.id] || 0;
1757
- const badgeText = badgeCount ? `${badgeCount}` : '';
1791
+ const badgeText = badgeCount ? String(badgeCount) : '';
1758
1792
  return {
1759
1793
  ...item,
1760
1794
  badgeText
@@ -2022,6 +2056,23 @@ const handleExtensionManagementMessagePort = async port => {
2022
2056
  set$1(rpc);
2023
2057
  };
2024
2058
 
2059
+ const hashString = value => {
2060
+ let hash = 2_166_136_261;
2061
+ for (const character of value) {
2062
+ hash ^= character.codePointAt(0) || 0;
2063
+ hash = Math.imul(hash, 16_777_619);
2064
+ }
2065
+ return (hash >>> 0).toString(36);
2066
+ };
2067
+ const getCustomIconClass = (id, iconUrl) => {
2068
+ const hashInput = id + '\n' + iconUrl;
2069
+ return `MaskIconCustomView${hashString(hashInput)}`;
2070
+ };
2071
+
2072
+ const isCustomIconUrl = icon => {
2073
+ return icon.startsWith('http://') || icon.startsWith('https://') || icon.startsWith('file://') || icon.startsWith('/');
2074
+ };
2075
+
2025
2076
  const Explorer = 'Explorer';
2026
2077
  const Extensions = 'Extensions';
2027
2078
  const RunAndDebug = 'Run And Debug';
@@ -2029,13 +2080,24 @@ const Search = 'Search';
2029
2080
  const SourceControl = 'Source Control';
2030
2081
 
2031
2082
  const toActivityBarItem = view => {
2032
- return {
2083
+ const icon = view.icon || Extensions$1;
2084
+ const customIconUrl = isCustomIconUrl(icon) ? icon : undefined;
2085
+ const customIconClass = customIconUrl ? getCustomIconClass(view.id, customIconUrl) : undefined;
2086
+ const item = {
2033
2087
  flags: Tab | Enabled,
2034
- icon: view.icon || Extensions$1,
2088
+ icon,
2035
2089
  id: view.id,
2036
2090
  keyShortcuts: '',
2037
2091
  title: view.title || view.id
2038
2092
  };
2093
+ if (customIconClass && customIconUrl) {
2094
+ return {
2095
+ ...item,
2096
+ customIconClass,
2097
+ customIconUrl
2098
+ };
2099
+ }
2100
+ return item;
2039
2101
  };
2040
2102
  const getActivityBarItems = (state, contributedViews = []) => {
2041
2103
  const {
@@ -2274,6 +2336,16 @@ const handleUpdateStateChange = async (state, config) => {
2274
2336
  };
2275
2337
  };
2276
2338
 
2339
+ const getUserState = userInfo => {
2340
+ if (!userInfo || typeof userInfo !== 'object') {
2341
+ return undefined;
2342
+ }
2343
+ if (!('userState' in userInfo)) {
2344
+ return undefined;
2345
+ }
2346
+ return userInfo.userState;
2347
+ };
2348
+
2277
2349
  const getActiveView = async () => {
2278
2350
  try {
2279
2351
  const activeView = await invoke('Layout.getActiveSideBarView');
@@ -2291,14 +2363,16 @@ const getUserInfo = async () => {
2291
2363
  }
2292
2364
  };
2293
2365
 
2294
- const getUserState = userInfo => {
2295
- if (!userInfo || typeof userInfo !== 'object') {
2296
- return undefined;
2297
- }
2298
- if (!('userState' in userInfo)) {
2299
- return undefined;
2300
- }
2301
- return userInfo.userState;
2366
+ const loadPreferences = async (accountEnabled, platform) => {
2367
+ const [accountEnabledNew, activeView, contributedViews, sidebarLocation, sideBarVisible, userInfo] = await Promise.all([getAccountEnabled(accountEnabled), getActiveView(), getContributedViews(platform), getSideBarPosition(), getSideBarVisible(), getUserInfo()]);
2368
+ return {
2369
+ accountEnabled: accountEnabledNew,
2370
+ activeView,
2371
+ contributedViews,
2372
+ sidebarLocation,
2373
+ sideBarVisible,
2374
+ userInfo
2375
+ };
2302
2376
  };
2303
2377
 
2304
2378
  const toUserLoginState = userState => {
@@ -2321,7 +2395,14 @@ const loadContent = async state => {
2321
2395
  itemHeight,
2322
2396
  platform
2323
2397
  } = state;
2324
- const [accountEnabledNew, activeView, contributedViews, sideBarVisible, sidebarLocation, userInfo] = await Promise.all([getAccountEnabled(accountEnabled), getActiveView(), getContributedViews(platform), getSideBarVisible(), getSideBarPosition(), getUserInfo()]);
2398
+ const {
2399
+ accountEnabled: accountEnabledNew,
2400
+ activeView,
2401
+ contributedViews,
2402
+ sidebarLocation,
2403
+ sideBarVisible,
2404
+ userInfo
2405
+ } = await loadPreferences(accountEnabled, platform);
2325
2406
  const newState = {
2326
2407
  ...state,
2327
2408
  accountEnabled: accountEnabledNew,
@@ -2345,19 +2426,44 @@ const loadContent = async state => {
2345
2426
  };
2346
2427
  };
2347
2428
 
2348
- const getCss = itemHeight => {
2429
+ const escapeCssUrl = url => {
2430
+ return url.replaceAll('\\', '\\\\').replaceAll('"', '\\"').replaceAll('\n', '\\a ').replaceAll('\r', '\\d ').replaceAll('\f', '\\c ');
2431
+ };
2432
+
2433
+ const getCustomIconCss = items => {
2434
+ const seen = new Set();
2435
+ let css = '';
2436
+ for (const item of items) {
2437
+ const {
2438
+ customIconClass,
2439
+ customIconUrl
2440
+ } = item;
2441
+ if (!customIconClass || !customIconUrl || seen.has(customIconClass)) {
2442
+ continue;
2443
+ }
2444
+ seen.add(customIconClass);
2445
+ css += `.${customIconClass} {
2446
+ mask-image: url("${escapeCssUrl(customIconUrl)}");
2447
+ }
2448
+ `;
2449
+ }
2450
+ return css;
2451
+ };
2452
+
2453
+ const getCss = (itemHeight, items = []) => {
2349
2454
  return `:root {
2350
2455
  --ActivityBarItemHeight: var(--${itemHeight}px);
2351
2456
  }
2352
- `;
2457
+ ${getCustomIconCss(items)}`;
2353
2458
  };
2354
2459
 
2355
2460
  const renderCss = (oldState, newState) => {
2356
2461
  const {
2462
+ filteredItems,
2357
2463
  itemHeight,
2358
2464
  uid
2359
2465
  } = newState;
2360
- const css = getCss(itemHeight);
2466
+ const css = getCss(itemHeight, filteredItems);
2361
2467
  return [SetCss, uid, css];
2362
2468
  };
2363
2469
 
@@ -2451,12 +2557,12 @@ const getChildrenWithCount = (nodes, startIndex, childCount) => {
2451
2557
  };
2452
2558
 
2453
2559
  const compareNodes = (oldNode, newNode) => {
2454
- const patches = [];
2455
2560
  // Check if node type changed - return null to signal incompatible nodes
2456
2561
  // (caller should handle this with a Replace operation)
2457
2562
  if (oldNode.type !== newNode.type) {
2458
2563
  return null;
2459
2564
  }
2565
+ const patches = [];
2460
2566
  // Handle reference nodes - special handling for uid changes
2461
2567
  if (oldNode.type === Reference) {
2462
2568
  if (oldNode.uid !== newNode.uid) {
@@ -2492,7 +2598,7 @@ const compareNodes = (oldNode, newNode) => {
2492
2598
  }
2493
2599
  // Check for removed attributes
2494
2600
  for (const key of oldKeys) {
2495
- if (!(key in newNode)) {
2601
+ if (!Object.hasOwn(newNode, key)) {
2496
2602
  patches.push({
2497
2603
  type: RemoveAttribute,
2498
2604
  key
@@ -2704,10 +2810,16 @@ const getClassName = (isFocused, marginTop, isSelected) => {
2704
2810
  return mergeClassNames(...classNames);
2705
2811
  };
2706
2812
 
2813
+ const getIconClass = (item, builtinPrefix) => {
2814
+ if (item.customIconClass) {
2815
+ return item.customIconClass;
2816
+ }
2817
+ return `${builtinPrefix}${item.icon}`;
2818
+ };
2819
+
2707
2820
  const getActivityBarItemInProgressDom = item => {
2708
2821
  const {
2709
2822
  flags,
2710
- icon,
2711
2823
  title
2712
2824
  } = item;
2713
2825
  const isTab = flags & Tab;
@@ -2730,7 +2842,7 @@ const getActivityBarItemInProgressDom = item => {
2730
2842
  type: Div
2731
2843
  }, {
2732
2844
  childCount: 0,
2733
- className: mergeClassNames(Icon, `MaskIcon${icon}`),
2845
+ className: mergeClassNames(Icon, getIconClass(item, 'MaskIcon')),
2734
2846
  role: None$1,
2735
2847
  type: Div
2736
2848
  }, ...getBadgeVirtualDom()];
@@ -2740,7 +2852,6 @@ const getActivityBarItemWithBadgeDom = item => {
2740
2852
  const {
2741
2853
  badgeText,
2742
2854
  flags,
2743
- icon,
2744
2855
  title
2745
2856
  } = item;
2746
2857
  if (!badgeText) {
@@ -2767,7 +2878,7 @@ const getActivityBarItemWithBadgeDom = item => {
2767
2878
  type: Div
2768
2879
  }, {
2769
2880
  childCount: 0,
2770
- className: mergeClassNames(Icon, `MaskIcon${icon}`),
2881
+ className: mergeClassNames(Icon, getIconClass(item, 'MaskIcon')),
2771
2882
  role: None$1,
2772
2883
  type: Div
2773
2884
  }, {
@@ -2777,10 +2888,10 @@ const getActivityBarItemWithBadgeDom = item => {
2777
2888
  }, text(badgeText)];
2778
2889
  };
2779
2890
 
2780
- const getIconVirtualDom = (icon, type = Div) => {
2891
+ const getIconVirtualDom = (icon, type = Div, customIconClass = '') => {
2781
2892
  return {
2782
2893
  childCount: 0,
2783
- className: `MaskIcon MaskIcon${icon}`,
2894
+ className: customIconClass ? `MaskIcon ${customIconClass}` : `MaskIcon MaskIcon${icon}`,
2784
2895
  role: None$1,
2785
2896
  type
2786
2897
  };
@@ -2812,7 +2923,7 @@ const getActivityBarItemVirtualDom = item => {
2812
2923
  role,
2813
2924
  title,
2814
2925
  type: Div
2815
- }, getIconVirtualDom(icon)];
2926
+ }, getIconVirtualDom(icon, Div, item.customIconClass)];
2816
2927
  }
2817
2928
 
2818
2929
  // TODO support progress on selected activity bar item
@@ -2827,7 +2938,7 @@ const getActivityBarItemVirtualDom = item => {
2827
2938
  ariaLabel: '',
2828
2939
  ariaSelected,
2829
2940
  childCount: 0,
2830
- className: mergeClassNames(className, `Icon${icon}`),
2941
+ className: mergeClassNames(className, getIconClass(item, 'Icon')),
2831
2942
  role,
2832
2943
  title,
2833
2944
  type: Div
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/activity-bar-worker",
3
- "version": "7.1.0",
3
+ "version": "7.3.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",