@blackbelt-technology/pi-dashboard-client-utils 0.7.0 → 0.9.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 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.7.0",
3
+ "version": "0.9.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,10 +25,34 @@
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"
31
35
  },
36
+ "./identity/pkce": {
37
+ "types": "./src/identity/pkce.ts",
38
+ "default": "./src/identity/pkce.ts"
39
+ },
40
+ "./identity/token-store": {
41
+ "types": "./src/identity/token-store.ts",
42
+ "default": "./src/identity/token-store.ts"
43
+ },
44
+ "./identity/oidc-flow": {
45
+ "types": "./src/identity/oidc-flow.ts",
46
+ "default": "./src/identity/oidc-flow.ts"
47
+ },
48
+ "./identity/login-flow": {
49
+ "types": "./src/identity/login-flow.ts",
50
+ "default": "./src/identity/login-flow.ts"
51
+ },
52
+ "./identity/dpop": {
53
+ "types": "./src/identity/dpop.ts",
54
+ "default": "./src/identity/dpop.ts"
55
+ },
32
56
  "./Popover": {
33
57
  "types": "./src/Popover.tsx",
34
58
  "default": "./src/Popover.tsx"
@@ -85,6 +109,10 @@
85
109
  "types": "./src/ActionList.tsx",
86
110
  "default": "./src/ActionList.tsx"
87
111
  },
112
+ "./mdi-by-key": {
113
+ "types": "./src/mdi-by-key.ts",
114
+ "default": "./src/mdi-by-key.ts"
115
+ },
88
116
  "./StatusPill": {
89
117
  "types": "./src/StatusPill.tsx",
90
118
  "default": "./src/StatusPill.tsx"
@@ -111,15 +139,20 @@
111
139
  }
112
140
  },
113
141
  "files": [
114
- "src/"
142
+ "src/",
143
+ "!**/AGENTS.md",
144
+ "!**/*.AGENTS.md",
145
+ "!**/__tests__",
146
+ "!**/*.test.ts",
147
+ "!**/*.test.tsx"
115
148
  ],
116
149
  "peerDependencies": {
117
150
  "react": ">=18.0.0",
118
151
  "react-dom": ">=18.0.0"
119
152
  },
120
153
  "dependencies": {
121
- "@blackbelt-technology/dashboard-plugin-runtime": "^0.7.0",
122
- "@blackbelt-technology/pi-dashboard-shared": "^0.7.0",
154
+ "@blackbelt-technology/dashboard-plugin-runtime": "^0.9.0",
155
+ "@blackbelt-technology/pi-dashboard-shared": "^0.9.0",
123
156
  "@mdi/js": "^7.4.47",
124
157
  "@mdi/react": "^1.6.1"
125
158
  },
@@ -7,11 +7,12 @@
7
7
  *
8
8
  * See change: adopt-server-driven-intent-rendering.
9
9
  */
10
- import Icon from "@mdi/react";
11
- import * as mdi from "@mdi/js";
12
- // We accept icon as a string key (MDI), look up via resolveMdiIcon at render time.
13
- import type { UiActionListProps } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
10
+
14
11
  import { sendPluginAction } from "@blackbelt-technology/dashboard-plugin-runtime";
12
+ // Icon is an MDI key string, resolved lazily via useMdiIconByKey.
13
+ import type { UiActionListProps } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
14
+ import Icon from "@mdi/react";
15
+ import { useMdiIconByKey } from "./mdi-by-key.js";
15
16
 
16
17
  /**
17
18
  * Extended item shape: in addition to `onClick`, items may carry a
@@ -70,16 +71,12 @@ export function ActionList({ actions }: UiActionListProps) {
70
71
  }
71
72
 
72
73
  /**
73
- * Render an MDI icon by its export-name key. Best-effort — unknown keys
74
- * render nothing. The shell ships @mdi/js so this is a flat property
75
- * lookup.
74
+ * Render an MDI icon by its export-name key. Renders nothing while the full
75
+ * icon set loads and for unknown keys. See change:
76
+ * harden-ios-safari-memory-and-ws-diagnostics.
76
77
  */
77
78
  function IconByKey({ iconKey }: { iconKey: string }) {
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;
79
+ const path = useMdiIconByKey(iconKey);
83
80
  if (!path) return null;
84
81
  return <Icon path={path} size={0.6} />;
85
82
  }
