推进 INI 面板 launch API manifest

This commit is contained in:
2026-06-15 06:25:47 +08:00
parent 6ba8e43850
commit 7d906f1809
8 changed files with 150 additions and 1 deletions

View File

@@ -11,6 +11,7 @@ control view:
import {
INI_PANEL_ENTRIES,
createControlPageBrowserApiMethods,
createIniPanelLaunchApiManifest,
createIniPanelLauncherLinkViewModel,
createIniPanelShellControlPageContract,
createIniPanelShellViewModel,
@@ -81,6 +82,10 @@ control page after save/load session workflows.
The launch page exposes `linuxCncIniPanelLaunchApi.getControlPageApiMethods()`
from the same shell view-model so entry pages can consume the available
read-only control-page API list without loading the control-page iframe first.
Use `createIniPanelLaunchApiManifest()` or
`linuxCncIniPanelLaunchApi.getLaunchApiManifest()` when an outer shell needs a
single read-only description of launch methods, visible entries, target pages,
and the control-page browser API methods.
The control-page refresh workflow lives in
`runtime/ui/ini-panel/control-page-refresh-workflow.js`. Use

View File

@@ -90,6 +90,7 @@
}
window.linuxCncIniPanelLaunchApi = {
getLaunchApiManifest: () => shellViewModel.launchApiManifest,
getLauncherLinks: () => shellViewModel.launcherLinks,
getControlPageApiMethods: () => shellViewModel.controlPage.browserApiMethods,
};

View File

