@lvce-editor/panel-worker 2.13.0 → 2.13.2
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 +62 -3
- package/package.json +1 -1
package/dist/panelWorkerMain.js
CHANGED
|
@@ -1621,6 +1621,10 @@ const diff2 = uid => {
|
|
|
1621
1621
|
return result;
|
|
1622
1622
|
};
|
|
1623
1623
|
|
|
1624
|
+
const getComponentState = uid => {
|
|
1625
|
+
return get(uid).newState;
|
|
1626
|
+
};
|
|
1627
|
+
|
|
1624
1628
|
const getCurrentViewletId = state => {
|
|
1625
1629
|
const {
|
|
1626
1630
|
currentViewletId
|
|
@@ -1787,6 +1791,21 @@ const getUid = () => {
|
|
|
1787
1791
|
return Math.random();
|
|
1788
1792
|
};
|
|
1789
1793
|
|
|
1794
|
+
const pending = new Map();
|
|
1795
|
+
const add = (uid, childUid) => {
|
|
1796
|
+
let children = pending.get(uid);
|
|
1797
|
+
if (!children) {
|
|
1798
|
+
children = new Set();
|
|
1799
|
+
pending.set(uid, children);
|
|
1800
|
+
}
|
|
1801
|
+
children.add(childUid);
|
|
1802
|
+
};
|
|
1803
|
+
const take = uid => {
|
|
1804
|
+
const children = pending.get(uid);
|
|
1805
|
+
pending.delete(uid);
|
|
1806
|
+
return children ? [...children] : [];
|
|
1807
|
+
};
|
|
1808
|
+
|
|
1790
1809
|
const command = 'SaveState.saveViewletStateWithStorageId';
|
|
1791
1810
|
const isCommandNotFoundError = error => {
|
|
1792
1811
|
if (!(error instanceof Error)) {
|
|
@@ -1812,6 +1831,7 @@ const openViewlet = async (state, id, focus = false, uri = '') => {
|
|
|
1812
1831
|
const {
|
|
1813
1832
|
childUid: currentChildUid,
|
|
1814
1833
|
currentViewletId,
|
|
1834
|
+
uid,
|
|
1815
1835
|
views
|
|
1816
1836
|
} = state;
|
|
1817
1837
|
if (!views.includes(id)) {
|
|
@@ -1825,7 +1845,7 @@ const openViewlet = async (state, id, focus = false, uri = '') => {
|
|
|
1825
1845
|
const index = views.indexOf(id);
|
|
1826
1846
|
await createViewlet(id, childUid, tabId, actionsUid, childDimensions, uri, focus);
|
|
1827
1847
|
if (currentChildUid > 0) {
|
|
1828
|
-
|
|
1848
|
+
add(uid, currentChildUid);
|
|
1829
1849
|
}
|
|
1830
1850
|
return {
|
|
1831
1851
|
...state,
|
|
@@ -2381,13 +2401,33 @@ const applyRender = (oldState, newState, diffResult) => {
|
|
|
2381
2401
|
return commands;
|
|
2382
2402
|
};
|
|
2383
2403
|
|
|
2384
|
-
const
|
|
2404
|
+
const hideViewlet = async uid => {
|
|
2405
|
+
try {
|
|
2406
|
+
const commands = await invoke$1('Viewlet.hide', uid);
|
|
2407
|
+
if (Array.isArray(commands)) {
|
|
2408
|
+
return commands;
|
|
2409
|
+
}
|
|
2410
|
+
} catch (error) {
|
|
2411
|
+
// Older renderers do not support deferred container disposal yet.
|
|
2412
|
+
if (!(error instanceof Error) || !error.message.includes('Viewlet.hide') || !error.message.toLowerCase().includes('not found')) {
|
|
2413
|
+
throw error;
|
|
2414
|
+
}
|
|
2415
|
+
}
|
|
2416
|
+
const commands = await invoke$1('Viewlet.dispose', uid, true);
|
|
2417
|
+
return Array.isArray(commands) ? commands : [];
|
|
2418
|
+
};
|
|
2419
|
+
|
|
2420
|
+
const render2 = async (uid, diffResult) => {
|
|
2385
2421
|
const {
|
|
2386
2422
|
newState,
|
|
2387
2423
|
oldState
|
|
2388
2424
|
} = get(uid);
|
|
2389
2425
|
set$1(uid, newState, newState);
|
|
2390
|
-
const commands = applyRender(oldState, newState, diffResult);
|
|
2426
|
+
const commands = [...applyRender(oldState, newState, diffResult)];
|
|
2427
|
+
// Keep referenced DOM nodes until the parent patches have replaced them.
|
|
2428
|
+
for (const childUid of take(uid)) {
|
|
2429
|
+
commands.push(...(await hideViewlet(childUid)));
|
|
2430
|
+
}
|
|
2391
2431
|
if (!isConnected()) return commands;
|
|
2392
2432
|
return renderDirect(uid, commands);
|
|
2393
2433
|
};
|
|
@@ -2462,11 +2502,29 @@ const selectName = async (state, name) => {
|
|
|
2462
2502
|
return selectIndex(state, index);
|
|
2463
2503
|
};
|
|
2464
2504
|
|
|
2505
|
+
const applyComponentState = (currentState, state) => {
|
|
2506
|
+
if (!state || typeof state !== 'object' || Array.isArray(state)) {
|
|
2507
|
+
throw new TypeError('Panel state must be an object');
|
|
2508
|
+
}
|
|
2509
|
+
const {
|
|
2510
|
+
uid
|
|
2511
|
+
} = state;
|
|
2512
|
+
const {
|
|
2513
|
+
uid: currentUid
|
|
2514
|
+
} = currentState;
|
|
2515
|
+
if (uid !== currentUid) {
|
|
2516
|
+
throw new Error(`Panel state uid must remain ${currentUid}`);
|
|
2517
|
+
}
|
|
2518
|
+
return state;
|
|
2519
|
+
};
|
|
2520
|
+
const setComponentState = wrapCommand(applyComponentState);
|
|
2521
|
+
|
|
2465
2522
|
const handleDirectMessagePort = (port, setAsRendererProcess = true) => handleMessagePort(port, commandMap, setAsRendererProcess);
|
|
2466
2523
|
const commandMap = {
|
|
2467
2524
|
'Panel.create': create,
|
|
2468
2525
|
'Panel.diff2': diff2,
|
|
2469
2526
|
'Panel.getCommandIds': getCommandIds,
|
|
2527
|
+
'Panel.getComponentState': getComponentState,
|
|
2470
2528
|
'Panel.getCurrentViewletId': wrapGetter(getCurrentViewletId),
|
|
2471
2529
|
'Panel.handleBlur': wrapCommand(handleBlur),
|
|
2472
2530
|
'Panel.handleClickClose': wrapCommand(handleClickClose),
|
|
@@ -2486,6 +2544,7 @@ const commandMap = {
|
|
|
2486
2544
|
'Panel.selectIndexRaw': wrapCommand(selectRaw),
|
|
2487
2545
|
'Panel.selectName': wrapCommand(selectName),
|
|
2488
2546
|
'Panel.setBadgeCount': wrapCommand(setBadgeCount),
|
|
2547
|
+
'Panel.setComponentState': setComponentState,
|
|
2489
2548
|
'Panel.terminate': terminate,
|
|
2490
2549
|
'Panel.toggleView': wrapCommand(toggleView)
|
|
2491
2550
|
};
|