@human-kit/ui 1.1.3 → 1.2.1

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.
@@ -95,7 +95,7 @@ and `TableCheckboxIndicatorProps`.
95
95
 
96
96
  - Use `Table.Root` as the stateful container for focus, selection, and sorting state.
97
97
  - Use `keyboardNavigation` to choose how far the roving tab stop reaches into the body: `'grid'` (default) makes every body cell a focus target, `'row'` makes the row the only one, and `'none'` leaves the body inert. The cell navigation has a cost: one focus registration and one focus state for each cell. A virtualized table does this again for each row that it makes. Use `'row'` when the body is a list, and not a surface where the user works. Use `'none'` only when nothing in the body does an action. The header keeps its own navigation in every mode.
98
- - Use `selectionBehavior="toggle"` to let the user remove the selection of a selected row. Use `selectionBehavior="replace"` to keep a selected row selected when the user presses it again.
98
+ - Use `selectionBehavior="toggle"` to let the user remove the selection of a selected row. Use `selectionBehavior="replace"` to keep a selected row selected when the user presses it again. Use `selectionBehavior="checkbox"` when a press on the row should only perform its action: then only the selection checkbox, `Space` or the select-all shortcut change the selection.
99
99
  - `Table.Column` is a logical-only wrapper for column metadata; it does not render DOM by itself and should wrap a single `Table.ColumnHeaderCell`.
100
100
  - Wrap each header cell in `Table.Column` so the table can register stable column metadata.
101
101
  - Add `Table.ColumnResizer` inside `Table.ColumnHeaderCell` to make the owning `Table.Column` resizable.
@@ -11,34 +11,34 @@ Description: State container for interactive table behavior, including roving fo
11
11
 
12
12
  Public prop type: `TableRootProps`
13
13
 
