@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
@@ -86,6 +86,11 @@ export function createTableContext(options = {}) {
86
86
  let selectableBodyRowCount = 0;
87
87
  let logicalBodyRowIds = null;
88
88
  let logicalBodyRowIndexCache = null;
89
+ // Section row keys come from two places: the section rows that registered
90
+ // (kept after they unmount, so a virtualizer scrolling them away does not
91
+ // make them selectable again) and the keys `Table.Body` declares up front.
92
+ const registeredSectionRowKeys = new SvelteSet();
93
+ const declaredSectionRowKeys = new SvelteSet();
89
94
  const cells = new SvelteMap();
90
95
  const cellOrderSet = new SvelteSet();
91
96
  // Cell keys grouped by row, so dropping a row does not have to scan every
@@ -480,6 +485,7 @@ export function createTableContext(options = {}) {
480
485
  left.section === right.section &&
481
486
  left.id === right.id &&
482
487
  left.disabled === right.disabled &&
488
+ left.isSection === right.isSection &&
483
489
  left.element === right.element);
484
490
  }
485
491
  function sameCellRegistration(left, right) {
@@ -489,7 +495,8 @@ export function createTableContext(options = {}) {
489
495
  left.columnIndex === right.columnIndex &&
490
496
  left.columnToken === right.columnToken &&
491
497
  left.element === right.element &&
492
- left.focusDelegate === right.focusDelegate);
498
+ left.focusDelegate === right.focusDelegate &&
499
+ left.spansRow === right.spansRow);
493
500
  }