package/src/Dialog.tsx CHANGED
@@ -1,12 +1,15 @@
1
+ import { mdiClose } from "@mdi/js";
2
+ import { Icon } from "@mdi/react";
1
3
  import React, {
4
+ type ReactNode,
5
+ useCallback,
2
6
  useId,
3
7
  useRef,
4
- type ReactNode,
8
+ useState,
5
9
  } from "react";
6
- import { mdiClose } from "@mdi/js";
7
- import { Icon } from "@mdi/react";
8
10
  import { DialogPortal } from "./DialogPortal.js";
9
11
  import { useEscapeDismiss } from "./escape-stack.js";
12
+ import { LayerHostProvider } from "./LayerPortal.js";
10
13
  import { useFocusTrap } from "./useFocusTrap.js";
11
14
 
12
15
  export type DialogSize = "sm" | "md" | "lg" | "full";
@@ -22,11 +25,25 @@ interface DialogProps {
22
25
  testId?: string;
23
26
  /** Used for aria-label when no `title` is given. */
24
27
  ariaLabel?: string;
25
- /** Edge-to-edge body: drop the inner padding + clip overflow so a
26
- * self-framed child (e.g. a chat/detail view with its own header) fills
27
- * the dialog as a single window. See change:
28
- * improve-flow-graph-dialog-and-card-interaction. */
28
+ /** Edge-to-edge body: drop the inner padding, clip overflow, and establish a
29
+ * flex COLUMN context so a self-framed child (e.g. a chat/detail view with
30
+ * its own header) fills the dialog as a single window and manages its own
31
+ * scroll. The panel carries only a `max-h` cap and no definite height, so a
32
+ * flush child must size itself `flex-1 min-h-0` — an `h-full` child resolves
33
+ * against an indefinite parent, grows to content, and its own
34
+ * `overflow-y-auto` never becomes a scroller. The built-in ✕ is suppressed
35
+ * in this mode (see `showClose`). See change:
36
+ * improve-flow-graph-dialog-and-card-interaction,
37
+ * fix-flush-dialog-scroll-and-close-collision. */
29
38
  flush?: boolean;
39
+ /** Restore the built-in ✕ under `flush`. For a flush child that renders no
40
+ * header (and therefore no dismissal affordance) of its own — notably a
41
+ * third-party plugin dialog. A flush child with NO focusable element of its
42
+ * own MUST set this, or the focus trap falls back to the container and
43
+ * keyboard users get no target and no visible exit. Ignored when `flush` is
44
+ * false (the ✕ always renders there). See change:
45
+ * fix-flush-dialog-scroll-and-close-collision. */
46
+ showClose?: boolean;
30
47
  children: ReactNode;
31
48
  }
32
49
 
