@alulore/kumiko 0.18.2 → 0.19.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 (147) hide show
  1. package/dist/dialog/ask.d.ts +7 -0
  2. package/dist/dialog/ask.js +8 -0
  3. package/dist/dialog/dialog-content.d.ts +23 -0
  4. package/dist/dialog/dialog-content.js +15 -0
  5. package/dist/dialog/dialog-entry.d.ts +14 -0
  6. package/dist/dialog/dialog-entry.js +111 -0
  7. package/dist/dialog/dialog-labels.d.ts +23 -0
  8. package/dist/dialog/dialog-labels.js +16 -0
  9. package/dist/dialog/dialog-store.d.ts +139 -0
  10. package/dist/dialog/dialog-store.js +296 -0
  11. package/dist/dialog/dialog.css +39 -1
  12. package/dist/dialog/dialog.d.ts +0 -3
  13. package/dist/dialog/dialog.js +0 -6
  14. package/dist/dialog/index.d.ts +8 -2
  15. package/dist/dialog/index.js +7 -2
  16. package/dist/dialog/leave-guard.d.ts +24 -0
  17. package/dist/dialog/leave-guard.js +98 -0
  18. package/dist/dialog/nest.d.ts +14 -0
  19. package/dist/dialog/nest.js +26 -0
  20. package/dist/dialog/open-dialog.d.ts +16 -0
  21. package/dist/dialog/open-dialog.js +13 -0
  22. package/dist/dialog/overlay-host.d.ts +27 -0
  23. package/dist/dialog/overlay-host.js +47 -0
  24. package/dist/dialog/question-dialog.d.ts +21 -0
  25. package/dist/dialog/question-dialog.js +78 -0
  26. package/dist/drawer/drawer.css +18 -16
  27. package/dist/menu/menu.css +21 -17
  28. package/dist/otp-input/otp-input.css +38 -37
  29. package/dist/page/index.d.ts +8 -0
  30. package/dist/page/index.js +8 -0
  31. package/dist/page/page-action.d.ts +26 -0
  32. package/dist/page/page-action.js +23 -0
  33. package/dist/page/page-actions.d.ts +10 -0
  34. package/dist/page/page-actions.js +66 -0
  35. package/dist/page/page-back.d.ts +11 -0
  36. package/dist/page/page-back.js +17 -0
  37. package/dist/page/page-breadcrumbs.d.ts +21 -0
  38. package/dist/page/page-breadcrumbs.js +60 -0
  39. package/dist/page/page-context.d.ts +5 -0
  40. package/dist/page/page-context.js +13 -0
  41. package/dist/page/page-fit.d.ts +26 -0
  42. package/dist/page/page-fit.js +36 -0
  43. package/dist/page/page-header.d.ts +26 -0
  44. package/dist/page/page-header.js +16 -0
  45. package/dist/page/page-icons.d.ts +4 -0
  46. package/dist/page/page-icons.js +13 -0
  47. package/dist/page/page-labels.d.ts +12 -0
  48. package/dist/page/page-labels.js +6 -0
  49. package/dist/page/page-section.d.ts +14 -0
  50. package/dist/page/page-section.js +9 -0
  51. package/dist/page/page.css +422 -0
  52. package/dist/page/page.d.ts +16 -0
  53. package/dist/page/page.js +12 -0
  54. package/dist/page/use-measured-fit.d.ts +22 -0
  55. package/dist/page/use-measured-fit.js +75 -0
  56. package/dist/page/use-stuck.d.ts +7 -0
  57. package/dist/page/use-stuck.js +31 -0
  58. package/dist/pagination/index.d.ts +3 -0
  59. package/dist/pagination/index.js +3 -0
  60. package/dist/pagination/pagination-extras.d.ts +28 -0
  61. package/dist/pagination/pagination-extras.js +42 -0
  62. package/dist/pagination/pagination-fit.d.ts +15 -0
  63. package/dist/pagination/pagination-fit.js +52 -0
  64. package/dist/pagination/pagination-icons.d.ts +4 -0
  65. package/dist/pagination/pagination-icons.js +16 -0
  66. package/dist/pagination/pagination-labels.d.ts +23 -0
  67. package/dist/pagination/pagination-labels.js +14 -0
  68. package/dist/pagination/pagination-math.d.ts +7 -0
  69. package/dist/pagination/pagination-math.js +24 -0
  70. package/dist/pagination/pagination-motion.d.ts +6 -0
  71. package/dist/pagination/pagination-motion.js +71 -0
  72. package/dist/pagination/pagination.css +455 -0
  73. package/dist/pagination/pagination.d.ts +59 -0
  74. package/dist/pagination/pagination.js +77 -0
  75. package/dist/select/select.css +6 -10
  76. package/dist/server-render.test.js +49 -0
  77. package/dist/sidebar/app-shell.d.ts +54 -0
  78. package/dist/sidebar/app-shell.js +28 -0
  79. package/dist/sidebar/index.d.ts +9 -0
  80. package/dist/sidebar/index.js +8 -0
  81. package/dist/sidebar/shell-context.d.ts +30 -0
  82. package/dist/sidebar/shell-context.js +20 -0
  83. package/dist/sidebar/shell-sheet.d.ts +7 -0
  84. package/dist/sidebar/shell-sheet.js +12 -0
  85. package/dist/sidebar/shell-top-bar.d.ts +8 -0
  86. package/dist/sidebar/shell-top-bar.js +25 -0
  87. package/dist/sidebar/sidebar-body.d.ts +5 -0
  88. package/dist/sidebar/sidebar-body.js +37 -0
  89. package/dist/sidebar/sidebar-icons.d.ts +4 -0
  90. package/dist/sidebar/sidebar-icons.js +13 -0
  91. package/dist/sidebar/sidebar-item.d.ts +26 -0
  92. package/dist/sidebar/sidebar-item.js +68 -0
  93. package/dist/sidebar/sidebar-labels.d.ts +14 -0
  94. package/dist/sidebar/sidebar-labels.js +7 -0
  95. package/dist/sidebar/sidebar-marker.d.ts +12 -0
  96. package/dist/sidebar/sidebar-marker.js +77 -0
  97. package/dist/sidebar/sidebar-storage.d.ts +18 -0
  98. package/dist/sidebar/sidebar-storage.js +27 -0
  99. package/dist/sidebar/sidebar-toggle.d.ts +7 -0
  100. package/dist/sidebar/sidebar-toggle.js +18 -0
  101. package/dist/sidebar/sidebar.css +587 -0
  102. package/dist/sidebar/sidebar.d.ts +19 -0
  103. package/dist/sidebar/sidebar.js +31 -0
  104. package/dist/sidebar/use-collapsed.d.ts +13 -0
  105. package/dist/sidebar/use-collapsed.js +20 -0
  106. package/dist/sidebar/use-narrow.d.ts +4 -0
  107. package/dist/sidebar/use-narrow.js +18 -0
  108. package/dist/sidebar/use-shell-focus.d.ts +8 -0
  109. package/dist/sidebar/use-shell-focus.js +30 -0
  110. package/dist/sidebar/use-shell-shortcut.d.ts +4 -0
  111. package/dist/sidebar/use-shell-shortcut.js +32 -0
  112. package/dist/sidebar/use-shell-state.d.ts +18 -0
  113. package/dist/sidebar/use-shell-state.js +47 -0
  114. package/dist/slider/slider.css +9 -6
  115. package/dist/smooth-caret/caret-geometry.js +10 -4
  116. package/dist/table/data-table-props.d.ts +96 -0
  117. package/dist/table/data-table-props.js +1 -0
  118. package/dist/table/data-table.d.ts +7 -0
  119. package/dist/table/data-table.js +59 -0
  120. package/dist/table/index.d.ts +7 -0
  121. package/dist/table/index.js +5 -0
  122. package/dist/table/table-actions.d.ts +9 -0
  123. package/dist/table/table-actions.js +24 -0
  124. package/dist/table/table-builder.d.ts +60 -0
  125. package/dist/table/table-builder.js +99 -0
  126. package/dist/table/table-cells.d.ts +19 -0
  127. package/dist/table/table-cells.js +67 -0
  128. package/dist/table/table-columns.d.ts +38 -0
  129. package/dist/table/table-columns.js +119 -0
  130. package/dist/table/table-icons.d.ts +3 -0
  131. package/dist/table/table-icons.js +8 -0
  132. package/dist/table/table-labels.d.ts +24 -0
  133. package/dist/table/table-labels.js +17 -0
  134. package/dist/table/table-model.d.ts +28 -0
  135. package/dist/table/table-model.js +69 -0
  136. package/dist/table/table-sections.d.ts +25 -0
  137. package/dist/table/table-sections.js +79 -0
  138. package/dist/table/table-state.d.ts +42 -0
  139. package/dist/table/table-state.js +81 -0
  140. package/dist/table/table-types.d.ts +86 -0
  141. package/dist/table/table-types.js +1 -0
  142. package/dist/table/table.css +919 -0
  143. package/dist/table/use-table-view.d.ts +30 -0
  144. package/dist/table/use-table-view.js +147 -0
  145. package/dist/toast/index.d.ts +1 -2
  146. package/dist/toast/index.js +1 -2
  147. package/package.json +44 -1
