@mdbase-dev/ui 0.1.0-beta.156 → 0.1.0-beta.157

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/css/controls.css CHANGED
@@ -262,7 +262,7 @@ textarea.mdbase-field {
262
262
  border-radius: var(--control-radius);
263
263
  outline: 0;
264
264
  color: var(--color-text-soft);
265
- background: var(--color-surface);
265
+ background: var(--color-surface-overlay);
266
266
  font-size: var(--control-font-size);
267
267
  overscroll-behavior: contain;
268
268
  }
@@ -715,8 +715,8 @@ textarea.mdbase-field {
715
715
  border: 1px solid var(--color-border-strong);
716
716
  border-radius: var(--control-radius);
717
717
  color: var(--color-text);
718
- background: var(--color-surface);
719
- box-shadow: none;
718
+ background: var(--color-surface-overlay);
719
+ box-shadow: var(--elevation-high);
720
720
  }
721
721
 
722
722
  .mdbase-dialog::backdrop {
package/css/motion.css CHANGED
@@ -2,6 +2,7 @@
2
2
  /* Transitions share durations and easing; settled confirmations hold then fade. */
3
3
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
4
4
  --ease-standard: cubic-bezier(0.4, 0, 0.2, 1);
5
+ --ease-exit: cubic-bezier(0.4, 0, 1, 1);
5
6
  --motion-fast: 120ms;
6
7
  --motion-quick: 150ms;
7
8
  --motion-base: 180ms;
@@ -11,7 +12,6 @@
11
12
  --motion-settle: 2.4s;
12
13
  --motion-enter: 160ms;
13
14
  --motion-exit: 120ms;
14
- --motion-grant: 300ms;
15
15
  --motion-confirm: 1s;
16
16
  }
17
17
 
@@ -21,12 +21,13 @@
21
21
  transition: opacity var(--motion-enter) var(--ease-out), transform var(--motion-enter) var(--ease-out);
22
22
  }
23
23
  .mdbase-overlay::backdrop { opacity: 1; transition: opacity var(--motion-enter) var(--ease-out); }
24
- .mdbase-overlay[data-open="false"]::backdrop { opacity: 0; transition-duration: var(--motion-exit); }
24
+ .mdbase-overlay[data-open="false"]::backdrop { opacity: 0; transition-duration: var(--motion-exit); transition-timing-function: var(--ease-exit); }
25
25
  .mdbase-overlay[data-open="false"] {
26
26
  opacity: 0;
27
27
  transform: scale(.98);
28
28
  pointer-events: none;
29
29
  transition-duration: var(--motion-exit);
30
+ transition-timing-function: var(--ease-exit);
30
31
  }
