@human-kit/ui 1.0.0-beta.9 → 1.1.0

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 (110) hide show
  1. package/README.md +27 -60
  2. package/dist/FOCUS_STATE_CONTRACT.md +1 -0
  3. package/dist/color-picker/README.md +78 -0
  4. package/dist/color-picker/area/color-picker-area.svelte +195 -0
  5. package/dist/color-picker/area/color-picker-area.svelte.d.ts +4 -0
  6. package/dist/color-picker/area-thumb/color-picker-area-thumb.svelte +231 -0
  7. package/dist/color-picker/area-thumb/color-picker-area-thumb.svelte.d.ts +4 -0
  8. package/dist/color-picker/channel-field/color-picker-channel-field.svelte +95 -0
  9. package/dist/color-picker/channel-field/color-picker-channel-field.svelte.d.ts +4 -0
  10. package/dist/color-picker/eye-dropper/color-picker-eye-dropper.svelte +79 -0
  11. package/dist/color-picker/eye-dropper/color-picker-eye-dropper.svelte.d.ts +4 -0
  12. package/dist/color-picker/hex-field/color-picker-hex-field.svelte +105 -0
  13. package/dist/color-picker/hex-field/color-picker-hex-field.svelte.d.ts +4 -0
  14. package/dist/color-picker/index.d.ts +16 -0
  15. package/dist/color-picker/index.js +15 -0
  16. package/dist/color-picker/index.parts.d.ts +12 -0
  17. package/dist/color-picker/index.parts.js +12 -0
  18. package/dist/color-picker/label/color-picker-label.svelte +34 -0
  19. package/dist/color-picker/label/color-picker-label.svelte.d.ts +4 -0
  20. package/dist/color-picker/preview/color-picker-preview.svelte +43 -0
  21. package/dist/color-picker/preview/color-picker-preview.svelte.d.ts +4 -0
  22. package/dist/color-picker/root/color-picker-root.svelte +365 -0
  23. package/dist/color-picker/root/color-picker-root.svelte.d.ts +4 -0
  24. package/dist/color-picker/root/color.d.ts +68 -0
  25. package/dist/color-picker/root/color.js +266 -0
  26. package/dist/color-picker/root/context.d.ts +127 -0
  27. package/dist/color-picker/root/context.js +44 -0
  28. package/dist/color-picker/slider/color-picker-slider.svelte +188 -0
  29. package/dist/color-picker/slider/color-picker-slider.svelte.d.ts +4 -0
  30. package/dist/color-picker/slider-thumb/color-picker-slider-thumb.svelte +208 -0
  31. package/dist/color-picker/slider-thumb/color-picker-slider-thumb.svelte.d.ts +4 -0
  32. package/dist/color-picker/swatch/color-picker-swatch.svelte +149 -0
  33. package/dist/color-picker/swatch/color-picker-swatch.svelte.d.ts +4 -0
  34. package/dist/color-picker/swatch-list/color-picker-swatch-list.svelte +133 -0
  35. package/dist/color-picker/swatch-list/color-picker-swatch-list.svelte.d.ts +4 -0
  36. package/dist/color-picker/types.d.ts +176 -0
  37. package/dist/color-picker/types.js +1 -0
  38. package/dist/index.d.ts +8 -0
  39. package/dist/index.js +8 -0
  40. package/dist/internal/localized-strings.d.ts +152 -0
  41. package/dist/internal/localized-strings.js +152 -0
  42. package/dist/pin-input/README.md +55 -0
  43. package/dist/pin-input/cell/pin-input-cell.svelte +210 -0
  44. package/dist/pin-input/cell/pin-input-cell.svelte.d.ts +4 -0
  45. package/dist/pin-input/index.d.ts +6 -0
  46. package/dist/pin-input/index.js +5 -0
  47. package/dist/pin-input/index.parts.d.ts +3 -0
  48. package/dist/pin-input/index.parts.js +3 -0
  49. package/dist/pin-input/label/pin-input-label.svelte +43 -0
  50. package/dist/pin-input/label/pin-input-label.svelte.d.ts +4 -0
  51. package/dist/pin-input/root/context.d.ts +70 -0
  52. package/dist/pin-input/root/context.js +15 -0
  53. package/dist/pin-input/root/pin-input-root.svelte +337 -0
  54. package/dist/pin-input/root/pin-input-root.svelte.d.ts +4 -0
  55. package/dist/pin-input/root/pin-input-utils.d.ts +18 -0
  56. package/dist/pin-input/root/pin-input-utils.js +44 -0
  57. package/dist/pin-input/types.d.ts +84 -0
  58. package/dist/pin-input/types.js +1 -0
  59. package/dist/rating/README.md +58 -0
  60. package/dist/rating/index.d.ts +7 -0
  61. package/dist/rating/index.js +6 -0
  62. package/dist/rating/index.parts.d.ts +4 -0
  63. package/dist/rating/index.parts.js +4 -0
  64. package/dist/rating/item/rating-item.svelte +177 -0
  65. package/dist/rating/item/rating-item.svelte.d.ts +4 -0
  66. package/dist/rating/label/rating-label.svelte +42 -0
  67. package/dist/rating/label/rating-label.svelte.d.ts +4 -0
  68. package/dist/rating/output/rating-output.svelte +38 -0
  69. package/dist/rating/output/rating-output.svelte.d.ts +4 -0
  70. package/dist/rating/root/context.d.ts +87 -0
  71. package/dist/rating/root/context.js +15 -0
  72. package/dist/rating/root/rating-root.svelte +521 -0
  73. package/dist/rating/root/rating-root.svelte.d.ts +4 -0
  74. package/dist/rating/root/rating-utils.d.ts +28 -0
  75. package/dist/rating/root/rating-utils.js +53 -0
  76. package/dist/rating/types.d.ts +124 -0
  77. package/dist/rating/types.js +1 -0
  78. package/dist/search-field/README.md +29 -0
  79. package/dist/search-field/clear/README.md +5 -0
  80. package/dist/search-field/clear/search-field-clear.svelte +99 -0
  81. package/dist/search-field/clear/search-field-clear.svelte.d.ts +10 -0
  82. package/dist/search-field/index.d.ts +15 -0
  83. package/dist/search-field/index.js +6 -0
  84. package/dist/search-field/index.parts.d.ts +4 -0
  85. package/dist/search-field/index.parts.js +4 -0
  86. package/dist/search-field/input/README.md +5 -0
  87. package/dist/search-field/input/search-field-input.svelte +158 -0
  88. package/dist/search-field/input/search-field-input.svelte.d.ts +14 -0
  89. package/dist/search-field/label/README.md +3 -0
  90. package/dist/search-field/label/search-field-label.svelte +27 -0
  91. package/dist/search-field/label/search-field-label.svelte.d.ts +7 -0
  92. package/dist/search-field/root/README.md +5 -0
  93. package/dist/search-field/root/context.d.ts +28 -0
  94. package/dist/search-field/root/context.js +15 -0
  95. package/dist/search-field/root/search-field-root.svelte +230 -0
  96. package/dist/search-field/root/search-field-root.svelte.d.ts +33 -0
  97. package/dist/table/README.md +62 -2
  98. package/dist/table/body/table-body.svelte +57 -4
  99. package/dist/table/index.d.ts +2 -1
  100. package/dist/table/index.js +1 -0
  101. package/dist/table/index.parts.d.ts +1 -0
  102. package/dist/table/index.parts.js +1 -0
  103. package/dist/table/root/context.svelte.d.ts +18 -0
  104. package/dist/table/root/context.svelte.js +104 -12
  105. package/dist/table/section-row/README.md +31 -0
  106. package/dist/table/section-row/table-section-row.svelte +201 -0
  107. package/dist/table/section-row/table-section-row.svelte.d.ts +4 -0
  108. package/dist/table/types.d.ts +26 -0
  109. package/dist/tooltip/root/tooltip-root.svelte +16 -11
  110. package/package.json +21 -1