@@ -15,6 +15,8 @@
15
15
  --kumiko-dialog-shadow: 0 24px 64px -16px color-mix(in oklab, CanvasText 40%, transparent);
16
16
  --kumiko-dialog-padding: 1.5rem;
17
17
  --kumiko-dialog-width: 28rem;
18
+ --kumiko-dialog-width-sm: 24rem;
19
+ --kumiko-dialog-width-lg: 40rem;
18
20
  --kumiko-dialog-max-width: 48rem;
19
21
  --kumiko-dialog-gutter: 1rem;
20
22
  --kumiko-dialog-gap: 1rem;
@@ -26,6 +28,9 @@
26
28
  --kumiko-dialog-description-weight: 400;
27
29
  --kumiko-dialog-close-size: 2rem;
28
30
  --kumiko-dialog-sheet-max-height: 85dvh;
31
+ --kumiko-dialog-warning-bg: #b45309;
32
+ --kumiko-dialog-warning-fg: #fff;
33
+ --kumiko-dialog-error-fg: light-dark(#b3261e, #ff8a80);
29
34
  }
30
35
 
31
36
  :where([data-slot$="dialog-content"]) {
@@ -70,6 +75,24 @@
70
75
  max-block-size: var(--_dialog-room-block);
71
76
  }
72
77
 
