优化窗格显示

This commit is contained in:
yhy
2026-09-01 08:38:36 +08:00
parent af2ee38443
commit 3b07e2a3c1
11 changed files with 137 additions and 30 deletions
+45
View File
@@ -226,6 +226,51 @@ export function buildItemPaneSectionButtons(kind: ItemPaneKind) {
];
}
export function isItemPaneSectionBody(body: HTMLElement): boolean {
return Boolean(body.closest("collapsible-section"));
}
export type SectionSummaryUpdater = (summary: string) => void;
export function clearSectionSummary(
body: HTMLElement,
updater?: SectionSummaryUpdater,
): void {
updater?.("");
const section = body.closest("collapsible-section");
if (section) section.setAttribute("summary", "");
}
const SECTION_HEAD_MESSAGE: Record<ItemPaneKind, FluentMessageId> = {
chat: "item-section-chat-head",
lecture: "item-section-lecture-head",
};
/** Ensure native section head shows plugin name (not just the icon). */
export function applyItemPaneSectionHeadLabel(
body: HTMLElement,
kind: ItemPaneKind,
): void {
const section = body.closest("collapsible-section") as HTMLElement | null;
if (!section) return;
const messageId = SECTION_HEAD_MESSAGE[kind];
const l10nId = getLocaleID(messageId);
section.dataset.l10nId = l10nId;
const label = getString(messageId, "label");
if (label && label !== l10nId) {
section.setAttribute("label", label);
return;
}
try {
body.ownerDocument?.l10n?.setAttributes?.(section, l10nId);
} catch {
// Fluent may not be ready yet; label stays empty until next render hook.
}
}
function resolveCollapsibleSection(
body: HTMLElement,
event?: Event,