@lvce-editor/panel-worker 1.2.0 → 1.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 +164 -75
- package/package.json +1 -1
package/dist/panelWorkerMain.js
CHANGED
|
@@ -653,7 +653,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
|
653
653
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
654
654
|
return create$1$1(id, errorProperty);
|
|
655
655
|
};
|
|
656
|
-
const create$
|
|
656
|
+
const create$7 = (message, result) => {
|
|
657
657
|
return {
|
|
658
658
|
jsonrpc: Two$1,
|
|
659
659
|
id: message.id,
|
|
@@ -662,7 +662,7 @@ const create$8 = (message, result) => {
|
|
|
662
662
|
};
|
|
663
663
|
const getSuccessResponse = (message, result) => {
|
|
664
664
|
const resultProperty = result ?? null;
|
|
665
|
-
return create$
|
|
665
|
+
return create$7(message, resultProperty);
|
|
666
666
|
};
|
|
667
667
|
const getErrorResponseSimple = (id, error) => {
|
|
668
668
|
return {
|
|
@@ -756,7 +756,7 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
756
756
|
|
|
757
757
|
const Two = '2.0';
|
|
758
758
|
|
|
759
|
-
const create$
|
|
759
|
+
const create$6 = (method, params) => {
|
|
760
760
|
return {
|
|
761
761
|
jsonrpc: Two,
|
|
762
762
|
method,
|
|
@@ -764,7 +764,7 @@ const create$7 = (method, params) => {
|
|
|
764
764
|
};
|
|
765
765
|
};
|
|
766
766
|
|
|
767
|
-
const create$
|
|
767
|
+
const create$5 = (id, method, params) => {
|
|
768
768
|
const message = {
|
|
769
769
|
id,
|
|
770
770
|
jsonrpc: Two,
|
|
@@ -775,12 +775,12 @@ const create$6 = (id, method, params) => {
|
|
|
775
775
|
};
|
|
776
776
|
|
|
777
777
|
let id = 0;
|
|
778
|
-
const create$
|
|
778
|
+
const create$4 = () => {
|
|
779
779
|
return ++id;
|
|
780
780
|
};
|
|
781
781
|
|
|
782
782
|
const registerPromise = map => {
|
|
783
|
-
const id = create$
|
|
783
|
+
const id = create$4();
|
|
784
784
|
const {
|
|
785
785
|
promise,
|
|
786
786
|
resolve
|
|
@@ -798,7 +798,7 @@ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer)
|
|
|
798
798
|
id,
|
|
799
799
|
promise
|
|
800
800
|
} = registerPromise(callbacks);
|
|
801
|
-
const message = create$
|
|
801
|
+
const message = create$5(id, method, params);
|
|
802
802
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
803
803
|
ipc.sendAndTransfer(message);
|
|
804
804
|
} else {
|
|
@@ -834,7 +834,7 @@ const createRpc = ipc => {
|
|
|
834
834
|
* @deprecated
|
|
835
835
|
*/
|
|
836
836
|
send(method, ...params) {
|
|
837
|
-
const message = create$
|
|
837
|
+
const message = create$6(method, params);
|
|
838
838
|
ipc.send(message);
|
|
839
839
|
}
|
|
840
840
|
};
|
|
@@ -874,7 +874,7 @@ const listen$1 = async (module, options) => {
|
|
|
874
874
|
return ipc;
|
|
875
875
|
};
|
|
876
876
|
|
|
877
|
-
const create$
|
|
877
|
+
const create$3 = async ({
|
|
878
878
|
commandMap
|
|
879
879
|
}) => {
|
|
880
880
|
// TODO create a commandMap per rpc instance
|
|
@@ -885,6 +885,9 @@ const create$4 = async ({
|
|
|
885
885
|
return rpc;
|
|
886
886
|
};
|
|
887
887
|
|
|
888
|
+
const Tab = 'tab';
|
|
889
|
+
|
|
890
|
+
const Button = 1;
|
|
888
891
|
const Div = 4;
|
|
889
892
|
const Text = 12;
|
|
890
893
|
const Reference = 100;
|
|
@@ -926,7 +929,7 @@ const remove = id => {
|
|
|
926
929
|
};
|
|
927
930
|
|
|
928
931
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
929
|
-
const create$
|
|
932
|
+
const create$2 = rpcId => {
|
|
930
933
|
return {
|
|
931
934
|
async dispose() {
|
|
932
935
|
const rpc = get$1(rpcId);
|
|
@@ -965,13 +968,13 @@ const create$3 = rpcId => {
|
|
|
965
968
|
const {
|
|
966
969
|
invoke,
|
|
967
970
|
set: set$1
|
|
968
|
-
} = create$
|
|
971
|
+
} = create$2(RendererWorker);
|
|
969
972
|
|
|
970
973
|
const toCommandId = key => {
|
|
971
974
|
const dotIndex = key.indexOf('.');
|
|
972
975
|
return key.slice(dotIndex + 1);
|
|
973
976
|
};
|
|
974
|
-
const create$
|
|
977
|
+
const create$1 = () => {
|
|
975
978
|
const states = Object.create(null);
|
|
976
979
|
const commandMapRef = {};
|
|
977
980
|
return {
|
|
@@ -1063,9 +1066,9 @@ const {
|
|
|
1063
1066
|
set,
|
|
1064
1067
|
wrapCommand,
|
|
1065
1068
|
wrapGetter
|
|
1066
|
-
} = create$
|
|
1069
|
+
} = create$1();
|
|
1067
1070
|
|
|
1068
|
-
const create
|
|
1071
|
+
const create = (uid, uri, x, y, width, height, platform, assetDir) => {
|
|
1069
1072
|
const state = {
|
|
1070
1073
|
actionsUid: 0,
|
|
1071
1074
|
assetDir,
|
|
@@ -1117,6 +1120,10 @@ const diff2 = uid => {
|
|
|
1117
1120
|
return result;
|
|
1118
1121
|
};
|
|
1119
1122
|
|
|
1123
|
+
const createViewlet = async (viewletModuleId, editorUid, tabId, bounds, uri) => {
|
|
1124
|
+
await invoke('Layout.createViewlet', viewletModuleId, editorUid, tabId, bounds, uri);
|
|
1125
|
+
};
|
|
1126
|
+
|
|
1120
1127
|
const DebugConsole = 'Debug Console';
|
|
1121
1128
|
const Output = 'Output';
|
|
1122
1129
|
const Problems = 'Problems';
|
|
@@ -1127,12 +1134,6 @@ const getPanelViews = () => {
|
|
|
1127
1134
|
return views;
|
|
1128
1135
|
};
|
|
1129
1136
|
|
|
1130
|
-
let idCounter = 0;
|
|
1131
|
-
const create = () => {
|
|
1132
|
-
idCounter++;
|
|
1133
|
-
return idCounter;
|
|
1134
|
-
};
|
|
1135
|
-
|
|
1136
1137
|
const getSavedViewletId = savedState => {
|
|
1137
1138
|
if (savedState && savedState.currentViewletId) {
|
|
1138
1139
|
return savedState.currentViewletId || Problems;
|
|
@@ -1175,48 +1176,25 @@ const getContentDimensions = dimensions => {
|
|
|
1175
1176
|
y: dimensions.y + 35
|
|
1176
1177
|
};
|
|
1177
1178
|
};
|
|
1179
|
+
|
|
1180
|
+
// TODO
|
|
1181
|
+
// export const getChildren = (state) => {
|
|
1182
|
+
// const { currentViewletId } = state
|
|
1183
|
+
// return [
|
|
1184
|
+
// {
|
|
1185
|
+
// id: currentViewletId,
|
|
1186
|
+
// ...getContentDimensions(state),
|
|
1187
|
+
// },
|
|
1188
|
+
// ]
|
|
1189
|
+
// }
|
|
1190
|
+
|
|
1178
1191
|
const openViewlet = async (state, id, focus = false) => {
|
|
1179
1192
|
const childDimensions = getContentDimensions(state);
|
|
1180
|
-
const
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
const
|
|
1184
|
-
|
|
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
|
-
}
|
|
1193
|
+
const childUid = Math.random();
|
|
1194
|
+
const tabId = 1234;
|
|
1195
|
+
// TODO get the actions uid somehow
|
|
1196
|
+
const actionsUid = Math.random();
|
|
1197
|
+
await createViewlet(id, childUid, tabId, childDimensions, '');
|
|
1220
1198
|
return {
|
|
1221
1199
|
...state,
|
|
1222
1200
|
actionsUid,
|
|
@@ -1225,7 +1203,7 @@ const openViewlet = async (state, id, focus = false) => {
|
|
|
1225
1203
|
};
|
|
1226
1204
|
};
|
|
1227
1205
|
const handleClickClose = async state => {
|
|
1228
|
-
await
|
|
1206
|
+
await invoke('Layout.hidePanel');
|
|
1229
1207
|
return state;
|
|
1230
1208
|
};
|
|
1231
1209
|
const handleClickMaximize = async state => {
|
|
@@ -1260,10 +1238,18 @@ const handleFilterInput = async (state, value) => {
|
|
|
1260
1238
|
currentViewletId
|
|
1261
1239
|
} = state;
|
|
1262
1240
|
const fullCommand = `${currentViewletId}.handleFilterInput`;
|
|
1263
|
-
await
|
|
1241
|
+
await invoke(fullCommand, value);
|
|
1264
1242
|
return state;
|
|
1265
1243
|
};
|
|
1266
1244
|
|
|
1245
|
+
const text = data => {
|
|
1246
|
+
return {
|
|
1247
|
+
childCount: 0,
|
|
1248
|
+
text: data,
|
|
1249
|
+
type: Text
|
|
1250
|
+
};
|
|
1251
|
+
};
|
|
1252
|
+
|
|
1267
1253
|
const SetText = 1;
|
|
1268
1254
|
const Replace = 2;
|
|
1269
1255
|
const SetAttribute = 3;
|
|
@@ -1552,15 +1538,121 @@ const diffTree = (oldNodes, newNodes) => {
|
|
|
1552
1538
|
return removeTrailingNavigationPatches(patches);
|
|
1553
1539
|
};
|
|
1554
1540
|
|
|
1555
|
-
const
|
|
1556
|
-
const
|
|
1541
|
+
const getActionsDom = newState => {
|
|
1542
|
+
const actions = newState.actionsUid || -1;
|
|
1543
|
+
if (actions === -1) {
|
|
1544
|
+
return [{
|
|
1545
|
+
childCount: 0,
|
|
1546
|
+
className: 'Actions',
|
|
1547
|
+
role: 'toolbar',
|
|
1548
|
+
type: Div
|
|
1549
|
+
}];
|
|
1550
|
+
}
|
|
1551
|
+
return [{
|
|
1552
|
+
type: Reference,
|
|
1553
|
+
uid: actions
|
|
1554
|
+
}];
|
|
1555
|
+
};
|
|
1556
|
+
|
|
1557
|
+
const HandleClickClose = 'handleClickClose';
|
|
1558
|
+
const HandleClickMaximize = 'handleClickMaximize';
|
|
1559
|
+
const HandleClickSelectTab = 'HandleClickSelectTab';
|
|
1560
|
+
|
|
1561
|
+
const getGlobalActionsDom = () => {
|
|
1562
|
+
return [{
|
|
1563
|
+
childCount: 2,
|
|
1564
|
+
className: 'PanelToolBar',
|
|
1565
|
+
role: 'toolbar',
|
|
1566
|
+
type: Div
|
|
1567
|
+
}, {
|
|
1568
|
+
ariaLabel: 'Maximize',
|
|
1569
|
+
childCount: 1,
|
|
1570
|
+
className: 'IconButton',
|
|
1571
|
+
onClick: HandleClickMaximize,
|
|
1572
|
+
titleM: 'Maximize',
|
|
1573
|
+
type: Button
|
|
1574
|
+
}, {
|
|
1557
1575
|
childCount: 0,
|
|
1558
|
-
className: '
|
|
1576
|
+
className: 'MaskIcon MaskIconChevronUp',
|
|
1577
|
+
type: Div
|
|
1578
|
+
}, {
|
|
1579
|
+
ariaLabel: 'Close',
|
|
1580
|
+
childCount: 1,
|
|
1581
|
+
className: 'IconButton',
|
|
1582
|
+
onClick: HandleClickClose,
|
|
1583
|
+
titleM: 'Close',
|
|
1584
|
+
type: Button
|
|
1585
|
+
}, {
|
|
1586
|
+
childCount: 0,
|
|
1587
|
+
className: 'MaskIcon MaskIconClose',
|
|
1559
1588
|
type: Div
|
|
1560
1589
|
}];
|
|
1590
|
+
};
|
|
1591
|
+
|
|
1592
|
+
const Badge = 'Badge';
|
|
1593
|
+
const PanelTab = 'PanelTab';
|
|
1594
|
+
const PanelTabSelected = 'PanelTabSelected';
|
|
1595
|
+
|
|
1596
|
+
const createPanelTab = (tab, badgeCount, isSelected, index) => {
|
|
1597
|
+
const label = tab;
|
|
1598
|
+
let className = PanelTab;
|
|
1599
|
+
if (isSelected) {
|
|
1600
|
+
className += ' ' + PanelTabSelected;
|
|
1601
|
+
}
|
|
1602
|
+
const childCount = badgeCount ? 2 : 1;
|
|
1603
|
+
const tabDom = {
|
|
1604
|
+
ariaSelected: isSelected,
|
|
1605
|
+
childCount,
|
|
1606
|
+
className,
|
|
1607
|
+
'data-index': index,
|
|
1608
|
+
onClick: HandleClickSelectTab,
|
|
1609
|
+
role: Tab,
|
|
1610
|
+
type: Div
|
|
1611
|
+
};
|
|
1612
|
+
const dom = [tabDom, text(label)];
|
|
1613
|
+
if (badgeCount) {
|
|
1614
|
+
dom.push({
|
|
1615
|
+
childCount: 1,
|
|
1616
|
+
className: Badge,
|
|
1617
|
+
type: Div
|
|
1618
|
+
}, text(' ' + badgeCount));
|
|
1619
|
+
}
|
|
1620
|
+
return dom;
|
|
1621
|
+
};
|
|
1622
|
+
const getPanelTabsVirtualDom = (tabs, selectedIndex, badgeCounts) => {
|
|
1623
|
+
const dom = [];
|
|
1624
|
+
for (let i = 0; i < tabs.length; i++) {
|
|
1625
|
+
const isSelected = i === selectedIndex;
|
|
1626
|
+
const tab = tabs[i];
|
|
1627
|
+
const badgeCount = badgeCounts[tab] || 0;
|
|
1628
|
+
dom.push(...createPanelTab(tab, badgeCount, isSelected, i));
|
|
1629
|
+
}
|
|
1561
1630
|
return dom;
|
|
1562
1631
|
};
|
|
1563
1632
|
|
|
1633
|
+
const getPanelDom = newState => {
|
|
1634
|
+
const {
|
|
1635
|
+
childUid
|
|
1636
|
+
} = newState;
|
|
1637
|
+
const tabsDom = getPanelTabsVirtualDom(newState.views, newState.selectedIndex, newState.badgeCounts);
|
|
1638
|
+
return [{
|
|
1639
|
+
childCount: 2,
|
|
1640
|
+
className: 'Panel',
|
|
1641
|
+
type: Div
|
|
1642
|
+
}, {
|
|
1643
|
+
childCount: 3,
|
|
1644
|
+
className: 'PanelHeader',
|
|
1645
|
+
type: Div
|
|
1646
|
+
}, {
|
|
1647
|
+
childCount: newState.views.length,
|
|
1648
|
+
className: 'PanelTabs',
|
|
1649
|
+
type: Div
|
|
1650
|
+
}, ...tabsDom, ...getActionsDom(newState), ...getGlobalActionsDom(), {
|
|
1651
|
+
type: Reference,
|
|
1652
|
+
uid: childUid
|
|
1653
|
+
}];
|
|
1654
|
+
};
|
|
1655
|
+
|
|
1564
1656
|
const renderItems = (oldState, newState) => {
|
|
1565
1657
|
const {
|
|
1566
1658
|
initial,
|
|
@@ -1569,7 +1661,7 @@ const renderItems = (oldState, newState) => {
|
|
|
1569
1661
|
if (initial) {
|
|
1570
1662
|
return [SetDom2, uid, []];
|
|
1571
1663
|
}
|
|
1572
|
-
const dom =
|
|
1664
|
+
const dom = getPanelDom(newState);
|
|
1573
1665
|
return [SetDom2, uid, dom];
|
|
1574
1666
|
};
|
|
1575
1667
|
|
|
@@ -1613,10 +1705,6 @@ const render2 = (uid, diffResult) => {
|
|
|
1613
1705
|
return commands;
|
|
1614
1706
|
};
|
|
1615
1707
|
|
|
1616
|
-
const HandleClickClose = 'handleClickClose';
|
|
1617
|
-
const HandleClickMaximize = 'handleClickMaximize';
|
|
1618
|
-
const HandleClickSelectTab = 'HandleClickSelectTab';
|
|
1619
|
-
|
|
1620
1708
|
const renderEventListeners = () => {
|
|
1621
1709
|
return [{
|
|
1622
1710
|
name: HandleClickMaximize,
|
|
@@ -1631,6 +1719,9 @@ const renderEventListeners = () => {
|
|
|
1631
1719
|
};
|
|
1632
1720
|
|
|
1633
1721
|
const resize = async (state, dimensions) => {
|
|
1722
|
+
const {
|
|
1723
|
+
childUid
|
|
1724
|
+
} = state;
|
|
1634
1725
|
// TODO
|
|
1635
1726
|
const currentViewletInstance = {};
|
|
1636
1727
|
const newState = {
|
|
@@ -1643,9 +1734,7 @@ const resize = async (state, dimensions) => {
|
|
|
1643
1734
|
};
|
|
1644
1735
|
}
|
|
1645
1736
|
// @ts-ignore
|
|
1646
|
-
|
|
1647
|
-
// @ts-ignore
|
|
1648
|
-
await invoke('Viewlet.resize', currentViewletUid, dimensions);
|
|
1737
|
+
await invoke('Viewlet.resize', childUid, dimensions);
|
|
1649
1738
|
return {
|
|
1650
1739
|
...newState
|
|
1651
1740
|
};
|
|
@@ -1661,7 +1750,7 @@ const saveState = state => {
|
|
|
1661
1750
|
};
|
|
1662
1751
|
|
|
1663
1752
|
const commandMap = {
|
|
1664
|
-
'Panel.create': create
|
|
1753
|
+
'Panel.create': create,
|
|
1665
1754
|
'Panel.diff2': diff2,
|
|
1666
1755
|
'Panel.getCommandIds': getCommandIds,
|
|
1667
1756
|
'Panel.handleClickClose': wrapCommand(handleClickClose),
|
|
@@ -1682,7 +1771,7 @@ const commandMap = {
|
|
|
1682
1771
|
|
|
1683
1772
|
const listen = async () => {
|
|
1684
1773
|
registerCommands(commandMap);
|
|
1685
|
-
const rpc = await create$
|
|
1774
|
+
const rpc = await create$3({
|
|
1686
1775
|
commandMap: commandMap
|
|
1687
1776
|
});
|
|
1688
1777
|
set$1(rpc);
|