@vuu-ui/vuu-table 0.8.95 → 0.8.97

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 (71) hide show
  1. package/cjs/Table.css.js +1 -1
  2. package/cjs/Table.js +19 -3
  3. package/cjs/Table.js.map +1 -1
  4. package/cjs/cell-block/CellBlock.css.js +1 -1
  5. package/cjs/cell-block/CellBlock.js +12 -2
  6. package/cjs/cell-block/CellBlock.js.map +1 -1
  7. package/cjs/cell-block/cellblock-utils.js +71 -0
  8. package/cjs/cell-block/cellblock-utils.js.map +1 -1
  9. package/cjs/cell-block/useCellBlockSelection.js +69 -74
  10. package/cjs/cell-block/useCellBlockSelection.js.map +1 -1
  11. package/cjs/cell-renderers/checkbox-row-selector/CheckboxRowSelectorCell.css.js +1 -1
  12. package/cjs/table-cell/TableCell.css.js +1 -1
  13. package/cjs/table-dom-utils.js +67 -10
  14. package/cjs/table-dom-utils.js.map +1 -1
  15. package/cjs/table-header/useTableHeader.js +1 -1
  16. package/cjs/table-header/useTableHeader.js.map +1 -1
  17. package/cjs/useCellFocus.js +98 -0
  18. package/cjs/useCellFocus.js.map +1 -0
  19. package/cjs/useKeyboardNavigation.js +13 -83
  20. package/cjs/useKeyboardNavigation.js.map +1 -1
  21. package/cjs/useMeasuredHeight.js +5 -5
  22. package/cjs/useMeasuredHeight.js.map +1 -1
  23. package/cjs/useTable.js +49 -7
  24. package/cjs/useTable.js.map +1 -1
  25. package/cjs/useTableContextMenu.js +2 -1
  26. package/cjs/useTableContextMenu.js.map +1 -1
  27. package/cjs/useTableModel.js +7 -7
  28. package/cjs/useTableModel.js.map +1 -1
  29. package/cjs/useTableScroll.js +115 -62
  30. package/cjs/useTableScroll.js.map +1 -1
  31. package/esm/Table.css.js +1 -1
  32. package/esm/Table.js +19 -3
  33. package/esm/Table.js.map +1 -1
  34. package/esm/cell-block/CellBlock.css.js +1 -1
  35. package/esm/cell-block/CellBlock.js +13 -3
  36. package/esm/cell-block/CellBlock.js.map +1 -1
  37. package/esm/cell-block/cellblock-utils.js +68 -1
  38. package/esm/cell-block/cellblock-utils.js.map +1 -1
  39. package/esm/cell-block/useCellBlockSelection.js +68 -73
  40. package/esm/cell-block/useCellBlockSelection.js.map +1 -1
  41. package/esm/cell-renderers/checkbox-row-selector/CheckboxRowSelectorCell.css.js +1 -1
  42. package/esm/table-cell/TableCell.css.js +1 -1
  43. package/esm/table-dom-utils.js +64 -10
  44. package/esm/table-dom-utils.js.map +1 -1
  45. package/esm/table-header/useTableHeader.js +1 -1
  46. package/esm/table-header/useTableHeader.js.map +1 -1
  47. package/esm/useCellFocus.js +96 -0
  48. package/esm/useCellFocus.js.map +1 -0
  49. package/esm/useKeyboardNavigation.js +13 -83
  50. package/esm/useKeyboardNavigation.js.map +1 -1
  51. package/esm/useMeasuredHeight.js +5 -5
  52. package/esm/useMeasuredHeight.js.map +1 -1
  53. package/esm/useTable.js +49 -7
  54. package/esm/useTable.js.map +1 -1
  55. package/esm/useTableContextMenu.js +2 -1
  56. package/esm/useTableContextMenu.js.map +1 -1
  57. package/esm/useTableModel.js +7 -7
  58. package/esm/useTableModel.js.map +1 -1
  59. package/esm/useTableScroll.js +115 -62
  60. package/esm/useTableScroll.js.map +1 -1
  61. package/package.json +9 -9
  62. package/types/Table.d.ts +3 -0
  63. package/types/cell-block/CellBlock.d.ts +2 -1
  64. package/types/cell-block/cellblock-utils.d.ts +20 -0
  65. package/types/cell-block/useCellBlockSelection.d.ts +7 -2
  66. package/types/table-dom-utils.d.ts +7 -5
  67. package/types/useCellFocus.d.ts +16 -0
  68. package/types/useKeyboardNavigation.d.ts +9 -7
  69. package/types/useMeasuredHeight.d.ts +2 -2
  70. package/types/useTable.d.ts +4 -1
  71. package/types/useTableScroll.d.ts +15 -5
@@ -1,7 +1,7 @@
1
- import { queryClosest, getIndexFromRowElement } from '@vuu-ui/vuu-utils';
1
+ import { queryClosest } from '@vuu-ui/vuu-utils';
2
2
  import { useControlled } from '@salt-ds/core';
3
3
  import { useRef, useCallback, useEffect } from 'react';
4
- import { getTableCell, cellDropdownShowing, closestRowIndex, headerCellQuery, dataCellQuery } from './table-dom-utils.js';
4
+ import { getTableCellPos, getNextCellPos, cellDropdownShowing, closestRowIndex } from './table-dom-utils.js';
5
5
 
