@lvce-editor/panel-worker 2.8.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 +172 -25
- 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,6 +1621,29 @@ 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
|
+
|
|
1506
1647
|
const setBadgeCount = (state, id, count) => {
|
|
1507
1648
|
const {
|
|
1508
1649
|
badgeCounts
|
|
@@ -1534,16 +1675,16 @@ const handleProblemsSummaryChange = (state, summary) => {
|
|
|
1534
1675
|
};
|
|
1535
1676
|
|
|
1536
1677
|
const handleClickClose = async state => {
|
|
1537
|
-
await invoke('Layout.hidePanel');
|
|
1678
|
+
await invoke$1('Layout.hidePanel');
|
|
1538
1679
|
return state;
|
|
1539
1680
|
};
|
|
1540
1681
|
|
|
1541
1682
|
const handleClickMaximize = async state => {
|
|
1542
|
-
await invoke('Layout.maximizePanel');
|
|
1683
|
+
await invoke$1('Layout.maximizePanel');
|
|
1543
1684
|
return state;
|
|
1544
1685
|
};
|
|
1545
1686
|
const handleClickUnmaximize = async state => {
|
|
1546
|
-
await invoke('Layout.unmaximizePanel');
|
|
1687
|
+
await invoke$1('Layout.unmaximizePanel');
|
|
1547
1688
|
return state;
|
|
1548
1689
|
};
|
|
1549
1690
|
|
|
@@ -1574,7 +1715,7 @@ const handleFilterInput = async (state, value) => {
|
|
|
1574
1715
|
currentViewletId
|
|
1575
1716
|
} = state;
|
|
1576
1717
|
const fullCommand = `${currentViewletId}.handleFilterInput`;
|
|
1577
|
-
await invoke(fullCommand, value);
|
|
1718
|
+
await invoke$1(fullCommand, value);
|
|
1578
1719
|
return state;
|
|
1579
1720
|
};
|
|
1580
1721
|
|
|
@@ -1591,7 +1732,7 @@ const getSavedViewletId = savedState => {
|
|
|
1591
1732
|
};
|
|
1592
1733
|
|
|
1593
1734
|
const createViewlet = async (viewletModuleId, editorUid, tabId, actionsUid, bounds, uri, focus) => {
|
|
1594
|
-
await invoke('Layout.createPanelViewlet', viewletModuleId, editorUid, tabId, actionsUid, bounds, uri, focus);
|
|
1735
|
+
await invoke$1('Layout.createPanelViewlet', viewletModuleId, editorUid, tabId, actionsUid, bounds, uri, focus);
|
|
1595
1736
|
};
|
|
1596
1737
|
|
|
1597
1738
|
const getContentDimensions = dimensions => {
|
|
@@ -1620,7 +1761,7 @@ const saveViewletState = async (childUid, viewletId) => {
|
|
|
1620
1761
|
return;
|
|
1621
1762
|
}
|
|
1622
1763
|
try {
|
|
1623
|
-
await invoke(command, childUid, viewletId);
|
|
1764
|
+
await invoke$1(command, childUid, viewletId);
|
|
1624
1765
|
} catch (error) {
|
|
1625
1766
|
if (!isCommandNotFoundError(error)) {
|
|
1626
1767
|
throw error;
|
|
@@ -2201,9 +2342,14 @@ const render2 = (uid, diffResult) => {
|
|
|
2201
2342
|
newState,
|
|
2202
2343
|
oldState
|
|
2203
2344
|
} = get(uid);
|
|
2204
|
-
set(uid, newState, newState);
|
|
2345
|
+
set$1(uid, newState, newState);
|
|
2205
2346
|
const commands = applyRender(oldState, newState, diffResult);
|
|
2206
|
-
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]];
|
|
2207
2353
|
};
|
|
2208
2354
|
|
|
2209
2355
|
const renderEventListeners = () => {
|
|
@@ -2241,7 +2387,7 @@ const resize = async (state, dimensions) => {
|
|
|
2241
2387
|
};
|
|
2242
2388
|
}
|
|
2243
2389
|
// @ts-ignore
|
|
2244
|
-
await invoke('Viewlet.resize', childUid, dimensions);
|
|
2390
|
+
await invoke$1('Viewlet.resize', childUid, dimensions);
|
|
2245
2391
|
return {
|
|
2246
2392
|
...newState
|
|
2247
2393
|
};
|
|
@@ -2281,6 +2427,7 @@ const commandMap = {
|
|
|
2281
2427
|
'Panel.handleClickMaximize': wrapCommand(handleClickMaximize),
|
|
2282
2428
|
'Panel.handleClickUnmaximize': wrapCommand(handleClickUnmaximize),
|
|
2283
2429
|
'Panel.handleFilterInput': wrapCommand(handleFilterInput),
|
|
2430
|
+
'Panel.handleMessagePort': handleMessagePort,
|
|
2284
2431
|
'Panel.handlePanelLayoutChanged': wrapCommand(handlePanelLayoutChanged),
|
|
2285
2432
|
'Panel.handleProblemsSummaryChange': wrapCommand(handleProblemsSummaryChange),
|
|
2286
2433
|
'Panel.loadContent': wrapCommand(loadContent),
|
|
@@ -2302,7 +2449,7 @@ const listen = async () => {
|
|
|
2302
2449
|
const rpc = await create$3({
|
|
2303
2450
|
commandMap: commandMap
|
|
2304
2451
|
});
|
|
2305
|
-
set$
|
|
2452
|
+
set$2(rpc);
|
|
2306
2453
|
};
|
|
2307
2454
|
|
|
2308
2455
|
const main = async () => {
|