@cloudscape-design/components 3.0.630 → 3.0.632

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 (111) hide show
  1. package/autosuggest/internal.d.ts.map +1 -1
  2. package/autosuggest/internal.js +10 -0
  3. package/autosuggest/internal.js.map +1 -1
  4. package/breadcrumb-group/implementation.d.ts +8 -0
  5. package/breadcrumb-group/implementation.d.ts.map +1 -0
  6. package/breadcrumb-group/implementation.js +71 -0
  7. package/breadcrumb-group/implementation.js.map +1 -0
  8. package/breadcrumb-group/index.js +1 -1
  9. package/breadcrumb-group/index.js.map +1 -1
  10. package/breadcrumb-group/internal.d.ts +1 -11
  11. package/breadcrumb-group/internal.d.ts.map +1 -1
  12. package/breadcrumb-group/internal.js +2 -70
  13. package/breadcrumb-group/internal.js.map +1 -1
  14. package/breadcrumb-group/item/item.js +1 -1
  15. package/breadcrumb-group/item/item.js.map +1 -1
  16. package/breadcrumb-group/utils.d.ts +7 -0
  17. package/breadcrumb-group/utils.d.ts.map +1 -0
  18. package/breadcrumb-group/utils.js +6 -0
  19. package/breadcrumb-group/utils.js.map +1 -0
  20. package/drawer/implementation.d.ts +7 -0
  21. package/drawer/implementation.d.ts.map +1 -0
  22. package/drawer/implementation.js +24 -0
  23. package/drawer/implementation.js.map +1 -0
  24. package/drawer/index.d.ts +1 -1
  25. package/drawer/index.d.ts.map +1 -1
  26. package/drawer/index.js +4 -18
  27. package/drawer/index.js.map +1 -1
  28. package/drawer/internal.d.ts +2 -0
  29. package/drawer/internal.d.ts.map +1 -0
  30. package/drawer/internal.js +5 -0
  31. package/drawer/internal.js.map +1 -0
  32. package/form-field/styles.css.js +23 -23
  33. package/form-field/styles.scoped.css +38 -37
  34. package/form-field/styles.selectors.js +23 -23
  35. package/help-panel/implementation.d.ts +7 -0
  36. package/help-panel/implementation.d.ts.map +1 -0
  37. package/help-panel/implementation.js +27 -0
  38. package/help-panel/implementation.js.map +1 -0
  39. package/help-panel/index.d.ts +1 -1
  40. package/help-panel/index.d.ts.map +1 -1
  41. package/help-panel/index.js +4 -21
  42. package/help-panel/index.js.map +1 -1
  43. package/help-panel/internal.d.ts +2 -0
  44. package/help-panel/internal.d.ts.map +1 -0
  45. package/help-panel/internal.js +5 -0
  46. package/help-panel/internal.js.map +1 -0
  47. package/internal/base-component/styles.scoped.css +5 -0
  48. package/internal/components/options-list/utils/use-keyboard.d.ts +2 -1
  49. package/internal/components/options-list/utils/use-keyboard.d.ts.map +1 -1
  50. package/internal/components/options-list/utils/use-keyboard.js +4 -4
  51. package/internal/components/options-list/utils/use-keyboard.js.map +1 -1
  52. package/internal/environment.js +1 -1
  53. package/internal/environment.json +1 -1
  54. package/internal/generated/styles/tokens.d.ts +1 -0
  55. package/internal/generated/styles/tokens.js +1 -0
  56. package/internal/generated/theming/index.cjs +31 -0
  57. package/internal/generated/theming/index.js +31 -0
  58. package/internal/manifest.json +1 -1
  59. package/internal/widgets/index.d.ts +4 -0
  60. package/internal/widgets/index.d.ts.map +1 -0
  61. package/internal/widgets/index.js +28 -0
  62. package/internal/widgets/index.js.map +1 -0
  63. package/link/styles.css.js +20 -20
  64. package/link/styles.scoped.css +71 -75
  65. package/link/styles.selectors.js +20 -20
  66. package/package.json +1 -1
  67. package/s3-resource-selector/s3-modal/index.js +2 -2
  68. package/s3-resource-selector/s3-modal/index.js.map +1 -1
  69. package/select/utils/use-select.d.ts.map +1 -1
  70. package/select/utils/use-select.js +15 -1
  71. package/select/utils/use-select.js.map +1 -1
  72. package/side-navigation/implementation.d.ts +7 -0
  73. package/side-navigation/implementation.d.ts.map +1 -0
  74. package/side-navigation/implementation.js +36 -0
  75. package/side-navigation/implementation.js.map +1 -0
  76. package/side-navigation/index.d.ts +1 -1
  77. package/side-navigation/index.d.ts.map +1 -1
  78. package/side-navigation/index.js +5 -29
  79. package/side-navigation/index.js.map +1 -1
  80. package/side-navigation/internal.d.ts +1 -17
  81. package/side-navigation/internal.d.ts.map +1 -1
  82. package/side-navigation/internal.js +2 -182
  83. package/side-navigation/internal.js.map +1 -1
  84. package/side-navigation/parts.d.ts +18 -0
  85. package/side-navigation/parts.d.ts.map +1 -0
  86. package/side-navigation/parts.js +185 -0
  87. package/side-navigation/parts.js.map +1 -0
  88. package/slider/internal.d.ts.map +1 -1
  89. package/slider/internal.js +6 -2
  90. package/slider/internal.js.map +1 -1
  91. package/slider/styles.css.js +25 -23
  92. package/slider/styles.scoped.css +95 -52
  93. package/slider/styles.selectors.js +25 -23
  94. package/slider/tick-marks.d.ts +1 -0
  95. package/slider/tick-marks.d.ts.map +1 -1
  96. package/slider/tick-marks.js +4 -1
  97. package/slider/tick-marks.js.map +1 -1
  98. package/split-panel/implementation.d.ts +1 -0
  99. package/split-panel/implementation.d.ts.map +1 -1
  100. package/split-panel/implementation.js +2 -0
  101. package/split-panel/implementation.js.map +1 -1
  102. package/split-panel/styles.css.js +57 -57
  103. package/split-panel/styles.scoped.css +78 -77
  104. package/split-panel/styles.selectors.js +57 -57
  105. package/split-panel/widget.d.ts +1 -5
  106. package/split-panel/widget.d.ts.map +1 -1
  107. package/split-panel/widget.js +1 -13
  108. package/split-panel/widget.js.map +1 -1
  109. package/table/selection/use-selection.d.ts.map +1 -1
  110. package/table/selection/use-selection.js +59 -64
  111. package/table/selection/use-selection.js.map +1 -1