14
- | Prop | Type | Default | Description |
15
- | ------------------------ | ------------------------------------------------------------ | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
16
- | `selectionMode` | `'none' \| 'single' \| 'multiple'` | `'none'` | Controls row selection behavior. |
17
- | `selectionBehavior` | `'toggle' \| 'replace'` | `'toggle'` | `toggle` uses checkbox-style selection. `replace` makes click replace selection, vertical arrows move selection, and `Shift+ArrowUp/Down` extend it. |
18
- | `disabledBehavior` | `'selection' \| 'all'` | `'all'` | Controls whether disabled rows only block selection or block both selection and row actions. |
19
- | `disallowEmptySelection` | `boolean` | `false` | Prevents the internal selection state from becoming empty when selection is enabled. |
20
- | `hiddenColumns` | `Iterable<string>` | `undefined` | Controlled hidden column ids. Supports `bind:hiddenColumns`. |
21
- | `defaultHiddenColumns` | `Iterable<string>` | `undefined` | Initial hidden column ids for uncontrolled usage. |
22
- | `selectedKeys` | `Iterable<string \| number>` | `undefined` | Controlled selected row ids. Supports `bind:selectedKeys`. |
23
- | `defaultSelectedKeys` | `Iterable<string \| number>` | `undefined` | Initial selected row ids for uncontrolled usage. When `selectionMode` later becomes `none`, the internal selection is cleared. |
24
- | `sortDescriptor` | `{ column: string; direction: 'ascending' \| 'descending' }` | `undefined` | Controlled sort state. Supports `bind:sortDescriptor`. Setting it back to `undefined` clears the sort. |
25
- | `defaultSortDescriptor` | `{ column: string; direction: 'ascending' \| 'descending' }` | `undefined` | Initial sort state for uncontrolled usage. |
26
- | `columnWidths` | `Map<string, TableColumnWidth>` | `undefined` | Controlled column width state. Supports px, `%`, and `fr` specs via `bind:columnWidths`. |
27
- | `defaultColumnWidths` | `Iterable<[string, TableColumnWidth]>` | `undefined` | Initial uncontrolled column widths using px, `%`, or `fr` specs. |
28
- | `disabledKeys` | `Iterable<string \| number>` | `undefined` | Row ids that should be non-selectable. |
29
- | `onRowAction` | `(id: string \| number) => void` | `undefined` | Called when a row action is triggered for an actionable row. |
30
- | `onSelectionChange` | `(keys: Set<string \| number>) => void` | `undefined` | Called when row selection changes. |
31
- | `onSortChange` | `(descriptor) => void` | `undefined` | Called when sortable header state changes. |
32
- | `onColumnWidthsChange` | `(widths: Map<string, TableColumnWidth>) => void` | `undefined` | Called when resize interactions update managed column widths. |
33
- | `onHiddenColumnsChange` | `(columnIds: string[]) => void` | `undefined` | Called when hidden column state changes. |
34
- | `onColumnResizeStart` | `(columnId: string) => void` | `undefined` | Called when a column resize drag starts. |
35
- | `onColumnResizeEnd` | `(widths: Map<string, TableColumnWidth>) => void` | `undefined` | Called when a column resize drag ends. |
36
- | `aria-label` | `string` | `undefined` | Accessible name when no external label is present. |
37
- | `aria-labelledby` | `string` | `undefined` | Id reference for an external label. |
38
- | `class` | `string` | `''` | Class names for the root table element. |
39
- | `context` | `TableContext` | `undefined` | Bindable reference to the active internal table context instance. |
40
- | `element` | `HTMLTableElement` | `undefined` | A bindable reference to the table element. |
41
- | `children` | `Snippet` | `undefined` | Composed table parts. |
14
+ | Prop | Type | Default | Description |
15
+ | ------------------------ | ------------------------------------------------------------ | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
16
+ | `selectionMode` | `'none' \| 'single' \| 'multiple'` | `'none'` | Controls row selection behavior. |
17
+ | `selectionBehavior` | `'toggle' \| 'replace' \| 'checkbox'` | `'toggle'` | `toggle` uses checkbox-style selection. `replace` makes click replace selection, vertical arrows move selection, and `Shift+ArrowUp/Down` extend it. `checkbox` leaves the selection to the checkbox and `Space`: a press only performs the row action. |
18
+ | `disabledBehavior` | `'selection' \| 'all'` | `'all'` | Controls whether disabled rows only block selection or block both selection and row actions. |
19
+ | `disallowEmptySelection` | `boolean` | `false` | Prevents the internal selection state from becoming empty when selection is enabled. |
20
+ | `hiddenColumns` | `Iterable<string>` | `undefined` | Controlled hidden column ids. Supports `bind:hiddenColumns`. |
21
+ | `defaultHiddenColumns` | `Iterable<string>` | `undefined` | Initial hidden column ids for uncontrolled usage. |
22
+ | `selectedKeys` | `Iterable<string \| number>` | `undefined` | Controlled selected row ids. Supports `bind:selectedKeys`. |
23
+ | `defaultSelectedKeys` | `Iterable<string \| number>` | `undefined` | Initial selected row ids for uncontrolled usage. When `selectionMode` later becomes `none`, the internal selection is cleared. |
24
+ | `sortDescriptor` | `{ column: string; direction: 'ascending' \| 'descending' }` | `undefined` | Controlled sort state. Supports `bind:sortDescriptor`. Setting it back to `undefined` clears the sort. |
25
+ | `defaultSortDescriptor` | `{ column: string; direction: 'ascending' \| 'descending' }` | `undefined` | Initial sort state for uncontrolled usage. |
26
+ | `columnWidths` | `Map<string, TableColumnWidth>` | `undefined` | Controlled column width state. Supports px, `%`, and `fr` specs via `bind:columnWidths`. |
27
+ | `defaultColumnWidths` | `Iterable<[string, TableColumnWidth]>` | `undefined` | Initial uncontrolled column widths using px, `%`, or `fr` specs. |
28
+ | `disabledKeys` | `Iterable<string \| number>` | `undefined` | Row ids that should be non-selectable. |
29
+ | `onRowAction` | `(id: string \| number) => void` | `undefined` | Called when a row action is triggered for an actionable row. |
30
+ | `onSelectionChange` | `(keys: Set<string \| number>) => void` | `undefined` | Called when row selection changes. |
31
+ | `onSortChange` | `(descriptor) => void` | `undefined` | Called when sortable header state changes. |
32
+ | `onColumnWidthsChange` | `(widths: Map<string, TableColumnWidth>) => void` | `undefined` | Called when resize interactions update managed column widths. |
33
+ | `onHiddenColumnsChange` | `(columnIds: string[]) => void` | `undefined` | Called when hidden column state changes. |
34
+ | `onColumnResizeStart` | `(columnId: string) => void` | `undefined` | Called when a column resize drag starts. |
35
+ | `onColumnResizeEnd` | `(widths: Map<string, TableColumnWidth>) => void` | `undefined` | Called when a column resize drag ends. |
36
+ | `aria-label` | `string` | `undefined` | Accessible name when no external label is present. |
37
+ | `aria-labelledby` | `string` | `undefined` | Id reference for an external label. |
38
+ | `class` | `string` | `''` | Class names for the root table element. |
39
+ | `context` | `TableContext` | `undefined` | Bindable reference to the active internal table context instance. |
40
+ | `element` | `HTMLTableElement` | `undefined` | A bindable reference to the table element. |
41
+ | `children` | `Snippet` | `undefined` | Composed table parts. |
42
42
 
