@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.
Files changed (81) hide show
  1. package/README.md +15 -6
  2. package/dist/FOCUS_STATE_CONTRACT.md +2 -0
  3. package/dist/autocomplete/list/autocomplete-list.svelte.d.ts +3 -1
  4. package/dist/button/root/button-root.svelte +19 -3
  5. package/dist/button/root/button-root.svelte.d.ts +10 -0
  6. package/dist/combobox/list/combobox-listbox.svelte.d.ts +3 -1
  7. package/dist/index.d.ts +2 -0
  8. package/dist/index.js +2 -0
  9. package/dist/internal/environment.d.ts +11 -0
  10. package/dist/internal/environment.js +14 -0
  11. package/dist/internal/localized-strings.d.ts +80 -0
  12. package/dist/internal/localized-strings.js +80 -0
  13. package/dist/listbox/README.md +27 -1
  14. package/dist/listbox/item/listbox-item.svelte +11 -2
  15. package/dist/listbox/root/context.d.ts +25 -0
  16. package/dist/listbox/root/context.js +108 -1
  17. package/dist/listbox/root/listbox.svelte +85 -7
  18. package/dist/listbox/root/listbox.svelte.d.ts +13 -1
  19. package/dist/menu/README.md +46 -0
  20. package/dist/menu/content/menu-content.svelte +16 -5
  21. package/dist/menu/content/menu-content.svelte.d.ts +2 -1
  22. package/dist/menu/context-trigger/menu-context-trigger.svelte +195 -0
  23. package/dist/menu/context-trigger/menu-context-trigger.svelte.d.ts +36 -0
  24. package/dist/menu/index.d.ts +4 -1
  25. package/dist/menu/index.js +1 -0
  26. package/dist/menu/index.parts.d.ts +1 -0
  27. package/dist/menu/index.parts.js +1 -0
  28. package/dist/menu/root/context.d.ts +18 -0
  29. package/dist/menu/root/menu-state.svelte.js +19 -0
  30. package/dist/popover/content/popover-content.svelte +2 -1
  31. package/dist/primitives/floating.d.ts +33 -5
  32. package/dist/primitives/floating.js +25 -0
  33. package/dist/primitives/index.d.ts +1 -0
  34. package/dist/primitives/index.js +1 -0
  35. package/dist/primitives/keyboard-navigation.d.ts +23 -5
  36. package/dist/primitives/keyboard-navigation.js +22 -15
  37. package/dist/primitives/long-press.d.ts +59 -0
  38. package/dist/primitives/long-press.js +142 -0
  39. package/dist/primitives/scroll-lock.d.ts +24 -0
  40. package/dist/primitives/scroll-lock.js +40 -0
  41. package/dist/toggle-group/README.md +10 -0
  42. package/dist/toggle-group/root/context.svelte.d.ts +1 -1
  43. package/dist/toggle-group/root/context.svelte.js +20 -11
  44. package/dist/toggle-group/root/toggle-group-root.svelte +20 -15
  45. package/dist/toggle-group/root/toggle-group-teardown-order-child.svelte +13 -0
  46. package/dist/toggle-group/root/toggle-group-teardown-order-child.svelte.d.ts +7 -0
  47. package/dist/toggle-group/types.d.ts +7 -8
  48. package/dist/transfer-list/README.md +121 -0
  49. package/dist/transfer-list/index.d.ts +33 -0
  50. package/dist/transfer-list/index.js +18 -0
  51. package/dist/transfer-list/index.parts.d.ts +9 -0
  52. package/dist/transfer-list/index.parts.js +10 -0
  53. package/dist/transfer-list/item/transfer-list-item.svelte +74 -0
  54. package/dist/transfer-list/item/transfer-list-item.svelte.d.ts +35 -0
  55. package/dist/transfer-list/list/transfer-list-list.svelte +162 -0
  56. package/dist/transfer-list/list/transfer-list-list.svelte.d.ts +56 -0
  57. package/dist/transfer-list/list/transfer-list-source.svelte +13 -0
  58. package/dist/transfer-list/list/transfer-list-source.svelte.d.ts +36 -0
  59. package/dist/transfer-list/list/transfer-list-target.svelte +14 -0
  60. package/dist/transfer-list/list/transfer-list-target.svelte.d.ts +36 -0
  61. package/dist/transfer-list/move/transfer-list-move-all.svelte +14 -0
  62. package/dist/transfer-list/move/transfer-list-move-all.svelte.d.ts +10 -0
  63. package/dist/transfer-list/move/transfer-list-move-button.svelte +103 -0
  64. package/dist/transfer-list/move/transfer-list-move-button.svelte.d.ts +25 -0
  65. package/dist/transfer-list/move/transfer-list-move-down.svelte +14 -0
  66. package/dist/transfer-list/move/transfer-list-move-down.svelte.d.ts +10 -0
  67. package/dist/transfer-list/move/transfer-list-move-selected.svelte +14 -0
  68. package/dist/transfer-list/move/transfer-list-move-selected.svelte.d.ts +10 -0
  69. package/dist/transfer-list/move/transfer-list-move-up.svelte +14 -0
  70. package/dist/transfer-list/move/transfer-list-move-up.svelte.d.ts +10 -0
  71. package/dist/transfer-list/move/transfer-list-reorder-button.svelte +83 -0
  72. package/dist/transfer-list/move/transfer-list-reorder-button.svelte.d.ts +21 -0
  73. package/dist/transfer-list/root/context.d.ts +70 -0
  74. package/dist/transfer-list/root/context.js +24 -0
  75. package/dist/transfer-list/root/transfer-list-root.svelte +342 -0
  76. package/dist/transfer-list/root/transfer-list-root.svelte.d.ts +65 -0
  77. package/dist/transfer-list/root/types.d.ts +22 -0
  78. package/dist/transfer-list/root/types.js +4 -0
  79. package/dist/transfer-list/status/transfer-list-status.svelte +70 -0
  80. package/dist/transfer-list/status/transfer-list-status.svelte.d.ts +15 -0
  81. package/package.json +6 -1
