@lvce-editor/find-widget-worker 3.17.0 → 3.19.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 +434 -209
- package/package.json +1 -1
|
@@ -508,6 +508,9 @@ const restoreExistingError = (error, currentStack) => {
|
|
|
508
508
|
};
|
|
509
509
|
const restoreMethodNotFoundError = (error, currentStack) => {
|
|
510
510
|
const restoredError = new JsonRpcError(error.message);
|
|
511
|
+
Object.assign(restoredError, {
|
|
512
|
+
code: error.code
|
|
513
|
+
});
|
|
511
514
|
const parentStack = getParentStack(error);
|
|
512
515
|
setStack(restoredError, `${parentStack}${NewLine}${currentStack}`);
|
|
513
516
|
return restoredError;
|
|
@@ -527,9 +530,13 @@ const applyDataProperties = (restoredError, error) => {
|
|
|
527
530
|
// @ts-ignore
|
|
528
531
|
restoredError.codeFrame = error.data.codeFrame;
|
|
529
532
|
}
|
|
530
|
-
if (error.data.code) {
|
|
533
|
+
if (typeof error.data.code === 'string' || typeof error.data.code === 'number') {
|
|
531
534
|
// @ts-ignore
|
|
532
|
-
restoredError
|
|
535
|
+
Object.defineProperty(restoredError, 'code', {
|
|
536
|
+
configurable: true,
|
|
537
|
+
value: error.data.code,
|
|
538
|
+
writable: true
|
|
539
|
+
});
|
|
533
540
|
}
|
|
534
541
|
if (error.data.type) {
|
|
535
542
|
// @ts-ignore
|
|
@@ -550,7 +557,14 @@ const applyDirectProperties = (restoredError, error) => {
|
|
|
550
557
|
}
|
|
551
558
|
};
|
|
552
559
|
const restoreMessageError = (error, _currentStack) => {
|
|
553
|
-
const restoredError = constructError(error.message, error.type, error.name);
|
|
560
|
+
const restoredError = constructError(error.message, error.type || error.data?.type, error.name);
|
|
561
|
+
if (typeof error.code === 'string' || typeof error.code === 'number') {
|
|
562
|
+
Object.defineProperty(restoredError, 'code', {
|
|
563
|
+
configurable: true,
|
|
564
|
+
value: error.code,
|
|
565
|
+
writable: true
|
|
566
|
+
});
|
|
567
|
+
}
|
|
554
568
|
if (error.data) {
|
|
555
569
|
applyDataProperties(restoredError, error);
|
|
556
570
|
} else {
|
|
@@ -558,6 +572,23 @@ const restoreMessageError = (error, _currentStack) => {
|
|
|
558
572
|
}
|
|
559
573
|
return restoredError;
|
|
560
574
|
};
|
|
575
|
+
const getFallbackMessage = error => {
|
|
576
|
+
if (error && typeof error.message === 'string' && error.message) {
|
|
577
|
+
return error.message;
|
|
578
|
+
}
|
|
579
|
+
if (error && error.data) {
|
|
580
|
+
return getFallbackMessage(error.data);
|
|
581
|
+
}
|
|
582
|
+
const stringified = String(error);
|
|
583
|
+
if (stringified !== '[object Object]') {
|
|
584
|
+
return stringified;
|
|
585
|
+
}
|
|
586
|
+
try {
|
|
587
|
+
return JSON.stringify(error);
|
|
588
|
+
} catch {
|
|
589
|
+
return stringified;
|
|
590
|
+
}
|
|
591
|
+
};
|
|
561
592
|
const restoreJsonRpcError = error => {
|
|
562
593
|
const currentStack = getCurrentStack();
|
|
563
594
|
if (error && error instanceof Error) {
|
|
@@ -566,13 +597,13 @@ const restoreJsonRpcError = error => {
|
|
|
566
597
|
if (error && error.code && error.code === MethodNotFound) {
|
|
567
598
|
return restoreMethodNotFoundError(error, currentStack);
|
|
568
599
|
}
|
|
600
|
+
if (error && error.error) {
|
|
601
|
+
return restoreJsonRpcError(error.error);
|
|
602
|
+
}
|
|
569
603
|
if (error && error.message) {
|
|
570
604
|
return restoreMessageError(error);
|
|
571
605
|
}
|
|
572
|
-
|
|
573
|
-
return new Error(`JsonRpc Error: ${error}`);
|
|
574
|
-
}
|
|
575
|
-
return new Error(`JsonRpc Error: ${error}`);
|
|
606
|
+
return new Error(`JsonRpc Error: ${getFallbackMessage(error)}`);
|
|
576
607
|
};
|
|
577
608
|
const unwrapJsonRpcResult = responseMessage => {
|
|
578
609
|
if ('error' in responseMessage) {
|
|
@@ -629,9 +660,9 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
629
660
|
return {
|
|
630
661
|
code: Custom,
|
|
631
662
|
data: {
|
|
632
|
-
code: prettyError.code,
|
|
663
|
+
code: prettyError.code ?? error?.code,
|
|
633
664
|
codeFrame: prettyError.codeFrame,
|
|
634
|
-
name: prettyError.name,
|
|
665
|
+
name: prettyError.name ?? error?.name,
|
|
635
666
|
stack: getStack(prettyError),
|
|
636
667
|
type: getErrorType(prettyError)
|
|
637
668
|
},
|
|
@@ -666,7 +697,12 @@ const getErrorResponseSimple = (id, error) => {
|
|
|
666
697
|
return {
|
|
667
698
|
error: {
|
|
668
699
|
code: Custom,
|
|
669
|
-
data: error
|
|
700
|
+
data: error instanceof Error ? {
|
|
701
|
+
...error,
|
|
702
|
+
code: 'code' in error ? error.code : undefined,
|
|
703
|
+
stack: error.stack,
|
|
704
|
+
type: error.name
|
|
705
|
+
} : error,
|
|
670
706
|
// @ts-ignore
|
|
671
707
|
message: error.message
|
|
672
708
|
},
|
|
@@ -955,175 +991,12 @@ const CheckBox = 'checkbox';
|
|
|
955
991
|
const Group = 'group';
|
|
956
992
|
const None = 'none';
|
|
957
993
|
|
|
958
|
-
const Audio = 0;
|
|
959
994
|
const Button = 1;
|
|
960
|
-
const Col = 2;
|
|
961
|
-
const ColGroup = 3;
|
|
962
995
|
const Div = 4;
|
|
963
|
-
const H1 = 5;
|
|
964
|
-
const Input = 6;
|
|
965
|
-
const Kbd = 7;
|
|
966
|
-
const Span = 8;
|
|
967
|
-
const Table = 9;
|
|
968
|
-
const TBody = 10;
|
|
969
|
-
const Td = 11;
|
|
970
996
|
const Text = 12;
|
|
971
|
-
const Th = 13;
|
|
972
|
-
const THead = 14;
|
|
973
|
-
const Tr = 15;
|
|
974
|
-
const I = 16;
|
|
975
|
-
const Img = 17;
|
|
976
|
-
const Root = 0;
|
|
977
|
-
const Ins = 20;
|
|
978
|
-
const Del = 21;
|
|
979
|
-
const H2 = 22;
|
|
980
|
-
const H3 = 23;
|
|
981
|
-
const H4 = 24;
|
|
982
|
-
const H5 = 25;
|
|
983
|
-
const H6 = 26;
|
|
984
|
-
const Article = 27;
|
|
985
|
-
const Aside = 28;
|
|
986
|
-
const Footer = 29;
|
|
987
|
-
const Header = 30;
|
|
988
|
-
const Nav = 40;
|
|
989
|
-
const Section = 41;
|
|
990
|
-
const Search = 42;
|
|
991
|
-
const Dd = 43;
|
|
992
|
-
const Dl = 44;
|
|
993
|
-
const Figcaption = 45;
|
|
994
|
-
const Figure = 46;
|
|
995
|
-
const Hr = 47;
|
|
996
|
-
const Li = 48;
|
|
997
|
-
const Ol = 49;
|
|
998
|
-
const P = 50;
|
|
999
|
-
const Pre = 51;
|
|
1000
|
-
const A = 53;
|
|
1001
|
-
const Abbr = 54;
|
|
1002
|
-
const Br = 55;
|
|
1003
|
-
const Cite = 56;
|
|
1004
|
-
const Data = 57;
|
|
1005
|
-
const Time = 58;
|
|
1006
|
-
const Tfoot = 59;
|
|
1007
|
-
const Ul = 60;
|
|
1008
|
-
const Video = 61;
|
|
1009
997
|
const TextArea = 62;
|
|
1010
|
-
const Select = 63;
|
|
1011
|
-
const Option = 64;
|
|
1012
|
-
const Code = 65;
|
|
1013
|
-
const Label = 66;
|
|
1014
|
-
const Dt = 67;
|
|
1015
|
-
const Iframe = 68;
|
|
1016
|
-
const Main = 69;
|
|
1017
|
-
const Strong = 70;
|
|
1018
|
-
const Em = 71;
|
|
1019
|
-
const Style = 72;
|
|
1020
|
-
const Html = 73;
|
|
1021
|
-
const Head = 74;
|
|
1022
|
-
const Title = 75;
|
|
1023
|
-
const Meta = 76;
|
|
1024
|
-
const Canvas = 77;
|
|
1025
|
-
const Form = 78;
|
|
1026
|
-
const BlockQuote = 79;
|
|
1027
|
-
const Quote = 80;
|
|
1028
|
-
const Circle = 81;
|
|
1029
|
-
const Defs = 82;
|
|
1030
|
-
const Ellipse = 83;
|
|
1031
|
-
const G = 84;
|
|
1032
|
-
const Line = 85;
|
|
1033
|
-
const Path = 86;
|
|
1034
|
-
const Polygon = 87;
|
|
1035
|
-
const Polyline = 88;
|
|
1036
|
-
const Rect = 89;
|
|
1037
|
-
const Svg = 90;
|
|
1038
|
-
const Use = 91;
|
|
1039
998
|
const Reference = 100;
|
|
1040
999
|
|
|
1041
|
-
const VirtualDomElements = {
|
|
1042
|
-
__proto__: null,
|
|
1043
|
-
A,
|
|
1044
|
-
Abbr,
|
|
1045
|
-
Article,
|
|
1046
|
-
Aside,
|
|
1047
|
-
Audio,
|
|
1048
|
-
BlockQuote,
|
|
1049
|
-
Br,
|
|
1050
|
-
Button,
|
|
1051
|
-
Canvas,
|
|
1052
|
-
Circle,
|
|
1053
|
-
Cite,
|
|
1054
|
-
Code,
|
|
1055
|
-
Col,
|
|
1056
|
-
ColGroup,
|
|
1057
|
-
Data,
|
|
1058
|
-
Dd,
|
|
1059
|
-
Defs,
|
|
1060
|
-
Del,
|
|
1061
|
-
Div,
|
|
1062
|
-
Dl,
|
|
1063
|
-
Dt,
|
|
1064
|
-
Ellipse,
|
|
1065
|
-
Em,
|
|
1066
|
-
Figcaption,
|
|
1067
|
-
Figure,
|
|
1068
|
-
Footer,
|
|
1069
|
-
Form,
|
|
1070
|
-
G,
|
|
1071
|
-
H1,
|
|
1072
|
-
H2,
|
|
1073
|
-
H3,
|
|
1074
|
-
H4,
|
|
1075
|
-
H5,
|
|
1076
|
-
H6,
|
|
1077
|
-
Head,
|
|
1078
|
-
Header,
|
|
1079
|
-
Hr,
|
|
1080
|
-
Html,
|
|
1081
|
-
I,
|
|
1082
|
-
Iframe,
|
|
1083
|
-
Img,
|
|
1084
|
-
Input,
|
|
1085
|
-
Ins,
|
|
1086
|
-
Kbd,
|
|
1087
|
-
Label,
|
|
1088
|
-
Li,
|
|
1089
|
-
Line,
|
|
1090
|
-
Main,
|
|
1091
|
-
Meta,
|
|
1092
|
-
Nav,
|
|
1093
|
-
Ol,
|
|
1094
|
-
Option,
|
|
1095
|
-
P,
|
|
1096
|
-
Path,
|
|
1097
|
-
Polygon,
|
|
1098
|
-
Polyline,
|
|
1099
|
-
Pre,
|
|
1100
|
-
Quote,
|
|
1101
|
-
Rect,
|
|
1102
|
-
Reference,
|
|
1103
|
-
Root,
|
|
1104
|
-
Search,
|
|
1105
|
-
Section,
|
|
1106
|
-
Select,
|
|
1107
|
-
Span,
|
|
1108
|
-
Strong,
|
|
1109
|
-
Style,
|
|
1110
|
-
Svg,
|
|
1111
|
-
TBody,
|
|
1112
|
-
THead,
|
|
1113
|
-
Table,
|
|
1114
|
-
Td,
|
|
1115
|
-
Text,
|
|
1116
|
-
TextArea,
|
|
1117
|
-
Tfoot,
|
|
1118
|
-
Th,
|
|
1119
|
-
Time,
|
|
1120
|
-
Title,
|
|
1121
|
-
Tr,
|
|
1122
|
-
Ul,
|
|
1123
|
-
Use,
|
|
1124
|
-
Video
|
|
1125
|
-
};
|
|
1126
|
-
|
|
1127
1000
|
const ClientX = 'event.clientX';
|
|
1128
1001
|
const ClientY = 'event.clientY';
|
|
1129
1002
|
const TargetName = 'event.target.name';
|
|
@@ -1148,6 +1021,7 @@ const FocusSelector = 'Viewlet.focusSelector';
|
|
|
1148
1021
|
const SetCss = 'Viewlet.setCss';
|
|
1149
1022
|
const SetFocusContext = 'Viewlet.setFocusContext';
|
|
1150
1023
|
const SetValueByName = 'Viewlet.setValueByName';
|
|
1024
|
+
const SetPatches = 'Viewlet.setPatches';
|
|
1151
1025
|
|
|
1152
1026
|
const Empty = 0;
|
|
1153
1027
|
const FocusFindWidget$1 = 16;
|
|
@@ -1192,7 +1066,8 @@ const create$1 = () => {
|
|
|
1192
1066
|
const commandQueues = new Map();
|
|
1193
1067
|
const generations = Object.create(null);
|
|
1194
1068
|
const states = Object.create(null);
|
|
1195
|
-
const commandMapRef =
|
|
1069
|
+
const commandMapRef = Object.create(null);
|
|
1070
|
+
const commandsById = Object.create(null);
|
|
1196
1071
|
const getGeneration = uid => generations[uid] || 0;
|
|
1197
1072
|
const isCurrentGeneration = (uid, generation) => {
|
|
1198
1073
|
return states[uid] !== undefined && getGeneration(uid) === generation;
|
|
@@ -1254,6 +1129,18 @@ const create$1 = () => {
|
|
|
1254
1129
|
delete states[key];
|
|
1255
1130
|
}
|
|
1256
1131
|
},
|
|
1132
|
+
createDirectEventCommandMap(requestRender) {
|
|
1133
|
+
return {
|
|
1134
|
+
async 'Viewlet.executeViewletCommand'(uid, command, ...args) {
|
|
1135
|
+
const fn = commandsById[command];
|
|
1136
|
+
if (!fn) {
|
|
1137
|
+
throw new Error(`Viewlet command not found: ${command}`);
|
|
1138
|
+
}
|
|
1139
|
+
await fn(uid, ...args);
|
|
1140
|
+
await requestRender(uid);
|
|
1141
|
+
}
|
|
1142
|
+
};
|
|
1143
|
+
},
|
|
1257
1144
|
diff(uid, modules, numbers) {
|
|
1258
1145
|
const {
|
|
1259
1146
|
oldState,
|
|
@@ -1285,6 +1172,9 @@ const create$1 = () => {
|
|
|
1285
1172
|
},
|
|
1286
1173
|
registerCommands(commandMap) {
|
|
1287
1174
|
Object.assign(commandMapRef, commandMap);
|
|
1175
|
+
for (const [key, fn] of Object.entries(commandMap)) {
|
|
1176
|
+
commandsById[toCommandId(key)] = fn;
|
|
1177
|
+
}
|
|
1288
1178
|
},
|
|
1289
1179
|
set(uid, oldState, newState, scheduledState) {
|
|
1290
1180
|
const current = states[uid];
|
|
@@ -1600,7 +1490,7 @@ const isEqual$4 = (oldState, newState) => {
|
|
|
1600
1490
|
};
|
|
1601
1491
|
|
|
1602
1492
|
const isEqual$3 = (oldState, newState) => {
|
|
1603
|
-
return oldState.inputErrorMessage === newState.inputErrorMessage && oldState.matchCase === newState.matchCase && oldState.matchCount === newState.matchCount && oldState.matchIndex === newState.matchIndex && oldState.matchWholeWord === newState.matchWholeWord && oldState.preserveCase === newState.preserveCase && oldState.replaceExpanded === newState.replaceExpanded && oldState.useRegularExpression === newState.useRegularExpression && oldState.version === newState.version;
|
|
1493
|
+
return oldState.inputErrorMessage === newState.inputErrorMessage && oldState.focus === newState.focus && oldState.matchCase === newState.matchCase && oldState.matchCount === newState.matchCount && oldState.matchIndex === newState.matchIndex && oldState.matchWholeWord === newState.matchWholeWord && oldState.preserveCase === newState.preserveCase && oldState.replaceExpanded === newState.replaceExpanded && oldState.useRegularExpression === newState.useRegularExpression && oldState.value === newState.value && oldState.version === newState.version;
|
|
1604
1494
|
};
|
|
1605
1495
|
|
|
1606
1496
|
const isEqual$2 = (oldState, newState) => {
|
|
@@ -1816,6 +1706,14 @@ const buildRegex = (searchString, options) => {
|
|
|
1816
1706
|
}
|
|
1817
1707
|
};
|
|
1818
1708
|
|
|
1709
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- Appends matches to the shared output array.
|
|
1710
|
+
const collectMatchesForLineInternal = (matches, line, lineIndex, regex) => {
|
|
1711
|
+
let lastMatch = regex.exec(line);
|
|
1712
|
+
while (lastMatch) {
|
|
1713
|
+
matches.push(lineIndex, lastMatch.index, lastMatch[0].length);
|
|
1714
|
+
lastMatch = regex.exec(line);
|
|
1715
|
+
}
|
|
1716
|
+
};
|
|
1819
1717
|
const findRegexMatches = (lines, regex) => {
|
|
1820
1718
|
if (!regex.global) {
|
|
1821
1719
|
throw new Error('regex must be global');
|
|
@@ -1824,15 +1722,8 @@ const findRegexMatches = (lines, regex) => {
|
|
|
1824
1722
|
length
|
|
1825
1723
|
} = lines;
|
|
1826
1724
|
const matches = [];
|
|
1827
|
-
const collectMatchesForLine = (line, lineIndex) => {
|
|
1828
|
-
let lastMatch = regex.exec(line);
|
|
1829
|
-
while (lastMatch) {
|
|
1830
|
-
matches.push(lineIndex, lastMatch.index, lastMatch[0].length);
|
|
1831
|
-
lastMatch = regex.exec(line);
|
|
1832
|
-
}
|
|
1833
|
-
};
|
|
1834
1725
|
for (let i = 0; i < length; i++) {
|
|
1835
|
-
|
|
1726
|
+
collectMatchesForLineInternal(matches, lines[i], i, regex);
|
|
1836
1727
|
}
|
|
1837
1728
|
return new Uint32Array(matches);
|
|
1838
1729
|
};
|
|
@@ -1974,11 +1865,11 @@ const togglePreserveCase = state => {
|
|
|
1974
1865
|
const {
|
|
1975
1866
|
preserveCase
|
|
1976
1867
|
} = state;
|
|
1977
|
-
|
|
1978
|
-
return {
|
|
1868
|
+
const newState = {
|
|
1979
1869
|
...state,
|
|
1980
1870
|
preserveCase: !preserveCase
|
|
1981
1871
|
};
|
|
1872
|
+
return refresh(newState, newState.value, User$1);
|
|
1982
1873
|
};
|
|
1983
1874
|
|
|
1984
1875
|
const toggleUseRegularExpression = state => {
|
|
@@ -1998,7 +1889,7 @@ const FocusPrevious = 'FocusPrevious';
|
|
|
1998
1889
|
const MatchCase$2 = 'MatchCase';
|
|
1999
1890
|
const MatchWholeWord$2 = 'MatchWholeWord';
|
|
2000
1891
|
const PreserveCase$1 = 'PreserveCase';
|
|
2001
|
-
const Replace$
|
|
1892
|
+
const Replace$3 = 'Replace';
|
|
2002
1893
|
const ReplaceAll$2 = 'ReplaceAll';
|
|
2003
1894
|
const ReplaceValue = 'replace-value';
|
|
2004
1895
|
const SearchValue = 'search-value';
|
|
@@ -2253,7 +2144,7 @@ const getClickHandler = name => {
|
|
|
2253
2144
|
return toggleMatchWholeWord;
|
|
2254
2145
|
case PreserveCase$1:
|
|
2255
2146
|
return togglePreserveCase;
|
|
2256
|
-
case Replace$
|
|
2147
|
+
case Replace$3:
|
|
2257
2148
|
return replace$1;
|
|
2258
2149
|
case ReplaceAll$2:
|
|
2259
2150
|
return replaceAll$1;
|
|
@@ -2278,7 +2169,7 @@ const getFindWidgetFocusKey = name => {
|
|
|
2278
2169
|
return FocusSearchWholeWord;
|
|
2279
2170
|
case PreserveCase$1:
|
|
2280
2171
|
return FocusSearchPreserveCase;
|
|
2281
|
-
case Replace$
|
|
2172
|
+
case Replace$3:
|
|
2282
2173
|
return FocusFindWidgetReplaceButton$1;
|
|
2283
2174
|
case ReplaceAll$2:
|
|
2284
2175
|
return FocusFindWidgetReplaceAllButton$1;
|
|
@@ -2796,6 +2687,343 @@ const renderBounds = (oldState, newState) => {
|
|
|
2796
2687
|
return [SetBounds, uid, x, y, width, height];
|
|
2797
2688
|
};
|
|
2798
2689
|
|
|
2690
|
+
const mergeClassNames = (...classNames) => {
|
|
2691
|
+
return classNames.filter(Boolean).join(' ');
|
|
2692
|
+
};
|
|
2693
|
+
|
|
2694
|
+
const text = data => {
|
|
2695
|
+
return {
|
|
2696
|
+
childCount: 0,
|
|
2697
|
+
text: data,
|
|
2698
|
+
type: Text
|
|
2699
|
+
};
|
|
2700
|
+
};
|
|
2701
|
+
|
|
2702
|
+
const SetText = 1;
|
|
2703
|
+
const Replace$2 = 2;
|
|
2704
|
+
const SetAttribute = 3;
|
|
2705
|
+
const RemoveAttribute = 4;
|
|
2706
|
+
const Add = 6;
|
|
2707
|
+
const NavigateChild = 7;
|
|
2708
|
+
const NavigateParent = 8;
|
|
2709
|
+
const RemoveChild = 9;
|
|
2710
|
+
const NavigateSibling = 10;
|
|
2711
|
+
const SetReferenceNodeUid = 11;
|
|
2712
|
+
const MultiNavigation = 18;
|
|
2713
|
+
|
|
2714
|
+
const isKey = key => {
|
|
2715
|
+
return key !== 'type' && key !== 'childCount';
|
|
2716
|
+
};
|
|
2717
|
+
|
|
2718
|
+
const getKeys = node => {
|
|
2719
|
+
const keys = Object.keys(node).filter(isKey);
|
|
2720
|
+
return keys;
|
|
2721
|
+
};
|
|
2722
|
+
|
|
2723
|
+
const arrayToTree = nodes => {
|
|
2724
|
+
const result = [];
|
|
2725
|
+
let i = 0;
|
|
2726
|
+
while (i < nodes.length) {
|
|
2727
|
+
const node = nodes[i];
|
|
2728
|
+
const {
|
|
2729
|
+
children,
|
|
2730
|
+
nodesConsumed
|
|
2731
|
+
} = getChildrenWithCount(nodes, i + 1, node.childCount || 0);
|
|
2732
|
+
result.push({
|
|
2733
|
+
node,
|
|
2734
|
+
children
|
|
2735
|
+
});
|
|
2736
|
+
i += 1 + nodesConsumed;
|
|
2737
|
+
}
|
|
2738
|
+
return result;
|
|
2739
|
+
};
|
|
2740
|
+
const getChildrenWithCount = (nodes, startIndex, childCount) => {
|
|
2741
|
+
if (childCount === 0) {
|
|
2742
|
+
return {
|
|
2743
|
+
children: [],
|
|
2744
|
+
nodesConsumed: 0
|
|
2745
|
+
};
|
|
2746
|
+
}
|
|
2747
|
+
const children = [];
|
|
2748
|
+
let i = startIndex;
|
|
2749
|
+
let remaining = childCount;
|
|
2750
|
+
let totalConsumed = 0;
|
|
2751
|
+
while (remaining > 0 && i < nodes.length) {
|
|
2752
|
+
const node = nodes[i];
|
|
2753
|
+
const nodeChildCount = node.childCount || 0;
|
|
2754
|
+
const {
|
|
2755
|
+
children: nodeChildren,
|
|
2756
|
+
nodesConsumed
|
|
2757
|
+
} = getChildrenWithCount(nodes, i + 1, nodeChildCount);
|
|
2758
|
+
children.push({
|
|
2759
|
+
node,
|
|
2760
|
+
children: nodeChildren
|
|
2761
|
+
});
|
|
2762
|
+
const nodeSize = 1 + nodesConsumed;
|
|
2763
|
+
i += nodeSize;
|
|
2764
|
+
totalConsumed += nodeSize;
|
|
2765
|
+
remaining--;
|
|
2766
|
+
}
|
|
2767
|
+
return {
|
|
2768
|
+
children,
|
|
2769
|
+
nodesConsumed: totalConsumed
|
|
2770
|
+
};
|
|
2771
|
+
};
|
|
2772
|
+
|
|
2773
|
+
const isNavigationPatch = patch => {
|
|
2774
|
+
switch (patch.type) {
|
|
2775
|
+
case NavigateChild:
|
|
2776
|
+
case NavigateParent:
|
|
2777
|
+
case NavigateSibling:
|
|
2778
|
+
return true;
|
|
2779
|
+
default:
|
|
2780
|
+
return false;
|
|
2781
|
+
}
|
|
2782
|
+
};
|
|
2783
|
+
const getNavigationIndex = patch => {
|
|
2784
|
+
switch (patch.type) {
|
|
2785
|
+
case NavigateChild:
|
|
2786
|
+
case NavigateSibling:
|
|
2787
|
+
return patch.index;
|
|
2788
|
+
default:
|
|
2789
|
+
return 0;
|
|
2790
|
+
}
|
|
2791
|
+
};
|
|
2792
|
+
const appendNavigationPatch = (patches, type, index) => {
|
|
2793
|
+
const previousPatch = patches.at(-1);
|
|
2794
|
+
if (!previousPatch) {
|
|
2795
|
+
patches.push(type === NavigateParent ? {
|
|
2796
|
+
type
|
|
2797
|
+
} : {
|
|
2798
|
+
index,
|
|
2799
|
+
type
|
|
2800
|
+
});
|
|
2801
|
+
return;
|
|
2802
|
+
}
|
|
2803
|
+
if (previousPatch.type === MultiNavigation) {
|
|
2804
|
+
previousPatch.navigations.push(type, index);
|
|
2805
|
+
return;
|
|
2806
|
+
}
|
|
2807
|
+
if (isNavigationPatch(previousPatch)) {
|
|
2808
|
+
patches[patches.length - 1] = {
|
|
2809
|
+
navigations: [previousPatch.type, getNavigationIndex(previousPatch), type, index],
|
|
2810
|
+
type: MultiNavigation
|
|
2811
|
+
};
|
|
2812
|
+
return;
|
|
2813
|
+
}
|
|
2814
|
+
patches.push(type === NavigateParent ? {
|
|
2815
|
+
type
|
|
2816
|
+
} : {
|
|
2817
|
+
index,
|
|
2818
|
+
type
|
|
2819
|
+
});
|
|
2820
|
+
};
|
|
2821
|
+
|
|
2822
|
+
const compareNodes = (oldNode, newNode) => {
|
|
2823
|
+
// Check if node type changed - return null to signal incompatible nodes
|
|
2824
|
+
// (caller should handle this with a Replace operation)
|
|
2825
|
+
if (oldNode.type !== newNode.type) {
|
|
2826
|
+
return null;
|
|
2827
|
+
}
|
|
2828
|
+
const patches = [];
|
|
2829
|
+
// Handle reference nodes - special handling for uid changes
|
|
2830
|
+
if (oldNode.type === Reference && oldNode.uid !== newNode.uid) {
|
|
2831
|
+
patches.push({
|
|
2832
|
+
type: SetReferenceNodeUid,
|
|
2833
|
+
uid: newNode.uid
|
|
2834
|
+
});
|
|
2835
|
+
}
|
|
2836
|
+
// Handle text nodes
|
|
2837
|
+
if (oldNode.type === Text && newNode.type === Text) {
|
|
2838
|
+
if (oldNode.text !== newNode.text) {
|
|
2839
|
+
patches.push({
|
|
2840
|
+
type: SetText,
|
|
2841
|
+
value: newNode.text
|
|
2842
|
+
});
|
|
2843
|
+
}
|
|
2844
|
+
return patches;
|
|
2845
|
+
}
|
|
2846
|
+
// Compare attributes
|
|
2847
|
+
const oldKeys = getKeys(oldNode).filter(key => oldNode.type !== Reference || key !== 'uid');
|
|
2848
|
+
const newKeys = getKeys(newNode).filter(key => newNode.type !== Reference || key !== 'uid');
|
|
2849
|
+
// Check for attribute changes
|
|
2850
|
+
for (const key of newKeys) {
|
|
2851
|
+
if (oldNode[key] !== newNode[key]) {
|
|
2852
|
+
patches.push({
|
|
2853
|
+
type: SetAttribute,
|
|
2854
|
+
key,
|
|
2855
|
+
value: newNode[key]
|
|
2856
|
+
});
|
|
2857
|
+
}
|
|
2858
|
+
}
|
|
2859
|
+
// Check for removed attributes
|
|
2860
|
+
for (const key of oldKeys) {
|
|
2861
|
+
if (!Object.hasOwn(newNode, key)) {
|
|
2862
|
+
patches.push({
|
|
2863
|
+
type: RemoveAttribute,
|
|
2864
|
+
key
|
|
2865
|
+
});
|
|
2866
|
+
}
|
|
2867
|
+
}
|
|
2868
|
+
return patches;
|
|
2869
|
+
};
|
|
2870
|
+
|
|
2871
|
+
const treeToArray = node => {
|
|
2872
|
+
const result = [];
|
|
2873
|
+
const stack = [node];
|
|
2874
|
+
while (stack.length > 0) {
|
|
2875
|
+
const current = stack.pop();
|
|
2876
|
+
result.push(current.node);
|
|
2877
|
+
for (let i = current.children.length - 1; i >= 0; i--) {
|
|
2878
|
+
stack.push(current.children[i]);
|
|
2879
|
+
}
|
|
2880
|
+
}
|
|
2881
|
+
return result;
|
|
2882
|
+
};
|
|
2883
|
+
|
|
2884
|
+
const navigateToChild = (patches, currentChildIndex, index) => {
|
|
2885
|
+
if (currentChildIndex === -1) {
|
|
2886
|
+
appendNavigationPatch(patches, NavigateChild, index);
|
|
2887
|
+
return index;
|
|
2888
|
+
}
|
|
2889
|
+
if (currentChildIndex !== index) {
|
|
2890
|
+
appendNavigationPatch(patches, NavigateSibling, index);
|
|
2891
|
+
}
|
|
2892
|
+
return index;
|
|
2893
|
+
};
|
|
2894
|
+
const navigateToParent = (patches, currentChildIndex) => {
|
|
2895
|
+
if (currentChildIndex >= 0) {
|
|
2896
|
+
appendNavigationPatch(patches, NavigateParent, 0);
|
|
2897
|
+
}
|
|
2898
|
+
return -1;
|
|
2899
|
+
};
|
|
2900
|
+
const addTree = (newNode, patches) => {
|
|
2901
|
+
patches.push({
|
|
2902
|
+
type: Add,
|
|
2903
|
+
nodes: treeToArray(newNode)
|
|
2904
|
+
});
|
|
2905
|
+
};
|
|
2906
|
+
const replaceTree = (newNode, patches) => {
|
|
2907
|
+
patches.push({
|
|
2908
|
+
type: Replace$2,
|
|
2909
|
+
nodes: treeToArray(newNode)
|
|
2910
|
+
});
|
|
2911
|
+
};
|
|
2912
|
+
const appendPatch = (patches, patch) => {
|
|
2913
|
+
switch (patch.type) {
|
|
2914
|
+
case MultiNavigation:
|
|
2915
|
+
for (let i = 0; i < patch.navigations.length; i += 2) {
|
|
2916
|
+
appendNavigationPatch(patches, patch.navigations[i], patch.navigations[i + 1]);
|
|
2917
|
+
}
|
|
2918
|
+
return;
|
|
2919
|
+
case NavigateChild:
|
|
2920
|
+
case NavigateSibling:
|
|
2921
|
+
appendNavigationPatch(patches, patch.type, patch.index);
|
|
2922
|
+
return;
|
|
2923
|
+
case NavigateParent:
|
|
2924
|
+
appendNavigationPatch(patches, patch.type, 0);
|
|
2925
|
+
return;
|
|
2926
|
+
default:
|
|
2927
|
+
patches.push(patch);
|
|
2928
|
+
}
|
|
2929
|
+
};
|
|
2930
|
+
const appendPatches = (patches, newPatches) => {
|
|
2931
|
+
for (const patch of newPatches) {
|
|
2932
|
+
appendPatch(patches, patch);
|
|
2933
|
+
}
|
|
2934
|
+
};
|
|
2935
|
+
const diffExistingChild = (oldNode, newNode, patches, currentChildIndex, index) => {
|
|
2936
|
+
const nodePatches = compareNodes(oldNode.node, newNode.node);
|
|
2937
|
+
if (nodePatches === null) {
|
|
2938
|
+
const nextChildIndex = navigateToChild(patches, currentChildIndex, index);
|
|
2939
|
+
replaceTree(newNode, patches);
|
|
2940
|
+
return nextChildIndex;
|
|
2941
|
+
}
|
|
2942
|
+
const hasChildrenToCompare = oldNode.children.length > 0 || newNode.children.length > 0;
|
|
2943
|
+
const childPatches = [];
|
|
2944
|
+
if (hasChildrenToCompare) {
|
|
2945
|
+
diffChildren(oldNode.children, newNode.children, childPatches);
|
|
2946
|
+
}
|
|
2947
|
+
if (nodePatches.length === 0 && childPatches.length === 0) {
|
|
2948
|
+
return currentChildIndex;
|
|
2949
|
+
}
|
|
2950
|
+
const nextChildIndex = navigateToChild(patches, currentChildIndex, index);
|
|
2951
|
+
patches.push(...nodePatches);
|
|
2952
|
+
appendPatches(patches, childPatches);
|
|
2953
|
+
return nextChildIndex;
|
|
2954
|
+
};
|
|
2955
|
+
const diffRootNode = (oldNode, newNode, patches) => {
|
|
2956
|
+
const nodePatches = compareNodes(oldNode.node, newNode.node);
|
|
2957
|
+
if (nodePatches === null) {
|
|
2958
|
+
replaceTree(newNode, patches);
|
|
2959
|
+
return;
|
|
2960
|
+
}
|
|
2961
|
+
if (nodePatches.length > 0) {
|
|
2962
|
+
patches.push(...nodePatches);
|
|
2963
|
+
}
|
|
2964
|
+
if (oldNode.children.length > 0 || newNode.children.length > 0) {
|
|
2965
|
+
diffChildren(oldNode.children, newNode.children, patches);
|
|
2966
|
+
}
|
|
2967
|
+
};
|
|
2968
|
+
const diffChildren = (oldChildren, newChildren, patches) => {
|
|
2969
|
+
const maxLength = Math.max(oldChildren.length, newChildren.length);
|
|
2970
|
+
let currentChildIndex = -1;
|
|
2971
|
+
const indicesToRemove = [];
|
|
2972
|
+
for (let i = 0; i < maxLength; i++) {
|
|
2973
|
+
const oldNode = oldChildren[i];
|
|
2974
|
+
const newNode = newChildren[i];
|
|
2975
|
+
if (!oldNode && !newNode) {
|
|
2976
|
+
continue;
|
|
2977
|
+
}
|
|
2978
|
+
if (!oldNode) {
|
|
2979
|
+
currentChildIndex = navigateToParent(patches, currentChildIndex);
|
|
2980
|
+
addTree(newNode, patches);
|
|
2981
|
+
continue;
|
|
2982
|
+
}
|
|
2983
|
+
if (!newNode) {
|
|
2984
|
+
indicesToRemove.push(i);
|
|
2985
|
+
continue;
|
|
2986
|
+
}
|
|
2987
|
+
currentChildIndex = diffExistingChild(oldNode, newNode, patches, currentChildIndex, i);
|
|
2988
|
+
}
|
|
2989
|
+
navigateToParent(patches, currentChildIndex);
|
|
2990
|
+
for (let j = indicesToRemove.length - 1; j >= 0; j--) {
|
|
2991
|
+
patches.push({
|
|
2992
|
+
type: RemoveChild,
|
|
2993
|
+
index: indicesToRemove[j]
|
|
2994
|
+
});
|
|
2995
|
+
}
|
|
2996
|
+
};
|
|
2997
|
+
const diffTrees = (oldTree, newTree, patches, path) => {
|
|
2998
|
+
if (path.length === 0 && oldTree.length === 1 && newTree.length === 1) {
|
|
2999
|
+
diffRootNode(oldTree[0], newTree[0], patches);
|
|
3000
|
+
return;
|
|
3001
|
+
}
|
|
3002
|
+
diffChildren(oldTree, newTree, patches);
|
|
3003
|
+
};
|
|
3004
|
+
|
|
3005
|
+
const removeTrailingNavigationPatches = patches => {
|
|
3006
|
+
while (patches.length > 0) {
|
|
3007
|
+
const patch = patches.at(-1);
|
|
3008
|
+
if (patch.type !== NavigateChild && patch.type !== NavigateParent && patch.type !== NavigateSibling && patch.type !== MultiNavigation) {
|
|
3009
|
+
break;
|
|
3010
|
+
}
|
|
3011
|
+
patches.pop();
|
|
3012
|
+
}
|
|
3013
|
+
return patches;
|
|
3014
|
+
};
|
|
3015
|
+
|
|
3016
|
+
const diffTree = (oldNodes, newNodes) => {
|
|
3017
|
+
// Step 1: Convert flat arrays to tree structures
|
|
3018
|
+
const oldTree = arrayToTree(oldNodes);
|
|
3019
|
+
const newTree = arrayToTree(newNodes);
|
|
3020
|
+
// Step 3: Compare the trees
|
|
3021
|
+
const patches = [];
|
|
3022
|
+
diffTrees(oldTree, newTree, patches, []);
|
|
3023
|
+
// Remove trailing navigation patches since they serve no purpose
|
|
3024
|
+
return removeTrailingNavigationPatches(patches);
|
|
3025
|
+
};
|
|
3026
|
+
|
|
2799
3027
|
const HandleBlur = 1;
|
|
2800
3028
|
const HandleClickButton = 2;
|
|
2801
3029
|
const HandleClickClose = 3;
|
|
@@ -2943,7 +3171,7 @@ const getFindWidgetButtons = (findButtonsEnabled, replaceButtonsEnabled, matchCa
|
|
|
2943
3171
|
disabled: !replaceButtonsEnabled,
|
|
2944
3172
|
icon: Replace,
|
|
2945
3173
|
label: replace(),
|
|
2946
|
-
name: Replace$
|
|
3174
|
+
name: Replace$3,
|
|
2947
3175
|
onClick: HandleClickButton
|
|
2948
3176
|
}, {
|
|
2949
3177
|
disabled: !replaceButtonsEnabled,
|
|
@@ -2969,20 +3197,6 @@ const getFindWidgetButtonsEnabled = (matchCount, value) => {
|
|
|
2969
3197
|
};
|
|
2970
3198
|
};
|
|
2971
3199
|
|
|
2972
|
-
const mergeClassNames = (...classNames) => {
|
|
2973
|
-
return classNames.filter(Boolean).join(' ');
|
|
2974
|
-
};
|
|
2975
|
-
|
|
2976
|
-
const text = data => {
|
|
2977
|
-
return {
|
|
2978
|
-
childCount: 0,
|
|
2979
|
-
text: data,
|
|
2980
|
-
type: Text
|
|
2981
|
-
};
|
|
2982
|
-
};
|
|
2983
|
-
|
|
2984
|
-
new Set(Object.values(VirtualDomElements));
|
|
2985
|
-
|
|
2986
3200
|
const FindWidget = 'FindWidget';
|
|
2987
3201
|
const FindWidgetFind = 'FindWidgetFind';
|
|
2988
3202
|
const FindWidgetMatchCount = 'FindWidgetMatchCount';
|
|
@@ -3216,20 +3430,20 @@ const getMatchCountText = (matchIndex, matchCount) => {
|
|
|
3216
3430
|
return matchOf(matchIndex + 1, matchCount);
|
|
3217
3431
|
};
|
|
3218
3432
|
|
|
3219
|
-
const
|
|
3433
|
+
const getDom = state => {
|
|
3220
3434
|
const {
|
|
3221
3435
|
focus,
|
|
3222
3436
|
inputErrorMessage,
|
|
3223
3437
|
matchCase,
|
|
3224
3438
|
matchCount,
|
|
3439
|
+
matchIndex,
|
|
3225
3440
|
matchWholeWord,
|
|
3226
3441
|
preserveCase,
|
|
3227
3442
|
replaceExpanded,
|
|
3228
|
-
uid,
|
|
3229
3443
|
useRegularExpression,
|
|
3230
3444
|
value
|
|
3231
|
-
} =
|
|
3232
|
-
const matchCountText = inputErrorMessage || getMatchCountText(
|
|
3445
|
+
} = state;
|
|
3446
|
+
const matchCountText = inputErrorMessage || getMatchCountText(matchIndex, matchCount);
|
|
3233
3447
|
const {
|
|
3234
3448
|
findButtonsEnabled,
|
|
3235
3449
|
replaceButtonsEnabled
|
|
@@ -3244,7 +3458,18 @@ const renderContent = (oldState, newState) => {
|
|
|
3244
3458
|
const inputFocused = focus === FocusSearchInput;
|
|
3245
3459
|
const replaceInputFocused = focus === FocusSearchReplaceInput;
|
|
3246
3460
|
const dom = getFindWidgetVirtualDom(matchCountText, replaceExpanded, findButtons, findFieldButtons, replaceButtons, replaceFieldButtons, matchCount, value, hasError, inputFocused, replaceInputFocused);
|
|
3247
|
-
return
|
|
3461
|
+
return dom;
|
|
3462
|
+
};
|
|
3463
|
+
const renderContent = (oldState, newState) => {
|
|
3464
|
+
const {
|
|
3465
|
+
uid
|
|
3466
|
+
} = newState;
|
|
3467
|
+
const dom = getDom(newState);
|
|
3468
|
+
if (oldState.version === 0) {
|
|
3469
|
+
return [SetDom2, uid, dom];
|
|
3470
|
+
}
|
|
3471
|
+
const oldDom = getDom(oldState);
|
|
3472
|
+
return [SetPatches, uid, diffTree(oldDom, dom)];
|
|
3248
3473
|
};
|
|
3249
3474
|
|
|
3250
3475
|
const renderCss = (oldState, newState) => {
|
|
@@ -3352,7 +3577,7 @@ const getFocusSelector = focusKey => {
|
|
|
3352
3577
|
case FocusFindWidgetReplaceAllButton$1:
|
|
3353
3578
|
return ReplaceAll$2;
|
|
3354
3579
|
case FocusFindWidgetReplaceButton$1:
|
|
3355
|
-
return Replace$
|
|
3580
|
+
return Replace$3;
|
|
3356
3581
|
case FocusSearchInput:
|
|
3357
3582
|
return SearchValue;
|
|
3358
3583
|
case FocusSearchMatchCase:
|