43
43
  ### Behavior notes
44
44
 
@@ -17,7 +17,17 @@ export type TableSelectionMode = 'none' | 'single' | 'multiple';
17
17
  * so it costs nothing, and it is where sorting and resizing live.
18
18
  */
19
19
  export type TableKeyboardNavigation = 'grid' | 'row' | 'none';
20
- export type TableSelectionBehavior = 'toggle' | 'replace';
20
+ /**
21
+ * How a press on a row relates to the selection.
22
+ *
23
+ * - `'toggle'`: a press toggles the row, checkbox-style. With `onRowAction`, a press performs the
24
+ * action while nothing is selected and toggles once something is.
25
+ * - `'replace'`: a press replaces the selection with the row; the arrows move it.
26
+ * - `'checkbox'`: a press never touches the selection. The row performs its action (if there is
27
+ * one), and only the selection checkbox, `Space` or the select-all shortcut select. Use it when
28
+ * the rows open something and selecting is a deliberate, secondary act.
29
+ */
30
+ export type TableSelectionBehavior = 'toggle' | 'replace' | 'checkbox';
21
31
  export type TableDisabledBehavior = 'selection' | 'all';
22
32
  export type TableSortDirection = 'ascending' | 'descending';
23
33
  export type TableSectionKind = 'header' | 'body' | 'footer';
@@ -208,6 +208,27 @@ export function createTableContext(options = {}) {
208
208
  });
209
209
  }
210
210
  }