@@ -56,10 +73,21 @@ export function Dialog({
56
73
  testId,
57
74
  ariaLabel,
58
75
  flush = false,
76
+ showClose = false,
59
77
  children,
60
78
  }: DialogProps) {
61
79
  const containerRef = useRef<HTMLDivElement>(null);
62
80
  const titleId = useId();
81
+ // The panel doubles as the layer host for any `LayerPortal` overlay a child
82
+ // opens (e.g. the run-config ModelSelector): portaling to `document.body`
83
+ // would land it at `z-popover`, BELOW this dialog's `z-dialog` backdrop. State
84
+ // (not just the ref) so children re-render once the element exists.
85
+ // See change: fix-composer-popover-layering.
86
+ const [panelEl, setPanelEl] = useState<HTMLDivElement | null>(null);
87
+ const setPanel = useCallback((el: HTMLDivElement | null) => {
88
+ containerRef.current = el;
89
+ setPanelEl(el);
90
+ }, []);
63
91
 
64
92
  useFocusTrap(containerRef, open);
65
93
 
@@ -71,37 +99,45 @@ export function Dialog({
71
99
  if (!open) return null;
72
100
 
73
101
  const hasHeader = Boolean(title || icon);
102
+ // A flush child is self-framed: it renders its own header and its own back
103
+ // affordance, and the panel reserves no corner for the ✕ (there is no header
104
+ // branch to apply `pr-8`). Rendering it anyway paints a duplicate dismissal
105
+ // control on top of whatever the child put there.
106
+ const renderClose = !flush || showClose;
74
107
 
75
108
  return (
76
109
  <DialogPortal>
77
- <div className="fixed inset-0 z-[60] flex items-center justify-center">
110
+ <div className="fixed inset-0 z-dialog flex items-center justify-center">
78
111
  <div
79
112
  className="absolute inset-0 bg-black/60"
80
113
  onClick={onClose}
81
114
  data-testid={testId ? `${testId}-overlay` : undefined}
82
115
  />
83
116
  <div
84
- ref={containerRef}
117
+ ref={setPanel}
85
118
  role="dialog"
86
119
  aria-modal="true"
87
120
  aria-labelledby={title ? titleId : undefined}
88
121
  aria-label={!title ? ariaLabel : undefined}
89
122
  tabIndex={-1}
90
123
  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`}
124
+ 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
125
  >
93
- {/* Standard close affordance on every dialog (Escape + backdrop also
94
- close). Absolutely positioned so it works for both headered and
95
- `flush` (headerless) dialogs. */}
96
- <button
97
- type="button"
98
- onClick={onClose}
99
- aria-label="Close"
100
- data-testid={testId ? `${testId}-close` : undefined}
101
- 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"
102
- >
103
- <Icon path={mdiClose} size={0.8} />
104
- </button>
126
+ {/* Standard close affordance on every non-flush dialog (Escape +
127
+ backdrop also close). Absolutely positioned; the headered branch
128
+ reserves its corner with `pr-8`. Suppressed under `flush` unless
129
+ `showClose` opts it back in. */}
130
+ {renderClose && (
131
+ <button
132
+ type="button"
133
+ onClick={onClose}
134
+ aria-label="Close"
135
+ data-testid={testId ? `${testId}-close` : undefined}
136
+ 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"
137
+ >
138
+ <Icon path={mdiClose} size={0.8} />
139
+ </button>
140
+ )}
105
141
  {hasHeader && (
106
142
  <div className="flex items-center gap-3 pr-8">
107
143
  {icon && (
@@ -119,7 +155,7 @@ export function Dialog({
119
155
  )}
120
156
  </div>
121
157
  )}
122
- {children}
158
+ <LayerHostProvider host={panelEl}>{children}</LayerHostProvider>
123
159
  </div>
124
160
  </div>
125
161
  </DialogPortal>
@@ -0,0 +1,61 @@
1
+ import { createContext, type ReactNode, useContext } from "react";
2
+ import { createPortal } from "react-dom";
3
+
4
+ /**
5
+ * The nearest layer host a `LayerPortal` should portal INTO, overriding the
6
+ * default `document.body`.
7
+ *
8
+ * `body` is the right host only while nothing higher on the layer scale wraps
9
+ * the overlay. Inside a `Dialog` it is wrong: the dialog paints at `z-dialog`
10
+ * with a full-viewport backdrop, so a popover portaled to `body` becomes its
11
+ * SIBLING at the lower `z-popover` — it sinks behind the backdrop and every
12
+ * click on it dismisses the dialog instead. Portaling into the dialog panel
13
+ * keeps the popover inside the dialog's stacking context (so it rides the
14
+ * dialog's rank against the rest of the scale) and inside its focus trap, while
15
+ * still escaping the ancestor stacking contexts INSIDE the dialog.
16
+ *
17
+ * `null` (the default, and the value while a host element is still mounting)
18
+ * means `document.body` — the composer/card case, which must keep escaping all
19
+ * the way out.
20
+ *
21
+ * See change: fix-composer-popover-layering.
22
+ */
23
+ export const LayerHostContext = createContext<HTMLElement | null>(null);
24
+
25
+ export function LayerHostProvider({
26
+ host,
27
+ children,
28
+ }: {
29
+ host: HTMLElement | null;
30
+ children: ReactNode;
31
+ }) {
32
+ return <LayerHostContext.Provider value={host}>{children}</LayerHostContext.Provider>;
33
+ }
34
+
35
+ /**
36
+ * LayerPortal — portals an overlay to the nearest layer host, defaulting to the
37
+ * top-level layer root (`document.body`), so it escapes ALL ancestor stacking
38
+ * contexts (`transform`, `will-change`, `opacity < 1`, `isolation: isolate`, an
39
+ * ancestor's own `z-*`).
40
+ *
41
+ * This is the mechanism the `overlay-layering` spec calls "portal-or-perish":
42
+ * a numeric z-index only orders siblings WITHIN the nearest ancestor stacking
43
+ * context, so an inline `position:absolute` overlay is trapped and can UNDERLAP
44
+ * a sibling (e.g. a `SessionCard` — it sets `isolate`). Portaling removes the
45
+ * overlay from those contexts; the `z-*` layer token then orders it against the
46
+ * other portaled layers.
47
+ *
48
+ * Companion of `DialogPortal`, which does the same portal but ALSO locks body
49
+ * scroll (`overflow: hidden`) — correct for a full-screen modal, WRONG for a
50
+ * menu/popover/dropdown, which must not freeze the page behind it. Use
51
+ * `DialogPortal` for modals; use `LayerPortal` for everything else that escapes
52
+ * its box. The portaled surface positions itself (`position: fixed`) from its
53
+ * trigger's viewport rect and carries a `z-*` layer utility.
54
+ *
55
+ * See openspec spec overlay-layering. See change: add-overlay-layering-system,
56
+ * fix-composer-popover-layering.
57
+ */
58
+ export function LayerPortal({ children }: { children: ReactNode }) {
59
+ const host = useContext(LayerHostContext);
60
+ return createPortal(children, host ?? document.body);
61
+ }
@@ -7,6 +7,26 @@ export interface SelectOption {
7
7
  description?: string;
8
8
  badge?: string;
9
9
  badgeColor?: string;
10
+ /**
11
+ * Group caption this option renders under. Options sharing a group render
12
+ * beneath one caption, in first-appearance order; ungrouped options keep
13
+ * the flat list. Inert unless set.
14
+ */
15
+ group?: string;
16
+ /**
17
+ * Rendered visible but non-selectable (e.g. a picker entry whose selection
18
+ * would overwrite a conflicting credential). Arrow navigation skips it and
19
+ * Enter is a no-op. Inert unless set.
20
+ */
21
+ disabled?: boolean;
22
+ /** Tooltip for a disabled option — names the way out (e.g. remove-first). */
23
+ disabledReason?: string;
24
+ /**
25
+ * Always rendered, even when the search filter does not match — for a
26
+ * pinned entry (e.g. "Custom endpoint…") that must stay reachable under any
27
+ * search term. Inert unless set.
28
+ */
29
+ pinned?: boolean;
10
30
  }
11
31
 
12
32
  interface Props {
@@ -38,37 +58,59 @@ export function SearchableSelectDialog({
38
58
  const filtered = useMemo(() => {
39
59
  if (!query.trim()) return options;
40
60
  const q = query.toLowerCase();
61
+ // `value` is the id — the picker contract matches on display name AND id.
62
+ // Pinned options stay reachable under any search term.
41
63
  return options.filter(
42
- (o) => o.label.toLowerCase().includes(q) || o.description?.toLowerCase().includes(q),
64
+ (o) =>
65
+ o.pinned ||
66
+ o.label.toLowerCase().includes(q) ||
67
+ o.description?.toLowerCase().includes(q) ||
68
+ o.value.toLowerCase().includes(q),
43
69
  );
44
70
  }, [options, query]);
45
71
 
46
72
  // Reset selection when filter changes
47
73
  useEffect(() => {
48
74
  setSelectedIndex(0);
49
- }, [filtered.length]);
75
+ }, [filtered.length, query]);
50
76
 
51
- // Scroll selected item into view
77
+ // Scroll selected item into view. A group caption renders as its own child
78
+ // before its options, so children indices no longer map to option indices —
79
+ // target the selected row by attribute instead.
52
80
  useEffect(() => {
53
- const el = listRef.current?.children[selectedIndex] as HTMLElement | undefined;
81
+ const el = listRef.current?.querySelector('[data-active="true"]') as HTMLElement | undefined;
54
82
  el?.scrollIntoView?.({ block: "nearest" });
55
83
  }, [selectedIndex]);
56
84
 
85
+ const moveSelection = (dir: 1 | -1) => {
86
+ setSelectedIndex((i) => {
87
+ let next = i;
88
+ // Arrow navigation skips disabled options so Enter never lands on one.
89
+ do {
90
+ next += dir;
91
+ } while (next > 0 && next < filtered.length - 1 && filtered[next]?.disabled);
92
+ return Math.max(0, Math.min(next, filtered.length - 1));
93
+ });
94
+ };
95
+
57
96
  const handleKeyDown = (e: React.KeyboardEvent) => {
58
97
  if (e.key === "ArrowDown") {
59
98
  e.preventDefault();
60
- setSelectedIndex((i) => Math.min(i + 1, filtered.length - 1));
99
+ moveSelection(1);
61
100
  } else if (e.key === "ArrowUp") {
62
101
  e.preventDefault();
63
- setSelectedIndex((i) => Math.max(i - 1, 0));
102
+ moveSelection(-1);
64
103
  } else if (e.key === "Enter") {
65
104
  e.preventDefault();
66
- if (filtered[selectedIndex]) {
67
- onSelect(filtered[selectedIndex].value);
105
+ const opt = filtered[selectedIndex];
106
+ if (opt && !opt.disabled) {
107
+ onSelect(opt.value);
68
108
  }
69
109
  }
70
110
  };
71
111
 
112
+ let lastGroup: string | undefined;
113
+
72
114
  return (
73
115
  <Dialog open onClose={onCancel} title={title} size="sm">
74
116
  {/* Search */}
@@ -89,30 +131,51 @@ export function SearchableSelectDialog({
89
131
  {filtered.length === 0 ? (
90
132
  <div className="px-3 py-4 text-xs text-[var(--text-muted)] text-center">{emptyMessage}</div>
91
133
  ) : (
92
- filtered.map((opt, i) => (
93
- <div
94
- key={opt.value}
95
- onClick={() => onSelect(opt.value)}
96
- onMouseEnter={() => setSelectedIndex(i)}
97
- className={`px-3 py-1.5 rounded-lg cursor-pointer flex items-center gap-2 ${
98
- i === selectedIndex
99
- ? "bg-blue-500/15 text-[var(--text-primary)]"
100
- : "text-[var(--text-secondary)] hover:bg-[var(--bg-tertiary)]"
101
- }`}
102
- >
103
- <div className="flex-1 min-w-0">
104
- <div className="text-xs truncate">{opt.label}</div>
105
- {opt.description && (
106
- <div className="text-[10px] text-[var(--text-muted)] truncate">{opt.description}</div>
134
+ filtered.map((opt, i) => {
135
+ const caption = opt.group !== undefined && opt.group !== lastGroup ? opt.group : null;
136
+ lastGroup = opt.group;
137
+ return (
138
+ <React.Fragment key={opt.value}>
139
+ {caption && (
140
+ <div className="px-2 pt-2 pb-1 text-[10px] font-semibold uppercase tracking-wider text-[var(--text-muted)]">
141
+ {caption}
142
+ </div>
107
143
  )}
108
- </div>
109
- {opt.badge && (
110
- <span className={`text-[9px] px-1 py-0.5 rounded flex-shrink-0 ${opt.badgeColor || "text-[var(--text-tertiary)]"}`}>
111
- {opt.badge}
112
- </span>
113
- )}
114
- </div>
115
- ))
144
+ <div
145
+ role="option"
146
+ aria-selected={i === selectedIndex && !opt.disabled}
147
+ aria-disabled={opt.disabled || undefined}
148
+ title={opt.disabled ? opt.disabledReason : undefined}
149
+ data-active={i === selectedIndex}
150
+ onClick={() => { if (!opt.disabled) onSelect(opt.value); }}
151
+ onMouseEnter={() => setSelectedIndex(i)}
152
+ className={`px-3 py-1.5 rounded-lg flex items-center gap-2 ${
153
+ opt.disabled
154
+ ? "cursor-not-allowed opacity-55"
155
+ : "cursor-pointer"
156
+ } ${
157
+ i === selectedIndex
158
+ ? "bg-blue-500/15 text-[var(--text-primary)]"
159
+ : "text-[var(--text-secondary)] hover:bg-[var(--bg-tertiary)]"
160
+ }`}
161
+ >
162
+ <div className="flex-1 min-w-0">
163
+ <div className="text-xs truncate">{opt.label}</div>
164
+ {opt.description && (
165
+ <div className="text-[10px] text-[var(--text-muted)] truncate">
166
+ {opt.description}
167
+ </div>
168
+ )}
169
+ </div>
170
+ {opt.badge && (
171
+ <span className={`text-[9px] px-1 py-0.5 rounded flex-shrink-0 ${opt.badgeColor || "text-[var(--text-tertiary)]"}`}>
172
+ {opt.badge}
173
+ </span>
174
+ )}
175
+ </div>
176
+ </React.Fragment>
177
+ );
178
+ })
116
179
  )}
117
180
  </div>
118
181
 
@@ -8,13 +8,14 @@
8
8
  * rendering get visual parity. See change:
9
9
  * adopt-server-driven-intent-rendering.
10
10
  */
11
- import React, { useEffect, useState } from "react";
12
- import Icon from "@mdi/react";
13
- import * as mdi from "@mdi/js";
11
+
14
12
  import type {
15
13
  UiStatusPillProps,
16
14
  UiStatusPillState,
17
15
  } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
16
+ import Icon from "@mdi/react";
17
+ import React, { useEffect, useState } from "react";
18
+ import { useMdiIconByKey } from "./mdi-by-key.js";
18
19
 
19
20
  const STATE_STYLE_DARK: Record<UiStatusPillState, { bg: string; fg: string }> = {
20
21
  running: { bg: "rgba(34, 197, 94, 0.15)", fg: "rgb(134, 239, 172)" },
@@ -64,12 +65,13 @@ export function StatusPill({ state, text, icon, tooltip }: UiStatusPillProps) {
64
65
  );
65
66
  }
66
67
 
68
+ /**
69
+ * Render an MDI icon by its export-name key. Renders nothing while the full
70
+ * icon set loads and for unknown keys. See change:
71
+ * harden-ios-safari-memory-and-ws-diagnostics.
72
+ */
67
73
  function IconByKey({ iconKey }: { iconKey: string }) {
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;
74
+ const path = useMdiIconByKey(iconKey);
73
75
  if (!path) return null;
74
76
  return <Icon path={path} size={0.55} />;
75
77
  }
@@ -1,6 +1,6 @@
1
- import React from "react";
1
+ import { mdiArrowExpandAll, mdiMagnifyMinusOutline, mdiMagnifyPlusOutline } from "@mdi/js";
2
2
  import { Icon } from "@mdi/react";
3
- import { mdiMagnifyPlusOutline, mdiMagnifyMinusOutline, mdiArrowExpandAll } from "@mdi/js";
3
+ import React from "react";
4
4
  // Shared zoom controls — used by MermaidBlock and FlowGraph
5
5
 
6
6
  export function ZoomControls({
@@ -8,11 +8,14 @@ export function ZoomControls({
8
8
  onZoomOut,
9
9
  onReset,
10
10
  scale,
11
+ initialScale = 1,
11
12
  }: {
12
13
  onZoomIn: () => void;
13
14
  onZoomOut: () => void;
14
15
  onReset: () => void;
15
16
  scale: number;
17
+ /** Scale the surface starts/resets at; the % readout shows only when scale differs. */
18
+ initialScale?: number;
16
19
  }) {
17
20
  const btnClass =
18
21
  "w-7 h-7 flex items-center justify-center rounded " +
@@ -35,7 +38,7 @@ export function ZoomControls({
35
38
  <button className={btnClass} onClick={onReset} title="Reset zoom">
36
39
  <Icon path={mdiArrowExpandAll} size={0.6} />
37
40
  </button>
38
- {scale !== 1 && (
41
+ {scale !== initialScale && (
39
42
  <div className="text-[10px] text-[var(--text-muted)] text-center tabular-nums">
40
43
  {Math.round(scale * 100)}%
41
44
  </div>
@@ -2,9 +2,10 @@
2
2
  * Shared utilities for agent card rendering.
3
3
  * Used by FlowAgentCard (flows) and AgentToolRenderer (subagents).
4
4
  */
5
- import React, { type ReactNode } from "react";
5
+
6
+ import { mdiAlertCircle, mdiCheckCircle, mdiCircleOutline, mdiCloseCircle, mdiLoading, mdiMinusCircleOutline, mdiPause, mdiStop } from "@mdi/js";
6
7
  import { Icon } from "@mdi/react";
7
- import { mdiCircleOutline, mdiLoading, mdiCheckCircle, mdiCloseCircle, mdiAlertCircle, mdiStop, mdiPause } from "@mdi/js";
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 */