@lvce-editor/extension-management-worker 4.83.1 → 4.83.3

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.
@@ -2160,6 +2160,12 @@ const parseDirective = directive => {
2160
2160
  const getWorkerUrls = absolutePath => {
2161
2161
  const applicationUrl = new URL(getOrigin());
2162
2162
  const workerUrl = new URL(absolutePath, applicationUrl);
2163
+ if (workerUrl.protocol === 'lvce:') {
2164
+ return {
2165
+ assetSource: new URL('./', workerUrl).href,
2166
+ origin: applicationUrl.origin
2167
+ };
2168
+ }
2163
2169
  if (workerUrl.protocol !== 'http:' && workerUrl.protocol !== 'https:') {
2164
2170
  return {
2165
2171
  origin: applicationUrl.origin
@@ -4892,11 +4898,12 @@ const hasView = (extension, viewId) => {
4892
4898
  const hasOnlyViewAndCommandActivations = extension => {
4893
4899
  return Array.isArray(extension.activation) && extension.activation.length > 0 && extension.activation.every(event => event.startsWith('onView:') || event.startsWith('onCommand:'));
4894
4900
  };
4901
+ const pendingViewCreations = new WeakMap();
4895
4902
  const hasOtherViewInstances = rpc => {
4896
4903
  return getEntries().some(entry => entry.instance.status === 'ready' && entry.instance.rpc === rpc);
4897
4904
  };
4898
4905
  const disposeViewOnlyExtensionWorker = async (extensionId, rpc) => {
4899
- if (hasOtherViewInstances(rpc)) {
4906
+ if (pendingViewCreations.has(rpc) || hasOtherViewInstances(rpc)) {
4900
4907
  return;
4901
4908
  }
4902
4909
  if (get$2(extensionId) !== rpc) {
@@ -4912,7 +4919,7 @@ const getExtensionForView = async (viewId, assetDir, platform, applicationId) =>
4912
4919
  }
4913
4920
  return extension;
4914
4921
  };
4915
- const getRpcForView = async (viewId, assetDir, platform, applicationId) => {
4922
+ const getRpcForView = async (viewId, assetDir, platform, applicationId, retain) => {
4916
4923
  const {
4917
4924
  assetDir: resolvedAssetDir,
4918
4925
  platform: resolvedPlatform
@@ -4922,22 +4929,26 @@ const getRpcForView = async (viewId, assetDir, platform, applicationId) => {
4922
4929
  const existingRpc = get$2(extensionId, applicationId);
4923
4930
  // Application teardown and reload own application workers; global view-only disposal does not.
4924
4931
  if (existingRpc) {
4925
- return {
4932
+ const worker = {
4926
4933
  disposeWorkerWhenLastViewCloses: applicationId === undefined && hasOnlyViewAndCommandActivations(extension),
4927
4934
  extensionId,
4928
4935
  rpc: existingRpc
4929
4936
  };
4937
+ retain?.(worker);
4938
+ return worker;
4930
4939
  }
4931
4940
  const activationResult = await activateByEvent(`onView:${viewId}`, resolvedAssetDir, resolvedPlatform, get$7(applicationId));
4932
4941
  if (activationResult.error) {
4933
4942
  throw activationResult.error;
4934
4943
  }
4935
4944
  const rpc = await getRpc$1(extension, resolvedAssetDir, resolvedPlatform);
4936
- return {
4945
+ const worker = {
4937
4946
  disposeWorkerWhenLastViewCloses: applicationId === undefined && hasOnlyViewAndCommandActivations(extension),
4938
4947
  extensionId,
4939
4948
  rpc
4940
4949
  };
4950
+ retain?.(worker);
4951
+ return worker;
4941
4952
  };
4942
4953
  const getRpcForInstance = async (viewId, uid, assetDir, platform) => {
4943
4954
  const instance = get$1(uid);
@@ -4966,12 +4977,18 @@ const getViewMetadata = async (rpc, viewId) => {
4966
4977
  };
4967
4978
  };
4968
4979
  const createViewInstance = async (viewId, uid, context, assetDir, platform, applicationId) => {
4980
+ let retainedWorker;
4981
+ const retain = worker => {
4982
+ retainedWorker = worker;
4983
+ pendingViewCreations.set(worker.rpc, (pendingViewCreations.get(worker.rpc) || 0) + 1);
4984
+ };
4969
4985
  try {
4986
+ // Retain at selection time, before yielding the RPC to the caller.
4970
4987
  const {
4971
4988
  disposeWorkerWhenLastViewCloses,
4972
4989
  extensionId,
4973
4990
  rpc
4974
- } = await getRpcForView(viewId, assetDir, platform, applicationId);
4991
+ } = await getRpcForView(viewId, assetDir, platform, applicationId, retain);
4975
4992
  const {
4976
4993
  eventListeners,
4977
4994
  stateful
@@ -5009,6 +5026,24 @@ const createViewInstance = async (viewId, uid, context, assetDir, platform, appl
5009
5026
  error: serializedError,
5010
5027
  ok: false
5011
5028
  };
5029
+ } finally {
5030
+ if (retainedWorker) {
5031
+ const {
5032
+ disposeWorkerWhenLastViewCloses,
5033
+ extensionId,
5034
+ rpc
5035
+ } = retainedWorker;
5036
+ const remaining = (pendingViewCreations.get(rpc) || 1) - 1;
5037
+ if (remaining) {
5038
+ pendingViewCreations.set(rpc, remaining);
5039
+ } else {
5040
+ pendingViewCreations.delete(rpc);
5041
+ }
5042
+ // Failed creations must also release a worker kept alive by an overlapping close.
5043
+ if (disposeWorkerWhenLastViewCloses) {
5044
+ await disposeViewOnlyExtensionWorker(extensionId, rpc);
5045
+ }
5046
+ }
5012
5047
  }
5013
5048
  };
5014
5049
  const dispatchViewEvent = async (viewId, uid, event, assetDir, platform) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-management-worker",
3
- "version": "4.83.1",
3
+ "version": "4.83.3",
4
4
  "description": "Webworker for the Extension Management functionality in Lvce Editor.",
5
5
  "keywords": [
6
6
  "web-worker"