@navikt/ds-react 8.4.0 → 8.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/accordion/Accordion.d.ts +10 -0
- package/cjs/accordion/Accordion.js +2 -2
- package/cjs/accordion/Accordion.js.map +1 -1
- package/cjs/data/table/helpers/table-cell.d.ts +2 -2
- package/cjs/data/table/helpers/table-cell.js +2 -5
- package/cjs/data/table/helpers/table-cell.js.map +1 -1
- package/cjs/data/table/helpers/table-focus.d.ts +26 -2
- package/cjs/data/table/helpers/table-focus.js +60 -9
- package/cjs/data/table/helpers/table-focus.js.map +1 -1
- package/cjs/data/table/helpers/table-grid-nav.d.ts +45 -9
- package/cjs/data/table/helpers/table-grid-nav.js +108 -24
- package/cjs/data/table/helpers/table-grid-nav.js.map +1 -1
- package/cjs/data/table/helpers/table-keyboard.d.ts +24 -3
- package/cjs/data/table/helpers/table-keyboard.js +30 -5
- package/cjs/data/table/helpers/table-keyboard.js.map +1 -1
- package/cjs/data/table/hooks/useGridCache.d.ts +17 -0
- package/cjs/data/table/hooks/useGridCache.js +65 -0
- package/cjs/data/table/hooks/useGridCache.js.map +1 -0
- package/cjs/data/table/root/DataTableRoot.d.ts +1 -1
- package/cjs/data/table/root/DataTableRoot.js +2 -2
- package/cjs/data/table/root/DataTableRoot.js.map +1 -1
- package/cjs/data/table/root/useTableKeyboardNav.d.ts +9 -3
- package/cjs/data/table/root/useTableKeyboardNav.js +53 -95
- package/cjs/data/table/root/useTableKeyboardNav.js.map +1 -1
- package/cjs/data/table/th/DataTableTh.d.ts +1 -1
- package/cjs/data/table/th/DataTableTh.js +3 -1
- package/cjs/data/table/th/DataTableTh.js.map +1 -1
- package/cjs/data/table/tr/DataTableTr.d.ts +6 -2
- package/cjs/data/table/tr/DataTableTr.js +4 -2
- package/cjs/data/table/tr/DataTableTr.js.map +1 -1
- package/cjs/link-card/LinkCard.d.ts +13 -0
- package/cjs/link-card/LinkCard.js +2 -2
- package/cjs/link-card/LinkCard.js.map +1 -1
- package/cjs/process/Process.d.ts +1 -1
- package/cjs/utils/i18n/locales/nb.d.ts +154 -75
- package/cjs/utils/i18n/locales/nb.js +154 -75
- package/cjs/utils/i18n/locales/nb.js.map +1 -1
- package/esm/accordion/Accordion.d.ts +10 -0
- package/esm/accordion/Accordion.js +2 -2
- package/esm/accordion/Accordion.js.map +1 -1
- package/esm/data/table/helpers/table-cell.d.ts +2 -2
- package/esm/data/table/helpers/table-cell.js +2 -5
- package/esm/data/table/helpers/table-cell.js.map +1 -1
- package/esm/data/table/helpers/table-focus.d.ts +26 -2
- package/esm/data/table/helpers/table-focus.js +55 -9
- package/esm/data/table/helpers/table-focus.js.map +1 -1
- package/esm/data/table/helpers/table-grid-nav.d.ts +45 -9
- package/esm/data/table/helpers/table-grid-nav.js +102 -23
- package/esm/data/table/helpers/table-grid-nav.js.map +1 -1
- package/esm/data/table/helpers/table-keyboard.d.ts +24 -3
- package/esm/data/table/helpers/table-keyboard.js +29 -4
- package/esm/data/table/helpers/table-keyboard.js.map +1 -1
- package/esm/data/table/hooks/useGridCache.d.ts +17 -0
- package/esm/data/table/hooks/useGridCache.js +63 -0
- package/esm/data/table/hooks/useGridCache.js.map +1 -0
- package/esm/data/table/root/DataTableRoot.d.ts +1 -1
- package/esm/data/table/root/DataTableRoot.js +2 -2
- package/esm/data/table/root/DataTableRoot.js.map +1 -1
- package/esm/data/table/root/useTableKeyboardNav.d.ts +9 -3
- package/esm/data/table/root/useTableKeyboardNav.js +58 -100
- package/esm/data/table/root/useTableKeyboardNav.js.map +1 -1
- package/esm/data/table/th/DataTableTh.d.ts +1 -1
- package/esm/data/table/th/DataTableTh.js +3 -1
- package/esm/data/table/th/DataTableTh.js.map +1 -1
- package/esm/data/table/tr/DataTableTr.d.ts +6 -2
- package/esm/data/table/tr/DataTableTr.js +4 -2
- package/esm/data/table/tr/DataTableTr.js.map +1 -1
- package/esm/link-card/LinkCard.d.ts +13 -0
- package/esm/link-card/LinkCard.js +2 -2
- package/esm/link-card/LinkCard.js.map +1 -1
- package/esm/process/Process.d.ts +1 -1
- package/esm/utils/i18n/locales/nb.d.ts +154 -75
- package/esm/utils/i18n/locales/nb.js +154 -75
- package/esm/utils/i18n/locales/nb.js.map +1 -1
- package/package.json +3 -3
- package/src/accordion/Accordion.tsx +19 -2
- package/src/data/table/helpers/table-cell.ts +2 -7
- package/src/data/table/helpers/table-focus.ts +70 -9
- package/src/data/table/helpers/table-grid-nav.ts +146 -31
- package/src/data/table/helpers/table-keyboard.test.ts +27 -27
- package/src/data/table/helpers/table-keyboard.ts +43 -4
- package/src/data/table/hooks/useGridCache.ts +73 -0
- package/src/data/table/root/DataTableRoot.tsx +2 -3
- package/src/data/table/root/useTableKeyboardNav.ts +95 -125
- package/src/data/table/th/DataTableTh.tsx +7 -3
- package/src/data/table/tr/DataTableTr.tsx +7 -3
- package/src/link-card/LinkCard.tsx +15 -1
- package/src/process/Process.tsx +1 -1
- package/src/utils/i18n/locales/nb.ts +83 -4
|
@@ -48,6 +48,16 @@ interface AccordionProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
48
48
|
* @see [📝 Documentation](https://aksel.nav.no/grunnleggende/styling/farger-tokens)
|
|
49
49
|
*/
|
|
50
50
|
"data-color"?: Exclude<AkselColor, AkselStatusColorRole>;
|
|
51
|
+
/**
|
|
52
|
+
* Changes the HTML element used for the root element.
|
|
53
|
+
*
|
|
54
|
+
* **When using `section`, provide either `aria-label` or `aria-labelledby` for better accessibility.**
|
|
55
|
+
* `axe-core` might warn about unique landmarks if you have multiple Accordions on page with the same label.
|
|
56
|
+
* In those cases consider updating to unique `aria-label` or `aria-labelledby` props.
|
|
57
|
+
* @see [📝 Landmarks unique](https://dequeuniversity.com/rules/axe/4.6/landmark-unique)
|
|
58
|
+
* @default "div"
|
|
59
|
+
*/
|
|
60
|
+
as?: "div" | "section";
|
|
51
61
|
}
|
|
52
62
|
/**
|
|
53
63
|
* A component that displays collapsible content sections.
|
|
@@ -81,7 +81,7 @@ exports.AccordionItem = AccordionItem_1.default;
|
|
|
81
81
|
* ```
|
|
82
82
|
*/
|
|
83
83
|
exports.Accordion = (0, react_1.forwardRef)((_a, ref) => {
|
|
84
|
-
var { className, variant = "default", size = "medium", indent = true } = _a, rest = __rest(_a, ["className", "variant", "size", "indent"]);
|
|
84
|
+
var { className, variant = "default", size = "medium", indent = true, as: Component = "div" } = _a, rest = __rest(_a, ["className", "variant", "size", "indent", "as"]);
|
|
85
85
|
const localRef = (0, react_1.useRef)(null);
|
|
86
86
|
const mergedRef = (0, hooks_1.useMergeRefs)(localRef, ref);
|
|
87
87
|
(0, react_1.useEffect)(() => {
|
|
@@ -101,7 +101,7 @@ exports.Accordion = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
101
101
|
mounted: true,
|
|
102
102
|
variant,
|
|
103
103
|
} },
|
|
104
|
-
react_1.default.createElement(
|
|
104
|
+
react_1.default.createElement(Component, Object.assign({}, (0, utils_external_1.omit)(rest, ["headingSize"]), { className: (0, helpers_1.cl)("aksel-accordion", className, `aksel-accordion--${size}`, { "aksel-accordion--indent": indent }), ref: mergedRef }))));
|
|
105
105
|
});
|
|
106
106
|
exports.Accordion.Header = AccordionHeader_1.default;
|
|
107
107
|
exports.Accordion.Content = AccordionContent_1.default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Accordion.js","sourceRoot":"","sources":["../../src/accordion/Accordion.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAA6D;AAG7D,sDAAyC;AACzC,8CAAsC;AACtC,oEAAiE;AACjE,0CAA8C;AAC9C,0EAA6E;
|
|
1
|
+
{"version":3,"file":"Accordion.js","sourceRoot":"","sources":["../../src/accordion/Accordion.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAA6D;AAG7D,sDA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,IAAI;YACJ,OAAO,EAAE,IAAI;YACb,OAAO;SACR;QAED,8BAAC,SAAS,oBACJ,IAAA,qBAAI,EAAC,IAAI,EAAE,CAAC,aAAa,CAAC,CAAC,IAC/B,SAAS,EAAE,IAAA,YAAE,EACX,iBAAiB,EACjB,SAAS,EACT,oBAAoB,IAAI,EAAE,EAC1B,EAAE,yBAAyB,EAAE,MAAM,EAAE,CACtC,EACD,GAAG,EAAE,SAAS,IACd,CACwB,CAC7B,CAAC;AACJ,CAAC,CACoB,CAAC;AAExB,iBAAS,CAAC,MAAM,GAAG,yBAAe,CAAC;AACnC,iBAAS,CAAC,OAAO,GAAG,0BAAgB,CAAC;AACrC,iBAAS,CAAC,IAAI,GAAG,uBAAa,CAAC;AAE/B,kBAAe,iBAAS,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
declare function getFirstCell(tableRef: HTMLTableElement): Element | null;
|
|
2
|
-
declare function
|
|
3
|
-
export {
|
|
2
|
+
declare function focusInitialTableTarget(tableRef: HTMLTableElement | null): Element | null;
|
|
3
|
+
export { getFirstCell, focusInitialTableTarget };
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getActiveCell = getActiveCell;
|
|
4
3
|
exports.getFirstCell = getFirstCell;
|
|
4
|
+
exports.focusInitialTableTarget = focusInitialTableTarget;
|
|
5
5
|
const table_focus_1 = require("./table-focus");
|
|
6
6
|
function getFirstCell(tableRef) {
|
|
7
7
|
return tableRef.querySelector("td, th");
|
|
8
8
|
}
|
|
9
|
-
function
|
|
9
|
+
function focusInitialTableTarget(tableRef) {
|
|
10
10
|
if (!tableRef) {
|
|
11
11
|
return null;
|
|
12
12
|
}
|
|
13
|
-
if (activeCell) {
|
|
14
|
-
return activeCell;
|
|
15
|
-
}
|
|
16
13
|
const firstCell = getFirstCell(tableRef);
|
|
17
14
|
return firstCell ? (0, table_focus_1.focusCell)(firstCell) : null;
|
|
18
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table-cell.js","sourceRoot":"","sources":["../../../../src/data/table/helpers/table-cell.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"table-cell.js","sourceRoot":"","sources":["../../../../src/data/table/helpers/table-cell.ts"],"names":[],"mappings":";;AAiBS,oCAAY;AAAE,0DAAuB;AAjB9C,+CAA0C;AAE1C,SAAS,YAAY,CAAC,QAA0B;IAC9C,OAAO,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;AAC1C,CAAC;AAED,SAAS,uBAAuB,CAC9B,QAAiC;IAEjC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,SAAS,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;IACzC,OAAO,SAAS,CAAC,CAAC,CAAC,IAAA,uBAAS,EAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACjD,CAAC"}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Restores the original tabIndex for a cell.
|
|
3
|
+
*/
|
|
4
|
+
declare function restoreTabIndex(cell: Element): void;
|
|
1
5
|
/**
|
|
2
6
|
* Makes sure only focusable and non-disabled elements are targeted when navigating through the table using keyboard interactions.
|
|
3
7
|
* Tries to find the most logical focus target inside a cell, by looking for commonly used interactive elements,
|
|
@@ -6,9 +10,29 @@
|
|
|
6
10
|
* If the assumed focus target is not the cell itself, we check if that element is hidden or disabled, and fall back to the cell if so,
|
|
7
11
|
* since we want to avoid/can't focus hidden/disabled elements.
|
|
8
12
|
*/
|
|
9
|
-
declare function
|
|
13
|
+
declare function findFocusableElementInCell(cell: Element): HTMLElement | null;
|
|
14
|
+
/**
|
|
15
|
+
* Checks if an element is visually hidden (but not SR-only).
|
|
16
|
+
*/
|
|
17
|
+
declare function isHiddenElement(el: HTMLElement): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Checks if an element is disabled (via aria-disabled, fieldset, or native disabled property).
|
|
20
|
+
*/
|
|
21
|
+
declare function isDisabledElement(el: HTMLElement): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Determines the focus target and updates tabIndex if the cell itself should be focused.
|
|
24
|
+
* Returns null if no focusable target found.
|
|
25
|
+
*/
|
|
26
|
+
declare function prepareCellFocus(cell: Element): HTMLElement | null;
|
|
27
|
+
/**
|
|
28
|
+
* Applies focus and scroll to an element.
|
|
29
|
+
*/
|
|
30
|
+
declare function applyFocusAndScroll(element: HTMLElement): void;
|
|
31
|
+
/**
|
|
32
|
+
* Focuses a cell by finding its focusable target and applying focus with scroll.
|
|
33
|
+
*/
|
|
10
34
|
declare function focusCell(cell: Element): Element | null;
|
|
11
35
|
declare function focusCellAndUpdateTabIndex(nextCell: Element, previousCell?: Element | null, { shouldFocus }?: {
|
|
12
36
|
shouldFocus?: boolean;
|
|
13
37
|
}): Element | null;
|
|
14
|
-
export { focusCell, focusCellAndUpdateTabIndex,
|
|
38
|
+
export { applyFocusAndScroll, focusCell, focusCellAndUpdateTabIndex, findFocusableElementInCell, isDisabledElement, isHiddenElement, prepareCellFocus, restoreTabIndex, };
|
|
@@ -1,8 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyFocusAndScroll = applyFocusAndScroll;
|
|
3
4
|
exports.focusCell = focusCell;
|
|
4
5
|
exports.focusCellAndUpdateTabIndex = focusCellAndUpdateTabIndex;
|
|
5
|
-
exports.
|
|
6
|
+
exports.findFocusableElementInCell = findFocusableElementInCell;
|
|
7
|
+
exports.isDisabledElement = isDisabledElement;
|
|
8
|
+
exports.isHiddenElement = isHiddenElement;
|
|
9
|
+
exports.prepareCellFocus = prepareCellFocus;
|
|
10
|
+
exports.restoreTabIndex = restoreTabIndex;
|
|
11
|
+
/**
|
|
12
|
+
* WeakMap to store original tabIndex values for cells.
|
|
13
|
+
* Used to restore tabIndex when navigation moves away from a cell.
|
|
14
|
+
*/
|
|
15
|
+
const originalTabIndexMap = new WeakMap();
|
|
16
|
+
/**
|
|
17
|
+
* Stores the original tabIndex of a cell if not already stored, and returns it.
|
|
18
|
+
*/
|
|
19
|
+
function syncOriginalTabIndex(cell) {
|
|
20
|
+
if (!originalTabIndexMap.has(cell)) {
|
|
21
|
+
const current = cell.tabIndex;
|
|
22
|
+
originalTabIndexMap.set(cell, current);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Restores the original tabIndex for a cell.
|
|
27
|
+
*/
|
|
28
|
+
function restoreTabIndex(cell) {
|
|
29
|
+
const original = originalTabIndexMap.get(cell);
|
|
30
|
+
if (original !== undefined) {
|
|
31
|
+
cell.tabIndex = original;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
6
34
|
/**
|
|
7
35
|
* Makes sure only focusable and non-disabled elements are targeted when navigating through the table using keyboard interactions.
|
|
8
36
|
* Tries to find the most logical focus target inside a cell, by looking for commonly used interactive elements,
|
|
@@ -11,7 +39,7 @@ exports.getFocusableTarget = getFocusableTarget;
|
|
|
11
39
|
* If the assumed focus target is not the cell itself, we check if that element is hidden or disabled, and fall back to the cell if so,
|
|
12
40
|
* since we want to avoid/can't focus hidden/disabled elements.
|
|
13
41
|
*/
|
|
14
|
-
function
|
|
42
|
+
function findFocusableElementInCell(cell) {
|
|
15
43
|
const el = cell;
|
|
16
44
|
if (!el || isHiddenElement(el)) {
|
|
17
45
|
return null;
|
|
@@ -29,8 +57,7 @@ function getFocusableTarget(cell) {
|
|
|
29
57
|
return el;
|
|
30
58
|
}
|
|
31
59
|
/**
|
|
32
|
-
*
|
|
33
|
-
* - validate this implementation against SR-only elements
|
|
60
|
+
* Checks if an element is visually hidden (but not SR-only).
|
|
34
61
|
*/
|
|
35
62
|
function isHiddenElement(el) {
|
|
36
63
|
if (el.hidden) {
|
|
@@ -39,6 +66,9 @@ function isHiddenElement(el) {
|
|
|
39
66
|
const style = window.getComputedStyle(el);
|
|
40
67
|
return style.display === "none" || style.visibility === "hidden";
|
|
41
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Checks if an element is disabled (via aria-disabled, fieldset, or native disabled property).
|
|
71
|
+
*/
|
|
42
72
|
function isDisabledElement(el) {
|
|
43
73
|
if (el.getAttribute("aria-disabled") === "true") {
|
|
44
74
|
return true;
|
|
@@ -54,27 +84,48 @@ function isDisabledElement(el) {
|
|
|
54
84
|
}
|
|
55
85
|
return false;
|
|
56
86
|
}
|
|
57
|
-
|
|
58
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Determines the focus target and updates tabIndex if the cell itself should be focused.
|
|
89
|
+
* Returns null if no focusable target found.
|
|
90
|
+
*/
|
|
91
|
+
function prepareCellFocus(cell) {
|
|
92
|
+
const focusTarget = findFocusableElementInCell(cell);
|
|
59
93
|
if (!focusTarget) {
|
|
60
94
|
return null;
|
|
61
95
|
}
|
|
62
96
|
if (focusTarget === cell) {
|
|
63
97
|
cell.tabIndex = 0;
|
|
64
98
|
}
|
|
65
|
-
focusTarget
|
|
99
|
+
return focusTarget;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Applies focus and scroll to an element.
|
|
103
|
+
*/
|
|
104
|
+
function applyFocusAndScroll(element) {
|
|
105
|
+
element.focus({
|
|
66
106
|
preventScroll: true,
|
|
67
107
|
});
|
|
68
|
-
|
|
108
|
+
element.scrollIntoView({
|
|
69
109
|
behavior: "smooth",
|
|
70
110
|
block: "nearest",
|
|
71
111
|
inline: "nearest",
|
|
72
112
|
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Focuses a cell by finding its focusable target and applying focus with scroll.
|
|
116
|
+
*/
|
|
117
|
+
function focusCell(cell) {
|
|
118
|
+
const focusTarget = prepareCellFocus(cell);
|
|
119
|
+
if (!focusTarget) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
applyFocusAndScroll(focusTarget);
|
|
73
123
|
return cell;
|
|
74
124
|
}
|
|
75
125
|
function focusCellAndUpdateTabIndex(nextCell, previousCell, { shouldFocus = true } = {}) {
|
|
76
126
|
if (previousCell && previousCell !== nextCell) {
|
|
77
|
-
previousCell
|
|
127
|
+
syncOriginalTabIndex(previousCell);
|
|
128
|
+
restoreTabIndex(previousCell);
|
|
78
129
|
}
|
|
79
130
|
if (!shouldFocus) {
|
|
80
131
|
return nextCell;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table-focus.js","sourceRoot":"","sources":["../../../../src/data/table/helpers/table-focus.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"table-focus.js","sourceRoot":"","sources":["../../../../src/data/table/helpers/table-focus.ts"],"names":[],"mappings":";;AA6JE,kDAAmB;AACnB,8BAAS;AACT,gEAA0B;AAC1B,gEAA0B;AAC1B,8CAAiB;AACjB,0CAAe;AACf,4CAAgB;AAChB,0CAAe;AApKjB;;;GAGG;AACH,MAAM,mBAAmB,GAAG,IAAI,OAAO,EAAmB,CAAC;AAE3D;;GAEG;AACH,SAAS,oBAAoB,CAAC,IAAa;IACzC,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QACnC,MAAM,OAAO,GAAI,IAAoB,CAAC,QAAQ,CAAC;QAC/C,mBAAmB,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,eAAe,CAAC,IAAa;IACpC,MAAM,QAAQ,GAAG,mBAAmB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC/C,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC1B,IAAoB,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC5C,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,0BAA0B,CAAC,IAAa;IAC/C,MAAM,EAAE,GAAG,IAA0B,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AS,CAAC,QAAQ,CAAC,CAAC;AAC7B,CAAC"}
|
|
@@ -1,33 +1,69 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Builds a utility grid allowing for easier keyboard-navigation between cells on columns and rows
|
|
3
3
|
*/
|
|
4
|
-
declare function
|
|
4
|
+
declare function buildTableGridMap(tableRef: HTMLTableElement): {
|
|
5
5
|
grid: (Element | undefined)[][];
|
|
6
6
|
positions: Map<Element, {
|
|
7
7
|
x: number;
|
|
8
8
|
y: number;
|
|
9
9
|
}>;
|
|
10
|
-
maxCols: number;
|
|
11
10
|
};
|
|
12
|
-
type TableGrid = ReturnType<typeof buildTableGrid>;
|
|
13
11
|
type GridCache = {
|
|
14
|
-
grid:
|
|
12
|
+
grid: ReturnType<typeof buildTableGridMap> | null;
|
|
15
13
|
dirty: boolean;
|
|
16
14
|
};
|
|
17
15
|
/**
|
|
18
|
-
*
|
|
16
|
+
* Pure function that calculates the next grid position given a current position and delta.
|
|
17
|
+
* Returns the position if valid, or null if out of bounds.
|
|
19
18
|
*/
|
|
20
|
-
declare function
|
|
19
|
+
declare function getNextGridPosition(grid: (Element | undefined)[][], currentPos: {
|
|
20
|
+
x: number;
|
|
21
|
+
y: number;
|
|
22
|
+
}, delta: {
|
|
23
|
+
x: number;
|
|
24
|
+
y: number;
|
|
25
|
+
}): {
|
|
26
|
+
x: number;
|
|
27
|
+
y: number;
|
|
28
|
+
} | null;
|
|
29
|
+
/**
|
|
30
|
+
* Checks if a cell is focusable (not the same as current cell and contains focusable elements).
|
|
31
|
+
* Type guard that narrows Element | undefined to Element.
|
|
32
|
+
*/
|
|
33
|
+
declare function isCellFocusable(cell: Element | undefined, currentCell: Element): cell is Element;
|
|
21
34
|
/**
|
|
22
35
|
* Finds the next cell in the given direction, starting from the current position.
|
|
23
36
|
* Skips over cells that are not focusable or are the same as the current cell.
|
|
24
37
|
* Returns null if no next cell is found in the given direction.
|
|
25
38
|
*/
|
|
26
|
-
declare function
|
|
39
|
+
declare function findNextFocusableCell(grid: (Element | undefined)[][], currentPos: {
|
|
27
40
|
x: number;
|
|
28
41
|
y: number;
|
|
29
42
|
}, delta: {
|
|
30
43
|
x: number;
|
|
31
44
|
y: number;
|
|
32
|
-
}, currentCell: Element
|
|
33
|
-
|
|
45
|
+
}, currentCell: Element): Element | null;
|
|
46
|
+
/**
|
|
47
|
+
* Finds the first focusable cell in the same row as the current position.
|
|
48
|
+
*/
|
|
49
|
+
declare function findFirstCellInRow(grid: (Element | undefined)[][], positions: Map<Element, {
|
|
50
|
+
x: number;
|
|
51
|
+
y: number;
|
|
52
|
+
}>, currentCell: Element): Element | null;
|
|
53
|
+
/**
|
|
54
|
+
* Finds the last focusable cell in the same row as the current position.
|
|
55
|
+
*/
|
|
56
|
+
declare function findLastCellInRow(grid: (Element | undefined)[][], positions: Map<Element, {
|
|
57
|
+
x: number;
|
|
58
|
+
y: number;
|
|
59
|
+
}>, currentCell: Element): Element | null;
|
|
60
|
+
/**
|
|
61
|
+
* Finds the first focusable cell in the entire table.
|
|
62
|
+
*/
|
|
63
|
+
declare function findFirstCell(grid: (Element | undefined)[][], currentCell: Element): Element | null;
|
|
64
|
+
/**
|
|
65
|
+
* Finds the last focusable cell in the entire table.
|
|
66
|
+
*/
|
|
67
|
+
declare function findLastCell(grid: (Element | undefined)[][], currentCell: Element): Element | null;
|
|
68
|
+
export { buildTableGridMap, findFirstCell, findFirstCellInRow, findLastCell, findLastCellInRow, findNextFocusableCell, getNextGridPosition, isCellFocusable, };
|
|
69
|
+
export type { GridCache };
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
5
|
-
exports.
|
|
3
|
+
exports.buildTableGridMap = buildTableGridMap;
|
|
4
|
+
exports.findFirstCell = findFirstCell;
|
|
5
|
+
exports.findFirstCellInRow = findFirstCellInRow;
|
|
6
|
+
exports.findLastCell = findLastCell;
|
|
7
|
+
exports.findLastCellInRow = findLastCellInRow;
|
|
8
|
+
exports.findNextFocusableCell = findNextFocusableCell;
|
|
9
|
+
exports.getNextGridPosition = getNextGridPosition;
|
|
10
|
+
exports.isCellFocusable = isCellFocusable;
|
|
6
11
|
const table_focus_1 = require("./table-focus");
|
|
7
12
|
/**
|
|
8
13
|
* Builds a utility grid allowing for easier keyboard-navigation between cells on columns and rows
|
|
9
14
|
*/
|
|
10
|
-
function
|
|
15
|
+
function buildTableGridMap(tableRef) {
|
|
11
16
|
const rows = tableRef.rows;
|
|
12
17
|
const grid = [];
|
|
13
18
|
const positions = new Map();
|
|
14
|
-
let maxCols = 0;
|
|
15
19
|
/* Walk trough each row in order */
|
|
16
20
|
for (let rowIndex = 0; rowIndex < rows.length; rowIndex += 1) {
|
|
17
21
|
const row = rows[rowIndex];
|
|
@@ -43,41 +47,121 @@ function buildTableGrid(tableRef) {
|
|
|
43
47
|
positions.set(cell, { x: colIndex, y: rowIndex });
|
|
44
48
|
}
|
|
45
49
|
colIndex += colSpan;
|
|
46
|
-
if (colIndex > maxCols) {
|
|
47
|
-
maxCols = colIndex;
|
|
48
|
-
}
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
|
-
return { grid, positions
|
|
52
|
+
return { grid, positions };
|
|
52
53
|
}
|
|
53
54
|
/**
|
|
54
|
-
*
|
|
55
|
+
* Pure function that calculates the next grid position given a current position and delta.
|
|
56
|
+
* Returns the position if valid, or null if out of bounds.
|
|
55
57
|
*/
|
|
56
|
-
function
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
function getNextGridPosition(grid, currentPos, delta) {
|
|
59
|
+
var _a;
|
|
60
|
+
const x = currentPos.x + delta.x;
|
|
61
|
+
const y = currentPos.y + delta.y;
|
|
62
|
+
if (y < 0 || y >= grid.length) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
const row = (_a = grid[y]) !== null && _a !== void 0 ? _a : [];
|
|
66
|
+
if (x < 0 || x >= row.length) {
|
|
67
|
+
return null;
|
|
60
68
|
}
|
|
61
|
-
return
|
|
69
|
+
return { x, y };
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Checks if a cell is focusable (not the same as current cell and contains focusable elements).
|
|
73
|
+
* Type guard that narrows Element | undefined to Element.
|
|
74
|
+
*/
|
|
75
|
+
function isCellFocusable(cell, currentCell) {
|
|
76
|
+
if (!cell || cell === currentCell) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
return !!(0, table_focus_1.findFocusableElementInCell)(cell);
|
|
62
80
|
}
|
|
63
81
|
/**
|
|
64
82
|
* Finds the next cell in the given direction, starting from the current position.
|
|
65
83
|
* Skips over cells that are not focusable or are the same as the current cell.
|
|
66
84
|
* Returns null if no next cell is found in the given direction.
|
|
67
85
|
*/
|
|
68
|
-
function
|
|
86
|
+
function findNextFocusableCell(grid, currentPos, delta, currentCell) {
|
|
87
|
+
let position = currentPos;
|
|
88
|
+
while (true) {
|
|
89
|
+
const nextPos = getNextGridPosition(grid, position, delta);
|
|
90
|
+
if (!nextPos) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
const cell = grid[nextPos.y][nextPos.x];
|
|
94
|
+
if (isCellFocusable(cell, currentCell)) {
|
|
95
|
+
return cell;
|
|
96
|
+
}
|
|
97
|
+
position = nextPos;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Finds the first focusable cell in the same row as the current position.
|
|
102
|
+
*/
|
|
103
|
+
function findFirstCellInRow(grid, positions, currentCell) {
|
|
69
104
|
var _a;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
105
|
+
const currentPos = positions.get(currentCell);
|
|
106
|
+
if (!currentPos) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
const row = (_a = grid[currentPos.y]) !== null && _a !== void 0 ? _a : [];
|
|
110
|
+
for (let x = 0; x < row.length; x += 1) {
|
|
111
|
+
const cell = row[x];
|
|
112
|
+
if (isCellFocusable(cell, currentCell)) {
|
|
113
|
+
return cell;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Finds the last focusable cell in the same row as the current position.
|
|
120
|
+
*/
|
|
121
|
+
function findLastCellInRow(grid, positions, currentCell) {
|
|
122
|
+
var _a;
|
|
123
|
+
const currentPos = positions.get(currentCell);
|
|
124
|
+
if (!currentPos) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
const row = (_a = grid[currentPos.y]) !== null && _a !== void 0 ? _a : [];
|
|
128
|
+
for (let x = row.length - 1; x >= 0; x -= 1) {
|
|
75
129
|
const cell = row[x];
|
|
76
|
-
if (cell
|
|
130
|
+
if (isCellFocusable(cell, currentCell)) {
|
|
77
131
|
return cell;
|
|
78
132
|
}
|
|
79
|
-
|
|
80
|
-
|
|
133
|
+
}
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Finds the first focusable cell in the entire table.
|
|
138
|
+
*/
|
|
139
|
+
function findFirstCell(grid, currentCell) {
|
|
140
|
+
var _a;
|
|
141
|
+
for (let y = 0; y < grid.length; y += 1) {
|
|
142
|
+
const row = (_a = grid[y]) !== null && _a !== void 0 ? _a : [];
|
|
143
|
+
for (let x = 0; x < row.length; x += 1) {
|
|
144
|
+
const cell = row[x];
|
|
145
|
+
if (isCellFocusable(cell, currentCell)) {
|
|
146
|
+
return cell;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Finds the last focusable cell in the entire table.
|
|
154
|
+
*/
|
|
155
|
+
function findLastCell(grid, currentCell) {
|
|
156
|
+
var _a;
|
|
157
|
+
for (let y = grid.length - 1; y >= 0; y -= 1) {
|
|
158
|
+
const row = (_a = grid[y]) !== null && _a !== void 0 ? _a : [];
|
|
159
|
+
for (let x = row.length - 1; x >= 0; x -= 1) {
|
|
160
|
+
const cell = row[x];
|
|
161
|
+
if (isCellFocusable(cell, currentCell)) {
|
|
162
|
+
return cell;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
81
165
|
}
|
|
82
166
|
return null;
|
|
83
167
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table-grid-nav.js","sourceRoot":"","sources":["../../../../src/data/table/helpers/table-grid-nav.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"table-grid-nav.js","sourceRoot":"","sources":["../../../../src/data/table/helpers/table-grid-nav.ts"],"names":[],"mappings":";;AAyNE,8CAAiB;AACjB,sCAAa;AACb,gDAAkB;AAClB,oCAAY;AACZ,8CAAiB;AACjB,sDAAqB;AACrB,kDAAmB;AACnB,0CAAe;AAhOjB,+CAA2D;AAE3D;;GAEG;AACH,SAAS,iBAAiB,CAAC,QAA0B;IAInD,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC;IAC3B,MAAM,IAAI,GAA8B,EAAE,CAAC;IAC3C,MAAM,SAAS,GAAG,IAAI,GAAG,EAAqC,CAAC;IAE/D,mCAAmC;IACnC,KAAK,IAAI,QAAQ,GAAG,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC,MAAM,EAAE,QAAQ,IAAI,CAAC,EAAE,CAAC;QAC7D,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC3B,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC;QACxB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;YACpB,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;QACtB,CAAC;QAED,IAAI,QAAQ,GAAG,CAAC,CAAC;QAEjB,kCAAkC;QAClC,KAAK,IAAI,SAAS,GAAG,CAAC,EAAE,SAAS,GAAG,KAAK,CAAC,MAAM,EAAE,SAAS,I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|
2
2
|
x: number;
|
|
3
3
|
y: number;
|
|
4
4
|
};
|
|
5
|
-
|
|
5
|
+
type NavigationAction = {
|
|
6
|
+
type: "delta";
|
|
7
|
+
delta: Delta;
|
|
8
|
+
} | {
|
|
9
|
+
type: "home";
|
|
10
|
+
} | {
|
|
11
|
+
type: "end";
|
|
12
|
+
} | {
|
|
13
|
+
type: "tableStart";
|
|
14
|
+
} | {
|
|
15
|
+
type: "tableEnd";
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Maps keyboard events to navigation actions.
|
|
19
|
+
* Supports arrow keys, Home/End (row navigation), Ctrl/Cmd+Home/End (table navigation),
|
|
20
|
+
* and PageUp/PageDown (multi-row navigation).
|
|
21
|
+
*/
|
|
22
|
+
declare function getNavigationAction(event: KeyboardEvent): NavigationAction | null;
|
|
6
23
|
/**
|
|
24
|
+
* Determines if keyboard navigation should be blocked based on the current focus context.
|
|
25
|
+
* Allows for custom blocking logic via an optional callback.
|
|
26
|
+
*
|
|
7
27
|
* Tries to make assumptions of what the user is currently doing inside a table cell
|
|
8
28
|
* Should block navigation if:
|
|
9
29
|
* - Input has selection, caret is not at start/end
|
|
@@ -11,5 +31,6 @@ declare function getDeltaFromKey(key: string): Delta | null;
|
|
|
11
31
|
* - User is navigating inside multiline textarea
|
|
12
32
|
* - contenteditable attrb is in use
|
|
13
33
|
*/
|
|
14
|
-
declare function
|
|
15
|
-
export {
|
|
34
|
+
declare function shouldBlockNavigation(event: KeyboardEvent, customBlockFn?: (event: KeyboardEvent) => boolean): boolean;
|
|
35
|
+
export { getNavigationAction, shouldBlockNavigation };
|
|
36
|
+
export type { Delta, NavigationAction };
|
|
@@ -1,20 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
3
|
+
exports.getNavigationAction = getNavigationAction;
|
|
4
|
+
exports.shouldBlockNavigation = shouldBlockNavigation;
|
|
5
5
|
const keyToCoord = {
|
|
6
6
|
ArrowUp: { x: 0, y: -1 },
|
|
7
7
|
ArrowDown: { x: 0, y: 1 },
|
|
8
8
|
ArrowLeft: { x: -1, y: 0 },
|
|
9
9
|
ArrowRight: { x: 1, y: 0 },
|
|
10
10
|
};
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Maps keyboard events to navigation actions.
|
|
13
|
+
* Supports arrow keys, Home/End (row navigation), Ctrl/Cmd+Home/End (table navigation),
|
|
14
|
+
* and PageUp/PageDown (multi-row navigation).
|
|
15
|
+
*/
|
|
16
|
+
function getNavigationAction(event) {
|
|
17
|
+
const key = event.key;
|
|
18
|
+
/* Arrow keys -> directional navigation */
|
|
12
19
|
if (key in keyToCoord) {
|
|
13
|
-
return keyToCoord[key];
|
|
20
|
+
return { type: "delta", delta: keyToCoord[key] };
|
|
21
|
+
}
|
|
22
|
+
// Home/End keys
|
|
23
|
+
if (key === "Home") {
|
|
24
|
+
return event.ctrlKey || event.metaKey
|
|
25
|
+
? { type: "tableStart" }
|
|
26
|
+
: { type: "home" };
|
|
27
|
+
}
|
|
28
|
+
if (key === "End") {
|
|
29
|
+
return event.ctrlKey || event.metaKey
|
|
30
|
+
? { type: "tableEnd" }
|
|
31
|
+
: { type: "end" };
|
|
14
32
|
}
|
|
15
33
|
return null;
|
|
16
34
|
}
|
|
17
35
|
/**
|
|
36
|
+
* Determines if keyboard navigation should be blocked based on the current focus context.
|
|
37
|
+
* Allows for custom blocking logic via an optional callback.
|
|
38
|
+
*
|
|
18
39
|
* Tries to make assumptions of what the user is currently doing inside a table cell
|
|
19
40
|
* Should block navigation if:
|
|
20
41
|
* - Input has selection, caret is not at start/end
|
|
@@ -22,7 +43,11 @@ function getDeltaFromKey(key) {
|
|
|
22
43
|
* - User is navigating inside multiline textarea
|
|
23
44
|
* - contenteditable attrb is in use
|
|
24
45
|
*/
|
|
25
|
-
function
|
|
46
|
+
function shouldBlockNavigation(event, customBlockFn) {
|
|
47
|
+
/* Check custom block function first */
|
|
48
|
+
if (customBlockFn === null || customBlockFn === void 0 ? void 0 : customBlockFn(event)) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
26
51
|
const key = event.key;
|
|
27
52
|
if (!(key in keyToCoord)) {
|
|
28
53
|
return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table-keyboard.js","sourceRoot":"","sources":["../../../../src/data/table/helpers/table-keyboard.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"table-keyboard.js","sourceRoot":"","sources":["../../../../src/data/table/helpers/table-keyboard.ts"],"names":[],"mappings":";;AAmKS,kDAAmB;AAAE,sDAAqB;AAnKnD,MAAM,UAAU,GAAG;IACjB,OAAO,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE;IACxB,SAAS,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;IACzB,SAAS,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;IAC1B,UAAU,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;CAClB,CAAC;AAWX;;;;GAIG;AACH,SAAS,mBAAmB,CAAC,KAAoB;IAC/C,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;IAEtB,0CAA0C;IAC1C,IAAI,GAAG,IAAI,UAAU,EAAE,CAAC;QACtB,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,GAAkB,CAAC,EAAE,CAAC;IAClE,CAAC;IAED,gBAAgB;IAChB,IAAI,GAAG,KAAK,MAAM,EAAE,CAAC;QACnB,OAAO,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO;YACnC,CAAC,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE;YACxB,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;I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