@human-kit/ui 1.2.0 → 1.3.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.
package/dist/table/README.md
CHANGED
|
@@ -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. Use `selectionBehavior="checkbox"` when a press on the row
|
|
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 must only do 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.
|
|
@@ -182,6 +182,7 @@ Put the groups and their rows in one `items` array. In the `children` snippet of
|
|
|
182
182
|
- A click, `Enter` or `Space` calls `onAction` of the section row. The table does not call `onRowAction` for a section row.
|
|
183
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
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
|
+
- When the section rows are not all the same height, pass `sectionRowHeight` as a function of the item. The table calls it only for the items that `isSectionItem` accepts.
|
|
185
186
|
- 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
187
|
|
|
187
188
|
## Composition contract
|
|
@@ -98,10 +98,13 @@
|
|
|
98
98
|
if (!virtualizer || !virtualizerEnabled || !isSectionItem) return undefined;
|
|
99
99
|
const { rowHeight, sectionRowHeight } = virtualizer;
|
|
100
100
|
if (sectionRowHeight === undefined || sectionRowHeight === rowHeight) return undefined;
|
|
101
|
+
const sectionHeight =
|
|
102
|
+
typeof sectionRowHeight === 'function' ? sectionRowHeight : () => sectionRowHeight;
|
|
101
103
|
|
|
102
104
|
const offsets = new Float64Array(itemList.length + 1);
|
|
103
105
|
for (let index = 0; index < itemList.length; index += 1) {
|
|
104
|
-
const
|
|
106
|
+
const item = itemList[index];
|
|
107
|
+
const height = isSectionItem(item) ? sectionHeight(item) : rowHeight;
|
|
105
108
|
offsets[index + 1] = offsets[index] + height;
|
|
106
109
|
}
|
|
107
110
|
return offsets;
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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)) {
|
package/dist/table/types.d.ts
CHANGED
|
@@ -57,13 +57,17 @@ export type TableHeaderProps = Omit<HTMLAttributes<HTMLTableSectionElement>, 'ch
|
|
|
57
57
|
children?: Snippet;
|
|
58
58
|
class?: string;
|
|
59
59
|
};
|
|
60
|
-
export type TableBodyVirtualizer = {
|
|
60
|
+
export type TableBodyVirtualizer<T extends TableRowItem = TableRowItem> = {
|
|
61
61
|
rowHeight: number;
|
|
62
62
|
/**
|
|
63
63
|
* Height, in px, of a section row, when it differs from `rowHeight`. It needs `isSectionItem` on
|
|
64
64
|
* `Table.Body` to know which items are section rows. Without it, each item is `rowHeight` high.
|
|
65
|
+
*
|
|
66
|
+
* A function sizes each section row on its own, for a body whose section rows are not all
|
|
67
|
+
* alike — a group's header beside the header of an open row's children, say. It is only
|
|
68
|
+
* called for the items `isSectionItem` accepts.
|
|
65
69
|
*/
|
|
66
|
-
sectionRowHeight?: number;
|
|
70
|
+
sectionRowHeight?: number | ((item: T) => number);
|
|
67
71
|
/**
|
|
68
72
|
* Extra rows rendered above and below the viewport, defaulting to 18. It
|
|
69
73
|
* buffers against row render cost: while the main thread builds rows, the
|
|
@@ -84,7 +88,7 @@ export type TableBodyManualProps = TableBodyBaseProps & {
|
|
|
84
88
|
};
|
|
85
89
|
export type TableBodyItemsProps<T extends TableRowItem = TableRowItem> = TableBodyBaseProps & {
|
|
86
90
|
items: readonly T[];
|
|
87
|
-
virtualizer?: TableBodyVirtualizer
|
|
91
|
+
virtualizer?: TableBodyVirtualizer<T>;
|
|
88
92
|
/**
|
|
89
93
|
* Tells which items render a `Table.SectionRow`. A section row that is mounted declares itself,
|
|
90
94
|
* so this is optional without a virtualizer. With one, pass it: it keeps the section rows that
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@human-kit/ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.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>",
|