@human-kit/ui 1.0.0-beta.0 → 1.0.0-beta.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.
Files changed (157) hide show
  1. package/README.md +2 -0
  2. package/dist/FOCUS_STATE_CONTRACT.md +1 -0
  3. package/dist/accordion/root/accordion-root.svelte +15 -3
  4. package/dist/accordion/root/context.svelte.js +4 -4
  5. package/dist/accordion/types.d.ts +9 -2
  6. package/dist/autocomplete/list/autocomplete-list.svelte.d.ts +6 -0
  7. package/dist/calendar/root/context.svelte.js +8 -2
  8. package/dist/checkbox/root/checkbox-root.svelte +28 -11
  9. package/dist/checkbox/root/checkbox-root.svelte.d.ts +13 -0
  10. package/dist/clock/root/create-time-selection-state.svelte.d.ts +5 -0
  11. package/dist/clock/root/create-time-selection-state.svelte.js +113 -10
  12. package/dist/clock/root/wheel-options.d.ts +7 -3
  13. package/dist/clock/root/wheel-options.js +7 -15
  14. package/dist/clock/wheel-column/clock-wheel-column.svelte +10 -2
  15. package/dist/clock/wheel-column/clock-wheel-column.svelte.d.ts +2 -1
  16. package/dist/collapsible/root/collapsible-root.svelte +9 -4
  17. package/dist/collapsible/types.d.ts +9 -0
  18. package/dist/combobox/input/combobox-input.svelte +12 -1
  19. package/dist/combobox/list/combobox-listbox.svelte +93 -1
  20. package/dist/combobox/list/combobox-listbox.svelte.d.ts +20 -0
  21. package/dist/combobox/root/combobox.svelte +118 -45
  22. package/dist/combobox/root/combobox.svelte.d.ts +11 -0
  23. package/dist/combobox/root/context.d.ts +12 -0
  24. package/dist/combobox/status/README.md +2 -2
  25. package/dist/combobox/tag-remove/combobox-tag-remove.svelte +14 -2
  26. package/dist/combobox/tag-remove/combobox-tag-remove.svelte.d.ts +7 -0
  27. package/dist/combobox/tags/combobox-tags.svelte +5 -2
  28. package/dist/combobox/tags/combobox-tags.svelte.d.ts +2 -0
  29. package/dist/combobox/trigger/combobox-trigger.svelte +4 -1
  30. package/dist/datepicker/README.md +3 -2
  31. package/dist/datepicker/root/date-picker-root.svelte +38 -2
  32. package/dist/datepicker/root/date-picker-root.svelte.d.ts +2 -0
  33. package/dist/datepicker/root/draft-evaluation.d.ts +7 -0
  34. package/dist/datepicker/root/draft-evaluation.js +2 -2
  35. package/dist/daterangepicker/root/date-range-picker-root.svelte +19 -1
  36. package/dist/daterangepicker/root/date-range-picker-root.svelte.d.ts +2 -0
  37. package/dist/dialog/README.md +9 -1
  38. package/dist/dialog/close/dialog-close.svelte +57 -0
  39. package/dist/dialog/close/dialog-close.svelte.d.ts +19 -0
  40. package/dist/dialog/content/dialog-content.svelte +2 -0
  41. package/dist/dialog/description/dialog-description.svelte +46 -0
  42. package/dist/dialog/description/dialog-description.svelte.d.ts +20 -0
  43. package/dist/dialog/index.d.ts +9 -0
  44. package/dist/dialog/index.js +3 -0
  45. package/dist/dialog/index.parts.d.ts +3 -0
  46. package/dist/dialog/index.parts.js +3 -0
  47. package/dist/dialog/root/context.d.ts +8 -0
  48. package/dist/dialog/root/dialog-root.svelte +58 -16
  49. package/dist/dialog/root/dialog-root.svelte.d.ts +10 -3
  50. package/dist/dialog/root/dialog-stack.d.ts +6 -22
  51. package/dist/dialog/root/dialog-stack.js +4 -33
  52. package/dist/dialog/title/dialog-title.svelte +43 -0
  53. package/dist/dialog/title/dialog-title.svelte.d.ts +21 -0
  54. package/dist/drawer/README.md +111 -0
  55. package/dist/drawer/body/drawer-body.svelte +47 -0
  56. package/dist/drawer/body/drawer-body.svelte.d.ts +32 -0
  57. package/dist/drawer/close/drawer-close.svelte +52 -0
  58. package/dist/drawer/close/drawer-close.svelte.d.ts +20 -0
  59. package/dist/drawer/content/drawer-content.svelte +597 -0
  60. package/dist/drawer/content/drawer-content.svelte.d.ts +28 -0
  61. package/dist/drawer/description/drawer-description.svelte +40 -0
  62. package/dist/drawer/description/drawer-description.svelte.d.ts +20 -0
  63. package/dist/drawer/indent/drawer-indent-background.svelte +36 -0
  64. package/dist/drawer/indent/drawer-indent-background.svelte.d.ts +17 -0
  65. package/dist/drawer/indent/drawer-indent.svelte +59 -0
  66. package/dist/drawer/indent/drawer-indent.svelte.d.ts +32 -0
  67. package/dist/drawer/index.d.ts +49 -0
  68. package/dist/drawer/index.js +25 -0
  69. package/dist/drawer/index.parts.d.ts +14 -0
  70. package/dist/drawer/index.parts.js +15 -0
  71. package/dist/drawer/overlay/drawer-overlay.svelte +67 -0
  72. package/dist/drawer/overlay/drawer-overlay.svelte.d.ts +12 -0
  73. package/dist/drawer/portal/drawer-portal.svelte +57 -0
  74. package/dist/drawer/portal/drawer-portal.svelte.d.ts +13 -0
  75. package/dist/drawer/root/context.d.ts +81 -0
  76. package/dist/drawer/root/context.js +20 -0
  77. package/dist/drawer/root/drawer-root.svelte +333 -0
  78. package/dist/drawer/root/drawer-root.svelte.d.ts +77 -0
  79. package/dist/drawer/root/drawer-stack.svelte.d.ts +73 -0
  80. package/dist/drawer/root/drawer-stack.svelte.js +113 -0
  81. package/dist/drawer/root/handle.svelte.d.ts +39 -0
  82. package/dist/drawer/root/handle.svelte.js +64 -0
  83. package/dist/drawer/root/keyboard-context.d.ts +13 -0
  84. package/dist/drawer/root/keyboard-context.js +8 -0
  85. package/dist/drawer/root/presence-context.d.ts +22 -0
  86. package/dist/drawer/root/presence-context.js +8 -0
  87. package/dist/drawer/root/snap-points.d.ts +68 -0
  88. package/dist/drawer/root/snap-points.js +120 -0
  89. package/dist/drawer/root/starting-style.svelte.d.ts +18 -0
  90. package/dist/drawer/root/starting-style.svelte.js +38 -0
  91. package/dist/drawer/root/types.d.ts +36 -0
  92. package/dist/drawer/root/types.js +1 -0
  93. package/dist/drawer/root/viewport-context.d.ts +2 -0
  94. package/dist/drawer/root/viewport-context.js +16 -0
  95. package/dist/drawer/swipe-area/drawer-swipe-area.svelte +143 -0
  96. package/dist/drawer/swipe-area/drawer-swipe-area.svelte.d.ts +22 -0
  97. package/dist/drawer/title/drawer-title.svelte +37 -0
  98. package/dist/drawer/title/drawer-title.svelte.d.ts +21 -0
  99. package/dist/drawer/trigger/drawer-trigger.svelte +90 -0
  100. package/dist/drawer/trigger/drawer-trigger.svelte.d.ts +41 -0
  101. package/dist/drawer/viewport/drawer-viewport.svelte +69 -0
  102. package/dist/drawer/viewport/drawer-viewport.svelte.d.ts +15 -0
  103. package/dist/drawer/virtual-keyboard/drawer-virtual-keyboard-provider.svelte +88 -0
  104. package/dist/drawer/virtual-keyboard/drawer-virtual-keyboard-provider.svelte.d.ts +29 -0
  105. package/dist/hooks/use-virtual-focus.svelte.d.ts +9 -0
  106. package/dist/hooks/use-virtual-focus.svelte.js +7 -1
  107. package/dist/index.d.ts +2 -0
  108. package/dist/index.js +2 -0
  109. package/dist/listbox/item/listbox-item.svelte +8 -1
  110. package/dist/listbox/root/context.d.ts +30 -0
  111. package/dist/listbox/root/context.js +10 -0
  112. package/dist/listbox/root/listbox.svelte +291 -8
  113. package/dist/listbox/root/listbox.svelte.d.ts +35 -2
  114. package/dist/menu/content/menu-content.svelte +3 -1
  115. package/dist/menu/overlay/menu-overlay.svelte +1 -1
  116. package/dist/numberfield/root/number-field-root.svelte +2 -1
  117. package/dist/popover/content/popover-content.svelte +1 -1
  118. package/dist/popover/overlay/popover-overlay.svelte +1 -1
  119. package/dist/popover/root/popover-root.svelte +23 -11
  120. package/dist/popover/root/popover-root.svelte.d.ts +10 -2
  121. package/dist/primitives/floating.d.ts +7 -0
  122. package/dist/primitives/floating.js +6 -2
  123. package/dist/primitives/index.d.ts +1 -0
  124. package/dist/primitives/index.js +1 -0
  125. package/dist/primitives/keyboard-navigation.js +3 -1
  126. package/dist/primitives/layer-stack.d.ts +29 -0
  127. package/dist/primitives/layer-stack.js +35 -0
  128. package/dist/primitives/list-virtualizer.d.ts +75 -0
  129. package/dist/primitives/list-virtualizer.js +59 -0
  130. package/dist/primitives/scroll-lock.d.ts +23 -3
  131. package/dist/primitives/scroll-lock.js +122 -9
  132. package/dist/primitives/swipe-gesture.d.ts +126 -0
  133. package/dist/primitives/swipe-gesture.js +351 -0
  134. package/dist/primitives/text.d.ts +8 -0
  135. package/dist/primitives/text.js +13 -0
  136. package/dist/switch/root/switch-root.svelte +23 -9
  137. package/dist/switch/root/switch-root.svelte.d.ts +9 -2
  138. package/dist/table/body/table-body.svelte +84 -9
  139. package/dist/table/cell/table-cell.svelte +1 -3
  140. package/dist/table/column/table-column.svelte +5 -1
  141. package/dist/table/column-resizer/table-column-resizer.svelte +1 -5
  142. package/dist/table/interactive-cell/table-interactive-cell.svelte +1 -3
  143. package/dist/table/root/context.svelte.js +99 -49
  144. package/dist/table/row/table-row.svelte +7 -7
  145. package/dist/table/sort-trigger/table-sort-trigger.svelte +5 -1
  146. package/dist/table/types.d.ts +6 -0
  147. package/dist/tabs/root/tabs-root.svelte +20 -6
  148. package/dist/tabs/types.d.ts +9 -0
  149. package/dist/timepicker/root/time-picker-root.svelte +11 -0
  150. package/dist/timepicker/root/time-picker-root.svelte.d.ts +2 -0
  151. package/dist/toggle-group/root/context.svelte.js +11 -4
  152. package/dist/toggle-group/root/toggle-group-root.svelte +19 -4
  153. package/dist/toggle-group/types.d.ts +9 -0
  154. package/dist/tree/root/context.svelte.js +6 -0
  155. package/dist/tree/root/tree-root.svelte +22 -8
  156. package/dist/tree/types.d.ts +13 -0
  157. package/package.json +227 -224
