@cloudscape-design/components 3.0.1308 → 3.0.1309

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 (137) hide show
  1. package/collection-preferences/content-display/content-display-option.js +1 -1
  2. package/collection-preferences/content-display/content-display-option.js.map +1 -1
  3. package/collection-preferences/content-display/index.d.ts +3 -7
  4. package/collection-preferences/content-display/index.d.ts.map +1 -1
  5. package/collection-preferences/content-display/index.js +63 -27
  6. package/collection-preferences/content-display/index.js.map +1 -1
  7. package/collection-preferences/content-display/utils.d.ts +41 -2
  8. package/collection-preferences/content-display/utils.d.ts.map +1 -1
  9. package/collection-preferences/content-display/utils.js +107 -13
  10. package/collection-preferences/content-display/utils.js.map +1 -1
  11. package/collection-preferences/index.d.ts.map +1 -1
  12. package/collection-preferences/index.js +2 -2
  13. package/collection-preferences/index.js.map +1 -1
  14. package/collection-preferences/interfaces.d.ts +30 -2
  15. package/collection-preferences/interfaces.d.ts.map +1 -1
  16. package/collection-preferences/interfaces.js.map +1 -1
  17. package/collection-preferences/styles.css.js +38 -36
  18. package/collection-preferences/styles.scoped.css +81 -37
  19. package/collection-preferences/styles.selectors.js +38 -36
  20. package/collection-preferences/utils.d.ts +1 -0
  21. package/collection-preferences/utils.d.ts.map +1 -1
  22. package/collection-preferences/utils.js +14 -0
  23. package/collection-preferences/utils.js.map +1 -1
  24. package/i18n/messages/all.all.js +1 -1
  25. package/i18n/messages/all.all.json +1 -1
  26. package/i18n/messages/all.en.js +1 -1
  27. package/i18n/messages/all.en.json +1 -1
  28. package/i18n/messages-types.d.ts +4 -0
  29. package/i18n/messages-types.d.ts.map +1 -1
  30. package/i18n/messages-types.js.map +1 -1
  31. package/internal/base-component/styles.scoped.css +1 -1
  32. package/internal/environment.js +2 -2
  33. package/internal/environment.json +2 -2
  34. package/internal/manifest.json +1 -1
  35. package/manifest.json +2 -2
  36. package/package.json +1 -1
  37. package/pagination/internal.d.ts.map +1 -1
  38. package/pagination/internal.js +4 -1
  39. package/pagination/internal.js.map +1 -1
  40. package/table/column-groups/col-group.d.ts +12 -0
  41. package/table/column-groups/col-group.d.ts.map +1 -0
  42. package/table/column-groups/col-group.js +24 -0
  43. package/table/column-groups/col-group.js.map +1 -0
  44. package/table/column-groups/split-utils.d.ts +31 -0
  45. package/table/column-groups/split-utils.d.ts.map +1 -0
  46. package/table/column-groups/split-utils.js +43 -0
  47. package/table/column-groups/split-utils.js.map +1 -0
  48. package/table/column-groups/use-column-groups.d.ts +7 -0
  49. package/table/column-groups/use-column-groups.d.ts.map +1 -0
  50. package/table/column-groups/use-column-groups.js +23 -0
  51. package/table/column-groups/use-column-groups.js.map +1 -0
  52. package/table/column-groups/utils.d.ts +54 -0
  53. package/table/column-groups/utils.d.ts.map +1 -0
  54. package/table/column-groups/utils.js +204 -0
  55. package/table/column-groups/utils.js.map +1 -0
  56. package/table/header-cell/common-props.d.ts +23 -0
  57. package/table/header-cell/common-props.d.ts.map +1 -0
  58. package/table/header-cell/common-props.js +4 -0
  59. package/table/header-cell/common-props.js.map +1 -0
  60. package/table/header-cell/group-header-cell.d.ts +45 -0
  61. package/table/header-cell/group-header-cell.d.ts.map +1 -0
  62. package/table/header-cell/group-header-cell.js +44 -0
  63. package/table/header-cell/group-header-cell.js.map +1 -0
  64. package/table/header-cell/index.d.ts +12 -22
  65. package/table/header-cell/index.d.ts.map +1 -1
  66. package/table/header-cell/index.js +3 -3
  67. package/table/header-cell/index.js.map +1 -1
  68. package/table/header-cell/styles.css.js +33 -30
  69. package/table/header-cell/styles.scoped.css +92 -68
  70. package/table/header-cell/styles.selectors.js +33 -30
  71. package/table/header-cell/th-element.d.ts +16 -0
  72. package/table/header-cell/th-element.d.ts.map +1 -1
  73. package/table/header-cell/th-element.js +6 -4
  74. package/table/header-cell/th-element.js.map +1 -1
  75. package/table/index.d.ts.map +1 -1
  76. package/table/index.js +5 -2
  77. package/table/index.js.map +1 -1
  78. package/table/interfaces.d.ts +37 -1
  79. package/table/interfaces.d.ts.map +1 -1
  80. package/table/interfaces.js.map +1 -1
  81. package/table/internal.d.ts.map +1 -1
  82. package/table/internal.js +17 -5
  83. package/table/internal.js.map +1 -1
  84. package/table/resizer/index.d.ts +9 -2
  85. package/table/resizer/index.d.ts.map +1 -1
  86. package/table/resizer/index.js +5 -5
  87. package/table/resizer/index.js.map +1 -1
  88. package/table/resizer/styles.css.js +16 -13
  89. package/table/resizer/styles.scoped.css +36 -26
  90. package/table/resizer/styles.selectors.js +16 -13
  91. package/table/sticky-header.d.ts +3 -0
  92. package/table/sticky-header.d.ts.map +1 -1
  93. package/table/sticky-header.js +7 -2
  94. package/table/sticky-header.js.map +1 -1
  95. package/table/sticky-scrolling.d.ts.map +1 -1
  96. package/table/sticky-scrolling.js +6 -1
  97. package/table/sticky-scrolling.js.map +1 -1
  98. package/table/styles.css.js +35 -34
  99. package/table/styles.scoped.css +47 -41
  100. package/table/styles.selectors.js +35 -34
  101. package/table/table-role/grid-navigation.d.ts.map +1 -1
  102. package/table/table-role/grid-navigation.js +5 -7
  103. package/table/table-role/grid-navigation.js.map +1 -1
  104. package/table/table-role/table-role-helper.d.ts +3 -0
  105. package/table/table-role/table-role-helper.d.ts.map +1 -1
  106. package/table/table-role/table-role-helper.js +9 -4
  107. package/table/table-role/table-role-helper.js.map +1 -1
  108. package/table/table-role/utils.d.ts +19 -0
  109. package/table/table-role/utils.d.ts.map +1 -1
  110. package/table/table-role/utils.js +86 -7
  111. package/table/table-role/utils.js.map +1 -1
  112. package/table/thead.d.ts +5 -0
  113. package/table/thead.d.ts.map +1 -1
  114. package/table/thead.js +145 -18
  115. package/table/thead.js.map +1 -1
  116. package/table/use-column-widths.d.ts +4 -0
  117. package/table/use-column-widths.d.ts.map +1 -1
  118. package/table/use-column-widths.js +68 -18
  119. package/table/use-column-widths.js.map +1 -1
  120. package/table/use-sticky-header.d.ts.map +1 -1
  121. package/table/use-sticky-header.js +4 -1
  122. package/table/use-sticky-header.js.map +1 -1
  123. package/table/utils.d.ts.map +1 -1
  124. package/table/utils.js +14 -4
  125. package/table/utils.js.map +1 -1
  126. package/test-utils/dom/collection-preferences/content-display-preference.d.ts +28 -2
  127. package/test-utils/dom/collection-preferences/content-display-preference.js +60 -2
  128. package/test-utils/dom/collection-preferences/content-display-preference.js.map +1 -1
  129. package/test-utils/dom/table/index.d.ts +18 -1
  130. package/test-utils/dom/table/index.js +22 -3
  131. package/test-utils/dom/table/index.js.map +1 -1
  132. package/test-utils/selectors/collection-preferences/content-display-preference.d.ts +28 -2
  133. package/test-utils/selectors/collection-preferences/content-display-preference.js +52 -2
  134. package/test-utils/selectors/collection-preferences/content-display-preference.js.map +1 -1
  135. package/test-utils/selectors/table/index.d.ts +18 -1
  136. package/test-utils/selectors/table/index.js +22 -3
  137. package/test-utils/selectors/table/index.js.map +1 -1
