@lvce-editor/preview-sandbox-worker 1.5.0 → 1.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.
- package/dist/previewSandBoxWorkerMain.js +137 -137
- package/package.json +2 -2
|
@@ -506,6 +506,27 @@ const IpcParentWithMessagePort$1 = {
|
|
|
506
506
|
wrap: wrap$5
|
|
507
507
|
};
|
|
508
508
|
|
|
509
|
+
class CommandNotFoundError extends Error {
|
|
510
|
+
constructor(command) {
|
|
511
|
+
super(`Command not found ${command}`);
|
|
512
|
+
this.name = 'CommandNotFoundError';
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
const commands = Object.create(null);
|
|
516
|
+
const register = commandMap => {
|
|
517
|
+
Object.assign(commands, commandMap);
|
|
518
|
+
};
|
|
519
|
+
const getCommand = key => {
|
|
520
|
+
return commands[key];
|
|
521
|
+
};
|
|
522
|
+
const execute = (command, ...args) => {
|
|
523
|
+
const fn = getCommand(command);
|
|
524
|
+
if (!fn) {
|
|
525
|
+
throw new CommandNotFoundError(command);
|
|
526
|
+
}
|
|
527
|
+
return fn(...args);
|
|
528
|
+
};
|
|
529
|
+
|
|
509
530
|
const Two$1 = '2.0';
|
|
510
531
|
const callbacks$1 = Object.create(null);
|
|
511
532
|
const get$2 = id => {
|
|
@@ -530,12 +551,12 @@ const getErrorConstructor = (message, type) => {
|
|
|
530
551
|
switch (type) {
|
|
531
552
|
case DomException:
|
|
532
553
|
return DOMException;
|
|
533
|
-
case TypeError$1:
|
|
534
|
-
return TypeError;
|
|
535
|
-
case SyntaxError$1:
|
|
536
|
-
return SyntaxError;
|
|
537
554
|
case ReferenceError$1:
|
|
538
555
|
return ReferenceError;
|
|
556
|
+
case SyntaxError$1:
|
|
557
|
+
return SyntaxError;
|
|
558
|
+
case TypeError$1:
|
|
559
|
+
return TypeError;
|
|
539
560
|
default:
|
|
540
561
|
return Error;
|
|
541
562
|
}
|
|
@@ -691,56 +712,56 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
691
712
|
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
692
713
|
return {
|
|
693
714
|
code: MethodNotFound,
|
|
694
|
-
|
|
695
|
-
|
|
715
|
+
data: error.stack,
|
|
716
|
+
message: error.message
|
|
696
717
|
};
|
|
697
718
|
}
|
|
698
719
|
return {
|
|
699
720
|
code: Custom,
|
|
700
|
-
message: prettyError.message,
|
|
701
721
|
data: {
|
|
702
|
-
stack: getStack(prettyError),
|
|
703
|
-
codeFrame: prettyError.codeFrame,
|
|
704
|
-
type: getErrorType(prettyError),
|
|
705
722
|
code: prettyError.code,
|
|
706
|
-
|
|
707
|
-
|
|
723
|
+
codeFrame: prettyError.codeFrame,
|
|
724
|
+
name: prettyError.name,
|
|
725
|
+
stack: getStack(prettyError),
|
|
726
|
+
type: getErrorType(prettyError)
|
|
727
|
+
},
|
|
728
|
+
message: prettyError.message
|
|
708
729
|
};
|
|
709
730
|
};
|
|
710
|
-
const create$1 = (id, error) => {
|
|
731
|
+
const create$1$1 = (id, error) => {
|
|
711
732
|
return {
|
|
712
|
-
|
|
733
|
+
error,
|
|
713
734
|
id,
|
|
714
|
-
|
|
735
|
+
jsonrpc: Two$1
|
|
715
736
|
};
|
|
716
737
|
};
|
|
717
738
|
const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
718
739
|
const prettyError = preparePrettyError(error);
|
|
719
740
|
logError(error, prettyError);
|
|
720
741
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
721
|
-
return create$1(id, errorProperty);
|
|
742
|
+
return create$1$1(id, errorProperty);
|
|
722
743
|
};
|
|
723
|
-
const create$
|
|
744
|
+
const create$6 = (message, result) => {
|
|
724
745
|
return {
|
|
725
|
-
jsonrpc: Two$1,
|
|
726
746
|
id: message.id,
|
|
747
|
+
jsonrpc: Two$1,
|
|
727
748
|
result: result ?? null
|
|
728
749
|
};
|
|
729
750
|
};
|
|
730
751
|
const getSuccessResponse = (message, result) => {
|
|
731
752
|
const resultProperty = result ?? null;
|
|
732
|
-
return create$
|
|
753
|
+
return create$6(message, resultProperty);
|
|
733
754
|
};
|
|
734
755
|
const getErrorResponseSimple = (id, error) => {
|
|
735
756
|
return {
|
|
736
|
-
jsonrpc: Two$1,
|
|
737
|
-
id,
|
|
738
757
|
error: {
|
|
739
758
|
code: Custom,
|
|
759
|
+
data: error,
|
|
740
760
|
// @ts-ignore
|
|
741
|
-
message: error.message
|
|
742
|
-
|
|
743
|
-
|
|
761
|
+
message: error.message
|
|
762
|
+
},
|
|
763
|
+
id,
|
|
764
|
+
jsonrpc: Two$1
|
|
744
765
|
};
|
|
745
766
|
};
|
|
746
767
|
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
@@ -770,35 +791,35 @@ const normalizeParams = args => {
|
|
|
770
791
|
if (args.length === 1) {
|
|
771
792
|
const options = args[0];
|
|
772
793
|
return {
|
|
794
|
+
execute: options.execute,
|
|
773
795
|
ipc: options.ipc,
|
|
796
|
+
logError: options.logError || defaultLogError,
|
|
774
797
|
message: options.message,
|
|
775
|
-
execute: options.execute,
|
|
776
|
-
resolve: options.resolve || defaultResolve,
|
|
777
798
|
preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
|
|
778
|
-
|
|
779
|
-
|
|
799
|
+
requiresSocket: options.requiresSocket || defaultRequiresSocket,
|
|
800
|
+
resolve: options.resolve || defaultResolve
|
|
780
801
|
};
|
|
781
802
|
}
|
|
782
803
|
return {
|
|
804
|
+
execute: args[2],
|
|
783
805
|
ipc: args[0],
|
|
806
|
+
logError: args[5],
|
|
784
807
|
message: args[1],
|
|
785
|
-
execute: args[2],
|
|
786
|
-
resolve: args[3],
|
|
787
808
|
preparePrettyError: args[4],
|
|
788
|
-
|
|
789
|
-
|
|
809
|
+
requiresSocket: args[6],
|
|
810
|
+
resolve: args[3]
|
|
790
811
|
};
|
|
791
812
|
};
|
|
792
813
|
const handleJsonRpcMessage = async (...args) => {
|
|
793
814
|
const options = normalizeParams(args);
|
|
794
815
|
const {
|
|
795
|
-
message,
|
|
796
|
-
ipc,
|
|
797
816
|
execute,
|
|
798
|
-
|
|
799
|
-
preparePrettyError,
|
|
817
|
+
ipc,
|
|
800
818
|
logError,
|
|
801
|
-
|
|
819
|
+
message,
|
|
820
|
+
preparePrettyError,
|
|
821
|
+
requiresSocket,
|
|
822
|
+
resolve
|
|
802
823
|
} = options;
|
|
803
824
|
if ('id' in message) {
|
|
804
825
|
if ('method' in message) {
|
|
@@ -821,36 +842,17 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
821
842
|
throw new JsonRpcError('unexpected message');
|
|
822
843
|
};
|
|
823
844
|
|
|
824
|
-
class CommandNotFoundError extends Error {
|
|
825
|
-
constructor(command) {
|
|
826
|
-
super(`Command not found ${command}`);
|
|
827
|
-
this.name = 'CommandNotFoundError';
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
const commands = Object.create(null);
|
|
831
|
-
const register = commandMap => {
|
|
832
|
-
Object.assign(commands, commandMap);
|
|
833
|
-
};
|
|
834
|
-
const getCommand = key => {
|
|
835
|
-
return commands[key];
|
|
836
|
-
};
|
|
837
|
-
const execute = (command, ...args) => {
|
|
838
|
-
const fn = getCommand(command);
|
|
839
|
-
if (!fn) {
|
|
840
|
-
throw new CommandNotFoundError(command);
|
|
841
|
-
}
|
|
842
|
-
return fn(...args);
|
|
843
|
-
};
|
|
844
|
-
|
|
845
845
|
const Two = '2.0';
|
|
846
|
-
|
|
846
|
+
|
|
847
|
+
const create$5 = (method, params) => {
|
|
847
848
|
return {
|
|
848
849
|
jsonrpc: Two,
|
|
849
850
|
method,
|
|
850
851
|
params
|
|
851
852
|
};
|
|
852
853
|
};
|
|
853
|
-
|
|
854
|
+
|
|
855
|
+
const create$4 = (id, method, params) => {
|
|
854
856
|
const message = {
|
|
855
857
|
id,
|
|
856
858
|
jsonrpc: Two,
|
|
@@ -859,15 +861,14 @@ const create$s = (id, method, params) => {
|
|
|
859
861
|
};
|
|
860
862
|
return message;
|
|
861
863
|
};
|
|
864
|
+
|
|
862
865
|
let id$1 = 0;
|
|
863
|
-
const create$
|
|
866
|
+
const create$3 = () => {
|
|
864
867
|
return ++id$1;
|
|
865
868
|
};
|
|
866
869
|
|
|
867
|
-
/* eslint-disable n/no-unsupported-features/es-syntax */
|
|
868
|
-
|
|
869
870
|
const registerPromise = map => {
|
|
870
|
-
const id = create$
|
|
871
|
+
const id = create$3();
|
|
871
872
|
const {
|
|
872
873
|
promise,
|
|
873
874
|
resolve
|
|
@@ -879,13 +880,12 @@ const registerPromise = map => {
|
|
|
879
880
|
};
|
|
880
881
|
};
|
|
881
882
|
|
|
882
|
-
// @ts-ignore
|
|
883
883
|
const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
|
|
884
884
|
const {
|
|
885
885
|
id,
|
|
886
886
|
promise
|
|
887
887
|
} = registerPromise(callbacks);
|
|
888
|
-
const message = create$
|
|
888
|
+
const message = create$4(id, method, params);
|
|
889
889
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
890
890
|
ipc.sendAndTransfer(message);
|
|
891
891
|
} else {
|
|
@@ -921,12 +921,13 @@ const createRpc = ipc => {
|
|
|
921
921
|
* @deprecated
|
|
922
922
|
*/
|
|
923
923
|
send(method, ...params) {
|
|
924
|
-
const message = create$
|
|
924
|
+
const message = create$5(method, params);
|
|
925
925
|
ipc.send(message);
|
|
926
926
|
}
|
|
927
927
|
};
|
|
928
928
|
return rpc;
|
|
929
929
|
};
|
|
930
|
+
|
|
930
931
|
const requiresSocket = () => {
|
|
931
932
|
return false;
|
|
932
933
|
};
|
|
@@ -941,6 +942,7 @@ const handleMessage = event => {
|
|
|
941
942
|
const actualExecute = event?.target?.execute || execute;
|
|
942
943
|
return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
943
944
|
};
|
|
945
|
+
|
|
944
946
|
const handleIpc = ipc => {
|
|
945
947
|
if ('addEventListener' in ipc) {
|
|
946
948
|
ipc.addEventListener('message', handleMessage);
|
|
@@ -949,6 +951,7 @@ const handleIpc = ipc => {
|
|
|
949
951
|
ipc.on('message', handleMessage);
|
|
950
952
|
}
|
|
951
953
|
};
|
|
954
|
+
|
|
952
955
|
const listen$1 = async (module, options) => {
|
|
953
956
|
const rawIpc = await module.listen(options);
|
|
954
957
|
if (module.signal) {
|
|
@@ -957,7 +960,8 @@ const listen$1 = async (module, options) => {
|
|
|
957
960
|
const ipc = module.wrap(rawIpc);
|
|
958
961
|
return ipc;
|
|
959
962
|
};
|
|
960
|
-
|
|
963
|
+
|
|
964
|
+
const create$2 = async ({
|
|
961
965
|
commandMap,
|
|
962
966
|
isMessagePortOpen = true,
|
|
963
967
|
messagePort
|
|
@@ -974,11 +978,8 @@ const create$5 = async ({
|
|
|
974
978
|
messagePort.start();
|
|
975
979
|
return rpc;
|
|
976
980
|
};
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
create: create$5
|
|
980
|
-
};
|
|
981
|
-
const create$2 = async ({
|
|
981
|
+
|
|
982
|
+
const create$1 = async ({
|
|
982
983
|
commandMap
|
|
983
984
|
}) => {
|
|
984
985
|
// TODO create a commandMap per rpc instance
|
|
@@ -988,10 +989,9 @@ const create$2 = async ({
|
|
|
988
989
|
const rpc = createRpc(ipc);
|
|
989
990
|
return rpc;
|
|
990
991
|
};
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
};
|
|
992
|
+
|
|
993
|
+
const RendererWorker = 1;
|
|
994
|
+
|
|
995
995
|
const createMockRpc = ({
|
|
996
996
|
commandMap
|
|
997
997
|
}) => {
|
|
@@ -1012,63 +1012,6 @@ const createMockRpc = ({
|
|
|
1012
1012
|
return mockRpc;
|
|
1013
1013
|
};
|
|
1014
1014
|
|
|
1015
|
-
const Button$1 = 1;
|
|
1016
|
-
const Div$1 = 4;
|
|
1017
|
-
const H1$1 = 5;
|
|
1018
|
-
const Input$1 = 6;
|
|
1019
|
-
const Span$1 = 8;
|
|
1020
|
-
const Table$1 = 9;
|
|
1021
|
-
const TBody$1 = 10;
|
|
1022
|
-
const Td$1 = 11;
|
|
1023
|
-
const Text = 12;
|
|
1024
|
-
const Th$1 = 13;
|
|
1025
|
-
const THead$1 = 14;
|
|
1026
|
-
const Tr$1 = 15;
|
|
1027
|
-
const Img$1 = 17;
|
|
1028
|
-
const Del$1 = 21;
|
|
1029
|
-
const H2$1 = 22;
|
|
1030
|
-
const H3$1 = 23;
|
|
1031
|
-
const H4$1 = 24;
|
|
1032
|
-
const H5$1 = 25;
|
|
1033
|
-
const H6$1 = 26;
|
|
1034
|
-
const Article$1 = 27;
|
|
1035
|
-
const Aside$1 = 28;
|
|
1036
|
-
const Footer$1 = 29;
|
|
1037
|
-
const Header$1 = 30;
|
|
1038
|
-
const Nav$1 = 40;
|
|
1039
|
-
const Section$1 = 41;
|
|
1040
|
-
const Search$1 = 42;
|
|
1041
|
-
const Dd$1 = 43;
|
|
1042
|
-
const Dl$1 = 44;
|
|
1043
|
-
const Figcaption$1 = 45;
|
|
1044
|
-
const Figure$1 = 46;
|
|
1045
|
-
const Hr$1 = 47;
|
|
1046
|
-
const Li$1 = 48;
|
|
1047
|
-
const Ol$1 = 49;
|
|
1048
|
-
const P$1 = 50;
|
|
1049
|
-
const Pre$1 = 51;
|
|
1050
|
-
const A$1 = 53;
|
|
1051
|
-
const Abbr$1 = 54;
|
|
1052
|
-
const Br$1 = 55;
|
|
1053
|
-
const Cite$1 = 56;
|
|
1054
|
-
const Data$1 = 57;
|
|
1055
|
-
const Time$1 = 58;
|
|
1056
|
-
const Tfoot$1 = 59;
|
|
1057
|
-
const Ul$1 = 60;
|
|
1058
|
-
const TextArea$1 = 62;
|
|
1059
|
-
const Select$1 = 63;
|
|
1060
|
-
const Option$1 = 64;
|
|
1061
|
-
const Code$1 = 65;
|
|
1062
|
-
const Label$1 = 66;
|
|
1063
|
-
const Dt$1 = 67;
|
|
1064
|
-
const Iframe$1 = 68;
|
|
1065
|
-
const Style = 72;
|
|
1066
|
-
const Html = 73;
|
|
1067
|
-
const Canvas$1 = 77;
|
|
1068
|
-
const Reference = 100;
|
|
1069
|
-
|
|
1070
|
-
const RendererWorker = 1;
|
|
1071
|
-
|
|
1072
1015
|
const rpcs = Object.create(null);
|
|
1073
1016
|
const set$4 = (id, rpc) => {
|
|
1074
1017
|
rpcs[id] = rpc;
|
|
@@ -1180,6 +1123,62 @@ const set$1 = (uid, instance) => {
|
|
|
1180
1123
|
states$1.set(uid, instance);
|
|
1181
1124
|
};
|
|
1182
1125
|
|
|
1126
|
+
const Button$1 = 1;
|
|
1127
|
+
const Div$1 = 4;
|
|
1128
|
+
const H1$1 = 5;
|
|
1129
|
+
const Input$1 = 6;
|
|
1130
|
+
const Span$1 = 8;
|
|
1131
|
+
const Table$1 = 9;
|
|
1132
|
+
const TBody$1 = 10;
|
|
1133
|
+
const Td$1 = 11;
|
|
1134
|
+
const Th$1 = 13;
|
|
1135
|
+
const THead$1 = 14;
|
|
1136
|
+
const Tr$1 = 15;
|
|
1137
|
+
const Img$1 = 17;
|
|
1138
|
+
const Del$1 = 21;
|
|
1139
|
+
const H2$1 = 22;
|
|
1140
|
+
const H3$1 = 23;
|
|
1141
|
+
const H4$1 = 24;
|
|
1142
|
+
const H5$1 = 25;
|
|
1143
|
+
const H6$1 = 26;
|
|
1144
|
+
const Article$1 = 27;
|
|
1145
|
+
const Aside$1 = 28;
|
|
1146
|
+
const Footer$1 = 29;
|
|
1147
|
+
const Header$1 = 30;
|
|
1148
|
+
const Nav$1 = 40;
|
|
1149
|
+
const Section$1 = 41;
|
|
1150
|
+
const Search$1 = 42;
|
|
1151
|
+
const Dd$1 = 43;
|
|
1152
|
+
const Dl$1 = 44;
|
|
1153
|
+
const Figcaption$1 = 45;
|
|
1154
|
+
const Figure$1 = 46;
|
|
1155
|
+
const Hr$1 = 47;
|
|
1156
|
+
const Li$1 = 48;
|
|
1157
|
+
const Ol$1 = 49;
|
|
1158
|
+
const P$1 = 50;
|
|
1159
|
+
const Pre$1 = 51;
|
|
1160
|
+
const A$1 = 53;
|
|
1161
|
+
const Abbr$1 = 54;
|
|
1162
|
+
const Br$1 = 55;
|
|
1163
|
+
const Cite$1 = 56;
|
|
1164
|
+
const Data$1 = 57;
|
|
1165
|
+
const Time$1 = 58;
|
|
1166
|
+
const Tfoot$1 = 59;
|
|
1167
|
+
const Ul$1 = 60;
|
|
1168
|
+
const TextArea$1 = 62;
|
|
1169
|
+
const Select$1 = 63;
|
|
1170
|
+
const Option$1 = 64;
|
|
1171
|
+
const Code$1 = 65;
|
|
1172
|
+
const Label$1 = 66;
|
|
1173
|
+
const Dt$1 = 67;
|
|
1174
|
+
const Iframe$1 = 68;
|
|
1175
|
+
const Style = 72;
|
|
1176
|
+
const Html = 73;
|
|
1177
|
+
const Canvas$1 = 77;
|
|
1178
|
+
const Reference = 100;
|
|
1179
|
+
|
|
1180
|
+
const Text = 12;
|
|
1181
|
+
|
|
1183
1182
|
const text = data => {
|
|
1184
1183
|
return {
|
|
1185
1184
|
childCount: 0,
|
|
@@ -1696,7 +1695,7 @@ const handleKeyup = (uid, hdId, key, code) => {
|
|
|
1696
1695
|
};
|
|
1697
1696
|
|
|
1698
1697
|
const handleMessagePort = async port => {
|
|
1699
|
-
const rpc = await
|
|
1698
|
+
const rpc = await create$2({
|
|
1700
1699
|
commandMap: {},
|
|
1701
1700
|
messagePort: port
|
|
1702
1701
|
});
|
|
@@ -89414,7 +89413,8 @@ const getErrorCodeFrame = (scriptContent, error, contextLines = 2) => {
|
|
|
89414
89413
|
const lines = scriptContent.split('\n');
|
|
89415
89414
|
|
|
89416
89415
|
// Line numbers in stack traces are 1-based
|
|
89417
|
-
|
|
89416
|
+
// Offset by -4 to account for the anonymous function wrapper
|
|
89417
|
+
const errorLineIndex = line - 1 - 2;
|
|
89418
89418
|
if (errorLineIndex < 0 || errorLineIndex >= lines.length) {
|
|
89419
89419
|
return '';
|
|
89420
89420
|
}
|
|
@@ -89878,7 +89878,7 @@ const commandMap = {
|
|
|
89878
89878
|
};
|
|
89879
89879
|
|
|
89880
89880
|
const listen = async () => {
|
|
89881
|
-
const rpc = await
|
|
89881
|
+
const rpc = await create$1({
|
|
89882
89882
|
commandMap: commandMap
|
|
89883
89883
|
});
|
|
89884
89884
|
set$2(rpc);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/preview-sandbox-worker",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "Preview SandBox Worker",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"type": "module",
|
|
12
12
|
"main": "dist/previewSandBoxWorkerMain.js",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@lvce-editor/virtual-dom-worker": "^8.
|
|
14
|
+
"@lvce-editor/virtual-dom-worker": "^8.9.0",
|
|
15
15
|
"happy-dom-without-node": "^14.12.3"
|
|
16
16
|
}
|
|
17
17
|
}
|