@@ -2,62 +2,62 @@
2
2
  // es-module interop with Babel and Typescript
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  module.exports.default = {
5
- "drawer": "awsui_drawer_1r9lg_19mex_201",
6
- "refresh": "awsui_refresh_1r9lg_19mex_201",
7
- "animating": "awsui_animating_1r9lg_19mex_215",
8
- "preference-icon--svg": "awsui_preference-icon--svg_1r9lg_19mex_328",
9
- "preference-icon--layout-border": "awsui_preference-icon--layout-border_1r9lg_19mex_331",
10
- "preference-icon--layout-background": "awsui_preference-icon--layout-background_1r9lg_19mex_335",
11
- "preference-icon--layout-header": "awsui_preference-icon--layout-header_1r9lg_19mex_338",
12
- "preference-icon--border": "awsui_preference-icon--border_1r9lg_19mex_341",
13
- "preference-icon--primary-button": "awsui_preference-icon--primary-button_1r9lg_19mex_345",
14
- "preference-icon--secondary": "awsui_preference-icon--secondary_1r9lg_19mex_348",
15
- "preference-icon--disabled-element": "awsui_preference-icon--disabled-element_1r9lg_19mex_351",
16
- "preference-icon--separator": "awsui_preference-icon--separator_1r9lg_19mex_354",
17
- "preference-icon--focus-text": "awsui_preference-icon--focus-text_1r9lg_19mex_357",
18
- "preference-icon-refresh--svg": "awsui_preference-icon-refresh--svg_1r9lg_19mex_361",
19
- "preference-icon-refresh--layout-top": "awsui_preference-icon-refresh--layout-top_1r9lg_19mex_364",
20
- "preference-icon-refresh--layout-main": "awsui_preference-icon-refresh--layout-main_1r9lg_19mex_367",
21
- "preference-icon-refresh--primary": "awsui_preference-icon-refresh--primary_1r9lg_19mex_370",
22
- "preference-icon-refresh--disabled": "awsui_preference-icon-refresh--disabled_1r9lg_19mex_373",
23
- "preference-icon-refresh--column-header": "awsui_preference-icon-refresh--column-header_1r9lg_19mex_376",
24
- "preference-icon-refresh--window": "awsui_preference-icon-refresh--window_1r9lg_19mex_379",
25
- "preference-icon-refresh--secondary": "awsui_preference-icon-refresh--secondary_1r9lg_19mex_383",
26
- "preference-icon-refresh--default": "awsui_preference-icon-refresh--default_1r9lg_19mex_386",
27
- "preference-icon-refresh--separator": "awsui_preference-icon-refresh--separator_1r9lg_19mex_389",
28
- "preference-icon-refresh--input-default": "awsui_preference-icon-refresh--input-default_1r9lg_19mex_392",
29
- "preference-icon-refresh--heading": "awsui_preference-icon-refresh--heading_1r9lg_19mex_395",
30
- "root": "awsui_root_1r9lg_19mex_399",
31
- "preferences-button": "awsui_preferences-button_1r9lg_19mex_434",
32
- "close-button": "awsui_close-button_1r9lg_19mex_438",
33
- "drawer-closed": "awsui_drawer-closed_1r9lg_19mex_450",
34
- "drawer-content-side": "awsui_drawer-content-side_1r9lg_19mex_455",
35
- "drawer-content-bottom": "awsui_drawer-content-bottom_1r9lg_19mex_471",
36
- "position-bottom": "awsui_position-bottom_1r9lg_19mex_477",
37
- "position-side": "awsui_position-side_1r9lg_19mex_504",
38
- "slider": "awsui_slider_1r9lg_19mex_510",
39
- "slider-side": "awsui_slider-side_1r9lg_19mex_545",
40
- "slider-wrapper-bottom": "awsui_slider-wrapper-bottom_1r9lg_19mex_552",
41
- "slider-wrapper-side": "awsui_slider-wrapper-side_1r9lg_19mex_563",
42
- "open-button": "awsui_open-button_1r9lg_19mex_574",
43
- "open-button-side": "awsui_open-button-side_1r9lg_19mex_578",
44
- "slider-icon": "awsui_slider-icon_1r9lg_19mex_587",
45
- "slider-icon-bottom": "awsui_slider-icon-bottom_1r9lg_19mex_593",
46
- "slider-icon-side": "awsui_slider-icon-side_1r9lg_19mex_597",
47
- "pane-header-wrapper-bottom": "awsui_pane-header-wrapper-bottom_1r9lg_19mex_601",
48
- "drawer-mobile": "awsui_drawer-mobile_1r9lg_19mex_612",
49
- "drawer-disable-content-paddings": "awsui_drawer-disable-content-paddings_1r9lg_19mex_616",
50
- "content-bottom": "awsui_content-bottom_1r9lg_19mex_625",
51
- "pane-bottom-center-align": "awsui_pane-bottom-center-align_1r9lg_19mex_641",
52
- "pane-bottom-content-nav-padding": "awsui_pane-bottom-content-nav-padding_1r9lg_19mex_646",
53
- "pane-bottom-content-tools-padding": "awsui_pane-bottom-content-tools-padding_1r9lg_19mex_650",
54
- "content-bottom-max-width": "awsui_content-bottom-max-width_1r9lg_19mex_654",
55
- "content-side": "awsui_content-side_1r9lg_19mex_659",
56
- "pane-header-wrapper-side": "awsui_pane-header-wrapper-side_1r9lg_19mex_669",
57
- "pane-content-wrapper-side": "awsui_pane-content-wrapper-side_1r9lg_19mex_675",
58
- "header": "awsui_header_1r9lg_19mex_682",
59
- "header-text": "awsui_header-text_1r9lg_19mex_692",
60
- "header-actions": "awsui_header-actions_1r9lg_19mex_705",
61
- "divider": "awsui_divider_1r9lg_19mex_713"
5
+ "drawer": "awsui_drawer_1r9lg_1y4zq_201",
6
+ "refresh": "awsui_refresh_1r9lg_1y4zq_201",
7
+ "animating": "awsui_animating_1r9lg_1y4zq_215",
8
+ "preference-icon--svg": "awsui_preference-icon--svg_1r9lg_1y4zq_328",
9
+ "preference-icon--layout-border": "awsui_preference-icon--layout-border_1r9lg_1y4zq_331",
10
+ "preference-icon--layout-background": "awsui_preference-icon--layout-background_1r9lg_1y4zq_335",
11
+ "preference-icon--layout-header": "awsui_preference-icon--layout-header_1r9lg_1y4zq_338",
12
+ "preference-icon--border": "awsui_preference-icon--border_1r9lg_1y4zq_341",
13
+ "preference-icon--primary-button": "awsui_preference-icon--primary-button_1r9lg_1y4zq_345",
14
+ "preference-icon--secondary": "awsui_preference-icon--secondary_1r9lg_1y4zq_348",
15
+ "preference-icon--disabled-element": "awsui_preference-icon--disabled-element_1r9lg_1y4zq_351",
16
+ "preference-icon--separator": "awsui_preference-icon--separator_1r9lg_1y4zq_354",
17
+ "preference-icon--focus-text": "awsui_preference-icon--focus-text_1r9lg_1y4zq_357",
18
+ "preference-icon-refresh--svg": "awsui_preference-icon-refresh--svg_1r9lg_1y4zq_361",
19
+ "preference-icon-refresh--layout-top": "awsui_preference-icon-refresh--layout-top_1r9lg_1y4zq_364",
20
+ "preference-icon-refresh--layout-main": "awsui_preference-icon-refresh--layout-main_1r9lg_1y4zq_367",
21
+ "preference-icon-refresh--primary": "awsui_preference-icon-refresh--primary_1r9lg_1y4zq_370",
22
+ "preference-icon-refresh--disabled": "awsui_preference-icon-refresh--disabled_1r9lg_1y4zq_373",
23
+ "preference-icon-refresh--column-header": "awsui_preference-icon-refresh--column-header_1r9lg_1y4zq_376",
24
+ "preference-icon-refresh--window": "awsui_preference-icon-refresh--window_1r9lg_1y4zq_379",
25
+ "preference-icon-refresh--secondary": "awsui_preference-icon-refresh--secondary_1r9lg_1y4zq_383",
26
+ "preference-icon-refresh--default": "awsui_preference-icon-refresh--default_1r9lg_1y4zq_386",
27
+ "preference-icon-refresh--separator": "awsui_preference-icon-refresh--separator_1r9lg_1y4zq_389",
28
+ "preference-icon-refresh--input-default": "awsui_preference-icon-refresh--input-default_1r9lg_1y4zq_392",
29
+ "preference-icon-refresh--heading": "awsui_preference-icon-refresh--heading_1r9lg_1y4zq_395",
30
+ "root": "awsui_root_1r9lg_1y4zq_399",
31
+ "preferences-button": "awsui_preferences-button_1r9lg_1y4zq_434",
32
+ "close-button": "awsui_close-button_1r9lg_1y4zq_438",
33
+ "drawer-closed": "awsui_drawer-closed_1r9lg_1y4zq_450",
34
+ "drawer-content-side": "awsui_drawer-content-side_1r9lg_1y4zq_455",
35
+ "drawer-content-bottom": "awsui_drawer-content-bottom_1r9lg_1y4zq_471",
36
+ "position-bottom": "awsui_position-bottom_1r9lg_1y4zq_478",
37
+ "position-side": "awsui_position-side_1r9lg_1y4zq_505",
38
+ "slider": "awsui_slider_1r9lg_1y4zq_511",
39
+ "slider-side": "awsui_slider-side_1r9lg_1y4zq_546",
40
+ "slider-wrapper-bottom": "awsui_slider-wrapper-bottom_1r9lg_1y4zq_553",
41
+ "slider-wrapper-side": "awsui_slider-wrapper-side_1r9lg_1y4zq_564",
42
+ "open-button": "awsui_open-button_1r9lg_1y4zq_575",
43
+ "open-button-side": "awsui_open-button-side_1r9lg_1y4zq_579",
44
+ "slider-icon": "awsui_slider-icon_1r9lg_1y4zq_588",
45
+ "slider-icon-bottom": "awsui_slider-icon-bottom_1r9lg_1y4zq_594",
46
+ "slider-icon-side": "awsui_slider-icon-side_1r9lg_1y4zq_598",
47
+ "pane-header-wrapper-bottom": "awsui_pane-header-wrapper-bottom_1r9lg_1y4zq_602",
48
+ "drawer-mobile": "awsui_drawer-mobile_1r9lg_1y4zq_613",
49
+ "drawer-disable-content-paddings": "awsui_drawer-disable-content-paddings_1r9lg_1y4zq_617",
50
+ "content-bottom": "awsui_content-bottom_1r9lg_1y4zq_626",
51
+ "pane-bottom-center-align": "awsui_pane-bottom-center-align_1r9lg_1y4zq_642",
52
+ "pane-bottom-content-nav-padding": "awsui_pane-bottom-content-nav-padding_1r9lg_1y4zq_647",
53
+ "pane-bottom-content-tools-padding": "awsui_pane-bottom-content-tools-padding_1r9lg_1y4zq_651",
54
+ "content-bottom-max-width": "awsui_content-bottom-max-width_1r9lg_1y4zq_655",
55
+ "content-side": "awsui_content-side_1r9lg_1y4zq_660",
56
+ "pane-header-wrapper-side": "awsui_pane-header-wrapper-side_1r9lg_1y4zq_670",
57
+ "pane-content-wrapper-side": "awsui_pane-content-wrapper-side_1r9lg_1y4zq_676",
58
+ "header": "awsui_header_1r9lg_1y4zq_683",
59
+ "header-text": "awsui_header-text_1r9lg_1y4zq_693",
60
+ "header-actions": "awsui_header-actions_1r9lg_1y4zq_706",
61
+ "divider": "awsui_divider_1r9lg_1y4zq_714"
62
62
  };
