@openartifactsai/ui 0.0.0-stage → 0.23.0-rc.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 (91) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +5 -0
  3. package/README.md +5 -2
  4. package/package.json +82 -4
  5. package/src/button.d.ts +30 -0
  6. package/src/button.js +29 -0
  7. package/src/clicks.d.ts +63 -0
  8. package/src/clicks.js +75 -0
  9. package/src/cn.d.ts +3 -0
  10. package/src/cn.js +5 -0
  11. package/src/color-picker.d.ts +98 -0
  12. package/src/color-picker.js +395 -0
  13. package/src/color.d.ts +150 -0
  14. package/src/color.js +543 -0
  15. package/src/crash-boundary.d.ts +29 -0
  16. package/src/crash-boundary.js +32 -0
  17. package/src/data/google-fonts.json +1775 -0
  18. package/src/drag-cover.d.ts +48 -0
  19. package/src/drag-cover.js +41 -0
  20. package/src/effect-editors.d.ts +48 -0
  21. package/src/effect-editors.js +230 -0
  22. package/src/effects.d.ts +118 -0
  23. package/src/effects.js +425 -0
  24. package/src/escape-to-popup.d.ts +53 -0
  25. package/src/escape-to-popup.js +78 -0
  26. package/src/field-announce.d.ts +28 -0
  27. package/src/field-announce.js +43 -0
  28. package/src/fields.d.ts +176 -0
  29. package/src/fields.js +377 -0
  30. package/src/focusables.d.ts +50 -0
  31. package/src/focusables.js +61 -0
  32. package/src/font-picker.d.ts +62 -0
  33. package/src/font-picker.js +242 -0
  34. package/src/fonts.d.ts +121 -0
  35. package/src/fonts.js +273 -0
  36. package/src/history-diff.d.ts +64 -0
  37. package/src/history-diff.js +151 -0
  38. package/src/history.d.ts +95 -0
  39. package/src/history.js +160 -0
  40. package/src/index.d.ts +38 -0
  41. package/src/index.js +38 -0
  42. package/src/key-chord.d.ts +74 -0
  43. package/src/key-chord.js +228 -0
  44. package/src/keys.d.ts +142 -0
  45. package/src/keys.js +172 -0
  46. package/src/layout.d.ts +74 -0
  47. package/src/layout.js +173 -0
  48. package/src/link-card-view.d.ts +97 -0
  49. package/src/link-card-view.js +175 -0
  50. package/src/link-card.d.ts +136 -0
  51. package/src/link-card.js +158 -0
  52. package/src/menu-shortcuts.d.ts +31 -0
  53. package/src/menu-shortcuts.js +91 -0
  54. package/src/menu.d.ts +120 -0
  55. package/src/menu.js +100 -0
  56. package/src/number-entry.d.ts +140 -0
  57. package/src/number-entry.js +202 -0
  58. package/src/number-limits.d.ts +2 -0
  59. package/src/number-limits.js +2 -0
  60. package/src/number-wheel.d.ts +29 -0
  61. package/src/number-wheel.js +27 -0
  62. package/src/numbers.d.ts +28 -0
  63. package/src/numbers.js +124 -0
  64. package/src/overlays.d.ts +71 -0
  65. package/src/overlays.js +131 -0
  66. package/src/pressed.d.ts +5 -0
  67. package/src/pressed.js +10 -0
  68. package/src/scroll.d.ts +24 -0
  69. package/src/scroll.js +111 -0
  70. package/src/scrub-number-field.d.ts +79 -0
  71. package/src/scrub-number-field.js +254 -0
  72. package/src/select-announce.d.ts +50 -0
  73. package/src/select-announce.js +71 -0
  74. package/src/slider-session.d.ts +43 -0
  75. package/src/slider-session.js +39 -0
  76. package/src/styles.css +96 -0
  77. package/src/tab-strip-layout.d.ts +76 -0
  78. package/src/tab-strip-layout.js +111 -0
  79. package/src/tab-strip.d.ts +73 -0
  80. package/src/tab-strip.js +498 -0
  81. package/src/text-area-view.d.ts +35 -0
  82. package/src/text-area-view.js +142 -0
  83. package/src/text-area.d.ts +38 -0
  84. package/src/text-area.js +51 -0
  85. package/src/theme.css +34 -0
  86. package/src/toast-fit.d.ts +21 -0
  87. package/src/toast-fit.js +30 -0
  88. package/src/toast-tone.d.ts +27 -0
  89. package/src/toast-tone.js +22 -0
  90. package/src/tooltip.d.ts +23 -0
  91. package/src/tooltip.js +18 -0
