@c9up/nebula 0.2.1 → 0.2.3

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 (98) hide show
  1. package/README.md +11 -9
  2. package/dist/atoms/AccessibleIcon.d.ts +24 -0
  3. package/dist/atoms/AccessibleIcon.js +27 -0
  4. package/dist/atoms/Checkbox.d.ts +1 -1
  5. package/dist/atoms/Checkbox.js +1 -1
  6. package/dist/atoms/Input.d.ts +5 -0
  7. package/dist/atoms/Input.js +1 -0
  8. package/dist/atoms/VisuallyHidden.d.ts +30 -0
  9. package/dist/atoms/VisuallyHidden.js +35 -0
  10. package/dist/atoms/index.d.ts +2 -0
  11. package/dist/atoms/index.js +2 -0
  12. package/dist/index.d.ts +7 -4
  13. package/dist/index.js +7 -4
  14. package/dist/lib/children.d.ts +13 -8
  15. package/dist/lib/children.js +5 -0
  16. package/dist/molecules/Breadcrumb.d.ts +11 -2
  17. package/dist/molecules/Breadcrumb.js +2 -2
  18. package/dist/molecules/InputOTP.d.ts +2 -0
  19. package/dist/molecules/InputOTP.js +3 -1
  20. package/dist/molecules/Pagination.d.ts +34 -2
  21. package/dist/molecules/Pagination.js +15 -6
  22. package/dist/molecules/PieceMap.d.ts +72 -0
  23. package/dist/molecules/PieceMap.js +78 -0
  24. package/dist/molecules/Resizable.d.ts +2 -0
  25. package/dist/molecules/Resizable.js +1 -1
  26. package/dist/molecules/Toolbar.d.ts +50 -0
  27. package/dist/molecules/Toolbar.js +70 -0
  28. package/dist/molecules/index.d.ts +10 -7
  29. package/dist/molecules/index.js +8 -5
  30. package/dist/organisms/Calendar.d.ts +13 -0
  31. package/dist/organisms/Calendar.js +2 -2
  32. package/dist/organisms/Carousel.d.ts +8 -0
  33. package/dist/organisms/Carousel.js +8 -5
  34. package/dist/organisms/DataTable.d.ts +23 -1
  35. package/dist/organisms/DataTable.js +57 -27
  36. package/dist/organisms/DatePicker.d.ts +7 -0
  37. package/dist/organisms/DatePicker.js +2 -1
  38. package/dist/organisms/DateRangePicker.d.ts +2 -0
  39. package/dist/organisms/DateRangePicker.js +2 -1
  40. package/dist/organisms/Dialog.d.ts +13 -3
  41. package/dist/organisms/Dialog.js +12 -5
  42. package/dist/organisms/Questionnaire.d.ts +4 -0
  43. package/dist/organisms/Questionnaire.js +5 -2
  44. package/dist/organisms/Select.d.ts +23 -4
  45. package/dist/organisms/Select.js +115 -15
  46. package/dist/organisms/Sheet.d.ts +2 -0
  47. package/dist/organisms/Sheet.js +2 -1
  48. package/dist/organisms/Sidebar.d.ts +6 -0
  49. package/dist/organisms/Sidebar.js +9 -4
  50. package/dist/organisms/Toaster.d.ts +80 -10
  51. package/dist/organisms/Toaster.js +152 -24
  52. package/dist/organisms/index.d.ts +3 -3
  53. package/dist/organisms/index.js +1 -1
  54. package/dist/primitives/direction.d.ts +38 -0
  55. package/dist/primitives/direction.js +57 -0
  56. package/dist/primitives/floating.js +25 -13
  57. package/dist/primitives/focusable.d.ts +10 -0
  58. package/dist/primitives/focusable.js +10 -1
  59. package/dist/primitives/index.d.ts +2 -1
  60. package/dist/primitives/index.js +2 -1
  61. package/dist/primitives/rovingFocus.js +14 -7
  62. package/dist/templates/SettingsLayout.d.ts +2 -0
  63. package/dist/templates/SettingsLayout.js +1 -1
  64. package/nebula.css +1 -1
  65. package/package.json +3 -3
  66. package/registry.json +76 -0
  67. package/src/atoms/AccessibleIcon.ts +39 -0
  68. package/src/atoms/Checkbox.ts +1 -1
  69. package/src/atoms/Input.ts +6 -0
  70. package/src/atoms/VisuallyHidden.ts +45 -0
  71. package/src/atoms/index.ts +8 -0
  72. package/src/index.ts +7 -4
  73. package/src/lib/children.ts +15 -7
  74. package/src/molecules/Breadcrumb.ts +15 -4
  75. package/src/molecules/InputOTP.ts +7 -1
  76. package/src/molecules/Pagination.ts +50 -8
  77. package/src/molecules/PieceMap.ts +136 -0
  78. package/src/molecules/Resizable.ts +3 -1
  79. package/src/molecules/Toolbar.ts +100 -0
  80. package/src/molecules/index.ts +28 -5
  81. package/src/organisms/Calendar.ts +16 -2
  82. package/src/organisms/Carousel.ts +17 -5
  83. package/src/organisms/DataTable.ts +95 -30
  84. package/src/organisms/DatePicker.ts +10 -2
  85. package/src/organisms/DateRangePicker.ts +4 -2
  86. package/src/organisms/Dialog.ts +17 -5
  87. package/src/organisms/Questionnaire.ts +10 -2
  88. package/src/organisms/Select.ts +137 -16
  89. package/src/organisms/Sheet.ts +5 -1
  90. package/src/organisms/Sidebar.ts +15 -4
  91. package/src/organisms/Toaster.ts +215 -37
  92. package/src/organisms/index.ts +9 -1
  93. package/src/primitives/direction.ts +61 -0
  94. package/src/primitives/floating.ts +29 -13
  95. package/src/primitives/focusable.ts +10 -1
  96. package/src/primitives/index.ts +7 -0
  97. package/src/primitives/rovingFocus.ts +18 -5
  98. package/src/templates/SettingsLayout.ts +3 -1