@@ -61,7 +61,7 @@ export function createTableContext(options = {}) {
61
61
  let focusedCellKey = $state(null);
62
62
  let focusedRowTarget = $state(null);
63
63
  let focusVisible = $state(false);
64
- const initialSelectedKeys = new Set(options.initialSelectedKeys ?? []);
64
+ const initialSelectedKeys = new SvelteSet(options.initialSelectedKeys ?? []);
65
65
  let selectedKeys = $state(initialSelectedKeys);
66
66
  let selectionAnchorKey = $state(initialSelectedKeys.values().next().value ?? null);
67
67
  const disabledKeys = new SvelteSet(options.disabledKeys ?? []);
@@ -69,24 +69,29 @@ export function createTableContext(options = {}) {
69
69
  let resizingColumnId = $state(null);
70
70
  let resizeSession = null;
71
71
  let suppressNextHeaderClick = false;
72
- const columns = new Map();
73
- const columnIds = new Map();
72
+ const columns = new SvelteMap();
73
+ const columnIds = new SvelteMap();
74
74
  const columnOrder = [];
75
- const columnsWithSortTriggers = new Set();
76
- const columnsWithResizers = new Set();
75
+ const columnsWithSortTriggers = new SvelteSet();
76
+ const columnsWithResizers = new SvelteSet();
77
77
  let resizerLayoutReady = false;
78
78
  const columnWidths = new SvelteMap(options.initialColumnWidths ?? []);
79
- const rows = new Map();
79
+ const rows = new SvelteMap();
80
80
  const headerRowOrder = [];
81
- const headerRowOrderSet = new Set();
81
+ const headerRowOrderSet = new SvelteSet();
82
82
  const bodyRowOrder = [];
83
- const bodyRowOrderSet = new Set();
83
+ const bodyRowOrderSet = new SvelteSet();
84
84
  let bodyRowsInitialized = false;
85
85
  let selectableBodyRowCount = 0;
86
86
  let logicalBodyRowIds = null;
87
87
  let logicalBodyRowIndexCache = null;
88
- const cells = new Map();
89
- const cellOrderSet = new Set();
88
+ const cells = new SvelteMap();
89
+ const cellOrderSet = new SvelteSet();
90
+ // Cell keys grouped by row, so dropping a row does not have to scan every
91
+ // registered cell. Virtualized scrolling unmounts rows continuously, and a
92
+ // full scan there costs (rows unmounted x total cells) per frame.
93
+ // eslint-disable-next-line svelte/prefer-svelte-reactivity -- a lookup index, not state: see the note above on the per-frame cost.
94
+ const cellKeysByRowToken = new Map();
90
95
  let orderedRowTokensCache = {
91
96
  header: null,
92
97
  body: null
@@ -113,9 +118,14 @@ export function createTableContext(options = {}) {
113
118
  let layoutEpoch = $state(0);
114
119
  let selectionEpoch = $state(0);
115
120
  let widthEpoch = $state(0);
121
+ // Plain Map on purpose. These counters only ever mint unique tokens; nothing
122
+ // reads them reactively. As a SvelteMap every row and every cell created a
123
+ // reactive source on mount — hundreds per scroll tick — and in dev each of
124
+ // those costs a stack capture (`get_stack` was 58% of mount in the profile).
125
+ // eslint-disable-next-line svelte/prefer-svelte-reactivity -- see the note above: reactive here cost 58% of mount time.
116
126
  const instanceCounters = new Map();
117
127
  const selectionUnavailableDescriptionId = createInstanceToken('selection-unavailable');
118
- setSelectedKeys(new Set(initialSelectedKeys), initialSelectedKeys.values().next().value ?? null);
128
+ setSelectedKeys(new SvelteSet(initialSelectedKeys), initialSelectedKeys.values().next().value ?? null);
119
129
  function createInstanceToken(prefix) {
120
130
  const nextCount = (instanceCounters.get(prefix) ?? 0) + 1;
121
131
  instanceCounters.set(prefix, nextCount);
@@ -205,8 +215,14 @@ export function createTableContext(options = {}) {
205
215
  columnWidthsCache = null;
206
216
  visibleColumnWidthsCache = null;
207
217
  resolvedVisibleColumnWidthsCache = null;
208
- measuredTableWidthCache = undefined;
209
- hasMeasuredTableWidthCache = false;
218
+ // The measured *container* width is deliberately NOT invalidated here.
219
+ // It is the stable reference fr/% resolution is built on (see
220
+ // `getMeasuredTableWidth`), and setting a column width cannot change it —
221
+ // only a real container/window resize can, which arrives through
222
+ // `refreshMeasuredLayout`. Clearing it on every width write made each
223
+ // resize frame re-run `getBoundingClientRect` + `getComputedStyle`
224
+ // immediately after writing new widths: a forced synchronous layout per
225
+ // frame, which profiled as ~87% of the column-drag cost.
210
226
  if (!widthNotifyScheduled) {
211
227
  widthNotifyScheduled = true;
212
228
  queueMicrotask(() => {
@@ -478,7 +494,17 @@ export function createTableContext(options = {}) {
478
494
  return key ? (cells.get(key) ?? null) : null;
479
495
  }
480
496
  function getResolvedBodyCellsForRow(rowToken) {
481
- return Array.from(cells.values()).filter((cell) => cell.section === 'body' && cell.rowToken === rowToken);
497
+ const rowCellKeys = cellKeysByRowToken.get(rowToken);
498
+ if (!rowCellKeys)
499
+ return [];
500
+ const rowCells = [];
501
+ for (const key of rowCellKeys) {
502
+ const cell = cells.get(key);
503
+ if (cell?.section === 'body') {
504
+ rowCells.push(cell);
505
+ }
506
+ }
507
+ return rowCells;
482
508
  }
483
509
  function registerColumn(column) {
484
510
  const existing = columns.get(column.token);
@@ -525,7 +551,7 @@ export function createTableContext(options = {}) {
525
551
  return orderedColumnTokensCache;
526
552
  // Pre-build a lookup from columnToken → header cell element to avoid
527
553
  // O(columns × cells) scanning inside the comparator.
528
- const headerElementByToken = new Map();
554
+ const headerElementByToken = new SvelteMap();
529
555
  for (const cell of cells.values()) {
530
556
  if (cell.section === 'header' && cell.columnToken && cell.element) {
531
557
  headerElementByToken.set(cell.columnToken, cell.element);
@@ -568,7 +594,7 @@ export function createTableContext(options = {}) {
568
594
  function getVisibleColumnIndexByTokenMap() {
569
595
  if (visibleColumnIndexByTokenCache)
570
596
  return visibleColumnIndexByTokenCache;
571
- const visibleColumnIndexByToken = new Map(getVisibleOrderedColumnTokens().map((token, index) => [token, index]));
597
+ const visibleColumnIndexByToken = new SvelteMap(getVisibleOrderedColumnTokens().map((token, index) => [token, index]));
572
598
  visibleColumnIndexByTokenCache = visibleColumnIndexByToken;
573
599
  return visibleColumnIndexByToken;
574
600
  }
@@ -710,7 +736,7 @@ export function createTableContext(options = {}) {
710
736
  function getColumnWidths() {
711
737
  if (columnWidthsCache)
712
738
  return columnWidthsCache;
713
- const widths = new Map();
739
+ const widths = new SvelteMap();
714
740
  for (const token of getOrderedColumnTokens()) {
715
741
  const column = columns.get(token);
716
742
  if (!column)
@@ -726,7 +752,7 @@ export function createTableContext(options = {}) {
726
752
  function getVisibleColumnWidths() {
727
753
  if (visibleColumnWidthsCache)
728
754
  return visibleColumnWidthsCache;
729
- const widths = new Map();
755
+ const widths = new SvelteMap();
730
756
  for (const [columnId, width] of getColumnWidths()) {
731
757
  if (isColumnHidden(columnId))
732
758
  continue;
@@ -749,7 +775,7 @@ export function createTableContext(options = {}) {
749
775
  function getResolvedVisibleColumnWidths() {
750
776
  if (resolvedVisibleColumnWidthsCache)
751
777
  return resolvedVisibleColumnWidthsCache;
752
- const widths = new Map();
778
+ const widths = new SvelteMap();
753
779
  const flexibleColumns = [];
754
780
  const relativeColumns = [];
755
781
  const tableWidth = getMeasuredTableWidth();
@@ -837,8 +863,8 @@ export function createTableContext(options = {}) {
837
863
  .at(-1)?.id;
838
864
  }
839
865
  function prepareColumnWidthsForResize(activeColumnId) {
840
- const next = new Map(columnWidths);
841
- const baselineWidths = new Map();
866
+ const next = new SvelteMap(columnWidths);
867
+ const baselineWidths = new SvelteMap();
842
868
  const preservedFlexibleColumnId = getResizableRelativeTailColumnId(activeColumnId);
843
869
  const preservedFlexibleEffectiveWidth = preservedFlexibleColumnId
844
870
  ? normalizeColumnWidth(getEffectiveColumnWidthSpec(preservedFlexibleColumnId))
@@ -900,8 +926,8 @@ export function createTableContext(options = {}) {
900
926
  return resizeSession?.activeColumnId !== columnId;
901
927
  }
902
928
  function setColumnWidths(widths) {
903
- const next = new Map();
904
- const incomingWidths = widths ? new Map(widths) : undefined;
929
+ const next = new SvelteMap();
930
+ const incomingWidths = widths ? new SvelteMap(widths) : undefined;
905
931
  for (const token of columnOrder) {
906
932
  const column = columns.get(token);
907
933
  if (!column)
@@ -1052,7 +1078,7 @@ export function createTableContext(options = {}) {
1052
1078
  }
1053
1079
  }
1054
1080
  function setHiddenColumns(columnIds) {
1055
- const next = new Set(columnIds ?? []);
1081
+ const next = new SvelteSet(columnIds ?? []);
1056
1082
  let changed = next.size !== hiddenColumnIds.size;
1057
1083
  if (!changed) {
1058
1084
  for (const columnId of hiddenColumnIds) {
@@ -1257,11 +1283,13 @@ export function createTableContext(options = {}) {
1257
1283
  }
1258
1284
  headerRowOrderSet.delete(token);
1259
1285
  bodyRowOrderSet.delete(token);
1260
- for (const [key, cell] of cells.entries()) {
1261
- if (cell.rowToken === token) {
1286
+ const rowCellKeys = cellKeysByRowToken.get(token);
1287
+ if (rowCellKeys) {
1288
+ for (const key of rowCellKeys) {
1262
1289
  cells.delete(key);
1263
1290
  cellOrderSet.delete(key);
1264
1291
  }
1292
+ cellKeysByRowToken.delete(token);
1265
1293
  }
1266
1294
  if (row && focusedCellKey) {
1267
1295
  const focusedCell = resolveCellTargetByKey(focusedCellKey);
@@ -1304,7 +1332,7 @@ export function createTableContext(options = {}) {
1304
1332
  if (!logicalBodyRowIds)
1305
1333
  return -1;
1306
1334
  if (!logicalBodyRowIndexCache) {
1307
- logicalBodyRowIndexCache = new Map();
1335
+ logicalBodyRowIndexCache = new SvelteMap();
1308
1336
  for (let index = 0; index < logicalBodyRowIds.length; index += 1) {
1309
1337
  const rowId = logicalBodyRowIds[index];
1310
1338
  if (!logicalBodyRowIndexCache.has(rowId)) {
@@ -1459,6 +1487,7 @@ export function createTableContext(options = {}) {
1459
1487
  return;
1460
1488
  }
1461
1489
  cells.set(cell.key, cell);
1490
+ indexCellByRow(cell);
1462
1491
  seedDefaultFocusKeyFromCell(cell);
1463
1492
  if (!alreadyOrdered) {
1464
1493
  cellOrderSet.add(cell.key);
@@ -1471,9 +1500,30 @@ export function createTableContext(options = {}) {
1471
1500
  scheduleBodyStructureCacheInvalidation();
1472
1501
  }
1473
1502
  }
1503
+ function indexCellByRow(cell) {
1504
+ const existing = cellKeysByRowToken.get(cell.rowToken);
1505
+ if (existing) {
1506
+ existing.add(cell.key);
1507
+ return;
1508
+ }
1509
+ // eslint-disable-next-line svelte/prefer-svelte-reactivity -- a bucket inside the non-reactive index above.
1510
+ cellKeysByRowToken.set(cell.rowToken, new Set([cell.key]));
1511
+ }
1512
+ function unindexCellByRow(cell) {
1513
+ if (!cell)
1514
+ return;
1515
+ const keys = cellKeysByRowToken.get(cell.rowToken);
1516
+ if (!keys)
1517
+ return;
1518
+ keys.delete(cell.key);
1519
+ if (keys.size === 0) {
1520
+ cellKeysByRowToken.delete(cell.rowToken);
1521
+ }
1522
+ }
1474
1523
  function unregisterCell(key) {
1475
1524
  defaultFocusKeyCache = undefined;
1476
1525
  const cell = cells.get(key);
1526
+ unindexCellByRow(cell);
1477
1527
  cells.delete(key);
1478
1528
  cellOrderSet.delete(key);
1479
1529
  if (focusedCellKey === key) {
@@ -1576,7 +1626,7 @@ export function createTableContext(options = {}) {
1576
1626
  function getRowsWithCells() {
1577
1627
  if (rowsWithCellsCache)
1578
1628
  return rowsWithCellsCache;
1579
- const rowsByIndex = new Map();
1629
+ const rowsByIndex = new SvelteMap();
1580
1630
  for (const { cell, coord } of getNavigableCells()) {
1581
1631
  const rowCells = rowsByIndex.get(coord.row) ?? [];
1582
1632
  rowCells.push({ col: coord.col, key: cell.key, element: cell.element });
@@ -1695,13 +1745,13 @@ export function createTableContext(options = {}) {
1695
1745
  return true;
1696
1746
  }
1697
1747
  function setSelectedKeys(next, anchor) {
1698
- const previousSelectedKeys = new Set(selectedKeys);
1748
+ const previousSelectedKeys = new SvelteSet(selectedKeys);
1699
1749
  selectedKeys =
1700
1750
  selectionMode === 'none'
1701
- ? new Set()
1751
+ ? new SvelteSet()
1702
1752
  : selectionMode === 'single' && next.size > 1
1703
- ? new Set([next.values().next().value])
1704
- : next;
1753
+ ? new SvelteSet([next.values().next().value])
1754
+ : new SvelteSet(next);
1705
1755
  if (selectionMode !== 'none' && disallowEmptySelection && selectedKeys.size === 0) {
1706
1756
  const fallbackKey = (anchor !== undefined && anchor !== null && !isRowSelectionDisabled(anchor)
1707
1757
  ? anchor
@@ -1711,7 +1761,7 @@ export function createTableContext(options = {}) {
1711
1761
  if (fallbackKey !== undefined &&
1712
1762
  fallbackKey !== null &&
1713
1763
  !isRowSelectionDisabled(fallbackKey)) {
1714
- selectedKeys = new Set([fallbackKey]);
1764
+ selectedKeys = new SvelteSet([fallbackKey]);
1715
1765
  }
1716
1766
  }
1717
1767
  const fallbackAnchor = selectedKeys.values().next().value ?? null;
@@ -1724,7 +1774,7 @@ export function createTableContext(options = {}) {
1724
1774
  function replaceSelectionWithRow(id) {
1725
1775
  if (id === undefined || isRowSelectionDisabled(id))
1726
1776
  return;
1727
- const next = new Set([id]);
1777
+ const next = new SvelteSet([id]);
1728
1778
  if (hasSameSelection(selectedKeys, next)) {
1729
1779
  setSelectedKeys(next, id);
1730
1780
  notifySelection();
@@ -1734,7 +1784,7 @@ export function createTableContext(options = {}) {
1734
1784
  emitSelectionChange();
1735
1785
  }
1736
1786
  function applySelectionChange(next, anchor) {
1737
- const previousSelection = new Set(selectedKeys);
1787
+ const previousSelection = new SvelteSet(selectedKeys);
1738
1788
  const previousAnchor = selectionAnchorKey;
1739
1789
  setSelectedKeys(next, anchor);
1740
1790
  if (!hasSameSelection(previousSelection, selectedKeys)) {
@@ -1750,10 +1800,10 @@ export function createTableContext(options = {}) {
1750
1800
  return;
1751
1801
  if (selectionMode === 'single') {
1752
1802
  const wasSelected = selectedKeys.has(id);
1753
- applySelectionChange(selectionBehavior === 'toggle' && wasSelected ? new Set() : new Set([id]), selectionBehavior === 'toggle' && wasSelected ? null : id);
1803
+ applySelectionChange(selectionBehavior === 'toggle' && wasSelected ? new SvelteSet() : new SvelteSet([id]), selectionBehavior === 'toggle' && wasSelected ? null : id);
1754
1804
  return;
1755
1805
  }
1756
- const next = new Set(selectedKeys);
1806
+ const next = new SvelteSet(selectedKeys);
1757
1807
  if (next.has(id)) {
1758
1808
  next.delete(id);
1759
1809
  }
@@ -1784,7 +1834,7 @@ export function createTableContext(options = {}) {
1784
1834
  }
1785
1835
  const start = Math.min(anchorIndex, targetIndex);
1786
1836
  const end = Math.max(anchorIndex, targetIndex);
1787
- applySelectionChange(new Set(orderedIds.slice(start, end + 1)), anchor);
1837
+ applySelectionChange(new SvelteSet(orderedIds.slice(start, end + 1)), anchor);
1788
1838
  }
1789
1839
  function performRowAction(id) {
1790
1840
  if (!onRowAction || id === undefined || isRowActionDisabled(id))
@@ -2035,7 +2085,7 @@ export function createTableContext(options = {}) {
2035
2085
  focusCellByKey(rowCells[rowCells.length - 1]?.key ?? null);
2036
2086
  }
2037
2087
  function emitSelectionChange() {
2038
- options.onSelectionChange?.(new Set(selectedKeys));
2088
+ options.onSelectionChange?.(new SvelteSet(selectedKeys));
2039
2089
  notifySelection();
2040
2090
  }
2041
2091
  function toggleRowSelection(id) {
@@ -2043,10 +2093,10 @@ export function createTableContext(options = {}) {
2043
2093
  return;
2044
2094
  if (selectionMode === 'single') {
2045
2095
  const wasSelected = selectedKeys.has(id);
2046
- applySelectionChange(wasSelected ? new Set() : new Set([id]), wasSelected ? null : id);
2096
+ applySelectionChange(wasSelected ? new SvelteSet() : new SvelteSet([id]), wasSelected ? null : id);
2047
2097
  return;
2048
2098
  }
2049
- const next = new Set(selectedKeys);
2099
+ const next = new SvelteSet(selectedKeys);
2050
2100
  if (next.has(id)) {
2051
2101
  next.delete(id);
2052
2102
  }
@@ -2058,18 +2108,18 @@ export function createTableContext(options = {}) {
2058
2108
  function selectAllRows() {
2059
2109
  if (selectionMode !== 'multiple')
2060
2110
  return;
2061
- const next = new Set(getOrderedSelectableRowIds());
2111
+ const next = new SvelteSet(getOrderedSelectableRowIds());
2062
2112
  applySelectionChange(next, next.values().next().value ?? null);
2063
2113
  }
2064
2114
  function deselectAllRows() {
2065
2115
  if (selectedKeys.size === 0)
2066
2116
  return;
2067
- applySelectionChange(new Set(), null);
2117
+ applySelectionChange(new SvelteSet(), null);
2068
2118
  }
2069
2119
  function setSelection(keys) {
2070
- const previousSelection = new Set(selectedKeys);
2120
+ const previousSelection = new SvelteSet(selectedKeys);
2071
2121
  const previousAnchor = selectionAnchorKey;
2072
- const next = new Set(keys);
2122
+ const next = new SvelteSet(keys);
2073
2123
  const preservedAnchor = selectionAnchorKey !== null && next.has(selectionAnchorKey) ? selectionAnchorKey : undefined;
2074
2124
  setSelectedKeys(next, preservedAnchor);
2075
2125
  if (!hasSameSelection(previousSelection, selectedKeys)) {
@@ -2081,10 +2131,10 @@ export function createTableContext(options = {}) {
2081
2131
  }
2082
2132
  }
2083
2133
  function setSelectionMode(mode) {
2084
- const previousSelectedKeys = new Set(selectedKeys);
2134
+ const previousSelectedKeys = new SvelteSet(selectedKeys);
2085
2135
  const previousAnchor = selectionAnchorKey;
2086
2136
  selectionMode = mode;
2087
- setSelectedKeys(new Set(selectedKeys), selectionAnchorKey);
2137
+ setSelectedKeys(new SvelteSet(selectedKeys), selectionAnchorKey);
2088
2138
  if (!hasSameSelection(previousSelectedKeys, selectedKeys) ||
2089
2139
  previousAnchor !== selectionAnchorKey) {
2090
2140
  emitSelectionChange();
@@ -2105,8 +2155,8 @@ export function createTableContext(options = {}) {
2105
2155
  }
2106
2156
  function setDisallowEmptySelection(disallow) {
2107
2157
  disallowEmptySelection = disallow;
2108
- const previousSelection = new Set(selectedKeys);
2109
- setSelectedKeys(new Set(selectedKeys), selectionAnchorKey);
2158
+ const previousSelection = new SvelteSet(selectedKeys);
2159
+ setSelectedKeys(new SvelteSet(selectedKeys), selectionAnchorKey);
2110
2160
  if (!hasSameSelection(previousSelection, selectedKeys)) {
2111
2161
  emitSelectionChange();
2112
2162
  return;
@@ -1,7 +1,11 @@
1
1
  <script lang="ts">
2
2
  import { onDestroy } from 'svelte';
3
3
  import { SvelteMap, SvelteSet } from 'svelte/reactivity';
4
- import { setTableRowContext, useTableContext, useTableSectionContext } from '../root/context.svelte';
4
+ import {
5
+ setTableRowContext,
6
+ useTableContext,
7
+ useTableSectionContext
8
+ } from '../root/context.svelte';
5
9
  import type { TableRowProps } from '../types.js';
6
10
  import {
7
11
  shouldShowFocusVisible,
@@ -260,12 +264,8 @@
260
264
  return table.getRowAriaIndex(rowToken);
261
265
  });
262
266
  const isSelected = $derived(section.section === 'body' ? table.isRowSelected(id) : false);
263
- const isFocusWithin = $derived(
264
- section.section === 'body' ? table.isRowFocused(rowToken) : false
265
- );
266
- const isFocused = $derived(
267
- section.section === 'body' ? table.isRowFocusTarget(rowToken) : false
268
- );
267
+ const isFocusWithin = $derived(section.section === 'body' ? table.isRowFocused(rowToken) : false);
268
+ const isFocused = $derived(section.section === 'body' ? table.isRowFocusTarget(rowToken) : false);
269
269
  const isFocusVisible = $derived(
270
270
  section.section === 'body' ? isFocused && table.focusVisible : false
271
271
  );
@@ -1,6 +1,10 @@
1
1
  <script lang="ts">
2
2
  import type { Snippet } from 'svelte';
3
- import { useTableCellContext, useTableColumnContext, useTableContext } from '../root/context.svelte';
3
+ import {
4
+ useTableCellContext,
5
+ useTableColumnContext,
6
+ useTableContext
7
+ } from '../root/context.svelte';
4
8
  import type { TableSortTriggerProps, TableSortTriggerRenderState } from '../types.js';
5
9
  import {
6
10
  shouldShowFocusVisible,
@@ -59,6 +59,12 @@ export type TableHeaderProps = Omit<HTMLAttributes<HTMLTableSectionElement>, 'ch
59
59
  };
60
60
  export type TableBodyVirtualizer = {
61
61
  rowHeight: number;
62
+ /**
63
+ * Extra rows rendered above and below the viewport, defaulting to 18. It
64
+ * buffers against row render cost: while the main thread builds rows, the
65
+ * compositor keeps scrolling, and anything past the last rendered row shows
66
+ * as blank. Raise it for expensive rows or very fast scrolling.
67
+ */
62
68
  overscan?: number;
63
69
  };
64
70
  type TableBodyBaseProps = Omit<HTMLAttributes<HTMLTableSectionElement>, 'children'> & {
@@ -11,6 +11,7 @@
11
11
  disabled = false,
12
12
  value = $bindable(),
13
13
  defaultValue,
14
+ controlledValue = false,
14
15
  disabledKeys,
15
16
  onChange,
16
17
  children,
@@ -21,7 +22,11 @@
21
22
  ...restProps
22
23
  }: TabsRootProps = $props();
23
24
 
24
- const isValueControlled = untrack(() => value !== undefined);
25
+ // Controlled-ness is opt-in, not inferred from `value` being defined: `bind:value` and
26
+ // `value={...}` are indistinguishable at runtime. It used to be inferred here, and the
27
+ // write-back below then ignored the result — so a genuinely controlled parent could
28
+ // not reject a change; the tab moved regardless of what `onChange` decided.
29
+ const isValueControlled = untrack(() => controlledValue);
25
30
  const instanceId = untrack(() => id) ?? generatedId;
26
31
 
27
32
  let rootRef: HTMLDivElement | null = $state(null);
@@ -34,14 +39,16 @@
34
39
  orientation: (() => orientation)(),
35
40
  isDisabled: (() => disabled)(),
36
41
  disabledKeys: (() => disabledKeys)(),
37
- initialValue: isValueControlled
38
- ? (untrack(() => value) ?? null)
39
- : untrack(() => defaultValue),
42
+ // `value` seeds the initial selection whenever it is supplied, bound or not.
43
+ initialValue: untrack(() => value) ?? untrack(() => defaultValue),
40
44
  onValueChange: (nextValue) => {
41
- value = nextValue;
45
+ if (!isValueControlled) {
46
+ value = nextValue;
47
+ }
42
48
  onChange?.(nextValue);
43
49
  },
44
50
  onValueSync: (nextValue) => {
51
+ if (isValueControlled) return;
45
52
  value = nextValue;
46
53
  }
47
54
  })
@@ -69,8 +76,15 @@
69
76
  tabs.setDisabledKeys(disabledKeys);
70
77
  });
71
78
 
79
+ // Whether to adopt an incoming `value` is a separate question from who owns the state,
80
+ // so it is latched at init off the prop rather than off `controlledValue`: a parent
81
+ // that supplies `value` drives the selection, bound or not. Latched, not reactive —
82
+ // re-checking `value !== undefined` would switch this on the moment our own write-back
83
+ // defines it, and the component would then re-adopt the echo of its own change.
84
+ const adoptsValueProp = untrack(() => value !== undefined);
85
+
72
86
  $effect(() => {
73
- if (!isValueControlled) return;
87
+ if (!adoptsValueProp) return;
74
88
  tabs.setSelectedValue(value ?? null);
75
89
  });
76
90
  </script>
@@ -6,8 +6,17 @@ export type TabsRootProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'c
6
6
  keyboardActivation?: TabsKeyboardActivation;
7
7
  orientation?: TabsOrientation;
8
8
  disabled?: boolean;
9
+ /** Selected tab value. Two-way by default — use `bind:value`. */
9
10
  value?: TabsValue | null;
11
+ /** Initially selected value, for when `value` is not supplied. */
10
12
  defaultValue?: TabsValue | null;
13
+ /**
14
+ * Opt into fully controlled state: the component stops writing back to `value` and
15
+ * only reports through `onChange`, so the parent can reject a change by not flowing
16
+ * the new value back down. Off by default, because `bind:value` — the common case —
17
+ * needs the write-back to work at all.
18
+ */
19
+ controlledValue?: boolean;
11
20
  disabledKeys?: Iterable<TabsValue>;
12
21
  onChange?: (value: TabsValue | null) => void;
13
22
  children?: Snippet;
@@ -21,6 +21,7 @@
21
21
  id?: string;
22
22
  value?: TimePickerTimeValue | null;
23
23
  defaultValue?: TimePickerTimeValue | null;
24
+ controlledValue?: boolean;
24
25
  onChange?: (value: TimePickerTimeValue | null) => void;
25
26
  minValue?: TimePickerTimeValue;
26
27
  maxValue?: TimePickerTimeValue;
@@ -34,6 +35,7 @@
34
35
  required?: boolean;
35
36
  open?: boolean;
36
37
  defaultOpen?: boolean;
38
+ controlledOpen?: boolean;
37
39
  onOpenChange?: (open: boolean, details: TimePickerOpenChangeDetails) => void;
38
40
  children?: Snippet;
39
41
  class?: string;
@@ -47,6 +49,7 @@
47
49
  id,
48
50
  value = $bindable(),
49
51
  defaultValue,
52
+ controlledValue = false,
50
53
  onChange,
51
54
  minValue,
52
55
  maxValue,
@@ -60,6 +63,7 @@
60
63
  required = false,
61
64
  open = $bindable(),
62
65
  defaultOpen = false,
66
+ controlledOpen = false,
63
67
  onOpenChange,
64
68
  children,
65
69
  class: className = '',
@@ -93,6 +97,9 @@
93
97
  value: () => value,
94
98
  defaultValue: () => defaultValue,
95
99
  writeValue: (next) => {
100
+ // Fully controlled: report only (via `onChange` below) and let the parent flow
101
+ // the value back down through the `value` prop.
102
+ if (controlledValue) return;
96
103
  value = next;
97
104
  },
98
105
  onChange: (next) => onChange?.(next),
@@ -162,6 +169,10 @@
162
169
  onOpenChange?.(nextOpen, resolvedDetails);
163
170
  if (resolvedDetails.isCanceled) return;
164
171
 
172
+ // Fully controlled: the parent owns the state and flows it back down through the
173
+ // `open` prop (the adopt effect above picks it up), so don't write it here.
174
+ if (controlledOpen) return;
175
+
165
176
  openInternal = nextOpen;
166
177
  open = nextOpen;
167
178
  }
@@ -5,6 +5,7 @@ type TimePickerRootProps = {
5
5
  id?: string;
6
6
  value?: TimePickerTimeValue | null;
7
7
  defaultValue?: TimePickerTimeValue | null;
8
+ controlledValue?: boolean;
8
9
  onChange?: (value: TimePickerTimeValue | null) => void;
9
10
  minValue?: TimePickerTimeValue;
10
11
  maxValue?: TimePickerTimeValue;
@@ -18,6 +19,7 @@ type TimePickerRootProps = {
18
19
  required?: boolean;
19
20
  open?: boolean;
20
21
  defaultOpen?: boolean;
22
+ controlledOpen?: boolean;
21
23
  onOpenChange?: (open: boolean, details: TimePickerOpenChangeDetails) => void;
22
24
  children?: Snippet;
23
25
  class?: string;
@@ -1,12 +1,12 @@
1
1
  import { getContext, setContext } from 'svelte';
2
- import { SvelteMap } from 'svelte/reactivity';
2
+ import { SvelteMap, SvelteSet } from 'svelte/reactivity';
3
3
  import { asCommand } from '../../internal/as-command.js';
4
4
  const TOGGLE_GROUP_CONTEXT_KEY = Symbol('toggle-group');
5
5
  function valuesMatch(left, right) {
6
6
  return Object.is(left, right);
7
7
  }
8
8
  function normalizeValues(values, selectionMode, order = []) {
9
- const normalized = new Set();
9
+ const normalized = new SvelteSet();
10
10
  if (selectionMode === 'single') {
11
11
  const value = order.find((orderedValue) => (values ?? []).some((candidate) => valuesMatch(candidate, orderedValue)));
12
12
  const fallbackValue = (values ?? []).find((candidate) => !order.some((orderedValue) => valuesMatch(candidate, orderedValue)));
@@ -115,6 +115,13 @@ export function createToggleGroupContext(options) {
115
115
  previousValue.some((value, index) => !valuesMatch(value, nextValue[index]));
116
116
  if (!didChange)
117
117
  return false;
118
+ if (isControlled && changeOptions?.notify !== false) {
119
+ // Controlled mode: request the change and let the parent apply it via props.
120
+ // Mirrors Accordion's identical `setOpen`, which had this guard while this one
121
+ // silently fell through and applied the change the parent might have rejected.
122
+ options.onValueChange?.(nextValue);
123
+ return true;
124
+ }
118
125
  selectedValues = normalizedValues;
119
126
  if (changeOptions?.notify !== false) {
120
127
  options.onValueChange?.(nextValue);
@@ -124,7 +131,7 @@ export function createToggleGroupContext(options) {
124
131
  function reconcileSelection(changedValue, changeOptions) {
125
132
  if (isControlled)
126
133
  return;
127
- const nextValues = new Set(selectedValues);
134
+ const nextValues = new SvelteSet(selectedValues);
128
135
  let removedSelectedValue;
129
136
  for (const selectedValue of selectedValues) {
130
137
  const registeredToggle = toggles.get(selectedValue);
@@ -216,7 +223,7 @@ export function createToggleGroupContext(options) {
216
223
  if (isToggleDisabled(value))
217
224
  return null;
218
225
  const isValueSelected = selectedValues.has(value);
219
- const nextValues = new Set(selectedValues);
226
+ const nextValues = new SvelteSet(selectedValues);
220
227
  if (selectionMode === 'single') {
221
228
  if (isValueSelected) {
222
229
  if (disallowEmptySelection)