@blackbelt-technology/pi-dashboard-client-utils 0.6.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -0
- package/package.json +13 -3
- package/src/ActionList.tsx +6 -18
- package/src/Dialog.tsx +41 -18
- package/src/LayerPortal.tsx +27 -0
- package/src/StatusPill.tsx +6 -14
- package/src/agent-card-utils.ts +10 -3
- package/src/useFocusTrap.ts +55 -1
- package/src/AGENTS.md +0 -25
- package/src/__tests__/ActionList.test.tsx +0 -53
- package/src/__tests__/Confirm.test.tsx +0 -105
- package/src/__tests__/Dialog.test.tsx +0 -215
- package/src/__tests__/DialogPortal.test.tsx +0 -58
- package/src/__tests__/EmptyState.test.tsx +0 -44
- package/src/__tests__/Skeleton.test.tsx +0 -51
- package/src/__tests__/StatusPill.test.tsx +0 -44
- package/src/__tests__/escape-stack.test.ts +0 -166
- package/src/__tests__/statusPresentation.test.ts +0 -34
- package/src/__tests__/useFocusTrap.test.tsx +0 -68
- package/src/__tests__/useMobile.test.tsx +0 -92
- package/src/__tests__/useZoomPan.test.ts +0 -128
- package/src/extension-ui/AGENTS.md +0 -10
- package/src/minimal-chat/AGENTS.md +0 -9
- package/src/minimal-chat/__tests__/MinimalChatView.test.tsx +0 -235
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Pi Dashboard Client Utils
|
|
2
|
+
|
|
3
|
+
Small reusable React components, hooks, and helpers shared between the Pi Dashboard
|
|
4
|
+
shell and dashboard plugins.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install @blackbelt-technology/pi-dashboard-client-utils
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Every entry is its own subpath export, so you pull in only what you use:
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { Dialog } from "@blackbelt-technology/pi-dashboard-client-utils/Dialog";
|
|
16
|
+
import { useMobile } from "@blackbelt-technology/pi-dashboard-client-utils/useMobile";
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Includes portals and an escape-stack, popover/dialog/confirm primitives, a focus
|
|
20
|
+
trap, zoom/pan helpers, status presentation, and extension-UI slots. No markdown
|
|
21
|
+
stack — that stays in the shell.
|
|
22
|
+
|
|
23
|
+
## License
|
|
24
|
+
|
|
25
|
+
MIT — part of [pi-agent-dashboard](https://github.com/BlackBeltTechnology/pi-agent-dashboard).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blackbelt-technology/pi-dashboard-client-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Small reusable React components, hooks, and helpers shared between the pi-dashboard shell and dashboard plugins. Per-subpath exports; no markdown stack.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -25,6 +25,10 @@
|
|
|
25
25
|
"types": "./src/DialogPortal.tsx",
|
|
26
26
|
"default": "./src/DialogPortal.tsx"
|
|
27
27
|
},
|
|
28
|
+
"./LayerPortal": {
|
|
29
|
+
"types": "./src/LayerPortal.tsx",
|
|
30
|
+
"default": "./src/LayerPortal.tsx"
|
|
31
|
+
},
|
|
28
32
|
"./escape-stack": {
|
|
29
33
|
"types": "./src/escape-stack.ts",
|
|
30
34
|
"default": "./src/escape-stack.ts"
|
|
@@ -111,14 +115,20 @@
|
|
|
111
115
|
}
|
|
112
116
|
},
|
|
113
117
|
"files": [
|
|
114
|
-
"src/"
|
|
118
|
+
"src/",
|
|
119
|
+
"!**/AGENTS.md",
|
|
120
|
+
"!**/*.AGENTS.md",
|
|
121
|
+
"!**/__tests__",
|
|
122
|
+
"!**/*.test.ts",
|
|
123
|
+
"!**/*.test.tsx"
|
|
115
124
|
],
|
|
116
125
|
"peerDependencies": {
|
|
117
126
|
"react": ">=18.0.0",
|
|
118
127
|
"react-dom": ">=18.0.0"
|
|
119
128
|
},
|
|
120
129
|
"dependencies": {
|
|
121
|
-
"@blackbelt-technology/
|
|
130
|
+
"@blackbelt-technology/dashboard-plugin-runtime": "^0.8.0",
|
|
131
|
+
"@blackbelt-technology/pi-dashboard-shared": "^0.8.0",
|
|
122
132
|
"@mdi/js": "^7.4.47",
|
|
123
133
|
"@mdi/react": "^1.6.1"
|
|
124
134
|
},
|
package/src/ActionList.tsx
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*
|
|
8
8
|
* See change: adopt-server-driven-intent-rendering.
|
|
9
9
|
*/
|
|
10
|
-
import React from "react";
|
|
11
10
|
import Icon from "@mdi/react";
|
|
11
|
+
import * as mdi from "@mdi/js";
|
|
12
12
|
// We accept icon as a string key (MDI), look up via resolveMdiIcon at render time.
|
|
13
13
|
import type { UiActionListProps } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
|
|
14
14
|
import { sendPluginAction } from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
@@ -75,23 +75,11 @@ export function ActionList({ actions }: UiActionListProps) {
|
|
|
75
75
|
* lookup.
|
|
76
76
|
*/
|
|
77
77
|
function IconByKey({ iconKey }: { iconKey: string }) {
|
|
78
|
-
//
|
|
79
|
-
//
|
|
80
|
-
//
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
let cancelled = false;
|
|
84
|
-
import("@mdi/js")
|
|
85
|
-
.then((mdi) => {
|
|
86
|
-
if (cancelled) return;
|
|
87
|
-
const candidate = (mdi as Record<string, unknown>)[iconKey];
|
|
88
|
-
setPath(typeof candidate === "string" ? candidate : null);
|
|
89
|
-
})
|
|
90
|
-
.catch(() => setPath(null));
|
|
91
|
-
return () => {
|
|
92
|
-
cancelled = true;
|
|
93
|
-
};
|
|
94
|
-
}, [iconKey]);
|
|
78
|
+
// @mdi/js is already eager (statically imported across the shell), so this
|
|
79
|
+
// is a synchronous flat property lookup — no dynamic import, no loading
|
|
80
|
+
// state. See change: shrink-client-index-chunk.
|
|
81
|
+
const candidate = (mdi as Record<string, unknown>)[iconKey];
|
|
82
|
+
const path = typeof candidate === "string" ? candidate : null;
|
|
95
83
|
if (!path) return null;
|
|
96
84
|
return <Icon path={path} size={0.6} />;
|
|
97
85
|
}
|
package/src/Dialog.tsx
CHANGED
|
@@ -22,11 +22,25 @@ interface DialogProps {
|
|
|
22
22
|
testId?: string;
|
|
23
23
|
/** Used for aria-label when no `title` is given. */
|
|
24
24
|
ariaLabel?: string;
|
|
25
|
-
/** Edge-to-edge body: drop the inner padding
|
|
26
|
-
* self-framed child (e.g. a chat/detail view with
|
|
27
|
-
* the dialog as a single window
|
|
28
|
-
*
|
|
25
|
+
/** Edge-to-edge body: drop the inner padding, clip overflow, and establish a
|
|
26
|
+
* flex COLUMN context so a self-framed child (e.g. a chat/detail view with
|
|
27
|
+
* its own header) fills the dialog as a single window and manages its own
|
|
28
|
+
* scroll. The panel carries only a `max-h` cap and no definite height, so a
|
|
29
|
+
* flush child must size itself `flex-1 min-h-0` — an `h-full` child resolves
|
|
30
|
+
* against an indefinite parent, grows to content, and its own
|
|
31
|
+
* `overflow-y-auto` never becomes a scroller. The built-in ✕ is suppressed
|
|
32
|
+
* in this mode (see `showClose`). See change:
|
|
33
|
+
* improve-flow-graph-dialog-and-card-interaction,
|
|
34
|
+
* fix-flush-dialog-scroll-and-close-collision. */
|
|
29
35
|
flush?: boolean;
|
|
36
|
+
/** Restore the built-in ✕ under `flush`. For a flush child that renders no
|
|
37
|
+
* header (and therefore no dismissal affordance) of its own — notably a
|
|
38
|
+
* third-party plugin dialog. A flush child with NO focusable element of its
|
|
39
|
+
* own MUST set this, or the focus trap falls back to the container and
|
|
40
|
+
* keyboard users get no target and no visible exit. Ignored when `flush` is
|
|
41
|
+
* false (the ✕ always renders there). See change:
|
|
42
|
+
* fix-flush-dialog-scroll-and-close-collision. */
|
|
43
|
+
showClose?: boolean;
|
|
30
44
|
children: ReactNode;
|
|
31
45
|
}
|
|
32
46
|
|
|
@@ -56,6 +70,7 @@ export function Dialog({
|
|
|
56
70
|
testId,
|
|
57
71
|
ariaLabel,
|
|
58
72
|
flush = false,
|
|
73
|
+
showClose = false,
|
|
59
74
|
children,
|
|
60
75
|
}: DialogProps) {
|
|
61
76
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
@@ -71,10 +86,15 @@ export function Dialog({
|
|
|
71
86
|
if (!open) return null;
|
|
72
87
|
|
|
73
88
|
const hasHeader = Boolean(title || icon);
|
|
89
|
+
// A flush child is self-framed: it renders its own header and its own back
|
|
90
|
+
// affordance, and the panel reserves no corner for the ✕ (there is no header
|
|
91
|
+
// branch to apply `pr-8`). Rendering it anyway paints a duplicate dismissal
|
|
92
|
+
// control on top of whatever the child put there.
|
|
93
|
+
const renderClose = !flush || showClose;
|
|
74
94
|
|
|
75
95
|
return (
|
|
76
96
|
<DialogPortal>
|
|
77
|
-
<div className="fixed inset-0 z-
|
|
97
|
+
<div className="fixed inset-0 z-dialog flex items-center justify-center">
|
|
78
98
|
<div
|
|
79
99
|
className="absolute inset-0 bg-black/60"
|
|
80
100
|
onClick={onClose}
|
|
@@ -88,20 +108,23 @@ export function Dialog({
|
|
|
88
108
|
aria-label={!title ? ariaLabel : undefined}
|
|
89
109
|
tabIndex={-1}
|
|
90
110
|
data-testid={testId}
|
|
91
|
-
className={`relative w-full mx-4 ${SIZE_MAX_W[size]} ${SIZE_MAX_H[size]} ${flush ? "overflow-hidden" : "overflow-y-auto p-5 space-y-4"} bg-[var(--bg-primary)] border border-[var(--border-primary)] rounded-lg shadow-xl focus:outline-none`}
|
|
111
|
+
className={`relative w-full mx-4 ${SIZE_MAX_W[size]} ${SIZE_MAX_H[size]} ${flush ? "overflow-hidden flex flex-col min-h-0" : "overflow-y-auto p-5 space-y-4"} bg-[var(--bg-primary)] border border-[var(--border-primary)] rounded-lg shadow-xl focus:outline-none`}
|
|
92
112
|
>
|
|
93
|
-
{/* Standard close affordance on every dialog (Escape +
|
|
94
|
-
close). Absolutely positioned
|
|
95
|
-
`flush`
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
113
|
+
{/* Standard close affordance on every non-flush dialog (Escape +
|
|
114
|
+
backdrop also close). Absolutely positioned; the headered branch
|
|
115
|
+
reserves its corner with `pr-8`. Suppressed under `flush` unless
|
|
116
|
+
`showClose` opts it back in. */}
|
|
117
|
+
{renderClose && (
|
|
118
|
+
<button
|
|
119
|
+
type="button"
|
|
120
|
+
onClick={onClose}
|
|
121
|
+
aria-label="Close"
|
|
122
|
+
data-testid={testId ? `${testId}-close` : undefined}
|
|
123
|
+
className="absolute top-3 right-3 z-10 flex items-center justify-center w-7 h-7 rounded text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-surface)] transition-colors"
|
|
124
|
+
>
|
|
125
|
+
<Icon path={mdiClose} size={0.8} />
|
|
126
|
+
</button>
|
|
127
|
+
)}
|
|
105
128
|
{hasHeader && (
|
|
106
129
|
<div className="flex items-center gap-3 pr-8">
|
|
107
130
|
{icon && (
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createPortal } from "react-dom";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* LayerPortal — portals an overlay to the top-level layer root (`document.body`)
|
|
6
|
+
* so it escapes ALL ancestor stacking contexts (`transform`, `will-change`,
|
|
7
|
+
* `opacity < 1`, `isolation: isolate`, an ancestor's own `z-*`).
|
|
8
|
+
*
|
|
9
|
+
* This is the mechanism the `overlay-layering` spec calls "portal-or-perish":
|
|
10
|
+
* a numeric z-index only orders siblings WITHIN the nearest ancestor stacking
|
|
11
|
+
* context, so an inline `position:absolute` overlay is trapped and can UNDERLAP
|
|
12
|
+
* a sibling (e.g. a `SessionCard` — it sets `isolate`). Portaling removes the
|
|
13
|
+
* overlay from those contexts; the `z-*` layer token then orders it against the
|
|
14
|
+
* other portaled layers.
|
|
15
|
+
*
|
|
16
|
+
* Companion of `DialogPortal`, which does the same portal but ALSO locks body
|
|
17
|
+
* scroll (`overflow: hidden`) — correct for a full-screen modal, WRONG for a
|
|
18
|
+
* menu/popover/dropdown, which must not freeze the page behind it. Use
|
|
19
|
+
* `DialogPortal` for modals; use `LayerPortal` for everything else that escapes
|
|
20
|
+
* its box. The portaled surface positions itself (`position: fixed`) from its
|
|
21
|
+
* trigger's viewport rect and carries a `z-*` layer utility.
|
|
22
|
+
*
|
|
23
|
+
* See openspec spec overlay-layering. See change: add-overlay-layering-system.
|
|
24
|
+
*/
|
|
25
|
+
export function LayerPortal({ children }: { children: ReactNode }) {
|
|
26
|
+
return createPortal(children, document.body);
|
|
27
|
+
}
|
package/src/StatusPill.tsx
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import React, { useEffect, useState } from "react";
|
|
12
12
|
import Icon from "@mdi/react";
|
|
13
|
+
import * as mdi from "@mdi/js";
|
|
13
14
|
import type {
|
|
14
15
|
UiStatusPillProps,
|
|
15
16
|
UiStatusPillState,
|
|
@@ -64,20 +65,11 @@ export function StatusPill({ state, text, icon, tooltip }: UiStatusPillProps) {
|
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
function IconByKey({ iconKey }: { iconKey: string }) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (cancelled) return;
|
|
73
|
-
const candidate = (mdi as Record<string, unknown>)[iconKey];
|
|
74
|
-
setPath(typeof candidate === "string" ? candidate : null);
|
|
75
|
-
})
|
|
76
|
-
.catch(() => setPath(null));
|
|
77
|
-
return () => {
|
|
78
|
-
cancelled = true;
|
|
79
|
-
};
|
|
80
|
-
}, [iconKey]);
|
|
68
|
+
// @mdi/js is already eager (statically imported across the shell), so this
|
|
69
|
+
// is a synchronous flat property lookup — no dynamic import, no loading
|
|
70
|
+
// state. See change: shrink-client-index-chunk.
|
|
71
|
+
const candidate = (mdi as Record<string, unknown>)[iconKey];
|
|
72
|
+
const path = typeof candidate === "string" ? candidate : null;
|
|
81
73
|
if (!path) return null;
|
|
82
74
|
return <Icon path={path} size={0.55} />;
|
|
83
75
|
}
|
package/src/agent-card-utils.ts
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
* Shared utilities for agent card rendering.
|
|
3
3
|
* Used by FlowAgentCard (flows) and AgentToolRenderer (subagents).
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
import { mdiAlertCircle, mdiCheckCircle, mdiCircleOutline, mdiCloseCircle, mdiLoading, mdiMinusCircleOutline, mdiPause, mdiStop } from "@mdi/js";
|
|
6
7
|
import { Icon } from "@mdi/react";
|
|
7
|
-
import
|
|
8
|
+
import React, { type ReactNode } from "react";
|
|
8
9
|
|
|
9
10
|
/** Format a token count compactly: 500 → "500", 12000 → "12k" */
|
|
10
11
|
export function formatTokens(n: number): string {
|
|
@@ -18,7 +19,7 @@ export function formatDuration(ms: number): string {
|
|
|
18
19
|
return sec < 60 ? `${sec.toFixed(1)}s` : `${Math.floor(sec / 60)}m ${Math.floor(sec % 60)}s`;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
export type AgentCardStatus = "pending" | "running" | "complete" | "error" | "blocked" | "stopped" | "background";
|
|
22
|
+
export type AgentCardStatus = "pending" | "running" | "complete" | "error" | "blocked" | "stopped" | "background" | "elided";
|
|
22
23
|
|
|
23
24
|
export interface StatusIconDef {
|
|
24
25
|
icon: ReactNode;
|
|
@@ -34,6 +35,12 @@ export const statusIconDefs: Record<string, StatusIconDef> = {
|
|
|
34
35
|
blocked: { icon: React.createElement(Icon, { path: mdiAlertCircle, size: 0.55 }), color: "text-orange-400" },
|
|
35
36
|
stopped: { icon: React.createElement(Icon, { path: mdiStop, size: 0.55 }), color: "text-[var(--text-tertiary)]" },
|
|
36
37
|
background: { icon: React.createElement(Icon, { path: mdiPause, size: 0.55 }), color: "text-blue-400" },
|
|
38
|
+
/**
|
|
39
|
+
* Result is not loadable (a backfill segment orphaned this call). Terminal
|
|
40
|
+
* and neutral: static glyph, muted colour, never the running spinner and
|
|
41
|
+
* never error red. See change: fix-lazy-history-backfill-ux (D5).
|
|
42
|
+
*/
|
|
43
|
+
elided: { icon: React.createElement(Icon, { path: mdiMinusCircleOutline, size: 0.55 }), color: "text-[var(--text-muted)]" },
|
|
37
44
|
};
|
|
38
45
|
|
|
39
46
|
/** Get status icon + color, with fallback to pending */
|
package/src/useFocusTrap.ts
CHANGED
|
@@ -23,7 +23,22 @@ const FOCUSABLE_SELECTOR = [
|
|
|
23
23
|
function getFocusable(container: HTMLElement): HTMLElement[] {
|
|
24
24
|
return Array.from(
|
|
25
25
|
container.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR),
|
|
26
|
-
).filter((el) => !
|
|
26
|
+
).filter((el) => !isHiddenWithin(el, container));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* `hidden` / `aria-hidden` on an ANCESTOR hides the element just as effectively
|
|
31
|
+
* as on the element itself, so checking only the candidate's own attributes
|
|
32
|
+
* would let focus land inside a subtree assistive technology cannot see. Walk
|
|
33
|
+
* up to (and excluding) the container, which is where this dialog's world ends.
|
|
34
|
+
*/
|
|
35
|
+
function isHiddenWithin(el: HTMLElement, container: HTMLElement): boolean {
|
|
36
|
+
let node: HTMLElement | null = el;
|
|
37
|
+
while (node && node !== container) {
|
|
38
|
+
if (node.hasAttribute("hidden") || node.getAttribute("aria-hidden") === "true") return true;
|
|
39
|
+
node = node.parentElement;
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
27
42
|
}
|
|
28
43
|
|
|
29
44
|
export function useFocusTrap(
|
|
@@ -38,10 +53,48 @@ export function useFocusTrap(
|
|
|
38
53
|
const previouslyFocused = document.activeElement as HTMLElement | null;
|
|
39
54
|
|
|
40
55
|
const focusable = getFocusable(container);
|
|
56
|
+
// When a child renders NOTHING focusable on its first paint, the container
|
|
57
|
+
// fallback below fires and focus is stranded on a non-interactive box even
|
|
58
|
+
// though the surface fills with controls a tick later. That was masked while
|
|
59
|
+
// every dialog rendered a built-in ✕ (always focusable[0]); suppressing it
|
|
60
|
+
// for `flush` surfaces exposed it — measured on `/settings/general`, which
|
|
61
|
+
// reaches 51 focusables but has 0 at mount. Watch for the first one and
|
|
62
|
+
// hand focus over, at most once, and only while focus is still parked on
|
|
63
|
+
// the container (never steal it back from the user).
|
|
64
|
+
// See change: fix-flush-dialog-scroll-and-close-collision.
|
|
65
|
+
let observer: MutationObserver | undefined;
|
|
41
66
|
if (focusable.length > 0) {
|
|
42
67
|
focusable[0].focus();
|
|
43
68
|
} else {
|
|
44
69
|
container.focus();
|
|
70
|
+
if (typeof MutationObserver !== "undefined") {
|
|
71
|
+
observer = new MutationObserver(() => {
|
|
72
|
+
if (document.activeElement !== container) {
|
|
73
|
+
observer?.disconnect();
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const late = getFocusable(container);
|
|
77
|
+
if (late.length === 0) return;
|
|
78
|
+
observer?.disconnect();
|
|
79
|
+
late[0].focus();
|
|
80
|
+
});
|
|
81
|
+
// Attributes matter as much as insertion: `getFocusable` keys on
|
|
82
|
+
// `:not([disabled])`, `[hidden]` and `aria-hidden`, so a button that is
|
|
83
|
+
// rendered DISABLED at mount and enables when data lands is a focusable
|
|
84
|
+
// that appears without any node being inserted (`href` likewise, for
|
|
85
|
+
// an anchor that gains one). Watching childList alone would strand
|
|
86
|
+
// focus in exactly that case.
|
|
87
|
+
//
|
|
88
|
+
// Cost is bounded by construction: the observer only exists for a
|
|
89
|
+
// dialog that opened with ZERO focusables, and it disconnects on the
|
|
90
|
+
// first one it finds (or the moment focus leaves the container).
|
|
91
|
+
observer.observe(container, {
|
|
92
|
+
childList: true,
|
|
93
|
+
subtree: true,
|
|
94
|
+
attributes: true,
|
|
95
|
+
attributeFilter: ["disabled", "hidden", "aria-hidden", "tabindex", "href"],
|
|
96
|
+
});
|
|
97
|
+
}
|
|
45
98
|
}
|
|
46
99
|
|
|
47
100
|
function onKeyDown(e: KeyboardEvent) {
|
|
@@ -73,6 +126,7 @@ export function useFocusTrap(
|
|
|
73
126
|
document.addEventListener("keydown", onKeyDown, true);
|
|
74
127
|
|
|
75
128
|
return () => {
|
|
129
|
+
observer?.disconnect();
|
|
76
130
|
document.removeEventListener("keydown", onKeyDown, true);
|
|
77
131
|
if (previouslyFocused && document.contains(previouslyFocused)) {
|
|
78
132
|
previouslyFocused.focus();
|
package/src/AGENTS.md
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# DOX — packages/client-utils/src
|
|
2
|
-
|
|
3
|
-
Files in this directory. One row per source file.
|
|
4
|
-
|
|
5
|
-
| File | Purpose |
|
|
6
|
-
|------|---------|
|
|
7
|
-
| `ActionList.tsx` | `ui:action-list` primitive. Exports `ActionList({ actions })` — horizontal row of MDI-icon + label buttons. `ExtendedActionItem` carries `dataAction` (pluginId/sessionId/action/payload) dispatched via `sendPluginAction`, or classical `onClick`. `IconByKey` lazy-imports `@mdi/js` and looks up path by export-name key. |
|
|
8
|
-
| `agent-card-utils.ts` | Shared helpers for agent card rendering. Exports `formatTokens`, `formatDuration`, `AgentCardStatus` type, `StatusIconDef`, `statusIconDefs` (pending/running/complete/error/blocked/stopped/background → MDI icon + color), `getStatusIcon`. Used by `FlowAgentCard` and `AgentToolRenderer`. |
|
|
9
|
-
| `AgentCardShell.tsx` | Exports `AgentCardShell` — reusable card container with status-colored border, header row (status icon + name + optional `headerRight`), optional `stats` line, clickable/selected states. `getStatusIcon` drives icon + border color. Consumers pass tool-specific content as children. |
|
|
10
|
-
| `Confirm.tsx` | Confirm preset over Dialog (size sm). Props `{open,onClose,title,message,body?,intent?,confirmLabel?,cancelLabel?,onConfirm,testId?}`. Action → onConfirm only (no auto-close); cancel/Esc/overlay → onClose. Replaces legacy ConfirmDialog. See change: unify-dialog-system. |
|
|
11
|
-
| `Dialog.tsx` | Unified modal shell. Props `{open,onClose,title?,icon?,size?,testId?,ariaLabel?,children}`. Owns DialogPortal, overlay `bg-black/60`, Esc via shared escape-stack (`useEscapeDismiss(open,onClose)` — onClose fires on Escape only when topmost registered layer; overlay opened above consumes it first), click-outside, focus trap (useFocusTrap), `role="dialog"`/`aria-modal`/`aria-labelledby`, `z-[60]`, size sm/md/lg → max-w-sm/md/lg, `max-h-[80vh]`. Renders standard ✕ close button (absolute top-right, testId `<testId>-close`) on every dialog incl. flush/headerless. Static subcomponents `Dialog.Footer`/`Dialog.Cancel`/`Dialog.Action` (intent primary\|danger\|neutral). See change: unify-dialog-system. |
|
|
12
|
-
| `DialogPortal.tsx` | Exports `DialogPortal` — `createPortal` to `document.body`. Hides body scroll (`overflow: hidden`) on mount, restores prior value on unmount. |
|
|
13
|
-
| `EmptyState.tsx` | EmptyState primitive. Props `{title, body?, icon?, action?, secondaryAction?}`. Single `action` prop enforces one-primary-CTA. Renders NN/g empty-state pattern: value-framed heading, optional body, ≤1 primary CTA, ≤1 secondary escape-hatch. data-empty-state markers. See change: extend-client-utils-state-feedback-primitives. |
|
|
14
|
-
| `escape-stack.ts` | Shared escape-dismiss stack. Single module-stable `document`-bubble `keydown` listener + LIFO registry; Escape invokes `onEscape` of topmost registered layer only, then `preventDefault`+`stopImmediatePropagation`; guards `e.repeat`+`e.defaultPrevented`. Attach-once/never-detach (early-returns on empty). Exports `useEscapeDismiss(active,onEscape)` (`useId`-stable id, ref-backed onEscape, remove-by-id), `registerEscapeLayer`/`unregisterEscapeLayer`, `__resetEscapeStack` (test-only, prod no-op). See change: fix-stacked-escape-closes-layers. |
|
|
15
|
-
| `focusRing.ts` | Exports `focusRing` = "focus-ring" className string. Points at `.focus-ring` utility in packages/client/src/index.css (:focus-visible, 2px outline, 2px offset, var(--focus-ring) color). Replaces ad-hoc focus:outline-none + 1px border. WCAG 2.2 §2.4.7/§2.4.11. See change: extend-client-utils-state-feedback-primitives. |
|
|
16
|
-
| `Popover.tsx` | `ui:popover` primitive. Exports `Popover`, `PopoverProps`, `computePopoverPosition` (pure). Anchors floating panel to `anchorEl`'s rect; flips above on bottom overflow, shifts left on right overflow; recomputes on resize/scroll. Dismisses on outside mousedown or Escape. Body portal, not modal/scroll-lock/tooltip. |
|
|
17
|
-
| `SearchableSelectDialog.tsx` | Exports `SearchableSelectDialog`, `SelectOption`. Filterable list inside `Dialog` (size `sm`). Arrow/Enter/Esc keyboard nav, scrolls selected into view, optional badge. Used for single-select choices. |
|
|
18
|
-
| `Skeleton.tsx` | Skeleton primitive for content-layout loads. Props `{variant=text\|card\|bubble\|row, count?}`. Honors prefers-reduced-motion via useMediaQuery (static, no animate-pulse). aria-hidden. data-skeleton / data-skeleton-item / data-static markers. See change: extend-client-utils-state-feedback-primitives. |
|
|
19
|
-
| `StatusPill.tsx` | `ui:status-pill` primitive. Exports `StatusPill({ state, text, icon?, tooltip? })` — state-tinted pill. `STATE_STYLE_DARK`/`STATE_STYLE_LIGHT` palettes keyed by `UiStatusPillState` (running/success/info/warn/error/muted). `useIsLightTheme` observes `data-theme` attr. `IconByKey` lazy-imports `@mdi/js`. |
|
|
20
|
-
| `statusPresentation.ts` | `statusPresentation(kind)` maps StatusKind (done\|current\|todo\|error) to `{glyph, tokenVar, label}`. Glyph = mandatory non-hue channel (✓ done, ▸ current, ○ todo, ✕ error). tokenVar references semantic --status-* / --text-muted token. `statusAriaLabel(name, kind)` returns "Name, label". WCAG 2.2 §1.4.1. Consumed by composer ArtifactChip + board BoardStatePill. See change: extend-client-utils-state-feedback-primitives. |
|
|
21
|
-
| `useFocusTrap.ts` | `useFocusTrap(ref,open)` hook. Stores prev activeElement, focuses first focusable child on open, traps Tab/Shift+Tab, restores focus on close. See change: unify-dialog-system. |
|
|
22
|
-
| `useMediaQuery.ts` | Reactive CSS media-query hook. Returns match boolean. Guards missing window.matchMedia (returns false). See change: extend-client-utils-state-feedback-primitives. |
|
|
23
|
-
| `useMobile.tsx` | Exports `MobileProvider` + `useMobile`. `MobileContext` provides boolean: viewport `max-width: 767px` OR `max-height: 599px` (catches landscape phones). Backed by `useMediaQuery`. |
|
|
24
|
-
| `useZoomPan.ts` | Exports `useZoomPan`, `ZoomPanState`, `UseZoomPanOptions`. State `{ scale, translateX, translateY }`. Wheel zoom centered on cursor, pointer drag pan (deferred capture past `DRAG_THRESHOLD` so clicks reach children), pinch zoom, double-click reset, `zoomIn`/`zoomOut`/`reset` controls. Clamp `minScale`/`maxScale`. Used by `MermaidBlock`, `FlowGraph`. |
|
|
25
|
-
| `ZoomControls.tsx` | Exports `ZoomControls({ onZoomIn, onZoomOut, onReset, scale })` — top-right overlay buttons (zoom in/out/reset) using MDI icons, percent readout when `scale !== 1`. Shared by `MermaidBlock` and `FlowGraph`. Stops pointer propagation. |
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { describe, it, expect, vi, afterEach } from "vitest";
|
|
3
|
-
import { render, fireEvent, cleanup } from "@testing-library/react";
|
|
4
|
-
import { ActionList } from "../ActionList.js";
|
|
5
|
-
|
|
6
|
-
afterEach(() => cleanup());
|
|
7
|
-
|
|
8
|
-
describe("ActionList", () => {
|
|
9
|
-
it("renders nothing for empty actions", () => {
|
|
10
|
-
const { container } = render(<ActionList actions={[]} />);
|
|
11
|
-
expect(container.firstChild).toBeNull();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it("renders each action as a button", () => {
|
|
15
|
-
const { getAllByRole } = render(
|
|
16
|
-
<ActionList
|
|
17
|
-
actions={[
|
|
18
|
-
{ label: "Run A" },
|
|
19
|
-
{ label: "Run B" },
|
|
20
|
-
]}
|
|
21
|
-
/>,
|
|
22
|
-
);
|
|
23
|
-
const buttons = getAllByRole("button");
|
|
24
|
-
expect(buttons).toHaveLength(2);
|
|
25
|
-
expect(buttons[0].textContent).toContain("Run A");
|
|
26
|
-
expect(buttons[1].textContent).toContain("Run B");
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("clicking calls onClick", () => {
|
|
30
|
-
const onClick = vi.fn();
|
|
31
|
-
const { getByRole } = render(
|
|
32
|
-
<ActionList actions={[{ label: "Run", onClick }]} />,
|
|
33
|
-
);
|
|
34
|
-
fireEvent.click(getByRole("button"));
|
|
35
|
-
expect(onClick).toHaveBeenCalledTimes(1);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("disabled buttons do not trigger onClick", () => {
|
|
39
|
-
const onClick = vi.fn();
|
|
40
|
-
const { getByRole } = render(
|
|
41
|
-
<ActionList actions={[{ label: "Run", onClick, disabled: true }]} />,
|
|
42
|
-
);
|
|
43
|
-
fireEvent.click(getByRole("button"));
|
|
44
|
-
expect(onClick).not.toHaveBeenCalled();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("tooltip is set from `tooltip` prop", () => {
|
|
48
|
-
const { getByRole } = render(
|
|
49
|
-
<ActionList actions={[{ label: "Run", tooltip: "Run flow X" }]} />,
|
|
50
|
-
);
|
|
51
|
-
expect(getByRole("button").getAttribute("title")).toBe("Run flow X");
|
|
52
|
-
});
|
|
53
|
-
});
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, afterEach, vi } from "vitest";
|
|
2
|
-
import { render, cleanup, fireEvent } from "@testing-library/react";
|
|
3
|
-
import React from "react";
|
|
4
|
-
import { Confirm } from "../Confirm.js";
|
|
5
|
-
|
|
6
|
-
afterEach(() => cleanup());
|
|
7
|
-
|
|
8
|
-
describe("Confirm", () => {
|
|
9
|
-
it("renders title and message", () => {
|
|
10
|
-
const { getByText, baseElement } = render(
|
|
11
|
-
<Confirm
|
|
12
|
-
open
|
|
13
|
-
onClose={() => {}}
|
|
14
|
-
onConfirm={() => {}}
|
|
15
|
-
title="Forget workspace?"
|
|
16
|
-
message="This cannot be undone."
|
|
17
|
-
testId="c"
|
|
18
|
-
/>,
|
|
19
|
-
);
|
|
20
|
-
expect(getByText("Forget workspace?")).toBeTruthy();
|
|
21
|
-
expect(getByText("This cannot be undone.")).toBeTruthy();
|
|
22
|
-
const container = baseElement.querySelector("[data-testid='c']")!;
|
|
23
|
-
expect(container.getAttribute("aria-labelledby")).toBeTruthy();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("renders optional body node", () => {
|
|
27
|
-
const { getByTestId } = render(
|
|
28
|
-
<Confirm
|
|
29
|
-
open
|
|
30
|
-
onClose={() => {}}
|
|
31
|
-
onConfirm={() => {}}
|
|
32
|
-
title="t"
|
|
33
|
-
message="m"
|
|
34
|
-
body={<ul data-testid="files" />}
|
|
35
|
-
/>,
|
|
36
|
-
);
|
|
37
|
-
expect(getByTestId("files")).toBeTruthy();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it("uses default labels", () => {
|
|
41
|
-
const { getByText } = render(
|
|
42
|
-
<Confirm open onClose={() => {}} onConfirm={() => {}} title="t" message="m" />,
|
|
43
|
-
);
|
|
44
|
-
expect(getByText("Confirm")).toBeTruthy();
|
|
45
|
-
expect(getByText("Cancel")).toBeTruthy();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("uses custom labels", () => {
|
|
49
|
-
const { getByText } = render(
|
|
50
|
-
<Confirm
|
|
51
|
-
open
|
|
52
|
-
onClose={() => {}}
|
|
53
|
-
onConfirm={() => {}}
|
|
54
|
-
title="t"
|
|
55
|
-
message="m"
|
|
56
|
-
confirmLabel="Forget"
|
|
57
|
-
cancelLabel="Keep"
|
|
58
|
-
/>,
|
|
59
|
-
);
|
|
60
|
-
expect(getByText("Forget")).toBeTruthy();
|
|
61
|
-
expect(getByText("Keep")).toBeTruthy();
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it("maps danger intent to action button class", () => {
|
|
65
|
-
const { baseElement } = render(
|
|
66
|
-
<Confirm
|
|
67
|
-
open
|
|
68
|
-
onClose={() => {}}
|
|
69
|
-
onConfirm={() => {}}
|
|
70
|
-
title="t"
|
|
71
|
-
message="m"
|
|
72
|
-
intent="danger"
|
|
73
|
-
testId="c"
|
|
74
|
-
/>,
|
|
75
|
-
);
|
|
76
|
-
expect(
|
|
77
|
-
baseElement.querySelector("[data-testid='c-action']")!.className,
|
|
78
|
-
).toContain("bg-red-600");
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it("action calls onConfirm only; cancel/Esc call onClose only", () => {
|
|
82
|
-
const onConfirm = vi.fn();
|
|
83
|
-
const onClose = vi.fn();
|
|
84
|
-
const { baseElement } = render(
|
|
85
|
-
<Confirm
|
|
86
|
-
open
|
|
87
|
-
onClose={onClose}
|
|
88
|
-
onConfirm={onConfirm}
|
|
89
|
-
title="t"
|
|
90
|
-
message="m"
|
|
91
|
-
testId="c"
|
|
92
|
-
/>,
|
|
93
|
-
);
|
|
94
|
-
fireEvent.click(baseElement.querySelector("[data-testid='c-action']")!);
|
|
95
|
-
expect(onConfirm).toHaveBeenCalledTimes(1);
|
|
96
|
-
expect(onClose).not.toHaveBeenCalled();
|
|
97
|
-
|
|
98
|
-
fireEvent.click(baseElement.querySelector("[data-testid='c-cancel']")!);
|
|
99
|
-
expect(onClose).toHaveBeenCalledTimes(1);
|
|
100
|
-
|
|
101
|
-
fireEvent.keyDown(document, { key: "Escape" });
|
|
102
|
-
expect(onClose).toHaveBeenCalledTimes(2);
|
|
103
|
-
expect(onConfirm).toHaveBeenCalledTimes(1);
|
|
104
|
-
});
|
|
105
|
-
});
|