@lvce-editor/extension-host-worker 5.29.0 → 5.31.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.
@@ -426,6 +426,9 @@ const getPreview = item => {
426
426
  }
427
427
  };
428
428
  const validate = (item, schema) => {
429
+ if (typeof schema === 'function') {
430
+ return schema(item);
431
+ }
429
432
  const actualType = getType(item);
430
433
  const expectedType = schema.type;
431
434
  if (actualType !== expectedType) {
@@ -2670,15 +2673,41 @@ const executeReferenceProvider2 = (uri, languageId, offset, position) => {
2670
2673
  });
2671
2674
  };
2672
2675
 
2676
+ const validateResult = renameResult => {
2677
+ if (renameResult === null || renameResult === undefined) {
2678
+ return '';
2679
+ }
2680
+ if (typeof renameResult !== 'object') {
2681
+ return 'rename result must be of type object';
2682
+ }
2683
+ if (typeof renameResult.canRename !== 'boolean') {
2684
+ return `renameResult.canRename must be of type boolean`;
2685
+ }
2686
+ if (!Array.isArray(renameResult.edits)) {
2687
+ return `renameResult.edits must be of type array`;
2688
+ }
2689
+ for (const item of renameResult.edits) {
2690
+ if (!item) {
2691
+ return `renameResult item must be defined`;
2692
+ }
2693
+ if (typeof item !== 'object') {
2694
+ return `renameResult item must be of type object`;
2695
+ }
2696
+ if (typeof item.uri !== 'string') {
2697
+ return `renameResult item uri must be of type string`;
2698
+ }
2699
+ if (!Array.isArray(item.edits)) {
2700
+ return `renameResult item edits must be of type array`;
2701
+ }
2702
+ }
2703
+ return '';
2704
+ };
2673
2705
  const {
2674
2706
  registerRenameProvider,
2675
2707
  executeRenameProvider,
2676
2708
  executeprepareRenameProvider} = create$b({
2677
2709
  name: 'Rename',
2678
- resultShape: {
2679
- type: Object$1,
2680
- allowUndefined: true
2681
- },
2710
+ resultShape: validateResult,
2682
2711
  additionalMethodNames: [
2683
2712
  // @ts-ignore
2684
2713
  {
@@ -2844,6 +2873,110 @@ const {
2844
2873
  }
2845
2874
  });
2846
2875
 
2876
+ const RE_PROTOCOL = /^([a-z-]+):\/\//;
2877
+ const getProtocol = uri => {
2878
+ const protocolMatch = uri.match(RE_PROTOCOL);
2879
+ if (protocolMatch) {
2880
+ return protocolMatch[1];
2881
+ }
2882
+ return '';
2883
+ };
2884
+
2885
+ const createWebViewIpc = async webView => {
2886
+ const {
2887
+ uid,
2888
+ origin
2889
+ } = webView;
2890
+ const {
2891
+ port1,
2892
+ port2
2893
+ } = getPortTuple();
2894
+ const rpcPromise = MessagePortRpcParent.create({
2895
+ messagePort: port2,
2896
+ isMessagePortOpen: false,
2897
+ commandMap: {}
2898
+ });
2899
+ const portType = 'test';
2900
+ await invokeAndTransfer$1('WebView.setPort', uid, port1, origin, portType);
2901
+ // TODO maybe don't send a message port only to get object url?
2902
+ // TODO dispose rpc to avoid memory leak
2903
+ const rpc = await rpcPromise;
2904
+ return rpc;
2905
+ };
2906
+
2907
+ const webViews = Object.create(null);
2908
+ const webViewProviders = Object.create(null);
2909
+ const getProvider = providerId => {
2910
+ return webViewProviders[providerId];
2911
+ };
2912
+ const setProvider = (providerId, provider) => {
2913
+ webViewProviders[providerId] = provider;
2914
+ };
2915
+ const getWebView = id => {
2916
+ return webViews[id];
2917
+ };
2918
+ const setWebView = (id, webView) => {
2919
+ webViews[id] = webView;
2920
+ };
2921
+ const getWebViews$1 = () => {
2922
+ return webViews;
2923
+ };
2924
+
2925
+ // TODO if webViewId is provided,
2926
+ // 1. read file as blob
2927
+ // 2. send blob to webview
2928
+ // 3. create objecturl in webview
2929
+ // 4. send back objecturl to extension host worker
2930
+ // 5. provide objectUrl to extension
2931
+
2932
+ const getRemoteUrlForWebView = async (uri, options = {}) => {
2933
+ // TODO webviews should be stored in iframe worker
2934
+ const webView = getWebView(options.webViewId);
2935
+ if (!webView) {
2936
+ throw new Error(`webview ${options.webViewId} not found`);
2937
+ }
2938
+ const [rpc, blob] = await Promise.all([createWebViewIpc(webView), invoke$1('FileSystem.getBlob', uri)]);
2939
+ const objectUrl = await rpc.invoke('createObjectUrl', blob);
2940
+ return objectUrl;
2941
+ };
2942
+
2943
+ const isFileProtocol = protocol => {
2944
+ return !protocol || protocol === 'file';
2945
+ };
2946
+ const getRemoteUrlSync = uri => {
2947
+ const protocol = getProtocol(uri);
2948
+ const withoutPrefix = uri.startsWith('file://') ? uri.slice('file://'.length) : uri;
2949
+ if (platform === Remote && isFileProtocol(protocol)) {
2950
+ if (uri.startsWith('/')) {
2951
+ return `/remote${withoutPrefix}`;
2952
+ }
2953
+ return `/remote/${withoutPrefix}`;
2954
+ }
2955
+ if (platform === Electron && isFileProtocol(protocol)) {
2956
+ if (uri.startsWith('/')) {
2957
+ return `/remote${withoutPrefix}`;
2958
+ }
2959
+ return `/remote/${withoutPrefix}`;
2960
+ }
2961
+ return '';
2962
+ };
2963
+ const getRemoteUrl$1 = async (uri, options = {}) => {
2964
+ // TODO uri should always have protocol
2965
+ // then ask file system provider for remote url, for example disk file system provider or html file system provider
2966
+ const syncUrl = getRemoteUrlSync(uri);
2967
+ if (syncUrl) {
2968
+ return syncUrl;
2969
+ }
2970
+ if (options.webViewId) {
2971
+ return getRemoteUrlForWebView(uri, options);
2972
+ }
2973
+ if (uri.startsWith('html://')) {
2974
+ const url = await invoke$1('Blob.getSrc', uri);
2975
+ return url;
2976
+ }
2977
+ throw new Error(`unsupported platform for remote url`);
2978
+ };
2979
+
2847
2980
  const state$9 = {
2848
2981
  webExtensions: []
2849
2982
  };
@@ -3022,7 +3155,10 @@ const getIconDefinitions = async providerId => {
3022
3155
  const id = extension.id.split('.');
3023
3156
  const shortId = id[1];
3024
3157
  if (shortId === providerId && extension['source-control-icons'] && Array.isArray(extension['source-control-icons'])) {
3025
- return extension['source-control-icons'];
3158
+ const baseIcons = extension['source-control-icons'];
3159
+ const absoluteUris = baseIcons.map(icon => `${extension.uri}/${icon}`);
3160
+ const remoteUris = absoluteUris.map(icon => getRemoteUrlSync(icon));
3161
+ return remoteUris;
3026
3162
  }
3027
3163
  }
3028
3164
  // TODO return warning that no icons were found?
@@ -3089,99 +3225,6 @@ const {
3089
3225
  }
3090
3226
  });
