@flipdish/ui-library 0.67.0 → 0.68.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/README.md +31 -31
  2. package/dist/components/atoms/PhoneInput/hooks/usePhoneEntry.cjs +13 -30
  3. package/dist/components/atoms/PhoneInput/hooks/usePhoneEntry.cjs.map +1 -1
  4. package/dist/components/atoms/PhoneInput/hooks/usePhoneEntry.d.ts.map +1 -1
  5. package/dist/components/atoms/PhoneInput/hooks/usePhoneEntry.js +10 -27
  6. package/dist/components/atoms/PhoneInput/hooks/usePhoneEntry.js.map +1 -1
  7. package/dist/components/atoms/PhoneInput/utilities/phoneEntry.utils.cjs +55 -0
  8. package/dist/components/atoms/PhoneInput/utilities/phoneEntry.utils.cjs.map +1 -0
  9. package/dist/components/atoms/PhoneInput/utilities/phoneEntry.utils.d.ts +56 -0
  10. package/dist/components/atoms/PhoneInput/utilities/phoneEntry.utils.d.ts.map +1 -0
  11. package/dist/components/atoms/PhoneInput/utilities/phoneEntry.utils.js +52 -0
  12. package/dist/components/atoms/PhoneInput/utilities/phoneEntry.utils.js.map +1 -0
  13. package/dist/components/molecules/EmptyState/index.cjs +4 -2
  14. package/dist/components/molecules/EmptyState/index.cjs.map +1 -1
  15. package/dist/components/molecules/EmptyState/index.d.ts.map +1 -1
  16. package/dist/components/molecules/EmptyState/index.js +4 -2
  17. package/dist/components/molecules/EmptyState/index.js.map +1 -1
  18. package/dist/components/molecules/Pagination/index.d.ts +1 -1
  19. package/dist/components/molecules/Pagination/index.d.ts.map +1 -1
  20. package/dist/components/molecules/Paginations/Pagination/Pagination.cjs +21 -5
  21. package/dist/components/molecules/Paginations/Pagination/Pagination.cjs.map +1 -1
  22. package/dist/components/molecules/Paginations/Pagination/Pagination.d.ts +7 -1
  23. package/dist/components/molecules/Paginations/Pagination/Pagination.d.ts.map +1 -1
  24. package/dist/components/molecules/Paginations/Pagination/Pagination.js +22 -6
  25. package/dist/components/molecules/Paginations/Pagination/Pagination.js.map +1 -1
  26. package/dist/components/molecules/Paginations/components/PaginationBase.cjs +2 -2
  27. package/dist/components/molecules/Paginations/components/PaginationBase.cjs.map +1 -1
  28. package/dist/components/molecules/Paginations/components/PaginationBase.d.ts +4 -2
  29. package/dist/components/molecules/Paginations/components/PaginationBase.d.ts.map +1 -1
  30. package/dist/components/molecules/Paginations/components/PaginationBase.js +2 -2
  31. package/dist/components/molecules/Paginations/components/PaginationBase.js.map +1 -1
  32. package/dist/components/molecules/Paginations/utilities/paginationScroll.utils.cjs +125 -0
  33. package/dist/components/molecules/Paginations/utilities/paginationScroll.utils.cjs.map +1 -0
  34. package/dist/components/molecules/Paginations/utilities/paginationScroll.utils.d.ts +42 -0
  35. package/dist/components/molecules/Paginations/utilities/paginationScroll.utils.d.ts.map +1 -0
  36. package/dist/components/molecules/Paginations/utilities/paginationScroll.utils.js +118 -0
  37. package/dist/components/molecules/Paginations/utilities/paginationScroll.utils.js.map +1 -0
  38. package/dist/components/organisms/FilterBar/index.cjs +3 -1
  39. package/dist/components/organisms/FilterBar/index.cjs.map +1 -1
  40. package/dist/components/organisms/FilterBar/index.d.ts.map +1 -1
  41. package/dist/components/organisms/FilterBar/index.js +3 -1
  42. package/dist/components/organisms/FilterBar/index.js.map +1 -1
  43. package/dist/components/organisms/Table/components/TableCardList.cjs +27 -0
  44. package/dist/components/organisms/Table/components/TableCardList.cjs.map +1 -0
  45. package/dist/components/organisms/Table/components/TableCardList.d.ts +4 -0
  46. package/dist/components/organisms/Table/components/TableCardList.d.ts.map +1 -0
  47. package/dist/components/organisms/Table/components/TableCardList.js +25 -0
  48. package/dist/components/organisms/Table/components/TableCardList.js.map +1 -0
  49. package/dist/components/organisms/Table/components/TableCardRow.cjs +80 -0
  50. package/dist/components/organisms/Table/components/TableCardRow.cjs.map +1 -0
  51. package/dist/components/organisms/Table/components/TableCardRow.d.ts +4 -0
  52. package/dist/components/organisms/Table/components/TableCardRow.d.ts.map +1 -0
  53. package/dist/components/organisms/Table/components/TableCardRow.js +78 -0
  54. package/dist/components/organisms/Table/components/TableCardRow.js.map +1 -0
  55. package/dist/components/organisms/Table/components/TableCardsSelectAll.cjs +24 -0
  56. package/dist/components/organisms/Table/components/TableCardsSelectAll.cjs.map +1 -0
  57. package/dist/components/organisms/Table/components/TableCardsSelectAll.d.ts +13 -0
  58. package/dist/components/organisms/Table/components/TableCardsSelectAll.d.ts.map +1 -0
  59. package/dist/components/organisms/Table/components/TableCardsSelectAll.js +22 -0
  60. package/dist/components/organisms/Table/components/TableCardsSelectAll.js.map +1 -0
  61. package/dist/components/organisms/Table/components/TableFallbackCard.cjs +12 -0
  62. package/dist/components/organisms/Table/components/TableFallbackCard.cjs.map +1 -0
  63. package/dist/components/organisms/Table/components/TableFallbackCard.d.ts +6 -0
  64. package/dist/components/organisms/Table/components/TableFallbackCard.d.ts.map +1 -0
  65. package/dist/components/organisms/Table/components/TableFallbackCard.js +10 -0
  66. package/dist/components/organisms/Table/components/TableFallbackCard.js.map +1 -0
  67. package/dist/components/organisms/Table/components/TableFocusGuard.cjs +23 -0
  68. package/dist/components/organisms/Table/components/TableFocusGuard.cjs.map +1 -0
  69. package/dist/components/organisms/Table/components/TableFocusGuard.d.ts +2 -0
  70. package/dist/components/organisms/Table/components/TableFocusGuard.d.ts.map +1 -0
  71. package/dist/components/organisms/Table/components/TableFocusGuard.js +21 -0
  72. package/dist/components/organisms/Table/components/TableFocusGuard.js.map +1 -0
  73. package/dist/components/organisms/Table/components/TableLayoutToggle.cjs +27 -0
  74. package/dist/components/organisms/Table/components/TableLayoutToggle.cjs.map +1 -0
  75. package/dist/components/organisms/Table/components/TableLayoutToggle.d.ts +17 -0
  76. package/dist/components/organisms/Table/components/TableLayoutToggle.d.ts.map +1 -0
  77. package/dist/components/organisms/Table/components/TableLayoutToggle.js +25 -0
  78. package/dist/components/organisms/Table/components/TableLayoutToggle.js.map +1 -0
  79. package/dist/components/organisms/Table/components/TableRowCard.cjs +79 -0
  80. package/dist/components/organisms/Table/components/TableRowCard.cjs.map +1 -0
  81. package/dist/components/organisms/Table/components/TableRowCard.d.ts +71 -0
  82. package/dist/components/organisms/Table/components/TableRowCard.d.ts.map +1 -0
  83. package/dist/components/organisms/Table/components/TableRowCard.js +72 -0
  84. package/dist/components/organisms/Table/components/TableRowCard.js.map +1 -0
  85. package/dist/components/organisms/Table/components/TableSortMenu.cjs +48 -0
  86. package/dist/components/organisms/Table/components/TableSortMenu.cjs.map +1 -0
  87. package/dist/components/organisms/Table/components/TableSortMenu.d.ts +35 -0
  88. package/dist/components/organisms/Table/components/TableSortMenu.d.ts.map +1 -0
  89. package/dist/components/organisms/Table/components/TableSortMenu.js +46 -0
  90. package/dist/components/organisms/Table/components/TableSortMenu.js.map +1 -0
  91. package/dist/components/organisms/Table/hooks/useFirstSortDirection.cjs +25 -0
  92. package/dist/components/organisms/Table/hooks/useFirstSortDirection.cjs.map +1 -0
  93. package/dist/components/organisms/Table/hooks/useFirstSortDirection.d.ts +12 -0
  94. package/dist/components/organisms/Table/hooks/useFirstSortDirection.d.ts.map +1 -0
  95. package/dist/components/organisms/Table/hooks/useFirstSortDirection.js +23 -0
  96. package/dist/components/organisms/Table/hooks/useFirstSortDirection.js.map +1 -0
  97. package/dist/components/organisms/Table/hooks/useIsAtLeastMd.cjs +21 -0
  98. package/dist/components/organisms/Table/hooks/useIsAtLeastMd.cjs.map +1 -0
  99. package/dist/components/organisms/Table/hooks/useIsAtLeastMd.d.ts +9 -0
  100. package/dist/components/organisms/Table/hooks/useIsAtLeastMd.d.ts.map +1 -0
  101. package/dist/components/organisms/Table/hooks/useIsAtLeastMd.js +19 -0
  102. package/dist/components/organisms/Table/hooks/useIsAtLeastMd.js.map +1 -0
  103. package/dist/components/organisms/Table/hooks/usePlaceholderRows.cjs +43 -0
  104. package/dist/components/organisms/Table/hooks/usePlaceholderRows.cjs.map +1 -0
  105. package/dist/components/organisms/Table/hooks/usePlaceholderRows.d.ts +23 -0
  106. package/dist/components/organisms/Table/hooks/usePlaceholderRows.d.ts.map +1 -0
  107. package/dist/components/organisms/Table/hooks/usePlaceholderRows.js +40 -0
  108. package/dist/components/organisms/Table/hooks/usePlaceholderRows.js.map +1 -0
  109. package/dist/components/organisms/Table/hooks/useSelectableRowRegistry.cjs +20 -2
  110. package/dist/components/organisms/Table/hooks/useSelectableRowRegistry.cjs.map +1 -1
  111. package/dist/components/organisms/Table/hooks/useSelectableRowRegistry.d.ts +8 -4
  112. package/dist/components/organisms/Table/hooks/useSelectableRowRegistry.d.ts.map +1 -1
  113. package/dist/components/organisms/Table/hooks/useSelectableRowRegistry.js +21 -3
  114. package/dist/components/organisms/Table/hooks/useSelectableRowRegistry.js.map +1 -1
  115. package/dist/components/organisms/Table/hooks/useTableSelection.cjs +47 -0
  116. package/dist/components/organisms/Table/hooks/useTableSelection.cjs.map +1 -0
  117. package/dist/components/organisms/Table/hooks/useTableSelection.d.ts +31 -0
  118. package/dist/components/organisms/Table/hooks/useTableSelection.d.ts.map +1 -0
  119. package/dist/components/organisms/Table/hooks/useTableSelection.js +45 -0
  120. package/dist/components/organisms/Table/hooks/useTableSelection.js.map +1 -0
  121. package/dist/components/organisms/Table/index.cjs +169 -38
  122. package/dist/components/organisms/Table/index.cjs.map +1 -1
  123. package/dist/components/organisms/Table/index.d.ts +57 -20
  124. package/dist/components/organisms/Table/index.d.ts.map +1 -1
  125. package/dist/components/organisms/Table/index.js +162 -33
  126. package/dist/components/organisms/Table/index.js.map +1 -1
  127. package/dist/components/organisms/Table/providers/Table.context.cjs +19 -0
  128. package/dist/components/organisms/Table/providers/Table.context.cjs.map +1 -0
  129. package/dist/components/organisms/Table/providers/Table.context.d.ts +44 -0
  130. package/dist/components/organisms/Table/providers/Table.context.d.ts.map +1 -0
  131. package/dist/components/organisms/Table/providers/Table.context.js +13 -0
  132. package/dist/components/organisms/Table/providers/Table.context.js.map +1 -0
  133. package/dist/components/organisms/Table/table.types.d.ts +35 -0
  134. package/dist/components/organisms/Table/table.types.d.ts.map +1 -0
  135. package/dist/components/organisms/Table/utilities/tableCard.utils.cjs +197 -0
  136. package/dist/components/organisms/Table/utilities/tableCard.utils.cjs.map +1 -0
  137. package/dist/components/organisms/Table/utilities/tableCard.utils.d.ts +161 -0
  138. package/dist/components/organisms/Table/utilities/tableCard.utils.d.ts.map +1 -0
  139. package/dist/components/organisms/Table/utilities/tableCard.utils.js +180 -0
  140. package/dist/components/organisms/Table/utilities/tableCard.utils.js.map +1 -0
  141. package/dist/components/organisms/Table/utilities/tableChildren.utils.cjs +47 -0
  142. package/dist/components/organisms/Table/utilities/tableChildren.utils.cjs.map +1 -0
  143. package/dist/components/organisms/Table/utilities/tableChildren.utils.d.ts +39 -0
  144. package/dist/components/organisms/Table/utilities/tableChildren.utils.d.ts.map +1 -0
  145. package/dist/components/organisms/Table/utilities/tableChildren.utils.js +43 -0
  146. package/dist/components/organisms/Table/utilities/tableChildren.utils.js.map +1 -0
  147. package/dist/components/organisms/Table/utilities/tableSelection.utils.cjs +106 -0
  148. package/dist/components/organisms/Table/utilities/tableSelection.utils.cjs.map +1 -0
  149. package/dist/components/organisms/Table/utilities/tableSelection.utils.d.ts +82 -0
  150. package/dist/components/organisms/Table/utilities/tableSelection.utils.d.ts.map +1 -0
  151. package/dist/components/organisms/Table/utilities/tableSelection.utils.js +98 -0
  152. package/dist/components/organisms/Table/utilities/tableSelection.utils.js.map +1 -0
  153. package/dist/components/organisms/Table/utilities/tableSort.utils.cjs +87 -0
  154. package/dist/components/organisms/Table/utilities/tableSort.utils.cjs.map +1 -0
  155. package/dist/components/organisms/Table/utilities/tableSort.utils.d.ts +67 -0
  156. package/dist/components/organisms/Table/utilities/tableSort.utils.d.ts.map +1 -0
  157. package/dist/components/organisms/Table/utilities/tableSort.utils.js +79 -0
  158. package/dist/components/organisms/Table/utilities/tableSort.utils.js.map +1 -0
  159. package/dist/utilities/searchParamsUtils/index.cjs +2 -9
  160. package/dist/utilities/searchParamsUtils/index.cjs.map +1 -1
  161. package/dist/utilities/searchParamsUtils/index.d.ts +5 -3
  162. package/dist/utilities/searchParamsUtils/index.d.ts.map +1 -1
  163. package/dist/utilities/searchParamsUtils/index.js +2 -9
  164. package/dist/utilities/searchParamsUtils/index.js.map +1 -1
  165. package/package.json +1 -1
  166. package/dist/components/organisms/Table/table.utils.cjs +0 -61
  167. package/dist/components/organisms/Table/table.utils.cjs.map +0 -1
  168. package/dist/components/organisms/Table/table.utils.d.ts +0 -48
  169. package/dist/components/organisms/Table/table.utils.d.ts.map +0 -1
  170. package/dist/components/organisms/Table/table.utils.js +0 -55
  171. package/dist/components/organisms/Table/table.utils.js.map +0 -1
