@lvce-editor/extension-management-worker 4.80.0 → 4.81.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.
@@ -2504,12 +2504,6 @@ const get$2 = (extensionId, applicationId) => {
2504
2504
  }
2505
2505
  return rpcs[extensionId];
2506
2506
  };
2507
- const getAll$1 = applicationId => {
2508
- if (applicationId !== undefined) {
2509
- return [...(applicationRpcs.get(applicationId)?.values() || [])];
2510
- }
2511
- return Object.values(rpcs);
2512
- };
2513
2507
  const getIds = applicationId => {
2514
2508
  if (applicationId !== undefined) {
2515
2509
  return [...(applicationRpcs.get(applicationId)?.keys() || [])];
@@ -5456,9 +5450,47 @@ const isRelativeIconPath = icon => {
5456
5450
  return icon.startsWith('./') || icon.startsWith('../') || icon.includes('/') || /\.(?:bmp|gif|ico|jpe?g|png|svg|webp)$/i.test(icon);
5457
5451
  };
5458
5452
 
5453
+ const getBuiltinIconPath = (extension, icon, assetDir, platform) => {
5454
+ const extensionPathUrl = extension.path || extension.uri || '';
5455
+ if (extension.builtin !== true || extension.isWeb === true || platform === Web || !extensionPathUrl.startsWith('file://')) {
5456
+ return undefined;
5457
+ }
5458
+ const isLocalFileUrl = icon.startsWith('file://');
5459
+ const isLocalAbsolutePath = icon.startsWith('/') || /^[A-Za-z]:[\\/]/.test(icon);
5460
+ const hasUrlScheme = /^[A-Za-z][A-Za-z\d+.-]*:/.test(icon);
5461
+ if (!isLocalFileUrl && (hasUrlScheme || !isLocalAbsolutePath && !isRelativeIconPath(icon))) {
5462
+ return undefined;
5463
+ }
5464
+ const extensionPath = new URL(extensionPathUrl).pathname.replaceAll('\\', '/').replace(/\/$/, '');
5465
+ let iconPath = icon;
5466
+ if (isLocalFileUrl) {
5467
+ iconPath = new URL(icon).pathname;
5468
+ } else if (!isLocalAbsolutePath) {
5469
+ iconPath = `${extensionPath}/${icon}`;
5470
+ }
5471
+ const normalizedIconPath = iconPath.replaceAll('\\', '/');
5472
+ const normalizedExtensionPath = extensionPath.replace(/^\/([A-Za-z]:\/)/, '$1');
5473
+ const normalizedAbsoluteIconPath = normalizedIconPath.replace(/^\/([A-Za-z]:\/)/, '$1');
5474
+ const isWindowsPath = /^[A-Za-z]:\//.test(normalizedExtensionPath);
5475
+ const pathToCompare = isWindowsPath ? normalizedExtensionPath.toLowerCase() : normalizedExtensionPath;
5476
+ const iconPathToCompare = isWindowsPath ? normalizedAbsoluteIconPath.toLowerCase() : normalizedAbsoluteIconPath;
5477
+ if (!iconPathToCompare.startsWith(`${pathToCompare}/`)) {
5478
+ return undefined;
5479
+ }
5480
+ const relativePath = normalizedAbsoluteIconPath.slice(normalizedExtensionPath.length + 1);
5481
+ const folderName = normalizedExtensionPath.split('/').findLast(Boolean);
5482
+ if (!relativePath || !folderName || relativePath.split('/').includes('..')) {
5483
+ return undefined;
5484
+ }
5485
+ return `${assetDir}/extensions/${folderName}/${relativePath}`;
5486
+ };
5459
5487
  const getIcon = (extension, manifestView, assetDir, platform) => {
5460
5488
  const manifestIcon = manifestView?.icon;
5461
5489
  if (typeof manifestIcon === 'string' && manifestIcon.length > 0) {
5490
+ const builtinIconPath = getBuiltinIconPath(extension, manifestIcon, assetDir, platform);
5491
+ if (builtinIconPath) {
5492
+ return builtinIconPath;
5493
+ }
5462
5494
  if (isAbsoluteIcon(manifestIcon) || !isRelativeIconPath(manifestIcon)) {
5463
5495
  return manifestIcon;
5464
5496
  }
@@ -5585,10 +5617,32 @@ const getItems = async rpc => {
5585
5617
  return rpc.invoke('ExtensionApi.getStatusBarItems');
5586
5618
  };
5587
5619
  const getStatusBarItems = async applicationId => {
5588
- const rpcs = getAll$1(applicationId);
5589
- const results = await Promise.all(rpcs.map(getItems));
5620
+ const extensionIds = getIds(applicationId);
5621
+ const results = await Promise.all(extensionIds.map(async extensionId => {
5622
+ const rpc = get$2(extensionId, applicationId);
5623
+ if (!rpc) {
5624
+ return [];
5625
+ }
5626
+ const items = await getItems(rpc);
5627
+ return items.map(item => ({
5628
+ ...item,
5629
+ extensionId
5630
+ }));
5631
+ }));
5590
5632
  return results.flat();
5591
5633
  };
5634
+ const getStatusBarItemContextMenuItems = async (extensionId, providerId, applicationId) => {
5635
+ const rpc = get$2(extensionId, applicationId);
5636
+ if (!rpc) {
5637
+ return [];
5638
+ }
5639
+ try {
5640
+ const items = await rpc.invoke('ExtensionApi.getStatusBarItemContextMenuItems', providerId);
5641
+ return Array.isArray(items) ? items : [];
5642
+ } catch {
5643
+ return [];
5644
+ }
5645
+ };
5592
5646
 
5593
5647
  const getCss = (extension, manifestView, assetDir, platform) => {
5594
5648
  const css = manifestView?.css;
@@ -6174,6 +6228,8 @@ const invokeForApplication = async (applicationId, method, ...args) => {
6174
6228
  return getRpcInfo$1(application, args[0]);
6175
6229
  case 'Extensions.getRuntimeStatus':
6176
6230
  return getRuntimeStatus$1(args[0], applicationId);
6231
+ case 'Extensions.getStatusBarItemContextMenuItems':
6232
+ return getStatusBarItemContextMenuItems(args[0], args[1], applicationId);
6177
6233
  case 'Extensions.getStatusBarItems':
6178
6234
  return getStatusBarItems(applicationId);
6179
6235
  case 'Extensions.getViews':
@@ -6274,6 +6330,7 @@ const commandMap = {
6274
6330
  'Extensions.getRpcInfo': getRpcInfo,
6275
6331
  'Extensions.getRunningExtensions': getRunningExtensions,
6276
6332
  'Extensions.getRuntimeStatus': getRuntimeStatus,
6333
+ 'Extensions.getStatusBarItemContextMenuItems': getStatusBarItemContextMenuItems,
6277
6334
  'Extensions.getStatusBarItems': getStatusBarItems,
6278
6335
  'Extensions.getViewActions': getViewActions,
6279
6336
  'Extensions.getViewActionsDom': getViewActionsDom,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-management-worker",
3
- "version": "4.80.0",
3
+ "version": "4.81.1",
4
4
  "description": "Webworker for the Extension Management functionality in Lvce Editor.",
5
5
  "keywords": [
6
6
  "web-worker"