@@ -1,9 +1,23 @@
1
1
  /**
2
2
  * Toaster — transient notifications.
3
3
  *
4
- * shadcn delegates this to `sonner`. nebula keeps it in-house, and the shape
5
- * is the same: one region mounted once near the app root, and a `toast()`
6
- * function callable from anywhere with no reference to it.
4
+ * shadcn ships two: `sonner`, which wraps a third-party library, and `toast`,
5
+ * its own, built on Base UI. nebula keeps it in-house with zero dependencies
6
+ * and follows the SECOND — the shape is the same: one region mounted once near
7
+ * the app root, and a `toast` object callable from anywhere with no reference
8
+ * to it.
9
+ *
10
+ * NAMED DEVIATIONS from Base UI's manager, all deliberate:
11
+ *
12
+ * - `show` / `dismiss` / `variant` / `duration` rather than `add` / `close` /
13
+ * `type` / `timeout`. `variant` is what every other nebula component calls
14
+ * this (Button, Alert, Badge), and renaming it here alone would make the
15
+ * package less consistent with itself than with Base UI.
16
+ * - `variant` keeps `warning`, which Base UI's `type` does not have.
17
+ * - No `priority` (display ordering), `data` (typed payload for a React render
18
+ * prop — a `Child` already covers it) or `positionerProps` (anchored toasts).
19
+ * - No `updateKey`. It exists to make React replay an animation without
20
+ * remounting; `update` here replaces the entry, and aurora re-renders it.
7
21
  *
8
22
  * That decoupling is the whole design. A queue in module state, a signal the
9
23
  * region subscribes to, and `toast.error(…)` works from a route handler's
@@ -23,20 +37,51 @@
23
37
  */
24
38
  import type { Child } from "../lib/children.js";
25
39
  import { type Reactive } from "../lib/props.js";
26
- export type ToastVariant = "default" | "success" | "error" | "warning";
40
+ export type ToastVariant = "default" | "success" | "error" | "warning" | "loading";
41
+ /**
42
+ * A toast's identity. A number when `show` minted it, a string when the caller
43
+ * supplied one — which is what makes `update` and deduplication possible, and
44
+ * how {@link toast.promise} turns one toast from loading into its outcome.
45
+ */
46
+ export type ToastId = number | string;
27
47
  export interface ToastOptions {
28
48
  title: Child;
29
49
  description?: Child;
30
50
  variant?: ToastVariant;
31
- /** Milliseconds on screen. `0` keeps it until dismissed. */
51
+ /**
52
+ * Milliseconds on screen. `0` keeps it until dismissed.
53
+ *
54
+ * Left out, it comes from the variant: an error stays twice as long because
55
+ * the user has to read it and often act on it, and a `loading` toast does not
56
+ * leave on its own at all — it is waiting for an outcome.
57
+ */
32
58
  duration?: number;
33
59
  action?: {
34
60
  label: string;
35
61
  onClick: () => void;
36
62
  };
63
+ /**
64
+ * A stable id. Showing a toast under an id that is already on screen UPDATES
65
+ * it instead of stacking another — so "you are offline", raised on every
66
+ * failed request, is one toast rather than nine.
67
+ */
68
+ id?: string;
69
+ /** Called once the toast leaves, however it left. */
70
+ onClose?: () => void;
37
71
  }
38
- declare function dismiss(id: number): void;
39
- declare function show(options: ToastOptions): number;
72
+ declare function dismiss(id: ToastId): void;
73
+ declare function show(options: ToastOptions): ToastId;
74
+ /**
75
+ * Change a toast that is already on screen. No-op if it has gone.
76
+ *
77
+ * The countdown is recomputed, because that is the part a caller would not
78
+ * think to ask for and always wants: a `loading` toast has no timer at all, so
79
+ * turning it into a success without rescheduling would leave it on screen for
80
+ * good. Which is exactly what {@link toast.promise} does to it.
81
+ */
82
+ declare function update(id: ToastId, patch: Partial<ToastOptions>): void;
83
+ /** What a `promise` stage says: just a title, or the whole toast. */
84
+ export type ToastMessage = Child | Omit<ToastOptions, "id" | "variant">;
40
85
  /**
41
86
  * Raise a toast. Returns its id, which `dismiss` accepts.
42
87
  *
@@ -44,16 +89,41 @@ declare function show(options: ToastOptions): number;
44
89
  */
