@human-kit/ui 1.0.0-beta.3 → 1.0.0-beta.5
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 +15 -6
- package/dist/FOCUS_STATE_CONTRACT.md +2 -0
- package/dist/autocomplete/list/autocomplete-list.svelte.d.ts +3 -1
- package/dist/button/root/button-root.svelte +19 -3
- package/dist/button/root/button-root.svelte.d.ts +10 -0
- package/dist/combobox/list/combobox-listbox.svelte.d.ts +3 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/internal/environment.d.ts +11 -0
- package/dist/internal/environment.js +14 -0
- package/dist/internal/localized-strings.d.ts +80 -0
- package/dist/internal/localized-strings.js +80 -0
- package/dist/listbox/README.md +27 -1
- package/dist/listbox/item/listbox-item.svelte +11 -2
- package/dist/listbox/root/context.d.ts +25 -0
- package/dist/listbox/root/context.js +108 -1
- package/dist/listbox/root/listbox.svelte +85 -7
- package/dist/listbox/root/listbox.svelte.d.ts +13 -1
- package/dist/menu/README.md +46 -0
- package/dist/menu/content/menu-content.svelte +16 -5
- package/dist/menu/content/menu-content.svelte.d.ts +2 -1
- package/dist/menu/context-trigger/menu-context-trigger.svelte +195 -0
- package/dist/menu/context-trigger/menu-context-trigger.svelte.d.ts +36 -0
- package/dist/menu/index.d.ts +4 -1
- package/dist/menu/index.js +1 -0
- package/dist/menu/index.parts.d.ts +1 -0
- package/dist/menu/index.parts.js +1 -0
- package/dist/menu/root/context.d.ts +18 -0
- package/dist/menu/root/menu-state.svelte.js +19 -0
- package/dist/popover/content/popover-content.svelte +2 -1
- package/dist/primitives/floating.d.ts +33 -5
- package/dist/primitives/floating.js +25 -0
- package/dist/primitives/index.d.ts +1 -0
- package/dist/primitives/index.js +1 -0
- package/dist/primitives/keyboard-navigation.d.ts +23 -5
- package/dist/primitives/keyboard-navigation.js +22 -15
- package/dist/primitives/long-press.d.ts +59 -0
- package/dist/primitives/long-press.js +142 -0
- package/dist/primitives/scroll-lock.d.ts +24 -0
- package/dist/primitives/scroll-lock.js +40 -0
- package/dist/toggle-group/README.md +10 -0
- package/dist/toggle-group/root/context.svelte.d.ts +1 -1
- package/dist/toggle-group/root/context.svelte.js +20 -11
- package/dist/toggle-group/root/toggle-group-root.svelte +20 -15
- package/dist/toggle-group/root/toggle-group-teardown-order-child.svelte +13 -0
- package/dist/toggle-group/root/toggle-group-teardown-order-child.svelte.d.ts +7 -0
- package/dist/toggle-group/types.d.ts +7 -8
- package/dist/transfer-list/README.md +121 -0
- package/dist/transfer-list/index.d.ts +33 -0
- package/dist/transfer-list/index.js +18 -0
- package/dist/transfer-list/index.parts.d.ts +9 -0
- package/dist/transfer-list/index.parts.js +10 -0
- package/dist/transfer-list/item/transfer-list-item.svelte +74 -0
- package/dist/transfer-list/item/transfer-list-item.svelte.d.ts +35 -0
- package/dist/transfer-list/list/transfer-list-list.svelte +162 -0
- package/dist/transfer-list/list/transfer-list-list.svelte.d.ts +56 -0
- package/dist/transfer-list/list/transfer-list-source.svelte +13 -0
- package/dist/transfer-list/list/transfer-list-source.svelte.d.ts +36 -0
- package/dist/transfer-list/list/transfer-list-target.svelte +14 -0
- package/dist/transfer-list/list/transfer-list-target.svelte.d.ts +36 -0
- package/dist/transfer-list/move/transfer-list-move-all.svelte +14 -0
- package/dist/transfer-list/move/transfer-list-move-all.svelte.d.ts +10 -0
- package/dist/transfer-list/move/transfer-list-move-button.svelte +103 -0
- package/dist/transfer-list/move/transfer-list-move-button.svelte.d.ts +25 -0
- package/dist/transfer-list/move/transfer-list-move-down.svelte +14 -0
- package/dist/transfer-list/move/transfer-list-move-down.svelte.d.ts +10 -0
- package/dist/transfer-list/move/transfer-list-move-selected.svelte +14 -0
- package/dist/transfer-list/move/transfer-list-move-selected.svelte.d.ts +10 -0
- package/dist/transfer-list/move/transfer-list-move-up.svelte +14 -0
- package/dist/transfer-list/move/transfer-list-move-up.svelte.d.ts +10 -0
- package/dist/transfer-list/move/transfer-list-reorder-button.svelte +83 -0
- package/dist/transfer-list/move/transfer-list-reorder-button.svelte.d.ts +21 -0
- package/dist/transfer-list/root/context.d.ts +70 -0
- package/dist/transfer-list/root/context.js +24 -0
- package/dist/transfer-list/root/transfer-list-root.svelte +342 -0
- package/dist/transfer-list/root/transfer-list-root.svelte.d.ts +65 -0
- package/dist/transfer-list/root/types.d.ts +22 -0
- package/dist/transfer-list/root/types.js +4 -0
- package/dist/transfer-list/status/transfer-list-status.svelte +70 -0
- package/dist/transfer-list/status/transfer-list-status.svelte.d.ts +15 -0
- package/package.json +6 -1
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
<script lang="ts" generics="T extends object = object">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import { tick, untrack } from 'svelte';
|
|
4
|
+
import { isApplePlatform } from '../../internal/environment';
|
|
5
|
+
import { ListBoxRoot as ListBox, type ListBoxContext } from '../../listbox';
|
|
6
|
+
import { setTransferListSide, useTransferListContext } from '../root/context';
|
|
7
|
+
import { oppositeSide, type TransferListSide } from '../root/types';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The list behind TransferList.Source and TransferList.Target.
|
|
11
|
+
*
|
|
12
|
+
* Both sides behave identically — the only difference is which slice of the Root's
|
|
13
|
+
* state they read — so the behaviour lives here once and the two public parts are
|
|
14
|
+
* thin wrappers over it.
|
|
15
|
+
*/
|
|
16
|
+
type TransferListListProps = {
|
|
17
|
+
/** Which side this list shows. Set by Source and Target, never by a consumer. */
|
|
18
|
+
side: TransferListSide;
|
|
19
|
+
/**
|
|
20
|
+
* Accessible name of the list. Also the name the move buttons and the live region use,
|
|
21
|
+
* which is why it is a string rather than only an `aria-label` pass-through: "Move
|
|
22
|
+
* selected to Selected" reads far better than "move right", and survives RTL.
|
|
23
|
+
*/
|
|
24
|
+
label: string;
|
|
25
|
+
/** Id of a visible heading, when the list already has one on screen. */
|
|
26
|
+
'aria-labelledby'?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Shows only the items this returns `true` for. The input that drives it is the
|
|
29
|
+
* consumer's — this only decides what the list renders.
|
|
30
|
+
*
|
|
31
|
+
* "Move all" then means the rows on screen rather than the whole side, which is what
|
|
32
|
+
* the button appears to promise while a filter is applied.
|
|
33
|
+
*/
|
|
34
|
+
filter?: (item: T, index: number) => boolean;
|
|
35
|
+
/** Rendered for each item on this side. */
|
|
36
|
+
children?: Snippet<[T]>;
|
|
37
|
+
/** Shown when the side has no items. Nothing is rendered when omitted. */
|
|
38
|
+
emptyPlaceholder?: string | Snippet;
|
|
39
|
+
/** Renders only the rows near the viewport. See `ListBox`'s own `virtualizer`. */
|
|
40
|
+
virtualizer?: { rowHeight?: number; overscan?: number };
|
|
41
|
+
/** CSS class for the list element. */
|
|
42
|
+
class?: string;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
let {
|
|
46
|
+
side,
|
|
47
|
+
label,
|
|
48
|
+
'aria-labelledby': ariaLabelledBy,
|
|
49
|
+
filter,
|
|
50
|
+
children,
|
|
51
|
+
emptyPlaceholder,
|
|
52
|
+
virtualizer,
|
|
53
|
+
class: className = ''
|
|
54
|
+
}: TransferListListProps = $props();
|
|
55
|
+
|
|
56
|
+
const ctx = useTransferListContext<T>('TransferList.Source / TransferList.Target');
|
|
57
|
+
|
|
58
|
+
// A list is one side for its whole life — `Source` and `Target` each hard-code it — so
|
|
59
|
+
// the initial value is the only one there will ever be.
|
|
60
|
+
setTransferListSide(untrack(() => side));
|
|
61
|
+
|
|
62
|
+
let listContext = $state<ListBoxContext | undefined>();
|
|
63
|
+
let listElement = $state<HTMLElement | undefined>();
|
|
64
|
+
|
|
65
|
+
const allItems = $derived(ctx.getItems(side));
|
|
66
|
+
const items = $derived(filter ? allItems.filter(filter) : allItems);
|
|
67
|
+
const selection = $derived(ctx.getSelection(side));
|
|
68
|
+
|
|
69
|
+
// Reported so "move all" and the shortcut act on the rows the user can see. Registered at
|
|
70
|
+
// init too, because effects do not run on the server and the buttons would otherwise
|
|
71
|
+
// render disabled in the markup.
|
|
72
|
+
untrack(() => ctx.setVisibleKeys(side, items.map(ctx.getKey)));
|
|
73
|
+
|
|
74
|
+
$effect(() => {
|
|
75
|
+
ctx.setVisibleKeys(
|
|
76
|
+
side,
|
|
77
|
+
items.map((item) => ctx.getKey(item))
|
|
78
|
+
);
|
|
79
|
+
return () => ctx.setVisibleKeys(side, null);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// Both keys work everywhere — only the name changes, so an Apple user is not told to press
|
|
83
|
+
// a modifier their keyboard uses for something else.
|
|
84
|
+
const shortcutName = isApplePlatform ? 'Meta+Enter' : 'Control+Enter';
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Sends this list's selection to the other one.
|
|
88
|
+
*
|
|
89
|
+
* Captured on the list rather than handed to `ListBox` as an `onkeydown`: the listbox
|
|
90
|
+
* treats Enter as "toggle this option" in its own bubble-phase handler, so the shortcut
|
|
91
|
+
* has to claim the event before it gets there.
|
|
92
|
+
*/
|
|
93
|
+
function handleShortcut(event: KeyboardEvent) {
|
|
94
|
+
if (!ctx.moveShortcut) return;
|
|
95
|
+
if (event.key !== 'Enter' || !(event.ctrlKey || event.metaKey)) return;
|
|
96
|
+
|
|
97
|
+
const keys = ctx.getMovableSelection(side);
|
|
98
|
+
if (keys.length === 0) return;
|
|
99
|
+
|
|
100
|
+
event.preventDefault();
|
|
101
|
+
event.stopPropagation();
|
|
102
|
+
|
|
103
|
+
const destination = oppositeSide(side);
|
|
104
|
+
const index = items.findIndex((item) => ctx.getKey(item) === keys[0]);
|
|
105
|
+
|
|
106
|
+
ctx.move(keys, destination);
|
|
107
|
+
|
|
108
|
+
// Same rule as a double click: the rows the user was on are gone, so focus goes to
|
|
109
|
+
// whatever took their place, or follows them when this side empties.
|
|
110
|
+
void tick().then(() => {
|
|
111
|
+
if (!ctx.focusItemAt(side, index)) ctx.focusList(destination);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
$effect(() => {
|
|
116
|
+
const element = listElement;
|
|
117
|
+
if (!element) return;
|
|
118
|
+
element.addEventListener('keydown', handleShortcut, true);
|
|
119
|
+
return () => element.removeEventListener('keydown', handleShortcut, true);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// Registered at init as well as reactively: effects do not run on the server, and the
|
|
123
|
+
// move buttons build their accessible name from this. Without the init call the markup
|
|
124
|
+
// would ship "Move selected to " and only gain the list's name after hydration.
|
|
125
|
+
untrack(() => ctx.setLabel(side, label));
|
|
126
|
+
|
|
127
|
+
$effect(() => {
|
|
128
|
+
ctx.setLabel(side, label);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
$effect(() => {
|
|
132
|
+
ctx.setListContext(side, listContext ?? null);
|
|
133
|
+
return () => ctx.setListContext(side, null);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
$effect(() => {
|
|
137
|
+
ctx.setListElement(side, listElement ?? null);
|
|
138
|
+
return () => ctx.setListElement(side, null);
|
|
139
|
+
});
|
|
140
|
+
</script>
|
|
141
|
+
|
|
142
|
+
{#snippet nothing()}{/snippet}
|
|
143
|
+
|
|
144
|
+
<ListBox
|
|
145
|
+
bind:context={listContext}
|
|
146
|
+
bind:element={listElement}
|
|
147
|
+
{items}
|
|
148
|
+
{virtualizer}
|
|
149
|
+
{children}
|
|
150
|
+
getItemKey={ctx.getKey}
|
|
151
|
+
selectionMode="multiple"
|
|
152
|
+
loop={false}
|
|
153
|
+
value={selection}
|
|
154
|
+
onChange={(next) => ctx.setSelection(side, Array.from(next))}
|
|
155
|
+
aria-label={ariaLabelledBy ? undefined : label}
|
|
156
|
+
aria-labelledby={ariaLabelledBy}
|
|
157
|
+
aria-keyshortcuts={ctx.moveShortcut ? shortcutName : undefined}
|
|
158
|
+
emptyPlaceholder={emptyPlaceholder ?? nothing}
|
|
159
|
+
class={className}
|
|
160
|
+
data-side={side}
|
|
161
|
+
data-empty={items.length === 0 ? 'true' : undefined}
|
|
162
|
+
/>
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import { type TransferListSide } from '../root/types';
|
|
3
|
+
declare function $$render<T extends object = object>(): {
|
|
4
|
+
props: {
|
|
5
|
+
/** Which side this list shows. Set by Source and Target, never by a consumer. */
|
|
6
|
+
side: TransferListSide;
|
|
7
|
+
/**
|
|
8
|
+
* Accessible name of the list. Also the name the move buttons and the live region use,
|
|
9
|
+
* which is why it is a string rather than only an `aria-label` pass-through: "Move
|
|
10
|
+
* selected to Selected" reads far better than "move right", and survives RTL.
|
|
11
|
+
*/
|
|
12
|
+
label: string;
|
|
13
|
+
/** Id of a visible heading, when the list already has one on screen. */
|
|
14
|
+
'aria-labelledby'?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Shows only the items this returns `true` for. The input that drives it is the
|
|
17
|
+
* consumer's — this only decides what the list renders.
|
|
18
|
+
*
|
|
19
|
+
* "Move all" then means the rows on screen rather than the whole side, which is what
|
|
20
|
+
* the button appears to promise while a filter is applied.
|
|
21
|
+
*/
|
|
22
|
+
filter?: (item: T, index: number) => boolean;
|
|
23
|
+
/** Rendered for each item on this side. */
|
|
24
|
+
children?: Snippet<[T]>;
|
|
25
|
+
/** Shown when the side has no items. Nothing is rendered when omitted. */
|
|
26
|
+
emptyPlaceholder?: string | Snippet;
|
|
27
|
+
/** Renders only the rows near the viewport. See `ListBox`'s own `virtualizer`. */
|
|
28
|
+
virtualizer?: {
|
|
29
|
+
rowHeight?: number;
|
|
30
|
+
overscan?: number;
|
|
31
|
+
};
|
|
32
|
+
/** CSS class for the list element. */
|
|
33
|
+
class?: string;
|
|
34
|
+
};
|
|
35
|
+
exports: {};
|
|
36
|
+
bindings: "";
|
|
37
|
+
slots: {};
|
|
38
|
+
events: {};
|
|
39
|
+
};
|
|
40
|
+
declare class __sveltets_Render<T extends object = object> {
|
|
41
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
42
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
43
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
44
|
+
bindings(): "";
|
|
45
|
+
exports(): {};
|
|
46
|
+
}
|
|
47
|
+
interface $$IsomorphicComponent {
|
|
48
|
+
new <T extends object = object>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
49
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
50
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
51
|
+
<T extends object = object>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
52
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
53
|
+
}
|
|
54
|
+
declare const TransferListList: $$IsomorphicComponent;
|
|
55
|
+
type TransferListList<T extends object = object> = InstanceType<typeof TransferListList<T>>;
|
|
56
|
+
export default TransferListList;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<script lang="ts" generics="T extends object = object">
|
|
2
|
+
import type { ComponentProps } from 'svelte';
|
|
3
|
+
import TransferListList from './transfer-list-list.svelte';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* TransferList.Source - The left-hand list: every item that is not in `value`.
|
|
7
|
+
*/
|
|
8
|
+
type TransferListSourceProps = Omit<ComponentProps<typeof TransferListList<T>>, 'side'>;
|
|
9
|
+
|
|
10
|
+
let props: TransferListSourceProps = $props();
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<TransferListList side="source" {...props} />
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
declare function $$render<T extends object = object>(): {
|
|
2
|
+
props: Omit<{
|
|
3
|
+
side: import("..").TransferListSide;
|
|
4
|
+
label: string;
|
|
5
|
+
'aria-labelledby'?: string;
|
|
6
|
+
filter?: ((item: T, index: number) => boolean) | undefined;
|
|
7
|
+
children?: import("svelte").Snippet<[T]> | undefined;
|
|
8
|
+
emptyPlaceholder?: string | import("svelte").Snippet;
|
|
9
|
+
virtualizer?: {
|
|
10
|
+
rowHeight?: number;
|
|
11
|
+
overscan?: number;
|
|
12
|
+
} | undefined;
|
|
13
|
+
class?: string;
|
|
14
|
+
}, "side">;
|
|
15
|
+
exports: {};
|
|
16
|
+
bindings: "";
|
|
17
|
+
slots: {};
|
|
18
|
+
events: {};
|
|
19
|
+
};
|
|
20
|
+
declare class __sveltets_Render<T extends object = object> {
|
|
21
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
22
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
23
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
24
|
+
bindings(): "";
|
|
25
|
+
exports(): {};
|
|
26
|
+
}
|
|
27
|
+
interface $$IsomorphicComponent {
|
|
28
|
+
new <T extends object = object>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
29
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
30
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
31
|
+
<T extends object = object>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
32
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
33
|
+
}
|
|
34
|
+
declare const TransferListSource: $$IsomorphicComponent;
|
|
35
|
+
type TransferListSource<T extends object = object> = InstanceType<typeof TransferListSource<T>>;
|
|
36
|
+
export default TransferListSource;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<script lang="ts" generics="T extends object = object">
|
|
2
|
+
import type { ComponentProps } from 'svelte';
|
|
3
|
+
import TransferListList from './transfer-list-list.svelte';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* TransferList.Target - The right-hand list, rendered in `value` order so items keep
|
|
7
|
+
* the sequence they were moved in.
|
|
8
|
+
*/
|
|
9
|
+
type TransferListTargetProps = Omit<ComponentProps<typeof TransferListList<T>>, 'side'>;
|
|
10
|
+
|
|
11
|
+
let props: TransferListTargetProps = $props();
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<TransferListList side="target" {...props} />
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
declare function $$render<T extends object = object>(): {
|
|
2
|
+
props: Omit<{
|
|
3
|
+
side: import("..").TransferListSide;
|
|
4
|
+
label: string;
|
|
5
|
+
'aria-labelledby'?: string;
|
|
6
|
+
filter?: ((item: T, index: number) => boolean) | undefined;
|
|
7
|
+
children?: import("svelte").Snippet<[T]> | undefined;
|
|
8
|
+
emptyPlaceholder?: string | import("svelte").Snippet;
|
|
9
|
+
virtualizer?: {
|
|
10
|
+
rowHeight?: number;
|
|
11
|
+
overscan?: number;
|
|
12
|
+
} | undefined;
|
|
13
|
+
class?: string;
|
|
14
|
+
}, "side">;
|
|
15
|
+
exports: {};
|
|
16
|
+
bindings: "";
|
|
17
|
+
slots: {};
|
|
18
|
+
events: {};
|
|
19
|
+
};
|
|
20
|
+
declare class __sveltets_Render<T extends object = object> {
|
|
21
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
22
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
23
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
24
|
+
bindings(): "";
|
|
25
|
+
exports(): {};
|
|
26
|
+
}
|
|
27
|
+
interface $$IsomorphicComponent {
|
|
28
|
+
new <T extends object = object>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
29
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
30
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
31
|
+
<T extends object = object>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
32
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
33
|
+
}
|
|
34
|
+
declare const TransferListTarget: $$IsomorphicComponent;
|
|
35
|
+
type TransferListTarget<T extends object = object> = InstanceType<typeof TransferListTarget<T>>;
|
|
36
|
+
export default TransferListTarget;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { ComponentProps } from 'svelte';
|
|
3
|
+
import MoveButton from './transfer-list-move-button.svelte';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* TransferList.MoveAll - Moves every movable item of the opposite list to `to`,
|
|
7
|
+
* selected or not. Items in `disabledKeys` stay where they are.
|
|
8
|
+
*/
|
|
9
|
+
type TransferListMoveAllProps = Omit<ComponentProps<typeof MoveButton>, 'scope'>;
|
|
10
|
+
|
|
11
|
+
let props: TransferListMoveAllProps = $props();
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<MoveButton scope="all" {...props} />
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ComponentProps } from 'svelte';
|
|
2
|
+
import MoveButton from './transfer-list-move-button.svelte';
|
|
3
|
+
/**
|
|
4
|
+
* TransferList.MoveAll - Moves every movable item of the opposite list to `to`,
|
|
5
|
+
* selected or not. Items in `disabledKeys` stay where they are.
|
|
6
|
+
*/
|
|
7
|
+
type TransferListMoveAllProps = Omit<ComponentProps<typeof MoveButton>, 'scope'>;
|
|
8
|
+
declare const TransferListMoveAll: import("svelte").Component<TransferListMoveAllProps, {}, "">;
|
|
9
|
+
type TransferListMoveAll = ReturnType<typeof TransferListMoveAll>;
|
|
10
|
+
export default TransferListMoveAll;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { HTMLButtonAttributes } from 'svelte/elements';
|
|
4
|
+
import { readable } from 'svelte/store';
|
|
5
|
+
import { ButtonRoot } from '../../button';
|
|
6
|
+
import { resolveLocalizedString } from '../../internal/localized-strings';
|
|
7
|
+
import { useLocaleContextOptional } from '../../locale-provider/context';
|
|
8
|
+
import { useTransferListContext } from '../root/context';
|
|
9
|
+
import { oppositeSide, type TransferListKey, type TransferListSide } from '../root/types';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The button behind TransferList.MoveSelected and TransferList.MoveAll.
|
|
13
|
+
*
|
|
14
|
+
* The two differ only in which keys they hand to `move` and in when they run out of
|
|
15
|
+
* work, so the shared parts — the accessible name, the disabled state and the focus
|
|
16
|
+
* hand-off — live here once.
|
|
17
|
+
*/
|
|
18
|
+
type MoveButtonProps = Omit<
|
|
19
|
+
HTMLButtonAttributes,
|
|
20
|
+
'children' | 'class' | 'disabled' | 'aria-disabled' | 'type'
|
|
21
|
+
> & {
|
|
22
|
+
/** Which list the items go to. */
|
|
23
|
+
to: TransferListSide;
|
|
24
|
+
/** Whether it moves the selection or everything movable. */
|
|
25
|
+
scope: 'selected' | 'all';
|
|
26
|
+
/** Button content — an arrow, a label, whatever the layout calls for. */
|
|
27
|
+
children?: Snippet;
|
|
28
|
+
/** CSS class for the button. */
|
|
29
|
+
class?: string;
|
|
30
|
+
/** Bindable reference to the rendered button element. */
|
|
31
|
+
element?: HTMLButtonElement | null;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
let {
|
|
35
|
+
to,
|
|
36
|
+
scope,
|
|
37
|
+
children,
|
|
38
|
+
'aria-label': ariaLabelExternal,
|
|
39
|
+
onclick: onClickExternal,
|
|
40
|
+
element = $bindable<HTMLButtonElement | null>(null),
|
|
41
|
+
...restProps
|
|
42
|
+
}: MoveButtonProps = $props();
|
|
43
|
+
|
|
44
|
+
const ctx = useTransferListContext('TransferList.MoveSelected / TransferList.MoveAll');
|
|
45
|
+
|
|
46
|
+
const localeContext = useLocaleContextOptional();
|
|
47
|
+
const emptyLocaleStore = readable<string | undefined>(undefined);
|
|
48
|
+
const localeStore = localeContext?.locale ?? emptyLocaleStore;
|
|
49
|
+
|
|
50
|
+
const from = $derived(oppositeSide(to));
|
|
51
|
+
const keys = $derived<TransferListKey[]>(
|
|
52
|
+
scope === 'selected' ? ctx.getMovableSelection(from) : ctx.getMovableKeys(from)
|
|
53
|
+
);
|
|
54
|
+
const disabled = $derived(keys.length === 0);
|
|
55
|
+
|
|
56
|
+
// Named after the destination list rather than after a direction: an arrow glyph says
|
|
57
|
+
// nothing on its own, and "move right" is wrong the moment the layout is mirrored.
|
|
58
|
+
//
|
|
59
|
+
// Undefined until that list has registered its name, which on the server means until it
|
|
60
|
+
// has rendered — a button that precedes its destination in the markup would otherwise
|
|
61
|
+
// ship "Move selected to " and only become meaningful after hydration. With no
|
|
62
|
+
// `aria-label` the button is named by its own content instead, which is at least true.
|
|
63
|
+
const destinationLabel = $derived(ctx.getLabel(to));
|
|
64
|
+
const defaultLabel = $derived(
|
|
65
|
+
destinationLabel
|
|
66
|
+
? resolveLocalizedString(
|
|
67
|
+
$localeStore,
|
|
68
|
+
scope === 'selected' ? 'transferList.moveSelectedTo' : 'transferList.moveAllTo',
|
|
69
|
+
{ label: destinationLabel }
|
|
70
|
+
)
|
|
71
|
+
: undefined
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
let buttonRef = $state<HTMLButtonElement | null>(null);
|
|
75
|
+
|
|
76
|
+
function handleClick(event: MouseEvent & { currentTarget: EventTarget & HTMLButtonElement }) {
|
|
77
|
+
// Focus stays on the button, as it does for any button press. Nothing has to be handed
|
|
78
|
+
// off, because `aria-disabled` leaves it focusable.
|
|
79
|
+
if (!disabled) ctx.move(keys, to);
|
|
80
|
+
onClickExternal?.(event);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
$effect(() => {
|
|
84
|
+
element = buttonRef;
|
|
85
|
+
});
|
|
86
|
+
</script>
|
|
87
|
+
|
|
88
|
+
<!-- `aria-disabled` rather than the native attribute: a move button spends most of its life
|
|
89
|
+
unavailable, and a natively disabled one leaves the tab order entirely. Half the actions
|
|
90
|
+
would be undiscoverable to someone exploring with a keyboard, and the tab order would
|
|
91
|
+
shift under them as they work. -->
|
|
92
|
+
<ButtonRoot
|
|
93
|
+
bind:element={buttonRef}
|
|
94
|
+
{disabled}
|
|
95
|
+
focusableWhenDisabled
|
|
96
|
+
aria-label={ariaLabelExternal ?? defaultLabel}
|
|
97
|
+
data-transfer-move={scope}
|
|
98
|
+
data-direction={to === 'target' ? 'to-target' : 'to-source'}
|
|
99
|
+
onclick={handleClick}
|
|
100
|
+
{...restProps}
|
|
101
|
+
>
|
|
102
|
+
{@render children?.()}
|
|
103
|
+
</ButtonRoot>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLButtonAttributes } from 'svelte/elements';
|
|
3
|
+
import { type TransferListSide } from '../root/types';
|
|
4
|
+
/**
|
|
5
|
+
* The button behind TransferList.MoveSelected and TransferList.MoveAll.
|
|
6
|
+
*
|
|
7
|
+
* The two differ only in which keys they hand to `move` and in when they run out of
|
|
8
|
+
* work, so the shared parts — the accessible name, the disabled state and the focus
|
|
9
|
+
* hand-off — live here once.
|
|
10
|
+
*/
|
|
11
|
+
type MoveButtonProps = Omit<HTMLButtonAttributes, 'children' | 'class' | 'disabled' | 'aria-disabled' | 'type'> & {
|
|
12
|
+
/** Which list the items go to. */
|
|
13
|
+
to: TransferListSide;
|
|
14
|
+
/** Whether it moves the selection or everything movable. */
|
|
15
|
+
scope: 'selected' | 'all';
|
|
16
|
+
/** Button content — an arrow, a label, whatever the layout calls for. */
|
|
17
|
+
children?: Snippet;
|
|
18
|
+
/** CSS class for the button. */
|
|
19
|
+
class?: string;
|
|
20
|
+
/** Bindable reference to the rendered button element. */
|
|
21
|
+
element?: HTMLButtonElement | null;
|
|
22
|
+
};
|
|
23
|
+
declare const TransferListMoveButton: import("svelte").Component<MoveButtonProps, {}, "element">;
|
|
24
|
+
type TransferListMoveButton = ReturnType<typeof TransferListMoveButton>;
|
|
25
|
+
export default TransferListMoveButton;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { ComponentProps } from 'svelte';
|
|
3
|
+
import ReorderButton from './transfer-list-reorder-button.svelte';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* TransferList.MoveDown - Shifts the right-hand selection one position later in `value`.
|
|
7
|
+
* Disabled while nothing is selected there, or while the selection already ends the list.
|
|
8
|
+
*/
|
|
9
|
+
type TransferListMoveDownProps = Omit<ComponentProps<typeof ReorderButton>, 'direction'>;
|
|
10
|
+
|
|
11
|
+
let props: TransferListMoveDownProps = $props();
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<ReorderButton direction="down" {...props} />
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ComponentProps } from 'svelte';
|
|
2
|
+
import ReorderButton from './transfer-list-reorder-button.svelte';
|
|
3
|
+
/**
|
|
4
|
+
* TransferList.MoveDown - Shifts the right-hand selection one position later in `value`.
|
|
5
|
+
* Disabled while nothing is selected there, or while the selection already ends the list.
|
|
6
|
+
*/
|
|
7
|
+
type TransferListMoveDownProps = Omit<ComponentProps<typeof ReorderButton>, 'direction'>;
|
|
8
|
+
declare const TransferListMoveDown: import("svelte").Component<TransferListMoveDownProps, {}, "">;
|
|
9
|
+
type TransferListMoveDown = ReturnType<typeof TransferListMoveDown>;
|
|
10
|
+
export default TransferListMoveDown;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { ComponentProps } from 'svelte';
|
|
3
|
+
import MoveButton from './transfer-list-move-button.svelte';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* TransferList.MoveSelected - Moves the selected items of the opposite list to `to`.
|
|
7
|
+
* Disabled while that list has nothing movable selected.
|
|
8
|
+
*/
|
|
9
|
+
type TransferListMoveSelectedProps = Omit<ComponentProps<typeof MoveButton>, 'scope'>;
|
|
10
|
+
|
|
11
|
+
let props: TransferListMoveSelectedProps = $props();
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<MoveButton scope="selected" {...props} />
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ComponentProps } from 'svelte';
|
|
2
|
+
import MoveButton from './transfer-list-move-button.svelte';
|
|
3
|
+
/**
|
|
4
|
+
* TransferList.MoveSelected - Moves the selected items of the opposite list to `to`.
|
|
5
|
+
* Disabled while that list has nothing movable selected.
|
|
6
|
+
*/
|
|
7
|
+
type TransferListMoveSelectedProps = Omit<ComponentProps<typeof MoveButton>, 'scope'>;
|
|
8
|
+
declare const TransferListMoveSelected: import("svelte").Component<TransferListMoveSelectedProps, {}, "">;
|
|
9
|
+
type TransferListMoveSelected = ReturnType<typeof TransferListMoveSelected>;
|
|
10
|
+
export default TransferListMoveSelected;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { ComponentProps } from 'svelte';
|
|
3
|
+
import ReorderButton from './transfer-list-reorder-button.svelte';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* TransferList.MoveUp - Shifts the right-hand selection one position earlier in `value`.
|
|
7
|
+
* Disabled while nothing is selected there, or while the selection already starts the list.
|
|
8
|
+
*/
|
|
9
|
+
type TransferListMoveUpProps = Omit<ComponentProps<typeof ReorderButton>, 'direction'>;
|
|
10
|
+
|
|
11
|
+
let props: TransferListMoveUpProps = $props();
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<ReorderButton direction="up" {...props} />
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ComponentProps } from 'svelte';
|
|
2
|
+
import ReorderButton from './transfer-list-reorder-button.svelte';
|
|
3
|
+
/**
|
|
4
|
+
* TransferList.MoveUp - Shifts the right-hand selection one position earlier in `value`.
|
|
5
|
+
* Disabled while nothing is selected there, or while the selection already starts the list.
|
|
6
|
+
*/
|
|
7
|
+
type TransferListMoveUpProps = Omit<ComponentProps<typeof ReorderButton>, 'direction'>;
|
|
8
|
+
declare const TransferListMoveUp: import("svelte").Component<TransferListMoveUpProps, {}, "">;
|
|
9
|
+
type TransferListMoveUp = ReturnType<typeof TransferListMoveUp>;
|
|
10
|
+
export default TransferListMoveUp;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { HTMLButtonAttributes } from 'svelte/elements';
|
|
4
|
+
import { readable } from 'svelte/store';
|
|
5
|
+
import { ButtonRoot } from '../../button';
|
|
6
|
+
import { resolveLocalizedString } from '../../internal/localized-strings';
|
|
7
|
+
import { useLocaleContextOptional } from '../../locale-provider/context';
|
|
8
|
+
import { useTransferListContext } from '../root/context';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The button behind TransferList.MoveUp and TransferList.MoveDown.
|
|
12
|
+
*
|
|
13
|
+
* Reordering only makes sense on the right: the left-hand order is the order `items`
|
|
14
|
+
* were given in, while the right-hand one is state the user is building.
|
|
15
|
+
*/
|
|
16
|
+
type ReorderButtonProps = Omit<
|
|
17
|
+
HTMLButtonAttributes,
|
|
18
|
+
'children' | 'class' | 'disabled' | 'aria-disabled' | 'type'
|
|
19
|
+
> & {
|
|
20
|
+
/** Which way the selection moves. */
|
|
21
|
+
direction: 'up' | 'down';
|
|
22
|
+
/** Button content — an arrow, a label, whatever the layout calls for. */
|
|
23
|
+
children?: Snippet;
|
|
24
|
+
/** CSS class for the button. */
|
|
25
|
+
class?: string;
|
|
26
|
+
/** Bindable reference to the rendered button element. */
|
|
27
|
+
element?: HTMLButtonElement | null;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
let {
|
|
31
|
+
direction,
|
|
32
|
+
children,
|
|
33
|
+
'aria-label': ariaLabelExternal,
|
|
34
|
+
onclick: onClickExternal,
|
|
35
|
+
element = $bindable<HTMLButtonElement | null>(null),
|
|
36
|
+
...restProps
|
|
37
|
+
}: ReorderButtonProps = $props();
|
|
38
|
+
|
|
39
|
+
const ctx = useTransferListContext('TransferList.MoveUp / TransferList.MoveDown');
|
|
40
|
+
|
|
41
|
+
const localeContext = useLocaleContextOptional();
|
|
42
|
+
const emptyLocaleStore = readable<string | undefined>(undefined);
|
|
43
|
+
const localeStore = localeContext?.locale ?? emptyLocaleStore;
|
|
44
|
+
|
|
45
|
+
// Disabled both when nothing is selected and when the selection is already flush against
|
|
46
|
+
// that end — a button that does nothing when pressed is worse than one that says so.
|
|
47
|
+
const disabled = $derived(!ctx.canReorder(direction));
|
|
48
|
+
|
|
49
|
+
const defaultLabel = $derived(
|
|
50
|
+
resolveLocalizedString(
|
|
51
|
+
$localeStore,
|
|
52
|
+
direction === 'up' ? 'transferList.moveUp' : 'transferList.moveDown'
|
|
53
|
+
)
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
let buttonRef = $state<HTMLButtonElement | null>(null);
|
|
57
|
+
|
|
58
|
+
function handleClick(event: MouseEvent & { currentTarget: EventTarget & HTMLButtonElement }) {
|
|
59
|
+
// The selection survives a reorder — unlike a move, the items are still there — so the
|
|
60
|
+
// button keeps its work and focus has nowhere else it should go.
|
|
61
|
+
if (!disabled) ctx.reorder(direction);
|
|
62
|
+
onClickExternal?.(event);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
$effect(() => {
|
|
66
|
+
element = buttonRef;
|
|
67
|
+
});
|
|
68
|
+
</script>
|
|
69
|
+
|
|
70
|
+
<!-- `aria-disabled` rather than the native attribute, for the same reason as the move buttons:
|
|
71
|
+
these are unavailable more often than not, and dropping out of the tab order each time
|
|
72
|
+
would move the ground under a keyboard user. -->
|
|
73
|
+
<ButtonRoot
|
|
74
|
+
bind:element={buttonRef}
|
|
75
|
+
{disabled}
|
|
76
|
+
focusableWhenDisabled
|
|
77
|
+
aria-label={ariaLabelExternal ?? defaultLabel}
|
|
78
|
+
data-transfer-reorder={direction}
|
|
79
|
+
onclick={handleClick}
|
|
80
|
+
{...restProps}
|
|
81
|
+
>
|
|
82
|
+
{@render children?.()}
|
|
83
|
+
</ButtonRoot>
|