494
501
  function resolveCellTargetByKey(key) {
495
502
  return key ? (cells.get(key) ?? null) : null;
@@ -981,6 +988,8 @@ export function createTableContext(options = {}) {
981
988
  notifyWidth();
982
989
  }
983
990
  function getCellColumn(cell) {
991
+ if (cell.spansRow)
992
+ return undefined;
984
993
  if (cell.section === 'header' && cell.columnToken) {
985
994
  return columns.get(cell.columnToken);
986
995
  }
@@ -1220,18 +1229,23 @@ export function createTableContext(options = {}) {
1220
1229
  bodyRowOrderSet.delete(row.token);
1221
1230
  }
1222
1231
  const previousSelectableBodyRow = isSelectableBodyRow(existing);
1232
+ const sectionKeysChanged = syncRegisteredSectionRowKey(row);
1223
1233
  rows.set(row.token, row);
1224
1234
  if (targetOrder && targetOrderSet && !targetOrderSet.has(row.token)) {
1225
1235
  targetOrder.push(row.token);
1226
1236
  targetOrderSet.add(row.token);
1227
1237
  }
1228
1238
  const nextSelectableBodyRow = isSelectableBodyRow(row);
1229
- if (previousSelectableBodyRow !== nextSelectableBodyRow) {
1239
+ if (sectionKeysChanged) {
1240
+ recomputeSelectableBodyRowCount();
1241
+ }
1242
+ else if (previousSelectableBodyRow !== nextSelectableBodyRow) {
1230
1243
  selectableBodyRowCount += nextSelectableBodyRow ? 1 : -1;
1231
1244
  }
1232
- if ((selectedKeys.size > 0 &&
1233
- logicalBodyRowIds === null &&
1234
- (existing?.section === 'body' || row.section === 'body')) ||
1245
+ if (sectionKeysChanged ||
1246
+ (selectedKeys.size > 0 &&
1247
+ logicalBodyRowIds === null &&
1248
+ (existing?.section === 'body' || row.section === 'body')) ||
1235
1249
  (bodyRowsInitialized &&
1236
1250
  (previousSelectableBodyRowCount === 0) !== (selectableBodyRowCount === 0))) {
1237
1251
  notifySelection();
@@ -1262,9 +1276,57 @@ export function createTableContext(options = {}) {
1262
1276
  return;
1263
1277
  logicalBodyRowIds = nextIds;
1264
1278
  logicalBodyRowIndexCache = null;
1279
+ pruneRegisteredSectionRowKeys();
1265
1280
  notifyLayout();
1266
1281
  notifySelection();
1267
1282
  }
1283
+ /**
1284
+ * Records a section row's key, or forgets it when a regular row now owns
1285
+ * that key. Returns whether the set of section keys changed.
1286
+ */
1287
+ function syncRegisteredSectionRowKey(row) {
1288
+ if (row.section !== 'body' || row.id === undefined)
1289
+ return false;
1290
+ if (row.isSection) {
1291
+ if (registeredSectionRowKeys.has(row.id))
1292
+ return false;
1293
+ registeredSectionRowKeys.add(row.id);
1294
+ return true;
1295
+ }
1296
+ return registeredSectionRowKeys.delete(row.id);
1297
+ }
1298
+ // A registered section key outlives its row, so that an unmounted
1299
+ // (virtualized) section stays out of the selection. Once the key leaves the
1300
+ // logical rows altogether it no longer names a section of this table.
1301
+ function pruneRegisteredSectionRowKeys() {
1302
+ if (registeredSectionRowKeys.size === 0 || logicalBodyRowIds === null)
1303
+ return;
1304
+ // eslint-disable-next-line svelte/prefer-svelte-reactivity -- a throwaway lookup, not state.
1305
+ const logicalKeys = new Set(logicalBodyRowIds);
1306
+ for (const key of [...registeredSectionRowKeys]) {
1307
+ if (!logicalKeys.has(key))
1308
+ registeredSectionRowKeys.delete(key);
1309
+ }
1310
+ }
1311
+ function setSectionRowKeys(ids) {
1312
+ // eslint-disable-next-line svelte/prefer-svelte-reactivity -- a throwaway comparison, not state.
1313
+ const next = new Set(ids ?? []);
1314
+ if (hasSameSelection(declaredSectionRowKeys, next))
1315
+ return;
1316
+ declaredSectionRowKeys.clear();
1317
+ for (const key of next) {
1318
+ declaredSectionRowKeys.add(key);
1319
+ }
1320
+ recomputeSelectableBodyRowCount();
1321
+ invalidateLayoutCaches();
1322
+ notifyLayout();
1323
+ notifySelection();
1324
+ }
1325
+ function isSectionRowKey(id) {
1326
+ if (id === undefined)
1327
+ return false;
1328
+ return declaredSectionRowKeys.has(id) || registeredSectionRowKeys.has(id);
1329
+ }
1268
1330
  function unregisterRow(token) {
1269
1331
  defaultFocusKeyCache = undefined;
1270
1332
  const row = rows.get(token);
@@ -1273,6 +1335,11 @@ export function createTableContext(options = {}) {
1273
1335
  if (isSelectableBodyRow(row)) {
1274
1336
  selectableBodyRowCount = Math.max(0, selectableBodyRowCount - 1);
1275
1337
  }
1338
+ // Without logical rows nothing else can tell the key apart, so a manual
1339
+ // section row that unmounts takes its key with it.
1340
+ if (row?.isSection && row.id !== undefined && logicalBodyRowIds === null) {
1341
+ registeredSectionRowKeys.delete(row.id);
1342
+ }
1276
1343
  if (focusedRowTarget?.rowToken === token) {
1277
1344
  focusedRowTarget = null;
1278
1345
  }
@@ -1400,13 +1467,19 @@ export function createTableContext(options = {}) {
1400
1467
  }
1401
1468
  return rowIds;
1402
1469
  }
1403
- function isRowSelectionDisabled(id, localDisabled = false) {
1470
+ function isRowKeyDisabled(id, localDisabled = false) {
1404
1471
  if (localDisabled)
1405
1472
  return true;
1406
1473
  if (id === undefined)
1407
1474
  return false;
1408
1475
  return disabledKeys.has(id);
1409
1476
  }
1477
+ // A section row is never selectable, but it is not disabled either: it stays
1478
+ // focusable and keeps its own action. That is why this check, and not
1479
+ // `isRowKeyDisabled`, is the one that knows about sections.
1480
+ function isRowSelectionDisabled(id, localDisabled = false) {
1481
+ return isRowKeyDisabled(id, localDisabled) || isSectionRowKey(id);
1482
+ }
1410
1483
  function isSelectableBodyRow(row) {
1411
1484
  return (row?.section === 'body' &&
1412
1485
  row.id !== undefined &&
@@ -1422,13 +1495,16 @@ export function createTableContext(options = {}) {
1422
1495
  selectableBodyRowCount = nextSelectableBodyRowCount;
1423
1496
  }
1424
1497
  function isRowDisabled(id, localDisabled = false) {
1425
- return disabledBehavior === 'all' && isRowSelectionDisabled(id, localDisabled);
1498
+ return disabledBehavior === 'all' && isRowKeyDisabled(id, localDisabled);
1426
1499
  }
1427
1500
  function isRowActionDisabled(id, localDisabled = false) {
1428
- return disabledBehavior === 'all' && isRowSelectionDisabled(id, localDisabled);
1501
+ return disabledBehavior === 'all' && isRowKeyDisabled(id, localDisabled);
1429
1502
  }
1430
1503
  function isRowActionable(id, localDisabled = false) {
1431
- return Boolean(onRowAction) && id !== undefined && !isRowActionDisabled(id, localDisabled);
1504
+ return (Boolean(onRowAction) &&
1505
+ id !== undefined &&
1506
+ !isSectionRowKey(id) &&
1507
+ !isRowActionDisabled(id, localDisabled));
1432
1508
  }
1433
1509
  function isRowSelected(id) {
1434
1510
  if (id === undefined)
@@ -1560,8 +1636,8 @@ export function createTableContext(options = {}) {
1560
1636
  if (isRowDisabled(row?.id, row?.disabled))
1561
1637
  continue;
1562
1638
  const bodyCells = getResolvedBodyCellsForRow(rowToken)
1563
- .filter((cell) => Boolean(cell.element) && cell.columnIndex !== undefined && !isCellColumnHidden(cell))
1564
- .sort((left, right) => left.columnIndex - right.columnIndex);
1639
+ .filter((cell) => Boolean(cell.element) && getColumnIndex(cell) >= 0)
1640
+ .sort((left, right) => getColumnIndex(left) - getColumnIndex(right));
1565
1641
  const firstBodyCell = bodyCells[0]?.key;
1566
1642
  if (firstBodyCell) {
1567
1643
  defaultFocusKeyCache = firstBodyCell;
@@ -1603,6 +1679,9 @@ export function createTableContext(options = {}) {
1603
1679
  return -1;
1604
1680
  }
1605
1681
  function getColumnIndex(cell) {
1682
+ if (cell.spansRow) {
1683
+ return getVisibleColumnCount() > 0 ? 0 : -1;
1684
+ }
1606
1685
  if (cell.section === 'header' && cell.columnToken) {
1607
1686
  return getVisibleColumnIndexByToken(cell.columnToken);
1608
1687
  }
@@ -1682,6 +1761,15 @@ export function createTableContext(options = {}) {
1682
1761
  return;
1683
1762
  if (isRowDisabled(row.id, row.disabled))
1684
1763
  return;
1764
+ // Under grid navigation a section row has no row-edge stop: its single
1765
+ // cell spans the row, so every move that would land on the row lands on
1766
+ // that cell instead, and the horizontal keys keep the focus there.
1767
+ if (row.isSection && keyboardNavigation === 'grid') {
1768
+ const [cell] = getResolvedBodyCellsForRow(token);
1769
+ if (cell)
1770
+ focusCellByKey(cell.key);
1771
+ return;
1772
+ }
1685
1773
  focusedCellKey = null;
1686
1774
  focusedRowTarget = { rowToken: token, edge };
1687
1775
  row.element.focus();
@@ -1847,7 +1935,9 @@ export function createTableContext(options = {}) {
1847
1935
  applySelectionChange(new SvelteSet(orderedIds.slice(start, end + 1)), anchor);
1848
1936
  }
1849
1937
  function performRowAction(id) {
1850
- if (!onRowAction || id === undefined || isRowActionDisabled(id))
1938
+ if (!onRowAction || id === undefined)
1939
+ return;
1940
+ if (isSectionRowKey(id) || isRowActionDisabled(id))
1851
1941
  return;
1852
1942
  onRowAction(id);
1853
1943
  }
@@ -2398,6 +2488,8 @@ export function createTableContext(options = {}) {
2398
2488
  registerRow: asCommand(registerRow),
2399
2489
  unregisterRow: asCommand(unregisterRow),
2400
2490
  setLogicalBodyRows: asCommand(setLogicalBodyRows),
2491
+ setSectionRowKeys: asCommand(setSectionRowKeys),
2492
+ isSectionRowKey,
2401
2493
  markBodyRowsInitialized: asCommand(markBodyRowsInitialized),
2402
2494
  getHeaderRowCount,
2403
2495
  getBodyRowCount,
@@ -0,0 +1,31 @@
1
+ <!-- markdownlint-disable MD024 -->
2
+
3
+ # Table.SectionRow
4
+
5
+ ## API reference
6
+
7
+ ### Table.SectionRow
8
+
9
+ Name: `Table.SectionRow`
10
+ Description: Full-width group header row inside `Table.Body`. It has one cell that covers all the visible columns. It takes the focus as a row, but it is not in the selection and does not call `onRowAction`.
11
+
12
+ Public prop type: `TableSectionRowProps`
13
+
14
+ | Prop | Type | Default | Description |
15
+ | ---------- | ------------------ | ----------- | --------------------------------------------------------------------------- |
16
+ | `id` | `string \| number` | `undefined` | Key of the item. It gives the row its place in the logical rows. |
17
+ | `onAction` | `() => void` | `undefined` | Called on click, and on `Enter` or `Space` while the section row has focus. |
18
+ | `class` | `string` | `''` | Class names for the `tr` element. |
19
+ | `children` | `Snippet` | `undefined` | Content of the single cell. |
20
+
21
+ Other attributes, for example `aria-expanded` or `data-*`, go to the `tr` element.
22
+
23
+ ### Data attributes
24
+
25
+ | Attribute | Element | Description |
26
+ | --------------------------- | ---------- | -------------------------------------------- |
27
+ | `data-section-row` | `tr` | Always set. |
28
+ | `data-focused` | `tr`, `td` | Set on the element that has the focus. |
29
+ | `data-focus-visible` | `tr`, `td` | Set when that focus comes from the keyboard. |
30
+ | `data-focus-within` | `tr` | Set when the row or its cell has the focus. |
31
+ | `data-focus-visible-within` | `tr` | Set when that focus comes from the keyboard. |
@@ -0,0 +1,201 @@
1
+ <script lang="ts">
2
+ import { onDestroy } from 'svelte';
3
+ import { useTableContext, useTableSectionContext } from '../root/context.svelte';
4
+ import type { TableSectionRowProps } from '../types.js';
5
+ import {
6
+ shouldShowFocusVisible,
7
+ trackInteractionModality
8
+ } from '../../primitives/input-modality';
9
+ import { handleTableBodyKeydown } from '../utils/handle-body-keydown';
10
+
11
+ let {
12
+ id,
13
+ onAction,
14
+ children,
15
+ class: className = '',
16
+ ...restProps
17
+ }: TableSectionRowProps = $props();
18
+
19
+ const table = useTableContext();
20
+ const section = useTableSectionContext();
21
+ if (section.section !== 'body') {
22
+ throw new Error('`Table.SectionRow` must be used inside `Table.Body`.');
23
+ }
24
+
25
+ const rowToken = table.createInstanceToken('row');
26
+ const cellKey = table.createInstanceToken('cell');
27
+
28
+ let rowElement = $state<HTMLTableRowElement | undefined>(undefined);
29
+ let cellElement = $state<HTMLTableCellElement | undefined>(undefined);
30
+
31
+ // A section row is a row for navigation only. It registers as one so the
32
+ // arrows walk into and out of it, and flags itself so the selection model
33
+ // (select-all, ranges, the header checkbox) and `onRowAction` skip it.
34
+ function syncRowRegistration() {
35
+ table.registerRow({
36
+ token: rowToken,
37
+ section: 'body',
38
+ id,
39
+ disabled: false,
40
+ isSection: true,
41
+ element: rowElement
42
+ });
43
+ }
44
+
45
+ syncRowRegistration();
46
+
47
+ $effect(() => {
48
+ syncRowRegistration();
49
+ });
50
+
51
+ // Under `'grid'` the single cell is the focus target; it registers at the
52
+ // first visible column (`spansRow`), so moving down from any column lands on
53
+ // it and moving down from it lands on the first column of the next row.
54
+ const isCellFocusTarget = $derived(table.keyboardNavigation === 'grid');
55
+ // Under `'row'` the row itself is the focus target, like any other row.
56
+ const isRowFocusTarget = $derived(table.keyboardNavigation === 'row');
57
+
58
+ $effect(() => {
59
+ if (!isCellFocusTarget) return;
60
+ table.registerCell({
61
+ key: cellKey,
62
+ rowToken,
63
+ section: 'body',
64
+ element: cellElement,
65
+ spansRow: true
66
+ });
67
+ });
68
+
69
+ onDestroy(() => {
70
+ // Mirrors `isCellFocusTarget` without reading it: a derived is not safe to
71
+ // read while the component tears down.
72
+ if (table.keyboardNavigation === 'grid') {
73
+ table.unregisterCell(cellKey);
74
+ }
75
+ table.unregisterRow(rowToken);
76
+ });
77
+
78
+ // The cell covers every visible column, the selection column included: that
79
+ // one is a regular `Table.Column`, so the visible count already has it.
80
+ const columnCount = $derived.by(() => {
81
+ void table.layoutEpoch;
82
+ return Math.max(table.getVisibleColumnCount(), 1);
83
+ });
84
+ const ariaRowIndex = $derived.by(() => {
85
+ void table.layoutEpoch;
86
+ return table.getRowAriaIndex(rowToken);
87
+ });
88
+
89
+ const isCellFocused = $derived(isCellFocusTarget ? table.isCellFocused(cellKey) : false);
90
+ const isRowFocused = $derived(isRowFocusTarget ? table.isRowFocusTarget(rowToken) : false);
91
+ const isFocusWithin = $derived(table.isRowFocused(rowToken));
92
+ const isCellFocusVisible = $derived(isCellFocused && table.focusVisible);
93
+ const isRowFocusVisible = $derived(isRowFocused && table.focusVisible);
94
+ const isFocusVisibleWithin = $derived(isFocusWithin && table.focusVisible);
95
+
96
+ const cellTabIndex = $derived.by(() => {
97
+ if (!isCellFocusTarget) return undefined;
98
+ if (table.focusedCellKey === null && table.getHeaderRowCount() > 0) return -1;
99
+ return table.isCellTabStop(cellKey) ? 0 : -1;
100
+ });
101
+ const rowTabIndex = $derived.by(() => {
102
+ if (!isRowFocusTarget) return undefined;
103
+ return table.isRowTabStop(rowToken) ? 0 : -1;
104
+ });
105
+
106
+ function runAction() {
107
+ onAction?.();
108
+ }
109
+
110
+ function handleKeyDown(event: KeyboardEvent, focusTarget: HTMLElement | undefined) {
111
+ handleTableBodyKeydown({
112
+ event,
113
+ table,
114
+ focusTarget,
115
+ isDisabled: false,
116
+ // Under grid navigation the cell is the whole row, so Home and End stay
117
+ // on it. Under row navigation they go to the first and last rows, the
118
+ // same as on any other row.
119
+ onHome: isCellFocusTarget ? () => table.moveToRowStart() : () => table.moveToBodyRowStart(),
120
+ onEnd: isCellFocusTarget ? () => table.moveToRowEnd() : () => table.moveToBodyRowEnd(),
121
+ onEnter: runAction,
122
+ onSpace: runAction
123
+ });
124
+ }
125
+
126
+ function handleRowFocus() {
127
+ if (!isRowFocusTarget) return;
128
+ if (!table.isRowTabStop(rowToken)) return;
129
+ table.setFocusedRow(rowToken, table.getRowFocusEdge(rowToken) ?? 'start');
130
+ table.setFocusVisible(shouldShowFocusVisible(rowElement ?? null));
131
+ }
132
+
133
+ function handleRowKeyDown(event: KeyboardEvent) {
134
+ if (!isRowFocusTarget) return;
135
+ if (event.target !== rowElement) return;
136
+ handleKeyDown(event, rowElement);
137
+ }
138
+
139
+ function handleCellFocus() {
140
+ table.setFocusedCell(cellKey);
141
+ table.setFocusVisible(shouldShowFocusVisible(cellElement ?? null));
142
+ }
143
+
144
+ function handleCellKeyDown(event: KeyboardEvent) {
145
+ if (event.target !== cellElement) return;
146
+ handleKeyDown(event, cellElement);
147
+ }
148
+
149
+ function handleMouseDown(event: MouseEvent) {
150
+ trackInteractionModality(event, cellElement ?? null);
151
+ table.setFocusVisible(false);
152
+ }
153
+
154
+ // A press moves focus to whatever the current mode can focus, so the
155
+ // keyboard carries on from the section row; it never goes through
156
+ // `pressRow`, which is what keeps it out of selection and `onRowAction`.
157
+ function handleClick() {
158
+ if (isCellFocusTarget) {
159
+ table.focusCellByKey(cellKey);
160
+ } else if (isRowFocusTarget) {
161
+ table.focusRowByToken(rowToken, 'start');
162
+ }
163
+ runAction();
164
+ }
165
+ </script>
166
+
167
+ <!-- svelte-ignore a11y_no_redundant_roles -->
168
+ <tr
169
+ bind:this={rowElement}
170
+ role="row"
171
+ class={className}
172
+ tabindex={rowTabIndex}
173
+ data-section-row
174
+ data-focused={isRowFocused ? 'true' : undefined}
175
+ data-focus-visible={isRowFocusVisible ? 'true' : undefined}
176
+ data-focus-within={isFocusWithin ? 'true' : undefined}
177
+ data-focus-visible-within={isFocusVisibleWithin ? 'true' : undefined}
178
+ aria-rowindex={ariaRowIndex}
179
+ onfocus={handleRowFocus}
180
+ onkeydown={handleRowKeyDown}
181
+ {...restProps}
182
+ >
183
+ <td
184
+ bind:this={cellElement}
185
+ role="gridcell"
186
+ colspan={columnCount}
187
+ tabindex={cellTabIndex}
188
+ aria-colindex={1}
189
+ data-focused={isCellFocused ? 'true' : undefined}
190
+ data-focus-visible={isCellFocusVisible ? 'true' : undefined}
191
+ style:box-sizing="border-box"
192
+ onfocus={isCellFocusTarget ? handleCellFocus : undefined}
193
+ onkeydown={isCellFocusTarget ? handleCellKeyDown : undefined}
194
+ onmousedown={handleMouseDown}
195
+ onclick={handleClick}
196
+ >
197
+ {#if children}
198
+ {@render children()}
199
+ {/if}
200
+ </td>
201
+ </tr>
@@ -0,0 +1,4 @@
1
+ import type { TableSectionRowProps } from '../types.js';
2
+ declare const TableSectionRow: import("svelte").Component<TableSectionRowProps, {}, "">;
3
+ type TableSectionRow = ReturnType<typeof TableSectionRow>;
4
+ export default TableSectionRow;
@@ -59,6 +59,11 @@ export type TableHeaderProps = Omit<HTMLAttributes<HTMLTableSectionElement>, 'ch
59
59
  };
60
60
  export type TableBodyVirtualizer = {
61
61
  rowHeight: number;
62
+ /**
63
+ * Height, in px, of a section row, when it differs from `rowHeight`. It needs `isSectionItem` on
64
+ * `Table.Body` to know which items are section rows. Without it, each item is `rowHeight` high.
65
+ */
66
+ sectionRowHeight?: number;
62
67
  /**
63
68
  * Extra rows rendered above and below the viewport, defaulting to 18. It
64
69
  * buffers against row render cost: while the main thread builds rows, the
@@ -73,12 +78,19 @@ type TableBodyBaseProps = Omit<HTMLAttributes<HTMLTableSectionElement>, 'childre
73
78
  export type TableBodyManualProps = TableBodyBaseProps & {
74
79
  items?: undefined;
75
80
  virtualizer?: undefined;
81
+ isSectionItem?: undefined;
76
82
  children?: Snippet;
77
83
  empty?: undefined;
78
84
  };
79
85
  export type TableBodyItemsProps<T extends TableRowItem = TableRowItem> = TableBodyBaseProps & {
80
86
  items: readonly T[];
81
87
  virtualizer?: TableBodyVirtualizer;
88
+ /**
89
+ * Tells which items render a `Table.SectionRow`. A section row that is mounted declares itself,
90
+ * so this is optional without a virtualizer. With one, pass it: it keeps the section rows that
91
+ * are not mounted out of select-all and range selection, and it lets `sectionRowHeight` apply.
92
+ */
93
+ isSectionItem?: (item: T) => boolean;
82
94
  children?: Snippet<[T]>;
83
95
  empty?: Snippet;
84
96
  };
@@ -145,6 +157,20 @@ export type TableRowProps = Omit<HTMLAttributes<HTMLTableRowElement>, 'children'
145
157
  children?: Snippet;
146
158
  class?: string;
147
159
  };
160
+ export type TableSectionRowProps = Omit<HTMLAttributes<HTMLTableRowElement>, 'children' | 'id'> & {
161
+ /**
162
+ * Key of the item this section row stands for. It takes a place in the logical rows (and in
163
+ * `aria-rowindex`) like any row, but it is never selected and never passed to `onRowAction`.
164
+ */
165
+ id?: TableSelectionKey;
166
+ /**
167
+ * Called when the section row is pressed: on click, and on `Enter` or `Space` while it has the
168
+ * focus. This is where a group collapses or expands. The table's `onRowAction` is not called.
169
+ */
170
+ onAction?: () => void;
171
+ children?: Snippet;
172
+ class?: string;
173
+ };
148
174
  export type TableColumnHeaderCellProps = Omit<HTMLAttributes<HTMLTableCellElement>, 'children'> & {
149
175
  children?: Snippet;
150
176
  class?: string;
@@ -21,13 +21,7 @@
21
21
  shouldSkipDelay,
22
22
  unregisterOpenTooltip
23
23
  } from './tooltip-group';
24
- import {
25
- buildSafePolygon,
26
- isPointInPolygon,
27
- isPointInRect,
28
- type Point,
29
- type Side
30
- } from './safe-polygon';
24
+ import { buildSafePolygon, isPointInPolygon, type Point, type Side } from './safe-polygon';
31
25
 
32
26
  /**
33
27
  * Tooltip.Root — the open state, the delays, and the interaction with the trigger.
@@ -164,7 +158,11 @@
164
158
  $effect(() => {
165
159
  if (!isOpen) return;
166
160
  registerOpenTooltip(groupEntry);
167
- return () => unregisterOpenTooltip(groupEntry);
161
+ return () => {
162
+ unregisterOpenTooltip(groupEntry);
163
+ // The panel may go with the pointer still on it, and no `pointerleave` follows.
164
+ pointerOnContent = false;
165
+ };
168
166
  });
169
167
 
170
168
  $effect(() => {
@@ -252,8 +250,12 @@
252
250
  function handleGapPointerMove(event: PointerEvent) {
253
251
  if (!gapPolygon) return;
254
252
  const point = { x: event.clientX, y: event.clientY };
255
- const onContent = contentRef ? isPointInRect(point, contentRef.getBoundingClientRect()) : false;
256
- const onTrigger = triggerRef ? isPointInRect(point, triggerRef.getBoundingClientRect()) : false;
253
+ // What the pointer is on, as the browser hit-tests it, not the bounding box: the corner of a
254
+ // rounded panel is inside its box but not on it, and no `pointerenter` comes from there to
255
+ // take over — tracking stopped on it left the tooltip open for good.
256
+ const target = event.target instanceof Node ? event.target : null;
257
+ const onContent = target !== null && (contentRef?.contains(target) ?? false);
258
+ const onTrigger = target !== null && (triggerRef?.contains(target) ?? false);
257
259
  if (onContent || onTrigger) {
258
260
  // The `pointerenter` of the content or the trigger takes over from here.
259
261
  stopGapTracking();
@@ -326,7 +328,10 @@
326
328
  }
327
329
 
328
330
  function handleContentPointerEnter(event: PointerEvent) {
329
- if (event.pointerType === 'touch') return;
331
+ // A closed panel is still in the DOM through its exit animation, and a pointer that lands
332
+ // on it then is not reading it: counted, it would hold the next open forever, because the
333
+ // panel leaves the DOM under the pointer and its `pointerleave` never comes.
334
+ if (event.pointerType === 'touch' || !isOpen) return;
330
335
  pointerOnContent = true;
331
336
  stopGapTracking();
332
337
  if (closeTimer !== null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@human-kit/ui",
3
- "version": "1.0.0-beta.9",
3
+ "version": "1.1.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>",
@@ -178,6 +178,26 @@
178
178
  "svelte": "./dist/radio-group/index.js",
179
179
  "default": "./dist/radio-group/index.js"
180
180
  },
181
+ "./rating": {
182
+ "types": "./dist/rating/index.d.ts",
183
+ "svelte": "./dist/rating/index.js",
184
+ "default": "./dist/rating/index.js"
185
+ },
186
+ "./pin-input": {
187
+ "types": "./dist/pin-input/index.d.ts",
188
+ "svelte": "./dist/pin-input/index.js",
189
+ "default": "./dist/pin-input/index.js"
190
+ },
191
+ "./color-picker": {
192
+ "types": "./dist/color-picker/index.d.ts",
193
+ "svelte": "./dist/color-picker/index.js",
194
+ "default": "./dist/color-picker/index.js"
195
+ },
196
+ "./search-field": {
197
+ "types": "./dist/search-field/index.d.ts",
198
+ "svelte": "./dist/search-field/index.js",
199
+ "default": "./dist/search-field/index.js"
200
+ },
181
201
  "./select": {
182
202
  "types": "./dist/select/index.d.ts",
183
203
  "svelte": "./dist/select/index.js",