@open-artifact/editor-kit 0.0.0-stage → 0.1.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.
Files changed (82) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +5 -0
  3. package/README.md +128 -2
  4. package/package.json +58 -4
  5. package/src/Announcer.d.ts +2 -0
  6. package/src/Announcer.js +8 -0
  7. package/src/FindBar.d.ts +31 -0
  8. package/src/FindBar.js +34 -0
  9. package/src/agent.d.ts +20 -0
  10. package/src/agent.js +40 -0
  11. package/src/announce.d.ts +18 -0
  12. package/src/announce.js +21 -0
  13. package/src/chrome.d.ts +180 -0
  14. package/src/chrome.js +108 -0
  15. package/src/collab/CommentList.d.ts +23 -0
  16. package/src/collab/CommentList.js +117 -0
  17. package/src/collab/CommentViews.d.ts +116 -0
  18. package/src/collab/CommentViews.js +531 -0
  19. package/src/collab/HistoryViews.d.ts +38 -0
  20. package/src/collab/HistoryViews.js +103 -0
  21. package/src/collab/PresenceViews.d.ts +52 -0
  22. package/src/collab/PresenceViews.js +46 -0
  23. package/src/collab/cds/cds.d.ts +148 -0
  24. package/src/collab/cds/cds.js +230 -0
  25. package/src/collab/cds/comment-card.d.ts +93 -0
  26. package/src/collab/cds/comment-card.js +211 -0
  27. package/src/collab/cds/comment-composer.d.ts +28 -0
  28. package/src/collab/cds/comment-composer.js +101 -0
  29. package/src/collab/cds/comments-css.d.ts +2 -0
  30. package/src/collab/cds/comments-css.js +3 -0
  31. package/src/collab/cds/comments.css +497 -0
  32. package/src/collab/cds/edge-piles.d.ts +69 -0
  33. package/src/collab/cds/edge-piles.js +178 -0
  34. package/src/collab/cds/layer.d.ts +41 -0
  35. package/src/collab/cds/layer.js +143 -0
  36. package/src/collab/cds/markdown.d.ts +17 -0
  37. package/src/collab/cds/markdown.js +507 -0
  38. package/src/collab/cds/shield.d.ts +28 -0
  39. package/src/collab/cds/shield.js +114 -0
  40. package/src/collab/cds/time.d.ts +2 -0
  41. package/src/collab/cds/time.js +41 -0
  42. package/src/collab/collab.d.ts +100 -0
  43. package/src/collab/collab.js +119 -0
  44. package/src/collab/comments.d.ts +147 -0
  45. package/src/collab/comments.js +287 -0
  46. package/src/collab/history-wiring.d.ts +32 -0
  47. package/src/collab/history-wiring.js +53 -0
  48. package/src/collab/history.d.ts +53 -0
  49. package/src/collab/history.js +94 -0
  50. package/src/collab/peer-colors.d.ts +123 -0
  51. package/src/collab/peer-colors.js +273 -0
  52. package/src/collab/pins.d.ts +70 -0
  53. package/src/collab/pins.js +44 -0
  54. package/src/collab/presence.d.ts +92 -0
  55. package/src/collab/presence.js +158 -0
  56. package/src/design-systems.d.ts +46 -0
  57. package/src/design-systems.js +61 -0
  58. package/src/downloads.d.ts +24 -0
  59. package/src/downloads.js +36 -0
  60. package/src/find.d.ts +64 -0
  61. package/src/find.js +147 -0
  62. package/src/index.d.ts +25 -0
  63. package/src/index.js +25 -0
  64. package/src/keys.d.ts +13 -0
  65. package/src/keys.js +20 -0
  66. package/src/merge.d.ts +23 -0
  67. package/src/merge.js +116 -0
  68. package/src/page-link.d.ts +33 -0
  69. package/src/page-link.js +75 -0
  70. package/src/project-sync.d.ts +118 -0
  71. package/src/project-sync.js +174 -0
  72. package/src/react.d.ts +16 -0
  73. package/src/react.js +16 -0
  74. package/src/roles.d.ts +33 -0
  75. package/src/roles.js +26 -0
  76. package/src/session.d.ts +42 -0
  77. package/src/session.js +37 -0
  78. package/src/shell.d.ts +56 -0
  79. package/src/shell.js +96 -0
  80. package/src/stash.d.ts +26 -0
  81. package/src/stash.js +66 -0
  82. package/src/styles.css +17 -0
