@svgrid/grid 2.2.0 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/dist/FlexRender.svelte +96 -96
  2. package/dist/GridFooter.svelte +178 -178
  3. package/dist/SvCarousel.svelte +141 -141
  4. package/dist/SvColorInput.svelte +187 -187
  5. package/dist/SvContextMenu.svelte +116 -116
  6. package/dist/SvDrawer.svelte +250 -250
  7. package/dist/SvGrid.svelte +3131 -3131
  8. package/dist/SvGridBoard.svelte +2339 -2339
  9. package/dist/SvGridChart.svelte +1724 -1724
  10. package/dist/SvGridChartPanel.svelte +485 -485
  11. package/dist/SvGridDropdown.svelte +689 -689
  12. package/dist/SvGroupCell.svelte +109 -109
  13. package/dist/SvMenu.svelte +124 -124
  14. package/dist/SvMenuList.svelte +117 -117
  15. package/dist/SvNumberInput.svelte +131 -131
  16. package/dist/SvOtpInput.svelte +158 -158
  17. package/dist/SvPopover.svelte +139 -139
  18. package/dist/SvRowGroupPanel.svelte +170 -170
  19. package/dist/SvScrollArea.svelte +61 -61
  20. package/dist/SvTooltip.svelte +127 -127
  21. package/dist/SvTour.svelte +204 -204
  22. package/dist/SvTree.svelte +377 -377
  23. package/dist/SvTreeSelect.svelte +230 -230
  24. package/dist/cdn/svgrid.js +8 -8
  25. package/dist/cdn/svgrid.svelte-external.js +8 -8
  26. package/dist/chart-export.js +8 -8
  27. package/package.json +10 -10
  28. package/src/FlexRender.svelte +96 -96
  29. package/src/GridFooter.svelte +178 -178
  30. package/src/SvCarousel.svelte +141 -141
  31. package/src/SvColorInput.svelte +187 -187
  32. package/src/SvContextMenu.svelte +116 -116
  33. package/src/SvDrawer.svelte +250 -250
  34. package/src/SvGrid.controller.svelte.ts +3158 -3158
  35. package/src/SvGrid.svelte +3131 -3131
  36. package/src/SvGrid.types.ts +1489 -1489
  37. package/src/SvGridBoard.svelte +2339 -2339
  38. package/src/SvGridChart.svelte +1724 -1724
  39. package/src/SvGridChartPanel.svelte +485 -485
  40. package/src/SvGridDropdown.svelte +689 -689
  41. package/src/SvGroupCell.svelte +109 -109
  42. package/src/SvMenu.svelte +124 -124
  43. package/src/SvMenu.test.ts +97 -97
  44. package/src/SvMenuList.svelte +117 -117
  45. package/src/SvNumberInput.svelte +131 -131
  46. package/src/SvOtpInput.svelte +158 -158
  47. package/src/SvPopover.svelte +139 -139
  48. package/src/SvRowGroupPanel.svelte +170 -170
  49. package/src/SvScrollArea.svelte +61 -61
  50. package/src/SvTooltip.svelte +127 -127
  51. package/src/SvTour.svelte +204 -204
  52. package/src/SvTree.svelte +377 -377
  53. package/src/SvTreeSelect.svelte +230 -230
  54. package/src/a11y.contract.test.ts +49 -49
  55. package/src/a11y.test.ts +59 -59
  56. package/src/a11y.ts +61 -61
  57. package/src/build-api.ts +870 -870
  58. package/src/cell-formatting.ts +169 -169
  59. package/src/cell-render.ts +469 -469
  60. package/src/chart-export.ts +201 -201
  61. package/src/chart.ts +2296 -2296
  62. package/src/collaboration.test.ts +104 -104
  63. package/src/collaboration.ts +167 -167
  64. package/src/core.performance.test.ts +30 -30
  65. package/src/core.ts +1111 -1111
  66. package/src/createAutocomplete.svelte.ts +132 -132
  67. package/src/createCombobox.svelte.ts +179 -179
  68. package/src/createCountryInput.svelte.ts +157 -157
  69. package/src/createDropdownList.svelte.ts +162 -162
  70. package/src/createGrid.svelte.ts +42 -42
  71. package/src/createGrid.test.ts +10 -10
  72. package/src/createGridState.svelte.ts +17 -17
  73. package/src/createMenu.svelte.ts +202 -202
  74. package/src/createPopoverSelect.svelte.ts +206 -206
  75. package/src/createTree.svelte.ts +319 -319
  76. package/src/editing.test.ts +859 -859
  77. package/src/editing.ts +675 -675
  78. package/src/export-data-api.test.ts +126 -126
  79. package/src/export-format.test.ts +107 -107
  80. package/src/export-format.ts +598 -598
  81. package/src/flex-render.ts +3 -3
  82. package/src/index.ts +623 -623
  83. package/src/keyboard.test.ts +59 -59
  84. package/src/keyboard.ts +97 -97
  85. package/src/list-nav.test.ts +49 -49
  86. package/src/list-nav.ts +29 -29
  87. package/src/menus.ts +639 -639
  88. package/src/merge-objects.ts +48 -48
  89. package/src/overlays.test.ts +90 -90
  90. package/src/render-component.ts +28 -28
  91. package/src/selection.test.ts +754 -754
  92. package/src/selection.ts +600 -600
  93. package/src/server-data-source.test.ts +289 -289
  94. package/src/server-data-source.ts +413 -413
  95. package/src/sparkline.test.ts +68 -68
  96. package/src/sparkline.ts +169 -169
  97. package/src/spreadsheet.test.ts +489 -489
  98. package/src/spreadsheet.ts +312 -312
  99. package/src/static-functions.ts +11 -11
  100. package/src/subscribe.ts +38 -38
  101. package/src/svgrid-wrapper.types.ts +501 -501
  102. package/src/svgrid.behavior.test.ts +706 -706
  103. package/src/svgrid.charting.test.ts +527 -527
  104. package/src/svgrid.features.test.ts +157 -157
  105. package/src/svgrid.new-features.wrapper.test.ts +251 -251
  106. package/src/svgrid.wrapper.test.ts +40 -40
  107. package/src/test-setup.ts +62 -62
  108. package/src/themes/index.ts +159 -159
  109. package/src/virtualization/column-virtualizer.test.ts +27 -27
  110. package/src/virtualization/column-virtualizer.ts +30 -30
  111. package/src/virtualization/svelte-virtualizer.svelte.ts +26 -26
  112. package/src/virtualization/types.ts +30 -30
  113. package/src/virtualization/virtualizer.test.ts +47 -47
  114. package/src/virtualization/virtualizer.ts +296 -296
