@human-kit/ui 1.0.0-beta.6 → 1.0.0-beta.8

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 (223) hide show
  1. package/dist/FOCUS_STATE_CONTRACT.md +15 -4
  2. package/dist/FOCUS_STATE_REVIEW_TEMPLATE.md +8 -8
  3. package/dist/autocomplete/item/autocomplete-item.svelte +10 -0
  4. package/dist/avatar/README.md +52 -0
  5. package/dist/avatar/count/avatar-count.svelte +56 -0
  6. package/dist/avatar/count/avatar-count.svelte.d.ts +4 -0
  7. package/dist/avatar/fallback/avatar-fallback.svelte +67 -0
  8. package/dist/avatar/fallback/avatar-fallback.svelte.d.ts +4 -0
  9. package/dist/avatar/group/avatar-group.svelte +65 -0
  10. package/dist/avatar/group/avatar-group.svelte.d.ts +4 -0
  11. package/dist/avatar/group/context.d.ts +15 -0
  12. package/dist/avatar/group/context.js +15 -0
  13. package/dist/avatar/image/avatar-image.svelte +104 -0
  14. package/dist/avatar/image/avatar-image.svelte.d.ts +4 -0
  15. package/dist/avatar/index.d.ts +22 -0
  16. package/dist/avatar/index.js +10 -0
  17. package/dist/avatar/index.parts.d.ts +5 -0
  18. package/dist/avatar/index.parts.js +5 -0
  19. package/dist/avatar/root/avatar-root.svelte +79 -0
  20. package/dist/avatar/root/avatar-root.svelte.d.ts +4 -0
  21. package/dist/avatar/root/context.d.ts +14 -0
  22. package/dist/avatar/root/context.js +15 -0
  23. package/dist/avatar/types.d.ts +84 -0
  24. package/dist/avatar/types.js +1 -0
  25. package/dist/breadcrumbs/README.md +65 -0
  26. package/dist/breadcrumbs/ellipsis/breadcrumbs-ellipsis.svelte +62 -0
  27. package/dist/breadcrumbs/ellipsis/breadcrumbs-ellipsis.svelte.d.ts +4 -0
  28. package/dist/breadcrumbs/index.d.ts +23 -0
  29. package/dist/breadcrumbs/index.js +10 -0
  30. package/dist/breadcrumbs/index.parts.d.ts +6 -0
  31. package/dist/breadcrumbs/index.parts.js +6 -0
  32. package/dist/breadcrumbs/item/breadcrumbs-item.svelte +42 -0
  33. package/dist/breadcrumbs/item/breadcrumbs-item.svelte.d.ts +4 -0
  34. package/dist/breadcrumbs/link/breadcrumbs-link.svelte +47 -0
  35. package/dist/breadcrumbs/link/breadcrumbs-link.svelte.d.ts +4 -0
  36. package/dist/breadcrumbs/list/breadcrumbs-list.svelte +31 -0
  37. package/dist/breadcrumbs/list/breadcrumbs-list.svelte.d.ts +4 -0
  38. package/dist/breadcrumbs/root/breadcrumbs-root.svelte +112 -0
  39. package/dist/breadcrumbs/root/breadcrumbs-root.svelte.d.ts +4 -0
  40. package/dist/breadcrumbs/root/context.d.ts +19 -0
  41. package/dist/breadcrumbs/root/context.js +15 -0
  42. package/dist/breadcrumbs/separator/breadcrumbs-separator.svelte +35 -0
  43. package/dist/breadcrumbs/separator/breadcrumbs-separator.svelte.d.ts +4 -0
  44. package/dist/breadcrumbs/types.d.ts +80 -0
  45. package/dist/breadcrumbs/types.js +1 -0
  46. package/dist/button/root/button-root.svelte +9 -0
  47. package/dist/calendar/body-cell/calendar-body-cell.svelte +7 -0
  48. package/dist/checkbox/indicator/checkbox-indicator.svelte +1 -0
  49. package/dist/checkbox/indicator/checkbox-indicator.svelte.d.ts +1 -0
  50. package/dist/checkbox/root/checkbox-root.svelte +106 -30
  51. package/dist/checkbox/root/checkbox-root.svelte.d.ts +5 -0
  52. package/dist/checkbox-group/README.md +95 -0
  53. package/dist/checkbox-group/index.d.ts +15 -0
  54. package/dist/checkbox-group/index.js +6 -0
  55. package/dist/checkbox-group/index.parts.d.ts +4 -0
  56. package/dist/checkbox-group/index.parts.js +7 -0
  57. package/dist/checkbox-group/label/checkbox-group-label.svelte +36 -0
  58. package/dist/checkbox-group/label/checkbox-group-label.svelte.d.ts +4 -0
  59. package/dist/checkbox-group/root/checkbox-group-root.svelte +118 -0
  60. package/dist/checkbox-group/root/checkbox-group-root.svelte.d.ts +4 -0
  61. package/dist/checkbox-group/root/context.svelte.d.ts +52 -0
  62. package/dist/checkbox-group/root/context.svelte.js +251 -0
  63. package/dist/checkbox-group/types.d.ts +57 -0
  64. package/dist/checkbox-group/types.js +1 -0
  65. package/dist/combobox/popover/combobox-popover.svelte +4 -56
  66. package/dist/dialog/root/dialog-root.svelte +15 -2
  67. package/dist/drawer/root/drawer-root.svelte +15 -2
  68. package/dist/index.d.ts +18 -0
  69. package/dist/index.js +17 -0
  70. package/dist/internal/localized-strings.d.ts +48 -0
  71. package/dist/internal/localized-strings.js +48 -0
  72. package/dist/internal/number-precision.d.ts +9 -0
  73. package/dist/internal/number-precision.js +27 -0
  74. package/dist/menu/root/focus-state.d.ts +2 -2
  75. package/dist/menu/root/focus-state.js +8 -32
  76. package/dist/menu/root/menu-state.svelte.js +5 -1
  77. package/dist/numberfield/root/number-utils.js +1 -20
  78. package/dist/popover/root/focus-state.d.ts +2 -2
  79. package/dist/popover/root/focus-state.js +7 -34
  80. package/dist/primitives/contain-wheel.d.ts +9 -0
  81. package/dist/primitives/contain-wheel.js +41 -0
  82. package/dist/primitives/floating.d.ts +6 -0
  83. package/dist/primitives/floating.js +26 -5
  84. package/dist/primitives/focus-visible.svelte.d.ts +14 -0
  85. package/dist/primitives/focus-visible.svelte.js +19 -0
  86. package/dist/primitives/index.d.ts +1 -0
  87. package/dist/primitives/index.js +1 -0
  88. package/dist/primitives/input-modality.d.ts +7 -0
  89. package/dist/primitives/input-modality.js +32 -5
  90. package/dist/primitives/keyboard-navigation.d.ts +6 -0
  91. package/dist/primitives/keyboard-navigation.js +2 -1
  92. package/dist/primitives/trigger-focus-state.d.ts +29 -0
  93. package/dist/primitives/trigger-focus-state.js +57 -0
  94. package/dist/progress/README.md +54 -0
  95. package/dist/progress/index.d.ts +21 -0
  96. package/dist/progress/index.js +9 -0
  97. package/dist/progress/index.parts.d.ts +5 -0
  98. package/dist/progress/index.parts.js +5 -0
  99. package/dist/progress/indicator/progress-indicator.svelte +37 -0
  100. package/dist/progress/indicator/progress-indicator.svelte.d.ts +4 -0
  101. package/dist/progress/label/progress-label.svelte +34 -0
  102. package/dist/progress/label/progress-label.svelte.d.ts +4 -0
  103. package/dist/progress/root/context.d.ts +26 -0
  104. package/dist/progress/root/context.js +15 -0
  105. package/dist/progress/root/progress-root.svelte +136 -0
  106. package/dist/progress/root/progress-root.svelte.d.ts +4 -0
  107. package/dist/progress/root/progress-utils.d.ts +12 -0
  108. package/dist/progress/root/progress-utils.js +41 -0
  109. package/dist/progress/track/progress-track.svelte +27 -0
  110. package/dist/progress/track/progress-track.svelte.d.ts +4 -0
  111. package/dist/progress/types.d.ts +81 -0
  112. package/dist/progress/types.js +1 -0
  113. package/dist/progress/value/progress-value.svelte +36 -0
  114. package/dist/progress/value/progress-value.svelte.d.ts +4 -0
  115. package/dist/radio-group/README.md +103 -0
  116. package/dist/radio-group/index.d.ts +18 -0
  117. package/dist/radio-group/index.js +9 -0
  118. package/dist/radio-group/index.parts.d.ts +4 -0
  119. package/dist/radio-group/index.parts.js +4 -0
  120. package/dist/radio-group/indicator/radio-group-indicator.svelte +43 -0
  121. package/dist/radio-group/indicator/radio-group-indicator.svelte.d.ts +12 -0
  122. package/dist/radio-group/item/context.d.ts +18 -0
  123. package/dist/radio-group/item/context.js +15 -0
  124. package/dist/radio-group/item/radio-group-item.svelte +377 -0
  125. package/dist/radio-group/item/radio-group-item.svelte.d.ts +35 -0
  126. package/dist/radio-group/label/radio-group-label.svelte +37 -0
  127. package/dist/radio-group/label/radio-group-label.svelte.d.ts +4 -0
  128. package/dist/radio-group/root/context.svelte.d.ts +57 -0
  129. package/dist/radio-group/root/context.svelte.js +284 -0
  130. package/dist/radio-group/root/radio-group-root.svelte +193 -0
  131. package/dist/radio-group/root/radio-group-root.svelte.d.ts +4 -0
  132. package/dist/radio-group/types.d.ts +50 -0
  133. package/dist/radio-group/types.js +1 -0
  134. package/dist/select/README.md +129 -0
  135. package/dist/select/index.d.ts +30 -0
  136. package/dist/select/index.js +16 -0
  137. package/dist/select/index.parts.d.ts +8 -0
  138. package/dist/select/index.parts.js +9 -0
  139. package/dist/select/item/select-item.svelte +68 -0
  140. package/dist/select/item/select-item.svelte.d.ts +10 -0
  141. package/dist/select/item-indicator/select-item-indicator.svelte +55 -0
  142. package/dist/select/item-indicator/select-item-indicator.svelte.d.ts +4 -0
  143. package/dist/select/label/select-label.svelte +46 -0
  144. package/dist/select/label/select-label.svelte.d.ts +4 -0
  145. package/dist/select/list/select-list.svelte +241 -0
  146. package/dist/select/list/select-list.svelte.d.ts +62 -0
  147. package/dist/select/popover/select-popover.svelte +80 -0
  148. package/dist/select/popover/select-popover.svelte.d.ts +9 -0
  149. package/dist/select/root/context.d.ts +106 -0
  150. package/dist/select/root/context.js +22 -0
  151. package/dist/select/root/select-root.svelte +544 -0
  152. package/dist/select/root/select-root.svelte.d.ts +25 -0
  153. package/dist/select/trigger/select-trigger.svelte +192 -0
  154. package/dist/select/trigger/select-trigger.svelte.d.ts +4 -0
  155. package/dist/select/types.d.ts +133 -0
  156. package/dist/select/types.js +1 -0
  157. package/dist/select/value/select-value.svelte +61 -0
  158. package/dist/select/value/select-value.svelte.d.ts +4 -0
  159. package/dist/separator/README.md +35 -0
  160. package/dist/separator/index.d.ts +7 -0
  161. package/dist/separator/index.js +3 -0
  162. package/dist/separator/separator.svelte +254 -0
  163. package/dist/separator/separator.svelte.d.ts +45 -0
  164. package/dist/separator/types.d.ts +1 -0
  165. package/dist/separator/types.js +1 -0
  166. package/dist/slider/README.md +61 -0
  167. package/dist/slider/fill/slider-fill.svelte +40 -0
  168. package/dist/slider/fill/slider-fill.svelte.d.ts +4 -0
  169. package/dist/slider/index.d.ts +9 -0
  170. package/dist/slider/index.js +8 -0
  171. package/dist/slider/index.parts.d.ts +6 -0
  172. package/dist/slider/index.parts.js +6 -0
  173. package/dist/slider/label/slider-label.svelte +44 -0
  174. package/dist/slider/label/slider-label.svelte.d.ts +4 -0
  175. package/dist/slider/output/slider-output.svelte +46 -0
  176. package/dist/slider/output/slider-output.svelte.d.ts +4 -0
  177. package/dist/slider/root/context.d.ts +106 -0
  178. package/dist/slider/root/context.js +15 -0
  179. package/dist/slider/root/slider-root.svelte +545 -0
  180. package/dist/slider/root/slider-root.svelte.d.ts +4 -0
  181. package/dist/slider/root/slider-utils.d.ts +57 -0
  182. package/dist/slider/root/slider-utils.js +88 -0
  183. package/dist/slider/thumb/slider-thumb.svelte +276 -0
  184. package/dist/slider/thumb/slider-thumb.svelte.d.ts +4 -0
  185. package/dist/slider/track/slider-track.svelte +60 -0
  186. package/dist/slider/track/slider-track.svelte.d.ts +4 -0
  187. package/dist/slider/types.d.ts +144 -0
  188. package/dist/slider/types.js +1 -0
  189. package/dist/switch/root/switch-root.svelte +9 -0
  190. package/dist/table/column-header-cell/table-column-header-cell.svelte +24 -0
  191. package/dist/table/root/table-root.svelte +29 -6
  192. package/dist/timepicker/input/time-picker-input.svelte +12 -4
  193. package/dist/timepicker/input/time-picker-input.svelte.d.ts +12 -4
  194. package/dist/toggle/root/toggle-root.svelte +28 -0
  195. package/dist/toggle/root/toggle-root.svelte.d.ts +19 -0
  196. package/dist/toggle-group/README.md +6 -4
  197. package/dist/toggle-group/index.d.ts +2 -0
  198. package/dist/toggle-group/index.parts.d.ts +1 -0
  199. package/dist/toggle-group/index.parts.js +4 -0
  200. package/dist/tooltip/README.md +53 -0
  201. package/dist/tooltip/arrow/tooltip-arrow.svelte +36 -0
  202. package/dist/tooltip/arrow/tooltip-arrow.svelte.d.ts +4 -0
  203. package/dist/tooltip/content/tooltip-content.svelte +148 -0
  204. package/dist/tooltip/content/tooltip-content.svelte.d.ts +4 -0
  205. package/dist/tooltip/index.d.ts +8 -0
  206. package/dist/tooltip/index.js +7 -0
  207. package/dist/tooltip/index.parts.d.ts +5 -0
  208. package/dist/tooltip/index.parts.js +5 -0
  209. package/dist/tooltip/provider/tooltip-provider.svelte +36 -0
  210. package/dist/tooltip/provider/tooltip-provider.svelte.d.ts +4 -0
  211. package/dist/tooltip/root/context.d.ts +46 -0
  212. package/dist/tooltip/root/context.js +22 -0
  213. package/dist/tooltip/root/safe-polygon.d.ts +26 -0
  214. package/dist/tooltip/root/safe-polygon.js +66 -0
  215. package/dist/tooltip/root/tooltip-group.d.ts +26 -0
  216. package/dist/tooltip/root/tooltip-group.js +41 -0
  217. package/dist/tooltip/root/tooltip-root.svelte +454 -0
  218. package/dist/tooltip/root/tooltip-root.svelte.d.ts +4 -0
  219. package/dist/tooltip/trigger/tooltip-trigger.svelte +52 -0
  220. package/dist/tooltip/trigger/tooltip-trigger.svelte.d.ts +4 -0
  221. package/dist/tooltip/types.d.ts +105 -0
  222. package/dist/tooltip/types.js +1 -0
  223. package/package.json +46 -1
