fix(skin): register runtime plugin layout parts

This commit is contained in:
illusia committed 2026-10-10 15:53:50 +08:00
1 parent 35cb6ad6df
commit 11a07eae0f
9 files changed
+80 -15

No files matched your search

+6 -2
View File
@@ -186,13 +186,17 @@ export default defineComponent({
return url;
}
function layoutComponentPath(component: SkinPluginComponent): string {
return props.componentNamespace ? `runtime_plugin_${props.componentNamespace}__${component.id}` : component.id;
}
function layoutPart(component: SkinPluginComponent, node: SkinPluginNode, nodePath: string): string {
const interactive = ["a", "button", "input", "select", "summary", "textarea"].includes(node.tag ?? "")
|| node.attributes?.role === "button"
|| ["click", "dblclick", "contextmenu", "keydown", "keyup", "pointerdown", "pointerup", "drop"]
.some((eventName) => Boolean(node.events?.[eventName as keyof typeof node.events]));
const part = node.part ? `part-${node.part}` : nodePath;
const componentPath = props.componentNamespace ? `${props.componentNamespace}.${component.id}` : component.id;
const componentPath = layoutComponentPath(component);
return `skin.${component.page}.${componentPath}.${interactive ? "control-" : ""}${part}`;
}
@@ -317,7 +321,7 @@ export default defineComponent({
"data-ws-plugin-component": props.componentNamespace ? `${props.componentNamespace}.${component.id}` : component.id,
"data-ws-plugin-name": component.name,
"data-ws-plugin-part": props.componentNamespace ? `${props.componentNamespace}.${component.id}` : component.id,
"data-ws-part": `skin.${component.page}.${props.componentNamespace ? `${props.componentNamespace}.` : ""}${component.id}`,
"data-ws-part": `skin.${component.page}.${layoutComponentPath(component)}`,
...(props.componentNamespace ? { "data-ws-runtime-plugin": props.componentNamespace } : {}),
...(component.mode === "surface" ? { "data-ws-plugin-surface": component.page } : {}),
"aria-label": component.accessibleName,
@@ -296,6 +296,33 @@ test("SkinPluginOutlet renders validated dynamic output and preserves package UI
assert.match(collisionHtml, /Package UI/);
});
test("runtime plugin component layout parts keep plugin and component identities in the layout registry format", async () => {
const html = await renderToString(createSSRApp(SkinPluginOutlet, {
skinId: "community.test",
skinVersion: "1.0.0",
document: {
schemaVersion: 3,
components: [{
id: "base-ui",
name: "Base UI",
page: "voice",
accessibleName: "Base UI",
permissions: [],
actions: {},
root: { tag: "main", children: [{ text: "Base UI" }] },
}],
},
extensionOutput: generatedOutput("voice-ui", { tag: "button", part: "join", children: [{ text: "Join" }] }),
componentNamespace: "voice-surface",
page: "voice",
data: {},
assets: {},
actions: {},
}));
assert.match(html, /data-ws-part="skin\.voice\.runtime_plugin_voice-surface__voice-ui"/);
assert.match(html, /data-ws-part="skin\.voice\.runtime_plugin_voice-surface__voice-ui\.control-part-join"/);
});
test("SkinPluginOutlet renders generated custom elements as inert host nodes", async () => {
const document: SkinPluginDocument = {
schemaVersion: 3,
@@ -60,6 +60,26 @@ test("legacy local layouts migrate matching entries and keep incompatible entrie
});
});
test("migration recovery preserves full runtime plugin layout identifiers", () => {
withLocalStorage(() => {
const componentId = `skin.voice.runtime_plugin_${"p".repeat(64)}__${"c".repeat(64)}.control-node-root-0`;
const legacy = JSON.stringify({
schemaVersion: 1,
skins: {
"community.illusia-voice": {
schemaVersion: 1,
pages: { voice: { desktop: { [componentId]: { width: 9000 } } } },
},
},
});
localStorage.setItem(LEGACY_SKIN_LAYOUT_STORAGE_KEY, legacy);
loadSkinLayoutOverrides("community.illusia-voice");
const recovery = getSkinLayoutMigrationRecovery("community.illusia-voice");
assert.equal(recovery?.items[0]?.componentId, componentId);
});
});
test("version 2 layout overrides can be saved, loaded, and cleared per skin", () => {
withLocalStorage((storage) => {
saveSkinLayoutOverrides("community.illusia-voice", {
+2 -2
View File
@@ -84,7 +84,7 @@ function parseCollection(source: string | null): SkinLayoutCollection {
items: recovery.items.filter(isRecord).map((item) => ({
page: typeof item.page === "string" ? item.page.slice(0, 80) : "",
profile: typeof item.profile === "string" ? item.profile.slice(0, 20) : "",
componentId: typeof item.componentId === "string" ? item.componentId.slice(0, 120) : "",
componentId: typeof item.componentId === "string" ? item.componentId.slice(0, 320) : "",
placement: item.placement,
})),
omittedCount: Math.max(0, recovery.omittedCount),
@@ -98,7 +98,7 @@ function recoverLegacyLayout(layout: unknown): { layout: SkinLayoutDocument; ite
const items: SkinLayoutMigrationRecovery["items"] = [];
const pages: SkinLayoutDocument["pages"] = {};
const remember = (page: string, profile: string, componentId: string, placement: unknown) => {
if (items.length < 1024) items.push({ page: page.slice(0, 80), profile: profile.slice(0, 20), componentId: componentId.slice(0, 120), placement });
if (items.length < 1024) items.push({ page: page.slice(0, 80), profile: profile.slice(0, 20), componentId: componentId.slice(0, 320), placement });
};
if (!isRecord(layout) || layout.schemaVersion !== 1 || !isRecord(layout.pages)) {
remember("", "", "__document__", layout);