@lvce-editor/panel-worker 1.12.0 → 2.3.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/panelWorkerMain.js +669 -258
- package/package.json +2 -5
package/dist/panelWorkerMain.js
CHANGED
|
@@ -63,7 +63,7 @@ class AssertionError extends Error {
|
|
|
63
63
|
const Object$1 = 1;
|
|
64
64
|
const Number$1 = 2;
|
|
65
65
|
const Array$1 = 3;
|
|
66
|
-
const String = 4;
|
|
66
|
+
const String$1 = 4;
|
|
67
67
|
const Boolean$1 = 5;
|
|
68
68
|
const Function = 6;
|
|
69
69
|
const Null = 7;
|
|
@@ -75,7 +75,7 @@ const getType = value => {
|
|
|
75
75
|
case 'function':
|
|
76
76
|
return Function;
|
|
77
77
|
case 'string':
|
|
78
|
-
return String;
|
|
78
|
+
return String$1;
|
|
79
79
|
case 'object':
|
|
80
80
|
if (value === null) {
|
|
81
81
|
return Null;
|
|
@@ -98,7 +98,7 @@ const object = value => {
|
|
|
98
98
|
};
|
|
99
99
|
const string = value => {
|
|
100
100
|
const type = getType(value);
|
|
101
|
-
if (type !== String) {
|
|
101
|
+
if (type !== String$1) {
|
|
102
102
|
throw new AssertionError('expected value to be of type string');
|
|
103
103
|
}
|
|
104
104
|
};
|
|
@@ -145,7 +145,6 @@ const walkValue = (value, transferrables, isTransferrable) => {
|
|
|
145
145
|
for (const property of Object.values(value)) {
|
|
146
146
|
walkValue(property, transferrables, isTransferrable);
|
|
147
147
|
}
|
|
148
|
-
return;
|
|
149
148
|
}
|
|
150
149
|
};
|
|
151
150
|
const getTransferrables = value => {
|
|
@@ -299,7 +298,14 @@ class IpcError extends VError {
|
|
|
299
298
|
const cause = new Error(message);
|
|
300
299
|
// @ts-ignore
|
|
301
300
|
cause.code = code;
|
|
302
|
-
|
|
301
|
+
if (stack) {
|
|
302
|
+
Object.defineProperty(cause, 'stack', {
|
|
303
|
+
configurable: true,
|
|
304
|
+
enumerable: false,
|
|
305
|
+
value: stack,
|
|
306
|
+
writable: true
|
|
307
|
+
});
|
|
308
|
+
}
|
|
303
309
|
super(cause, betterMessage);
|
|
304
310
|
} else {
|
|
305
311
|
super(betterMessage);
|
|
@@ -492,7 +498,10 @@ const constructError = (message, type, name) => {
|
|
|
492
498
|
if (ErrorConstructor === Error) {
|
|
493
499
|
const error = new Error(message);
|
|
494
500
|
if (name && name !== 'VError') {
|
|
495
|
-
error
|
|
501
|
+
Object.defineProperty(error, 'name', {
|
|
502
|
+
configurable: true,
|
|
503
|
+
value: name
|
|
504
|
+
});
|
|
496
505
|
}
|
|
497
506
|
return error;
|
|
498
507
|
}
|
|
@@ -509,8 +518,10 @@ const getCurrentStack = () => {
|
|
|
509
518
|
const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
|
|
510
519
|
return currentStack;
|
|
511
520
|
};
|
|
512
|
-
const getNewLineIndex = (string, startIndex
|
|
513
|
-
|
|
521
|
+
const getNewLineIndex = (string, startIndex) => {
|
|
522
|
+
{
|
|
523
|
+
return string.indexOf(NewLine);
|
|
524
|
+
}
|
|
514
525
|
};
|
|
515
526
|
const getParentStack = error => {
|
|
516
527
|
let parentStack = error.stack || error.data || error.message || '';
|
|
@@ -521,55 +532,91 @@ const getParentStack = error => {
|
|
|
521
532
|
};
|
|
522
533
|
const MethodNotFound = -32601;
|
|
523
534
|
const Custom = -32001;
|
|
535
|
+
const setStack = (error, stack) => {
|
|
536
|
+
const descriptor = Object.getOwnPropertyDescriptor(error, 'stack');
|
|
537
|
+
if (descriptor) {
|
|
538
|
+
if (!descriptor.configurable && !descriptor.writable) {
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
541
|
+
if (!descriptor.configurable && descriptor.writable) {
|
|
542
|
+
error.stack = stack;
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
Object.defineProperty(error, 'stack', {
|
|
547
|
+
configurable: true,
|
|
548
|
+
value: stack,
|
|
549
|
+
writable: true
|
|
550
|
+
});
|
|
551
|
+
};
|
|
552
|
+
const restoreExistingError = (error, currentStack) => {
|
|
553
|
+
if (typeof error.stack === 'string') {
|
|
554
|
+
setStack(error, `${error.stack}${NewLine}${currentStack}`);
|
|
555
|
+
}
|
|
556
|
+
return error;
|
|
557
|
+
};
|
|
558
|
+
const restoreMethodNotFoundError = (error, currentStack) => {
|
|
559
|
+
const restoredError = new JsonRpcError(error.message);
|
|
560
|
+
const parentStack = getParentStack(error);
|
|
561
|
+
setStack(restoredError, `${parentStack}${NewLine}${currentStack}`);
|
|
562
|
+
return restoredError;
|
|
563
|
+
};
|
|
564
|
+
const restoreStackFromData = (restoredError, error, currentStack) => {
|
|
565
|
+
if (error.data.stack && error.data.type && error.message) {
|
|
566
|
+
setStack(restoredError, `${error.data.type}: ${error.message}${NewLine}${error.data.stack}${NewLine}${currentStack}`);
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
if (error.data.stack) {
|
|
570
|
+
setStack(restoredError, error.data.stack);
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
const applyDataProperties = (restoredError, error) => {
|
|
574
|
+
restoreStackFromData(restoredError, error, getCurrentStack());
|
|
575
|
+
if (error.data.codeFrame) {
|
|
576
|
+
// @ts-ignore
|
|
577
|
+
restoredError.codeFrame = error.data.codeFrame;
|
|
578
|
+
}
|
|
579
|
+
if (error.data.code) {
|
|
580
|
+
// @ts-ignore
|
|
581
|
+
restoredError.code = error.data.code;
|
|
582
|
+
}
|
|
583
|
+
if (error.data.type) {
|
|
584
|
+
// @ts-ignore
|
|
585
|
+
restoredError.name = error.data.type;
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
const applyDirectProperties = (restoredError, error) => {
|
|
589
|
+
if (error.stack) {
|
|
590
|
+
const lowerStack = restoredError.stack || '';
|
|
591
|
+
const indexNewLine = getNewLineIndex(lowerStack);
|
|
592
|
+
const parentStack = getParentStack(error);
|
|
593
|
+
// @ts-ignore
|
|
594
|
+
setStack(restoredError, `${parentStack}${lowerStack.slice(indexNewLine)}`);
|
|
595
|
+
}
|
|
596
|
+
if (error.codeFrame) {
|
|
597
|
+
// @ts-ignore
|
|
598
|
+
restoredError.codeFrame = error.codeFrame;
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
const restoreMessageError = (error, _currentStack) => {
|
|
602
|
+
const restoredError = constructError(error.message, error.type, error.name);
|
|
603
|
+
if (error.data) {
|
|
604
|
+
applyDataProperties(restoredError, error);
|
|
605
|
+
} else {
|
|
606
|
+
applyDirectProperties(restoredError, error);
|
|
607
|
+
}
|
|
608
|
+
return restoredError;
|
|
609
|
+
};
|
|
524
610
|
const restoreJsonRpcError = error => {
|
|
525
611
|
const currentStack = getCurrentStack();
|
|
526
612
|
if (error && error instanceof Error) {
|
|
527
|
-
|
|
528
|
-
error.stack = error.stack + NewLine + currentStack;
|
|
529
|
-
}
|
|
530
|
-
return error;
|
|
613
|
+
return restoreExistingError(error, currentStack);
|
|
531
614
|
}
|
|
532
615
|
if (error && error.code && error.code === MethodNotFound) {
|
|
533
|
-
|
|
534
|
-
const parentStack = getParentStack(error);
|
|
535
|
-
restoredError.stack = parentStack + NewLine + currentStack;
|
|
536
|
-
return restoredError;
|
|
616
|
+
return restoreMethodNotFoundError(error, currentStack);
|
|
537
617
|
}
|
|
538
618
|
if (error && error.message) {
|
|
539
|
-
|
|
540
|
-
if (error.data) {
|
|
541
|
-
if (error.data.stack && error.data.type && error.message) {
|
|
542
|
-
restoredError.stack = error.data.type + ': ' + error.message + NewLine + error.data.stack + NewLine + currentStack;
|
|
543
|
-
} else if (error.data.stack) {
|
|
544
|
-
restoredError.stack = error.data.stack;
|
|
545
|
-
}
|
|
546
|
-
if (error.data.codeFrame) {
|
|
547
|
-
// @ts-ignore
|
|
548
|
-
restoredError.codeFrame = error.data.codeFrame;
|
|
549
|
-
}
|
|
550
|
-
if (error.data.code) {
|
|
551
|
-
// @ts-ignore
|
|
552
|
-
restoredError.code = error.data.code;
|
|
553
|
-
}
|
|
554
|
-
if (error.data.type) {
|
|
555
|
-
// @ts-ignore
|
|
556
|
-
restoredError.name = error.data.type;
|
|
557
|
-
}
|
|
558
|
-
} else {
|
|
559
|
-
if (error.stack) {
|
|
560
|
-
const lowerStack = restoredError.stack || '';
|
|
561
|
-
// @ts-ignore
|
|
562
|
-
const indexNewLine = getNewLineIndex(lowerStack);
|
|
563
|
-
const parentStack = getParentStack(error);
|
|
564
|
-
// @ts-ignore
|
|
565
|
-
restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
|
|
566
|
-
}
|
|
567
|
-
if (error.codeFrame) {
|
|
568
|
-
// @ts-ignore
|
|
569
|
-
restoredError.codeFrame = error.codeFrame;
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
return restoredError;
|
|
619
|
+
return restoreMessageError(error);
|
|
573
620
|
}
|
|
574
621
|
if (typeof error === 'string') {
|
|
575
622
|
return new Error(`JsonRpc Error: ${error}`);
|
|
@@ -884,21 +931,6 @@ const create$3 = async ({
|
|
|
884
931
|
return rpc;
|
|
885
932
|
};
|
|
886
933
|
|
|
887
|
-
const Tab = 'tab';
|
|
888
|
-
const TabList = 'tablist';
|
|
889
|
-
const ToolBar = 'toolbar';
|
|
890
|
-
|
|
891
|
-
const Button = 1;
|
|
892
|
-
const Div = 4;
|
|
893
|
-
const Text = 12;
|
|
894
|
-
const Reference = 100;
|
|
895
|
-
|
|
896
|
-
const TargetName = 'event.target.name';
|
|
897
|
-
|
|
898
|
-
const RendererWorker = 1;
|
|
899
|
-
|
|
900
|
-
const SetPatches = 'Viewlet.setPatches';
|
|
901
|
-
|
|
902
934
|
const createMockRpc = ({
|
|
903
935
|
commandMap
|
|
904
936
|
}) => {
|
|
@@ -967,6 +999,185 @@ const create$2 = rpcId => {
|
|
|
967
999
|
};
|
|
968
1000
|
};
|
|
969
1001
|
|
|
1002
|
+
const Tab = 'tab';
|
|
1003
|
+
const TabList = 'tablist';
|
|
1004
|
+
const ToolBar = 'toolbar';
|
|
1005
|
+
|
|
1006
|
+
const Audio = 0;
|
|
1007
|
+
const Button = 1;
|
|
1008
|
+
const Col = 2;
|
|
1009
|
+
const ColGroup = 3;
|
|
1010
|
+
const Div = 4;
|
|
1011
|
+
const H1 = 5;
|
|
1012
|
+
const Input = 6;
|
|
1013
|
+
const Kbd = 7;
|
|
1014
|
+
const Span = 8;
|
|
1015
|
+
const Table = 9;
|
|
1016
|
+
const TBody = 10;
|
|
1017
|
+
const Td = 11;
|
|
1018
|
+
const Text = 12;
|
|
1019
|
+
const Th = 13;
|
|
1020
|
+
const THead = 14;
|
|
1021
|
+
const Tr = 15;
|
|
1022
|
+
const I = 16;
|
|
1023
|
+
const Img = 17;
|
|
1024
|
+
const Root = 0;
|
|
1025
|
+
const Ins = 20;
|
|
1026
|
+
const Del = 21;
|
|
1027
|
+
const H2 = 22;
|
|
1028
|
+
const H3 = 23;
|
|
1029
|
+
const H4 = 24;
|
|
1030
|
+
const H5 = 25;
|
|
1031
|
+
const H6 = 26;
|
|
1032
|
+
const Article = 27;
|
|
1033
|
+
const Aside = 28;
|
|
1034
|
+
const Footer = 29;
|
|
1035
|
+
const Header = 30;
|
|
1036
|
+
const Nav = 40;
|
|
1037
|
+
const Section = 41;
|
|
1038
|
+
const Search = 42;
|
|
1039
|
+
const Dd = 43;
|
|
1040
|
+
const Dl = 44;
|
|
1041
|
+
const Figcaption = 45;
|
|
1042
|
+
const Figure = 46;
|
|
1043
|
+
const Hr = 47;
|
|
1044
|
+
const Li = 48;
|
|
1045
|
+
const Ol = 49;
|
|
1046
|
+
const P = 50;
|
|
1047
|
+
const Pre = 51;
|
|
1048
|
+
const A = 53;
|
|
1049
|
+
const Abbr = 54;
|
|
1050
|
+
const Br = 55;
|
|
1051
|
+
const Cite = 56;
|
|
1052
|
+
const Data = 57;
|
|
1053
|
+
const Time = 58;
|
|
1054
|
+
const Tfoot = 59;
|
|
1055
|
+
const Ul = 60;
|
|
1056
|
+
const Video = 61;
|
|
1057
|
+
const TextArea = 62;
|
|
1058
|
+
const Select = 63;
|
|
1059
|
+
const Option = 64;
|
|
1060
|
+
const Code = 65;
|
|
1061
|
+
const Label = 66;
|
|
1062
|
+
const Dt = 67;
|
|
1063
|
+
const Iframe = 68;
|
|
1064
|
+
const Main = 69;
|
|
1065
|
+
const Strong = 70;
|
|
1066
|
+
const Em = 71;
|
|
1067
|
+
const Style = 72;
|
|
1068
|
+
const Html = 73;
|
|
1069
|
+
const Head = 74;
|
|
1070
|
+
const Title = 75;
|
|
1071
|
+
const Meta = 76;
|
|
1072
|
+
const Canvas = 77;
|
|
1073
|
+
const Form = 78;
|
|
1074
|
+
const BlockQuote = 79;
|
|
1075
|
+
const Quote = 80;
|
|
1076
|
+
const Circle = 81;
|
|
1077
|
+
const Defs = 82;
|
|
1078
|
+
const Ellipse = 83;
|
|
1079
|
+
const G = 84;
|
|
1080
|
+
const Line = 85;
|
|
1081
|
+
const Path = 86;
|
|
1082
|
+
const Polygon = 87;
|
|
1083
|
+
const Polyline = 88;
|
|
1084
|
+
const Rect = 89;
|
|
1085
|
+
const Svg = 90;
|
|
1086
|
+
const Use = 91;
|
|
1087
|
+
const Reference = 100;
|
|
1088
|
+
|
|
1089
|
+
const VirtualDomElements = {
|
|
1090
|
+
__proto__: null,
|
|
1091
|
+
A,
|
|
1092
|
+
Abbr,
|
|
1093
|
+
Article,
|
|
1094
|
+
Aside,
|
|
1095
|
+
Audio,
|
|
1096
|
+
BlockQuote,
|
|
1097
|
+
Br,
|
|
1098
|
+
Button,
|
|
1099
|
+
Canvas,
|
|
1100
|
+
Circle,
|
|
1101
|
+
Cite,
|
|
1102
|
+
Code,
|
|
1103
|
+
Col,
|
|
1104
|
+
ColGroup,
|
|
1105
|
+
Data,
|
|
1106
|
+
Dd,
|
|
1107
|
+
Defs,
|
|
1108
|
+
Del,
|
|
1109
|
+
Div,
|
|
1110
|
+
Dl,
|
|
1111
|
+
Dt,
|
|
1112
|
+
Ellipse,
|
|
1113
|
+
Em,
|
|
1114
|
+
Figcaption,
|
|
1115
|
+
Figure,
|
|
1116
|
+
Footer,
|
|
1117
|
+
Form,
|
|
1118
|
+
G,
|
|
1119
|
+
H1,
|
|
1120
|
+
H2,
|
|
1121
|
+
H3,
|
|
1122
|
+
H4,
|
|
1123
|
+
H5,
|
|
1124
|
+
H6,
|
|
1125
|
+
Head,
|
|
1126
|
+
Header,
|
|
1127
|
+
Hr,
|
|
1128
|
+
Html,
|
|
1129
|
+
I,
|
|
1130
|
+
Iframe,
|
|
1131
|
+
Img,
|
|
1132
|
+
Input,
|
|
1133
|
+
Ins,
|
|
1134
|
+
Kbd,
|
|
1135
|
+
Label,
|
|
1136
|
+
Li,
|
|
1137
|
+
Line,
|
|
1138
|
+
Main,
|
|
1139
|
+
Meta,
|
|
1140
|
+
Nav,
|
|
1141
|
+
Ol,
|
|
1142
|
+
Option,
|
|
1143
|
+
P,
|
|
1144
|
+
Path,
|
|
1145
|
+
Polygon,
|
|
1146
|
+
Polyline,
|
|
1147
|
+
Pre,
|
|
1148
|
+
Quote,
|
|
1149
|
+
Rect,
|
|
1150
|
+
Reference,
|
|
1151
|
+
Root,
|
|
1152
|
+
Search,
|
|
1153
|
+
Section,
|
|
1154
|
+
Select,
|
|
1155
|
+
Span,
|
|
1156
|
+
Strong,
|
|
1157
|
+
Style,
|
|
1158
|
+
Svg,
|
|
1159
|
+
TBody,
|
|
1160
|
+
THead,
|
|
1161
|
+
Table,
|
|
1162
|
+
Td,
|
|
1163
|
+
Text,
|
|
1164
|
+
TextArea,
|
|
1165
|
+
Tfoot,
|
|
1166
|
+
Th,
|
|
1167
|
+
Time,
|
|
1168
|
+
Title,
|
|
1169
|
+
Tr,
|
|
1170
|
+
Ul,
|
|
1171
|
+
Use,
|
|
1172
|
+
Video
|
|
1173
|
+
};
|
|
1174
|
+
|
|
1175
|
+
const TargetName = 'event.target.name';
|
|
1176
|
+
|
|
1177
|
+
const RendererWorker = 1;
|
|
1178
|
+
|
|
1179
|
+
const SetPatches = 'Viewlet.setPatches';
|
|
1180
|
+
|
|
970
1181
|
const {
|
|
971
1182
|
invoke,
|
|
972
1183
|
set: set$1
|
|
@@ -977,29 +1188,87 @@ const toCommandId = key => {
|
|
|
977
1188
|
return key.slice(dotIndex + 1);
|
|
978
1189
|
};
|
|
979
1190
|
const create$1 = () => {
|
|
1191
|
+
const commandQueues = new Map();
|
|
1192
|
+
const generations = Object.create(null);
|
|
980
1193
|
const states = Object.create(null);
|
|
981
1194
|
const commandMapRef = {};
|
|
1195
|
+
const getGeneration = uid => generations[uid] || 0;
|
|
1196
|
+
const isCurrentGeneration = (uid, generation) => {
|
|
1197
|
+
return states[uid] !== undefined && getGeneration(uid) === generation;
|
|
1198
|
+
};
|
|
1199
|
+
const updateState = (uid, generation, fallbackState, updater) => {
|
|
1200
|
+
if (!isCurrentGeneration(uid, generation)) {
|
|
1201
|
+
return Promise.resolve(fallbackState);
|
|
1202
|
+
}
|
|
1203
|
+
const current = states[uid];
|
|
1204
|
+
const updatedState = updater(current.newState);
|
|
1205
|
+
if (updatedState !== current.newState) {
|
|
1206
|
+
states[uid] = {
|
|
1207
|
+
newState: updatedState,
|
|
1208
|
+
oldState: current.oldState,
|
|
1209
|
+
scheduledState: updatedState
|
|
1210
|
+
};
|
|
1211
|
+
}
|
|
1212
|
+
return Promise.resolve(updatedState);
|
|
1213
|
+
};
|
|
1214
|
+
const createAsyncCommandContext = (uid, generation) => {
|
|
1215
|
+
let latestState = states[uid].newState;
|
|
1216
|
+
return {
|
|
1217
|
+
getState: () => {
|
|
1218
|
+
if (isCurrentGeneration(uid, generation)) {
|
|
1219
|
+
latestState = states[uid].newState;
|
|
1220
|
+
}
|
|
1221
|
+
return latestState;
|
|
1222
|
+
},
|
|
1223
|
+
updateState: async updater => {
|
|
1224
|
+
latestState = await updateState(uid, generation, latestState, updater);
|
|
1225
|
+
return latestState;
|
|
1226
|
+
}
|
|
1227
|
+
};
|
|
1228
|
+
};
|
|
1229
|
+
const enqueueCommand = async (uid, command) => {
|
|
1230
|
+
const previous = commandQueues.get(uid) || Promise.resolve();
|
|
1231
|
+
const run = async () => {
|
|
1232
|
+
try {
|
|
1233
|
+
await previous;
|
|
1234
|
+
} catch {
|
|
1235
|
+
// The previous caller receives its error; later commands must still run.
|
|
1236
|
+
}
|
|
1237
|
+
await command();
|
|
1238
|
+
};
|
|
1239
|
+
const current = run();
|
|
1240
|
+
commandQueues.set(uid, current);
|
|
1241
|
+
try {
|
|
1242
|
+
await current;
|
|
1243
|
+
} finally {
|
|
1244
|
+
if (commandQueues.get(uid) === current) {
|
|
1245
|
+
commandQueues.delete(uid);
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
};
|
|
982
1249
|
return {
|
|
983
1250
|
clear() {
|
|
1251
|
+
commandQueues.clear();
|
|
984
1252
|
for (const key of Object.keys(states)) {
|
|
985
1253
|
delete states[key];
|
|
986
1254
|
}
|
|
987
1255
|
},
|
|
988
1256
|
diff(uid, modules, numbers) {
|
|
989
1257
|
const {
|
|
990
|
-
|
|
991
|
-
|
|
1258
|
+
oldState,
|
|
1259
|
+
scheduledState
|
|
992
1260
|
} = states[uid];
|
|
993
1261
|
const diffResult = [];
|
|
994
1262
|
for (let i = 0; i < modules.length; i++) {
|
|
995
1263
|
const fn = modules[i];
|
|
996
|
-
if (!fn(oldState,
|
|
1264
|
+
if (!fn(oldState, scheduledState)) {
|
|
997
1265
|
diffResult.push(numbers[i]);
|
|
998
1266
|
}
|
|
999
1267
|
}
|
|
1000
1268
|
return diffResult;
|
|
1001
1269
|
},
|
|
1002
1270
|
dispose(uid) {
|
|
1271
|
+
commandQueues.delete(uid);
|
|
1003
1272
|
delete states[uid];
|
|
1004
1273
|
},
|
|
1005
1274
|
get(uid) {
|
|
@@ -1011,21 +1280,33 @@ const create$1 = () => {
|
|
|
1011
1280
|
return ids;
|
|
1012
1281
|
},
|
|
1013
1282
|
getKeys() {
|
|
1014
|
-
return Object.keys(states).map(
|
|
1015
|
-
return Number.parseInt(key);
|
|
1016
|
-
});
|
|
1283
|
+
return Object.keys(states).map(Number);
|
|
1017
1284
|
},
|
|
1018
1285
|
registerCommands(commandMap) {
|
|
1019
1286
|
Object.assign(commandMapRef, commandMap);
|
|
1020
1287
|
},
|
|
1021
|
-
set(uid, oldState, newState) {
|
|
1288
|
+
set(uid, oldState, newState, scheduledState) {
|
|
1289
|
+
const current = states[uid];
|
|
1290
|
+
if (!current || oldState === newState && newState !== current.newState) {
|
|
1291
|
+
generations[uid] = getGeneration(uid) + 1;
|
|
1292
|
+
}
|
|
1022
1293
|
states[uid] = {
|
|
1023
1294
|
newState,
|
|
1024
|
-
oldState
|
|
1295
|
+
oldState,
|
|
1296
|
+
scheduledState: scheduledState ?? newState
|
|
1297
|
+
};
|
|
1298
|
+
},
|
|
1299
|
+
wrapAsyncCommand(fn) {
|
|
1300
|
+
const wrapped = async (uid, ...args) => {
|
|
1301
|
+
const generation = getGeneration(uid);
|
|
1302
|
+
const context = createAsyncCommandContext(uid, generation);
|
|
1303
|
+
await fn(context, ...args);
|
|
1025
1304
|
};
|
|
1305
|
+
return wrapped;
|
|
1026
1306
|
},
|
|
1027
1307
|
wrapCommand(fn) {
|
|
1028
1308
|
const wrapped = async (uid, ...args) => {
|
|
1309
|
+
const generation = getGeneration(uid);
|
|
1029
1310
|
const {
|
|
1030
1311
|
newState,
|
|
1031
1312
|
oldState
|
|
@@ -1034,6 +1315,9 @@ const create$1 = () => {
|
|
|
1034
1315
|
if (oldState === newerState || newState === newerState) {
|
|
1035
1316
|
return;
|
|
1036
1317
|
}
|
|
1318
|
+
if (!isCurrentGeneration(uid, generation)) {
|
|
1319
|
+
return;
|
|
1320
|
+
}
|
|
1037
1321
|
const latestOld = states[uid];
|
|
1038
1322
|
const latestNew = {
|
|
1039
1323
|
...latestOld.newState,
|
|
@@ -1041,7 +1325,8 @@ const create$1 = () => {
|
|
|
1041
1325
|
};
|
|
1042
1326
|
states[uid] = {
|
|
1043
1327
|
newState: latestNew,
|
|
1044
|
-
oldState: latestOld.oldState
|
|
1328
|
+
oldState: latestOld.oldState,
|
|
1329
|
+
scheduledState: latestNew
|
|
1045
1330
|
};
|
|
1046
1331
|
};
|
|
1047
1332
|
return wrapped;
|
|
@@ -1054,6 +1339,89 @@ const create$1 = () => {
|
|
|
1054
1339
|
return fn(newState, ...args);
|
|
1055
1340
|
};
|
|
1056
1341
|
return wrapped;
|
|
1342
|
+
},
|
|
1343
|
+
wrapLoadContent(fn) {
|
|
1344
|
+
const wrapped = async (uid, ...args) => {
|
|
1345
|
+
const generation = getGeneration(uid);
|
|
1346
|
+
const {
|
|
1347
|
+
newState,
|
|
1348
|
+
oldState
|
|
1349
|
+
} = states[uid];
|
|
1350
|
+
const result = await fn(newState, ...args);
|
|
1351
|
+
const {
|
|
1352
|
+
error,
|
|
1353
|
+
state
|
|
1354
|
+
} = result;
|
|
1355
|
+
if (oldState === state || newState === state) {
|
|
1356
|
+
return {
|
|
1357
|
+
error
|
|
1358
|
+
};
|
|
1359
|
+
}
|
|
1360
|
+
if (!isCurrentGeneration(uid, generation)) {
|
|
1361
|
+
return {
|
|
1362
|
+
error
|
|
1363
|
+
};
|
|
1364
|
+
}
|
|
1365
|
+
const latestOld = states[uid];
|
|
1366
|
+
const latestNew = {
|
|
1367
|
+
...latestOld.newState,
|
|
1368
|
+
...state
|
|
1369
|
+
};
|
|
1370
|
+
states[uid] = {
|
|
1371
|
+
newState: latestNew,
|
|
1372
|
+
oldState: latestOld.oldState,
|
|
1373
|
+
scheduledState: latestNew
|
|
1374
|
+
};
|
|
1375
|
+
return {
|
|
1376
|
+
error
|
|
1377
|
+
};
|
|
1378
|
+
};
|
|
1379
|
+
return wrapped;
|
|
1380
|
+
},
|
|
1381
|
+
wrapSerialAsyncCommand(fn) {
|
|
1382
|
+
const wrapped = async (uid, ...args) => {
|
|
1383
|
+
await enqueueCommand(uid, async () => {
|
|
1384
|
+
if (!states[uid]) {
|
|
1385
|
+
return;
|
|
1386
|
+
}
|
|
1387
|
+
const generation = getGeneration(uid);
|
|
1388
|
+
const context = createAsyncCommandContext(uid, generation);
|
|
1389
|
+
await fn(context, ...args);
|
|
1390
|
+
});
|
|
1391
|
+
};
|
|
1392
|
+
return wrapped;
|
|
1393
|
+
},
|
|
1394
|
+
wrapSerialCommand(fn) {
|
|
1395
|
+
const wrapped = async (uid, ...args) => {
|
|
1396
|
+
await enqueueCommand(uid, async () => {
|
|
1397
|
+
if (!states[uid]) {
|
|
1398
|
+
return;
|
|
1399
|
+
}
|
|
1400
|
+
const generation = getGeneration(uid);
|
|
1401
|
+
const {
|
|
1402
|
+
newState,
|
|
1403
|
+
oldState
|
|
1404
|
+
} = states[uid];
|
|
1405
|
+
const newerState = await fn(newState, ...args);
|
|
1406
|
+
if (oldState === newerState || newState === newerState) {
|
|
1407
|
+
return;
|
|
1408
|
+
}
|
|
1409
|
+
if (!isCurrentGeneration(uid, generation)) {
|
|
1410
|
+
return;
|
|
1411
|
+
}
|
|
1412
|
+
const latestOld = states[uid];
|
|
1413
|
+
const latestNew = {
|
|
1414
|
+
...latestOld.newState,
|
|
1415
|
+
...newerState
|
|
1416
|
+
};
|
|
1417
|
+
states[uid] = {
|
|
1418
|
+
newState: latestNew,
|
|
1419
|
+
oldState: latestOld.oldState,
|
|
1420
|
+
scheduledState: latestNew
|
|
1421
|
+
};
|
|
1422
|
+
});
|
|
1423
|
+
};
|
|
1424
|
+
return wrapped;
|
|
1057
1425
|
}
|
|
1058
1426
|
};
|
|
1059
1427
|
};
|
|
@@ -1078,8 +1446,10 @@ const create = (uid, uri, x, y, width, height, platform, assetDir) => {
|
|
|
1078
1446
|
childUid: 0,
|
|
1079
1447
|
currentViewletId: '',
|
|
1080
1448
|
errorCount: 0,
|
|
1449
|
+
headerHeight: 35,
|
|
1081
1450
|
height: 0,
|
|
1082
1451
|
initial: true,
|
|
1452
|
+
maximized: false,
|
|
1083
1453
|
platform,
|
|
1084
1454
|
selectedIndex: -1,
|
|
1085
1455
|
tabs: [],
|
|
@@ -1093,20 +1463,25 @@ const create = (uid, uri, x, y, width, height, platform, assetDir) => {
|
|
|
1093
1463
|
set(uid, state, state);
|
|
1094
1464
|
};
|
|
1095
1465
|
|
|
1466
|
+
const isEqual$2 = (oldState, newState) => {
|
|
1467
|
+
return oldState.actionsUid === newState.actionsUid;
|
|
1468
|
+
};
|
|
1469
|
+
|
|
1096
1470
|
const isEqual$1 = (oldState, newState) => {
|
|
1097
1471
|
return oldState.childUid === newState.childUid;
|
|
1098
1472
|
};
|
|
1099
1473
|
|
|
1100
1474
|
const isEqual = (oldState, newState) => {
|
|
1101
|
-
return oldState.assetDir === newState.assetDir && oldState.initial === newState.initial && oldState.currentViewletId === newState.currentViewletId && oldState.selectedIndex === newState.selectedIndex && oldState.views === newState.views && oldState.childUid === newState.childUid && oldState.actionsUid === newState.actionsUid;
|
|
1475
|
+
return oldState.assetDir === newState.assetDir && oldState.initial === newState.initial && oldState.currentViewletId === newState.currentViewletId && oldState.maximized === newState.maximized && oldState.selectedIndex === newState.selectedIndex && oldState.views === newState.views && oldState.childUid === newState.childUid && oldState.actionsUid === newState.actionsUid;
|
|
1102
1476
|
};
|
|
1103
1477
|
|
|
1104
1478
|
const RenderItems = 4;
|
|
1105
1479
|
const RenderIncremental = 11;
|
|
1106
1480
|
const RenderChildUid = 12;
|
|
1481
|
+
const RenderActionsUid = 13;
|
|
1107
1482
|
|
|
1108
|
-
const modules = [isEqual, isEqual$1];
|
|
1109
|
-
const numbers = [RenderIncremental, RenderChildUid];
|
|
1483
|
+
const modules = [isEqual, isEqual$1, isEqual$2];
|
|
1484
|
+
const numbers = [RenderIncremental, RenderChildUid, RenderActionsUid];
|
|
1110
1485
|
|
|
1111
1486
|
const diff = (oldState, newState) => {
|
|
1112
1487
|
const diffResult = [];
|
|
@@ -1137,6 +1512,26 @@ const handleClickMaximize = async state => {
|
|
|
1137
1512
|
await invoke('Layout.maximizePanel');
|
|
1138
1513
|
return state;
|
|
1139
1514
|
};
|
|
1515
|
+
const handleClickUnmaximize = async state => {
|
|
1516
|
+
await invoke('Layout.unmaximizePanel');
|
|
1517
|
+
return state;
|
|
1518
|
+
};
|
|
1519
|
+
|
|
1520
|
+
const handlePanelLayoutChanged = (state, change) => {
|
|
1521
|
+
const {
|
|
1522
|
+
maximized: currentMaximized
|
|
1523
|
+
} = state;
|
|
1524
|
+
const {
|
|
1525
|
+
maximized
|
|
1526
|
+
} = change;
|
|
1527
|
+
if (currentMaximized === maximized) {
|
|
1528
|
+
return state;
|
|
1529
|
+
}
|
|
1530
|
+
return {
|
|
1531
|
+
...state,
|
|
1532
|
+
maximized
|
|
1533
|
+
};
|
|
1534
|
+
};
|
|
1140
1535
|
|
|
1141
1536
|
const handleBlur = async state => {
|
|
1142
1537
|
return state;
|
|
@@ -1170,26 +1565,33 @@ const getSavedViewletId = savedState => {
|
|
|
1170
1565
|
return Problems;
|
|
1171
1566
|
};
|
|
1172
1567
|
|
|
1173
|
-
const createViewlet = async (viewletModuleId, editorUid, tabId, bounds, uri) => {
|
|
1174
|
-
await invoke('Layout.
|
|
1568
|
+
const createViewlet = async (viewletModuleId, editorUid, tabId, actionsUid, bounds, uri) => {
|
|
1569
|
+
await invoke('Layout.createPanelViewlet', viewletModuleId, editorUid, tabId, actionsUid, bounds, uri);
|
|
1175
1570
|
};
|
|
1176
1571
|
|
|
1177
1572
|
const getContentDimensions = dimensions => {
|
|
1178
1573
|
return {
|
|
1179
|
-
height: dimensions.height -
|
|
1574
|
+
height: dimensions.height - dimensions.headerHeight,
|
|
1180
1575
|
width: dimensions.width,
|
|
1181
1576
|
x: dimensions.x,
|
|
1182
|
-
y: dimensions.y +
|
|
1577
|
+
y: dimensions.y + dimensions.headerHeight
|
|
1183
1578
|
};
|
|
1184
1579
|
};
|
|
1185
1580
|
|
|
1581
|
+
const getUid = () => {
|
|
1582
|
+
return Math.random();
|
|
1583
|
+
};
|
|
1584
|
+
|
|
1186
1585
|
const openViewlet = async (state, id, focus = false) => {
|
|
1586
|
+
const {
|
|
1587
|
+
views
|
|
1588
|
+
} = state;
|
|
1187
1589
|
const childDimensions = getContentDimensions(state);
|
|
1188
|
-
const childUid =
|
|
1189
|
-
const tabId =
|
|
1190
|
-
const actionsUid =
|
|
1191
|
-
const index =
|
|
1192
|
-
await createViewlet(id, childUid, tabId, childDimensions, '');
|
|
1590
|
+
const childUid = getUid();
|
|
1591
|
+
const tabId = getUid();
|
|
1592
|
+
const actionsUid = getUid();
|
|
1593
|
+
const index = views.indexOf(id);
|
|
1594
|
+
await createViewlet(id, childUid, tabId, actionsUid, childDimensions, '');
|
|
1193
1595
|
return {
|
|
1194
1596
|
...state,
|
|
1195
1597
|
actionsUid,
|
|
@@ -1219,7 +1621,7 @@ const selectIndex = async (state, index) => {
|
|
|
1219
1621
|
};
|
|
1220
1622
|
|
|
1221
1623
|
const selectRaw = async (state, rawIndex) => {
|
|
1222
|
-
return selectIndex(state, Number
|
|
1624
|
+
return selectIndex(state, Number(rawIndex));
|
|
1223
1625
|
};
|
|
1224
1626
|
|
|
1225
1627
|
const setBadgeCount = (state, id, count) => {
|
|
@@ -1236,16 +1638,28 @@ const setBadgeCount = (state, id, count) => {
|
|
|
1236
1638
|
};
|
|
1237
1639
|
|
|
1238
1640
|
const toggleView = async (state, name) => {
|
|
1239
|
-
const
|
|
1641
|
+
const {
|
|
1642
|
+
currentViewletId,
|
|
1643
|
+
views
|
|
1644
|
+
} = state;
|
|
1645
|
+
const index = views.indexOf(name);
|
|
1240
1646
|
if (index === -1) {
|
|
1241
1647
|
return state;
|
|
1242
1648
|
}
|
|
1243
|
-
if (name ===
|
|
1649
|
+
if (name === currentViewletId) {
|
|
1244
1650
|
return state;
|
|
1245
1651
|
}
|
|
1246
1652
|
return selectIndex(state, index);
|
|
1247
1653
|
};
|
|
1248
1654
|
|
|
1655
|
+
const renderActionsUid = (oldState, newState) => {
|
|
1656
|
+
const oldActionsUid = oldState.actionsUid;
|
|
1657
|
+
if (oldActionsUid <= 0 || oldActionsUid === newState.actionsUid) {
|
|
1658
|
+
return [];
|
|
1659
|
+
}
|
|
1660
|
+
return ['Viewlet.dispose', oldActionsUid];
|
|
1661
|
+
};
|
|
1662
|
+
|
|
1249
1663
|
// TODO also need to dispose child when panel becomes hidden
|
|
1250
1664
|
const renderChildUid = (oldState, newState) => {
|
|
1251
1665
|
const oldChildUid = oldState.childUid;
|
|
@@ -1267,6 +1681,8 @@ const text = data => {
|
|
|
1267
1681
|
};
|
|
1268
1682
|
};
|
|
1269
1683
|
|
|
1684
|
+
new Set(Object.values(VirtualDomElements));
|
|
1685
|
+
|
|
1270
1686
|
const SetText = 1;
|
|
1271
1687
|
const Replace = 2;
|
|
1272
1688
|
const SetAttribute = 3;
|
|
@@ -1338,21 +1754,18 @@ const getChildrenWithCount = (nodes, startIndex, childCount) => {
|
|
|
1338
1754
|
};
|
|
1339
1755
|
|
|
1340
1756
|
const compareNodes = (oldNode, newNode) => {
|
|
1341
|
-
const patches = [];
|
|
1342
1757
|
// Check if node type changed - return null to signal incompatible nodes
|
|
1343
1758
|
// (caller should handle this with a Replace operation)
|
|
1344
1759
|
if (oldNode.type !== newNode.type) {
|
|
1345
1760
|
return null;
|
|
1346
1761
|
}
|
|
1762
|
+
const patches = [];
|
|
1347
1763
|
// Handle reference nodes - special handling for uid changes
|
|
1348
|
-
if (oldNode.type === Reference) {
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
});
|
|
1354
|
-
}
|
|
1355
|
-
return patches;
|
|
1764
|
+
if (oldNode.type === Reference && oldNode.uid !== newNode.uid) {
|
|
1765
|
+
patches.push({
|
|
1766
|
+
type: SetReferenceNodeUid,
|
|
1767
|
+
uid: newNode.uid
|
|
1768
|
+
});
|
|
1356
1769
|
}
|
|
1357
1770
|
// Handle text nodes
|
|
1358
1771
|
if (oldNode.type === Text && newNode.type === Text) {
|
|
@@ -1365,8 +1778,8 @@ const compareNodes = (oldNode, newNode) => {
|
|
|
1365
1778
|
return patches;
|
|
1366
1779
|
}
|
|
1367
1780
|
// Compare attributes
|
|
1368
|
-
const oldKeys = getKeys(oldNode);
|
|
1369
|
-
const newKeys = getKeys(newNode);
|
|
1781
|
+
const oldKeys = getKeys(oldNode).filter(key => oldNode.type !== Reference || key !== 'uid');
|
|
1782
|
+
const newKeys = getKeys(newNode).filter(key => newNode.type !== Reference || key !== 'uid');
|
|
1370
1783
|
// Check for attribute changes
|
|
1371
1784
|
for (const key of newKeys) {
|
|
1372
1785
|
if (oldNode[key] !== newNode[key]) {
|
|
@@ -1379,7 +1792,7 @@ const compareNodes = (oldNode, newNode) => {
|
|
|
1379
1792
|
}
|
|
1380
1793
|
// Check for removed attributes
|
|
1381
1794
|
for (const key of oldKeys) {
|
|
1382
|
-
if (!(key
|
|
1795
|
+
if (!Object.hasOwn(newNode, key)) {
|
|
1383
1796
|
patches.push({
|
|
1384
1797
|
type: RemoveAttribute,
|
|
1385
1798
|
key
|
|
@@ -1397,11 +1810,78 @@ const treeToArray = node => {
|
|
|
1397
1810
|
return result;
|
|
1398
1811
|
};
|
|
1399
1812
|
|
|
1813
|
+
const navigateToChild = (patches, currentChildIndex, index) => {
|
|
1814
|
+
if (currentChildIndex === -1) {
|
|
1815
|
+
patches.push({
|
|
1816
|
+
type: NavigateChild,
|
|
1817
|
+
index
|
|
1818
|
+
});
|
|
1819
|
+
return index;
|
|
1820
|
+
}
|
|
1821
|
+
if (currentChildIndex !== index) {
|
|
1822
|
+
patches.push({
|
|
1823
|
+
type: NavigateSibling,
|
|
1824
|
+
index
|
|
1825
|
+
});
|
|
1826
|
+
}
|
|
1827
|
+
return index;
|
|
1828
|
+
};
|
|
1829
|
+
const navigateToParent = (patches, currentChildIndex) => {
|
|
1830
|
+
if (currentChildIndex >= 0) {
|
|
1831
|
+
patches.push({
|
|
1832
|
+
type: NavigateParent
|
|
1833
|
+
});
|
|
1834
|
+
}
|
|
1835
|
+
return -1;
|
|
1836
|
+
};
|
|
1837
|
+
const addTree = (newNode, patches) => {
|
|
1838
|
+
patches.push({
|
|
1839
|
+
type: Add,
|
|
1840
|
+
nodes: treeToArray(newNode)
|
|
1841
|
+
});
|
|
1842
|
+
};
|
|
1843
|
+
const replaceTree = (newNode, patches) => {
|
|
1844
|
+
patches.push({
|
|
1845
|
+
type: Replace,
|
|
1846
|
+
nodes: treeToArray(newNode)
|
|
1847
|
+
});
|
|
1848
|
+
};
|
|
1849
|
+
const diffExistingChild = (oldNode, newNode, patches, currentChildIndex, index) => {
|
|
1850
|
+
const nodePatches = compareNodes(oldNode.node, newNode.node);
|
|
1851
|
+
if (nodePatches === null) {
|
|
1852
|
+
const nextChildIndex = navigateToChild(patches, currentChildIndex, index);
|
|
1853
|
+
replaceTree(newNode, patches);
|
|
1854
|
+
return nextChildIndex;
|
|
1855
|
+
}
|
|
1856
|
+
const hasChildrenToCompare = oldNode.children.length > 0 || newNode.children.length > 0;
|
|
1857
|
+
if (nodePatches.length === 0 && !hasChildrenToCompare) {
|
|
1858
|
+
return currentChildIndex;
|
|
1859
|
+
}
|
|
1860
|
+
const nextChildIndex = navigateToChild(patches, currentChildIndex, index);
|
|
1861
|
+
if (nodePatches.length > 0) {
|
|
1862
|
+
patches.push(...nodePatches);
|
|
1863
|
+
}
|
|
1864
|
+
if (hasChildrenToCompare) {
|
|
1865
|
+
diffChildren(oldNode.children, newNode.children, patches);
|
|
1866
|
+
}
|
|
1867
|
+
return nextChildIndex;
|
|
1868
|
+
};
|
|
1869
|
+
const diffRootNode = (oldNode, newNode, patches) => {
|
|
1870
|
+
const nodePatches = compareNodes(oldNode.node, newNode.node);
|
|
1871
|
+
if (nodePatches === null) {
|
|
1872
|
+
replaceTree(newNode, patches);
|
|
1873
|
+
return;
|
|
1874
|
+
}
|
|
1875
|
+
if (nodePatches.length > 0) {
|
|
1876
|
+
patches.push(...nodePatches);
|
|
1877
|
+
}
|
|
1878
|
+
if (oldNode.children.length > 0 || newNode.children.length > 0) {
|
|
1879
|
+
diffChildren(oldNode.children, newNode.children, patches);
|
|
1880
|
+
}
|
|
1881
|
+
};
|
|
1400
1882
|
const diffChildren = (oldChildren, newChildren, patches) => {
|
|
1401
1883
|
const maxLength = Math.max(oldChildren.length, newChildren.length);
|
|
1402
|
-
// Track where we are: -1 means at parent, >= 0 means at child index
|
|
1403
1884
|
let currentChildIndex = -1;
|
|
1404
|
-
// Collect indices of children to remove (we'll add these patches at the end in reverse order)
|
|
1405
1885
|
const indicesToRemove = [];
|
|
1406
1886
|
for (let i = 0; i < maxLength; i++) {
|
|
1407
1887
|
const oldNode = oldChildren[i];
|
|
@@ -1410,89 +1890,17 @@ const diffChildren = (oldChildren, newChildren, patches) => {
|
|
|
1410
1890
|
continue;
|
|
1411
1891
|
}
|
|
1412
1892
|
if (!oldNode) {
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
});
|
|
1419
|
-
currentChildIndex = -1;
|
|
1420
|
-
}
|
|
1421
|
-
// Flatten the entire subtree so renderInternal can handle it
|
|
1422
|
-
const flatNodes = treeToArray(newNode);
|
|
1423
|
-
patches.push({
|
|
1424
|
-
type: Add,
|
|
1425
|
-
nodes: flatNodes
|
|
1426
|
-
});
|
|
1427
|
-
} else if (newNode) {
|
|
1428
|
-
// Compare nodes to see if we need any patches
|
|
1429
|
-
const nodePatches = compareNodes(oldNode.node, newNode.node);
|
|
1430
|
-
// If nodePatches is null, the node types are incompatible - need to replace
|
|
1431
|
-
if (nodePatches === null) {
|
|
1432
|
-
// Navigate to this child
|
|
1433
|
-
if (currentChildIndex === -1) {
|
|
1434
|
-
patches.push({
|
|
1435
|
-
type: NavigateChild,
|
|
1436
|
-
index: i
|
|
1437
|
-
});
|
|
1438
|
-
currentChildIndex = i;
|
|
1439
|
-
} else if (currentChildIndex !== i) {
|
|
1440
|
-
patches.push({
|
|
1441
|
-
type: NavigateSibling,
|
|
1442
|
-
index: i
|
|
1443
|
-
});
|
|
1444
|
-
currentChildIndex = i;
|
|
1445
|
-
}
|
|
1446
|
-
// Replace the entire subtree
|
|
1447
|
-
const flatNodes = treeToArray(newNode);
|
|
1448
|
-
patches.push({
|
|
1449
|
-
type: Replace,
|
|
1450
|
-
nodes: flatNodes
|
|
1451
|
-
});
|
|
1452
|
-
// After replace, we're at the new element (same position)
|
|
1453
|
-
continue;
|
|
1454
|
-
}
|
|
1455
|
-
// Check if we need to recurse into children
|
|
1456
|
-
const hasChildrenToCompare = oldNode.children.length > 0 || newNode.children.length > 0;
|
|
1457
|
-
// Only navigate to this element if we need to do something
|
|
1458
|
-
if (nodePatches.length > 0 || hasChildrenToCompare) {
|
|
1459
|
-
// Navigate to this child if not already there
|
|
1460
|
-
if (currentChildIndex === -1) {
|
|
1461
|
-
patches.push({
|
|
1462
|
-
type: NavigateChild,
|
|
1463
|
-
index: i
|
|
1464
|
-
});
|
|
1465
|
-
currentChildIndex = i;
|
|
1466
|
-
} else if (currentChildIndex !== i) {
|
|
1467
|
-
patches.push({
|
|
1468
|
-
type: NavigateSibling,
|
|
1469
|
-
index: i
|
|
1470
|
-
});
|
|
1471
|
-
currentChildIndex = i;
|
|
1472
|
-
}
|
|
1473
|
-
// Apply node patches (these apply to the current element, not children)
|
|
1474
|
-
if (nodePatches.length > 0) {
|
|
1475
|
-
patches.push(...nodePatches);
|
|
1476
|
-
}
|
|
1477
|
-
// Compare children recursively
|
|
1478
|
-
if (hasChildrenToCompare) {
|
|
1479
|
-
diffChildren(oldNode.children, newNode.children, patches);
|
|
1480
|
-
}
|
|
1481
|
-
}
|
|
1482
|
-
} else {
|
|
1483
|
-
// Remove old node - collect the index for later removal
|
|
1893
|
+
currentChildIndex = navigateToParent(patches, currentChildIndex);
|
|
1894
|
+
addTree(newNode, patches);
|
|
1895
|
+
continue;
|
|
1896
|
+
}
|
|
1897
|
+
if (!newNode) {
|
|
1484
1898
|
indicesToRemove.push(i);
|
|
1899
|
+
continue;
|
|
1485
1900
|
}
|
|
1901
|
+
currentChildIndex = diffExistingChild(oldNode, newNode, patches, currentChildIndex, i);
|
|
1486
1902
|
}
|
|
1487
|
-
|
|
1488
|
-
if (currentChildIndex >= 0) {
|
|
1489
|
-
patches.push({
|
|
1490
|
-
type: NavigateParent
|
|
1491
|
-
});
|
|
1492
|
-
currentChildIndex = -1;
|
|
1493
|
-
}
|
|
1494
|
-
// Add remove patches in reverse order (highest index first)
|
|
1495
|
-
// This ensures indices remain valid as we remove
|
|
1903
|
+
navigateToParent(patches, currentChildIndex);
|
|
1496
1904
|
for (let j = indicesToRemove.length - 1; j >= 0; j--) {
|
|
1497
1905
|
patches.push({
|
|
1498
1906
|
type: RemoveChild,
|
|
@@ -1501,47 +1909,22 @@ const diffChildren = (oldChildren, newChildren, patches) => {
|
|
|
1501
1909
|
}
|
|
1502
1910
|
};
|
|
1503
1911
|
const diffTrees = (oldTree, newTree, patches, path) => {
|
|
1504
|
-
// At the root level (path.length === 0), we're already AT the element
|
|
1505
|
-
// So we compare the root node directly, then compare its children
|
|
1506
1912
|
if (path.length === 0 && oldTree.length === 1 && newTree.length === 1) {
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
// Compare root nodes
|
|
1510
|
-
const nodePatches = compareNodes(oldNode.node, newNode.node);
|
|
1511
|
-
// If nodePatches is null, the root node types are incompatible - need to replace
|
|
1512
|
-
if (nodePatches === null) {
|
|
1513
|
-
const flatNodes = treeToArray(newNode);
|
|
1514
|
-
patches.push({
|
|
1515
|
-
type: Replace,
|
|
1516
|
-
nodes: flatNodes
|
|
1517
|
-
});
|
|
1518
|
-
return;
|
|
1519
|
-
}
|
|
1520
|
-
if (nodePatches.length > 0) {
|
|
1521
|
-
patches.push(...nodePatches);
|
|
1522
|
-
}
|
|
1523
|
-
// Compare children
|
|
1524
|
-
if (oldNode.children.length > 0 || newNode.children.length > 0) {
|
|
1525
|
-
diffChildren(oldNode.children, newNode.children, patches);
|
|
1526
|
-
}
|
|
1527
|
-
} else {
|
|
1528
|
-
// Non-root level or multiple root elements - use the regular comparison
|
|
1529
|
-
diffChildren(oldTree, newTree, patches);
|
|
1913
|
+
diffRootNode(oldTree[0], newTree[0], patches);
|
|
1914
|
+
return;
|
|
1530
1915
|
}
|
|
1916
|
+
diffChildren(oldTree, newTree, patches);
|
|
1531
1917
|
};
|
|
1532
1918
|
|
|
1533
1919
|
const removeTrailingNavigationPatches = patches => {
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
for (let i = patches.length - 1; i >= 0; i--) {
|
|
1537
|
-
const patch = patches[i];
|
|
1920
|
+
while (patches.length > 0) {
|
|
1921
|
+
const patch = patches.at(-1);
|
|
1538
1922
|
if (patch.type !== NavigateChild && patch.type !== NavigateParent && patch.type !== NavigateSibling) {
|
|
1539
|
-
lastNonNavigationIndex = i;
|
|
1540
1923
|
break;
|
|
1541
1924
|
}
|
|
1925
|
+
patches.pop();
|
|
1542
1926
|
}
|
|
1543
|
-
|
|
1544
|
-
return lastNonNavigationIndex === -1 ? [] : patches.slice(0, lastNonNavigationIndex + 1);
|
|
1927
|
+
return patches;
|
|
1545
1928
|
};
|
|
1546
1929
|
|
|
1547
1930
|
const diffTree = (oldNodes, newNodes) => {
|
|
@@ -1566,17 +1949,19 @@ const IconButton = 'IconButton';
|
|
|
1566
1949
|
const MaskIcon = 'MaskIcon';
|
|
1567
1950
|
const MaskIconChevronUp = 'MaskIconChevronUp';
|
|
1568
1951
|
const MaskIconClose = 'MaskIconClose';
|
|
1952
|
+
const MaskIconRestore = 'MaskIconRestore';
|
|
1569
1953
|
const Actions = 'Actions';
|
|
1570
1954
|
|
|
1955
|
+
const emptyActionsNode = {
|
|
1956
|
+
childCount: 0,
|
|
1957
|
+
className: Actions,
|
|
1958
|
+
role: ToolBar,
|
|
1959
|
+
type: Div
|
|
1960
|
+
};
|
|
1571
1961
|
const getActionsDom = newState => {
|
|
1572
1962
|
const actions = newState.actionsUid || -1;
|
|
1573
|
-
if (actions
|
|
1574
|
-
return [
|
|
1575
|
-
childCount: 0,
|
|
1576
|
-
className: Actions,
|
|
1577
|
-
role: ToolBar,
|
|
1578
|
-
type: Div
|
|
1579
|
-
}];
|
|
1963
|
+
if (actions <= 0) {
|
|
1964
|
+
return [emptyActionsNode];
|
|
1580
1965
|
}
|
|
1581
1966
|
return [{
|
|
1582
1967
|
type: Reference,
|
|
@@ -1586,47 +1971,59 @@ const getActionsDom = newState => {
|
|
|
1586
1971
|
|
|
1587
1972
|
const HandleClickClose = 'handleClickClose';
|
|
1588
1973
|
const HandleClickMaximize = 'handleClickMaximize';
|
|
1974
|
+
const HandleClickUnmaximize = 'handleClickUnmaximize';
|
|
1589
1975
|
const HandleClickSelectTab = 'HandleClickSelectTab';
|
|
1590
1976
|
const HandleClickTab = 'HandleClickTab';
|
|
1591
1977
|
|
|
1592
1978
|
const emptyObject = {};
|
|
1593
|
-
const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
|
|
1594
1979
|
const i18nString = (key, placeholders = emptyObject) => {
|
|
1595
1980
|
if (placeholders === emptyObject) {
|
|
1596
1981
|
return key;
|
|
1597
1982
|
}
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1983
|
+
let result = key;
|
|
1984
|
+
for (const [placeholder, replacement] of Object.entries(placeholders)) {
|
|
1985
|
+
result = result.split(`{${placeholder}}`).join(String(replacement));
|
|
1986
|
+
}
|
|
1987
|
+
return result;
|
|
1602
1988
|
};
|
|
1603
1989
|
|
|
1604
1990
|
const Maximize = 'Maximize';
|
|
1991
|
+
const Unmaximize = 'Unmaximize';
|
|
1605
1992
|
const Close = 'Close';
|
|
1606
1993
|
|
|
1607
1994
|
const maximize = () => {
|
|
1608
1995
|
return i18nString(Maximize);
|
|
1609
1996
|
};
|
|
1997
|
+
const unmaximize = () => {
|
|
1998
|
+
return i18nString(Unmaximize);
|
|
1999
|
+
};
|
|
1610
2000
|
const close = () => {
|
|
1611
2001
|
return i18nString(Close);
|
|
1612
2002
|
};
|
|
1613
2003
|
|
|
1614
|
-
const
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
2004
|
+
const panelToolBarNode = {
|
|
2005
|
+
childCount: 2,
|
|
2006
|
+
className: PanelToolBar,
|
|
2007
|
+
role: ToolBar,
|
|
2008
|
+
type: Div
|
|
2009
|
+
};
|
|
2010
|
+
const getGlobalActionsDom = state => {
|
|
2011
|
+
const {
|
|
2012
|
+
maximized
|
|
2013
|
+
} = state;
|
|
2014
|
+
const maximizeLabel = maximized ? unmaximize() : maximize();
|
|
2015
|
+
const maximizeOnClick = maximized ? HandleClickUnmaximize : HandleClickMaximize;
|
|
2016
|
+
const maximizeIcon = maximized ? MaskIconRestore : MaskIconChevronUp;
|
|
2017
|
+
return [panelToolBarNode, {
|
|
2018
|
+
ariaLabel: maximizeLabel,
|
|
1622
2019
|
childCount: 1,
|
|
1623
2020
|
className: IconButton,
|
|
1624
|
-
onClick:
|
|
1625
|
-
title:
|
|
2021
|
+
onClick: maximizeOnClick,
|
|
2022
|
+
title: maximizeLabel,
|
|
1626
2023
|
type: Button
|
|
1627
2024
|
}, {
|
|
1628
2025
|
childCount: 0,
|
|
1629
|
-
className: mergeClassNames(MaskIcon,
|
|
2026
|
+
className: mergeClassNames(MaskIcon, maximizeIcon),
|
|
1630
2027
|
type: Div
|
|
1631
2028
|
}, {
|
|
1632
2029
|
ariaLabel: close(),
|
|
@@ -1642,14 +2039,19 @@ const getGlobalActionsDom = () => {
|
|
|
1642
2039
|
}];
|
|
1643
2040
|
};
|
|
1644
2041
|
|
|
2042
|
+
const selectedClass = mergeClassNames(PanelTab, PanelTabSelected);
|
|
1645
2043
|
const getTabClassName = isSelected => {
|
|
1646
|
-
let className = PanelTab;
|
|
1647
2044
|
if (isSelected) {
|
|
1648
|
-
|
|
2045
|
+
return selectedClass;
|
|
1649
2046
|
}
|
|
1650
|
-
return
|
|
2047
|
+
return PanelTab;
|
|
1651
2048
|
};
|
|
1652
2049
|
|
|
2050
|
+
const badgeNode = {
|
|
2051
|
+
childCount: 1,
|
|
2052
|
+
className: Badge,
|
|
2053
|
+
type: Div
|
|
2054
|
+
};
|
|
1653
2055
|
const createPanelTab = (tab, badgeCount, isSelected) => {
|
|
1654
2056
|
const label = tab;
|
|
1655
2057
|
const className = getTabClassName(isSelected);
|
|
@@ -1665,11 +2067,8 @@ const createPanelTab = (tab, badgeCount, isSelected) => {
|
|
|
1665
2067
|
};
|
|
1666
2068
|
const dom = [tabDom, text(label)];
|
|
1667
2069
|
if (badgeCount) {
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
className: Badge,
|
|
1671
|
-
type: Div
|
|
1672
|
-
}, text(' ' + badgeCount));
|
|
2070
|
+
const badgeCountText = ` ${badgeCount}`;
|
|
2071
|
+
dom.push(badgeNode, text(badgeCountText));
|
|
1673
2072
|
}
|
|
1674
2073
|
return dom;
|
|
1675
2074
|
};
|
|
@@ -1685,29 +2084,31 @@ const getPanelTabsVirtualDom = (tabs, selectedIndex, badgeCounts) => {
|
|
|
1685
2084
|
return dom;
|
|
1686
2085
|
};
|
|
1687
2086
|
|
|
2087
|
+
const panelHeaderNode = {
|
|
2088
|
+
childCount: 3,
|
|
2089
|
+
className: PanelHeader,
|
|
2090
|
+
type: Div
|
|
2091
|
+
};
|
|
1688
2092
|
const getPanelHeaderDom = newState => {
|
|
1689
2093
|
const tabsDom = getPanelTabsVirtualDom(newState.views, newState.selectedIndex, newState.badgeCounts);
|
|
1690
|
-
return [{
|
|
1691
|
-
childCount: 3,
|
|
1692
|
-
className: PanelHeader,
|
|
1693
|
-
type: Div
|
|
1694
|
-
}, {
|
|
2094
|
+
return [panelHeaderNode, {
|
|
1695
2095
|
childCount: newState.views.length,
|
|
1696
2096
|
className: PanelTabs,
|
|
1697
2097
|
role: TabList,
|
|
1698
2098
|
type: Div
|
|
1699
|
-
}, ...tabsDom, ...getActionsDom(newState), ...getGlobalActionsDom()];
|
|
2099
|
+
}, ...tabsDom, ...getActionsDom(newState), ...getGlobalActionsDom(newState)];
|
|
1700
2100
|
};
|
|
1701
2101
|
|
|
2102
|
+
const panelNode = {
|
|
2103
|
+
childCount: 2,
|
|
2104
|
+
className: Panel,
|
|
2105
|
+
type: Div
|
|
2106
|
+
};
|
|
1702
2107
|
const getPanelDom = newState => {
|
|
1703
2108
|
const {
|
|
1704
2109
|
childUid
|
|
1705
2110
|
} = newState;
|
|
1706
|
-
return [{
|
|
1707
|
-
childCount: 2,
|
|
1708
|
-
className: Panel,
|
|
1709
|
-
type: Div
|
|
1710
|
-
}, ...getPanelHeaderDom(newState), {
|
|
2111
|
+
return [panelNode, ...getPanelHeaderDom(newState), {
|
|
1711
2112
|
type: Reference,
|
|
1712
2113
|
uid: childUid
|
|
1713
2114
|
}];
|
|
@@ -1733,6 +2134,8 @@ const renderIncremental = (oldState, newState) => {
|
|
|
1733
2134
|
|
|
1734
2135
|
const getRenderer = diffType => {
|
|
1735
2136
|
switch (diffType) {
|
|
2137
|
+
case RenderActionsUid:
|
|
2138
|
+
return renderActionsUid;
|
|
1736
2139
|
case RenderChildUid:
|
|
1737
2140
|
return renderChildUid;
|
|
1738
2141
|
case RenderIncremental:
|
|
@@ -1770,6 +2173,9 @@ const renderEventListeners = () => {
|
|
|
1770
2173
|
return [{
|
|
1771
2174
|
name: HandleClickMaximize,
|
|
1772
2175
|
params: ['handleClickMaximize']
|
|
2176
|
+
}, {
|
|
2177
|
+
name: HandleClickUnmaximize,
|
|
2178
|
+
params: ['handleClickUnmaximize']
|
|
1773
2179
|
}, {
|
|
1774
2180
|
name: HandleClickClose,
|
|
1775
2181
|
params: ['handleClickClose']
|
|
@@ -1817,7 +2223,10 @@ const selectName = async (state, name) => {
|
|
|
1817
2223
|
if (!name) {
|
|
1818
2224
|
return state;
|
|
1819
2225
|
}
|
|
1820
|
-
const
|
|
2226
|
+
const {
|
|
2227
|
+
views
|
|
2228
|
+
} = state;
|
|
2229
|
+
const index = views.indexOf(name);
|
|
1821
2230
|
if (index === -1) {
|
|
1822
2231
|
return state;
|
|
1823
2232
|
}
|
|
@@ -1831,7 +2240,9 @@ const commandMap = {
|
|
|
1831
2240
|
'Panel.handleBlur': wrapCommand(handleBlur),
|
|
1832
2241
|
'Panel.handleClickClose': wrapCommand(handleClickClose),
|
|
1833
2242
|
'Panel.handleClickMaximize': wrapCommand(handleClickMaximize),
|
|
2243
|
+
'Panel.handleClickUnmaximize': wrapCommand(handleClickUnmaximize),
|
|
1834
2244
|
'Panel.handleFilterInput': wrapCommand(handleFilterInput),
|
|
2245
|
+
'Panel.handlePanelLayoutChanged': wrapCommand(handlePanelLayoutChanged),
|
|
1835
2246
|
'Panel.loadContent': wrapCommand(loadContent),
|
|
1836
2247
|
'Panel.openViewlet': wrapCommand(openViewlet),
|
|
1837
2248
|
'Panel.render2': render2,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/panel-worker",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Panel Worker",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -9,8 +9,5 @@
|
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"author": "Lvce Editor",
|
|
11
11
|
"type": "module",
|
|
12
|
-
"main": "dist/panelWorkerMain.js"
|
|
13
|
-
"dependencies": {
|
|
14
|
-
"@lvce-editor/virtual-dom-worker": "^8.3.0"
|
|
15
|
-
}
|
|
12
|
+
"main": "dist/panelWorkerMain.js"
|
|
16
13
|
}
|