@lvce-editor/panel-worker 1.1.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 +117 -9
- 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
|
};
|
|
@@ -1100,6 +1149,18 @@ const loadContent = (state, savedState) => {
|
|
|
1100
1149
|
};
|
|
1101
1150
|
return openViewlet(loaded, savedViewletId);
|
|
1102
1151
|
};
|
|
1152
|
+
const setBadgeCount = (state, id, count) => {
|
|
1153
|
+
const {
|
|
1154
|
+
badgeCounts
|
|
1155
|
+
} = state;
|
|
1156
|
+
return {
|
|
1157
|
+
...state,
|
|
1158
|
+
badgeCounts: {
|
|
1159
|
+
...badgeCounts,
|
|
1160
|
+
[id]: count
|
|
1161
|
+
}
|
|
1162
|
+
};
|
|
1163
|
+
};
|
|
1103
1164
|
|
|
1104
1165
|
// export const contentLoaded = (state) => {
|
|
1105
1166
|
// const commands = []
|
|
@@ -1163,6 +1224,45 @@ const openViewlet = async (state, id, focus = false) => {
|
|
|
1163
1224
|
currentViewletId: id
|
|
1164
1225
|
};
|
|
1165
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
|
+
};
|
|
1166
1266
|
|
|
1167
1267
|
const SetText = 1;
|
|
1168
1268
|
const Replace = 2;
|
|
@@ -1561,15 +1661,23 @@ const saveState = state => {
|
|
|
1561
1661
|
};
|
|
1562
1662
|
|
|
1563
1663
|
const commandMap = {
|
|
1564
|
-
'
|
|
1565
|
-
'
|
|
1566
|
-
'
|
|
1567
|
-
'
|
|
1568
|
-
'
|
|
1569
|
-
'
|
|
1570
|
-
'
|
|
1571
|
-
'
|
|
1572
|
-
'
|
|
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)
|
|
1573
1681
|
};
|
|
1574
1682
|
|
|
1575
1683
|
const listen = async () => {
|