@@ -0,0 +1,230 @@
1
+ <script lang="ts">
2
+ import { readable } from 'svelte/store';
3
+ import { untrack, type Snippet } from 'svelte';
4
+ import type { HTMLAttributes } from 'svelte/elements';
5
+ import { resolveLocalizedString } from '../../internal/localized-strings';
6
+ import { useLocaleContextOptional } from '../../locale-provider/context';
7
+ import { isAriaInvalidValue } from '../../utils/aria-invalid';
8
+ import { composeEventHandlers } from '../../utils/compose-event-handlers';
9
+ import {
10
+ setSearchFieldContext,
11
+ type SearchFieldChangeReason,
12
+ type SearchFieldContext
13
+ } from './context';
14
+
15
+ type SearchFieldRootProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class' | 'id'> & {
16
+ children?: Snippet;
17
+ class?: string;
18
+ /** The id of the root element. If you give none, the component makes one. */
19
+ id?: string;
20
+ /** The search text. You can bind it with `bind:value`. */
21
+ value?: string;
22
+ /** The search text at the start, for when you give no `value`. A form reset goes back to it. */
23
+ defaultValue?: string;
24
+ /** The component calls it when the search text changes. */
25
+ onChange?: (value: string) => void;
26
+ /** The component calls it with the search text when the user presses `Enter` in the input. */
27
+ onSubmit?: (value: string) => void;
28
+ /** The component calls it after the `Escape` key or the clear button empties the input. */
29
+ onClear?: () => void;
30
+ /** Disables the input and the clear button. */
31
+ disabled?: boolean;
32
+ /** The user cannot change the text. The `Escape` key and the clear button do nothing. */
33
+ readonly?: boolean;
34
+ /** Tells a form that it must have a value. The input gets the native `required`. */
35
+ required?: boolean;
36
+ /** Marks the value as invalid. The input gets `aria-invalid`. */
37
+ invalid?: boolean;
38
+ /** Marks the value as invalid, the same as `invalid`. */
39
+ 'aria-invalid'?: HTMLAttributes<HTMLDivElement>['aria-invalid'];
40
+ /** The name of the input in a form. The form submits the search text with this name. */
41
+ name?: string;
42
+ };
43
+
44
+ const generatedId = $props.id();
45
+ const localeContext = useLocaleContextOptional();
46
+ const emptyLocaleStore = readable<string | undefined>(undefined);
47
+ const localeStore = localeContext?.locale ?? emptyLocaleStore;
48
+
49
+ let {
50
+ children,
51
+ class: className,
52
+ id,
53
+ value = $bindable<string | undefined>(undefined),
54
+ defaultValue = '',
55
+ onChange,
56
+ onSubmit,
57
+ onClear,
58
+ disabled = false,
59
+ readonly = false,
60
+ required = false,
61
+ invalid = false,
62
+ 'aria-invalid': ariaInvalid,
63
+ name,
64
+ onfocusin: onFocusInExternal,
65
+ onfocusout: onFocusOutExternal,
66
+ ...restProps
67
+ }: SearchFieldRootProps = $props();
68
+
69
+ const rootId = untrack(() => id) ?? generatedId;
70
+ const inputId = `${rootId}-input`;
71
+ const initialDefaultValue = untrack(() => defaultValue) ?? '';
72
+
73
+ const initialValue = untrack(() => value) ?? initialDefaultValue;
74
+
75
+ let currentValue = $state(initialValue);
76
+ let focused = $state(false);
77
+ let focusVisible = $state(false);
78
+ let focusWithin = $state(false);
79
+ let inputRef: HTMLInputElement | null = $state(null);
80
+
81
+ if (untrack(() => value) === undefined) {
82
+ value = initialValue;
83
+ }
84
+
85
+ // A new value from the parent replaces the text. The text that the user types goes to the
86
+ // parent through `setValue`, thus the two stay equal and this does nothing for it.
87
+ $effect(() => {
88
+ const next = value ?? '';
89
+ untrack(() => {
90
+ if (next !== currentValue) currentValue = next;
91
+ });
92
+ });
93
+
94
+ const isEmpty = $derived(currentValue === '');
95
+ const resolvedInvalid = $derived(Boolean(invalid || isAriaInvalidValue(ariaInvalid)));
96
+ const clearAriaLabel = $derived(resolveLocalizedString($localeStore, 'searchField.clear'));
97
+
98
+ $effect(() => {
99
+ if (!disabled) return;
100
+ focused = false;
101
+ focusVisible = false;
102
+ focusWithin = false;
103
+ });
104
+
105
+ $effect(() => {
106
+ const form = inputRef?.form;
107
+ if (!form) return;
108
+
109
+ // The browser puts `defaultValue` back in the input, but it sends no `input` event.
110
+ const handleFormReset = () => setValue(initialDefaultValue, 'form-reset');
111
+
112
+ form.addEventListener('reset', handleFormReset);
113
+ return () => form.removeEventListener('reset', handleFormReset);
114
+ });
115
+
116
+ function setValue(next: string, reason: SearchFieldChangeReason) {
117
+ if (reason !== 'form-reset' && (disabled || readonly)) return;
118
+ if (next === currentValue) return;
119
+
120
+ currentValue = next;
121
+ value = next;
122
+ onChange?.(next);
123
+ }
124
+
125
+ function clear(reason: 'escape-key' | 'clear-press'): boolean {
126
+ if (disabled || readonly) return false;
127
+ // The text can be in the input and not in the state, when a script wrote `input.value`.
128
+ if (currentValue === '' && (!inputRef || inputRef.value === '')) return false;
129
+
130
+ setValue('', reason);
131
+ if (inputRef && inputRef.value !== '') inputRef.value = '';
132
+ onClear?.();
133
+ return true;
134
+ }
135
+
136
+ function submit() {
137
+ if (disabled || readonly) return;
138
+ onSubmit?.(currentValue);
139
+ }
140
+
141
+ function handleFocusIn() {
142
+ if (disabled) return;
143
+ focusWithin = true;
144
+ }
145
+
146
+ function handleFocusOut(event: FocusEvent) {
147
+ const root = event.currentTarget as HTMLElement;
148
+ const next = event.relatedTarget as Node | null;
149
+ if (next && root.contains(next)) return;
150
+ focusWithin = false;
151
+ }
152
+
153
+ const context: SearchFieldContext = {
154
+ get id() {
155
+ return rootId;
156
+ },
157
+ get inputId() {
158
+ return inputId;
159
+ },
160
+ get value() {
161
+ return currentValue;
162
+ },
163
+ get defaultValue() {
164
+ return initialDefaultValue;
165
+ },
166
+ get name() {
167
+ return name;
168
+ },
169
+ get isEmpty() {
170
+ return isEmpty;
171
+ },
172
+ get isDisabled() {
173
+ return disabled;
174
+ },
175
+ get isReadOnly() {
176
+ return readonly;
177
+ },
178
+ get isRequired() {
179
+ return required;
180
+ },
181
+ get isInvalid() {
182
+ return resolvedInvalid;
183
+ },
184
+ get clearAriaLabel() {
185
+ return clearAriaLabel;
186
+ },
187
+ get focused() {
188
+ return focused;
189
+ },
190
+ get focusVisible() {
191
+ return focusVisible;
192
+ },
193
+ get inputRef() {
194
+ return inputRef;
195
+ },
196
+ setInputRef(element) {
197
+ inputRef = element;
198
+ },
199
+ setFocused(next) {
200
+ focused = next;
201
+ if (!next) focusVisible = false;
202
+ },
203
+ setFocusVisible(next) {
204
+ focusVisible = next;
205
+ },
206
+ setValue,
207
+ clear,
208
+ submit
209
+ };
210
+
211
+ setSearchFieldContext(context);
212
+ </script>
213
+
214
+ <div
215
+ {...restProps}
216
+ id={rootId}
217
+ class={className}
218
+ data-search-field-root="true"
219
+ data-empty={isEmpty || undefined}
220
+ data-disabled={disabled || undefined}
221
+ data-readonly={readonly || undefined}
222
+ data-required={required || undefined}
223
+ data-invalid={resolvedInvalid || undefined}
224
+ data-focus-within={focusWithin || undefined}
225
+ data-focus-visible={(focusWithin && focusVisible) || undefined}
226
+ onfocusin={composeEventHandlers(handleFocusIn, onFocusInExternal ?? undefined)}
227
+ onfocusout={composeEventHandlers(handleFocusOut, onFocusOutExternal ?? undefined)}
228
+ >
229
+ {@render children?.()}
230
+ </div>
@@ -0,0 +1,33 @@
1
+ import { type Snippet } from 'svelte';
2
+ import type { HTMLAttributes } from 'svelte/elements';
3
+ type SearchFieldRootProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class' | 'id'> & {
4
+ children?: Snippet;
5
+ class?: string;
6
+ /** The id of the root element. If you give none, the component makes one. */
7
+ id?: string;
8
+ /** The search text. You can bind it with `bind:value`. */
9
+ value?: string;
10
+ /** The search text at the start, for when you give no `value`. A form reset goes back to it. */
11
+ defaultValue?: string;
12
+ /** The component calls it when the search text changes. */
13
+ onChange?: (value: string) => void;
14
+ /** The component calls it with the search text when the user presses `Enter` in the input. */
15
+ onSubmit?: (value: string) => void;
16
+ /** The component calls it after the `Escape` key or the clear button empties the input. */
17
+ onClear?: () => void;
18
+ /** Disables the input and the clear button. */
19
+ disabled?: boolean;
20
+ /** The user cannot change the text. The `Escape` key and the clear button do nothing. */
21
+ readonly?: boolean;
22
+ /** Tells a form that it must have a value. The input gets the native `required`. */
23
+ required?: boolean;
24
+ /** Marks the value as invalid. The input gets `aria-invalid`. */
25
+ invalid?: boolean;
26
+ /** Marks the value as invalid, the same as `invalid`. */
27
+ 'aria-invalid'?: HTMLAttributes<HTMLDivElement>['aria-invalid'];
28
+ /** The name of the input in a form. The form submits the search text with this name. */
29
+ name?: string;
30
+ };
31
+ declare const SearchFieldRoot: import("svelte").Component<SearchFieldRootProps, {}, "value">;
32
+ type SearchFieldRoot = ReturnType<typeof SearchFieldRoot>;
33
+ export default SearchFieldRoot;
@@ -9,7 +9,7 @@
9
9
  The table barrel exports the prop types of each public Table part.
