mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 20:12:52 +08:00
feat(kaak): match channel sidebar and audio dock reference
This commit is contained in:
1 parent
b13bdf1eb2
commit
96d2ebae01
17 files changed
+847
-135
No files matched your search
Binary file not shown.
@@ -1,19 +1,21 @@
|
||||
<template>
|
||||
<ul
|
||||
v-if="tree.length"
|
||||
v-if="visibleTree.length"
|
||||
class="ws-voice-channel-tree"
|
||||
data-ws-part="voice.channel-tree.list"
|
||||
:data-layout="layout"
|
||||
role="tree"
|
||||
aria-label="语音频道 / Voice channels"
|
||||
>
|
||||
<VoiceChannelTreeItem
|
||||
v-for="node in tree"
|
||||
v-for="node in visibleTree"
|
||||
:key="node.channel.id"
|
||||
:node="node"
|
||||
:depth="0"
|
||||
:layout="layout"
|
||||
:current-channel-id="currentChannelId"
|
||||
:selected-channel-id="selectedChannelId"
|
||||
:expanded-ids="expandedIds"
|
||||
:expanded-ids="effectiveExpandedIds"
|
||||
:avatar-style="avatarStyle"
|
||||
:avatar-initial="avatarInitial"
|
||||
:is-speaking="isSpeaking"
|
||||
@@ -28,19 +30,21 @@
|
||||
class="ws-voice-channel-tree-empty"
|
||||
data-ws-part="voice.channel-tree.empty"
|
||||
role="status"
|
||||
>无可用语音频道 / No voice channels</div>
|
||||
>{{ query.trim() ? "没有匹配的频道 / No matching channels" : "无可用语音频道 / No voice channels" }}</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch, type CSSProperties } from "vue";
|
||||
import type { ChannelMember } from "../../composables/useVoiceWebSocket.js";
|
||||
import type { TreeChannel } from "../../composables/useWebClientChannels.js";
|
||||
import { buildVoiceChannelTree } from "../../services/voice-channel-tree.js";
|
||||
import { buildVoiceChannelTree, filterVoiceChannelTree } from "../../services/voice-channel-tree.js";
|
||||
import VoiceChannelTreeItem from "./VoiceChannelTreeItem.vue";
|
||||
|
||||
const props = defineProps<{
|
||||
channels: readonly TreeChannel[];
|
||||
currentChannelId?: string;
|
||||
query?: string;
|
||||
layout?: "default" | "server-sidebar";
|
||||
avatarStyle: (name: string, isSelf?: boolean, avatar?: string) => CSSProperties;
|
||||
avatarInitial: (name: string) => string;
|
||||
isSpeaking: (member: ChannelMember) => boolean;
|
||||
@@ -48,8 +52,22 @@ const props = defineProps<{
|
||||
}>();
|
||||
|
||||
const tree = computed(() => buildVoiceChannelTree(props.channels));
|
||||
const layout = computed(() => props.layout ?? "default");
|
||||
const query = computed(() => props.query ?? "");
|
||||
const visibleTree = computed(() => filterVoiceChannelTree(tree.value, query.value));
|
||||
const selectedChannelId = ref(props.currentChannelId ?? "");
|
||||
const expandedIds = ref(new Set<string>());
|
||||
const effectiveExpandedIds = computed(() => {
|
||||
const result = new Set(expandedIds.value);
|
||||
if (!query.value.trim()) return result;
|
||||
const pending = [...visibleTree.value];
|
||||
while (pending.length) {
|
||||
const node = pending.pop()!;
|
||||
if (node.children.length) result.add(node.channel.id);
|
||||
pending.push(...node.children);
|
||||
}
|
||||
return result;
|
||||
});
|
||||
|
||||
watch(() => props.currentChannelId, (channelId) => {
|
||||
if (channelId) selectedChannelId.value = channelId;
|
||||
@@ -62,7 +80,7 @@ watch(tree, (nodes) => {
|
||||
while (pending.length) {
|
||||
const node = pending.pop()!;
|
||||
availableIds.add(node.channel.id);
|
||||
if (node.children.length || node.channel.members.length) expanded.add(node.channel.id);
|
||||
if (node.children.length || (layout.value === "default" && node.channel.members.length)) expanded.add(node.channel.id);
|
||||
pending.push(...node.children);
|
||||
}
|
||||
for (const id of expanded) if (!availableIds.has(id)) expanded.delete(id);
|
||||
@@ -85,4 +103,5 @@ function joinChannel(channel: TreeChannel): void {
|
||||
const emit = defineEmits<{
|
||||
join: [channel: TreeChannel];
|
||||
}>();
|
||||
|
||||
</script>
|
||||
@@ -4,15 +4,15 @@
|
||||
data-ws-part="voice.channel-tree.node"
|
||||
role="treeitem"
|
||||
:aria-level="depth + 1"
|
||||
:aria-expanded="hasContents ? expanded : undefined"
|
||||
:aria-expanded="isExpandable ? expanded : undefined"
|
||||
:aria-selected="selected"
|
||||
:aria-current="current ? 'location' : undefined"
|
||||
:data-current="current ? 'true' : 'false'"
|
||||
:data-selected="selected ? 'true' : 'false'"
|
||||
>
|
||||
<div class="ws-voice-channel-line" data-ws-part="voice.channel-tree.line">
|
||||
<div class="ws-voice-channel-line" data-ws-part="voice.channel-tree.line" :style="{ '--channel-depth': depth }">
|
||||
<button
|
||||
v-if="hasContents"
|
||||
v-if="isExpandable"
|
||||
type="button"
|
||||
class="ws-voice-channel-expander"
|
||||
data-ws-part="voice.channel-tree.expander"
|
||||
@@ -20,7 +20,6 @@
|
||||
:aria-expanded="expanded"
|
||||
@click.stop="emit('toggle', node.channel.id)"
|
||||
><Icon :name="expanded ? 'chevron-down' : 'chevron-right'" :size="13" /></button>
|
||||
<span v-else class="ws-voice-channel-expander-placeholder" aria-hidden="true"></span>
|
||||
<button
|
||||
type="button"
|
||||
class="ws-voice-channel-row"
|
||||
@@ -39,8 +38,72 @@
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<template v-if="layout === 'server-sidebar'">
|
||||
<ul v-if="node.channel.members.length" class="ws-voice-channel-member-list" role="group" :style="{ '--channel-depth': depth }">
|
||||
<li
|
||||
v-for="member in node.channel.members"
|
||||
:key="member.id"
|
||||
class="ws-voice-channel-member"
|
||||
data-ws-part="voice.channel-tree.member"
|
||||
role="treeitem"
|
||||
:aria-level="depth + 2"
|
||||
:aria-label="`${member.nickname}${member.isSelf ? `, ${t('you')}` : ''}${member.inputMuted ? `, ${t('inputMuted')}` : ''}`"
|
||||
:data-self="member.isSelf ? 'true' : 'false'"
|
||||
>
|
||||
<span
|
||||
class="ws-voice-channel-member-avatar"
|
||||
data-ws-part="voice.channel-tree.avatar"
|
||||
:style="avatarStyle(member.nickname, member.isSelf, member.avatar)"
|
||||
aria-hidden="true"
|
||||
>{{ member.avatar ? '' : avatarInitial(member.nickname) }}</span>
|
||||
<span class="ws-voice-channel-member-name" data-ws-part="voice.channel-tree.member-name">{{ member.nickname }}</span>
|
||||
<span v-if="member.isSelf" class="ws-voice-channel-member-self">你</span>
|
||||
<Icon
|
||||
v-if="member.inputMuted"
|
||||
class="ws-voice-channel-member-muted"
|
||||
data-ws-part="voice.channel-tree.member-muted"
|
||||
name="mic-off"
|
||||
:size="13"
|
||||
:title="t('inputMuted')"
|
||||
/>
|
||||
<Icon
|
||||
v-else
|
||||
class="ws-voice-channel-member-mic"
|
||||
name="mic"
|
||||
:size="13"
|
||||
:title="t('microphoneActive')"
|
||||
/>
|
||||
</li>
|
||||
</ul>
|
||||
<div
|
||||
v-if="hasChildren"
|
||||
class="ws-voice-channel-branch"
|
||||
data-ws-part="voice.channel-tree.branch"
|
||||
:data-expanded="expanded ? 'true' : 'false'"
|
||||
>
|
||||
<ul class="ws-voice-channel-branch-content" role="group">
|
||||
<VoiceChannelTreeItem
|
||||
v-for="child in node.children"
|
||||
:key="child.channel.id"
|
||||
:node="child"
|
||||
:depth="depth + 1"
|
||||
:layout="layout"
|
||||
:current-channel-id="currentChannelId"
|
||||
:selected-channel-id="selectedChannelId"
|
||||
:expanded-ids="expandedIds"
|
||||
:avatar-style="avatarStyle"
|
||||
:avatar-initial="avatarInitial"
|
||||
:is-speaking="isSpeaking"
|
||||
:t="t"
|
||||
@toggle="emit('toggle', $event)"
|
||||
@select="emit('select', $event)"
|
||||
@join="emit('join', $event)"
|
||||
/>
|
||||
</ul>
|
||||
</div>
|
||||
</template>
|
||||
<div
|
||||
v-if="hasContents"
|
||||
v-else-if="hasContents"
|
||||
class="ws-voice-channel-branch"
|
||||
data-ws-part="voice.channel-tree.branch"
|
||||
:data-expanded="expanded ? 'true' : 'false'"
|
||||
@@ -88,6 +151,7 @@
|
||||
:key="child.channel.id"
|
||||
:node="child"
|
||||
:depth="depth + 1"
|
||||
:layout="layout"
|
||||
:current-channel-id="currentChannelId"
|
||||
:selected-channel-id="selectedChannelId"
|
||||
:expanded-ids="expandedIds"
|
||||
@@ -116,6 +180,7 @@ defineOptions({ name: "VoiceChannelTreeItem" });
|
||||
const props = defineProps<{
|
||||
node: VoiceChannelTreeNode<TreeChannel>;
|
||||
depth: number;
|
||||
layout: "default" | "server-sidebar";
|
||||
currentChannelId?: string;
|
||||
selectedChannelId: string;
|
||||
expandedIds: ReadonlySet<string>;
|
||||
@@ -132,7 +197,9 @@ const emit = defineEmits<{
|
||||
}>();
|
||||
|
||||
const expanded = computed(() => props.expandedIds.has(props.node.channel.id));
|
||||
const hasContents = computed(() => props.node.children.length > 0 || props.node.channel.members.length > 0);
|
||||
const hasChildren = computed(() => props.node.children.length > 0);
|
||||
const hasContents = computed(() => hasChildren.value || props.node.channel.members.length > 0);
|
||||
const isExpandable = computed(() => props.layout === "server-sidebar" ? hasChildren.value : hasContents.value);
|
||||
const current = computed(() => props.node.channel.id === props.currentChannelId);
|
||||
const selected = computed(() => props.node.channel.id === props.selectedChannelId);
|
||||
const memberCount = computed(() => String(props.node.channel.members.length).padStart(2, "0"));
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
<template>
|
||||
<header class="ws-voice-server-header">
|
||||
<div class="ws-voice-server-title-line">
|
||||
<strong class="ws-voice-server-name">{{ serverLabel || "TeamSpeak" }}</strong>
|
||||
<VoiceServerSwitcher :servers="servers" :on-switch-server="onSwitchServer" />
|
||||
</div>
|
||||
<div class="ws-voice-server-meta-line">
|
||||
<div class="ws-voice-server-tags">
|
||||
<span class="ws-voice-server-tag">TeamSpeak</span>
|
||||
<span class="ws-voice-server-tag" :class="`is-${connectionState}`">
|
||||
<i v-if="connectionState === 'connected'" aria-hidden="true"></i>
|
||||
{{ connectionLabel }}
|
||||
</span>
|
||||
</div>
|
||||
<button
|
||||
ref="searchButton"
|
||||
class="ws-voice-server-search-toggle"
|
||||
type="button"
|
||||
:aria-expanded="searchOpen"
|
||||
aria-label="搜索频道 / Search channels"
|
||||
title="搜索频道 / Search channels"
|
||||
@click="toggleSearch"
|
||||
><Icon name="search" :size="18" /></button>
|
||||
</div>
|
||||
<label v-if="searchOpen" class="ws-voice-server-search-box">
|
||||
<span class="sr-only">搜索频道名称 / Search channel names</span>
|
||||
<Icon name="search" :size="16" />
|
||||
<input
|
||||
ref="searchInput"
|
||||
v-model="query"
|
||||
type="search"
|
||||
autocomplete="off"
|
||||
spellcheck="false"
|
||||
placeholder="搜索频道 / Search channels"
|
||||
@keydown.esc.prevent="closeSearch"
|
||||
/>
|
||||
<button v-if="query" type="button" aria-label="清除搜索 / Clear search" @click="query = ''; searchInput?.focus()">
|
||||
<Icon name="close" :size="15" />
|
||||
</button>
|
||||
</label>
|
||||
<div class="ws-voice-server-divider" aria-hidden="true"></div>
|
||||
</header>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, ref, watch } from "vue";
|
||||
import type { SkinPluginQuickServer } from "../../services/skin-plugin-context.js";
|
||||
import Icon from "../Icon.vue";
|
||||
import VoiceServerSwitcher from "./VoiceServerSwitcher.vue";
|
||||
|
||||
const props = defineProps<{
|
||||
serverLabel: string;
|
||||
connectionState: "connected" | "connecting" | "disconnected";
|
||||
servers: readonly SkinPluginQuickServer[];
|
||||
onSwitchServer: (quickServerId: string) => void;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{ "update:query": [value: string] }>();
|
||||
const searchOpen = ref(false);
|
||||
const query = ref("");
|
||||
const searchButton = ref<HTMLButtonElement | null>(null);
|
||||
const searchInput = ref<HTMLInputElement | null>(null);
|
||||
const connectionLabel = computed(() => ({
|
||||
connected: "已连接",
|
||||
connecting: "连接中",
|
||||
disconnected: "未连接",
|
||||
})[props.connectionState]);
|
||||
|
||||
watch(query, (value) => emit("update:query", value));
|
||||
|
||||
async function toggleSearch(): Promise<void> {
|
||||
if (searchOpen.value) {
|
||||
closeSearch();
|
||||
return;
|
||||
}
|
||||
searchOpen.value = true;
|
||||
await nextTick();
|
||||
searchInput.value?.focus();
|
||||
}
|
||||
|
||||
function closeSearch(): void {
|
||||
searchOpen.value = false;
|
||||
query.value = "";
|
||||
void nextTick(() => searchButton.value?.focus());
|
||||
}
|
||||
</script>
|
||||
@@ -46,10 +46,10 @@ export const BUILTIN_SKIN_CATALOG: SkinCatalogEntry[] = [
|
||||
{
|
||||
id: BUILTIN_KAAK_SKIN_ID,
|
||||
name: "KAAK",
|
||||
version: "3.1.65",
|
||||
version: "3.1.66",
|
||||
author: "WebSpeak Project",
|
||||
license: "AGPL-3.0-only",
|
||||
description: "A KOOK-inspired voice-room workspace with a live server header, quick server switching, a nested channel tree with member avatars, attached channel chat, and WebSpeak voice controls.",
|
||||
description: "A KOOK-inspired voice-room workspace with a searchable server header, nested channel members, attached channel chat, and a compact WebSpeak audio dock.",
|
||||
minAppVersion: "0.2.7-preview",
|
||||
installedAt: 0,
|
||||
builtIn: true,
|
||||
|
||||
@@ -464,7 +464,7 @@ test("the distributable KAAK package provides full home and voice surfaces", asy
|
||||
const file = new File([archive], "kaak-voice.wskin", { type: "application/octet-stream" });
|
||||
const skin = await importSkinPack(file);
|
||||
assert.equal(skin.id, "community.kaak-voice");
|
||||
assert.equal(skin.version, "3.1.65");
|
||||
assert.equal(skin.version, "3.1.66");
|
||||
assert.equal(BUILTIN_SKIN_CATALOG.find((entry) => entry.id === skin.id)?.version, skin.version);
|
||||
assert.equal(skin.schemaVersion, 3);
|
||||
const home = skin.pluginData?.components.find((component) => component.page === "home");
|
||||
@@ -478,6 +478,7 @@ test("the distributable KAAK package provides full home and voice surfaces", asy
|
||||
assert.ok(voice?.permissions.includes("ui.surface.replace"));
|
||||
assert.ok(voice?.permissions.includes("servers.quickList.read"));
|
||||
assert.ok(voice?.permissions.includes("servers.quickList.switch"));
|
||||
assert.ok(voice?.permissions.includes("session.status.read"));
|
||||
assert.ok(voice?.permissions.includes("session.channels.read"));
|
||||
assert.ok(voice?.permissions.includes("session.members.read"));
|
||||
assert.ok(voice?.permissions.includes("session.memberAvatars.read"));
|
||||
@@ -497,11 +498,11 @@ test("the distributable KAAK package provides full home and voice surfaces", asy
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
assert.equal(findPart(voice?.root, "server-name")?.children?.[0]?.text, "{{session.status.serverLabel}}");
|
||||
assert.equal(findPart(voice?.root, "server-switcher")?.widget, "voice.server-switcher");
|
||||
assert.deepEqual(findPart(voice?.root, "server-connection-dot")?.when, { path: "session.status.connectionState", equals: "connected" });
|
||||
assert.equal(findPart(voice?.root, "server-subtitle")?.children?.[0]?.text, "已连接 · {{session.status.userName}}");
|
||||
assert.equal(findPart(voice?.root, "server-summary")?.widget, "voice.server-header");
|
||||
assert.equal(findPart(voice?.root, "record-placeholder")?.attributes?.disabled, true);
|
||||
assert.equal(findPart(voice?.root, "recording-label")?.children?.[0]?.text, "REC");
|
||||
assert.equal(findPart(voice?.root, "voice-channel-tree")?.widget, "voice.channel-tree");
|
||||
assert.deepEqual(findPart(voice?.root, "voice-channel-tree")?.options, { layout: "server-sidebar" });
|
||||
assert.equal(findPart(voice?.root, "channel-row"), undefined, "channels render in the trusted nested tree widget");
|
||||
assert.equal(voice?.actions["select-channel"], undefined);
|
||||
assert.equal(voice?.actions["join-channel"], undefined);
|
||||
@@ -555,6 +556,7 @@ test("the distributable KAAK package provides full home and voice surfaces", asy
|
||||
assert.equal(findPart(voice?.root, "audio-controls")?.widget, "voice.audio-controls");
|
||||
assert.deepEqual(findPart(voice?.root, "audio-controls")?.options, { layout: "room-panel" });
|
||||
assert.ok(skin.css.includes('[data-ws-plugin-part="kaak-workspace.server-summary"]'));
|
||||
assert.ok(skin.css.includes(".ws-voice-server-search-toggle"));
|
||||
assert.ok(skin.css.includes(".ws-voice-server-switcher-menu"));
|
||||
assert.ok(skin.css.includes('[data-ws-plugin-part="kaak-workspace"] .ws-voice-channel-row'));
|
||||
assert.match(skin.css, /ws-voice-channel-node\[data-current="true"\][\s\S]*?box-shadow: inset 2px 0 var\(--skin-kaak-accent\);/);
|
||||
@@ -562,12 +564,15 @@ test("the distributable KAAK package provides full home and voice surfaces", asy
|
||||
assert.match(skin.css, /ws-voice-channel-member-avatar[\s\S]*?border-radius: 50%;/);
|
||||
assert.match(skin.css, /--skin-kaak-font:[\s\S]*?PingFang SC/);
|
||||
assert.match(skin.css, /--skin-kaak-accent: #6cbf00;/);
|
||||
assert.match(skin.css, /voice-dock"\] \{[\s\S]*?width: min\(264px, 100%\);[\s\S]*?border-radius: 17px;/);
|
||||
assert.match(skin.css, /voice-dock-actions"\] \{[\s\S]*?grid-template-columns: minmax\(0, 1fr\) 37px 37px 37px;[\s\S]*?grid-template-rows: 28px 23px;/);
|
||||
assert.match(skin.css, /\[data-ws-plugin-part="kaak-workspace\.voice-dock"\] \{[\s\S]*?width: min\(282px, calc\(100% - 22px\)\);[\s\S]*?margin-bottom: 11px;[\s\S]*?border-radius: 17px;/);
|
||||
assert.match(skin.css, /\[data-ws-plugin-part="kaak-workspace\.voice-dock-actions"\] \{[\s\S]*?grid-template-columns: minmax\(0, 1fr\) 36px 36px 36px;[\s\S]*?grid-template-rows: 29px 26px;[\s\S]*?row-gap: 21px;/);
|
||||
assert.match(skin.css, /ws-voice-channel-tree\[data-layout="server-sidebar"\] \.ws-voice-channel-line[\s\S]*?min-height: 38px;/);
|
||||
assert.match(skin.css, /ws-voice-channel-tree\[data-layout="server-sidebar"\] \.ws-voice-channel-member[\s\S]*?min-height: 29px;/);
|
||||
assert.match(skin.css, /kaak-workspace\.record-placeholder"\][\s\S]*?grid-column: 3;[\s\S]*?grid-row: 1;[\s\S]*?background: #69c000;/);
|
||||
assert.match(skin.css, /desktop-audio-dock-room-panel \{\s*display: contents;\s*\}/);
|
||||
assert.match(skin.css, /desktop-audio-dock-copy \{ display: none; \}/);
|
||||
assert.match(skin.css, /kaak-workspace\.voice-dock-share"\] \{ grid-column: 1 \/ 4; grid-row: 1;/);
|
||||
assert.match(skin.css, /kaak-workspace\.voice-dock-share[\s\S]*?skin-runtime-screen-share-start \{[\s\S]*?height: 28px;[\s\S]*?background: #6cbf00;/);
|
||||
assert.match(skin.css, /\[data-ws-plugin-part="kaak-workspace\.voice-dock-share"\] \{ grid-column: 1 \/ 3; grid-row: 1;/);
|
||||
assert.match(skin.css, /\[data-ws-plugin-part="kaak-workspace\.voice-dock-share"\] \.skin-runtime-screen-share-start \{[\s\S]*?background: #69c000;/);
|
||||
assert.match(skin.css, /room-panel-audio-settings[\s\S]*?grid-column: 1;[\s\S]*?grid-row: 2;/);
|
||||
assert.match(skin.css, /noise-suppression-toggle \{ grid-column: 2; grid-row: 2; align-self: center; \}/);
|
||||
assert.match(skin.css, /voice\.audio-dock\.microphone[\s\S]*?grid-column: 3;[\s\S]*?grid-row: 2;/);
|
||||
@@ -625,8 +630,8 @@ test("the distributable KAAK package provides full home and voice surfaces", asy
|
||||
assert.match(skin.css, /data-voice-group-open="false"[\s\S]*?voice-channel-list[\s\S]*?grid-template-rows: 0fr;[\s\S]*?visibility: hidden;[\s\S]*?visibility 0s linear \.18s/);
|
||||
assert.match(skin.css, /voice-stage-heading[\s\S]*?flex: 0 0 46px;/);
|
||||
assert.doesNotMatch(skin.css, /aria-expanded="true"\]\s*[^\n]*voice-stage-heading[^\n]*display: none;/);
|
||||
assert.match(skin.css, /kaak-workspace"\]:has\(\[data-ws-plugin-part="kaak-workspace\.chat-panel-toggle"\]\[aria-expanded="false"\]\)[\s\S]*?grid-template-columns: 86px 290px minmax\(280px, 1fr\) 0;/);
|
||||
assert.match(skin.css, /grid-template-columns: 86px 290px/);
|
||||
assert.match(skin.css, /grid-template-columns: 86px 304px minmax\(280px, 1fr\) 0;/);
|
||||
assert.match(skin.css, /grid-template-columns: 86px 304px/);
|
||||
assert.match(skin.css, /minmax\(340px, min\(38vw, 520px\)\)/);
|
||||
assert.match(skin.css, /grid-template-rows: 40px/);
|
||||
assert.match(skin.css, /kaak-workspace\.server-rail"\]\s*\{[\s\S]*?--skin-kaak-rail-bg: #191a1d;[\s\S]*?--skin-kaak-rail-item-bg: #2b2d32;[\s\S]*?--skin-kaak-rail-accent: #75c900;[\s\S]*?gap: 18px;[\s\S]*?padding: 14px 0 96px;[\s\S]*?background: var\(--skin-kaak-rail-bg\);/);
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { buildVoiceChannelTree, filterVoiceChannelTree } from "./voice-channel-tree.js";
|
||||
|
||||
test("channel search keeps matching nested channels and only their ancestors", () => {
|
||||
const tree = buildVoiceChannelTree([
|
||||
{ id: "root", depth: 0, name: "大厅" },
|
||||
{ id: "lobby", depth: 1, name: "聊天大厅" },
|
||||
{ id: "games", depth: 1, name: "游戏区" },
|
||||
{ id: "afk", depth: 2, name: "AFK" },
|
||||
{ id: "music", depth: 2, name: "音乐" },
|
||||
{ id: "other", depth: 0, name: "其他" },
|
||||
]);
|
||||
|
||||
const results = filterVoiceChannelTree(tree, " afk ");
|
||||
assert.deepEqual(results.map(({ channel }) => channel.id), ["root"]);
|
||||
assert.deepEqual(results[0].children.map(({ channel }) => channel.id), ["games"]);
|
||||
assert.deepEqual(results[0].children[0].children.map(({ channel }) => channel.id), ["afk"]);
|
||||
assert.deepEqual(filterVoiceChannelTree(tree, "大厅").map(({ channel }) => channel.id), ["root"]);
|
||||
assert.deepEqual(filterVoiceChannelTree(tree, "missing"), []);
|
||||
assert.deepEqual(filterVoiceChannelTree(tree, " "), tree);
|
||||
});
|
||||
@@ -35,3 +35,18 @@ export function buildVoiceChannelTree<T extends VoiceChannelTreeSource>(
|
||||
|
||||
return roots;
|
||||
}
|
||||
|
||||
/** Filters visible channel names while retaining ancestors of matching nested channels. */
|
||||
export function filterVoiceChannelTree<T extends VoiceChannelTreeSource & { name: string }>(
|
||||
nodes: readonly VoiceChannelTreeNode<T>[],
|
||||
query: string,
|
||||
): VoiceChannelTreeNode<T>[] {
|
||||
const needle = query.trim().toLocaleLowerCase();
|
||||
if (!needle) return [...nodes];
|
||||
return nodes.flatMap((node) => {
|
||||
const children = filterVoiceChannelTree(node.children, needle);
|
||||
return node.channel.name.toLocaleLowerCase().includes(needle) || children.length
|
||||
? [{ ...node, children }]
|
||||
: [];
|
||||
});
|
||||
}
|
||||
@@ -981,6 +981,7 @@ import VoiceMemberCards from "../components/web-client/VoiceMemberCards.vue";
|
||||
import VoicePerformancePanel from "../components/web-client/VoicePerformancePanel.vue";
|
||||
import VoiceChannelTree from "../components/web-client/VoiceChannelTree.vue";
|
||||
import VoiceServerSwitcher from "../components/web-client/VoiceServerSwitcher.vue";
|
||||
import VoiceServerHeader from "../components/web-client/VoiceServerHeader.vue";
|
||||
import ScreenShareSettingsDialog from "../components/web-client/ScreenShareSettingsDialog.vue";
|
||||
import ScreenSharePlayer from "../components/web-client/ScreenSharePlayer.vue";
|
||||
import AudioDock from "../components/web-client/AudioDock.vue";
|
||||
@@ -1121,7 +1122,8 @@ const serverPassword = ref("");
|
||||
const rememberIdentity = ref(localStorage.getItem("webspeak:remember-identity") !== "0");
|
||||
const accelerationRelayId = ref("");
|
||||
const browserError = ref("");
|
||||
const memberQuery = ref("");
|
||||
const memberQuery = ref("");
|
||||
const channelTreeSearchQuery = ref("");
|
||||
const selectedChannelId = ref("");
|
||||
const settingsOpen = ref(false);
|
||||
const favoriteServerDialogOpen = ref(false);
|
||||
@@ -1779,9 +1781,18 @@ const skinPluginWidgets = {
|
||||
servers: skinPluginQuickList.value,
|
||||
onSwitchServer: switchQuickServerByOpaqueId,
|
||||
}),
|
||||
"voice.channel-tree": () => h(VoiceChannelTree, {
|
||||
"voice.server-header": () => h(VoiceServerHeader, {
|
||||
serverLabel: currentServerDisplayName.value,
|
||||
connectionState: voiceState.connected ? "connected" : voiceState.connecting || voiceState.reconnecting ? "connecting" : "disconnected",
|
||||
servers: skinPluginQuickList.value,
|
||||
onSwitchServer: switchQuickServerByOpaqueId,
|
||||
"onUpdate:query": (value: string) => { channelTreeSearchQuery.value = value; },
|
||||
}),
|
||||
"voice.channel-tree": (options?: SkinPluginWidgetOptions) => h(VoiceChannelTree, {
|
||||
channels: channelTree.value,
|
||||
currentChannelId: currentChannel.value?.id,
|
||||
query: channelTreeSearchQuery.value,
|
||||
layout: options?.layout === "server-sidebar" ? "server-sidebar" : "default",
|
||||
avatarStyle,
|
||||
avatarInitial,
|
||||
isSpeaking,
|
||||
@@ -1857,10 +1868,10 @@ const skinPluginWidgets = {
|
||||
}, [h(Icon, { name: "music", size: 18 })]),
|
||||
] : []),
|
||||
])
|
||||
: h(AudioDock, {
|
||||
: h(AudioDock, {
|
||||
model: audioDockState,
|
||||
controls: audioControls,
|
||||
layout: options?.layout,
|
||||
layout: options?.layout === "room-panel" ? "room-panel" : "default",
|
||||
t,
|
||||
rangeStyle,
|
||||
onSettings: () => { settingsOpen.value = true; },
|
||||
|
||||
Reference in new issue
Block a user