@@ -0,0 +1,103 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ /**
3
+ * Version history on the page, for any editor: the panel (`HistoryPanel`
4
+ * from the UI package) on the right, and the frame of a read-only preview
5
+ * of a past version over the editor: its banner (restore it, back to the
6
+ * latest), a pan-and-zoom surface fitted to what the editor draws, Esc to
7
+ * leave.
8
+ *
9
+ * Editor-agnostic: the editor draws
10
+ * the version's content in world px (`renderWorld`) and anything that
11
+ * follows it on screen (`renderOverlay`).
12
+ */
13
+ import { useEffect, useLayoutEffect, useRef, useState } from 'react';
14
+ import { History, Loader2, RotateCcw, X } from 'lucide-react';
15
+ import { Button, ConfirmDialog, HistoryPanel } from '@open-artifact/ui';
16
+ /** The history panel, on the right. */
17
+ export function HistoryAside({ history, viewerId }) {
18
+ const previewing = history.store((s) => s.previewing);
19
+ const capability = history.capability();
20
+ if (!capability)
21
+ return null;
22
+ return (_jsx("aside", { className: "flex w-80 shrink-0 flex-col border-l border-line bg-surface", "aria-label": "Version history", children: _jsx(HistoryPanel, { className: "min-h-0 flex-1", history: capability, viewerId: viewerId, previewing: previewing, onPreview: (n) => void history.preview(n), onClose: () => history.toggle(false) }) }));
23
+ }
24
+ /** Pixels around the fitted content. */
25
+ const FIT_MARGIN = 80;
26
+ /** A camera that shows `rect` whole (at most 100%) in a `w` × `h` viewport. */
27
+ export function fitCamera(rect, w, h, margin = FIT_MARGIN) {
28
+ if (!rect)
29
+ return { x: w / 2, y: h / 2, zoom: 1 };
30
+ const zoom = Math.max(0.02, Math.min(1, (w - margin * 2) / Math.max(1, rect.w), (h - margin * 2) / Math.max(1, rect.h)));
31
+ return { zoom, x: w / 2 - (rect.x + rect.w / 2) * zoom, y: h / 2 - (rect.y + rect.h / 2) * zoom };
32
+ }
33
+ /** The read-only preview of a past version, over the editor. */
34
+ export function VersionPreview({ history, readOnly, bounds, renderWorld, renderOverlay, fitKey, emptyText }) {
35
+ const previewing = history.store((s) => s.previewing);
36
+ const preview = history.store((s) => s.preview);
37
+ const loading = history.store((s) => s.loading);
38
+ const error = history.store((s) => s.error);
39
+ const canRestore = history.store((s) => s.canRestore);
40
+ const root = useRef(null);
41
+ const [camera, setCamera] = useState({ x: 0, y: 0, zoom: 1 });
42
+ const [confirm, setConfirm] = useState(false);
43
+ const fitted = preview ? bounds(preview) : null;
44
+ // Fit when a version arrives.
45
+ useLayoutEffect(() => {
46
+ const element = root.current;
47
+ if (!preview || !element)
48
+ return;
49
+ setCamera(fitCamera(fitted, element.clientWidth, element.clientHeight));
50
+ // `fitted` is derived from `preview` and `fitKey`.
51
+ }, [preview, fitKey]);
52
+ // Wheel pans; Ctrl/⌘ (and pinch) zooms around the pointer.
53
+ useEffect(() => {
54
+ const element = root.current;
55
+ if (!element)
56
+ return;
57
+ const onWheel = (event) => {
58
+ event.preventDefault();
59
+ const unit = event.deltaMode === 1 ? 16 : 1;
60
+ const box = element.getBoundingClientRect();
61
+ setCamera((c) => {
62
+ if (event.ctrlKey || event.metaKey) {
63
+ const zoom = Math.min(8, Math.max(0.02, c.zoom * Math.exp(-event.deltaY * unit * 0.0025)));
64
+ const px = event.clientX - box.left;
65
+ const py = event.clientY - box.top;
66
+ return { zoom, x: px - ((px - c.x) / c.zoom) * zoom, y: py - ((py - c.y) / c.zoom) * zoom };
67
+ }
68
+ return { ...c, x: c.x - event.deltaX * unit, y: c.y - event.deltaY * unit };
69
+ });
70
+ };
71
+ element.addEventListener('wheel', onWheel, { passive: false });
72
+ return () => element.removeEventListener('wheel', onWheel);
73
+ }, [previewing]);
74
+ // Esc goes back to the current version.
75
+ useEffect(() => {
76
+ if (previewing === null)
77
+ return;
78
+ const onKey = (event) => {
79
+ if (event.key === 'Escape' && !confirm) {
80
+ event.stopPropagation();
81
+ void history.preview(null);
82
+ }
83
+ };
84
+ window.addEventListener('keydown', onKey, true);
85
+ return () => window.removeEventListener('keydown', onKey, true);
86
+ }, [previewing, confirm, history]);
87
+ if (previewing === null)
88
+ return null;
89
+ const restorable = canRestore && !readOnly;
90
+ return (_jsxs("div", { className: "absolute inset-0 z-[30] flex flex-col bg-canvas", "aria-label": `Version ${previewing}, read-only`, children: [_jsxs("div", { role: "status", className: "flex h-11 shrink-0 items-center gap-2 border-b border-line bg-surface px-3 text-[13px] text-fg", children: [_jsx(History, { className: "size-4 text-fg-muted" }), _jsxs("span", { className: "font-medium", children: ["Version ", previewing] }), _jsxs("span", { className: "text-fg-muted", children: ["Read-only preview", readOnly ? '' : ' · go back to the latest version to edit'] }), _jsx("span", { className: "flex-1" }), restorable ? (_jsx(Button, { size: "sm", variant: "secondary", icon: _jsx(RotateCcw, { className: "size-3.5" }), onClick: () => setConfirm(true), children: "Restore this version" })) : null, _jsx(Button, { size: "sm", variant: "primary", icon: _jsx(X, { className: "size-3.5" }), onClick: () => void history.preview(null), children: "Back to latest" })] }), _jsx("div", { ref: root, className: "relative min-h-0 flex-1 cursor-grab touch-none select-none overflow-hidden", onPointerDown: (event) => {
91
+ if (event.target.closest('button'))
92
+ return;
93
+ const start = { x: event.clientX, y: event.clientY, camera };
94
+ event.currentTarget.setPointerCapture(event.pointerId);
95
+ const move = (e) => setCamera({ ...start.camera, x: start.camera.x + e.clientX - start.x, y: start.camera.y + e.clientY - start.y });
96
+ const up = () => {
97
+ window.removeEventListener('pointermove', move);
98
+ window.removeEventListener('pointerup', up);
99
+ };
100
+ window.addEventListener('pointermove', move);
101
+ window.addEventListener('pointerup', up);
102
+ }, children: loading || !preview ? (_jsx("div", { className: "absolute inset-0 flex items-center justify-center text-[13px] text-fg-muted", children: error ? `Version ${previewing} could not be read: ${error}` : _jsx(Loader2, { className: "size-5 animate-spin", "aria-label": "Loading the version" }) })) : (_jsxs(_Fragment, { children: [_jsx("div", { className: "absolute left-0 top-0 origin-top-left", style: { transform: `translate(${camera.x}px, ${camera.y}px) scale(${camera.zoom})` }, children: renderWorld(preview) }), renderOverlay?.(preview, camera, previewing, restorable), !fitted ? (_jsx("div", { className: "absolute inset-0 flex items-center justify-center text-[13px] text-fg-subtle", children: emptyText?.(previewing) ?? `Nothing here in version ${previewing}.` })) : null] })) }), _jsx(ConfirmDialog, { open: confirm, onOpenChange: setConfirm, title: `Restore version ${previewing}?`, description: "Every file goes back to how this version left it. The current state stays in the history, so this can be undone by restoring it.", confirmLabel: "Restore", onConfirm: () => void history.restore(previewing) })] }));
103
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Other people (and the agent) for any editor: their pointers, outlines of
3
+ * what they have selected or are editing, in a surface's camera-follow
4
+ * layer; and their avatars.
5
+ *
6
+ * Editor-agnostic: the editor turns
7
+ * its peers' state into world boxes ({@link PeerBox}); these draw them.
8
+ */
9
+ import type { ComponentType, ReactElement, ReactNode } from 'react';
10
+ import { type PeerView } from './presence.ts';
11
+ import { type Box, type Camera } from './pins.ts';
12
+ /** An outline drawn for a peer (or the agent). */
13
+ export interface PeerBox {
14
+ key: string;
15
+ color: string;
16
+ /** World box. */
17
+ rect: Box;
18
+ /** A chip over its top-right corner ("Ana is editing", "Agent edited"). */
19
+ label?: string;
20
+ /** The chip carries the agent's mark, and the outline pulses. */
21
+ agent?: boolean;
22
+ }
23
+ /** Peers' outlines and chips, in screen space. */
24
+ export declare function PeerBoxes({ camera, boxes }: {
25
+ camera: Camera;
26
+ boxes: readonly PeerBox[];
27
+ }): ReactNode;
28
+ /** Peers' pointers with their names, in screen space. `shown` filters peers (another page…). */
29
+ export declare function PeerCursors<S>({ camera, peers, shown }: {
30
+ camera: Camera;
31
+ peers: readonly PeerView<S>[];
32
+ shown?(peer: PeerView<S>): boolean;
33
+ }): ReactNode;
34
+ /** Initials of a name. */
35
+ export declare function initials(name: string): string;
36
+ /** A tooltip component (the editor's own, or the UI package's). */
37
+ export type TipComponent = ComponentType<{
38
+ label: ReactNode;
39
+ children: ReactElement<Record<string, unknown>>;
40
+ }>;
41
+ export interface PresenceAvatarsProps<S> {
42
+ peers: readonly PeerView<S>[];
43
+ /** The agent wrote moments ago (it shows, pulsing, even when it is not a peer). */
44
+ agentWrote: boolean;
45
+ /** What a person's tooltip adds to their name ("editing"). */
46
+ status?(peer: PeerView<S>): string | null;
47
+ /** What the document is called ("design"). */
48
+ noun?: string;
49
+ Tip?: TipComponent;
50
+ }
51
+ /** Avatars of the people and the agent here now. */
52
+ export declare function PresenceAvatars<S>({ peers, agentWrote, status, noun, Tip }: PresenceAvatarsProps<S>): ReactNode;
@@ -0,0 +1,46 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { Bot } from 'lucide-react';
3
+ import { Tooltip, cn } from '@open-artifact/ui';
4
+ import { AGENT_COLOR } from "./presence.js";
5
+ import { screenBox } from "./pins.js";
6
+ /** Peers' outlines and chips, in screen space. */
7
+ export function PeerBoxes({ camera, boxes }) {
8
+ return (_jsx(_Fragment, { children: boxes.map((b) => {
9
+ const s = screenBox(camera, b.rect);
10
+ return (_jsx("div", { className: cn('pointer-events-none absolute rounded-[2px] border-2', b.agent && 'animate-pulse'), style: { ...s, borderColor: b.color }, children: b.label ? (_jsxs("span", { role: "status", className: "absolute -top-6 right-0 flex items-center gap-1 whitespace-nowrap rounded-full px-2 py-0.5 text-[11px] font-medium text-white shadow", style: { background: b.color }, children: [b.agent ? _jsx(Bot, { className: "size-3" }) : null, b.label] })) : null }, b.key));
11
+ }) }));
12
+ }
13
+ /** Peers' pointers with their names, in screen space. `shown` filters peers (another page…). */
14
+ export function PeerCursors({ camera, peers, shown }) {
15
+ return (_jsx(_Fragment, { children: peers.map((peer) => {
16
+ const c = peer.cursor;
17
+ if (!c || (shown && !shown(peer)))
18
+ return null;
19
+ return (_jsxs("div", { className: "pointer-events-none absolute transition-[left,top] duration-75 ease-linear", style: { left: c.x * camera.zoom + camera.x, top: c.y * camera.zoom + camera.y }, "aria-hidden": "true", children: [_jsx("svg", { width: "18", height: "18", viewBox: "0 0 18 18", className: "drop-shadow", children: _jsx("path", { d: "M2 1.5 L15 8.5 L9 10 L6.5 16 Z", fill: peer.color, stroke: "white", strokeWidth: "1.2", strokeLinejoin: "round" }) }), _jsx("span", { className: "absolute left-3.5 top-4 whitespace-nowrap rounded-full px-1.5 py-px text-[11px] font-medium text-white", style: { background: peer.color }, children: peer.name })] }, `cursor:${peer.id}`));
20
+ }) }));
21
+ }
22
+ /** Initials of a name. */
23
+ export function initials(name) {
24
+ const parts = name.trim().split(/\s+/).filter(Boolean);
25
+ return ((parts[0]?.[0] ?? '?') + (parts.length > 1 ? (parts[parts.length - 1][0] ?? '') : '')).toUpperCase();
26
+ }
27
+ function Avatar({ peer, pulse = false }) {
28
+ return (_jsx("span", { className: cn('flex size-6 shrink-0 items-center justify-center rounded-full border-2 border-[var(--color-chrome,white)] text-[10px] font-semibold text-white', pulse && 'animate-pulse'), style: { background: peer.color }, children: peer.kind === 'agent' ? _jsx(Bot, { className: "size-3.5" }) : initials(peer.name) }));
29
+ }
30
+ /** Most avatars drawn before "+n". */
31
+ const MAX_AVATARS = 4;
32
+ /** Avatars of the people and the agent here now. */
33
+ export function PresenceAvatars({ peers, agentWrote, status, noun = 'document', Tip = Tooltip }) {
34
+ const people = peers.filter((p) => p.kind === 'person');
35
+ const agentPeer = peers.find((p) => p.kind === 'agent');
36
+ // The agent shows while it is connected as a peer, and for a moment after it writes.
37
+ const agent = agentPeer ?? (agentWrote ? { name: 'Agent', kind: 'agent', color: AGENT_COLOR } : null);
38
+ if (people.length === 0 && !agent)
39
+ return null;
40
+ const shown = people.slice(0, MAX_AVATARS);
41
+ const more = people.length - shown.length;
42
+ return (_jsx("div", { className: "flex items-center pl-1 pr-0.5", "aria-label": "Here now", children: _jsxs("div", { className: "flex -space-x-1.5", children: [shown.map((peer) => {
43
+ const extra = status?.(peer);
44
+ return (_jsx(Tip, { label: extra ? `${peer.name} · ${extra}` : peer.name, children: _jsx("span", { className: "inline-flex", children: _jsx(Avatar, { peer: peer }) }) }, peer.id));
45
+ }), more > 0 ? (_jsx(Tip, { label: people.slice(MAX_AVATARS).map((p) => p.name).join(', '), children: _jsxs("span", { className: "flex size-6 items-center justify-center rounded-full border-2 border-[var(--color-chrome,white)] bg-chrome-line text-[10px] font-semibold text-chrome-fg", children: ["+", more] }) })) : null, agent ? (_jsx(Tip, { label: agentWrote ? `${agent.name} just changed this ${noun}` : agent.name, children: _jsx("span", { className: "inline-flex", children: _jsx(Avatar, { peer: agent, pulse: agentWrote }) }) })) : null] }) }));
46
+ }
@@ -0,0 +1,148 @@
1
+ import { Menu as BaseMenu } from '@base-ui/react/menu';
2
+ import { clsx as cn } from 'clsx';
3
+ import { type LucideIcon } from 'lucide-react';
4
+ import { type ButtonHTMLAttributes, type CSSProperties, type ReactElement, type ReactNode, type Ref, type TextareaHTMLAttributes } from 'react';
5
+ export { cn };
6
+ export interface CdsRoot {
7
+ /** Popups (tooltips, menus) portal here: inside the shadow root, so the CDS styles reach them. */
8
+ container: HTMLElement | null;
9
+ dark: boolean;
10
+ }
11
+ export declare const CdsRootContext: import("react").Context<CdsRoot>;
12
+ export declare const useCdsRoot: () => CdsRoot;
13
+ /** The focused element in `node`'s tree (its shadow root, or the document), or null. */
14
+ export declare function focusedIn(node: Node): Element | null;
15
+ /**
16
+ * After the current task, unless something took focus meanwhile, focuses the first target still in the page.
17
+ * `root` is the tree the targets live in (taken while the part giving focus back was still attached).
18
+ */
19
+ export declare function returnFocus(root: Document | ShadowRoot, targets: readonly (Element | null | undefined)[]): void;
20
+ /** Merges refs (callback or object). */
21
+ export declare function mergeRefs<T>(...refs: (Ref<T> | undefined | null)[]): (value: T | null) => void;
22
+ /** The icons this UI draws, by name. `filled` ones are drawn solid, with the stroke in the panel's colour. */
23
+ declare const ICONS: {
24
+ X: {
25
+ icon: LucideIcon;
26
+ };
27
+ Check: {
28
+ icon: LucideIcon;
29
+ };
30
+ CheckCircleFilled: {
31
+ icon: LucideIcon;
32
+ filled: true;
33
+ };
34
+ DotsHorizontal: {
35
+ icon: LucideIcon;
36
+ };
37
+ ArrowUp: {
38
+ icon: LucideIcon;
39
+ };
40
+ Edit: {
41
+ icon: LucideIcon;
42
+ };
43
+ Trash: {
44
+ icon: LucideIcon;
45
+ };
46
+ Comment: {
47
+ icon: LucideIcon;
48
+ };
49
+ Info: {
50
+ icon: LucideIcon;
51
+ };
52
+ WarningCircle: {
53
+ icon: LucideIcon;
54
+ };
55
+ CommentFilled: {
56
+ icon: LucideIcon;
57
+ filled: true;
58
+ };
59
+ CaretDown: {
60
+ icon: LucideIcon;
61
+ };
62
+ };
63
+ export type IconName = keyof typeof ICONS;
64
+ export type IconSize = 'xs' | 'sm' | 'md' | 'auto';
65
+ export declare function Icon({ name, size, bold, className, style, }: {
66
+ name: IconName;
67
+ size?: IconSize;
68
+ bold?: boolean;
69
+ className?: string;
70
+ style?: CSSProperties;
71
+ }): import("react/jsx-runtime").JSX.Element;
72
+ export declare const panelClass: (raised: boolean) => string;
73
+ /** The CSS variables a panel surface sets for what is drawn on it (focus rings sit on its colour). */
74
+ export declare function panelVars(dark: boolean): CSSProperties;
75
+ export declare function Tooltip({ content, shortcut, side, multiline, disabled, children, }: {
76
+ content?: ReactNode;
77
+ shortcut?: string;
78
+ side?: 'top' | 'bottom' | 'left' | 'right';
79
+ multiline?: boolean;
80
+ disabled?: boolean;
81
+ children: ReactElement;
82
+ }): import("react/jsx-runtime").JSX.Element;
83
+ export type ButtonVariant = 'primary' | 'secondary' | 'ghost' | 'danger';
84
+ export interface ButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'children'> {
85
+ ref?: Ref<HTMLButtonElement>;
86
+ variant?: ButtonVariant;
87
+ iconOnly?: boolean;
88
+ /** An icon name (drawn at the density's size) or a ready element. */
89
+ icon?: IconName | ReactElement;
90
+ /** Icon-only buttons show their aria-label as a tooltip unless this is false. */
91
+ tooltip?: boolean;
92
+ shortcut?: string;
93
+ busy?: boolean;
94
+ children?: ReactNode;
95
+ }
96
+ export declare function Button({ ref, variant, iconOnly, icon, tooltip, shortcut, busy, className, children, onMouseDown, type, ...rest }: ButtonProps): import("react/jsx-runtime").JSX.Element;
97
+ export declare const MENU_ITEM = "cds-reset flex w-full items-center gap-xs compact:px-2 comfortable:px-2.5 py-[calc((var(--cds-h-control)-var(--cds-leading-body))/2)] rounded text-body font-normal font-control [--cds-shortcut-cap-ink:var(--cds-text-muted)] select-none outline-none focus-visible:outline-hidden data-[disabled]:opacity-disabled data-[disabled]:pointer-events-none data-[disabled]:focus-visible:shadow-focus";
98
+ export interface MenuItemSpec {
99
+ label: string;
100
+ icon?: IconName;
101
+ variant?: 'default' | 'danger';
102
+ separatorBefore?: boolean;
103
+ /** Drawn at the row's end, muted (the header menu's comment count). */
104
+ trailing?: ReactNode;
105
+ onSelect: () => void;
106
+ }
107
+ export declare function MenuItems({ items }: {
108
+ items: readonly MenuItemSpec[];
109
+ }): import("react/jsx-runtime").JSX.Element;
110
+ export declare function MenuPopup({ align, children }: {
111
+ align?: 'start' | 'center' | 'end';
112
+ children: ReactNode;
113
+ }): import("react/jsx-runtime").JSX.Element;
114
+ export { BaseMenu as Menu };
115
+ /** Up to two letters: the first word's and the last word's. */
116
+ export declare function initials(name: string, count?: 1 | 2): string;
117
+ /** A robot head: the agent's avatar. */
118
+ export declare function RobotGlyph(): import("react/jsx-runtime").JSX.Element;
119
+ export declare function Avatar({ name, variant, size, className, }: {
120
+ name: string;
121
+ variant?: 'default' | 'agent';
122
+ size?: 'sm' | 'md';
123
+ className?: string;
124
+ }): import("react/jsx-runtime").JSX.Element;
125
+ export declare function Badge({ children }: {
126
+ children: ReactNode;
127
+ }): import("react/jsx-runtime").JSX.Element;
128
+ export declare function Checkbox({ label, checked, disabled, onCheckedChange, }: {
129
+ label: string;
130
+ checked: boolean;
131
+ disabled?: boolean;
132
+ onCheckedChange: (checked: boolean) => void;
133
+ }): import("react/jsx-runtime").JSX.Element;
134
+ /** The checkbox's box and tick, for a parent with `group/cb` that sets data-checked / data-unchecked (a menu's
135
+ * checkbox item). */
136
+ export declare function CheckboxMark(): import("react/jsx-runtime").JSX.Element;
137
+ export interface PlainEditorProps extends Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, 'onChange' | 'onSubmit' | 'value'> {
138
+ ref?: Ref<HTMLTextAreaElement>;
139
+ value: string;
140
+ onChange: (value: string) => void;
141
+ /** Enter (or ⌘/Ctrl+Enter); Shift+Enter and Alt+Enter add a line. */
142
+ onSubmit?: (value: string, how: {
143
+ modifierKey: boolean;
144
+ }) => void;
145
+ }
146
+ export declare function PlainEditor({ ref, value, onChange, onSubmit, onKeyDown, rows, className, style, ...rest }: PlainEditorProps): import("react/jsx-runtime").JSX.Element;
147
+ /** The field box comment editors sit in. */
148
+ export declare const FIELD_CLASS = "rounded bg-fill-field shadow-field-ring data-[invalid]:shadow-field-invalid px-md py-sm transition duration-fast [&:hover:not(:focus-within):not([data-invalid]):not([data-disabled])]:shadow-field-hover focus-within:shadow-focus data-[invalid]:focus-within:shadow-focus-danger font-sans text-body text-primary";
@@ -0,0 +1,230 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { Checkbox as BaseCheckbox } from '@base-ui/react/checkbox';
3
+ import { Menu as BaseMenu } from '@base-ui/react/menu';
4
+ import { Tooltip as BaseTooltip } from '@base-ui/react/tooltip';
5
+ import { clsx as cn } from 'clsx';
6
+ import { ArrowUp, Check, ChevronDown, CircleAlert, CircleCheck, Ellipsis, Info, MessageCircle, Pencil, Trash2, X, } from 'lucide-react';
7
+ import { createContext, useContext, useLayoutEffect, useRef, } from 'react';
8
+ export { cn };
9
+ export const CdsRootContext = createContext({ container: null, dark: false });
10
+ export const useCdsRoot = () => useContext(CdsRootContext);
11
+ // ---------- focus, in a tree that may be a shadow root ----------
12
+ /** The focused element in `node`'s tree (its shadow root, or the document), or null. */
13
+ export function focusedIn(node) {
14
+ const root = node.getRootNode();
15
+ const active = root.activeElement ?? null;
16
+ return active && active !== node.ownerDocument?.body ? active : null;
17
+ }
18
+ /** Whether anything has focus: inside the layer, or on the page around it. */
19
+ function focusTaken(root) {
20
+ const doc = 'host' in root ? root.host.ownerDocument : root;
21
+ const outer = doc.activeElement;
22
+ if ('host' in root && outer === root.host)
23
+ return root.activeElement !== null;
24
+ return outer !== null && outer !== doc.body;
25
+ }
26
+ /**
27
+ * After the current task, unless something took focus meanwhile, focuses the first target still in the page.
28
+ * `root` is the tree the targets live in (taken while the part giving focus back was still attached).
29
+ */
30
+ export function returnFocus(root, targets) {
31
+ queueMicrotask(() => {
32
+ if (focusTaken(root))
33
+ return;
34
+ for (const target of targets) {
35
+ if (!(target instanceof HTMLElement) || !target.isConnected)
36
+ continue;
37
+ target.focus({ preventScroll: true });
38
+ if (root.activeElement === target)
39
+ return;
40
+ }
41
+ });
42
+ }
43
+ /** Merges refs (callback or object). */
44
+ export function mergeRefs(...refs) {
45
+ return value => {
46
+ for (const ref of refs) {
47
+ if (typeof ref === 'function')
48
+ ref(value);
49
+ else if (ref)
50
+ ref.current = value;
51
+ }
52
+ };
53
+ }
54
+ // ---------- Icon (lucide) ----------
55
+ /** The icons this UI draws, by name. `filled` ones are drawn solid, with the stroke in the panel's colour. */
56
+ const ICONS = {
57
+ X: { icon: X },
58
+ Check: { icon: Check },
59
+ CheckCircleFilled: { icon: CircleCheck, filled: true },
60
+ DotsHorizontal: { icon: Ellipsis },
61
+ ArrowUp: { icon: ArrowUp },
62
+ Edit: { icon: Pencil },
63
+ Trash: { icon: Trash2 },
64
+ Comment: { icon: MessageCircle },
65
+ Info: { icon: Info },
66
+ WarningCircle: { icon: CircleAlert },
67
+ CommentFilled: { icon: MessageCircle, filled: true },
68
+ CaretDown: { icon: ChevronDown },
69
+ };
70
+ /** Box size (px at a 16px root) and stroke width (in the 24-unit icon grid) by size; bold thickens it. */
71
+ const ICON_SIZES = {
72
+ xs: { px: 12, stroke: 2.25, strong: 2.75 },
73
+ sm: { px: 16, stroke: 1.75, strong: 2.5 },
74
+ md: { px: 20, stroke: 1.6, strong: 2.25 },
75
+ };
76
+ export function Icon({ name, size = 'auto', bold = false, className, style, }) {
77
+ // `auto` follows the density; this UI is always comfortable.
78
+ const spec = ICON_SIZES[size === 'auto' ? 'md' : size];
79
+ const { icon: Glyph, filled = false } = ICONS[name];
80
+ return (_jsx("span", { "data-cds": "Icon", "aria-hidden": true, className: className, style: { fontSize: `calc(${spec.px / 16}rem * var(--cds-rem-scale,1))`, ...style }, children: _jsx(Glyph, { "aria-hidden": true, focusable: false, strokeWidth: bold ? spec.strong : spec.stroke, ...(filled ? { fill: 'currentColor', stroke: 'var(--cds-page-bg, Canvas)' } : {}) }) }));
81
+ }
82
+ // ---------- Surface (panel) ----------
83
+ export const panelClass = (raised) => `rounded-card bg-surface-2 ${raised ? 'shadow-panel' : 'shadow-panel-sm'} forced-colors:border forced-colors:border-solid forced-colors:border-[color:CanvasText]`;
84
+ /** The CSS variables a panel surface sets for what is drawn on it (focus rings sit on its colour). */
85
+ export function panelVars(dark) {
86
+ const glow = (role) => `0 0 0 3px color-mix(in srgb, var(--cds-fill-${role}) ${dark ? 40 : 28}%, transparent)`;
87
+ return {
88
+ '--cds-page-bg': 'var(--cds-surface-2)',
89
+ '--cds-focus-shadow': `inset 0 0 0 1px var(--cds-page-bg), 0 0 0 1px var(--cds-fill-accent), ${glow('accent')}`,
90
+ '--cds-focus-shadow-danger': `inset 0 0 0 1px var(--cds-page-bg), 0 0 0 1px var(--cds-fill-danger), ${glow('danger')}`,
91
+ };
92
+ }
93
+ // ---------- Tooltip ----------
94
+ const TOOLTIP_POPUP = 'px-2 rounded-[calc(0.375rem*var(--cds-rem-scale,1))] bg-[var(--cds-tooltip-bg)] text-[var(--cds-tooltip-fg)] shadow-sm dark:shadow-panel-sm print:hidden text-[calc(0.8125rem*var(--cds-rem-scale,1))]/[calc(1.125rem*var(--cds-rem-scale,1))] font-normal origin-[var(--transform-origin)] transition-[opacity,scale] duration-snap ease-snap motion-reduce:transition-none data-[starting-style]:opacity-0 data-[starting-style]:scale-[0.98] data-[ending-style]:opacity-0 data-[ending-style]:scale-[0.98] data-[instant]:duration-0';
95
+ const TOOLTIP_SINGLE = 'inline-flex items-center gap-2 min-h-[calc(1.5rem*var(--cds-rem-scale,1))] max-w-[240px] py-[calc(0.1875rem*var(--cds-rem-scale,1))]';
96
+ const TOOLTIP_MULTI = 'flex flex-col gap-0.5 max-w-[240px] whitespace-normal py-1.5';
97
+ const SHORTCUT_TEXT = 'text-[calc(0.75rem*var(--cds-rem-scale,1))] [--cds-shortcut-cap-ink:var(--cds-text-muted)] self-start';
98
+ const SHORTCUT_GLYPHS = { enter: '↵', 'cmd+enter': '⌘↵', escape: 'Esc' };
99
+ export function Tooltip({ content, shortcut, side = 'top', multiline = false, disabled = false, children, }) {
100
+ const { container } = useCdsRoot();
101
+ if (content === undefined || content === null || content === '' || content === false)
102
+ return children;
103
+ return (_jsxs(BaseTooltip.Root, { disabled: disabled, children: [_jsx(BaseTooltip.Trigger, { delay: 300, render: children }), _jsx(BaseTooltip.Portal, { container: container, children: _jsx(BaseTooltip.Positioner, { side: side, sideOffset: 4, positionMethod: "fixed", "data-cds": "Tooltip", className: "data-[anchor-hidden]:invisible", children: _jsxs(BaseTooltip.Popup, { className: cn(TOOLTIP_POPUP, multiline ? TOOLTIP_MULTI : TOOLTIP_SINGLE, !shortcut && 'text-balance'), children: [_jsx("span", { className: "min-w-0 break-words", children: content }), shortcut && _jsx("span", { className: SHORTCUT_TEXT, children: SHORTCUT_GLYPHS[shortcut] ?? shortcut })] }) }) })] }));
104
+ }
105
+ const FOCUS = 'focus-visible:shadow-focus [&[data-initial-focus]:focus]:shadow-focus';
106
+ const FOCUS_DANGER = 'focus-visible:shadow-focus-danger [&[data-initial-focus]:focus]:shadow-focus-danger';
107
+ const BUTTON_BASE = 'cds-reset group/btn relative isolate inline-flex shrink-0 items-center justify-center gap-1.5 whitespace-nowrap select-none cursor-[var(--cds-cursor-interactive)] aria-disabled:cursor-default data-[disabled]:cursor-default border-0 outline-none focus-visible:outline-hidden [&[data-initial-focus]:focus]:outline-hidden rounded h-control font-sans text-body [&:disabled:not([aria-busy])]:opacity-disabled disabled:pointer-events-none transition-shadow duration-fast';
108
+ const BUTTON_VARIANT = {
109
+ primary: `text-on-primary font-medium font-control [--cds-shortcut-cap-ink:currentColor] ${FOCUS}`,
110
+ secondary: `text-primary font-normal font-control aria-pressed:text-accent ${FOCUS}`,
111
+ ghost: `text-primary font-normal font-control aria-pressed:text-accent ${FOCUS}`,
112
+ danger: `text-on-danger font-medium font-control [--cds-shortcut-cap-ink:currentColor] ${FOCUS_DANGER}`,
113
+ };
114
+ const PAINT_BASE = 'absolute inset-0 rounded-[inherit] transition-[background-color,box-shadow,color] duration-fast ease-out group-focus-visible/btn:shadow-[inset_0_0_0_1px_var(--cds-page-bg)] group-[[data-initial-focus]:focus]/btn:shadow-[inset_0_0_0_1px_var(--cds-page-bg)]';
115
+ const PAINT_VARIANT = {
116
+ primary: 'bg-fill-primary group-hover/btn:bg-fill-primary-hover group-[[aria-haspopup][aria-expanded=true]]/btn:bg-fill-primary-hover',
117
+ secondary: 'bg-fill-secondary group-hover/btn:bg-fill-secondary-hover group-[[aria-haspopup][aria-expanded=true]]/btn:bg-fill-secondary-hover',
118
+ ghost: 'bg-transparent group-hover/btn:bg-fill-ghost-hover group-[[aria-haspopup][aria-expanded=true]]/btn:bg-fill-ghost-hover',
119
+ danger: 'bg-fill-danger group-hover/btn:bg-fill-danger-hover group-[[aria-haspopup][aria-expanded=true]]/btn:bg-fill-danger-hover',
120
+ };
121
+ const PAINT_PRESSED = 'group-aria-pressed/btn:bg-tint-blue group-hover/btn:group-aria-pressed/btn:bg-tint-blue';
122
+ const PAINT_FIELD = 'shadow-field group-aria-pressed/btn:shadow-field-pressed group-focus-visible/btn:group-aria-pressed/btn:shadow-[inset_0_0_0_1px_var(--cds-page-bg)]';
123
+ export function Button({ ref, variant = 'secondary', iconOnly = false, icon, tooltip = true, shortcut, busy = false, className, children, onMouseDown, type = 'button', ...rest }) {
124
+ const solid = variant === 'primary' || variant === 'danger';
125
+ const field = variant === 'secondary';
126
+ const iconEl = typeof icon === 'string' ? _jsx(Icon, { name: icon }) : icon;
127
+ const button = (_jsxs("button", { ref: ref, type: type, "data-cds": "Button", "data-cds-icon-only": iconOnly || undefined, "data-cds-ghost": variant === 'ghost' || undefined, "aria-busy": busy || undefined, ...rest, className: cn(BUTTON_BASE, BUTTON_VARIANT[variant], iconOnly ? 'aspect-square w-control px-0' : 'px-md', className), onMouseDown: event => {
128
+ onMouseDown?.(event);
129
+ // A double click on a button never selects the text around it.
130
+ if (event.detail > 1)
131
+ event.preventDefault();
132
+ }, children: [_jsx("span", { "aria-hidden": true, className: `absolute -z-[1] rounded-[inherit] ${solid ? 'inset-[0.5px]' : 'inset-0'} cds-btn-squish`, children: _jsx("span", { "data-cds-part": "paint", className: cn(PAINT_BASE, PAINT_VARIANT[variant], PAINT_PRESSED, field && PAINT_FIELD) }) }), _jsx("span", { className: "inline-flex min-w-0 items-center gap-1", children: iconOnly ? (iconEl) : (_jsxs(_Fragment, { children: [iconEl && _jsx("span", { className: "-ms-1 inline-flex", children: iconEl }), children] })) })] }));
133
+ const label = rest['aria-label'];
134
+ return iconOnly && label && tooltip ? (_jsx(Tooltip, { content: label, shortcut: shortcut, children: button })) : (button);
135
+ }
136
+ // ---------- Menu ----------
137
+ const MENU_POPUP = 'cds-reset draggable-none group/menu-popup relative flex flex-col min-w-[128px] max-w-[320px] max-h-[var(--available-height)] bg-surface-3 shadow-panel text-body font-normal text-primary outline-none focus-visible:outline-hidden rounded-[calc(var(--cds-radius)+var(--cds-menu-gutter,calc(0.25rem*var(--cds-rem-scale,1))))]';
138
+ const MENU_SCROLL = 'relative min-h-0 overflow-y-auto overflow-x-hidden scroll-fade-y rounded-[inherit] border-b-[length:var(--cds-ring-inner)] border-transparent forced-colors:border-b-0 p-[var(--cds-menu-gutter,0.25rem)]';
139
+ export const MENU_ITEM = 'cds-reset flex w-full items-center gap-xs compact:px-2 comfortable:px-2.5 py-[calc((var(--cds-h-control)-var(--cds-leading-body))/2)] rounded text-body font-normal font-control [--cds-shortcut-cap-ink:var(--cds-text-muted)] select-none outline-none focus-visible:outline-hidden data-[disabled]:opacity-disabled data-[disabled]:pointer-events-none data-[disabled]:focus-visible:shadow-focus';
140
+ const MENU_ITEM_VARIANT = {
141
+ default: 'text-primary data-[highlighted]:bg-fill-ghost-hover',
142
+ danger: 'group/menu-danger text-danger data-[highlighted]:bg-fill-danger data-[highlighted]:text-on-danger data-[highlighted]:[--cds-shortcut-cap-ink:currentColor]',
143
+ };
144
+ export function MenuItems({ items }) {
145
+ return (_jsx(_Fragment, { children: items.map((item, i) => (_jsxs("div", { className: "contents", children: [item.separatorBefore && _jsx(BaseMenu.Separator, { className: "compact:mx-2 comfortable:mx-2.5 my-1 h-px bg-border" }), _jsxs(BaseMenu.Item, { className: cn(MENU_ITEM, MENU_ITEM_VARIANT[item.variant ?? 'default']), "data-cds-icon-row": item.icon ? '' : undefined, onClick: item.onSelect, children: [item.icon && (_jsx("span", { className: "flex size-icon shrink-0 items-center justify-center", children: _jsx(Icon, { name: item.icon, size: "auto" }) })), _jsx("span", { className: "min-w-0 flex-1 truncate", children: item.label }), item.trailing != null && _jsx("span", { className: "shrink-0 ps-4 text-muted tabular-nums", children: item.trailing })] })] }, i))) }));
146
+ }
147
+ export function MenuPopup({ align = 'center', children }) {
148
+ const { container } = useCdsRoot();
149
+ const popup = useRef(null);
150
+ // On close, focus goes back to the trigger unless it already moved on (an edit box took it).
151
+ const finalFocus = () => {
152
+ const el = popup.current;
153
+ const active = el ? focusedIn(el) : null;
154
+ return !(active && el && !el.contains(active));
155
+ };
156
+ return (_jsx(BaseMenu.Portal, { container: container, children: _jsx(BaseMenu.Positioner, { side: "bottom", align: align, sideOffset: 6, positionMethod: "fixed", children: _jsx(BaseMenu.Popup, { ref: popup, finalFocus: finalFocus, "data-cds": "Menu", className: MENU_POPUP, children: _jsx("div", { className: MENU_SCROLL, children: children }) }) }) }));
157
+ }
158
+ export { BaseMenu as Menu };
159
+ // ---------- Avatar ----------
160
+ const AVATAR_BASE = 'inline-flex shrink-0 select-none items-center justify-center overflow-hidden rounded-full font-sans font-medium leading-none';
161
+ const AVATAR_SIZE = {
162
+ sm: 'size-[var(--cds-avatar-sm)] text-[calc(0.5625rem*var(--cds-rem-scale,1))]',
163
+ md: 'size-[var(--cds-avatar-md)] text-footnote',
164
+ };
165
+ /** Up to two letters: the first word's and the last word's. */
166
+ export function initials(name, count = 2) {
167
+ const words = name.trim().split(/\s+/);
168
+ const first = (word) => (word ? ([...word][0] ?? '') : '');
169
+ return (first(words[0]) + (count === 2 && words.length > 1 ? first(words[words.length - 1]) : '')).toLocaleUpperCase() || '?';
170
+ }
171
+ /** A robot head: the agent's avatar. */
172
+ export function RobotGlyph() {
173
+ return (_jsxs("svg", { viewBox: "0 0 16 16", width: "60%", height: "60%", fill: "none", stroke: "currentColor", strokeWidth: 1.3, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": true, children: [_jsx("rect", { x: "3", y: "5.5", width: "10", height: "7.5", rx: "2" }), _jsx("path", { d: "M8 5.5V3.3" }), _jsx("circle", { cx: "8", cy: "2.6", r: ".7", fill: "currentColor", stroke: "none" }), _jsx("circle", { cx: "6.1", cy: "8.9", r: "1", fill: "currentColor", stroke: "none" }), _jsx("circle", { cx: "9.9", cy: "8.9", r: "1", fill: "currentColor", stroke: "none" }), _jsx("path", { d: "M6.6 11.1h2.8M1.5 8.5v2M14.5 8.5v2" })] }));
174
+ }
175
+ export function Avatar({ name, variant = 'default', size = 'sm', className, }) {
176
+ return (_jsx("span", { "data-cds": "Avatar", role: "img", "aria-label": name, className: cn(AVATAR_BASE, AVATAR_SIZE[size], variant === 'agent' ? 'bg-fill-brand text-on-brand' : 'bg-fill-control text-primary', className), children: variant === 'agent' ? _jsx(RobotGlyph, {}) : initials(name) }));
177
+ }
178
+ // ---------- Badge (the accent one: the composer's @agent mention) ----------
179
+ export function Badge({ children }) {
180
+ return (_jsx("span", { "data-cds": "Badge", className: "inline-flex items-center gap-1 align-middle h-control-nested whitespace-nowrap rounded-chip px-sm font-sans text-caption font-medium font-badge leading-[round(1.25em,1px)] shrink-0 bg-tint-blue text-accent", children: _jsx("span", { className: "leading-[calc(0.75rem*var(--cds-rem-scale,1))] py-[0.125em] -my-[0.125em]", children: children }) }));
181
+ }
182
+ // ---------- Checkbox ----------
183
+ const CHECKBOX_ROOT = 'cds-reset group/cb border-0 outline-none focus-visible:outline-hidden data-[disabled]:opacity-disabled inline-flex gap-xs text-start font-sans text-body font-normal text-primary items-start';
184
+ const CHECKBOX_BOX = 'flex shrink-0 size-[var(--cds-checkbox)] items-center justify-center rounded-[var(--cds-checkbox-radius)] border border-strong bg-transparent group-data-[unchecked]/cb:group-hover/cb:border-stronger group-data-[checked]/cb:bg-fill-accent group-data-[checked]/cb:border-transparent group-data-[indeterminate]/cb:bg-fill-accent group-data-[indeterminate]/cb:border-transparent group-data-[checked]/cb:group-hover/cb:bg-fill-accent-hover group-data-[indeterminate]/cb:group-hover/cb:bg-fill-accent-hover group-data-[disabled]/cb:group-data-[unchecked]/cb:group-hover/cb:border-strong group-focus-visible/cb:shadow-focus mt-[calc((1lh_-_var(--cds-checkbox,1rem))_/_2)]';
185
+ const CHECKBOX_GLYPH = 'text-on-accent [clip-path:inset(0_100%_0_0)] group-data-[checked]/cb:[clip-path:inset(0)] group-data-[indeterminate]/cb:[clip-path:inset(0)]';
186
+ export function Checkbox({ label, checked, disabled = false, onCheckedChange, }) {
187
+ return (_jsxs(BaseCheckbox.Root, { "data-cds": "Checkbox", "data-size": "sm", checked: checked, disabled: disabled, onCheckedChange: value => onCheckedChange(value === true), className: CHECKBOX_ROOT, children: [_jsx(CheckboxMark, {}), _jsx("span", { children: label })] }));
188
+ }
189
+ /** The checkbox's box and tick, for a parent with `group/cb` that sets data-checked / data-unchecked (a menu's
190
+ * checkbox item). */
191
+ export function CheckboxMark() {
192
+ return (_jsx("span", { className: CHECKBOX_BOX, children: _jsx("span", { className: CHECKBOX_GLYPH, children: _jsx(Icon, { name: "Check", size: "sm", bold: true, style: { fontSize: 'var(--cds-checkbox-glyph)' } }) }) }));
193
+ }
194
+ // ---------- TextArea (bare) / PlainEditor ----------
195
+ const supportsFieldSizing = () => typeof CSS !== 'undefined' && CSS.supports?.('field-sizing', 'content') === true;
196
+ export function PlainEditor({ ref, value, onChange, onSubmit, onKeyDown, rows = 1, className, style, ...rest }) {
197
+ const own = useRef(null);
198
+ // Browsers without `field-sizing: content` grow the box by hand.
199
+ useLayoutEffect(() => {
200
+ const el = own.current;
201
+ if (!el || supportsFieldSizing())
202
+ return;
203
+ el.style.height = '0px';
204
+ el.style.height = `${el.scrollHeight + (el.offsetHeight - el.clientHeight)}px`;
205
+ }, [value]);
206
+ const keyDown = (event) => {
207
+ onKeyDown?.(event);
208
+ if (event.defaultPrevented || event.currentTarget.readOnly || !onSubmit || event.key !== 'Enter')
209
+ return;
210
+ const native = event.nativeEvent;
211
+ if (event.altKey && !event.shiftKey && !event.ctrlKey && !event.metaKey && !native.isComposing) {
212
+ event.preventDefault();
213
+ const el = event.currentTarget;
214
+ const doc = el.ownerDocument;
215
+ if (!(typeof doc.execCommand === 'function' && doc.execCommand('insertText', false, '\n'))) {
216
+ el.setRangeText('\n', el.selectionStart, el.selectionEnd, 'end');
217
+ onChange(el.value);
218
+ }
219
+ return;
220
+ }
221
+ if (event.shiftKey || event.altKey || native.isComposing || native.keyCode === 229)
222
+ return;
223
+ event.preventDefault();
224
+ onSubmit(event.currentTarget.value, { modifierKey: event.metaKey || event.ctrlKey });
225
+ };
226
+ const hasMinHeight = /(^|\s)min-h-/.test(className ?? '');
227
+ return (_jsx("textarea", { ref: mergeRefs(own, ref), "data-cds": "PlainEditor", rows: rows, value: value, onChange: event => onChange(event.target.value), onKeyDown: keyDown, style: { ...style, '--cds-textarea-rows': rows }, ...rest, className: cn('cds-reset w-full block resize-none border-0 bg-transparent p-0 shadow-none', 'font-sans text-body text-primary placeholder:text-muted outline-none focus-visible:outline-hidden disabled:opacity-disabled', '[field-sizing:content]', !hasMinHeight && 'min-h-[calc(var(--cds-textarea-rows)*1lh)]', className) }));
228
+ }
229
+ /** The field box comment editors sit in. */
230
+ export const FIELD_CLASS = 'rounded bg-fill-field shadow-field-ring data-[invalid]:shadow-field-invalid px-md py-sm transition duration-fast [&:hover:not(:focus-within):not([data-invalid]):not([data-disabled])]:shadow-field-hover focus-within:shadow-focus data-[invalid]:focus-within:shadow-focus-danger font-sans text-body text-primary';