@lvce-editor/quick-pick-worker 4.28.0 → 4.29.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.
@@ -2834,7 +2834,7 @@ const getPicks$e = async (value, args, {
2834
2834
  const extensionPicks = await getExtensionPicks(assetDir, platform, applicationId);
2835
2835
  const allPicks = [...builtinPicks, ...extensionPicks];
2836
2836
  const converted = allPicks.map(toProtoVisibleItem$3);
2837
- return converted;
2837
+ return value === '>' ? converted.toSorted((a, b) => a.label.localeCompare(b.label)) : converted;
2838
2838
  };
2839
2839
 
2840
2840
  const state$3 = {
@@ -2943,9 +2943,8 @@ const invoke$2 = (method, ...args) => {
2943
2943
 
2944
2944
  const cacheName = 'quick-pick-files-v1';
2945
2945
  const cacheUrl = workspace => {
2946
- const url = new URL('https://quick-pick-cache.invalid/cache/v1');
2947
- url.searchParams.set('folder', workspace);
2948
- return url.href;
2946
+ const path = workspace.replaceAll('\\', '/').replace(/^\/+/, '').split('/').map(encodeURIComponent).join('/');
2947
+ return `https://quick-pick-cache.invalid/cache/v1/file/${path}`;
2949
2948
  };
2950
2949
  const isEntry = value => {
2951
2950
  if (!value || typeof value !== 'object') {
@@ -2972,12 +2971,15 @@ const get = async workspace => {
2972
2971
  };
2973
2972
  const set$1 = async (workspace, entry) => {
2974
2973
  const expires = new Date(Date.now() + 90 * 24 * 60 * 60 * 1000).toUTCString();
2974
+ const body = JSON.stringify(entry);
2975
2975
  const headers = {
2976
2976
  'cache-control': 'private, max-age=7776000',
2977
+ 'content-length': String(new TextEncoder().encode(body).byteLength),
2978
+ 'content-type': 'application/json',
2977
2979
  expires
2978
2980
  };
2979
2981
  try {
2980
- await invoke$2('Cache.setCacheStorageItem', cacheUrl(workspace), JSON.stringify(entry), cacheName, headers);
2982
+ await invoke$2('Cache.setCacheStorageItem', cacheUrl(workspace), body, cacheName, headers);
2981
2983
  } catch {
2982
2984
  // Caching is optional; a storage failure must not break file search.
2983
2985
  }
@@ -3013,6 +3015,41 @@ const trimTrailingSeparators = path => {
3013
3015
  }
3014
3016
  return result;
3015
3017
  };
3018
+ const normalizePath = path => path.replaceAll('\\', '/');
3019
+ const getWorkspaceDisplayPath = workspace => {
3020
+ if (!hasUriScheme(workspace)) {
3021
+ return {
3022
+ path: normalizePath(workspace)
3023
+ };
3024
+ }
3025
+ const url = new URL(workspace);
3026
+ return {
3027
+ host: url.host,
3028
+ path: decodeURIComponent(url.pathname),
3029
+ scheme: url.protocol
3030
+ };
3031
+ };
3032
+ const getRelativeDirectory = (workspace, uri, dirName) => {
3033
+ const workspacePath = getWorkspaceDisplayPath(workspace);
3034
+ if (hasUriScheme(uri)) {
3035
+ const url = new URL(uri);
3036
+ if (workspacePath.scheme !== url.protocol || workspacePath.host !== url.host) {
3037
+ return dirName;
3038
+ }
3039
+ } else if (workspacePath.scheme) {
3040
+ return dirName;
3041
+ }
3042
+ const normalizedWorkspace = trimTrailingSeparators(workspacePath.path);
3043
+ const normalizedDirectory = normalizePath(dirName);
3044
+ const prefix = normalizedWorkspace.endsWith('/') ? normalizedWorkspace : `${normalizedWorkspace}/`;
3045
+ if (normalizedDirectory === normalizedWorkspace) {
3046
+ return '';
3047
+ }
3048
+ if (!normalizedDirectory.startsWith(prefix)) {
3049
+ return dirName;
3050
+ }
3051
+ return normalizedDirectory.slice(prefix.length);
3052
+ };
3016
3053
  const resolveFileUri = (workspace, path) => {
3017
3054
  if (hasUriScheme(path)) {
3018
3055
  return path;
@@ -3029,12 +3066,13 @@ const resolveFileUri = (workspace, path) => {
3029
3066
  }
3030
3067
  return `${trimTrailingSeparators(workspace)}/${path}`;
3031
3068
  };
3032
- const convertToPick = uri => {
3069
+ const convertToPick = (workspace, uri) => {
3033
3070
  const displayPath = hasUriScheme(uri) ? decodeURIComponent(new URL(uri).pathname) : uri.replaceAll('\\', '/');
3034
3071
  const baseName = pathBaseName(displayPath);
3035
3072
  const dirName = pathDirName(displayPath);
3073
+ const description = getRelativeDirectory(workspace, uri, dirName);
3036
3074
  return {
3037
- description: dirName,
3075
+ description,
3038
3076
  direntType: File,
3039
3077
  fileIcon: '',
3040
3078
  icon: '',
@@ -3076,7 +3114,7 @@ const getPicks$b = async searchValue => {
3076
3114
  });
3077
3115
  }
3078
3116
  }
3079
- const picks = files.map(path => convertToPick(resolveFileUri(workspace, path)));
3117
+ const picks = files.map(path => convertToPick(workspace, resolveFileUri(workspace, path)));
3080
3118
  return picks;
3081
3119
  };
3082
3120
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/quick-pick-worker",
3
- "version": "4.28.0",
3
+ "version": "4.29.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/lvce-editor/quick-pick-worker.git"