@lvce-editor/find-widget-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/findWidgetWorkerMain.js +142 -66
- package/package.json +1 -1
|
@@ -859,9 +859,11 @@ const create$2 = () => {
|
|
|
859
859
|
const {
|
|
860
860
|
get: get$1,
|
|
861
861
|
set: set$1,
|
|
862
|
-
wrapCommand
|
|
862
|
+
wrapCommand,
|
|
863
|
+
dispose: dispose$1
|
|
863
864
|
} = create$2();
|
|
864
865
|
|
|
866
|
+
const Script$1 = 2;
|
|
865
867
|
const Unknown = 0;
|
|
866
868
|
|
|
867
869
|
const create$1 = (uid, x, y, width, height, parentUid) => {
|
|
@@ -891,29 +893,30 @@ const create$1 = (uid, x, y, width, height, parentUid) => {
|
|
|
891
893
|
editorX: x,
|
|
892
894
|
editorY: y,
|
|
893
895
|
editorWidth: width,
|
|
894
|
-
editorHeight: height
|
|
896
|
+
editorHeight: height,
|
|
897
|
+
inputSource: 0
|
|
895
898
|
};
|
|
896
899
|
set$1(uid, state, state);
|
|
897
900
|
return state;
|
|
898
901
|
};
|
|
899
902
|
|
|
900
|
-
const isEqual$
|
|
903
|
+
const isEqual$5 = (oldState, newState) => {
|
|
901
904
|
return oldState.x === newState.x && oldState.y === newState.y && oldState.width === newState.width && oldState.height === newState.height;
|
|
902
905
|
};
|
|
903
906
|
|
|
904
|
-
const isEqual$
|
|
907
|
+
const isEqual$4 = (oldState, newState) => {
|
|
905
908
|
return oldState.version === newState.version;
|
|
906
909
|
};
|
|
907
910
|
|
|
908
|
-
const isEqual$
|
|
911
|
+
const isEqual$3 = (oldState, newState) => {
|
|
909
912
|
return oldState.focused === newState.focused;
|
|
910
913
|
};
|
|
911
914
|
|
|
912
|
-
const isEqual$
|
|
915
|
+
const isEqual$2 = (oldState, newState) => {
|
|
913
916
|
return oldState.version === newState.version && oldState.replaceExpanded === newState.replaceExpanded && oldState.matchCount === newState.matchCount && oldState.matchIndex === newState.matchIndex;
|
|
914
917
|
};
|
|
915
918
|
|
|
916
|
-
const isEqual = (oldState, newState) => {
|
|
919
|
+
const isEqual$1 = (oldState, newState) => {
|
|
917
920
|
return oldState.version === newState.version;
|
|
918
921
|
};
|
|
919
922
|
|
|
@@ -923,9 +926,17 @@ const RenderUid = 12;
|
|
|
923
926
|
const RenderContent = 13;
|
|
924
927
|
const RenderFocusContext = 14;
|
|
925
928
|
const RenderFocus = 15;
|
|
929
|
+
const RenderValue = 16;
|
|
926
930
|
|
|
927
|
-
const
|
|
928
|
-
const
|
|
931
|
+
const Script = 1;
|
|
932
|
+
const User = 2;
|
|
933
|
+
|
|
934
|
+
const isEqual = (oldState, newState) => {
|
|
935
|
+
return newState.inputSource === User || oldState.value === newState.value;
|
|
936
|
+
};
|
|
937
|
+
|
|
938
|
+
const modules = [isEqual$4, isEqual$2, isEqual$5, isEqual$1, isEqual$3, isEqual$3, isEqual];
|
|
939
|
+
const numbers = [RenderEventListeners, RenderContent, RenderBounds, RenderUid, RenderFocusContext, RenderFocus, RenderValue];
|
|
929
940
|
|
|
930
941
|
const diff = (oldState, newState) => {
|
|
931
942
|
const diffResult = [];
|
|
@@ -947,6 +958,29 @@ const diff2 = uid => {
|
|
|
947
958
|
return diffResult;
|
|
948
959
|
};
|
|
949
960
|
|
|
961
|
+
const dispose = uid => {
|
|
962
|
+
return dispose$1(uid);
|
|
963
|
+
};
|
|
964
|
+
|
|
965
|
+
const FocusFindWidgetCloseButton = 48;
|
|
966
|
+
const FocusFindWidgetReplace = 43;
|
|
967
|
+
const FocusFindWidgetReplaceAllButton = 47;
|
|
968
|
+
|
|
969
|
+
const setFindWidgetFocus = (state, focusKey) => {
|
|
970
|
+
if (state.focus === focusKey) {
|
|
971
|
+
return state;
|
|
972
|
+
}
|
|
973
|
+
return {
|
|
974
|
+
...state,
|
|
975
|
+
focus: focusKey,
|
|
976
|
+
focusSource: Script$1
|
|
977
|
+
};
|
|
978
|
+
};
|
|
979
|
+
|
|
980
|
+
const focusCloseButton = state => {
|
|
981
|
+
return setFindWidgetFocus(state, FocusFindWidgetCloseButton);
|
|
982
|
+
};
|
|
983
|
+
|
|
950
984
|
// TODO don't call renderer worker, set editor state
|
|
951
985
|
// TODO this function should be synchronous
|
|
952
986
|
const focusIndex = (state, index) => {
|
|
@@ -1008,6 +1042,14 @@ const focusPrevious = state => {
|
|
|
1008
1042
|
return focusIndex(state, matchIndex - 1);
|
|
1009
1043
|
};
|
|
1010
1044
|
|
|
1045
|
+
const focusReplace = state => {
|
|
1046
|
+
return setFindWidgetFocus(state, FocusFindWidgetReplace);
|
|
1047
|
+
};
|
|
1048
|
+
|
|
1049
|
+
const focusReplaceAllButton = state => {
|
|
1050
|
+
return setFindWidgetFocus(state, FocusFindWidgetReplaceAllButton);
|
|
1051
|
+
};
|
|
1052
|
+
|
|
1011
1053
|
const handleBlur = async state => {
|
|
1012
1054
|
return {
|
|
1013
1055
|
...state,
|
|
@@ -1016,11 +1058,63 @@ const handleBlur = async state => {
|
|
|
1016
1058
|
};
|
|
1017
1059
|
};
|
|
1018
1060
|
|
|
1019
|
-
const
|
|
1020
|
-
|
|
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
|
+
const close$1 = async state => {
|
|
1106
|
+
const {
|
|
1107
|
+
editorUid
|
|
1108
|
+
} = state;
|
|
1109
|
+
// @ts-ignore
|
|
1110
|
+
await invoke('Editor.closeFind2', editorUid);
|
|
1021
1111
|
return state;
|
|
1022
1112
|
};
|
|
1023
1113
|
|
|
1114
|
+
const handleClickClose = state => {
|
|
1115
|
+
return close$1(state);
|
|
1116
|
+
};
|
|
1117
|
+
|
|
1024
1118
|
const findRegexMatches = (lines, regex) => {
|
|
1025
1119
|
if (!regex.global) {
|
|
1026
1120
|
throw new Error('regex must be global');
|
|
@@ -1079,7 +1173,8 @@ const refresh$1 = (state, value) => {
|
|
|
1079
1173
|
matches,
|
|
1080
1174
|
matchIndex: 0,
|
|
1081
1175
|
matchCount,
|
|
1082
|
-
value
|
|
1176
|
+
value,
|
|
1177
|
+
inputSource: User
|
|
1083
1178
|
};
|
|
1084
1179
|
};
|
|
1085
1180
|
|
|
@@ -1132,50 +1227,6 @@ const getFindWidgetPosition = (editorX, editorY, editorWidth) => {
|
|
|
1132
1227
|
};
|
|
1133
1228
|
};
|
|
1134
1229
|
|
|
1135
|
-
const rpcs = Object.create(null);
|
|
1136
|
-
const set$a = (id, rpc) => {
|
|
1137
|
-
rpcs[id] = rpc;
|
|
1138
|
-
};
|
|
1139
|
-
const get = id => {
|
|
1140
|
-
return rpcs[id];
|
|
1141
|
-
};
|
|
1142
|
-
|
|
1143
|
-
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
1144
|
-
|
|
1145
|
-
const create = rpcId => {
|
|
1146
|
-
return {
|
|
1147
|
-
// @ts-ignore
|
|
1148
|
-
invoke(method, ...params) {
|
|
1149
|
-
const rpc = get(rpcId);
|
|
1150
|
-
// @ts-ignore
|
|
1151
|
-
return rpc.invoke(method, ...params);
|
|
1152
|
-
},
|
|
1153
|
-
// @ts-ignore
|
|
1154
|
-
invokeAndTransfer(method, ...params) {
|
|
1155
|
-
const rpc = get(rpcId);
|
|
1156
|
-
// @ts-ignore
|
|
1157
|
-
return rpc.invokeAndTransfer(method, ...params);
|
|
1158
|
-
},
|
|
1159
|
-
set(rpc) {
|
|
1160
|
-
set$a(rpcId, rpc);
|
|
1161
|
-
}
|
|
1162
|
-
};
|
|
1163
|
-
};
|
|
1164
|
-
const EditorWorker$1 = 99;
|
|
1165
|
-
const {
|
|
1166
|
-
invoke: invoke$9,
|
|
1167
|
-
set: set$9
|
|
1168
|
-
} = create(EditorWorker$1);
|
|
1169
|
-
const EditorWorker = {
|
|
1170
|
-
__proto__: null,
|
|
1171
|
-
invoke: invoke$9,
|
|
1172
|
-
set: set$9
|
|
1173
|
-
};
|
|
1174
|
-
|
|
1175
|
-
const {
|
|
1176
|
-
invoke,
|
|
1177
|
-
set} = EditorWorker;
|
|
1178
|
-
|
|
1179
1230
|
const getLines = async editorUid => {
|
|
1180
1231
|
// @ts-ignore
|
|
1181
1232
|
const lines = await invoke('Editor.getLines2', editorUid);
|
|
@@ -1183,6 +1234,15 @@ const getLines = async editorUid => {
|
|
|
1183
1234
|
return lines;
|
|
1184
1235
|
};
|
|
1185
1236
|
|
|
1237
|
+
const getSelectedText = (lines, selections) => {
|
|
1238
|
+
const startRowIndex = selections[0];
|
|
1239
|
+
const startColumnIndex = selections[1];
|
|
1240
|
+
const endColumnIndex = selections[3];
|
|
1241
|
+
const line = lines[startRowIndex];
|
|
1242
|
+
const value = line.slice(startColumnIndex, endColumnIndex);
|
|
1243
|
+
return value;
|
|
1244
|
+
};
|
|
1245
|
+
|
|
1186
1246
|
const getSelections = async editorUid => {
|
|
1187
1247
|
// @ts-ignore
|
|
1188
1248
|
const selections = await invoke('Editor.getSelections2', editorUid);
|
|
@@ -1208,11 +1268,7 @@ const loadContent = async state => {
|
|
|
1208
1268
|
if (lines.length === 0) {
|
|
1209
1269
|
return state;
|
|
1210
1270
|
}
|
|
1211
|
-
const
|
|
1212
|
-
const startColumnIndex = selections[1];
|
|
1213
|
-
const endColumnIndex = selections[3];
|
|
1214
|
-
const line = lines[startRowIndex];
|
|
1215
|
-
const value = line.slice(startColumnIndex, endColumnIndex);
|
|
1271
|
+
const value = getSelectedText(lines, selections);
|
|
1216
1272
|
const matches = findMatchesCaseInsensitive(lines, value);
|
|
1217
1273
|
const matchCount = getMatchCount(matches);
|
|
1218
1274
|
return {
|
|
@@ -1228,7 +1284,8 @@ const loadContent = async state => {
|
|
|
1228
1284
|
height,
|
|
1229
1285
|
lines,
|
|
1230
1286
|
selections,
|
|
1231
|
-
focused: true
|
|
1287
|
+
focused: true,
|
|
1288
|
+
inputSource: Script
|
|
1232
1289
|
};
|
|
1233
1290
|
};
|
|
1234
1291
|
|
|
@@ -1318,6 +1375,9 @@ const Close$1 = 'Close';
|
|
|
1318
1375
|
const Replace$1 = 'Replace';
|
|
1319
1376
|
const ReplaceAll$1 = 'ReplaceAll';
|
|
1320
1377
|
|
|
1378
|
+
const ToggleReplace = 'ToggleReplace';
|
|
1379
|
+
const SearchValue = 'search-value';
|
|
1380
|
+
const ReplaceValue = 'replace-value';
|
|
1321
1381
|
const ReplaceAll = 'ReplaceAll';
|
|
1322
1382
|
const Close = 'Close';
|
|
1323
1383
|
const FocusNext = 'FocusNext';
|
|
@@ -1389,6 +1449,10 @@ const SearchField = 'SearchField';
|
|
|
1389
1449
|
const SearchFieldButton = 'SearchFieldButton';
|
|
1390
1450
|
const SearchFieldButtonChecked = 'SearchFieldButtonChecked';
|
|
1391
1451
|
const SearchFieldButtons = 'SearchFieldButtons';
|
|
1452
|
+
const Viewlet = 'Viewlet';
|
|
1453
|
+
const ViewletFind = 'ViewletFind';
|
|
1454
|
+
const FindWidget = 'FindWidget';
|
|
1455
|
+
const ViewletFindWidget = 'ViewletFindWidget';
|
|
1392
1456
|
|
|
1393
1457
|
const mergeClassNames = (...classNames) => {
|
|
1394
1458
|
return classNames.filter(Boolean).join(' ');
|
|
@@ -1519,13 +1583,11 @@ const getFindWidgetReplaceVirtualDom = (replaceExpanded, replaceButtons) => {
|
|
|
1519
1583
|
type: Div,
|
|
1520
1584
|
className: FindWidgetReplace,
|
|
1521
1585
|
childCount: 1 + replaceButtons.length
|
|
1522
|
-
}, ...getSearchFieldVirtualDom(
|
|
1586
|
+
}, ...getSearchFieldVirtualDom(ReplaceValue, replace(), HandleReplaceInput, [], [], HandleReplaceFocus), ...replaceButtons.flatMap(getIconButtonVirtualDom));
|
|
1523
1587
|
}
|
|
1524
1588
|
return dom;
|
|
1525
1589
|
};
|
|
1526
1590
|
|
|
1527
|
-
const ToggleReplace = 'ToggleReplace';
|
|
1528
|
-
|
|
1529
1591
|
const getSearchToggleButtonVirtualDom = (replaceExpanded, onClick = '') => {
|
|
1530
1592
|
return [{
|
|
1531
1593
|
type: Button,
|
|
@@ -1549,7 +1611,7 @@ const getFindWidgetVirtualDom = (matchCountText, replaceExpanded, findButtons, r
|
|
|
1549
1611
|
const dom = [];
|
|
1550
1612
|
dom.push({
|
|
1551
1613
|
type: Div,
|
|
1552
|
-
className:
|
|
1614
|
+
className: mergeClassNames(Viewlet, ViewletFind, ViewletFindWidget, FindWidget),
|
|
1553
1615
|
childCount: 2,
|
|
1554
1616
|
role: Group
|
|
1555
1617
|
});
|
|
@@ -1664,6 +1726,14 @@ const renderUid = (oldState, newState) => {
|
|
|
1664
1726
|
return [SetUid, uid, editorUid];
|
|
1665
1727
|
};
|
|
1666
1728
|
|
|
1729
|
+
const renderValue = (oldState, newState) => {
|
|
1730
|
+
const {
|
|
1731
|
+
uid,
|
|
1732
|
+
value
|
|
1733
|
+
} = newState;
|
|
1734
|
+
return [/* method */'Viewlet.setValueByName', uid, SearchValue, value];
|
|
1735
|
+
};
|
|
1736
|
+
|
|
1667
1737
|
const getRenderer = diffType => {
|
|
1668
1738
|
switch (diffType) {
|
|
1669
1739
|
case RenderContent:
|
|
@@ -1678,6 +1748,8 @@ const getRenderer = diffType => {
|
|
|
1678
1748
|
return renderFocusContext;
|
|
1679
1749
|
case RenderFocus:
|
|
1680
1750
|
return renderFocus;
|
|
1751
|
+
case RenderValue:
|
|
1752
|
+
return renderValue;
|
|
1681
1753
|
default:
|
|
1682
1754
|
throw new Error('unknown renderer');
|
|
1683
1755
|
}
|
|
@@ -1709,11 +1781,15 @@ const terminate = () => {
|
|
|
1709
1781
|
const commandMap = {
|
|
1710
1782
|
'FindWidget.create': create$1,
|
|
1711
1783
|
'FindWidget.diff2': diff2,
|
|
1784
|
+
'FindWidget.dispose': dispose,
|
|
1785
|
+
'FindWidget.focusCloseButton': wrapCommand(focusCloseButton),
|
|
1712
1786
|
'FindWidget.focusFirst': wrapCommand(focusFirst),
|
|
1713
1787
|
'FindWidget.focusIndex': wrapCommand(focusIndex),
|
|
1714
1788
|
'FindWidget.focusLast': wrapCommand(focusLast),
|
|
1715
1789
|
'FindWidget.focusNext': wrapCommand(focusNext),
|
|
1716
1790
|
'FindWidget.focusPrevious': wrapCommand(focusPrevious),
|
|
1791
|
+
'FindWidget.focusReplace': wrapCommand(focusReplace),
|
|
1792
|
+
'FindWidget.focusReplaceAllButton': wrapCommand(focusReplaceAllButton),
|
|
1717
1793
|
'FindWidget.getCommandIds': getCommandIds,
|
|
1718
1794
|
'FindWidget.handleBlur': wrapCommand(handleBlur),
|
|
1719
1795
|
'FindWidget.handleClickClose': wrapCommand(handleClickClose),
|