@lvce-editor/preview-sandbox-worker 4.5.0 → 4.7.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.
@@ -580,7 +580,10 @@ const constructError = (message, type, name) => {
580
580
  if (ErrorConstructor === Error) {
581
581
  const error = new Error(message);
582
582
  if (name && name !== 'VError') {
583
- error.name = name;
583
+ Object.defineProperty(error, 'name', {
584
+ configurable: true,
585
+ value: name
586
+ });
584
587
  }
585
588
  return error;
586
589
  }
@@ -597,8 +600,10 @@ const getCurrentStack = () => {
597
600
  const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
598
601
  return currentStack;
599
602
  };
600
- const getNewLineIndex = (string, startIndex = undefined) => {
601
- return string.indexOf(NewLine, startIndex);
603
+ const getNewLineIndex = (string, startIndex) => {
604
+ {
605
+ return string.indexOf(NewLine);
606
+ }
602
607
  };
603
608
  const getParentStack = error => {
604
609
  let parentStack = error.stack || error.data || error.message || '';
@@ -609,55 +614,91 @@ const getParentStack = error => {
609
614
  };
610
615
  const MethodNotFound = -32601;
611
616
  const Custom = -32001;
617
+ const setStack = (error, stack) => {
618
+ const descriptor = Object.getOwnPropertyDescriptor(error, 'stack');
619
+ if (descriptor) {
620
+ if (!descriptor.configurable && !descriptor.writable) {
621
+ return;
622
+ }
623
+ if (!descriptor.configurable && descriptor.writable) {
624
+ error.stack = stack;
625
+ return;
626
+ }
627
+ }
628
+ Object.defineProperty(error, 'stack', {
629
+ configurable: true,
630
+ value: stack,
631
+ writable: true
632
+ });
633
+ };
634
+ const restoreExistingError = (error, currentStack) => {
635
+ if (typeof error.stack === 'string') {
636
+ setStack(error, `${error.stack}${NewLine}${currentStack}`);
637
+ }
638
+ return error;
639
+ };
640
+ const restoreMethodNotFoundError = (error, currentStack) => {
641
+ const restoredError = new JsonRpcError(error.message);
642
+ const parentStack = getParentStack(error);
643
+ setStack(restoredError, `${parentStack}${NewLine}${currentStack}`);
644
+ return restoredError;
645
+ };
646
+ const restoreStackFromData = (restoredError, error, currentStack) => {
647
+ if (error.data.stack && error.data.type && error.message) {
648
+ setStack(restoredError, `${error.data.type}: ${error.message}${NewLine}${error.data.stack}${NewLine}${currentStack}`);
649
+ return;
650
+ }
651
+ if (error.data.stack) {
652
+ setStack(restoredError, error.data.stack);
653
+ }
654
+ };
655
+ const applyDataProperties = (restoredError, error) => {
656
+ restoreStackFromData(restoredError, error, getCurrentStack());
657
+ if (error.data.codeFrame) {
658
+ // @ts-ignore
659
+ restoredError.codeFrame = error.data.codeFrame;
660
+ }
661
+ if (error.data.code) {
662
+ // @ts-ignore
663
+ restoredError.code = error.data.code;
664
+ }
665
+ if (error.data.type) {
666
+ // @ts-ignore
667
+ restoredError.name = error.data.type;
668
+ }
669
+ };
670
+ const applyDirectProperties = (restoredError, error) => {
671
+ if (error.stack) {
672
+ const lowerStack = restoredError.stack || '';
673
+ const indexNewLine = getNewLineIndex(lowerStack);
674
+ const parentStack = getParentStack(error);
675
+ // @ts-ignore
676
+ setStack(restoredError, `${parentStack}${lowerStack.slice(indexNewLine)}`);
677
+ }
678
+ if (error.codeFrame) {
679
+ // @ts-ignore
680
+ restoredError.codeFrame = error.codeFrame;
681
+ }
682
+ };
683
+ const restoreMessageError = (error, _currentStack) => {
684
+ const restoredError = constructError(error.message, error.type, error.name);
685
+ if (error.data) {
686
+ applyDataProperties(restoredError, error);
687
+ } else {
688
+ applyDirectProperties(restoredError, error);
689
+ }
690
+ return restoredError;
691
+ };
612
692
  const restoreJsonRpcError = error => {
613
693
  const currentStack = getCurrentStack();
614
694
  if (error && error instanceof Error) {
615
- if (typeof error.stack === 'string') {
616
- error.stack = error.stack + NewLine + currentStack;
617
- }
618
- return error;
695
+ return restoreExistingError(error, currentStack);
619
696
  }
620
697
  if (error && error.code && error.code === MethodNotFound) {
621
- const restoredError = new JsonRpcError(error.message);
622
- const parentStack = getParentStack(error);
623
- restoredError.stack = parentStack + NewLine + currentStack;
624
- return restoredError;
698
+ return restoreMethodNotFoundError(error, currentStack);
625
699
  }
626
700
  if (error && error.message) {
627
- const restoredError = constructError(error.message, error.type, error.name);
628
- if (error.data) {
629
- if (error.data.stack && error.data.type && error.message) {
630
- restoredError.stack = error.data.type + ': ' + error.message + NewLine + error.data.stack + NewLine + currentStack;
631
- } else if (error.data.stack) {
632
- restoredError.stack = error.data.stack;
633
- }
634
- if (error.data.codeFrame) {
635
- // @ts-ignore
636
- restoredError.codeFrame = error.data.codeFrame;
637
- }
638
- if (error.data.code) {
639
- // @ts-ignore
640
- restoredError.code = error.data.code;
641
- }
642
- if (error.data.type) {
643
- // @ts-ignore
644
- restoredError.name = error.data.type;
645
- }
646
- } else {
647
- if (error.stack) {
648
- const lowerStack = restoredError.stack || '';
649
- // @ts-ignore
650
- const indexNewLine = getNewLineIndex(lowerStack);
651
- const parentStack = getParentStack(error);
652
- // @ts-ignore
653
- restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
654
- }
655
- if (error.codeFrame) {
656
- // @ts-ignore
657
- restoredError.codeFrame = error.codeFrame;
658
- }
659
- }
660
- return restoredError;
701
+ return restoreMessageError(error);
661
702
  }
662
703
  if (typeof error === 'string') {
663
704
  return new Error(`JsonRpc Error: ${error}`);
@@ -741,7 +782,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
741
782
  const errorProperty = getErrorProperty(error, prettyError);
742
783
  return create$1$1(id, errorProperty);
743
784
  };
744
- const create$6 = (message, result) => {
785
+ const create$8 = (message, result) => {
745
786
  return {
746
787
  id: message.id,
747
788
  jsonrpc: Two$1,
@@ -750,7 +791,7 @@ const create$6 = (message, result) => {
750
791
  };
751
792
  const getSuccessResponse = (message, result) => {
752
793
  const resultProperty = result ?? null;
753
- return create$6(message, resultProperty);
794
+ return create$8(message, resultProperty);
754
795
  };
755
796
  const getErrorResponseSimple = (id, error) => {
756
797
  return {
@@ -844,7 +885,7 @@ const handleJsonRpcMessage = async (...args) => {
844
885
 
845
886
  const Two = '2.0';
846
887
 
847
- const create$5 = (method, params) => {
888
+ const create$7 = (method, params) => {
848
889
  return {
849
890
  jsonrpc: Two,
850
891
  method,
@@ -852,7 +893,7 @@ const create$5 = (method, params) => {
852
893
  };
853
894
  };
854
895
 
855
- const create$4 = (id, method, params) => {
896
+ const create$6 = (id, method, params) => {
856
897
  const message = {
857
898
  id,
858
899
  jsonrpc: Two,
@@ -863,12 +904,12 @@ const create$4 = (id, method, params) => {
863
904
  };
864
905
 
865
906
  let id$1 = 0;
866
- const create$3 = () => {
907
+ const create$5 = () => {
867
908
  return ++id$1;
868
909
  };
869
910
 
870
911
  const registerPromise = map => {
871
- const id = create$3();
912
+ const id = create$5();
872
913
  const {
873
914
  promise,
874
915
  resolve
@@ -885,7 +926,7 @@ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer)
885
926
  id,
886
927
  promise
887
928
  } = registerPromise(callbacks);
888
- const message = create$4(id, method, params);
929
+ const message = create$6(id, method, params);
889
930
  if (useSendAndTransfer && ipc.sendAndTransfer) {
890
931
  ipc.sendAndTransfer(message);
891
932
  } else {
@@ -921,7 +962,7 @@ const createRpc = ipc => {
921
962
  * @deprecated
922
963
  */
923
964
  send(method, ...params) {
924
- const message = create$5(method, params);
965
+ const message = create$7(method, params);
925
966
  ipc.send(message);
926
967
  }
927
968
  };
@@ -961,7 +1002,7 @@ const listen$1 = async (module, options) => {
961
1002
  return ipc;
962
1003
  };
963
1004
 
964
- const create$2 = async ({
1005
+ const create$4 = async ({
965
1006
  commandMap,
966
1007
  isMessagePortOpen = true,
967
1008
  messagePort
@@ -979,6 +1020,65 @@ const create$2 = async ({
979
1020
  return rpc;
980
1021
  };
981
1022
 
1023
+ const create$3 = async ({
1024
+ commandMap,
1025
+ isMessagePortOpen,
1026
+ send
1027
+ }) => {
1028
+ const {
1029
+ port1,
1030
+ port2
1031
+ } = new MessageChannel();
1032
+ await send(port1);
1033
+ return create$4({
1034
+ commandMap,
1035
+ isMessagePortOpen,
1036
+ messagePort: port2
1037
+ });
1038
+ };
1039
+
1040
+ const createSharedLazyRpc = factory => {
1041
+ let rpcPromise;
1042
+ const getOrCreate = () => {
1043
+ if (!rpcPromise) {
1044
+ rpcPromise = factory();
1045
+ }
1046
+ return rpcPromise;
1047
+ };
1048
+ return {
1049
+ async dispose() {
1050
+ const rpc = await getOrCreate();
1051
+ await rpc.dispose();
1052
+ },
1053
+ async invoke(method, ...params) {
1054
+ const rpc = await getOrCreate();
1055
+ return rpc.invoke(method, ...params);
1056
+ },
1057
+ async invokeAndTransfer(method, ...params) {
1058
+ const rpc = await getOrCreate();
1059
+ return rpc.invokeAndTransfer(method, ...params);
1060
+ },
1061
+ async send(method, ...params) {
1062
+ const rpc = await getOrCreate();
1063
+ rpc.send(method, ...params);
1064
+ }
1065
+ };
1066
+ };
1067
+
1068
+ const create$2 = async ({
1069
+ commandMap,
1070
+ isMessagePortOpen,
1071
+ send
1072
+ }) => {
1073
+ return createSharedLazyRpc(() => {
1074
+ return create$3({
1075
+ commandMap,
1076
+ isMessagePortOpen,
1077
+ send
1078
+ });
1079
+ });
1080
+ };
1081
+
982
1082
  const create$1 = async ({
983
1083
  commandMap
984
1084
  }) => {
@@ -1011,7 +1111,7 @@ const createMockRpc = ({
1011
1111
  };
1012
1112
 
1013
1113
  const rpcs = Object.create(null);
1014
- const set$4 = (id, rpc) => {
1114
+ const set$5 = (id, rpc) => {
1015
1115
  rpcs[id] = rpc;
1016
1116
  };
1017
1117
  const get$1 = id => {
@@ -1044,7 +1144,7 @@ const create = rpcId => {
1044
1144
  const mockRpc = createMockRpc({
1045
1145
  commandMap
1046
1146
  });
1047
- set$4(rpcId, mockRpc);
1147
+ set$5(rpcId, mockRpc);
1048
1148
  // @ts-ignore
1049
1149
  mockRpc[Symbol.dispose] = () => {
1050
1150
  remove(rpcId);
@@ -1053,77 +1153,32 @@ const create = rpcId => {
1053
1153
  return mockRpc;
1054
1154
  },
1055
1155
  set(rpc) {
1056
- set$4(rpcId, rpc);
1156
+ set$5(rpcId, rpc);
1057
1157
  }
1058
1158
  };
1059
1159
  };
1060
1160
 
1061
- const Button$1 = 1;
1062
- const Div$1 = 4;
1063
- const H1$1 = 5;
1064
- const Input$1 = 6;
1065
- const Span$1 = 8;
1066
- const Table$1 = 9;
1067
- const TBody$1 = 10;
1068
- const Td$1 = 11;
1069
- const Text = 12;
1070
- const Th$1 = 13;
1071
- const THead$1 = 14;
1072
- const Tr$1 = 15;
1073
- const Img$1 = 17;
1074
- const Del$1 = 21;
1075
- const H2$1 = 22;
1076
- const H3$1 = 23;
1077
- const H4$1 = 24;
1078
- const H5$1 = 25;
1079
- const H6$1 = 26;
1080
- const Article$1 = 27;
1081
- const Aside$1 = 28;
1082
- const Footer$1 = 29;
1083
- const Header$1 = 30;
1084
- const Nav$1 = 40;
1085
- const Section$1 = 41;
1086
- const Search$1 = 42;
1087
- const Dd$1 = 43;
1088
- const Dl$1 = 44;
1089
- const Figcaption$1 = 45;
1090
- const Figure$1 = 46;
1091
- const Hr$1 = 47;
1092
- const Li$1 = 48;
1093
- const Ol$1 = 49;
1094
- const P$1 = 50;
1095
- const Pre$1 = 51;
1096
- const A$1 = 53;
1097
- const Abbr$1 = 54;
1098
- const Br$1 = 55;
1099
- const Cite$1 = 56;
1100
- const Data$1 = 57;
1101
- const Time$1 = 58;
1102
- const Tfoot$1 = 59;
1103
- const Ul$1 = 60;
1104
- const TextArea$1 = 62;
1105
- const Select$1 = 63;
1106
- const Option$1 = 64;
1107
- const Code$1 = 65;
1108
- const Label$1 = 66;
1109
- const Dt$1 = 67;
1110
- const Iframe$1 = 68;
1111
- const Style = 72;
1112
- const Html = 73;
1113
- const Canvas$1 = 77;
1114
- const Reference = 100;
1115
-
1161
+ const DialogWorker = 7014;
1116
1162
  const RendererWorker = 1;
1117
1163
 
1118
1164
  const {
1119
1165
  invoke: invoke$1,
1166
+ set: set$4
1167
+ } = create(DialogWorker);
1168
+
1169
+ const {
1170
+ invoke,
1120
1171
  set: set$3
1121
1172
  } = create(3211);
1122
1173
 
1123
1174
  const {
1124
- invoke,
1175
+ invokeAndTransfer,
1125
1176
  set: set$2
1126
1177
  } = create(RendererWorker);
1178
+ const sendMessagePortToDialogWorker = async port => {
1179
+ const command = 'HandleMessagePort.handleMessagePort';
1180
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToDialogWorker', port, command);
1181
+ };
1127
1182
 
1128
1183
  const terminate = () => {
1129
1184
  globalThis.close();
@@ -1214,7 +1269,7 @@ const getOffscreenCanvas = async (uid, width, height) => {
1214
1269
  id,
1215
1270
  promise
1216
1271
  } = registerCallback();
1217
- await invoke$1('Preview.createOffscreenCanvas', uid, id, width, height);
1272
+ await invoke('Preview.createOffscreenCanvas', uid, id, width, height);
1218
1273
  const [offscreenCanvas, canvasId] = await promise;
1219
1274
  return {
1220
1275
  canvasId,
@@ -1232,6 +1287,61 @@ const set$1 = (uid, instance) => {
1232
1287
  states$1.set(uid, instance);
1233
1288
  };
1234
1289
 
1290
+ const Button$1 = 1;
1291
+ const Div$1 = 4;
1292
+ const H1$1 = 5;
1293
+ const Input$1 = 6;
1294
+ const Span$1 = 8;
1295
+ const Table$1 = 9;
1296
+ const TBody$1 = 10;
1297
+ const Td$1 = 11;
1298
+ const Text = 12;
1299
+ const Th$1 = 13;
1300
+ const THead$1 = 14;
1301
+ const Tr$1 = 15;
1302
+ const Img$1 = 17;
1303
+ const Del$1 = 21;
1304
+ const H2$1 = 22;
1305
+ const H3$1 = 23;
1306
+ const H4$1 = 24;
1307
+ const H5$1 = 25;
1308
+ const H6$1 = 26;
1309
+ const Article$1 = 27;
1310
+ const Aside$1 = 28;
1311
+ const Footer$1 = 29;
1312
+ const Header$1 = 30;
1313
+ const Nav$1 = 40;
1314
+ const Section$1 = 41;
1315
+ const Search$1 = 42;
1316
+ const Dd$1 = 43;
1317
+ const Dl$1 = 44;
1318
+ const Figcaption$1 = 45;
1319
+ const Figure$1 = 46;
1320
+ const Hr$1 = 47;
1321
+ const Li$1 = 48;
1322
+ const Ol$1 = 49;
1323
+ const P$1 = 50;
1324
+ const Pre$1 = 51;
1325
+ const A$1 = 53;
1326
+ const Abbr$1 = 54;
1327
+ const Br$1 = 55;
1328
+ const Cite$1 = 56;
1329
+ const Data$1 = 57;
1330
+ const Time$1 = 58;
1331
+ const Tfoot$1 = 59;
1332
+ const Ul$1 = 60;
1333
+ const TextArea$1 = 62;
1334
+ const Select$1 = 63;
1335
+ const Option$1 = 64;
1336
+ const Code$1 = 65;
1337
+ const Label$1 = 66;
1338
+ const Dt$1 = 67;
1339
+ const Iframe$1 = 68;
1340
+ const Style = 72;
1341
+ const Html = 73;
1342
+ const Canvas$1 = 77;
1343
+ const Reference = 100;
1344
+
1235
1345
  const mergeClassNames = (...classNames) => {
1236
1346
  return classNames.filter(Boolean).join(' ');
1237
1347
  };
@@ -1895,7 +2005,7 @@ const handleKeyup = (uid, hdId, key, code) => {
1895
2005
  };
1896
2006
 
1897
2007
  const handleMessagePort = async port => {
1898
- const rpc = await create$2({
2008
+ const rpc = await create$4({
1899
2009
  commandMap: {},
1900
2010
  messagePort: port
1901
2011
  });
@@ -89876,7 +89986,7 @@ const getErrorCodeFrame = (scriptContent, error, contextLines = 2) => {
89876
89986
  };
89877
89987
 
89878
89988
  const alert = message => {
89879
- void invoke('ConfirmPrompt.prompt', message);
89989
+ void invoke$1('ConfirmPrompt.prompt', message);
89880
89990
  };
89881
89991
 
89882
89992
  const createLocalStorage = () => {
@@ -90124,7 +90234,7 @@ const handleMutations = async uid => {
90124
90234
  });
90125
90235
  getParsedNodesChildNodeCount(serialized.dom);
90126
90236
  try {
90127
- await invoke$1('Preview.handleMutation', uid);
90237
+ await invoke('Preview.handleMutation', uid);
90128
90238
  } catch (error) {
90129
90239
  console.error(error);
90130
90240
  // ignore
@@ -90471,6 +90581,11 @@ const listen = async () => {
90471
90581
  commandMap: commandMap
90472
90582
  });
90473
90583
  set$2(rpc);
90584
+ const dialogRpc = await create$2({
90585
+ commandMap: {},
90586
+ send: sendMessagePortToDialogWorker
90587
+ });
90588
+ set$4(dialogRpc);
90474
90589
  };
90475
90590
 
90476
90591
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/preview-sandbox-worker",
3
- "version": "4.5.0",
3
+ "version": "4.7.0",
4
4
  "description": "Preview SandBox Worker",
5
5
  "repository": {
6
6
  "type": "git",