@@ -0,0 +1,118 @@
1
+ <script lang="ts">
2
+ import { untrack } from 'svelte';
3
+ import type { CheckboxGroupRootProps } from '../types.js';
4
+ import { createCheckboxGroupContext, setCheckboxGroupContext } from './context.svelte';
5
+
6
+ const generatedId = $props.id();
7
+
8
+ let {
9
+ id,
10
+ value = $bindable(),
11
+ defaultValue,
12
+ onChange,
13
+ name,
14
+ disabled: disabledProp = false,
15
+ readonly: readOnlyProp = false,
16
+ required: requiredProp = false,
17
+ orientation = 'vertical',
18
+ children,
19
+ class: className = '',
20
+ element = $bindable<HTMLDivElement | null>(null),
21
+ context = $bindable(),
22
+ 'aria-labelledby': ariaLabelledBy,
23
+ ...restProps
24
+ }: CheckboxGroupRootProps = $props();
25
+
26
+ const instanceId = untrack(() => id) ?? generatedId;
27
+
28
+ let rootRef: HTMLDivElement | null = $state(null);
29
+
30
+ const checkboxGroup = setCheckboxGroupContext(
31
+ createCheckboxGroupContext({
32
+ // `value` seeds the initial selection whenever it is supplied, bound or not.
33
+ initialValue: untrack(() => value) ?? untrack(() => defaultValue),
34
+ name: (() => name)(),
35
+ isDisabled: (() => disabledProp)(),
36
+ isReadOnly: (() => readOnlyProp)(),
37
+ isRequired: (() => requiredProp)(),
38
+ orientation: (() => orientation)(),
39
+ onValueChange: (nextValue) => {
40
+ // One path for both usages: with `bind:value` this reaches the parent, and
41
+ // without a binding the write stays local, so nothing here has to know
42
+ // which one the caller chose.
43
+ value = nextValue;
44
+ onChange?.(nextValue);
45
+ }
46
+ })
47
+ );
48
+
49
+ context = checkboxGroup;
50
+
51
+ // Marks the window in which a checkbox disappearing is a real change rather than the group
52
+ // itself coming or going. `$effect.pre` because Svelte destroys an effect's children
53
+ // before running that effect's own teardown, so an `onDestroy` here would fire *after*
54
+ // every checkbox had already unregistered: this one is created while the script runs,
55
+ // before the children exist, so it is first in destroy order and its cleanup lands ahead
56
+ // of theirs. On the server it never runs, which is right too — there the checkboxes
57
+ // unregister as the markup closes and nobody is listening any more.
58
+ $effect.pre(() => {
59
+ checkboxGroup.setLive(true);
60
+ return () => checkboxGroup.setLive(false);
61
+ });
62
+
63
+ const disabled = $derived(checkboxGroup.isDisabled);
64
+ const readOnly = $derived(checkboxGroup.isReadOnly);
65
+ const required = $derived(checkboxGroup.isRequired);
66
+ const currentOrientation = $derived(checkboxGroup.orientation);
67
+
68
+ $effect(() => {
69
+ element = rootRef;
70
+ });
71
+
72
+ $effect(() => {
73
+ checkboxGroup.setName(name);
74
+ });
75
+
76
+ $effect(() => {
77
+ checkboxGroup.setDisabled(disabledProp);
78
+ });
79
+
80
+ $effect(() => {
81
+ checkboxGroup.setReadOnly(readOnlyProp);
82
+ });
83
+
84
+ $effect(() => {
85
+ checkboxGroup.setRequired(requiredProp);
86
+ });
87
+
88
+ $effect(() => {
89
+ checkboxGroup.setOrientation(orientation);
90
+ });
91
+
92
+ // A parent that supplies `value` drives the selection, bound or not. Latched at init,
93
+ // not reactive — re-checking `value !== undefined` would switch this on the moment our
94
+ // own write-back defines it, and a `defaultValue`-only group would start following the
95
+ // echo of its own changes.
96
+ const adoptsValueProp = untrack(() => value !== undefined);
97
+
98
+ $effect(() => {
99
+ if (!adoptsValueProp) return;
100
+ checkboxGroup.setSelectedValues(value);
101
+ });
102
+ </script>
103
+
104
+ <div
105
+ {...restProps}
106
+ bind:this={rootRef}
107
+ id={instanceId}
108
+ role="group"
109
+ aria-labelledby={ariaLabelledBy ?? checkboxGroup.labelledBy}
110
+ class={className}
111
+ data-checkbox-group-root="true"
112
+ data-orientation={currentOrientation}
113
+ data-disabled={disabled || undefined}
114
+ data-readonly={readOnly || undefined}
115
+ data-required={required || undefined}
116
+ >
117
+ {@render children?.()}
118
+ </div>
@@ -0,0 +1,4 @@
1
+ import type { CheckboxGroupRootProps } from '../types.js';
2
+ declare const CheckboxGroupRoot: import("svelte").Component<CheckboxGroupRootProps, {}, "value" | "element" | "context">;
3
+ type CheckboxGroupRoot = ReturnType<typeof CheckboxGroupRoot>;
4
+ export default CheckboxGroupRoot;
@@ -0,0 +1,52 @@
1
+ export type CheckboxGroupValue = string;
2
+ export type CheckboxGroupOrientation = 'horizontal' | 'vertical';
3
+ export type CreateCheckboxGroupContextOptions = {
4
+ initialValue?: CheckboxGroupValue[];
5
+ name?: string;
6
+ isDisabled?: boolean;
7
+ isReadOnly?: boolean;
8
+ isRequired?: boolean;
9
+ orientation?: CheckboxGroupOrientation;
10
+ onValueChange?: (value: CheckboxGroupValue[]) => void;
11
+ };
12
+ export type CheckboxGroupContext = {
13
+ name: string | undefined;
14
+ isDisabled: boolean;
15
+ isReadOnly: boolean;
16
+ isRequired: boolean;
17
+ orientation: CheckboxGroupOrientation;
18
+ /** The ids of the `CheckboxGroup.Label` parts, for `aria-labelledby` on the group. */
19
+ labelledBy: string | undefined;
20
+ selectedValues: Set<CheckboxGroupValue>;
21
+ /** Every registered checkbox is selected, and there is at least one. */
22
+ allSelected: boolean;
23
+ /** Some but not all registered checkboxes are selected. Drives a parent `indeterminate`. */
24
+ someSelected: boolean;
25
+ /** Registers a label id; the returned function unregisters it. */
26
+ registerLabel: (id: string) => () => void;
27
+ registerCheckbox: (value: CheckboxGroupValue, options: {
28
+ isDisabled?: boolean;
29
+ element?: HTMLElement | null;
30
+ owner?: symbol;
31
+ }) => void;
32
+ unregisterCheckbox: (value: CheckboxGroupValue) => void;
33
+ setLive: (live: boolean) => void;
34
+ setName: (name: string | undefined) => void;
35
+ setDisabled: (disabled: boolean) => void;
36
+ setReadOnly: (readonly: boolean) => void;
37
+ setRequired: (required: boolean) => void;
38
+ setOrientation: (orientation: CheckboxGroupOrientation) => void;
39
+ setSelectedValues: (value?: CheckboxGroupValue[]) => void;
40
+ toggleValue: (value: CheckboxGroupValue) => boolean | null;
41
+ setValueSelected: (value: CheckboxGroupValue, selected: boolean) => boolean | null;
42
+ selectAll: () => void;
43
+ clearAll: () => void;
44
+ isSelected: (value: CheckboxGroupValue) => boolean;
45
+ isCheckboxDisabled: (value: CheckboxGroupValue) => boolean;
46
+ getValue: () => CheckboxGroupValue[];
47
+ getEnabledValues: () => CheckboxGroupValue[];
48
+ };
49
+ export declare function valuesToArray(values: Set<CheckboxGroupValue>, order: CheckboxGroupValue[]): CheckboxGroupValue[];
50
+ export declare function createCheckboxGroupContext(options: CreateCheckboxGroupContextOptions): CheckboxGroupContext;
51
+ export declare function setCheckboxGroupContext(context: CheckboxGroupContext): CheckboxGroupContext;
52
+ export declare function getCheckboxGroupContext(): CheckboxGroupContext | undefined;
@@ -0,0 +1,251 @@
1
+ import { getContext, setContext, untrack } from 'svelte';
2
+ import { SvelteMap, SvelteSet } from 'svelte/reactivity';
3
+ import { asCommand } from '../../internal/as-command.js';
4
+ const CHECKBOX_GROUP_CONTEXT_KEY = Symbol('checkbox-group');
5
+ export function valuesToArray(values, order) {
6
+ const orderedValues = order.filter((value) => values.has(value));
7
+ const unknownValues = Array.from(values).filter((value) => !order.includes(value));
8
+ return [...orderedValues, ...unknownValues];
9
+ }
10
+ export function createCheckboxGroupContext(options) {
11
+ let name = $state(options.name);
12
+ let isDisabled = $state(options.isDisabled ?? false);
13
+ let isReadOnly = $state(options.isReadOnly ?? false);
14
+ let isRequired = $state(options.isRequired ?? false);
15
+ let orientation = $state(options.orientation ?? 'vertical');
16
+ let labelIds = $state([]);
17
+ // A `SvelteSet` carries its own reactivity, so it is mutated in place rather than
18
+ // reassigned: a plain Set behind `$state` would need a new instance for every change,
19
+ // and it would invalidate every reader of the group on each one.
20
+ const selectedValues = new SvelteSet(options.initialValue ?? []);
21
+ // Whether the group is mounted and interactive. Plain `let`, not `$state`: nothing renders
22
+ // from it, and the reads happen while checkboxes register and unregister, where a reactive
23
+ // read would only add a dependency.
24
+ let isLive = false;
25
+ const checkboxes = new SvelteMap();
26
+ const checkboxOrder = $state([]);
27
+ function getOrderedValues() {
28
+ const connected = [];
29
+ const detachedValues = [];
30
+ for (const value of checkboxOrder) {
31
+ const element = checkboxes.get(value)?.element;
32
+ if (element?.isConnected) {
33
+ connected.push({ value, element });
34
+ }
35
+ else {
36
+ detachedValues.push(value);
37
+ }
38
+ }
39
+ connected.sort((left, right) => left.element.compareDocumentPosition(right.element) & Node.DOCUMENT_POSITION_FOLLOWING
40
+ ? -1
41
+ : 1);
42
+ return [...connected.map((entry) => entry.value), ...detachedValues];
43
+ }
44
+ function getEnabledValues() {
45
+ return getOrderedValues().filter((value) => checkboxes.has(value) && !isCheckboxDisabled(value));
46
+ }
47
+ function getValue() {
48
+ return valuesToArray(selectedValues, getOrderedValues());
49
+ }
50
+ function setSelection(nextValues, changeOptions) {
51
+ const order = getOrderedValues();
52
+ const previousValue = valuesToArray(selectedValues, order);
53
+ const nextValue = valuesToArray(nextValues, order);
54
+ const didChange = previousValue.length !== nextValue.length ||
55
+ previousValue.some((value, index) => value !== nextValue[index]);
56
+ if (!didChange)
57
+ return false;
58
+ selectedValues.clear();
59
+ for (const value of nextValue) {
60
+ selectedValues.add(value);
61
+ }
62
+ if (changeOptions?.notify !== false) {
63
+ options.onValueChange?.(nextValue);
64
+ }
65
+ return true;
66
+ }
67
+ // Unlike `ToggleGroup`, a disabled checkbox keeps its selection: a checked and disabled
68
+ // checkbox is a real state the platform supports, and dropping it would silently rewrite
69
+ // the value a form was seeded with. Only a checkbox that leaves the tree leaves the value.
70
+ function reconcileSelection(removedValue, changeOptions) {
71
+ if (removedValue === undefined || checkboxes.has(removedValue))
72
+ return;
73
+ if (!selectedValues.has(removedValue))
74
+ return;
75
+ const nextValues = new SvelteSet(selectedValues);
76
+ nextValues.delete(removedValue);
77
+ setSelection(nextValues, changeOptions);
78
+ }
79
+ function registerCheckbox(value, registerOptions) {
80
+ const existingCheckbox = checkboxes.get(value);
81
+ if (existingCheckbox !== undefined &&
82
+ existingCheckbox.owner !== undefined &&
83
+ registerOptions.owner !== undefined &&
84
+ existingCheckbox.owner !== registerOptions.owner) {
85
+ throw new Error('Checkbox.Root values must be unique within a CheckboxGroup.Root.');
86
+ }
87
+ checkboxes.set(value, {
88
+ value,
89
+ isDisabled: Boolean(registerOptions.isDisabled),
90
+ element: registerOptions.element,
91
+ owner: registerOptions.owner
92
+ });
93
+ if (existingCheckbox === undefined) {
94
+ checkboxOrder.push(value);
95
+ }
96
+ }
97
+ // Turned on by the root as it renders and off as it goes away, which is the only way to
98
+ // tell the two unregistrations apart: a checkbox removed from a live group leaves a group
99
+ // behind that still has to show something, while a group on its way out has no one left
100
+ // to show anything to.
101
+ function setLive(live) {
102
+ isLive = live;
103
+ }
104
+ function unregisterCheckbox(value) {
105
+ if (!checkboxes.has(value))
106
+ return;
107
+ checkboxes.delete(value);
108
+ const index = checkboxOrder.indexOf(value);
109
+ if (index >= 0) {
110
+ checkboxOrder.splice(index, 1);
111
+ }
112
+ // Outside the live window the checkbox is leaving because the group is — on the client
113
+ // while it unmounts, on the server as the markup closes — and reporting a value change
114
+ // there would tell a consumer already on its way out that the user cleared a box.
115
+ if (!isLive)
116
+ return;
117
+ reconcileSelection(value);
118
+ }
119
+ function setName(nextName) {
120
+ if (name === nextName)
121
+ return;
122
+ name = nextName;
123
+ }
124
+ function setDisabled(disabled) {
125
+ if (isDisabled === disabled)
126
+ return;
127
+ isDisabled = disabled;
128
+ }
129
+ function setReadOnly(readonly) {
130
+ if (isReadOnly === readonly)
131
+ return;
132
+ isReadOnly = readonly;
133
+ }
134
+ function setRequired(required) {
135
+ if (isRequired === required)
136
+ return;
137
+ isRequired = required;
138
+ }
139
+ function setOrientation(nextOrientation) {
140
+ if (orientation === nextOrientation)
141
+ return;
142
+ orientation = nextOrientation;
143
+ }
144
+ function setSelectedValues(value) {
145
+ setSelection(new SvelteSet(value ?? []), { notify: false });
146
+ }
147
+ function setValueSelected(value, selected) {
148
+ if (isCheckboxDisabled(value) || isReadOnly)
149
+ return null;
150
+ if (selectedValues.has(value) === selected)
151
+ return null;
152
+ const nextValues = new SvelteSet(selectedValues);
153
+ if (selected) {
154
+ nextValues.add(value);
155
+ }
156
+ else {
157
+ nextValues.delete(value);
158
+ }
159
+ return setSelection(nextValues) ? selected : null;
160
+ }
161
+ function toggleValue(value) {
162
+ return setValueSelected(value, !selectedValues.has(value));
163
+ }
164
+ function selectAll() {
165
+ if (isReadOnly)
166
+ return;
167
+ const nextValues = new SvelteSet(selectedValues);
168
+ for (const value of getEnabledValues()) {
169
+ nextValues.add(value);
170
+ }
171
+ setSelection(nextValues);
172
+ }
173
+ function clearAll() {
174
+ if (isReadOnly)
175
+ return;
176
+ const nextValues = new SvelteSet(selectedValues);
177
+ for (const value of getEnabledValues()) {
178
+ nextValues.delete(value);
179
+ }
180
+ setSelection(nextValues);
181
+ }
182
+ function isSelected(value) {
183
+ return selectedValues.has(value);
184
+ }
185
+ function isCheckboxDisabled(value) {
186
+ return isDisabled || Boolean(checkboxes.get(value)?.isDisabled);
187
+ }
188
+ return {
189
+ get name() {
190
+ return name;
191
+ },
192
+ get isDisabled() {
193
+ return isDisabled;
194
+ },
195
+ get isReadOnly() {
196
+ return isReadOnly;
197
+ },
198
+ get isRequired() {
199
+ return isRequired;
200
+ },
201
+ get orientation() {
202
+ return orientation;
203
+ },
204
+ get labelledBy() {
205
+ return labelIds.length > 0 ? labelIds.join(' ') : undefined;
206
+ },
207
+ get selectedValues() {
208
+ return selectedValues;
209
+ },
210
+ get allSelected() {
211
+ return checkboxOrder.length > 0 && checkboxOrder.every((value) => selectedValues.has(value));
212
+ },
213
+ get someSelected() {
214
+ const selectedCount = checkboxOrder.filter((value) => selectedValues.has(value)).length;
215
+ return selectedCount > 0 && selectedCount < checkboxOrder.length;
216
+ },
217
+ // `untrack` because the caller registers from an effect: reading `labelIds` here would
218
+ // make that effect depend on what it writes, and the pair would run without end.
219
+ registerLabel(id) {
220
+ untrack(() => {
221
+ labelIds = [...labelIds, id];
222
+ });
223
+ return () => untrack(() => {
224
+ labelIds = labelIds.filter((candidate) => candidate !== id);
225
+ });
226
+ },
227
+ registerCheckbox: asCommand(registerCheckbox),
228
+ unregisterCheckbox: asCommand(unregisterCheckbox),
229
+ setLive: asCommand(setLive),
230
+ setName: asCommand(setName),
231
+ setDisabled: asCommand(setDisabled),
232
+ setReadOnly: asCommand(setReadOnly),
233
+ setRequired: asCommand(setRequired),
234
+ setOrientation: asCommand(setOrientation),
235
+ setSelectedValues: asCommand(setSelectedValues),
236
+ toggleValue: asCommand(toggleValue),
237
+ setValueSelected: asCommand(setValueSelected),
238
+ selectAll: asCommand(selectAll),
239
+ clearAll: asCommand(clearAll),
240
+ isSelected,
241
+ isCheckboxDisabled,
242
+ getValue,
243
+ getEnabledValues
244
+ };
245
+ }
246
+ export function setCheckboxGroupContext(context) {
247
+ return setContext(CHECKBOX_GROUP_CONTEXT_KEY, context);
248
+ }
249
+ export function getCheckboxGroupContext() {
250
+ return getContext(CHECKBOX_GROUP_CONTEXT_KEY);
251
+ }
@@ -0,0 +1,57 @@
1
+ import type { Snippet } from 'svelte';
2
+ import type { HTMLAttributes } from 'svelte/elements';
3
+ import type { CheckboxGroupContext, CheckboxGroupOrientation, CheckboxGroupValue } from './root/context.svelte.js';
4
+ export type { CheckboxGroupContext, CheckboxGroupOrientation, CheckboxGroupValue } from './root/context.svelte.js';
5
+ export type CheckboxGroupRootProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class'> & {
6
+ /**
7
+ * The selected values. When you give this prop, it is the source of truth, with `bind:value` or
8
+ * without it. The component writes each change here and reports it through `onChange`.
9
+ *
10
+ * Without a binding, that write stays local. Thus a parent that hears `onChange` and refuses the
11
+ * change — it sends no new `value` down — sees the group move. The group then goes back to the
12
+ * value of the parent at the next render.
13
+ */
14
+ value?: CheckboxGroupValue[];
15
+ /** The selected values at the start, for when you give no `value`. */
16
+ defaultValue?: CheckboxGroupValue[];
17
+ /** The component calls it when the user changes the selection. */
18
+ onChange?: (value: CheckboxGroupValue[]) => void;
19
+ /** The `name` of the hidden input of every checkbox in the group, for form submission. */
20
+ name?: string;
21
+ /** Disables each checkbox in the group. */
22
+ disabled?: boolean;
23
+ /** Shows the value of the group, and refuses each change from the user. */
24
+ readonly?: boolean;
25
+ /**
26
+ * Records that the group needs an answer. It gives `data-required` for your styles, and it
27
+ * does not enforce a minimum count. It marks neither the group nor the boxes with
28
+ * `aria-required`: `role="group"` does not support that property, and native `required` on a
29
+ * box demands that one box. Say it in the group label, and give the reason with
30
+ * `aria-describedby`.
31
+ */
32
+ required?: boolean;
33
+ /**
34
+ * The orientation of the layout. It sets `data-orientation` for your styles. It does not change
35
+ * the keyboard behavior: each checkbox keeps its own tab stop.
36
+ */
37
+ orientation?: CheckboxGroupOrientation;
38
+ /** The checkboxes of the group. */
39
+ children?: Snippet;
40
+ class?: string;
41
+ /** The id of the group element. The component makes one when you give none. */
42
+ id?: string;
43
+ /** The group element. Use `bind:element` to read it. */
44
+ element?: HTMLDivElement | null;
45
+ /**
46
+ * The state of the group. Use `bind:context` to read `allSelected` and `someSelected` for a
47
+ * parent "select all" checkbox, and to call `selectAll` and `clearAll`.
48
+ */
49
+ context?: CheckboxGroupContext;
50
+ };
51
+ export type CheckboxGroupLabelProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children' | 'class' | 'id'> & {
52
+ /** The name of the group. */
53
+ children?: Snippet;
54
+ class?: string;
55
+ /** The id of the label element. The component makes one when you give none. */
56
+ id?: string;
57
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -3,6 +3,7 @@
3
3
  import { useComboBoxContext } from '../root/context';