3091
3227
 
3092
- const RE_PROTOCOL = /^([a-z-]+):\/\//;
3093
- const getProtocol = uri => {
3094
- const protocolMatch = uri.match(RE_PROTOCOL);
3095
- if (protocolMatch) {
3096
- return protocolMatch[1];
3097
- }
3098
- return '';
3099
- };
3100
-
3101
- const createWebViewIpc = async webView => {
3102
- const {
3103
- uid,
3104
- origin
3105
- } = webView;
3106
- const {
3107
- port1,
3108
- port2
3109
- } = getPortTuple();
3110
- const rpcPromise = MessagePortRpcParent.create({
3111
- messagePort: port2,
3112
- isMessagePortOpen: false,
3113
- commandMap: {}
3114
- });
3115
- const portType = 'test';
3116
- await invokeAndTransfer$1('WebView.setPort', uid, port1, origin, portType);
3117
- // TODO maybe don't send a message port only to get object url?
3118
- // TODO dispose rpc to avoid memory leak
3119
- const rpc = await rpcPromise;
3120
- return rpc;
3121
- };
3122
-
3123
- const webViews = Object.create(null);
3124
- const webViewProviders = Object.create(null);
3125
- const getProvider = providerId => {
3126
- return webViewProviders[providerId];
3127
- };
3128
- const setProvider = (providerId, provider) => {
3129
- webViewProviders[providerId] = provider;
3130
- };
3131
- const getWebView = id => {
3132
- return webViews[id];
3133
- };
3134
- const setWebView = (id, webView) => {
3135
- webViews[id] = webView;
3136
- };
3137
- const getWebViews$1 = () => {
3138
- return webViews;
3139
- };
3140
-
3141
- // TODO if webViewId is provided,
3142
- // 1. read file as blob
3143
- // 2. send blob to webview
3144
- // 3. create objecturl in webview
3145
- // 4. send back objecturl to extension host worker
3146
- // 5. provide objectUrl to extension
3147
-
3148
- const getRemoteUrlForWebView = async (uri, options = {}) => {
3149
- // TODO webviews should be stored in iframe worker
3150
- const webView = getWebView(options.webViewId);
3151
- if (!webView) {
3152
- throw new Error(`webview ${options.webViewId} not found`);
3153
- }
3154
- const [rpc, blob] = await Promise.all([createWebViewIpc(webView), invoke$1('FileSystem.getBlob', uri)]);
3155
- const objectUrl = await rpc.invoke('createObjectUrl', blob);
3156
- return objectUrl;
3157
- };
3158
-
3159
- const getRemoteUrl$1 = async (uri, options = {}) => {
3160
- // TODO uri should always have protocol
3161
- // then ask file system provider for remote url, for example disk file system provider or html file system provider
3162
- const protocol = getProtocol(uri);
3163
- if (platform === Remote && !protocol) {
3164
- if (uri.startsWith('/')) {
3165
- return `/remote${uri}`;
3166
- }
3167
- return `/remote/${uri}`;
3168
- }
3169
- if (platform === Electron && !protocol) {
3170
- if (uri.startsWith('/')) {
3171
- return `/remote${uri}`;
3172
- }
3173
- return `/remote/${uri}`;
3174
- }
3175
- if (options.webViewId) {
3176
- return getRemoteUrlForWebView(uri, options);
3177
- }
3178
- if (uri.startsWith('html://')) {
3179
- const url = await invoke$1('Blob.getSrc', uri);
3180
- return url;
3181
- }
3182
- throw new Error(`unsupported platform for remote url`);
3183
- };
3184
-
3185
3228
  // TODO pass uuid to allow having multiple webviews open at the same time
3186
3229
 
3187
3230
  /**
@@ -4606,6 +4649,9 @@ const getColorThemeUri = (extensions, colorThemeId) => {
4606
4649
  const getColorThemeJson$2 = async colorThemeId => {
4607
4650
  const extensions = await getExtensions();
4608
4651
  const colorThemeUri = getColorThemeUri(extensions, colorThemeId);
4652
+ if (!colorThemeUri) {
4653
+ return {};
4654
+ }
4609
4655
  const json = await readJson(colorThemeUri);
4610
4656
  return json;
4611
4657
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-host-worker",
3
- "version": "5.29.0",
3
+ "version": "5.31.0",
4
4
  "description": "Webworker for the extension host functionality in Lvce Editor.",
5
5
  "keywords": [
6
6
  "web-worker"