@lvce-editor/find-widget-worker 1.4.0 → 1.6.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 +102 -41
- package/package.json +1 -1
|
@@ -862,6 +862,7 @@ const {
|
|
|
862
862
|
wrapCommand
|
|
863
863
|
} = create$2();
|
|
864
864
|
|
|
865
|
+
const Script$1 = 2;
|
|
865
866
|
const Unknown = 0;
|
|
866
867
|
|
|
867
868
|
const create$1 = (uid, x, y, width, height, parentUid) => {
|
|
@@ -891,29 +892,30 @@ const create$1 = (uid, x, y, width, height, parentUid) => {
|
|
|
891
892
|
editorX: x,
|
|
892
893
|
editorY: y,
|
|
893
894
|
editorWidth: width,
|
|
894
|
-
editorHeight: height
|
|
895
|
+
editorHeight: height,
|
|
896
|
+
inputSource: 0
|
|
895
897
|
};
|
|
896
898
|
set$1(uid, state, state);
|
|
897
899
|
return state;
|
|
898
900
|
};
|
|
899
901
|
|
|
900
|
-
const isEqual$
|
|
902
|
+
const isEqual$5 = (oldState, newState) => {
|
|
901
903
|
return oldState.x === newState.x && oldState.y === newState.y && oldState.width === newState.width && oldState.height === newState.height;
|
|
902
904
|
};
|
|
903
905
|
|
|
904
|
-
const isEqual$
|
|
906
|
+
const isEqual$4 = (oldState, newState) => {
|
|
905
907
|
return oldState.version === newState.version;
|
|
906
908
|
};
|
|
907
909
|
|
|
908
|
-
const isEqual$
|
|
910
|
+
const isEqual$3 = (oldState, newState) => {
|
|
909
911
|
return oldState.focused === newState.focused;
|
|
910
912
|
};
|
|
911
913
|
|
|
912
|
-
const isEqual$
|
|
914
|
+
const isEqual$2 = (oldState, newState) => {
|
|
913
915
|
return oldState.version === newState.version && oldState.replaceExpanded === newState.replaceExpanded && oldState.matchCount === newState.matchCount && oldState.matchIndex === newState.matchIndex;
|
|
914
916
|
};
|
|
915
917
|
|
|
916
|
-
const isEqual = (oldState, newState) => {
|
|
918
|
+
const isEqual$1 = (oldState, newState) => {
|
|
917
919
|
return oldState.version === newState.version;
|
|
918
920
|
};
|
|
919
921
|
|
|
@@ -923,9 +925,17 @@ const RenderUid = 12;
|
|
|
923
925
|
const RenderContent = 13;
|
|
924
926
|
const RenderFocusContext = 14;
|
|
925
927
|
const RenderFocus = 15;
|
|
928
|
+
const RenderValue = 16;
|
|
926
929
|
|
|
927
|
-
const
|
|
928
|
-
const
|
|
930
|
+
const Script = 1;
|
|
931
|
+
const User = 2;
|
|
932
|
+
|
|
933
|
+
const isEqual = (oldState, newState) => {
|
|
934
|
+
return newState.inputSource === User || oldState.value === newState.value;
|
|
935
|
+
};
|
|
936
|
+
|
|
937
|
+
const modules = [isEqual$4, isEqual$2, isEqual$5, isEqual$1, isEqual$3, isEqual$3, isEqual];
|
|
938
|
+
const numbers = [RenderEventListeners, RenderContent, RenderBounds, RenderUid, RenderFocusContext, RenderFocus, RenderValue];
|
|
929
939
|
|
|
930
940
|
const diff = (oldState, newState) => {
|
|
931
941
|
const diffResult = [];
|
|
@@ -947,6 +957,25 @@ const diff2 = uid => {
|
|
|
947
957
|
return diffResult;
|
|
948
958
|
};
|
|
949
959
|
|
|
960
|
+
const FocusFindWidgetCloseButton = 48;
|
|
961
|
+
const FocusFindWidgetReplace = 43;
|
|
962
|
+
const FocusFindWidgetReplaceAllButton = 47;
|
|
963
|
+
|
|
964
|
+
const setFindWidgetFocus = (state, focusKey) => {
|
|
965
|
+
if (state.focus === focusKey) {
|
|
966
|
+
return state;
|
|
967
|
+
}
|
|
968
|
+
return {
|
|
969
|
+
...state,
|
|
970
|
+
focus: focusKey,
|
|
971
|
+
focusSource: Script$1
|
|
972
|
+
};
|
|
973
|
+
};
|
|
974
|
+
|
|
975
|
+
const focusCloseButton = state => {
|
|
976
|
+
return setFindWidgetFocus(state, FocusFindWidgetCloseButton);
|
|
977
|
+
};
|
|
978
|
+
|
|
950
979
|
// TODO don't call renderer worker, set editor state
|
|
951
980
|
// TODO this function should be synchronous
|
|
952
981
|
const focusIndex = (state, index) => {
|
|
@@ -974,7 +1003,10 @@ const focusIndex = (state, index) => {
|
|
|
974
1003
|
// newState,
|
|
975
1004
|
// }
|
|
976
1005
|
// const newWidgets = [...widgets.slice(0, childIndex), newWidget, ...widgets.slice(childIndex + 1)]
|
|
977
|
-
return
|
|
1006
|
+
return {
|
|
1007
|
+
...state,
|
|
1008
|
+
matchIndex: index
|
|
1009
|
+
};
|
|
978
1010
|
};
|
|
979
1011
|
const focusFirst = state => {
|
|
980
1012
|
return focusIndex(state, 0);
|
|
@@ -1005,6 +1037,14 @@ const focusPrevious = state => {
|
|
|
1005
1037
|
return focusIndex(state, matchIndex - 1);
|
|
1006
1038
|
};
|
|
1007
1039
|
|
|
1040
|
+
const focusReplace = state => {
|
|
1041
|
+
return setFindWidgetFocus(state, FocusFindWidgetReplace);
|
|
1042
|
+
};
|
|
1043
|
+
|
|
1044
|
+
const focusReplaceAllButton = state => {
|
|
1045
|
+
return setFindWidgetFocus(state, FocusFindWidgetReplaceAllButton);
|
|
1046
|
+
};
|
|
1047
|
+
|
|
1008
1048
|
const handleBlur = async state => {
|
|
1009
1049
|
return {
|
|
1010
1050
|
...state,
|
|
@@ -1076,7 +1116,8 @@ const refresh$1 = (state, value) => {
|
|
|
1076
1116
|
matches,
|
|
1077
1117
|
matchIndex: 0,
|
|
1078
1118
|
matchCount,
|
|
1079
|
-
value
|
|
1119
|
+
value,
|
|
1120
|
+
inputSource: User
|
|
1080
1121
|
};
|
|
1081
1122
|
};
|
|
1082
1123
|
|
|
@@ -1180,6 +1221,15 @@ const getLines = async editorUid => {
|
|
|
1180
1221
|
return lines;
|
|
1181
1222
|
};
|
|
1182
1223
|
|
|
1224
|
+
const getSelectedText = (lines, selections) => {
|
|
1225
|
+
const startRowIndex = selections[0];
|
|
1226
|
+
const startColumnIndex = selections[1];
|
|
1227
|
+
const endColumnIndex = selections[3];
|
|
1228
|
+
const line = lines[startRowIndex];
|
|
1229
|
+
const value = line.slice(startColumnIndex, endColumnIndex);
|
|
1230
|
+
return value;
|
|
1231
|
+
};
|
|
1232
|
+
|
|
1183
1233
|
const getSelections = async editorUid => {
|
|
1184
1234
|
// @ts-ignore
|
|
1185
1235
|
const selections = await invoke('Editor.getSelections2', editorUid);
|
|
@@ -1205,11 +1255,7 @@ const loadContent = async state => {
|
|
|
1205
1255
|
if (lines.length === 0) {
|
|
1206
1256
|
return state;
|
|
1207
1257
|
}
|
|
1208
|
-
const
|
|
1209
|
-
const startColumnIndex = selections[1];
|
|
1210
|
-
const endColumnIndex = selections[3];
|
|
1211
|
-
const line = lines[startRowIndex];
|
|
1212
|
-
const value = line.slice(startColumnIndex, endColumnIndex);
|
|
1258
|
+
const value = getSelectedText(lines, selections);
|
|
1213
1259
|
const matches = findMatchesCaseInsensitive(lines, value);
|
|
1214
1260
|
const matchCount = getMatchCount(matches);
|
|
1215
1261
|
return {
|
|
@@ -1225,7 +1271,8 @@ const loadContent = async state => {
|
|
|
1225
1271
|
height,
|
|
1226
1272
|
lines,
|
|
1227
1273
|
selections,
|
|
1228
|
-
focused: true
|
|
1274
|
+
focused: true,
|
|
1275
|
+
inputSource: Script
|
|
1229
1276
|
};
|
|
1230
1277
|
};
|
|
1231
1278
|
|
|
@@ -1272,45 +1319,41 @@ const i18nString = (key, placeholders = emptyObject) => {
|
|
|
1272
1319
|
return key.replaceAll(RE_PLACEHOLDER, replacer);
|
|
1273
1320
|
};
|
|
1274
1321
|
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
const
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
Find: 'Find',
|
|
1285
|
-
Replace: 'Replace',
|
|
1286
|
-
ReplaceAll: 'Replace All'
|
|
1287
|
-
};
|
|
1322
|
+
const MatchOf = '{PH1} of {PH2}';
|
|
1323
|
+
const NoResults = 'No Results';
|
|
1324
|
+
const Close$2 = 'Close';
|
|
1325
|
+
const PreviousMatch = 'Previous Match';
|
|
1326
|
+
const NextMatch = 'Next Match';
|
|
1327
|
+
const Find$1 = 'Find';
|
|
1328
|
+
const Replace$2 = 'Replace';
|
|
1329
|
+
const ReplaceAll$2 = 'Replace All';
|
|
1330
|
+
|
|
1288
1331
|
const noResults = () => {
|
|
1289
|
-
return i18nString(
|
|
1332
|
+
return i18nString(NoResults);
|
|
1290
1333
|
};
|
|
1291
1334
|
const matchOf = (matchIndex, matchCount) => {
|
|
1292
|
-
return i18nString(
|
|
1335
|
+
return i18nString(MatchOf, {
|
|
1293
1336
|
PH1: matchIndex,
|
|
1294
1337
|
PH2: matchCount
|
|
1295
1338
|
});
|
|
1296
1339
|
};
|
|
1297
1340
|
const previousMatch = () => {
|
|
1298
|
-
return i18nString(
|
|
1341
|
+
return i18nString(PreviousMatch);
|
|
1299
1342
|
};
|
|
1300
1343
|
const nextMatch = () => {
|
|
1301
|
-
return i18nString(
|
|
1344
|
+
return i18nString(NextMatch);
|
|
1302
1345
|
};
|
|
1303
1346
|
const close = () => {
|
|
1304
|
-
return i18nString(
|
|
1347
|
+
return i18nString(Close$2);
|
|
1305
1348
|
};
|
|
1306
1349
|
const find = () => {
|
|
1307
|
-
return i18nString(
|
|
1350
|
+
return i18nString(Find$1);
|
|
1308
1351
|
};
|
|
1309
1352
|
const replace = () => {
|
|
1310
|
-
return i18nString(
|
|
1353
|
+
return i18nString(Replace$2);
|
|
1311
1354
|
};
|
|
1312
1355
|
const replaceAll = () => {
|
|
1313
|
-
return i18nString(
|
|
1356
|
+
return i18nString(ReplaceAll$2);
|
|
1314
1357
|
};
|
|
1315
1358
|
|
|
1316
1359
|
const ArrowDown = 'ArrowDown';
|
|
@@ -1319,6 +1362,9 @@ const Close$1 = 'Close';
|
|
|
1319
1362
|
const Replace$1 = 'Replace';
|
|
1320
1363
|
const ReplaceAll$1 = 'ReplaceAll';
|
|
1321
1364
|
|
|
1365
|
+
const ToggleReplace = 'ToggleReplace';
|
|
1366
|
+
const SearchValue = 'search-value';
|
|
1367
|
+
const ReplaceValue = 'replace-value';
|
|
1322
1368
|
const ReplaceAll = 'ReplaceAll';
|
|
1323
1369
|
const Close = 'Close';
|
|
1324
1370
|
const FocusNext = 'FocusNext';
|
|
@@ -1390,6 +1436,10 @@ const SearchField = 'SearchField';
|
|
|
1390
1436
|
const SearchFieldButton = 'SearchFieldButton';
|
|
1391
1437
|
const SearchFieldButtonChecked = 'SearchFieldButtonChecked';
|
|
1392
1438
|
const SearchFieldButtons = 'SearchFieldButtons';
|
|
1439
|
+
const Viewlet = 'Viewlet';
|
|
1440
|
+
const ViewletFind = 'ViewletFind';
|
|
1441
|
+
const FindWidget = 'FindWidget';
|
|
1442
|
+
const ViewletFindWidget = 'ViewletFindWidget';
|
|
1393
1443
|
|
|
1394
1444
|
const mergeClassNames = (...classNames) => {
|
|
1395
1445
|
return classNames.filter(Boolean).join(' ');
|
|
@@ -1520,13 +1570,11 @@ const getFindWidgetReplaceVirtualDom = (replaceExpanded, replaceButtons) => {
|
|
|
1520
1570
|
type: Div,
|
|
1521
1571
|
className: FindWidgetReplace,
|
|
1522
1572
|
childCount: 1 + replaceButtons.length
|
|
1523
|
-
}, ...getSearchFieldVirtualDom(
|
|
1573
|
+
}, ...getSearchFieldVirtualDom(ReplaceValue, replace(), HandleReplaceInput, [], [], HandleReplaceFocus), ...replaceButtons.flatMap(getIconButtonVirtualDom));
|
|
1524
1574
|
}
|
|
1525
1575
|
return dom;
|
|
1526
1576
|
};
|
|
1527
1577
|
|
|
1528
|
-
const ToggleReplace = 'ToggleReplace';
|
|
1529
|
-
|
|
1530
1578
|
const getSearchToggleButtonVirtualDom = (replaceExpanded, onClick = '') => {
|
|
1531
1579
|
return [{
|
|
1532
1580
|
type: Button,
|
|
@@ -1550,7 +1598,7 @@ const getFindWidgetVirtualDom = (matchCountText, replaceExpanded, findButtons, r
|
|
|
1550
1598
|
const dom = [];
|
|
1551
1599
|
dom.push({
|
|
1552
1600
|
type: Div,
|
|
1553
|
-
className:
|
|
1601
|
+
className: mergeClassNames(Viewlet, ViewletFind, ViewletFindWidget, FindWidget),
|
|
1554
1602
|
childCount: 2,
|
|
1555
1603
|
role: Group
|
|
1556
1604
|
});
|
|
@@ -1665,6 +1713,14 @@ const renderUid = (oldState, newState) => {
|
|
|
1665
1713
|
return [SetUid, uid, editorUid];
|
|
1666
1714
|
};
|
|
1667
1715
|
|
|
1716
|
+
const renderValue = (oldState, newState) => {
|
|
1717
|
+
const {
|
|
1718
|
+
uid,
|
|
1719
|
+
value
|
|
1720
|
+
} = newState;
|
|
1721
|
+
return [/* method */'Viewlet.setValueByName', uid, SearchValue, value];
|
|
1722
|
+
};
|
|
1723
|
+
|
|
1668
1724
|
const getRenderer = diffType => {
|
|
1669
1725
|
switch (diffType) {
|
|
1670
1726
|
case RenderContent:
|
|
@@ -1679,6 +1735,8 @@ const getRenderer = diffType => {
|
|
|
1679
1735
|
return renderFocusContext;
|
|
1680
1736
|
case RenderFocus:
|
|
1681
1737
|
return renderFocus;
|
|
1738
|
+
case RenderValue:
|
|
1739
|
+
return renderValue;
|
|
1682
1740
|
default:
|
|
1683
1741
|
throw new Error('unknown renderer');
|
|
1684
1742
|
}
|
|
@@ -1710,11 +1768,14 @@ const terminate = () => {
|
|
|
1710
1768
|
const commandMap = {
|
|
1711
1769
|
'FindWidget.create': create$1,
|
|
1712
1770
|
'FindWidget.diff2': diff2,
|
|
1771
|
+
'FindWidget.focusCloseButton': wrapCommand(focusCloseButton),
|
|
1713
1772
|
'FindWidget.focusFirst': wrapCommand(focusFirst),
|
|
1714
1773
|
'FindWidget.focusIndex': wrapCommand(focusIndex),
|
|
1715
1774
|
'FindWidget.focusLast': wrapCommand(focusLast),
|
|
1716
1775
|
'FindWidget.focusNext': wrapCommand(focusNext),
|
|
1717
1776
|
'FindWidget.focusPrevious': wrapCommand(focusPrevious),
|
|
1777
|
+
'FindWidget.focusReplace': wrapCommand(focusReplace),
|
|
1778
|
+
'FindWidget.focusReplaceAllButton': wrapCommand(focusReplaceAllButton),
|
|
1718
1779
|
'FindWidget.getCommandIds': getCommandIds,
|
|
1719
1780
|
'FindWidget.handleBlur': wrapCommand(handleBlur),
|
|
1720
1781
|
'FindWidget.handleClickClose': wrapCommand(handleClickClose),
|