feat(plugins): expose Dialog/ConfirmDialog/Toast/useToast/useConfirmDelete on plugin SDK

Additive expansion of window.__HERMES_PLUGIN_SDK__. Plugins can now render
host-styled dialogs, confirmations, and toasts instead of falling back to
window.alert/confirm/prompt.

New components: Dialog, DialogClose, DialogContent, DialogDescription,
DialogFooter, DialogHeader, DialogTitle, ConfirmDialog, Toast.
New hooks: useToast (replaces showToast/toast pair), useConfirmDelete
(single-id delete-confirm state machine).

SDK_CONTRACT_VERSION unchanged at 1.1.0 — additive surface per
sdk.d.ts:23-25 (no major bump required).

Consumer: kanban plugin's 'replace native dialogs' work, see issue #50547.
A reference prototype showing 4 design variants is committed at
docs/design/kanban-dialogs/index.html.

Adds web/src/plugins/registry.test.ts (3 vitest cases) that smoke-test the
new keys are wired and that the version constant is unchanged.
This commit is contained in:
David Metcalfe
2026-06-21 19:59:09 -07:00
committed by Teknium
parent da68ecf4b3
commit 7448e7a506
3 changed files with 102 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
/**
* Smoke test for the plugin SDK surface additions.
*
* Verifies that `exposePluginSDK()` writes the new dialog/toast primitives to
* `window.__HERMES_PLUGIN_SDK__`. Each new key is checked individually so a
* regression in one helper doesn't mask the others.
*
* Companion to the additive PR "feat(plugins): expose Dialog/ConfirmDialog/
* Toast/useToast/useConfirmDelete on the plugin SDK". See issue #50547.
*/
import { beforeEach, describe, expect, it } from "vitest";
import { exposePluginSDK } from "./registry";
describe("plugin SDK dialog/toast surface", () => {
beforeEach(() => {
// Reset window between tests so exposePluginSDK() writes fresh.
(globalThis as any).window = {
__HERMES_PLUGINS__: undefined,
__HERMES_PLUGIN_SDK__: undefined,
};
});
it("exposes Dialog + subcomponents on components", () => {
exposePluginSDK();
const sdk = (globalThis as any).window.__HERMES_PLUGIN_SDK__;
expect(sdk.components.Dialog).toBeDefined();
expect(sdk.components.DialogContent).toBeDefined();
expect(sdk.components.DialogHeader).toBeDefined();
expect(sdk.components.DialogTitle).toBeDefined();
expect(sdk.components.DialogDescription).toBeDefined();
expect(sdk.components.DialogFooter).toBeDefined();
expect(sdk.components.DialogClose).toBeDefined();
expect(sdk.components.ConfirmDialog).toBeDefined();
expect(sdk.components.Toast).toBeDefined();
});
it("exposes useToast and useConfirmDelete on hooks", () => {
exposePluginSDK();
const sdk = (globalThis as any).window.__HERMES_PLUGIN_SDK__;
expect(typeof sdk.hooks.useToast).toBe("function");
expect(typeof sdk.hooks.useConfirmDelete).toBe("function");
// Original React hooks still present (no accidental removal).
expect(typeof sdk.hooks.useState).toBe("function");
expect(typeof sdk.hooks.useCallback).toBe("function");
});
it("does not bump SDK_CONTRACT_VERSION (additive change)", () => {
exposePluginSDK();
const sdk = (globalThis as any).window.__HERMES_PLUGIN_SDK__;
// Pre-existing version per registry.ts:98. This test fails if a future
// PR accidentally bumps the major for an additive surface change.
expect(sdk.sdkVersion).toBe("1.1.0");
});
});
+24
View File
@@ -22,6 +22,14 @@ import { cn, timeAgo, isoTimeAgo } from "@/lib/utils";
import { Badge } from "@nous-research/ui/ui/components/badge";
import { Button } from "@nous-research/ui/ui/components/button";
import { Checkbox } from "@nous-research/ui/ui/components/checkbox";
import { ConfirmDialog } from "@nous-research/ui/ui/components/confirm-dialog";
import {
Dialog, DialogClose, DialogContent, DialogDescription,
DialogFooter, DialogHeader, DialogTitle,
} from "@nous-research/ui/ui/components/dialog";
import { Toast } from "@nous-research/ui/ui/components/toast";
import { useConfirmDelete } from "@nous-research/ui/hooks/use-confirm-delete";
import { useToast } from "@nous-research/ui/hooks/use-toast";
import { Select, SelectOption } from "@nous-research/ui/ui/components/select";
import { Card, CardHeader, CardTitle, CardContent } from "@nous-research/ui/ui/components/card";
import { Input } from "@nous-research/ui/ui/components/input";
@@ -121,6 +129,13 @@ export function exposePluginSDK() {
useRef,
useContext,
createContext,
// useToast returns { showToast, toast } where toast is the current
// visible toast (or null) and showToast(message, 'success'|'error')
// replaces it. useConfirmDelete<TId>({ onDelete }) returns the state
// machine (requestDelete / confirm / cancel / isOpen / isDeleting /
// pendingId) for single-id delete confirmations.
useToast,
useConfirmDelete,
},
// Hermes API client
@@ -148,6 +163,14 @@ export function exposePluginSDK() {
Badge,
Button,
Checkbox,
ConfirmDialog,
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
Input,
Label,
Select,
@@ -156,6 +179,7 @@ export function exposePluginSDK() {
Tabs,
TabsList,
TabsTrigger,
Toast,
PluginSlot,
},
+24
View File
@@ -105,6 +105,30 @@ export interface HermesPluginSDK {
useRef: typeof import("react").useRef;
useContext: typeof import("react").useContext;
createContext: typeof import("react").createContext;
/**
* Toast feedback. Returns ``{ showToast, toast }`` where ``toast`` is the
* current visible toast (or null) and ``showToast(message, 'success' | 'error')``
* replaces it. Mount the ``Toast`` component (also on ``components``) somewhere
* in your plugin's tree to render the visible toast.
*/
useToast: () => {
showToast: (message: string, type: "success" | "error") => void;
toast: { message: string; type: "success" | "error" } | null;
};
/**
* Single-id delete-confirm state machine. Pass ``onDelete(id)`` (an async
* function). Returns ``{ requestDelete, confirm, cancel, isOpen, isDeleting,
* pendingId }``. Pair with the ``ConfirmDialog`` primitive (passed as
* ``open={isOpen}`` etc.) or any custom dialog.
*/
useConfirmDelete: <TId,>(opts: { onDelete: (id: TId) => Promise<void> }) => {
requestDelete: (id: TId) => void;
confirm: () => Promise<void>;
cancel: () => void;
isOpen: boolean;
isDeleting: boolean;
pendingId: TId | null;
};
};
/**