@lvce-editor/panel-worker 2.7.0 → 2.9.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 +203 -44
- package/package.json +1 -1
package/dist/panelWorkerMain.js
CHANGED
|
@@ -423,6 +423,100 @@ const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
|
423
423
|
listen: listen$6,
|
|
424
424
|
wrap: wrap$e
|
|
425
425
|
};
|
|
426
|
+
const addListener = (emitter, type, callback) => {
|
|
427
|
+
if ('addEventListener' in emitter) {
|
|
428
|
+
emitter.addEventListener(type, callback);
|
|
429
|
+
} else {
|
|
430
|
+
emitter.on(type, callback);
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
const removeListener = (emitter, type, callback) => {
|
|
434
|
+
if ('removeEventListener' in emitter) {
|
|
435
|
+
emitter.removeEventListener(type, callback);
|
|
436
|
+
} else {
|
|
437
|
+
emitter.off(type, callback);
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
const getFirstEvent = (eventEmitter, eventMap) => {
|
|
441
|
+
const {
|
|
442
|
+
promise,
|
|
443
|
+
resolve
|
|
444
|
+
} = Promise.withResolvers();
|
|
445
|
+
const listenerMap = Object.create(null);
|
|
446
|
+
const cleanup = value => {
|
|
447
|
+
for (const event of Object.keys(eventMap)) {
|
|
448
|
+
removeListener(eventEmitter, event, listenerMap[event]);
|
|
449
|
+
}
|
|
450
|
+
resolve(value);
|
|
451
|
+
};
|
|
452
|
+
for (const [event, type] of Object.entries(eventMap)) {
|
|
453
|
+
const listener = event => {
|
|
454
|
+
cleanup({
|
|
455
|
+
event,
|
|
456
|
+
type
|
|
457
|
+
});
|
|
458
|
+
};
|
|
459
|
+
addListener(eventEmitter, event, listener);
|
|
460
|
+
listenerMap[event] = listener;
|
|
461
|
+
}
|
|
462
|
+
return promise;
|
|
463
|
+
};
|
|
464
|
+
const Message$1 = 3;
|
|
465
|
+
const create$5$1 = async ({
|
|
466
|
+
isMessagePortOpen,
|
|
467
|
+
messagePort
|
|
468
|
+
}) => {
|
|
469
|
+
if (!isMessagePort(messagePort)) {
|
|
470
|
+
throw new IpcError('port must be of type MessagePort');
|
|
471
|
+
}
|
|
472
|
+
if (isMessagePortOpen) {
|
|
473
|
+
return messagePort;
|
|
474
|
+
}
|
|
475
|
+
const eventPromise = getFirstEvent(messagePort, {
|
|
476
|
+
message: Message$1
|
|
477
|
+
});
|
|
478
|
+
messagePort.start();
|
|
479
|
+
const {
|
|
480
|
+
event,
|
|
481
|
+
type
|
|
482
|
+
} = await eventPromise;
|
|
483
|
+
if (type !== Message$1) {
|
|
484
|
+
throw new IpcError('Failed to wait for ipc message');
|
|
485
|
+
}
|
|
486
|
+
if (event.data !== readyMessage) {
|
|
487
|
+
throw new IpcError('unexpected first message');
|
|
488
|
+
}
|
|
489
|
+
return messagePort;
|
|
490
|
+
};
|
|
491
|
+
const signal$1 = messagePort => {
|
|
492
|
+
messagePort.start();
|
|
493
|
+
};
|
|
494
|
+
class IpcParentWithMessagePort extends Ipc {
|
|
495
|
+
getData = getData$2;
|
|
496
|
+
send(message) {
|
|
497
|
+
this._rawIpc.postMessage(message);
|
|
498
|
+
}
|
|
499
|
+
sendAndTransfer(message) {
|
|
500
|
+
const transfer = getTransferrables(message);
|
|
501
|
+
this._rawIpc.postMessage(message, transfer);
|
|
502
|
+
}
|
|
503
|
+
dispose() {
|
|
504
|
+
this._rawIpc.close();
|
|
505
|
+
}
|
|
506
|
+
onMessage(callback) {
|
|
507
|
+
this._rawIpc.addEventListener('message', callback);
|
|
508
|
+
}
|
|
509
|
+
onClose(callback) {}
|
|
510
|
+
}
|
|
511
|
+
const wrap$5 = messagePort => {
|
|
512
|
+
return new IpcParentWithMessagePort(messagePort);
|
|
513
|
+
};
|
|
514
|
+
const IpcParentWithMessagePort$1 = {
|
|
515
|
+
__proto__: null,
|
|
516
|
+
create: create$5$1,
|
|
517
|
+
signal: signal$1,
|
|
518
|
+
wrap: wrap$5
|
|
519
|
+
};
|
|
426
520
|
|
|
427
521
|
class CommandNotFoundError extends Error {
|
|
428
522
|
constructor(command) {
|
|
@@ -700,7 +794,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
|
700
794
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
701
795
|
return create$1$1(id, errorProperty);
|
|
702
796
|
};
|
|
703
|
-
const create$
|
|
797
|
+
const create$8 = (message, result) => {
|
|
704
798
|
return {
|
|
705
799
|
id: message.id,
|
|
706
800
|
jsonrpc: Two$1,
|
|
@@ -709,7 +803,7 @@ const create$7 = (message, result) => {
|
|
|
709
803
|
};
|
|
710
804
|
const getSuccessResponse = (message, result) => {
|
|
711
805
|
const resultProperty = result ?? null;
|
|
712
|
-
return create$
|
|
806
|
+
return create$8(message, resultProperty);
|
|
713
807
|
};
|
|
714
808
|
const getErrorResponseSimple = (id, error) => {
|
|
715
809
|
return {
|
|
@@ -803,7 +897,7 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
803
897
|
|
|
804
898
|
const Two = '2.0';
|
|
805
899
|
|
|
806
|
-
const create$
|
|
900
|
+
const create$7 = (method, params) => {
|
|
807
901
|
return {
|
|
808
902
|
jsonrpc: Two,
|
|
809
903
|
method,
|
|
@@ -811,7 +905,7 @@ const create$6 = (method, params) => {
|
|
|
811
905
|
};
|
|
812
906
|
};
|
|
813
907
|
|
|
814
|
-
const create$
|
|
908
|
+
const create$6 = (id, method, params) => {
|
|
815
909
|
const message = {
|
|
816
910
|
id,
|
|
817
911
|
jsonrpc: Two,
|
|
@@ -822,12 +916,12 @@ const create$5 = (id, method, params) => {
|
|
|
822
916
|
};
|
|
823
917
|
|
|
824
918
|
let id = 0;
|
|
825
|
-
const create$
|
|
919
|
+
const create$5 = () => {
|
|
826
920
|
return ++id;
|
|
827
921
|
};
|
|
828
922
|
|
|
829
923
|
const registerPromise = map => {
|
|
830
|
-
const id = create$
|
|
924
|
+
const id = create$5();
|
|
831
925
|
const {
|
|
832
926
|
promise,
|
|
833
927
|
resolve
|
|
@@ -844,7 +938,7 @@ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer)
|
|
|
844
938
|
id,
|
|
845
939
|
promise
|
|
846
940
|
} = registerPromise(callbacks);
|
|
847
|
-
const message = create$
|
|
941
|
+
const message = create$6(id, method, params);
|
|
848
942
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
849
943
|
ipc.sendAndTransfer(message);
|
|
850
944
|
} else {
|
|
@@ -880,7 +974,7 @@ const createRpc = ipc => {
|
|
|
880
974
|
* @deprecated
|
|
881
975
|
*/
|
|
882
976
|
send(method, ...params) {
|
|
883
|
-
const message = create$
|
|
977
|
+
const message = create$7(method, params);
|
|
884
978
|
ipc.send(message);
|
|
885
979
|
}
|
|
886
980
|
};
|
|
@@ -920,6 +1014,24 @@ const listen$1 = async (module, options) => {
|
|
|
920
1014
|
return ipc;
|
|
921
1015
|
};
|
|
922
1016
|
|
|
1017
|
+
const create$4 = async ({
|
|
1018
|
+
commandMap,
|
|
1019
|
+
isMessagePortOpen = true,
|
|
1020
|
+
messagePort
|
|
1021
|
+
}) => {
|
|
1022
|
+
// TODO create a commandMap per rpc instance
|
|
1023
|
+
register(commandMap);
|
|
1024
|
+
const rawIpc = await IpcParentWithMessagePort$1.create({
|
|
1025
|
+
isMessagePortOpen,
|
|
1026
|
+
messagePort
|
|
1027
|
+
});
|
|
1028
|
+
const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
|
|
1029
|
+
handleIpc(ipc);
|
|
1030
|
+
const rpc = createRpc(ipc);
|
|
1031
|
+
messagePort.start();
|
|
1032
|
+
return rpc;
|
|
1033
|
+
};
|
|
1034
|
+
|
|
923
1035
|
const create$3 = async ({
|
|
924
1036
|
commandMap
|
|
925
1037
|
}) => {
|
|
@@ -952,7 +1064,7 @@ const createMockRpc = ({
|
|
|
952
1064
|
};
|
|
953
1065
|
|
|
954
1066
|
const rpcs = Object.create(null);
|
|
955
|
-
const set$
|
|
1067
|
+
const set$4 = (id, rpc) => {
|
|
956
1068
|
rpcs[id] = rpc;
|
|
957
1069
|
};
|
|
958
1070
|
const get$1 = id => {
|
|
@@ -985,7 +1097,7 @@ const create$2 = rpcId => {
|
|
|
985
1097
|
const mockRpc = createMockRpc({
|
|
986
1098
|
commandMap
|
|
987
1099
|
});
|
|
988
|
-
set$
|
|
1100
|
+
set$4(rpcId, mockRpc);
|
|
989
1101
|
// @ts-ignore
|
|
990
1102
|
mockRpc[Symbol.dispose] = () => {
|
|
991
1103
|
remove(rpcId);
|
|
@@ -994,7 +1106,7 @@ const create$2 = rpcId => {
|
|
|
994
1106
|
return mockRpc;
|
|
995
1107
|
},
|
|
996
1108
|
set(rpc) {
|
|
997
|
-
set$
|
|
1109
|
+
set$4(rpcId, rpc);
|
|
998
1110
|
}
|
|
999
1111
|
};
|
|
1000
1112
|
};
|
|
@@ -1174,13 +1286,19 @@ const VirtualDomElements = {
|
|
|
1174
1286
|
|
|
1175
1287
|
const TargetName = 'event.target.name';
|
|
1176
1288
|
|
|
1289
|
+
const RendererProcess = 1670;
|
|
1177
1290
|
const RendererWorker = 1;
|
|
1178
1291
|
|
|
1179
1292
|
const SetPatches = 'Viewlet.setPatches';
|
|
1180
1293
|
|
|
1181
1294
|
const {
|
|
1182
|
-
invoke,
|
|
1183
|
-
set: set$
|
|
1295
|
+
invoke: invoke$2,
|
|
1296
|
+
set: set$3
|
|
1297
|
+
} = create$2(RendererProcess);
|
|
1298
|
+
|
|
1299
|
+
const {
|
|
1300
|
+
invoke: invoke$1,
|
|
1301
|
+
set: set$2
|
|
1184
1302
|
} = create$2(RendererWorker);
|
|
1185
1303
|
|
|
1186
1304
|
const toCommandId = key => {
|
|
@@ -1433,7 +1551,7 @@ const {
|
|
|
1433
1551
|
get,
|
|
1434
1552
|
getCommandIds,
|
|
1435
1553
|
registerCommands,
|
|
1436
|
-
set,
|
|
1554
|
+
set: set$1,
|
|
1437
1555
|
wrapCommand,
|
|
1438
1556
|
wrapGetter
|
|
1439
1557
|
} = create$1();
|
|
@@ -1460,7 +1578,7 @@ const create = (uid, uri, x, y, width, height, platform, assetDir) => {
|
|
|
1460
1578
|
x,
|
|
1461
1579
|
y
|
|
1462
1580
|
};
|
|
1463
|
-
set(uid, state, state);
|
|
1581
|
+
set$1(uid, state, state);
|
|
1464
1582
|
};
|
|
1465
1583
|
|
|
1466
1584
|
const isEqual$2 = (oldState, newState) => {
|
|
@@ -1503,17 +1621,70 @@ const diff2 = uid => {
|
|
|
1503
1621
|
return result;
|
|
1504
1622
|
};
|
|
1505
1623
|
|
|
1624
|
+
const state = {
|
|
1625
|
+
connected: false
|
|
1626
|
+
};
|
|
1627
|
+
const isConnected = () => {
|
|
1628
|
+
const {
|
|
1629
|
+
connected
|
|
1630
|
+
} = state;
|
|
1631
|
+
return connected;
|
|
1632
|
+
};
|
|
1633
|
+
const invoke = (method, ...params) => invoke$2(method, ...params);
|
|
1634
|
+
const set = rpc => {
|
|
1635
|
+
set$3(rpc);
|
|
1636
|
+
state.connected = true;
|
|
1637
|
+
};
|
|
1638
|
+
|
|
1639
|
+
const handleMessagePort = async port => {
|
|
1640
|
+
const rpc = await create$4({
|
|
1641
|
+
commandMap: {},
|
|
1642
|
+
messagePort: port
|
|
1643
|
+
});
|
|
1644
|
+
set(rpc);
|
|
1645
|
+
};
|
|
1646
|
+
|
|
1647
|
+
const setBadgeCount = (state, id, count) => {
|
|
1648
|
+
const {
|
|
1649
|
+
badgeCounts
|
|
1650
|
+
} = state;
|
|
1651
|
+
return {
|
|
1652
|
+
...state,
|
|
1653
|
+
badgeCounts: {
|
|
1654
|
+
...badgeCounts,
|
|
1655
|
+
[id]: count
|
|
1656
|
+
}
|
|
1657
|
+
};
|
|
1658
|
+
};
|
|
1659
|
+
|
|
1660
|
+
const DebugConsole = 'Debug Console';
|
|
1661
|
+
const Output = 'Output';
|
|
1662
|
+
const Ports = 'Ports';
|
|
1663
|
+
const Problems = 'Problems';
|
|
1664
|
+
const Terminals = 'Terminals';
|
|
1665
|
+
|
|
1666
|
+
const handleProblemsSummaryChange = (state, summary) => {
|
|
1667
|
+
const {
|
|
1668
|
+
badgeCounts
|
|
1669
|
+
} = state;
|
|
1670
|
+
const count = summary.hasEditor ? summary.problemCount : 0;
|
|
1671
|
+
if (badgeCounts[Problems] === count) {
|
|
1672
|
+
return state;
|
|
1673
|
+
}
|
|
1674
|
+
return setBadgeCount(state, Problems, count);
|
|
1675
|
+
};
|
|
1676
|
+
|
|
1506
1677
|
const handleClickClose = async state => {
|
|
1507
|
-
await invoke('Layout.hidePanel');
|
|
1678
|
+
await invoke$1('Layout.hidePanel');
|
|
1508
1679
|
return state;
|
|
1509
1680
|
};
|
|
1510
1681
|
|
|
1511
1682
|
const handleClickMaximize = async state => {
|
|
1512
|
-
await invoke('Layout.maximizePanel');
|
|
1683
|
+
await invoke$1('Layout.maximizePanel');
|
|
1513
1684
|
return state;
|
|
1514
1685
|
};
|
|
1515
1686
|
const handleClickUnmaximize = async state => {
|
|
1516
|
-
await invoke('Layout.unmaximizePanel');
|
|
1687
|
+
await invoke$1('Layout.unmaximizePanel');
|
|
1517
1688
|
return state;
|
|
1518
1689
|
};
|
|
1519
1690
|
|
|
@@ -1544,16 +1715,10 @@ const handleFilterInput = async (state, value) => {
|
|
|
1544
1715
|
currentViewletId
|
|
1545
1716
|
} = state;
|
|
1546
1717
|
const fullCommand = `${currentViewletId}.handleFilterInput`;
|
|
1547
|
-
await invoke(fullCommand, value);
|
|
1718
|
+
await invoke$1(fullCommand, value);
|
|
1548
1719
|
return state;
|
|
1549
1720
|
};
|
|
1550
1721
|
|
|
1551
|
-
const DebugConsole = 'Debug Console';
|
|
1552
|
-
const Output = 'Output';
|
|
1553
|
-
const Ports = 'Ports';
|
|
1554
|
-
const Problems = 'Problems';
|
|
1555
|
-
const Terminals = 'Terminals';
|
|
1556
|
-
|
|
1557
1722
|
const getPanelViews = () => {
|
|
1558
1723
|
const views = [Problems, Output, DebugConsole, Terminals, Ports];
|
|
1559
1724
|
return views;
|
|
@@ -1567,7 +1732,7 @@ const getSavedViewletId = savedState => {
|
|
|
1567
1732
|
};
|
|
1568
1733
|
|
|
1569
1734
|
const createViewlet = async (viewletModuleId, editorUid, tabId, actionsUid, bounds, uri, focus) => {
|
|
1570
|
-
await invoke('Layout.createPanelViewlet', viewletModuleId, editorUid, tabId, actionsUid, bounds, uri, focus);
|
|
1735
|
+
await invoke$1('Layout.createPanelViewlet', viewletModuleId, editorUid, tabId, actionsUid, bounds, uri, focus);
|
|
1571
1736
|
};
|
|
1572
1737
|
|
|
1573
1738
|
const getContentDimensions = dimensions => {
|
|
@@ -1596,7 +1761,7 @@ const saveViewletState = async (childUid, viewletId) => {
|
|
|
1596
1761
|
return;
|
|
1597
1762
|
}
|
|
1598
1763
|
try {
|
|
1599
|
-
await invoke(command, childUid, viewletId);
|
|
1764
|
+
await invoke$1(command, childUid, viewletId);
|
|
1600
1765
|
} catch (error) {
|
|
1601
1766
|
if (!isCommandNotFoundError(error)) {
|
|
1602
1767
|
throw error;
|
|
@@ -1649,19 +1814,6 @@ const selectRaw = async (state, rawIndex) => {
|
|
|
1649
1814
|
return selectIndex(state, Number(rawIndex));
|
|
1650
1815
|
};
|
|
1651
1816
|
|
|
1652
|
-
const setBadgeCount = (state, id, count) => {
|
|
1653
|
-
const {
|
|
1654
|
-
badgeCounts
|
|
1655
|
-
} = state;
|
|
1656
|
-
return {
|
|
1657
|
-
...state,
|
|
1658
|
-
badgeCounts: {
|
|
1659
|
-
...badgeCounts,
|
|
1660
|
-
[id]: count
|
|
1661
|
-
}
|
|
1662
|
-
};
|
|
1663
|
-
};
|
|
1664
|
-
|
|
1665
1817
|
const toggleView = async (state, name, uri = '') => {
|
|
1666
1818
|
const {
|
|
1667
1819
|
currentViewletId,
|
|
@@ -2190,9 +2342,14 @@ const render2 = (uid, diffResult) => {
|
|
|
2190
2342
|
newState,
|
|
2191
2343
|
oldState
|
|
2192
2344
|
} = get(uid);
|
|
2193
|
-
set(uid, newState, newState);
|
|
2345
|
+
set$1(uid, newState, newState);
|
|
2194
2346
|
const commands = applyRender(oldState, newState, diffResult);
|
|
2195
|
-
return commands;
|
|
2347
|
+
if (!isConnected()) return commands;
|
|
2348
|
+
return renderDirect(uid, commands);
|
|
2349
|
+
};
|
|
2350
|
+
const renderDirect = async (uid, commands) => {
|
|
2351
|
+
const transactionId = await invoke('Viewlet.queueCommands', uid, commands);
|
|
2352
|
+
return [['Viewlet.commitPending', uid, transactionId]];
|
|
2196
2353
|
};
|
|
2197
2354
|
|
|
2198
2355
|
const renderEventListeners = () => {
|
|
@@ -2230,7 +2387,7 @@ const resize = async (state, dimensions) => {
|
|
|
2230
2387
|
};
|
|
2231
2388
|
}
|
|
2232
2389
|
// @ts-ignore
|
|
2233
|
-
await invoke('Viewlet.resize', childUid, dimensions);
|
|
2390
|
+
await invoke$1('Viewlet.resize', childUid, dimensions);
|
|
2234
2391
|
return {
|
|
2235
2392
|
...newState
|
|
2236
2393
|
};
|
|
@@ -2270,7 +2427,9 @@ const commandMap = {
|
|
|
2270
2427
|
'Panel.handleClickMaximize': wrapCommand(handleClickMaximize),
|
|
2271
2428
|
'Panel.handleClickUnmaximize': wrapCommand(handleClickUnmaximize),
|
|
2272
2429
|
'Panel.handleFilterInput': wrapCommand(handleFilterInput),
|
|
2430
|
+
'Panel.handleMessagePort': handleMessagePort,
|
|
2273
2431
|
'Panel.handlePanelLayoutChanged': wrapCommand(handlePanelLayoutChanged),
|
|
2432
|
+
'Panel.handleProblemsSummaryChange': wrapCommand(handleProblemsSummaryChange),
|
|
2274
2433
|
'Panel.loadContent': wrapCommand(loadContent),
|
|
2275
2434
|
'Panel.openViewlet': wrapCommand(openViewlet),
|
|
2276
2435
|
'Panel.render2': render2,
|
|
@@ -2290,7 +2449,7 @@ const listen = async () => {
|
|
|
2290
2449
|
const rpc = await create$3({
|
|
2291
2450
|
commandMap: commandMap
|
|
2292
2451
|
});
|
|
2293
|
-
set$
|
|
2452
|
+
set$2(rpc);
|
|
2294
2453
|
};
|
|
2295
2454
|
|
|
2296
2455
|
const main = async () => {
|