10
10
 
11
11
  These are `TableRootProps`, `TableColumnProps`, `TableHeaderProps`, `TableBodyProps`,
12
- `TableFooterProps`, `TableRowProps`, `TableColumnHeaderCellProps`, `TableSortTriggerProps`,
12
+ `TableFooterProps`, `TableRowProps`, `TableSectionRowProps`, `TableColumnHeaderCellProps`, `TableSortTriggerProps`,
13
13
  `TableColumnResizerProps`, `TableCellProps`, `TableEmptyStateProps`, `TableCheckboxProps`,
14
14
  and `TableCheckboxIndicatorProps`.
15
15
 
@@ -82,6 +82,7 @@ and `TableCheckboxIndicatorProps`.
82
82
  - `Table.EmptyState`
83
83
  - `Table.Footer`
84
84
  - `Table.Row`
85
+ - `Table.SectionRow`
85
86
  - `Table.ColumnHeaderCell`
86
87
  - `Table.SortTrigger`
87
88
  - `Table.ColumnResizer`
@@ -124,9 +125,68 @@ and `TableCheckboxIndicatorProps`.
124
125
  - In body rows, pressing `ArrowLeft` before the first cell or `ArrowRight` after the last cell moves focus to the row itself. Repeating that same horizontal arrow loops back into the opposite edge cell of the same row.