@@ -61,6 +61,27 @@ export function createIniPanelLauncherLinkViewModel(entries = getVisibleIniPanel
}));
}
export function createIniPanelLaunchApiManifest(entries = getVisibleIniPanelEntries()) {
return {
apiName: "ini-panel-launch",
methods: [
"getLaunchApiManifest",
"getLauncherLinks",
"getControlPageApiMethods",
],
visibleEntries: entries.map(({ id, href, title }) => ({
id,
href,
title,
})),
targetPages: entries.map(({ id, href }) => ({
entryId: id,
href,
})),
controlPageApiMethods: createControlPageBrowserApiMethods(),
};
}
export function createIniPanelShellControlPageContract() {
const readonlyStatusApiManifest = createMachineSessionReadonlyStatusApiManifest();
return {
@@ -99,6 +120,7 @@ export function createIniPanelShellViewModel(entries = getVisibleIniPanelEntries
title,
})),
launcherLinks: createIniPanelLauncherLinkViewModel(entries),
launchApiManifest: createIniPanelLaunchApiManifest(entries),
controlPage: {
browserApiMethods: createControlPageBrowserApiMethods(),
contract: createIniPanelShellControlPageContract(),

View File

@@ -9,6 +9,7 @@
<script type="module">
import {
createControlPageBrowserApiMethods,
createIniPanelLaunchApiManifest,
createIniPanelLauncherLinkViewModel,
createIniPanelShellViewModel,
getIniPanelEntryByHref,
@@ -51,12 +52,43 @@
createControlPageBrowserApiMethods().join(","),
"launch shell control-page browser API methods",
);
assertEqual(
createIniPanelShellViewModel().launchApiManifest.apiName,
"ini-panel-launch",
"launch shell API manifest name",
);
assertEqual(
createIniPanelShellViewModel().launchApiManifest.methods.join(","),
createIniPanelLaunchApiManifest().methods.join(","),
"launch shell API manifest methods",
);
const launchDoc = await loadLaunchFrame();
const launchApi = launchDoc.defaultView.linuxCncIniPanelLaunchApi;
if (!launchApi?.getLauncherLinks || !launchApi?.getControlPageApiMethods) {
if (!launchApi?.getLaunchApiManifest || !launchApi?.getLauncherLinks || !launchApi?.getControlPageApiMethods) {
throw new Error("launch API namespace did not expose shell helpers");
}
const launchApiManifest = launchApi.getLaunchApiManifest();
assertEqual(
launchApiManifest.apiName,
"ini-panel-launch",
"launch API manifest name",
);
assertEqual(
launchApiManifest.methods.join(","),
"getLaunchApiManifest,getLauncherLinks,getControlPageApiMethods",
"launch API manifest methods",
);
assertEqual(
launchApiManifest.visibleEntries.length,
2,
"launch API manifest visible entry count",
);
assertEqual(
launchApiManifest.targetPages[1].href,
"./control-page.html",
"launch API manifest control target",
);
assertEqual(
launchDoc.querySelector('a[href="./index.html"]').textContent,
"Open edit and run panel",

View File

@@ -8,6 +8,7 @@ import {
controlPageStatusText,
createControlPageSessionLoadState,
createControlPageBrowserApiMethods,
createIniPanelLaunchApiManifest,
createIniPanelLauncherLinkViewModel,
createIniPanelShellControlPageContract,
createIniPanelShellViewModel,
@@ -39,6 +40,7 @@ const requiredShellExports = [
"controlPageStatusText",
"createControlPageBrowserApiMethods",
"createControlPageSessionLoadState",
"createIniPanelLaunchApiManifest",
"createIniPanelLauncherLinkViewModel",
"createIniPanelShellControlPageContract",
"createIniPanelShellViewModel",
@@ -96,6 +98,7 @@ assert.deepEqual(
);
assert.deepEqual(createIniPanelShellViewModel().pages, getVisibleIniPanelEntries());
assert.deepEqual(createIniPanelShellViewModel().launcherLinks, createIniPanelLauncherLinkViewModel());
assert.deepEqual(createIniPanelShellViewModel().launchApiManifest, createIniPanelLaunchApiManifest());
assert.deepEqual(
createIniPanelShellViewModel().controlPage.contract,
createIniPanelShellControlPageContract(),
@@ -128,8 +131,10 @@ assert.equal(createIniPanelShellViewModel().controlPage.readStatus, readMachineS
assert.equal(createIniPanelShellViewModel().controlPage.refresh, refreshMachineSessionControlPage);
assert.equal(typeof createIniPanelShellViewModel().controlPage.renderView, "function");
assert.match(shellText, /\bexport function createControlPageBrowserApiMethods\b/);
assert.match(shellText, /\bexport function createIniPanelLaunchApiManifest\b/);
assert.match(controlPageText, /\bgetControlPageApiMethods\b/);
assert.match(launchText, /\blinuxCncIniPanelLaunchApi\b/);
assert.match(launchText, /\bgetLaunchApiManifest\b/);
assert.match(launchText, /\bgetControlPageApiMethods\b/);
assert.match(controlPageText, /\bgetControlPageContract\b/);
assert.match(controlPageText, /\breadControlPageStatus\b/);
@@ -137,6 +142,8 @@ assert.match(controlPageText, /\bcreateIniPanelShellControlPageContract\b/);
assert.match(docText, /\blinuxCncIniPanelControlPageApi\.getControlPageApiMethods\b/);
assert.match(docText, /\blinuxCncIniPanelControlPageApi\.getControlPageContract\b/);
assert.match(docText, /\blinuxCncIniPanelControlPageApi\.readControlPageStatus\b/);
assert.match(docText, /\bcreateIniPanelLaunchApiManifest\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getLaunchApiManifest\b/);
assert.match(docText, /\blinuxCncIniPanelLaunchApi\.getControlPageApiMethods\b/);
for (const entry of INI_PANEL_ENTRIES) {

View File

@@ -5,6 +5,7 @@ import { fileURLToPath } from "node:url";
import {
createControlPageBrowserApiMethods,
createIniPanelLaunchApiManifest,
createIniPanelShellControlPageContract,
createIniPanelShellViewModel,
createMachineSessionControlPageController,
@@ -55,6 +56,7 @@ assert.deepEqual(contract, {
});
const shellViewModel = createIniPanelShellViewModel();
assert.deepEqual(shellViewModel.launchApiManifest, createIniPanelLaunchApiManifest());
assert.deepEqual(Object.keys(shellViewModel.controlPage), [
"browserApiMethods",
"contract",

View File

@@ -4,6 +4,7 @@ import {
INI_PANEL_ENTRIES,
controlPageStatusText,
createControlPageBrowserApiMethods,
createIniPanelLaunchApiManifest,
createIniPanelLauncherLinkViewModel,
createIniPanelShellControlPageContract,
createIniPanelShellViewModel,
@@ -46,6 +47,7 @@ assert.equal(typeof createMachineSessionControlPageController, "function");
assert.equal(typeof createMachineSessionReadonlyStatus, "function");
assert.equal(typeof createMachineSessionReadonlyStatusApiManifest, "function");
assert.equal(typeof createControlPageBrowserApiMethods, "function");
assert.equal(typeof createIniPanelLaunchApiManifest, "function");
assert.equal(typeof createIniPanelShellControlPageContract, "function");
assert.equal(typeof loadMachineSessionForControlPageWorkflow, "function");
assert.equal(typeof readMachineSessionReadonlyStatus, "function");
@@ -87,6 +89,7 @@ assert.deepEqual(shellViewModel.pages, [
},
]);
assert.deepEqual(shellViewModel.launcherLinks, createIniPanelLauncherLinkViewModel());
assert.deepEqual(shellViewModel.launchApiManifest, createIniPanelLaunchApiManifest());
assert.deepEqual(shellViewModel.controlPage.browserApiMethods, createControlPageBrowserApiMethods());
assert.equal(shellViewModel.controlPage.createController, createMachineSessionControlPageController);
assert.deepEqual(shellViewModel.controlPage.contract, createIniPanelShellControlPageContract());