@human-kit/ui 1.0.0-beta.0 → 1.0.0-beta.1

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 (157) hide show
  1. package/README.md +2 -0
  2. package/dist/FOCUS_STATE_CONTRACT.md +1 -0
  3. package/dist/accordion/root/accordion-root.svelte +15 -3
  4. package/dist/accordion/root/context.svelte.js +4 -4
  5. package/dist/accordion/types.d.ts +9 -2
  6. package/dist/autocomplete/list/autocomplete-list.svelte.d.ts +6 -0
  7. package/dist/calendar/root/context.svelte.js +8 -2
  8. package/dist/checkbox/root/checkbox-root.svelte +28 -11
  9. package/dist/checkbox/root/checkbox-root.svelte.d.ts +13 -0
  10. package/dist/clock/root/create-time-selection-state.svelte.d.ts +5 -0
  11. package/dist/clock/root/create-time-selection-state.svelte.js +113 -10
  12. package/dist/clock/root/wheel-options.d.ts +7 -3
  13. package/dist/clock/root/wheel-options.js +7 -15
  14. package/dist/clock/wheel-column/clock-wheel-column.svelte +10 -2
  15. package/dist/clock/wheel-column/clock-wheel-column.svelte.d.ts +2 -1
  16. package/dist/collapsible/root/collapsible-root.svelte +9 -4
  17. package/dist/collapsible/types.d.ts +9 -0
  18. package/dist/combobox/input/combobox-input.svelte +12 -1
  19. package/dist/combobox/list/combobox-listbox.svelte +93 -1
  20. package/dist/combobox/list/combobox-listbox.svelte.d.ts +20 -0
  21. package/dist/combobox/root/combobox.svelte +118 -45
  22. package/dist/combobox/root/combobox.svelte.d.ts +11 -0
  23. package/dist/combobox/root/context.d.ts +12 -0
  24. package/dist/combobox/status/README.md +2 -2
  25. package/dist/combobox/tag-remove/combobox-tag-remove.svelte +14 -2
  26. package/dist/combobox/tag-remove/combobox-tag-remove.svelte.d.ts +7 -0
  27. package/dist/combobox/tags/combobox-tags.svelte +5 -2
  28. package/dist/combobox/tags/combobox-tags.svelte.d.ts +2 -0
  29. package/dist/combobox/trigger/combobox-trigger.svelte +4 -1
  30. package/dist/datepicker/README.md +3 -2
  31. package/dist/datepicker/root/date-picker-root.svelte +38 -2
  32. package/dist/datepicker/root/date-picker-root.svelte.d.ts +2 -0
  33. package/dist/datepicker/root/draft-evaluation.d.ts +7 -0
  34. package/dist/datepicker/root/draft-evaluation.js +2 -2
  35. package/dist/daterangepicker/root/date-range-picker-root.svelte +19 -1
  36. package/dist/daterangepicker/root/date-range-picker-root.svelte.d.ts +2 -0
  37. package/dist/dialog/README.md +9 -1
  38. package/dist/dialog/close/dialog-close.svelte +57 -0
  39. package/dist/dialog/close/dialog-close.svelte.d.ts +19 -0
  40. package/dist/dialog/content/dialog-content.svelte +2 -0
  41. package/dist/dialog/description/dialog-description.svelte +46 -0
  42. package/dist/dialog/description/dialog-description.svelte.d.ts +20 -0
  43. package/dist/dialog/index.d.ts +9 -0
  44. package/dist/dialog/index.js +3 -0
  45. package/dist/dialog/index.parts.d.ts +3 -0
  46. package/dist/dialog/index.parts.js +3 -0
  47. package/dist/dialog/root/context.d.ts +8 -0
  48. package/dist/dialog/root/dialog-root.svelte +58 -16
  49. package/dist/dialog/root/dialog-root.svelte.d.ts +10 -3
  50. package/dist/dialog/root/dialog-stack.d.ts +6 -22
  51. package/dist/dialog/root/dialog-stack.js +4 -33
  52. package/dist/dialog/title/dialog-title.svelte +43 -0
  53. package/dist/dialog/title/dialog-title.svelte.d.ts +21 -0
  54. package/dist/drawer/README.md +111 -0
  55. package/dist/drawer/body/drawer-body.svelte +47 -0
  56. package/dist/drawer/body/drawer-body.svelte.d.ts +32 -0
  57. package/dist/drawer/close/drawer-close.svelte +52 -0
  58. package/dist/drawer/close/drawer-close.svelte.d.ts +20 -0
  59. package/dist/drawer/content/drawer-content.svelte +597 -0
  60. package/dist/drawer/content/drawer-content.svelte.d.ts +28 -0
  61. package/dist/drawer/description/drawer-description.svelte +40 -0
  62. package/dist/drawer/description/drawer-description.svelte.d.ts +20 -0
  63. package/dist/drawer/indent/drawer-indent-background.svelte +36 -0
  64. package/dist/drawer/indent/drawer-indent-background.svelte.d.ts +17 -0
  65. package/dist/drawer/indent/drawer-indent.svelte +59 -0
  66. package/dist/drawer/indent/drawer-indent.svelte.d.ts +32 -0
  67. package/dist/drawer/index.d.ts +49 -0
  68. package/dist/drawer/index.js +25 -0
  69. package/dist/drawer/index.parts.d.ts +14 -0
  70. package/dist/drawer/index.parts.js +15 -0
  71. package/dist/drawer/overlay/drawer-overlay.svelte +67 -0
  72. package/dist/drawer/overlay/drawer-overlay.svelte.d.ts +12 -0
  73. package/dist/drawer/portal/drawer-portal.svelte +57 -0
  74. package/dist/drawer/portal/drawer-portal.svelte.d.ts +13 -0
  75. package/dist/drawer/root/context.d.ts +81 -0
  76. package/dist/drawer/root/context.js +20 -0
  77. package/dist/drawer/root/drawer-root.svelte +333 -0
  78. package/dist/drawer/root/drawer-root.svelte.d.ts +77 -0
  79. package/dist/drawer/root/drawer-stack.svelte.d.ts +73 -0
  80. package/dist/drawer/root/drawer-stack.svelte.js +113 -0
  81. package/dist/drawer/root/handle.svelte.d.ts +39 -0
  82. package/dist/drawer/root/handle.svelte.js +64 -0
  83. package/dist/drawer/root/keyboard-context.d.ts +13 -0
  84. package/dist/drawer/root/keyboard-context.js +8 -0
  85. package/dist/drawer/root/presence-context.d.ts +22 -0
  86. package/dist/drawer/root/presence-context.js +8 -0
  87. package/dist/drawer/root/snap-points.d.ts +68 -0
  88. package/dist/drawer/root/snap-points.js +120 -0
  89. package/dist/drawer/root/starting-style.svelte.d.ts +18 -0
  90. package/dist/drawer/root/starting-style.svelte.js +38 -0
  91. package/dist/drawer/root/types.d.ts +36 -0
  92. package/dist/drawer/root/types.js +1 -0
  93. package/dist/drawer/root/viewport-context.d.ts +2 -0
  94. package/dist/drawer/root/viewport-context.js +16 -0
  95. package/dist/drawer/swipe-area/drawer-swipe-area.svelte +143 -0
  96. package/dist/drawer/swipe-area/drawer-swipe-area.svelte.d.ts +22 -0
  97. package/dist/drawer/title/drawer-title.svelte +37 -0
  98. package/dist/drawer/title/drawer-title.svelte.d.ts +21 -0
  99. package/dist/drawer/trigger/drawer-trigger.svelte +90 -0
  100. package/dist/drawer/trigger/drawer-trigger.svelte.d.ts +41 -0
  101. package/dist/drawer/viewport/drawer-viewport.svelte +69 -0
  102. package/dist/drawer/viewport/drawer-viewport.svelte.d.ts +15 -0
  103. package/dist/drawer/virtual-keyboard/drawer-virtual-keyboard-provider.svelte +88 -0
  104. package/dist/drawer/virtual-keyboard/drawer-virtual-keyboard-provider.svelte.d.ts +29 -0
  105. package/dist/hooks/use-virtual-focus.svelte.d.ts +9 -0
  106. package/dist/hooks/use-virtual-focus.svelte.js +7 -1
  107. package/dist/index.d.ts +2 -0
  108. package/dist/index.js +2 -0
  109. package/dist/listbox/item/listbox-item.svelte +8 -1
  110. package/dist/listbox/root/context.d.ts +30 -0
  111. package/dist/listbox/root/context.js +10 -0
  112. package/dist/listbox/root/listbox.svelte +291 -8
  113. package/dist/listbox/root/listbox.svelte.d.ts +35 -2
  114. package/dist/menu/content/menu-content.svelte +3 -1
  115. package/dist/menu/overlay/menu-overlay.svelte +1 -1
  116. package/dist/numberfield/root/number-field-root.svelte +2 -1
  117. package/dist/popover/content/popover-content.svelte +1 -1
  118. package/dist/popover/overlay/popover-overlay.svelte +1 -1
  119. package/dist/popover/root/popover-root.svelte +23 -11
  120. package/dist/popover/root/popover-root.svelte.d.ts +10 -2
  121. package/dist/primitives/floating.d.ts +7 -0
  122. package/dist/primitives/floating.js +6 -2
  123. package/dist/primitives/index.d.ts +1 -0
  124. package/dist/primitives/index.js +1 -0
  125. package/dist/primitives/keyboard-navigation.js +3 -1
  126. package/dist/primitives/layer-stack.d.ts +29 -0
  127. package/dist/primitives/layer-stack.js +35 -0
  128. package/dist/primitives/list-virtualizer.d.ts +75 -0
  129. package/dist/primitives/list-virtualizer.js +59 -0
  130. package/dist/primitives/scroll-lock.d.ts +23 -3
  131. package/dist/primitives/scroll-lock.js +122 -9
  132. package/dist/primitives/swipe-gesture.d.ts +126 -0
  133. package/dist/primitives/swipe-gesture.js +351 -0
  134. package/dist/primitives/text.d.ts +8 -0
  135. package/dist/primitives/text.js +13 -0
  136. package/dist/switch/root/switch-root.svelte +23 -9
  137. package/dist/switch/root/switch-root.svelte.d.ts +9 -2
  138. package/dist/table/body/table-body.svelte +84 -9
  139. package/dist/table/cell/table-cell.svelte +1 -3
  140. package/dist/table/column/table-column.svelte +5 -1
  141. package/dist/table/column-resizer/table-column-resizer.svelte +1 -5
  142. package/dist/table/interactive-cell/table-interactive-cell.svelte +1 -3
  143. package/dist/table/root/context.svelte.js +99 -49
  144. package/dist/table/row/table-row.svelte +7 -7
  145. package/dist/table/sort-trigger/table-sort-trigger.svelte +5 -1
  146. package/dist/table/types.d.ts +6 -0
  147. package/dist/tabs/root/tabs-root.svelte +20 -6
  148. package/dist/tabs/types.d.ts +9 -0
  149. package/dist/timepicker/root/time-picker-root.svelte +11 -0
  150. package/dist/timepicker/root/time-picker-root.svelte.d.ts +2 -0
  151. package/dist/toggle-group/root/context.svelte.js +11 -4
  152. package/dist/toggle-group/root/toggle-group-root.svelte +19 -4
  153. package/dist/toggle-group/types.d.ts +9 -0
  154. package/dist/tree/root/context.svelte.js +6 -0
  155. package/dist/tree/root/tree-root.svelte +22 -8
  156. package/dist/tree/types.d.ts +13 -0
  157. package/package.json +227 -224