45
90
  export declare const toast: {
46
91
  show: typeof show;
92
+ update: typeof update;
47
93
  dismiss: typeof dismiss;
48
- success: (title: Child, description?: Child) => number;
49
- error: (title: Child, description?: Child) => number;
50
- warning: (title: Child, description?: Child) => number;
94
+ success: (title: Child, description?: Child) => ToastId;
95
+ error: (title: Child, description?: Child) => ToastId;
96
+ warning: (title: Child, description?: Child) => ToastId;
97
+ loading: (title: Child, description?: Child) => ToastId;
98
+ /**
99
+ * One toast for the whole life of an async call: waiting, then the outcome.
100
+ *
101
+ * ```ts
102
+ * await toast.promise(save(form), {
103
+ * loading: 'Saving…',
104
+ * success: (saved) => `Saved ${saved.name}`,
105
+ * error: (reason) => ({ title: 'Could not save', description: String(reason) }),
106
+ * })
107
+ * ```
108
+ *
109
+ * Returns the SAME promise it was given, rejection included. It reports, it
110
+ * does not handle: swallowing the rejection here would turn a failed call
111
+ * into a red toast and nothing else, with the caller's own error path never
112
+ * running.
113
+ */
114
+ promise<T>(work: Promise<T>, messages: {
115
+ loading: ToastMessage;
116
+ success: ToastMessage | ((value: T) => ToastMessage);
117
+ error: ToastMessage | ((reason: unknown) => ToastMessage);
118
+ }): Promise<T>;
51
119
  /** Clear everything — on navigation, say. */
52
120
  clear(): void;
53
121
  };
54
122
  export interface ToasterProps {
55
123
  /** Which corner. Default `"bottom-right"`. */
56
124
  position?: "top-right" | "top-left" | "bottom-right" | "bottom-left";
125
+ /** The dismiss cross's accessible name, as sonner names the prop. */
126
+ closeButtonAriaLabel?: string;
57
127
  class?: Reactive<string>;
58
128
  }
59
129
  /**
@@ -1,9 +1,23 @@
1
1
  /**
2
2
  * Toaster — transient notifications.
3
3
  *
4
- * shadcn delegates this to `sonner`. nebula keeps it in-house, and the shape
5
- * is the same: one region mounted once near the app root, and a `toast()`
6
- * function callable from anywhere with no reference to it.
4
+ * shadcn ships two: `sonner`, which wraps a third-party library, and `toast`,
5
+ * its own, built on Base UI. nebula keeps it in-house with zero dependencies
6
+ * and follows the SECOND — the shape is the same: one region mounted once near
7
+ * the app root, and a `toast` object callable from anywhere with no reference
8
+ * to it.
9
+ *
10
+ * NAMED DEVIATIONS from Base UI's manager, all deliberate:
11
+ *
12
+ * - `show` / `dismiss` / `variant` / `duration` rather than `add` / `close` /
13
+ * `type` / `timeout`. `variant` is what every other nebula component calls
14
+ * this (Button, Alert, Badge), and renaming it here alone would make the
15
+ * package less consistent with itself than with Base UI.
16
+ * - `variant` keeps `warning`, which Base UI's `type` does not have.
17
+ * - No `priority` (display ordering), `data` (typed payload for a React render
18
+ * prop — a `Child` already covers it) or `positionerProps` (anchored toasts).
19
+ * - No `updateKey`. It exists to make React replay an animation without
20
+ * remounting; `update` here replaces the entry, and aurora re-renders it.
7
21
  *
8
22
  * That decoupling is the whole design. A queue in module state, a signal the
9
23
  * region subscribes to, and `toast.error(…)` works from a route handler's
@@ -23,10 +37,16 @@
23
37
  */
24
38
  import { component, html, signal } from "@c9up/aurora";
25
39
  import { cn } from "../lib/cn.js";
26
- import { XIcon } from "../lib/icons.js";
40
+ import { LoaderIcon, XIcon } from "../lib/icons.js";
27
41
  import { fadeInOut } from "../lib/motion.js";
28
42
  import { read } from "../lib/props.js";
29
43
  const DEFAULT_DURATION_MS = 5000;
44
+ /** How long a variant stays when the caller did not say. */
45
+ function defaultDuration(variant) {
46
+ if (variant === "loading")
47
+ return 0;
48
+ return variant === "error" ? DEFAULT_DURATION_MS * 2 : DEFAULT_DURATION_MS;
49
+ }
30
50
  const queue = signal([]);
31
51
  const timers = new Map();
32
52
  /** When each toast is due to disappear, as an epoch timestamp. */
@@ -35,10 +55,29 @@ const deadlines = new Map();
35
55
  const remainders = new Map();
36
56
  let nextId = 0;
37
57
  function dismiss(id) {
58
+ const leaving = queue().find((entry) => entry.id === id);
38
59
  clearTimer(id);
39
60
  deadlines.delete(id);
40
61
  remainders.delete(id);
41
62
  queue(queue().filter((entry) => entry.id !== id));
63
+ notifyClosed(leaving);
64
+ }
65
+ /**
66
+ * Run a toast's `onClose`, without letting it take the caller down.
67
+ *
68
+ * The callback belongs to application code and runs from a timer, a click and
69
+ * `clear()` alike. One that throws would otherwise break whichever of those
70
+ * happened to be running — a dismissal that leaves the queue half-updated.
71
+ */
72
+ function notifyClosed(entry) {
73
+ if (entry?.onClose === undefined)
74
+ return;
75
+ try {
76
+ entry.onClose();
77
+ }
78
+ catch (error) {
79
+ console.error("[nebula] a toast onClose callback threw", error);
80
+ }
42
81
  }