125
126
  - `Table.Checkbox` is the supported interactive control inside table cells for explicit row selection in v1.
126
127
 
128
+ ## Grouped lists
129
+
130
+ Use `Table.SectionRow` to show a list in groups. A section row is a full-width header row between the body rows. It has one cell, and that cell covers all the visible columns, also the selection column.
131
+
132
+ Put the groups and their rows in one `items` array. In the `children` snippet of `Table.Body`, render a `Table.SectionRow` for each group item and a `Table.Row` for each other item. To close a group, remove its rows from `items`.
133
+
134
+ ```svelte
135
+ <script lang="ts">
136
+ type Item =
137
+ | { id: string; kind: 'group'; label: string; count: number }
138
+ | { id: string; kind: 'user'; email: string };
139
+
140
+ let collapsed = $state(new Set<string>());
141
+
142
+ const items = $derived(
143
+ groups.flatMap((group): Item[] => [
144
+ { id: `group-${group.name}`, kind: 'group', label: group.name, count: group.users.length },
145
+ ...(collapsed.has(group.name)
146
+ ? []
147
+ : group.users.map((user): Item => ({ id: user.id, kind: 'user', email: user.email })))
148
+ ])
149
+ );
150
+
151
+ function toggle(name: string) {
152
+ const next = new Set(collapsed);
153
+ if (next.has(name)) next.delete(name);
154
+ else next.add(name);
155
+ collapsed = next;
156
+ }
157
+ </script>
158
+
159
+ <Table.Body {items} isSectionItem={(item) => item.kind === 'group'}>
160
+ {#snippet children(item)}
161
+ {#if item.kind === 'group'}
162
+ <Table.SectionRow
163
+ id={item.id}
164
+ aria-expanded={!collapsed.has(item.label)}
165
+ onAction={() => toggle(item.label)}
166
+ >
167
+ <ChevronIcon />
168
+ {item.label}
169
+ <span>{item.count}</span>
170
+ </Table.SectionRow>
171
+ {:else}
172
+ <Table.Row id={item.id}>
173
+ <Table.Cell>{item.email}</Table.Cell>
174
+ </Table.Row>
175
+ {/if}
176
+ {/snippet}
177
+ </Table.Body>
178
+ ```
179
+
180
+ - A section row is a row for the keyboard. `ArrowUp` and `ArrowDown` move into it and out of it. Under `keyboardNavigation="grid"` its single cell takes the focus, and `Home`, `End`, `ArrowLeft` and `ArrowRight` keep the focus on that cell. Under `keyboardNavigation="row"` the row takes the focus, as other rows do.
181
+ - A section row is not a data row. It has no checkbox, and it is not in the selection. Select-all, the range selection with `Shift`, and the header checkbox do not include it.
182
+ - A click, `Enter` or `Space` calls `onAction` of the section row. The table does not call `onRowAction` for a section row.
183
+ - A mounted section row tells the table that it is a section row. With a virtualizer, also set `isSectionItem` on `Table.Body`, because the table does not know the section rows that are not mounted.
184
+ - With a virtualizer, set `sectionRowHeight` when a section row has a different height from `rowHeight`. This also needs `isSectionItem`. Give the rows the same heights in CSS.
185
+ - The cell is not sticky. In a table with pinned columns, add `sticky left-0` (or a similar class) to the content of the section row to keep it in view.
186
+
127
187
  ## Composition contract
