fix(plugins): key plugin center layout off container width

This commit is contained in:
Abeautifulsnow authored and GitHub committed 2026-09-29 17:26:45 +08:00
1 parent 497d7c9e1e
commit ebc9fcc098
4 files changed
+98 -16

No files matched your search

@@ -5033,16 +5033,21 @@ function dismissAwayUpdates() {
onMounted(async () => {
assistantViewMounted = true;
// Size handling has to be live before the first `await`: the bootstrap below
// Register the resize/drop wiring before the first `await`: the bootstrap below
// can take several frames (persisted runs plus the dynamic import of the code
// highlighter), and a panel drag or window resize during that window would
// otherwise be dropped, leaving the composer on a stale compact/expanded state.
// highlighter), and a panel drag, window resize, or file/table drop during that
// window would otherwise be dropped, leaving the composer on a stale
// compact/expanded state — and the listeners of a panel closed mid-load were
// added after onUnmounted had already run, leaking them.
window.addEventListener("resize", handleWindowResize);
document.addEventListener("dbx:tauri-file-drop", onTauriFileDrop as EventListener);
window.addEventListener(DBX_TABLE_REFERENCE_DROP_EVENT, onTableReferenceDropEvent);
if (typeof ResizeObserver !== "undefined" && assistantRootRef.value) {
promptPanelResizeObserver = new ResizeObserver(handleObservedPanelResize);
promptPanelResizeObserver.observe(assistantRootRef.value);
if (promptPanelRef.value) promptPanelResizeObserver.observe(promptPanelRef.value);
}
scheduleResponsiveControlMeasurement(true);
const savedHeight = localStorage.getItem(AI_TEXTAREA_HEIGHT_STORAGE_KEY);
if (savedHeight) {
const height = parseInt(savedHeight, 10);
@@ -5147,10 +5152,6 @@ onMounted(async () => {
shikiCodeHighlighter.value = await createAiShikiCodeHighlighter({
appearance: () => aiCodeAppearance.value,
}).catch(() => undefined);
document.addEventListener("dbx:tauri-file-drop", onTauriFileDrop as EventListener);
window.addEventListener(DBX_TABLE_REFERENCE_DROP_EVENT, onTableReferenceDropEvent);
scheduleResponsiveControlMeasurement(true);
});
function maxTextareaHeight() {
@@ -1124,15 +1124,19 @@ onBeforeUnmount(() => {
<span class="mx-1.5 text-border">·</span>{{ t("pluginPlatform.marketplaceGuideDescription") }}
</div>
</div>
<!-- 吸顶:矮窗滚动时搜索/排序控件始终可达 -->
<div class="sticky top-0 z-20 flex w-full flex-col gap-2 rounded-xl border bg-background/95 p-3 backdrop-blur-sm sm:flex-row sm:items-center">
<!-- 吸顶:矮窗滚动时搜索/排序控件始终可达。
行/列切换按「面板宽度」(@container) 而非视口断点:窗口 minWidth=900 时 sm: 恒为真,
而分屏/侧栏挤压下的商店面板可远窄于窗口,视口断点会让整行溢出、批量管理/刷新被推出可视区(#10582)。
54rem(容器 864px) 高于实测下限(容器 781–800px:控制簇 580px + 搜索框 180–199px + 内边距);
flex-wrap 则兜住比 54rem 更窄时的极端情况。 -->
<div data-plugin-marketplace-toolbar class="sticky top-0 z-20 flex w-full flex-col flex-wrap gap-2 rounded-xl border bg-background/95 p-3 backdrop-blur-sm @min-[54rem]:flex-row @min-[54rem]:items-center">
<div class="relative">
<Search class="pointer-events-none absolute left-2.5 top-2.5 size-3.5 text-muted-foreground" />
<Input data-plugin-marketplace-search v-model="marketplaceQuery" class="h-8 min-w-0 pl-8 text-xs sm:w-[min(100%,28rem)]" :placeholder="t('pluginPlatform.searchMarketplace')" />
<Input data-plugin-marketplace-search v-model="marketplaceQuery" class="h-8 min-w-0 pl-8 text-xs @min-[54rem]:w-[min(100%,28rem)]" :placeholder="t('pluginPlatform.searchMarketplace')" />
</div>
<div class="flex min-w-0 items-center gap-2 sm:ml-auto">
<div data-plugin-marketplace-controls class="flex min-w-0 flex-wrap items-center gap-2 @min-[54rem]:ml-auto">
<Select v-model="marketplaceSortMode">
<SelectTrigger class="h-8 min-w-0 flex-1 text-xs sm:w-40 sm:flex-none" :aria-label="t('pluginPlatform.sortBy')"><SelectValue /></SelectTrigger>
<SelectTrigger data-plugin-marketplace-sort class="h-8 min-w-0 flex-1 text-xs @min-[54rem]:w-40 @min-[54rem]:flex-none" :aria-label="t('pluginPlatform.sortBy')"><SelectValue /></SelectTrigger>
<SelectContent>
<SelectItem value="name">{{ t("pluginPlatform.sortByName") }}</SelectItem>
<SelectItem value="recently-updated">{{ t("pluginPlatform.sortByRecentlyUpdated") }}</SelectItem>
@@ -1141,7 +1145,7 @@ onBeforeUnmount(() => {
</SelectContent>
</Select>
<Select v-model="marketplaceRepositoryId">
<SelectTrigger class="h-8 min-w-0 flex-1 text-xs sm:w-52 sm:flex-none"><SelectValue :placeholder="t('pluginPlatform.allRepositories')" /></SelectTrigger>
<SelectTrigger data-plugin-marketplace-repository class="h-8 min-w-0 flex-1 text-xs @min-[54rem]:w-52 @min-[54rem]:flex-none"><SelectValue :placeholder="t('pluginPlatform.allRepositories')" /></SelectTrigger>
<SelectContent>
<SelectItem value="all">{{ t("pluginPlatform.allRepositories") }}</SelectItem>
<SelectItem v-for="repository in repositories.filter((entry) => entry.enabled)" :key="repository.id" :value="repository.id">{{ repository.name }}</SelectItem>
@@ -1640,7 +1644,7 @@ onBeforeUnmount(() => {
</div>
</TabsContent>
<TabsContent value="settings" class="m-0 min-h-0 flex-1 overflow-y-auto">
<TabsContent value="settings" class="@container m-0 min-h-0 flex-1 overflow-y-auto">
<div class="space-y-4 pb-2">
<PluginShortcutSettings />
<section class="space-y-3 rounded-xl border p-4">
@@ -1693,7 +1697,9 @@ onBeforeUnmount(() => {
<Button v-if="!repository.managed" size="icon" variant="ghost" class="size-7 text-destructive" :disabled="mutationRunning" @click="removeRepository(repository)"><Trash2 class="size-3.5" /></Button>
</div>
</div>
<div class="grid gap-2 lg:grid-cols-[180px_220px_minmax(260px,1fr)_auto]">
<!-- 同样按面板宽度切换:四列固定轨道 + 最长语言按钮实测约需 855px(含 pt-BR 标签),
视口断点(lg:)在窄面板下会整行溢出(#10582 同类) -->
<div class="grid gap-2 @min-[56rem]:grid-cols-[180px_220px_minmax(260px,1fr)_auto]">
<Input v-model="repositoryId" class="h-8 text-xs" :placeholder="t('pluginPlatform.repositoryIdPlaceholder')" />
<Input v-model="repositoryName" class="h-8 text-xs" :placeholder="t('pluginPlatform.repositoryNamePlaceholder')" />
<Input v-model="repositoryCatalogUrl" class="h-8 text-xs" :placeholder="t('pluginPlatform.repositoryCatalogUrlPlaceholder')" />
@@ -1746,7 +1752,7 @@ onBeforeUnmount(() => {
<Button size="icon" variant="ghost" class="size-7 text-destructive" :disabled="mutationRunning" @click="removeTrustedKey(key.keyId)"><Trash2 class="size-3.5" /></Button>
</div>
</div>
<div class="grid gap-2 md:grid-cols-[180px_minmax(260px,1fr)_auto]">
<div class="grid gap-2 @min-[42rem]:grid-cols-[180px_minmax(260px,1fr)_auto]">
<Input v-model="trustedKeyId" class="h-8 text-xs" :placeholder="t('pluginPlatform.repositoryKeyIdPlaceholder')" />
<Input v-model="trustedPublicKey" class="h-8 font-mono text-xs" :placeholder="t('pluginPlatform.repositoryPublicKeyPlaceholder')" />
<Button size="sm" class="h-8 gap-1.5" :disabled="mutationRunning" @click="saveTrustedKey"><ShieldCheck class="size-3.5" />{{ t("pluginPlatform.trustRepository") }}</Button>
@@ -1255,3 +1255,77 @@ describe("PluginContributionsPanel settings navigation", () => {
expect(current.activeSection).toBe("settings");
});
});
describe("PluginContributionsPanel narrow-pane layout contracts", () => {
// #10582: the plugin center is mounted in the editor-content pane, whose width is independent of the
// window (window minWidth is 900, but the sidebar or a split group can leave the pane far narrower).
// A viewport breakpoint therefore keys the layout off the wrong width: the marketplace toolbar row
// overflowed its scroller and 批量管理 / 刷新 left the visible area (measured 155px overflow at a 650px
// pane). happy-dom cannot measure layout, so this guards the class contract the measurement rig
// validates — same style as the #10444 grid guard above.
it("keys the marketplace toolbar off the panel width instead of the viewport", () => {
const toolbar = host.querySelector<HTMLElement>("[data-plugin-marketplace-toolbar]");
expect(toolbar, "marketplace toolbar").not.toBeNull();
expect(toolbar!.classList.contains("sm:flex-row"), "row switch must not use the viewport breakpoint (#10582)").toBe(false);
expect(toolbar!.classList.contains("sm:items-center"), "row switch must not use the viewport breakpoint (#10582)").toBe(false);
expect(toolbar!.classList.contains("@min-[54rem]:flex-row"), "row switch tracks the panel width").toBe(true);
expect(toolbar!.classList.contains("flex-wrap"), "an overflowing control set must wrap, never leave the pane").toBe(true);
const controls = host.querySelector<HTMLElement>("[data-plugin-marketplace-controls]");
expect(controls, "marketplace control cluster").not.toBeNull();
expect(controls!.classList.contains("flex-wrap"), "control cluster wraps").toBe(true);
expect(controls!.classList.contains("sm:ml-auto"), "auto margin must not use the viewport breakpoint").toBe(false);
expect(controls!.classList.contains("@min-[54rem]:ml-auto"), "auto margin tracks the panel width").toBe(true);
// App.vue focuses this input by attribute for Mod+F, so the hook has to survive layout changes.
const search = host.querySelector<HTMLInputElement>("[data-plugin-marketplace-search]");
expect(search, "marketplace search input hook").not.toBeNull();
expect(search!.classList.contains("sm:w-[min(100%,28rem)]")).toBe(false);
expect(search!.classList.contains("@min-[54rem]:w-[min(100%,28rem)]")).toBe(true);
// The Select family shares one passthrough stub here, so the triggers are located by their own
// data hooks (same convention as data-plugin-marketplace-search) instead of by a layout class.
const triggers = ["sort", "repository"].map((role) => {
const trigger = toolbar!.querySelector<HTMLElement>(`[data-plugin-marketplace-${role}]`);
expect(trigger, `marketplace ${role} select`).not.toBeNull();
return trigger!;
});
for (const trigger of triggers) {
const viewportClasses = [...trigger.classList].filter((name) => /^(sm|md|lg|xl):/.test(name));
expect(viewportClasses, `viewport breakpoints left on a select trigger: ${trigger.className}`).toEqual([]);
expect(
[...trigger.classList].some((name) => name.startsWith("@min-[54rem]:w-")),
`select trigger tracks the panel width: ${trigger.className}`,
).toBe(true);
}
});
it("keys the settings-tab repository grids off the panel width", async () => {
// The trusted-key grid only renders once a key exists, so remount with one (the same pattern the
// settings-navigation tests above use).
app.unmount();
host.remove();
host = document.createElement("div");
document.body.append(host);
mocks.listPluginTrustedKeys.mockResolvedValue([{ keyId: "custom", publicKey: "public-key" }]);
app = createApp(PluginContributionsPanel);
const instance = app.mount(host) as ComponentPublicInstance & { $: { setupState: PanelState } };
state = instance.$.setupState;
state.activeSection = "settings";
await flushUi();
const gridFor = (placeholderKey: string) => {
const input = [...host.querySelectorAll<HTMLInputElement>("input")].find((element) => element.placeholder.startsWith(`pluginPlatform.${placeholderKey}`));
expect(input, placeholderKey).toBeDefined();
return input!.parentElement!;
};
const addRow = gridFor("repositoryCatalogUrlPlaceholder");
expect(addRow.classList.contains("lg:grid-cols-[180px_220px_minmax(260px,1fr)_auto]"), "add-repository grid must not switch on the viewport").toBe(false);
expect(addRow.className, "add-repository grid tracks the panel width").toContain("@min-[56rem]:grid-cols-[180px_220px_minmax(260px,1fr)_auto]");
const trustRow = gridFor("repositoryPublicKeyPlaceholder");
expect(trustRow.classList.contains("md:grid-cols-[180px_minmax(260px,1fr)_auto]"), "trusted-key grid must not switch on the viewport").toBe(false);
expect(trustRow.className, "trusted-key grid tracks the panel width").toContain("@min-[42rem]:grid-cols-[180px_minmax(260px,1fr)_auto]");
});
});