@@ -9,7 +9,7 @@ export const getClassName = (suffix) => styles[[componentPrefix, suffix].filter(
9
9
  const ContentDisplayOption = forwardRef(({ onToggle, option }, ref) => {
10
10
  const idPrefix = useUniqueId(componentPrefix);
11
11
  const controlId = `${idPrefix}-control-${option.id}`;
12
- return (React.createElement("div", { ref: ref, className: getClassName('content') },
12
+ return (React.createElement("div", { ref: ref, className: getClassName('content'), "data-item-type": "column" },
13
13
  React.createElement("label", { className: getClassName('label'), htmlFor: controlId }, option.label),
14
14
  React.createElement("div", { className: getClassName('toggle') },
15
15
  React.createElement(InternalToggle, { checked: !!option.visible, onChange: () => onToggle && onToggle(option), disabled: option.alwaysVisible === true, controlId: controlId }))));
@@ -1 +1 @@
1
- {"version":3,"file":"content-display-option.js","sourceRoot":"","sources":["../../../../src/collection-preferences/content-display/content-display-option.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAgB,UAAU,EAAE,MAAM,OAAO,CAAC;AAExD,OAAO,EAAE,WAAW,EAAE,MAAM,+CAA+C,CAAC;AAE5E,OAAO,cAAc,MAAM,uBAAuB,CAAC;AAGnD,OAAO,MAAM,MAAM,kBAAkB,CAAC;AAEtC,MAAM,eAAe,GAAG,wBAAwB,CAAC;AACjD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAe,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAO7G,MAAM,oBAAoB,GAAG,UAAU,CACrC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAA6B,EAAE,GAAiC,EAAE,EAAE;IACrF,MAAM,QAAQ,GAAG,WAAW,CAAC,eAAe,CAAC,CAAC;IAC9C,MAAM,SAAS,GAAG,GAAG,QAAQ,YAAY,MAAM,CAAC,EAAE,EAAE,CAAC;IACrD,OAAO,CACL,6BAAK,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,YAAY,CAAC,SAAS,CAAC;QAC/C,+BAAO,SAAS,EAAE,YAAY,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,SAAS,IACxD,MAAM,CAAC,KAAK,CACP;QACR,6BAAK,SAAS,EAAE,YAAY,CAAC,QAAQ,CAAC;YACpC,oBAAC,cAAc,IACb,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,EACzB,QAAQ,EAAE,GAAG,EAAE,CAAC,QAAQ,IAAI,QAAQ,CAAC,MAAM,CAAC,EAC5C,QAAQ,EAAE,MAAM,CAAC,aAAa,KAAK,IAAI,EACvC,SAAS,EAAE,SAAS,GACpB,CACE,CACF,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,oBAAoB,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { ForwardedRef, forwardRef } from 'react';\n\nimport { useUniqueId } from '@cloudscape-design/component-toolkit/internal';\n\nimport InternalToggle from '../../toggle/internal';\nimport { OptionWithVisibility } from './utils';\n\nimport styles from '../styles.css.js';\n\nconst componentPrefix = 'content-display-option';\nexport const getClassName = (suffix?: string) => styles[[componentPrefix, suffix].filter(Boolean).join('-')];\n\ninterface ContentDisplayOptionProps {\n onToggle?: (option: OptionWithVisibility) => void;\n option: OptionWithVisibility;\n}\n\nconst ContentDisplayOption = forwardRef(\n ({ onToggle, option }: ContentDisplayOptionProps, ref: ForwardedRef<HTMLDivElement>) => {\n const idPrefix = useUniqueId(componentPrefix);\n const controlId = `${idPrefix}-control-${option.id}`;\n return (\n <div ref={ref} className={getClassName('content')}>\n <label className={getClassName('label')} htmlFor={controlId}>\n {option.label}\n </label>\n <div className={getClassName('toggle')}>\n <InternalToggle\n checked={!!option.visible}\n onChange={() => onToggle && onToggle(option)}\n disabled={option.alwaysVisible === true}\n controlId={controlId}\n />\n </div>\n </div>\n );\n }\n);\n\nexport default ContentDisplayOption;\n"]}
1
+ {"version":3,"file":"content-display-option.js","sourceRoot":"","sources":["../../../../src/collection-preferences/content-display/content-display-option.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAgB,UAAU,EAAE,MAAM,OAAO,CAAC;AAExD,OAAO,EAAE,WAAW,EAAE,MAAM,+CAA+C,CAAC;AAE5E,OAAO,cAAc,MAAM,uBAAuB,CAAC;AAGnD,OAAO,MAAM,MAAM,kBAAkB,CAAC;AAEtC,MAAM,eAAe,GAAG,wBAAwB,CAAC;AACjD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAe,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAO7G,MAAM,oBAAoB,GAAG,UAAU,CACrC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAA6B,EAAE,GAAiC,EAAE,EAAE;IACrF,MAAM,QAAQ,GAAG,WAAW,CAAC,eAAe,CAAC,CAAC;IAC9C,MAAM,SAAS,GAAG,GAAG,QAAQ,YAAY,MAAM,CAAC,EAAE,EAAE,CAAC;IACrD,OAAO,CACL,6BAAK,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,YAAY,CAAC,SAAS,CAAC,oBAAiB,QAAQ;QACxE,+BAAO,SAAS,EAAE,YAAY,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,SAAS,IACxD,MAAM,CAAC,KAAK,CACP;QACR,6BAAK,SAAS,EAAE,YAAY,CAAC,QAAQ,CAAC;YACpC,oBAAC,cAAc,IACb,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,EACzB,QAAQ,EAAE,GAAG,EAAE,CAAC,QAAQ,IAAI,QAAQ,CAAC,MAAM,CAAC,EAC5C,QAAQ,EAAE,MAAM,CAAC,aAAa,KAAK,IAAI,EACvC,SAAS,EAAE,SAAS,GACpB,CACE,CACF,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,oBAAoB,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { ForwardedRef, forwardRef } from 'react';\n\nimport { useUniqueId } from '@cloudscape-design/component-toolkit/internal';\n\nimport InternalToggle from '../../toggle/internal';\nimport { OptionWithVisibility } from './utils';\n\nimport styles from '../styles.css.js';\n\nconst componentPrefix = 'content-display-option';\nexport const getClassName = (suffix?: string) => styles[[componentPrefix, suffix].filter(Boolean).join('-')];\n\ninterface ContentDisplayOptionProps {\n onToggle?: (option: OptionWithVisibility) => void;\n option: OptionWithVisibility;\n}\n\nconst ContentDisplayOption = forwardRef(\n ({ onToggle, option }: ContentDisplayOptionProps, ref: ForwardedRef<HTMLDivElement>) => {\n const idPrefix = useUniqueId(componentPrefix);\n const controlId = `${idPrefix}-control-${option.id}`;\n return (\n <div ref={ref} className={getClassName('content')} data-item-type=\"column\">\n <label className={getClassName('label')} htmlFor={controlId}>\n {option.label}\n </label>\n <div className={getClassName('toggle')}>\n <InternalToggle\n checked={!!option.visible}\n onChange={() => onToggle && onToggle(option)}\n disabled={option.alwaysVisible === true}\n controlId={controlId}\n />\n </div>\n </div>\n );\n }\n);\n\nexport default ContentDisplayOption;\n"]}
@@ -8,14 +8,10 @@ export default function ContentDisplayPreference({
8
8
  description,
9
9
  options,
10
10
  value,
11
+ groups,
11
12
  onChange,
12
- liveAnnouncementDndStarted,
13
- liveAnnouncementDndItemReordered,
14
- liveAnnouncementDndItemCommitted,
15
- liveAnnouncementDndDiscarded,
16
- dragHandleAriaDescription,
17
- dragHandleAriaLabel,
18
13
  enableColumnFiltering,
19
- i18nStrings
14
+ i18nStrings,
15
+ ...dndProps
20
16
  }: ContentDisplayPreferenceProps): JSX.Element;
21
17
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/collection-preferences/content-display/index.tsx"],"names":[],"mappings":"AAkBA,OAAO,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAU3D,UAAU,6BAA8B,SAAQ,0BAA0B,CAAC,wBAAwB;IACjG,QAAQ,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,0BAA0B,CAAC,kBAAkB,CAAC,KAAK,IAAI,CAAC;IACxF,KAAK,CAAC,EAAE,aAAa,CAAC,0BAA0B,CAAC,kBAAkB,CAAC,CAAC;CACtE;AAED,MAAM,CAAC,OAAO,UAAU,wBAAwB,CAAC,EAC/C,KAAK,EACL,WAAW,EACX,OAAO,EACP,KAGG,EACH,QAAQ,EACR,0BAA0B,EAC1B,gCAAgC,EAChC,gCAAgC,EAChC,4BAA4B,EAC5B,yBAAyB,EACzB,mBAAmB,EACnB,qBAA6B,EAC7B,WAAW,GACZ,EAAE,6BAA6B,eAgI/B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/collection-preferences/content-display/index.tsx"],"names":[],"mappings":"AAmBA,OAAO,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAkB3D,UAAU,6BAA8B,SAAQ,0BAA0B,CAAC,wBAAwB;IACjG,QAAQ,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,0BAA0B,CAAC,kBAAkB,CAAC,KAAK,IAAI,CAAC;IACxF,KAAK,CAAC,EAAE,aAAa,CAAC,0BAA0B,CAAC,kBAAkB,CAAC,CAAC;CACtE;AAqJD,MAAM,CAAC,OAAO,UAAU,wBAAwB,CAAC,EAC/C,KAAK,EACL,WAAW,EACX,OAAO,EACP,KAGG,EACH,MAAM,EACN,QAAQ,EACR,qBAA6B,EAC7B,WAAW,EACX,GAAG,QAAQ,EACZ,EAAE,6BAA6B,eAgJ/B"}
@@ -11,53 +11,89 @@ import InternalSpaceBetween from '../../space-between/internal';
11
11
  import InternalTextFilter from '../../text-filter/internal';
12
12
  import { getAnalyticsInnerContextAttribute } from '../analytics-metadata/utils';
13
13
  import ContentDisplayOption from './content-display-option';
14
- import { getFilteredOptions, getSortedOptions } from './utils';
14
+ import { buildOptionTree, getFilteredOptions, getFilteredTree, getSortedOptions, toContentDisplayItems, } from './utils';
15
15
  import styles from '../styles.css.js';
16
16
  const componentPrefix = 'content-display';
17
17
  const getClassName = (suffix) => styles[`${componentPrefix}-${suffix}`];
18
+ function getDndI18nStrings(i18n, props) {
19
+ return {
20
+ liveAnnouncementDndStarted: i18n('contentDisplayPreference.liveAnnouncementDndStarted', props.liveAnnouncementDndStarted, formatDndStarted),
21
+ liveAnnouncementDndItemReordered: i18n('contentDisplayPreference.liveAnnouncementDndItemReordered', props.liveAnnouncementDndItemReordered, formatDndItemReordered),
22
+ liveAnnouncementDndItemCommitted: i18n('contentDisplayPreference.liveAnnouncementDndItemCommitted', props.liveAnnouncementDndItemCommitted, formatDndItemCommitted),
23
+ liveAnnouncementDndDiscarded: i18n('contentDisplayPreference.liveAnnouncementDndDiscarded', props.liveAnnouncementDndDiscarded),
24
+ dragHandleAriaLabel: i18n('contentDisplayPreference.dragHandleAriaLabel', props.dragHandleAriaLabel),
25
+ dragHandleAriaDescription: i18n('contentDisplayPreference.dragHandleAriaDescription', props.dragHandleAriaDescription),
26
+ };
27
+ }
28
+ function GroupItem({ node, onToggle, onChildrenChange, i18nStrings, sortDisabled, groupLabelFormatter, }) {
29
+ return (React.createElement("div", { "data-item-type": "group" },
30
+ React.createElement(InternalSpaceBetween, { size: "xxs" },
31
+ React.createElement("div", { className: styles['content-display-group-header'] },
32
+ React.createElement(InternalBox, { fontWeight: "bold", display: "inline" }, node.label)),
33
+ node.children.length > 0 && (React.createElement("div", { className: styles['content-display-group-children'] },
34
+ React.createElement(HierarchicalContentDisplay, { tree: node.children, onToggle: onToggle, onTreeChange: onChildrenChange, i18nStrings: i18nStrings, sortDisabled: sortDisabled, ariaLabel: node.label, parentGroupLabel: node.label, groupLabelFormatter: groupLabelFormatter }))))));
35
+ }
36
+ function HierarchicalContentDisplay({ tree, onToggle, onTreeChange, ariaLabel, ariaLabelledby, ariaDescribedby, i18nStrings, sortDisabled, parentGroupLabel, groupLabelFormatter, }) {
37
+ return (React.createElement(InternalList, { items: tree, sortDisabled: sortDisabled, sortable: true, disableItemPaddings: true, ariaLabel: ariaLabel, ariaLabelledby: ariaLabelledby, ariaDescribedby: ariaDescribedby, i18nStrings: i18nStrings, onSortingChange: ({ detail: { items } }) => onTreeChange([...items]), renderItem: node => ({
38
+ id: node.id,
39
+ announcementLabel: node.type === 'group'
40
+ ? groupLabelFormatter(node.label, node.children.length)
41
+ : parentGroupLabel
42
+ ? `${node.label}, ${parentGroupLabel}`
43
+ : node.label,
44
+ content: node.type === 'group' ? (React.createElement(GroupItem, { node: node, onToggle: onToggle, onChildrenChange: newChildren => onTreeChange(tree.map(n => (n.id === node.id && n.type === 'group' ? { ...n, children: newChildren } : n))), i18nStrings: i18nStrings, sortDisabled: sortDisabled, groupLabelFormatter: groupLabelFormatter })) : (React.createElement(ContentDisplayOption, { option: node, onToggle: () => onToggle(node.id) })),
45
+ }) }));
46
+ }
18
47
  export default function ContentDisplayPreference({ title, description, options, value = options.map(({ id }) => ({
19
48
  id,
20
49
  visible: true,
21
- })), onChange, liveAnnouncementDndStarted, liveAnnouncementDndItemReordered, liveAnnouncementDndItemCommitted, liveAnnouncementDndDiscarded, dragHandleAriaDescription, dragHandleAriaLabel, enableColumnFiltering = false, i18nStrings, }) {
50
+ })), groups, onChange, enableColumnFiltering = false, i18nStrings, ...dndProps }) {
51
+ var _a;
22
52
  const idPrefix = useUniqueId(componentPrefix);
23
53
  const i18n = useInternalI18n('collection-preferences');
24
54
  const [columnFilteringText, setColumnFilteringText] = useState('');
25
55
  const titleId = `${idPrefix}-title`;
26
56
  const descriptionId = `${idPrefix}-description`;
27
- const [sortedOptions, sortedAndFilteredOptions] = useMemo(() => {
28
- const sorted = getSortedOptions({ options, contentDisplay: value });
29
- const filtered = getFilteredOptions(sorted, columnFilteringText);
30
- return [sorted, filtered];
31
- }, [columnFilteringText, options, value]);
32
- const onToggle = (option) => {
33
- // We use sortedOptions as base and not value because there might be options that
34
- // are not in the value yet, so they're added as non-visible after the known ones.
35
- onChange(sortedOptions.map(({ id, visible }) => ({ id, visible: id === option.id ? !option.visible : visible })));
57
+ const listI18nStrings = getDndI18nStrings(i18n, dndProps);
58
+ const groupLabelFormatter = (label, count) => {
59
+ var _a, _b;
60
+ return i18n('contentDisplayPreference.liveAnnouncementDndGroupLabel', (_b = (_a = dndProps.liveAnnouncementDndGroupLabel) === null || _a === void 0 ? void 0 : _a.call(dndProps, label, count)) !== null && _b !== void 0 ? _b : `${label}, ${count} ${count === 1 ? 'item' : 'items'}`, format => format({ label, count }));
61
+ };
62
+ const hasGroups = !!groups && groups.length > 0;
63
+ const isFiltering = columnFilteringText.trim().length > 0;
64
+ const sortedOptions = useMemo(() => getSortedOptions({ options, contentDisplay: value }), [options, value]);
65
+ const filteredOptions = useMemo(() => getFilteredOptions(sortedOptions, columnFilteringText), [sortedOptions, columnFilteringText]);
66
+ const optionTree = useMemo(() => (hasGroups ? buildOptionTree(options, groups, value) : null), [hasGroups, groups, options, value]);
67
+ const filteredTree = useMemo(() => (optionTree ? getFilteredTree(optionTree, columnFilteringText) : null), [optionTree, columnFilteringText]);
68
+ const handleToggle = (id) => {
69
+ // For flat (non-grouped) mode, rebuild from sortedOptions to handle items not in value
70
+ if (!hasGroups) {
71
+ onChange(sortedOptions.map(opt => ({ id: opt.id, visible: opt.id === id ? !opt.visible : opt.visible })));
72
+ return;
73
+ }
74
+ // For grouped mode, walk the tree and flip the matching item
75
+ const toggle = (items) => items.map(item => {
76
+ if (item.type === 'group') {
77
+ return { ...item, children: toggle(item.children) };
78
+ }
79
+ return item.id === id ? { ...item, visible: !item.visible } : item;
80
+ });
81
+ onChange(toggle(value));
36
82
  };
83
+ const noResults = filteredTree ? filteredTree.length === 0 : filteredOptions.length === 0;
37
84
  return (React.createElement("div", { role: "group", "aria-labelledby": titleId, "aria-describedby": descriptionId, className: styles[componentPrefix], ...getAnalyticsInnerContextAttribute('contentDisplay') },
38
85
  React.createElement("h3", { className: getClassName('title'), id: titleId }, i18n('contentDisplayPreference.title', title)),
39
86
  React.createElement("p", { className: getClassName('description'), id: descriptionId }, i18n('contentDisplayPreference.description', description)),
40
87
  enableColumnFiltering && (React.createElement("div", { className: getClassName('text-filter') },
41
- React.createElement(InternalTextFilter, { filteringText: columnFilteringText, filteringPlaceholder: i18n('contentDisplayPreference.i18nStrings.columnFilteringPlaceholder', i18nStrings === null || i18nStrings === void 0 ? void 0 : i18nStrings.columnFilteringPlaceholder), filteringAriaLabel: i18n('contentDisplayPreference.i18nStrings.columnFilteringAriaLabel', i18nStrings === null || i18nStrings === void 0 ? void 0 : i18nStrings.columnFilteringAriaLabel), filteringClearAriaLabel: i18n('contentDisplayPreference.i18nStrings.columnFilteringClearFilterText', i18nStrings === null || i18nStrings === void 0 ? void 0 : i18nStrings.columnFilteringClearFilterText), onChange: ({ detail }) => setColumnFilteringText(detail.filteringText), countText: i18n('contentDisplayPreference.i18nStrings.columnFilteringCountText', (i18nStrings === null || i18nStrings === void 0 ? void 0 : i18nStrings.columnFilteringCountText)
42
- ? i18nStrings === null || i18nStrings === void 0 ? void 0 : i18nStrings.columnFilteringCountText(sortedAndFilteredOptions.length)
43
- : undefined, format => format({ count: sortedAndFilteredOptions.length })) }))),
44
- sortedAndFilteredOptions.length === 0 && (React.createElement("div", { className: getClassName('no-match') },
88
+ React.createElement(InternalTextFilter, { filteringText: columnFilteringText, filteringPlaceholder: i18n('contentDisplayPreference.i18nStrings.columnFilteringPlaceholder', i18nStrings === null || i18nStrings === void 0 ? void 0 : i18nStrings.columnFilteringPlaceholder), filteringAriaLabel: i18n('contentDisplayPreference.i18nStrings.columnFilteringAriaLabel', i18nStrings === null || i18nStrings === void 0 ? void 0 : i18nStrings.columnFilteringAriaLabel), filteringClearAriaLabel: i18n('contentDisplayPreference.i18nStrings.columnFilteringClearFilterText', i18nStrings === null || i18nStrings === void 0 ? void 0 : i18nStrings.columnFilteringClearFilterText), onChange: ({ detail }) => setColumnFilteringText(detail.filteringText), countText: i18n('contentDisplayPreference.i18nStrings.columnFilteringCountText', (_a = i18nStrings === null || i18nStrings === void 0 ? void 0 : i18nStrings.columnFilteringCountText) === null || _a === void 0 ? void 0 : _a.call(i18nStrings, filteredOptions.length), format => format({ count: filteredOptions.length })) }))),
89
+ noResults && (React.createElement("div", { className: getClassName('no-match') },
45
90
  React.createElement(InternalSpaceBetween, { size: "s", alignItems: "center" },
46
91
  React.createElement(InternalBox, { margin: { top: 'm' } }, i18n('contentDisplayPreference.i18nStrings.columnFilteringNoMatchText', i18nStrings === null || i18nStrings === void 0 ? void 0 : i18nStrings.columnFilteringNoMatchText)),
47
92
  React.createElement(InternalButton, { onClick: () => setColumnFilteringText('') }, i18n('contentDisplayPreference.i18nStrings.columnFilteringClearFilterText', i18nStrings === null || i18nStrings === void 0 ? void 0 : i18nStrings.columnFilteringClearFilterText))))),
48
- React.createElement(InternalList, { items: sortedAndFilteredOptions, renderItem: item => ({
93
+ React.createElement("div", { role: "application", "aria-labelledby": titleId }, optionTree && filteredTree ? (React.createElement(HierarchicalContentDisplay, { tree: isFiltering ? filteredTree : optionTree, onToggle: handleToggle, onTreeChange: newTree => onChange(toContentDisplayItems(newTree)), ariaLabelledby: titleId, ariaDescribedby: descriptionId, i18nStrings: listI18nStrings, sortDisabled: isFiltering, groupLabelFormatter: groupLabelFormatter })) : (React.createElement(InternalList, { items: filteredOptions, sortable: true, sortDisabled: isFiltering, disableItemPaddings: true, ariaLabelledby: titleId, ariaDescribedby: descriptionId, i18nStrings: listI18nStrings, onSortingChange: ({ detail: { items } }) => onChange(items.map(({ id, visible }) => ({ id, visible }))), renderItem: item => ({
49
94
  id: item.id,
50
- content: React.createElement(ContentDisplayOption, { option: item, onToggle: onToggle }),
51
95
  announcementLabel: item.label,
52
- }), disableItemPaddings: true, sortable: true, sortDisabled: columnFilteringText.trim().length > 0, onSortingChange: ({ detail: { items } }) => {
53
- onChange(items);
54
- }, ariaDescribedby: descriptionId, ariaLabelledby: titleId, i18nStrings: {
55
- liveAnnouncementDndStarted: i18n('contentDisplayPreference.liveAnnouncementDndStarted', liveAnnouncementDndStarted, formatDndStarted),
56
- liveAnnouncementDndItemReordered: i18n('contentDisplayPreference.liveAnnouncementDndItemReordered', liveAnnouncementDndItemReordered, formatDndItemReordered),
57
- liveAnnouncementDndItemCommitted: i18n('contentDisplayPreference.liveAnnouncementDndItemCommitted', liveAnnouncementDndItemCommitted, formatDndItemCommitted),
58
- liveAnnouncementDndDiscarded: i18n('contentDisplayPreference.liveAnnouncementDndDiscarded', liveAnnouncementDndDiscarded),
59
- dragHandleAriaLabel: i18n('contentDisplayPreference.dragHandleAriaLabel', dragHandleAriaLabel),
60
- dragHandleAriaDescription: i18n('contentDisplayPreference.dragHandleAriaDescription', dragHandleAriaDescription),
61
- } })));
96
+ content: React.createElement(ContentDisplayOption, { option: item, onToggle: () => handleToggle(item.id) }),
97
+ }) })))));
62
98
  }
63
99
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":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B;gBACD,mBAAmB,EAAE,IAAI,CAAC,8CAA8C,EAAE,mBAAmB,CAAC;gBAC9F,yBAAyB,EAAE,IAAI,CAC7B,oDAAoD,EACpD,yBAAyB,CAC1B;aACF,GACD,CACE,CACP,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useMemo, useState } from 'react';\n\nimport { useUniqueId } from '@cloudscape-design/component-toolkit/internal';\n\nimport InternalBox from '../../box/internal';\nimport InternalButton from '../../button/internal';\nimport { useInternalI18n } from '../../i18n/context';\nimport {\n formatDndItemCommitted,\n formatDndItemReordered,\n formatDndStarted,\n} from '../../internal/components/sortable-area/use-live-announcements';\nimport InternalList from '../../list/internal';\nimport InternalSpaceBetween from '../../space-between/internal';\nimport InternalTextFilter from '../../text-filter/internal';\nimport { getAnalyticsInnerContextAttribute } from '../analytics-metadata/utils';\nimport { CollectionPreferencesProps } from '../interfaces';\nimport ContentDisplayOption from './content-display-option';\nimport { getFilteredOptions, getSortedOptions, OptionWithVisibility } from './utils';\n\nimport styles from '../styles.css.js';\n\nconst componentPrefix = 'content-display';\n\nconst getClassName = (suffix: string) => styles[`${componentPrefix}-${suffix}`];\n\ninterface ContentDisplayPreferenceProps extends CollectionPreferencesProps.ContentDisplayPreference {\n onChange: (value: ReadonlyArray<CollectionPreferencesProps.ContentDisplayItem>) => void;\n value?: ReadonlyArray<CollectionPreferencesProps.ContentDisplayItem>;\n}\n\nexport default function ContentDisplayPreference({\n title,\n description,\n options,\n value = options.map(({ id }) => ({\n id,\n visible: true,\n })),\n onChange,\n liveAnnouncementDndStarted,\n liveAnnouncementDndItemReordered,\n liveAnnouncementDndItemCommitted,\n liveAnnouncementDndDiscarded,\n dragHandleAriaDescription,\n dragHandleAriaLabel,\n enableColumnFiltering = false,\n i18nStrings,\n}: ContentDisplayPreferenceProps) {\n const idPrefix = useUniqueId(componentPrefix);\n const i18n = useInternalI18n('collection-preferences');\n const [columnFilteringText, setColumnFilteringText] = useState('');\n\n const titleId = `${idPrefix}-title`;\n const descriptionId = `${idPrefix}-description`;\n\n const [sortedOptions, sortedAndFilteredOptions] = useMemo(() => {\n const sorted = getSortedOptions({ options, contentDisplay: value });\n const filtered = getFilteredOptions(sorted, columnFilteringText);\n return [sorted, filtered];\n }, [columnFilteringText, options, value]);\n\n const onToggle = (option: OptionWithVisibility) => {\n // We use sortedOptions as base and not value because there might be options that\n // are not in the value yet, so they're added as non-visible after the known ones.\n onChange(sortedOptions.map(({ id, visible }) => ({ id, visible: id === option.id ? !option.visible : visible })));\n };\n\n return (\n <div\n role=\"group\"\n aria-labelledby={titleId}\n aria-describedby={descriptionId}\n className={styles[componentPrefix]}\n {...getAnalyticsInnerContextAttribute('contentDisplay')}\n >\n <h3 className={getClassName('title')} id={titleId}>\n {i18n('contentDisplayPreference.title', title)}\n </h3>\n <p className={getClassName('description')} id={descriptionId}>\n {i18n('contentDisplayPreference.description', description)}\n </p>\n\n {/* Filter input */}\n {enableColumnFiltering && (\n <div className={getClassName('text-filter')}>\n <InternalTextFilter\n filteringText={columnFilteringText}\n filteringPlaceholder={i18n(\n 'contentDisplayPreference.i18nStrings.columnFilteringPlaceholder',\n i18nStrings?.columnFilteringPlaceholder\n )}\n filteringAriaLabel={i18n(\n 'contentDisplayPreference.i18nStrings.columnFilteringAriaLabel',\n i18nStrings?.columnFilteringAriaLabel\n )}\n filteringClearAriaLabel={i18n(\n 'contentDisplayPreference.i18nStrings.columnFilteringClearFilterText',\n i18nStrings?.columnFilteringClearFilterText\n )}\n onChange={({ detail }) => setColumnFilteringText(detail.filteringText)}\n countText={i18n(\n 'contentDisplayPreference.i18nStrings.columnFilteringCountText',\n i18nStrings?.columnFilteringCountText\n ? i18nStrings?.columnFilteringCountText(sortedAndFilteredOptions.length)\n : undefined,\n format => format({ count: sortedAndFilteredOptions.length })\n )}\n />\n </div>\n )}\n\n {/* No match */}\n {sortedAndFilteredOptions.length === 0 && (\n <div className={getClassName('no-match')}>\n <InternalSpaceBetween size=\"s\" alignItems=\"center\">\n <InternalBox margin={{ top: 'm' }}>\n {i18n(\n 'contentDisplayPreference.i18nStrings.columnFilteringNoMatchText',\n i18nStrings?.columnFilteringNoMatchText\n )}\n </InternalBox>\n <InternalButton onClick={() => setColumnFilteringText('')}>\n {i18n(\n 'contentDisplayPreference.i18nStrings.columnFilteringClearFilterText',\n i18nStrings?.columnFilteringClearFilterText\n )}\n </InternalButton>\n </InternalSpaceBetween>\n </div>\n )}\n\n <InternalList\n items={sortedAndFilteredOptions}\n renderItem={item => ({\n id: item.id,\n content: <ContentDisplayOption option={item} onToggle={onToggle} />,\n announcementLabel: item.label,\n })}\n disableItemPaddings={true}\n sortable={true}\n sortDisabled={columnFilteringText.trim().length > 0}\n onSortingChange={({ detail: { items } }) => {\n onChange(items);\n }}\n ariaDescribedby={descriptionId}\n ariaLabelledby={titleId}\n i18nStrings={{\n liveAnnouncementDndStarted: i18n(\n 'contentDisplayPreference.liveAnnouncementDndStarted',\n liveAnnouncementDndStarted,\n formatDndStarted\n ),\n liveAnnouncementDndItemReordered: i18n(\n 'contentDisplayPreference.liveAnnouncementDndItemReordered',\n liveAnnouncementDndItemReordered,\n formatDndItemReordered\n ),\n liveAnnouncementDndItemCommitted: i18n(\n 'contentDisplayPreference.liveAnnouncementDndItemCommitted',\n liveAnnouncementDndItemCommitted,\n formatDndItemCommitted\n ),\n liveAnnouncementDndDiscarded: i18n(\n 'contentDisplayPreference.liveAnnouncementDndDiscarded',\n liveAnnouncementDndDiscarded\n ),\n dragHandleAriaLabel: i18n('contentDisplayPreference.dragHandleAriaLabel', dragHandleAriaLabel),\n dragHandleAriaDescription: i18n(\n 'contentDisplayPreference.dragHandleAriaDescription',\n dragHandleAriaDescription\n ),\n }}\n />\n </div>\n );\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/collection-preferences/content-display/index.tsx"],"names":[],"mappings":"AAAA,qEAAqE;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tB,YAAY,EAAE,OAAO,CAAC,EAAE,CAAC,QAAQ,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,EACjE,cAAc,EAAE,OAAO,EACvB,eAAe,EAAE,aAAa,EAC9B,WAAW,EAAE,eAAe,EAC5B,YAAY,EAAE,WAAW,EACzB,mBAAmB,EAAE,mBAAmB,GACxC,CACH,CAAC,CAAC,CAAC,CACF,oBAAC,YAAY,IACX,KAAK,EAAE,eAAe,EACtB,QAAQ,EAAE,IAAI,EACd,YAAY,EAAE,WAAW,EACzB,mBAAmB,EAAE,IAAI,EACzB,cAAc,EAAE,OAAO,EACvB,eAAe,EAAE,aAAa,EAC9B,WAAW,EAAE,eAAe,EAC5B,eAAe,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EACvG,UAAU,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;gBACnB,EAAE,EAAE,IAAI,CAAC,EAAE;gBACX,iBAAiB,EAAE,IAAI,CAAC,KAAK;gBAC7B,OAAO,EAAE,oBAAC,oBAAoB,IAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,GAAI;aACvF,CAAC,GACF,CACH,CACG,CACF,CACP,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useMemo, useState } from 'react';\n\nimport { useUniqueId } from '@cloudscape-design/component-toolkit/internal';\n\nimport InternalBox from '../../box/internal';\nimport InternalButton from '../../button/internal';\nimport { useInternalI18n } from '../../i18n/context';\nimport { SortableAreaProps } from '../../internal/components/sortable-area/interfaces';\nimport {\n formatDndItemCommitted,\n formatDndItemReordered,\n formatDndStarted,\n} from '../../internal/components/sortable-area/use-live-announcements';\nimport InternalList from '../../list/internal';\nimport InternalSpaceBetween from '../../space-between/internal';\nimport InternalTextFilter from '../../text-filter/internal';\nimport { getAnalyticsInnerContextAttribute } from '../analytics-metadata/utils';\nimport { CollectionPreferencesProps } from '../interfaces';\nimport ContentDisplayOption from './content-display-option';\nimport {\n buildOptionTree,\n getFilteredOptions,\n getFilteredTree,\n getSortedOptions,\n OptionGroupNode,\n OptionTreeNode,\n toContentDisplayItems,\n} from './utils';\n\nimport styles from '../styles.css.js';\n\nconst componentPrefix = 'content-display';\n\nconst getClassName = (suffix: string) => styles[`${componentPrefix}-${suffix}`];\n\ninterface ContentDisplayPreferenceProps extends CollectionPreferencesProps.ContentDisplayPreference {\n onChange: (value: ReadonlyArray<CollectionPreferencesProps.ContentDisplayItem>) => void;\n value?: ReadonlyArray<CollectionPreferencesProps.ContentDisplayItem>;\n}\nfunction getDndI18nStrings(\n i18n: ReturnType<typeof useInternalI18n<'collection-preferences'>>,\n props: Pick<\n ContentDisplayPreferenceProps,\n | 'liveAnnouncementDndStarted'\n | 'liveAnnouncementDndItemReordered'\n | 'liveAnnouncementDndItemCommitted'\n | 'liveAnnouncementDndDiscarded'\n | 'dragHandleAriaLabel'\n | 'dragHandleAriaDescription'\n >\n) {\n return {\n liveAnnouncementDndStarted: i18n(\n 'contentDisplayPreference.liveAnnouncementDndStarted',\n props.liveAnnouncementDndStarted,\n formatDndStarted\n ),\n liveAnnouncementDndItemReordered: i18n(\n 'contentDisplayPreference.liveAnnouncementDndItemReordered',\n props.liveAnnouncementDndItemReordered,\n formatDndItemReordered\n ),\n liveAnnouncementDndItemCommitted: i18n(\n 'contentDisplayPreference.liveAnnouncementDndItemCommitted',\n props.liveAnnouncementDndItemCommitted,\n formatDndItemCommitted\n ),\n liveAnnouncementDndDiscarded: i18n(\n 'contentDisplayPreference.liveAnnouncementDndDiscarded',\n props.liveAnnouncementDndDiscarded\n ),\n dragHandleAriaLabel: i18n('contentDisplayPreference.dragHandleAriaLabel', props.dragHandleAriaLabel),\n dragHandleAriaDescription: i18n(\n 'contentDisplayPreference.dragHandleAriaDescription',\n props.dragHandleAriaDescription\n ),\n };\n}\n\ninterface HierarchicalContentDisplayProps {\n tree: OptionTreeNode[];\n onToggle: (id: string) => void;\n onTreeChange: (newTree: OptionTreeNode[]) => void;\n ariaLabel?: string;\n ariaLabelledby?: string;\n ariaDescribedby?: string;\n i18nStrings: SortableAreaProps.DndAreaI18nStrings;\n sortDisabled: boolean;\n parentGroupLabel?: string;\n groupLabelFormatter: (label: string, count: number) => string;\n}\n\nfunction GroupItem({\n node,\n onToggle,\n onChildrenChange,\n i18nStrings,\n sortDisabled,\n groupLabelFormatter,\n}: {\n node: OptionGroupNode;\n onToggle: (id: string) => void;\n onChildrenChange: (children: OptionTreeNode[]) => void;\n i18nStrings: SortableAreaProps.DndAreaI18nStrings;\n sortDisabled: boolean;\n groupLabelFormatter: (label: string, count: number) => string;\n}) {\n return (\n <div data-item-type=\"group\">\n <InternalSpaceBetween size=\"xxs\">\n <div className={styles['content-display-group-header']}>\n <InternalBox fontWeight=\"bold\" display=\"inline\">\n {node.label}\n </InternalBox>\n </div>\n {node.children.length > 0 && (\n <div className={styles['content-display-group-children']}>\n <HierarchicalContentDisplay\n tree={node.children}\n onToggle={onToggle}\n onTreeChange={onChildrenChange}\n i18nStrings={i18nStrings}\n sortDisabled={sortDisabled}\n ariaLabel={node.label}\n parentGroupLabel={node.label}\n groupLabelFormatter={groupLabelFormatter}\n />\n </div>\n )}\n </InternalSpaceBetween>\n </div>\n );\n}\n\nfunction HierarchicalContentDisplay({\n tree,\n onToggle,\n onTreeChange,\n ariaLabel,\n ariaLabelledby,\n ariaDescribedby,\n i18nStrings,\n sortDisabled,\n parentGroupLabel,\n groupLabelFormatter,\n}: HierarchicalContentDisplayProps) {\n return (\n <InternalList\n items={tree}\n sortDisabled={sortDisabled}\n sortable={true}\n disableItemPaddings={true}\n ariaLabel={ariaLabel}\n ariaLabelledby={ariaLabelledby}\n ariaDescribedby={ariaDescribedby}\n i18nStrings={i18nStrings}\n onSortingChange={({ detail: { items } }) => onTreeChange([...items])}\n renderItem={node => ({\n id: node.id,\n announcementLabel:\n node.type === 'group'\n ? groupLabelFormatter(node.label, node.children.length)\n : parentGroupLabel\n ? `${node.label}, ${parentGroupLabel}`\n : node.label,\n content:\n node.type === 'group' ? (\n <GroupItem\n node={node}\n onToggle={onToggle}\n onChildrenChange={newChildren =>\n onTreeChange(\n tree.map(n => (n.id === node.id && n.type === 'group' ? { ...n, children: newChildren } : n))\n )\n }\n i18nStrings={i18nStrings}\n sortDisabled={sortDisabled}\n groupLabelFormatter={groupLabelFormatter}\n />\n ) : (\n <ContentDisplayOption option={node} onToggle={() => onToggle(node.id)} />\n ),\n })}\n />\n );\n}\n\nexport default function ContentDisplayPreference({\n title,\n description,\n options,\n value = options.map(({ id }) => ({\n id,\n visible: true,\n })),\n groups,\n onChange,\n enableColumnFiltering = false,\n i18nStrings,\n ...dndProps\n}: ContentDisplayPreferenceProps) {\n const idPrefix = useUniqueId(componentPrefix);\n const i18n = useInternalI18n('collection-preferences');\n const [columnFilteringText, setColumnFilteringText] = useState('');\n\n const titleId = `${idPrefix}-title`;\n const descriptionId = `${idPrefix}-description`;\n\n const listI18nStrings = getDndI18nStrings(i18n, dndProps);\n const groupLabelFormatter = (label: string, count: number) =>\n i18n(\n 'contentDisplayPreference.liveAnnouncementDndGroupLabel',\n dndProps.liveAnnouncementDndGroupLabel?.(label, count) ?? `${label}, ${count} ${count === 1 ? 'item' : 'items'}`,\n format => format({ label, count })\n );\n const hasGroups = !!groups && groups.length > 0;\n const isFiltering = columnFilteringText.trim().length > 0;\n\n const sortedOptions = useMemo(() => getSortedOptions({ options, contentDisplay: value }), [options, value]);\n const filteredOptions = useMemo(\n () => getFilteredOptions(sortedOptions, columnFilteringText),\n [sortedOptions, columnFilteringText]\n );\n const optionTree = useMemo(\n () => (hasGroups ? buildOptionTree(options, groups, value) : null),\n [hasGroups, groups, options, value]\n );\n const filteredTree = useMemo(\n () => (optionTree ? getFilteredTree(optionTree, columnFilteringText) : null),\n [optionTree, columnFilteringText]\n );\n\n const handleToggle = (id: string) => {\n // For flat (non-grouped) mode, rebuild from sortedOptions to handle items not in value\n if (!hasGroups) {\n onChange(sortedOptions.map(opt => ({ id: opt.id, visible: opt.id === id ? !opt.visible : opt.visible })));\n return;\n }\n // For grouped mode, walk the tree and flip the matching item\n const toggle = (\n items: ReadonlyArray<CollectionPreferencesProps.ContentDisplayItem>\n ): CollectionPreferencesProps.ContentDisplayItem[] =>\n items.map(item => {\n if (item.type === 'group') {\n return { ...item, children: toggle(item.children) };\n }\n return item.id === id ? { ...item, visible: !item.visible } : item;\n });\n onChange(toggle(value));\n };\n const noResults = filteredTree ? filteredTree.length === 0 : filteredOptions.length === 0;\n return (\n <div\n role=\"group\"\n aria-labelledby={titleId}\n aria-describedby={descriptionId}\n className={styles[componentPrefix]}\n {...getAnalyticsInnerContextAttribute('contentDisplay')}\n >\n <h3 className={getClassName('title')} id={titleId}>\n {i18n('contentDisplayPreference.title', title)}\n </h3>\n <p className={getClassName('description')} id={descriptionId}>\n {i18n('contentDisplayPreference.description', description)}\n </p>\n\n {/* Filter input */}\n {enableColumnFiltering && (\n <div className={getClassName('text-filter')}>\n <InternalTextFilter\n filteringText={columnFilteringText}\n filteringPlaceholder={i18n(\n 'contentDisplayPreference.i18nStrings.columnFilteringPlaceholder',\n i18nStrings?.columnFilteringPlaceholder\n )}\n filteringAriaLabel={i18n(\n 'contentDisplayPreference.i18nStrings.columnFilteringAriaLabel',\n i18nStrings?.columnFilteringAriaLabel\n )}\n filteringClearAriaLabel={i18n(\n 'contentDisplayPreference.i18nStrings.columnFilteringClearFilterText',\n i18nStrings?.columnFilteringClearFilterText\n )}\n onChange={({ detail }) => setColumnFilteringText(detail.filteringText)}\n countText={i18n(\n 'contentDisplayPreference.i18nStrings.columnFilteringCountText',\n i18nStrings?.columnFilteringCountText?.(filteredOptions.length),\n format => format({ count: filteredOptions.length })\n )}\n />\n </div>\n )}\n\n {noResults && (\n <div className={getClassName('no-match')}>\n <InternalSpaceBetween size=\"s\" alignItems=\"center\">\n <InternalBox margin={{ top: 'm' }}>\n {i18n(\n 'contentDisplayPreference.i18nStrings.columnFilteringNoMatchText',\n i18nStrings?.columnFilteringNoMatchText\n )}\n </InternalBox>\n <InternalButton onClick={() => setColumnFilteringText('')}>\n {i18n(\n 'contentDisplayPreference.i18nStrings.columnFilteringClearFilterText',\n i18nStrings?.columnFilteringClearFilterText\n )}\n </InternalButton>\n </InternalSpaceBetween>\n </div>\n )}\n\n <div role=\"application\" aria-labelledby={titleId}>\n {optionTree && filteredTree ? (\n <HierarchicalContentDisplay\n tree={isFiltering ? filteredTree : optionTree}\n onToggle={handleToggle}\n onTreeChange={newTree => onChange(toContentDisplayItems(newTree))}\n ariaLabelledby={titleId}\n ariaDescribedby={descriptionId}\n i18nStrings={listI18nStrings}\n sortDisabled={isFiltering}\n groupLabelFormatter={groupLabelFormatter}\n />\n ) : (\n <InternalList\n items={filteredOptions}\n sortable={true}\n sortDisabled={isFiltering}\n disableItemPaddings={true}\n ariaLabelledby={titleId}\n ariaDescribedby={descriptionId}\n i18nStrings={listI18nStrings}\n onSortingChange={({ detail: { items } }) => onChange(items.map(({ id, visible }) => ({ id, visible })))}\n renderItem={item => ({\n id: item.id,\n announcementLabel: item.label,\n content: <ContentDisplayOption option={item} onToggle={() => handleToggle(item.id)} />,\n })}\n />\n )}\n </div>\n </div>\n );\n}\n"]}
@@ -1,7 +1,32 @@
1
1
  import { CollectionPreferencesProps } from '../interfaces';