package/src/keys.d.ts ADDED
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Keyboard guards shared by the kit's controls.
3
+ *
4
+ * A key held down auto-repeats: without a guard, holding Enter on a button,
5
+ * a menu row that keeps its menu open or a switch presses it again and again,
6
+ * and a press that moves focus (closing a toast, opening a dialog) lands the
7
+ * repeats on whatever gets focus next.
8
+ */
9
+ /** The fields of a keyboard event the guards read. */
10
+ export interface KeyLike {
11
+ key: string;
12
+ repeat: boolean;
13
+ }
14
+ /** The fields of a keyboard event that tell an input method is composing. */
15
+ export interface ComposingLike {
16
+ isComposing?: boolean;
17
+ keyCode?: number;
18
+ }
19
+ /**
20
+ * True while an input method composes (Chinese, Japanese, Korean…): the
21
+ * Enter or Escape it sees picks or drops the candidate, so a field must not
22
+ * also commit or cancel on it. Safari reports the end of a composition as
23
+ * key code 229 with `isComposing` already false.
24
+ */
25
+ export declare function isComposingKey(event: ComposingLike): boolean;
26
+ /** True for an auto-repeated Enter or Space. */
27
+ export declare function isRepeatedActivation(event: KeyLike): boolean;
28
+ /** A keydown event as the guards see it. */
29
+ export type GuardedKeyEvent = KeyLike & {
30
+ target: unknown;
31
+ currentTarget: unknown;
32
+ preventDefault(): void;
33
+ };
34
+ /**
35
+ * A keydown handler that keeps a held Enter or Space from pressing the
36
+ * focused control again: the repeats have their default (the native click,
37
+ * or Base UI's activation) prevented.
38
+ */
39
+ export declare function preventRepeatedActivation(event: GuardedKeyEvent): void;
40
+ /**
41
+ * Wraps a keydown handler so a held Enter or Space presses the control once:
42
+ * the repeats have their default (the native click, or Base UI's activation)
43
+ * prevented. The wrapped handler still runs (and sees `defaultPrevented`).
44
+ */
45
+ export declare function withRepeatGuard<E extends GuardedKeyEvent>(handler?: (event: E) => void): (event: E) => void;
46
+ /** The parts of a window {@link guardHeldActivation} listens on. */
47
+ export interface KeyGuardWindow {
48
+ addEventListener(type: 'keydown' | 'keyup', listener: (event: KeyGuardEvent) => void, capture: boolean): void;
49
+ removeEventListener(type: 'keydown' | 'keyup', listener: (event: KeyGuardEvent) => void, capture: boolean): void;
50
+ setTimeout(callback: () => void, ms: number): number;
51
+ clearTimeout(id: number): void;
52
+ }
53
+ /** The parts of a keyboard event {@link guardHeldActivation} reads. */
54
+ export interface KeyGuardEvent extends KeyLike {
55
+ type: string;
56
+ target: unknown;
57
+ preventDefault(): void;
58
+ stopImmediatePropagation(): void;
59
+ }
60
+ /** How long the guard stays after the first key is released. */
61
+ export declare const HELD_KEY_SETTLE_MS = 200;
62
+ /** The guard never lasts longer than this. */
63
+ export declare const HELD_KEY_GUARD_MAX_MS = 2000;
64
+ /**
65
+ * After an Enter or Space press that closes something (a toast's close
66
+ * button), keeps the activation keys from pressing what gets focus next:
67
+ * until the pressed key is released, plus a short settle, Enter and Space
68
+ * keydowns outside `isInside` are swallowed at the window, and so are Space
69
+ * keyups (a native button acts on Space's keyup). Lasts at most 2 s.
70
+ * Returns a function that ends the guard early.
71
+ */
72
+ export declare function guardHeldActivation(win: KeyGuardWindow, firstKey: string, isInside: (target: unknown) => boolean): () => void;
73
+ /** The parts of a window {@link guardComposingKeys} listens on. */
74
+ export interface ComposingGuardWindow {
75
+ addEventListener(type: 'keydown', listener: (event: ComposingGuardEvent) => void, capture: boolean): void;
76
+ removeEventListener(type: 'keydown', listener: (event: ComposingGuardEvent) => void, capture: boolean): void;
77
+ }
78
+ /** The parts of a keydown {@link guardComposingKeys} reads. */
79
+ export interface ComposingGuardEvent extends ComposingLike {
80
+ key: string;
81
+ target: unknown;
82
+ stopImmediatePropagation(): void;
83
+ }
84
+ /** The keys an input method uses to pick, drop or move between candidates. */
85
+ export declare const COMPOSING_COMMIT_KEYS: readonly string[];
86
+ /**
87
+ * Keeps the page's shortcuts off the keys an input method composes with:
88
+ * an Enter, Escape or Tab pressed while it composes (see {@link isComposingKey})
89
+ * is stopped at the window, before any other handler sees it, so it only
90
+ * picks or drops the candidate. Its default is left alone. Keys inside
91
+ * `skip` (a rich-text editor that reads composition itself) pass. Returns a
92
+ * function that removes the guard.
93
+ */
94
+ export declare function guardComposingKeys(win: ComposingGuardWindow, skip?: string): () => void;
95
+ /** The fields of a keyboard event {@link shortcutLetter} reads. */
96
+ export interface ShortcutKeyLike {
97
+ key: string;
98
+ code?: string;
99
+ }
100
+ /**
101
+ * The letter a shortcut means, lower-cased. A Latin letter is taken as typed,
102
+ * so remapped layouts (Dvorak, AZERTY) keep their own letters; any other
103
+ * character (Cyrillic, Greek, a symbol the Option key makes) falls back to the
104
+ * physical key, so ⌘S still saves on a Russian layout. Keys that are not
105
+ * letters (`Escape`, `Enter`) come back lower-cased.
106
+ */
107
+ export declare function shortcutLetter(event: ShortcutKeyLike): string;
108
+ /** The fields of a keydown {@link isSelectAllLetter} reads. */
109
+ export interface SelectAllKeyLike {
110
+ key: string;
111
+ code?: string;
112
+ }
113
+ /**
114
+ * True when the key is the A of Select All (with ⌘ or Ctrl, which the caller checks): an ASCII key must be "a"; a
115
+ * layout that types another single character there (Cyrillic ф), or a key the browser can't name (`Dead`,
116
+ * `Unidentified`), counts by the physical KeyA. Named keys (`Enter`…) never do.
117
+ */
118
+ export declare function isSelectAllLetter(event: SelectAllKeyLike): boolean;
119
+ /**
120
+ * A dangerous confirmation ignores Enter and Space while it appears, so the
121
+ * press that opened it (a held Enter or Delete) can't confirm it too. The
122
+ * window runs from opening until the dialog has been fully shown for
123
+ * {@link EARLY_PRESS_SETTLE_MS}, and never past {@link EARLY_PRESS_MAX_MS}.
124
+ */
125
+ export declare const EARLY_PRESS_SETTLE_MS = 300;
126
+ /** The early-press window never lasts longer than this after opening. */
127
+ export declare const EARLY_PRESS_MAX_MS = 3000;
128
+ /** When a guarded dialog opened and when it was fully shown (`null`: still appearing). */
129
+ export interface EarlyPressTimes {
130
+ opened: number;
131
+ shown: number | null;
132
+ }
133
+ /** The time the early-press window closes. */
134
+ export declare function earlyPressEnds(times: EarlyPressTimes): number;
135
+ /**
136
+ * True when a key event must not activate anything in a guarded dialog: an
137
+ * Enter or Space from the user (synthetic events pass) inside the window, or
138
+ * an auto-repeat at any time.
139
+ */
140
+ export declare function blocksEarlyPress(times: EarlyPressTimes, now: number, event: KeyLike & {
141
+ isTrusted?: boolean;
142
+ }): boolean;
package/src/keys.js ADDED
@@ -0,0 +1,172 @@
1
+ /**
2
+ * Keyboard guards shared by the kit's controls.
3
+ *
4
+ * A key held down auto-repeats: without a guard, holding Enter on a button,
5
+ * a menu row that keeps its menu open or a switch presses it again and again,
6
+ * and a press that moves focus (closing a toast, opening a dialog) lands the
7
+ * repeats on whatever gets focus next.
8
+ */
9
+ /**
10
+ * True while an input method composes (Chinese, Japanese, Korean…): the
11
+ * Enter or Escape it sees picks or drops the candidate, so a field must not
12
+ * also commit or cancel on it. Safari reports the end of a composition as
13
+ * key code 229 with `isComposing` already false.
14
+ */
15
+ export function isComposingKey(event) {
16
+ return Boolean(event.isComposing) || event.keyCode === 229;
17
+ }
18
+ /** True for an auto-repeated Enter or Space. */
19
+ export function isRepeatedActivation(event) {
20
+ return event.repeat && (event.key === 'Enter' || event.key === ' ');
21
+ }
22
+ /**
23
+ * A keydown handler that keeps a held Enter or Space from pressing the
24
+ * focused control again: the repeats have their default (the native click,
25
+ * or Base UI's activation) prevented.
26
+ */
27
+ export function preventRepeatedActivation(event) {
28
+ if (isRepeatedActivation(event) && event.target === event.currentTarget)
29
+ event.preventDefault();
30
+ }
31
+ /**
32
+ * Wraps a keydown handler so a held Enter or Space presses the control once:
33
+ * the repeats have their default (the native click, or Base UI's activation)
34
+ * prevented. The wrapped handler still runs (and sees `defaultPrevented`).
35
+ */
36
+ export function withRepeatGuard(handler) {
37
+ if (!handler)
38
+ return preventRepeatedActivation;
39
+ return (event) => {
40
+ preventRepeatedActivation(event);
41
+ handler(event);
42
+ };
43
+ }
44
+ /** How long the guard stays after the first key is released. */
45
+ export const HELD_KEY_SETTLE_MS = 200;
46
+ /** The guard never lasts longer than this. */
47
+ export const HELD_KEY_GUARD_MAX_MS = 2000;
48
+ /**
49
+ * After an Enter or Space press that closes something (a toast's close
50
+ * button), keeps the activation keys from pressing what gets focus next:
51
+ * until the pressed key is released, plus a short settle, Enter and Space
52
+ * keydowns outside `isInside` are swallowed at the window, and so are Space
53
+ * keyups (a native button acts on Space's keyup). Lasts at most 2 s.
54
+ * Returns a function that ends the guard early.
55
+ */
56
+ export function guardHeldActivation(win, firstKey, isInside) {
57
+ let settling = null;
58
+ let ended = false;
59
+ const end = () => {
60
+ if (ended)
61
+ return;
62
+ ended = true;
63
+ win.removeEventListener('keydown', onKey, true);
64
+ win.removeEventListener('keyup', onKey, true);
65
+ win.clearTimeout(limit);
66
+ if (settling !== null)
67
+ win.clearTimeout(settling);
68
+ };
69
+ const onKey = (event) => {
70
+ const activation = event.key === 'Enter' || event.key === ' ';
71
+ if (event.type === 'keyup') {
72
+ if (event.key === ' ' && !isInside(event.target))
73
+ event.preventDefault();
74
+ if (event.key === firstKey && settling === null)
75
+ settling = win.setTimeout(end, HELD_KEY_SETTLE_MS);
76
+ return;
77
+ }
78
+ if (activation && !isInside(event.target)) {
79
+ event.preventDefault();
80
+ event.stopImmediatePropagation();
81
+ }
82
+ };
83
+ const limit = win.setTimeout(end, HELD_KEY_GUARD_MAX_MS);
84
+ win.addEventListener('keydown', onKey, true);
85
+ win.addEventListener('keyup', onKey, true);
86
+ return end;
87
+ }
88
+ /** The keys an input method uses to pick, drop or move between candidates. */
89
+ export const COMPOSING_COMMIT_KEYS = ['Enter', 'Escape', 'Tab'];
90
+ /** True when `target` is an element inside one that matches `selector`. */
91
+ function insideSelector(target, selector) {
92
+ const closest = target?.closest;
93
+ return typeof closest === 'function' && closest.call(target, selector) !== null;
94
+ }
95
+ /**
96
+ * Keeps the page's shortcuts off the keys an input method composes with:
97
+ * an Enter, Escape or Tab pressed while it composes (see {@link isComposingKey})
98
+ * is stopped at the window, before any other handler sees it, so it only
99
+ * picks or drops the candidate. Its default is left alone. Keys inside
100
+ * `skip` (a rich-text editor that reads composition itself) pass. Returns a
101
+ * function that removes the guard.
102
+ */
103
+ export function guardComposingKeys(win, skip = '.ProseMirror') {
104
+ const onKey = (event) => {
105
+ if (!COMPOSING_COMMIT_KEYS.includes(event.key) || !isComposingKey(event))
106
+ return;
107
+ if (skip && insideSelector(event.target, skip))
108
+ return;
109
+ event.stopImmediatePropagation();
110
+ };
111
+ win.addEventListener('keydown', onKey, true);
112
+ return () => win.removeEventListener('keydown', onKey, true);
113
+ }
114
+ /**
115
+ * The letter a shortcut means, lower-cased. A Latin letter is taken as typed,
116
+ * so remapped layouts (Dvorak, AZERTY) keep their own letters; any other
117
+ * character (Cyrillic, Greek, a symbol the Option key makes) falls back to the
118
+ * physical key, so ⌘S still saves on a Russian layout. Keys that are not
119
+ * letters (`Escape`, `Enter`) come back lower-cased.
120
+ */
121
+ export function shortcutLetter(event) {
122
+ if (/^[a-z]$/i.test(event.key))
123
+ return event.key.toLowerCase();
124
+ const physical = /^Key([A-Z])$/.exec(event.code ?? '');
125
+ if (physical && event.key.length === 1)
126
+ return physical[1].toLowerCase();
127
+ return event.key.toLowerCase();
128
+ }
129
+ /**
130
+ * True when the key is the A of Select All (with ⌘ or Ctrl, which the caller checks): an ASCII key must be "a"; a
131
+ * layout that types another single character there (Cyrillic ф), or a key the browser can't name (`Dead`,
132
+ * `Unidentified`), counts by the physical KeyA. Named keys (`Enter`…) never do.
133
+ */
134
+ export function isSelectAllLetter(event) {
135
+ const { key, code } = event;
136
+ if (typeof key !== 'string')
137
+ return false;
138
+ const ascii = key.length === 1 && key.charCodeAt(0) >= 0x20 && key.charCodeAt(0) <= 0x7e;
139
+ if (ascii)
140
+ return key === 'a' || key === 'A';
141
+ // Another layout's letter, or a key that names no character: the physical A key.
142
+ const notNamed = Array.from(key).length === 1 || key === 'Dead' || key === 'Unidentified';
143
+ return notNamed && code === 'KeyA';
144
+ }
145
+ /**
146
+ * A dangerous confirmation ignores Enter and Space while it appears, so the
147
+ * press that opened it (a held Enter or Delete) can't confirm it too. The
148
+ * window runs from opening until the dialog has been fully shown for
149
+ * {@link EARLY_PRESS_SETTLE_MS}, and never past {@link EARLY_PRESS_MAX_MS}.
150
+ */
151
+ export const EARLY_PRESS_SETTLE_MS = 300;
152
+ /** The early-press window never lasts longer than this after opening. */
153
+ export const EARLY_PRESS_MAX_MS = 3000;
154
+ /** The time the early-press window closes. */
155
+ export function earlyPressEnds(times) {
156
+ const limit = times.opened + EARLY_PRESS_MAX_MS;
157
+ return times.shown === null ? limit : Math.min(limit, Math.max(times.opened, times.shown) + EARLY_PRESS_SETTLE_MS);
158
+ }
159
+ /**
160
+ * True when a key event must not activate anything in a guarded dialog: an
161
+ * Enter or Space from the user (synthetic events pass) inside the window, or
162
+ * an auto-repeat at any time.
163
+ */
164
+ export function blocksEarlyPress(times, now, event) {
165
+ if (event.key !== 'Enter' && event.key !== ' ')
166
+ return false;
167
+ if (event.repeat)
168
+ return true;
169
+ if (event.isTrusted === false)
170
+ return false;
171
+ return now < earlyPressEnds(times);
172
+ }
@@ -0,0 +1,74 @@
1
+ import { type HTMLAttributes, type ReactNode } from 'react';
2
+ import { type ToastWords } from './toast-tone.js';
3
+ /** One tab of {@link Tabs}. */
4
+ export interface TabItem<T extends string> {
5
+ value: T;
6
+ label: ReactNode;
7
+ content: ReactNode;
8
+ /** Kept rendered, hidden, while another tab is on show (its content is unmounted otherwise). */
9
+ keepMounted?: boolean;
10
+ }
11
+ /** Props of {@link Tabs}. */
12
+ export interface TabsProps<T extends string> {
13
+ value: T;
14
+ onChange: (value: T) => void;
15
+ items: TabItem<T>[];
16
+ className?: string;
17
+ /** Extra controls shown at the end of the tab bar. */
18
+ trailing?: ReactNode;
19
+ /** The tab list's accessible name. */
20
+ label?: string;
21
+ }
22
+ /** A tab strip with panels. */
23
+ export declare function Tabs<T extends string>({ value, onChange, items, className, trailing, label }: TabsProps<T>): import("react/jsx-runtime").JSX.Element;
24
+ /** Props of {@link Section}. */
25
+ export interface SectionProps {
26
+ title: ReactNode;
27
+ children: ReactNode;
28
+ /** Controls at the right of the heading (add, reset…). */
29
+ actions?: ReactNode;
30
+ /** Collapsed state is uncontrolled; start open unless `defaultOpen` is false. */
31
+ defaultOpen?: boolean;
32
+ }
33
+ /** A collapsible group of inspector rows. Carries `data-ui-section` (its heading `data-ui-section-head`) for page styles. */
34
+ export declare function Section({ title, children, actions, defaultOpen }: SectionProps): import("react/jsx-runtime").JSX.Element;
35
+ /** A label + control row inside a {@link Section}. Carries `data-ui-row` (its label `data-ui-row-label`) for page styles. */
36
+ export declare function Row({ label, children, className }: {
37
+ label?: ReactNode;
38
+ children: ReactNode;
39
+ className?: string;
40
+ }): import("react/jsx-runtime").JSX.Element;
41
+ /** A floating bar (toolbars, zoom controls). */
42
+ export declare function Bar({ className, ...rest }: HTMLAttributes<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
43
+ /** A thin vertical divider for bars. */
44
+ export declare function BarDivider(): import("react/jsx-runtime").JSX.Element;
45
+ /** A keyboard key hint. */
46
+ export declare function Kbd({ children }: {
47
+ children: ReactNode;
48
+ }): import("react/jsx-runtime").JSX.Element;
49
+ /** A centered empty or loading state. */
50
+ export declare function EmptyState({ icon, title, children }: {
51
+ icon?: ReactNode;
52
+ title: ReactNode;
53
+ children?: ReactNode;
54
+ }): import("react/jsx-runtime").JSX.Element;
55
+ /**
56
+ * The app-wide toast manager: `toast.add({ title, description })`. Every
57
+ * toast is the same card; its `type` only picks the sign at its start: an
58
+ * info sign for a plain toast, a filled check for `'success'` (something went
59
+ * through), a filled alert in the warning color for `'warning'` (something is
60
+ * not done yet, an edit not saved) and in the danger color for `'error'`
61
+ * (something failed).
62
+ */
63
+ export declare const toast: import("@base-ui/react").ToastManager<any>;
64
+ /**
65
+ * Reports something that failed: the error sign, or the warning sign when it
66
+ * stays until dismissed (`durationMs` 0). Returns the toast's id.
67
+ */
68
+ export declare function errorToast(words: ToastWords, durationMs?: number): string;
69
+ /** Reports something not done yet, with the warning sign. Returns the toast's id. */
70
+ export declare function warningToast(words: ToastWords, durationMs?: number): string;
71
+ /** Mount once near the app root to show toasts. */
72
+ export declare function Toaster({ children }: {
73
+ children?: ReactNode;
74
+ }): import("react/jsx-runtime").JSX.Element;
package/src/layout.js ADDED
@@ -0,0 +1,173 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * Layout pieces: tabs, inspector sections and rows, the toolbar shell,
4
+ * keyboard hints, toasts and a few small helpers.
5
+ */
6
+ import { Collapsible } from '@base-ui/react/collapsible';
7
+ import { Tabs as BaseTabs } from '@base-ui/react/tabs';
8
+ import { Toast } from '@base-ui/react/toast';
9
+ import { ChevronDown, CircleAlert, CircleCheck, Info, TriangleAlert, X } from 'lucide-react';
10
+ import { useEffect, useLayoutEffect, useRef, useState } from 'react';
11
+ import { cn } from "./cn.js";
12
+ import { scrollStanding } from "./focusables.js";
13
+ import { guardHeldActivation } from "./keys.js";
14
+ import { TOAST_TOP_GAP_PX, toastBodyLimit } from "./toast-fit.js";
15
+ import { failureTone, troubleToast } from "./toast-tone.js";
16
+ /** A tab strip with panels. */
17
+ export function Tabs({ value, onChange, items, className, trailing, label }) {
18
+ return (_jsxs(BaseTabs.Root, { value: value, onValueChange: (next) => onChange(next), className: cn('flex min-h-0 flex-col', className), children: [_jsxs("div", { className: "flex h-9 shrink-0 items-center gap-1 border-b border-line px-2", "data-ui-tabs-bar": "", children: [_jsx(BaseTabs.List, { "aria-label": label, className: "relative flex items-center gap-1", children: items.map((item) => (_jsx(BaseTabs.Tab, { value: item.value, className: "h-7 rounded-md px-2 text-[13px] font-medium text-fg-muted outline-none hover:text-fg data-[active]:bg-hover data-[active]:text-fg focus-visible:outline-2 focus-visible:outline-accent", children: item.label }, item.value))) }), _jsx("div", { className: "ml-auto flex items-center gap-1", children: trailing })] }), items.map((item) => (
19
+ // The open panel takes the focus after its tab (Tab from the strip), so it shows the focus ring then. The panel
20
+ // being left stays in the page until its exit is over (a frame or two, longer on a busy machine): hidden at once,
21
+ // it never pushes the new one down for that moment (a press aimed at the new panel then lands under it).
22
+ _jsx(BaseTabs.Panel, { value: item.value, keepMounted: item.keepMounted, className: "min-h-0 flex-1 overflow-auto outline-none focus-visible:rounded focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-accent data-[ending-style]:hidden", children: item.content }, item.value)))] }));
23
+ }
24
+ /** A collapsible group of inspector rows. Carries `data-ui-section` (its heading `data-ui-section-head`) for page styles. */
25
+ export function Section({ title, children, actions, defaultOpen = true }) {
26
+ return (_jsxs(Collapsible.Root, { defaultOpen: defaultOpen, className: "border-b border-line px-3 py-2", "data-ui-section": "", children: [_jsxs("div", { className: "flex h-7 items-center gap-1", "data-ui-section-head": "", children: [_jsxs(Collapsible.Trigger, { className: "group flex flex-1 items-center gap-1 text-left text-xs font-semibold text-fg outline-none", children: [_jsx(ChevronDown, { className: "size-3 text-fg-subtle transition-transform group-data-[panel-open]:rotate-0 -rotate-90" }), title] }), actions] }), _jsx(Collapsible.Panel, { className: "flex flex-col gap-1.5 pb-1 pt-1", children: children })] }));
27
+ }
28
+ /** A label + control row inside a {@link Section}. Carries `data-ui-row` (its label `data-ui-row-label`) for page styles. */
29
+ export function Row({ label, children, className }) {
30
+ return (_jsxs("div", { className: cn('flex min-w-0 items-center gap-2', className), "data-ui-row": "", children: [label !== undefined ? (_jsx("div", { className: "w-16 shrink-0 truncate text-xs text-fg-muted", "data-ui-row-label": "", children: label })) : null, _jsx("div", { className: "flex min-w-0 flex-1 items-center gap-1.5", children: children })] }));
31
+ }
32
+ /** A floating bar (toolbars, zoom controls). */
33
+ export function Bar({ className, ...rest }) {
34
+ return (_jsx("div", { className: cn('flex items-center gap-0.5 rounded-xl bg-surface p-1 shadow-popup', className), ...rest }));
35
+ }
36
+ /** A thin vertical divider for bars. */
37
+ export function BarDivider() {
38
+ return _jsx("div", { className: "mx-1 h-5 w-px bg-line", "aria-hidden": "true" });
39
+ }
40
+ /** A keyboard key hint. */
41
+ export function Kbd({ children }) {
42
+ return _jsx("kbd", { className: "rounded border border-line bg-surface-2 px-1 font-mono text-[11px] text-fg-muted", children: children });
43
+ }
44
+ /** A centered empty or loading state. */
45
+ export function EmptyState({ icon, title, children }) {
46
+ return (_jsxs("div", { className: "flex h-full flex-col items-center justify-center gap-2 p-8 text-center text-fg-muted", children: [icon ? _jsx("div", { className: "text-fg-subtle", children: icon }) : null, _jsx("div", { className: "text-[15px] font-semibold text-fg", children: title }), children ? _jsx("div", { className: "max-w-sm", children: children }) : null] }));
47
+ }
48
+ /* --------------------------------- Toasts --------------------------------- */
49
+ /**
50
+ * The app-wide toast manager: `toast.add({ title, description })`. Every
51
+ * toast is the same card; its `type` only picks the sign at its start: an
52
+ * info sign for a plain toast, a filled check for `'success'` (something went
53
+ * through), a filled alert in the warning color for `'warning'` (something is
54
+ * not done yet, an edit not saved) and in the danger color for `'error'`
55
+ * (something failed).
56
+ */
57
+ export const toast = Toast.createToastManager();
58
+ /**
59
+ * Reports something that failed: the error sign, or the warning sign when it
60
+ * stays until dismissed (`durationMs` 0). Returns the toast's id.
61
+ */
62
+ export function errorToast(words, durationMs) {
63
+ return toast.add(troubleToast(words, failureTone(durationMs), durationMs));
64
+ }
65
+ /** Reports something not done yet, with the warning sign. Returns the toast's id. */
66
+ export function warningToast(words, durationMs) {
67
+ return toast.add(troubleToast(words, 'warning', durationMs));
68
+ }
69
+ /**
70
+ * Enter or Space on a toast's close button closes it and focus moves on:
71
+ * until the key is released, Enter and Space must not press whatever gets
72
+ * focus next.
73
+ */
74
+ function guardToastClose(event) {
75
+ if (event.repeat || (event.key !== 'Enter' && event.key !== ' '))
76
+ return;
77
+ const toastElement = event.currentTarget.closest('[data-toast]') ?? event.currentTarget;
78
+ const view = toastElement.ownerDocument.defaultView;
79
+ if (!view)
80
+ return;
81
+ guardHeldActivation(view, event.key, (target) => target instanceof view.Node && toastElement.contains(target));
82
+ }
83
+ /**
84
+ * A toast's text. A long one is held to its share of the room above the
85
+ * column (see {@link useToastFit}) and scrolls, fading out at its foot while
86
+ * there is more below; it then takes focus as a group, so keys can scroll it.
87
+ * The close button stays outside.
88
+ */
89
+ function ToastBody({ children }) {
90
+ const ref = useRef(null);
91
+ const [standing, setStanding] = useState('none');
92
+ useEffect(() => {
93
+ const node = ref.current;
94
+ if (!node)
95
+ return undefined;
96
+ const measure = () => {
97
+ const style = getComputedStyle(node);
98
+ const { scrollWidth, clientWidth, scrollHeight, clientHeight, scrollTop } = node;
99
+ setStanding(scrollStanding({ scrollWidth, clientWidth, scrollHeight, clientHeight, scrollTop, overflowX: style.overflowX, overflowY: style.overflowY }));
100
+ };
101
+ measure();
102
+ const observer = new ResizeObserver(measure);
103
+ observer.observe(node);
104
+ for (const child of node.children)
105
+ observer.observe(child);
106
+ node.addEventListener('scroll', measure, { passive: true });
107
+ return () => {
108
+ observer.disconnect();
109
+ node.removeEventListener('scroll', measure);
110
+ };
111
+ }, []);
112
+ return (_jsx(Toast.Content, { ref: ref, role: standing === 'none' ? undefined : 'group', tabIndex: standing === 'none' ? undefined : 0, "data-overflow": standing === 'none' ? undefined : standing, "data-toast-body": "", className: "flex max-h-[var(--toast-fit,none)] min-w-0 flex-1 flex-col gap-0.5 overflow-y-auto overscroll-contain rounded-sm focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent data-[overflow=more]:[mask-image:linear-gradient(to_bottom,black_calc(100%-1.5rem),transparent)]", children: children }));
113
+ }
114
+ /**
115
+ * Keeps `--toast-fit` on the column at the height each toast's text is held
116
+ * to, so every toast stays below the top of the window. Measured again when
117
+ * toasts come and go, change size, or the window does.
118
+ */
119
+ function useToastFit(viewport, toasts) {
120
+ useLayoutEffect(() => {
121
+ const view = viewport?.ownerDocument.defaultView;
122
+ if (!viewport || !view)
123
+ return undefined;
124
+ const cards = () => Array.from(viewport.querySelectorAll('[data-toast]'));
125
+ const update = () => {
126
+ const extents = [];
127
+ for (const card of cards()) {
128
+ const body = card.querySelector('[data-toast-body]');
129
+ if (body)
130
+ extents.push({ chrome: card.offsetHeight - body.offsetHeight, content: body.scrollHeight });
131
+ }
132
+ const room = viewport.getBoundingClientRect().bottom - TOAST_TOP_GAP_PX;
133
+ const limit = toastBodyLimit(extents, room, parseFloat(view.getComputedStyle(viewport).rowGap) || 0);
134
+ const value = limit === null ? 'none' : `${limit}px`;
135
+ if (viewport.style.getPropertyValue('--toast-fit') !== value)
136
+ viewport.style.setProperty('--toast-fit', value);
137
+ };
138
+ update();
139
+ const observer = new ResizeObserver(update);
140
+ for (const card of cards()) {
141
+ observer.observe(card);
142
+ const body = card.querySelector('[data-toast-body]');
143
+ if (body)
144
+ for (const part of body.children)
145
+ observer.observe(part);
146
+ }
147
+ view.addEventListener('resize', update);
148
+ return () => {
149
+ observer.disconnect();
150
+ view.removeEventListener('resize', update);
151
+ };
152
+ }, [viewport, toasts]);
153
+ }
154
+ /** The sign at the start of a toast of a given `type`. */
155
+ function ToastIcon({ type }) {
156
+ if (type === 'success')
157
+ return _jsx(CircleCheck, { "aria-hidden": "true", className: "mt-px size-4 shrink-0 fill-success text-surface" });
158
+ if (type === 'error')
159
+ return _jsx(CircleAlert, { "aria-hidden": "true", className: "mt-px size-4 shrink-0 fill-danger text-surface" });
160
+ if (type === 'warning')
161
+ return _jsx(TriangleAlert, { "aria-hidden": "true", className: "mt-px size-4 shrink-0 fill-warning text-surface" });
162
+ return _jsx(Info, { "aria-hidden": "true", className: "mt-px size-4 shrink-0 text-fg-muted" });
163
+ }
164
+ function ToastList({ viewport }) {
165
+ const { toasts } = Toast.useToastManager();
166
+ useToastFit(viewport, toasts);
167
+ return toasts.map((item) => (_jsxs(Toast.Root, { toast: item, "data-toast": "", className: "pointer-events-auto flex w-80 items-start gap-3 rounded-lg bg-surface p-3 text-fg shadow-popup transition-[opacity,transform] data-[starting-style]:translate-y-2 data-[starting-style]:opacity-0 data-[ending-style]:opacity-0", children: [_jsx(ToastIcon, { type: item.type }), _jsxs(ToastBody, { children: [_jsx(Toast.Title, { className: "text-[13px] font-semibold" }), _jsx(Toast.Description, { className: "text-xs text-fg-muted" }), item.actionProps ? (_jsx(Toast.Action, { className: "mt-1 self-start rounded px-2 py-0.5 text-xs font-medium text-accent hover:bg-hover" })) : null] }), _jsx(Toast.Close, { "aria-label": "Dismiss", onKeyDown: guardToastClose, className: "rounded p-0.5 text-fg-muted hover:bg-hover", children: _jsx(X, { className: "size-3.5" }) })] }, item.id)));
168
+ }
169
+ /** Mount once near the app root to show toasts. */
170
+ export function Toaster({ children }) {
171
+ const [viewport, setViewport] = useState(null);
172
+ return (_jsxs(Toast.Provider, { toastManager: toast, timeout: 4000, children: [children, _jsx(Toast.Portal, { children: _jsx(Toast.Viewport, { ref: setViewport, "aria-label": "Notifications", className: "pointer-events-none fixed bottom-[var(--toast-foot,1rem)] right-4 z-[1100] flex flex-col gap-2", children: _jsx(ToastList, { viewport: viewport }) }) })] }));
173
+ }
@@ -0,0 +1,97 @@
1
+ /**
2
+ * The link cards.
3
+ *
4
+ * - {@link LinkCard}: the card at a link in rich text being edited. It
5
+ * shows the address, and Open, Copy link, Edit and Remove. Editing the
6
+ * address saves on Enter and puts it back on Escape; Escape on the card
7
+ * gives the focus back to the text. The editor brings what differs: what
8
+ * a typed address becomes (`normalize`), how it is copied and how the
9
+ * link changes.
10
+ * - {@link LinkDetailsCard}: the read-only card that shows while the
11
+ * pointer rests on a link in a page being viewed: the address (itself a
12
+ * link that opens in a new tab) and Copy link.
13
+ */
14
+ import { type HTMLAttributes } from 'react';
15
+ import { type ScreenBox } from './link-card.js';
16
+ /** Said once the address is on the clipboard. */
17
+ export declare const LINK_COPIED_MESSAGE = "Link copied";
18
+ /** Said when copying the address failed. */
19
+ export declare const LINK_COPY_FAILED_MESSAGE = "The link couldn\u2019t be copied. Try again.";
20
+ /** Under an address the card can't open. */
21
+ export declare const LINK_BLOCKED_MESSAGE = "This link can\u2019t be opened from here.";
22
+ /** What the address link does, for screen readers. */
23
+ export declare const LINK_OPENS_NEW_TAB = "Opens in a new tab";
24
+ /** The size a card is taken to have before it is measured. */
25
+ export declare const LINK_CARD_ESTIMATE: {
26
+ readonly w: 500;
27
+ readonly h: 44;
28
+ };
29
+ /** The card starts this far left of the link (screen pixels), so its address lines up with the link's text. */
30
+ export declare const LINK_CARD_SHIFT_X_PX = -8;
31
+ /** Props of {@link LinkCard}. */
32
+ export interface LinkCardProps {
33
+ /** The link in the text; the card sits under it. */
34
+ link: HTMLElement;
35
+ /** The address as the document writes it: shown, copied and edited. */
36
+ target: string;
37
+ /** The address resolved, which Open goes to. */
38
+ href: string;
39
+ /** What a typed address becomes, or null when it cannot be one. */
40
+ normalize(typed: string): string | null;
41
+ /** Shown under an address `normalize` refused. */
42
+ invalidMessage?: string;
43
+ onCopy(target: string): void;
44
+ /** Writes a new address into the link; returns false when it could not. */
45
+ onEdit(target: string): boolean;
46
+ onRemove(): void;
47
+ /** Gives focus back to the text, with the caret in the link. */
48
+ onReturn(): void;
49
+ /**
50
+ * Sit above the link, clear of `avoid`, and below it only when that does
51
+ * not fit (by default the card sits below the link).
52
+ */
53
+ above?: boolean;
54
+ /** With `above`: a bar the card must not cover, as it is now. */
55
+ avoid?: () => ScreenBox | null;
56
+ /** Open on the address input rather than the address (the card asked for to change the link). */
57
+ editOnOpen?: boolean;
58
+ className?: string;
59
+ }
60
+ export declare function LinkCard({ link, target, href, normalize, invalidMessage, onCopy, onEdit, onRemove, onReturn, above, avoid, editOnOpen, className }: LinkCardProps): import("react/jsx-runtime").JSX.Element;
61
+ /** Props of {@link LinkDetailsCard}. */
62
+ export interface LinkDetailsCardProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onCopy' | 'children'> {
63
+ /** The resolved address: shown, opened and copied. */
64
+ href: string;
65
+ /** The link's box on screen; for a link over several lines, the line the card belongs to. */
66
+ anchor: ScreenBox;
67
+ /** A box the card keeps clear of (a toolbar over the link). */
68
+ avoid?: ScreenBox | null;
69
+ /** Whether the address may be opened from here (default: a web or mail address). */
70
+ openable?: boolean;
71
+ /** Opens the address instead of the browser: the address becomes a button that calls it. */
72
+ onOpen?: (href: string) => void;
73
+ /**
74
+ * Copies the address; resolves to whether it did. The button shows a check
75
+ * mark for {@link LINK_COPIED_MS} after a copy; saying {@link LINK_COPIED_MESSAGE} or
76
+ * {@link LINK_COPY_FAILED_MESSAGE} is the caller's.
77
+ */
78
+ onCopy: (href: string) => boolean | Promise<boolean>;
79
+ /** Escape on the card (not while an input method composes). */
80
+ onClose?: () => void;
81
+ /**
82
+ * Tab past the card's last control, or Shift+Tab before its first. The
83
+ * card is usually rendered away from its link, so the caller puts focus
84
+ * back next to the link; return false to let the browser move it.
85
+ */
86
+ onTabOut?: (backwards: boolean) => boolean;
87
+ }
88
+ /**
89
+ * The read-only link card: a group named "Link details" with the address on
90
+ * one line (the site in full, the path after it lighter and cut from its
91
+ * end; a site too long for the card is cut from its start), and Copy link.
92
+ * The address is a link that opens in a new tab; one that can't be opened
93
+ * from here is greyed out and says so under it. It sits above the link,
94
+ * 6px away, or below it when above does not fit, and
95
+ * takes no clicks for {@link LINK_CARD_SETTLE_MS} after it lands somewhere.
96
+ */
97
+ export declare const LinkDetailsCard: import("react").ForwardRefExoticComponent<LinkDetailsCardProps & import("react").RefAttributes<HTMLDivElement>>;