@lvce-editor/panel-worker 1.0.0 → 1.2.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 +250 -32
- package/package.json +1 -1
package/dist/panelWorkerMain.js
CHANGED
|
@@ -54,6 +54,55 @@ class VError extends Error {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
class AssertionError extends Error {
|
|
58
|
+
constructor(message) {
|
|
59
|
+
super(message);
|
|
60
|
+
this.name = 'AssertionError';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const Object$1 = 1;
|
|
64
|
+
const Number$1 = 2;
|
|
65
|
+
const Array$1 = 3;
|
|
66
|
+
const String = 4;
|
|
67
|
+
const Boolean = 5;
|
|
68
|
+
const Function = 6;
|
|
69
|
+
const Null = 7;
|
|
70
|
+
const Unknown = 8;
|
|
71
|
+
const getType = value => {
|
|
72
|
+
switch (typeof value) {
|
|
73
|
+
case 'number':
|
|
74
|
+
return Number$1;
|
|
75
|
+
case 'function':
|
|
76
|
+
return Function;
|
|
77
|
+
case 'string':
|
|
78
|
+
return String;
|
|
79
|
+
case 'object':
|
|
80
|
+
if (value === null) {
|
|
81
|
+
return Null;
|
|
82
|
+
}
|
|
83
|
+
if (Array.isArray(value)) {
|
|
84
|
+
return Array$1;
|
|
85
|
+
}
|
|
86
|
+
return Object$1;
|
|
87
|
+
case 'boolean':
|
|
88
|
+
return Boolean;
|
|
89
|
+
default:
|
|
90
|
+
return Unknown;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const object = value => {
|
|
94
|
+
const type = getType(value);
|
|
95
|
+
if (type !== Object$1) {
|
|
96
|
+
throw new AssertionError('expected value to be of type object');
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const string = value => {
|
|
100
|
+
const type = getType(value);
|
|
101
|
+
if (type !== String) {
|
|
102
|
+
throw new AssertionError('expected value to be of type string');
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
57
106
|
const isMessagePort = value => {
|
|
58
107
|
return value && value instanceof MessagePort;
|
|
59
108
|
};
|
|
@@ -604,7 +653,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
|
604
653
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
605
654
|
return create$1$1(id, errorProperty);
|
|
606
655
|
};
|
|
607
|
-
const create$
|
|
656
|
+
const create$8 = (message, result) => {
|
|
608
657
|
return {
|
|
609
658
|
jsonrpc: Two$1,
|
|
610
659
|
id: message.id,
|
|
@@ -613,7 +662,7 @@ const create$7 = (message, result) => {
|
|
|
613
662
|
};
|
|
614
663
|
const getSuccessResponse = (message, result) => {
|
|
615
664
|
const resultProperty = result ?? null;
|
|
616
|
-
return create$
|
|
665
|
+
return create$8(message, resultProperty);
|
|
617
666
|
};
|
|
618
667
|
const getErrorResponseSimple = (id, error) => {
|
|
619
668
|
return {
|
|
@@ -707,7 +756,7 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
707
756
|
|
|
708
757
|
const Two = '2.0';
|
|
709
758
|
|
|
710
|
-
const create$
|
|
759
|
+
const create$7 = (method, params) => {
|
|
711
760
|
return {
|
|
712
761
|
jsonrpc: Two,
|
|
713
762
|
method,
|
|
@@ -715,7 +764,7 @@ const create$6 = (method, params) => {
|
|
|
715
764
|
};
|
|
716
765
|
};
|
|
717
766
|
|
|
718
|
-
const create$
|
|
767
|
+
const create$6 = (id, method, params) => {
|
|
719
768
|
const message = {
|
|
720
769
|
id,
|
|
721
770
|
jsonrpc: Two,
|
|
@@ -726,12 +775,12 @@ const create$5 = (id, method, params) => {
|
|
|
726
775
|
};
|
|
727
776
|
|
|
728
777
|
let id = 0;
|
|
729
|
-
const create$
|
|
778
|
+
const create$5 = () => {
|
|
730
779
|
return ++id;
|
|
731
780
|
};
|
|
732
781
|
|
|
733
782
|
const registerPromise = map => {
|
|
734
|
-
const id = create$
|
|
783
|
+
const id = create$5();
|
|
735
784
|
const {
|
|
736
785
|
promise,
|
|
737
786
|
resolve
|
|
@@ -749,7 +798,7 @@ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer)
|
|
|
749
798
|
id,
|
|
750
799
|
promise
|
|
751
800
|
} = registerPromise(callbacks);
|
|
752
|
-
const message = create$
|
|
801
|
+
const message = create$6(id, method, params);
|
|
753
802
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
754
803
|
ipc.sendAndTransfer(message);
|
|
755
804
|
} else {
|
|
@@ -785,7 +834,7 @@ const createRpc = ipc => {
|
|
|
785
834
|
* @deprecated
|
|
786
835
|
*/
|
|
787
836
|
send(method, ...params) {
|
|
788
|
-
const message = create$
|
|
837
|
+
const message = create$7(method, params);
|
|
789
838
|
ipc.send(message);
|
|
790
839
|
}
|
|
791
840
|
};
|
|
@@ -825,7 +874,7 @@ const listen$1 = async (module, options) => {
|
|
|
825
874
|
return ipc;
|
|
826
875
|
};
|
|
827
876
|
|
|
828
|
-
const create$
|
|
877
|
+
const create$4 = async ({
|
|
829
878
|
commandMap
|
|
830
879
|
}) => {
|
|
831
880
|
// TODO create a commandMap per rpc instance
|
|
@@ -877,7 +926,7 @@ const remove = id => {
|
|
|
877
926
|
};
|
|
878
927
|
|
|
879
928
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
880
|
-
const create$
|
|
929
|
+
const create$3 = rpcId => {
|
|
881
930
|
return {
|
|
882
931
|
async dispose() {
|
|
883
932
|
const rpc = get$1(rpcId);
|
|
@@ -914,14 +963,15 @@ const create$2 = rpcId => {
|
|
|
914
963
|
};
|
|
915
964
|
|
|
916
965
|
const {
|
|
966
|
+
invoke,
|
|
917
967
|
set: set$1
|
|
918
|
-
} = create$
|
|
968
|
+
} = create$3(RendererWorker);
|
|
919
969
|
|
|
920
970
|
const toCommandId = key => {
|
|
921
971
|
const dotIndex = key.indexOf('.');
|
|
922
972
|
return key.slice(dotIndex + 1);
|
|
923
973
|
};
|
|
924
|
-
const create$
|
|
974
|
+
const create$2 = () => {
|
|
925
975
|
const states = Object.create(null);
|
|
926
976
|
const commandMapRef = {};
|
|
927
977
|
return {
|
|
@@ -1013,21 +1063,26 @@ const {
|
|
|
1013
1063
|
set,
|
|
1014
1064
|
wrapCommand,
|
|
1015
1065
|
wrapGetter
|
|
1016
|
-
} = create$
|
|
1066
|
+
} = create$2();
|
|
1017
1067
|
|
|
1018
|
-
const create = (uid, uri, x, y, width, height, platform, assetDir) => {
|
|
1068
|
+
const create$1 = (uid, uri, x, y, width, height, platform, assetDir) => {
|
|
1019
1069
|
const state = {
|
|
1020
1070
|
actionsUid: 0,
|
|
1021
1071
|
assetDir,
|
|
1022
1072
|
badgeCounts: {},
|
|
1023
1073
|
childUid: 0,
|
|
1074
|
+
currentViewletId: '',
|
|
1024
1075
|
errorCount: 0,
|
|
1076
|
+
height: 0,
|
|
1025
1077
|
initial: true,
|
|
1026
1078
|
platform,
|
|
1027
1079
|
selectedIndex: -1,
|
|
1028
1080
|
uid,
|
|
1029
1081
|
views: [],
|
|
1030
|
-
warningCount: 0
|
|
1082
|
+
warningCount: 0,
|
|
1083
|
+
width: 0,
|
|
1084
|
+
x: 0,
|
|
1085
|
+
y: 0
|
|
1031
1086
|
};
|
|
1032
1087
|
set(uid, state, state);
|
|
1033
1088
|
};
|
|
@@ -1062,15 +1117,153 @@ const diff2 = uid => {
|
|
|
1062
1117
|
return result;
|
|
1063
1118
|
};
|
|
1064
1119
|
|
|
1065
|
-
const
|
|
1120
|
+
const DebugConsole = 'Debug Console';
|
|
1121
|
+
const Output = 'Output';
|
|
1122
|
+
const Problems = 'Problems';
|
|
1123
|
+
const Terminals = 'Terminals';
|
|
1124
|
+
|
|
1125
|
+
const getPanelViews = () => {
|
|
1126
|
+
const views = [Problems, Output, DebugConsole, Terminals];
|
|
1127
|
+
return views;
|
|
1128
|
+
};
|
|
1129
|
+
|
|
1130
|
+
let idCounter = 0;
|
|
1131
|
+
const create = () => {
|
|
1132
|
+
idCounter++;
|
|
1133
|
+
return idCounter;
|
|
1134
|
+
};
|
|
1135
|
+
|
|
1136
|
+
const getSavedViewletId = savedState => {
|
|
1137
|
+
if (savedState && savedState.currentViewletId) {
|
|
1138
|
+
return savedState.currentViewletId || Problems;
|
|
1139
|
+
}
|
|
1140
|
+
return Problems;
|
|
1141
|
+
};
|
|
1142
|
+
const loadContent = (state, savedState) => {
|
|
1143
|
+
const savedViewletId = getSavedViewletId(savedState);
|
|
1144
|
+
const views = getPanelViews();
|
|
1145
|
+
const loaded = {
|
|
1146
|
+
...state,
|
|
1147
|
+
currentViewletId: savedViewletId,
|
|
1148
|
+
views
|
|
1149
|
+
};
|
|
1150
|
+
return openViewlet(loaded, savedViewletId);
|
|
1151
|
+
};
|
|
1152
|
+
const setBadgeCount = (state, id, count) => {
|
|
1153
|
+
const {
|
|
1154
|
+
badgeCounts
|
|
1155
|
+
} = state;
|
|
1066
1156
|
return {
|
|
1067
1157
|
...state,
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1158
|
+
badgeCounts: {
|
|
1159
|
+
...badgeCounts,
|
|
1160
|
+
[id]: count
|
|
1161
|
+
}
|
|
1071
1162
|
};
|
|
1072
1163
|
};
|
|
1073
1164
|
|
|
1165
|
+
// export const contentLoaded = (state) => {
|
|
1166
|
+
// const commands = []
|
|
1167
|
+
// return commands
|
|
1168
|
+
// }
|
|
1169
|
+
|
|
1170
|
+
const getContentDimensions = dimensions => {
|
|
1171
|
+
return {
|
|
1172
|
+
height: dimensions.height - 35,
|
|
1173
|
+
width: dimensions.width,
|
|
1174
|
+
x: dimensions.x,
|
|
1175
|
+
y: dimensions.y + 35
|
|
1176
|
+
};
|
|
1177
|
+
};
|
|
1178
|
+
const openViewlet = async (state, id, focus = false) => {
|
|
1179
|
+
const childDimensions = getContentDimensions(state);
|
|
1180
|
+
const {
|
|
1181
|
+
uid
|
|
1182
|
+
} = state;
|
|
1183
|
+
const childUid = create();
|
|
1184
|
+
const commands = await ViewletManager.load({
|
|
1185
|
+
append: false,
|
|
1186
|
+
args: [],
|
|
1187
|
+
focus,
|
|
1188
|
+
getModule: ViewletModule.load,
|
|
1189
|
+
height: childDimensions.height,
|
|
1190
|
+
id,
|
|
1191
|
+
parentUid: uid,
|
|
1192
|
+
setBounds: false,
|
|
1193
|
+
shouldRenderEvents: false,
|
|
1194
|
+
show: false,
|
|
1195
|
+
type: 0,
|
|
1196
|
+
uid: childUid,
|
|
1197
|
+
// @ts-ignore
|
|
1198
|
+
uri: '',
|
|
1199
|
+
width: childDimensions.width,
|
|
1200
|
+
x: childDimensions.x,
|
|
1201
|
+
y: childDimensions.y
|
|
1202
|
+
}, false, true);
|
|
1203
|
+
let actionsDom = [];
|
|
1204
|
+
let actionsUid = -1;
|
|
1205
|
+
if (commands) {
|
|
1206
|
+
const actionsDomIndex = commands.findIndex(command => command[2] === 'setActionsDom');
|
|
1207
|
+
if (actionsDomIndex !== -1) {
|
|
1208
|
+
const actionDomEntry = commands[actionsDomIndex]?.[3];
|
|
1209
|
+
if (Array.isArray(actionDomEntry)) {
|
|
1210
|
+
actionsDom = actionDomEntry;
|
|
1211
|
+
}
|
|
1212
|
+
commands.splice(actionsDomIndex, 1);
|
|
1213
|
+
}
|
|
1214
|
+
const eventsIndex = commands.findIndex(command => command[0] === 'Viewlet.registerEventListeners');
|
|
1215
|
+
const events = eventsIndex === -1 ? [] : commands[eventsIndex]?.[2];
|
|
1216
|
+
actionsUid = create();
|
|
1217
|
+
commands.push(['Viewlet.createFunctionalRoot', id, actionsUid, true], ['Viewlet.registerEventListeners', actionsUid, events], ['Viewlet.setDom2', actionsUid, actionsDom], ['Viewlet.setUid', actionsUid, childUid]);
|
|
1218
|
+
await RendererProcess.invoke('Viewlet.sendMultiple', commands);
|
|
1219
|
+
}
|
|
1220
|
+
return {
|
|
1221
|
+
...state,
|
|
1222
|
+
actionsUid,
|
|
1223
|
+
childUid,
|
|
1224
|
+
currentViewletId: id
|
|
1225
|
+
};
|
|
1226
|
+
};
|
|
1227
|
+
const handleClickClose = async state => {
|
|
1228
|
+
await Command.execute('Layout.hidePanel');
|
|
1229
|
+
return state;
|
|
1230
|
+
};
|
|
1231
|
+
const handleClickMaximize = async state => {
|
|
1232
|
+
// TODO
|
|
1233
|
+
return state;
|
|
1234
|
+
};
|
|
1235
|
+
const selectIndex = async (state, index) => {
|
|
1236
|
+
await openViewlet(state, state.views[index]);
|
|
1237
|
+
return {
|
|
1238
|
+
...state,
|
|
1239
|
+
selectedIndex: index
|
|
1240
|
+
};
|
|
1241
|
+
};
|
|
1242
|
+
const selectRaw = async (state, rawIndex) => {
|
|
1243
|
+
return selectIndex(state, Number.parseInt(rawIndex, 10));
|
|
1244
|
+
};
|
|
1245
|
+
const toggleView = async (state, name) => {
|
|
1246
|
+
const index = state.views.indexOf(name);
|
|
1247
|
+
if (index === -1) {
|
|
1248
|
+
return state;
|
|
1249
|
+
}
|
|
1250
|
+
if (name === state.currentViewletId) {
|
|
1251
|
+
// await Command.execute('Layout.hidePanel') // TODO
|
|
1252
|
+
return state;
|
|
1253
|
+
}
|
|
1254
|
+
return selectIndex(state, index);
|
|
1255
|
+
};
|
|
1256
|
+
const handleFilterInput = async (state, value) => {
|
|
1257
|
+
object(state);
|
|
1258
|
+
string(value);
|
|
1259
|
+
const {
|
|
1260
|
+
currentViewletId
|
|
1261
|
+
} = state;
|
|
1262
|
+
const fullCommand = `${currentViewletId}.handleFilterInput`;
|
|
1263
|
+
await Command.execute(fullCommand, value);
|
|
1264
|
+
return state;
|
|
1265
|
+
};
|
|
1266
|
+
|
|
1074
1267
|
const SetText = 1;
|
|
1075
1268
|
const Replace = 2;
|
|
1076
1269
|
const SetAttribute = 3;
|
|
@@ -1437,34 +1630,59 @@ const renderEventListeners = () => {
|
|
|
1437
1630
|
}];
|
|
1438
1631
|
};
|
|
1439
1632
|
|
|
1440
|
-
const resize = (state, dimensions) => {
|
|
1441
|
-
|
|
1633
|
+
const resize = async (state, dimensions) => {
|
|
1634
|
+
// TODO
|
|
1635
|
+
const currentViewletInstance = {};
|
|
1636
|
+
const newState = {
|
|
1442
1637
|
...state,
|
|
1443
1638
|
...dimensions
|
|
1444
1639
|
};
|
|
1640
|
+
if (!currentViewletInstance) {
|
|
1641
|
+
return {
|
|
1642
|
+
...newState
|
|
1643
|
+
};
|
|
1644
|
+
}
|
|
1645
|
+
// @ts-ignore
|
|
1646
|
+
const currentViewletUid = currentViewletInstance.state.uid;
|
|
1647
|
+
// @ts-ignore
|
|
1648
|
+
await invoke('Viewlet.resize', currentViewletUid, dimensions);
|
|
1649
|
+
return {
|
|
1650
|
+
...newState
|
|
1651
|
+
};
|
|
1445
1652
|
};
|
|
1446
1653
|
|
|
1447
1654
|
const saveState = state => {
|
|
1655
|
+
const {
|
|
1656
|
+
currentViewletId
|
|
1657
|
+
} = state;
|
|
1448
1658
|
return {
|
|
1449
|
-
|
|
1659
|
+
currentViewletId
|
|
1450
1660
|
};
|
|
1451
1661
|
};
|
|
1452
1662
|
|
|
1453
1663
|
const commandMap = {
|
|
1454
|
-
'
|
|
1455
|
-
'
|
|
1456
|
-
'
|
|
1457
|
-
'
|
|
1458
|
-
'
|
|
1459
|
-
'
|
|
1460
|
-
'
|
|
1461
|
-
'
|
|
1462
|
-
'
|
|
1664
|
+
'Panel.create': create$1,
|
|
1665
|
+
'Panel.diff2': diff2,
|
|
1666
|
+
'Panel.getCommandIds': getCommandIds,
|
|
1667
|
+
'Panel.handleClickClose': wrapCommand(handleClickClose),
|
|
1668
|
+
'Panel.handleClickMaximize': wrapCommand(handleClickMaximize),
|
|
1669
|
+
'Panel.handleFilterInput': wrapCommand(handleFilterInput),
|
|
1670
|
+
'Panel.loadContent': wrapCommand(loadContent),
|
|
1671
|
+
'Panel.openViewlet': wrapCommand(openViewlet),
|
|
1672
|
+
'Panel.render2': render2,
|
|
1673
|
+
'Panel.renderEventListeners': renderEventListeners,
|
|
1674
|
+
'Panel.resize': wrapCommand(resize),
|
|
1675
|
+
'Panel.saveState': wrapGetter(saveState),
|
|
1676
|
+
'Panel.selectIndex': wrapCommand(selectIndex),
|
|
1677
|
+
'Panel.selectIndexRaw': wrapCommand(selectRaw),
|
|
1678
|
+
'Panel.setBadgeCount': wrapCommand(setBadgeCount),
|
|
1679
|
+
'Panel.terminate': terminate,
|
|
1680
|
+
'Panel.toggleView': wrapCommand(toggleView)
|
|
1463
1681
|
};
|
|
1464
1682
|
|
|
1465
1683
|
const listen = async () => {
|
|
1466
1684
|
registerCommands(commandMap);
|
|
1467
|
-
const rpc = await create$
|
|
1685
|
+
const rpc = await create$4({
|
|
1468
1686
|
commandMap: commandMap
|
|
1469
1687
|
});
|
|
1470
1688
|
set$1(rpc);
|