@lvce-editor/extension-host-worker 3.17.0 → 3.19.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.
@@ -2753,7 +2753,7 @@ const getWebView = id => {
2753
2753
  const setWebView = (id, webView) => {
2754
2754
  webViews[id] = webView;
2755
2755
  };
2756
- const getWebViews = () => {
2756
+ const getWebViews$1 = () => {
2757
2757
  return webViews;
2758
2758
  };
2759
2759
 
@@ -2775,7 +2775,7 @@ const getRemoteUrlForWebView = async (uri, options = {}) => {
2775
2775
  return objectUrl;
2776
2776
  };
2777
2777
 
2778
- const getRemoteUrl = async (uri, options = {}) => {
2778
+ const getRemoteUrl$1 = async (uri, options = {}) => {
2779
2779
  // TODO uri should always have protocol
2780
2780
  // then ask file system provider for remote url, for example disk file system provider or html file system provider
2781
2781
  const protocol = getProtocol(uri);
@@ -2978,7 +2978,7 @@ const api = {
2978
2978
  registerTypeDefinitionProvider: registerTypeDefinitionProvider,
2979
2979
  executeTypeDefinitionProvider: executeTypeDefinitionProvider,
2980
2980
  // Url
2981
- getRemoteUrl: getRemoteUrl,
2981
+ getRemoteUrl: getRemoteUrl$1,
2982
2982
  // Webview
2983
2983
  registerWebViewProvider: registerWebViewProvider,
2984
2984
  // Worker
@@ -3574,22 +3574,47 @@ const getColorThemeCssCached = async (colorThemeId, getData) => {
3574
3574
  return newData;
3575
3575
  };
3576
3576
 
3577
- const getColorThemeJson$2 = colorThemeId => {
3578
- return invoke$2(/* ExtensionHost.getColorThemeJson */'ExtensionHost.getColorThemeJson', /* colorThemeId */colorThemeId);
3577
+ const readJson = url => {
3578
+ return invoke$2('FileSystem.readJson', url);
3579
3579
  };
3580
3580
 
3581
- const getAssetDir = () => {
3582
- // @ts-ignore
3583
- if (typeof ASSET_DIR !== 'undefined') {
3584
- // @ts-ignore
3585
- return ASSET_DIR;
3581
+ const dirname = (pathSeparator, path) => {
3582
+ const index = path.lastIndexOf(pathSeparator);
3583
+ if (index === -1) {
3584
+ return path;
3586
3585
  }
3587
- if (platform === Electron) {
3588
- return '../../../../..';
3586
+ return path.slice(0, index);
3587
+ };
3588
+ const extname = path => {
3589
+ const index = path.lastIndexOf('.');
3590
+ if (index === -1) {
3591
+ return '';
3592
+ }
3593
+ return path.slice(index);
3594
+ };
3595
+ const join = (pathSeparator, ...parts) => {
3596
+ return parts.join(pathSeparator);
3597
+ };
3598
+
3599
+ const getColorThemeUri = (extensions, colorThemeId) => {
3600
+ for (const extension of extensions) {
3601
+ if (!extension.colorThemes) {
3602
+ continue;
3603
+ }
3604
+ for (const colorTheme of extension.colorThemes) {
3605
+ if (colorTheme.id !== colorThemeId) {
3606
+ continue;
3607
+ }
3608
+ const absolutePath = join('/', extension.uri, colorTheme.path);
3609
+ return absolutePath;
3610
+ }
3589
3611
  }
3590
3612
  return '';
3591
3613
  };
3592
- const assetDir = getAssetDir();
3614
+
3615
+ const state$5 = {
3616
+ webExtensions: []
3617
+ };
3593
3618
 
3594
3619
  const getJson = async url => {
3595
3620
  try {
@@ -3604,6 +3629,97 @@ const getJson = async url => {
3604
3629
  }
3605
3630
  };
3606
3631
 
3632
+ const getAssetDir = () => {
3633
+ // @ts-ignore
3634
+ if (typeof ASSET_DIR !== 'undefined') {
3635
+ // @ts-ignore
3636
+ return ASSET_DIR;
3637
+ }
3638
+ if (platform === Electron) {
3639
+ return '../../../../..';
3640
+ }
3641
+ return '';
3642
+ };
3643
+ const assetDir = getAssetDir();
3644
+
3645
+ const webExtensionsUrl = `${assetDir}/config/webExtensions.json`;
3646
+
3647
+ const getSharedProcessExtensions$1 = () => {
3648
+ return invoke$2(/* ExtensionManagement.getExtensions */'ExtensionManagement.getExtensions');
3649
+ };
3650
+ const getStaticWebExtensions = () => {
3651
+ return getJson(webExtensionsUrl);
3652
+ };
3653
+ const getWebExtensionsWeb = async () => {
3654
+ const staticWebExtensions = await getStaticWebExtensions();
3655
+ return [...staticWebExtensions, ...state$5.webExtensions];
3656
+ };
3657
+ const isWebExtension = extension => {
3658
+ return extension && typeof extension.browser === 'string';
3659
+ };
3660
+ const getWebExtensionsDefault = async () => {
3661
+ const staticWebExtensions = await getStaticWebExtensions();
3662
+ const sharedProcessExtensions = await getSharedProcessExtensions$1();
3663
+ const sharedProcessWebExtensions = sharedProcessExtensions.filter(isWebExtension);
3664
+ return [...staticWebExtensions, sharedProcessWebExtensions, ...state$5.webExtensions];
3665
+ };
3666
+ const getWebExtensions = async () => {
3667
+ try {
3668
+ switch (platform) {
3669
+ case Web:
3670
+ return await getWebExtensionsWeb();
3671
+ default:
3672
+ return await getWebExtensionsDefault();
3673
+ }
3674
+ } catch {
3675
+ return state$5.webExtensions;
3676
+ }
3677
+ };
3678
+
3679
+ const getSharedProcessExtensions = () => {
3680
+ return invoke$2(/* ExtensionManagement.getExtensions */'ExtensionManagement.getExtensions');
3681
+ };
3682
+ const getExtensions$1 = async () => {
3683
+ if (platform === Web) {
3684
+ const webExtensions = await getWebExtensions();
3685
+ return webExtensions;
3686
+ }
3687
+ if (platform === Remote) {
3688
+ const webExtensions = await getWebExtensions();
3689
+ const sharedProcessExtensions = await getSharedProcessExtensions();
3690
+ return [...sharedProcessExtensions, ...webExtensions];
3691
+ }
3692
+ const extensions = await getSharedProcessExtensions();
3693
+ return extensions;
3694
+ };
3695
+
3696
+ const cache = Object.create(null);
3697
+ const id = 1;
3698
+ const get = () => {
3699
+ return cache[id];
3700
+ };
3701
+ const has = () => {
3702
+ return id in cache;
3703
+ };
3704
+ const set = value => {
3705
+ cache[id] = value;
3706
+ };
3707
+
3708
+ // TODO getExtensions is still called 6 times on startup instead of 1
3709
+ const getExtensions = () => {
3710
+ if (!has()) {
3711
+ set(getExtensions$1());
3712
+ }
3713
+ return get();
3714
+ };
3715
+
3716
+ const getColorThemeJson$2 = async colorThemeId => {
3717
+ const extensions = await getExtensions();
3718
+ const colorThemeUri = getColorThemeUri(extensions, colorThemeId);
3719
+ const json = await readJson(colorThemeUri);
3720
+ return json;
3721
+ };
3722
+
3607
3723
  const getColorThemeUrlWeb = colorThemeId => {
3608
3724
  return `${assetDir}/extensions/builtin.theme-${colorThemeId}/color-theme.json`;
3609
3725
  };
@@ -3645,7 +3761,7 @@ const setThemeColor = async themeColor => {
3645
3761
  // TODO by default color theme should come from local storage, session storage, cache storage, indexeddb or blob url -> fast initial load
3646
3762
  // actual color theme can be computed after workbench has loaded (most times will be the same and doesn't need to be computed)
3647
3763
 
3648
- const state$5 = {
3764
+ const state$4 = {
3649
3765
  watchedTheme: ''
3650
3766
  };
3651
3767
  const FALLBACK_COLOR_THEME_ID = 'slime';
@@ -3656,7 +3772,7 @@ const FALLBACK_COLOR_THEME_ID = 'slime';
3656
3772
  const applyColorTheme = async colorThemeId => {
3657
3773
  try {
3658
3774
  string(colorThemeId);
3659
- state$5.colorTheme = colorThemeId;
3775
+ state$4.colorTheme = colorThemeId;
3660
3776
  const colorThemeCss = await getColorThemeCss(colorThemeId);
3661
3777
  await addCssStyleSheet('ContributedColorTheme', colorThemeCss);
3662
3778
  if (platform === Web) {
@@ -3671,10 +3787,10 @@ const applyColorTheme = async colorThemeId => {
3671
3787
  }
3672
3788
  };
3673
3789
  const watch = async id => {
3674
- if (state$5.watchedTheme === id) {
3790
+ if (state$4.watchedTheme === id) {
3675
3791
  return;
3676
3792
  }
3677
- state$5.watchedTheme = id;
3793
+ state$4.watchedTheme = id;
3678
3794
  await invoke$2('ExtensionHost.watchColorTheme', id);
3679
3795
  };
3680
3796
  const getPreferredColorTheme = () => {
@@ -3709,11 +3825,11 @@ const getConfiguredIframeWorkerUrl = async () => {
3709
3825
  return configuredWorkerUrl;
3710
3826
  };
3711
3827
 
3712
- const state$4 = {
3828
+ const state$3 = {
3713
3829
  id: 0
3714
3830
  };
3715
3831
  const create$1 = () => {
3716
- return ++state$4.id;
3832
+ return ++state$3.id;
3717
3833
  };
3718
3834
 
3719
3835
  const commandMap$1 = {
@@ -4467,21 +4583,6 @@ const getMimeType = fileExtension => {
4467
4583
  }
4468
4584
  };
4469
4585
 
4470
- const dirname = (pathSeparator, path) => {
4471
- const index = path.lastIndexOf(pathSeparator);
4472
- if (index === -1) {
4473
- return path;
4474
- }
4475
- return path.slice(0, index);
4476
- };
4477
- const extname = path => {
4478
- const index = path.lastIndexOf('.');
4479
- if (index === -1) {
4480
- return '';
4481
- }
4482
- return path.slice(index);
4483
- };
4484
-
4485
4586
  const getContentType = uri => {
4486
4587
  const extension = extname(uri);
4487
4588
  const mime = getMimeType(extension);
@@ -4490,11 +4591,11 @@ const getContentType = uri => {
4490
4591
 
4491
4592
  // TODO move this to an extension?
4492
4593
 
4493
- const state$3 = {
4594
+ const state$2 = {
4494
4595
  files: Object.create(null)
4495
4596
  };
4496
4597
  const getDirent = uri => {
4497
- return state$3.files[uri];
4598
+ return state$2.files[uri];
4498
4599
  };
4499
4600
  const readFile = uri => {
4500
4601
  const dirent = getDirent(uri);
@@ -4511,7 +4612,7 @@ const ensureParentDir = uri => {
4511
4612
  let endIndex = uri.indexOf(Slash);
4512
4613
  while (endIndex >= 0) {
4513
4614
  const part = uri.slice(startIndex, endIndex + 1);
4514
- state$3.files[part] = {
4615
+ state$2.files[part] = {
4515
4616
  type: Directory$1,
4516
4617
  content: ''
4517
4618
  };
@@ -4526,7 +4627,7 @@ const writeFile = (uri, content) => {
4526
4627
  dirent.content = content;
4527
4628
  } else {
4528
4629
  ensureParentDir(uri);
4529
- state$3.files[uri] = {
4630
+ state$2.files[uri] = {
4530
4631
  type: File$1,
4531
4632
  content
4532
4633
  };
@@ -4537,20 +4638,20 @@ const mkdir = uri => {
4537
4638
  uri += Slash;
4538
4639
  }
4539
4640
  ensureParentDir(uri);
4540
- state$3.files[uri] = {
4641
+ state$2.files[uri] = {
4541
4642
  type: Directory$1,
4542
4643
  content: ''
4543
4644
  };
4544
4645
  };
4545
4646
  const remove = uri => {
4546
4647
  const toDelete = [];
4547
- for (const key of Object.keys(state$3.files)) {
4648
+ for (const key of Object.keys(state$2.files)) {
4548
4649
  if (key.startsWith(uri)) {
4549
4650
  toDelete.push(key);
4550
4651
  }
4551
4652
  }
4552
4653
  for (const key of toDelete) {
4553
- delete state$3.files[key];
4654
+ delete state$2.files[key];
4554
4655
  }
4555
4656
  };
4556
4657
  const readDirWithFileTypes = uri => {
@@ -4558,7 +4659,7 @@ const readDirWithFileTypes = uri => {
4558
4659
  uri += Slash;
4559
4660
  }
4560
4661
  const dirents = [];
4561
- for (const [key, value] of Object.entries(state$3.files)) {
4662
+ for (const [key, value] of Object.entries(state$2.files)) {
4562
4663
  if (key.startsWith(uri)) {
4563
4664
  // @ts-ignore
4564
4665
  switch (value.type) {
@@ -4602,15 +4703,7 @@ const chmod = () => {
4602
4703
  throw new Error('[memfs] chmod not implemented');
4603
4704
  };
4604
4705
  const getFiles = () => {
4605
- return state$3.files;
4606
- };
4607
-
4608
- const state$2 = {
4609
- webExtensions: []
4610
- };
4611
-
4612
- const readJson = url => {
4613
- return invoke$2('FileSystem.readJson', url);
4706
+ return state$2.files;
4614
4707
  };
4615
4708
 
4616
4709
  const findMatchingIconThemeExtension = (extensions, iconThemeId) => {
@@ -4629,76 +4722,6 @@ const findMatchingIconThemeExtension = (extensions, iconThemeId) => {
4629
4722
  return undefined;
4630
4723
  };
4631
4724
 
4632
- const webExtensionsUrl = `${assetDir}/config/webExtensions.json`;
4633
-
4634
- const getSharedProcessExtensions$1 = () => {
4635
- return invoke$2(/* ExtensionManagement.getExtensions */'ExtensionManagement.getExtensions');
4636
- };
4637
- const getStaticWebExtensions = () => {
4638
- return getJson(webExtensionsUrl);
4639
- };
4640
- const getWebExtensionsWeb = async () => {
4641
- const staticWebExtensions = await getStaticWebExtensions();
4642
- return [...staticWebExtensions, ...state$2.webExtensions];
4643
- };
4644
- const isWebExtension = extension => {
4645
- return extension && typeof extension.browser === 'string';
4646
- };
4647
- const getWebExtensionsDefault = async () => {
4648
- const staticWebExtensions = await getStaticWebExtensions();
4649
- const sharedProcessExtensions = await getSharedProcessExtensions$1();
4650
- const sharedProcessWebExtensions = sharedProcessExtensions.filter(isWebExtension);
4651
- return [...staticWebExtensions, sharedProcessWebExtensions, ...state$2.webExtensions];
4652
- };
4653
- const getWebExtensions = async () => {
4654
- try {
4655
- switch (platform) {
4656
- case Web:
4657
- return await getWebExtensionsWeb();
4658
- default:
4659
- return await getWebExtensionsDefault();
4660
- }
4661
- } catch {
4662
- return state$2.webExtensions;
4663
- }
4664
- };
4665
-
4666
- const getSharedProcessExtensions = () => {
4667
- return invoke$2(/* ExtensionManagement.getExtensions */'ExtensionManagement.getExtensions');
4668
- };
4669
- const getExtensions$1 = async () => {
4670
- if (platform === Web) {
4671
- const webExtensions = await getWebExtensions();
4672
- return webExtensions;
4673
- }
4674
- if (platform === Remote) {
4675
- const webExtensions = await getWebExtensions();
4676
- const sharedProcessExtensions = await getSharedProcessExtensions();
4677
- return [...sharedProcessExtensions, ...webExtensions];
4678
- }
4679
- const extensions = await getSharedProcessExtensions();
4680
- return extensions;
4681
- };
4682
-
4683
- const cache = Object.create(null);
4684
- const id = 1;
4685
- const get = () => {
4686
- return cache[id];
4687
- };
4688
- const has = () => {
4689
- return id in cache;
4690
- };
4691
- const set = value => {
4692
- cache[id] = value;
4693
- };
4694
-
4695
- const getExtensions = () => {
4696
- if (!has()) {
4697
- set(getExtensions$1());
4698
- }
4699
- return get();
4700
- };
4701
-
4702
4725
  const getIconThemeUrl = iconThemeId => {
4703
4726
  return `${assetDir}/extensions/builtin.${iconThemeId}/icon-theme.json`;
4704
4727
  };
@@ -4712,7 +4735,7 @@ const getIconThemeJson = async iconThemeId => {
4712
4735
  extensionPath: `${assetDir}/extensions/builtin.${iconThemeId}`
4713
4736
  };
4714
4737
  }
4715
- for (const webExtension of state$2.webExtensions) {
4738
+ for (const webExtension of state$5.webExtensions) {
4716
4739
  if (webExtension.iconThemes) {
4717
4740
  for (const iconTheme of webExtension.iconThemes) {
4718
4741
  // TODO handle error when icon theme path is not of type string
@@ -4746,6 +4769,39 @@ const getRpcInfo = rpcId => {
4746
4769
  return info;
4747
4770
  };
4748
4771
 
4772
+ const getRemoteUrl = uri => {
4773
+ return `/remote/${uri}`;
4774
+ };
4775
+
4776
+ const getWebViewsFromExtensions = extensions => {
4777
+ const webViews = [];
4778
+ for (const extension of extensions) {
4779
+ if (extension && extension.webViews) {
4780
+ for (const webView of extension.webViews) {
4781
+ let path = extension.path;
4782
+ if (webView && webView.path) {
4783
+ path = `${extension.path}/${webView.path}`;
4784
+ }
4785
+ const uri = path;
4786
+ const remotePath = getRemoteUrl(uri);
4787
+ webViews.push({
4788
+ ...webView,
4789
+ path,
4790
+ uri,
4791
+ remotePath
4792
+ });
4793
+ }
4794
+ }
4795
+ }
4796
+ return webViews;
4797
+ };
4798
+
4799
+ const getWebViews = async () => {
4800
+ const extensions = await getExtensions();
4801
+ const webViews = getWebViewsFromExtensions(extensions);
4802
+ return webViews;
4803
+ };
4804
+
4749
4805
  const handleBeforeUnload = () => {
4750
4806
  // TODO save all webviews in localstorage
4751
4807
  // cannot use indexeddb during unload
@@ -4893,6 +4949,48 @@ const getHandle$1 = async uri => {
4893
4949
  return handle;
4894
4950
  };
4895
4951
 
4952
+ const getLanguagesFromExtension = extension => {
4953
+ // TODO what if extension is null? should not crash process, handle error gracefully
4954
+ // TODO what if extension languages is not of type array?
4955
+ // TODO what if language is null?
4956
+ if (!extension) {
4957
+ return [];
4958
+ }
4959
+ if (!extension.languages) {
4960
+ return [];
4961
+ }
4962
+ const extensionPath = extension.path;
4963
+ const getLanguageFromExtension = language => {
4964
+ if (language.tokenize) {
4965
+ if (typeof language.tokenize !== 'string') {
4966
+ console.warn(`[info] ${language.id}: language.tokenize must be of type string but was of type ${typeof language.tokenize}`);
4967
+ return {
4968
+ ...language,
4969
+ extensionPath,
4970
+ tokenize: ''
4971
+ };
4972
+ }
4973
+ return {
4974
+ ...language,
4975
+ extensionPath,
4976
+ tokenize: `${extensionPath}/${language.tokenize}`
4977
+ };
4978
+ }
4979
+ return language;
4980
+ };
4981
+ return extension.languages.map(getLanguageFromExtension);
4982
+ };
4983
+
4984
+ const getLanguages = async () => {
4985
+ try {
4986
+ const extensions = await getExtensions();
4987
+ const languages = extensions.flatMap(getLanguagesFromExtension);
4988
+ return languages;
4989
+ } catch (error) {
4990
+ throw new VError(error, 'Failed to load languages');
4991
+ }
4992
+ };
4993
+
4896
4994
  const loadWebView = async (providerId, savedState) => {
4897
4995
  const rpc = getWebView(providerId);
4898
4996
  await rpc.provider.create(rpc, rpc.uri, savedState);
@@ -4936,7 +5034,7 @@ const getAdditional = () => {
4936
5034
  }
4937
5035
  };
4938
5036
  const saveState = async () => {
4939
- const webViews = getWebViews();
5037
+ const webViews = getWebViews$1();
4940
5038
  const serialized = await serializeWebViews(webViews);
4941
5039
  const additional = await getAdditional();
4942
5040
  const all = [...serialized, ...additional];
@@ -5253,10 +5351,13 @@ const textSearch = async (scheme, root, query, options, assetDir) => {
5253
5351
 
5254
5352
  const commandMap = {
5255
5353
  'BulkReplacement.applyBulkReplacement': applyBulkReplacement,
5354
+ 'ColorTheme.getColorThemeCssFromJson': getColorThemeCssFromJson,
5355
+ 'ColorTheme.getColorThemeJson': getColorThemeJson,
5256
5356
  'ColorTheme.hydrate': hydrate$1,
5257
5357
  'ExtensionHost.launchIframeWorker': launchIframeWorker,
5258
5358
  'ExtensionHostRename.executeprepareRenameProvider': executeprepareRenameProvider,
5259
5359
  'ExtensionHostRename.executeRenameProvider': executeRenameProvider,
5360
+ 'Extensions.getExtensions': getExtensions,
5260
5361
  'FileSystemFetch.chmod': chmod$1,
5261
5362
  'FileSystemFetch.getBlob': getBlob$1,
5262
5363
  'FileSystemFetch.mkdir': mkdir$1,
@@ -5273,8 +5374,8 @@ const commandMap = {
5273
5374
  'FileSystemMemory.readFile': readFile,
5274
5375
  'FileSystemMemory.remove': remove,
5275
5376
  'FileSystemMemory.writeFile': writeFile,
5276
- 'IconTheme.getState': getState,
5277
5377
  'IconTheme.getJson': getIconThemeJson,
5378
+ 'IconTheme.getState': getState,
5278
5379
  'IconTheme.hydrate': hydrate,
5279
5380
  'IconTheme.setIconTheme': setIconTheme,
5280
5381
  'IndexedDb.addHandle': addHandle,
@@ -5284,6 +5385,7 @@ const commandMap = {
5284
5385
  'IndexedDb.getValuesByIndexName': getValuesByIndexName,
5285
5386
  'IndexedDb.saveValue': saveValue,
5286
5387
  'IndexedDb.set': set$4,
5388
+ 'Languages.getLanguages': getLanguages,
5287
5389
  'SearchFileWithFetch.searchFileWithFetch': searchFile$1,
5288
5390
  'SearchFileWithHtml.searchFileWithHtml': searchFile,
5289
5391
  'TextSearchFetch.textSearch': textSearch$2,
@@ -5292,6 +5394,7 @@ const commandMap = {
5292
5394
  'WebView.create3': createWebView3,
5293
5395
  'WebView.createWebViewWorkerRpc': createWebViewWorkerRpc,
5294
5396
  'WebView.getRpcInfo': getRpcInfo,
5397
+ 'WebViews.getWebViews': getWebViews,
5295
5398
  ['ExtensionHostDebug.evaluate']: evaluate,
5296
5399
  ['ExtensionHostDebug.getProperties']: getProperties,
5297
5400
  ['ExtensionHostDebug.listProcesses']: listProcesses,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-host-worker",
3
- "version": "3.17.0",
3
+ "version": "3.19.0",
4
4
  "description": "Webworker for the extension host functionality in Lvce Editor.",
5
5
  "main": "dist/extensionHostWorkerMain.js",
6
6
  "type": "module",