6
6
  const rowNavigationKeys = /* @__PURE__ */ new Set([
7
7
  "Home",
@@ -26,43 +26,13 @@ const isNavigationKey = (key, navigationStyle) => {
26
26
  };
27
27
  const PageKeys = ["Home", "End", "PageUp", "PageDown"];
28
28
  const isPagingKey = (key) => PageKeys.includes(key);
29
- const NULL_CELL_POS = [-1, -1];
30
- function nextCellPos(key, [rowIdx, colIdx], columnCount, rowCount) {
31
- if (key === "ArrowUp") {
32
- if (rowIdx > -1) {
33
- return [rowIdx - 1, colIdx];
34
- } else {
35
- return [rowIdx, colIdx];
36
- }
37
- } else if (key === "ArrowDown") {
38
- if (rowIdx === -1) {
39
- return [0, colIdx];
40
- } else if (rowIdx === rowCount - 1) {
41
- return [rowIdx, colIdx];
42
- } else {
43
- return [rowIdx + 1, colIdx];
44
- }
45
- } else if (key === "ArrowRight") {
46
- if (colIdx < columnCount) {
47
- return [rowIdx, colIdx + 1];
48
- } else {
49
- return [rowIdx, colIdx];
50
- }
51
- } else if (key === "ArrowLeft") {
52
- if (colIdx > 1) {
53
- return [rowIdx, colIdx - 1];
54
- } else {
55
- return [rowIdx, colIdx];
56
- }
57
- }
58
- return [rowIdx, colIdx];
59
- }
60
29
  const useKeyboardNavigation = ({
30
+ cellFocusStateRef,
61
31
  columnCount = 0,
62
32
  containerRef,
63
- disableFocus = false,
64
33
  defaultHighlightedIndex,
65
34
  disableHighlightOnFocus,
35
+ focusCell,
66
36
  highlightedIndex: highlightedIndexProp,
67
37
  navigationStyle,
68
38
  requestScroll,
@@ -71,7 +41,6 @@ const useKeyboardNavigation = ({
71
41
  viewportRowCount
72
42
  }) => {
73
43
  const focusedCellPos = useRef([-1, -1]);
74
- const focusableCell = useRef();
75
44
  const activeCellPos = useRef([-1, 0]);
76
45
  const highlightedIndexRef = useRef();
77
46
  const [highlightedIndex, setHighlightedIdx] = useControlled({
@@ -81,7 +50,7 @@ const useKeyboardNavigation = ({
81
50
  });
82
51
  highlightedIndexRef.current = highlightedIndex;
83
52
  const setHighlightedIndex = useCallback(
84
- (idx, fromKeyboard = false) => {
53
+ (idx) => {
85
54
  onHighlight?.(idx);
86
55
  setHighlightedIdx(idx);
87
56
  },
@@ -90,39 +59,6 @@ const useKeyboardNavigation = ({
90
59
  const getFocusedCell = (element) => element?.closest(
91
60
  "[role='columnHeader'],[role='cell']"
92
61
  );
93
- const getTableCellPos = (tableCell) => {
94
- if (tableCell.role === "columnHeader") {
95
- const colIdx = parseInt(tableCell.dataset.idx ?? "-1", 10);
96
- return [-1, colIdx];
97
- } else {
98
- const focusedRow = tableCell.closest("[role='row']");
99
- if (focusedRow) {
100
- const rowIdx = getIndexFromRowElement(focusedRow);
101
- const colIdx = Array.from(focusedRow.childNodes).indexOf(tableCell);
102
- return [rowIdx, colIdx];
103
- }
104
- }
105
- return NULL_CELL_POS;
106
- };
107
- const focusCell = useCallback(
108
- (cellPos) => {
109
- if (containerRef.current) {
110
- const activeCell = getTableCell(containerRef, cellPos);
111
- if (activeCell) {
112
- if (activeCell !== focusableCell.current) {
113
- focusableCell.current?.removeAttribute("tabindex");
114
- focusableCell.current = activeCell;
115
- activeCell.setAttribute("tabindex", "0");
116
- }
117
- requestScroll?.({ type: "scroll-row", rowIndex: cellPos[0] });
118
- activeCell.focus({ preventScroll: true });
119
- }
120
- }
121
- },
122
- // TODO we recreate this function whenever viewportRange changes, which will
123
- // be often whilst scrolling - store range in a a ref ?
124
- [containerRef, requestScroll]
125
- );
126
62
  const setActiveCell = useCallback(
127
63
  (rowIdx, colIdx, fromKeyboard = false) => {
128
64
  const pos = [rowIdx, colIdx];
@@ -130,7 +66,7 @@ const useKeyboardNavigation = ({
130
66
  if (navigationStyle === "row") {
131
67
  setHighlightedIdx(rowIdx);
132
68
  } else {
133
- focusCell(pos);
69
+ focusCell(pos, fromKeyboard);
134
70
  }
135
71
  if (fromKeyboard) {
136
72
  focusedCellPos.current = pos;
@@ -141,10 +77,12 @@ const useKeyboardNavigation = ({
141
77
  const nextPageItemIdx = useCallback(
142
78
  (key, [rowIdx, colIdx]) => new Promise((resolve) => {
143
79
  let newRowIdx = rowIdx;
80
+ const { current: focusState } = cellFocusStateRef;
144
81
  switch (key) {
145
82
  case "PageDown": {
146
83
  newRowIdx = Math.min(rowCount - 1, rowIdx + viewportRowCount);
147
84
  if (newRowIdx !== rowIdx) {
85
+ focusState.cellPos = [newRowIdx, colIdx];
148
86
  requestScroll?.({ type: "scroll-page", direction: "down" });
149
87
  }
150
88
  break;
@@ -152,6 +90,7 @@ const useKeyboardNavigation = ({
152
90
  case "PageUp": {
153
91
  newRowIdx = Math.max(0, rowIdx - viewportRowCount);
154
92
  if (newRowIdx !== rowIdx) {
93
+ focusState.cellPos = [newRowIdx, colIdx];
155
94
  requestScroll?.({ type: "scroll-page", direction: "up" });
156
95
  }
157
96
  break;
@@ -159,6 +98,7 @@ const useKeyboardNavigation = ({
159
98
  case "Home": {
160
99
  newRowIdx = 0;
161
100
  if (newRowIdx !== rowIdx) {
101
+ focusState.cellPos = [0, colIdx];
162
102
  requestScroll?.({ type: "scroll-end", direction: "home" });
163
103
  }
164
104
  break;
@@ -166,6 +106,7 @@ const useKeyboardNavigation = ({
166
106
  case "End": {
167
107
  newRowIdx = rowCount - 1;
168
108
  if (newRowIdx !== rowIdx) {
109
+ focusState.cellPos = [newRowIdx, colIdx];
169
110
  requestScroll?.({ type: "scroll-end", direction: "end" });
170
111
  }
171
112
  break;
@@ -197,7 +138,7 @@ const useKeyboardNavigation = ({
197
138
  ]);
198
139
  const navigateChildItems = useCallback(
199
140
  async (key) => {
200
- const [nextRowIdx, nextColIdx] = isPagingKey(key) ? await nextPageItemIdx(key, activeCellPos.current) : nextCellPos(key, activeCellPos.current, columnCount, rowCount);
141
+ const [nextRowIdx, nextColIdx] = isPagingKey(key) ? await nextPageItemIdx(key, activeCellPos.current) : getNextCellPos(key, activeCellPos.current, columnCount, rowCount);
201
142
  const [rowIdx, colIdx] = activeCellPos.current;
202
143
  if (nextRowIdx !== rowIdx || nextColIdx !== colIdx) {
203
144
  setActiveCell(nextRowIdx, nextColIdx, true);
@@ -214,7 +155,7 @@ const useKeyboardNavigation = ({
214
155
  const moveHighlightedRow = useCallback(
215
156
  async (key) => {
216
157
  const { current: highlighted } = highlightedIndexRef;
217
- const [nextRowIdx] = isPagingKey(key) ? await nextPageItemIdx(key, [highlighted ?? -1, 0]) : nextCellPos(key, [highlighted ?? -1, 0], columnCount, rowCount);
158
+ const [nextRowIdx] = isPagingKey(key) ? await nextPageItemIdx(key, [highlighted ?? -1, 0]) : getNextCellPos(key, [highlighted ?? -1, 0], columnCount, rowCount);
218
159
  if (nextRowIdx !== highlighted) {
219
160
  setHighlightedIndex(nextRowIdx);
220
161
  scrollRowIntoViewIfNecessary(nextRowIdx);
@@ -280,17 +221,6 @@ const useKeyboardNavigation = ({
280
221
  const navigate = useCallback(() => {
281
222
  navigateChildItems("ArrowDown");
282
223
  }, [navigateChildItems]);
283
- const fullyRendered = containerRef.current?.firstChild != null;
284
- useEffect(() => {
285
- if (fullyRendered && focusableCell.current === void 0 && !disableFocus) {
286
- const { current: container } = containerRef;
287
- const cell = container?.querySelector(headerCellQuery(0)) || container?.querySelector(dataCellQuery(0, 0));
288
- if (cell) {
289
- cell.setAttribute("tabindex", "0");
290
- focusableCell.current = cell;
291
- }
292
- }
293
- }, [containerRef, disableFocus, fullyRendered]);
294
224
  return {
295
225
  highlightedIndexRef,
296
226
  navigate,
@@ -1 +1 @@
1
- {"version":3,"file":"useKeyboardNavigation.js","sources":["../src/useKeyboardNavigation.ts"],"sourcesContent":["import { VuuRange } from \"@vuu-ui/vuu-protocol-types\";\nimport { getIndexFromRowElement, queryClosest } from \"@vuu-ui/vuu-utils\";\nimport { useControlled } from \"@salt-ds/core\";\nimport {\n KeyboardEvent,\n MouseEvent,\n RefObject,\n useCallback,\n useEffect,\n useRef,\n} from \"react\";\nimport { TableNavigationStyle } from \"./Table\";\nimport {\n CellPos,\n cellDropdownShowing,\n closestRowIndex,\n dataCellQuery,\n getTableCell,\n headerCellQuery,\n} from \"./table-dom-utils\";\nimport { ScrollRequestHandler } from \"./useTableScroll\";\n\nconst rowNavigationKeys = new Set<NavigationKey>([\n \"Home\",\n \"End\",\n \"PageUp\",\n \"PageDown\",\n \"ArrowDown\",\n \"ArrowUp\",\n]);\n\nconst cellNavigationKeys = new Set(rowNavigationKeys);\ncellNavigationKeys.add(\"ArrowLeft\");\ncellNavigationKeys.add(\"ArrowRight\");\n\nexport const isNavigationKey = (\n key: string,\n navigationStyle: TableNavigationStyle,\n): key is NavigationKey => {\n switch (navigationStyle) {\n case \"cell\":\n return cellNavigationKeys.has(key as NavigationKey);\n case \"row\":\n return rowNavigationKeys.has(key as NavigationKey);\n default:\n return false;\n }\n};\n\ntype ArrowKey = \"ArrowUp\" | \"ArrowDown\" | \"ArrowLeft\" | \"ArrowRight\";\ntype PageKey = \"Home\" | \"End\" | \"PageUp\" | \"PageDown\";\ntype NavigationKey = PageKey | ArrowKey;\n\nconst PageKeys = [\"Home\", \"End\", \"PageUp\", \"PageDown\"];\nexport const isPagingKey = (key: string): key is PageKey =>\n PageKeys.includes(key);\n\nconst NULL_CELL_POS: CellPos = [-1, -1];\n\nfunction nextCellPos(\n key: ArrowKey,\n [rowIdx, colIdx]: CellPos,\n columnCount: number,\n rowCount: number,\n): CellPos {\n if (key === \"ArrowUp\") {\n if (rowIdx > -1) {\n return [rowIdx - 1, colIdx];\n } else {\n return [rowIdx, colIdx];\n }\n } else if (key === \"ArrowDown\") {\n if (rowIdx === -1) {\n return [0, colIdx];\n } else if (rowIdx === rowCount - 1) {\n return [rowIdx, colIdx];\n } else {\n return [rowIdx + 1, colIdx];\n }\n } else if (key === \"ArrowRight\") {\n // The colIdx is 1 based, because of the selection decorator\n if (colIdx < columnCount) {\n return [rowIdx, colIdx + 1];\n } else {\n return [rowIdx, colIdx];\n }\n } else if (key === \"ArrowLeft\") {\n if (colIdx > 1) {\n return [rowIdx, colIdx - 1];\n } else {\n return [rowIdx, colIdx];\n }\n }\n return [rowIdx, colIdx];\n}\n\nexport interface NavigationHookProps {\n containerRef: RefObject<HTMLElement>;\n columnCount?: number;\n defaultHighlightedIndex?: number;\n disableFocus?: boolean;\n disableHighlightOnFocus?: boolean;\n highlightedIndex?: number;\n label?: string;\n navigationStyle: TableNavigationStyle;\n viewportRange: VuuRange;\n onHighlight?: (idx: number) => void;\n requestScroll?: ScrollRequestHandler;\n restoreLastFocus?: boolean;\n rowCount?: number;\n selected?: unknown;\n viewportRowCount: number;\n}\n\nexport const useKeyboardNavigation = ({\n columnCount = 0,\n containerRef,\n disableFocus = false,\n defaultHighlightedIndex,\n disableHighlightOnFocus,\n highlightedIndex: highlightedIndexProp,\n navigationStyle,\n requestScroll,\n onHighlight,\n rowCount = 0,\n viewportRowCount,\n}: // viewportRange,\nNavigationHookProps) => {\n // const { from: viewportFirstRow, to: viewportLastRow } = viewportRange;\n const focusedCellPos = useRef<CellPos>([-1, -1]);\n const focusableCell = useRef<HTMLElement>();\n const activeCellPos = useRef<CellPos>([-1, 0]);\n // Keep this in sync with state value. This can be used by functions that need\n // to reference highlightedIndex at call time but do not need to be regenerated\n // every time it changes (i.e keep highlightedIndex out of their dependency\n // arrays, as it can update frequently)\n const highlightedIndexRef = useRef<number | undefined>();\n\n const [highlightedIndex, setHighlightedIdx] = useControlled({\n controlled: highlightedIndexProp,\n default: defaultHighlightedIndex,\n name: \"UseKeyboardNavigation\",\n });\n highlightedIndexRef.current = highlightedIndex;\n const setHighlightedIndex = useCallback(\n (idx: number, fromKeyboard = false) => {\n onHighlight?.(idx);\n setHighlightedIdx(idx);\n if (fromKeyboard) {\n // lastFocus.current = idx;\n }\n },\n [onHighlight, setHighlightedIdx],\n );\n\n const getFocusedCell = (element: HTMLElement | Element | null) =>\n element?.closest(\n \"[role='columnHeader'],[role='cell']\",\n ) as HTMLDivElement | null;\n\n const getTableCellPos = (tableCell: HTMLDivElement): CellPos => {\n if (tableCell.role === \"columnHeader\") {\n const colIdx = parseInt(tableCell.dataset.idx ?? \"-1\", 10);\n return [-1, colIdx];\n } else {\n const focusedRow = tableCell.closest(\"[role='row']\") as HTMLElement;\n if (focusedRow) {\n const rowIdx = getIndexFromRowElement(focusedRow);\n // TODO will get trickier when we introduce horizontal virtualisation\n const colIdx = Array.from(focusedRow.childNodes).indexOf(tableCell);\n return [rowIdx, colIdx];\n }\n }\n return NULL_CELL_POS;\n };\n\n const focusCell = useCallback(\n (cellPos: CellPos) => {\n if (containerRef.current) {\n const activeCell = getTableCell(containerRef, cellPos);\n if (activeCell) {\n if (activeCell !== focusableCell.current) {\n focusableCell.current?.removeAttribute(\"tabindex\");\n focusableCell.current = activeCell;\n activeCell.setAttribute(\"tabindex\", \"0\");\n }\n // TODO needs to be scroll cell\n requestScroll?.({ type: \"scroll-row\", rowIndex: cellPos[0] });\n activeCell.focus({ preventScroll: true });\n }\n }\n },\n // TODO we recreate this function whenever viewportRange changes, which will\n // be often whilst scrolling - store range in a a ref ?\n [containerRef, requestScroll],\n );\n\n const setActiveCell = useCallback(\n (rowIdx: number, colIdx: number, fromKeyboard = false) => {\n const pos: CellPos = [rowIdx, colIdx];\n activeCellPos.current = pos;\n if (navigationStyle === \"row\") {\n setHighlightedIdx(rowIdx);\n } else {\n focusCell(pos);\n }\n if (fromKeyboard) {\n focusedCellPos.current = pos;\n }\n },\n [focusCell, navigationStyle, setHighlightedIdx],\n );\n\n const nextPageItemIdx = useCallback(\n (\n key: \"PageDown\" | \"PageUp\" | \"Home\" | \"End\",\n [rowIdx, colIdx]: CellPos,\n ): Promise<CellPos> =>\n new Promise((resolve) => {\n let newRowIdx = rowIdx;\n switch (key) {\n case \"PageDown\": {\n newRowIdx = Math.min(rowCount - 1, rowIdx + viewportRowCount);\n if (newRowIdx !== rowIdx) {\n requestScroll?.({ type: \"scroll-page\", direction: \"down\" });\n }\n break;\n }\n case \"PageUp\": {\n newRowIdx = Math.max(0, rowIdx - viewportRowCount);\n if (newRowIdx !== rowIdx) {\n requestScroll?.({ type: \"scroll-page\", direction: \"up\" });\n }\n break;\n }\n case \"Home\": {\n newRowIdx = 0;\n if (newRowIdx !== rowIdx) {\n requestScroll?.({ type: \"scroll-end\", direction: \"home\" });\n }\n break;\n }\n case \"End\": {\n newRowIdx = rowCount - 1;\n if (newRowIdx !== rowIdx) {\n requestScroll?.({ type: \"scroll-end\", direction: \"end\" });\n }\n break;\n }\n }\n // Introduce a delay to allow the scroll operation to complete,\n // which will trigger a range reset and rerender of rows. We\n // might need to tweak how this works. If we introduce too big\n // a delay, we risk seeing the newly rendered rows, with the focus\n // still on the old cell, which will be apparent as a brief flash\n // of the old cell focus before switching to correct cell. If we were\n // to change the way re assign keys such that we can guarantee that\n // when we page down, rows in same position get same keys, then same\n // cell would be focussed in new page as previous and issue would not\n // arise.\n setTimeout(() => {\n resolve([newRowIdx, colIdx]);\n }, 35);\n }),\n [requestScroll, rowCount, viewportRowCount],\n );\n\n const handleFocus = useCallback(() => {\n if (disableHighlightOnFocus !== true) {\n if (containerRef.current?.contains(document.activeElement)) {\n // IF focus arrives via keyboard, a cell will have received focus,\n // we handle that here. If focus arrives via click on a cell with\n // no tabindex (i.e all cells except one) we leave that to the\n // click handler.\n const focusedCell = getFocusedCell(document.activeElement);\n if (focusedCell) {\n focusedCellPos.current = getTableCellPos(focusedCell);\n if (navigationStyle === \"row\") {\n setHighlightedIdx(focusedCellPos.current[0]);\n }\n }\n }\n }\n }, [\n disableHighlightOnFocus,\n containerRef,\n navigationStyle,\n setHighlightedIdx,\n ]);\n\n const navigateChildItems = useCallback(\n async (key: NavigationKey) => {\n const [nextRowIdx, nextColIdx] = isPagingKey(key)\n ? await nextPageItemIdx(key, activeCellPos.current)\n : nextCellPos(key, activeCellPos.current, columnCount, rowCount);\n const [rowIdx, colIdx] = activeCellPos.current;\n if (nextRowIdx !== rowIdx || nextColIdx !== colIdx) {\n setActiveCell(nextRowIdx, nextColIdx, true);\n }\n },\n [columnCount, nextPageItemIdx, rowCount, setActiveCell],\n );\n\n const scrollRowIntoViewIfNecessary = useCallback(\n (rowIndex: number) => {\n requestScroll?.({ type: \"scroll-row\", rowIndex });\n },\n [requestScroll],\n );\n\n const moveHighlightedRow = useCallback(\n async (key: NavigationKey) => {\n const { current: highlighted } = highlightedIndexRef;\n const [nextRowIdx] = isPagingKey(key)\n ? await nextPageItemIdx(key, [highlighted ?? -1, 0])\n : nextCellPos(key, [highlighted ?? -1, 0], columnCount, rowCount);\n if (nextRowIdx !== highlighted) {\n setHighlightedIndex(nextRowIdx);\n // TO(DO make this a scroll request)\n scrollRowIntoViewIfNecessary(nextRowIdx);\n }\n },\n [\n columnCount,\n nextPageItemIdx,\n rowCount,\n scrollRowIntoViewIfNecessary,\n setHighlightedIndex,\n ],\n );\n\n useEffect(() => {\n if (highlightedIndexProp !== undefined && highlightedIndexProp !== -1) {\n requestAnimationFrame(() => {\n // deferred call, ensuring table has fully rendered\n scrollRowIntoViewIfNecessary(highlightedIndexProp);\n });\n }\n }, [highlightedIndexProp, scrollRowIntoViewIfNecessary]);\n\n const handleKeyDown = useCallback(\n (e: KeyboardEvent) => {\n const cell = queryClosest<HTMLDivElement>(e.target, \".vuuTableCell\");\n if (cellDropdownShowing(cell)) {\n return;\n }\n if (rowCount > 0 && isNavigationKey(e.key, navigationStyle)) {\n e.preventDefault();\n e.stopPropagation();\n if (navigationStyle === \"row\") {\n moveHighlightedRow(e.key);\n } else {\n void navigateChildItems(e.key);\n }\n }\n },\n [rowCount, navigationStyle, moveHighlightedRow, navigateChildItems],\n );\n\n const handleClick = useCallback(\n // Might not be a cell e.g the Settings button\n (evt: MouseEvent) => {\n const target = evt.target as HTMLElement;\n const focusedCell = getFocusedCell(target);\n if (focusedCell) {\n const [rowIdx, colIdx] = getTableCellPos(focusedCell);\n setActiveCell(rowIdx, colIdx);\n }\n },\n [setActiveCell],\n );\n\n const handleMouseLeave = useCallback(() => {\n setHighlightedIndex(-1);\n }, [setHighlightedIndex]);\n\n const handleMouseMove = useCallback(\n (evt: MouseEvent) => {\n const idx = closestRowIndex(evt.target as HTMLElement);\n if (idx !== -1 && idx !== highlightedIndexRef.current) {\n setHighlightedIndex(idx);\n }\n },\n [setHighlightedIndex],\n );\n\n const navigate = useCallback(() => {\n navigateChildItems(\"ArrowDown\");\n }, [navigateChildItems]);\n\n // First render will only render the outer container when explicit\n // sizing has not been provided. Outer container is measured and\n // only then, on second render, is content rendered.\n const fullyRendered = containerRef.current?.firstChild != null;\n useEffect(() => {\n if (fullyRendered && focusableCell.current === undefined && !disableFocus) {\n const { current: container } = containerRef;\n const cell = (container?.querySelector(headerCellQuery(0)) ||\n container?.querySelector(dataCellQuery(0, 0))) as HTMLElement;\n if (cell) {\n cell.setAttribute(\"tabindex\", \"0\");\n focusableCell.current = cell;\n }\n }\n }, [containerRef, disableFocus, fullyRendered]);\n\n return {\n highlightedIndexRef,\n navigate,\n onClick: handleClick,\n onFocus: handleFocus,\n onKeyDown: handleKeyDown,\n onMouseLeave: navigationStyle === \"row\" ? handleMouseLeave : undefined,\n onMouseMove: navigationStyle === \"row\" ? handleMouseMove : undefined,\n };\n};\n"],"names":[],"mappings":";;;;;AAsBA,MAAM,iBAAA,uBAAwB,GAAmB,CAAA;AAAA,EAC/C,MAAA;AAAA,EACA,KAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;AAAA,EACA,WAAA;AAAA,EACA,SAAA;AACF,CAAC,CAAA,CAAA;AAED,MAAM,kBAAA,GAAqB,IAAI,GAAA,CAAI,iBAAiB,CAAA,CAAA;AACpD,kBAAA,CAAmB,IAAI,WAAW,CAAA,CAAA;AAClC,kBAAA,CAAmB,IAAI,YAAY,CAAA,CAAA;AAEtB,MAAA,eAAA,GAAkB,CAC7B,GAAA,EACA,eACyB,K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A,IACX,YAAA,EAAc,eAAoB,KAAA,KAAA,GAAQ,gBAAmB,GAAA,KAAA,CAAA;AAAA,IAC7D,WAAA,EAAa,eAAoB,KAAA,KAAA,GAAQ,eAAkB,GAAA,KAAA,CAAA;AAAA,GAC7D,CAAA;AACF;;;;"}
1
+ {"version":3,"file":"useKeyboardNavigation.js","sources":["../src/useKeyboardNavigation.ts"],"sourcesContent":["import { VuuRange } from \"@vuu-ui/vuu-protocol-types\";\nimport { PageKey, queryClosest } from \"@vuu-ui/vuu-utils\";\nimport { useControlled } from \"@salt-ds/core\";\nimport {\n KeyboardEvent,\n MouseEvent,\n MutableRefObject,\n RefObject,\n useCallback,\n useEffect,\n useRef,\n} from \"react\";\nimport { TableNavigationStyle } from \"./Table\";\nimport {\n NavigationKey,\n cellDropdownShowing,\n closestRowIndex,\n getTableCellPos,\n getNextCellPos,\n} from \"./table-dom-utils\";\nimport { ScrollRequestHandler } from \"./useTableScroll\";\nimport { FocusCell } from \"./useCellFocus\";\nimport { CellFocusState, CellPos } from \"@vuu-ui/vuu-table-types\";\n\nconst rowNavigationKeys = new Set<NavigationKey>([\n \"Home\",\n \"End\",\n \"PageUp\",\n \"PageDown\",\n \"ArrowDown\",\n \"ArrowUp\",\n]);\n\nconst cellNavigationKeys = new Set(rowNavigationKeys);\ncellNavigationKeys.add(\"ArrowLeft\");\ncellNavigationKeys.add(\"ArrowRight\");\n\nexport const isNavigationKey = (\n key: string,\n navigationStyle: TableNavigationStyle,\n): key is NavigationKey => {\n switch (navigationStyle) {\n case \"cell\":\n return cellNavigationKeys.has(key as NavigationKey);\n case \"row\":\n return rowNavigationKeys.has(key as NavigationKey);\n default:\n return false;\n }\n};\n\nconst PageKeys = [\"Home\", \"End\", \"PageUp\", \"PageDown\"];\nexport const isPagingKey = (key: string): key is PageKey =>\n PageKeys.includes(key);\n\nexport interface NavigationHookProps {\n cellFocusStateRef: MutableRefObject<CellFocusState>;\n containerRef: RefObject<HTMLElement>;\n columnCount?: number;\n defaultHighlightedIndex?: number;\n disableFocus?: boolean;\n disableHighlightOnFocus?: boolean;\n focusCell: FocusCell;\n highlightedIndex?: number;\n label?: string;\n navigationStyle: TableNavigationStyle;\n viewportRange: VuuRange;\n onHighlight?: (idx: number) => void;\n requestScroll?: ScrollRequestHandler;\n restoreLastFocus?: boolean;\n rowCount?: number;\n selected?: unknown;\n viewportRowCount: number;\n}\n\nexport const useKeyboardNavigation = ({\n cellFocusStateRef,\n columnCount = 0,\n containerRef,\n defaultHighlightedIndex,\n disableHighlightOnFocus,\n focusCell,\n highlightedIndex: highlightedIndexProp,\n navigationStyle,\n requestScroll,\n onHighlight,\n rowCount = 0,\n viewportRowCount,\n}: NavigationHookProps) => {\n const focusedCellPos = useRef<CellPos>([-1, -1]);\n const activeCellPos = useRef<CellPos>([-1, 0]);\n // Keep this in sync with state value. This can be used by functions that need\n // to reference highlightedIndex at call time but do not need to be regenerated\n // every time it changes (i.e keep highlightedIndex out of their dependency\n // arrays, as it can update frequently)\n const highlightedIndexRef = useRef<number | undefined>();\n\n const [highlightedIndex, setHighlightedIdx] = useControlled({\n controlled: highlightedIndexProp,\n default: defaultHighlightedIndex,\n name: \"UseKeyboardNavigation\",\n });\n highlightedIndexRef.current = highlightedIndex;\n const setHighlightedIndex = useCallback(\n (idx: number) => {\n onHighlight?.(idx);\n setHighlightedIdx(idx);\n },\n [onHighlight, setHighlightedIdx],\n );\n\n const getFocusedCell = (element: HTMLElement | Element | null) =>\n element?.closest(\n \"[role='columnHeader'],[role='cell']\",\n ) as HTMLDivElement | null;\n\n const setActiveCell = useCallback(\n (rowIdx: number, colIdx: number, fromKeyboard = false) => {\n const pos: CellPos = [rowIdx, colIdx];\n // TODO do we still need this when we have cellFocusStateRef ?\n activeCellPos.current = pos;\n if (navigationStyle === \"row\") {\n setHighlightedIdx(rowIdx);\n } else {\n focusCell(pos, fromKeyboard);\n }\n if (fromKeyboard) {\n focusedCellPos.current = pos;\n }\n },\n [focusCell, navigationStyle, setHighlightedIdx],\n );\n\n const nextPageItemIdx = useCallback(\n (\n key: \"PageDown\" | \"PageUp\" | \"Home\" | \"End\",\n [rowIdx, colIdx]: CellPos,\n ): Promise<CellPos> =>\n new Promise((resolve) => {\n let newRowIdx = rowIdx;\n const { current: focusState } = cellFocusStateRef;\n switch (key) {\n case \"PageDown\": {\n newRowIdx = Math.min(rowCount - 1, rowIdx + viewportRowCount);\n if (newRowIdx !== rowIdx) {\n focusState.cellPos = [newRowIdx, colIdx];\n requestScroll?.({ type: \"scroll-page\", direction: \"down\" });\n }\n break;\n }\n case \"PageUp\": {\n newRowIdx = Math.max(0, rowIdx - viewportRowCount);\n if (newRowIdx !== rowIdx) {\n focusState.cellPos = [newRowIdx, colIdx];\n requestScroll?.({ type: \"scroll-page\", direction: \"up\" });\n }\n break;\n }\n case \"Home\": {\n newRowIdx = 0;\n if (newRowIdx !== rowIdx) {\n focusState.cellPos = [0, colIdx];\n requestScroll?.({ type: \"scroll-end\", direction: \"home\" });\n }\n break;\n }\n case \"End\": {\n newRowIdx = rowCount - 1;\n if (newRowIdx !== rowIdx) {\n focusState.cellPos = [newRowIdx, colIdx];\n requestScroll?.({ type: \"scroll-end\", direction: \"end\" });\n }\n break;\n }\n }\n // Introduce a delay to allow the scroll operation to complete,\n // which will trigger a range reset and rerender of rows. We\n // might need to tweak how this works. If we introduce too big\n // a delay, we risk seeing the newly rendered rows, with the focus\n // still on the old cell, which will be apparent as a brief flash\n // of the old cell focus before switching to correct cell. If we were\n // to change the way re assign keys such that we can guarantee that\n // when we page down, rows in same position get same keys, then same\n // cell would be focussed in new page as previous and issue would not\n // arise.\n setTimeout(() => {\n resolve([newRowIdx, colIdx]);\n }, 35);\n }),\n [requestScroll, rowCount, viewportRowCount],\n );\n\n const handleFocus = useCallback(() => {\n if (disableHighlightOnFocus !== true) {\n if (containerRef.current?.contains(document.activeElement)) {\n // IF focus arrives via keyboard, a cell will have received focus,\n // we handle that here. If focus arrives via click on a cell with\n // no tabindex (i.e all cells except one) we leave that to the\n // click handler.\n const focusedCell = getFocusedCell(document.activeElement);\n if (focusedCell) {\n focusedCellPos.current = getTableCellPos(focusedCell);\n if (navigationStyle === \"row\") {\n setHighlightedIdx(focusedCellPos.current[0]);\n }\n }\n }\n }\n }, [\n disableHighlightOnFocus,\n containerRef,\n navigationStyle,\n setHighlightedIdx,\n ]);\n\n const navigateChildItems = useCallback(\n async (key: NavigationKey) => {\n const [nextRowIdx, nextColIdx] = isPagingKey(key)\n ? await nextPageItemIdx(key, activeCellPos.current)\n : getNextCellPos(key, activeCellPos.current, columnCount, rowCount);\n const [rowIdx, colIdx] = activeCellPos.current;\n if (nextRowIdx !== rowIdx || nextColIdx !== colIdx) {\n setActiveCell(nextRowIdx, nextColIdx, true);\n }\n },\n [columnCount, nextPageItemIdx, rowCount, setActiveCell],\n );\n\n const scrollRowIntoViewIfNecessary = useCallback(\n (rowIndex: number) => {\n requestScroll?.({ type: \"scroll-row\", rowIndex });\n },\n [requestScroll],\n );\n\n const moveHighlightedRow = useCallback(\n async (key: NavigationKey) => {\n const { current: highlighted } = highlightedIndexRef;\n const [nextRowIdx] = isPagingKey(key)\n ? await nextPageItemIdx(key, [highlighted ?? -1, 0])\n : getNextCellPos(key, [highlighted ?? -1, 0], columnCount, rowCount);\n if (nextRowIdx !== highlighted) {\n setHighlightedIndex(nextRowIdx);\n // TO(DO make this a scroll request)\n scrollRowIntoViewIfNecessary(nextRowIdx);\n }\n },\n [\n columnCount,\n nextPageItemIdx,\n rowCount,\n scrollRowIntoViewIfNecessary,\n setHighlightedIndex,\n ],\n );\n\n useEffect(() => {\n if (highlightedIndexProp !== undefined && highlightedIndexProp !== -1) {\n requestAnimationFrame(() => {\n // deferred call, ensuring table has fully rendered\n scrollRowIntoViewIfNecessary(highlightedIndexProp);\n });\n }\n }, [highlightedIndexProp, scrollRowIntoViewIfNecessary]);\n\n const handleKeyDown = useCallback(\n (e: KeyboardEvent) => {\n const cell = queryClosest<HTMLDivElement>(e.target, \".vuuTableCell\");\n if (cellDropdownShowing(cell)) {\n return;\n }\n if (rowCount > 0 && isNavigationKey(e.key, navigationStyle)) {\n e.preventDefault();\n e.stopPropagation();\n if (navigationStyle === \"row\") {\n moveHighlightedRow(e.key);\n } else {\n void navigateChildItems(e.key);\n }\n }\n },\n [rowCount, navigationStyle, moveHighlightedRow, navigateChildItems],\n );\n\n const handleClick = useCallback(\n // Might not be a cell e.g the Settings button\n (evt: MouseEvent) => {\n const target = evt.target as HTMLElement;\n const focusedCell = getFocusedCell(target);\n if (focusedCell) {\n const [rowIdx, colIdx] = getTableCellPos(focusedCell);\n setActiveCell(rowIdx, colIdx);\n }\n },\n [setActiveCell],\n );\n\n const handleMouseLeave = useCallback(() => {\n setHighlightedIndex(-1);\n }, [setHighlightedIndex]);\n\n const handleMouseMove = useCallback(\n (evt: MouseEvent) => {\n const idx = closestRowIndex(evt.target as HTMLElement);\n if (idx !== -1 && idx !== highlightedIndexRef.current) {\n setHighlightedIndex(idx);\n }\n },\n [setHighlightedIndex],\n );\n\n const navigate = useCallback(() => {\n navigateChildItems(\"ArrowDown\");\n }, [navigateChildItems]);\n\n return {\n highlightedIndexRef,\n navigate,\n onClick: handleClick,\n onFocus: handleFocus,\n onKeyDown: handleKeyDown,\n onMouseLeave: navigationStyle === \"row\" ? handleMouseLeave : undefined,\n onMouseMove: navigationStyle === \"row\" ? handleMouseMove : undefined,\n };\n};\n"],"names":[],"mappings":";;;;;AAwBA,MAAM,iBAAA,uBAAwB,GAAmB,CAAA;AAAA,EAC/C,MAAA;AAAA,EACA,KAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;AAAA,EACA,WAAA;AAAA,EACA,SAAA;AACF,CAAC,CAAA,CAAA;AAED,MAAM,kBAAA,GAAqB,IAAI,GAAA,CAAI,iBAAiB,CAAA,CAAA;AACpD,kBAAA,CAAmB,IAAI,WAAW,CAAA,CAAA;AAClC,kBAAA,CAAmB,IAAI,YAAY,CAAA,CAAA;AAEtB,MAAA,eAAA,GAAk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AAEA,EAAM,MAAA,gBAAA,GAAmB,YAAY,MAAM;AACzC,IAAA,mBAAA,CAAoB,CAAE,CAAA,CAAA,CAAA;AAAA,GACxB,EAAG,CAAC,mBAAmB,CAAC,CAAA,CAAA;AAExB,EAAA,MAAM,eAAkB,GAAA,WAAA;AAAA,IACtB,CAAC,GAAoB,KAAA;AACnB,MAAM,MAAA,GAAA,GAAM,eAAgB,CAAA,GAAA,CAAI,MAAqB,CAAA,CAAA;AACrD,MAAA,IAAI,GAAQ,KAAA,CAAA,CAAA,IAAM,GAAQ,KAAA,mBAAA,CAAoB,OAAS,EAAA;AACrD,QAAA,mBAAA,CAAoB,GAAG,CAAA,CAAA;AAAA,OACzB;AAAA,KACF;AAAA,IACA,CAAC,mBAAmB,CAAA;AAAA,GACtB,CAAA;AAEA,EAAM,MAAA,QAAA,GAAW,YAAY,MAAM;AACjC,IAAA,kBAAA,CAAmB,WAAW,CAAA,CAAA;AAAA,GAChC,EAAG,CAAC,kBAAkB,CAAC,CAAA,CAAA;AAEvB,EAAO,OAAA;AAAA,IACL,mBAAA;AAAA,IACA,QAAA;AAAA,IACA,OAAS,EAAA,WAAA;AAAA,IACT,OAAS,EAAA,WAAA;AAAA,IACT,SAAW,EAAA,aAAA;AAAA,IACX,YAAA,EAAc,eAAoB,KAAA,KAAA,GAAQ,gBAAmB,GAAA,KAAA,CAAA;AAAA,IAC7D,WAAA,EAAa,eAAoB,KAAA,KAAA,GAAQ,eAAkB,GAAA,KAAA,CAAA;AAAA,GAC7D,CAAA;AACF;;;;"}
@@ -5,26 +5,26 @@ const useMeasuredHeight = ({
5
5
  onHeightMeasured,
6
6
  height: heightProp = 0
7
7
  }) => {
8
- const [rowHeight, setRowHeight] = useState(heightProp);
8
+ const [measuredHeight, setMeasuredHeight] = useState(heightProp);
9
9
  const resizeObserver = useMemo(() => {
10
10
  return new ResizeObserver((entries) => {
11
11
  for (const entry of entries) {
12
12
  const [{ blockSize: measuredSize }] = entry.borderBoxSize;
13
13
  const newHeight = Math.round(measuredSize);
14
14
  if (isValidNumber(newHeight)) {
15
- setRowHeight(newHeight);
15
+ setMeasuredHeight(newHeight);
16
16
  onHeightMeasured?.(newHeight);
17
17
  }
18
18
  }
19
19
  });
20
20
  }, [onHeightMeasured]);
21
- const rowRef = useCallback(
21
+ const measuredRef = useCallback(
22
22
  (el) => {
23
23
  if (el) {
24
24
  if (heightProp === 0) {
25
25
  const { height } = el.getBoundingClientRect();
26
26
  resizeObserver.observe(el);
27
- setRowHeight(height);
27
+ setMeasuredHeight(Math.round(height));
28
28
  }
29
29
  } else {
30
30
  resizeObserver.disconnect();
@@ -32,7 +32,7 @@ const useMeasuredHeight = ({
32
32
  },
33
33
  [resizeObserver, heightProp]
34
34
  );
35
- return { rowHeight, rowRef };
35
+ return { measuredHeight, measuredRef };
36
36
  };
37
37
 
38
38
  export { useMeasuredHeight };
@@ -1 +1 @@
1
- {"version":3,"file":"useMeasuredHeight.js","sources":["../src/useMeasuredHeight.ts"],"sourcesContent":["import { isValidNumber } from \"@vuu-ui/vuu-utils\";\nimport { RefCallback, useCallback, useMemo, useState } from \"react\";\n\ninterface MeasuredHeightHookProps {\n onHeightMeasured?: (height: number) => void;\n height?: number;\n}\n\nexport const useMeasuredHeight = ({\n onHeightMeasured,\n height: heightProp = 0,\n}: MeasuredHeightHookProps) => {\n const [rowHeight, setRowHeight] = useState(heightProp);\n\n const resizeObserver = useMemo(() => {\n return new ResizeObserver((entries: ResizeObserverEntry[]) => {\n for (const entry of entries) {\n const [{ blockSize: measuredSize }] = entry.borderBoxSize;\n const newHeight = Math.round(measuredSize);\n if (isValidNumber(newHeight)) {\n setRowHeight(newHeight);\n onHeightMeasured?.(newHeight);\n }\n }\n });\n }, [onHeightMeasured]);\n\n const rowRef = useCallback<RefCallback<HTMLDivElement>>(\n (el) => {\n if (el) {\n if (heightProp === 0) {\n const { height } = el.getBoundingClientRect();\n resizeObserver.observe(el);\n setRowHeight(height);\n }\n } else {\n resizeObserver.disconnect();\n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A,EAAO,OAAA,EAAE,WAAW,MAAO,EAAA,CAAA;AAC7B;;;;"}
1
+ {"version":3,"file":"useMeasuredHeight.js","sources":["../src/useMeasuredHeight.ts"],"sourcesContent":["import { isValidNumber } from \"@vuu-ui/vuu-utils\";\nimport { RefCallback, useCallback, useMemo, useState } from \"react\";\n\ninterface MeasuredHeightHookProps {\n onHeightMeasured?: (height: number) => void;\n height?: number;\n}\n\nexport const useMeasuredHeight = ({\n onHeightMeasured,\n height: heightProp = 0,\n}: MeasuredHeightHookProps) => {\n const [measuredHeight, setMeasuredHeight] = useState(heightProp);\n\n const resizeObserver = useMemo(() => {\n return new ResizeObserver((entries: ResizeObserverEntry[]) => {\n for (const entry of entries) {\n const [{ blockSize: measuredSize }] = entry.borderBoxSize;\n const newHeight = Math.round(measuredSize);\n if (isValidNumber(newHeight)) {\n setMeasuredHeight(newHeight);\n onHeightMeasured?.(newHeight);\n }\n }\n });\n }, [onHeightMeasured]);\n\n const measuredRef = useCallback<RefCallback<HTMLDivElement>>(\n (el) => {\n if (el) {\n if (heightProp === 0) {\n const { height } = el.getBoundingClientRect();\n resizeObserver.observe(el);\n // avoids tiny sub-pixel discrepancies\n setMeasuredHeight(Math.round(height));\n }\n } else {\n resizeObserver.disconnect();\n }\n },\n [resizeObserver, heightProp],\n );\n return { measuredHeight, measuredRef };\n};\n"],"names":[],"mappings":";;;AAQO,MAAM,oBAAoB,CAAC;AAAA,EAChC,gBAAA;AAAA,EACA,QAAQ,UAAa,GAAA,CAAA;AACvB,CAA+B,KAAA;AAC7B,EAAA,MAAM,CAAC,cAAA,EAAgB,iBAAiB,CAAA,GAAI,SAAS,UAAU,CAAA,CAAA;AAE/D,EAAM,MAAA,cAAA,GAAiB,QAAQ,MAAM;AACnC,IAAO,OAAA,IAAI,cAAe,CAAA,CAAC,OAAmC,KAAA;AAC5D,MAAA,KAAA,MAAW,SAAS,OAAS,EAAA;AAC3B,QAAA,MAAM,CAAC,EAAE,SAAA,EAAW,YAAa,EAAC,IAAI,KAAM,CAAA,aAAA,CAAA;AAC5C,QAAM,MAAA,SAAA,GAAY,IAAK,CAAA,KAAA,CAAM,YAAY,CAAA,CAAA;AACzC,QAAI,IAAA,aAAA,CAAc,SAAS,CAAG,EAAA;AAC5B,UAAA,iBAAA,CAAkB,SAAS,CAAA,CAAA;AAC3B,UAAA,gBAAA,GAAmB,SAAS,CAAA,CAAA;AAAA,SAC9B;AAAA,OACF;AAAA,KACD,CAAA,CAAA;AAAA,GACH,EAAG,CAAC,gBAAgB,CAAC,CAAA,CAAA;AAErB,EAAA,MAAM,WAAc,GAAA,WAAA;AAAA,IAClB,CAAC,EAAO,KAAA;AACN,MAAA,IAAI,EAAI,EAAA;AACN,QAAA,IAAI,eAAe,CAAG,EAAA;AACpB,UAAA,MAAM,EAAE,MAAA,EAAW,GAAA,EAAA,CAAG,qBAAsB,EAAA,CAAA;AAC5C,UAAA,cAAA,CAAe,QAAQ,EAAE,CAAA,CAAA;AAEzB,UAAkB,iBAAA,CAAA,IAAA,CAAK,KAAM,CAAA,MAAM,CAAC,CAAA,CAAA;AAAA,SACtC;AAAA,OACK,MAAA;AACL,QAAA,cAAA,CAAe,UAAW,EAAA,CAAA;AAAA,OAC5B;AAAA,KACF;AAAA,IACA,CAAC,gBAAgB,UAAU,CAAA;AAAA,GAC7B,CAAA;AACA,EAAO,OAAA,EAAE,gBAAgB,WAAY,EAAA,CAAA;AACvC;;;;"}
package/esm/useTable.js CHANGED
@@ -1,24 +1,33 @@
1
1
  import { useDragDrop } from '@vuu-ui/vuu-ui-controls';
2
- import { useLayoutEffectSkipFirst, buildColumnMap, updateColumn, toggleOrApplySort, isValidNumber, isJsonGroup, isGroupColumn, asDataSourceRowObject, getIndexFromRowElement, metadataKeys } from '@vuu-ui/vuu-utils';
2
+ import { useLayoutEffectSkipFirst, buildColumnMap, updateColumn, toggleOrApplySort, isValidNumber, isJsonGroup, isGroupColumn, asDataSourceRowObject, metadataKeys } from '@vuu-ui/vuu-utils';
3
3
  import { useRef, useMemo, useState, useCallback, useEffect } from 'react';
4
+ import { useCellBlockSelection } from './cell-block/useCellBlockSelection.js';
4
5
  import { buildContextMenuDescriptors } from './context-menu/buildContextMenuDescriptors.js';
5
6
  import { useHandleTableContextMenu } from './context-menu/useHandleTableContextMenu.js';
6
7
  import { updateTableConfig } from './table-config.js';
8
+ import { getIndexFromRowElement } from './table-dom-utils.js';
7
9
  import { useCellEditing } from './useCellEditing.js';
10
+ import { useCellFocus } from './useCellFocus.js';
8
11
  import { useDataSource } from './useDataSource.js';
9
12
  import { useKeyboardNavigation } from './useKeyboardNavigation.js';
13
+ import { useRowClassNameGenerators } from './useRowClassNameGenerators.js';
10
14
  import { useSelection } from './useSelection.js';
15
+ import { useTableAndColumnSettings } from './useTableAndColumnSettings.js';
11
16
  import { useTableContextMenu } from './useTableContextMenu.js';
12
17
  import { useTableModel, isShowColumnSettings, isShowTableSettings } from './useTableModel.js';
13
18
  import { useTableScroll } from './useTableScroll.js';
14
19
  import { useTableViewport } from './useTableViewport.js';
15
- import { useTableAndColumnSettings } from './useTableAndColumnSettings.js';
16
- import { useRowClassNameGenerators } from './useRowClassNameGenerators.js';
17
- import { useCellBlockSelection } from './cell-block/useCellBlockSelection.js';
18
20
 
19
21
  const stripInternalProperties = (tableConfig) => {
20
22
  return tableConfig;
21
23
  };
24
+ const NullCellFocusState = {
25
+ cellPos: void 0,
26
+ el: null,
27
+ outsideViewport: false,
28
+ placeholderEl: null,
29
+ pos: void 0
30
+ };
22
31
  const { KEY, IS_EXPANDED, IS_LEAF } = metadataKeys;
23
32
  const NULL_DRAG_DROP = {
24
33
  draggable: void 0,
@@ -61,6 +70,8 @@ const useTable = ({
61
70
  useMemo(() => {
62
71
  tableConfigRef.current = config;
63
72
  }, [config]);
73
+ const cellFocusStateRef = useRef(NullCellFocusState);
74
+ const focusCellRef = useRef();
64
75
  const [headerHeight, setHeaderHeight] = useState(showColumnHeaders ? -1 : 0);
65
76
  const [rowCount, setRowCount] = useState(dataSource.size);
66
77
  if (dataSource === void 0) {
@@ -153,7 +164,9 @@ const useTable = ({
153
164
  onSubscribed
154
165
  });
155
166
  const { requestScroll, ...scrollProps } = useTableScroll({
167
+ cellFocusStateRef,
156
168
  columns,
169
+ focusCell: focusCellRef.current,
157
170
  getRowAtPosition,
158
171
  rowHeight,
159
172
  scrollingApiRef,
@@ -380,6 +393,19 @@ const useTable = ({
380
393
  },
381
394
  [columnMap, columns, dataSource, dispatchTableModelAction]
382
395
  );
396
+ const {
397
+ focusCell,
398
+ focusCellPlaceholderKeyDown,
399
+ focusCellPlaceholderRef,
400
+ tableBodyRef
401
+ } = useCellFocus({
402
+ cellFocusStateRef,
403
+ containerRef,
404
+ disableFocus,
405
+ requestScroll
406
+ });
407
+ focusCellRef.current = focusCell;
408
+ const columnCount = columns.filter((c) => c.hidden !== true).length;
383
409
  const {
384
410
  highlightedIndexRef,
385
411
  navigate,
@@ -387,13 +413,15 @@ const useTable = ({
387
413
  onKeyDown: navigationKeyDown,
388
414
  ...containerProps
389
415
  } = useKeyboardNavigation({
390
- columnCount: columns.filter((c) => c.hidden !== true).length,
416
+ cellFocusStateRef,
417
+ columnCount,
391
418
  containerRef,
392
419
  disableFocus,
420
+ focusCell,
393
421
  highlightedIndex: highlightedIndexProp,
394
422
  navigationStyle,
395
423
  requestScroll,
396
- rowCount: dataSource?.size,
424
+ rowCount,
397
425
  onHighlight,
398
426
  viewportRange: range,
399
427
  viewportRowCount: viewportMeasurements.rowCount
@@ -465,13 +493,24 @@ const useTable = ({
465
493
  onSelectionChange: handleSelectionChange,
466
494
  selectionModel
467
495
  });
496
+ const handleSelectCellBlock = useCallback(
497
+ (cellBlock2) => {
498
+ handleSelectionChange([]);
499
+ onSelectCellBlock?.(cellBlock2);
500
+ },
501
+ [handleSelectionChange, onSelectCellBlock]
502
+ );
468
503
  const {
469
504
  onMouseDown: cellBlockHookMouseDown,
470
505
  cellBlock,
471
506
  onKeyDown: cellBlockSelectionKeyDown
472
507
  } = useCellBlockSelection({
473
508
  allowCellBlockSelection,
474
- onSelectCellBlock
509
+ columnCount,
510
+ containerRef,
511
+ focusCell,
512
+ onSelectCellBlock: handleSelectCellBlock,
513
+ rowCount
475
514
  });
476
515
  const handleRowClick = useCallback(
477
516
  (evt, row, rangeSelect, keepExistingSelection) => {
@@ -577,6 +616,8 @@ const useTable = ({
577
616
  columns,
578
617
  data,
579
618
  draggableRow,
619
+ focusCellPlaceholderKeyDown,
620
+ focusCellPlaceholderRef,
580
621
  getRowOffset,
581
622
  handleContextMenuAction,
582
623
  headerHeight,
@@ -602,6 +643,7 @@ const useTable = ({
602
643
  scrollProps,
603
644
  // TODO don't think we need these ...
604
645
  tableAttributes,
646
+ tableBodyRef,
605
647
  tableConfig,
606
648
  viewportMeasurements
607
649
  };