@@ -0,0 +1,333 @@
1
+ <!--
2
+ Generic over the handle's payload so `Drawer.Root handle={h}` accepts a
3
+ `DrawerHandle<User>`. A fixed `DrawerHandle<unknown>` cannot: `open(payload?)`
4
+ puts the type in a contravariant position, which makes the handle invariant.
5
+ -->
6
+ <script lang="ts" generics="Payload = unknown">
7
+ import { tick, untrack, type Snippet } from 'svelte';
8
+ import { setDrawerContext, type DrawerContext } from './context';
9
+ import type {
10
+ DrawerCloseReason,
11
+ DrawerModal,
12
+ DrawerSide,
13
+ DrawerSnapPoint,
14
+ DrawerStateHelpers
15
+ } from './types';
16
+ import type { DrawerHandle } from './handle.svelte';
17
+ import {
18
+ focusWithModality,
19
+ resolveCloseInteractionModality
20
+ } from '../../primitives/input-modality';
21
+
22
+ /**
23
+ * Drawer.Root — state container for the whole drawer.
24
+ * Renders no element of its own; it provides the context every other part reads.
25
+ */
26
+ type DrawerRootProps = {
27
+ /** Open state. Two-way by default — use `bind:open`. */
28
+ open?: boolean;
29
+ /** Initial open state, for when `open` is not supplied. */
30
+ defaultOpen?: boolean;
31
+ /**
32
+ * Opt into fully controlled state: the component stops writing back to `open` and
33
+ * only reports through `onOpenChange`, so the parent can reject a change by not
34
+ * flowing the new value back down. Off by default, because `bind:open` — the
35
+ * common case — needs the write-back to work at all.
36
+ */
37
+ controlledOpen?: boolean;
38
+ /** Callback when the open state changes. */
39
+ onOpenChange?: (open: boolean) => void;
40
+ /** Edge the panel is anchored to. */
41
+ side?: DrawerSide;
42
+ /** Focus trap / scroll lock behaviour. See `DrawerModal`. */
43
+ modal?: DrawerModal;
44
+ /** Whether a swipe toward the anchored edge may dismiss the drawer. */
45
+ dismissible?: boolean;
46
+ /** Whether pressing Escape closes the drawer. */
47
+ shouldCloseOnEscape?: boolean;
48
+ /** Whether pressing outside the panel closes it. */
49
+ shouldCloseOnInteractOutside?: boolean;
50
+ /**
51
+ * Resting positions the panel may settle on, smallest offset first is not
52
+ * required — they are sorted internally. See `DrawerSnapPoint` for the accepted
53
+ * value forms. Without this the drawer is either fully open or closed.
54
+ */
55
+ snapPoints?: readonly DrawerSnapPoint[];
56
+ /** Active snap point. Two-way by default — use `bind:snapPoint`. */
57
+ snapPoint?: DrawerSnapPoint | null;
58
+ /** Initial snap point, for when `snapPoint` is not supplied. */
59
+ defaultSnapPoint?: DrawerSnapPoint | null;
60
+ /** Callback when the active snap point changes. */
61
+ onSnapPointChange?: (snapPoint: DrawerSnapPoint | null, event?: Event) => void;
62
+ /**
63
+ * Stops a fast flick from skipping past the neighbouring snap point. Use it when
64
+ * every step is meaningful and jumping two at once would disorient.
65
+ */
66
+ snapToSequentialPoints?: boolean;
67
+ /**
68
+ * Drives the drawer from a detached handle instead of the `open` prop, so
69
+ * triggers can live anywhere in the tree. See `createDrawerHandle`.
70
+ */
71
+ handle?: DrawerHandle<Payload>;
72
+ /** Reference to the trigger element. Set manually or via Drawer.Trigger. */
73
+ triggerRef?: HTMLElement | null;
74
+ /** Children snippet, receiving state helpers. */
75
+ children?: Snippet<[DrawerStateHelpers<Payload>]>;
76
+ };
77
+
78
+ let {
79
+ open: openProp = $bindable(),
80
+ defaultOpen = false,
81
+ controlledOpen = false,
82
+ onOpenChange,
83
+ side = 'bottom',
84
+ modal = true,
85
+ dismissible = true,
86
+ shouldCloseOnEscape = true,
87
+ shouldCloseOnInteractOutside = true,
88
+ snapPoints,
89
+ snapPoint: snapPointProp = $bindable(),
90
+ defaultSnapPoint = null,
91
+ onSnapPointChange,
92
+ snapToSequentialPoints = false,
93
+ handle,
94
+ triggerRef = $bindable<HTMLElement | null>(null),
95
+ children
96
+ }: DrawerRootProps = $props();
97
+
98
+ // Function call so only the INITIAL value is captured, not a reactive read.
99
+ let isOpenInternal = $state((() => defaultOpen)());
100
+
101
+ let stackLevel = $state(0);
102
+ let stackIndex = $state(0);
103
+ let swipeProgress = $state(0);
104
+ let isSwiping = $state(false);
105
+ let swipeOpenDistance = $state<number | null>(null);
106
+ let panelExtent = $state(0);
107
+
108
+ // Same shape as `open`: the prop wins when supplied, the internal state carries
109
+ // the uncontrolled case. `controlledOpen` governs both, since a consumer driving
110
+ // one of them from outside is almost always driving the other too.
111
+ let snapPointInternal = $state<DrawerSnapPoint | null>((() => defaultSnapPoint)());
112
+ const snapPoint = $derived(
113
+ controlledOpen ? (snapPointProp ?? null) : (snapPointProp ?? snapPointInternal)
114
+ );
115
+
116
+ function setSnapPoint(point: DrawerSnapPoint | null, event?: Event) {
117
+ onSnapPointChange?.(point, event);
118
+ if (controlledOpen) return;
119
+ snapPointInternal = point;
120
+ snapPointProp = point;
121
+ }
122
+
123
+ // Label/description ids, in registration order. Arrays rather than a single id
124
+ // because `aria-labelledby` takes a list, and a drawer may legitimately be
125
+ // named by more than one element.
126
+ let labelIds = $state<string[]>([]);
127
+ let descriptionIds = $state<string[]>([]);
128
+
129
+ // `open` wins whenever it is supplied — that covers both `bind:open` and a plain
130
+ // `open={...}` — and the internal state only carries the fully uncontrolled case.
131
+ // Controlled-ness is NOT inferred from `open` being defined: `bind:open={value}` and
132
+ // `open={value}` are indistinguishable at runtime, so inferring it silently breaks
133
+ // every `bind:open` seeded with `false`. It is opt-in via `controlledOpen` instead.
134
+ /**
135
+ * Current open state, read straight from whichever source owns it.
136
+ *
137
+ * A plain function rather than only a `$derived` because `closeDrawer` has to
138
+ * re-read the state in the same tick it wrote it, to tell a rejected close from a
139
+ * real one. A derived read back inside the handler it was just invalidated from
140
+ * is exactly the case where the cached value bites.
141
+ */
142
+ function readOpen(): boolean {
143
+ // A handle outranks everything: its whole point is that the state lives outside
144
+ // this component, where the scattered triggers can reach it.
145
+ if (handle) return handle.isOpen;
146
+ if (controlledOpen) return Boolean(openProp);
147
+ return openProp ?? isOpenInternal;
148
+ }
149
+
150
+ const isOpen = $derived(readOpen());
151
+
152
+ function setOpen(value: boolean) {
153
+ onOpenChange?.(value);
154
+
155
+ if (handle) {
156
+ handle.setOpen(value);
157
+ return;
158
+ }
159
+
160
+ // Fully controlled: the parent owns the state and reacts in `onOpenChange`,
161
+ // flowing the value back down (or ignoring it to reject the change). Writing
162
+ // `openProp` here would locally override the parent's prop.
163
+ if (controlledOpen) return;
164
+
165
+ isOpenInternal = value;
166
+ openProp = value;
167
+ }
168
+
169
+ function openDrawer() {
170
+ setOpen(true);
171
+ }
172
+
173
+ /**
174
+ * Returns focus to the trigger, retrying once the DOM has caught up.
175
+ *
176
+ * While a modal drawer is open, `ariaHideOutside` marks everything outside the
177
+ * panel `inert` — including the trigger — and `focus()` on an inert element is a
178
+ * no-op. The attribute is only lifted during the update this close kicks off, so
179
+ * the first attempt can silently land on `<body>`. The retry costs nothing when
180
+ * the first one worked, and is the difference between returning the keyboard user
181
+ * to where they were and dumping them at the top of the page.
182
+ */
183
+ function restoreFocusTo(
184
+ target: HTMLElement,
185
+ modality: ReturnType<typeof resolveCloseInteractionModality>
186
+ ) {
187
+ focusWithModality(target, modality);
188
+ if (document.activeElement === target) return;
189
+
190
+ void tick().then(() => {
191
+ if (!target.isConnected || document.activeElement === target) return;
192
+ focusWithModality(target, modality);
193
+ });
194
+ }
195
+
196
+ function closeDrawer(reason: DrawerCloseReason = 'imperative-action', event?: Event) {
197
+ const wasOpen = readOpen();
198
+ setOpen(false);
199
+ // A controlled parent may have rejected the close (by not flowing `false`
200
+ // back down) — don't steal focus while the drawer is still open.
201
+ if (!wasOpen || readOpen()) return;
202
+ // With a handle, focus belongs to the trigger that actually opened it — not to
203
+ // whichever one happened to register itself last.
204
+ const restoreTarget = handle?.trigger ?? triggerRef;
205
+ if (restoreTarget) {
206
+ restoreFocusTo(restoreTarget, resolveCloseInteractionModality(reason, event));
207
+ }
208
+ }
209
+
210
+ function toggle() {
211
+ setOpen(!isOpen);
212
+ }
213
+
214
+ const ctx: DrawerContext = {
215
+ get isOpen() {
216
+ return isOpen;
217
+ },
218
+ get side() {
219
+ return side;
220
+ },
221
+ get modal() {
222
+ return modal;
223
+ },
224
+ get dismissible() {
225
+ return dismissible;
226
+ },
227
+ get shouldCloseOnEscape() {
228
+ return shouldCloseOnEscape;
229
+ },
230
+ get shouldCloseOnInteractOutside() {
231
+ return shouldCloseOnInteractOutside;
232
+ },
233
+ get triggerRef() {
234
+ return handle?.trigger ?? triggerRef ?? null;
235
+ },
236
+ get stackLevel() {
237
+ return stackLevel;
238
+ },
239
+ get stackIndex() {
240
+ return stackIndex;
241
+ },
242
+ setStackIndex(index: number) {
243
+ stackIndex = index;
244
+ },
245
+ get labelledBy() {
246
+ return labelIds.length > 0 ? labelIds.join(' ') : undefined;
247
+ },
248
+ get describedBy() {
249
+ return descriptionIds.length > 0 ? descriptionIds.join(' ') : undefined;
250
+ },
251
+ get snapPoints() {
252
+ return snapPoints;
253
+ },
254
+ get snapPoint() {
255
+ return snapPoint;
256
+ },
257
+ get snapToSequentialPoints() {
258
+ return snapToSequentialPoints;
259
+ },
260
+ setSnapPoint,
261
+ get swipeProgress() {
262
+ return swipeProgress;
263
+ },
264
+ get isSwiping() {
265
+ return isSwiping;
266
+ },
267
+ // `untrack` is load-bearing: these are called from an `$effect` inside
268
+ // Drawer.Title/Description, and reading the list to append to it would
269
+ // subscribe that effect to the very state it writes — an update loop that
270
+ // registers the same id forever.
271
+ registerLabel(id: string) {
272
+ untrack(() => {
273
+ labelIds = [...labelIds, id];
274
+ });
275
+ return () =>
276
+ untrack(() => {
277
+ labelIds = labelIds.filter((candidate) => candidate !== id);
278
+ });
279
+ },
280
+ registerDescription(id: string) {
281
+ untrack(() => {
282
+ descriptionIds = [...descriptionIds, id];
283
+ });
284
+ return () =>
285
+ untrack(() => {
286
+ descriptionIds = descriptionIds.filter((candidate) => candidate !== id);
287
+ });
288
+ },
289
+ setSwipeState(progress: number, swiping: boolean) {
290
+ swipeProgress = progress;
291
+ isSwiping = swiping;
292
+ },
293
+ get swipeOpenDistance() {
294
+ return swipeOpenDistance;
295
+ },
296
+ setSwipeOpenDistance(distance: number | null) {
297
+ swipeOpenDistance = distance;
298
+ },
299
+ get panelExtent() {
300
+ return panelExtent;
301
+ },
302
+ setPanelExtent(extent: number) {
303
+ panelExtent = extent;
304
+ },
305
+ setTriggerRef(el: HTMLElement | null) {
306
+ triggerRef = el;
307
+ },
308
+ setStackLevel(level: number) {
309
+ stackLevel = level;
310
+ },
311
+ open: openDrawer,
312
+ close: closeDrawer,
313
+ toggle,
314
+ onOpenChange: setOpen
315
+ };
316
+
317
+ setDrawerContext(ctx);
318
+ </script>
319
+
320
+ {#if children}
321
+ <!--
322
+ Zero-arg wrappers, NOT the internal functions: the snippet helpers are typed
323
+ `() => void`, so a consumer writing `onclick={close}` would otherwise hand the
324
+ MouseEvent to `closeDrawer` as its `reason`, degrading the close-focus modality.
325
+ -->
326
+ {@render children({
327
+ close: () => closeDrawer('imperative-action'),
328
+ open: () => openDrawer(),
329
+ toggle: () => toggle(),
330
+ isOpen,
331
+ payload: handle?.payload
332
+ })}
333
+ {/if}
@@ -0,0 +1,77 @@
1
+ import { type Snippet } from 'svelte';
2
+ import type { DrawerModal, DrawerSide, DrawerSnapPoint, DrawerStateHelpers } from './types';
3
+ import type { DrawerHandle } from './handle.svelte';
4
+ declare function $$render<Payload = unknown>(): {
5
+ props: {
6
+ /** Open state. Two-way by default — use `bind:open`. */
7
+ open?: boolean;
8
+ /** Initial open state, for when `open` is not supplied. */
9
+ defaultOpen?: boolean;
10
+ /**
11
+ * Opt into fully controlled state: the component stops writing back to `open` and
12
+ * only reports through `onOpenChange`, so the parent can reject a change by not
13
+ * flowing the new value back down. Off by default, because `bind:open` — the
14
+ * common case — needs the write-back to work at all.
15
+ */
16
+ controlledOpen?: boolean;
17
+ /** Callback when the open state changes. */
18
+ onOpenChange?: (open: boolean) => void;
19
+ /** Edge the panel is anchored to. */
20
+ side?: DrawerSide;
21
+ /** Focus trap / scroll lock behaviour. See `DrawerModal`. */
22
+ modal?: DrawerModal;
23
+ /** Whether a swipe toward the anchored edge may dismiss the drawer. */
24
+ dismissible?: boolean;
25
+ /** Whether pressing Escape closes the drawer. */
26
+ shouldCloseOnEscape?: boolean;
27
+ /** Whether pressing outside the panel closes it. */
28
+ shouldCloseOnInteractOutside?: boolean;
29
+ /**
30
+ * Resting positions the panel may settle on, smallest offset first is not
31
+ * required — they are sorted internally. See `DrawerSnapPoint` for the accepted
32
+ * value forms. Without this the drawer is either fully open or closed.
33
+ */
34
+ snapPoints?: readonly DrawerSnapPoint[];
35
+ /** Active snap point. Two-way by default — use `bind:snapPoint`. */
36
+ snapPoint?: DrawerSnapPoint | null;
37
+ /** Initial snap point, for when `snapPoint` is not supplied. */
38
+ defaultSnapPoint?: DrawerSnapPoint | null;
39
+ /** Callback when the active snap point changes. */
40
+ onSnapPointChange?: (snapPoint: DrawerSnapPoint | null, event?: Event) => void;
41
+ /**
42
+ * Stops a fast flick from skipping past the neighbouring snap point. Use it when
43
+ * every step is meaningful and jumping two at once would disorient.
44
+ */
45
+ snapToSequentialPoints?: boolean;
46
+ /**
47
+ * Drives the drawer from a detached handle instead of the `open` prop, so
48
+ * triggers can live anywhere in the tree. See `createDrawerHandle`.
49
+ */
50
+ handle?: DrawerHandle<Payload>;
51
+ /** Reference to the trigger element. Set manually or via Drawer.Trigger. */
52
+ triggerRef?: HTMLElement | null;
53
+ /** Children snippet, receiving state helpers. */
54
+ children?: Snippet<[DrawerStateHelpers<Payload>]>;
55
+ };
56
+ exports: {};
57
+ bindings: "open" | "triggerRef" | "snapPoint";
58
+ slots: {};
59
+ events: {};
60
+ };
61
+ declare class __sveltets_Render<Payload = unknown> {
62
+ props(): ReturnType<typeof $$render<Payload>>['props'];
63
+ events(): ReturnType<typeof $$render<Payload>>['events'];
64
+ slots(): ReturnType<typeof $$render<Payload>>['slots'];
65
+ bindings(): "open" | "triggerRef" | "snapPoint";
66
+ exports(): {};
67
+ }
68
+ interface $$IsomorphicComponent {
69
+ new <Payload = unknown>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<Payload>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<Payload>['props']>, ReturnType<__sveltets_Render<Payload>['events']>, ReturnType<__sveltets_Render<Payload>['slots']>> & {
70
+ $$bindings?: ReturnType<__sveltets_Render<Payload>['bindings']>;
71
+ } & ReturnType<__sveltets_Render<Payload>['exports']>;
72
+ <Payload = unknown>(internal: unknown, props: ReturnType<__sveltets_Render<Payload>['props']> & {}): ReturnType<__sveltets_Render<Payload>['exports']>;
73
+ z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
74
+ }
75
+ declare const DrawerRoot: $$IsomorphicComponent;
76
+ type DrawerRoot<Payload = unknown> = InstanceType<typeof DrawerRoot<Payload>>;
77
+ export default DrawerRoot;
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Global registry of open drawers, in open order.
3
+ *
4
+ * Separate from `primitives/layer-stack.ts` on purpose: that one answers "who owns
5
+ * the next Escape, and at what z-index", which drawers share with dialogs. This one
6
+ * answers questions only drawers ask — how deep am I in the stack, how tall is the
7
+ * frontmost one, how far has it been dragged — so a drawer behind another can shrink
8
+ * back, and the app behind all of them can indent.
9
+ */
10
+ export type DrawerStackEntry = {
11
+ id: symbol;
12
+ /** Panel extent along its own axis, in px. */
13
+ extent: number;
14
+ /**
15
+ * How present the drawer is, 0–1: 1 at rest, falling toward 0 as it is dragged
16
+ * away. Drives the indent so the app comes back as the drawer leaves, rather
17
+ * than snapping at the moment it closes.
18
+ */
19
+ presence: number;
20
+ /** Whether the drawer is being dragged right now. */
21
+ swiping: boolean;
22
+ /**
23
+ * Whether the drawer is playing its exit animation.
24
+ *
25
+ * A closing drawer stays registered until it unmounts, because it is still on
26
+ * screen — but it should stop counting as "on top of" the one behind it the
27
+ * moment it starts leaving. Waiting for the unmount made the drawer underneath
28
+ * sit still through the whole exit and only then begin its own animation, which
29
+ * read as the stack unwinding in slow motion instead of the two moving together.
30
+ */
31
+ exiting: boolean;
32
+ };
33
+ /** Registers an opened drawer and returns its identity. */
34
+ export declare function registerDrawer(): symbol;
35
+ export declare function unregisterDrawer(id: symbol): void;
36
+ /**
37
+ * Updates a drawer's measurements.
38
+ *
39
+ * Reads are untracked because callers patch from inside an `$effect` that also
40
+ * reads the stack; subscribing to the array here would make that effect retrigger
41
+ * itself forever.
42
+ */
43
+ export declare function updateDrawer(id: symbol, patch: Partial<Omit<DrawerStackEntry, 'id'>>): void;
44
+ /** Index in open order, or `-1` when the drawer is not registered. */
45
+ export declare function getDrawerIndex(id: symbol): number;
46
+ /**
47
+ * Reactive view of the stack. A getter object rather than exported values so
48
+ * consumers read through the proxy and stay subscribed.
49
+ */
50
+ export declare const drawerStack: {
51
+ readonly entries: readonly DrawerStackEntry[];
52
+ readonly count: number;
53
+ /** Extent of the drawer on top of the stack, in px. */
54
+ readonly frontmostExtent: number;
55
+ /**
56
+ * How far the app behind should be indented, 0–1. Takes the maximum rather than
57
+ * summing so a stack of drawers indents exactly as much as one does.
58
+ */
59
+ readonly indentProgress: number;
60
+ /** Whether any drawer is mid-drag, used to suspend the indent transition. */
61
+ readonly isSwiping: boolean;
62
+ };
63
+ /**
64
+ * Whether a drawer opened after `id` is currently open.
65
+ *
66
+ * Exiting drawers do not count: a drawer on its way out should release the one
67
+ * behind it immediately, so both animate at once rather than in sequence.
68
+ */
69
+ export declare function hasDrawerAbove(id: symbol): boolean;
70
+ /** Whether a drawer opened after `id` is being dragged. */
71
+ export declare function hasSwipingDrawerAbove(id: symbol): boolean;
72
+ /** Distance from the front of the stack — 0 is the frontmost drawer. */
73
+ export declare function getDepthFromFront(id: symbol): number;
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Global registry of open drawers, in open order.
3
+ *
4
+ * Separate from `primitives/layer-stack.ts` on purpose: that one answers "who owns
5
+ * the next Escape, and at what z-index", which drawers share with dialogs. This one
6
+ * answers questions only drawers ask — how deep am I in the stack, how tall is the
7
+ * frontmost one, how far has it been dragged — so a drawer behind another can shrink
8
+ * back, and the app behind all of them can indent.
9
+ */
10
+ import { untrack } from 'svelte';
11
+ const entries = $state([]);
12
+ /** Registers an opened drawer and returns its identity. */
13
+ export function registerDrawer() {
14
+ const id = Symbol('drawer');
15
+ untrack(() => {
16
+ entries.push({ id, extent: 0, presence: 1, swiping: false, exiting: false });
17
+ });
18
+ return id;
19
+ }
20
+ export function unregisterDrawer(id) {
21
+ untrack(() => {
22
+ const index = entries.findIndex((entry) => entry.id === id);
23
+ if (index !== -1)
24
+ entries.splice(index, 1);
25
+ });
26
+ }
27
+ /**
28
+ * Updates a drawer's measurements.
29
+ *
30
+ * Reads are untracked because callers patch from inside an `$effect` that also
31
+ * reads the stack; subscribing to the array here would make that effect retrigger
32
+ * itself forever.
33
+ */
34
+ export function updateDrawer(id, patch) {
35
+ untrack(() => {
36
+ const entry = entries.find((candidate) => candidate.id === id);
37
+ if (!entry)
38
+ return;
39
+ if (patch.extent !== undefined && patch.extent !== entry.extent)
40
+ entry.extent = patch.extent;
41
+ if (patch.presence !== undefined && patch.presence !== entry.presence) {
42
+ entry.presence = patch.presence;
43
+ }
44
+ if (patch.swiping !== undefined && patch.swiping !== entry.swiping) {
45
+ entry.swiping = patch.swiping;
46
+ }
47
+ if (patch.exiting !== undefined && patch.exiting !== entry.exiting) {
48
+ entry.exiting = patch.exiting;
49
+ }
50
+ });
51
+ }
52
+ /** Index in open order, or `-1` when the drawer is not registered. */
53
+ export function getDrawerIndex(id) {
54
+ return entries.findIndex((entry) => entry.id === id);
55
+ }
56
+ /**
57
+ * Reactive view of the stack. A getter object rather than exported values so
58
+ * consumers read through the proxy and stay subscribed.
59
+ */
60
+ export const drawerStack = {
61
+ get entries() {
62
+ return entries;
63
+ },
64
+ get count() {
65
+ return entries.length;
66
+ },
67
+ /** Extent of the drawer on top of the stack, in px. */
68
+ get frontmostExtent() {
69
+ return entries.length > 0 ? entries[entries.length - 1].extent : 0;
70
+ },
71
+ /**
72
+ * How far the app behind should be indented, 0–1. Takes the maximum rather than
73
+ * summing so a stack of drawers indents exactly as much as one does.
74
+ */
75
+ get indentProgress() {
76
+ let progress = 0;
77
+ for (const entry of entries) {
78
+ if (entry.presence > progress)
79
+ progress = entry.presence;
80
+ }
81
+ return progress;
82
+ },
83
+ /** Whether any drawer is mid-drag, used to suspend the indent transition. */
84
+ get isSwiping() {
85
+ return entries.some((entry) => entry.swiping);
86
+ }
87
+ };
88
+ /**
89
+ * Whether a drawer opened after `id` is currently open.
90
+ *
91
+ * Exiting drawers do not count: a drawer on its way out should release the one
92
+ * behind it immediately, so both animate at once rather than in sequence.
93
+ */
94
+ export function hasDrawerAbove(id) {
95
+ const index = getDrawerIndex(id);
96
+ if (index === -1)
97
+ return false;
98
+ return entries.slice(index + 1).some((entry) => !entry.exiting);
99
+ }
100
+ /** Whether a drawer opened after `id` is being dragged. */
101
+ export function hasSwipingDrawerAbove(id) {
102
+ const index = getDrawerIndex(id);
103
+ if (index === -1)
104
+ return false;
105
+ return entries.slice(index + 1).some((entry) => entry.swiping && !entry.exiting);
106
+ }
107
+ /** Distance from the front of the stack — 0 is the frontmost drawer. */
108
+ export function getDepthFromFront(id) {
109
+ const index = getDrawerIndex(id);
110
+ if (index === -1)
111
+ return 0;
112
+ return entries.slice(index + 1).filter((entry) => !entry.exiting).length;
113
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Detached trigger handles.
3
+ *
4
+ * Normally a `Drawer.Trigger` lives inside the `Drawer.Root` it opens. That breaks
5
+ * down when the openers are scattered — a row action in every line of a table, say,
6
+ * each needing to open the same drawer with a different record. Duplicating the
7
+ * whole drawer per row is wasteful and puts several modal panels in the DOM at once.
8
+ *
9
+ * A handle is the shared object in between: triggers push into it, one root reads
10
+ * from it, and the value the trigger carried arrives as the root's `payload`.
11
+ *
12
+ * ```svelte
13
+ * <script>
14
+ * const profile = createDrawerHandle();
15
+ * </script>
16
+ *
17
+ * {#each users as user}
18
+ * <Drawer.Trigger handle={profile} payload={user}>{user.name}</Drawer.Trigger>
19
+ * {/each}
20
+ *
21
+ * <Drawer.Root handle={profile}>
22
+ * {#snippet children({ payload })}…{/snippet}
23
+ * </Drawer.Root>
24
+ * ```
25
+ */
26
+ export type DrawerHandle<Payload = unknown> = {
27
+ readonly isOpen: boolean;
28
+ /** Value carried by the trigger that opened the drawer. */
29
+ readonly payload: Payload | undefined;
30
+ /** Element that opened the drawer, so focus can return to the right one. */
31
+ readonly trigger: HTMLElement | null;
32
+ /** Opens the drawer, optionally carrying a payload. */
33
+ open: (payload?: Payload, trigger?: HTMLElement | null) => void;
34
+ close: () => void;
35
+ toggle: (payload?: Payload, trigger?: HTMLElement | null) => void;
36
+ /** Used by `Drawer.Root` to mirror its own state changes back into the handle. */
37
+ setOpen: (open: boolean) => void;
38
+ };
39
+ export declare function createDrawerHandle<Payload = unknown>(): DrawerHandle<Payload>;