@dbx-tools/ui 0.9.213 → 0.11.2

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 CHANGED
@@ -46,6 +46,30 @@ import { dbxToolsAssetDataUrls } from "@dbx-tools/ui/branding/assets";
46
46
  Import `@dbx-tools/ui/branding/styles.css` for default brand variables. Static
47
47
  SVG assets are exported under `@dbx-tools/ui/branding/assets/*`.
48
48
 
49
+ `BrandContext` can also publish an optional semantic typography and density
50
+ scale. Omitted fields leave existing component sizing unchanged.
51
+
52
+ ```tsx
53
+ import { parseBrandContext } from "@dbx-tools/shared-core";
54
+
55
+ const brand = parseBrandContext({
56
+ typography: {
57
+ body: { size: 14, lineHeight: 20, weight: 400 },
58
+ title: { size: 16, lineHeight: 22, weight: 600 },
59
+ caption: { size: 12, lineHeight: 16, weight: 400 },
60
+ },
61
+ density: { controlHeight: 36, sectionSpacing: 12 },
62
+ colors: {
63
+ chart: { baseline: "#1B3139", expected: "#0E538B", range: "#00A972" },
64
+ },
65
+ });
66
+ ```
67
+
68
+ Applying this context publishes `--brand-font-body-*`,
69
+ `--brand-font-title-*`, `--brand-font-caption-*`, `--brand-control-height`,
70
+ `--brand-section-spacing`, and optional semantic chart variables alongside the
71
+ existing family and identity-color variables.
72
+
49
73
  ## Authentication
50
74
 