211
+ /**
212
+ * The body's rows changed (one added, one removed, the order of the items), and nothing about
213
+ * the columns did. Only the caches built from the rows go, so their aria indexes and the
214
+ * navigation are worked out again; the column layout and the widths stay.
215
+ *
216
+ * `notifyLayout` threw those away too, and the next read of a width re-measured the table:
217
+ * a `getBoundingClientRect` that forced a synchronous layout of every row on each line added
218
+ * to an editable sheet, which grew with the sheet. The container's own size still reaches the
219
+ * widths through `refreshMeasuredLayout`, which the root's `ResizeObserver` calls — including
220
+ * when a vertical scrollbar appears because the rows outgrew the box.
221
+ */
222
+ function notifyBodyLayout() {
223
+ invalidateBodyStructureCaches();
224
+ if (!layoutNotifyScheduled) {
225
+ layoutNotifyScheduled = true;
226
+ queueMicrotask(() => {
227
+ layoutNotifyScheduled = false;
228
+ layoutEpoch += 1;
229
+ });
230
+ }
231
+ }
211
232
  function notifySelection() {
212
233
  if (!selectionNotifyScheduled) {
213
234
  selectionNotifyScheduled = true;
@@ -1277,7 +1298,7 @@ export function createTableContext(options = {}) {
1277
1298
  logicalBodyRowIds = nextIds;
1278
1299
  logicalBodyRowIndexCache = null;
1279
1300
  pruneRegisteredSectionRowKeys();
1280
- notifyLayout();
1301
+ notifyBodyLayout();
1281
1302
  notifySelection();
1282
1303
  }
1283
1304
  /**
@@ -1400,7 +1421,10 @@ export function createTableContext(options = {}) {
1400
1421
  if (!logicalBodyRowIds)
1401
1422
  return -1;
1402
1423
  if (!logicalBodyRowIndexCache) {
1403
- logicalBodyRowIndexCache = new SvelteMap();
1424
+ // A plain map: a cache rebuilt when the rows change and read through `layoutEpoch`,
1425
+ // like the other layout caches. Reactive, it set up a signal per row on every rebuild.
1426
+ // eslint-disable-next-line svelte/prefer-svelte-reactivity -- epoch-driven cache, not state.
1427
+ logicalBodyRowIndexCache = new Map();
1404
1428
  for (let index = 0; index < logicalBodyRowIds.length; index += 1) {
1405
1429
  const rowId = logicalBodyRowIds[index];
1406
1430
  if (!logicalBodyRowIndexCache.has(rowId)) {
@@ -1898,7 +1922,7 @@ export function createTableContext(options = {}) {
1898
1922
  return;
1899
1923
  if (selectionMode === 'single') {
1900
1924
  const wasSelected = selectedKeys.has(id);
1901
- applySelectionChange(selectionBehavior === 'toggle' && wasSelected ? new SvelteSet() : new SvelteSet([id]), selectionBehavior === 'toggle' && wasSelected ? null : id);
1925
+ applySelectionChange(selectionBehavior !== 'replace' && wasSelected ? new SvelteSet() : new SvelteSet([id]), selectionBehavior !== 'replace' && wasSelected ? null : id);
1902
1926
  return;
1903
1927
  }
1904
1928
  const next = new SvelteSet(selectedKeys);
@@ -1971,6 +1995,8 @@ export function createTableContext(options = {}) {
1971
1995
  performRowAction(id);
1972
1996
  return;
1973
1997
  }
1998
+ if (selectionBehavior === 'checkbox')
1999
+ return;
1974
2000
  pressRowSelection(id, interaction);
1975
2001
  return;
1976
2002
  }
@@ -1986,6 +2012,12 @@ export function createTableContext(options = {}) {
1986
2012
  toggleRowSelection(id);
1987
2013
  return;
1988
2014
  }
2015
+ // Only the checkbox selects: the row does what it does, or nothing.
2016
+ if (selectionBehavior === 'checkbox') {
2017
+ if (source === 'pointer' && onRowAction)
2018
+ performRowAction(id);
2019
+ return;
2020
+ }
1989
2021
  if (source === 'pointer-double') {
1990
2022
  if (onRowAction && selectionMode !== 'none' && selectionBehavior === 'replace') {
1991
2023
  performRowAction(id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@human-kit/ui",
3
- "version": "1.1.3",
3
+ "version": "1.2.1",
4
4
  "description": "Accessible, typed UI components for Svelte 5 — shipped as native ESM with per-component subpath exports so bundlers only include what you import.",
5
5
  "license": "MIT",
6
6
  "author": "Agustin Delgado <agustindariodelgado@gmail.com>",