@@ -0,0 +1,197 @@
1
+ 'use strict';
2
+
3
+ var testIdUtils = require('@flipdish/ui-library/utilities/testIdUtils');
4
+ var React = require('react');
5
+ var filterDOMProps = require('react-aria/filterDOMProps');
6
+ var tableChildren_utils = require('./tableChildren.utils.cjs');
7
+
8
+ /**
9
+ * Picks the layout a table renders from the viewport, the two layout props, and whether react-aria virtualizes it.
10
+ * @param isAtLeastMd - Whether the viewport is `md` or wider; `false` where `matchMedia` is missing or never matches.
11
+ * @param mobileLayout - What the table asked for below `md`.
12
+ * @param desktopLayout - What the table asked for from `md` up.
13
+ * @param isVirtualized - Whether the table sits in a react-aria `Virtualizer`, whose table layout cannot lay out cards.
14
+ * @returns The table inside a `Virtualizer`; otherwise `desktopLayout` from `md` up and `mobileLayout` below it.
15
+ */
16
+ const tableLayoutOf = (isAtLeastMd, mobileLayout, desktopLayout, isVirtualized = false) => {
17
+ if (isVirtualized)
18
+ return 'table';
19
+ return isAtLeastMd ? desktopLayout : mobileLayout;
20
+ };
21
+ /**
22
+ * Hands the table's remaining props to the card list unchanged; react-aria filters them there as it does for the table.
23
+ * The parameter's type is the guard: props that still carry a table-only prop, such as `style`, fail typecheck.
24
+ * @param props - The table's props with every `TableOnlyProp` already taken out.
25
+ * @returns The same object, typed for the card list.
26
+ */
27
+ const cardListPropsOf = (props) => props;
28
+ /**
29
+ * Hands `Table.Body`'s remaining DOM props to the card list unchanged; react-aria filters them there as it does for the body.
30
+ * The parameter's type is the guard: props that still carry a body-only prop, such as `className`, fail typecheck.
31
+ * @param props - The body's props with every `TableBodyOnlyProp` already taken out.
32
+ * @returns The same object, typed for the card list.
33
+ */
34
+ const cardBodyPropsOf = (props) => props;
35
+ /**
36
+ * Hands a react-aria `TableLoadMoreItem`'s props to the card list's `GridListLoadMoreItem`, which takes the same ones.
37
+ * @param props - The table loader's props.
38
+ * @returns The same props for the card list's loader, less the `render`, `className` and `style` written for the table's row,
39
+ * as the body and the rows drop theirs.
40
+ */
41
+ const cardLoadMorePropsOf = ({ render: _tableRowRender, className: _tableRowClassName, style: _tableRowStyle, ...props }) => props;
42
+ /**
43
+ * Hands a row's remaining props to its card's `GridListItem` unchanged; react-aria filters them there as it does for the row.
44
+ * The parameter's type is the guard: props that still carry a row-only prop, such as `style`, fail typecheck.
45
+ * @param props - The row's props with every `TableRowOnlyProp` already taken out.
46
+ * @returns The same object, typed for the card's `GridListItem`.
47
+ */
48
+ const cardRowPropsOf = (props) => props;
49
+ /**
50
+ * Picks from a cell's remaining props what react-aria's `Cell` puts on the table's cell, for the element around the cell's
51
+ * content on a fallback card. The parameter's type is the guard: props that still carry a cell-only prop, such as `colSpan`, fail typecheck.
52
+ * @param props - The cell's props with every `TableCellOnlyProp` already taken out.
53
+ * @returns Its `data-*` attributes, `dir`, `lang`, `hidden`, `inert` and `translate`, and its mouse, pointer, touch, scroll,
54
+ * wheel, animation and transition handlers; nothing the table's cell drops, such as `aria-label`, `tabIndex` or `onKeyDown`.
55
+ */
56
+ const cardCellPropsOf = (props) =>
57
+ // The filter react-aria's `Cell` applies, so the card and the table never disagree on what a cell passes on.
58
+ filterDOMProps.filterDOMProps(props, { global: true });
59
+ /**
60
+ * Derives a row's `data-testid`, the same in both layouts.
61
+ * @param testIdPrefix - The table's resolved id; a row outside a table has none.
62
+ * @param id - The row's id; a row without one gets no derived id.
63
+ * @param override - The row's own `data-testid`, which wins outright.
64
+ * @returns `<root>--row-<id>`, the override, or `undefined`.
65
+ */
66
+ const rowTestIdOf = (testIdPrefix, id, override) => {
67
+ if (override !== undefined)
68
+ return override;
69
+ return testIdPrefix && id !== undefined ? testIdUtils.joinTestId(testIdPrefix, `row-${testIdUtils.slugifyTestId(String(id))}`) : undefined;
70
+ };
71
+ /**
72
+ * Reads the text a node shows, for a name that has to be a string.
73
+ * @param node - Any renderable content. An element's `textValue` prop, as a `Table.Cell` takes, stands for everything in
74
+ * it; otherwise only children are read, never props such as `alt`, so a component that draws its own text reads as empty.
75
+ * @returns The strings and numbers in the node, joined by single spaces; empty when it shows no text.
76
+ */
77
+ const textOfNode = (node) => {
78
+ const collect = (part) => {
79
+ if (typeof part === 'string' || typeof part === 'number')
80
+ return [String(part)];
81
+ if (Array.isArray(part))
82
+ return part.flatMap(collect);
83
+ if (!React.isValidElement(part))
84
+ return [];
85
+ if (typeof part.props.textValue === 'string')
86
+ return [part.props.textValue];
87
+ return collect(part.props.children);
88
+ };
89
+ return collect(node).join(' ').replace(/\s+/g, ' ').trim();
90
+ };
91
+ /**
92
+ * Says whether a card slot, such as a footer's `end` or a header's `badge`, has something to show, so an empty slot leaves
93
+ * no empty box behind.
94
+ * @param node - What the slot was given.
95
+ * @returns `true` for content, `0` included; `false` for `null`, `undefined`, a boolean, as `cond && …` leaves, and `''`.
96
+ */
97
+ const isSlotShown = (node) => node != null && typeof node !== 'boolean' && node !== '';
98
+ /**
99
+ * Names a card row as the table names a row, by its title alone.
100
+ * @param textValue - The row's own `textValue`, which wins outright.
101
+ * @param isPlaceholder - Whether the row carries `Table.RowCard.Skeleton`, which has no text to be named by.
102
+ * @param title - The card's title, or the row-header cell for the fallback card.
103
+ * @returns The row's name; empty when the title shows no text, and then the browser names the row from all of its content.
104
+ */
105
+ const cardRowNameOf = (textValue, isPlaceholder, title) => {
106
+ if (textValue !== undefined)
107
+ return textValue;
108
+ return isPlaceholder ? 'Loading' : textOfNode(title);
109
+ };
110
+ /**
111
+ * Says whether a press on a card does something, for its pointer cursor: the row's action or link, the table's row
112
+ * action, or selection. A placeholder or disabled row does nothing.
113
+ * @param actions - The row's and the table's state; see `CardRowActions`.
114
+ * @returns `true` when a press acts on the row.
115
+ */
116
+ const isCardRowInteractive = ({ isPlaceholder, hasOwnAction, hasRowAction, isDisabled, selectionMode }) => !isPlaceholder && !isDisabled && (hasOwnAction || hasRowAction || selectionMode !== 'none');
117
+ /**
118
+ * Tells when a fallback card cannot label its values from the table's columns.
119
+ * @param columnCount - The columns `Table` found in a `Table.Header` among its direct children.
120
+ * @param cellCount - The columns the row's cells span: each of its direct children other than its card counts its `colSpan`.
121
+ * @returns `'no-columns'` when the table found no columns for a row with cells, as when a wrapper component renders
122
+ * `Table.Header`; `'cell-count'` when the counts differ; `undefined` when every cell has its column.
123
+ */
124
+ const fallbackCardWarningOf = (columnCount, cellCount) => {
125
+ if (cellCount === 0)
126
+ return undefined;
127
+ if (columnCount === 0)
128
+ return 'no-columns';
129
+ return cellCount === columnCount ? undefined : 'cell-count';
130
+ };
131
+ /**
132
+ * Finds the title a declared card shows in its header.
133
+ * @param card - The row's `Table.RowCard` element.
134
+ * @param headerType - The `Table.RowCard.Header` component.
135
+ * @returns The header's `title`, or `undefined` when the card has no header among its direct children.
136
+ */
137
+ const cardTitleOf = (card, headerType) => tableChildren_utils.findElement(card.props.children, headerType)?.props.title;
138
+ /**
139
+ * Reads how many columns a cell spans, as the table lays it out.
140
+ * @param cell - One of the row's cells.
141
+ * @returns Its `colSpan` when that is a whole number above 1; 1 otherwise, as for any cell without one.
142
+ */
143
+ const cellSpanOf = (cell) => {
144
+ const colSpan = React.isValidElement(cell) ? cell.props.colSpan : undefined;
145
+ return typeof colSpan === 'number' && Number.isInteger(colSpan) && colSpan > 1 ? colSpan : 1;
146
+ };
147
+ /**
148
+ * Counts the columns a row's cells cover, for comparing them with the table's columns.
149
+ * @param cells - The row's cells.
150
+ * @returns The sum of each cell's `colSpan`, 1 for a cell without one.
151
+ */
152
+ const spannedColumnCountOf = (cells) => cells.reduce((count, cell) => count + cellSpanOf(cell), 0);
153
+ /**
154
+ * Lays a row's cells out on the fallback card by the column each starts in, as the table lays them out.
155
+ * @param columns - The columns `Table.Header` declares, conditionals already resolved.
156
+ * @param cells - The row's cells, in the same order.
157
+ * @param spanOf - How many columns a cell spans; 1 for each when omitted.
158
+ * @returns The cell starting in the row-header column as the title, the trailing cells and the label/value lines, each value
159
+ * labelled by the column its cell starts in.
160
+ */
161
+ const fallbackCardSlots = (columns, cells, spanOf = () => 1) => {
162
+ const titleColumn = Math.max(columns.findIndex((column) => column.isRowHeader), 0);
163
+ const slots = { trailing: [], lines: [] };
164
+ let nextColumn = 0;
165
+ cells.forEach((cell, index) => {
166
+ const startColumn = nextColumn;
167
+ nextColumn += spanOf(cell);
168
+ if (startColumn === titleColumn) {
169
+ slots.title = cell;
170
+ return;
171
+ }
172
+ const column = columns[startColumn];
173
+ if (column && !column.label)
174
+ slots.trailing.push(cell);
175
+ else
176
+ slots.lines.push({ key: index, label: column?.label, value: cell });
177
+ });
178
+ return slots;
179
+ };
180
+
181
+ exports.cardBodyPropsOf = cardBodyPropsOf;
182
+ exports.cardCellPropsOf = cardCellPropsOf;
183
+ exports.cardListPropsOf = cardListPropsOf;
184
+ exports.cardLoadMorePropsOf = cardLoadMorePropsOf;
185
+ exports.cardRowNameOf = cardRowNameOf;
186
+ exports.cardRowPropsOf = cardRowPropsOf;
187
+ exports.cardTitleOf = cardTitleOf;
188
+ exports.cellSpanOf = cellSpanOf;
189
+ exports.fallbackCardSlots = fallbackCardSlots;
190
+ exports.fallbackCardWarningOf = fallbackCardWarningOf;
191
+ exports.isCardRowInteractive = isCardRowInteractive;
192
+ exports.isSlotShown = isSlotShown;
193
+ exports.rowTestIdOf = rowTestIdOf;
194
+ exports.spannedColumnCountOf = spannedColumnCountOf;
195
+ exports.tableLayoutOf = tableLayoutOf;
196
+ exports.textOfNode = textOfNode;
197
+ //# sourceMappingURL=tableCard.utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tableCard.utils.cjs","sources":["../../../../../src/components/organisms/Table/utilities/tableCard.utils.ts"],"sourcesContent":[null],"names":["filterDOMProps","joinTestId","slugifyTestId","isValidElement","findElement"],"mappings":";;;;;;;AAOA;;;;;;;AAOG;AACI,MAAM,aAAa,GAAG,CAAC,WAAoB,EAAE,YAAyB,EAAE,aAA0B,EAAE,aAAa,GAAG,KAAK,KAAiB;AAC/I,IAAA,IAAI,aAAa;AAAE,QAAA,OAAO,OAAO;IACjC,OAAO,WAAW,GAAG,aAAa,GAAG,YAAY;AACnD;AAKA;;;;;AAKG;AACI,MAAM,eAAe,GAAG,CAAmB,KAA2C,KAC3F;AAKF;;;;;AAKG;AACI,MAAM,eAAe,GAAG,CAAmB,KAA+C,KAC/F;AAEF;;;;;AAKG;AACI,MAAM,mBAAmB,GAAG,CAAC,EAClC,MAAM,EAAE,eAAe,EACvB,SAAS,EAAE,kBAAkB,EAC7B,KAAK,EAAE,cAAc,EACrB,GAAG,KAAK,EACe,KAAgC;AAezD;;;;;AAKG;AACI,MAAM,cAAc,GAAG,CAAmB,KAA8C,KAC7F;AAKF;;;;;;AAMG;AACI,MAAM,eAAe,GAAG,CAAmB,KAA+C;AAC/F;AACAA,6BAAc,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;AAExC;;;;;;AAMG;AACI,MAAM,WAAW,GAAG,CAAC,YAAgC,EAAE,EAAmB,EAAE,QAA4B,KAAwB;IACrI,IAAI,QAAQ,KAAK,SAAS;AAAE,QAAA,OAAO,QAAQ;IAC3C,OAAO,YAAY,IAAI,EAAE,KAAK,SAAS,GAAGC,sBAAU,CAAC,YAAY,EAAE,CAAA,IAAA,EAAOC,yBAAa,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAA,CAAE,CAAC,GAAG,SAAS;AACpH;AAEA;;;;;AAKG;AACI,MAAM,UAAU,GAAG,CAAC,I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B,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,KAAI;QAC5B,MAAM,WAAW,GAAG,UAAU;AAC9B,QAAA,UAAU,IAAI,MAAM,CAAC,IAAI,CAAC;AAC1B,QAAA,IAAI,WAAW,KAAK,WAAW,EAAE;AAC/B,YAAA,KAAK,CAAC,KAAK,GAAG,IAAI;YAClB;QACF;AACA,QAAA,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;AACnC,QAAA,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK;AAAE,YAAA,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;;YACjD,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC1E,IAAA,CAAC,CAAC;AAEF,IAAA,OAAO,KAAK;AACd;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,161 @@
1
+ import { type ReactElement, type ReactNode } from 'react';
2
+ import type { GridListItemProps, GridListLoadMoreItemProps, Key, TableLoadMoreItemProps } from 'react-aria-components';
3
+ import type { TableCardColumn, TableCardListProps, TableLayout } from '../table.types';
4
+ /**
5
+ * Picks the layout a table renders from the viewport, the two layout props, and whether react-aria virtualizes it.
6
+ * @param isAtLeastMd - Whether the viewport is `md` or wider; `false` where `matchMedia` is missing or never matches.
7
+ * @param mobileLayout - What the table asked for below `md`.
8
+ * @param desktopLayout - What the table asked for from `md` up.
9
+ * @param isVirtualized - Whether the table sits in a react-aria `Virtualizer`, whose table layout cannot lay out cards.
10
+ * @returns The table inside a `Virtualizer`; otherwise `desktopLayout` from `md` up and `mobileLayout` below it.
11
+ */
12
+ export declare const tableLayoutOf: (isAtLeastMd: boolean, mobileLayout: TableLayout, desktopLayout: TableLayout, isVirtualized?: boolean) => TableLayout;
13
+ /** Props written for the table alone, which never reach the card list. */
14
+ export type TableOnlyProp = 'className' | 'style' | 'render' | 'children' | 'dragAndDropHooks' | 'sortDescriptor' | 'onSortChange' | 'onRowAction';
15
+ /**
16
+ * Hands the table's remaining props to the card list unchanged; react-aria filters them there as it does for the table.
17
+ * The parameter's type is the guard: props that still carry a table-only prop, such as `style`, fail typecheck.
18
+ * @param props - The table's props with every `TableOnlyProp` already taken out.
19
+ * @returns The same object, typed for the card list.
20
+ */
21
+ export declare const cardListPropsOf: <P extends object>(props: P & { [K in TableOnlyProp]?: never; }) => TableCardListProps;
22
+ /** Props of `Table.Body` written for the table alone, or that the card list sets itself, which never reach its `GridList`. */
23
+ export type TableBodyOnlyProp = 'className' | 'style' | 'render' | 'children' | 'items' | 'dependencies' | 'renderEmptyState' | 'data-testid';
24
+ /**
25
+ * Hands `Table.Body`'s remaining DOM props to the card list unchanged; react-aria filters them there as it does for the body.
26
+ * The parameter's type is the guard: props that still carry a body-only prop, such as `className`, fail typecheck.
27
+ * @param props - The body's props with every `TableBodyOnlyProp` already taken out.
28
+ * @returns The same object, typed for the card list.
29
+ */
30
+ export declare const cardBodyPropsOf: <P extends object>(props: P & { [K in TableBodyOnlyProp]?: never; }) => TableCardListProps;
31
+ /**
32
+ * Hands a react-aria `TableLoadMoreItem`'s props to the card list's `GridListLoadMoreItem`, which takes the same ones.
33
+ * @param props - The table loader's props.
34
+ * @returns The same props for the card list's loader, less the `render`, `className` and `style` written for the table's row,
35
+ * as the body and the rows drop theirs.
36
+ */
37
+ export declare const cardLoadMorePropsOf: ({ render: _tableRowRender, className: _tableRowClassName, style: _tableRowStyle, ...props }: TableLoadMoreItemProps) => GridListLoadMoreItemProps;
38
+ /** Props written for the table's row alone, or that its card sets itself, which never reach the card's `GridListItem`. */
39
+ export type TableRowOnlyProp = 'className' | 'style' | 'render' | 'children' | 'columns' | 'size' | 'highlightSelectedRow' | 'isHighlighted' | 'textValue' | 'data-testid';
40
+ /**
41
+ * Hands a row's remaining props to its card's `GridListItem` unchanged; react-aria filters them there as it does for the row.
42
+ * The parameter's type is the guard: props that still carry a row-only prop, such as `style`, fail typecheck.
43
+ * @param props - The row's props with every `TableRowOnlyProp` already taken out.
44
+ * @returns The same object, typed for the card's `GridListItem`.
45
+ */
46
+ export declare const cardRowPropsOf: <P extends object>(props: P & { [K in TableRowOnlyProp]?: never; }) => GridListItemProps<object>;
47
+ /** Props of `Table.Cell` written for the table's cell alone, which never reach the element around its content on a fallback card. */
48
+ export type TableCellOnlyProp = 'className' | 'style' | 'render' | 'children' | 'colSpan' | 'size' | 'textValue' | 'id';
49
+ /**
50
+ * Picks from a cell's remaining props what react-aria's `Cell` puts on the table's cell, for the element around the cell's
51
+ * content on a fallback card. The parameter's type is the guard: props that still carry a cell-only prop, such as `colSpan`, fail typecheck.
52
+ * @param props - The cell's props with every `TableCellOnlyProp` already taken out.
53
+ * @returns Its `data-*` attributes, `dir`, `lang`, `hidden`, `inert` and `translate`, and its mouse, pointer, touch, scroll,
54
+ * wheel, animation and transition handlers; nothing the table's cell drops, such as `aria-label`, `tabIndex` or `onKeyDown`.
55
+ */
56
+ export declare const cardCellPropsOf: <P extends object>(props: P & { [K in TableCellOnlyProp]?: never; }) => import("@react-types/shared").DOMProps & import("@react-types/shared").AriaLabelingProps & import("@react-types/shared").GlobalDOMAttributes<Element>;
57
+ /**
58
+ * Derives a row's `data-testid`, the same in both layouts.
59
+ * @param testIdPrefix - The table's resolved id; a row outside a table has none.
60
+ * @param id - The row's id; a row without one gets no derived id.
61
+ * @param override - The row's own `data-testid`, which wins outright.
62
+ * @returns `<root>--row-<id>`, the override, or `undefined`.
63
+ */
64
+ export declare const rowTestIdOf: (testIdPrefix: string | undefined, id: Key | undefined, override: string | undefined) => string | undefined;
65
+ /**
66
+ * Reads the text a node shows, for a name that has to be a string.
67
+ * @param node - Any renderable content. An element's `textValue` prop, as a `Table.Cell` takes, stands for everything in
68
+ * it; otherwise only children are read, never props such as `alt`, so a component that draws its own text reads as empty.
69
+ * @returns The strings and numbers in the node, joined by single spaces; empty when it shows no text.
70
+ */
71
+ export declare const textOfNode: (node: ReactNode) => string;
72
+ /**
73
+ * Says whether a card slot, such as a footer's `end` or a header's `badge`, has something to show, so an empty slot leaves
74
+ * no empty box behind.
75
+ * @param node - What the slot was given.
76
+ * @returns `true` for content, `0` included; `false` for `null`, `undefined`, a boolean, as `cond && …` leaves, and `''`.
77
+ */
78
+ export declare const isSlotShown: (node: ReactNode) => boolean;
79
+ /**
80
+ * Names a card row as the table names a row, by its title alone.
81
+ * @param textValue - The row's own `textValue`, which wins outright.
82
+ * @param isPlaceholder - Whether the row carries `Table.RowCard.Skeleton`, which has no text to be named by.
83
+ * @param title - The card's title, or the row-header cell for the fallback card.
84
+ * @returns The row's name; empty when the title shows no text, and then the browser names the row from all of its content.
85
+ */
86
+ export declare const cardRowNameOf: (textValue: string | undefined, isPlaceholder: boolean, title: ReactNode) => string;
87
+ /** What decides whether a press on a card does something. */
88
+ export interface CardRowActions {
89
+ /** The row carries `Table.RowCard.Skeleton`. */
90
+ isPlaceholder: boolean;
91
+ /** The row has its own `onAction` or `href`. */
92
+ hasOwnAction: boolean;
93
+ /** The table has an `onRowAction`. */
94
+ hasRowAction: boolean;
95
+ /** The row is disabled, by its own `isDisabled`, the table's `disabledKeys`, or as a placeholder. */
96
+ isDisabled: boolean;
97
+ /** The table's `selectionMode`. */
98
+ selectionMode: 'none' | 'single' | 'multiple';
99
+ }
100
+ /**
101
+ * Says whether a press on a card does something, for its pointer cursor: the row's action or link, the table's row
102
+ * action, or selection. A placeholder or disabled row does nothing.
103
+ * @param actions - The row's and the table's state; see `CardRowActions`.
104
+ * @returns `true` when a press acts on the row.
105
+ */
106
+ export declare const isCardRowInteractive: ({ isPlaceholder, hasOwnAction, hasRowAction, isDisabled, selectionMode }: CardRowActions) => boolean;
107
+ /** Why a fallback card may show values under the wrong labels, or none. */
108
+ export type FallbackCardWarning = 'no-columns' | 'cell-count';
109
+ /**
110
+ * Tells when a fallback card cannot label its values from the table's columns.
111
+ * @param columnCount - The columns `Table` found in a `Table.Header` among its direct children.
112
+ * @param cellCount - The columns the row's cells span: each of its direct children other than its card counts its `colSpan`.
113
+ * @returns `'no-columns'` when the table found no columns for a row with cells, as when a wrapper component renders
114
+ * `Table.Header`; `'cell-count'` when the counts differ; `undefined` when every cell has its column.
115
+ */
116
+ export declare const fallbackCardWarningOf: (columnCount: number, cellCount: number) => FallbackCardWarning | undefined;
117
+ /**
118
+ * Finds the title a declared card shows in its header.
119
+ * @param card - The row's `Table.RowCard` element.
120
+ * @param headerType - The `Table.RowCard.Header` component.
121
+ * @returns The header's `title`, or `undefined` when the card has no header among its direct children.
122
+ */
123
+ export declare const cardTitleOf: (card: ReactElement, headerType: unknown) => ReactNode;
124
+ /** One label/value line of the fallback card. */
125
+ export interface FallbackCardLine<T> {
126
+ /** The cell's position in the row, stable while the columns are. */
127
+ key: number;
128
+ /** The column's label; unset when the table declares no columns to read it from. */
129
+ label?: string;
130
+ value: T;
131
+ }
132
+ /** Where each of a row's cells goes on the fallback card. */
133
+ export interface FallbackCardSlots<T> {
134
+ /** The row-header cell, or the first cell when no column is marked `isRowHeader`. */
135
+ title?: T;
136
+ /** Cells of columns with no label, such as a row's actions, at the header's trailing end. */
137
+ trailing: T[];
138
+ lines: FallbackCardLine<T>[];
139
+ }
140
+ /**
141
+ * Reads how many columns a cell spans, as the table lays it out.
142
+ * @param cell - One of the row's cells.
143
+ * @returns Its `colSpan` when that is a whole number above 1; 1 otherwise, as for any cell without one.
144
+ */
145
+ export declare const cellSpanOf: (cell: ReactNode) => number;
146
+ /**
147
+ * Counts the columns a row's cells cover, for comparing them with the table's columns.
148
+ * @param cells - The row's cells.
149
+ * @returns The sum of each cell's `colSpan`, 1 for a cell without one.
150
+ */
151
+ export declare const spannedColumnCountOf: (cells: readonly ReactNode[]) => number;
152
+ /**
153
+ * Lays a row's cells out on the fallback card by the column each starts in, as the table lays them out.
154
+ * @param columns - The columns `Table.Header` declares, conditionals already resolved.
155
+ * @param cells - The row's cells, in the same order.
156
+ * @param spanOf - How many columns a cell spans; 1 for each when omitted.
157
+ * @returns The cell starting in the row-header column as the title, the trailing cells and the label/value lines, each value
158
+ * labelled by the column its cell starts in.
159
+ */
160
+ export declare const fallbackCardSlots: <T>(columns: readonly TableCardColumn[], cells: readonly T[], spanOf?: (cell: T) => number) => FallbackCardSlots<T>;
161
+ //# sourceMappingURL=tableCard.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tableCard.utils.d.ts","sourceRoot":"","sources":["../../../../../src/components/organisms/Table/utilities/tableCard.utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,KAAK,YAAY,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE1E,OAAO,KAAK,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,GAAG,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AACvH,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAGvF;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,GAAI,aAAa,OAAO,EAAE,cAAc,WAAW,EAAE,eAAe,WAAW,EAAE,uBAAqB,KAAG,WAGlI,CAAC;AAEF,0EAA0E;AAC1E,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,OAAO,GAAG,QAAQ,GAAG,UAAU,GAAG,kBAAkB,GAAG,gBAAgB,GAAG,cAAc,GAAG,aAAa,CAAC;AAEnJ;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,MAAM,EAAE,OAAO,CAAC,GAAG,GAAG,CAAC,IAAI,aAAa,CAAC,CAAC,EAAE,KAAK,GAAE,KAAG,kBACxD,CAAC;AAEzC,8HAA8H;AAC9H,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG,OAAO,GAAG,QAAQ,GAAG,UAAU,GAAG,OAAO,GAAG,cAAc,GAAG,kBAAkB,GAAG,aAAa,CAAC;AAE9I;;;;;GAKG;AAC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EF;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAAI,OAAO,SAAS,SAAS,EAAE,KAAG,MAA4E,CAAC;AAEhJ;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,EACjC,SAAS,SAAS,eAAe,EAAE,EACnC,OAAO,SAAS,CAAC,EAAE,EACnB,SAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,MAAgB,KACpC,iBAAiB,CAAC,CAAC,CAqBrB,CAAC"}
@@ -0,0 +1,180 @@
1
+ import { joinTestId, slugifyTestId } from '@flipdish/ui-library/utilities/testIdUtils';
2
+ import { isValidElement } from 'react';
3
+ import { filterDOMProps } from 'react-aria/filterDOMProps';
4
+ import { findElement } from './tableChildren.utils.js';
5
+
6
+ /**
7
+ * Picks the layout a table renders from the viewport, the two layout props, and whether react-aria virtualizes it.
8
+ * @param isAtLeastMd - Whether the viewport is `md` or wider; `false` where `matchMedia` is missing or never matches.
9
+ * @param mobileLayout - What the table asked for below `md`.
10
+ * @param desktopLayout - What the table asked for from `md` up.
11
+ * @param isVirtualized - Whether the table sits in a react-aria `Virtualizer`, whose table layout cannot lay out cards.
12
+ * @returns The table inside a `Virtualizer`; otherwise `desktopLayout` from `md` up and `mobileLayout` below it.
13
+ */
14
+ const tableLayoutOf = (isAtLeastMd, mobileLayout, desktopLayout, isVirtualized = false) => {
15
+ if (isVirtualized)
16
+ return 'table';
17
+ return isAtLeastMd ? desktopLayout : mobileLayout;
18
+ };
19
+ /**
20
+ * Hands the table's remaining props to the card list unchanged; react-aria filters them there as it does for the table.
21
+ * The parameter's type is the guard: props that still carry a table-only prop, such as `style`, fail typecheck.
22
+ * @param props - The table's props with every `TableOnlyProp` already taken out.
23
+ * @returns The same object, typed for the card list.
24
+ */
25
+ const cardListPropsOf = (props) => props;
26
+ /**
27
+ * Hands `Table.Body`'s remaining DOM props to the card list unchanged; react-aria filters them there as it does for the body.
28
+ * The parameter's type is the guard: props that still carry a body-only prop, such as `className`, fail typecheck.
29
+ * @param props - The body's props with every `TableBodyOnlyProp` already taken out.
30
+ * @returns The same object, typed for the card list.
31
+ */
32
+ const cardBodyPropsOf = (props) => props;
33
+ /**
34
+ * Hands a react-aria `TableLoadMoreItem`'s props to the card list's `GridListLoadMoreItem`, which takes the same ones.
35
+ * @param props - The table loader's props.
36
+ * @returns The same props for the card list's loader, less the `render`, `className` and `style` written for the table's row,
37
+ * as the body and the rows drop theirs.
38
+ */
39
+ const cardLoadMorePropsOf = ({ render: _tableRowRender, className: _tableRowClassName, style: _tableRowStyle, ...props }) => props;
40
+ /**
41
+ * Hands a row's remaining props to its card's `GridListItem` unchanged; react-aria filters them there as it does for the row.
42
+ * The parameter's type is the guard: props that still carry a row-only prop, such as `style`, fail typecheck.
43
+ * @param props - The row's props with every `TableRowOnlyProp` already taken out.
44
+ * @returns The same object, typed for the card's `GridListItem`.
45
+ */
46
+ const cardRowPropsOf = (props) => props;
47
+ /**
48
+ * Picks from a cell's remaining props what react-aria's `Cell` puts on the table's cell, for the element around the cell's
49
+ * content on a fallback card. The parameter's type is the guard: props that still carry a cell-only prop, such as `colSpan`, fail typecheck.
50
+ * @param props - The cell's props with every `TableCellOnlyProp` already taken out.
51
+ * @returns Its `data-*` attributes, `dir`, `lang`, `hidden`, `inert` and `translate`, and its mouse, pointer, touch, scroll,
52
+ * wheel, animation and transition handlers; nothing the table's cell drops, such as `aria-label`, `tabIndex` or `onKeyDown`.
53
+ */
54
+ const cardCellPropsOf = (props) =>
55
+ // The filter react-aria's `Cell` applies, so the card and the table never disagree on what a cell passes on.
56
+ filterDOMProps(props, { global: true });
57
+ /**
58
+ * Derives a row's `data-testid`, the same in both layouts.
59
+ * @param testIdPrefix - The table's resolved id; a row outside a table has none.
60
+ * @param id - The row's id; a row without one gets no derived id.
61
+ * @param override - The row's own `data-testid`, which wins outright.
62
+ * @returns `<root>--row-<id>`, the override, or `undefined`.
63
+ */
64
+ const rowTestIdOf = (testIdPrefix, id, override) => {
65
+ if (override !== undefined)
66
+ return override;
67
+ return testIdPrefix && id !== undefined ? joinTestId(testIdPrefix, `row-${slugifyTestId(String(id))}`) : undefined;
68
+ };
69
+ /**
70
+ * Reads the text a node shows, for a name that has to be a string.
71
+ * @param node - Any renderable content. An element's `textValue` prop, as a `Table.Cell` takes, stands for everything in
72
+ * it; otherwise only children are read, never props such as `alt`, so a component that draws its own text reads as empty.
73
+ * @returns The strings and numbers in the node, joined by single spaces; empty when it shows no text.
74
+ */
75
+ const textOfNode = (node) => {
76
+ const collect = (part) => {
77
+ if (typeof part === 'string' || typeof part === 'number')
78
+ return [String(part)];
79
+ if (Array.isArray(part))
80
+ return part.flatMap(collect);
81
+ if (!isValidElement(part))
82
+ return [];
83
+ if (typeof part.props.textValue === 'string')
84
+ return [part.props.textValue];
85
+ return collect(part.props.children);
86
+ };
87
+ return collect(node).join(' ').replace(/\s+/g, ' ').trim();
88
+ };
89
+ /**
90
+ * Says whether a card slot, such as a footer's `end` or a header's `badge`, has something to show, so an empty slot leaves
91
+ * no empty box behind.
92
+ * @param node - What the slot was given.
93
+ * @returns `true` for content, `0` included; `false` for `null`, `undefined`, a boolean, as `cond && …` leaves, and `''`.
94
+ */
95
+ const isSlotShown = (node) => node != null && typeof node !== 'boolean' && node !== '';
96
+ /**
97
+ * Names a card row as the table names a row, by its title alone.
98
+ * @param textValue - The row's own `textValue`, which wins outright.
99
+ * @param isPlaceholder - Whether the row carries `Table.RowCard.Skeleton`, which has no text to be named by.
100
+ * @param title - The card's title, or the row-header cell for the fallback card.
101
+ * @returns The row's name; empty when the title shows no text, and then the browser names the row from all of its content.
102
+ */
103
+ const cardRowNameOf = (textValue, isPlaceholder, title) => {
104
+ if (textValue !== undefined)
105
+ return textValue;
106
+ return isPlaceholder ? 'Loading' : textOfNode(title);
107
+ };
108
+ /**
109
+ * Says whether a press on a card does something, for its pointer cursor: the row's action or link, the table's row
110
+ * action, or selection. A placeholder or disabled row does nothing.
111
+ * @param actions - The row's and the table's state; see `CardRowActions`.
112
+ * @returns `true` when a press acts on the row.
113
+ */
114
+ const isCardRowInteractive = ({ isPlaceholder, hasOwnAction, hasRowAction, isDisabled, selectionMode }) => !isPlaceholder && !isDisabled && (hasOwnAction || hasRowAction || selectionMode !== 'none');
115
+ /**
116
+ * Tells when a fallback card cannot label its values from the table's columns.
117
+ * @param columnCount - The columns `Table` found in a `Table.Header` among its direct children.
118
+ * @param cellCount - The columns the row's cells span: each of its direct children other than its card counts its `colSpan`.
119
+ * @returns `'no-columns'` when the table found no columns for a row with cells, as when a wrapper component renders
120
+ * `Table.Header`; `'cell-count'` when the counts differ; `undefined` when every cell has its column.
121
+ */
122
+ const fallbackCardWarningOf = (columnCount, cellCount) => {
123
+ if (cellCount === 0)
124
+ return undefined;
125
+ if (columnCount === 0)
126
+ return 'no-columns';
127
+ return cellCount === columnCount ? undefined : 'cell-count';
128
+ };
129
+ /**
130
+ * Finds the title a declared card shows in its header.
131
+ * @param card - The row's `Table.RowCard` element.
132
+ * @param headerType - The `Table.RowCard.Header` component.
133
+ * @returns The header's `title`, or `undefined` when the card has no header among its direct children.
134
+ */
135
+ const cardTitleOf = (card, headerType) => findElement(card.props.children, headerType)?.props.title;
136
+ /**
137
+ * Reads how many columns a cell spans, as the table lays it out.
138
+ * @param cell - One of the row's cells.
139
+ * @returns Its `colSpan` when that is a whole number above 1; 1 otherwise, as for any cell without one.
140
+ */
141
+ const cellSpanOf = (cell) => {
142
+ const colSpan = isValidElement(cell) ? cell.props.colSpan : undefined;
143
+ return typeof colSpan === 'number' && Number.isInteger(colSpan) && colSpan > 1 ? colSpan : 1;
144
+ };
145
+ /**
146
+ * Counts the columns a row's cells cover, for comparing them with the table's columns.
147
+ * @param cells - The row's cells.
148
+ * @returns The sum of each cell's `colSpan`, 1 for a cell without one.
149
+ */
150
+ const spannedColumnCountOf = (cells) => cells.reduce((count, cell) => count + cellSpanOf(cell), 0);
151
+ /**
152
+ * Lays a row's cells out on the fallback card by the column each starts in, as the table lays them out.
153
+ * @param columns - The columns `Table.Header` declares, conditionals already resolved.
154
+ * @param cells - The row's cells, in the same order.
155
+ * @param spanOf - How many columns a cell spans; 1 for each when omitted.
156
+ * @returns The cell starting in the row-header column as the title, the trailing cells and the label/value lines, each value
157
+ * labelled by the column its cell starts in.
158
+ */
159
+ const fallbackCardSlots = (columns, cells, spanOf = () => 1) => {
160
+ const titleColumn = Math.max(columns.findIndex((column) => column.isRowHeader), 0);
161
+ const slots = { trailing: [], lines: [] };
162
+ let nextColumn = 0;
163
+ cells.forEach((cell, index) => {
164
+ const startColumn = nextColumn;
165
+ nextColumn += spanOf(cell);
166
+ if (startColumn === titleColumn) {
167
+ slots.title = cell;
168
+ return;
169
+ }
170
+ const column = columns[startColumn];
171
+ if (column && !column.label)
172
+ slots.trailing.push(cell);
173
+ else
174
+ slots.lines.push({ key: index, label: column?.label, value: cell });
175
+ });
176
+ return slots;
177
+ };
178
+
179
+ export { cardBodyPropsOf, cardCellPropsOf, cardListPropsOf, cardLoadMorePropsOf, cardRowNameOf, cardRowPropsOf, cardTitleOf, cellSpanOf, fallbackCardSlots, fallbackCardWarningOf, isCardRowInteractive, isSlotShown, rowTestIdOf, spannedColumnCountOf, tableLayoutOf, textOfNode };
180
+ //# sourceMappingURL=tableCard.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tableCard.utils.js","sources":["../../../../../src/components/organisms/Table/utilities/tableCard.utils.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAOA;;;;;;;AAOG;AACI,MAAM,aAAa,GAAG,CAAC,WAAoB,EAAE,YAAyB,EAAE,aAA0B,EAAE,aAAa,GAAG,KAAK,KAAiB;AAC/I,IAAA,IAAI,aAAa;AAAE,QAAA,OAAO,OAAO;IACjC,OAAO,WAAW,GAAG,aAAa,GAAG,YAAY;AACnD;AAKA;;;;;AAKG;AACI,MAAM,eAAe,GAAG,CAAmB,KAA2C,KAC3F;AAKF;;;;;AAKG;AACI,MAAM,eAAe,GAAG,CAAmB,KAA+C,KAC/F;A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;AAC1E,IAAA,CAAC,CAAC;AAEF,IAAA,OAAO,KAAK;AACd;;"}
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+ var children_utils = require('../../../../utilities/__internal__/childrenUtils/children.utils.cjs');
5
+
6
+ /**
7
+ * Finds the first element of a type among children, looking through fragments.
8
+ * @param children - What a component received as `children`.
9
+ * @param type - The component to look for.
10
+ * @returns That element, or `undefined` when no child renders it directly.
11
+ */
12
+ const findElement = (children, type) => children_utils.flattenChildren(children).find((child) => React.isValidElement(child) && child.type === type);
13
+ /**
14
+ * Splits a `Table.Row`'s children into its card and its cells. Only a direct child counts as the card: one nested inside
15
+ * another element stays among the cells, so the row gets the fallback card, and the nested card renders nothing in either
16
+ * layout (`Table.RowCard` checks where it sits). A row whose cells come from a column function has no card.
17
+ * @param children - The row's children, as nodes or as a function of each column.
18
+ * @param columns - The row's `columns`, which a function of each column is called with.
19
+ * @param isCard - Tells a card element apart from a cell.
20
+ * @returns The card, when the row declares one, and the cells.
21
+ */
22
+ const splitRowChildren = (children, columns, isCard) => {
23
+ if (typeof children === 'function')
24
+ return { cardCount: 0, cells: React.Children.toArray(Array.from(columns ?? [], children)) };
25
+ const flat = children_utils.flattenChildren(children);
26
+ const isCardChild = (child) => React.isValidElement(child) && isCard(child);
27
+ const cards = flat.filter(isCardChild);
28
+ return { card: cards[0], cardCount: cards.length, cells: flat.filter((child) => !isCardChild(child)) };
29
+ };
30
+ /**
31
+ * Reads each column a `Table.Header` declares, for a card, which has no header of its own to read them from.
32
+ * @param children - The header's children: `Table.Head` elements, conditionals among them, or a function of each column.
33
+ * @param columns - The header's `columns`, which a function of each column is called with.
34
+ * @returns One entry per rendered column, in order; a string child stands in for a missing `label`.
35
+ */
36
+ const columnsOfHeader = (children, columns) => {
37
+ const heads = typeof children === 'function' ? Array.from(columns ?? [], children) : children_utils.flattenChildren(children);
38
+ return heads.filter((React.isValidElement)).map(({ props }) => ({
39
+ label: props.label ?? (typeof props.children === 'string' ? props.children : undefined),
40
+ isRowHeader: props.isRowHeader === true,
41
+ }));
42
+ };
43
+
44
+ exports.columnsOfHeader = columnsOfHeader;
45
+ exports.findElement = findElement;
46
+ exports.splitRowChildren = splitRowChildren;
47
+ //# sourceMappingURL=tableChildren.utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tableChildren.utils.cjs","sources":["../../../../../src/components/organisms/Table/utilities/tableChildren.utils.ts"],"sourcesContent":[null],"names":["flattenChildren","isValidElement","Children"],"mappings":";;;;;AAOA;;;;;AAKG;AACI,MAAM,WAAW,GAAG,CAAI,QAAmB,EAAE,IAAa,KAC/DA,8BAAe,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,KAA+BC,oBAAc,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI;AAYlH;;;;;;;;AAQG;AACI,MAAM,gBAAgB,GAAG,CAC9B,QAA+B,EAC/B,OAAgC,EAChC,MAA0C,KAC3B;IACf,IAAI,OAAO,QAAQ,KAAK,UAAU;QAAE,OAAO,EAAE,SAAS,EAAE,CAAC,EAAE,KAAK,EAAEC,cAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,EAAE,QAAQ,CAAC,CAAC,EAAE;AACzH,IAAA,MAAM,IAAI,GAAGF,8BAAe,CAAC,QAAQ,CAAC;AACtC,IAAA,MAAM,WAAW,GAAG,CAAC,KAAgB,KAA4BC,oBAAc,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC;IACvG,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;AACtC,IAAA,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,EA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