4
4
  import { Popover } from '../../popover';
5
5
  import { focusWithModality, type InputModality } from '../../primitives/input-modality';
6
+ import { containWheel } from '../../primitives/contain-wheel';
6
7
  import type { PopoverOpenChangeDetails } from '../../popover/root/context';
7
8
 
8
9
  /**
@@ -98,65 +99,12 @@
98
99
  };
99
100
  }
100
101
 
101
- function canElementScrollInDirection(element: HTMLElement, deltaY: number) {
102
- const isScrollingDown = deltaY > 0;
103
- const isScrollingUp = deltaY < 0;
104
- const canScrollDown = element.scrollTop < element.scrollHeight - element.clientHeight;
105
- const canScrollUp = element.scrollTop > 0;
106
-
107
- return (isScrollingDown && canScrollDown) || (isScrollingUp && canScrollUp);
108
- }
109
-
110
- function isScrollableElement(element: HTMLElement) {
111
- const { overflowY } = getComputedStyle(element);
112
- return (
113
- ['auto', 'scroll', 'overlay'].includes(overflowY) &&
114
- element.scrollHeight > element.clientHeight
115
- );
116
- }
117
-
118
- function hasScrollableDescendantForWheel(
119
- boundary: HTMLElement,
120
- target: EventTarget | null,
121
- deltaY: number
122
- ) {
123
- let current =
124
- target instanceof HTMLElement ? target : target instanceof Node ? target.parentElement : null;
125
-
126
- while (current) {
127
- if (isScrollableElement(current) && canElementScrollInDirection(current, deltaY)) {
128
- return true;
129
- }
130
-
131
- if (current === boundary) {
132
- break;
133
- }
134
-
135
- current = current.parentElement;
136
- }
137
-
138
- return false;
139
- }
140
-
141
- /**
142
- * Prevent wheel/scroll events from propagating to the page
143
- * This keeps the page from scrolling when scrolling over the popover
144
- * But allows internal scrolling when either the popover or a descendant owns overflow
145
- */
102
+ // The page must not scroll under the popover, and a scroll of the page closes it. The
103
+ // wheel scrolls the panel, or a scrollable element inside it, while one of them can move.
146
104
  function handleWheel(event: WheelEvent) {
147
105
  const element = event.currentTarget as HTMLElement;
148
106
  if (!element) return;
149
-
150
- if (
151
- hasScrollableDescendantForWheel(element, event.target, event.deltaY) ||
152
- (isScrollableElement(element) && canElementScrollInDirection(element, event.deltaY))
153
- ) {
154
- event.stopPropagation();
155
- return;
156
- }
157
-
158
- event.preventDefault();
159
- event.stopPropagation();
107
+ containWheel(event, element);
160
108
  }