78
+ /*
79
+ * An opened dialog says its size with data-size. Medium is the plain width, so an app that sets
80
+ * --kumiko-dialog-width, or --kumiko-dialog-width-md for medium alone, still moves it.
81
+ */
82
+ :where([data-slot$="dialog-content"][data-size]:not([data-presentation="sheet"])) {
83
+ --_dialog-width: var(--kumiko-dialog-width-md, var(--kumiko-dialog-width));
84
+
85
+ inline-size: min(var(--_dialog-width), var(--_dialog-room-inline));
86
+ }
87
+
88
+ :where([data-slot$="dialog-content"][data-size="sm"]:not([data-presentation="sheet"])) {
89
+ --_dialog-width: var(--kumiko-dialog-width-sm);
90
+ }
91
+
92
+ :where([data-slot$="dialog-content"][data-size="lg"]:not([data-presentation="sheet"])) {
93
+ --_dialog-width: var(--kumiko-dialog-width-lg);
94
+ }
95
+
73
96
  /* A sheet rises from the bottom edge, so only its top corners are round. */
74
97
  :where([data-slot$="dialog-content"][data-presentation="sheet"]) {
75
98
  --sheet-backdrop: var(--kumiko-dialog-backdrop);
@@ -108,8 +131,10 @@
108
131
  /*
109
132
  * The header, body and footer are stacked with a gap; the description sits close to its title.
110
133
  * Layers inside the panel (a nested dialog, a menu or a popover, all [popover]) place themselves.
134
+ * No sibling combinator here: one led by :not() makes the browser restyle the whole parent of
135
+ * anything inserted or removed anywhere on the page, such as an app root when a dialog opens.
111
136
  */
112
- :where([data-slot$="dialog-content"] > :not([popover]) ~ :not([popover])) {
137
+ :where([data-slot$="dialog-content"] > :not([popover], :first-child)) {
113
138
  margin-block-start: var(--kumiko-dialog-gap);
114
139
  }
115
140
 
@@ -155,6 +180,19 @@
155
180
  color: var(--kumiko-dialog-fg);
156
181
  }
157
182
 
183
+ /* The line a failed question action leaves above its buttons. */
184
+ :where([data-kumiko-dialog-error]) {
185
+ margin: 0;
186
+ color: var(--kumiko-dialog-error-fg);
187
+ font-size: var(--kumiko-dialog-description-size);
188
+ }
189
+
190
+ /* There is no warning Button variant: a warning confirm is a solid one with the warning colours. */
191
+ :where([data-slot="button"][data-variant="solid"][data-tone="warning"]) {
192
+ --kumiko-button-solid-bg: var(--kumiko-dialog-warning-bg);
193
+ --kumiko-button-solid-fg: var(--kumiko-dialog-warning-fg);
194
+ }
195
+
158
196
  /* The dim behind a dialog: the Backdrop part, or the panel's own ::backdrop without one. */
159
197
  :where([data-slot$="dialog-backdrop"]) {
160
198
  position: fixed;
@@ -1,9 +1,6 @@
1
1
  import { type AlertDialogProps } from "@ui-sdk/react/alert-dialog";
2
2
  import { type DialogProps } from "@ui-sdk/react/dialog";
3
- import { type OverlayHostProps } from "@ui-sdk/react/overlays";
4
3
  /** The ui-sdk dialog, whose close isn't stretched by infinite animations inside it. */
5
4
  export declare function Dialog(props: DialogProps): React.JSX.Element;
6
5
  /** The ui-sdk alert dialog, whose close isn't stretched by infinite animations inside it. */
7
6
  export declare function AlertDialog(props: AlertDialogProps): React.JSX.Element;
8
- /** The ui-sdk host for `confirm()` and `toast()`, whose closes aren't stretched by infinite animations. */
9
- export declare function OverlayHost(props: OverlayHostProps): React.JSX.Element;
@@ -1,7 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { AlertDialog as SdkAlertDialog } from "@ui-sdk/react/alert-dialog";
3
3
  import { Dialog as SdkDialog } from "@ui-sdk/react/dialog";
4
- import { OverlayHost as SdkOverlayHost } from "@ui-sdk/react/overlays";
5
4
  import { useSettledClose } from "../motion/settle-close";
6
5
  /** The ui-sdk dialog, whose close isn't stretched by infinite animations inside it. */
7
6
  export function Dialog(props) {
@@ -13,8 +12,3 @@ export function AlertDialog(props) {
13
12
  useSettledClose();
14
13
  return _jsx(SdkAlertDialog, { ...props });
15
14
  }
16
- /** The ui-sdk host for `confirm()` and `toast()`, whose closes aren't stretched by infinite animations. */
17
- export function OverlayHost(props) {
18
- useSettledClose();
19
- return _jsx(SdkOverlayHost, { ...props });
20
- }
@@ -1,4 +1,10 @@
1
1
  export { createDialogController, DialogBackdrop, DialogClose, DialogContent, DialogDescription, DialogShortcut, DialogTitle, DialogTrigger, type DialogApi, type DialogBackdropState, type DialogCloseActionDetails, type DialogCloseProps, type DialogCloseState, type DialogContentProps, type DialogContentState, type DialogController, type DialogDismissAttemptDetails, type DialogDismissReason, type DialogFinalFocus, type DialogInitialFocus, type DialogOpenChangeDetails, type DialogOpenChangeReason, type DialogOptions, type DialogPayloadChangeReason, type DialogProps, type DialogShortcutProps, type DialogTriggerProps, type DialogTriggerState } from "@ui-sdk/react/dialog";
2
2
  export { AlertDialogBackdrop, AlertDialogClose, AlertDialogContent, AlertDialogDescription, AlertDialogShortcut, AlertDialogTitle, AlertDialogTrigger, confirm, createAlertDialogController, createConfirm, type AlertDialogCloseProps, type AlertDialogContentProps, type AlertDialogContentState, type AlertDialogController, type AlertDialogOpenChangeReason, type AlertDialogOptions, type AlertDialogProps, type AlertDialogTriggerProps, type ConfirmEntry, type ConfirmOptions } from "@ui-sdk/react/alert-dialog";
3
- export { AlertDialog, Dialog, OverlayHost } from "./dialog";
4
- export { type OverlayHostProps } from "@ui-sdk/react/overlays";
3
+ export { ask, type AskOptions } from "./ask";
4
+ export { AlertDialog, Dialog } from "./dialog";
5
+ export { DialogActions, useDialogContent, type DialogContentApi } from "./dialog-content";
6
+ export { defaultDialogLabels, type DialogLabels } from "./dialog-labels";
7
+ export type { DialogChrome, DialogSize, DismissGuard, EntryUpdate as DialogUpdate, QuestionConfirmControl } from "./dialog-store";
8
+ export { useLeaveGuard, type LeaveGuardOptions, type LeaveBlocker } from "./leave-guard";
9
+ export { openDialog, type DialogHandle, type OpenDialogOptions } from "./open-dialog";
10
+ export { OverlayHost, type OverlayHostProps } from "./overlay-host";
@@ -1,4 +1,9 @@
1
1
  export { createDialogController, DialogBackdrop, DialogClose, DialogContent, DialogDescription, DialogShortcut, DialogTitle, DialogTrigger } from "@ui-sdk/react/dialog";
2
2
  export { AlertDialogBackdrop, AlertDialogClose, AlertDialogContent, AlertDialogDescription, AlertDialogShortcut, AlertDialogTitle, AlertDialogTrigger, confirm, createAlertDialogController, createConfirm } from "@ui-sdk/react/alert-dialog";
3
- export { AlertDialog, Dialog, OverlayHost } from "./dialog";
4
- export {} from "@ui-sdk/react/overlays";
3
+ export { ask } from "./ask";
4
+ export { AlertDialog, Dialog } from "./dialog";
5
+ export { DialogActions, useDialogContent } from "./dialog-content";
6
+ export { defaultDialogLabels } from "./dialog-labels";
7
+ export { useLeaveGuard } from "./leave-guard";
8
+ export { openDialog } from "./open-dialog";
9
+ export { OverlayHost } from "./overlay-host";
@@ -0,0 +1,24 @@
1
+ import type { DialogLabels } from "./dialog-labels";
2
+ /** What a router's blocker gives, as TanStack Router's `useBlocker({ withResolver: true })` does. */
3
+ export interface LeaveBlocker {
4
+ /** `"blocked"` while a move waits for an answer. */
5
+ status: string;
6
+ /** Lets the blocked move go ahead. */
7
+ proceed: () => void;
8
+ /** Cancels the blocked move. */
9
+ reset: () => void;
10
+ }
11
+ export interface LeaveGuardOptions {
12
+ /** Whether there is something to lose, such as unsaved changes. */
13
+ when: boolean;
14
+ /** The router's blocker. Without one, the guard only covers closing or reloading the tab. */
15
+ blocker?: LeaveBlocker;
16
+ /** Words that replace the host's `leaveTitle`, `leaveDescription`, `leave` and `stay`. */
17
+ labels?: Partial<Pick<DialogLabels, "leaveTitle" | "leaveDescription" | "leave" | "stay">>;
18
+ }
19
+ /**
20
+ * Guards leaving while `when` is true. Closing or reloading the tab gets the browser's own prompt. With a
21
+ * router's `blocker`, a blocked move asks "Leave this page?" and then proceeds or resets.
22
+ * An `OverlayHost` must be mounted to ask.
23
+ */
24
+ export declare function useLeaveGuard({ when, blocker, labels }: LeaveGuardOptions): void;
@@ -0,0 +1,98 @@
1
+ import { useEffect, useRef } from "react";
2
+ import { addQuestion, currentLabels } from "./dialog-store";
3
+ function warnBeforeUnload(event) {
4
+ event.preventDefault();
5
+ }
6
+ function askToLeave(labels) {
7
+ const words = { ...currentLabels(), ...labels };
8
+ return addQuestion({
9
+ title: words.leaveTitle,
10
+ description: words.leaveDescription,
11
+ tone: "warning",
12
+ confirmLabel: words.leave,
13
+ cancelLabel: words.stay
14
+ });
15
+ }
16
+ function useBeforeUnload(when) {
17
+ useEffect(() => {
18
+ if (!when) {
19
+ return undefined;
20
+ }
21
+ window.addEventListener("beforeunload", warnBeforeUnload);
22
+ return () => {
23
+ window.removeEventListener("beforeunload", warnBeforeUnload);
24
+ };
25
+ }, [when]);
26
+ }
27
+ /** Asks, and acts on the answer unless the question was taken back meanwhile. */
28
+ function startAsking(live) {
29
+ const next = askToLeave(live.labels.current);
30
+ live.asking.current = next;
31
+ void next.promise.then((leave) => {
32
+ if (live.asking.current !== next) {
33
+ return;
34
+ }
35
+ live.asking.current = null;
36
+ if (leave) {
37
+ live.blocker.current?.proceed();
38
+ }
39
+ else {
40
+ live.blocker.current?.reset();
41
+ }
42
+ });
43
+ }
44
+ /** Takes back a question that is still up, and cancels the move it was asked for. */
45
+ function stopAsking(live, resetMove) {
46
+ const current = live.asking.current;
47
+ if (current) {
48
+ live.asking.current = null;
49
+ current.cancel();
50
+ if (resetMove) {
51
+ live.blocker.current?.reset();
52
+ }
53
+ }
54
+ }
55
+ /**
56
+ * Guards leaving while `when` is true. Closing or reloading the tab gets the browser's own prompt. With a
57
+ * router's `blocker`, a blocked move asks "Leave this page?" and then proceeds or resets.
58
+ * An `OverlayHost` must be mounted to ask.
59
+ */
60
+ export function useLeaveGuard({ when, blocker, labels }) {
61
+ const live = {
62
+ asking: useRef(null),
63
+ blocker: useRef(blocker),
64
+ labels: useRef(labels)
65
+ };
66
+ const blocked = blocker?.status === "blocked";
67
+ useEffect(() => {
68
+ live.blocker.current = blocker;
69
+ live.labels.current = labels;
70
+ });
71
+ useBeforeUnload(when);
72
+ useEffect(() => {
73
+ if (blocked && when && !live.asking.current) {
74
+ startAsking(live);
75
+ }
76
+ else if (blocked && !when && !live.asking.current) {
77
+ live.blocker.current?.proceed();
78
+ }
79
+ else if (!(blocked && when)) {
80
+ stopAsking(live, blocked);
81
+ }
82
+ }, [blocked, when]);
83
+ const mounted = useRef(false);
84
+ useEffect(() => {
85
+ mounted.current = true;
86
+ return () => {
87
+ mounted.current = false;
88
+ const wasAsking = live.asking.current !== null;
89
+ stopAsking(live, false);
90
+ // StrictMode unmounts and mounts again at once; only a real unmount cancels the move.
91
+ queueMicrotask(() => {
92
+ if (wasAsking && !mounted.current) {
93
+ live.blocker.current?.reset();
94
+ }
95
+ });
96
+ };
97
+ }, []);
98
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * A dialog rendered inside another carries this trigger, hidden and out of the tab order, that nobody presses.
3
+ * Without a trigger ui-sdk never nests it, however it opens: the one under gets no `data-nested-open`
4
+ * and no stack count, so it doesn't step back.
5
+ */
6
+ export declare function NestAnchor({ alert }: {
7
+ alert?: boolean;
8
+ }): React.JSX.Element;
9
+ /**
10
+ * What had focus when the caller first rendered, as a `finalFocus`. A dialog with a trigger returns focus
11
+ * there, and the hidden anchor can't take it, so this puts it back where the person was. An element that
12
+ * has since left the page gives `undefined`.
13
+ */
14
+ export declare function useOpener(): () => HTMLElement | undefined;
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { AlertDialogTrigger } from "@ui-sdk/react/alert-dialog";
3
+ import { DialogTrigger } from "@ui-sdk/react/dialog";
4
+ import { useLayoutEffect, useRef } from "react";
5
+ /**
6
+ * A dialog rendered inside another carries this trigger, hidden and out of the tab order, that nobody presses.
7
+ * Without a trigger ui-sdk never nests it, however it opens: the one under gets no `data-nested-open`
8
+ * and no stack count, so it doesn't step back.
9
+ */
10
+ export function NestAnchor({ alert = false }) {
11
+ const Trigger = alert ? AlertDialogTrigger : DialogTrigger;
12
+ return (_jsx(Trigger, { render: _jsx("span", { hidden: true }), "aria-label": "Nested dialog", "aria-hidden": "true", tabIndex: -1 }));
13
+ }
14
+ /**
15
+ * What had focus when the caller first rendered, as a `finalFocus`. A dialog with a trigger returns focus
16
+ * there, and the hidden anchor can't take it, so this puts it back where the person was. An element that
17
+ * has since left the page gives `undefined`.
18
+ */
19
+ export function useOpener() {
20
+ const opener = useRef(null);
21
+ useLayoutEffect(() => {
22
+ const { activeElement } = document;
23
+ opener.current = activeElement instanceof HTMLElement ? activeElement : null;
24
+ }, []);
25
+ return () => (opener.current?.isConnected ? opener.current : undefined);
26
+ }
@@ -0,0 +1,16 @@
1
+ import { type EntryOptions, type EntryUpdate } from "./dialog-store";
2
+ export type OpenDialogOptions = EntryOptions;
3
+ export interface DialogHandle<Result = unknown> {
4
+ /** Settles once, with the value passed to `close()`, or `undefined` when dismissed. */
5
+ result: Promise<Result | undefined>;
6
+ /** Closes the dialog, and anything opened above it, from outside. */
7
+ close: (value?: Result) => void;
8
+ /** Changes the title, description or content while the dialog is open. */
9
+ update: (update: EntryUpdate) => void;
10
+ }
11
+ /**
12
+ * Opens a dialog from anywhere. An `OverlayHost` must be mounted, or this throws.
13
+ * Dialogs opened while another is open stack above it.
14
+ * The content reads `useDialogContent()` to close, or to mark itself pending or dirty.
15
+ */
16
+ export declare function openDialog<Result = unknown>(options: OpenDialogOptions): DialogHandle<Result>;
@@ -0,0 +1,13 @@
1
+ import { addEntry, closeEntry, updateEntry } from "./dialog-store";
2
+ export function openDialog(options) {
3
+ const { id, result } = addEntry(options);
4
+ return {
5
+ result,
6
+ close: (value) => {
7
+ closeEntry(id, value);
8
+ },
9
+ update: (update) => {
10
+ updateEntry(id, update);
11
+ }
12
+ };
13
+ }
@@ -0,0 +1,27 @@
1
+ import type { DialogProps } from "@ui-sdk/react/dialog";
2
+ import { type OverlayHostProps as SdkOverlayHostProps } from "@ui-sdk/react/overlays";
3
+ import { type ReactNode } from "react";
4
+ import type { DialogLabels } from "./dialog-labels";
5
+ export type OverlayHostProps = SdkOverlayHostProps & {
6
+ /** The words of opened dialogs and questions, and of the leave guard. Any you leave out are English. */
7
+ labels?: Partial<DialogLabels>;
8
+ /**
9
+ * How modal `openDialog()`'s dialogs are. `"trap-focus"` keeps Tab inside without making the rest of the
10
+ * page inert, which restyles every element of a big app on each open. Questions are always modal.
11
+ * @defaultValue true
12
+ */
13
+ dialogModal?: DialogProps["modal"];
14
+ /** Called with `true` when the first hosted dialog or question opens, and `false` when the last one closes. */
15
+ onDialogsChange?: (open: boolean) => void;
16
+ /**
17
+ * What the corner close button of `openDialog()`'s dialogs shows, such as the app's own icon.
18
+ * @defaultValue "×"
19
+ */
20
+ dialogCloseIcon?: ReactNode;
21
+ };
22
+ /**
23
+ * The host for `toast()`, `confirm()`, `openDialog()` and `ask()`. Mount it once, near the root and inside
24
+ * the app's providers: what it shows renders where it is. With two mounted, the first shows the dialogs.
25
+ * Closes of its dialogs aren't stretched by infinite animations inside them.
26
+ */
27
+ export declare function OverlayHost({ labels, dialogModal, dialogCloseIcon, onDialogsChange, ...props }: OverlayHostProps): React.JSX.Element;
@@ -0,0 +1,47 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { OverlayHost as SdkOverlayHost } from "@ui-sdk/react/overlays";
3
+ import { useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";
4
+ import { useSettledClose } from "../motion/settle-close";
5
+ import { DialogCloseIconContext, DialogModalContext, Stack } from "./dialog-entry";
6
+ import { getSnapshot, registerHost, setHostLabels, subscribe } from "./dialog-store";
7
+ function anyOpen(state) {
8
+ return (state.entries.some((entry) => entry.phase !== "closed") || state.question?.phase === "open");
9
+ }
10
+ /** Tells the app when hosted dialogs come and go, once per change. */
11
+ function useDialogsChange(open, onChange) {
12
+ const told = useRef(false);
13
+ const latest = useRef(onChange);
14
+ useLayoutEffect(() => {
15
+ latest.current = onChange;
16
+ });
17
+ useEffect(() => {
18
+ if (open !== told.current) {
19
+ told.current = open;
20
+ latest.current?.(open);
21
+ }
22
+ }, [open]);
23
+ }
24
+ /**
25
+ * The opened dialogs, in a box of their own that is always there. Mounted straight into a big container,
26
+ * each open and close would make the browser recheck most of that container; inside this box, only the box.
27
+ */
28
+ function DialogHost({ token, modal, closeIcon, onDialogsChange }) {
29
+ const state = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
30
+ const active = state.activeHost === token;
31
+ useDialogsChange(active && anyOpen(state), active ? onDialogsChange : undefined);
32
+ return (_jsx("div", { "data-slot": "dialog-host", style: { display: "contents" }, children: active ? (_jsx(DialogModalContext.Provider, { value: modal, children: _jsx(DialogCloseIconContext.Provider, { value: closeIcon, children: _jsx(Stack, { parent: null, state: state }) }) })) : null }));
33
+ }
34
+ /**
35
+ * The host for `toast()`, `confirm()`, `openDialog()` and `ask()`. Mount it once, near the root and inside
36
+ * the app's providers: what it shows renders where it is. With two mounted, the first shows the dialogs.
37
+ * Closes of its dialogs aren't stretched by infinite animations inside them.
38
+ */
39
+ export function OverlayHost({ labels, dialogModal = true, dialogCloseIcon = "×", onDialogsChange, ...props }) {
40
+ useSettledClose();
41
+ const [token] = useState(() => Symbol("overlay-host"));
42
+ useLayoutEffect(() => registerHost(token, undefined), [token]);
43
+ useEffect(() => {
44
+ setHostLabels(token, labels);
45
+ }, [token, labels]);
46
+ return (_jsxs(_Fragment, { children: [_jsx(SdkOverlayHost, { ...props }), _jsx(DialogHost, { token: token, modal: dialogModal, closeIcon: dialogCloseIcon, onDialogsChange: onDialogsChange })] }));
47
+ }
@@ -0,0 +1,21 @@
1
+ import type { DialogLabels } from "./dialog-labels";
2
+ import type { QuestionOptions } from "./dialog-store";
3
+ export interface QuestionDialogProps {
4
+ open: boolean;
5
+ options: QuestionOptions;
6
+ labels: DialogLabels;
7
+ /** Whether it shows inside a dialog, which it then nests under. */
8
+ nested: boolean;
9
+ /** Runs once the question has closed, with whether it was confirmed. */
10
+ onAnswer: (yes: boolean) => void;
11
+ /** Runs once the question has finished animating out. */
12
+ onComplete: () => void;
13
+ /** Where focus goes when the question closes. Without it, back to where it was before the question. */
14
+ finalFocus?: () => HTMLElement | null | undefined;
15
+ }
16
+ /**
17
+ * One question as an alert dialog.
18
+ * With an `action` the confirm button shows loading while it runs, Cancel and Escape can't close the dialog,
19
+ * and a throw keeps it open with the error and a retry.
20
+ */
21
+ export declare function QuestionDialog(props: QuestionDialogProps): React.JSX.Element;
@@ -0,0 +1,78 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { AlertDialogClose, AlertDialogContent, AlertDialogDescription, AlertDialogTitle } from "@ui-sdk/react/alert-dialog";
3
+ import { useRef, useState } from "react";
4
+ import { Button } from "../button";
5
+ import { AlertDialog } from "./dialog";
6
+ import { NestAnchor, useOpener } from "./nest";
7
+ function messageOf(error, fallback) {
8
+ return error instanceof Error && error.message !== "" ? error.message : fallback;
9
+ }
10
+ /** The action wrapped to remember what it threw, until the next try. A throw still reaches ui-sdk, which keeps the dialog open. */
11
+ function useAction(action, fallback) {
12
+ const [failure, setFailure] = useState(null);
13
+ const [pending, setPending] = useState(false);
14
+ if (!action) {
15
+ return { failure, pending, run: undefined };
16
+ }
17
+ const run = async () => {
18
+ setPending(true);
19
+ setFailure(null);
20
+ try {
21
+ await action();
22
+ }
23
+ catch (error) {
24
+ setFailure({ message: messageOf(error, fallback) });
25
+ throw error;
26
+ }
27
+ finally {
28
+ setPending(false);
29
+ }
30
+ };
31
+ return { failure, pending, run };
32
+ }
33
+ /**
34
+ * The app's own confirm control. It answers through a hidden confirm Close, so `action`, pending and the
35
+ * refused dismissals work as they do for the button.
36
+ */
37
+ function OwnConfirm(props) {
38
+ const close = useRef(null);
39
+ const { options } = props;
40
+ return (_jsxs(_Fragment, { children: [_jsx(AlertDialogClose, { ref: close, value: "confirm", action: props.run, hidden: true, tabIndex: -1 }), options.renderConfirm?.({
41
+ label: props.label,
42
+ tone: options.tone,
43
+ pending: props.pending,
44
+ confirm: () => {
45
+ close.current?.click();
46
+ }
47
+ })] }));
48
+ }
49
+ /** The plain confirm button, which shows loading while the action runs. */
50
+ function ConfirmButton(props) {
51
+ const { options } = props;
52
+ return (_jsx(AlertDialogClose, { value: "confirm", action: props.run, render: (closeProps, state) => (_jsx(Button, { ...closeProps, variant: options.tone === "danger" ? "destructive" : "solid", "data-tone": options.tone === "warning" ? "warning" : undefined, status: state.pending ? "loading" : undefined, feedback: false, children: props.label })) }));
53
+ }
54
+ /** The buttons: Cancel first, so it takes focus, then the confirm button or the app's own control. */
55
+ function Buttons(props) {
56
+ const { options, labels } = props;
57
+ const confirmLabel = props.failed ? labels.retry : (options.confirmLabel ?? labels.confirm);
58
+ return (_jsxs("div", { "data-kumiko-actions": "", children: [_jsx(AlertDialogClose, { render: _jsx(Button, { variant: "secondary" }), children: options.cancelLabel ?? labels.cancel }), options.renderConfirm ? (_jsx(OwnConfirm, { options: options, label: confirmLabel, pending: props.pending, run: props.run })) : (_jsx(ConfirmButton, { options: options, label: confirmLabel, run: props.run }))] }));
59
+ }
60
+ /**
61
+ * One question as an alert dialog.
62
+ * With an `action` the confirm button shows loading while it runs, Cancel and Escape can't close the dialog,
63
+ * and a throw keeps it open with the error and a retry.
64
+ */
65
+ export function QuestionDialog(props) {
66
+ const { options, labels } = props;
67
+ const opener = useOpener();
68
+ const { failure, pending, run } = useAction(options.action, labels.failed);
69
+ return (_jsxs(AlertDialog, { open: props.open, onOpenChange: (open, details) => {
70
+ if (!open) {
71
+ props.onAnswer(details.returnValue === "confirm");
72
+ }
73
+ }, onOpenChangeComplete: (open) => {
74
+ if (!open) {
75
+ props.onComplete();
76
+ }
77
+ }, pendingAnnouncement: options.title, children: [props.nested ? _jsx(NestAnchor, { alert: true }) : null, _jsxs(AlertDialogContent, { finalFocus: props.nested ? (props.finalFocus ?? opener) : undefined, children: [_jsx(AlertDialogTitle, { children: options.title }), options.description ? (_jsx(AlertDialogDescription, { children: options.description })) : null, failure ? (_jsx("p", { role: "alert", "data-kumiko-dialog-error": "", children: failure.message })) : null, _jsx(Buttons, { options: options, labels: labels, failed: failure !== null, pending: pending, run: run })] })] }));
78
+ }
@@ -338,33 +338,37 @@
338
338
  backdrop-filter: blur(var(--_drawer-backdrop-blur));
339
339
  }
340
340
 
341
+ /* A title in the header never makes room for the content's corner button. */
341
342
  :where([data-slot="drawer-header"]) {
343
+ --_drawer-title-end: 0px;
344
+
342
345
  display: grid;
343
346
  grid-template-columns: minmax(0, 1fr);
344
347
  gap: 0.375rem;
345
348
  }
346
349
 
350
+ :where([data-slot="drawer-header"] > *) {
351
+ grid-column: 1;
352
+ }
353
+
347
354
  /* A close button in the header sits at its end, beside the title. */
348
355
  :where([data-slot="drawer-header"]:has(> [data-kumiko-drawer-close])) {
349
356
  grid-template-columns: minmax(0, 1fr) auto;
350
357
  column-gap: 0.75rem;
358
+ }
351
359
 
352
- & > :not([data-kumiko-drawer-close]) {
353
- grid-column: 1;
354
- }
355
-
356
- & > [data-kumiko-drawer-close] {
357
- grid-row: 1 / span 2;
358
- grid-column: 2;
359
- align-self: start;
360
- margin-block-start: calc(
361
- (var(--_drawer-title-size) * 1.25 - var(--_drawer-close-size)) / 2
362
- );
363
- }
360
+ :where([data-slot="drawer-header"]) > [data-kumiko-drawer-close] {
361
+ grid-row: 1 / span 2;
362
+ grid-column: 2;
363
+ align-self: start;
364
+ margin-block-start: calc(
365
+ (var(--_drawer-title-size) * 1.25 - var(--_drawer-close-size)) / 2
366
+ );
364
367
  }
365
368
 
366
369
  :where([data-slot="drawer-title"]) {
367
370
  margin: 0;
371
+ padding-inline-end: var(--_drawer-title-end, 0px);
368
372
  color: var(--kumiko-drawer-title-fg, inherit);
369
373
  font-family: var(--_drawer-title-font);
370
374
  font-size: var(--_drawer-title-size);
@@ -373,10 +377,8 @@
373
377
  }
374
378
 
375
379
  /* A title beside a corner "×" leaves room for it. */
376
- :where(
377
- [data-slot="drawer-content"]:has(> [data-kumiko-drawer-close]) > [data-slot="drawer-title"]
378
- ) {
379
- padding-inline-end: var(--_drawer-close-size);
380
+ :where([data-slot="drawer-content"]:has(> [data-kumiko-drawer-close])) {
381
+ --_drawer-title-end: var(--_drawer-close-size);
380
382
  }
381
383
 
382
384
  :where([data-slot="drawer-description"]) {
@@ -265,27 +265,31 @@
265
265
  scale: -1 1;
266
266
  }
267
267
 
268
- /* When some items have an icon or a check, the rest keep that space so labels line up. */
268
+ /*
269
+ * When some items have an icon or a check, the rest keep that space so labels line up. The menu passes the
270
+ * gap down as a property: a :has() before a combinator would restyle the whole page on every change.
271
+ */
272
+ :where([data-slot="menu-content"]) {
273
+ --_menu-gutter: none;
274
+ }
275
+
269
276
  :where(
270
- [data-slot="menu-content"]:is(
271
- [data-has-icons],
272
- :has(> [aria-checked], > [role="group"] > [aria-checked])
273
- )
277
+ [data-slot="menu-content"]:is(
278
+ [data-has-icons],
279
+ :has(> [aria-checked], > [role="group"] > [aria-checked])
274
280
  )
275
- > :where([role^="menuitem"]),
281
+ ) {
282
+ --_menu-gutter: "";
283
+ }
284
+
276
285
  :where(
277
- [data-slot="menu-content"]:is(
278
- [data-has-icons],
279
- :has(> [aria-checked], > [role="group"] > [aria-checked])
280
- )
286
+ [role^="menuitem"]:not(
287
+ :has(> [data-slot="menu-item-icon"], > [data-slot="menu-item-indicator"])
281
288
  )
282
- > [role="group"]
283
- > :where([role^="menuitem"]) {
284
- &:not(:has(> [data-slot="menu-item-icon"], > [data-slot="menu-item-indicator"]))::before {
285
- flex: none;
286
- inline-size: var(--kumiko-menu-icon-size);
287
- content: "";
288
- }
289
+ )::before {
290
+ flex: none;
291
+ inline-size: var(--kumiko-menu-icon-size);
292
+ content: var(--_menu-gutter);
289
293
  }
290
294
 
291
295
  :where([data-slot="menu-checkbox-item"] > [data-slot="menu-item-indicator"])::before {