63
63
 
@@ -1,6 +1,2 @@
1
- import React from 'react';
2
- import { SplitPanelProps } from './interfaces';
3
- type SplitPanelType = React.ForwardRefExoticComponent<SplitPanelProps & React.RefAttributes<HTMLElement>>;
4
- export declare function createWidgetizedSplitPanel(SplitPanelLoader?: SplitPanelType): SplitPanelType;
5
- export {};
1
+ export { createWidgetizedSplitPanel } from './implementation';
6
2
  //# sourceMappingURL=widget.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../../../src/split-panel/widget.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAI/C,KAAK,cAAc,GAAG,KAAK,CAAC,yBAAyB,CAAC,eAAe,GAAG,KAAK,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC;AAE1G,wBAAgB,0BAA0B,CAAC,gBAAgB,CAAC,EAAE,cAAc,GAAG,cAAc,CAS5F"}
1
+ {"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../../../src/split-panel/widget.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC"}
@@ -1,16 +1,4 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import React from 'react';
4
- import { getGlobalFlag } from '../internal/utils/global-flags';
5
- import { useVisualRefresh } from '../internal/hooks/use-visual-mode';
6
- import { SplitPanelImplementation } from './implementation';
7
- export function createWidgetizedSplitPanel(SplitPanelLoader) {
8
- return React.forwardRef((props, ref) => {
9
- const isRefresh = useVisualRefresh();
10
- if (isRefresh && getGlobalFlag('appLayoutWidget') && SplitPanelLoader) {
11
- return React.createElement(SplitPanelLoader, Object.assign({ ref: ref }, props));
12
- }
13
- return React.createElement(SplitPanelImplementation, Object.assign({ ref: ref }, props));
14
- });
15
- }
3
+ export { createWidgetizedSplitPanel } from './implementation';
16
4
  //# sourceMappingURL=widget.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"widget.js","sourceRoot":"","sources":["../../../src/split-panel/widget.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAE/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAI5D,MAAM,UAAU,0BAA0B,CAAC,gBAAiC;IAC1E,OAAO,KAAK,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QACrC,MAAM,SAAS,GAAG,gBAAgB,EAAE,CAAC;QACrC,IAAI,SAAS,IAAI,aAAa,CAAC,iBAAiB,CAAC,IAAI,gBAAgB,EAAE;YACrE,OAAO,oBAAC,gBAAgB,kBAAC,GAAG,EAAE,GAAG,IAAM,KAAK,EAAI,CAAC;SAClD;QAED,OAAO,oBAAC,wBAAwB,kBAAC,GAAG,EAAE,GAAG,IAAM,KAAK,EAAI,CAAC;IAC3D,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React from 'react';\nimport { getGlobalFlag } from '../internal/utils/global-flags';\nimport { SplitPanelProps } from './interfaces';\nimport { useVisualRefresh } from '../internal/hooks/use-visual-mode';\nimport { SplitPanelImplementation } from './implementation';\n\ntype SplitPanelType = React.ForwardRefExoticComponent<SplitPanelProps & React.RefAttributes<HTMLElement>>;\n\nexport function createWidgetizedSplitPanel(SplitPanelLoader?: SplitPanelType): SplitPanelType {\n return React.forwardRef((props, ref) => {\n const isRefresh = useVisualRefresh();\n if (isRefresh && getGlobalFlag('appLayoutWidget') && SplitPanelLoader) {\n return <SplitPanelLoader ref={ref} {...props} />;\n }\n\n return <SplitPanelImplementation ref={ref} {...props} />;\n });\n}\n"]}