161
109
 
162
110
  $effect(() => {
@@ -2,6 +2,7 @@
2
2
  import { tick, untrack, type Snippet } from 'svelte';
3
3
  import { setDialogContext, type DialogContext } from './context';
4
4
  import type { DialogStateHelpers } from './types';
5
+ import { focusFellToBody } from '../../primitives/trigger-focus-state';
5
6
  import {
6
7
  focusWithModality,
7
8
  resolveCloseInteractionModality
@@ -95,8 +96,20 @@
95
96
  */
96
97
  function restoreFocusTo(
97
98
  target: HTMLElement,
98
- modality: ReturnType<typeof resolveCloseInteractionModality>
99
+ modality: ReturnType<typeof resolveCloseInteractionModality>,
100
+ reason: string = 'imperative-action'
99
101
  ) {
102
+ // An outside press moves the focus after this runs: the browser sends it to the
103
+ // pressed element, and to the body when that element takes no focus — which is every
104
+ // element outside a modal, since the page is inert. A restore made now is undone a
105
+ // moment later, so it waits a frame and then fills the gap the press left.
106
+ if (reason === 'outside-press') {
107
+ requestAnimationFrame(() => {
108
+ if (!target.isConnected || !focusFellToBody()) return;
109
+ focusWithModality(target, modality);
110
+ });
111
+ return;
112
+ }
100
113
  focusWithModality(target, modality);
101
114
  if (document.activeElement === target) return;
102
115
 
@@ -113,7 +126,7 @@
113
126
  // back down) — don't steal focus while the dialog is still open.
114
127
  if (!wasOpen || isOpen) return;
115
128
  if (triggerRef) {
116
- restoreFocusTo(triggerRef, resolveCloseInteractionModality(reason, event));
129
+ restoreFocusTo(triggerRef, resolveCloseInteractionModality(reason, event), reason);
117
130
  }
118
131
  }
119
132
 
@@ -14,6 +14,7 @@
14
14
  DrawerStateHelpers
15
15
  } from './types';
16
16
  import type { DrawerHandle } from './handle.svelte';
17
+ import { focusFellToBody } from '../../primitives/trigger-focus-state';
17
18
  import {
18
19
  focusWithModality,
19
20
  resolveCloseInteractionModality
@@ -184,8 +185,20 @@
184
185
  */
185
186
  function restoreFocusTo(
186
187
  target: HTMLElement,
187
- modality: ReturnType<typeof resolveCloseInteractionModality>
188
+ modality: ReturnType<typeof resolveCloseInteractionModality>,
189
+ reason: string = 'imperative-action'
188
190
  ) {
191
+ // An outside press moves the focus after this runs: the browser sends it to the
192
+ // pressed element, and to the body when that element takes no focus — which is every
193
+ // element outside a modal, since the page is inert. A restore made now is undone a
194
+ // moment later, so it waits a frame and then fills the gap the press left.
195
+ if (reason === 'outside-press') {
196
+ requestAnimationFrame(() => {
197
+ if (!target.isConnected || !focusFellToBody()) return;
198
+ focusWithModality(target, modality);
199
+ });
200
+ return;
201
+ }
189
202
  focusWithModality(target, modality);
190
203
  if (document.activeElement === target) return;
191
204
 
@@ -205,7 +218,7 @@
205
218
  // whichever one happened to register itself last.
206
219
  const restoreTarget = handle?.trigger ?? triggerRef;
207
220
  if (restoreTarget) {
208
- restoreFocusTo(restoreTarget, resolveCloseInteractionModality(reason, event));
221
+ restoreFocusTo(restoreTarget, resolveCloseInteractionModality(reason, event), reason);
209
222
  }
210
223
  }
211
224