43
82
  function clearTimer(id) {
44
83
  const timer = timers.get(id);
@@ -77,17 +116,67 @@ function resumeAll(minimumMs) {
77
116
  remainders.clear();
78
117
  }
79
118
  function show(options) {
80
- nextId += 1;
81
- const id = nextId;
82
- const entry = {
83
- ...options,
84
- id,
85
- variant: options.variant ?? "default",
86
- };
119
+ // A supplied id that is already on screen updates rather than stacks.
120
+ if (options.id !== undefined && has(options.id)) {
121
+ update(options.id, options);
122
+ return options.id;
123
+ }
124
+ let id;
125
+ if (options.id === undefined) {
126
+ nextId += 1;
127
+ id = nextId;
128
+ }
129
+ else {
130
+ id = options.id;
131
+ }
132
+ const variant = options.variant ?? "default";
133
+ const entry = { ...options, id, variant };
87
134
  queue([...queue(), entry]);
88
- schedule(id, options.duration ?? DEFAULT_DURATION_MS);
135
+ schedule(id, options.duration ?? defaultDuration(variant));
89
136
  return id;
90
137
  }
138
+ function has(id) {
139
+ return queue().some((entry) => entry.id === id);
140
+ }
141
+ /**
142
+ * Change a toast that is already on screen. No-op if it has gone.
143
+ *
144
+ * The countdown is recomputed, because that is the part a caller would not
145
+ * think to ask for and always wants: a `loading` toast has no timer at all, so
146
+ * turning it into a success without rescheduling would leave it on screen for
147
+ * good. Which is exactly what {@link toast.promise} does to it.
148
+ */
149
+ function update(id, patch) {
150
+ const current = queue().find((entry) => entry.id === id);
151
+ if (current === undefined)
152
+ return;
153
+ const variant = patch.variant ?? current.variant;
154
+ const next = { ...current, ...patch, id, variant };
155
+ queue(queue().map((entry) => (entry.id === id ? next : entry)));
156
+ clearTimer(id);
157
+ deadlines.delete(id);
158
+ remainders.delete(id);
159
+ schedule(id, patch.duration ?? next.duration ?? defaultDuration(variant));
160
+ }
161
+ function optionsOf(message) {
162
+ // A plain object with a `title` is the options form; anything else — a
163
+ // string, a number, a template — is the title itself. Checked on `title`
164
+ // rather than on the shape in general, because a template result IS an
165
+ // object and would otherwise be mistaken for options.
166
+ if (typeof message === "object" &&
167
+ message !== null &&
168
+ "title" in message &&
169
+ !Array.isArray(message)) {
170
+ return message;
171
+ }
172
+ return { title: message };
173
+ }
174
+ function resolveMessage(message, value) {
175
+ if (typeof message === "function") {
176
+ return optionsOf(message(value));
177
+ }
178
+ return optionsOf(message);
179
+ }
91
180
  /**
92
181
  * Raise a toast. Returns its id, which `dismiss` accepts.
93
182
  *
@@ -95,17 +184,45 @@ function show(options) {
95
184
  */
96
185
  export const toast = {
97
186
  show,
187
+ update,
98
188
  dismiss,
99
189
  success: (title, description) => show({ title, description, variant: "success" }),
100
- error: (title, description) =>
101
- // Errors stay twice as long: the user has to read them, and often act.
102
- show({
103
- title,
104
- description,
105
- variant: "error",
106
- duration: DEFAULT_DURATION_MS * 2,
107
- }),
190
+ error: (title, description) => show({ title, description, variant: "error" }),
108
191
  warning: (title, description) => show({ title, description, variant: "warning" }),
192
+ loading: (title, description) => show({ title, description, variant: "loading" }),
193
+ /**
194
+ * One toast for the whole life of an async call: waiting, then the outcome.
195
+ *
196
+ * ```ts
197
+ * await toast.promise(save(form), {
198
+ * loading: 'Saving…',
199
+ * success: (saved) => `Saved ${saved.name}`,
200
+ * error: (reason) => ({ title: 'Could not save', description: String(reason) }),
201
+ * })
202
+ * ```
203
+ *
204
+ * Returns the SAME promise it was given, rejection included. It reports, it
205
+ * does not handle: swallowing the rejection here would turn a failed call
206
+ * into a red toast and nothing else, with the caller's own error path never
207
+ * running.
208
+ */
209
+ promise(work, messages) {
210
+ const id = show({ ...optionsOf(messages.loading), variant: "loading" });
211
+ // A separate chain, whose own rejection IS handled — so reporting the
212
+ // failure never adds an unhandled rejection of its own.
213
+ work.then((value) => {
214
+ update(id, {
215
+ ...resolveMessage(messages.success, value),
216
+ variant: "success",
217
+ });
218
+ }, (reason) => {
219
+ update(id, {
220
+ ...resolveMessage(messages.error, reason),
221
+ variant: "error",
222
+ });
223
+ });
224
+ return work;
225
+ },
109
226
  /** Clear everything — on navigation, say. */
110
227
  clear() {
111
228
  for (const timer of timers.values())
@@ -113,11 +230,17 @@ export const toast = {
113
230
  timers.clear();
114
231
  deadlines.clear();
115
232
  remainders.clear();
233
+ const leaving = queue();
116
234
  queue([]);
235
+ // After the queue is empty, so a callback that raises a toast of its own
236
+ // is not swept away by the clear that called it.
237
+ for (const entry of leaving)
238
+ notifyClosed(entry);
117
239
  },
118
240
  };
119
241
  const variantClasses = {
120
242
  default: "bg-popover text-popover-foreground border",
243
+ loading: "bg-popover text-muted-foreground border",
121
244
  success: "bg-popover text-popover-foreground border-l-4 border-l-primary border",
122
245
  error: "bg-popover text-destructive border-l-4 border-l-destructive border",
123
246
  warning: "bg-popover text-popover-foreground border-l-4 border-l-chart-4 border",
@@ -137,6 +260,8 @@ const positionClasses = {
137
260
  */
138
261
  export const Toaster = component((props) => {
139
262
  const position = props.position ?? "bottom-right";
263
+ const closeLabel = props.closeButtonAriaLabel ?? "Dismiss notification";
264
+ const render = (entry) => renderToast(entry, closeLabel);
140
265
  return html `<div
141
266
  data-slot="toaster"
142
267
  data-nebula-live
@@ -147,22 +272,25 @@ export const Toaster = component((props) => {
147
272
  <div role="status" aria-live="polite" aria-atomic="false" class="contents">
148
273
  ${() => queue()
149
274
  .filter((entry) => entry.variant !== "error")
150
- .map(renderToast)}
275
+ .map(render)}
151
276
  </div>
152
277
  <div role="alert" aria-live="assertive" aria-atomic="false" class="contents">
153
278
  ${() => queue()
154
279
  .filter((entry) => entry.variant === "error")
155
- .map(renderToast)}
280
+ .map(render)}
156
281
  </div>
157
282
  </div>`;
158
283
  });
159
- function renderToast(entry) {
284
+ function renderToast(entry, closeLabel) {
160
285
  return html `<div
161
286
  data-slot="toast"
162
287
  data-variant="${entry.variant}"
163
288
  data-state="open"
164
289
  class="${cn("pointer-events-auto mt-2 flex w-full items-start gap-3 rounded-md p-4 shadow-lg", variantClasses[entry.variant], fadeInOut)}"
165
290
  >
291
+ ${entry.variant === "loading"
292
+ ? LoaderIcon({ class: "size-4 mt-0.5 shrink-0 animate-spin" })
293
+ : null}
166
294
  <div class="flex-1 text-sm">
167
295
  <div class="font-medium">${entry.title}</div>
168
296
  ${entry.description === undefined
@@ -181,7 +309,7 @@ function renderToast(entry) {
181
309
  >${entry.action.label}</button>`}
182
310
  <button
183
311
  type="button"
184
- aria-label="Dismiss notification"
312
+ aria-label="${closeLabel}"
185
313
  class="opacity-60 transition-opacity hover:opacity-100"
186
314
  @click="${() => dismiss(entry.id)}"
187
315
  >${XIcon({ class: "size-4" })}</button>
@@ -13,7 +13,7 @@
13
13
  * restoration, hiding the page from assistive technology) exist once.
14
14
  */
15
15
  export { AlertDialog, AlertDialogAction, type AlertDialogButtonProps, AlertDialogCancel, AlertDialogContent, type AlertDialogContentProps, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogMedia, AlertDialogOverlay, AlertDialogPortal, type AlertDialogPortalProps, type AlertDialogProps, type AlertDialogSectionProps, AlertDialogTitle, AlertDialogTrigger, type AlertDialogTriggerProps, } from "./AlertDialog.js";
16
- export { addDays, addMonths, Calendar, type CalendarProps, type DateRange, isSameDay, monthGrid, startOfDay, } from "./Calendar.js";
16
+ export { addDays, addMonths, Calendar, type CalendarLabels, type CalendarProps, type DateRange, isSameDay, monthGrid, startOfDay, } from "./Calendar.js";
17
17
  export { Carousel, type CarouselButtonProps, CarouselContent, type CarouselContentProps, CarouselItem, type CarouselItemProps, CarouselNext, CarouselPrevious, type CarouselProps, } from "./Carousel.js";
18
18
  export { Chart, type ChartDatum, type ChartProps, type ChartSeries, valueRange, } from "./Chart.js";
19
19
  export { Combobox, type ComboboxOption, type ComboboxProps, } from "./Combobox.js";
@@ -21,7 +21,7 @@ export { Command, type CommandCandidate, CommandEmpty, type CommandEmptyProps, C
21
21
  export { CommandDialog, type CommandDialogProps } from "./CommandDialog.js";
22
22
  export { ContextMenu, ContextMenuCheckboxItem, type ContextMenuCheckboxItemProps, ContextMenuContent, type ContextMenuContentProps, ContextMenuGroup, type ContextMenuGroupProps, ContextMenuItem, type ContextMenuItemProps, ContextMenuLabel, type ContextMenuLabelProps, ContextMenuPortal, type ContextMenuPortalProps, type ContextMenuProps, ContextMenuRadioGroup, type ContextMenuRadioGroupProps, ContextMenuRadioItem, type ContextMenuRadioItemProps, ContextMenuSeparator, type ContextMenuSeparatorProps, ContextMenuShortcut, type ContextMenuShortcutProps, ContextMenuSub, ContextMenuSubContent, type ContextMenuSubContentProps, type ContextMenuSubProps, ContextMenuSubTrigger, type ContextMenuSubTriggerProps, ContextMenuTrigger, type ContextMenuTriggerProps, } from "./ContextMenu.js";
23
23
  export { type Column, DataTable, type DataTableProps } from "./DataTable.js";
24
- export { DatePicker, type DatePickerProps, toISODate } from "./DatePicker.js";
24
+ export { DatePicker, type DatePickerLabels, type DatePickerProps, toISODate, } from "./DatePicker.js";
25
25
  export { DateRangePicker, type DateRangePickerProps, } from "./DateRangePicker.js";
26
26
  export { Dialog, DialogClose, type DialogCloseProps, DialogContent, type DialogContentProps, DialogDescription, DialogFooter, type DialogFooterProps, DialogHeader, DialogOverlay, type DialogOverlayProps, DialogPortal, type DialogPortalProps, type DialogProps, type DialogSectionProps, DialogTitle, type DialogTitleProps, DialogTrigger, type DialogTriggerProps, dialogBackdropClasses, dialogPanelClasses, useDialog, } from "./Dialog.js";
27
27
  export { Drawer, DrawerClose, type DrawerCloseProps, DrawerContent, type DrawerContentProps, DrawerDescription, DrawerFooter, DrawerHeader, DrawerOverlay, type DrawerOverlayProps, type DrawerProps, type DrawerSectionProps, DrawerTitle, DrawerTrigger, type DrawerTriggerProps, } from "./Drawer.js";
@@ -36,5 +36,5 @@ export { type Answer, type Answers, type FreeformQuestion, isAnswered, type Mult
36
36
  export { Select, SelectContent, type SelectContentProps, SelectGroup, type SelectGroupProps, SelectItem, type SelectItemProps, SelectLabel, type SelectLabelProps, type SelectProps, type SelectScrollButtonProps, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, type SelectSeparatorProps, SelectTrigger, type SelectTriggerProps, SelectValue, type SelectValueProps, selectContentClasses, selectTriggerClasses, } from "./Select.js";
37
37
  export { Sheet, SheetClose, type SheetCloseProps, SheetContent, type SheetContentProps, SheetDescription, SheetFooter, SheetHeader, SheetOverlay, type SheetOverlayProps, type SheetProps, type SheetSectionProps, SheetTitle, type SheetTitleProps, SheetTrigger, type SheetTriggerProps, } from "./Sheet.js";
38
38
  export { Sidebar, type SidebarActionProps, type SidebarApi, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupAction, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarInput, type SidebarInputProps, SidebarInset, type SidebarInsetProps, SidebarMenu, SidebarMenuAction, SidebarMenuBadge, SidebarMenuButton, type SidebarMenuButtonProps, type SidebarMenuButtonVariants, SidebarMenuItem, SidebarMenuSkeleton, type SidebarMenuSkeletonProps, SidebarMenuSub, SidebarMenuSubButton, type SidebarMenuSubButtonProps, SidebarMenuSubItem, type SidebarProps, SidebarProvider, type SidebarProviderProps, SidebarRail, type SidebarRailProps, SidebarSeparator, type SidebarSeparatorProps, SidebarTrigger, type SidebarTriggerProps, sidebarCollapsed, sidebarMenuButtonVariants, sidebarState, useSidebar, } from "./Sidebar.js";
39
- export { Toaster, type ToasterProps, type ToastOptions, type ToastVariant, toast, } from "./Toaster.js";
39
+ export { Toaster, type ToasterProps, type ToastId, type ToastMessage, type ToastOptions, type ToastVariant, toast, } from "./Toaster.js";
40
40
  export { Tooltip, TooltipContent, type TooltipContentProps, type TooltipProps, TooltipProvider, type TooltipProviderProps, TooltipTrigger, type TooltipTriggerProps, } from "./Tooltip.js";
@@ -21,7 +21,7 @@ export { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, Command
21
21
  export { CommandDialog } from "./CommandDialog.js";
22
22
  export { ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuPortal, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger, } from "./ContextMenu.js";
23
23
  export { DataTable } from "./DataTable.js";
24
- export { DatePicker, toISODate } from "./DatePicker.js";
24
+ export { DatePicker, toISODate, } from "./DatePicker.js";
25
25
  export { DateRangePicker, } from "./DateRangePicker.js";
26
26
  export { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, dialogBackdropClasses, dialogPanelClasses, useDialog, } from "./Dialog.js";
27
27
  export { Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerOverlay, DrawerTitle, DrawerTrigger, } from "./Drawer.js";
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Reading direction — the one place that answers "which way is forward?".
3
+ *
4
+ * Radix ships a `DirectionProvider` and threads the answer through React
5
+ * context. Aurora has a context, but a provider would be the wrong mechanism
6
+ * here: the direction is already on the page. `<html dir="rtl">`, a `dir`
7
+ * attribute on one panel, a stylesheet setting `direction` — all of them are
8
+ * answered by the computed style, and none of them requires the application to
9
+ * remember to wrap anything. A provider would be a second source of truth that
10
+ * silently disagrees with the first.
11
+ *
12
+ * The distinction that matters to callers is PHYSICAL versus LOGICAL. An arrow
13
+ * key is physical: ArrowRight means the key to the right, always. "The next
14
+ * item" is logical, and in a right-to-left list the next item is to the LEFT.
15
+ * `forward()` converts one into the other, and is the whole of this module's
16
+ * job.
17
+ */
18
+ export type Direction = "ltr" | "rtl";
19
+ /**
20
+ * The direction this element is laid out in.
21
+ *
22
+ * The computed style rather than the `dir` attribute, so an element inheriting
23
+ * from `<html dir="rtl">` answers correctly without every anchor carrying the
24
+ * attribute itself. `ltr` wherever there is no layout to ask — a server
25
+ * render, a jsdom without styles — which is also the correct default.
26
+ */
27
+ export declare function directionOf(element: Element | null | undefined): Direction;
28
+ /** Shorthand for the check that reads better at a call site than `=== "rtl"`. */
29
+ export declare function isRightToLeft(element: Element | null | undefined): boolean;
30
+ /**
31
+ * Which way a horizontal arrow key actually moves.
32
+ *
33
+ * `+1` for the next item, `-1` for the previous. ArrowRight is `+1` in a
34
+ * left-to-right widget and `-1` in a right-to-left one — that mirroring is the
35
+ * entire reason this exists, and getting it wrong makes every menu, tab list
36
+ * and toolbar navigate backwards for half the world's readers.
37
+ */
38
+ export declare function forward(key: "ArrowLeft" | "ArrowRight", element: Element | null | undefined): -1 | 1;
@@ -0,0 +1,57 @@
1
+ /// <reference lib="dom" />
2
+ /**
3
+ * Reading direction — the one place that answers "which way is forward?".
4
+ *
5
+ * Radix ships a `DirectionProvider` and threads the answer through React
6
+ * context. Aurora has a context, but a provider would be the wrong mechanism
7
+ * here: the direction is already on the page. `<html dir="rtl">`, a `dir`
8
+ * attribute on one panel, a stylesheet setting `direction` — all of them are
9
+ * answered by the computed style, and none of them requires the application to
10
+ * remember to wrap anything. A provider would be a second source of truth that
11
+ * silently disagrees with the first.
12
+ *
13
+ * The distinction that matters to callers is PHYSICAL versus LOGICAL. An arrow
14
+ * key is physical: ArrowRight means the key to the right, always. "The next
15
+ * item" is logical, and in a right-to-left list the next item is to the LEFT.
16
+ * `forward()` converts one into the other, and is the whole of this module's
17
+ * job.
18
+ */
19
+ /**
20
+ * The direction this element is laid out in.
21
+ *
22
+ * The computed style rather than the `dir` attribute, so an element inheriting
23
+ * from `<html dir="rtl">` answers correctly without every anchor carrying the
24
+ * attribute itself. `ltr` wherever there is no layout to ask — a server
25
+ * render, a jsdom without styles — which is also the correct default.
26
+ */
27
+ export function directionOf(element) {
28
+ if (element === null || element === undefined)
29
+ return "ltr";
30
+ if (typeof getComputedStyle !== "function")
31
+ return "ltr";
32
+ try {
33
+ return getComputedStyle(element).direction === "rtl" ? "rtl" : "ltr";
34
+ }
35
+ catch {
36
+ // A detached node in some environments. Not a reason to fail a keypress.
37
+ return "ltr";
38
+ }
39
+ }
40
+ /** Shorthand for the check that reads better at a call site than `=== "rtl"`. */
41
+ export function isRightToLeft(element) {
42
+ return directionOf(element) === "rtl";
43
+ }
44
+ /**
45
+ * Which way a horizontal arrow key actually moves.
46
+ *
47
+ * `+1` for the next item, `-1` for the previous. ArrowRight is `+1` in a
48
+ * left-to-right widget and `-1` in a right-to-left one — that mirroring is the
49
+ * entire reason this exists, and getting it wrong makes every menu, tab list
50
+ * and toolbar navigate backwards for half the world's readers.
51
+ */
52
+ export function forward(key, element) {
53
+ const rightIsForward = !isRightToLeft(element);
54
+ if (key === "ArrowRight")
55
+ return rightIsForward ? 1 : -1;
56
+ return rightIsForward ? -1 : 1;
57
+ }
@@ -24,6 +24,7 @@
24
24
  * clipping ancestor between it and the root; an absolutely positioned popover
25
25
  * has to find an offset parent, and gets it wrong the moment one appears.
26
26
  */
27
+ import { isRightToLeft } from "./direction.js";
27
28
  const DEFAULT_OFFSET = 4;
28
29
  const DEFAULT_PADDING = 8;
29
30
  /**
@@ -221,6 +222,29 @@ function clamp(value, min, max) {
221
222
  return min;
222
223
  return Math.min(Math.max(value, min), max);
223
224
  }
225
+ /**
226
+ * The surface's size as laid out, before any transform.
227
+ *
228
+ * `getBoundingClientRect()` includes transforms, and every surface opens under
229
+ * `zoom-in-95`: measured on its first frame it is 5% short, and one placed on
230
+ * the `top` side lands that much too low, over the control that opened it. A
231
+ * transform never changes layout, so the `ResizeObserver` would not correct it
232
+ * afterwards either. floating-ui reads the same two sources in the same order
233
+ * (`getCssDimensions`): the computed size, which keeps sub-pixel widths, and
234
+ * the integer offset size when the two disagree.
235
+ */
236
+ function layoutRect(element) {
237
+ const box = element.getBoundingClientRect();
238
+ const css = getComputedStyle(element);
239
+ let width = Number.parseFloat(css.width) || 0;
240
+ let height = Number.parseFloat(css.height) || 0;
241
+ if (Math.round(width) !== element.offsetWidth ||
242
+ Math.round(height) !== element.offsetHeight) {
243
+ width = element.offsetWidth;
244
+ height = element.offsetHeight;
245
+ }
246
+ return { x: box.x, y: box.y, width, height };
247
+ }
224
248
  /**
225
249
  * Position `floating` against `anchor` and keep it there.
226
250
  *
@@ -239,7 +263,7 @@ export function autoPosition(anchor, floating, options = {}) {
239
263
  if (options.matchWidth === true) {
240
264
  floating.style.width = `${anchorRect.width}px`;
241
265
  }
242
- const floatingRect = floating.getBoundingClientRect();
266
+ const floatingRect = layoutRect(floating);
243
267
  const position = resolvePosition(anchorRect, floatingRect, { width: window.innerWidth, height: window.innerHeight }, { ...options, rtl });
244
268
  floating.style.position = "fixed";
245
269
  floating.style.left = `${Math.round(position.x)}px`;
@@ -285,18 +309,6 @@ export function autoPosition(anchor, floating, options = {}) {
285
309
  },
286
310
  };
287
311
  }
288
- /**
289
- * Is this element laid out right to left?
290
- *
291
- * The computed style rather than the `dir` attribute, so an element inheriting
292
- * the direction from `<html dir="rtl">` is answered correctly without every
293
- * anchor having to carry the attribute itself.
294
- */
295
- function isRightToLeft(element) {
296
- if (typeof getComputedStyle !== "function")
297
- return false;
298
- return getComputedStyle(element).direction === "rtl";
299
- }
300
312
  /**
301
313
  * Watch elements for size changes, where the platform supports it.
302
314
  *
@@ -11,6 +11,16 @@
11
11
  * layout engine, which is why `isVisible` reads `offsetParent` and computed
12
12
  * styles rather than trusting the markup.
13
13
  */
14
+ /**
15
+ * The standard tabbable set.
16
+ *
17
+ * Exported because a composite widget that navigates "whatever controls are in
18
+ * here" — a toolbar — needs the same definition, and a second copy next door
19
+ * is how the two drift into disagreeing about `summary` or `contenteditable`.
20
+ * It is a selector, not an answer: `isFocusable` below is still what decides,
21
+ * because a selector cannot see `display: none` or a collapsed `<details>`.
22
+ */
23
+ export declare const FOCUSABLE_SELECTOR: string;
14
24
  /**
15
25
  * Is the element rendered and interactive right now?
16
26
  *
@@ -12,7 +12,16 @@
12
12
  * layout engine, which is why `isVisible` reads `offsetParent` and computed
13
13
  * styles rather than trusting the markup.
14
14
  */
15
- const FOCUSABLE_SELECTOR = [
15
+ /**
16
+ * The standard tabbable set.
17
+ *
18
+ * Exported because a composite widget that navigates "whatever controls are in
19
+ * here" — a toolbar — needs the same definition, and a second copy next door
20
+ * is how the two drift into disagreeing about `summary` or `contenteditable`.
21
+ * It is a selector, not an answer: `isFocusable` below is still what decides,
22
+ * because a selector cannot see `display: none` or a collapsed `<details>`.
23
+ */
24
+ export const FOCUSABLE_SELECTOR = [
16
25
  "a[href]",
17
26
  "area[href]",
18
27
  "button:not([disabled])",
@@ -13,10 +13,11 @@
13
13
  * subtly different implementation next door.
14
14
  */
15
15
  export { type Controllable, type ControllableOptions, controllable, } from "./controllable.js";
16
+ export { type Direction, directionOf, forward, isRightToLeft, } from "./direction.js";
16
17
  export { type DismissableLayer, type DismissableOptions, type DismissReason, dismissable, layerCount, } from "./dismissable.js";
17
18
  export { type Align, type AutoPosition, type AutoPositionOptions, autoPosition, type Placement, type Position, type PositionOptions, type Rect, resolvePosition, type Side, type Viewport, } from "./floating.js";
18
19
  export { type FloatingSurfaceOptions, floatingSurface, } from "./floatingSurface.js";
19
- export { firstFocusable, focusableWithin, focusSilently, isFocusable, isVisible, } from "./focusable.js";
20
+ export { FOCUSABLE_SELECTOR, firstFocusable, focusableWithin, focusSilently, isFocusable, isVisible, } from "./focusable.js";
20
21
  export { type FocusTrap, type FocusTrapOptions, focusTrap, } from "./focusTrap.js";
21
22
  export { type MenuAction, type MenuCheckbox, type MenuEntry, type MenuLabel, type MenuRadioGroup, type MenuSeparator, type MenuSubmenu, menuPanel, menuPanelClasses, wireMenu, } from "./menu.js";
22
23
  export { type ModalSurfaceOptions, modalSurface } from "./modalSurface.js";
@@ -13,10 +13,11 @@
13
13
  * subtly different implementation next door.
14
14
  */
15
15
  export { controllable, } from "./controllable.js";
16
+ export { directionOf, forward, isRightToLeft, } from "./direction.js";
16
17
  export { dismissable, layerCount, } from "./dismissable.js";
17
18
  export { autoPosition, resolvePosition, } from "./floating.js";
18
19
  export { floatingSurface, } from "./floatingSurface.js";
19
- export { firstFocusable, focusableWithin, focusSilently, isFocusable, isVisible, } from "./focusable.js";
20
+ export { FOCUSABLE_SELECTOR, firstFocusable, focusableWithin, focusSilently, isFocusable, isVisible, } from "./focusable.js";
20
21
  export { focusTrap, } from "./focusTrap.js";
21
22
  export { menuPanel, menuPanelClasses, wireMenu, } from "./menu.js";
22
23
  export { modalSurface } from "./modalSurface.js";