@lvce-editor/markdown-worker 3.1.0 → 4.0.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/markdownWorkerMain.js +97 -98
- package/package.json +1 -1
|
@@ -462,7 +462,7 @@ const getFirstEvent = (eventEmitter, eventMap) => {
|
|
|
462
462
|
return promise;
|
|
463
463
|
};
|
|
464
464
|
const Message$1 = 3;
|
|
465
|
-
const create$5
|
|
465
|
+
const create$5 = async ({
|
|
466
466
|
isMessagePortOpen,
|
|
467
467
|
messagePort
|
|
468
468
|
}) => {
|
|
@@ -513,61 +513,19 @@ const wrap$5 = messagePort => {
|
|
|
513
513
|
};
|
|
514
514
|
const IpcParentWithMessagePort$1 = {
|
|
515
515
|
__proto__: null,
|
|
516
|
-
create: create$5
|
|
516
|
+
create: create$5,
|
|
517
517
|
signal: signal$1,
|
|
518
518
|
wrap: wrap$5
|
|
519
519
|
};
|
|
520
520
|
|
|
521
|
-
const Two = '2.0';
|
|
522
|
-
const create$4 = (method, params) => {
|
|
523
|
-
return {
|
|
524
|
-
jsonrpc: Two,
|
|
525
|
-
method,
|
|
526
|
-
params
|
|
527
|
-
};
|
|
528
|
-
};
|
|
521
|
+
const Two$1 = '2.0';
|
|
529
522
|
const callbacks = Object.create(null);
|
|
530
|
-
const set$3 = (id, fn) => {
|
|
531
|
-
callbacks[id] = fn;
|
|
532
|
-
};
|
|
533
523
|
const get$1 = id => {
|
|
534
524
|
return callbacks[id];
|
|
535
525
|
};
|
|
536
526
|
const remove = id => {
|
|
537
527
|
delete callbacks[id];
|
|
538
528
|
};
|
|
539
|
-
let id = 0;
|
|
540
|
-
const create$3 = () => {
|
|
541
|
-
return ++id;
|
|
542
|
-
};
|
|
543
|
-
const registerPromise = () => {
|
|
544
|
-
const id = create$3();
|
|
545
|
-
const {
|
|
546
|
-
resolve,
|
|
547
|
-
promise
|
|
548
|
-
} = Promise.withResolvers();
|
|
549
|
-
set$3(id, resolve);
|
|
550
|
-
return {
|
|
551
|
-
id,
|
|
552
|
-
promise
|
|
553
|
-
};
|
|
554
|
-
};
|
|
555
|
-
const create$2 = (method, params) => {
|
|
556
|
-
const {
|
|
557
|
-
id,
|
|
558
|
-
promise
|
|
559
|
-
} = registerPromise();
|
|
560
|
-
const message = {
|
|
561
|
-
jsonrpc: Two,
|
|
562
|
-
method,
|
|
563
|
-
params,
|
|
564
|
-
id
|
|
565
|
-
};
|
|
566
|
-
return {
|
|
567
|
-
message,
|
|
568
|
-
promise
|
|
569
|
-
};
|
|
570
|
-
};
|
|
571
529
|
class JsonRpcError extends Error {
|
|
572
530
|
constructor(message) {
|
|
573
531
|
super(message);
|
|
@@ -761,9 +719,9 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
761
719
|
}
|
|
762
720
|
};
|
|
763
721
|
};
|
|
764
|
-
const create$1
|
|
722
|
+
const create$1 = (id, error) => {
|
|
765
723
|
return {
|
|
766
|
-
jsonrpc: Two,
|
|
724
|
+
jsonrpc: Two$1,
|
|
767
725
|
id,
|
|
768
726
|
error
|
|
769
727
|
};
|
|
@@ -772,22 +730,22 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
|
772
730
|
const prettyError = preparePrettyError(error);
|
|
773
731
|
logError(error, prettyError);
|
|
774
732
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
775
|
-
return create$1
|
|
733
|
+
return create$1(id, errorProperty);
|
|
776
734
|
};
|
|
777
|
-
const create$
|
|
735
|
+
const create$3 = (message, result) => {
|
|
778
736
|
return {
|
|
779
|
-
jsonrpc: Two,
|
|
737
|
+
jsonrpc: Two$1,
|
|
780
738
|
id: message.id,
|
|
781
739
|
result: result ?? null
|
|
782
740
|
};
|
|
783
741
|
};
|
|
784
742
|
const getSuccessResponse = (message, result) => {
|
|
785
743
|
const resultProperty = result ?? null;
|
|
786
|
-
return create$
|
|
744
|
+
return create$3(message, resultProperty);
|
|
787
745
|
};
|
|
788
746
|
const getErrorResponseSimple = (id, error) => {
|
|
789
747
|
return {
|
|
790
|
-
jsonrpc: Two,
|
|
748
|
+
jsonrpc: Two$1,
|
|
791
749
|
id,
|
|
792
750
|
error: {
|
|
793
751
|
code: Custom,
|
|
@@ -874,29 +832,6 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
874
832
|
}
|
|
875
833
|
throw new JsonRpcError('unexpected message');
|
|
876
834
|
};
|
|
877
|
-
const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
878
|
-
const {
|
|
879
|
-
message,
|
|
880
|
-
promise
|
|
881
|
-
} = create$2(method, params);
|
|
882
|
-
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
883
|
-
ipc.sendAndTransfer(message);
|
|
884
|
-
} else {
|
|
885
|
-
ipc.send(message);
|
|
886
|
-
}
|
|
887
|
-
const responseMessage = await promise;
|
|
888
|
-
return unwrapJsonRpcResult(responseMessage);
|
|
889
|
-
};
|
|
890
|
-
const send = (transport, method, ...params) => {
|
|
891
|
-
const message = create$4(method, params);
|
|
892
|
-
transport.send(message);
|
|
893
|
-
};
|
|
894
|
-
const invoke$1 = (ipc, method, ...params) => {
|
|
895
|
-
return invokeHelper(ipc, method, params, false);
|
|
896
|
-
};
|
|
897
|
-
const invokeAndTransfer$1 = (ipc, method, ...params) => {
|
|
898
|
-
return invokeHelper(ipc, method, params, true);
|
|
899
|
-
};
|
|
900
835
|
|
|
901
836
|
class CommandNotFoundError extends Error {
|
|
902
837
|
constructor(command) {
|
|
@@ -919,24 +854,87 @@ const execute = (command, ...args) => {
|
|
|
919
854
|
return fn(...args);
|
|
920
855
|
};
|
|
921
856
|
|
|
857
|
+
const Two = '2.0';
|
|
858
|
+
const create$p = (method, params) => {
|
|
859
|
+
return {
|
|
860
|
+
jsonrpc: Two,
|
|
861
|
+
method,
|
|
862
|
+
params
|
|
863
|
+
};
|
|
864
|
+
};
|
|
865
|
+
const create$o = (id, method, params) => {
|
|
866
|
+
const message = {
|
|
867
|
+
id,
|
|
868
|
+
jsonrpc: Two,
|
|
869
|
+
method,
|
|
870
|
+
params
|
|
871
|
+
};
|
|
872
|
+
return message;
|
|
873
|
+
};
|
|
874
|
+
let id = 0;
|
|
875
|
+
const create$n = () => {
|
|
876
|
+
return ++id;
|
|
877
|
+
};
|
|
878
|
+
|
|
879
|
+
/* eslint-disable n/no-unsupported-features/es-syntax */
|
|
880
|
+
|
|
881
|
+
const registerPromise = map => {
|
|
882
|
+
const id = create$n();
|
|
883
|
+
const {
|
|
884
|
+
promise,
|
|
885
|
+
resolve
|
|
886
|
+
} = Promise.withResolvers();
|
|
887
|
+
map[id] = resolve;
|
|
888
|
+
return {
|
|
889
|
+
id,
|
|
890
|
+
promise
|
|
891
|
+
};
|
|
892
|
+
};
|
|
893
|
+
|
|
894
|
+
// @ts-ignore
|
|
895
|
+
const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
|
|
896
|
+
const {
|
|
897
|
+
id,
|
|
898
|
+
promise
|
|
899
|
+
} = registerPromise(callbacks);
|
|
900
|
+
const message = create$o(id, method, params);
|
|
901
|
+
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
902
|
+
ipc.sendAndTransfer(message);
|
|
903
|
+
} else {
|
|
904
|
+
ipc.send(message);
|
|
905
|
+
}
|
|
906
|
+
const responseMessage = await promise;
|
|
907
|
+
return unwrapJsonRpcResult(responseMessage);
|
|
908
|
+
};
|
|
922
909
|
const createRpc = ipc => {
|
|
910
|
+
const callbacks = Object.create(null);
|
|
911
|
+
ipc._resolve = (id, response) => {
|
|
912
|
+
const fn = callbacks[id];
|
|
913
|
+
if (!fn) {
|
|
914
|
+
console.warn(`callback ${id} may already be disposed`);
|
|
915
|
+
return;
|
|
916
|
+
}
|
|
917
|
+
fn(response);
|
|
918
|
+
delete callbacks[id];
|
|
919
|
+
};
|
|
923
920
|
const rpc = {
|
|
921
|
+
async dispose() {
|
|
922
|
+
await ipc?.dispose();
|
|
923
|
+
},
|
|
924
|
+
invoke(method, ...params) {
|
|
925
|
+
return invokeHelper(callbacks, ipc, method, params, false);
|
|
926
|
+
},
|
|
927
|
+
invokeAndTransfer(method, ...params) {
|
|
928
|
+
return invokeHelper(callbacks, ipc, method, params, true);
|
|
929
|
+
},
|
|
924
930
|
// @ts-ignore
|
|
925
931
|
ipc,
|
|
926
932
|
/**
|
|
927
933
|
* @deprecated
|
|
928
934
|
*/
|
|
929
935
|
send(method, ...params) {
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
invoke(method, ...params) {
|
|
933
|
-
return invoke$1(ipc, method, ...params);
|
|
934
|
-
},
|
|
935
|
-
invokeAndTransfer(method, ...params) {
|
|
936
|
-
return invokeAndTransfer$1(ipc, method, ...params);
|
|
937
|
-
},
|
|
938
|
-
async dispose() {
|
|
939
|
-
await ipc?.dispose();
|
|
936
|
+
const message = create$p(method, params);
|
|
937
|
+
ipc.send(message);
|
|
940
938
|
}
|
|
941
939
|
};
|
|
942
940
|
return rpc;
|
|
@@ -953,7 +951,7 @@ const logError = () => {
|
|
|
953
951
|
const handleMessage = event => {
|
|
954
952
|
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
|
|
955
953
|
const actualExecute = event?.target?.execute || execute;
|
|
956
|
-
return handleJsonRpcMessage(event.target, event.data, actualExecute,
|
|
954
|
+
return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
957
955
|
};
|
|
958
956
|
const handleIpc = ipc => {
|
|
959
957
|
if ('addEventListener' in ipc) {
|
|
@@ -971,15 +969,16 @@ const listen$1 = async (module, options) => {
|
|
|
971
969
|
const ipc = module.wrap(rawIpc);
|
|
972
970
|
return ipc;
|
|
973
971
|
};
|
|
974
|
-
const create$
|
|
972
|
+
const create$7 = async ({
|
|
975
973
|
commandMap,
|
|
974
|
+
isMessagePortOpen = true,
|
|
976
975
|
messagePort
|
|
977
976
|
}) => {
|
|
978
977
|
// TODO create a commandMap per rpc instance
|
|
979
978
|
register(commandMap);
|
|
980
979
|
const rawIpc = await IpcParentWithMessagePort$1.create({
|
|
981
|
-
|
|
982
|
-
|
|
980
|
+
isMessagePortOpen,
|
|
981
|
+
messagePort
|
|
983
982
|
});
|
|
984
983
|
const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
|
|
985
984
|
handleIpc(ipc);
|
|
@@ -989,9 +988,9 @@ const create$5 = async ({
|
|
|
989
988
|
};
|
|
990
989
|
const PlainMessagePortRpc = {
|
|
991
990
|
__proto__: null,
|
|
992
|
-
create: create$
|
|
991
|
+
create: create$7
|
|
993
992
|
};
|
|
994
|
-
const create$
|
|
993
|
+
const create$2 = async ({
|
|
995
994
|
commandMap
|
|
996
995
|
}) => {
|
|
997
996
|
// TODO create a commandMap per rpc instance
|
|
@@ -1003,7 +1002,7 @@ const create$1 = async ({
|
|
|
1003
1002
|
};
|
|
1004
1003
|
const WebWorkerRpcClient = {
|
|
1005
1004
|
__proto__: null,
|
|
1006
|
-
create: create$
|
|
1005
|
+
create: create$2
|
|
1007
1006
|
};
|
|
1008
1007
|
const createMockRpc = ({
|
|
1009
1008
|
commandMap
|
|
@@ -1018,9 +1017,9 @@ const createMockRpc = ({
|
|
|
1018
1017
|
return command(...params);
|
|
1019
1018
|
};
|
|
1020
1019
|
const mockRpc = {
|
|
1020
|
+
invocations,
|
|
1021
1021
|
invoke,
|
|
1022
|
-
invokeAndTransfer: invoke
|
|
1023
|
-
invocations
|
|
1022
|
+
invokeAndTransfer: invoke
|
|
1024
1023
|
};
|
|
1025
1024
|
return mockRpc;
|
|
1026
1025
|
};
|
|
@@ -1076,8 +1075,6 @@ const Document = 'document';
|
|
|
1076
1075
|
|
|
1077
1076
|
const Markdown = 'Markdown';
|
|
1078
1077
|
|
|
1079
|
-
const HandleReadmeContextMenu = 'handleReadmeContextMenu';
|
|
1080
|
-
|
|
1081
1078
|
const getVirtualDomChildCount = markdownDom => {
|
|
1082
1079
|
const max = markdownDom.length - 1;
|
|
1083
1080
|
let stack = [];
|
|
@@ -1536,14 +1533,16 @@ const parseHtml = (html, allowedAttributes) => {
|
|
|
1536
1533
|
return dom;
|
|
1537
1534
|
};
|
|
1538
1535
|
|
|
1539
|
-
const getMarkdownVirtualDom = html
|
|
1536
|
+
const getMarkdownVirtualDom = (html, {
|
|
1537
|
+
onContextMenu = undefined
|
|
1538
|
+
} = {}) => {
|
|
1540
1539
|
string(html);
|
|
1541
1540
|
const childDom = parseHtml(html, allowedMarkdownAttributes);
|
|
1542
1541
|
const markdownChildCount = getVirtualDomChildCount(childDom);
|
|
1543
1542
|
return [{
|
|
1544
1543
|
childCount: markdownChildCount,
|
|
1545
1544
|
className: Markdown,
|
|
1546
|
-
onContextMenu
|
|
1545
|
+
onContextMenu,
|
|
1547
1546
|
role: Document,
|
|
1548
1547
|
type: Div$1
|
|
1549
1548
|
}, ...childDom];
|