feat(skin): render voice members under channels

This commit is contained in:
illusia committed 2026-10-10 15:53:49 +08:00
1 parent 54c77bcb27
commit dd0d779e49
13 files changed
+257 -32

No files matched your search

+7 -4
View File
@@ -2,6 +2,7 @@ import { computed, defineComponent, Fragment, h, onUnmounted, reactive, ref, Tel
import {
SKIN_PLUGIN_COMPONENT_LIMIT,
SKIN_PLUGIN_PERMISSIONS,
SKIN_PLUGIN_RENDER_NODE_LIMIT,
SKIN_PLUGIN_REPEAT_LIMIT,
parseSkinPluginDocument,
type SkinPluginActionDefinition,
@@ -187,7 +188,9 @@ export default defineComponent({
return `skin.${component.page}.${component.id}.${interactive ? "control-" : ""}${part}`;
}
function renderNode(component: SkinPluginComponent, node: SkinPluginNode, context: SafeContext, state: Record<string, Scalar>, skipRepeat = false, nodePath = "node-root"): VNodeChild {
function renderNode(component: SkinPluginComponent, node: SkinPluginNode, context: SafeContext, state: Record<string, Scalar>, budget: { remaining: number }, skipRepeat = false, nodePath = "node-root"): VNodeChild {
if (budget.remaining <= 0) return null;
budget.remaining -= 1;
if (node.widget) {
if (node.when) {
const value = resolvePath(node.when.path, context, state);
@@ -215,7 +218,7 @@ export default defineComponent({
const values = resolvePath(node.repeat.path, context, state);
if (!Array.isArray(values)) return null;
const repeatLimit = props.document.schemaVersion >= 3 ? SKIN_PLUGIN_REPEAT_LIMIT : 100;
return h(Fragment, null, values.slice(0, repeatLimit).map((value) => renderNode(component, node, { ...context, [node.repeat!.as]: value }, state, true, nodePath)));
return h(Fragment, null, values.slice(0, repeatLimit).map((value) => renderNode(component, node, { ...context, [node.repeat!.as]: value }, state, budget, true, nodePath)));
}
if (node.when) {
const value = resolvePath(node.when.path, context, state);
@@ -264,7 +267,7 @@ export default defineComponent({
};
}
if (node.tag === "form" && !node.events?.submit) attrs.onSubmit = (event: Event) => event.preventDefault();
const children = (node.children ?? []).map((child, index) => renderNode(component, child, context, state, false, `${nodePath}-${index}`));
const children = (node.children ?? []).map((child, index) => renderNode(component, child, context, state, budget, false, `${nodePath}-${index}`));
// Custom element names are inert host-rendered placeholders. Never instantiate a page-registered
// custom element from generated output, since its connectedCallback would run with page privileges.
const tag = node.tag.includes("-") ? "div" : node.tag;
@@ -308,7 +311,7 @@ export default defineComponent({
"data-ws-part": `skin.${component.page}.${component.id}`,
...(component.mode === "surface" ? { "data-ws-plugin-surface": component.page } : {}),
"aria-label": component.accessibleName,
}, [renderNode(component, component.root, props.data, localState(component))]));
}, [renderNode(component, component.root, props.data, localState(component), { remaining: SKIN_PLUGIN_RENDER_NODE_LIMIT })]));
const hasPermissions = matchingComponents.value.some((component) => component.permissions.length > 0);
const showConsent = pendingApproval.value.length > 0 || manageOpen.value;
const accessToggle = hasPermissions ? h(Teleport, { to: "body" }, [h("button", {
@@ -3,6 +3,7 @@ import test from "node:test";
import { createRenderer, createSSRApp, nextTick } from "vue";
import { renderToString } from "@vue/server-renderer";
import type { SkinPluginDocument } from "../../../src/shared/skin-plugin.js";
import { approveSkinPluginComponents } from "./skin-plugin-approval.js";
import {
parseSkinExtensionUiOutput,
SKIN_EXTENSION_UI_OUTPUT_LIMIT_BYTES,
@@ -292,6 +293,70 @@ test("SkinPluginOutlet renders generated custom elements as inert host nodes", a
assert.match(html, /Server/);
});
test("SkinPluginOutlet renders bounded members nested under their channel", async () => {
const document = {
schemaVersion: 3,
components: [{
id: "channel-members",
name: "Channel members",
page: "voice",
accessibleName: "Voice channels and members",
permissions: ["session.channels.read", "session.members.read"],
actions: {},
root: {
tag: "nav",
repeat: { path: "session.channels", as: "channel" },
children: [{
tag: "section",
children: [
{ tag: "h2", children: [{ text: "{{channel.name}}" }] },
{
tag: "ul",
children: [{
tag: "li",
repeat: { path: "channel.members", as: "member" },
children: [{ text: "{{member.name}}" }],
}],
},
],
}],
},
}],
} as unknown as SkinPluginDocument;
const storage = new Map<string, string>();
const previousStorage = Object.getOwnPropertyDescriptor(globalThis, "localStorage");
Object.defineProperty(globalThis, "localStorage", {
configurable: true,
value: {
getItem: (key: string) => storage.get(key) ?? null,
setItem: (key: string, value: string) => { storage.set(key, value); },
},
});
try {
approveSkinPluginComponents("community.test", "1.0.0", document.components);
const html = await renderToString(createSSRApp(SkinPluginOutlet, {
skinId: "community.test",
skinVersion: "1.0.0",
document,
page: "voice",
data: { session: { channels: Array.from({ length: 100 }, (_, channelIndex) => ({
id: `room-${channelIndex}`,
name: channelIndex === 0 ? "Room One" : `Room ${channelIndex}`,
members: Array.from({ length: 100 }, (_, memberIndex) => ({ id: `user-${channelIndex}-${memberIndex}`, name: `Member-${channelIndex}-${memberIndex}` })),
})) } },
assets: {},
actions: {},
}));
assert.match(html, /Room One/);
const renderedMembers = html.match(/Member-\d+-\d+/g) ?? [];
assert.ok(renderedMembers.length > 0);
assert.ok(renderedMembers.length < 10_000, "nested repeats must stop at the component render-node limit");
} finally {
if (previousStorage) Object.defineProperty(globalThis, "localStorage", previousStorage);
else Reflect.deleteProperty(globalThis, "localStorage");
}
});
test("skin-authored DOM nodes expose independent layout parts and retain touch bounds for controls", async () => {
const document: SkinPluginDocument = {
schemaVersion: 3,
+3
View File
@@ -409,7 +409,10 @@ test("the distributable KAAK v3 package validates end to end", async () => {
assert.equal(skin.schemaVersion, 3);
assert.deepEqual(skin.pluginData?.components.map((component) => component.id), ["kaak-channel-sidebar", "kaak-members-sidebar"]);
assert.equal(skin.pluginData?.components[0].root.children?.[1].children?.[0].children?.[0].events?.dblclick, "join-channel");
assert.ok(skin.pluginData?.components[0].permissions.includes("session.members.read"));
assert.equal(skin.pluginData?.components[0].root.children?.[1].children?.[0].children?.[1].children?.[0].repeat?.path, "channel.members");
assert.ok(skin.css.includes('data-ws-plugin-part="kaak-channel-sidebar.channel-row"'));
assert.ok(skin.css.includes('data-ws-plugin-part="kaak-channel-sidebar.channel-members"'));
assert.ok(skin.css.includes('data-ws-plugin-part="kaak-members-sidebar.member-row-content"'));
});
+21 -16
View File
@@ -1468,6 +1468,14 @@ const skinPluginQuickList = computed(() => skinPluginQuickServers.project(quickS
const skinPluginFavorites = computed(() => skinPluginQuickList.value
.filter((server) => server.favorite)
.map(({ favorite: _favorite, ...server }) => server));
const skinPluginMembers = computed(() => memberChannels.value.flatMap((item) => item.members.map((member) => ({
id: String(member.id),
name: member.nickname,
channelId: item.id,
status: member.away ? "away" : member.inputMuted ? "muted" : speakingIds.has(member.id) ? "speaking" : "online",
speaking: speakingIds.has(member.id),
self: member.id === voiceState.tsClientId,
}))));
const skinPluginContext = computed(() => ({
session: {
@@ -1478,22 +1486,19 @@ const skinPluginContext = computed(() => ({
channelName: currentChannelName.value,
userName: nickname.value,
},
channels: channelTree.value.map((item) => ({
id: item.id,
name: item.name,
parentId: item.parentID,
depth: item.depth,
memberCount: item.members.length,
current: item.id === currentChannel.value?.id,
})),
members: memberChannels.value.flatMap((item) => item.members.map((member) => ({
id: String(member.id),
name: member.nickname,
channelId: item.id,
status: member.away ? "away" : member.inputMuted ? "muted" : speakingIds.has(member.id) ? "speaking" : "online",
speaking: speakingIds.has(member.id),
self: member.id === voiceState.tsClientId,
}))),
channels: channelTree.value.map((item) => {
const members = skinPluginMembers.value.filter((member) => member.channelId === item.id);
return {
id: item.id,
name: item.name,
parentId: item.parentID,
depth: item.depth,
memberCount: item.members.length,
current: item.id === currentChannel.value?.id,
members,
};
}),
members: skinPluginMembers.value,
},
favorites: { items: skinPluginFavorites.value },
servers: { quickList: skinPluginQuickList.value },