@human-kit/ui 1.0.0-beta.0 → 1.0.0-beta.2
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/README.md +2 -0
- package/dist/FOCUS_STATE_CONTRACT.md +1 -0
- package/dist/accordion/root/accordion-root.svelte +15 -3
- package/dist/accordion/root/context.svelte.js +4 -4
- package/dist/accordion/types.d.ts +9 -2
- package/dist/autocomplete/list/autocomplete-list.svelte.d.ts +6 -0
- package/dist/calendar/root/context.svelte.js +8 -2
- package/dist/checkbox/root/checkbox-root.svelte +28 -11
- package/dist/checkbox/root/checkbox-root.svelte.d.ts +13 -0
- package/dist/clock/root/create-time-selection-state.svelte.d.ts +5 -0
- package/dist/clock/root/create-time-selection-state.svelte.js +113 -10
- package/dist/clock/root/wheel-options.d.ts +7 -3
- package/dist/clock/root/wheel-options.js +7 -15
- package/dist/clock/wheel-column/clock-wheel-column.svelte +10 -2
- package/dist/clock/wheel-column/clock-wheel-column.svelte.d.ts +2 -1
- package/dist/collapsible/root/collapsible-root.svelte +9 -4
- package/dist/collapsible/types.d.ts +9 -0
- package/dist/combobox/input/combobox-input.svelte +12 -1
- package/dist/combobox/list/combobox-listbox.svelte +93 -1
- package/dist/combobox/list/combobox-listbox.svelte.d.ts +20 -0
- package/dist/combobox/root/combobox.svelte +118 -45
- package/dist/combobox/root/combobox.svelte.d.ts +11 -0
- package/dist/combobox/root/context.d.ts +12 -0
- package/dist/combobox/status/README.md +2 -2
- package/dist/combobox/tag-remove/combobox-tag-remove.svelte +14 -2
- package/dist/combobox/tag-remove/combobox-tag-remove.svelte.d.ts +7 -0
- package/dist/combobox/tags/combobox-tags.svelte +5 -2
- package/dist/combobox/tags/combobox-tags.svelte.d.ts +2 -0
- package/dist/combobox/trigger/combobox-trigger.svelte +4 -1
- package/dist/datepicker/README.md +3 -2
- package/dist/datepicker/root/date-picker-root.svelte +38 -2
- package/dist/datepicker/root/date-picker-root.svelte.d.ts +2 -0
- package/dist/datepicker/root/draft-evaluation.d.ts +7 -0
- package/dist/datepicker/root/draft-evaluation.js +2 -2
- package/dist/daterangepicker/root/date-range-picker-root.svelte +19 -1
- package/dist/daterangepicker/root/date-range-picker-root.svelte.d.ts +2 -0
- package/dist/dialog/README.md +9 -1
- package/dist/dialog/close/dialog-close.svelte +57 -0
- package/dist/dialog/close/dialog-close.svelte.d.ts +19 -0
- package/dist/dialog/content/dialog-content.svelte +2 -0
- package/dist/dialog/description/dialog-description.svelte +46 -0
- package/dist/dialog/description/dialog-description.svelte.d.ts +20 -0
- package/dist/dialog/index.d.ts +9 -0
- package/dist/dialog/index.js +3 -0
- package/dist/dialog/index.parts.d.ts +3 -0
- package/dist/dialog/index.parts.js +3 -0
- package/dist/dialog/root/context.d.ts +8 -0
- package/dist/dialog/root/dialog-root.svelte +58 -16
- package/dist/dialog/root/dialog-root.svelte.d.ts +10 -3
- package/dist/dialog/root/dialog-stack.d.ts +6 -22
- package/dist/dialog/root/dialog-stack.js +4 -33
- package/dist/dialog/title/dialog-title.svelte +43 -0
- package/dist/dialog/title/dialog-title.svelte.d.ts +21 -0
- package/dist/drawer/README.md +111 -0
- package/dist/drawer/body/drawer-body.svelte +47 -0
- package/dist/drawer/body/drawer-body.svelte.d.ts +32 -0
- package/dist/drawer/close/drawer-close.svelte +52 -0
- package/dist/drawer/close/drawer-close.svelte.d.ts +20 -0
- package/dist/drawer/content/drawer-content.svelte +597 -0
- package/dist/drawer/content/drawer-content.svelte.d.ts +28 -0
- package/dist/drawer/description/drawer-description.svelte +40 -0
- package/dist/drawer/description/drawer-description.svelte.d.ts +20 -0
- package/dist/drawer/indent/drawer-indent-background.svelte +36 -0
- package/dist/drawer/indent/drawer-indent-background.svelte.d.ts +17 -0
- package/dist/drawer/indent/drawer-indent.svelte +59 -0
- package/dist/drawer/indent/drawer-indent.svelte.d.ts +32 -0
- package/dist/drawer/index.d.ts +49 -0
- package/dist/drawer/index.js +25 -0
- package/dist/drawer/index.parts.d.ts +14 -0
- package/dist/drawer/index.parts.js +15 -0
- package/dist/drawer/overlay/drawer-overlay.svelte +67 -0
- package/dist/drawer/overlay/drawer-overlay.svelte.d.ts +12 -0
- package/dist/drawer/portal/drawer-portal.svelte +57 -0
- package/dist/drawer/portal/drawer-portal.svelte.d.ts +13 -0
- package/dist/drawer/root/context.d.ts +81 -0
- package/dist/drawer/root/context.js +20 -0
- package/dist/drawer/root/drawer-root.svelte +333 -0
- package/dist/drawer/root/drawer-root.svelte.d.ts +77 -0
- package/dist/drawer/root/drawer-stack.svelte.d.ts +73 -0
- package/dist/drawer/root/drawer-stack.svelte.js +113 -0
- package/dist/drawer/root/handle.svelte.d.ts +39 -0
- package/dist/drawer/root/handle.svelte.js +64 -0
- package/dist/drawer/root/keyboard-context.d.ts +13 -0
- package/dist/drawer/root/keyboard-context.js +8 -0
- package/dist/drawer/root/presence-context.d.ts +22 -0
- package/dist/drawer/root/presence-context.js +8 -0
- package/dist/drawer/root/snap-points.d.ts +68 -0
- package/dist/drawer/root/snap-points.js +120 -0
- package/dist/drawer/root/starting-style.svelte.d.ts +18 -0
- package/dist/drawer/root/starting-style.svelte.js +38 -0
- package/dist/drawer/root/types.d.ts +36 -0
- package/dist/drawer/root/types.js +1 -0
- package/dist/drawer/root/viewport-context.d.ts +2 -0
- package/dist/drawer/root/viewport-context.js +16 -0
- package/dist/drawer/swipe-area/drawer-swipe-area.svelte +143 -0
- package/dist/drawer/swipe-area/drawer-swipe-area.svelte.d.ts +22 -0
- package/dist/drawer/title/drawer-title.svelte +37 -0
- package/dist/drawer/title/drawer-title.svelte.d.ts +21 -0
- package/dist/drawer/trigger/drawer-trigger.svelte +90 -0
- package/dist/drawer/trigger/drawer-trigger.svelte.d.ts +41 -0
- package/dist/drawer/viewport/drawer-viewport.svelte +69 -0
- package/dist/drawer/viewport/drawer-viewport.svelte.d.ts +15 -0
- package/dist/drawer/virtual-keyboard/drawer-virtual-keyboard-provider.svelte +88 -0
- package/dist/drawer/virtual-keyboard/drawer-virtual-keyboard-provider.svelte.d.ts +29 -0
- package/dist/hooks/use-virtual-focus.svelte.d.ts +9 -0
- package/dist/hooks/use-virtual-focus.svelte.js +7 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/listbox/item/listbox-item.svelte +8 -1
- package/dist/listbox/root/context.d.ts +30 -0
- package/dist/listbox/root/context.js +10 -0
- package/dist/listbox/root/listbox.svelte +291 -8
- package/dist/listbox/root/listbox.svelte.d.ts +35 -2
- package/dist/menu/content/menu-content.svelte +3 -1
- package/dist/menu/overlay/menu-overlay.svelte +1 -1
- package/dist/numberfield/root/number-field-root.svelte +2 -1
- package/dist/popover/content/popover-content.svelte +1 -1
- package/dist/popover/overlay/popover-overlay.svelte +1 -1
- package/dist/popover/root/popover-root.svelte +23 -11
- package/dist/popover/root/popover-root.svelte.d.ts +10 -2
- package/dist/primitives/floating.d.ts +7 -0
- package/dist/primitives/floating.js +6 -2
- package/dist/primitives/index.d.ts +1 -0
- package/dist/primitives/index.js +1 -0
- package/dist/primitives/keyboard-navigation.js +3 -1
- package/dist/primitives/layer-stack.d.ts +29 -0
- package/dist/primitives/layer-stack.js +35 -0
- package/dist/primitives/list-virtualizer.d.ts +75 -0
- package/dist/primitives/list-virtualizer.js +59 -0
- package/dist/primitives/scroll-lock.d.ts +23 -3
- package/dist/primitives/scroll-lock.js +122 -9
- package/dist/primitives/swipe-gesture.d.ts +126 -0
- package/dist/primitives/swipe-gesture.js +351 -0
- package/dist/primitives/text.d.ts +8 -0
- package/dist/primitives/text.js +13 -0
- package/dist/switch/root/switch-root.svelte +23 -9
- package/dist/switch/root/switch-root.svelte.d.ts +9 -2
- package/dist/table/body/table-body.svelte +84 -9
- package/dist/table/cell/table-cell.svelte +1 -3
- package/dist/table/column/table-column.svelte +5 -1
- package/dist/table/column-resizer/table-column-resizer.svelte +1 -5
- package/dist/table/index.d.ts +1 -1
- package/dist/table/index.js +1 -1
- package/dist/table/interactive-cell/table-interactive-cell.svelte +1 -3
- package/dist/table/root/context.svelte.js +99 -49
- package/dist/table/row/table-row.svelte +7 -7
- package/dist/table/sort-trigger/table-sort-trigger.svelte +5 -1
- package/dist/table/types.d.ts +6 -0
- package/dist/tabs/root/tabs-root.svelte +20 -6
- package/dist/tabs/types.d.ts +9 -0
- package/dist/timepicker/root/time-picker-root.svelte +11 -0
- package/dist/timepicker/root/time-picker-root.svelte.d.ts +2 -0
- package/dist/toggle-group/root/context.svelte.js +11 -4
- package/dist/toggle-group/root/toggle-group-root.svelte +19 -4
- package/dist/toggle-group/types.d.ts +9 -0
- package/dist/tree/root/context.svelte.js +6 -0
- package/dist/tree/root/tree-root.svelte +22 -8
- package/dist/tree/types.d.ts +13 -0
- package/package.json +227 -224
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
<!-- Generic over the payload so it lines up with the handle it pushes into. -->
|
|
2
|
+
<script lang="ts" generics="Payload = unknown">
|
|
3
|
+
import { untrack, type Snippet } from 'svelte';
|
|
4
|
+
import type { HTMLButtonAttributes } from 'svelte/elements';
|
|
5
|
+
import { ButtonRoot } from '../../button/index.js';
|
|
6
|
+
import { getDrawerContext } from '../root/context';
|
|
7
|
+
import type { DrawerHandle } from '../root/handle.svelte';
|
|
8
|
+
|
|
9
|
+
// Not exported: a generic component cannot re-export a type that mentions its own
|
|
10
|
+
// type parameter. The public `DrawerTriggerProps` comes from `ComponentProps` in
|
|
11
|
+
// the index, which resolves the generic properly anyway.
|
|
12
|
+
type DrawerTriggerProps = Omit<
|
|
13
|
+
HTMLButtonAttributes,
|
|
14
|
+
'type' | 'class' | 'children' | 'aria-haspopup' | 'aria-expanded'
|
|
15
|
+
> & {
|
|
16
|
+
/** Button label. */
|
|
17
|
+
children?: Snippet;
|
|
18
|
+
/** CSS class for the button. */
|
|
19
|
+
class?: string;
|
|
20
|
+
/** Bindable reference to the rendered button. */
|
|
21
|
+
element?: HTMLButtonElement | null;
|
|
22
|
+
/**
|
|
23
|
+
* Opens the drawer through a detached handle instead of context, so the trigger
|
|
24
|
+
* can live anywhere in the tree. See `createDrawerHandle`.
|
|
25
|
+
*/
|
|
26
|
+
handle?: DrawerHandle<Payload>;
|
|
27
|
+
/** Value handed to the drawer's `children` snippet when this trigger opens it. */
|
|
28
|
+
payload?: Payload;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
type DrawerTriggerMouseEvent = MouseEvent & {
|
|
32
|
+
currentTarget: EventTarget & HTMLButtonElement;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
let {
|
|
36
|
+
children,
|
|
37
|
+
class: className = '',
|
|
38
|
+
element = $bindable<HTMLButtonElement | null>(null),
|
|
39
|
+
handle,
|
|
40
|
+
payload,
|
|
41
|
+
onclick: onClickExternal,
|
|
42
|
+
...restProps
|
|
43
|
+
}: DrawerTriggerProps = $props();
|
|
44
|
+
|
|
45
|
+
// With a handle the trigger is usually OUTSIDE the root, so context is optional;
|
|
46
|
+
// without one it is the only way to reach the drawer, and its absence is a bug.
|
|
47
|
+
// Context can only be read during init, so `handle` is read untracked — a handle
|
|
48
|
+
// swapped later would not change which mechanism this trigger uses anyway.
|
|
49
|
+
const ctx = getDrawerContext();
|
|
50
|
+
if (!ctx && !untrack(() => handle)) {
|
|
51
|
+
throw new Error('Drawer.Trigger must be used inside a Drawer.Root, or given a `handle`.');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let buttonRef: HTMLButtonElement | null = $state(null);
|
|
55
|
+
|
|
56
|
+
const isOpen = $derived(handle ? handle.isOpen : (ctx?.isOpen ?? false));
|
|
57
|
+
|
|
58
|
+
function handleClick(event: DrawerTriggerMouseEvent) {
|
|
59
|
+
if (handle) {
|
|
60
|
+
handle.toggle(payload, buttonRef);
|
|
61
|
+
} else {
|
|
62
|
+
ctx?.toggle();
|
|
63
|
+
}
|
|
64
|
+
onClickExternal?.(event);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
$effect(() => {
|
|
68
|
+
element = buttonRef;
|
|
69
|
+
// A handled trigger records itself on the handle at click time instead: with
|
|
70
|
+
// many triggers sharing one drawer, the last one to mount is not the one focus
|
|
71
|
+
// should return to.
|
|
72
|
+
if (buttonRef && !handle) {
|
|
73
|
+
ctx?.setTriggerRef(buttonRef);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
</script>
|
|
77
|
+
|
|
78
|
+
<ButtonRoot
|
|
79
|
+
{...restProps}
|
|
80
|
+
bind:element={buttonRef}
|
|
81
|
+
class={className}
|
|
82
|
+
type="button"
|
|
83
|
+
pressed={isOpen || undefined}
|
|
84
|
+
aria-haspopup="dialog"
|
|
85
|
+
aria-expanded={isOpen}
|
|
86
|
+
data-drawer-trigger="true"
|
|
87
|
+
onclick={handleClick}
|
|
88
|
+
>
|
|
89
|
+
{@render children?.()}
|
|
90
|
+
</ButtonRoot>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLButtonAttributes } from 'svelte/elements';
|
|
3
|
+
import type { DrawerHandle } from '../root/handle.svelte';
|
|
4
|
+
declare function $$render<Payload = unknown>(): {
|
|
5
|
+
props: Omit<HTMLButtonAttributes, "children" | "class" | "aria-expanded" | "aria-haspopup" | "type"> & {
|
|
6
|
+
/** Button label. */
|
|
7
|
+
children?: Snippet;
|
|
8
|
+
/** CSS class for the button. */
|
|
9
|
+
class?: string;
|
|
10
|
+
/** Bindable reference to the rendered button. */
|
|
11
|
+
element?: HTMLButtonElement | null;
|
|
12
|
+
/**
|
|
13
|
+
* Opens the drawer through a detached handle instead of context, so the trigger
|
|
14
|
+
* can live anywhere in the tree. See `createDrawerHandle`.
|
|
15
|
+
*/
|
|
16
|
+
handle?: DrawerHandle<Payload>;
|
|
17
|
+
/** Value handed to the drawer's `children` snippet when this trigger opens it. */
|
|
18
|
+
payload?: Payload;
|
|
19
|
+
};
|
|
20
|
+
exports: {};
|
|
21
|
+
bindings: "element";
|
|
22
|
+
slots: {};
|
|
23
|
+
events: {};
|
|
24
|
+
};
|
|
25
|
+
declare class __sveltets_Render<Payload = unknown> {
|
|
26
|
+
props(): ReturnType<typeof $$render<Payload>>['props'];
|
|
27
|
+
events(): ReturnType<typeof $$render<Payload>>['events'];
|
|
28
|
+
slots(): ReturnType<typeof $$render<Payload>>['slots'];
|
|
29
|
+
bindings(): "element";
|
|
30
|
+
exports(): {};
|
|
31
|
+
}
|
|
32
|
+
interface $$IsomorphicComponent {
|
|
33
|
+
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']>> & {
|
|
34
|
+
$$bindings?: ReturnType<__sveltets_Render<Payload>['bindings']>;
|
|
35
|
+
} & ReturnType<__sveltets_Render<Payload>['exports']>;
|
|
36
|
+
<Payload = unknown>(internal: unknown, props: ReturnType<__sveltets_Render<Payload>['props']> & {}): ReturnType<__sveltets_Render<Payload>['exports']>;
|
|
37
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
38
|
+
}
|
|
39
|
+
declare const DrawerTrigger: $$IsomorphicComponent;
|
|
40
|
+
type DrawerTrigger<Payload = unknown> = InstanceType<typeof DrawerTrigger<Payload>>;
|
|
41
|
+
export default DrawerTrigger;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
|
+
import { requireDrawerContext } from '../root/context';
|
|
5
|
+
import { getDrawerPresenceContext } from '../root/presence-context';
|
|
6
|
+
import { markDrawerViewport } from '../root/viewport-context';
|
|
7
|
+
import { getContentZIndex } from '../../primitives/layer-stack';
|
|
8
|
+
import type { DrawerSide } from '../root/types';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Drawer.Viewport — the positioning layer that pins the panel to its edge.
|
|
12
|
+
* Belongs inside a Drawer.Portal, wrapping a Drawer.Content.
|
|
13
|
+
*/
|
|
14
|
+
type DrawerViewportProps = {
|
|
15
|
+
/** The panel this viewport places. */
|
|
16
|
+
children?: Snippet;
|
|
17
|
+
/** CSS class for the viewport. */
|
|
18
|
+
class?: string;
|
|
19
|
+
} & Omit<HTMLAttributes<HTMLDivElement>, 'class' | 'children'>;
|
|
20
|
+
|
|
21
|
+
let {
|
|
22
|
+
children,
|
|
23
|
+
class: className = '',
|
|
24
|
+
style: styleProp,
|
|
25
|
+
...restProps
|
|
26
|
+
}: DrawerViewportProps = $props();
|
|
27
|
+
|
|
28
|
+
const ctx = requireDrawerContext('Drawer.Viewport');
|
|
29
|
+
const presence = getDrawerPresenceContext();
|
|
30
|
+
|
|
31
|
+
// Tells the Content inside to stay in flow instead of pinning itself.
|
|
32
|
+
markDrawerViewport();
|
|
33
|
+
|
|
34
|
+
const zIndex = $derived(getContentZIndex(ctx.stackLevel));
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The viewport spans the whole screen so the panel can be aligned with flexbox
|
|
38
|
+
* and still size itself to its content. It is transparent to pointers — only the
|
|
39
|
+
* panel inside it takes them — so a non-modal drawer leaves the rest of the page
|
|
40
|
+
* fully usable, and a modal one relies on Drawer.Overlay to block instead.
|
|
41
|
+
*/
|
|
42
|
+
function layoutFor(side: DrawerSide): string {
|
|
43
|
+
const vertical = side === 'top' || side === 'bottom';
|
|
44
|
+
const direction = vertical ? 'column' : 'row';
|
|
45
|
+
const justify = side === 'bottom' || side === 'right' ? 'flex-end' : 'flex-start';
|
|
46
|
+
return `flex-direction: ${direction}; justify-content: ${justify}; align-items: stretch;`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// A consumer `style` is appended rather than spread through `restProps`, which
|
|
50
|
+
// would land after this attribute and drop the positioning with it.
|
|
51
|
+
const style = $derived(
|
|
52
|
+
`position: fixed; inset: 0; z-index: ${zIndex}; display: flex; pointer-events: none; ${layoutFor(ctx.side)} ${styleProp ?? ''}`
|
|
53
|
+
);
|
|
54
|
+
</script>
|
|
55
|
+
|
|
56
|
+
<div
|
|
57
|
+
class={className}
|
|
58
|
+
data-drawer-viewport
|
|
59
|
+
data-side={ctx.side}
|
|
60
|
+
data-state={presence ? presence.state : 'open'}
|
|
61
|
+
data-entering={presence?.isEntering || undefined}
|
|
62
|
+
data-exiting={presence?.isExiting || undefined}
|
|
63
|
+
{style}
|
|
64
|
+
{...restProps}
|
|
65
|
+
>
|
|
66
|
+
{#if children}
|
|
67
|
+
{@render children()}
|
|
68
|
+
{/if}
|
|
69
|
+
</div>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
/**
|
|
4
|
+
* Drawer.Viewport — the positioning layer that pins the panel to its edge.
|
|
5
|
+
* Belongs inside a Drawer.Portal, wrapping a Drawer.Content.
|
|
6
|
+
*/
|
|
7
|
+
type DrawerViewportProps = {
|
|
8
|
+
/** The panel this viewport places. */
|
|
9
|
+
children?: Snippet;
|
|
10
|
+
/** CSS class for the viewport. */
|
|
11
|
+
class?: string;
|
|
12
|
+
} & Omit<HTMLAttributes<HTMLDivElement>, 'class' | 'children'>;
|
|
13
|
+
declare const DrawerViewport: import("svelte").Component<DrawerViewportProps, {}, "">;
|
|
14
|
+
type DrawerViewport = ReturnType<typeof DrawerViewport>;
|
|
15
|
+
export default DrawerViewport;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import { browser } from '../../internal/environment';
|
|
4
|
+
import { setDrawerKeyboardContext } from '../root/keyboard-context';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Drawer.VirtualKeyboardProvider — keeps a drawer's fields above the software
|
|
8
|
+
* keyboard.
|
|
9
|
+
*
|
|
10
|
+
* Wrap it around `Drawer.Root` (it renders no element of its own). While the
|
|
11
|
+
* keyboard is up, `Drawer.Content` exposes `--drawer-keyboard-inset` — the height
|
|
12
|
+
* the keyboard covers — so a footer can be lifted clear of it:
|
|
13
|
+
*
|
|
14
|
+
* ```css
|
|
15
|
+
* .Footer { padding-bottom: var(--drawer-keyboard-inset, 0px); }
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* The variable is only set while the keyboard is actually up, which is what makes
|
|
19
|
+
* the `0px` fallback the right default rather than a guess.
|
|
20
|
+
*
|
|
21
|
+
* On a phone the keyboard shrinks the VISUAL viewport without touching the layout
|
|
22
|
+
* viewport, so nothing in CSS notices it — `100vh` still spans the full screen and
|
|
23
|
+
* a bottom sheet ends up underneath the keys. `window.visualViewport` is the only
|
|
24
|
+
* thing that reports the difference. Where it is missing (older browsers, and
|
|
25
|
+
* every desktop where this does not apply anyway) the provider is inert.
|
|
26
|
+
*/
|
|
27
|
+
type DrawerVirtualKeyboardProviderProps = {
|
|
28
|
+
/** The subtree the keyboard inset is published to. */
|
|
29
|
+
children?: Snippet;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
let { children }: DrawerVirtualKeyboardProviderProps = $props();
|
|
33
|
+
|
|
34
|
+
let inset = $state(0);
|
|
35
|
+
|
|
36
|
+
setDrawerKeyboardContext({
|
|
37
|
+
get inset() {
|
|
38
|
+
return inset;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
$effect(() => {
|
|
43
|
+
if (!browser) return;
|
|
44
|
+
const viewport = window.visualViewport;
|
|
45
|
+
if (!viewport) return;
|
|
46
|
+
|
|
47
|
+
function measure() {
|
|
48
|
+
if (!viewport) return;
|
|
49
|
+
const layoutHeight = document.documentElement.clientHeight;
|
|
50
|
+
// `offsetTop` matters when the user has pinch-zoomed and panned: the visual
|
|
51
|
+
// viewport is then both shorter AND offset, and ignoring it reports an inset
|
|
52
|
+
// that is off by the pan distance.
|
|
53
|
+
const covered = layoutHeight - (viewport.height + viewport.offsetTop);
|
|
54
|
+
// Sub-pixel noise is constant on HiDPI screens; anything under a few pixels
|
|
55
|
+
// is not a keyboard.
|
|
56
|
+
inset = covered > 4 ? covered : 0;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
measure();
|
|
60
|
+
viewport.addEventListener('resize', measure);
|
|
61
|
+
viewport.addEventListener('scroll', measure);
|
|
62
|
+
|
|
63
|
+
return () => {
|
|
64
|
+
viewport.removeEventListener('resize', measure);
|
|
65
|
+
viewport.removeEventListener('scroll', measure);
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Bring the focused field back into view once the keyboard has settled. The
|
|
70
|
+
// browser does this for the document scroller on its own, but not for a field
|
|
71
|
+
// inside a fixed-position panel.
|
|
72
|
+
$effect(() => {
|
|
73
|
+
if (!browser || inset <= 0) return;
|
|
74
|
+
|
|
75
|
+
const frame = requestAnimationFrame(() => {
|
|
76
|
+
const active = document.activeElement;
|
|
77
|
+
if (!(active instanceof HTMLElement)) return;
|
|
78
|
+
if (!active.closest('[data-drawer-content]')) return;
|
|
79
|
+
active.scrollIntoView({ block: 'nearest', behavior: 'smooth' });
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
return () => cancelAnimationFrame(frame);
|
|
83
|
+
});
|
|
84
|
+
</script>
|
|
85
|
+
|
|
86
|
+
{#if children}
|
|
87
|
+
{@render children()}
|
|
88
|
+
{/if}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
/**
|
|
3
|
+
* Drawer.VirtualKeyboardProvider — keeps a drawer's fields above the software
|
|
4
|
+
* keyboard.
|
|
5
|
+
*
|
|
6
|
+
* Wrap it around `Drawer.Root` (it renders no element of its own). While the
|
|
7
|
+
* keyboard is up, `Drawer.Content` exposes `--drawer-keyboard-inset` — the height
|
|
8
|
+
* the keyboard covers — so a footer can be lifted clear of it:
|
|
9
|
+
*
|
|
10
|
+
* ```css
|
|
11
|
+
* .Footer { padding-bottom: var(--drawer-keyboard-inset, 0px); }
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* The variable is only set while the keyboard is actually up, which is what makes
|
|
15
|
+
* the `0px` fallback the right default rather than a guess.
|
|
16
|
+
*
|
|
17
|
+
* On a phone the keyboard shrinks the VISUAL viewport without touching the layout
|
|
18
|
+
* viewport, so nothing in CSS notices it — `100vh` still spans the full screen and
|
|
19
|
+
* a bottom sheet ends up underneath the keys. `window.visualViewport` is the only
|
|
20
|
+
* thing that reports the difference. Where it is missing (older browsers, and
|
|
21
|
+
* every desktop where this does not apply anyway) the provider is inert.
|
|
22
|
+
*/
|
|
23
|
+
type DrawerVirtualKeyboardProviderProps = {
|
|
24
|
+
/** The subtree the keyboard inset is published to. */
|
|
25
|
+
children?: Snippet;
|
|
26
|
+
};
|
|
27
|
+
declare const DrawerVirtualKeyboardProvider: import("svelte").Component<DrawerVirtualKeyboardProviderProps, {}, "">;
|
|
28
|
+
type DrawerVirtualKeyboardProvider = ReturnType<typeof DrawerVirtualKeyboardProvider>;
|
|
29
|
+
export default DrawerVirtualKeyboardProvider;
|
|
@@ -33,6 +33,15 @@ export type VirtualFocusOptions = {
|
|
|
33
33
|
itemPrefix?: string;
|
|
34
34
|
/** Reference to container element for scoped DOM queries */
|
|
35
35
|
containerRef?: () => HTMLElement | null;
|
|
36
|
+
/**
|
|
37
|
+
* The authoritative item order, when the caller has one.
|
|
38
|
+
*
|
|
39
|
+
* Navigation otherwise reads the order off the DOM, which is only the same thing while
|
|
40
|
+
* every item is mounted. A virtualized list mounts a window of rows, so without this
|
|
41
|
+
* `last()` would land on the last *rendered* item and `next()` would stop at the edge of
|
|
42
|
+
* that window. Return `undefined` to fall back to the DOM order.
|
|
43
|
+
*/
|
|
44
|
+
orderedIds?: () => (string | number)[] | undefined;
|
|
36
45
|
};
|
|
37
46
|
export type VirtualFocusReturn = {
|
|
38
47
|
readonly focusedId: string | number | null;
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
*/
|
|
29
29
|
import { SvelteMap } from 'svelte/reactivity';
|
|
30
30
|
export function useVirtualFocus(options) {
|
|
31
|
-
const { instanceId, itemPrefix = 'combobox-item', containerRef } = options;
|
|
31
|
+
const { instanceId, itemPrefix = 'combobox-item', containerRef, orderedIds: getOrderedIds } = options;
|
|
32
32
|
// Internal state
|
|
33
33
|
let focusedId = $state(null);
|
|
34
34
|
let itemIds = $state([]);
|
|
@@ -47,6 +47,12 @@ export function useVirtualFocus(options) {
|
|
|
47
47
|
* Uses cache when available, queries DOM otherwise.
|
|
48
48
|
*/
|
|
49
49
|
function getItemIdsInOrder() {
|
|
50
|
+
// Given order wins over the DOM, and is never cached: it is derived from the caller's
|
|
51
|
+
// own list, which already changes exactly when the order does.
|
|
52
|
+
const given = getOrderedIds?.();
|
|
53
|
+
if (given !== undefined) {
|
|
54
|
+
return given;
|
|
55
|
+
}
|
|
50
56
|
if (cachedItemOrder !== null) {
|
|
51
57
|
return cachedItemOrder;
|
|
52
58
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export { DatePicker } from './datepicker/index.js';
|
|
|
10
10
|
export { DateRangePicker } from './daterangepicker/index.js';
|
|
11
11
|
export { TimePicker } from './timepicker/index.js';
|
|
12
12
|
export { Dialog } from './dialog/index.js';
|
|
13
|
+
export { Drawer } from './drawer/index.js';
|
|
13
14
|
export { ListBox } from './listbox/index.js';
|
|
14
15
|
export { Menu } from './menu/index.js';
|
|
15
16
|
export { NumberField } from './numberfield/index.js';
|
|
@@ -41,6 +42,7 @@ export * from './daterangepicker/index.js';
|
|
|
41
42
|
export * from './dropzone/index.js';
|
|
42
43
|
export * from './timepicker/index.js';
|
|
43
44
|
export * from './dialog/index.js';
|
|
45
|
+
export * from './drawer/index.js';
|
|
44
46
|
export * from './listbox/index.js';
|
|
45
47
|
export * from './menu/index.js';
|
|
46
48
|
export * from './numberfield/index.js';
|
package/dist/index.js
CHANGED
|
@@ -12,6 +12,7 @@ export { DatePicker } from './datepicker/index.js';
|
|
|
12
12
|
export { DateRangePicker } from './daterangepicker/index.js';
|
|
13
13
|
export { TimePicker } from './timepicker/index.js';
|
|
14
14
|
export { Dialog } from './dialog/index.js';
|
|
15
|
+
export { Drawer } from './drawer/index.js';
|
|
15
16
|
export { ListBox } from './listbox/index.js';
|
|
16
17
|
export { Menu } from './menu/index.js';
|
|
17
18
|
export { NumberField } from './numberfield/index.js';
|
|
@@ -45,6 +46,7 @@ export * from './daterangepicker/index.js';
|
|
|
45
46
|
export * from './dropzone/index.js';
|
|
46
47
|
export * from './timepicker/index.js';
|
|
47
48
|
export * from './dialog/index.js';
|
|
49
|
+
export * from './drawer/index.js';
|
|
48
50
|
export * from './listbox/index.js';
|
|
49
51
|
export * from './menu/index.js';
|
|
50
52
|
export * from './numberfield/index.js';
|
|
@@ -168,8 +168,15 @@
|
|
|
168
168
|
unsubscribeFocusVisible?.();
|
|
169
169
|
});
|
|
170
170
|
|
|
171
|
-
// Scroll into view when focused (if enabled)
|
|
171
|
+
// Scroll into view when focused (if enabled).
|
|
172
|
+
//
|
|
173
|
+
// Not in a virtualized list: there the scroll is the list's, which places the row against
|
|
174
|
+
// the whole collection — including rows that aren't mounted. An item pulling itself to
|
|
175
|
+
// the nearest edge afterwards undid that placement, which is what left the row the list
|
|
176
|
+
// had just opened on stuck against the bottom edge.
|
|
172
177
|
$effect(() => {
|
|
178
|
+
if (listboxCtx.isVirtualized()) return;
|
|
179
|
+
|
|
173
180
|
if (scrollOnFocus && isFocusedComputed && isFocusVisibleComputed && elementRef) {
|
|
174
181
|
requestAnimationFrame(() => {
|
|
175
182
|
elementRef?.scrollIntoView({ block: 'nearest' });
|
|
@@ -49,6 +49,36 @@ export type ListBoxContext = {
|
|
|
49
49
|
setFocusedId: (id: string | number | null) => void;
|
|
50
50
|
/** Sets whether the focused item should render keyboard focus-visible. */
|
|
51
51
|
setFocusVisible: (visible: boolean) => void;
|
|
52
|
+
/**
|
|
53
|
+
* Brings a row into view by its index in the full list, mounting it when the listbox is
|
|
54
|
+
* virtualized and the window hadn't reached it. Resolves once the row exists in the DOM.
|
|
55
|
+
*
|
|
56
|
+
* A no-op for an unvirtualized listbox, where every row is mounted already. Registered by
|
|
57
|
+
* the ListBox itself — the context is created before that function exists, so it starts
|
|
58
|
+
* out as the no-op and is replaced on mount.
|
|
59
|
+
*/
|
|
60
|
+
scrollIndexIntoView: (index: number, options?: {
|
|
61
|
+
align?: 'nearest' | 'center';
|
|
62
|
+
}) => Promise<boolean>;
|
|
63
|
+
/**
|
|
64
|
+
* Whether the ListBox renders only a window of its rows.
|
|
65
|
+
*
|
|
66
|
+
* An item asks before scrolling itself into view: in a virtualized list the scroll
|
|
67
|
+
* belongs to the list, which is the only one that knows where a row *would* be — and
|
|
68
|
+
* an item nudging itself to the nearest edge undoes the placement the list just made.
|
|
69
|
+
*/
|
|
70
|
+
isVirtualized: () => boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Registers how to read that. A *getter*, registered while the ListBox initializes,
|
|
73
|
+
* rather than a value pushed from an effect: a child's effects run before its parent's,
|
|
74
|
+
* so an item would ask the question before the answer had been written and scroll itself
|
|
75
|
+
* anyway.
|
|
76
|
+
*/
|
|
77
|
+
setVirtualized: (isVirtualized: () => boolean) => void;
|
|
78
|
+
/** Registers the ListBox's own implementation of {@link scrollIndexIntoView}. */
|
|
79
|
+
setScrollIndexIntoView: (fn: (index: number, options?: {
|
|
80
|
+
align?: 'nearest' | 'center';
|
|
81
|
+
}) => Promise<boolean>) => void;
|
|
52
82
|
/** Subscribes to selection changes for a specific item. Returns unsubscribe function. */
|
|
53
83
|
subscribeToItem: (id: string | number, callback: (selected: boolean) => void) => () => void;
|
|
54
84
|
/** Subscribes to focus changes for a specific item. Returns unsubscribe function. */
|
|
@@ -190,6 +190,8 @@ export function createListBoxContext(options = {}) {
|
|
|
190
190
|
function setSelection(newSelection) {
|
|
191
191
|
applySelection(newSelection);
|
|
192
192
|
}
|
|
193
|
+
let readVirtualized = () => false;
|
|
194
|
+
let scrollIndexIntoViewImpl = async () => false;
|
|
193
195
|
const keyboardNav = createKeyboardNavigation({
|
|
194
196
|
orientation: 'vertical',
|
|
195
197
|
// Getter-based so reactive prop changes are honoured after creation.
|
|
@@ -233,6 +235,14 @@ export function createListBoxContext(options = {}) {
|
|
|
233
235
|
setSelection,
|
|
234
236
|
setFocusedId,
|
|
235
237
|
setFocusVisible,
|
|
238
|
+
isVirtualized: () => readVirtualized(),
|
|
239
|
+
setVirtualized: (next) => {
|
|
240
|
+
readVirtualized = next;
|
|
241
|
+
},
|
|
242
|
+
scrollIndexIntoView: (index, options) => scrollIndexIntoViewImpl(index, options),
|
|
243
|
+
setScrollIndexIntoView: (fn) => {
|
|
244
|
+
scrollIndexIntoViewImpl = fn;
|
|
245
|
+
},
|
|
236
246
|
subscribeToItem,
|
|
237
247
|
subscribeToFocus,
|
|
238
248
|
subscribeToFocusVisible
|