@cloudscape-design/components 3.0.376 → 3.0.377
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/cards/index.d.ts.map +1 -1
- package/cards/index.js +2 -3
- package/cards/index.js.map +1 -1
- package/internal/analytics/hooks/use-funnel.d.ts.map +1 -1
- package/internal/analytics/hooks/use-funnel.js +6 -2
- package/internal/analytics/hooks/use-funnel.js.map +1 -1
- package/internal/analytics/index.d.ts.map +1 -1
- package/internal/analytics/index.js +2 -0
- package/internal/analytics/index.js.map +1 -1
- package/internal/analytics/interfaces.d.ts +24 -0
- package/internal/analytics/interfaces.d.ts.map +1 -1
- package/internal/analytics/interfaces.js.map +1 -1
- package/internal/environment.js +1 -1
- package/internal/environment.json +1 -1
- package/internal/manifest.json +1 -1
- package/package.json +1 -1
- package/table/internal.d.ts.map +1 -1
- package/table/internal.js +2 -3
- package/table/internal.js.map +1 -1
- package/table/selection/index.d.ts +6 -0
- package/table/selection/index.d.ts.map +1 -0
- package/table/selection/index.js +7 -0
- package/table/selection/index.js.map +1 -0
- package/table/selection/interfaces.d.ts +10 -0
- package/table/selection/interfaces.d.ts.map +1 -0
- package/table/selection/interfaces.js +4 -0
- package/table/selection/interfaces.js.map +1 -0
- package/table/{selection-control/index.d.ts → selection/selection-control.d.ts} +3 -3
- package/table/selection/selection-control.d.ts.map +1 -0
- package/table/{selection-control/index.js → selection/selection-control.js} +2 -2
- package/table/selection/selection-control.js.map +1 -0
- package/table/selection/styles.css.js +8 -0
- package/table/{selection-control → selection}/styles.scoped.css +3 -3
- package/table/{selection-control → selection}/styles.selectors.js +3 -3
- package/table/selection/use-selection-focus-move.d.ts +12 -0
- package/table/selection/use-selection-focus-move.d.ts.map +1 -0
- package/table/selection/use-selection-focus-move.js +46 -0
- package/table/selection/use-selection-focus-move.js.map +1 -0
- package/table/selection/use-selection.d.ts +9 -0
- package/table/selection/use-selection.d.ts.map +1 -0
- package/table/{use-selection.js → selection/use-selection.js} +5 -64
- package/table/selection/use-selection.js.map +1 -0
- package/table/selection/utils.d.ts +23 -0
- package/table/selection/utils.d.ts.map +1 -0
- package/table/selection/utils.js +22 -0
- package/table/selection/utils.js.map +1 -0
- package/table/table-role/interfaces.d.ts +1 -1
- package/table/table-role/interfaces.js.map +1 -1
- package/table/table-role/table-role-helper.d.ts +2 -8
- package/table/table-role/table-role-helper.d.ts.map +1 -1
- package/table/table-role/table-role-helper.js +0 -6
- package/table/table-role/table-role-helper.js.map +1 -1
- package/table/table-role/use-grid-navigation.js +12 -33
- package/table/table-role/use-grid-navigation.js.map +1 -1
- package/table/table-role/utils.d.ts +1 -6
- package/table/table-role/utils.d.ts.map +1 -1
- package/table/table-role/utils.js +57 -51
- package/table/table-role/utils.js.map +1 -1
- package/table/thead.d.ts +1 -1
- package/table/thead.d.ts.map +1 -1
- package/table/thead.js +1 -2
- package/table/thead.js.map +1 -1
- package/test-utils/dom/table/index.js +1 -1
- package/test-utils/dom/table/index.js.map +1 -1
- package/test-utils/selectors/table/index.js +1 -1
- package/test-utils/selectors/table/index.js.map +1 -1
- package/test-utils/tsconfig.tsbuildinfo +1 -1
- package/table/selection-control/index.d.ts.map +0 -1
- package/table/selection-control/index.js.map +0 -1
- package/table/selection-control/styles.css.js +0 -8
- package/table/use-selection.d.ts +0 -38
- package/table/use-selection.d.ts.map +0 -1
- package/table/use-selection.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"lib/default/","sources":["table/selection/interfaces.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;IAClB,aAAa,EAAE,QAAQ,GAAG,OAAO,CAAC;IAClC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"lib/default/","sources":["table/selection/interfaces.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nexport interface SelectionProps {\n name: string;\n disabled: boolean;\n selectionType: 'single' | 'multi';\n indeterminate?: boolean;\n checked: boolean;\n onChange: () => void;\n ariaLabel?: string;\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { KeyboardEventHandler } from 'react';
|
|
2
|
-
import { SelectionProps } from '
|
|
2
|
+
import { SelectionProps } from './interfaces';
|
|
3
3
|
export interface SelectionControlProps extends SelectionProps {
|
|
4
4
|
onShiftToggle?(shiftPressed: boolean): void;
|
|
5
5
|
onFocusUp?: KeyboardEventHandler;
|
|
@@ -8,5 +8,5 @@ export interface SelectionControlProps extends SelectionProps {
|
|
|
8
8
|
tabIndex?: -1;
|
|
9
9
|
focusedComponent?: null | string;
|
|
10
10
|
}
|
|
11
|
-
export
|
|
12
|
-
//# sourceMappingURL=
|
|
11
|
+
export declare function SelectionControl({ selectionType, indeterminate, onShiftToggle, onFocusUp, onFocusDown, name, ariaLabel, focusedComponent, ...sharedProps }: SelectionControlProps): JSX.Element;
|
|
12
|
+
//# sourceMappingURL=selection-control.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selection-control.d.ts","sourceRoot":"lib/default/","sources":["table/selection/selection-control.tsx"],"names":[],"mappings":"AAGA,OAAc,EAAiB,oBAAoB,EAAc,MAAM,OAAO,CAAC;AAO/E,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,MAAM,WAAW,qBAAsB,SAAQ,cAAc;IAC3D,aAAa,CAAC,CAAC,YAAY,EAAE,OAAO,GAAG,IAAI,CAAC;IAC5C,SAAS,CAAC,EAAE,oBAAoB,CAAC;IACjC,WAAW,CAAC,EAAE,oBAAoB,CAAC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;IACd,gBAAgB,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;CAClC;AAED,wBAAgB,gBAAgB,CAAC,EAC/B,aAAa,EACb,aAAqB,EACrB,aAAa,EACb,SAAS,EACT,WAAW,EACX,IAAI,EACJ,SAAS,EACT,gBAAgB,EAChB,GAAG,WAAW,EACf,EAAE,qBAAqB,eA2EvB"}
|
|
@@ -8,7 +8,7 @@ import { useUniqueId } from '../../internal/hooks/use-unique-id';
|
|
|
8
8
|
import InternalCheckbox from '../../checkbox/internal';
|
|
9
9
|
import RadioButton from '../../radio-group/radio-button';
|
|
10
10
|
import styles from './styles.css.js';
|
|
11
|
-
export
|
|
11
|
+
export function SelectionControl(_a) {
|
|
12
12
|
var { selectionType, indeterminate = false, onShiftToggle, onFocusUp, onFocusDown, name, ariaLabel, focusedComponent } = _a, sharedProps = __rest(_a, ["selectionType", "indeterminate", "onShiftToggle", "onFocusUp", "onFocusDown", "name", "ariaLabel", "focusedComponent"]);
|
|
13
13
|
const controlId = useUniqueId();
|
|
14
14
|
const isMultiSelection = selectionType === 'multi';
|
|
@@ -51,4 +51,4 @@ export default function SelectionControl(_a) {
|
|
|
51
51
|
React.createElement("label", { onKeyDown: handleKeyDown, onKeyUp: setShiftState, onMouseDown: onMouseDownHandler, onMouseUp: setShiftState, onClick: handleClick, htmlFor: controlId, className: clsx(styles.label, styles.root), "aria-label": ariaLabel, title: ariaLabel }, selector),
|
|
52
52
|
React.createElement("span", { className: clsx(styles.stud), "aria-hidden": true }, "\u00A0")));
|
|
53
53
|
}
|
|
54
|
-
//# sourceMappingURL=
|
|
54
|
+
//# sourceMappingURL=selection-control.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selection-control.js","sourceRoot":"l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,EAAE,SAAS,IAEf,QAAQ,CACH;QAER,8BAAM,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAe,IAAI,aAE9C,CACN,CACJ,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport clsx from 'clsx';\nimport React, { KeyboardEvent, KeyboardEventHandler, MouseEvent } from 'react';\nimport { KeyCode } from '../../internal/keycode';\nimport { useUniqueId } from '../../internal/hooks/use-unique-id';\nimport InternalCheckbox from '../../checkbox/internal';\nimport RadioButton from '../../radio-group/radio-button';\n\nimport styles from './styles.css.js';\nimport { SelectionProps } from './interfaces';\n\nexport interface SelectionControlProps extends SelectionProps {\n onShiftToggle?(shiftPressed: boolean): void;\n onFocusUp?: KeyboardEventHandler;\n onFocusDown?: KeyboardEventHandler;\n ariaLabel?: string;\n tabIndex?: -1;\n focusedComponent?: null | string;\n}\n\nexport function SelectionControl({\n selectionType,\n indeterminate = false,\n onShiftToggle,\n onFocusUp,\n onFocusDown,\n name,\n ariaLabel,\n focusedComponent,\n ...sharedProps\n}: SelectionControlProps) {\n const controlId = useUniqueId();\n const isMultiSelection = selectionType === 'multi';\n\n const setShiftState = (event: KeyboardEvent | MouseEvent) => {\n if (isMultiSelection) {\n onShiftToggle && onShiftToggle(event.shiftKey);\n }\n };\n\n const onMouseDownHandler = (event: MouseEvent) => {\n setShiftState(event);\n if (isMultiSelection) {\n // To overcome an issue\n // If you shift+click or ctrl+click on a label for a checkbox, checkbox is not checked.\n // https://bugzilla.mozilla.org/show_bug.cgi?id=559506\n event.preventDefault();\n }\n };\n\n // native checkboxes do not have focus move via keyboard, we implement it here programmatically\n const handleKeyDown = (event: KeyboardEvent) => {\n setShiftState(event);\n if (isMultiSelection) {\n if (event.keyCode === KeyCode.up) {\n event.preventDefault();\n onFocusUp && onFocusUp(event);\n }\n if (event.keyCode === KeyCode.down) {\n event.preventDefault();\n onFocusDown && onFocusDown(event);\n }\n }\n };\n\n const handleClick = (event: MouseEvent) => {\n const target = event.currentTarget;\n const nativeInput = (target.tagName === 'INPUT' ? target : target.querySelector('input')) as HTMLInputElement;\n // Clicking on input, does not focus it on Firefox (AWSUI-11345)\n nativeInput?.focus();\n };\n\n const selector = isMultiSelection ? (\n <InternalCheckbox\n {...sharedProps}\n showOutline={focusedComponent === 'selection-control'}\n controlId={controlId}\n data-focus-id=\"selection-control\"\n indeterminate={indeterminate}\n />\n ) : (\n <RadioButton {...sharedProps} controlId={controlId} name={name} value={''} label={''} />\n );\n\n return (\n <>\n <label\n onKeyDown={handleKeyDown}\n onKeyUp={setShiftState}\n onMouseDown={onMouseDownHandler}\n onMouseUp={setShiftState}\n onClick={handleClick}\n htmlFor={controlId}\n className={clsx(styles.label, styles.root)}\n aria-label={ariaLabel}\n title={ariaLabel}\n >\n {selector}\n </label>\n {/* HACK: IE11 collapses td's height to 0, if it contains only an absolutely positioned label */}\n <span className={clsx(styles.stud)} aria-hidden={true}>\n \n </span>\n </>\n );\n}\n"]}
|
|
@@ -90,11 +90,11 @@ surrounding text. (WCAG F73) https://www.w3.org/WAI/WCAG21/Techniques/failures/F
|
|
|
90
90
|
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
91
91
|
SPDX-License-Identifier: Apache-2.0
|
|
92
92
|
*/
|
|
93
|
-
.
|
|
93
|
+
.awsui_root_1s55x_bbxfi_93:not(#\9) {
|
|
94
94
|
/* used in test-utils and in the use-selection hook */
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
.
|
|
97
|
+
.awsui_label_1s55x_bbxfi_97:not(#\9) {
|
|
98
98
|
display: flex;
|
|
99
99
|
align-items: center;
|
|
100
100
|
justify-content: center;
|
|
@@ -108,6 +108,6 @@ surrounding text. (WCAG F73) https://www.w3.org/WAI/WCAG21/Techniques/failures/F
|
|
|
108
108
|
border-right: 1px solid transparent;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
.
|
|
111
|
+
.awsui_stud_1s55x_bbxfi_111:not(#\9) {
|
|
112
112
|
visibility: hidden;
|
|
113
113
|
}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// es-module interop with Babel and Typescript
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
module.exports.default = {
|
|
5
|
-
"root": "
|
|
6
|
-
"label": "
|
|
7
|
-
"stud": "
|
|
5
|
+
"root": "awsui_root_1s55x_bbxfi_93",
|
|
6
|
+
"label": "awsui_label_1s55x_bbxfi_97",
|
|
7
|
+
"stud": "awsui_stud_1s55x_bbxfi_111"
|
|
8
8
|
};
|
|
9
9
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { KeyboardEvent } from 'react';
|
|
2
|
+
import { TableProps } from '../interfaces';
|
|
3
|
+
export declare function useSelectionFocusMove(selectionType: TableProps['selectionType'], totalItems: number): {
|
|
4
|
+
moveFocusDown?: undefined;
|
|
5
|
+
moveFocusUp?: undefined;
|
|
6
|
+
moveFocus?: undefined;
|
|
7
|
+
} | {
|
|
8
|
+
moveFocusDown: (event: KeyboardEvent) => void;
|
|
9
|
+
moveFocusUp: (event: KeyboardEvent) => void;
|
|
10
|
+
moveFocus: (sourceElement: HTMLElement, fromIndex: number, direction: -1 | 1) => void;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=use-selection-focus-move.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-selection-focus-move.d.ts","sourceRoot":"lib/default/","sources":["table/selection/use-selection-focus-move.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEtC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAM3C,wBAAgB,qBAAqB,CAAC,aAAa,EAAE,UAAU,CAAC,eAAe,CAAC,EAAE,UAAU,EAAE,MAAM;;;;;2BAkBjF,aAAa;yBAAb,aAAa;+BAdI,WAAW,aAAa,MAAM,aAAa,CAAC,CAAC,GAAG,CAAC;EA0BpF"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { findUpUntil } from '../../internal/utils/dom';
|
|
2
|
+
import selectionStyles from './styles.css.js';
|
|
3
|
+
import { SELECTION_ITEM } from './utils';
|
|
4
|
+
// The hooks moves focus between multi-selection checkboxes.
|
|
5
|
+
// Not eligible for tables with grid navigation.
|
|
6
|
+
export function useSelectionFocusMove(selectionType, totalItems) {
|
|
7
|
+
if (selectionType !== 'multi') {
|
|
8
|
+
return {};
|
|
9
|
+
}
|
|
10
|
+
function moveFocus(sourceElement, fromIndex, direction) {
|
|
11
|
+
let index = fromIndex;
|
|
12
|
+
const rootContainer = findRootContainer(sourceElement);
|
|
13
|
+
while (index >= -1 && index < totalItems) {
|
|
14
|
+
index += direction;
|
|
15
|
+
const control = findSelectionControlByIndex(rootContainer, index);
|
|
16
|
+
if (control && !control.disabled) {
|
|
17
|
+
control.focus();
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const [moveFocusDown, moveFocusUp] = [1, -1].map(direction => {
|
|
23
|
+
return (event) => {
|
|
24
|
+
const target = event.currentTarget;
|
|
25
|
+
const itemNode = findUpUntil(target, node => node.dataset.selectionItem === 'item');
|
|
26
|
+
const fromIndex = Array.prototype.indexOf.call(itemNode.parentElement.children, itemNode);
|
|
27
|
+
moveFocus(target, fromIndex, direction);
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
31
|
+
moveFocusDown,
|
|
32
|
+
moveFocusUp,
|
|
33
|
+
moveFocus,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function findSelectionControlByIndex(rootContainer, index) {
|
|
37
|
+
if (index === -1) {
|
|
38
|
+
// find "select all" checkbox
|
|
39
|
+
return rootContainer.querySelector(`[data-${SELECTION_ITEM}="all"] .${selectionStyles.root} input`);
|
|
40
|
+
}
|
|
41
|
+
return rootContainer.querySelectorAll(`[data-${SELECTION_ITEM}="item"] .${selectionStyles.root} input`)[index];
|
|
42
|
+
}
|
|
43
|
+
function findRootContainer(element) {
|
|
44
|
+
return findUpUntil(element, node => node.dataset.selectionRoot === 'true');
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=use-selection-focus-move.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-selection-focus-move.js","sourceRoot":"lib/default/","sources":["table/selection/use-selection-focus-move.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,eAAe,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,4DAA4D;AAC5D,gDAAgD;AAChD,MAAM,UAAU,qBAAqB,CAAC,aAA0C,EAAE,UAAkB;IAClG,IAAI,aAAa,KAAK,OAAO,EAAE;QAC7B,OAAO,EAAE,CAAC;KACX;IACD,SAAS,SAAS,CAAC,aAA0B,EAAE,SAAiB,EAAE,SAAiB;QACjF,IAAI,KAAK,GAAG,SAAS,CAAC;QACtB,MAAM,aAAa,GAAG,iBAAiB,CAAC,aAAa,CAAC,CAAC;QAEvD,OAAO,KAAK,IAAI,CAAC,CAAC,IAAI,KAAK,GAAG,UAAU,EAAE;YACxC,KAAK,IAAI,SAAS,CAAC;YACnB,MAAM,OAAO,GAAG,2BAA2B,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;YAClE,IAAI,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;gBAChC,OAAO,CAAC,KAAK,EAAE,CAAC;gBAChB,MAAM;aACP;SACF;IACH,CAAC;IACD,MAAM,CAAC,aAAa,EAAE,WAAW,CAAC,GAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAW,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE;QACtE,OAAO,CAAC,KAAoB,EAAE,EAAE;YAC9B,MAAM,MAAM,GAAG,KAAK,CAAC,aAA4B,CAAC;YAClD,MAAM,QAAQ,GAAG,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,KAAK,MAAM,CAAE,CAAC;YACrF,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,aAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;YAC3F,SAAS,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;QAC1C,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,OAAO;QACL,aAAa;QACb,WAAW;QACX,SAAS;KACV,CAAC;AACJ,CAAC;AAED,SAAS,2BAA2B,CAAC,aAA0B,EAAE,KAAa;IAC5E,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE;QAChB,6BAA6B;QAC7B,OAAO,aAAa,CAAC,aAAa,CAChC,SAAS,cAAc,YAAY,eAAe,CAAC,IAAI,QAAQ,CAChE,CAAC;KACH;IACD,OAAO,aAAa,CAAC,gBAAgB,CACnC,SAAS,cAAc,aAAa,eAAe,CAAC,IAAI,QAAQ,CACjE,CAAC,KAAK,CAAC,CAAC;AACX,CAAC;AAED,SAAS,iBAAiB,CAAC,OAAoB;IAC7C,OAAO,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,KAAK,MAAM,CAAE,CAAC;AAC9E,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { KeyboardEvent } from 'react';\nimport { findUpUntil } from '../../internal/utils/dom';\nimport { TableProps } from '../interfaces';\nimport selectionStyles from './styles.css.js';\nimport { SELECTION_ITEM } from './utils';\n\n// The hooks moves focus between multi-selection checkboxes.\n// Not eligible for tables with grid navigation.\nexport function useSelectionFocusMove(selectionType: TableProps['selectionType'], totalItems: number) {\n if (selectionType !== 'multi') {\n return {};\n }\n function moveFocus(sourceElement: HTMLElement, fromIndex: number, direction: -1 | 1) {\n let index = fromIndex;\n const rootContainer = findRootContainer(sourceElement);\n\n while (index >= -1 && index < totalItems) {\n index += direction;\n const control = findSelectionControlByIndex(rootContainer, index);\n if (control && !control.disabled) {\n control.focus();\n break;\n }\n }\n }\n const [moveFocusDown, moveFocusUp] = ([1, -1] as const).map(direction => {\n return (event: KeyboardEvent) => {\n const target = event.currentTarget as HTMLElement;\n const itemNode = findUpUntil(target, node => node.dataset.selectionItem === 'item')!;\n const fromIndex = Array.prototype.indexOf.call(itemNode.parentElement!.children, itemNode);\n moveFocus(target, fromIndex, direction);\n };\n });\n return {\n moveFocusDown,\n moveFocusUp,\n moveFocus,\n };\n}\n\nfunction findSelectionControlByIndex(rootContainer: HTMLElement, index: number) {\n if (index === -1) {\n // find \"select all\" checkbox\n return rootContainer.querySelector<HTMLInputElement>(\n `[data-${SELECTION_ITEM}=\"all\"] .${selectionStyles.root} input`\n );\n }\n return rootContainer.querySelectorAll<HTMLInputElement>(\n `[data-${SELECTION_ITEM}=\"item\"] .${selectionStyles.root} input`\n )[index];\n}\n\nfunction findRootContainer(element: HTMLElement) {\n return findUpUntil(element, node => node.dataset.selectionRoot === 'true')!;\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TableProps } from '../interfaces';
|
|
2
|
+
import { SelectionProps } from './interfaces';
|
|
3
|
+
export declare function useSelection<T>({ items, selectedItems, selectionType, isItemDisabled, trackBy, onSelectionChange, ariaLabels, loading, }: Pick<TableProps<T>, 'ariaLabels' | 'items' | 'selectedItems' | 'selectionType' | 'isItemDisabled' | 'trackBy' | 'onSelectionChange' | 'loading'>): {
|
|
4
|
+
isItemSelected: (item: T) => boolean;
|
|
5
|
+
getSelectAllProps: () => SelectionProps;
|
|
6
|
+
getItemSelectionProps: (item: T) => SelectionProps;
|
|
7
|
+
updateShiftToggle: (value: boolean) => void;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=use-selection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-selection.d.ts","sourceRoot":"lib/default/","sources":["table/selection/use-selection.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAG9C,wBAAgB,YAAY,CAAC,CAAC,EAAE,EAC9B,KAAK,EACL,aAAkB,EAClB,aAAa,EACb,cAA4B,EAC5B,OAAO,EACP,iBAAiB,EACjB,UAAU,EACV,OAAO,GACR,EAAE,IAAI,CACL,UAAU,CAAC,CAAC,CAAC,EACX,YAAY,GACZ,OAAO,GACP,eAAe,GACf,eAAe,GACf,gBAAgB,GAChB,SAAS,GACT,mBAAmB,GACnB,SAAS,CACZ;;6BA8F0B,cAAc;kCAiBP,CAAC,KAAG,cAAc;+BAgBrB,OAAO;EAIrC"}
|
|
@@ -1,70 +1,11 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { useState } from 'react';
|
|
4
|
-
import { fireNonCancelableEvent } from '
|
|
5
|
-
import { useUniqueId } from '
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
import { joinStrings } from '../internal/utils/strings';
|
|
10
|
-
const SELECTION_ITEM = 'selection-item';
|
|
11
|
-
const SELECTION_ROOT = 'selection-root';
|
|
12
|
-
function findSelectionControlByIndex(rootContainer, index) {
|
|
13
|
-
if (index === -1) {
|
|
14
|
-
// find "select all" checkbox
|
|
15
|
-
return rootContainer.querySelector(`[data-${SELECTION_ITEM}="all"] .${selectionStyles.root} input`);
|
|
16
|
-
}
|
|
17
|
-
return rootContainer.querySelectorAll(`[data-${SELECTION_ITEM}="item"] .${selectionStyles.root} input`)[index];
|
|
18
|
-
}
|
|
19
|
-
function findRootContainer(element) {
|
|
20
|
-
return findUpUntil(element, node => node.dataset.selectionRoot === 'true');
|
|
21
|
-
}
|
|
22
|
-
export function useFocusMove(selectionType, totalItems) {
|
|
23
|
-
if (selectionType !== 'multi') {
|
|
24
|
-
return {};
|
|
25
|
-
}
|
|
26
|
-
function moveFocus(sourceElement, fromIndex, direction) {
|
|
27
|
-
let index = fromIndex;
|
|
28
|
-
const rootContainer = findRootContainer(sourceElement);
|
|
29
|
-
while (index >= -1 && index < totalItems) {
|
|
30
|
-
index += direction;
|
|
31
|
-
const control = findSelectionControlByIndex(rootContainer, index);
|
|
32
|
-
if (control && !control.disabled) {
|
|
33
|
-
control.focus();
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
const [moveFocusDown, moveFocusUp] = [1, -1].map(direction => {
|
|
39
|
-
return (event) => {
|
|
40
|
-
const target = event.currentTarget;
|
|
41
|
-
const itemNode = findUpUntil(target, node => node.dataset.selectionItem === 'item');
|
|
42
|
-
const fromIndex = Array.prototype.indexOf.call(itemNode.parentElement.children, itemNode);
|
|
43
|
-
moveFocus(target, fromIndex, direction);
|
|
44
|
-
};
|
|
45
|
-
});
|
|
46
|
-
return {
|
|
47
|
-
moveFocusDown,
|
|
48
|
-
moveFocusUp,
|
|
49
|
-
moveFocus,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
// A set, that compares items by their "trackables" (the results of applying `trackBy` to them)
|
|
53
|
-
class ItemSet {
|
|
54
|
-
constructor(trackBy, items) {
|
|
55
|
-
this.map = new Map();
|
|
56
|
-
this.put = (item) => this.map.set.call(this.map, getTrackableValue(this.trackBy, item), item);
|
|
57
|
-
this.has = (item) => this.map.has.call(this.map, getTrackableValue(this.trackBy, item));
|
|
58
|
-
this.forEach = this.map.forEach.bind(this.map);
|
|
59
|
-
this.trackBy = trackBy;
|
|
60
|
-
items.forEach(this.put);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
export const focusMarkers = {
|
|
64
|
-
item: { ['data-' + SELECTION_ITEM]: 'item' },
|
|
65
|
-
all: { ['data-' + SELECTION_ITEM]: 'all' },
|
|
66
|
-
root: { ['data-' + SELECTION_ROOT]: 'true' },
|
|
67
|
-
};
|
|
4
|
+
import { fireNonCancelableEvent } from '../../internal/events';
|
|
5
|
+
import { useUniqueId } from '../../internal/hooks/use-unique-id';
|
|
6
|
+
import { getTrackableValue } from '../utils';
|
|
7
|
+
import { joinStrings } from '../../internal/utils/strings';
|
|
8
|
+
import { ItemSet } from './utils';
|
|
68
9
|
export function useSelection({ items, selectedItems = [], selectionType, isItemDisabled = () => false, trackBy, onSelectionChange, ariaLabels, loading, }) {
|
|
69
10
|
const [shiftPressed, setShiftPressed] = useState(false);
|
|
70
11
|
const [lastClickedItem, setLastClickedItem] = useState(null);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-selection.js","sourceRoot":"lib/default/","sources":["table/selection/use-selection.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAEjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAE3D,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,MAAM,UAAU,YAAY,CAAI,EAC9B,KAAK,EACL,aAAa,GAAG,EAAE,EAClB,aAAa,EACb,cAAc,GAAG,GAAG,EAAE,CAAC,KAAK,EAC5B,OAAO,EACP,iBAAiB,EACjB,UAAU,EACV,OAAO,GAWR;IACC,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IACxD,MA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AAV,UAAU,uBAAV,UAAU,CAAE,mBAAmB,EAC/B,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,kBAAkB,2DAAG,EAAE,aAAa,EAAE,EAAE,IAAI,CAAC,CAC1D;gBACD,QAAQ,EAAE,gBAAgB,CAAC,IAAI,CAAC;gBAChC,OAAO,EAAE,cAAc,CAAC,IAAI,CAAC;gBAC7B,QAAQ,EAAE,cAAc,CAAC,IAAI,CAAC;aAC/B,CAAC;QACJ,CAAC;QACD,iBAAiB,EAAE,CAAC,KAAc,EAAE,EAAE;YACpC,eAAe,CAAC,KAAK,CAAC,CAAC;QACzB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { useState } from 'react';\nimport { fireNonCancelableEvent } from '../../internal/events';\nimport { useUniqueId } from '../../internal/hooks/use-unique-id';\nimport { TableProps } from '../interfaces';\nimport { getTrackableValue } from '../utils';\nimport { joinStrings } from '../../internal/utils/strings';\nimport { SelectionProps } from './interfaces';\nimport { ItemSet } from './utils';\n\nexport function useSelection<T>({\n items,\n selectedItems = [],\n selectionType,\n isItemDisabled = () => false,\n trackBy,\n onSelectionChange,\n ariaLabels,\n loading,\n}: Pick<\n TableProps<T>,\n | 'ariaLabels'\n | 'items'\n | 'selectedItems'\n | 'selectionType'\n | 'isItemDisabled'\n | 'trackBy'\n | 'onSelectionChange'\n | 'loading'\n>) {\n const [shiftPressed, setShiftPressed] = useState(false);\n const [lastClickedItem, setLastClickedItem] = useState<T | null>(null);\n const selectionName = useUniqueId();\n const finalSelectedItems = selectionType === 'single' ? selectedItems.slice(0, 1) : selectedItems;\n const selectedSet = new ItemSet(trackBy, finalSelectedItems);\n const itemIndexesMap = new Map();\n items.forEach((item, i) => itemIndexesMap.set(getTrackableValue(trackBy, item), i));\n const isItemSelected = selectedSet.has.bind(selectedSet);\n const getItemState = (item: T) => ({\n disabled: isItemDisabled(item),\n selected: isItemSelected(item),\n });\n const [allDisabled, allEnabledSelected] = selectionType\n ? items.reduce(\n ([allDisabled, allEnabledSelected], item) => {\n const { disabled, selected } = getItemState(item);\n return [\n // all items are disabled (or none are present)\n allDisabled && disabled,\n // all enabled items are selected (or none are present)\n allEnabledSelected && (selected || disabled),\n ];\n },\n [true, true]\n )\n : [true, true];\n\n // the page has at least one selected item\n const hasSelected = finalSelectedItems.length > 0;\n\n const handleToggleAll = () => {\n const requestedItems = new ItemSet(trackBy, items);\n const newSelectedItems = allEnabledSelected ? deselectItems(requestedItems) : selectItems(requestedItems);\n fireNonCancelableEvent(onSelectionChange, { selectedItems: newSelectedItems });\n };\n\n const getRequestedItems = (item: T) => {\n const requestedItems = new ItemSet(trackBy, [item]);\n let lastClickedItemIndex = lastClickedItem ? itemIndexesMap.get(getTrackableValue(trackBy, lastClickedItem)) : -1;\n if (lastClickedItemIndex === undefined) {\n lastClickedItemIndex = -1;\n }\n // we use lastClickedItemIndex to determine if filtering/sorting/pagination\n // made previously selected item invisible, therefore we reset state for shift-select\n if (shiftPressed && lastClickedItemIndex !== -1) {\n // item is always in items\n const currentItemIndex = itemIndexesMap.get(getTrackableValue(trackBy, item)) as number;\n const start = Math.min(currentItemIndex, lastClickedItemIndex);\n const end = Math.max(currentItemIndex, lastClickedItemIndex);\n items.slice(start, end + 1).forEach(item => requestedItems.put(item));\n }\n return requestedItems;\n };\n\n const deselectItems = (requestedItems: ItemSet<T>) => {\n const newSelectedItems: Array<T> = [];\n selectedItems.forEach(selectedItem => {\n const toUnselect = requestedItems.has(selectedItem);\n if (!toUnselect || isItemDisabled(selectedItem)) {\n newSelectedItems.push(selectedItem);\n }\n });\n return newSelectedItems;\n };\n\n const selectItems = (requestedItems: ItemSet<T>) => {\n const newSelectedItems = [...selectedItems];\n requestedItems.forEach(newItem => {\n const { selected, disabled } = getItemState(newItem);\n if (!selected && !disabled) {\n newSelectedItems.push(newItem);\n }\n });\n return newSelectedItems;\n };\n\n const handleToggleItem = (item: T) => () => {\n const { disabled, selected } = getItemState(item);\n if (disabled || (selectionType === 'single' && selected)) {\n return;\n }\n if (selectionType === 'single') {\n fireNonCancelableEvent(onSelectionChange, { selectedItems: [item] });\n } else {\n const requestedItems = getRequestedItems(item);\n const selectedItems = selected ? deselectItems(requestedItems) : selectItems(requestedItems);\n fireNonCancelableEvent(onSelectionChange, { selectedItems });\n setLastClickedItem(item);\n }\n };\n\n return {\n isItemSelected,\n getSelectAllProps: (): SelectionProps => {\n if (!selectionType) {\n throw new Error('Invariant violation: calling selection props with missing selection type.');\n }\n return {\n name: selectionName,\n disabled: allDisabled || !!loading,\n selectionType: selectionType,\n indeterminate: hasSelected && !allEnabledSelected,\n checked: hasSelected && allEnabledSelected,\n onChange: handleToggleAll,\n ariaLabel: joinStrings(\n ariaLabels?.selectionGroupLabel,\n ariaLabels?.allItemsSelectionLabel?.({ selectedItems })\n ),\n };\n },\n getItemSelectionProps: (item: T): SelectionProps => {\n if (!selectionType) {\n throw new Error('Invariant violation: calling selection props with missing selection type.');\n }\n return {\n name: selectionName,\n selectionType: selectionType,\n ariaLabel: joinStrings(\n ariaLabels?.selectionGroupLabel,\n ariaLabels?.itemSelectionLabel?.({ selectedItems }, item)\n ),\n onChange: handleToggleItem(item),\n checked: isItemSelected(item),\n disabled: isItemDisabled(item),\n };\n },\n updateShiftToggle: (value: boolean) => {\n setShiftPressed(value);\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { TableProps } from '../interfaces';
|
|
2
|
+
export declare const SELECTION_ITEM = "selection-item";
|
|
3
|
+
export declare const SELECTION_ROOT = "selection-root";
|
|
4
|
+
export declare class ItemSet<T> {
|
|
5
|
+
constructor(trackBy: TableProps.TrackBy<T> | undefined, items: ReadonlyArray<T>);
|
|
6
|
+
private trackBy;
|
|
7
|
+
private map;
|
|
8
|
+
put: (item: T) => Map<unknown, T>;
|
|
9
|
+
has: (item: T) => boolean;
|
|
10
|
+
forEach: (callbackfn: (value: T, key: unknown, map: Map<unknown, T>) => void, thisArg?: any) => void;
|
|
11
|
+
}
|
|
12
|
+
export declare const focusMarkers: {
|
|
13
|
+
item: {
|
|
14
|
+
[x: string]: string;
|
|
15
|
+
};
|
|
16
|
+
all: {
|
|
17
|
+
[x: string]: string;
|
|
18
|
+
};
|
|
19
|
+
root: {
|
|
20
|
+
[x: string]: string;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"lib/default/","sources":["table/selection/utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,eAAO,MAAM,cAAc,mBAAmB,CAAC;AAC/C,eAAO,MAAM,cAAc,mBAAmB,CAAC;AAG/C,qBAAa,OAAO,CAAC,CAAC;gBACR,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,SAAS,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC;IAI/E,OAAO,CAAC,OAAO,CAAoC;IACnD,OAAO,CAAC,GAAG,CAA8B;IACzC,GAAG,SAAU,CAAC,qBAA8E;IAC5F,GAAG,SAAU,CAAC,aAAwE;IACtF,OAAO,8FAAmC;CAC3C;AAED,eAAO,MAAM,YAAY;;;;;;;;;;CAIxB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { getTrackableValue } from '../utils';
|
|
4
|
+
export const SELECTION_ITEM = 'selection-item';
|
|
5
|
+
export const SELECTION_ROOT = 'selection-root';
|
|
6
|
+
// A set, that compares items by their "trackables" (the results of applying `trackBy` to them)
|
|
7
|
+
export class ItemSet {
|
|
8
|
+
constructor(trackBy, items) {
|
|
9
|
+
this.map = new Map();
|
|
10
|
+
this.put = (item) => this.map.set.call(this.map, getTrackableValue(this.trackBy, item), item);
|
|
11
|
+
this.has = (item) => this.map.has.call(this.map, getTrackableValue(this.trackBy, item));
|
|
12
|
+
this.forEach = this.map.forEach.bind(this.map);
|
|
13
|
+
this.trackBy = trackBy;
|
|
14
|
+
items.forEach(this.put);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export const focusMarkers = {
|
|
18
|
+
item: { ['data-' + SELECTION_ITEM]: 'item' },
|
|
19
|
+
all: { ['data-' + SELECTION_ITEM]: 'all' },
|
|
20
|
+
root: { ['data-' + SELECTION_ROOT]: 'true' },
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"lib/default/","sources":["table/selection/utils.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAGtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,MAAM,CAAC,MAAM,cAAc,GAAG,gBAAgB,CAAC;AAC/C,MAAM,CAAC,MAAM,cAAc,GAAG,gBAAgB,CAAC;AAE/C,+FAA+F;AAC/F,MAAM,OAAO,OAAO;IAClB,YAAY,OAA0C,EAAE,KAAuB;QAKvE,QAAG,GAAoB,IAAI,GAAG,EAAE,CAAC;QACzC,QAAG,GAAG,CAAC,IAAO,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,iBAAiB,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;QAC5F,QAAG,GAAG,CAAC,IAAO,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,iBAAiB,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;QACtF,YAAO,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAPxC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;CAMF;AAED,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,EAAE,CAAC,OAAO,GAAG,cAAc,CAAC,EAAE,MAAM,EAAE;IAC5C,GAAG,EAAE,EAAE,CAAC,OAAO,GAAG,cAAc,CAAC,EAAE,KAAK,EAAE;IAC1C,IAAI,EAAE,EAAE,CAAC,OAAO,GAAG,cAAc,CAAC,EAAE,MAAM,EAAE;CAC7C,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { TableProps } from '../interfaces';\nimport { getTrackableValue } from '../utils';\n\nexport const SELECTION_ITEM = 'selection-item';\nexport const SELECTION_ROOT = 'selection-root';\n\n// A set, that compares items by their \"trackables\" (the results of applying `trackBy` to them)\nexport class ItemSet<T> {\n constructor(trackBy: TableProps.TrackBy<T> | undefined, items: ReadonlyArray<T>) {\n this.trackBy = trackBy;\n items.forEach(this.put);\n }\n private trackBy: TableProps.TrackBy<T> | undefined;\n private map: Map<unknown, T> = new Map();\n put = (item: T) => this.map.set.call(this.map, getTrackableValue(this.trackBy, item), item);\n has = (item: T) => this.map.has.call(this.map, getTrackableValue(this.trackBy, item));\n forEach = this.map.forEach.bind(this.map);\n}\n\nexport const focusMarkers = {\n item: { ['data-' + SELECTION_ITEM]: 'item' },\n all: { ['data-' + SELECTION_ITEM]: 'all' },\n root: { ['data-' + SELECTION_ROOT]: 'true' },\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"lib/default/","sources":["table/table-role/interfaces.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nexport type TableRole = 'table' | 'grid' | 'grid-default';\n\nexport interface GridNavigationProps {\n tableRole: TableRole;\n pageSize: number;\n getTable: () => null | HTMLTableElement;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface GridNavigationAPI {}\n\nexport interface FocusedCell {\n rowIndex: number;\n colIndex: number;\n elementIndex: number;\n rowElement: HTMLTableRowElement;\n cellElement: HTMLTableCellElement;\n element: HTMLElement;\n
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"lib/default/","sources":["table/table-role/interfaces.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nexport type TableRole = 'table' | 'grid' | 'grid-default';\n\nexport interface GridNavigationProps {\n tableRole: TableRole;\n pageSize: number;\n getTable: () => null | HTMLTableElement;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface GridNavigationAPI {}\n\nexport interface FocusedCell {\n rowIndex: number;\n colIndex: number;\n elementIndex: number;\n rowElement: HTMLTableRowElement;\n cellElement: HTMLTableCellElement;\n element: HTMLElement;\n dialog: boolean;\n}\n"]}
|
|
@@ -25,17 +25,11 @@ export declare function getTableColHeaderRoleProps(options: {
|
|
|
25
25
|
tableRole: TableRole;
|
|
26
26
|
colIndex: number;
|
|
27
27
|
sortingStatus?: SortingStatus;
|
|
28
|
-
|
|
29
|
-
}): import("react").ThHTMLAttributes<HTMLTableCellElement> & {
|
|
30
|
-
'data-widget-cell'?: boolean | undefined;
|
|
31
|
-
};
|
|
28
|
+
}): import("react").ThHTMLAttributes<HTMLTableCellElement>;
|
|
32
29
|
export declare function getTableCellRoleProps(options: {
|
|
33
30
|
tableRole: TableRole;
|
|
34
31
|
colIndex: number;
|
|
35
32
|
isRowHeader?: boolean;
|
|
36
|
-
|
|
37
|
-
}): import("react").TdHTMLAttributes<HTMLTableCellElement> & {
|
|
38
|
-
'data-widget-cell'?: boolean | undefined;
|
|
39
|
-
};
|
|
33
|
+
}): import("react").TdHTMLAttributes<HTMLTableCellElement>;
|
|
40
34
|
export {};
|
|
41
35
|
//# sourceMappingURL=table-role-helper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table-role-helper.d.ts","sourceRoot":"lib/default/","sources":["table/table-role/table-role-helper.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,KAAK,aAAa,GAAG,UAAU,GAAG,WAAW,GAAG,YAAY,CAAC;AAa7D,wBAAgB,iBAAiB,CAAC,OAAO,EAAE;IACzC,SAAS,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,GAAG,KAAK,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,CAuB9C;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE;IAAE,SAAS,EAAE,SAAS,CAAC;IAAC,YAAY,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,kDAWpH;AAED,wBAAgB,0BAA0B,CAAC,OAAO,EAAE;IAAE,SAAS,EAAE,SAAS,CAAA;CAAE,uDAS3E;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE;IAAE,SAAS,EAAE,SAAS,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,uDAa5G;AAED,wBAAgB,0BAA0B,CAAC,OAAO,EAAE;IAClD,SAAS,EAAE,SAAS,CAAC;IACrB,QAAQ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
|
|
@@ -66,9 +66,6 @@ export function getTableColHeaderRoleProps(options) {
|
|
|
66
66
|
if (options.sortingStatus) {
|
|
67
67
|
nativeProps['aria-sort'] = getAriaSort(options.sortingStatus);
|
|
68
68
|
}
|
|
69
|
-
if (options.tableRole === 'grid' && options.isWidget) {
|
|
70
|
-
nativeProps['data-widget-cell'] = true;
|
|
71
|
-
}
|
|
72
69
|
return nativeProps;
|
|
73
70
|
}
|
|
74
71
|
export function getTableCellRoleProps(options) {
|
|
@@ -79,9 +76,6 @@ export function getTableCellRoleProps(options) {
|
|
|
79
76
|
if (options.isRowHeader) {
|
|
80
77
|
nativeProps.scope = 'row';
|
|
81
78
|
}
|
|
82
|
-
if (options.tableRole === 'grid' && options.isWidget) {
|
|
83
|
-
nativeProps['data-widget-cell'] = true;
|
|
84
|
-
}
|
|
85
79
|
return nativeProps;
|
|
86
80
|
}
|
|
87
81
|
//# sourceMappingURL=table-role-helper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table-role-helper.js","sourceRoot":"lib/default/","sources":["table/table-role/table-role-helper.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAMtC,MAAM,eAAe,GAAG;IACtB,QAAQ,EAAE,MAAM;IAChB,SAAS,EAAE,WAAW;IACtB,UAAU,EAAE,YAAY;CAChB,CAAC;AACX,MAAM,WAAW,GAAG,CAAC,YAA2B,EAAE,EAAE,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;AAEnF,mGAAmG;AACnG,8GAA8G;AAC9G,uFAAuF;AAEvF,MAAM,UAAU,iBAAiB,CAAC,OAMjC;IACC,MAAM,WAAW,GAAgD,EAAE,CAAC;IAEpE,sFAAsF;IACtF,qFAAqF;IACrF,WAAW,CAAC,IAAI,GAAG,OAAO,CAAC,SAAS,KAAK,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC;IAErF,WAAW,CAAC,YAAY,CAAC,GA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CAAC,UAAU,KAAK,SAAS,EAAE;QACzC,WAAW,CAAC,eAAe,CAAC,GAAG,OAAO,CAAC,UAAU,GAAG,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;KAC1E;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,OAI1C;IACC,MAAM,WAAW,GAAiD,EAAE,CAAC;IAErE,WAAW,CAAC,KAAK,GAAG,KAAK,CAAC;IAE1B,IAAI,OAAO,CAAC,SAAS,KAAK,MAAM,EAAE;QAChC,WAAW,CAAC,eAAe,CAAC,GAAG,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;KACrD;IAED,IAAI,OAAO,CAAC,aAAa,EAAE;QACzB,WAAW,CAAC,WAAW,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;KAC/D;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,OAA0E;IAC9G,MAAM,WAAW,GAAiD,EAAE,CAAC;IAErE,IAAI,OAAO,CAAC,SAAS,KAAK,MAAM,EAAE;QAChC,WAAW,CAAC,eAAe,CAAC,GAAG,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;KACrD;IAED,IAAI,OAAO,CAAC,WAAW,EAAE;QACvB,WAAW,CAAC,KAAK,GAAG,KAAK,CAAC;KAC3B;IAED,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { TableRole } from './interfaces';\n\ntype SortingStatus = 'sortable' | 'ascending' | 'descending';\n\nconst stateToAriaSort = {\n sortable: 'none',\n ascending: 'ascending',\n descending: 'descending',\n} as const;\nconst getAriaSort = (sortingState: SortingStatus) => stateToAriaSort[sortingState];\n\n// Depending on its content the table can have different semantic representation which includes the\n// ARIA role of the table component (\"table\", \"grid\", \"treegrid\") but also roles and other semantic attributes\n// of the child elements. The TableRole helper encapsulates table's semantic structure.\n\nexport function getTableRoleProps(options: {\n tableRole: TableRole;\n ariaLabel?: string;\n ariaLabelledBy?: string;\n totalItemsCount?: number;\n totalColumnsCount?: number;\n}): React.TableHTMLAttributes<HTMLTableElement> {\n const nativeProps: React.TableHTMLAttributes<HTMLTableElement> = {};\n\n // Browsers have weird mechanism to guess whether it's a data table or a layout table.\n // If we state explicitly, they get it always correctly even with low number of rows.\n nativeProps.role = options.tableRole === 'grid-default' ? 'grid' : options.tableRole;\n\n nativeProps['aria-label'] = options.ariaLabel;\n nativeProps['aria-labelledby'] = options.ariaLabelledBy;\n\n // Incrementing the total count by one to account for the header row.\n nativeProps['aria-rowcount'] = options.totalItemsCount ? options.totalItemsCount + 1 : -1;\n\n if (options.tableRole === 'grid') {\n nativeProps['aria-colcount'] = options.totalColumnsCount;\n }\n\n // Make table component programmatically focusable to attach focusin/focusout for keyboard navigation.\n if (options.tableRole === 'grid') {\n nativeProps.tabIndex = -1;\n }\n\n return nativeProps;\n}\n\nexport function getTableWrapperRoleProps(options: { tableRole: TableRole; isScrollable: boolean; ariaLabel?: string }) {\n const nativeProps: React.HTMLAttributes<HTMLDivElement> = {};\n\n // When the table is scrollable, the wrapper is made focusable so that keyboard users can scroll it horizontally with arrow keys.\n if (options.isScrollable && options.tableRole !== 'grid') {\n nativeProps.role = 'region';\n nativeProps.tabIndex = 0;\n nativeProps['aria-label'] = options.ariaLabel;\n }\n\n return nativeProps;\n}\n\nexport function getTableHeaderRowRoleProps(options: { tableRole: TableRole }) {\n const nativeProps: React.HTMLAttributes<HTMLTableRowElement> = {};\n\n // For grids headers are treated similar to data rows and are indexed accordingly.\n if (options.tableRole === 'grid' || options.tableRole === 'grid-default') {\n nativeProps['aria-rowindex'] = 1;\n }\n\n return nativeProps;\n}\n\nexport function getTableRowRoleProps(options: { tableRole: TableRole; rowIndex: number; firstIndex?: number }) {\n const nativeProps: React.HTMLAttributes<HTMLTableRowElement> = {};\n\n // The data cell indices are incremented by 1 to account for the header cells.\n if (options.tableRole === 'grid') {\n nativeProps['aria-rowindex'] = (options.firstIndex || 1) + options.rowIndex + 1;\n }\n // For tables indices are only added when the first index is not 0 (not the first page/frame).\n else if (options.firstIndex !== undefined) {\n nativeProps['aria-rowindex'] = options.firstIndex + options.rowIndex + 1;\n }\n\n return nativeProps;\n}\n\nexport function getTableColHeaderRoleProps(options: {\n tableRole: TableRole;\n colIndex: number;\n sortingStatus?: SortingStatus;\n}) {\n const nativeProps: React.ThHTMLAttributes<HTMLTableCellElement> = {};\n\n nativeProps.scope = 'col';\n\n if (options.tableRole === 'grid') {\n nativeProps['aria-colindex'] = options.colIndex + 1;\n }\n\n if (options.sortingStatus) {\n nativeProps['aria-sort'] = getAriaSort(options.sortingStatus);\n }\n\n return nativeProps;\n}\n\nexport function getTableCellRoleProps(options: { tableRole: TableRole; colIndex: number; isRowHeader?: boolean }) {\n const nativeProps: React.TdHTMLAttributes<HTMLTableCellElement> = {};\n\n if (options.tableRole === 'grid') {\n nativeProps['aria-colindex'] = options.colIndex + 1;\n }\n\n if (options.isRowHeader) {\n nativeProps.scope = 'row';\n }\n\n return nativeProps;\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { useEffect, useMemo } from 'react';
|
|
4
|
-
import { findFocusinCell, moveFocusBy,
|
|
4
|
+
import { findFocusinCell, moveFocusBy, restoreTableFocusables, updateTableFocusables } from './utils';
|
|
5
5
|
import { KeyCode } from '../../internal/keycode';
|
|
6
6
|
import { nodeContains } from '@cloudscape-design/component-toolkit/dom';
|
|
7
7
|
/**
|
|
@@ -41,6 +41,10 @@ class GridNavigationModel {
|
|
|
41
41
|
if (!cell) {
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
|
+
if (cell.element !== event.target) {
|
|
45
|
+
cell.element.focus();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
44
48
|
this.prevFocusedCell = cell;
|
|
45
49
|
this.focusedCell = cell;
|
|
46
50
|
updateTableFocusables(this.table, cell);
|
|
@@ -52,7 +56,6 @@ class GridNavigationModel {
|
|
|
52
56
|
if (!this.focusedCell) {
|
|
53
57
|
return;
|
|
54
58
|
}
|
|
55
|
-
const f2Code = 113;
|
|
56
59
|
const ctrlKey = event.ctrlKey ? 1 : 0;
|
|
57
60
|
const altKey = event.altKey ? 1 : 0;
|
|
58
61
|
const shiftKey = event.shiftKey ? 1 : 0;
|
|
@@ -68,12 +71,8 @@ class GridNavigationModel {
|
|
|
68
71
|
const from = this.focusedCell;
|
|
69
72
|
const minExtreme = Number.NEGATIVE_INFINITY;
|
|
70
73
|
const maxExtreme = Number.POSITIVE_INFINITY;
|
|
71
|
-
// When focus is inside
|
|
72
|
-
if (from.
|
|
73
|
-
if (key === KeyCode.escape || key === f2Code) {
|
|
74
|
-
event.preventDefault();
|
|
75
|
-
return moveFocusBy(this.table, from, { y: 0, x: 0 });
|
|
76
|
-
}
|
|
74
|
+
// When focus is inside a dialog do not intercept any keyboard input.
|
|
75
|
+
if (from.dialog) {
|
|
77
76
|
return;
|
|
78
77
|
}
|
|
79
78
|
switch (key) {
|
|
@@ -107,31 +106,11 @@ class GridNavigationModel {
|
|
|
107
106
|
case -KeyCode.end:
|
|
108
107
|
event.preventDefault();
|
|
109
108
|
return moveFocusBy(this.table, from, { y: maxExtreme, x: maxExtreme });
|
|
110
|
-
case KeyCode.enter:
|
|
111
|
-
if (from.element === from.cellElement) {
|
|
112
|
-
event.preventDefault();
|
|
113
|
-
return moveFocusIn(from);
|
|
114
|
-
}
|
|
115
|
-
break;
|
|
116
|
-
case KeyCode.escape:
|
|
117
|
-
if (from.element !== from.cellElement) {
|
|
118
|
-
event.preventDefault();
|
|
119
|
-
return moveFocusBy(this.table, from, { y: 0, x: 0 });
|
|
120
|
-
}
|
|
121
|
-
break;
|
|
122
|
-
case f2Code:
|
|
123
|
-
event.preventDefault();
|
|
124
|
-
if (from.element === from.cellElement) {
|
|
125
|
-
return moveFocusIn(from);
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
return moveFocusBy(this.table, from, { y: 0, x: 0 });
|
|
129
|
-
}
|
|
130
109
|
default:
|
|
131
110
|
return;
|
|
132
111
|
}
|
|
133
112
|
};
|
|
134
|
-
this.
|
|
113
|
+
this.onTableNodeMutation = (mutationRecords) => {
|
|
135
114
|
var _a;
|
|
136
115
|
if (!this.prevFocusedCell) {
|
|
137
116
|
return;
|
|
@@ -141,12 +120,12 @@ class GridNavigationModel {
|
|
|
141
120
|
if (record.type === 'childList') {
|
|
142
121
|
for (const removedNode of Array.from(record.removedNodes)) {
|
|
143
122
|
if (removedNode === this.prevFocusedCell.element || nodeContains(removedNode, this.prevFocusedCell.element)) {
|
|
123
|
+
updateTableFocusables(this.table, (_a = this.focusedCell) !== null && _a !== void 0 ? _a : this.prevFocusedCell);
|
|
144
124
|
moveFocusBy(this.table, this.prevFocusedCell, { y: 0, x: 0 });
|
|
145
125
|
}
|
|
146
126
|
}
|
|
147
127
|
}
|
|
148
128
|
}
|
|
149
|
-
updateTableFocusables(this.table, (_a = this.focusedCell) !== null && _a !== void 0 ? _a : this.prevFocusedCell);
|
|
150
129
|
};
|
|
151
130
|
}
|
|
152
131
|
init(table) {
|
|
@@ -155,14 +134,14 @@ class GridNavigationModel {
|
|
|
155
134
|
this.table.addEventListener('focusin', this.onFocusin);
|
|
156
135
|
this.table.addEventListener('focusout', this.onFocusout);
|
|
157
136
|
this.table.addEventListener('keydown', this.onKeydown);
|
|
158
|
-
const
|
|
159
|
-
|
|
137
|
+
const tableNodesObserver = new MutationObserver(this.onTableNodeMutation);
|
|
138
|
+
tableNodesObserver.observe(table, { childList: true, subtree: true });
|
|
160
139
|
updateTableFocusables(this.table, (_a = this.focusedCell) !== null && _a !== void 0 ? _a : this.prevFocusedCell);
|
|
161
140
|
this.cleanup = () => {
|
|
162
141
|
this.table.removeEventListener('focusin', this.onFocusin);
|
|
163
142
|
this.table.removeEventListener('focusout', this.onFocusout);
|
|
164
143
|
this.table.removeEventListener('keydown', this.onKeydown);
|
|
165
|
-
|
|
144
|
+
tableNodesObserver.disconnect();
|
|
166
145
|
restoreTableFocusables(this.table);
|
|
167
146
|
};
|
|
168
147
|
}
|