推进 INI 面板 control-page API manifest predicate

This commit is contained in:
2026-06-15 07:36:48 +08:00
parent 01d168e247
commit b3f131fa5f
8 changed files with 274 additions and 0 deletions

View File

@@ -5,8 +5,11 @@ import {
createMachineSessionControlPageController,
} from "./control-page-controller.js";
import {
createControlPageBrowserApiManifest,
createControlPageBrowserApiMethods,
createControlPageBrowserApiSchema,
createIniPanelShellControlPageContract,
isSupportedIniPanelControlPageApiManifest,
} from "./ui-shell.js";
const panelFrameNode = document.getElementById("panel-frame");
@@ -23,6 +26,9 @@ const controller = createMachineSessionControlPageController({
controller.mount();
window.linuxCncIniPanelControlPageApi = {
isSupportedControlPageApiManifest: isSupportedIniPanelControlPageApiManifest,
getControlPageApiSchema: createControlPageBrowserApiSchema,
getControlPageApiManifest: createControlPageBrowserApiManifest,
getControlPageApiMethods: createControlPageBrowserApiMethods,
getControlView: controller.getControlView,
getControlPageContract: createIniPanelShellControlPageContract,

View File

@@ -87,6 +87,33 @@ export function isSupportedIniPanelLaunchApiManifest(manifest, schema = createIn
return schema.fields.every((fieldName) => Object.hasOwn(manifest, fieldName));
}
export function createControlPageBrowserApiSchema() {
return {
apiName: "ini-panel-control-page",
manifestVersion: 1,
fields: [
"apiName",
"manifestVersion",
"methods",
"contract",
"readonlyStatusApiManifest",
],
};
}
export function isSupportedIniPanelControlPageApiManifest(
manifest,
schema = createControlPageBrowserApiSchema(),
) {
if (!manifest || typeof manifest !== "object") {
return false;
}
if (manifest.apiName !== schema.apiName || manifest.manifestVersion !== schema.manifestVersion) {
return false;
}
return schema.fields.every((fieldName) => Object.hasOwn(manifest, fieldName));
}
export function createIniPanelLaunchApiManifest(entries = getVisibleIniPanelEntries()) {
const schema = createIniPanelLaunchApiSchema();
return {
@@ -148,6 +175,9 @@ export function createIniPanelShellControlPageContract() {
export function createControlPageBrowserApiMethods() {
return [
"isSupportedControlPageApiManifest",
"getControlPageApiSchema",
"getControlPageApiManifest",
"getControlPageApiMethods",
"getControlPageContract",
"getControlView",
@@ -159,6 +189,18 @@ export function createControlPageBrowserApiMethods() {
];
}
export function createControlPageBrowserApiManifest() {
const schema = createControlPageBrowserApiSchema();
const contract = createIniPanelShellControlPageContract();
return {
apiName: schema.apiName,
manifestVersion: schema.manifestVersion,
methods: createControlPageBrowserApiMethods(),
contract,
readonlyStatusApiManifest: contract.readonlyStatusApiManifest,
};
}
export function createIniPanelShellViewModel(entries = getVisibleIniPanelEntries()) {
return {
pages: entries.map(({ id, href, title }) => ({
@@ -170,9 +212,12 @@ export function createIniPanelShellViewModel(entries = getVisibleIniPanelEntries
launchApiSchema: createIniPanelLaunchApiSchema(),
launchApiManifest: createIniPanelLaunchApiManifest(entries),
controlPage: {
browserApiSchema: createControlPageBrowserApiSchema(),
browserApiManifest: createControlPageBrowserApiManifest(),
browserApiMethods: createControlPageBrowserApiMethods(),
contract: createIniPanelShellControlPageContract(),
createController: createMachineSessionControlPageController,
isSupportedBrowserApiManifest: isSupportedIniPanelControlPageApiManifest,
loadSessionState: loadMachineSessionForControlPageWorkflow,
readonlyStatusApiManifest: createMachineSessionReadonlyStatusApiManifest(),
readStatus: readMachineSessionReadonlyStatus,