推进 INI 面板 launcher link view-model helper
This commit is contained in:
@@ -10,8 +10,9 @@ control view:
|
||||
```js
|
||||
import {
|
||||
INI_PANEL_ENTRIES,
|
||||
createIniPanelLauncherLinkViewModel,
|
||||
getIniPanelEntryByHref,
|
||||
getIniPanelEntryManifest,
|
||||
getVisibleIniPanelEntries,
|
||||
createMachineSessionControlPageController,
|
||||
renderMachineSessionControlView,
|
||||
} from "../runtime/ui/ini-panel/ui-shell.js";
|
||||
@@ -28,15 +29,19 @@ controller, and the control-view renderer. It does not implement CNC behavior.
|
||||
| Edit and run | `runtime/ui/ini-panel/index.html` | Editable INI panel and existing run workflow surface. |
|
||||
| Read-only control view | `runtime/ui/ini-panel/control-page.html` | Read-only control view backed by the panel API. |
|
||||
|
||||
## Entry Manifest
|
||||
## Visible Entries
|
||||
|
||||
The visible launch entries come from `getIniPanelEntryManifest()`:
|
||||
The visible launch entries come from `getVisibleIniPanelEntries()`:
|
||||
|
||||
| Entry id | Href | Title |
|
||||
| --- | --- | --- |
|
||||
| `edit-run` | `./index.html` | Open edit and run panel |
|
||||
| `control-view` | `./control-page.html` | Open read-only control view |
|
||||
|
||||
Launcher pages can render links from `createIniPanelLauncherLinkViewModel()`
|
||||
without reading manifest field names directly. Each item has `entryId`, `href`,
|
||||
and `label`.
|
||||
|
||||
## Boundary
|
||||
|
||||
The entry shell only links pages and renders already-observed panel state. It
|
||||
|
||||
@@ -73,16 +73,16 @@
|
||||
</section>
|
||||
</main>
|
||||
<script type="module">
|
||||
import { getIniPanelEntryManifest } from "./ui-shell.js";
|
||||
import { createIniPanelLauncherLinkViewModel } from "./ui-shell.js";
|
||||
|
||||
const manifest = getIniPanelEntryManifest();
|
||||
for (const entry of manifest) {
|
||||
const link = document.querySelector(`a[data-entry-id="${entry.id}"]`);
|
||||
const links = createIniPanelLauncherLinkViewModel();
|
||||
for (const linkModel of links) {
|
||||
const link = document.querySelector(`a[data-entry-id="${linkModel.entryId}"]`);
|
||||
if (!link) {
|
||||
throw new Error(`Missing launcher entry ${entry.id}`);
|
||||
throw new Error(`Missing launcher entry ${linkModel.entryId}`);
|
||||
}
|
||||
link.textContent = entry.title;
|
||||
link.href = entry.href;
|
||||
link.textContent = linkModel.label;
|
||||
link.href = linkModel.href;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
import {
|
||||
INI_PANEL_ENTRIES,
|
||||
getIniPanelEntryByHref,
|
||||
getIniPanelEntryManifest,
|
||||
} from "./entry-manifest.js";
|
||||
export {
|
||||
INI_PANEL_ENTRIES,
|
||||
getIniPanelEntryByHref,
|
||||
@@ -9,3 +14,15 @@ export {
|
||||
export {
|
||||
renderMachineSessionControlView,
|
||||
} from "./control-view-renderer.js";
|
||||
|
||||
export function getVisibleIniPanelEntries() {
|
||||
return getIniPanelEntryManifest();
|
||||
}
|
||||
|
||||
export function createIniPanelLauncherLinkViewModel(entries = getVisibleIniPanelEntries()) {
|
||||
return entries.map(({ id, href, title }) => ({
|
||||
entryId: id,
|
||||
href,
|
||||
label: title,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
<pre id="status">running</pre>
|
||||
<script type="module">
|
||||
import {
|
||||
createIniPanelLauncherLinkViewModel,
|
||||
getIniPanelEntryByHref,
|
||||
getIniPanelEntryManifest,
|
||||
getVisibleIniPanelEntries,
|
||||
} from "../../runtime/ui/ini-panel/ui-shell.js";
|
||||
|
||||
function assertEqual(actual, expected, label) {
|
||||
@@ -30,8 +31,13 @@
|
||||
}
|
||||
|
||||
try {
|
||||
const manifest = getIniPanelEntryManifest();
|
||||
assertEqual(manifest.length, 2, "launch manifest length");
|
||||
const visibleEntries = getVisibleIniPanelEntries();
|
||||
assertEqual(visibleEntries.length, 2, "launch visible entry length");
|
||||
const launcherLinks = createIniPanelLauncherLinkViewModel();
|
||||
assertEqual(launcherLinks.length, 2, "launcher link model length");
|
||||
assertEqual(launcherLinks[0].entryId, "edit-run", "launcher link entry id");
|
||||
assertEqual(launcherLinks[0].label, "Open edit and run panel", "launcher link label");
|
||||
assertEqual(launcherLinks[0].href, "./index.html", "launcher link href");
|
||||
assertEqual(getIniPanelEntryByHref("./index.html").id, "edit-run", "launch manifest edit entry");
|
||||
assertEqual(
|
||||
getIniPanelEntryByHref("./control-page.html").title,
|
||||
|
||||
@@ -5,7 +5,8 @@ import { dirname, resolve } from "node:path";
|
||||
|
||||
import {
|
||||
INI_PANEL_ENTRIES,
|
||||
getIniPanelEntryManifest,
|
||||
createIniPanelLauncherLinkViewModel,
|
||||
getVisibleIniPanelEntries,
|
||||
} from "../../../runtime/ui/ini-panel/ui-shell.js";
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
@@ -15,8 +16,9 @@ const shellText = readFileSync(resolve(root, "runtime/ui/ini-panel/ui-shell.js")
|
||||
|
||||
const requiredShellExports = [
|
||||
"INI_PANEL_ENTRIES",
|
||||
"createIniPanelLauncherLinkViewModel",
|
||||
"getIniPanelEntryByHref",
|
||||
"getIniPanelEntryManifest",
|
||||
"getVisibleIniPanelEntries",
|
||||
"createMachineSessionControlPageController",
|
||||
"renderMachineSessionControlView",
|
||||
];
|
||||
@@ -36,7 +38,15 @@ for (const [label, path] of requiredPages) {
|
||||
assert.match(docText, new RegExp(`\\| ${label} \\| \`${path.replaceAll("/", "\\/")}\``));
|
||||
}
|
||||
|
||||
assert.deepEqual(getIniPanelEntryManifest(), INI_PANEL_ENTRIES);
|
||||
assert.deepEqual(getVisibleIniPanelEntries(), INI_PANEL_ENTRIES);
|
||||
assert.deepEqual(
|
||||
createIniPanelLauncherLinkViewModel(),
|
||||
INI_PANEL_ENTRIES.map(({ id, href, title }) => ({
|
||||
entryId: id,
|
||||
href,
|
||||
label: title,
|
||||
})),
|
||||
);
|
||||
|
||||
for (const entry of INI_PANEL_ENTRIES) {
|
||||
const escapedHref = entry.href.replace(".", "\\.");
|
||||
|
||||
@@ -2,13 +2,16 @@ import assert from "node:assert/strict";
|
||||
|
||||
import {
|
||||
INI_PANEL_ENTRIES,
|
||||
createIniPanelLauncherLinkViewModel,
|
||||
createMachineSessionControlPageController,
|
||||
getIniPanelEntryByHref,
|
||||
getIniPanelEntryManifest,
|
||||
getVisibleIniPanelEntries,
|
||||
renderMachineSessionControlView,
|
||||
} from "../../../runtime/ui/ini-panel/ui-shell.js";
|
||||
|
||||
assert.deepEqual(getIniPanelEntryManifest(), INI_PANEL_ENTRIES);
|
||||
assert.deepEqual(getVisibleIniPanelEntries(), INI_PANEL_ENTRIES);
|
||||
assert.equal(getIniPanelEntryByHref("./index.html")?.id, "edit-run");
|
||||
assert.equal(typeof createMachineSessionControlPageController, "function");
|
||||
assert.equal(typeof renderMachineSessionControlView, "function");
|
||||
@@ -16,6 +19,24 @@ assert.equal(typeof renderMachineSessionControlView, "function");
|
||||
const shellManifest = getIniPanelEntryManifest();
|
||||
shellManifest[0].title = "changed";
|
||||
assert.equal(INI_PANEL_ENTRIES[0].title, "Open edit and run panel");
|
||||
const visibleEntries = getVisibleIniPanelEntries();
|
||||
visibleEntries[0].title = "changed";
|
||||
assert.equal(INI_PANEL_ENTRIES[0].title, "Open edit and run panel");
|
||||
assert.deepEqual(createIniPanelLauncherLinkViewModel(), [
|
||||
{
|
||||
entryId: "edit-run",
|
||||
href: "./index.html",
|
||||
label: "Open edit and run panel",
|
||||
},
|
||||
{
|
||||
entryId: "control-view",
|
||||
href: "./control-page.html",
|
||||
label: "Open read-only control view",
|
||||
},
|
||||
]);
|
||||
const launcherLinks = createIniPanelLauncherLinkViewModel();
|
||||
launcherLinks[0].label = "changed";
|
||||
assert.equal(INI_PANEL_ENTRIES[0].title, "Open edit and run panel");
|
||||
|
||||
const panelFrame = {
|
||||
contentWindow: {
|
||||
|
||||
Reference in New Issue
Block a user