1
+ {"version":3,"file":"widget.js","sourceRoot":"","sources":["../../../src/split-panel/widget.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nexport { createWidgetizedSplitPanel } from './implementation';\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"use-selection.d.ts","sourceRoot":"","sources":["../../../../src/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
+ {"version":3,"file":"use-selection.d.ts","sourceRoot":"","sources":["../../../../src/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;;6BAuF0B,cAAc;kCAiBP,CAAC,KAAG,cAAc;+BAiBrB,OAAO;EAIrC"}
@@ -7,84 +7,78 @@ import { getTrackableValue } from '../utils';
7
7
  import { joinStrings } from '../../internal/utils/strings';
8
8
  import { ItemSet } from './utils';
9
9
  export function useSelection({ items, selectedItems = [], selectionType, isItemDisabled = () => false, trackBy, onSelectionChange, ariaLabels, loading, }) {
10
- const [shiftPressed, setShiftPressed] = useState(false);
11
- const [lastClickedItem, setLastClickedItem] = useState(null);
12
- const selectionName = useUniqueId();
10
+ // The name assigned to all radio- controls to combine them in a single group.
11
+ const selectionControlName = useUniqueId();
12
+ // Selection state for individual items.
13
13
  const finalSelectedItems = selectionType === 'single' ? selectedItems.slice(0, 1) : selectedItems;
14
14
  const selectedSet = new ItemSet(trackBy, finalSelectedItems);
15
- const itemIndexesMap = new Map();
16
- items.forEach((item, i) => itemIndexesMap.set(getTrackableValue(trackBy, item), i));
17
15
  const isItemSelected = selectedSet.has.bind(selectedSet);
18
- const getItemState = (item) => ({
19
- disabled: isItemDisabled(item),
20
- selected: isItemSelected(item),
21
- });
22
- const [allDisabled, allEnabledSelected] = selectionType
23
- ? items.reduce(([allDisabled, allEnabledSelected], item) => {
24
- const { disabled, selected } = getItemState(item);
25
- return [
26
- // all items are disabled (or none are present)
27
- allDisabled && disabled,
28
- // all enabled items are selected (or none are present)
29
- allEnabledSelected && (selected || disabled),
30
- ];
31
- }, [true, true])
32
- : [true, true];
33
- // the page has at least one selected item
34
- const hasSelected = finalSelectedItems.length > 0;
35
- const handleToggleAll = () => {
36
- const requestedItems = new ItemSet(trackBy, items);
37
- const newSelectedItems = allEnabledSelected ? deselectItems(requestedItems) : selectItems(requestedItems);
38
- fireNonCancelableEvent(onSelectionChange, { selectedItems: newSelectedItems });
39
- };
40
- const getRequestedItems = (item) => {
41
- const requestedItems = new ItemSet(trackBy, [item]);
42
- let lastClickedItemIndex = lastClickedItem ? itemIndexesMap.get(getTrackableValue(trackBy, lastClickedItem)) : -1;
43
- if (lastClickedItemIndex === undefined) {
44
- lastClickedItemIndex = -1;
16
+ // Derived selection state for all-items checkbox.
17
+ let allItemsDisabled = true;
18
+ let allEnabledItemsSelected = true;
19
+ if (selectionType === 'multi') {
20
+ for (const item of items) {
21
+ allItemsDisabled = allItemsDisabled && isItemDisabled(item);
22
+ allEnabledItemsSelected = allEnabledItemsSelected && (isItemSelected(item) || isItemDisabled(item));
45
23
  }
46
- // we use lastClickedItemIndex to determine if filtering/sorting/pagination
47
- // made previously selected item invisible, therefore we reset state for shift-select
48
- if (shiftPressed && lastClickedItemIndex !== -1) {
49
- // item is always in items
24
+ }
25
+ const allItemsCheckboxSelected = finalSelectedItems.length > 0 && allEnabledItemsSelected;
26
+ const allItemsCheckboxIndeterminate = finalSelectedItems.length > 0 && !allEnabledItemsSelected;
27
+ // Shift-selection helpers.
28
+ const [shiftPressed, setShiftPressed] = useState(false);
29
+ const [lastClickedItem, setLastClickedItem] = useState(null);
30
+ const itemIndexesMap = new Map();
31
+ items.forEach((item, i) => itemIndexesMap.set(getTrackableValue(trackBy, item), i));
32
+ const getShiftSelectedItems = (item) => {
33
+ const lastClickedItemIndex = lastClickedItem
34
+ ? itemIndexesMap.get(getTrackableValue(trackBy, lastClickedItem))
35
+ : undefined;
36
+ // We use lastClickedItemIndex to determine if filtering/sorting/pagination
37
+ // made previously selected item invisible, therefore we reset state for shift-select.
38
+ if (lastClickedItemIndex !== undefined) {
50
39
  const currentItemIndex = itemIndexesMap.get(getTrackableValue(trackBy, item));
51
40
  const start = Math.min(currentItemIndex, lastClickedItemIndex);
52
41
  const end = Math.max(currentItemIndex, lastClickedItemIndex);
53
- items.slice(start, end + 1).forEach(item => requestedItems.put(item));
42
+ return items.slice(start, end + 1);
54
43
  }
55
- return requestedItems;
44
+ return [item];
45
+ };
46
+ // Select items that are not already selected or disabled.
47
+ const selectItems = (requestedItems) => {
48
+ const newSelectedItems = [...selectedItems];
49
+ requestedItems.forEach(newItem => {
50
+ if (!isItemSelected(newItem) && !isItemDisabled(newItem)) {
51
+ newSelectedItems.push(newItem);
52
+ }
53
+ });
54
+ return newSelectedItems;
56
55
  };
56
+ // Unselect items unless they are disabled.
57
57
  const deselectItems = (requestedItems) => {
58
+ const requestedItemsSet = new ItemSet(trackBy, requestedItems);
58
59
  const newSelectedItems = [];
59
60
  selectedItems.forEach(selectedItem => {
60
- const toUnselect = requestedItems.has(selectedItem);
61
- if (!toUnselect || isItemDisabled(selectedItem)) {
61
+ const shouldUnselect = requestedItemsSet.has(selectedItem);
62
+ if (!shouldUnselect || isItemDisabled(selectedItem)) {
62
63
  newSelectedItems.push(selectedItem);
63
64
  }
64
65
  });
65
66
  return newSelectedItems;
66
67
  };
67
- const selectItems = (requestedItems) => {
68
- const newSelectedItems = [...selectedItems];
69
- requestedItems.forEach(newItem => {
70
- const { selected, disabled } = getItemState(newItem);
71
- if (!selected && !disabled) {
72
- newSelectedItems.push(newItem);
73
- }
74
- });
75
- return newSelectedItems;
68
+ const handleToggleAll = () => {
69
+ const newSelectedItems = allEnabledItemsSelected ? deselectItems(items) : selectItems(items);
70
+ fireNonCancelableEvent(onSelectionChange, { selectedItems: newSelectedItems });
76
71
  };
77
- const handleToggleItem = (item) => () => {
78
- const { disabled, selected } = getItemState(item);
79
- if (disabled || (selectionType === 'single' && selected)) {
72
+ const handleToggleItem = (item) => {
73
+ if (isItemDisabled(item)) {
80
74
  return;
81
75
  }
82
- if (selectionType === 'single') {
76
+ if (selectionType === 'single' && !isItemSelected(item)) {
83
77
  fireNonCancelableEvent(onSelectionChange, { selectedItems: [item] });
84
78
  }
85
- else {
86
- const requestedItems = getRequestedItems(item);
87
- const selectedItems = selected ? deselectItems(requestedItems) : selectItems(requestedItems);
79
+ if (selectionType === 'multi') {
80
+ const requestedItems = shiftPressed ? getShiftSelectedItems(item) : [item];
81
+ const selectedItems = isItemSelected(item) ? deselectItems(requestedItems) : selectItems(requestedItems);
88
82
  fireNonCancelableEvent(onSelectionChange, { selectedItems });
89
83
  setLastClickedItem(item);
90
84
  }
@@ -97,11 +91,11 @@ export function useSelection({ items, selectedItems = [], selectionType, isItemD
97
91
  throw new Error('Invariant violation: calling selection props with missing selection type.');
98
92
  }
99
93
  return {
100
- name: selectionName,
101
- disabled: allDisabled || !!loading,
94
+ name: selectionControlName,
102
95
  selectionType: selectionType,
103
- indeterminate: hasSelected && !allEnabledSelected,
104
- checked: hasSelected && allEnabledSelected,
96
+ disabled: allItemsDisabled || !!loading,
97
+ checked: allItemsCheckboxSelected,
98
+ indeterminate: allItemsCheckboxIndeterminate,
105
99
  onChange: handleToggleAll,
106
100
  ariaLabel: joinStrings(ariaLabels === null || ariaLabels === void 0 ? void 0 : ariaLabels.selectionGroupLabel, (_a = ariaLabels === null || ariaLabels === void 0 ? void 0 : ariaLabels.allItemsSelectionLabel) === null || _a === void 0 ? void 0 : _a.call(ariaLabels, { selectedItems })),
107
101
  };
@@ -112,12 +106,13 @@ export function useSelection({ items, selectedItems = [], selectionType, isItemD
112
106
  throw new Error('Invariant violation: calling selection props with missing selection type.');
113
107
  }
114
108
  return {
115
- name: selectionName,
109
+ name: selectionControlName,
116
110
  selectionType: selectionType,
117
- ariaLabel: joinStrings(ariaLabels === null || ariaLabels === void 0 ? void 0 : ariaLabels.selectionGroupLabel, (_a = ariaLabels === null || ariaLabels === void 0 ? void 0 : ariaLabels.itemSelectionLabel) === null || _a === void 0 ? void 0 : _a.call(ariaLabels, { selectedItems }, item)),
118
- onChange: handleToggleItem(item),
119
- checked: isItemSelected(item),
120
111
  disabled: isItemDisabled(item),
112
+ checked: isItemSelected(item),
113
+ indeterminate: false,
114
+ onChange: () => handleToggleItem(item),
115
+ ariaLabel: joinStrings(ariaLabels === null || ariaLabels === void 0 ? void 0 : ariaLabels.selectionGroupLabel, (_a = ariaLabels === null || ariaLabels === void 0 ? void 0 : ariaLabels.itemSelectionLabel) === null || _a === void 0 ? void 0 : _a.call(ariaLabels, { selectedItems }, item)),
121
116
  };
122
117
  },
123
118
  updateShiftToggle: (value) => {
@@ -1 +1 @@
1
- {"version":3,"file":"use-selection.js","sourceRoot":"","sources":["../../../../src/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,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AAa;gBACnB,aAAa,EAAE,aAAa;gBAC5B,SAAS,EAAE,WAAW,CACpB,UAAU,aAAV,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"]}
1
+ {"version":3,"file":"use-selection.js","sourceRoot":"","sources":["../../../../src/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,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C;gBAC7B,aAAa,EAAE,KAAK;gBACpB,QAAQ,EAAE,GAAG,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC;gBACtC,SAAS,EAAE,WAAW,CACpB,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,mBAAmB,EAC/B,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,kBAAkB,2DAAG,EAAE,aAAa,EAAE,EAAE,IAAI,CAAC,CAC1D;aACF,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 // The name assigned to all radio- controls to combine them in a single group.\n const selectionControlName = useUniqueId();\n\n // Selection state for individual items.\n const finalSelectedItems = selectionType === 'single' ? selectedItems.slice(0, 1) : selectedItems;\n const selectedSet = new ItemSet(trackBy, finalSelectedItems);\n const isItemSelected = selectedSet.has.bind(selectedSet);\n\n // Derived selection state for all-items checkbox.\n let allItemsDisabled = true;\n let allEnabledItemsSelected = true;\n if (selectionType === 'multi') {\n for (const item of items) {\n allItemsDisabled = allItemsDisabled && isItemDisabled(item);\n allEnabledItemsSelected = allEnabledItemsSelected && (isItemSelected(item) || isItemDisabled(item));\n }\n }\n const allItemsCheckboxSelected = finalSelectedItems.length > 0 && allEnabledItemsSelected;\n const allItemsCheckboxIndeterminate = finalSelectedItems.length > 0 && !allEnabledItemsSelected;\n\n // Shift-selection helpers.\n const [shiftPressed, setShiftPressed] = useState(false);\n const [lastClickedItem, setLastClickedItem] = useState<null | T>(null);\n const itemIndexesMap = new Map<T, number>();\n items.forEach((item, i) => itemIndexesMap.set(getTrackableValue(trackBy, item), i));\n const getShiftSelectedItems = (item: T): T[] => {\n const lastClickedItemIndex = lastClickedItem\n ? itemIndexesMap.get(getTrackableValue(trackBy, lastClickedItem))\n : undefined;\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 (lastClickedItemIndex !== undefined) {\n const currentItemIndex = itemIndexesMap.get(getTrackableValue(trackBy, item))!;\n const start = Math.min(currentItemIndex, lastClickedItemIndex);\n const end = Math.max(currentItemIndex, lastClickedItemIndex);\n return items.slice(start, end + 1);\n }\n return [item];\n };\n\n // Select items that are not already selected or disabled.\n const selectItems = (requestedItems: readonly T[]) => {\n const newSelectedItems = [...selectedItems];\n requestedItems.forEach(newItem => {\n if (!isItemSelected(newItem) && !isItemDisabled(newItem)) {\n newSelectedItems.push(newItem);\n }\n });\n return newSelectedItems;\n };\n\n // Unselect items unless they are disabled.\n const deselectItems = (requestedItems: readonly T[]) => {\n const requestedItemsSet = new ItemSet(trackBy, requestedItems);\n const newSelectedItems: Array<T> = [];\n selectedItems.forEach(selectedItem => {\n const shouldUnselect = requestedItemsSet.has(selectedItem);\n if (!shouldUnselect || isItemDisabled(selectedItem)) {\n newSelectedItems.push(selectedItem);\n }\n });\n return newSelectedItems;\n };\n\n const handleToggleAll = () => {\n const newSelectedItems = allEnabledItemsSelected ? deselectItems(items) : selectItems(items);\n fireNonCancelableEvent(onSelectionChange, { selectedItems: newSelectedItems });\n };\n\n const handleToggleItem = (item: T) => {\n if (isItemDisabled(item)) {\n return;\n }\n if (selectionType === 'single' && !isItemSelected(item)) {\n fireNonCancelableEvent(onSelectionChange, { selectedItems: [item] });\n }\n if (selectionType === 'multi') {\n const requestedItems = shiftPressed ? getShiftSelectedItems(item) : [item];\n const selectedItems = isItemSelected(item) ? 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: selectionControlName,\n selectionType: selectionType,\n disabled: allItemsDisabled || !!loading,\n checked: allItemsCheckboxSelected,\n indeterminate: allItemsCheckboxIndeterminate,\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: selectionControlName,\n selectionType: selectionType,\n disabled: isItemDisabled(item),\n checked: isItemSelected(item),\n indeterminate: false,\n onChange: () => handleToggleItem(item),\n ariaLabel: joinStrings(\n ariaLabels?.selectionGroupLabel,\n ariaLabels?.itemSelectionLabel?.({ selectedItems }, item)\n ),\n };\n },\n updateShiftToggle: (value: boolean) => {\n setShiftPressed(value);\n },\n };\n}\n"]}