128
188
 
129
- - DOM-rendering parts: `Table.Root`, `Table.Header`, `Table.Body`, `Table.Footer`, `Table.Row`, `Table.Cell`, `Table.InteractiveCell`, `Table.ColumnHeaderCell`, `Table.ColumnResizer`, `Table.Checkbox`, `Table.CheckboxIndicator`, and `Table.EmptyState` all render DOM.
189
+ - DOM-rendering parts: `Table.Root`, `Table.Header`, `Table.Body`, `Table.Footer`, `Table.Row`, `Table.SectionRow`, `Table.Cell`, `Table.InteractiveCell`, `Table.ColumnHeaderCell`, `Table.ColumnResizer`, `Table.Checkbox`, `Table.CheckboxIndicator`, and `Table.EmptyState` all render DOM.
130
190
  - Metadata-only part: `Table.Column` does not render its own element. It only registers the public column input for the surrounding header composition.
131
191
  - Sorting: `Table.SortTrigger` is the public opt-in for sortable columns. Rendering it inside `Table.ColumnHeaderCell` makes the owning `Table.Column` sortable and toggles `Table.Root.sortDescriptor`.
132
192
  - `Table.SortTrigger.children` can consume a `sortDirection` render state so the trigger button can expose stateful labels or visuals without reading the root descriptor directly.
