@lvce-editor/find-widget-worker 1.8.0 → 1.10.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/findWidgetWorkerMain.js +118 -84
- package/package.json +1 -1
|
@@ -470,6 +470,16 @@ const constructError = (message, type, name) => {
|
|
|
470
470
|
}
|
|
471
471
|
return new ErrorConstructor(message);
|
|
472
472
|
};
|
|
473
|
+
const joinLines = lines => {
|
|
474
|
+
return lines.join(NewLine);
|
|
475
|
+
};
|
|
476
|
+
const splitLines = lines => {
|
|
477
|
+
return lines.split(NewLine);
|
|
478
|
+
};
|
|
479
|
+
const getCurrentStack = () => {
|
|
480
|
+
const currentStack = joinLines(splitLines(new Error().stack || '').slice(2));
|
|
481
|
+
return currentStack;
|
|
482
|
+
};
|
|
473
483
|
const getNewLineIndex = (string, startIndex = undefined) => {
|
|
474
484
|
return string.indexOf(NewLine, startIndex);
|
|
475
485
|
};
|
|
@@ -480,19 +490,16 @@ const getParentStack = error => {
|
|
|
480
490
|
}
|
|
481
491
|
return parentStack;
|
|
482
492
|
};
|
|
483
|
-
const joinLines = lines => {
|
|
484
|
-
return lines.join(NewLine);
|
|
485
|
-
};
|
|
486
493
|
const MethodNotFound = -32601;
|
|
487
494
|
const Custom = -32001;
|
|
488
|
-
const splitLines = lines => {
|
|
489
|
-
return lines.split(NewLine);
|
|
490
|
-
};
|
|
491
495
|
const restoreJsonRpcError = error => {
|
|
496
|
+
const currentStack = getCurrentStack();
|
|
492
497
|
if (error && error instanceof Error) {
|
|
498
|
+
if (typeof error.stack === 'string') {
|
|
499
|
+
error.stack = error.stack + NewLine + currentStack;
|
|
500
|
+
}
|
|
493
501
|
return error;
|
|
494
502
|
}
|
|
495
|
-
const currentStack = joinLines(splitLines(new Error().stack || '').slice(1));
|
|
496
503
|
if (error && error.code && error.code === MethodNotFound) {
|
|
497
504
|
const restoredError = new JsonRpcError(error.message);
|
|
498
505
|
const parentStack = getParentStack(error);
|
|
@@ -573,6 +580,17 @@ const getErrorType = prettyError => {
|
|
|
573
580
|
}
|
|
574
581
|
return undefined;
|
|
575
582
|
};
|
|
583
|
+
const isAlreadyStack = line => {
|
|
584
|
+
return line.trim().startsWith('at ');
|
|
585
|
+
};
|
|
586
|
+
const getStack = prettyError => {
|
|
587
|
+
const stackString = prettyError.stack || '';
|
|
588
|
+
const newLineIndex = stackString.indexOf('\n');
|
|
589
|
+
if (newLineIndex !== -1 && !isAlreadyStack(stackString.slice(0, newLineIndex))) {
|
|
590
|
+
return stackString.slice(newLineIndex + 1);
|
|
591
|
+
}
|
|
592
|
+
return stackString;
|
|
593
|
+
};
|
|
576
594
|
const getErrorProperty = (error, prettyError) => {
|
|
577
595
|
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
578
596
|
return {
|
|
@@ -585,7 +603,7 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
585
603
|
code: Custom,
|
|
586
604
|
message: prettyError.message,
|
|
587
605
|
data: {
|
|
588
|
-
stack: prettyError
|
|
606
|
+
stack: getStack(prettyError),
|
|
589
607
|
codeFrame: prettyError.codeFrame,
|
|
590
608
|
type: getErrorType(prettyError),
|
|
591
609
|
code: prettyError.code,
|
|
@@ -593,18 +611,18 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
593
611
|
}
|
|
594
612
|
};
|
|
595
613
|
};
|
|
596
|
-
const create$1$1 = (
|
|
614
|
+
const create$1$1 = (id, error) => {
|
|
597
615
|
return {
|
|
598
616
|
jsonrpc: Two,
|
|
599
|
-
id
|
|
617
|
+
id,
|
|
600
618
|
error
|
|
601
619
|
};
|
|
602
620
|
};
|
|
603
|
-
const getErrorResponse = (
|
|
621
|
+
const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
604
622
|
const prettyError = preparePrettyError(error);
|
|
605
623
|
logError(error, prettyError);
|
|
606
624
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
607
|
-
return create$1$1(
|
|
625
|
+
return create$1$1(id, errorProperty);
|
|
608
626
|
};
|
|
609
627
|
const create$5 = (message, result) => {
|
|
610
628
|
return {
|
|
@@ -617,12 +635,27 @@ const getSuccessResponse = (message, result) => {
|
|
|
617
635
|
const resultProperty = result ?? null;
|
|
618
636
|
return create$5(message, resultProperty);
|
|
619
637
|
};
|
|
638
|
+
const getErrorResponseSimple = (id, error) => {
|
|
639
|
+
return {
|
|
640
|
+
jsonrpc: Two,
|
|
641
|
+
id,
|
|
642
|
+
error: {
|
|
643
|
+
code: Custom,
|
|
644
|
+
// @ts-ignore
|
|
645
|
+
message: error.message,
|
|
646
|
+
data: error
|
|
647
|
+
}
|
|
648
|
+
};
|
|
649
|
+
};
|
|
620
650
|
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
621
651
|
try {
|
|
622
652
|
const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
|
|
623
653
|
return getSuccessResponse(message, result);
|
|
624
654
|
} catch (error) {
|
|
625
|
-
|
|
655
|
+
if (ipc.canUseSimpleErrorResponse) {
|
|
656
|
+
return getErrorResponseSimple(message.id, error);
|
|
657
|
+
}
|
|
658
|
+
return getErrorResponse(message.id, error, preparePrettyError, logError);
|
|
626
659
|
}
|
|
627
660
|
};
|
|
628
661
|
const defaultPreparePrettyError = error => {
|
|
@@ -677,7 +710,7 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
677
710
|
try {
|
|
678
711
|
ipc.send(response);
|
|
679
712
|
} catch (error) {
|
|
680
|
-
const errorResponse = getErrorResponse(message, error, preparePrettyError, logError);
|
|
713
|
+
const errorResponse = getErrorResponse(message.id, error, preparePrettyError, logError);
|
|
681
714
|
ipc.send(errorResponse);
|
|
682
715
|
}
|
|
683
716
|
return;
|
|
@@ -981,36 +1014,77 @@ const focusCloseButton = state => {
|
|
|
981
1014
|
return setFindWidgetFocus(state, FocusFindWidgetCloseButton);
|
|
982
1015
|
};
|
|
983
1016
|
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
1017
|
+
const rpcs = Object.create(null);
|
|
1018
|
+
const set$f = (id, rpc) => {
|
|
1019
|
+
rpcs[id] = rpc;
|
|
1020
|
+
};
|
|
1021
|
+
const get = id => {
|
|
1022
|
+
return rpcs[id];
|
|
1023
|
+
};
|
|
1024
|
+
|
|
1025
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
1026
|
+
|
|
1027
|
+
const create = rpcId => {
|
|
1028
|
+
return {
|
|
1029
|
+
// @ts-ignore
|
|
1030
|
+
invoke(method, ...params) {
|
|
1031
|
+
const rpc = get(rpcId);
|
|
1032
|
+
// @ts-ignore
|
|
1033
|
+
return rpc.invoke(method, ...params);
|
|
1034
|
+
},
|
|
1035
|
+
// @ts-ignore
|
|
1036
|
+
invokeAndTransfer(method, ...params) {
|
|
1037
|
+
const rpc = get(rpcId);
|
|
1038
|
+
// @ts-ignore
|
|
1039
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
1040
|
+
},
|
|
1041
|
+
set(rpc) {
|
|
1042
|
+
set$f(rpcId, rpc);
|
|
1043
|
+
},
|
|
1044
|
+
async dispose() {
|
|
1045
|
+
const rpc = get(rpcId);
|
|
1046
|
+
await rpc.dispose();
|
|
1047
|
+
}
|
|
1048
|
+
};
|
|
1049
|
+
};
|
|
1050
|
+
const EditorWorker$1 = 99;
|
|
1051
|
+
const {
|
|
1052
|
+
invoke: invoke$c,
|
|
1053
|
+
set: set$c} = create(EditorWorker$1);
|
|
1054
|
+
const EditorWorker = {
|
|
1055
|
+
__proto__: null,
|
|
1056
|
+
invoke: invoke$c,
|
|
1057
|
+
set: set$c
|
|
1058
|
+
};
|
|
1059
|
+
|
|
1060
|
+
const {
|
|
1061
|
+
invoke,
|
|
1062
|
+
set} = EditorWorker;
|
|
1063
|
+
|
|
1064
|
+
const setSelections = async (editorUid, selections) => {
|
|
1065
|
+
// @ts-ignore
|
|
1066
|
+
await invoke('Editor.setSelections2', editorUid, selections);
|
|
1067
|
+
};
|
|
1068
|
+
|
|
1069
|
+
const focusIndex = async (state, index) => {
|
|
987
1070
|
const {
|
|
988
|
-
matchIndex
|
|
1071
|
+
matchIndex,
|
|
1072
|
+
matches,
|
|
1073
|
+
editorUid,
|
|
1074
|
+
value
|
|
989
1075
|
} = state;
|
|
990
1076
|
if (index === matchIndex) {
|
|
991
1077
|
return state;
|
|
992
1078
|
}
|
|
993
|
-
// TODO update editor
|
|
994
|
-
// const { widgets } = editor
|
|
995
|
-
// const childIndex = widgets.findIndex(isFind)
|
|
996
|
-
// const childWidget = widgets[childIndex]
|
|
997
|
-
|
|
998
1079
|
// // TODO find next match and highlight it
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
// ...findState,
|
|
1004
|
-
// matchIndex: index,
|
|
1005
|
-
// }
|
|
1006
|
-
// const newWidget = {
|
|
1007
|
-
// ...childWidget,
|
|
1008
|
-
// newState,
|
|
1009
|
-
// }
|
|
1010
|
-
// const newWidgets = [...widgets.slice(0, childIndex), newWidget, ...widgets.slice(childIndex + 1)]
|
|
1080
|
+
const matchRowIndex = matches[index * 2];
|
|
1081
|
+
const matchColumnIndex = matches[index * 2 + 1];
|
|
1082
|
+
const newSelections = new Uint32Array([matchRowIndex, matchColumnIndex, matchRowIndex, matchColumnIndex + value.length]);
|
|
1083
|
+
await setSelections(editorUid, newSelections);
|
|
1011
1084
|
return {
|
|
1012
1085
|
...state,
|
|
1013
|
-
matchIndex: index
|
|
1086
|
+
matchIndex: index,
|
|
1087
|
+
selections: [...newSelections]
|
|
1014
1088
|
};
|
|
1015
1089
|
};
|
|
1016
1090
|
const focusFirst = state => {
|
|
@@ -1058,50 +1132,6 @@ const handleBlur = async state => {
|
|
|
1058
1132
|
};
|
|
1059
1133
|
};
|
|
1060
1134
|
|
|
1061
|
-
const rpcs = Object.create(null);
|
|
1062
|
-
const set$a = (id, rpc) => {
|
|
1063
|
-
rpcs[id] = rpc;
|
|
1064
|
-
};
|
|
1065
|
-
const get = id => {
|
|
1066
|
-
return rpcs[id];
|
|
1067
|
-
};
|
|
1068
|
-
|
|
1069
|
-
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
1070
|
-
|
|
1071
|
-
const create = rpcId => {
|
|
1072
|
-
return {
|
|
1073
|
-
// @ts-ignore
|
|
1074
|
-
invoke(method, ...params) {
|
|
1075
|
-
const rpc = get(rpcId);
|
|
1076
|
-
// @ts-ignore
|
|
1077
|
-
return rpc.invoke(method, ...params);
|
|
1078
|
-
},
|
|
1079
|
-
// @ts-ignore
|
|
1080
|
-
invokeAndTransfer(method, ...params) {
|
|
1081
|
-
const rpc = get(rpcId);
|
|
1082
|
-
// @ts-ignore
|
|
1083
|
-
return rpc.invokeAndTransfer(method, ...params);
|
|
1084
|
-
},
|
|
1085
|
-
set(rpc) {
|
|
1086
|
-
set$a(rpcId, rpc);
|
|
1087
|
-
}
|
|
1088
|
-
};
|
|
1089
|
-
};
|
|
1090
|
-
const EditorWorker$1 = 99;
|
|
1091
|
-
const {
|
|
1092
|
-
invoke: invoke$9,
|
|
1093
|
-
set: set$9
|
|
1094
|
-
} = create(EditorWorker$1);
|
|
1095
|
-
const EditorWorker = {
|
|
1096
|
-
__proto__: null,
|
|
1097
|
-
invoke: invoke$9,
|
|
1098
|
-
set: set$9
|
|
1099
|
-
};
|
|
1100
|
-
|
|
1101
|
-
const {
|
|
1102
|
-
invoke,
|
|
1103
|
-
set} = EditorWorker;
|
|
1104
|
-
|
|
1105
1135
|
const close$1 = async state => {
|
|
1106
1136
|
const {
|
|
1107
1137
|
editorUid
|
|
@@ -1287,6 +1317,10 @@ const loadContent = async state => {
|
|
|
1287
1317
|
};
|
|
1288
1318
|
};
|
|
1289
1319
|
|
|
1320
|
+
const preventDefaultBrowserFind = state => {
|
|
1321
|
+
return state;
|
|
1322
|
+
};
|
|
1323
|
+
|
|
1290
1324
|
const SetBounds = 'Viewlet.setBounds';
|
|
1291
1325
|
const SetDom2 = 'Viewlet.setDom2';
|
|
1292
1326
|
const SetUid = 'Viewlet.setUid';
|
|
@@ -1305,7 +1339,6 @@ const renderBounds = (oldState, newState) => {
|
|
|
1305
1339
|
|
|
1306
1340
|
const HandleBlur = 'handleBlur';
|
|
1307
1341
|
const HandleClickClose = 'handleClickClose';
|
|
1308
|
-
const HandleClickFocusPreviousMatch = 'handleClickFocusPreviousMatch';
|
|
1309
1342
|
const HandleClickNextMatch = 'handleClickNextMatch';
|
|
1310
1343
|
const HandleClickPreviousMatch = 'handleClickPreviousMatch';
|
|
1311
1344
|
const HandleClickReplace = 'handleClickReplace';
|
|
@@ -1658,11 +1691,11 @@ const getEventListeners = (uid, widgetId) => {
|
|
|
1658
1691
|
name: HandleClickClose,
|
|
1659
1692
|
params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleClickClose', 0, widgetId]
|
|
1660
1693
|
}, {
|
|
1661
|
-
name:
|
|
1662
|
-
params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.
|
|
1694
|
+
name: HandleClickPreviousMatch,
|
|
1695
|
+
params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.focusPrevious', 0, widgetId]
|
|
1663
1696
|
}, {
|
|
1664
1697
|
name: HandleClickNextMatch,
|
|
1665
|
-
params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.
|
|
1698
|
+
params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.focusNext', 0, widgetId]
|
|
1666
1699
|
}, {
|
|
1667
1700
|
name: HandleClickReplace,
|
|
1668
1701
|
params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleClickReplace', 0, widgetId]
|
|
@@ -1793,6 +1826,7 @@ const commandMap = {
|
|
|
1793
1826
|
'FindWidget.handleClickClose': wrapCommand(handleClickClose),
|
|
1794
1827
|
'FindWidget.handleInput': wrapCommand(handleInput),
|
|
1795
1828
|
'FindWidget.loadContent': wrapCommand(loadContent),
|
|
1829
|
+
'FindWidget.preventDefaultBrowserFind': wrapCommand(preventDefaultBrowserFind),
|
|
1796
1830
|
'FindWidget.render2': render2,
|
|
1797
1831
|
'FindWidget.terminate': terminate,
|
|
1798
1832
|
'FindWidget.toggleReplace': wrapCommand(toggleReplace)
|