@@ -1,59 +1,59 @@
1
- import { describe, expect, it } from 'vitest'
2
- import { getKeyboardIntent, getNextActiveCell } from './keyboard'
3
-
4
- describe('keyboard navigation engine', () => {
5
- it('maps keys to navigation intents', () => {
6
- expect(getKeyboardIntent(new KeyboardEvent('keydown', { key: 'ArrowLeft' }))).toBe(
7
- 'moveLeft',
8
- )
9
- expect(getKeyboardIntent(new KeyboardEvent('keydown', { key: 'Home', ctrlKey: true }))).toBe(
10
- 'gridStart',
11
- )
12
- expect(getKeyboardIntent(new KeyboardEvent('keydown', { key: ' ' }))).toBe(
13
- 'activate',
14
- )
15
- })
16
-
17
- it('computes next active cell within bounds', () => {
18
- const next = getNextActiveCell(
19
- { rowIndex: 1, colIndex: 1, cellId: null },
20
- 'moveDown',
21
- { maxRow: 2, maxCol: 3, pageSize: 10 },
22
- )
23
- expect(next.rowIndex).toBe(2)
24
- expect(next.colIndex).toBe(1)
25
- })
26
-
27
- it('handles row and grid boundary intents', () => {
28
- const rowEnd = getNextActiveCell(
29
- { rowIndex: 2, colIndex: 1, cellId: null },
30
- 'rowEnd',
31
- { maxRow: 2, maxCol: 4, pageSize: 2 },
32
- )
33
- expect(rowEnd.colIndex).toBe(4)
34
-
35
- const gridStart = getNextActiveCell(
36
- { rowIndex: 2, colIndex: 4, cellId: null },
37
- 'gridStart',
38
- { maxRow: 2, maxCol: 4, pageSize: 2 },
39
- )
40
- expect(gridStart.rowIndex).toBe(0)
41
- expect(gridStart.colIndex).toBe(0)
42
- })
43
-
44
- it('clamps page navigation to valid bounds', () => {
45
- const pageUp = getNextActiveCell(
46
- { rowIndex: 1, colIndex: 0, cellId: null },
47
- 'pageUp',
48
- { maxRow: 20, maxCol: 2, pageSize: 10 },
49
- )
50
- const pageDown = getNextActiveCell(
51
- { rowIndex: 18, colIndex: 0, cellId: null },
52
- 'pageDown',
53
- { maxRow: 20, maxCol: 2, pageSize: 10 },
54
- )
55
-
56
- expect(pageUp.rowIndex).toBe(0)
57
- expect(pageDown.rowIndex).toBe(20)
58
- })
59
- })
1
+ import { describe, expect, it } from 'vitest'
2
+ import { getKeyboardIntent, getNextActiveCell } from './keyboard'
3
+
4
+ describe('keyboard navigation engine', () => {
5
+ it('maps keys to navigation intents', () => {
6
+ expect(getKeyboardIntent(new KeyboardEvent('keydown', { key: 'ArrowLeft' }))).toBe(
7
+ 'moveLeft',
8
+ )
9
+ expect(getKeyboardIntent(new KeyboardEvent('keydown', { key: 'Home', ctrlKey: true }))).toBe(
10
+ 'gridStart',
11
+ )
12
+ expect(getKeyboardIntent(new KeyboardEvent('keydown', { key: ' ' }))).toBe(
13
+ 'activate',
14
+ )
15
+ })
16
+
17
+ it('computes next active cell within bounds', () => {
18
+ const next = getNextActiveCell(
19
+ { rowIndex: 1, colIndex: 1, cellId: null },
20
+ 'moveDown',
21
+ { maxRow: 2, maxCol: 3, pageSize: 10 },
22
+ )
23
+ expect(next.rowIndex).toBe(2)
24
+ expect(next.colIndex).toBe(1)
25
+ })
26
+
27
+ it('handles row and grid boundary intents', () => {
28
+ const rowEnd = getNextActiveCell(
29
+ { rowIndex: 2, colIndex: 1, cellId: null },
30
+ 'rowEnd',
31
+ { maxRow: 2, maxCol: 4, pageSize: 2 },
32
+ )
33
+ expect(rowEnd.colIndex).toBe(4)
34
+
35
+ const gridStart = getNextActiveCell(
36
+ { rowIndex: 2, colIndex: 4, cellId: null },
37
+ 'gridStart',
38
+ { maxRow: 2, maxCol: 4, pageSize: 2 },
39
+ )
40
+ expect(gridStart.rowIndex).toBe(0)
41
+ expect(gridStart.colIndex).toBe(0)
42
+ })
43
+
44
+ it('clamps page navigation to valid bounds', () => {
45
+ const pageUp = getNextActiveCell(
46
+ { rowIndex: 1, colIndex: 0, cellId: null },
47
+ 'pageUp',
48
+ { maxRow: 20, maxCol: 2, pageSize: 10 },
49
+ )
50
+ const pageDown = getNextActiveCell(
51
+ { rowIndex: 18, colIndex: 0, cellId: null },
52
+ 'pageDown',
53
+ { maxRow: 20, maxCol: 2, pageSize: 10 },
54
+ )
55
+
56
+ expect(pageUp.rowIndex).toBe(0)
57
+ expect(pageDown.rowIndex).toBe(20)
58
+ })
59
+ })
package/src/keyboard.ts CHANGED
@@ -1,97 +1,97 @@
1
- import type { ActiveCellState } from './core'
2
-
3
- export type GridKeyboardIntent =
4
- | 'moveLeft'
5
- | 'moveRight'
6
- | 'moveUp'
7
- | 'moveDown'
8
- | 'tabNext'
9
- | 'tabPrev'
10
- | 'rowStart'
11
- | 'rowEnd'
12
- | 'gridStart'
13
- | 'gridEnd'
14
- | 'pageUp'
15
- | 'pageDown'
16
- | 'activate'
17
- | 'clearCells'
18
- | 'noop'
19
-
20
- export function getKeyboardIntent(event: KeyboardEvent): GridKeyboardIntent {
21
- // Ctrl+Home / Ctrl+End come before plain Home / End so the modifier wins.
22
- if (event.ctrlKey && event.key === 'Home') return 'gridStart'
23
- if (event.ctrlKey && event.key === 'End') return 'gridEnd'
24
-
25
- if (event.key === 'ArrowLeft') return 'moveLeft'
26
- if (event.key === 'ArrowRight') return 'moveRight'
27
- if (event.key === 'ArrowUp') return 'moveUp'
28
- if (event.key === 'ArrowDown') return 'moveDown'
29
- if (event.key === 'Home') return 'rowStart'
30
- if (event.key === 'End') return 'rowEnd'
31
- if (event.key === 'PageUp') return 'pageUp'
32
- if (event.key === 'PageDown') return 'pageDown'
33
-
34
- // Excel-style data-entry navigation:
35
- // Enter → move down (Shift+Enter → up)
36
- // Tab → move right (Shift+Tab → left), wraps at row boundaries
37
- // Delete → clear contents of the selected cells
38
- // F2 / Space → start editing the active cell
39
- if (event.key === 'Enter') return event.shiftKey ? 'moveUp' : 'moveDown'
40
- if (event.key === 'Tab') return event.shiftKey ? 'tabPrev' : 'tabNext'
41
- if (event.key === 'F2') return 'activate'
42
- if (event.key === ' ') return 'activate'
43
- if (event.key === 'Delete') return 'clearCells'
44
-
45
- return 'noop'
46
- }
47
-
48
- export function getNextActiveCell(
49
- current: ActiveCellState,
50
- intent: GridKeyboardIntent,
51
- bounds: { maxRow: number; maxCol: number; pageSize?: number },
52
- ): ActiveCellState {
53
- const pageSize = bounds.pageSize ?? 10
54
- let rowIndex = current.rowIndex
55
- let colIndex = current.colIndex
56
-
57
- if (intent === 'moveLeft') colIndex -= 1
58
- if (intent === 'moveRight') colIndex += 1
59
- if (intent === 'moveUp') rowIndex -= 1
60
- if (intent === 'moveDown') rowIndex += 1
61
- if (intent === 'tabNext') {
62
- // Right one column; if we fall off the right edge, wrap to the
63
- // first column of the next row - Excel's "data entry" behavior.
64
- colIndex += 1
65
- if (colIndex > bounds.maxCol) {
66
- colIndex = 0
67
- rowIndex += 1
68
- }
69
- }
70
- if (intent === 'tabPrev') {
71
- colIndex -= 1
72
- if (colIndex < 0) {
73
- colIndex = bounds.maxCol
74
- rowIndex -= 1
75
- }
76
- }
77
- if (intent === 'rowStart') colIndex = 0
78
- if (intent === 'rowEnd') colIndex = bounds.maxCol
79
- if (intent === 'gridStart') {
80
- rowIndex = 0
81
- colIndex = 0
82
- }
83
- if (intent === 'gridEnd') {
84
- rowIndex = bounds.maxRow
85
- colIndex = bounds.maxCol
86
- }
87
- if (intent === 'pageUp') rowIndex -= pageSize
88
- if (intent === 'pageDown') rowIndex += pageSize
89
-
90
- rowIndex = Math.min(Math.max(rowIndex, 0), Math.max(bounds.maxRow, 0))
91
- colIndex = Math.min(Math.max(colIndex, 0), Math.max(bounds.maxCol, 0))
92
- return {
93
- rowIndex,
94
- colIndex,
95
- cellId: current.cellId,
96
- }
97
- }
1
+ import type { ActiveCellState } from './core'
2
+
3
+ export type GridKeyboardIntent =
4
+ | 'moveLeft'
5
+ | 'moveRight'
6
+ | 'moveUp'
7
+ | 'moveDown'
8
+ | 'tabNext'
9
+ | 'tabPrev'
10
+ | 'rowStart'
11
+ | 'rowEnd'
12
+ | 'gridStart'
13
+ | 'gridEnd'
14
+ | 'pageUp'
15
+ | 'pageDown'
16
+ | 'activate'
17
+ | 'clearCells'
18
+ | 'noop'
19
+
20
+ export function getKeyboardIntent(event: KeyboardEvent): GridKeyboardIntent {
21
+ // Ctrl+Home / Ctrl+End come before plain Home / End so the modifier wins.
22
+ if (event.ctrlKey && event.key === 'Home') return 'gridStart'
23
+ if (event.ctrlKey && event.key === 'End') return 'gridEnd'
24
+
25
+ if (event.key === 'ArrowLeft') return 'moveLeft'
26
+ if (event.key === 'ArrowRight') return 'moveRight'
27
+ if (event.key === 'ArrowUp') return 'moveUp'
28
+ if (event.key === 'ArrowDown') return 'moveDown'
29
+ if (event.key === 'Home') return 'rowStart'
30
+ if (event.key === 'End') return 'rowEnd'
31
+ if (event.key === 'PageUp') return 'pageUp'
32
+ if (event.key === 'PageDown') return 'pageDown'
33
+
34
+ // Excel-style data-entry navigation:
35
+ // Enter → move down (Shift+Enter → up)
36
+ // Tab → move right (Shift+Tab → left), wraps at row boundaries
37
+ // Delete → clear contents of the selected cells
38
+ // F2 / Space → start editing the active cell
39
+ if (event.key === 'Enter') return event.shiftKey ? 'moveUp' : 'moveDown'
40
+ if (event.key === 'Tab') return event.shiftKey ? 'tabPrev' : 'tabNext'
41
+ if (event.key === 'F2') return 'activate'
42
+ if (event.key === ' ') return 'activate'
43
+ if (event.key === 'Delete') return 'clearCells'
44
+
45
+ return 'noop'
46
+ }
47
+
48
+ export function getNextActiveCell(
49
+ current: ActiveCellState,
50
+ intent: GridKeyboardIntent,
51
+ bounds: { maxRow: number; maxCol: number; pageSize?: number },
52
+ ): ActiveCellState {
53
+ const pageSize = bounds.pageSize ?? 10
54
+ let rowIndex = current.rowIndex
55
+ let colIndex = current.colIndex
56
+
57
+ if (intent === 'moveLeft') colIndex -= 1
58
+ if (intent === 'moveRight') colIndex += 1
59
+ if (intent === 'moveUp') rowIndex -= 1
60
+ if (intent === 'moveDown') rowIndex += 1
61
+ if (intent === 'tabNext') {
62
+ // Right one column; if we fall off the right edge, wrap to the
63
+ // first column of the next row - Excel's "data entry" behavior.
64
+ colIndex += 1
65
+ if (colIndex > bounds.maxCol) {
66
+ colIndex = 0
67
+ rowIndex += 1
68
+ }
69
+ }
70
+ if (intent === 'tabPrev') {
71
+ colIndex -= 1
72
+ if (colIndex < 0) {
73
+ colIndex = bounds.maxCol
74
+ rowIndex -= 1
75
+ }
76
+ }
77
+ if (intent === 'rowStart') colIndex = 0
78
+ if (intent === 'rowEnd') colIndex = bounds.maxCol
79
+ if (intent === 'gridStart') {
80
+ rowIndex = 0
81
+ colIndex = 0
82
+ }
83
+ if (intent === 'gridEnd') {
84
+ rowIndex = bounds.maxRow
85
+ colIndex = bounds.maxCol
86
+ }
87
+ if (intent === 'pageUp') rowIndex -= pageSize
88
+ if (intent === 'pageDown') rowIndex += pageSize
89
+
90
+ rowIndex = Math.min(Math.max(rowIndex, 0), Math.max(bounds.maxRow, 0))
91
+ colIndex = Math.min(Math.max(colIndex, 0), Math.max(bounds.maxCol, 0))
92
+ return {
93
+ rowIndex,
94
+ colIndex,
95
+ cellId: current.cellId,
96
+ }
97
+ }
@@ -1,49 +1,49 @@
1
- import { describe, expect, it } from 'vitest'
2
- import { enabledIndices, wrapMove } from './list-nav'
3
-
4
- describe('enabledIndices', () => {
5
- it('lists every index when nothing is disabled', () => {
6
- expect(enabledIndices(3)).toEqual([0, 1, 2])
7
- })
8
-
9
- it('skips indices the predicate marks disabled', () => {
10
- expect(enabledIndices(5, (i) => i === 1 || i === 3)).toEqual([0, 2, 4])
11
- })
12
-
13
- it('returns an empty array for a zero count', () => {
14
- expect(enabledIndices(0)).toEqual([])
15
- })
16
- })
17
-
18
- describe('wrapMove', () => {
19
- const list = [0, 2, 4] // e.g. indices 1 and 3 are disabled
20
-
21
- it('moves forward to the next enabled index', () => {
22
- expect(wrapMove(list, 2, 1)).toBe(4)
23
- })
24
-
25
- it('wraps past the end back to the head', () => {
26
- expect(wrapMove(list, 4, 1)).toBe(0)
27
- })
28
-
29
- it('wraps before the head to the tail', () => {
30
- expect(wrapMove(list, 0, -1)).toBe(4)
31
- })
32
-
33
- it('from an absent current, delta 1 lands on the first entry', () => {
34
- expect(wrapMove(list, -1, 1)).toBe(0)
35
- })
36
-
37
- it('from an absent current, delta -1 lands on the last-but-one', () => {
38
- expect(wrapMove(list, -1, -1)).toBe(2)
39
- })
40
-
41
- it('stays put for a single-entry list', () => {
42
- expect(wrapMove([5], 5, 1)).toBe(5)
43
- expect(wrapMove([5], 5, -1)).toBe(5)
44
- })
45
-
46
- it('returns -1 for an empty list', () => {
47
- expect(wrapMove([], 0, 1)).toBe(-1)
48
- })
49
- })
1
+ import { describe, expect, it } from 'vitest'
2
+ import { enabledIndices, wrapMove } from './list-nav'
3
+
4
+ describe('enabledIndices', () => {
5
+ it('lists every index when nothing is disabled', () => {
6
+ expect(enabledIndices(3)).toEqual([0, 1, 2])
7
+ })
8
+
9
+ it('skips indices the predicate marks disabled', () => {
10
+ expect(enabledIndices(5, (i) => i === 1 || i === 3)).toEqual([0, 2, 4])
11
+ })
12
+
13
+ it('returns an empty array for a zero count', () => {
14
+ expect(enabledIndices(0)).toEqual([])
15
+ })
16
+ })
17
+
18
+ describe('wrapMove', () => {
19
+ const list = [0, 2, 4] // e.g. indices 1 and 3 are disabled
20
+
21
+ it('moves forward to the next enabled index', () => {
22
+ expect(wrapMove(list, 2, 1)).toBe(4)
23
+ })
24
+
25
+ it('wraps past the end back to the head', () => {
26
+ expect(wrapMove(list, 4, 1)).toBe(0)
27
+ })
28
+
29
+ it('wraps before the head to the tail', () => {
30
+ expect(wrapMove(list, 0, -1)).toBe(4)
31
+ })
32
+
33
+ it('from an absent current, delta 1 lands on the first entry', () => {
34
+ expect(wrapMove(list, -1, 1)).toBe(0)
35
+ })
36
+
37
+ it('from an absent current, delta -1 lands on the last-but-one', () => {
38
+ expect(wrapMove(list, -1, -1)).toBe(2)
39
+ })
40
+
41
+ it('stays put for a single-entry list', () => {
42
+ expect(wrapMove([5], 5, 1)).toBe(5)
43
+ expect(wrapMove([5], 5, -1)).toBe(5)
44
+ })
45
+
46
+ it('returns -1 for an empty list', () => {
47
+ expect(wrapMove([], 0, 1)).toBe(-1)
48
+ })
49
+ })
package/src/list-nav.ts CHANGED
@@ -1,29 +1,29 @@
1
- /**
2
- * list-nav - the pure, framework-free navigation math shared by the roving-focus
3
- * cores (createListbox, createPopoverSelect, createMenu). No runes, no DOM - just
4
- * index arithmetic, so it is unit-testable on its own and behaves identically
5
- * everywhere. The cores wrap these in `$state`.
6
- */
7
-
8
- /** Indices of items that can take roving focus / selection - i.e. the ones the
9
- * caller does not mark disabled. `count` is the total item count; `isDisabled`
10
- * is consulted per index (a separator counts as disabled to the caller). */
11
- export function enabledIndices(count: number, isDisabled?: (index: number) => boolean): number[] {
12
- const out: number[] = []
13
- for (let i = 0; i < count; i++) if (!isDisabled?.(i)) out.push(i)
14
- return out
15
- }
16
-
17
- /**
18
- * The next index when moving `delta` steps through `list`, wrapping around the
19
- * ends. `current` need not be in `list` (it may sit on a disabled item): when it
20
- * is absent we start just before the head so `delta: 1` lands on the first entry
21
- * and `delta: -1` on the last-but-one - the same behaviour every existing core
22
- * already had. Returns `-1` for an empty list.
23
- */
24
- export function wrapMove(list: readonly number[], current: number, delta: number): number {
25
- const len = list.length
26
- if (len === 0) return -1
27
- const pos = list.indexOf(current)
28
- return list[(pos + delta + len) % len]!
29
- }
1
+ /**
2
+ * list-nav - the pure, framework-free navigation math shared by the roving-focus
3
+ * cores (createListbox, createPopoverSelect, createMenu). No runes, no DOM - just
4
+ * index arithmetic, so it is unit-testable on its own and behaves identically
5
+ * everywhere. The cores wrap these in `$state`.
6
+ */
7
+
8
+ /** Indices of items that can take roving focus / selection - i.e. the ones the
9
+ * caller does not mark disabled. `count` is the total item count; `isDisabled`
10
+ * is consulted per index (a separator counts as disabled to the caller). */
11
+ export function enabledIndices(count: number, isDisabled?: (index: number) => boolean): number[] {
12
+ const out: number[] = []
13
+ for (let i = 0; i < count; i++) if (!isDisabled?.(i)) out.push(i)
14
+ return out
15
+ }
16
+
17
+ /**
18
+ * The next index when moving `delta` steps through `list`, wrapping around the
19
+ * ends. `current` need not be in `list` (it may sit on a disabled item): when it
20
+ * is absent we start just before the head so `delta: 1` lands on the first entry
21
+ * and `delta: -1` on the last-but-one - the same behaviour every existing core
22
+ * already had. Returns `-1` for an empty list.
23
+ */
24
+ export function wrapMove(list: readonly number[], current: number, delta: number): number {
25
+ const len = list.length
26
+ if (len === 0) return -1
27
+ const pos = list.indexOf(current)
28
+ return list[(pos + delta + len) % len]!
29
+ }