@lvce-editor/iframe-worker 5.32.0 → 5.34.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.
@@ -303,22 +303,11 @@ class IpcChildWithModuleWorker extends Ipc {
303
303
  const wrap$f = global => {
304
304
  return new IpcChildWithModuleWorker(global);
305
305
  };
306
- const withResolvers = () => {
307
- let _resolve;
308
- const promise = new Promise(resolve => {
309
- _resolve = resolve;
310
- });
311
- return {
312
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
313
- resolve: _resolve,
314
- promise
315
- };
316
- };
317
306
  const waitForFirstMessage = async port => {
318
307
  const {
319
308
  resolve,
320
309
  promise
321
- } = withResolvers();
310
+ } = Promise.withResolvers();
322
311
  port.addEventListener('message', resolve, {
323
312
  once: true
324
313
  });
@@ -397,7 +386,7 @@ const getFirstEvent = (eventEmitter, eventMap) => {
397
386
  const {
398
387
  resolve,
399
388
  promise
400
- } = withResolvers();
389
+ } = Promise.withResolvers();
401
390
  const listenerMap = Object.create(null);
402
391
  const cleanup = value => {
403
392
  for (const event of Object.keys(eventMap)) {
@@ -575,6 +564,16 @@ const constructError = (message, type, name) => {
575
564
  }
576
565
  return new ErrorConstructor(message);
577
566
  };
567
+ const joinLines = lines => {
568
+ return lines.join(NewLine);
569
+ };
570
+ const splitLines = lines => {
571
+ return lines.split(NewLine);
572
+ };
573
+ const getCurrentStack = () => {
574
+ const currentStack = joinLines(splitLines(new Error().stack || '').slice(2));
575
+ return currentStack;
576
+ };
578
577
  const getNewLineIndex = (string, startIndex = undefined) => {
579
578
  return string.indexOf(NewLine, startIndex);
580
579
  };
@@ -585,19 +584,16 @@ const getParentStack = error => {
585
584
  }
586
585
  return parentStack;
587
586
  };
588
- const joinLines = lines => {
589
- return lines.join(NewLine);
590
- };
591
587
  const MethodNotFound = -32601;
592
588
  const Custom = -32001;
593
- const splitLines = lines => {
594
- return lines.split(NewLine);
595
- };
596
589
  const restoreJsonRpcError = error => {
590
+ const currentStack = getCurrentStack();
597
591
  if (error && error instanceof Error) {
592
+ if (typeof error.stack === 'string') {
593
+ error.stack = error.stack + NewLine + currentStack;
594
+ }
598
595
  return error;
599
596
  }
600
- const currentStack = joinLines(splitLines(new Error().stack || '').slice(1));
601
597
  if (error && error.code && error.code === MethodNotFound) {
602
598
  const restoredError = new JsonRpcError(error.message);
603
599
  const parentStack = getParentStack(error);
@@ -678,6 +674,17 @@ const getErrorType = prettyError => {
678
674
  }
679
675
  return undefined;
680
676
  };
677
+ const isAlreadyStack = line => {
678
+ return line.trim().startsWith('at ');
679
+ };
680
+ const getStack = prettyError => {
681
+ const stackString = prettyError.stack || '';
682
+ const newLineIndex = stackString.indexOf('\n');
683
+ if (newLineIndex !== -1 && !isAlreadyStack(stackString.slice(0, newLineIndex))) {
684
+ return stackString.slice(newLineIndex + 1);
685
+ }
686
+ return stackString;
687
+ };
681
688
  const getErrorProperty = (error, prettyError) => {
682
689
  if (error && error.code === E_COMMAND_NOT_FOUND) {
683
690
  return {
@@ -690,7 +697,7 @@ const getErrorProperty = (error, prettyError) => {
690
697
  code: Custom,
691
698
  message: prettyError.message,
692
699
  data: {
693
- stack: prettyError.stack,
700
+ stack: getStack(prettyError),
694
701
  codeFrame: prettyError.codeFrame,
695
702
  type: getErrorType(prettyError),
696
703
  code: prettyError.code,
@@ -887,7 +894,7 @@ const listen$1 = async (module, options) => {
887
894
  const ipc = module.wrap(rawIpc);
888
895
  return ipc;
889
896
  };
890
- const create$8 = async ({
897
+ const create$9 = async ({
891
898
  commandMap,
892
899
  messagePort,
893
900
  isMessagePortOpen
@@ -905,7 +912,7 @@ const create$8 = async ({
905
912
  };
906
913
  const MessagePortRpcParent = {
907
914
  __proto__: null,
908
- create: create$8
915
+ create: create$9
909
916
  };
910
917
  const create$2 = async ({
911
918
  commandMap
@@ -1854,6 +1861,10 @@ const create3 = async ({
1854
1861
  };
1855
1862
  };
1856
1863
 
1864
+ const executeCommand = (method, ...params) => {
1865
+ return invoke$4('ExecuteExternalCommand.executeExternalCommand', method, ...params);
1866
+ };
1867
+
1857
1868
  const getSecret = async key => {
1858
1869
  return invoke('WebView.getSecret', key);
1859
1870
  };
@@ -1904,7 +1915,8 @@ const commandMap = {
1904
1915
  'WebView.getSecret': getSecret,
1905
1916
  'WebView.getWebViewInfo': getWebViewInfo,
1906
1917
  'WebView.registerInterceptor': registerInterceptor,
1907
- 'WebView.unregisterInterceptor': unregisterInterceptor
1918
+ 'WebView.unregisterInterceptor': unregisterInterceptor,
1919
+ 'WebView.executeExternalCommand': executeCommand
1908
1920
  };
1909
1921
 
1910
1922
  const listen = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/iframe-worker",
3
- "version": "5.32.0",
3
+ "version": "5.34.0",
4
4
  "description": "Web Worker to manage creation and lifecycle of iframes in Lvce Editor",
5
5
  "keywords": [
6
6
  "iframe"