@@ -9,6 +9,7 @@
9
9
  let {
10
10
  items,
11
11
  virtualizer,
12
+ isSectionItem,
12
13
  children,
13
14
  empty,
14
15
  class: className = '',
@@ -31,6 +32,17 @@
31
32
  };
32
33
  });
33
34
 
35
+ $effect(() => {
36
+ table.setSectionRowKeys(
37
+ isSectionItem && items
38
+ ? items.filter((item) => isSectionItem(item)).map((item) => item.id)
39
+ : undefined
40
+ );
41
+ return () => {
42
+ table.setSectionRowKeys(undefined);
43
+ };
44
+ });
45
+
34
46
  const itemList = $derived(items ?? []);
35
47
  const isItemsMode = $derived(items !== undefined);
36
48
  const virtualizerEnabled = $derived(Boolean(virtualizer && itemList.length > 0));
@@ -77,6 +89,39 @@
77
89
  return 18;
78
90
  });
79
91
 
92
+ /**
93
+ * Top offset of each item (and, last, the total height) when section rows
94
+ * have a height of their own. `undefined` keeps the uniform path, where the
95
+ * offsets are plain multiples of `rowHeight`.
96
+ */
97
+ const rowOffsets = $derived.by(() => {
98
+ if (!virtualizer || !virtualizerEnabled || !isSectionItem) return undefined;
99
+ const { rowHeight, sectionRowHeight } = virtualizer;
100
+ if (sectionRowHeight === undefined || sectionRowHeight === rowHeight) return undefined;
101
+
102
+ const offsets = new Float64Array(itemList.length + 1);
103
+ for (let index = 0; index < itemList.length; index += 1) {
104
+ const height = isSectionItem(itemList[index]) ? sectionRowHeight : rowHeight;
105
+ offsets[index + 1] = offsets[index] + height;
106
+ }
107
+ return offsets;
108
+ });
109
+
110
+ /** Index of the item whose box contains `offset` (the last one past the end). */
111
+ function findItemIndexAt(offsets: Float64Array, offset: number) {
112
+ let low = 0;
113
+ let high = offsets.length - 2;
114
+ while (low < high) {
115
+ const middle = Math.ceil((low + high) / 2);
116
+ if (offsets[middle] <= offset) {
117
+ low = middle;
118
+ } else {
119
+ high = middle - 1;
120
+ }
121
+ }
122
+ return low;
123
+ }
124
+
80
125
  // Plain (non-reactive) memo of the last window, used only to keep the derived
