@lvce-editor/iframe-worker 3.3.0 → 3.5.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.
@@ -267,14 +267,14 @@ const readyMessage = 'ready';
267
267
  const getData$2 = event => {
268
268
  return event.data;
269
269
  };
270
- const listen$6 = () => {
270
+ const listen$7 = () => {
271
271
  // @ts-ignore
272
272
  if (typeof WorkerGlobalScope === 'undefined') {
273
273
  throw new TypeError('module is not in web worker scope');
274
274
  }
275
275
  return globalThis;
276
276
  };
277
- const signal$6 = global => {
277
+ const signal$7 = global => {
278
278
  global.postMessage(readyMessage);
279
279
  };
280
280
  class IpcChildWithModuleWorker extends Ipc {
@@ -300,7 +300,7 @@ class IpcChildWithModuleWorker extends Ipc {
300
300
  this._rawIpc.addEventListener('message', callback);
301
301
  }
302
302
  }
303
- const wrap$d = global => {
303
+ const wrap$e = global => {
304
304
  return new IpcChildWithModuleWorker(global);
305
305
  };
306
306
  const withResolvers = () => {
@@ -325,10 +325,10 @@ const waitForFirstMessage = async port => {
325
325
  // @ts-ignore
326
326
  return event.data;
327
327
  };
328
- const listen$5 = async () => {
329
- const parentIpcRaw = listen$6();
330
- signal$6(parentIpcRaw);
331
- const parentIpc = wrap$d(parentIpcRaw);
328
+ const listen$6 = async () => {
329
+ const parentIpcRaw = listen$7();
330
+ signal$7(parentIpcRaw);
331
+ const parentIpc = wrap$e(parentIpcRaw);
332
332
  const firstMessage = await waitForFirstMessage(parentIpc);
333
333
  if (firstMessage.method !== 'initialize') {
334
334
  throw new IpcError('unexpected first message');
@@ -373,13 +373,13 @@ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
373
373
  this._rawIpc.start();
374
374
  }
375
375
  }
376
- const wrap$c = port => {
376
+ const wrap$d = port => {
377
377
  return new IpcChildWithModuleWorkerAndMessagePort(port);
378
378
  };
379
379
  const IpcChildWithModuleWorkerAndMessagePort$1 = {
380
380
  __proto__: null,
381
- listen: listen$5,
382
- wrap: wrap$c
381
+ listen: listen$6,
382
+ wrap: wrap$d
383
383
  };
384
384
 
385
385
  const Two = '2.0';
@@ -404,9 +404,6 @@ let id = 0;
404
404
  const create$3 = () => {
405
405
  return ++id;
406
406
  };
407
- const warn = (...args) => {
408
- console.warn(...args);
409
- };
410
407
  const registerPromise = () => {
411
408
  const id = create$3();
412
409
  const {
@@ -419,16 +416,6 @@ const registerPromise = () => {
419
416
  promise
420
417
  };
421
418
  };
422
- const resolve = (id, response) => {
423
- const fn = get(id);
424
- if (!fn) {
425
- console.log(response);
426
- warn(`callback ${id} may already be disposed`);
427
- return;
428
- }
429
- fn(response);
430
- remove(id);
431
- };
432
419
  const create$2$1 = (method, params) => {
433
420
  const {
434
421
  id,
@@ -576,6 +563,19 @@ const unwrapJsonRpcResult = responseMessage => {
576
563
  }
577
564
  throw new JsonRpcError('unexpected response message');
578
565
  };
566
+ const warn = (...args) => {
567
+ console.warn(...args);
568
+ };
569
+ const resolve = (id, response) => {
570
+ const fn = get(id);
571
+ if (!fn) {
572
+ console.log(response);
573
+ warn(`callback ${id} may already be disposed`);
574
+ return;
575
+ }
576
+ fn(response);
577
+ remove(id);
578
+ };
579
579
  const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
580
580
  const getErrorType = prettyError => {
581
581
  if (prettyError && prettyError.type) {
@@ -953,7 +953,9 @@ const getIframeSrcRemote = (webViews, webViewPort, webViewId, locationProtocol,
953
953
  // TODO either
954
954
  // - load webviews the same as in web using blob urls
955
955
  // - load webviews from a pattern like /webviews/:id/:fileName
956
- iframeContent = iframeContent.replaceAll('/media/', '/').replaceAll('//', '/');
956
+ if (!webView.path) {
957
+ iframeContent = iframeContent.replaceAll('/media/', '/').replaceAll('//', '/');
958
+ }
957
959
  return {
958
960
  srcDoc: '',
959
961
  iframeSrc,
@@ -989,13 +991,16 @@ const getDefaultBaseUrl = webView => {
989
991
  }
990
992
  return '';
991
993
  };
992
- const getWebViewBaseUrl = webView => {
994
+ const getWebViewBaseUrl = (webView, locationOrigin) => {
993
995
  const defaultBaseUrl = getDefaultBaseUrl(webView);
996
+ if (defaultBaseUrl.startsWith(locationOrigin)) {
997
+ return defaultBaseUrl.slice(locationOrigin.length);
998
+ }
994
999
  return defaultBaseUrl;
995
1000
  };
996
1001
 
997
1002
  const getIframeSrc$1 = (webView, locationOrigin, assetDir) => {
998
- const baseUrl = getWebViewBaseUrl(webView);
1003
+ const baseUrl = getWebViewBaseUrl(webView, locationOrigin);
999
1004
  const srcHtml = getWebViewHtml(baseUrl, locationOrigin, webView.elements, assetDir);
1000
1005
  if (srcHtml) {
1001
1006
  const blobUrl = getBlobUrl(srcHtml, 'text/html');
@@ -1210,6 +1215,7 @@ const getModule = platform => {
1210
1215
  return register$1;
1211
1216
  }
1212
1217
  };
1218
+
1213
1219
  const register = async (previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent) => {
1214
1220
  const fn = getModule(platform);
1215
1221
  return fn(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/iframe-worker",
3
- "version": "3.3.0",
3
+ "version": "3.5.0",
4
4
  "description": "Web Worker to manage creation and lifecycle of iframes in Lvce Editor",
5
5
  "main": "dist/iframeWorkerMain.js",
6
6
  "type": "module",