31
32
  @starting-style {
32
33
  .mdbase-overlay[data-open="true"] { opacity: 0; transform: scale(.98); }
@@ -36,7 +37,6 @@
36
37
  :root {
37
38
  --motion-enter: 0ms;
38
39
  --motion-exit: 0ms;
39
- --motion-grant: 0ms;
40
40
  --motion-confirm: 0ms;
41
41
  --motion-fast: 0ms;
42
42
  --motion-quick: 0ms;
package/css/palette.css CHANGED
@@ -1,5 +1,6 @@
1
1
  /* Shared by the portal palette and Editor quick open after its npm repin. */
2
2
  .mdbase-dialog.mdbase-command-palette {
3
+ --accent-soft: var(--color-accent-soft);
3
4
  width: min(var(--palette-width), calc(100vw - 16px));
4
5
  margin: var(--palette-top) auto auto;
5
6
  max-height: calc(100dvh - var(--palette-top) - 16px);
@@ -40,14 +41,17 @@
40
41
  }
41
42
 
42
43
  .mdbase-command-results {
43
- min-height: 0;
44
+ max-height: 380px;
44
45
  overflow: auto;
45
46
  padding: 4px 6px 8px;
46
47
  scroll-padding: 28px 0 8px;
47
- transition: height var(--motion-enter) var(--ease-out);
48
48
  }
49
49
 
50
50
  .mdbase-command-group {
51
+ position: sticky;
52
+ top: -4px;
53
+ z-index: 1;
54
+ background: var(--color-surface-overlay);
51
55
  padding: 10px 10px 4px;
52
56
  color: var(--color-text-muted);
53
57
  font-size: var(--font-size-caption);
@@ -100,6 +104,11 @@
100
104
  font-weight: var(--font-weight-medium);
101
105
  }
102
106
 
107
+ .mdbase-command-results mark {
108
+ color: inherit;
109
+ background: var(--accent-soft);
110
+ }
111
+
103
112
  .mdbase-command-results small {
104
113
  flex: 1 1 auto;
105
114
  color: var(--color-text-muted);
package/css/toast.css CHANGED
@@ -3,9 +3,9 @@
3
3
  .mdbase-toast-slot[data-open="false"] { grid-template-rows: 0fr; opacity: 0; transform: translateY(8px); pointer-events: none; transition-duration: var(--motion-exit); }
4
4
  @starting-style { .mdbase-toast-slot[data-open="true"] { grid-template-rows: 0fr; opacity: 0; transform: translateY(8px); } }
5
5
  .mdbase-toast-clip { min-height: 0; overflow: hidden; }
6
- .mdbase-toast { display: flex; align-items: center; gap: 9px; padding: 8px 8px 8px 13px; border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm); background: var(--color-surface); color: var(--color-text-soft); box-shadow: var(--elevation-high); font-size: var(--font-size-ui); }
6
+ .mdbase-toast { display: flex; align-items: center; gap: 9px; padding: 8px 8px 8px 13px; border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm); background: var(--color-surface-overlay); color: var(--color-text-soft); box-shadow: var(--elevation-high); font-size: var(--font-size-ui); }
7
7
  .mdbase-toast-clip > .mdbase-toast { margin-top: 8px; }
8
8
  .mdbase-toast span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
9
9
  .mdbase-toast button { flex: none; font-size: inherit; }
10
- @media (max-width: 640px) { .mdbase-toaster { top: max(16px, env(safe-area-inset-top)); bottom: auto; left: 16px; right: 16px; max-width: none; } }
10
+ @media (max-width: 640px) { .mdbase-toaster { bottom: max(16px, env(safe-area-inset-bottom)); left: 16px; right: 16px; max-width: none; } }
11
11
  @media (prefers-reduced-motion: reduce) { .mdbase-toast-slot { transition: none; transform: none; } }
package/css/tokens.css CHANGED
@@ -8,6 +8,7 @@
8
8
  --color-canvas: oklch(100% 0 0);
9
9
  --color-sidebar: oklch(98% 0.002 286);
10
10
  --color-surface: oklch(100% 0 0);
11
+ --color-surface-overlay: oklch(100% 0 0);
11
12
  --color-surface-subtle: oklch(97% 0.001 286);
12
13
  --color-text: oklch(21% 0.006 286);
13
14
  --color-text-soft: oklch(37% 0.012 286);
@@ -83,6 +84,7 @@
83
84
  --color-canvas: oklch(18.7% 0.002 286);
84
85
  --color-sidebar: oklch(16% 0.002 286);
85
86
  --color-surface: oklch(18.7% 0.002 286);
87
+ --color-surface-overlay: oklch(21.4% 0.003 286);
86
88
  --color-surface-subtle: oklch(23.6% 0.004 286);
87
89
  --color-text: oklch(94.7% 0.003 286);
88
90
  --color-text-soft: oklch(82% 0.007 286);
@@ -127,6 +129,7 @@
127
129
  --color-canvas: oklch(18.7% 0.002 286);
128
130
  --color-sidebar: oklch(16% 0.002 286);
129
131
  --color-surface: oklch(18.7% 0.002 286);
132
+ --color-surface-overlay: oklch(21.4% 0.003 286);
130
133
  --color-surface-subtle: oklch(23.6% 0.004 286);
131
134
  --color-text: oklch(94.7% 0.003 286);
132
135
  --color-text-soft: oklch(82% 0.007 286);
@@ -2,6 +2,7 @@ import { type JSX, type RefObject, type ReactNode } from "react";
2
2
  export interface Command {
3
3
  readonly id: string;
4
4
  readonly label: string;
5
+ readonly content?: ReactNode;
5
6
  readonly detail?: string | undefined;
6
7
  readonly icon?: ReactNode;
7
8
  /** Stable group ID; headings follow first appearance and may be presented by groupLabel. */
@@ -28,7 +29,7 @@ export declare function matchingCommands(commands: readonly Command[], query: st
28
29
  * Find or run anything: every mdbase app opens it with Mod+K. Typing filters commands; the
29
30
  * arrows move, Enter runs, Shift+Enter runs a command's alternate, Escape closes.
30
31
  */
31
- export declare function CommandPalette({ open, commands, onClose, label, placeholder, showAll, groupLabel, returnFocusRef, emptyState }: {
32
+ export declare function CommandPalette({ open, commands, onClose, label, placeholder, showAll, groupLabel, returnFocusRef, emptyState, initialQuery, getResults, inputLabel }: {
32
33
  readonly open: boolean;
33
34
  readonly commands: readonly Command[];
34
35
  readonly onClose: () => void;
@@ -39,4 +40,7 @@ export declare function CommandPalette({ open, commands, onClose, label, placeho
39
40
  readonly groupLabel?: ((group: string) => string) | undefined;
40
41
  readonly returnFocusRef?: RefObject<HTMLElement | null> | undefined;
41
42
  readonly emptyState?: ReactNode;
43
+ readonly initialQuery?: string;
44
+ readonly getResults?: (query: string) => readonly Command[];
45
+ readonly inputLabel?: string;
42
46
  }): JSX.Element | null;
@@ -2,7 +2,7 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
2
2
  import { i18n as _i18n } from "@lingui/core";
3
3
  import { useLocaleRevision } from "./i18n.js";
4
4
  import { Dialog } from "./Dialog.js";
5
- import { Fragment, useEffect, useId, useMemo, useRef, useState } from "react";
5
+ import { Fragment, useEffect, useLayoutEffect, useId, useMemo, useRef, useState } from "react";
6
6
  export function isApplePlatform() {
7
7
  return typeof navigator !== "undefined" && /Mac|iPhone|iPad/u.test(navigator.platform || navigator.userAgent);
8
8
  }
@@ -20,6 +20,21 @@ export function shortcutLabel(shortcut) {
20
20
  return apple ? "⇧" : "Shift";
21
21
  case "alt":
22
22
  return apple ? "⌥" : "Alt";
23
+ case "arrowdown":
24
+ return "↓";
25
+ case "arrowup":
26
+ return "↑";
27
+ case "arrowleft":
28
+ return "←";
29
+ case "arrowright":
30
+ return "→";
31
+ case "contextmenu":
32
+ return _i18n._(
33
+ /** i18n */
34
+ {
35
+ id: "zucql-",
36
+ message: "Menu"
37
+ });
23
38
  default:
24
39
  return part.length === 1 ? part.toUpperCase() : part;
25
40
  }
@@ -75,7 +90,10 @@ export function CommandPalette({
75
90
  showAll,
76
91
  groupLabel,
77
92
  returnFocusRef,
78
- emptyState
93
+ emptyState,
94
+ initialQuery = "",
95
+ getResults,
96
+ inputLabel = placeholder
79
97
  }) {
80
98
  useLocaleRevision();
81
99
  return _jsx(Dialog, {
@@ -93,7 +111,10 @@ export function CommandPalette({
93
111
  showAll: showAll,
94
112
  groupLabel: groupLabel,
95
113
  returnFocusRef: returnFocusRef,
96
- emptyState: emptyState
114
+ emptyState: emptyState,
115
+ initialQuery: initialQuery,
116
+ getResults: getResults,
117
+ inputLabel: inputLabel
97
118
  })
98
119
  });
99
120
  }
@@ -106,20 +127,28 @@ function OpenCommandPalette({
106
127
  showAll,
107
128
  groupLabel,
108
129
  returnFocusRef,
109
- emptyState
130
+ emptyState,
131
+ initialQuery,
132
+ getResults,
133
+ inputLabel
110
134
  }) {
111
135
  useLocaleRevision();
112
- const [query, setQuery] = useState("");
136
+ const [query, setQuery] = useState(initialQuery);
113
137
  const [active, setActive] = useState(0);
114
138
  const inputRef = useRef(null);
115
- const matches = useMemo(() => matchingCommands(commands, query, showAll), [commands, query, showAll]);
116
- const resultHeight = Math.min(380, Math.max(152, Math.ceil((matches.length * 38 + new Set(matches.map(command => command.group)).size * 30 + 12) / 76) * 76));
139
+ const resultsRef = useRef(null);
140
+ const matches = useMemo(() => getResults ? getResults(query) : matchingCommands(commands, query, showAll), [commands, query, showAll, getResults]);
141
+ useLayoutEffect(() => {
142
+ resultsRef.current.querySelector('[aria-selected="true"]')?.scrollIntoView({
143
+ block: "nearest"
144
+ });
145
+ }, [active, matches]);
117
146
  useEffect(() => {
118
147
  if (open) {
119
- setQuery("");
148
+ setQuery(initialQuery);
120
149
  setActive(0);
121
150
  }
122
- }, [open]);
151
+ }, [open, initialQuery]);
123
152
  const run = (command, alternate = false) => {
124
153
  inputRef.current?.closest("dialog")?.close();
125
154
  returnFocusRef?.current?.focus({
@@ -147,7 +176,7 @@ function OpenCommandPalette({
147
176
  })]
148
177
  }), _jsx("span", {
149
178
  className: "mdbase-visually-hidden",
150
- children: placeholder
179
+ children: inputLabel
151
180
  }), _jsx("input", {
152
181
  ref: inputRef,
153
182
  "data-autofocus": true,
@@ -167,11 +196,9 @@ function OpenCommandPalette({
167
196
  }
168
197
  })]
169
198
  }), _jsx("div", {
199
+ ref: resultsRef,
170
200
  id: `${hintId}-results`,
171
201
  className: "mdbase-command-results",
172
- style: {
173
- height: resultHeight
174
- },
175
202
  role: "listbox",
176
203
  "aria-label": _i18n._(
177
204
  /** i18n */
@@ -188,6 +215,7 @@ function OpenCommandPalette({
188
215
  }) : null, _jsx(CommandRow, {
189
216
  id: `${hintId}-${command.id}`,
190
217
  command: command,
218
+ query: query,
191
219
  active: index === active,
192
220
  onRun: run
193
221
  })]
@@ -251,19 +279,17 @@ function OpenCommandPalette({
251
279
  function CommandRow({
252
280
  id,
253
281
  command,
282
+ query,
254
283
  active,
255
284
  onRun
256
285
  }) {
257
286
  useLocaleRevision();
258
- const ref = useRef(null);
259
- useEffect(() => {
260
- if (active) ref.current?.scrollIntoView({
261
- block: "nearest"
262
- });
263
- }, [active]);
287
+ const pattern = query.trim().split(/\s+/u).filter(Boolean).map(term => term.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&")).join("|");
288
+ const label = pattern ? command.label.split(new RegExp(`(${pattern})`, "giu")).map((part, index) => index % 2 ? _jsx("mark", {
289
+ children: part
290
+ }, index) : part) : command.label;
264
291
  return _jsxs("button", {
265
292
  id: id,
266
- ref: ref,
267
293
  tabIndex: -1,
268
294
  type: "button",
269
295
  role: "option",
@@ -274,13 +300,15 @@ function CommandRow({
274
300
  className: "mdbase-command-icon",
275
301
  "aria-hidden": "true",
276
302
  children: command.icon
277
- }), _jsxs("span", {
303
+ }), _jsx("span", {
278
304
  className: "mdbase-command-copy",
279
- children: [_jsx("strong", {
280
- children: command.label
281
- }), command.detail ? _jsx("small", {
282
- children: command.detail
283
- }) : null]
305
+ children: command.content ?? _jsxs(_Fragment, {
306
+ children: [_jsx("strong", {
307
+ children: label
308
+ }), command.detail ? _jsx("small", {
309
+ children: command.detail
310
+ }) : null]
311
+ })
284
312
  }), command.alternate && active ? _jsxs("span", {
285
313
  className: "mdbase-command-alternate",
286
314
  children: [shortcutLabel("shift"), "\u21B5 ", command.alternate.label]
@@ -297,6 +325,9 @@ function handleKeys(event, matches, active, setActive, run, close) {
297
325
  event.preventDefault();
298
326
  const direction = event.key === "ArrowDown" ? 1 : -1;
299
327
  setActive((active + direction + matches.length) % Math.max(1, matches.length));
328
+ } else if (event.key === "Home" || event.key === "End") {
329
+ event.preventDefault();
330
+ setActive(event.key === "Home" ? 0 : Math.max(0, matches.length - 1));
300
331
  } else if (event.key === "Enter") {
301
332
  const command = matches[active];
302
333
  if (command) {
@@ -1,5 +1,5 @@
1
1
  import { type ReactNode, type RefObject } from "react";
2
- export declare function ConfirmDialog({ open, title, consequence, confirmLabel, pendingLabel, busy, disabled, onConfirm, onClose, returnFocusRef, children }: {
2
+ export declare function ConfirmDialog({ open, title, consequence, confirmLabel, pendingLabel, busy, disabled, onConfirm, onClose, returnFocusRef, children, cancelLabel, tone, initialFocus, role }: {
3
3
  readonly open: boolean;
4
4
  readonly title: string;
5
5
  readonly consequence?: string;
@@ -11,4 +11,8 @@ export declare function ConfirmDialog({ open, title, consequence, confirmLabel,
11
11
  readonly onClose: () => void;
12
12
  readonly returnFocusRef?: RefObject<HTMLElement | null> | undefined;
13
13
  readonly children?: ReactNode;
14
+ readonly cancelLabel?: string | undefined;
15
+ readonly tone?: "default" | "danger" | undefined;
16
+ readonly initialFocus?: "confirm" | "cancel" | undefined;
17
+ readonly role?: "dialog" | "alertdialog";
14
18
  }): import("react").JSX.Element;
@@ -14,7 +14,16 @@ export function ConfirmDialog({
14
14
  onConfirm,
15
15
  onClose,
16
16
  returnFocusRef,
17
- children
17
+ children,
18
+ cancelLabel = _i18n._(
19
+ /** i18n */
20
+ {
21
+ id: "dEgA5A",
22
+ message: "Cancel"
23
+ }),
24
+ tone = "danger",
25
+ initialFocus = "cancel",
26
+ role = "dialog"
18
27
  }) {
19
28
  useLocaleRevision();
20
29
  const [pending, setPending] = useState(false);
@@ -22,6 +31,7 @@ export function ConfirmDialog({
22
31
  const working = busy || pending;
23
32
  return _jsxs(Dialog, {
24
33
  open: open,
34
+ role: role,
25
35
  title: title,
26
36
  descriptionId: consequence ? descriptionId : undefined,
27
37
  onClose: onClose,
@@ -36,21 +46,20 @@ export function ConfirmDialog({
36
46
  children: [_jsx("button", {
37
47
  type: "button",
38
48
  className: "mdbase-button is-tertiary",
39
- "data-autofocus": true,
49
+ "data-autofocus": initialFocus === "cancel" || undefined,
40
50
  disabled: working,
41
51
  onClick: onClose,
42
- children: _i18n._(
43
- /** i18n */
44
- {
45
- id: "dEgA5A",
46
- message: "Cancel"
47
- })
52
+ children: cancelLabel
48
53
  }), _jsx("button", {
49
54
  type: "button",
50
- className: "mdbase-button is-danger",
55
+ className: `mdbase-button ${tone === "danger" ? "is-danger" : "is-primary"}`,
56
+ "data-autofocus": initialFocus === "confirm" || undefined,
51
57
  "aria-busy": working || undefined,
52
58
  disabled: working || disabled,
53
- onClick: async () => {
59
+ onClick: async event => {
60
+ event.currentTarget.closest("dialog")?.focus({
61
+ preventScroll: true
62
+ });
54
63
  setPending(true);
55
64
  try {
56
65
  await onConfirm();
package/dist/Dialog.d.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  import { type JSX, type ReactNode, type RefObject } from "react";
2
- export declare function Dialog({ open, onClose, title, descriptionId, className, closeDisabled, returnFocusRef, children }: {
2
+ export declare function Dialog({ open, onClose, title, descriptionId, className, closeDisabled, returnFocusRef, initialFocusRef, role, children }: {
3
3
  readonly open: boolean;
4
4
  readonly onClose: () => void;
5
- readonly title: string;
5
+ readonly title: ReactNode;
6
6
  readonly descriptionId?: string | undefined;
7
7
  readonly className?: string | undefined;
8
8
  readonly closeDisabled?: boolean;
9
9
  readonly returnFocusRef?: RefObject<HTMLElement | null> | undefined;
10
+ readonly initialFocusRef?: RefObject<HTMLElement | null> | undefined;
11
+ readonly role?: "dialog" | "alertdialog";
10
12
  readonly children: ReactNode;
11
13
  }): JSX.Element | null;
package/dist/Dialog.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { i18n as _i18n } from "@lingui/core";
3
- import { useLayoutEffect, useRef } from "react";
3
+ import { useId, useLayoutEffect, useRef } from "react";
4
4
  import { createPortal } from "react-dom";
5
5
  import { useLocaleRevision } from "./i18n.js";
6
6
  import { useOverlay } from "./overlay.js";
@@ -12,6 +12,8 @@ export function Dialog({
12
12
  className,
13
13
  closeDisabled = false,
14
14
  returnFocusRef,
15
+ initialFocusRef,
16
+ role = "dialog",
15
17
  children
16
18
  }) {
17
19
  useLocaleRevision();
@@ -20,26 +22,55 @@ export function Dialog({
20
22
  present
21
23
  } = useOverlay(open);
22
24
  const invoker = useRef(null);
25
+ const titleId = useId();
23
26
  useLayoutEffect(() => {
24
27
  const dialog = ref.current;
25
28
  if (!dialog || !open || dialog.open) return;
26
- const previous = document.querySelector("dialog[open]");
27
- if (previous && previous !== dialog) {
28
- previous.dispatchEvent(new Event("cancel", {
29
- cancelable: true
30
- }));
31
- previous.close();
32
- }
33
29
  invoker.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
34
30
  dialog.showModal();
35
- dialog.querySelector("[data-autofocus]")?.focus();
36
- }, [open, ref]);
31
+ const focus = () => {
32
+ const scope = initialFocusRef?.current ?? dialog;
33
+ return scope.querySelector(initialFocusRef ? 'button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex="0"]' : "[data-autofocus]");
34
+ };
35
+ const first = focus();
36
+ if (first) first.focus({
37
+ preventScroll: true
38
+ });else if (initialFocusRef) dialog.focus({
39
+ preventScroll: true
40
+ });
41
+ if (!initialFocusRef || first) return;
42
+ const observer = new MutationObserver(() => {
43
+ if (document.activeElement !== dialog) return;
44
+ const control = focus();
45
+ if (control) {
46
+ control.focus({
47
+ preventScroll: true
48
+ });
49
+ observer.disconnect();
50
+ }
51
+ });
52
+ observer.observe(dialog, {
53
+ childList: true,
54
+ subtree: true
55
+ });
56
+ return () => observer.disconnect();
57
+ }, [open, ref, initialFocusRef]);
58
+ useLayoutEffect(() => {
59
+ const dialog = ref.current;
60
+ if (!dialog || !open) return;
61
+ if (closeDisabled && (!dialog.contains(document.activeElement) || document.activeElement?.matches(":disabled"))) dialog.focus({
62
+ preventScroll: true
63
+ });
64
+ if (!closeDisabled && document.activeElement === dialog) dialog.querySelector("[data-autofocus]:not(:disabled)")?.focus({
65
+ preventScroll: true
66
+ });
67
+ }, [closeDisabled, open, ref]);
37
68
  useLayoutEffect(() => {
38
69
  const dialog = ref.current;
39
70
  return () => {
40
71
  const wasOpen = dialog?.open;
41
72
  dialog?.close();
42
- if (wasOpen && !document.querySelector("dialog[open]")) (returnFocusRef?.current ?? invoker.current)?.focus({
73
+ if (wasOpen) (returnFocusRef?.current ?? invoker.current)?.focus({
43
74
  preventScroll: true
44
75
  });
45
76
  };
@@ -49,21 +80,32 @@ export function Dialog({
49
80
  ref: ref,
50
81
  className: ["mdbase-dialog mdbase-overlay", className].filter(Boolean).join(" "),
51
82
  "data-open": open,
52
- role: "dialog",
53
- "aria-label": title,
83
+ role: role,
84
+ "aria-modal": "true",
85
+ "aria-labelledby": titleId,
54
86
  "aria-describedby": descriptionId,
87
+ tabIndex: -1,
55
88
  onKeyDown: event => {
56
89
  event.stopPropagation();
57
90
  if (event.key === "Escape") {
58
91
  event.preventDefault();
59
92
  if (!closeDisabled) onClose();
60
93
  }
94
+ if (event.key === "Tab" && closeDisabled) {
95
+ const controls = [...event.currentTarget.querySelectorAll('button:not(:disabled), a[href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex="0"]')].filter(control => control.getClientRects().length > 0);
96
+ const current = controls.indexOf(document.activeElement);
97
+ const next = current < 0 ? event.shiftKey ? controls.length - 1 : 0 : (current + (event.shiftKey ? -1 : 1) + controls.length) % controls.length;
98
+ event.preventDefault();
99
+ (controls.length ? controls[next] : event.currentTarget)?.focus({
100
+ preventScroll: true
101
+ });
102
+ }
61
103
  },
62
104
  onCancel: event => {
63
105
  event.preventDefault();
64
106
  if (!closeDisabled) onClose();
65
107
  },
66
- onMouseDown: event => {
108
+ onClick: event => {
67
109
  if (!closeDisabled && event.target === event.currentTarget) onClose();
68
110
  },
69
111
  children: _jsxs("div", {
@@ -71,6 +113,7 @@ export function Dialog({
71
113
  children: [_jsxs("header", {
72
114
  className: "mdbase-dialog-header",
73
115
  children: [_jsx("h2", {
116
+ id: titleId,
74
117
  children: title
75
118
  }), _jsx("button", {
76
119
  type: "button",
@@ -71,6 +71,7 @@ export function FeedbackMarkup({
71
71
  setTool("draw");
72
72
  setCount(0);
73
73
  setError("");
74
+ cursor.current = null;
74
75
  let live = true;
75
76
  const decoded = new Image();
76
77
  decoded.src = screenshotUrl(screenshot);
package/dist/Menu.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { ReactNode, RefObject } from "react";
2
- export declare function Menu({ open, triggerRef, onClose, id, label, className, children }: {
1
+ import { type KeyboardEvent, type ReactNode, type RefObject } from "react";
2
+ export declare function Menu({ open, triggerRef, onClose, id, label, className, children, point }: {
3
3
  readonly open: boolean;
4
4
  readonly triggerRef: RefObject<HTMLElement | null>;
5
5
  readonly onClose: (refocus: boolean) => void;
@@ -7,4 +7,22 @@ export declare function Menu({ open, triggerRef, onClose, id, label, className,
7
7
  readonly label?: string;
8
8
  readonly className?: string;
9
9
  readonly children: ReactNode;
10
+ readonly point?: {
11
+ readonly left: number;
12
+ readonly top: number;
13
+ } | undefined;
10
14
  }): import("react").JSX.Element | null;
15
+ export declare function useMenuTrigger(): {
16
+ id: string;
17
+ open: boolean;
18
+ close: (refocus: boolean) => void;
19
+ trigger: RefObject<HTMLButtonElement | null>;
20
+ triggerProps: {
21
+ ref: RefObject<HTMLButtonElement | null>;
22
+ "aria-haspopup": "menu";
23
+ "aria-expanded": boolean;
24
+ "aria-controls": string | undefined;
25
+ onClick: () => void;
26
+ onKeyDown: (event: KeyboardEvent) => void;
27
+ };
28
+ };
package/dist/Menu.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useId, useRef, useState } from "react";
2
3
  import { moveMenuFocus, useMenuPopover } from "./popover.js";
3
4
  import { useOverlay } from "./overlay.js";
4
5
  export function Menu({
@@ -8,7 +9,8 @@ export function Menu({
8
9
  id,
9
10
  label,
10
11
  className = "mdbase-menu",
11
- children
12
+ children,
13
+ point
12
14
  }) {
13
15
  const {
14
16
  ref,
@@ -16,7 +18,8 @@ export function Menu({
16
18
  } = useOverlay(open);
17
19
  useMenuPopover(ref, triggerRef, onClose, {
18
20
  align: "end",
19
- open
21
+ open,
22
+ point
20
23
  });
21
24
  return present ? _jsx("div", {
22
25
  ref: ref,
@@ -31,3 +34,31 @@ export function Menu({
31
34
  children: children
32
35
  }) : null;
33
36
  }
37
+ export function useMenuTrigger() {
38
+ const id = useId();
39
+ const [open, setOpen] = useState(false);
40
+ const trigger = useRef(null);
41
+ const close = refocus => {
42
+ setOpen(false);
43
+ if (refocus) trigger.current?.focus();
44
+ };
45
+ return {
46
+ id,
47
+ open,
48
+ close,
49
+ trigger,
50
+ triggerProps: {
51
+ ref: trigger,
52
+ "aria-haspopup": "menu",
53
+ "aria-expanded": open,
54
+ "aria-controls": open ? id : undefined,
55
+ onClick: () => setOpen(value => !value),
56
+ onKeyDown: event => {
57
+ if (event.key === "ArrowDown" || event.key === "ArrowUp") {
58
+ event.preventDefault();
59
+ setOpen(true);
60
+ }
61
+ }
62
+ }
63
+ };
64
+ }
package/dist/Toaster.d.ts CHANGED
@@ -1,2 +1,19 @@
1
+ export interface ToastItem {
2
+ id: string;
3
+ message: string;
4
+ tone?: "info" | "success" | "error";
5
+ action?: {
6
+ label: string;
7
+ onAction: () => void;
8
+ busy?: boolean;
9
+ dismiss?: boolean;
10
+ };
11
+ sticky?: boolean;
12
+ dismissible?: boolean;
13
+ durationMs?: number;
14
+ }
1
15
  export declare function toast(message: string, undo?: () => void): void;
2
- export declare function Toaster(): import("react").JSX.Element;
16
+ export declare function Toaster({ items, onDismiss }: {
17
+ items?: readonly ToastItem[];
18
+ onDismiss?: (id: string) => void;
19
+ }): import("react").JSX.Element;