@@ -3,7 +3,6 @@ export type ToggleGroupSelectionMode = 'single' | 'multiple';
3
3
  export type ToggleGroupOrientation = 'horizontal' | 'vertical';
4
4
  export type CreateToggleGroupContextOptions = {
5
5
  initialValue?: ToggleGroupValue[];
6
- isControlled?: boolean;
7
6
  selectionMode?: ToggleGroupSelectionMode;
8
7
  isDisabled?: boolean;
9
8
  orientation?: ToggleGroupOrientation;
@@ -23,6 +22,7 @@ export type ToggleGroupContext = {
23
22
  owner?: symbol;
24
23
  }) => void;
25
24
  unregisterToggle: (value: ToggleGroupValue) => void;
25
+ setLive: (live: boolean) => void;
26
26
  setSelectionMode: (mode: ToggleGroupSelectionMode) => void;
27
27
  setDisabled: (disabled: boolean) => void;
28
28
  setOrientation: (orientation: ToggleGroupOrientation) => void;
@@ -29,7 +29,6 @@ export function valuesToArray(values, order) {
29
29
  return [...orderedValues, ...unknownValues];
30
30
  }
31
31
  export function createToggleGroupContext(options) {
32
- const isControlled = options.isControlled ?? false;
33
32
  let selectionMode = $state(options.selectionMode ?? 'single');
34
33
  let isDisabled = $state(options.isDisabled ?? false);
35
34
  let orientation = $state(options.orientation ?? 'horizontal');
@@ -39,6 +38,10 @@ export function createToggleGroupContext(options) {
39
38
  let selectedValues = $state(normalizeValues(options.initialValue, options.selectionMode ?? 'single'));
40
39
  let focusedValue = $state(null);
41
40
  let focusVisible = $state(false);
41
+ // Whether the group is mounted and interactive. Plain `let`, not `$state`: nothing renders
42
+ // from it, and the reads happen while toggles register and unregister, where a reactive
43
+ // read would only add a dependency.
44
+ let isLive = false;
42
45
  const toggles = new SvelteMap();
43
46
  const toggleOrder = $state([]);
44
47
  function getOrderedValues() {
@@ -115,13 +118,6 @@ export function createToggleGroupContext(options) {
115
118
  previousValue.some((value, index) => !valuesMatch(value, nextValue[index]));
116
119
  if (!didChange)
117
120
  return false;
118
- if (isControlled && changeOptions?.notify !== false) {
119
- // Controlled mode: request the change and let the parent apply it via props.
120
- // Mirrors Accordion's identical `setOpen`, which had this guard while this one
121
- // silently fell through and applied the change the parent might have rejected.
122
- options.onValueChange?.(nextValue);
123
- return true;
124
- }
125
121
  selectedValues = normalizedValues;
126
122
  if (changeOptions?.notify !== false) {
127
123
  options.onValueChange?.(nextValue);
@@ -129,8 +125,6 @@ export function createToggleGroupContext(options) {
129
125
  return true;
130
126
  }
131
127
  function reconcileSelection(changedValue, changeOptions) {
132
- if (isControlled)
133
- return;
134
128
  const nextValues = new SvelteSet(selectedValues);
135
129
  let removedSelectedValue;
136
130
  for (const selectedValue of selectedValues) {
@@ -175,6 +169,13 @@ export function createToggleGroupContext(options) {
175
169
  }
176
170
  reconcileSelection(value, { notify: isExisting });
177
171
  }
172
+ // Turned on by the root as it renders and off as it goes away, which is the only way to
173
+ // tell the two unregistrations apart: a toggle removed from a live group leaves a group
174
+ // behind that still has to show something, while a group on its way out has no one left
175
+ // to show anything to.
176
+ function setLive(live) {
177
+ isLive = live;
178
+ }
178
179
  function unregisterToggle(value) {
179
180
  if (!toggles.has(value))
180
181
  return;
@@ -186,13 +187,20 @@ export function createToggleGroupContext(options) {
186
187
  if (focusedValue !== null && valuesMatch(focusedValue, value)) {
187
188
  focusedValue = null;
188
189
  }
190
+ // Only a live group can lose a toggle from under it. Outside that window the toggle is
191
+ // leaving because the group is — on the client while it unmounts, on the server as the
192
+ // markup closes — and picking a fallback would report a selection the user never made,
193
+ // to a consumer already on its way out. Bound to a URL, that fake change navigated
194
+ // straight back to the screen being left.
195
+ if (!isLive)
196
+ return;
189
197
  reconcileSelection(value);
190
198
  }
191
199
  function setSelectionMode(mode) {
192
200
  if (selectionMode === mode)
193
201
  return;
194
202
  selectionMode = mode;
195
- setSelection(selectedValues, { notify: !isControlled });
203
+ setSelection(selectedValues);
196
204
  reconcileSelection();
197
205
  }
198
206
  function setDisabled(disabled) {
@@ -307,6 +315,7 @@ export function createToggleGroupContext(options) {
307
315
  },
308
316
  registerToggle: asCommand(registerToggle),
309
317
  unregisterToggle: asCommand(unregisterToggle),
318
+ setLive: asCommand(setLive),
310
319
  setSelectionMode: asCommand(setSelectionMode),
311
320
  setDisabled: asCommand(setDisabled),
312
321
  setOrientation: asCommand(setOrientation),
@@ -18,7 +18,6 @@
18
18
  id,
19
19
  value = $bindable(),
20
20
  defaultValue,
21
- controlledValue = false,
22
21
  onChange,
23
22
  selectionMode = 'single',
24
23
  disabled: disabledProp = false,
@@ -33,18 +32,12 @@
33
32
  ...restProps
34
33
  }: ToggleGroupRootProps = $props();
35
34
 
36
- // Controlled-ness is opt-in, not inferred from `value` being defined: `bind:value` and
37
- // `value={...}` are indistinguishable at runtime. It used to be inferred here, and the
38
- // write-back below ignored the result anyway, so a controlled parent could not reject
39
- // a change — the selection moved regardless of what `onChange` decided.
40
- const isControlled = untrack(() => controlledValue);
41
35
  const instanceId = untrack(() => id) ?? generatedId;
42
36
 
43
37
  let rootRef: HTMLDivElement | null = $state(null);
44
38
 
45
39
  const toggleGroup = setToggleGroupContext(
46
40
  createToggleGroupContext({
47
- isControlled,
48
41
  // `value` seeds the initial selection whenever it is supplied, bound or not.
49
42
  initialValue: untrack(() => value) ?? untrack(() => defaultValue),
50
43
  selectionMode: (() => selectionMode)(),
@@ -52,9 +45,10 @@
52
45
  orientation: (() => orientation)(),
53
46
  disallowEmptySelection: (() => disallowEmptySelection)(),
54
47
  onValueChange: (nextValue) => {
55
- if (!isControlled) {
56
- value = nextValue;
57
- }
48
+ // One path for both usages: with `bind:value` this reaches the parent, and
49
+ // without a binding the write stays local, so nothing here has to know
50
+ // which one the caller chose.
51
+ value = nextValue;
58
52
  onChange?.(nextValue);
59
53
  }
60
54
  })
@@ -62,6 +56,18 @@
62
56
 
63
57
  context = toggleGroup;
64
58
 
59
+ // Marks the window in which a toggle disappearing is a real change rather than the group
60
+ // itself coming or going. `$effect.pre` because Svelte destroys an effect's children
61
+ // before running that effect's own teardown, so an `onDestroy` here would fire *after*
62
+ // every toggle had already unregistered: this one is created while the script runs,
63
+ // before the children exist, so it is first in destroy order and its cleanup lands ahead
64
+ // of theirs. On the server it never runs, which is right too — there the toggles
65
+ // unregister as the markup closes and nobody is listening any more.
66
+ $effect.pre(() => {
67
+ toggleGroup.setLive(true);
68
+ return () => toggleGroup.setLive(false);
69
+ });
70
+
65
71
  const disabled = $derived(toggleGroup.isDisabled);
66
72
  const multiple = $derived(toggleGroup.selectionMode === 'multiple');
67
73
  const currentOrientation = $derived(toggleGroup.orientation);
@@ -86,11 +92,10 @@
86
92
  toggleGroup.setDisallowEmptySelection(disallowEmptySelection);
87
93
  });
88
94
 
89
- // Whether to adopt an incoming `value` is a separate question from who owns the state,
90
- // so it is latched at init off the prop rather than off `controlledValue`: a parent
91
- // that supplies `value` drives the selection, bound or not. Latched, not reactive —
92
- // re-checking `value !== undefined` would switch this on the moment our own write-back
93
- // defines it, and the component would then re-adopt the echo of its own change.
95
+ // A parent that supplies `value` drives the selection, bound or not. Latched at init,
96
+ // not reactive — re-checking `value !== undefined` would switch this on the moment our
97
+ // own write-back defines it, and a `defaultValue`-only group would start following the
98
+ // echo of its own changes.
94
99
  const adoptsValueProp = untrack(() => value !== undefined);
95
100
 
96
101
  $effect(() => {
@@ -0,0 +1,13 @@
1
+ <script lang="ts">
2
+ import { onDestroy } from 'svelte';
3
+
4
+ type Props = {
5
+ /** Shared log, so the parent can assert who tore down first. */
6
+ record: (step: string) => void;
7
+ };
8
+
9
+ let { record }: Props = $props();
10
+
11
+ // Stands in for `Toggle.Root`, which unregisters from `onDestroy`.
12
+ onDestroy(() => record('child-destroy'));
13
+ </script>
@@ -0,0 +1,7 @@
1
+ type Props = {
2
+ /** Shared log, so the parent can assert who tore down first. */
3
+ record: (step: string) => void;
4
+ };
5
+ declare const ToggleGroupTeardownOrderChild: import("svelte").Component<Props, {}, "">;
6
+ type ToggleGroupTeardownOrderChild = ReturnType<typeof ToggleGroupTeardownOrderChild>;
7
+ export default ToggleGroupTeardownOrderChild;
@@ -3,17 +3,16 @@ import type { HTMLAttributes } from 'svelte/elements';
3
3
  import type { ToggleGroupContext, ToggleGroupOrientation, ToggleGroupSelectionMode, ToggleGroupValue } from './root/context.svelte';
4
4
  export type { ToggleGroupContext, ToggleGroupOrientation, ToggleGroupSelectionMode, ToggleGroupValue } from './root/context.svelte';
5
5
  export type ToggleGroupRootProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class'> & {
6
- /** Selected values. Two-way by default — use `bind:value`. */
6
+ /**
7
+ * Selected values, and the source of truth whenever it is supplied — with `bind:value`
8
+ * or without. Every change is written back here and reported through `onChange`; without
9
+ * a binding that write only lands locally, so a parent that hears `onChange` and refuses
10
+ * the change (never flowing a new `value` down) sees the group move anyway, and snap back
11
+ * to the supplied `value` the next time the parent renders.
12
+ */
7
13
  value?: ToggleGroupValue[];
8
14
  /** Initially selected values, for when `value` is not supplied. */
9
15
  defaultValue?: ToggleGroupValue[];
10
- /**
11
- * Opt into fully controlled state: the component stops writing back to `value` and
12
- * only reports through `onChange`, so the parent can reject a change by not flowing
13
- * the new value back down. Off by default, because `bind:value` — the common case —
14
- * needs the write-back to work at all.
15
- */
16
- controlledValue?: boolean;
17
16
  onChange?: (value: ToggleGroupValue[]) => void;
18
17
  selectionMode?: ToggleGroupSelectionMode;
19
18
  disabled?: boolean;
@@ -0,0 +1,121 @@
1
+ # TransferList
2
+
3
+ ## Description
4
+
5
+ `TransferList` is two selectable lists side by side with buttons that move items between
6
+ them — picking visible columns, granting permissions, building a shortlist. Both lists are
7
+ `ListBox`es, so selection, keyboard navigation, typeahead and virtualization come from there
8
+ unchanged.
9
+
10
+ ## Usage guidelines
11
+
12
+ - Use `TransferList.Root` to hold the collection and the split between the two sides.
13
+ - Give each side a `label`: it names the list, the move buttons and the announcements.
14
+ - Render each row with `TransferList.Item`, from the snippet the list hands you.
15
+ - Use `TransferList.MoveSelected` and `TransferList.MoveAll` with `to="source" | "target"`.
16
+ - Use `TransferList.MoveUp` / `TransferList.MoveDown` to order the right-hand list.
17
+ - Give a side a `filter` predicate to show only part of it; the input driving it is yours.
18
+ - Pass `name` on the Root to submit `value` through hidden inputs.
19
+ - Add `TransferList.Status` so screen reader users hear what a move did.
20
+ - Layout is yours: `TransferList.Root` renders a plain element, so arrange the two lists and
21
+ the buttons with your own grid or flex.
22
+
23
+ ## State
24
+
25
+ There is one source of truth. `items` is the whole collection; `value` is the ordered list of
26
+ keys that sit on the right. The left is everything else.
27
+
28
+ That makes `value` exactly what a form submits, and it gives the right-hand list an order for
29
+ free — items land in the sequence they were moved, and the list renders in `value` order
30
+ rather than in `items` order.
31
+
32
+ - `getKey` identifies an item. Defaults to its `id` field.
33
+ - `value` / `defaultValue` / `onChange` behave like every other component here.
34
+ `controlledValue` is **opt-in**: `bind:value={keys}` and `value={keys}` are
35
+ indistinguishable at runtime, so controlled-ness is never inferred.
36
+ - `disabledKeys` pins items to the side they are on. They are skipped by "move all", left out
37
+ of range selections, and ignored by double click.
38
+
39
+ ## Behaviour
40
+
41
+ - A move takes the keys off one side and appends them to the other, in the order the
42
+ originating list showed them.
43
+ - Items that move arrive **deselected**, so the next click on the opposite button is never an
44
+ accidental undo. The selection is pruned against what is actually on each side rather than
45
+ cleared outright, so a controlled parent that rejects a move leaves the user's selection
46
+ intact.
47
+ - **Double click moves a row.** `Enter` deliberately does not: in a multi-select listbox Enter
48
+ and Space toggle the selection, and overriding that would break the contract every other
49
+ list in the library keeps. `Ctrl`/`Cmd`+`Enter` is the shortcut instead — each list has one
50
+ destination, so it needs no direction and survives a mirrored layout. Disable it with
51
+ `moveShortcut={false}`.
52
+ - Shift+click and Shift+Arrow select a range — see `ListBox`. With `virtualizer`, the range
53
+ still spans rows that were never rendered: the component hands `ListBox` its `getKey`.
54
+ - A **filter** on a side changes what "move all" means: the rows on screen, not the whole
55
+ side. Moving items the user cannot see would be invisible work.
56
+ - **Reordering** exists only on the right, where the order is state the user is building; the
57
+ left is the order `items` were given in. It edits the whole `value`, not what a filter is
58
+ showing.
59
+
60
+ ## Focus after a move
61
+
62
+ - From a button, focus stays on the button, as it does for any button press. The buttons are
63
+ `aria-disabled` rather than natively disabled, so one that has just run out of work can
64
+ still hold it.
65
+ - From a double click or the keyboard shortcut, the row the user was on is gone, so focus
66
+ lands on whichever row took its place (or the last row, if it was the last). When the side
67
+ empties, it follows the items to the destination list rather than falling to the `<body>`.
68
+
69
+ ## Accessibility
70
+
71
+ - Give the **Root** an `aria-label` or `aria-labelledby`. It then renders `role="group"`, which
72
+ is what tells assistive technology that the two lists and the buttons are one control rather
73
+ than unrelated ones. Without a name the role is left off: an unlabelled group is skipped
74
+ anyway, so claiming it would only add noise.
75
+ - Each list is a `role="listbox"` with `aria-multiselectable="true"`, named by `label` — or by
76
+ `aria-labelledby` when there is a visible heading.
77
+ - The move buttons carry `aria-disabled` rather than the native attribute, so they stay in the
78
+ tab order when they have nothing to do. These controls are unavailable more often than not,
79
+ and natively disabling them would hide half the actions from a keyboard user and shift the
80
+ tab order underfoot. Style them with `data-disabled` — `:disabled` will never match.
81
+ - The move buttons are named after where items go ("Move selected to Selected"), not after a
82
+ direction: an arrow glyph says nothing on its own, and "move right" is wrong the moment the
83
+ layout is mirrored. Override with `aria-label`.
84
+ - `TransferList.Status` announces each move in a polite live region.
85
+
86
+ ## Anatomy
87
+
88
+ ```svelte
89
+ <TransferList.Root {items} bind:value class="grid grid-cols-[1fr_auto_1fr] gap-4">
90
+ <TransferList.Source label="Available">
91
+ {#snippet children(item)}
92
+ <TransferList.Item {item}>{item.name}</TransferList.Item>
93
+ {/snippet}
94
+ </TransferList.Source>
95
+
96
+ <div>
97
+ <TransferList.MoveSelected to="target">→</TransferList.MoveSelected>
98
+ <TransferList.MoveAll to="target">⇒</TransferList.MoveAll>
99
+ <TransferList.MoveAll to="source">⇐</TransferList.MoveAll>
100
+ <TransferList.MoveSelected to="source">←</TransferList.MoveSelected>
101
+ </div>
102
+
103
+ <TransferList.Target label="Selected">
104
+ {#snippet children(item)}
105
+ <TransferList.Item {item}>{item.name}</TransferList.Item>
106
+ {/snippet}
107
+ </TransferList.Target>
108
+
109
+ <TransferList.Status />
110
+ </TransferList.Root>
111
+ ```
112
+
113
+ - `TransferList.Root`
114
+ - `TransferList.Source`
115
+ - `TransferList.Target`
116
+ - `TransferList.Item`
117
+ - `TransferList.MoveSelected`
118
+ - `TransferList.MoveAll`
119
+ - `TransferList.MoveUp`
120
+ - `TransferList.MoveDown`
121
+ - `TransferList.Status`
@@ -0,0 +1,33 @@
1
+ import type { ComponentProps } from 'svelte';
2
+ import type TransferListRootComponent from './root/transfer-list-root.svelte';
3
+ import type TransferListSourceComponent from './list/transfer-list-source.svelte';
4
+ import type TransferListTargetComponent from './list/transfer-list-target.svelte';
5
+ import type TransferListItemComponent from './item/transfer-list-item.svelte';
6
+ import type TransferListMoveSelectedComponent from './move/transfer-list-move-selected.svelte';
7
+ import type TransferListMoveAllComponent from './move/transfer-list-move-all.svelte';
8
+ import type TransferListMoveUpComponent from './move/transfer-list-move-up.svelte';
9
+ import type TransferListMoveDownComponent from './move/transfer-list-move-down.svelte';
10
+ import type TransferListStatusComponent from './status/transfer-list-status.svelte';
11
+ export * as TransferList from './index.parts.js';
12
+ export { default as TransferListRoot } from './root/transfer-list-root.svelte';
13
+ export { default as TransferListSource } from './list/transfer-list-source.svelte';
14
+ export { default as TransferListTarget } from './list/transfer-list-target.svelte';
15
+ export { default as TransferListItem } from './item/transfer-list-item.svelte';
16
+ export { default as TransferListMoveSelected } from './move/transfer-list-move-selected.svelte';
17
+ export { default as TransferListMoveAll } from './move/transfer-list-move-all.svelte';
18
+ export { default as TransferListMoveUp } from './move/transfer-list-move-up.svelte';
19
+ export { default as TransferListMoveDown } from './move/transfer-list-move-down.svelte';
20
+ export { default as TransferListStatus } from './status/transfer-list-status.svelte';
21
+ export type TransferListRootProps = ComponentProps<typeof TransferListRootComponent>;
22
+ export type TransferListSourceProps = ComponentProps<typeof TransferListSourceComponent>;
23
+ export type TransferListTargetProps = ComponentProps<typeof TransferListTargetComponent>;
24
+ export type TransferListItemProps = ComponentProps<typeof TransferListItemComponent>;
25
+ export type TransferListMoveSelectedProps = ComponentProps<typeof TransferListMoveSelectedComponent>;
26
+ export type TransferListMoveAllProps = ComponentProps<typeof TransferListMoveAllComponent>;
27
+ export type TransferListMoveUpProps = ComponentProps<typeof TransferListMoveUpComponent>;
28
+ export type TransferListMoveDownProps = ComponentProps<typeof TransferListMoveDownComponent>;
29
+ export type TransferListStatusProps = ComponentProps<typeof TransferListStatusComponent>;
30
+ export { setTransferListContext, useTransferListContext, useTransferListSide, type TransferListContext } from './root/context.js';
31
+ export { oppositeSide, type TransferListKey, type TransferListMoveDetails, type TransferListSide } from './root/types.js';
32
+ import * as TransferListParts from './index.parts.js';
33
+ export default TransferListParts;
@@ -0,0 +1,18 @@
1
+ // Namespace export for component composition: <TransferList.Root>, <TransferList.Source>, etc.
2
+ export * as TransferList from './index.parts.js';
3
+ // Direct named exports for individual imports
4
+ export { default as TransferListRoot } from './root/transfer-list-root.svelte';
5
+ export { default as TransferListSource } from './list/transfer-list-source.svelte';
6
+ export { default as TransferListTarget } from './list/transfer-list-target.svelte';
7
+ export { default as TransferListItem } from './item/transfer-list-item.svelte';
8
+ export { default as TransferListMoveSelected } from './move/transfer-list-move-selected.svelte';
9
+ export { default as TransferListMoveAll } from './move/transfer-list-move-all.svelte';
10
+ export { default as TransferListMoveUp } from './move/transfer-list-move-up.svelte';
11
+ export { default as TransferListMoveDown } from './move/transfer-list-move-down.svelte';
12
+ export { default as TransferListStatus } from './status/transfer-list-status.svelte';
13
+ // Context and types
14
+ export { setTransferListContext, useTransferListContext, useTransferListSide } from './root/context.js';
15
+ export { oppositeSide } from './root/types.js';
16
+ // Default export as namespace object
17
+ import * as TransferListParts from './index.parts.js';
18
+ export default TransferListParts;
@@ -0,0 +1,9 @@
1
+ export { default as Root } from './root/transfer-list-root.svelte';
2
+ export { default as Source } from './list/transfer-list-source.svelte';
3
+ export { default as Target } from './list/transfer-list-target.svelte';
4
+ export { default as Item } from './item/transfer-list-item.svelte';
5
+ export { default as MoveSelected } from './move/transfer-list-move-selected.svelte';
6
+ export { default as MoveAll } from './move/transfer-list-move-all.svelte';
7
+ export { default as MoveUp } from './move/transfer-list-move-up.svelte';
8
+ export { default as MoveDown } from './move/transfer-list-move-down.svelte';
9
+ export { default as Status } from './status/transfer-list-status.svelte';
@@ -0,0 +1,10 @@
1
+ // Namespace parts for <TransferList.Root>, <TransferList.Source>, etc.
2
+ export { default as Root } from './root/transfer-list-root.svelte';
3
+ export { default as Source } from './list/transfer-list-source.svelte';
4
+ export { default as Target } from './list/transfer-list-target.svelte';
5
+ export { default as Item } from './item/transfer-list-item.svelte';
6
+ export { default as MoveSelected } from './move/transfer-list-move-selected.svelte';
7
+ export { default as MoveAll } from './move/transfer-list-move-all.svelte';
8
+ export { default as MoveUp } from './move/transfer-list-move-up.svelte';
9
+ export { default as MoveDown } from './move/transfer-list-move-down.svelte';
10
+ export { default as Status } from './status/transfer-list-status.svelte';
@@ -0,0 +1,74 @@
1
+ <script lang="ts" generics="T extends object = object">
2
+ import type { Snippet } from 'svelte';
3
+ import type { HTMLAttributes } from 'svelte/elements';
4
+ import { tick } from 'svelte';
5
+ import { ListBoxItem } from '../../listbox';
6
+ import { useTransferListContext, useTransferListSide } from '../root/context';
7
+ import { oppositeSide } from '../root/types';
8
+
9
+ /**
10
+ * TransferList.Item - One row, on whichever side it currently lives.
11
+ *
12
+ * Double clicking sends it to the other list. Enter deliberately does not: in a
13
+ * multi-select listbox Enter and Space toggle the selection, and overriding that here
14
+ * would break the contract every other list in the library keeps. The keyboard route
15
+ * is the move buttons, which are in the tab order.
16
+ */
17
+ type TransferListItemProps = {
18
+ /** The item this row renders. Its key comes from the Root's `getKey`. */
19
+ item: T;
20
+ /** Text used for typeahead. Falls back to the row's text content. */
21
+ textValue?: string;
22
+ /** CSS class for the row. */
23
+ class?: string;
24
+ /** Row content. */
25
+ children?: Snippet;
26
+ } & Omit<HTMLAttributes<HTMLDivElement>, 'id' | 'class' | 'children'>;
27
+
28
+ let {
29
+ item,
30
+ textValue,
31
+ class: className = '',
32
+ children,
33
+ ondblclick: onDoubleClickExternal,
34
+ ...restProps
35
+ }: TransferListItemProps = $props();
36
+
37
+ const ctx = useTransferListContext<T>('TransferList.Item');
38
+ const side = useTransferListSide('TransferList.Item');
39
+
40
+ const key = $derived(ctx.getKey(item));
41
+ const disabled = $derived(ctx.isDisabled(key));
42
+
43
+ async function handleDoubleClick(
44
+ event: MouseEvent & { currentTarget: EventTarget & HTMLDivElement }
45
+ ) {
46
+ if (!disabled) {
47
+ // Captured before the move, while this row still exists.
48
+ const index = ctx.getItems(side).findIndex((candidate) => ctx.getKey(candidate) === key);
49
+ const destination = oppositeSide(side);
50
+
51
+ ctx.move([key], destination);
52
+ await tick();
53
+
54
+ // The row that took this one's place keeps the keyboard where the user was
55
+ // working; with the side emptied there is nothing left to hold focus, so it
56
+ // follows the items instead of falling back to the <body>.
57
+ if (!ctx.focusItemAt(side, index)) {
58
+ ctx.focusList(destination);
59
+ }
60
+ }
61
+ onDoubleClickExternal?.(event);
62
+ }
63
+ </script>
64
+
65
+ <ListBoxItem
66
+ id={key}
67
+ {disabled}
68
+ {textValue}
69
+ class={className}
70
+ ondblclick={handleDoubleClick}
71
+ {...restProps}
72
+ >
73
+ {@render children?.()}
74
+ </ListBoxItem>
@@ -0,0 +1,35 @@
1
+ import type { Snippet } from 'svelte';
2
+ import type { HTMLAttributes } from 'svelte/elements';
3
+ declare function $$render<T extends object = object>(): {
4
+ props: {
5
+ /** The item this row renders. Its key comes from the Root's `getKey`. */
6
+ item: T;
7
+ /** Text used for typeahead. Falls back to the row's text content. */
8
+ textValue?: string;
9
+ /** CSS class for the row. */
10
+ class?: string;
11
+ /** Row content. */
12
+ children?: Snippet;
13
+ } & Omit<HTMLAttributes<HTMLDivElement>, "children" | "class" | "id">;
14
+ exports: {};
15
+ bindings: "";
16
+ slots: {};
17
+ events: {};
18
+ };
19
+ declare class __sveltets_Render<T extends object = object> {
20
+ props(): ReturnType<typeof $$render<T>>['props'];
21
+ events(): ReturnType<typeof $$render<T>>['events'];
22
+ slots(): ReturnType<typeof $$render<T>>['slots'];
23
+ bindings(): "";
24
+ exports(): {};
25
+ }
26
+ interface $$IsomorphicComponent {
27
+ 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']>> & {
28
+ $$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
29
+ } & ReturnType<__sveltets_Render<T>['exports']>;
30
+ <T extends object = object>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
31
+ z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
32
+ }
33
+ declare const TransferListItem: $$IsomorphicComponent;
34
+ type TransferListItem<T extends object = object> = InstanceType<typeof TransferListItem<T>>;
35
+ export default TransferListItem;