51
75
  ```tsx
@@ -6,8 +6,8 @@ export * as emailApprovalCard from "./src/email/react/email-approval-card.tsx";
6
6
  export * as emailBody from "./src/email/react/email-body.tsx";
7
7
  export * as emailCompose from "./src/email/react/email-compose.tsx";
8
8
  export * as fields from "./src/email/react/fields.ts";
9
- export { EmailPreview, EmailApprovalCard } from "./src/email/react/email-approval-card.tsx";
10
- export type { EmailPreviewProps, EmailApprovalCardProps } from "./src/email/react/email-approval-card.tsx";
9
+ export { EmailFieldRow, EmailPreview, EmailApprovalCard } from "./src/email/react/email-approval-card.tsx";
10
+ export type { EmailPreviewProps, EmailFieldRowProps, EmailApprovalCardProps } from "./src/email/react/email-approval-card.tsx";
11
11
  export { EmailBody } from "./src/email/react/email-body.tsx";
12
12
  export type { EmailBodyProps } from "./src/email/react/email-body.tsx";
13
13
  export { EmailComposeView } from "./src/email/react/email-compose.tsx";
package/index.react.ts CHANGED
@@ -4,22 +4,37 @@
4
4
 
5
5
  export * as brandPicker from "./src/react/brand-picker.tsx";
6
6
  export * as clipboard from "./src/react/clipboard.ts";
7
+ export * as confirmDialog from "./src/react/confirm-dialog.tsx";
8
+ export * as copyButton from "./src/react/copy-button.tsx";
7
9
  export * as debugCapture from "./src/react/debug-capture.tsx";
10
+ export * as elementSize from "./src/react/element-size.ts";
8
11
  export * as errorBoundary from "./src/react/error-boundary.tsx";
9
12
  export * as highlightedCode from "./src/react/highlighted-code.tsx";
13
+ export * as iconTooltipButton from "./src/react/icon-tooltip-button.tsx";
10
14
  export * as recordPreviewData from "./src/react/record-preview-data.ts";
11
15
  export * as recordPreview from "./src/react/record-preview.tsx";
12
16
  export * as shikiPlugin from "./src/react/shiki-plugin.ts";
17
+ export * as storage from "./src/react/storage.ts";
13
18
  export { BrandPicker } from "./src/react/brand-picker.tsx";
14
19
  export type { BrandPreset, BrandPickerProps } from "./src/react/brand-picker.tsx";
15
20
  export { copyText } from "./src/react/clipboard.ts";
21
+ export { ConfirmDialog } from "./src/react/confirm-dialog.tsx";
22
+ export type { ConfirmDialogProps } from "./src/react/confirm-dialog.tsx";
23
+ export { useCopyFeedback, CopyButton } from "./src/react/copy-button.tsx";
24
+ export type { CopyButtonProps } from "./src/react/copy-button.tsx";
16
25
  export { useBrowserDebugCapture, BrowserDebugCaptureButton } from "./src/react/debug-capture.tsx";
17
26
  export type { BrowserDebugCaptureTarget, UseBrowserDebugCaptureOptions, BrowserDebugCaptureState, BrowserDebugCaptureButtonProps } from "./src/react/debug-capture.tsx";
27
+ export { useElementSize } from "./src/react/element-size.ts";
28
+ export type { ElementSize } from "./src/react/element-size.ts";
18
29
  export { ErrorBoundary } from "./src/react/error-boundary.tsx";
19
30
  export { detectCodeLanguage, useHighlightedHtml, HighlightedCodeBlock, JsonBlock } from "./src/react/highlighted-code.tsx";
20
31
  export type { DetectedCodeLanguage } from "./src/react/highlighted-code.tsx";
32
+ export { IconTooltipButton } from "./src/react/icon-tooltip-button.tsx";
33
+ export type { IconTooltipButtonProps } from "./src/react/icon-tooltip-button.tsx";
21
34
  export { recordPreviewRows, formatRecordPreviewJson, parseNestedJsonText, looksLikeMarkdown, markdownForPreview } from "./src/react/record-preview-data.ts";
22
35
  export type { RecordPreviewRow } from "./src/react/record-preview-data.ts";
23
36
  export { RecordPreview } from "./src/react/record-preview.tsx";
24
37
  export type { RecordPreviewProps } from "./src/react/record-preview.tsx";
25
38
  export { highlightToHtml, createShikiPlugin } from "./src/react/shiki-plugin.ts";
39
+ export { browserStorage, readStoredItem, writeStoredItem, removeStoredItem, useStoredState } from "./src/react/storage.ts";
40
+ export type { BrowserStorageKind, StorageLike, StoredStateOptions } from "./src/react/storage.ts";
package/index.ts CHANGED
@@ -3,4 +3,4 @@
3
3
  // Hand edits are overwritten on the next generation; this file is read-only.
4
4
 
5
5
  export const PACKAGE_IDENTIFIER = "@dbx-tools/ui";
6
- export const PACKAGE_VERSION = "0.9.213";
6
+ export const PACKAGE_VERSION = "0.11.2";
package/package.json CHANGED
@@ -20,23 +20,23 @@
20
20
  "devDependencies": {
21
21
  "@types/react": "^19.2.2",
22
22
  "@types/react-dom": "^19.2.2",
23
- "react": "~19.2.4",
24
- "react-dom": "~19.2.4",
23
+ "react": "19.3.1",
24
+ "react-dom": "19.3.1",
25
25
  "typescript": "^5.9.3"
26
26
  },
27
27
  "peerDependencies": {
28
- "react": "~19.2.4",
29
- "react-dom": "~19.2.4"
28
+ "react": "19.3.1",
29
+ "react-dom": "19.3.1"
30
30
  },
31
31
  "dependencies": {
32
32
  "@better-auth/passkey": "1.7.6",
33
- "@databricks/appkit-ui": "0.81.0",
34
- "@dbx-tools/shared-appkit": "0.9.213",
35
- "@dbx-tools/shared-auth": "0.9.213",
36
- "@dbx-tools/shared-core": "0.9.213",
37
- "@dbx-tools/shared-email": "0.9.213",
38
- "@dbx-tools/shared-email-template": "0.9.213",
39
- "@dbx-tools/shared-search": "0.9.213",
33
+ "@databricks/appkit-ui": "0.106.0",
34
+ "@dbx-tools/shared-appkit": "0.11.2",
35
+ "@dbx-tools/shared-auth": "0.11.2",
36
+ "@dbx-tools/shared-core": "0.11.2",
37
+ "@dbx-tools/shared-email": "0.11.2",
38
+ "@dbx-tools/shared-email-template": "0.11.2",
39
+ "@dbx-tools/shared-search": "0.11.2",
40
40
  "@tanstack/react-table": "^8.21.3",
41
41
  "lucide-react": "^0.554.0",
42
42
  "shiki": "^3.0.0",
@@ -48,7 +48,7 @@
48
48
  "publishConfig": {
49
49
  "access": "public"
50
50
  },
51
- "version": "0.9.213",
51
+ "version": "0.11.2",
52
52
  "types": "index.ts",
53
53
  "dbxToolsConfig": {
54
54
  "tags": [
@@ -9,6 +9,23 @@ const builtInAssets = new Map<string, string>([
9
9
  [DEFAULT_BRAND_ASSETS.favicon, dbxToolsAssetDataUrls.iconLight],
10
10
  ]);
11
11
 
12
+ const optionalBrandVariables = [
13
+ "--brand-font-body-size",
14
+ "--brand-font-body-line-height",
15
+ "--brand-font-body-weight",
16
+ "--brand-font-title-size",
17
+ "--brand-font-title-line-height",
18
+ "--brand-font-title-weight",
19
+ "--brand-font-caption-size",
20
+ "--brand-font-caption-line-height",
21
+ "--brand-font-caption-weight",
22
+ "--brand-control-height",
23
+ "--brand-section-spacing",
24
+ "--brand-chart-baseline",
25
+ "--brand-chart-expected",
26
+ "--brand-chart-range",
27
+ ] as const;
28
+
12
29
  /** Resolve a brand asset identifier to a browser-loadable URL. */
13
30
  export type BrandAssetResolver = (source: string) => string;
14
31
 
@@ -18,7 +35,7 @@ export const resolveBrandAsset: BrandAssetResolver = (source) =>
18
35
 
19
36
  /** Convert a validated context to CSS custom properties. */
20
37
  export function brandCssVariables(context: BrandContext): Record<string, string> {
21
- return {
38
+ const variables: Record<string, string> = {
22
39
  "--brand-color-primary": context.colors.primary,
23
40
  "--brand-color-primary-hover": context.colors.primaryHover,
24
41
  "--brand-color-accent": context.colors.accent,
@@ -30,6 +47,32 @@ export function brandCssVariables(context: BrandContext): Record<string, string>
30
47
  "--brand-font-sans": context.typography.sans,
31
48
  "--brand-font-mono": context.typography.mono,
32
49
  };
50
+ const textStyles = [
51
+ ["body", context.typography.body],
52
+ ["title", context.typography.title],
53
+ ["caption", context.typography.caption],
54
+ ] as const;
55
+ for (const [name, style] of textStyles) {
56
+ if (style?.size !== undefined) variables[`--brand-font-${name}-size`] = `${style.size}px`;
57
+ if (style?.lineHeight !== undefined) {
58
+ variables[`--brand-font-${name}-line-height`] = `${style.lineHeight}px`;
59
+ }
60
+ if (style?.weight !== undefined) {
61
+ variables[`--brand-font-${name}-weight`] = String(style.weight);
62
+ }
63
+ }
64
+ if (context.density?.controlHeight !== undefined) {
65
+ variables["--brand-control-height"] = `${context.density.controlHeight}px`;
66
+ }
67
+ if (context.density?.sectionSpacing !== undefined) {
68
+ variables["--brand-section-spacing"] = `${context.density.sectionSpacing}px`;
69
+ }
70
+ if (context.colors.chart) {
71
+ variables["--brand-chart-baseline"] = context.colors.chart.baseline;
72
+ variables["--brand-chart-expected"] = context.colors.chart.expected;
73
+ variables["--brand-chart-range"] = context.colors.chart.range;
74
+ }
75
+ return variables;
33
76
  }
34
77
 
35
78
  /** Document, root element, asset, title, and favicon behavior for applying a brand. */
@@ -48,7 +91,11 @@ export function applyBrandContext(
48
91
  ): void {
49
92
  const documentRef = options.document ?? globalThis.document;
50
93
  const root = options.root ?? documentRef?.documentElement;
51
- for (const [name, value] of Object.entries(brandCssVariables(context))) {
94
+ const variables = brandCssVariables(context);
95
+ for (const name of optionalBrandVariables) {
96
+ if (!(name in variables)) root?.style.removeProperty(name);
97
+ }
98
+ for (const [name, value] of Object.entries(variables)) {
52
99
  root?.style.setProperty(name, value);
53
100
  }
54
101
  // Detection flag for the `brand-bridge.css` tag selector: setting
@@ -1,4 +1,4 @@
1
- import { Button } from "@databricks/appkit-ui/react";
1
+ import { Button, cn } from "@databricks/appkit-ui/react";
2
2
  import {
3
3
  EmailCard,
4
4
  emailBrandFromContext,
@@ -6,6 +6,7 @@ import {
6
6
  type EmailBrand,
7
7
  } from "@dbx-tools/shared-email-template";
8
8
  import { CheckIcon, MailIcon, PaperclipIcon, XIcon } from "lucide-react";
9
+ import type { ReactNode } from "react";
9
10
 
10
11
  import { attachmentNames, joinAddresses, type EmailDraft } from "./fields.ts";
11
12
  import { useBrand } from "../../branding/react/brand.tsx";
@@ -33,11 +34,29 @@ function senderInitials(name: string): string {
33
34
  return `${parts[0]![0] ?? ""}${parts[1]![0] ?? ""}`.toUpperCase();
34
35
  }
35
36
 
36
- /** One muted "Label: value" row in the client chrome. */
37
- const ChromeRow = ({ label, value }: { label: string; value: string }) => (
38
- <p className="truncate text-xs text-muted-foreground">
39
- <span className="font-medium text-foreground/70">{label}</span> {value}
40
- </p>
37
+ /** Props for one compact email envelope or body field. */
38
+ export interface EmailFieldRowProps {
39
+ /** Visible field label. */
40
+ label: string;
41
+ /** Field content. */
42
+ children: ReactNode;
43
+ /** Class applied to the row. */
44
+ className?: string;
45
+ /** Class applied to the field content. */
46
+ valueClassName?: string;
47
+ }
48
+
49
+ /** Compact labeled email field used by previews and approval surfaces. */
50
+ export const EmailFieldRow = ({
51
+ label,
52
+ children,
53
+ className,
54
+ valueClassName,
55
+ }: EmailFieldRowProps) => (
56
+ <div className={cn("flex min-w-0 gap-2 text-xs text-muted-foreground", className)}>
57
+ <span className="w-14 shrink-0 font-medium text-foreground/70">{label}</span>
58
+ <div className={cn("min-w-0 flex-1 truncate", valueClassName)}>{children}</div>
59
+ </div>
41
60
  );
42
61
 
43
62
  /**
@@ -84,9 +103,9 @@ export const EmailPreview = ({ email, brand }: EmailPreviewProps) => {
84
103
  </div>
85
104
  <time className="shrink-0 text-xs text-muted-foreground">Just now</time>
86
105
  </div>
87
- {to ? <ChromeRow label="To" value={to} /> : null}
88
- {cc ? <ChromeRow label="Cc" value={cc} /> : null}
89
- {bcc ? <ChromeRow label="Bcc" value={bcc} /> : null}
106
+ {to ? <EmailFieldRow label="To">{to}</EmailFieldRow> : null}
107
+ {cc ? <EmailFieldRow label="Cc">{cc}</EmailFieldRow> : null}
108
+ {bcc ? <EmailFieldRow label="Bcc">{bcc}</EmailFieldRow> : null}
90
109
  <p className="pt-1 text-sm font-medium leading-snug text-foreground">{subject}</p>
91
110
  </div>
92
111
  </div>
@@ -0,0 +1,77 @@
1
+ /** Shared confirmation dialog composition. */
2
+
3
+ import {
4
+ AlertDialog,
5
+ AlertDialogAction,
6
+ AlertDialogCancel,
7
+ AlertDialogContent,
8
+ AlertDialogDescription,
9
+ AlertDialogFooter,
10
+ AlertDialogHeader,
11
+ AlertDialogTitle,
12
+ } from "@databricks/appkit-ui/react";
13
+ import type { ComponentProps, ReactNode } from "react";
14
+
15
+ /** Props for the shared confirmation dialog. */
16
+ export interface ConfirmDialogProps {
17
+ /** Whether the dialog is open. */
18
+ open: boolean;
19
+ /** Receive open-state changes from dismissal and actions. */
20
+ onOpenChange: (open: boolean) => void;
21
+ /** Dialog heading. */
22
+ title: ReactNode;
23
+ /** Dialog explanation. */
24
+ description: ReactNode;
25
+ /** Optional content between the explanation and action row. */
26
+ children?: ReactNode;
27
+ /** Optional actions rendered between the cancel and confirm controls. */
28
+ additionalActions?: ReactNode;
29
+ /** Cancel control text. */
30
+ cancelLabel?: ReactNode;
31
+ /** Confirm control text. */
32
+ confirmLabel: ReactNode;
33
+ /** Props passed to the cancel control. */
34
+ cancelProps?: Omit<ComponentProps<typeof AlertDialogCancel>, "children">;
35
+ /** Props passed to the confirm control. */
36
+ confirmProps?: Omit<ComponentProps<typeof AlertDialogAction>, "children">;
37
+ /** Class applied to the dialog content. */
38
+ className?: string;
39
+ /** Class applied to the dialog header. */
40
+ headerClassName?: string;
41
+ /** Class applied to the action row. */
42
+ footerClassName?: string;
43
+ }
44
+
45
+ /** Accessible confirmation dialog with consistent action placement. */
46
+ export function ConfirmDialog({
47
+ open,
48
+ onOpenChange,
49
+ title,
50
+ description,
51
+ children,
52
+ additionalActions,
53
+ cancelLabel = "Cancel",
54
+ confirmLabel,
55
+ cancelProps,
56
+ confirmProps,
57
+ className,
58
+ headerClassName,
59
+ footerClassName,
60
+ }: ConfirmDialogProps) {
61
+ return (
62
+ <AlertDialog open={open} onOpenChange={onOpenChange}>
63
+ <AlertDialogContent className={className}>
64
+ <AlertDialogHeader className={headerClassName}>
65
+ <AlertDialogTitle>{title}</AlertDialogTitle>
66
+ <AlertDialogDescription>{description}</AlertDialogDescription>
67
+ </AlertDialogHeader>
68
+ {children}
69
+ <AlertDialogFooter className={footerClassName}>
70
+ <AlertDialogCancel {...cancelProps}>{cancelLabel}</AlertDialogCancel>
71
+ {additionalActions}
72
+ <AlertDialogAction {...confirmProps}>{confirmLabel}</AlertDialogAction>
73
+ </AlertDialogFooter>
74
+ </AlertDialogContent>
75
+ </AlertDialog>
76
+ );
77
+ }
@@ -0,0 +1,81 @@
1
+ /** Shared clipboard feedback and compact copy action. */
2
+
3
+ import { Button, Tooltip, TooltipContent, TooltipTrigger, cn } from "@databricks/appkit-ui/react";
4
+ import { CheckIcon, CopyIcon } from "lucide-react";
5
+ import { useCallback, useEffect, useRef, useState, type ComponentProps } from "react";
6
+
7
+ import { copyText } from "./clipboard.ts";
8
+
9
+ /** Copy text and expose transient success feedback. */
10
+ export function useCopyFeedback(durationMs = 1_500) {
11
+ const [copied, setCopied] = useState(false);
12
+ const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
13
+ useEffect(() => () => clearTimeout(timer.current), []);
14
+ const copy = useCallback(
15
+ async (value: string): Promise<boolean> => {
16
+ const success = await copyText(value);
17
+ if (!success) return false;
18
+ setCopied(true);
19
+ clearTimeout(timer.current);
20
+ timer.current = setTimeout(() => setCopied(false), durationMs);
21
+ return true;
22
+ },
23
+ [durationMs],
24
+ );
25
+ const reset = useCallback(() => {
26
+ clearTimeout(timer.current);
27
+ setCopied(false);
28
+ }, []);
29
+ return { copied, copy, reset } as const;
30
+ }
31
+
32
+ /** Props for the shared compact copy action. */
33
+ export interface CopyButtonProps extends Omit<
34
+ ComponentProps<typeof Button>,
35
+ "children" | "onClick"
36
+ > {
37
+ /** Text written to the clipboard. */
38
+ value: string;
39
+ /** Accessible label and tooltip before a successful copy. */
40
+ label?: string;
41
+ /** Accessible label and tooltip during success feedback. */
42
+ copiedLabel?: string;
43
+ /** Class applied to the copy and success icons. */
44
+ iconClassName?: string;
45
+ }
46
+
47
+ /** Compact icon button with clipboard fallback and transient success feedback. */
48
+ export function CopyButton({
49
+ value,
50
+ label = "Copy",
51
+ copiedLabel = "Copied",
52
+ iconClassName,
53
+ className,
54
+ ...button
55
+ }: CopyButtonProps) {
56
+ const { copied, copy, reset } = useCopyFeedback();
57
+ useEffect(() => reset(), [reset, value]);
58
+ const accessibleLabel = copied ? copiedLabel : label;
59
+ return (
60
+ <Tooltip>
61
+ <TooltipTrigger asChild>
62
+ <Button
63
+ type="button"
64
+ size="icon"
65
+ variant="ghost"
66
+ aria-label={accessibleLabel}
67
+ className={cn("size-7", className)}
68
+ onClick={() => void copy(value)}
69
+ {...button}
70
+ >
71
+ {copied ? (
72
+ <CheckIcon className={iconClassName} aria-hidden="true" />
73
+ ) : (
74
+ <CopyIcon className={iconClassName} aria-hidden="true" />
75
+ )}
76
+ </Button>
77
+ </TooltipTrigger>
78
+ <TooltipContent>{accessibleLabel}</TooltipContent>
79
+ </Tooltip>
80
+ );
81
+ }
@@ -1,12 +1,4 @@
1
- import {
2
- Button,
3
- Tooltip,
4
- TooltipContent,
5
- TooltipProvider,
6
- TooltipTrigger,
7
- cn,
8
- usePluginClientConfig,
9
- } from "@databricks/appkit-ui/react";
1
+ import { TooltipProvider, cn, usePluginClientConfig } from "@databricks/appkit-ui/react";
10
2
  import {
11
3
  DEBUG_CAPTURE_PLUGIN_NAME,
12
4
  DebugCaptureClientConfigSchema,
@@ -16,10 +8,13 @@ import {
16
8
  type DebugCaptureEvent,
17
9
  type DebugCaptureScalar,
18
10
  } from "@dbx-tools/shared-appkit/debug";
11
+ import { errorMessage } from "@dbx-tools/shared-core";
19
12
  import { BugIcon, CheckIcon } from "lucide-react";
20
13
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
21
14
 
22
15
  import { copyText } from "./clipboard.ts";
16
+ import { IconTooltipButton } from "./icon-tooltip-button.tsx";
17
+ import { browserStorage, readStoredItem, removeStoredItem, writeStoredItem } from "./storage.ts";
23
18
 
24
19
  const ACTIVE_CAPTURE_STORAGE_KEY = "dbx-tools.browser-debug-capture";
25
20
  const MAX_BUFFERED_EVENTS = 40;
@@ -106,21 +101,13 @@ export interface BrowserDebugCaptureState {
106
101
  }
107
102
 
108
103
  function storedCaptureId(): string | null {
109
- if (typeof window === "undefined") return null;
110
- try {
111
- return window.sessionStorage.getItem(ACTIVE_CAPTURE_STORAGE_KEY);
112
- } catch {
113
- return null;
114
- }
104
+ return readStoredItem(ACTIVE_CAPTURE_STORAGE_KEY, browserStorage("session")) ?? null;
115
105
  }
116
106
 
117
107
  function setStoredCaptureId(captureId: string | null): void {
118
- try {
119
- if (captureId) window.sessionStorage.setItem(ACTIVE_CAPTURE_STORAGE_KEY, captureId);
120
- else window.sessionStorage.removeItem(ACTIVE_CAPTURE_STORAGE_KEY);
121
- } catch {
122
- // Recording remains usable when session storage is unavailable.
123
- }
108
+ const storage = browserStorage("session");
109
+ if (captureId) writeStoredItem(ACTIVE_CAPTURE_STORAGE_KEY, captureId, storage);
110
+ else removeStoredItem(ACTIVE_CAPTURE_STORAGE_KEY, storage);
124
111
  }
125
112
 
126
113
  function targetConfig(target: string | BrowserDebugCaptureTarget): BrowserDebugCaptureTarget {
@@ -305,7 +292,7 @@ export function useBrowserDebugCapture(
305
292
  await post({ action: "append", captureId: activeCaptureId, events });
306
293
  })
307
294
  .catch((requestError: unknown) => {
308
- setError(requestError instanceof Error ? requestError.message : "Debug capture failed.");
295
+ setError(errorMessage(requestError));
309
296
  });
310
297
  pendingRequestRef.current = request;
311
298
  return request;
@@ -403,7 +390,7 @@ export function useBrowserDebugCapture(
403
390
  setPhase("recording");
404
391
  return result.captureId;
405
392
  } catch (startError) {
406
- setError(startError instanceof Error ? startError.message : "Could not start capture.");
393
+ setError(errorMessage(startError));
407
394
  setPhase("idle");
408
395
  return null;
409
396
  }
@@ -428,7 +415,7 @@ export function useBrowserDebugCapture(
428
415
  return activeCaptureId;
429
416
  } catch (stopError) {
430
417
  recordingRef.current = true;
431
- setError(stopError instanceof Error ? stopError.message : "Could not stop capture.");
418
+ setError(errorMessage(stopError));
432
419
  setPhase("recording");
433
420
  return null;
434
421
  }
@@ -499,38 +486,31 @@ export function BrowserDebugCaptureButton({
499
486
  return (
500
487
  <div className="relative flex shrink-0 items-center">
501
488
  <TooltipProvider delayDuration={200}>
502
- <Tooltip>
503
- <TooltipTrigger asChild>
504
- <Button
505
- type="button"
506
- size="icon"
507
- variant="ghost"
508
- disabled={busy}
509
- aria-label={recording ? "Stop browser capture and copy ID" : "Start browser capture"}
510
- aria-pressed={recording}
511
- data-capture-id={captureId ?? copiedId ?? undefined}
512
- data-capture-state={phase}
513
- className={cn(
514
- "relative size-8",
515
- recording && "bg-destructive/15 text-destructive hover:bg-destructive/25",
516
- error && "text-destructive",
517
- className,
518
- )}
519
- onClick={(event) => toggle(event.currentTarget)}
520
- >
521
- {copiedId && !recording ? (
522
- <CheckIcon className="size-4" />
523
- ) : (
524
- <BugIcon className="size-4" />
525
- )}
526
-
527
- {recording ? (
528
- <span className="absolute right-1 top-1 size-1.5 rounded-full bg-destructive" />
529
- ) : null}
530
- </Button>
531
- </TooltipTrigger>
532
- <TooltipContent>{tooltip}</TooltipContent>
533
- </Tooltip>
489
+ <IconTooltipButton
490
+ tooltip={tooltip}
491
+ disabled={busy}
492
+ aria-label={recording ? "Stop browser capture and copy ID" : "Start browser capture"}
493
+ aria-pressed={recording}
494
+ data-capture-id={captureId ?? copiedId ?? undefined}
495
+ data-capture-state={phase}
496
+ className={cn(
497
+ "relative size-8",
498
+ recording && "bg-destructive/15 text-destructive hover:bg-destructive/25",
499
+ error && "text-destructive",
500
+ className,
501
+ )}
502
+ onClick={(event) => toggle(event.currentTarget)}
503
+ >
504
+ {copiedId && !recording ? (
505
+ <CheckIcon className="size-4" />
506
+ ) : (
507
+ <BugIcon className="size-4" />
508
+ )}
509
+
510
+ {recording ? (
511
+ <span className="absolute right-1 top-1 size-1.5 rounded-full bg-destructive" />
512
+ ) : null}
513
+ </IconTooltipButton>
534
514
  </TooltipProvider>
535
515
  {copiedId && !recording ? (
536
516
  <span
@@ -0,0 +1,34 @@
1
+ /** Reactive element dimensions backed by one ResizeObserver. */
2
+
3
+ import { useEffect, useState, type RefObject } from "react";
4
+
5
+ /** Current content-box dimensions for an observed element. */
6
+ export interface ElementSize {
7
+ readonly width: number;
8
+ readonly height: number;
9
+ }
10
+
11
+ const EMPTY_SIZE: ElementSize = { width: 0, height: 0 };
12
+
13
+ /** Observe an element and return its latest non-negative content-box size. */
14
+ export function useElementSize(ref: RefObject<HTMLElement | null>): ElementSize {
15
+ const [size, setSize] = useState<ElementSize>(EMPTY_SIZE);
16
+ useEffect(() => {
17
+ const element = ref.current;
18
+ if (!element || typeof ResizeObserver === "undefined") return;
19
+ const update = (width: number, height: number) => {
20
+ if (width < 0 || height < 0) return;
21
+ setSize((current) =>
22
+ current.width === width && current.height === height ? current : { width, height },
23
+ );
24
+ };
25
+ update(element.clientWidth, element.clientHeight);
26
+ const observer = new ResizeObserver((entries) => {
27
+ const bounds = entries[0]?.contentRect;
28
+ update(bounds?.width ?? element.clientWidth, bounds?.height ?? element.clientHeight);
29
+ });
30
+ observer.observe(element);
31
+ return () => observer.disconnect();
32
+ }, [ref]);
33
+ return size;
34
+ }
@@ -0,0 +1,46 @@
1
+ /** Shared compact icon action with an accessible tooltip. */
2
+
3
+ import { Button, Tooltip, TooltipContent, TooltipTrigger, cn } from "@databricks/appkit-ui/react";
4
+ import type { ComponentProps, ReactElement, ReactNode } from "react";
5
+
6
+ /** Props for the shared compact tooltip action. */
7
+ export interface IconTooltipButtonProps extends Omit<ComponentProps<typeof Button>, "children"> {
8
+ /** Visible tooltip text. Also supplies the accessible label when it is a string. */
9
+ tooltip: ReactNode;
10
+ /** Icon or as-child element rendered by the button. */
11
+ children: ReactNode;
12
+ /** Class applied to the tooltip content. */
13
+ tooltipClassName?: string;
14
+ /** Wrap the button in another as-child trigger, such as a popover or dialog trigger. */
15
+ wrapButton?: (button: ReactElement) => ReactElement;
16
+ }
17
+
18
+ /** Compact icon button with one tooltip and accessible-label policy. */
19
+ export function IconTooltipButton({
20
+ tooltip,
21
+ children,
22
+ className,
23
+ tooltipClassName,
24
+ wrapButton,
25
+ "aria-label": ariaLabel,
26
+ ...button
27
+ }: IconTooltipButtonProps) {
28
+ const iconButton = (
29
+ <Button
30
+ type="button"
31
+ size="icon"
32
+ variant="ghost"
33
+ aria-label={ariaLabel ?? (typeof tooltip === "string" ? tooltip : undefined)}
34
+ className={cn("size-7", className)}
35
+ {...button}
36
+ >
37
+ {children}
38
+ </Button>
39
+ );
40
+ return (
41
+ <Tooltip>
42
+ <TooltipTrigger asChild>{wrapButton ? wrapButton(iconButton) : iconButton}</TooltipTrigger>
43
+ <TooltipContent className={tooltipClassName}>{tooltip}</TooltipContent>
44
+ </Tooltip>
45
+ );
46
+ }
@@ -5,23 +5,13 @@
5
5
  * @module
6
6
  */
7
7
 
8
- import {
9
- Button,
10
- Table,
11
- TableBody,
12
- TableCell,
13
- TableHead,
14
- TableRow,
15
- Tooltip,
16
- TooltipContent,
17
- TooltipTrigger,
18
- cn,
19
- } from "@databricks/appkit-ui/react";
8
+ import { Table, TableBody, TableCell, TableHead, TableRow, cn } from "@databricks/appkit-ui/react";
20
9
  import { BracesIcon, Table2Icon } from "lucide-react";
21
10
  import { createContext, Fragment, useContext, useState } from "react";
22
11
  import { Streamdown, type LinkSafetyConfig } from "streamdown";
23
12
 
24
13
  import { detectCodeLanguage, HighlightedCodeBlock, JsonBlock } from "./highlighted-code.tsx";
14
+ import { IconTooltipButton } from "./icon-tooltip-button.tsx";
25
15
  import {
26
16
  formatRecordPreviewJson,
27
17
  looksLikeMarkdown,
@@ -82,22 +72,15 @@ export function RecordPreview({ value, className, linkSafety }: RecordPreviewPro
82
72
  )}
83
73
  >
84
74
  <div className="pointer-events-none sticky top-1 z-20 flex h-0 justify-end pr-1">
85
- <Tooltip>
86
- <TooltipTrigger asChild>
87
- <Button
88
- type="button"
89
- size="icon"
90
- variant="ghost"
91
- aria-pressed={raw}
92
- aria-label={raw ? "Show table" : "Show JSON"}
93
- className="pointer-events-auto size-6 bg-background shadow-sm ring-1 ring-border/40"
94
- onClick={() => setRaw((current) => !current)}
95
- >
96
- {raw ? <Table2Icon className="size-3" /> : <BracesIcon className="size-3" />}
97
- </Button>
98
- </TooltipTrigger>
99
- <TooltipContent>{raw ? "Table" : "JSON"}</TooltipContent>
100
- </Tooltip>
75
+ <IconTooltipButton
76
+ tooltip={raw ? "Table" : "JSON"}
77
+ aria-pressed={raw}
78
+ aria-label={raw ? "Show table" : "Show JSON"}
79
+ className="pointer-events-auto size-6 bg-background shadow-sm ring-1 ring-border/40"
80
+ onClick={() => setRaw((current) => !current)}
81
+ >
82
+ {raw ? <Table2Icon className="size-3" /> : <BracesIcon className="size-3" />}
83
+ </IconTooltipButton>
101
84
  </div>
102
85
  {raw ? (
103
86
  <JsonBlock json={rawJson} className="rounded bg-background/40 p-2 pr-8 text-[11px]" />
@@ -0,0 +1,129 @@
1
+ /** Safe browser storage access and React state persistence. */
2
+
3
+ import {
4
+ useCallback,
5
+ useEffect,
6
+ useMemo,
7
+ useRef,
8
+ useState,
9
+ type Dispatch,
10
+ type SetStateAction,
11
+ } from "react";
12
+
13
+ /** Browser storage scope. */
14
+ export type BrowserStorageKind = "local" | "session";
15
+
16
+ /** Minimal browser-storage contract used by persistence helpers and tests. */
17
+ export type StorageLike = Pick<Storage, "getItem" | "setItem" | "removeItem">;
18
+
19
+ /** Resolve browser storage without throwing during SSR or restricted browser sessions. */
20
+ export function browserStorage(kind: BrowserStorageKind = "local"): StorageLike | undefined {
21
+ if (typeof window === "undefined") return undefined;
22
+ try {
23
+ return kind === "session" ? window.sessionStorage : window.localStorage;
24
+ } catch {
25
+ return undefined;
26
+ }
27
+ }
28
+
29
+ /** Read one item without propagating browser-storage failures. */
30
+ export function readStoredItem(
31
+ key: string,
32
+ storage: StorageLike | undefined = browserStorage(),
33
+ ): string | undefined {
34
+ try {
35
+ return storage?.getItem(key) ?? undefined;
36
+ } catch {
37
+ return undefined;
38
+ }
39
+ }
40
+
41
+ /** Write one item and report whether persistence succeeded. */
42
+ export function writeStoredItem(
43
+ key: string,
44
+ value: string,
45
+ storage: StorageLike | undefined = browserStorage(),
46
+ ): boolean {
47
+ try {
48
+ if (!storage) return false;
49
+ storage.setItem(key, value);
50
+ return true;
51
+ } catch {
52
+ return false;
53
+ }
54
+ }
55
+
56
+ /** Remove one item and report whether persistence succeeded. */
57
+ export function removeStoredItem(
58
+ key: string,
59
+ storage: StorageLike | undefined = browserStorage(),
60
+ ): boolean {
61
+ try {
62
+ if (!storage) return false;
63
+ storage.removeItem(key);
64
+ return true;
65
+ } catch {
66
+ return false;
67
+ }
68
+ }
69
+
70
+ /** Serialization policy for {@link useStoredState}. */
71
+ export interface StoredStateOptions<T> {
72
+ /** Browser scope or explicit storage implementation. */
73
+ storage?: BrowserStorageKind | StorageLike;
74
+ /** Convert stored text into state. Throw to use the fallback value. */
75
+ parse?: (value: string) => T;
76
+ /** Convert state into stored text. */
77
+ serialize?: (value: T) => string;
78
+ }
79
+
80
+ function initialValue<T>(initial: T | (() => T)): T {
81
+ return typeof initial === "function" ? (initial as () => T)() : initial;
82
+ }
83
+
84
+ /** React state that persists updates without failing when browser storage is unavailable. */
85
+ export function useStoredState<T>(
86
+ key: string,
87
+ initial: T | (() => T),
88
+ options: StoredStateOptions<T> = {},
89
+ ): readonly [T, Dispatch<SetStateAction<T>>] {
90
+ const initialRef = useRef(initial);
91
+ const parseRef = useRef(options.parse);
92
+ const serializeRef = useRef(options.serialize);
93
+ initialRef.current = initial;
94
+ parseRef.current = options.parse;
95
+ serializeRef.current = options.serialize;
96
+ const storage = useMemo(
97
+ () =>
98
+ typeof options.storage === "string"
99
+ ? browserStorage(options.storage)
100
+ : (options.storage ?? browserStorage()),
101
+ [options.storage],
102
+ );
103
+ const read = useCallback(() => {
104
+ const fallback = initialValue(initialRef.current);
105
+ const stored = readStoredItem(key, storage);
106
+ if (stored === undefined) return fallback;
107
+ try {
108
+ return parseRef.current ? parseRef.current(stored) : (stored as T);
109
+ } catch {
110
+ return fallback;
111
+ }
112
+ }, [key, storage]);
113
+ const [value, setValue] = useState<T>(read);
114
+
115
+ useEffect(() => setValue(read()), [read]);
116
+
117
+ const setStoredValue = useCallback<Dispatch<SetStateAction<T>>>(
118
+ (next) => {
119
+ setValue((current) => {
120
+ const resolved = typeof next === "function" ? (next as (value: T) => T)(current) : next;
121
+ writeStoredItem(key, serializeRef.current?.(resolved) ?? String(resolved), storage);
122
+ return resolved;
123
+ });
124
+ },
125
+ [key, storage],
126
+ );
127
+
128
+ return [value, setStoredValue] as const;
129
+ }
@@ -6,6 +6,7 @@ import type {
6
6
  SortingState,
7
7
  VisibilityState,
8
8
  } from "@tanstack/react-table";
9
+ import { browserStorage, type StorageLike } from "../../react/storage.ts";
9
10
 
10
11
  /** Browser storage used for persisted table state. */
11
12
  export type DataTableStorage = "local" | "session";
@@ -33,15 +34,6 @@ export interface DataTablePersistence {
33
34
  include?: readonly DataTablePersistedField[];
34
35
  }
35
36
 
36
- interface StorageReader {
37
- getItem(key: string): string | null;
38
- }
39
-
40
- interface StorageWriter extends StorageReader {
41
- removeItem(key: string): void;
42
- setItem(key: string, value: string): void;
43
- }
44
-
45
37
  /** Default set of table fields saved between visits. */
46
38
  export const defaultDataTablePersistedFields: readonly DataTablePersistedField[] = [
47
39
  "columnFilters",
@@ -95,7 +87,7 @@ function filterState(value: unknown): ColumnFiltersState | undefined {
95
87
 
96
88
  /** Read and validate a persisted table snapshot. */
97
89
  export function readDataTableState(
98
- storage: StorageReader | undefined,
90
+ storage: Pick<StorageLike, "getItem"> | undefined,
99
91
  key: string,
100
92
  ): Partial<DataTableStateSnapshot> {
101
93
  if (!storage) return {};
@@ -132,7 +124,7 @@ export function mergeDataTableColumnOrder(
132
124
 
133
125
  /** Write selected table fields without breaking interaction when storage is unavailable. */
134
126
  export function writeDataTableState(
135
- storage: StorageWriter | undefined,
127
+ storage: StorageLike | undefined,
136
128
  key: string,
137
129
  value: DataTableStateSnapshot,
138
130
  include: readonly DataTablePersistedField[],
@@ -149,11 +141,5 @@ export function writeDataTableState(
149
141
  }
150
142
 
151
143
  /** Resolve browser storage without throwing in SSR or privacy-restricted contexts. */
152
- export function dataTableBrowserStorage(kind: DataTableStorage): StorageWriter | undefined {
153
- if (typeof window === "undefined") return undefined;
154
- try {
155
- return kind === "session" ? window.sessionStorage : window.localStorage;
156
- } catch {
157
- return undefined;
158
- }
159
- }
144
+ export const dataTableBrowserStorage = (kind: DataTableStorage): StorageLike | undefined =>
145
+ browserStorage(kind);