81
126
  // value's identity stable across recomputations that produce the same window.
82
127
  let lastVisibleRange:
@@ -94,8 +139,14 @@
94
139
 
95
140
  const rowHeight = virtualizer.rowHeight;
96
141
  const rowCount = itemList.length;
97
- const startIndex = Math.min(rowCount - 1, Math.floor(Math.max(0, scrollTop) / rowHeight));
98
- const endIndex = Math.min(rowCount - 1, startIndex + visibleCount - 1);
142
+ const offsets = rowOffsets;
143
+ const viewportTop = Math.max(0, scrollTop);
144
+ const startIndex = offsets
145
+ ? findItemIndexAt(offsets, viewportTop)
146
+ : Math.min(rowCount - 1, Math.floor(viewportTop / rowHeight));
147
+ const endIndex = offsets
148
+ ? findItemIndexAt(offsets, viewportTop + effectiveViewportHeight)
149
+ : Math.min(rowCount - 1, startIndex + visibleCount - 1);
99
150
 
100
151
  // Snap the window edges to a block boundary so scrolling *within* a block
101
152
  // leaves the rendered set identical.
@@ -130,8 +181,10 @@
130
181
  const from = Math.max(0, Math.floor(rawFrom / block) * block);
131
182
  const to = Math.max(from, Math.min(rowCount - 1, Math.ceil((rawTo + 1) / block) * block - 1));
132
183
 
133
- const topSpacerHeight = from * rowHeight;
134
- const bottomSpacerHeight = Math.max(0, (rowCount - to - 1) * rowHeight);
184
+ const topSpacerHeight = offsets ? offsets[from] : from * rowHeight;
185
+ const bottomSpacerHeight = offsets
186
+ ? Math.max(0, offsets[rowCount] - offsets[to + 1])
187
+ : Math.max(0, (rowCount - to - 1) * rowHeight);
135
188
 
136
189
  // Return the *same object* when nothing about the window changed. Scrolling
137
190
  // within a block recomputes this on every scroll event, and a fresh object
@@ -1,5 +1,5 @@
1
1
  export * as Table from './index.parts.js';
2
- export type { CellContext, CellProps, CellRenderer, ColumnDef, Row, RowData, TableBodyProps, TableBodyVirtualizer, TableCellProps, TableCheckboxIndicatorProps, TableCheckboxProps, TableColumnHeaderCellProps, TableColumnProps, TableColumnResizerProps, TableSortTriggerRenderState, TableSortTriggerProps, TableInteractiveCellProps, TableEmptyStateProps, TableFooterProps, TableHeaderProps, TableRowProps, TableRootProps } from './types.js';
2
+ export type { CellContext, CellProps, CellRenderer, ColumnDef, Row, RowData, TableBodyProps, TableBodyVirtualizer, TableCellProps, TableCheckboxIndicatorProps, TableCheckboxProps, TableColumnHeaderCellProps, TableColumnProps, TableColumnResizerProps, TableSortTriggerRenderState, TableSortTriggerProps, TableInteractiveCellProps, TableEmptyStateProps, TableFooterProps, TableHeaderProps, TableRowProps, TableRootProps, TableSectionRowProps } from './types.js';
3
3
  export { default as TableRoot } from './root/table-root.svelte';
4
4
  export { default as TableColumn } from './column/table-column.svelte';
5
5
  export { default as TableHeader } from './header/table-header.svelte';
@@ -7,6 +7,7 @@ export { default as TableBody } from './body/table-body.svelte';
7
7
  export { default as TableEmptyState } from './empty-state/table-empty-state.svelte';
8
8
  export { default as TableFooter } from './footer/table-footer.svelte';
9
9
  export { default as TableRow } from './row/table-row.svelte';
