feat(plugins): localize options_action and rework dock plus picker
This commit is contained in:
1 parent
5d21ba79df
commit
d2c471306c
14 files changed
+220
-47
No files matched your search
+100
-3
@@ -1,14 +1,14 @@
|
|||||||
// @vitest-environment happy-dom
|
// @vitest-environment happy-dom
|
||||||
|
|
||||||
import { createApp, defineComponent, h, ref, type App } from "vue";
|
import { createApp, defineComponent, h, inject, provide, ref, type App } from "vue";
|
||||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import type { InstalledPlugin } from "@/types/database";
|
import type { InstalledPlugin } from "@/types/database";
|
||||||
|
|
||||||
const mocks = vi.hoisted(() => ({ listPlugins: vi.fn(), invokePlugin: vi.fn() }));
|
const mocks = vi.hoisted(() => ({ listPlugins: vi.fn(), invokePlugin: vi.fn(), useConnectionStore: vi.fn() }));
|
||||||
|
|
||||||
vi.mock("@/lib/backend/api", () => ({ listPlugins: mocks.listPlugins, invokePlugin: mocks.invokePlugin }));
|
vi.mock("@/lib/backend/api", () => ({ listPlugins: mocks.listPlugins, invokePlugin: mocks.invokePlugin }));
|
||||||
vi.mock("vue-i18n", () => ({ useI18n: () => ({ locale: ref("en"), t: (key: string) => key }) }));
|
vi.mock("vue-i18n", () => ({ useI18n: () => ({ locale: ref("en"), t: (key: string) => key }) }));
|
||||||
vi.mock("@/stores/connectionStore", () => ({ useConnectionStore: () => ({ connections: [] }) }));
|
vi.mock("@/stores/connectionStore", () => ({ useConnectionStore: mocks.useConnectionStore }));
|
||||||
vi.mock("@/stores/queryStore", () => ({ useQueryStore: () => ({}) }));
|
vi.mock("@/stores/queryStore", () => ({ useQueryStore: () => ({}) }));
|
||||||
vi.mock("@/components/ui/button", () => ({
|
vi.mock("@/components/ui/button", () => ({
|
||||||
Button: defineComponent(
|
Button: defineComponent(
|
||||||
@@ -35,6 +35,37 @@ vi.mock("@/components/ui/tooltip", () => ({
|
|||||||
),
|
),
|
||||||
}));
|
}));
|
||||||
vi.mock("./PluginIcon.vue", () => ({ default: defineComponent(() => () => h("span")) }));
|
vi.mock("./PluginIcon.vue", () => ({ default: defineComponent(() => () => h("span")) }));
|
||||||
|
vi.mock("@/components/icons/ConnectionIcon.vue", () => ({ default: defineComponent(() => () => h("span", { "data-connection-icon-stub": "" })) }));
|
||||||
|
// DropdownMenu harness: content renders unconditionally and the trigger's
|
||||||
|
// click forwards `update:open`, so picker tests assert menu content and item
|
||||||
|
// selection without depending on reka-ui's floating/portal behavior.
|
||||||
|
vi.mock("@/components/ui/dropdown-menu", () => ({
|
||||||
|
DropdownMenu: defineComponent({
|
||||||
|
props: { open: { type: Boolean, default: false } },
|
||||||
|
emits: ["update:open"],
|
||||||
|
setup(_, { slots, emit }) {
|
||||||
|
provide("dbxDropdownTestSetOpen", (value: boolean) => emit("update:open", value));
|
||||||
|
return () => h("div", { "data-dropdown-menu-stub": "" }, slots.default?.());
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
DropdownMenuTrigger: defineComponent({
|
||||||
|
setup(_, { slots }) {
|
||||||
|
const setOpen = inject<(value: boolean) => void>("dbxDropdownTestSetOpen")!;
|
||||||
|
return () => h("div", { onClick: () => setOpen(true) }, slots.default?.());
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
DropdownMenuContent: defineComponent(
|
||||||
|
(_, { slots }) =>
|
||||||
|
() =>
|
||||||
|
h("div", { "data-plugin-dock-plus-menu": "" }, slots.default?.()),
|
||||||
|
),
|
||||||
|
DropdownMenuItem: defineComponent({
|
||||||
|
emits: ["select"],
|
||||||
|
setup(_, { slots, emit }) {
|
||||||
|
return () => h("div", { "data-dropdown-item-stub": "", onClick: () => emit("select", {}) }, slots.default?.());
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
}));
|
||||||
// Mirrors the real PluginWorkbenchHost, whose title computed dereferences
|
// Mirrors the real PluginWorkbenchHost, whose title computed dereferences
|
||||||
// props.contribution.label unconditionally — an undefined contribution must
|
// props.contribution.label unconditionally — an undefined contribution must
|
||||||
// never reach it, otherwise the whole dock subtree crashes during render.
|
// never reach it, otherwise the whole dock subtree crashes during render.
|
||||||
@@ -70,6 +101,7 @@ describe("PluginBottomDock workbench contribution guard", () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
|
mocks.useConnectionStore.mockReturnValue({ connections: [], sidebarLayout: { groups: [], order: [] }, ensureConnected: vi.fn(() => Promise.resolve()) });
|
||||||
root = document.createElement("div");
|
root = document.createElement("div");
|
||||||
document.body.appendChild(root);
|
document.body.appendChild(root);
|
||||||
});
|
});
|
||||||
@@ -137,11 +169,76 @@ describe("PluginBottomDock workbench contribution guard", () => {
|
|||||||
expect(renderError).toBeUndefined();
|
expect(renderError).toBeUndefined();
|
||||||
expect(mocks.invokePlugin).not.toHaveBeenCalled();
|
expect(mocks.invokePlugin).not.toHaveBeenCalled();
|
||||||
expect(warnSpy.mock.calls.filter((call) => String(call[0]).includes("[DBX][plugin:dock]"))).toEqual([]);
|
expect(warnSpy.mock.calls.filter((call) => String(call[0]).includes("[DBX][plugin:dock]"))).toEqual([]);
|
||||||
|
// Without options_action the command doesn't own the picker, so the
|
||||||
|
// generic replay item stays visible.
|
||||||
|
expect(root.querySelector("[data-plugin-dock-plus-menu]")?.textContent).toContain("pluginDock.newTerminal");
|
||||||
} finally {
|
} finally {
|
||||||
warnSpy.mockRestore();
|
warnSpy.mockRestore();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("passes the current UI locale to the options_action fetch", async () => {
|
||||||
|
// Sidecars need the UI language to localize launch-option labels; the host
|
||||||
|
// used to call options_action with an empty payload.
|
||||||
|
const plugin = installedPlugin("sample.panel");
|
||||||
|
plugin.manifest.contributions!.push({
|
||||||
|
type: "command",
|
||||||
|
id: "sample.open",
|
||||||
|
label: "Open sample",
|
||||||
|
action: { type: "open-workbench", workbench: "sample.panel", presentation: "panel", options_action: "local/terminal/launch-options" },
|
||||||
|
});
|
||||||
|
mocks.listPlugins.mockResolvedValue([plugin]);
|
||||||
|
mocks.invokePlugin.mockResolvedValue({ entries: [{ label: "Local terminal (auto-detect)", description: "Default shell: /bin/zsh", context: {} }] });
|
||||||
|
entryIds.push(dock.addPluginDockEntry({ pluginId: "io.dbx.sample", workbenchContributionId: "sample.panel", kind: "command", commandId: "sample.open", title: "Sample terminal" }));
|
||||||
|
await mountDock();
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||||
|
|
||||||
|
expect(mocks.invokePlugin).toHaveBeenCalledWith("io.dbx.sample", "local/terminal/launch-options", { locale: "en" });
|
||||||
|
const menu = root.querySelector("[data-plugin-dock-plus-menu]");
|
||||||
|
expect(menu?.textContent).toContain("Local terminal (auto-detect)");
|
||||||
|
expect(menu?.textContent).toContain("Default shell: /bin/zsh");
|
||||||
|
// The plugin owns the picker now: the generic replay item hides.
|
||||||
|
expect(menu?.textContent).not.toContain("pluginDock.newTerminal");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("renders the + picker connection targets as sidebar-grouped rows and opens them on pick", async () => {
|
||||||
|
const plugin = installedPlugin("sample.panel");
|
||||||
|
plugin.manifest.contributions!.push(
|
||||||
|
{ type: "connection-provider", id: "ssh", label: "SSH", database_type: "plugin", fields: [] },
|
||||||
|
{
|
||||||
|
type: "command",
|
||||||
|
id: "sample.open",
|
||||||
|
label: "Open sample",
|
||||||
|
action: { type: "open-workbench", workbench: "sample.panel", presentation: "panel", connection_targets: true },
|
||||||
|
},
|
||||||
|
);
|
||||||
|
mocks.listPlugins.mockResolvedValue([plugin]);
|
||||||
|
mocks.useConnectionStore.mockReturnValue({
|
||||||
|
connections: [{ id: "conn-1", name: "my-server", plugin_connection_provider: "ssh" }],
|
||||||
|
sidebarLayout: {
|
||||||
|
groups: [{ id: "g1", name: "Prod", collapsed: false }],
|
||||||
|
order: [{ type: "group", id: "g1", children: [{ type: "connection", id: "conn-1" }] }],
|
||||||
|
},
|
||||||
|
ensureConnected: vi.fn(() => Promise.resolve()),
|
||||||
|
});
|
||||||
|
entryIds.push(dock.addPluginDockEntry({ pluginId: "io.dbx.sample", workbenchContributionId: "sample.panel", kind: "command", commandId: "sample.open", title: "Sample terminal" }));
|
||||||
|
await mountDock();
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||||
|
|
||||||
|
const menu = root.querySelector("[data-plugin-dock-plus-menu]")!;
|
||||||
|
expect(menu.textContent).toContain("Prod");
|
||||||
|
expect(menu.textContent).toContain("my-server");
|
||||||
|
// The flat "connection · name" prefix is gone; rows carry icons instead.
|
||||||
|
expect(menu.textContent).not.toContain("pluginDock.connectionTerminal");
|
||||||
|
|
||||||
|
const row = [...menu.querySelectorAll("[data-dropdown-item-stub]")].find((element) => element.textContent?.includes("my-server")) as HTMLElement;
|
||||||
|
row.click();
|
||||||
|
const state = dock.usePluginBottomDock();
|
||||||
|
const picked = state.entries.value[state.entries.value.length - 1]!;
|
||||||
|
entryIds.push(picked.id);
|
||||||
|
expect(picked).toMatchObject({ kind: "connection", context: { connectionId: "conn-1" } });
|
||||||
|
});
|
||||||
|
|
||||||
it("degrades to an empty frame instead of crashing when the plugin no longer declares the entry's workbench contribution", async () => {
|
it("degrades to an empty frame instead of crashing when the plugin no longer declares the entry's workbench contribution", async () => {
|
||||||
// Plugin upgrade/downgrade replaced the workbench id the entry was opened with.
|
// Plugin upgrade/downgrade replaced the workbench id the entry was opened with.
|
||||||
mocks.listPlugins.mockResolvedValue([installedPlugin("sample.renamed")]);
|
mocks.listPlugins.mockResolvedValue([installedPlugin("sample.renamed")]);
|
||||||
|
|||||||
@@ -6,10 +6,11 @@
|
|||||||
// Each entry owns a host-stable workbenchId; v-show keeps sessions alive while switching tabs.
|
// Each entry owns a host-stable workbenchId; v-show keeps sessions alive while switching tabs.
|
||||||
import { computed, nextTick, onScopeDispose, ref, watch } from "vue";
|
import { computed, nextTick, onScopeDispose, ref, watch } from "vue";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import { ChevronDown, ChevronUp, Maximize2, Minimize2, Plus, X } from "@lucide/vue";
|
import { ChevronDown, ChevronRight, ChevronUp, Folder, Maximize2, Minimize2, Plus, X } from "@lucide/vue";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
||||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
|
||||||
|
import ConnectionIcon from "@/components/icons/ConnectionIcon.vue";
|
||||||
import PluginIcon from "@/components/plugins/PluginIcon.vue";
|
import PluginIcon from "@/components/plugins/PluginIcon.vue";
|
||||||
import PluginWorkbenchHost from "@/components/plugins/PluginWorkbenchHost.vue";
|
import PluginWorkbenchHost from "@/components/plugins/PluginWorkbenchHost.vue";
|
||||||
import { useConnectionStore } from "@/stores/connectionStore";
|
import { useConnectionStore } from "@/stores/connectionStore";
|
||||||
@@ -28,6 +29,7 @@ import {
|
|||||||
usePluginBottomDock,
|
usePluginBottomDock,
|
||||||
type PluginDockEntry,
|
type PluginDockEntry,
|
||||||
} from "@/lib/plugins/pluginBottomDock";
|
} from "@/lib/plugins/pluginBottomDock";
|
||||||
|
import { buildConnectionPickerRows } from "@/lib/connection/connectionPickerTree";
|
||||||
import { useDockResize } from "@/composables/useDockResize";
|
import { useDockResize } from "@/composables/useDockResize";
|
||||||
import { executePluginCommand } from "@/lib/plugins/pluginCommandRegistry";
|
import { executePluginCommand } from "@/lib/plugins/pluginCommandRegistry";
|
||||||
import { createFrontendPluginRegistry } from "@/lib/plugins/frontendPlugin";
|
import { createFrontendPluginRegistry } from "@/lib/plugins/frontendPlugin";
|
||||||
@@ -36,7 +38,7 @@ import { useQueryStore } from "@/stores/queryStore";
|
|||||||
import * as api from "@/lib/backend/api";
|
import * as api from "@/lib/backend/api";
|
||||||
import type { InstalledPlugin, PluginWorkbenchContribution } from "@/types/database";
|
import type { InstalledPlugin, PluginWorkbenchContribution } from "@/types/database";
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t, locale } = useI18n();
|
||||||
// Tab strip interactions (drag reorder + double-click rename).
|
// Tab strip interactions (drag reorder + double-click rename).
|
||||||
const dragEntryId = ref<string | null>(null);
|
const dragEntryId = ref<string | null>(null);
|
||||||
const renamingEntryId = ref<string | null>(null);
|
const renamingEntryId = ref<string | null>(null);
|
||||||
@@ -179,7 +181,9 @@ async function loadLaunchOptions() {
|
|||||||
// options_action is OPTIONAL on open-workbench commands: without it there is
|
// options_action is OPTIONAL on open-workbench commands: without it there is
|
||||||
// nothing to fetch — proceeding fired a doomed invokePlugin(undefined) IPC
|
// nothing to fetch — proceeding fired a doomed invokePlugin(undefined) IPC
|
||||||
// round trip and a console.warn on every picker open / entry switch.
|
// round trip and a console.warn on every picker open / entry switch.
|
||||||
const cacheKey = action?.options_action && pluginId && commandId ? `${pluginId}:${commandId}` : "";
|
// The locale is part of the cache key: a UI language switch must refetch
|
||||||
|
// instead of repainting labels cached under the previous language.
|
||||||
|
const cacheKey = action?.options_action && pluginId && commandId ? `${pluginId}:${commandId}:${locale.value}` : "";
|
||||||
if (!cacheKey) {
|
if (!cacheKey) {
|
||||||
launchOptionEntries.value = [];
|
launchOptionEntries.value = [];
|
||||||
return;
|
return;
|
||||||
@@ -191,7 +195,10 @@ async function loadLaunchOptions() {
|
|||||||
launchOptionEntries.value = cached ?? [];
|
launchOptionEntries.value = cached ?? [];
|
||||||
launchOptionsLoading.value = !cached;
|
launchOptionsLoading.value = !cached;
|
||||||
try {
|
try {
|
||||||
const result = await api.invokePlugin<{ entries?: Array<{ label: string; description?: string; context?: Record<string, unknown> }> }>(pluginId!, action!.options_action!, {});
|
// locale tells the sidecar which UI language to label the entries in —
|
||||||
|
// the same field the plugin UI webview receives at init. Sidecars that
|
||||||
|
// don't read it are unaffected (they ignore the extra param).
|
||||||
|
const result = await api.invokePlugin<{ entries?: Array<{ label: string; description?: string; context?: Record<string, unknown> }> }>(pluginId!, action!.options_action!, { locale: locale.value });
|
||||||
const next = (result?.entries ?? []).map((entry, index) => ({ key: `opt:${index}`, label: entry.label, description: entry.description, context: entry.context }));
|
const next = (result?.entries ?? []).map((entry, index) => ({ key: `opt:${index}`, label: entry.label, description: entry.description, context: entry.context }));
|
||||||
launchOptionsCache.set(cacheKey, next);
|
launchOptionsCache.set(cacheKey, next);
|
||||||
// A stale response (entry switched while fetching) must not overwrite the
|
// A stale response (entry switched while fetching) must not overwrite the
|
||||||
@@ -385,28 +392,76 @@ const plusOpen = ref(false);
|
|||||||
// what the entries mean.
|
// what the entries mean.
|
||||||
const plusFilter = ref("");
|
const plusFilter = ref("");
|
||||||
const PLUS_FILTER_THRESHOLD = 8;
|
const PLUS_FILTER_THRESHOLD = 8;
|
||||||
const plusItemCount = computed(() => 1 + launchOptionEntries.value.length + connectionTargets.value.length);
|
// A command declaring options_action owns this picker: the generic replay
|
||||||
|
// item hides (replaying a singleton command would only refocus the live
|
||||||
|
// panel — multi-open is exactly what the plugin's own options exist for).
|
||||||
|
const showReplayItem = computed(() => !activeAction.value?.options_action);
|
||||||
|
const plusItemCount = computed(() => (showReplayItem.value ? 1 : 0) + launchOptionEntries.value.length + connectionTargets.value.length);
|
||||||
const plusQuery = computed(() => plusFilter.value.trim().toLowerCase());
|
const plusQuery = computed(() => plusFilter.value.trim().toLowerCase());
|
||||||
function plusMatches(label: string): boolean {
|
function plusMatches(label: string): boolean {
|
||||||
return !plusQuery.value || label.toLowerCase().includes(plusQuery.value);
|
return !plusQuery.value || label.toLowerCase().includes(plusQuery.value);
|
||||||
}
|
}
|
||||||
const visibleLaunchOptions = computed(() => launchOptionEntries.value.filter((option) => plusMatches(option.label)));
|
const visibleLaunchOptions = computed(() => launchOptionEntries.value.filter((option) => plusMatches(option.label)));
|
||||||
const visibleConnectionTargets = computed(() => connectionTargets.value.filter((target) => plusMatches(optionLabel(target))));
|
// Connection rows reuse the AI assistant's connection tree select logic
|
||||||
function optionLabel(target: { label: string }): string {
|
// (buildConnectionPickerRows): sidebar groups, per-connection icons, and a
|
||||||
return target.label;
|
// search that also matches group paths and force-expands its matches — the
|
||||||
|
// flat label filter below stays for the replay/launch-option items only.
|
||||||
|
// Collapsed groups are dock-local view state.
|
||||||
|
const collapsedPickerGroups = ref(new Set<string>());
|
||||||
|
const connectionById = computed(() => new Map(connectionTargets.value.map((target) => [target.connection.id, target.connection])));
|
||||||
|
const connectionPickerRows = computed(() =>
|
||||||
|
buildConnectionPickerRows(
|
||||||
|
connectionStore.sidebarLayout,
|
||||||
|
connectionTargets.value.map((target) => target.connection),
|
||||||
|
collapsedPickerGroups.value,
|
||||||
|
plusQuery.value,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
function togglePickerGroup(groupId: string) {
|
||||||
|
if (plusQuery.value) return;
|
||||||
|
const next = new Set(collapsedPickerGroups.value);
|
||||||
|
if (!next.delete(groupId)) next.add(groupId);
|
||||||
|
collapsedPickerGroups.value = next;
|
||||||
}
|
}
|
||||||
function setPlusOpen(open: boolean) {
|
const plusHasMatches = computed(() => (showReplayItem.value && plusMatches(t("pluginDock.newTerminal"))) || visibleLaunchOptions.value.length > 0 || connectionPickerRows.value.length > 0);
|
||||||
plusOpen.value = open;
|
async function setPlusOpen(open: boolean) {
|
||||||
plusFilter.value = "";
|
plusFilter.value = "";
|
||||||
if (open) {
|
if (!open) {
|
||||||
void loadLaunchOptions();
|
plusOpen.value = false;
|
||||||
warmActivePluginPanelHtml();
|
return;
|
||||||
}
|
}
|
||||||
|
// Collapsed dock: the strip hugs the window bottom edge, leaving no room
|
||||||
|
// below the "+" for a downward picker. Restore the panel body first — the
|
||||||
|
// picker is about to add a panel entry, which a collapsed frame would hide.
|
||||||
|
if (collapsed.value) collapsed.value = false;
|
||||||
|
await nextTick();
|
||||||
|
measurePlusMenuHeight();
|
||||||
|
plusOpen.value = true;
|
||||||
|
void loadLaunchOptions();
|
||||||
|
warmActivePluginPanelHtml();
|
||||||
}
|
}
|
||||||
function closePlusMenu() {
|
function closePlusMenu() {
|
||||||
plusOpen.value = false;
|
plusOpen.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Keep the "+" picker opening strictly downward. reka's menu chain silently
|
||||||
|
// drops the `side-flip` prop (MenuContentImpl forwards side/align/sticky/... to
|
||||||
|
// PopperContent but not sideFlip), so the flip middleware is always live: any
|
||||||
|
// bottom overflow makes the menu jump above the trigger. Instead of fighting
|
||||||
|
// the middleware, cap the menu height to the space remaining under the trigger
|
||||||
|
// — floating-ui then never sees a bottom overflow, so the menu can only open
|
||||||
|
// downward, while cross-axis shift keeps it inside the window near the edges.
|
||||||
|
// Must run before `plusOpen` flips true: the inline cap has to be bound when
|
||||||
|
// the content mounts, or the first uncapped measurement would still flip it.
|
||||||
|
const PLUS_MENU_MIN_HEIGHT_PX = 80;
|
||||||
|
const plusMenuMaxHeight = ref<string>();
|
||||||
|
function measurePlusMenuHeight() {
|
||||||
|
const trigger = dockRoot.value?.querySelector<HTMLElement>("[data-plugin-dock-plus-trigger]");
|
||||||
|
if (!trigger) return;
|
||||||
|
const below = window.innerHeight - trigger.getBoundingClientRect().bottom - 8;
|
||||||
|
plusMenuMaxHeight.value = `${Math.max(PLUS_MENU_MIN_HEIGHT_PX, below)}px`;
|
||||||
|
}
|
||||||
|
|
||||||
// Hide the first-open html pipeline under the time the user spends reading the
|
// Hide the first-open html pipeline under the time the user spends reading the
|
||||||
// "+" picker: the read/decode/inline of a multi-megabyte ui build runs while
|
// "+" picker: the read/decode/inline of a multi-megabyte ui build runs while
|
||||||
// the menu is open, so whichever panel the user picks mounts on a warm cache
|
// the menu is open, so whichever panel the user picks mounts on a warm cache
|
||||||
@@ -489,31 +544,55 @@ onScopeDispose(() => window.removeEventListener("blur", onPlusMenuWindowBlur));
|
|||||||
viewport edge instead of running off-screen. -->
|
viewport edge instead of running off-screen. -->
|
||||||
<DropdownMenu v-if="activeCommand" :open="plusOpen" @update:open="setPlusOpen">
|
<DropdownMenu v-if="activeCommand" :open="plusOpen" @update:open="setPlusOpen">
|
||||||
<DropdownMenuTrigger as-child>
|
<DropdownMenuTrigger as-child>
|
||||||
<Button variant="ghost" size="icon" class="h-7 w-7" :aria-label="t('pluginDock.newTerminal')" :aria-expanded="plusOpen">
|
<Button variant="ghost" size="icon" class="h-7 w-7" :aria-label="t('pluginDock.newTerminal')" :aria-expanded="plusOpen" data-plugin-dock-plus-trigger>
|
||||||
<Plus class="h-4 w-4" />
|
<Plus class="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<!-- sideFlip=false pins the menu below the "+": the dock panel body
|
<!-- Always pinned below the "+" (see measurePlusMenuHeight): the inline
|
||||||
below it is the intended scroll area, so flipping upward over the
|
max-height caps the menu to the space under the trigger, so the
|
||||||
workbench (the default when the panel is short) reads as the menu
|
flip middleware never sees a bottom overflow. Cross-axis shift
|
||||||
"growing from the mouse". Cross-axis shift stays on, so the menu
|
stays on, so the menu still hugs the window edge instead of
|
||||||
still hugs the window edge instead of overflowing it; height
|
overflowing it; the capped list scrolls internally. -->
|
||||||
follows the popper's available space below the trigger. -->
|
<DropdownMenuContent align="start" :side-offset="4" class="max-h-(--reka-dropdown-menu-content-available-height) w-64" :style="plusMenuMaxHeight ? { maxHeight: plusMenuMaxHeight } : undefined" data-plugin-dock-plus-menu>
|
||||||
<DropdownMenuContent align="start" :side-offset="4" :side-flip="false" class="max-h-(--reka-dropdown-menu-content-available-height) w-64" data-plugin-dock-plus-menu>
|
|
||||||
<!-- Generic list filter (appears only for long lists): the host filters
|
<!-- Generic list filter (appears only for long lists): the host filters
|
||||||
by label without knowing what the entries mean. -->
|
by label without knowing what the entries mean. -->
|
||||||
<input v-if="plusItemCount > PLUS_FILTER_THRESHOLD" v-model="plusFilter" class="mb-1 w-full rounded-md border bg-background px-2 py-1 text-xs outline-none focus:ring-1 focus:ring-primary/40" :placeholder="t('pluginDock.filter')" spellcheck="false" @keydown.stop />
|
<input v-if="plusItemCount > PLUS_FILTER_THRESHOLD" v-model="plusFilter" class="mb-1 w-full rounded-md border bg-background px-2 py-1 text-xs outline-none focus:ring-1 focus:ring-primary/40" :placeholder="t('pluginDock.filter')" spellcheck="false" @keydown.stop />
|
||||||
<DropdownMenuItem v-if="plusMatches(t('pluginDock.newTerminal'))" @select="onPlusAction('replay')">
|
<DropdownMenuItem v-if="showReplayItem && plusMatches(t('pluginDock.newTerminal'))" @select="onPlusAction('replay')">
|
||||||
<Plus class="h-3.5 w-3.5 shrink-0" />
|
<Plus class="h-3.5 w-3.5 shrink-0" />
|
||||||
<span class="truncate">{{ t("pluginDock.newTerminal") }}</span>
|
<span class="min-w-0 flex-1 truncate text-sm">{{ t("pluginDock.newTerminal") }}</span>
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem v-for="option in visibleLaunchOptions" :key="option.key" @select="onPlusAction(option.key)">
|
<DropdownMenuItem v-for="option in visibleLaunchOptions" :key="option.key" @select="onPlusAction(option.key)">
|
||||||
<span class="truncate">{{ option.label }}</span>
|
<PluginIcon :plugin-id="activeEntry?.pluginId ?? ''" :icon="activeCommand?.icon" class="h-3.5 w-3.5 shrink-0" />
|
||||||
|
<span class="min-w-0 flex-1">
|
||||||
|
<span class="block truncate text-sm">{{ option.label }}</span>
|
||||||
|
<span v-if="option.description" class="block truncate text-xs text-muted-foreground">{{ option.description }}</span>
|
||||||
|
</span>
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem v-for="target in visibleConnectionTargets" :key="target.key" :title="target.connection.name" @select="onPlusAction(target.key)">
|
<DropdownMenuSeparator v-if="visibleLaunchOptions.length && connectionPickerRows.length" />
|
||||||
<span class="truncate">{{ t("pluginDock.connectionTerminal") }} · {{ target.label }}</span>
|
<template v-for="row in connectionPickerRows" :key="row.key">
|
||||||
</DropdownMenuItem>
|
<!-- Group headers are plain rows, not menu items: clicking toggles
|
||||||
<div v-if="plusQuery && !plusMatches(t('pluginDock.newTerminal')) && !visibleLaunchOptions.length && !visibleConnectionTargets.length" class="px-2 py-1.5 text-xs text-muted-foreground">
|
collapse (a no-op while searching), and reka-ui keyboard
|
||||||
|
navigation skips them — same contract as the AI assistant's
|
||||||
|
connection tree select. -->
|
||||||
|
<div
|
||||||
|
v-if="row.kind === 'group'"
|
||||||
|
:title="row.label"
|
||||||
|
:aria-expanded="!row.collapsed"
|
||||||
|
:style="{ paddingLeft: `${8 + row.depth * 14}px` }"
|
||||||
|
class="flex h-6 cursor-default select-none items-center gap-1.5 rounded-md pr-2 text-xs font-medium text-muted-foreground"
|
||||||
|
@click="togglePickerGroup(row.id)"
|
||||||
|
>
|
||||||
|
<ChevronDown v-if="!row.collapsed" class="h-3 w-3 shrink-0" />
|
||||||
|
<ChevronRight v-else class="h-3 w-3 shrink-0" />
|
||||||
|
<Folder class="h-3.5 w-3.5 shrink-0" />
|
||||||
|
<span class="truncate">{{ row.label }}</span>
|
||||||
|
</div>
|
||||||
|
<DropdownMenuItem v-else :title="row.label" :style="{ paddingLeft: `${8 + row.depth * 14}px` }" @select="onPlusAction(`conn:${row.id}`)">
|
||||||
|
<ConnectionIcon :connection="connectionById.get(row.id)" class="h-3.5 w-3.5 shrink-0" />
|
||||||
|
<span class="min-w-0 flex-1 truncate text-sm">{{ row.label }}</span>
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</template>
|
||||||
|
<div v-if="plusQuery && !plusHasMatches" class="px-2 py-1.5 text-xs text-muted-foreground">
|
||||||
{{ t("pluginDock.noMatch") }}
|
{{ t("pluginDock.noMatch") }}
|
||||||
</div>
|
</div>
|
||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
|
|||||||
@@ -438,7 +438,7 @@ describe("PluginConnectionFields", () => {
|
|||||||
await mountContribution(dynamic, { sudo_profile: "ghost" }, "io.dbx.ssh");
|
await mountContribution(dynamic, { sudo_profile: "ghost" }, "io.dbx.ssh");
|
||||||
await flushAsync();
|
await flushAsync();
|
||||||
|
|
||||||
expect(invokePluginMock).toHaveBeenCalledWith("io.dbx.ssh", "sudo/profiles/options");
|
expect(invokePluginMock).toHaveBeenCalledWith("io.dbx.ssh", "sudo/profiles/options", { locale: "en" });
|
||||||
expect(document.querySelector("input#dyn-connection-sudo_profile")).toBeNull();
|
expect(document.querySelector("input#dyn-connection-sudo_profile")).toBeNull();
|
||||||
const trigger = document.querySelector<HTMLButtonElement>('#dyn-connection-sudo_profile, button[role="combobox"]');
|
const trigger = document.querySelector<HTMLButtonElement>('#dyn-connection-sudo_profile, button[role="combobox"]');
|
||||||
expect(trigger).not.toBeNull();
|
expect(trigger).not.toBeNull();
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ const emit = defineEmits<{
|
|||||||
"update:modelValue": [value: Record<string, PluginFormFieldValue>];
|
"update:modelValue": [value: Record<string, PluginFormFieldValue>];
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t, locale } = useI18n();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
|
|
||||||
const formValues = computed(() => props.modelValue);
|
const formValues = computed(() => props.modelValue);
|
||||||
@@ -118,7 +118,9 @@ watch(
|
|||||||
const action = field.options_action;
|
const action = field.options_action;
|
||||||
if (!action || !props.pluginId || dynamicOptionsRequested.value.has(field.key)) continue;
|
if (!action || !props.pluginId || dynamicOptionsRequested.value.has(field.key)) continue;
|
||||||
dynamicOptionsRequested.value.add(field.key);
|
dynamicOptionsRequested.value.add(field.key);
|
||||||
invokePlugin<{ options?: PluginFormFieldOption[] }>(props.pluginId, action)
|
// locale lets the sidecar localize the returned option labels (same
|
||||||
|
// field the plugin UI webview receives at init); older sidecars ignore it.
|
||||||
|
invokePlugin<{ options?: PluginFormFieldOption[] }>(props.pluginId, action, { locale: locale.value })
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
const options = Array.isArray(result?.options) ? result.options.filter((option) => option && option.value !== undefined) : [];
|
const options = Array.isArray(result?.options) ? result.options.filter((option) => option && option.value !== undefined) : [];
|
||||||
dynamicOptions.value = { ...dynamicOptions.value, [field.key]: options };
|
dynamicOptions.value = { ...dynamicOptions.value, [field.key]: options };
|
||||||
|
|||||||
@@ -685,7 +685,6 @@ export default {
|
|||||||
restore: "Restore panel",
|
restore: "Restore panel",
|
||||||
newTerminal: "New terminal",
|
newTerminal: "New terminal",
|
||||||
newLocalTerminal: "Local terminal",
|
newLocalTerminal: "Local terminal",
|
||||||
connectionTerminal: "Connection",
|
|
||||||
filter: "Filter…",
|
filter: "Filter…",
|
||||||
noMatch: "No matches",
|
noMatch: "No matches",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -676,7 +676,6 @@ export default withEnglishFallback({
|
|||||||
restore: "Restaurar panel",
|
restore: "Restaurar panel",
|
||||||
newTerminal: "Nuevo terminal",
|
newTerminal: "Nuevo terminal",
|
||||||
newLocalTerminal: "Terminal local",
|
newLocalTerminal: "Terminal local",
|
||||||
connectionTerminal: "Conexión",
|
|
||||||
filter: "Filtrar…",
|
filter: "Filtrar…",
|
||||||
noMatch: "Sin coincidencias",
|
noMatch: "Sin coincidencias",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -671,7 +671,6 @@ export default withEnglishFallback({
|
|||||||
restore: "Ripristina pannello",
|
restore: "Ripristina pannello",
|
||||||
newTerminal: "Nuovo terminale",
|
newTerminal: "Nuovo terminale",
|
||||||
newLocalTerminal: "Terminale locale",
|
newLocalTerminal: "Terminale locale",
|
||||||
connectionTerminal: "Connessione",
|
|
||||||
filter: "Filtra…",
|
filter: "Filtra…",
|
||||||
noMatch: "Nessuna corrispondenza",
|
noMatch: "Nessuna corrispondenza",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -671,7 +671,6 @@ export default withEnglishFallback({
|
|||||||
restore: "パネルを元に戻す",
|
restore: "パネルを元に戻す",
|
||||||
newTerminal: "新規ターミナル",
|
newTerminal: "新規ターミナル",
|
||||||
newLocalTerminal: "ローカルターミナル",
|
newLocalTerminal: "ローカルターミナル",
|
||||||
connectionTerminal: "接続",
|
|
||||||
filter: "フィルタ…",
|
filter: "フィルタ…",
|
||||||
noMatch: "一致する項目がありません",
|
noMatch: "一致する項目がありません",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -678,7 +678,6 @@ export default withEnglishFallback({
|
|||||||
restore: "패널 복원",
|
restore: "패널 복원",
|
||||||
newTerminal: "새 터미널",
|
newTerminal: "새 터미널",
|
||||||
newLocalTerminal: "로컬 터미널",
|
newLocalTerminal: "로컬 터미널",
|
||||||
connectionTerminal: "연결",
|
|
||||||
filter: "필터…",
|
filter: "필터…",
|
||||||
noMatch: "일치 항목이 없습니다",
|
noMatch: "일치 항목이 없습니다",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -671,7 +671,6 @@ export default withEnglishFallback({
|
|||||||
restore: "Restaurar painel",
|
restore: "Restaurar painel",
|
||||||
newTerminal: "Novo terminal",
|
newTerminal: "Novo terminal",
|
||||||
newLocalTerminal: "Terminal local",
|
newLocalTerminal: "Terminal local",
|
||||||
connectionTerminal: "Conexão",
|
|
||||||
filter: "Filtrar…",
|
filter: "Filtrar…",
|
||||||
noMatch: "Nenhuma correspondência",
|
noMatch: "Nenhuma correspondência",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -630,7 +630,6 @@ export default withEnglishFallback({
|
|||||||
restore: "Восстановить панель",
|
restore: "Восстановить панель",
|
||||||
newTerminal: "Новый терминал",
|
newTerminal: "Новый терминал",
|
||||||
newLocalTerminal: "Локальный терминал",
|
newLocalTerminal: "Локальный терминал",
|
||||||
connectionTerminal: "Подключение",
|
|
||||||
filter: "Фильтр…",
|
filter: "Фильтр…",
|
||||||
noMatch: "Совпадений нет",
|
noMatch: "Совпадений нет",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -601,7 +601,6 @@ export default withEnglishFallback({
|
|||||||
restore: "还原面板",
|
restore: "还原面板",
|
||||||
newTerminal: "新建终端",
|
newTerminal: "新建终端",
|
||||||
newLocalTerminal: "本地终端",
|
newLocalTerminal: "本地终端",
|
||||||
connectionTerminal: "连接",
|
|
||||||
filter: "筛选…",
|
filter: "筛选…",
|
||||||
noMatch: "没有匹配项",
|
noMatch: "没有匹配项",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -674,7 +674,6 @@ export default withEnglishFallback({
|
|||||||
restore: "還原面板",
|
restore: "還原面板",
|
||||||
newTerminal: "新增終端",
|
newTerminal: "新增終端",
|
||||||
newLocalTerminal: "本機終端",
|
newLocalTerminal: "本機終端",
|
||||||
connectionTerminal: "連線",
|
|
||||||
filter: "篩選…",
|
filter: "篩選…",
|
||||||
noMatch: "沒有符合項目",
|
noMatch: "沒有符合項目",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -362,7 +362,9 @@ export interface PluginFormField {
|
|||||||
default?: PluginFormFieldValue | null;
|
default?: PluginFormFieldValue | null;
|
||||||
options?: PluginFormFieldOption[];
|
options?: PluginFormFieldOption[];
|
||||||
/** Plugin method returning `{ options: [{ value, label }] }` for dynamic
|
/** Plugin method returning `{ options: [{ value, label }] }` for dynamic
|
||||||
* select rendering; falls back to the declared type when unavailable. */
|
* select rendering; the host calls it with `{ locale }` (the current DBX UI
|
||||||
|
* locale) so plugins can localize the labels. Falls back to the declared
|
||||||
|
* type when unavailable. */
|
||||||
options_action?: string;
|
options_action?: string;
|
||||||
/** Host API 1.1: offer a local-file action on this field. */
|
/** Host API 1.1: offer a local-file action on this field. */
|
||||||
picker?: PluginFormFieldPicker;
|
picker?: PluginFormFieldPicker;
|
||||||
@@ -517,8 +519,10 @@ export interface PluginOpenWorkbenchAction extends PluginOpenWorkbenchTarget {
|
|||||||
/**
|
/**
|
||||||
* Generic launch-options extension point: sidecar method returning
|
* Generic launch-options extension point: sidecar method returning
|
||||||
* `{ entries: [{ label, description?, context? }] }` for the dock "+" picker.
|
* `{ entries: [{ label, description?, context? }] }` for the dock "+" picker.
|
||||||
* The host renders labels and merges the chosen context into the
|
* The host calls it with `{ locale }` (the current DBX UI locale, e.g.
|
||||||
* host-authored panel context — never interpreting the business meaning.
|
* "en"/"zh-CN") so plugins can localize the returned labels, renders the
|
||||||
|
* labels and merges the chosen context into the host-authored panel
|
||||||
|
* context — never interpreting the business meaning.
|
||||||
*/
|
*/
|
||||||
options_action?: string;
|
options_action?: string;
|
||||||
/** When true, the host also offers the plugin's own saved connections as launch targets. */
|
/** When true, the host also offers the plugin's own saved connections as launch targets. */
|
||||||
|
|||||||
Reference in new issue
Block a user