@human-kit/ui 1.1.2 → 1.2.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.
@@ -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';
@@ -1898,7 +1898,7 @@ export function createTableContext(options = {}) {
1898
1898
  return;
1899
1899
  if (selectionMode === 'single') {
1900
1900
  const wasSelected = selectedKeys.has(id);
1901
- applySelectionChange(selectionBehavior === 'toggle' && wasSelected ? new SvelteSet() : new SvelteSet([id]), selectionBehavior === 'toggle' && wasSelected ? null : id);
1901
+ applySelectionChange(selectionBehavior !== 'replace' && wasSelected ? new SvelteSet() : new SvelteSet([id]), selectionBehavior !== 'replace' && wasSelected ? null : id);
1902
1902
  return;
1903
1903
  }
1904
1904
  const next = new SvelteSet(selectedKeys);
@@ -1971,6 +1971,8 @@ export function createTableContext(options = {}) {
1971
1971
  performRowAction(id);
1972
1972
  return;
1973
1973
  }
1974
+ if (selectionBehavior === 'checkbox')
1975
+ return;
1974
1976
  pressRowSelection(id, interaction);
1975
1977
  return;
1976
1978
  }
@@ -1986,6 +1988,12 @@ export function createTableContext(options = {}) {
1986
1988
  toggleRowSelection(id);
1987
1989
  return;
1988
1990
  }
1991
+ // Only the checkbox selects: the row does what it does, or nothing.
1992
+ if (selectionBehavior === 'checkbox') {
1993
+ if (source === 'pointer' && onRowAction)
1994
+ performRowAction(id);
1995
+ return;
1996
+ }
1989
1997
  if (source === 'pointer-double') {
1990
1998
  if (onRowAction && selectionMode !== 'none' && selectionBehavior === 'replace') {
1991
1999
  performRowAction(id);
@@ -1,6 +1,5 @@
1
1
  <script lang="ts">
2
2
  import { onDestroy } from 'svelte';
3
- import { SvelteMap, SvelteSet } from 'svelte/reactivity';
4
3
  import {
5
4
  setTableRowContext,
6
5
  useTableContext,
@@ -24,9 +23,12 @@
24
23
  const table = useTableContext();
25
24
  const section = useTableSectionContext();
26
25
  const rowToken = table.createInstanceToken('row');
26
+ // Plain, not reactive: the epoch below is what announces a change. These used to be a
27
+ // `SvelteSet` and a `SvelteMap` whose indexes were rewritten for every cell after the one that
28
+ // left, so a virtualized row of fourteen columns leaving the viewport made ~100 reactive writes
29
+ // — the whole cost of scrolling a wide table. A row has a handful of cells: `indexOf` over them
30
+ // is cheaper than keeping an index map in step.
27
31
  const cellOrder: string[] = [];
28
- const cellOrderSet = new SvelteSet<string>();
29
- const cellIndexByToken = new SvelteMap<string, number>();
30
32
  const cellElements: Record<string, () => HTMLElement | undefined> = {};
31
33
  // Counter-based on purpose: cell indexes are resolved against the live DOM
32
34
  // (`rowElement.children`), so order changes are event-like (registration /
@@ -101,10 +103,8 @@
101
103
  }
102
104
 
103
105
  function registerCellToken(token: string, getElement?: () => HTMLElement | undefined) {
104
- const alreadyOrdered = cellOrderSet.has(token);
106
+ const alreadyOrdered = cellOrder.includes(token);
105
107
  if (!alreadyOrdered) {
106
- cellOrderSet.add(token);
107
- cellIndexByToken.set(token, cellOrder.length);
108
108
  cellOrder.push(token);
109
109
  }
110
110
  if (getElement) {
@@ -125,17 +125,15 @@
125
125
 
126
126
  function unregisterCellToken(token: string) {
127
127
  delete cellElements[token];
128
- const index = cellIndexByToken.get(token) ?? -1;
128
+ const index = cellOrder.indexOf(token);
129
129
  if (index >= 0) {
130
130
  cellOrder.splice(index, 1);
131
- cellOrderSet.delete(token);
132
- cellIndexByToken.delete(token);
133
- for (let nextIndex = index; nextIndex < cellOrder.length; nextIndex += 1) {
134
- cellIndexByToken.set(cellOrder[nextIndex], nextIndex);
135
- }
136
131
  if (isBodyRow && !tracksDynamicBodyCellOrder) {
137
132
  if (bodyCellOrderSealed) {
138
133
  promoteBodyCellOrderTracking();
134
+ } else if (index < cellOrder.length) {
135
+ // The cells after it moved down one: the index map used to say so by itself.
136
+ notifyCellOrderChange();
139
137
  }
140
138
  return;
141
139
  }
@@ -150,7 +148,7 @@
150
148
  const index = Array.from(rowElement.children).indexOf(element);
151
149
  if (index >= 0) return index;
152
150
  }
153
- return cellIndexByToken.get(token) ?? -1;
151
+ return cellOrder.indexOf(token);
154
152
  }
155
153
 
156
154
  setTableRowContext({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@human-kit/ui",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
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>",