@lvce-editor/extension-host-worker 4.1.0 → 4.3.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.
@@ -3076,6 +3076,73 @@ const setup = ({
3076
3076
  global.vscode = api;
3077
3077
  };
3078
3078
 
3079
+ const state$6 = {
3080
+ webExtensions: []
3081
+ };
3082
+
3083
+ const cache = Object.create(null);
3084
+ const id = 1;
3085
+ const get$5 = () => {
3086
+ return cache[id];
3087
+ };
3088
+ const has = () => {
3089
+ return id in cache;
3090
+ };
3091
+ const set$4 = value => {
3092
+ cache[id] = value;
3093
+ };
3094
+ const clear = () => {
3095
+ delete cache[id];
3096
+ };
3097
+
3098
+ const getJson = async url => {
3099
+ try {
3100
+ const response = await fetch(url);
3101
+ if (!response.ok) {
3102
+ throw new Error(response.statusText);
3103
+ }
3104
+ const json = await response.json();
3105
+ return json;
3106
+ } catch (error) {
3107
+ throw new VError(error, `Failed to get json`);
3108
+ }
3109
+ };
3110
+
3111
+ const NewLine = '\n';
3112
+ const Slash$1 = '/';
3113
+
3114
+ const interExtensionId = path => {
3115
+ const slashIndex = path.lastIndexOf(Slash$1);
3116
+ return path.slice(slashIndex + 1);
3117
+ };
3118
+
3119
+ const getWebExtensionManifest = async (path, manifestPath) => {
3120
+ try {
3121
+ const manifest = await getJson(manifestPath);
3122
+ return {
3123
+ ...manifest,
3124
+ path
3125
+ };
3126
+ } catch (error) {
3127
+ const id = interExtensionId(path);
3128
+ throw new VError(error, `Failed to load extension manifest for ${id}`);
3129
+ }
3130
+ };
3131
+
3132
+ const getWebManifestPath = path => {
3133
+ const manifestPath = `${path}/extension.json`;
3134
+ return manifestPath;
3135
+ };
3136
+
3137
+ const addWebExtension = async path => {
3138
+ const manifestPath = getWebManifestPath(path);
3139
+ const manifest = await getWebExtensionManifest(path, manifestPath);
3140
+ // TODO avoid mutation if possible
3141
+ state$6.webExtensions.push(manifest);
3142
+ clear();
3143
+ return manifest;
3144
+ };
3145
+
3079
3146
  const applyBulkReplacement = async (files, ranges, replacement) => {
3080
3147
  console.log({
3081
3148
  files,
@@ -3089,8 +3156,6 @@ const addCssStyleSheet = (id, css) => {
3089
3156
  return invoke$2('Css.addCssStyleSheet', id, css);
3090
3157
  };
3091
3158
 
3092
- const NewLine = '\n';
3093
-
3094
3159
  const warn = (...args) => {
3095
3160
  console.warn(...args);
3096
3161
  };
@@ -3451,13 +3516,13 @@ const storeId = 'lvce-keyvalue';
3451
3516
 
3452
3517
  // TODO high memory usage in idb because of transactionDoneMap
3453
3518
 
3454
- const state$6 = {
3519
+ const state$5 = {
3455
3520
  databases: Object.create(null),
3456
3521
  dbVersion: 2,
3457
3522
  cachedDb: undefined
3458
3523
  };
3459
3524
  const getDb$1 = async () => {
3460
- const db = await openDB(storeId, state$6.dbVersion, {
3525
+ const db = await openDB(storeId, state$5.dbVersion, {
3461
3526
  async upgrade(db, oldVersion) {
3462
3527
  if (!db.objectStoreNames.contains(storeId)) {
3463
3528
  await db.createObjectStore(storeId, {
@@ -3469,13 +3534,13 @@ const getDb$1 = async () => {
3469
3534
  return db;
3470
3535
  };
3471
3536
  const getDbMemoized$1 = async () => {
3472
- state$6.cachedDb ||= await getDb$1();
3473
- return state$6.cachedDb;
3537
+ state$5.cachedDb ||= await getDb$1();
3538
+ return state$5.cachedDb;
3474
3539
  };
3475
3540
 
3476
3541
  // TODO high memory usage in idb because of transactionDoneMap
3477
3542
 
3478
- const set$4 = async (key, value) => {
3543
+ const set$3 = async (key, value) => {
3479
3544
  try {
3480
3545
  const db = await getDbMemoized$1();
3481
3546
  await db.put(storeId, value, key);
@@ -3483,7 +3548,7 @@ const set$4 = async (key, value) => {
3483
3548
  throw new VError(error, 'Failed to save value to indexed db');
3484
3549
  }
3485
3550
  };
3486
- const get$5 = async key => {
3551
+ const get$4 = async key => {
3487
3552
  try {
3488
3553
  const db = await getDbMemoized$1();
3489
3554
  const value = await db.get(storeId, key);
@@ -3496,19 +3561,19 @@ const get$5 = async key => {
3496
3561
  const getCacheKey$1 = colorThemeId => {
3497
3562
  return 'color-theme-' + colorThemeId;
3498
3563
  };
3499
- const get$4 = colorThemeId => {
3564
+ const get$3 = colorThemeId => {
3500
3565
  const cacheKey = getCacheKey$1(colorThemeId);
3501
- return get$5(cacheKey);
3566
+ return get$4(cacheKey);
3502
3567
  };
3503
- const set$3 = (colorThemeId, data) => {
3568
+ const set$2 = (colorThemeId, data) => {
3504
3569
  const cacheKey = getCacheKey$1(colorThemeId);
3505
- return set$4(cacheKey, data);
3570
+ return set$3(cacheKey, data);
3506
3571
  };
3507
3572
 
3508
3573
  const GetColorThemeCssCachedIndexedDb = {
3509
3574
  __proto__: null,
3510
- get: get$4,
3511
- set: set$3
3575
+ get: get$3,
3576
+ set: set$2
3512
3577
  };
3513
3578
 
3514
3579
  const getText$1 = key => {
@@ -3521,35 +3586,35 @@ const setText = (key, value) => {
3521
3586
  const getCacheKey = colorThemeId => {
3522
3587
  return 'lvce-color-theme-' + colorThemeId;
3523
3588
  };
3524
- const get$3 = colorThemeId => {
3589
+ const get$2 = colorThemeId => {
3525
3590
  const cacheKey = getCacheKey(colorThemeId);
3526
3591
  return getText$1(cacheKey);
3527
3592
  };
3528
- const set$2 = (colorThemeId, data) => {
3593
+ const set$1 = (colorThemeId, data) => {
3529
3594
  const cacheKey = getCacheKey(colorThemeId);
3530
3595
  return setText(cacheKey, data);
3531
3596
  };
3532
3597
 
3533
3598
  const GetColorThemeCssCachedLocalStorage = {
3534
3599
  __proto__: null,
3535
- get: get$3,
3536
- set: set$2
3600
+ get: get$2,
3601
+ set: set$1
3537
3602
  };
3538
3603
 
3539
- const get$2 = colorThemeId => {
3604
+ const get$1 = colorThemeId => {
3540
3605
  return '';
3541
3606
  };
3542
- const set$1 = (colorThemeId, data) => {
3607
+ const set = (colorThemeId, data) => {
3543
3608
  // noop
3544
3609
  };
3545
3610
 
3546
3611
  const GetColorThemeCssCachedNoop = {
3547
3612
  __proto__: null,
3548
- get: get$2,
3549
- set: set$1
3613
+ get: get$1,
3614
+ set
3550
3615
  };
3551
3616
 
3552
- const get$1 = key => {
3617
+ const get = key => {
3553
3618
  return invoke$2('Preferences.get', key);
3554
3619
  };
3555
3620
 
@@ -3564,7 +3629,7 @@ const getCacheFn = config => {
3564
3629
  }
3565
3630
  };
3566
3631
  const getColorThemeCssCached = async (colorThemeId, getData) => {
3567
- const config = await get$1('colorTheme.cache');
3632
+ const config = await get('colorTheme.cache');
3568
3633
  const module = await getCacheFn(config);
3569
3634
  const cachedData = await module.get(colorThemeId);
3570
3635
  if (cachedData) {
@@ -3613,23 +3678,6 @@ const getColorThemeUri = (extensions, colorThemeId) => {
3613
3678
  return '';
3614
3679
  };
3615
3680
 
3616
- const state$5 = {
3617
- webExtensions: []
3618
- };
3619
-
3620
- const getJson = async url => {
3621
- try {
3622
- const response = await fetch(url);
3623
- if (!response.ok) {
3624
- throw new Error(response.statusText);
3625
- }
3626
- const json = await response.json();
3627
- return json;
3628
- } catch (error) {
3629
- throw new VError(error, `Failed to get json`);
3630
- }
3631
- };
3632
-
3633
3681
  const getAssetDir = () => {
3634
3682
  // @ts-ignore
3635
3683
  if (typeof ASSET_DIR !== 'undefined') {
@@ -3653,7 +3701,7 @@ const getSharedProcessExtensions = () => {
3653
3701
  return invoke$2(/* ExtensionManagement.getExtensions */'ExtensionManagement.getExtensions');
3654
3702
  };
3655
3703
  const doGetExtensions = async () => {
3656
- const meta = state$5.webExtensions;
3704
+ const meta = state$6.webExtensions;
3657
3705
  if (platform === Web) {
3658
3706
  const webExtensions = await getWebExtensions();
3659
3707
  return [...webExtensions, ...meta];
@@ -3670,24 +3718,12 @@ const getExtensions$1 = async () => {
3670
3718
  return doGetExtensions();
3671
3719
  };
3672
3720
 
3673
- const cache = Object.create(null);
3674
- const id = 1;
3675
- const get = () => {
3676
- return cache[id];
3677
- };
3678
- const has = () => {
3679
- return id in cache;
3680
- };
3681
- const set = value => {
3682
- cache[id] = value;
3683
- };
3684
-
3685
3721
  // TODO getExtensions is still called 6 times on startup instead of 1
3686
3722
  const getExtensions = () => {
3687
3723
  if (!has()) {
3688
- set(getExtensions$1());
3724
+ set$4(getExtensions$1());
3689
3725
  }
3690
- return get();
3726
+ return get$5();
3691
3727
  };
3692
3728
 
3693
3729
  const getColorThemeJson$2 = async colorThemeId => {
@@ -3756,7 +3792,7 @@ const applyColorTheme = async colorThemeId => {
3756
3792
  const themeColor = getMetaThemeColor(colorThemeId) || '';
3757
3793
  await setThemeColor(themeColor);
3758
3794
  }
3759
- if (platform !== Web && (await get$1('development.watchColorTheme'))) {
3795
+ if (platform !== Web && (await get('development.watchColorTheme'))) {
3760
3796
  watch(colorThemeId);
3761
3797
  }
3762
3798
  } catch (error) {
@@ -3771,7 +3807,7 @@ const watch = async id => {
3771
3807
  await invoke$2('ExtensionHost.watchColorTheme', id);
3772
3808
  };
3773
3809
  const getPreferredColorTheme = () => {
3774
- const preferredColorTheme = get$1('workbench.colorTheme');
3810
+ const preferredColorTheme = get('workbench.colorTheme');
3775
3811
  return preferredColorTheme;
3776
3812
  };
3777
3813
 
@@ -3794,7 +3830,7 @@ const hydrate$1 = async () => {
3794
3830
  const iframeWorkerUrl = `${assetDir}/packages/renderer-worker/node_modules/@lvce-editor/iframe-worker/dist/iframeWorkerMain.js`;
3795
3831
 
3796
3832
  const getConfiguredIframeWorkerUrl = async () => {
3797
- let configuredWorkerUrl = (await get$1('develop.iframeWorkerPath')) || '';
3833
+ let configuredWorkerUrl = (await get('develop.iframeWorkerPath')) || '';
3798
3834
  if (configuredWorkerUrl) {
3799
3835
  configuredWorkerUrl = '/remote' + configuredWorkerUrl;
3800
3836
  }
@@ -4732,7 +4768,7 @@ const getIconThemeJson$1 = async iconThemeId => {
4732
4768
  extensionPath: `${assetDir}/extensions/builtin.${iconThemeId}`
4733
4769
  };
4734
4770
  }
4735
- for (const webExtension of state$5.webExtensions) {
4771
+ for (const webExtension of state$6.webExtensions) {
4736
4772
  if (webExtension.iconThemes) {
4737
4773
  for (const iconTheme of webExtension.iconThemes) {
4738
4774
  // TODO handle error when icon theme path is not of type string
@@ -4853,7 +4889,7 @@ const setIconTheme = async iconThemeId => {
4853
4889
  }
4854
4890
  };
4855
4891
  const hydrate = async () => {
4856
- const iconThemeId = (await get$1('icon-theme')) || 'vscode-icons';
4892
+ const iconThemeId = (await get('icon-theme')) || 'vscode-icons';
4857
4893
  await setIconTheme(iconThemeId);
4858
4894
  };
4859
4895
 
@@ -5360,6 +5396,7 @@ const commandMap = {
5360
5396
  'ExtensionHostRename.executeprepareRenameProvider': executeprepareRenameProvider,
5361
5397
  'ExtensionHostRename.executeRenameProvider': executeRenameProvider,
5362
5398
  'Extensions.getExtensions': getExtensions,
5399
+ 'Extensions.addWebExtension': addWebExtension,
5363
5400
  'FileSystemFetch.chmod': chmod$1,
5364
5401
  'FileSystemFetch.getBlob': getBlob$1,
5365
5402
  'FileSystemFetch.mkdir': mkdir$1,
@@ -5381,12 +5418,12 @@ const commandMap = {
5381
5418
  'IconTheme.hydrate': hydrate,
5382
5419
  'IconTheme.setIconTheme': setIconTheme,
5383
5420
  'IndexedDb.addHandle': addHandle,
5384
- 'IndexedDb.get': get$5,
5421
+ 'IndexedDb.get': get$4,
5385
5422
  'IndexedDb.getHandle': getHandle$1,
5386
5423
  'IndexedDb.getValues': getValues,
5387
5424
  'IndexedDb.getValuesByIndexName': getValuesByIndexName,
5388
5425
  'IndexedDb.saveValue': saveValue,
5389
- 'IndexedDb.set': set$4,
5426
+ 'IndexedDb.set': set$3,
5390
5427
  'Languages.getLanguages': getLanguages,
5391
5428
  'SearchFileWithFetch.searchFileWithFetch': searchFile$1,
5392
5429
  'SearchFileWithHtml.searchFileWithHtml': searchFile,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-host-worker",
3
- "version": "4.1.0",
3
+ "version": "4.3.0",
4
4
  "description": "Webworker for the extension host functionality in Lvce Editor.",
5
5
  "main": "dist/extensionHostWorkerMain.js",
6
6
  "type": "module",