10
+ export { default as TableSectionRow } from './section-row/table-section-row.svelte';
10
11
  export { default as TableColumnHeaderCell } from './column-header-cell/table-column-header-cell.svelte';
11
12
  export { default as TableSortTrigger } from './sort-trigger/table-sort-trigger.svelte';
12
13
  export { default as TableColumnResizer } from './column-resizer/table-column-resizer.svelte';
@@ -6,6 +6,7 @@ export { default as TableBody } from './body/table-body.svelte';
6
6
  export { default as TableEmptyState } from './empty-state/table-empty-state.svelte';
7
7
  export { default as TableFooter } from './footer/table-footer.svelte';
8
8
  export { default as TableRow } from './row/table-row.svelte';
9
+ export { default as TableSectionRow } from './section-row/table-section-row.svelte';
9
10
  export { default as TableColumnHeaderCell } from './column-header-cell/table-column-header-cell.svelte';
10
11
  export { default as TableSortTrigger } from './sort-trigger/table-sort-trigger.svelte';
11
12
  export { default as TableColumnResizer } from './column-resizer/table-column-resizer.svelte';
@@ -5,6 +5,7 @@ export { default as Body } from './body/table-body.svelte';
5
5
  export { default as EmptyState } from './empty-state/table-empty-state.svelte';
6
6
  export { default as Footer } from './footer/table-footer.svelte';
7
7
  export { default as Row } from './row/table-row.svelte';
8
+ export { default as SectionRow } from './section-row/table-section-row.svelte';
8
9
  export { default as ColumnHeaderCell } from './column-header-cell/table-column-header-cell.svelte';
9
10
  export { default as SortTrigger } from './sort-trigger/table-sort-trigger.svelte';
10
11
  export { default as ColumnResizer } from './column-resizer/table-column-resizer.svelte';
@@ -5,6 +5,7 @@ export { default as Body } from './body/table-body.svelte';
5
5
  export { default as EmptyState } from './empty-state/table-empty-state.svelte';
6
6
  export { default as Footer } from './footer/table-footer.svelte';
7
7
  export { default as Row } from './row/table-row.svelte';
8
+ export { default as SectionRow } from './section-row/table-section-row.svelte';
8
9
  export { default as ColumnHeaderCell } from './column-header-cell/table-column-header-cell.svelte';
9
10
  export { default as SortTrigger } from './sort-trigger/table-sort-trigger.svelte';
10
11
  export { default as ColumnResizer } from './column-resizer/table-column-resizer.svelte';
@@ -85,6 +85,11 @@ type TableRowRegistration = {
85
85
  section: TableSectionKind;
86
86
  id?: TableSelectionKey;
87
87
  disabled: boolean;
88
+ /**
89
+ * Marks a `Table.SectionRow`: a full-width group header that takes part in
90
+ * focus navigation but never in selection or in `onRowAction`.
91
+ */
92
+ isSection?: boolean;
88
93
  element?: HTMLTableRowElement;
89
94
  };
90
95
  type TableCellRegistration = {
@@ -95,6 +100,12 @@ type TableCellRegistration = {
95
100
  columnToken?: string;
96
101
  element?: HTMLElement;
97
102
  focusDelegate?: () => HTMLElement | undefined;
103
+ /**
104
+ * The single cell of a `Table.SectionRow`. It spans every column, so it
105
+ * belongs to no column: it sits at the first visible column for navigation
106
+ * and never takes part in column measurement or column hiding.
107
+ */
108
+ spansRow?: boolean;
98
109
  };
99
110
  export type CreateTableContextOptions = {
100
111
  selectionMode?: TableSelectionMode;
@@ -191,6 +202,13 @@ export type TableContext = {
191
202
  registerRow: (row: TableRowRegistration) => void;
192
203
  unregisterRow: (token: string) => void;
193
204
  setLogicalBodyRows: (ids?: Iterable<TableSelectionKey>) => void;
205
+ /**
206
+ * Declares which logical body rows are section rows. `Table.Body` calls it
207
+ * from `isSectionItem`, so section rows a virtualizer has not mounted are
208
+ * still kept out of select-all and range selection.
209
+ */
210
+ setSectionRowKeys: (ids?: Iterable<TableSelectionKey>) => void;
211
+ isSectionRowKey: (id: TableSelectionKey | undefined) => boolean;
194
212
  markBodyRowsInitialized: () => void;
195
213
  getHeaderRowCount: () => number;
196
214
  getBodyRowCount: () => number;