2
- export interface OptionWithVisibility extends CollectionPreferencesProps.ContentDisplayOption {
2
+ type ContentDisplayItem = CollectionPreferencesProps.ContentDisplayItem;
3
+ type ContentDisplayOption = CollectionPreferencesProps.ContentDisplayOption;
4
+ type ContentDisplayOptionGroup = CollectionPreferencesProps.ContentDisplayOptionGroup;
5
+ export interface OptionWithVisibility extends ContentDisplayOption {
3
6
  visible: boolean;
4
7
  }
8
+ export interface OptionGroupNode {
9
+ type: 'group';
10
+ id: string;
11
+ label: string;
12
+ visible: boolean;
13
+ children: OptionTreeNode[];
14
+ }
15
+ export interface OptionLeafNode extends OptionWithVisibility {
16
+ type: 'leaf';
17
+ }
18
+ export type OptionTreeNode = OptionGroupNode | OptionLeafNode;
19
+ /**
20
+ * Extracts a flat ordered list of leaf items from the contentDisplay tree (depth-first).
21
+ */
22
+ export declare function walkLeaves(items: ReadonlyArray<ContentDisplayItem>): {
23
+ id: string;
24
+ visible: boolean;
25
+ }[];
26
+ /**
27
+ * Returns options ordered by contentDisplay, with visibility applied.
28
+ * Options not in contentDisplay are appended as non-visible.
29
+ */
5
30
  export declare function getSortedOptions({
6
31
  options,
7
32
  contentDisplay
@@ -9,4 +34,18 @@ export declare function getSortedOptions({
9
34
  options: ReadonlyArray<CollectionPreferencesProps.ContentDisplayOption>;
10
35
  contentDisplay: ReadonlyArray<CollectionPreferencesProps.ContentDisplayItem>;
11
36
  }): ReadonlyArray<OptionWithVisibility>;
12
- export declare function getFilteredOptions(options: ReadonlyArray<OptionWithVisibility>, filterText: string): readonly OptionWithVisibility[];
37
+ /**
38
+ * Converts contentDisplay tree into an internal OptionTreeNode tree,
39
+ * resolving labels from options/groups definitions.
40
+ */
41
+ export declare function buildOptionTree(options: ReadonlyArray<ContentDisplayOption>, groups: ReadonlyArray<ContentDisplayOptionGroup>, contentDisplay: ReadonlyArray<ContentDisplayItem>): OptionTreeNode[];
42
+ /**
43
+ * Converts OptionTreeNode[] back to ContentDisplayItem[].
44
+ */
45
+ export declare function toContentDisplayItems(tree: OptionTreeNode[]): ContentDisplayItem[];
46
+ /**
47
+ * Filters tree, keeping leaves matching filterText and groups with matching descendants.
48
+ */
49
+ export declare function getFilteredTree(tree: OptionTreeNode[], filterText: string): OptionTreeNode[];
50
+ export declare function getFilteredOptions(options: ReadonlyArray<OptionWithVisibility>, filterText: string): readonly OptionWithVisibility[];
51
+ export {};
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/collection-preferences/content-display/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAE3D,MAAM,WAAW,oBAAqB,SAAQ,0BAA0B,CAAC,oBAAoB;IAC3F,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,wBAAgB,gBAAgB,CAAC,EAC/B,OAAO,EACP,cAAc,GACf,EAAE;IACD,OAAO,EAAE,aAAa,CAAC,0BAA0B,CAAC,oBAAoB,CAAC,CAAC;IACxE,cAAc,EAAE,aAAa,CAAC,0BAA0B,CAAC,kBAAkB,CAAC,CAAC;CAC9E,GAAG,aAAa,CAAC,oBAAoB,CAAC,CActC;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,aAAa,CAAC,oBAAoB,CAAC,EAAE,UAAU,EAAE,MAAM,mCAQlG"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/collection-preferences/content-display/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAE3D,KAAK,kBAAkB,GAAG,0BAA0B,CAAC,kBAAkB,CAAC;AACxE,KAAK,oBAAoB,GAAG,0BAA0B,CAAC,oBAAoB,CAAC;AAC5E,KAAK,yBAAyB,GAAG,0BAA0B,CAAC,yBAAyB,CAAC;AAEtF,MAAM,WAAW,oBAAqB,SAAQ,oBAAoB;IAChE,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,OAAO,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,cAAc,EAAE,CAAC;CAC5B;AAED,MAAM,WAAW,cAAe,SAAQ,oBAAoB;IAC1D,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,cAAc,GAAG,eAAe,GAAG,cAAc,CAAC;AAE9D;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,aAAa,CAAC,kBAAkB,CAAC,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,EAAE,CAUvG;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,OAAO,EACP,cAAc,GACf,EAAE;IACD,OAAO,EAAE,aAAa,CAAC,0BAA0B,CAAC,oBAAoB,CAAC,CAAC;IACxE,cAAc,EAAE,aAAa,CAAC,0BAA0B,CAAC,kBAAkB,CAAC,CAAC;CAC9E,GAAG,aAAa,CAAC,oBAAoB,CAAC,CAkBtC;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,aAAa,CAAC,oBAAoB,CAAC,EAC5C,MAAM,EAAE,aAAa,CAAC,yBAAyB,CAAC,EAChD,cAAc,EAAE,aAAa,CAAC,kBAAkB,CAAC,GAChD,cAAc,EAAE,CAgClB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,cAAc,EAAE,GAAG,kBAAkB,EAAE,CAYlF;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,cAAc,EAAE,EAAE,UAAU,EAAE,MAAM,GAAG,cAAc,EAAE,CAkB5F;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,aAAa,CAAC,oBAAoB,CAAC,EAAE,UAAU,EAAE,MAAM,mCAMlG"}
@@ -1,23 +1,117 @@
1
+ /**
2
+ * Extracts a flat ordered list of leaf items from the contentDisplay tree (depth-first).
3
+ */
4
+ export function walkLeaves(items) {
5
+ const result = [];
6
+ for (const item of items) {
7
+ if (item.type === 'group') {
8
+ result.push(...walkLeaves(item.children));
9
+ }
10
+ else {
11
+ result.push({ id: item.id, visible: item.visible });
12
+ }
13
+ }
14
+ return result;
15
+ }
16
+ /**
17
+ * Returns options ordered by contentDisplay, with visibility applied.
18
+ * Options not in contentDisplay are appended as non-visible.
19
+ */
1
20
  export function getSortedOptions({ options, contentDisplay, }) {
2
- // By using a Map, we are guaranteed to preserve insertion order on future iteration.
3
- const optionsById = new Map();
4
- // We insert contentDisplay first so we respect the currently selected order
5
- for (const { id, visible } of contentDisplay) {
6
- // If an option is provided in contentDisplay and not options, we default the label to the id
7
- optionsById.set(id, { id, label: id, visible });
21
+ const optionMap = new Map(options.map(o => [o.id, o]));
22
+ const result = new Map();
23
+ for (const { id, visible } of walkLeaves(contentDisplay)) {
24
+ const option = optionMap.get(id);
25
+ if (option) {
26
+ result.set(id, { ...option, visible });
27
+ }
8
28
  }
9
- // We merge options data, and insert any that were not in contentDisplay as non-visible
10
29
  for (const option of options) {
11
- const existing = optionsById.get(option.id);
12
- optionsById.set(option.id, { ...option, visible: !!(existing === null || existing === void 0 ? void 0 : existing.visible) });
30
+ if (!result.has(option.id)) {
31
+ result.set(option.id, { ...option, visible: false });
32
+ }
33
+ }
34
+ return Array.from(result.values());
35
+ }
36
+ /**
37
+ * Converts contentDisplay tree into an internal OptionTreeNode tree,
38
+ * resolving labels from options/groups definitions.
39
+ */
40
+ export function buildOptionTree(options, groups, contentDisplay) {
41
+ if (!groups.length) {
42
+ const sorted = getSortedOptions({ options, contentDisplay });
43
+ return sorted.map(opt => ({ ...opt, type: 'leaf' }));
44
+ }
45
+ const optionMap = new Map(options.map(o => [o.id, o]));
46
+ const groupMap = new Map(groups.map(g => [g.id, g]));
47
+ const convert = (items) => {
48
+ var _a;
49
+ const result = [];
50
+ for (const item of items) {
51
+ if (item.type === 'group') {
52
+ const group = groupMap.get(item.id);
53
+ result.push({
54
+ type: 'group',
55
+ id: item.id,
56
+ label: (_a = group === null || group === void 0 ? void 0 : group.label) !== null && _a !== void 0 ? _a : item.id,
57
+ visible: item.visible,
58
+ children: convert(item.children),
59
+ });
60
+ }
61
+ else {
62
+ const option = optionMap.get(item.id);
63
+ if (option) {
64
+ result.push({ type: 'leaf', ...option, visible: item.visible });
65
+ }
66
+ }
67
+ }
68
+ return result;
69
+ };
70
+ return convert(contentDisplay);
71
+ }
72
+ /**
73
+ * Converts OptionTreeNode[] back to ContentDisplayItem[].
74
+ */
75
+ export function toContentDisplayItems(tree) {
76
+ return tree.map(node => {
77
+ if (node.type === 'group') {
78
+ return {
79
+ type: 'group',
80
+ id: node.id,
81
+ visible: node.visible,
82
+ children: toContentDisplayItems(node.children),
83
+ };
84
+ }
85
+ return { id: node.id, visible: node.visible };
86
+ });
87
+ }
88
+ /**
89
+ * Filters tree, keeping leaves matching filterText and groups with matching descendants.
90
+ */
91
+ export function getFilteredTree(tree, filterText) {
92
+ const text = filterText.trim().toLowerCase();
93
+ if (!text) {
94
+ return tree;
95
+ }
96
+ const result = [];
97
+ for (const node of tree) {
98
+ if (node.type === 'group') {
99
+ const children = getFilteredTree(node.children, text);
100
+ if (children.length > 0) {
101
+ result.push({ ...node, children });
102
+ }
103
+ }
104
+ else if (node.label.toLowerCase().includes(text)) {
105
+ result.push(node);
106
+ }
13
107
  }
14
- return Array.from(optionsById.values());
108
+ return result;
15
109
  }
16
110
  export function getFilteredOptions(options, filterText) {
17
- filterText = filterText.trim().toLowerCase();
18
- if (!filterText) {
111
+ const text = filterText.trim().toLowerCase();
112
+ if (!text) {
19
113
  return options;
20
114
  }
21
- return options.filter(option => option.label.toLowerCase().trim().includes(filterText));
115
+ return options.filter(option => option.label.toLowerCase().includes(text));
22
116
  }
23
117
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/collection-preferences/content-display/utils.ts"],"names":[],"mappings":"AAQA,MAAM,UAAU,gBAAgB,CAAC,EAC/B,OAAO,EACP,cAAc,GAIf;IACC,qFAAqF;IACrF,MAAM,WAAW,GAAG,IAAI,GAAG,EAAgC,CAAC;IAC5D,4EAA4E;IAC5E,KAAK,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,cAAc,EAAE,CAAC;QAC7C,6FAA6F;QAC7F,WAAW,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;IAClD,CAAC;IACD,uFAAuF;IACvF,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC5C,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,OAAO,CAAA,EAAE,CAAC,CAAC;IAC1E,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,OAA4C,EAAE,UAAkB;IACjG,UAAU,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAE7C,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,OAAO,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC;AAC1F,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { CollectionPreferencesProps } from '../interfaces';\n\nexport interface OptionWithVisibility extends CollectionPreferencesProps.ContentDisplayOption {\n visible: boolean;\n}\n\nexport function getSortedOptions({\n options,\n contentDisplay,\n}: {\n options: ReadonlyArray<CollectionPreferencesProps.ContentDisplayOption>;\n contentDisplay: ReadonlyArray<CollectionPreferencesProps.ContentDisplayItem>;\n}): ReadonlyArray<OptionWithVisibility> {\n // By using a Map, we are guaranteed to preserve insertion order on future iteration.\n const optionsById = new Map<string, OptionWithVisibility>();\n // We insert contentDisplay first so we respect the currently selected order\n for (const { id, visible } of contentDisplay) {\n // If an option is provided in contentDisplay and not options, we default the label to the id\n optionsById.set(id, { id, label: id, visible });\n }\n // We merge options data, and insert any that were not in contentDisplay as non-visible\n for (const option of options) {\n const existing = optionsById.get(option.id);\n optionsById.set(option.id, { ...option, visible: !!existing?.visible });\n }\n return Array.from(optionsById.values());\n}\n\nexport function getFilteredOptions(options: ReadonlyArray<OptionWithVisibility>, filterText: string) {\n filterText = filterText.trim().toLowerCase();\n\n if (!filterText) {\n return options;\n }\n\n return options.filter(option => option.label.toLowerCase().trim().includes(filterText));\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/collection-preferences/content-display/utils.ts"],"names":[],"mappings":"AA0BA;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,KAAwC;IACjE,MAAM,MAAM,GAAuC,EAAE,CAAC;IACtD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YAC1B,MAAM,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC5C,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,EAC/B,OAAO,EACP,cAAc,GAIf;IACC,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,G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BAAkB,CAAC,OAA4C,EAAE,UAAkB;IACjG,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC7C,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,OAAO,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;AAC7E,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { CollectionPreferencesProps } from '../interfaces';\n\ntype ContentDisplayItem = CollectionPreferencesProps.ContentDisplayItem;\ntype ContentDisplayOption = CollectionPreferencesProps.ContentDisplayOption;\ntype ContentDisplayOptionGroup = CollectionPreferencesProps.ContentDisplayOptionGroup;\n\nexport interface OptionWithVisibility extends ContentDisplayOption {\n visible: boolean;\n}\n\nexport interface OptionGroupNode {\n type: 'group';\n id: string;\n label: string;\n visible: boolean;\n children: OptionTreeNode[];\n}\n\nexport interface OptionLeafNode extends OptionWithVisibility {\n type: 'leaf';\n}\n\nexport type OptionTreeNode = OptionGroupNode | OptionLeafNode;\n\n/**\n * Extracts a flat ordered list of leaf items from the contentDisplay tree (depth-first).\n */\nexport function walkLeaves(items: ReadonlyArray<ContentDisplayItem>): { id: string; visible: boolean }[] {\n const result: { id: string; visible: boolean }[] = [];\n for (const item of items) {\n if (item.type === 'group') {\n result.push(...walkLeaves(item.children));\n } else {\n result.push({ id: item.id, visible: item.visible });\n }\n }\n return result;\n}\n\n/**\n * Returns options ordered by contentDisplay, with visibility applied.\n * Options not in contentDisplay are appended as non-visible.\n */\nexport function getSortedOptions({\n options,\n contentDisplay,\n}: {\n options: ReadonlyArray<CollectionPreferencesProps.ContentDisplayOption>;\n contentDisplay: ReadonlyArray<CollectionPreferencesProps.ContentDisplayItem>;\n}): ReadonlyArray<OptionWithVisibility> {\n const optionMap = new Map(options.map(o => [o.id, o]));\n const result = new Map<string, OptionWithVisibility>();\n\n for (const { id, visible } of walkLeaves(contentDisplay)) {\n const option = optionMap.get(id);\n if (option) {\n result.set(id, { ...option, visible });\n }\n }\n\n for (const option of options) {\n if (!result.has(option.id)) {\n result.set(option.id, { ...option, visible: false });\n }\n }\n\n return Array.from(result.values());\n}\n\n/**\n * Converts contentDisplay tree into an internal OptionTreeNode tree,\n * resolving labels from options/groups definitions.\n */\nexport function buildOptionTree(\n options: ReadonlyArray<ContentDisplayOption>,\n groups: ReadonlyArray<ContentDisplayOptionGroup>,\n contentDisplay: ReadonlyArray<ContentDisplayItem>\n): OptionTreeNode[] {\n if (!groups.length) {\n const sorted = getSortedOptions({ options, contentDisplay });\n return sorted.map(opt => ({ ...opt, type: 'leaf' as const }));\n }\n\n const optionMap = new Map(options.map(o => [o.id, o]));\n const groupMap = new Map(groups.map(g => [g.id, g]));\n\n const convert = (items: ReadonlyArray<ContentDisplayItem>): OptionTreeNode[] => {\n const result: OptionTreeNode[] = [];\n for (const item of items) {\n if (item.type === 'group') {\n const group = groupMap.get(item.id);\n result.push({\n type: 'group',\n id: item.id,\n label: group?.label ?? item.id,\n visible: item.visible,\n children: convert(item.children),\n });\n } else {\n const option = optionMap.get(item.id);\n if (option) {\n result.push({ type: 'leaf', ...option, visible: item.visible });\n }\n }\n }\n return result;\n };\n\n return convert(contentDisplay);\n}\n\n/**\n * Converts OptionTreeNode[] back to ContentDisplayItem[].\n */\nexport function toContentDisplayItems(tree: OptionTreeNode[]): ContentDisplayItem[] {\n return tree.map(node => {\n if (node.type === 'group') {\n return {\n type: 'group' as const,\n id: node.id,\n visible: node.visible,\n children: toContentDisplayItems(node.children),\n };\n }\n return { id: node.id, visible: node.visible };\n });\n}\n\n/**\n * Filters tree, keeping leaves matching filterText and groups with matching descendants.\n */\nexport function getFilteredTree(tree: OptionTreeNode[], filterText: string): OptionTreeNode[] {\n const text = filterText.trim().toLowerCase();\n if (!text) {\n return tree;\n }\n\n const result: OptionTreeNode[] = [];\n for (const node of tree) {\n if (node.type === 'group') {\n const children = getFilteredTree(node.children, text);\n if (children.length > 0) {\n result.push({ ...node, children });\n }\n } else if (node.label.toLowerCase().includes(text)) {\n result.push(node);\n }\n }\n return result;\n}\n\nexport function getFilteredOptions(options: ReadonlyArray<OptionWithVisibility>, filterText: string) {\n const text = filterText.trim().toLowerCase();\n if (!text) {\n return options;\n }\n return options.filter(option => option.label.toLowerCase().includes(text));\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/collection-preferences/index.tsx"],"names":[],"mappings":"AAwBA,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAiB1D,OAAO,EAAE,0BAA0B,EAAE,CAAC;AAItC,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAAC,EAC5C,KAAK,EACL,YAAY,EACZ,WAAW,EACX,cAAc,EACd,QAAgB,EAChB,SAAS,EACT,QAAQ,EACR,wBAAwB,EACxB,wBAAwB,EACxB,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,wBAAwB,EACxB,uBAAuB,EACvB,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,aAAa,EACb,GAAG,IAAI,EACR,EAAE,0BAA0B,eAiO5B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/collection-preferences/index.tsx"],"names":[],"mappings":"AAwBA,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAkB1D,OAAO,EAAE,0BAA0B,EAAE,CAAC;AAItC,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAAC,EAC5C,KAAK,EACL,YAAY,EACZ,WAAW,EACX,cAAc,EACd,QAAgB,EAChB,SAAS,EACT,QAAQ,EACR,wBAAwB,EACxB,wBAAwB,EACxB,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,wBAAwB,EACxB,uBAAuB,EACvB,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,aAAa,EACb,GAAG,IAAI,EACR,EAAE,0BAA0B,eAkO5B"}
@@ -19,7 +19,7 @@ import InternalModal from '../modal/internal';
19
19
  import InternalSpaceBetween from '../space-between/internal';
20
20
  import { getComponentAnalyticsMetadata } from './analytics-metadata/utils';
21
21
  import ContentDisplayPreference from './content-display';
22
- import { ContentDensityPreference, copyPreferences, CustomPreference, mergePreferences, ModalContentLayout, PageSizePreference, StickyColumnsPreference, StripedRowsPreference, WrapLinesPreference, } from './utils';
22
+ import { collectVisibleIds, ContentDensityPreference, copyPreferences, CustomPreference, mergePreferences, ModalContentLayout, PageSizePreference, StickyColumnsPreference, StripedRowsPreference, WrapLinesPreference, } from './utils';
23
23
  import VisibleContentPreference from './visible-content';
24
24
  import analyticsSelectors from './analytics-metadata/styles.css.js';
25
25
  import styles from './styles.css.js';
@@ -86,7 +86,7 @@ export default function CollectionPreferences({ title, confirmLabel, cancelLabel
86
86
  tableComponentContext.preferencesRef.current.pageSize = preferences === null || preferences === void 0 ? void 0 : preferences.pageSize;
87
87
  // When both are used contentDisplayPreference takes preference and so we always prefer to use this as our visible columns if available
88
88
  if (preferences === null || preferences === void 0 ? void 0 : preferences.contentDisplay) {
89
- tableComponentContext.preferencesRef.current.visibleColumns = preferences === null || preferences === void 0 ? void 0 : preferences.contentDisplay.filter(column => column.visible).map(column => column.id);
89
+ tableComponentContext.preferencesRef.current.visibleColumns = collectVisibleIds(preferences.contentDisplay, true);
90
90
  }
91
91
  else if (preferences === null || preferences === void 0 ? void 0 : preferences.visibleContent) {
92
92
  tableComponentContext.preferencesRef.current.visibleColumns = [...preferences.visibleContent];