@lvce-editor/extension-host-worker 3.17.0 → 3.18.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.
@@ -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
@@ -4893,6 +4916,51 @@ const getHandle$1 = async uri => {
4893
4916
  return handle;
4894
4917
  };
4895
4918
 
4919
+ const getLanguagesFromExtension = extension => {
4920
+ // TODO what if extension is null? should not crash process, handle error gracefully
4921
+ // TODO what if extension languages is not of type array?
4922
+ // TODO what if language is null?
4923
+ if (!extension) {
4924
+ return [];
4925
+ }
4926
+ if (!extension.languages) {
4927
+ return [];
4928
+ }
4929
+ const extensionPath = extension.path;
4930
+ const getLanguageFromExtension = language => {
4931
+ if (language.tokenize) {
4932
+ if (typeof language.tokenize !== 'string') {
4933
+ console.warn(`[info] ${language.id}: language.tokenize must be of type string but was of type ${typeof language.tokenize}`);
4934
+ return {
4935
+ ...language,
4936
+ extensionPath,
4937
+ tokenize: ''
4938
+ };
4939
+ }
4940
+ return {
4941
+ ...language,
4942
+ extensionPath,
4943
+ tokenize: `${extensionPath}/${language.tokenize}`
4944
+ };
4945
+ }
4946
+ return language;
4947
+ };
4948
+ return extension.languages.map(getLanguageFromExtension);
4949
+ };
4950
+
4951
+ const getLanguages = async () => {
4952
+ try {
4953
+ const extensions = await getExtensions();
4954
+ const languages = extensions.flatMap(getLanguagesFromExtension);
4955
+ console.log({
4956
+ languages
4957
+ });
4958
+ return languages;
4959
+ } catch (error) {
4960
+ throw new VError(error, 'Failed to load languages');
4961
+ }
4962
+ };
4963
+
4896
4964
  const loadWebView = async (providerId, savedState) => {
4897
4965
  const rpc = getWebView(providerId);
4898
4966
  await rpc.provider.create(rpc, rpc.uri, savedState);
@@ -5253,6 +5321,8 @@ const textSearch = async (scheme, root, query, options, assetDir) => {
5253
5321
 
5254
5322
  const commandMap = {
5255
5323
  'BulkReplacement.applyBulkReplacement': applyBulkReplacement,
5324
+ 'ColorTheme.getColorThemeCssFromJson': getColorThemeCssFromJson,
5325
+ 'ColorTheme.getColorThemeJson': getColorThemeJson,
5256
5326
  'ColorTheme.hydrate': hydrate$1,
5257
5327
  'ExtensionHost.launchIframeWorker': launchIframeWorker,
5258
5328
  'ExtensionHostRename.executeprepareRenameProvider': executeprepareRenameProvider,
@@ -5265,6 +5335,7 @@ const commandMap = {
5265
5335
  'FileSystemFetch.remove': remove$1,
5266
5336
  'FileSystemFetch.writeFile': writeFile$1,
5267
5337
  'FileSystemMemory.chmod': chmod,
5338
+ 'Languages.getLanguages': getLanguages,
5268
5339
  'FileSystemMemory.getBlob': getBlob,
5269
5340
  'FileSystemMemory.getBlobUrl': getBlobUrl,
5270
5341
  'FileSystemMemory.getFiles': getFiles,
@@ -5273,8 +5344,8 @@ const commandMap = {
5273
5344
  'FileSystemMemory.readFile': readFile,
5274
5345
  'FileSystemMemory.remove': remove,
5275
5346
  'FileSystemMemory.writeFile': writeFile,
5276
- 'IconTheme.getState': getState,
5277
5347
  'IconTheme.getJson': getIconThemeJson,
5348
+ 'IconTheme.getState': getState,
5278
5349
  'IconTheme.hydrate': hydrate,
5279
5350
  'IconTheme.setIconTheme': setIconTheme,
5280
5351
  'IndexedDb.addHandle': addHandle,
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.18.0",
4
4
  "description": "Webworker for the extension host functionality in Lvce Editor.",
5
5
  "main": "dist/extensionHostWorkerMain.js",
6
6
  "type": "module",