@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,46 @@
1
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
2
+ import { SwitchVertical01 } from '@flipdish/ui-icons';
3
+ import { Button } from '@flipdish/ui-library/components/atoms/Buttons';
4
+ import { Dropdown } from '@flipdish/ui-library/components/molecules/Dropdown';
5
+ import { cx } from '@flipdish/ui-library/utilities/cx';
6
+ import { useResolvedTestId, joinTestId } from '@flipdish/ui-library/utilities/testIdUtils';
7
+ import { useIsAtLeastMd } from '../hooks/useIsAtLeastMd.js';
8
+ import { tableLayoutOf } from '../utilities/tableCard.utils.js';
9
+ import { isSameSort, sortMenuColumnKeyOf, columnOfSortMenuKey, sortOfColumnChoice, sortOfDirectionChoice } from '../utilities/tableSort.utils.js';
10
+
11
+ const firstKeyOf = (selection) => (selection === 'all' ? undefined : [...selection][0]);
12
+ /** A "Sort by" menu of a table's sortable columns, both directions and "Clear sort", shown while the table shows cards; icon-only below `md`. */
13
+ const TableSortMenu = ({ columns, sortDescriptor, defaultSortDescriptor, onSortChange, mobileLayout = 'cards', desktopLayout = 'table', size = 'md', className, 'data-testid': dataTestId, }) => {
14
+ const rootTestId = useResolvedTestId({ testId: dataTestId, segment: 'table-sort-menu', rootName: 'table-sort-menu' });
15
+ // Icon-only on the server and while hydrating too, so the two renders agree; the label comes once the viewport is known.
16
+ const isAtLeastMd = useIsAtLeastMd();
17
+ const isIconOnly = !isAtLeastMd;
18
+ const sortedColumn = sortDescriptor ? columns.find((column) => column.id === sortDescriptor.column) : undefined;
19
+ const sortName = sortedColumn && sortDescriptor ? `Sort by ${sortedColumn.label}, ${sortDescriptor.direction}` : undefined;
20
+ // The order differs from the one the page rests at, so there is something to clear and the icon marks it.
21
+ const isAwayFromRest = !isSameSort(sortDescriptor, defaultSortDescriptor);
22
+ const chooseColumn = (selection) => {
23
+ const column = columnOfSortMenuKey(columns, firstKeyOf(selection));
24
+ if (column)
25
+ onSortChange(sortOfColumnChoice(sortDescriptor, column.id));
26
+ };
27
+ const chooseDirection = (selection) => {
28
+ const direction = firstKeyOf(selection);
29
+ if (direction === 'ascending' || direction === 'descending')
30
+ onSortChange(sortOfDirectionChoice(sortDescriptor, direction));
31
+ };
32
+ const clearSort = () => onSortChange(defaultSortDescriptor);
33
+ const renderColumnItem = (column) => (jsx(Dropdown.Item, { id: sortMenuColumnKeyOf(column.id), label: column.label }, sortMenuColumnKeyOf(column.id)));
34
+ // Read as the table reads it, so the two always agree, on the server and while hydrating too.
35
+ if (tableLayoutOf(isAtLeastMd, mobileLayout, desktopLayout) === 'table')
36
+ return null;
37
+ return (jsxs(Dropdown.Root, { "data-testid": rootTestId, children: [isIconOnly ? (jsx(Button, { color: "secondary", size: size, iconLeading: SwitchVertical01, className: cx('shrink-0',
38
+ // A decorative dot while the sort differs from the resting one; the name already states what the sort is.
39
+ isAwayFromRest && "after:absolute after:top-1 after:right-1 after:size-2 after:rounded-full after:bg-brand-solid after:content-['']", className), "aria-label": sortName ?? 'Sort by', "data-testid": joinTestId(rootTestId, 'trigger') })) : (jsxs(Button, { color: "secondary", size: size, iconLeading: SwitchVertical01,
40
+ // The label truncates, so the trigger never grows wider than the space it is given.
41
+ className: cx('max-w-full min-w-0 *:data-text:min-w-0 *:data-text:truncate', className), "aria-label": sortName, "data-testid": joinTestId(rootTestId, 'trigger'), children: ["Sort by", sortedColumn && (jsxs(Fragment, { children: [' ', jsx("span", { className: "text-tertiary", children: sortedColumn.label })] }))] })), jsx(Dropdown.Popover, { children: jsxs(Dropdown.Menu, { "aria-label": "Sort by", children: [jsx(Dropdown.Section, { "aria-label": "Column", selectionMode: "single", disallowEmptySelection: true, selectedKeys: sortedColumn ? [sortMenuColumnKeyOf(sortedColumn.id)] : [], onSelectionChange: chooseColumn, children: columns.map(renderColumnItem) }), jsx(Dropdown.Separator, {}), jsxs(Dropdown.Section, { "aria-label": "Direction", selectionMode: "single", disallowEmptySelection: true, selectedKeys: sortedColumn && sortDescriptor ? [sortDescriptor.direction] : [], onSelectionChange: chooseDirection, children: [jsx(Dropdown.Item, { id: "ascending", label: "Ascending", isDisabled: !sortedColumn }), jsx(Dropdown.Item, { id: "descending", label: "Descending", isDisabled: !sortedColumn })] }), isAwayFromRest && jsx(Dropdown.Separator, {}), isAwayFromRest && jsx(Dropdown.Item, { id: "clear", label: "Clear sort", onAction: clearSort })] }) })] }));
42
+ };
43
+ TableSortMenu.displayName = 'TableSortMenu';
44
+
45
+ export { TableSortMenu };
46
+ //# sourceMappingURL=TableSortMenu.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TableSortMenu.js","sources":["../../../../../src/components/organisms/Table/components/TableSortMenu.tsx"],"sourcesContent":[null],"names":["_jsx","_jsxs","_Fragment"],"mappings":";;;;;;;;;;AAsCA,MAAM,UAAU,GAAG,CAAC,SAAoB,MAAuB,SAAS,KAAK,KAAK,GAAG,SAAS,GAAG,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;AAEnH;AACO,MAAM,aAAa,GAAG,CAAC,EAC5B,OAAO,EACP,cAAc,EACd,qBAAqB,EACrB,YAAY,EACZ,YAAY,GAAG,OAAO,EACtB,aAAa,GAAG,OAAO,EACvB,IAAI,GAAG,IAAI,EACX,SAAS,EACT,aAAa,EAAE,UAAU,GACN,KAAI;AACvB,IAAA,MAAM,UAAU,GAAG,iBAAiB,CAAC,EAAE,MAA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the direction the sorted column first landed on, so a press can tell its second direction, which the next press
8
+ * clears, from its first. It records the direction whenever another column becomes sorted, on mount too, and whenever the
9
+ * sort is the resting one, which always starts its column's cycle; it forgets it while nothing is sorted.
10
+ *
11
+ * @param sortDescriptor The table's sort; `undefined` when nothing is sorted.
12
+ * @param defaultSortDescriptor The page's resting sort; `undefined` when the list rests unsorted.
13
+ * @returns The sorted column's first direction, or `undefined` while nothing is sorted.
14
+ */
15
+ const useFirstSortDirection = (sortDescriptor, defaultSortDescriptor) => {
16
+ const [firstSort, setFirstSort] = React.useState(() => tableSort_utils.firstSortOf(undefined, sortDescriptor, defaultSortDescriptor));
17
+ const nextFirstSort = tableSort_utils.firstSortOf(firstSort, sortDescriptor, defaultSortDescriptor);
18
+ // Updated while rendering, as React allows for state derived from a prop, so the press that follows reads it at once.
19
+ if (nextFirstSort !== firstSort)
20
+ setFirstSort(nextFirstSort);
21
+ return nextFirstSort?.direction;
22
+ };
23
+
24
+ exports.useFirstSortDirection = useFirstSortDirection;
25
+ //# sourceMappingURL=useFirstSortDirection.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFirstSortDirection.cjs","sources":["../../../../../src/components/organisms/Table/hooks/useFirstSortDirection.ts"],"sourcesContent":[null],"names":["useState","firstSortOf"],"mappings":";;;;;AAMA;;;;;;;;AAQG;MACU,qBAAqB,GAAG,CACnC,cAA0C,EAC1C,qBAAsC,KACT;IAC7B,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAGA,cAAQ,CAAC,MAAMC,2BAAW,CAAC,SAAS,EAAE,cAAc,EAAE,qBAAqB,CAAC,CAAC;IAC/G,MAAM,aAAa,GAAGA,2BAAW,CAAC,SAAS,EAAE,cAAc,EAAE,qBAAqB,CAAC;;IAEnF,IAAI,aAAa,KAAK,SAAS;QAAE,YAAY,CAAC,aAAa,CAAC;IAC5D,OAAO,aAAa,EAAE,SAAS;AACjC;;"}
@@ -0,0 +1,12 @@
1
+ import type { SortDescriptor, SortDirection } from 'react-aria-components';
2
+ /**
3
+ * Remembers the direction the sorted column first landed on, so a press can tell its second direction, which the next press
4
+ * clears, from its first. It records the direction whenever another column becomes sorted, on mount too, and whenever the
5
+ * sort is the resting one, which always starts its column's cycle; it forgets it while nothing is sorted.
6
+ *
7
+ * @param sortDescriptor The table's sort; `undefined` when nothing is sorted.
8
+ * @param defaultSortDescriptor The page's resting sort; `undefined` when the list rests unsorted.
9
+ * @returns The sorted column's first direction, or `undefined` while nothing is sorted.
10
+ */
11
+ export declare const useFirstSortDirection: (sortDescriptor: SortDescriptor | undefined, defaultSortDescriptor?: SortDescriptor) => SortDirection | undefined;
12
+ //# sourceMappingURL=useFirstSortDirection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFirstSortDirection.d.ts","sourceRoot":"","sources":["../../../../../src/components/organisms/Table/hooks/useFirstSortDirection.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAG3E;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,GAChC,gBAAgB,cAAc,GAAG,SAAS,EAC1C,wBAAwB,cAAc,KACrC,aAAa,GAAG,SAMlB,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { useState } from 'react';
2
+ import { firstSortOf } from '../utilities/tableSort.utils.js';
3
+
4
+ /**
5
+ * Remembers the direction the sorted column first landed on, so a press can tell its second direction, which the next press
6
+ * clears, from its first. It records the direction whenever another column becomes sorted, on mount too, and whenever the
7
+ * sort is the resting one, which always starts its column's cycle; it forgets it while nothing is sorted.
8
+ *
9
+ * @param sortDescriptor The table's sort; `undefined` when nothing is sorted.
10
+ * @param defaultSortDescriptor The page's resting sort; `undefined` when the list rests unsorted.
11
+ * @returns The sorted column's first direction, or `undefined` while nothing is sorted.
12
+ */
13
+ const useFirstSortDirection = (sortDescriptor, defaultSortDescriptor) => {
14
+ const [firstSort, setFirstSort] = useState(() => firstSortOf(undefined, sortDescriptor, defaultSortDescriptor));
15
+ const nextFirstSort = firstSortOf(firstSort, sortDescriptor, defaultSortDescriptor);
16
+ // Updated while rendering, as React allows for state derived from a prop, so the press that follows reads it at once.
17
+ if (nextFirstSort !== firstSort)
18
+ setFirstSort(nextFirstSort);
19
+ return nextFirstSort?.direction;
20
+ };
21
+
22
+ export { useFirstSortDirection };
23
+ //# sourceMappingURL=useFirstSortDirection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFirstSortDirection.js","sources":["../../../../../src/components/organisms/Table/hooks/useFirstSortDirection.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAMA;;;;;;;;AAQG;MACU,qBAAqB,GAAG,CACnC,cAA0C,EAC1C,qBAAsC,KACT;IAC7B,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,MAAM,WAAW,CAAC,SAAS,EAAE,cAAc,EAAE,qBAAqB,CAAC,CAAC;IAC/G,MAAM,aAAa,GAAG,WAAW,CAAC,SAAS,EAAE,cAAc,EAAE,qBAAqB,CAAC;;IAEnF,IAAI,aAAa,KAAK,SAAS;QAAE,YAAY,CAAC,aAAa,CAAC;IAC5D,OAAO,aAAa,EAAE,SAAS;AACjC;;"}
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ var useBreakpoints = require('@flipdish/ui-library/hooks/useBreakpoints');
4
+ var React = require('react');
5
+
6
+ const subscribeToNothing = () => () => { };
7
+ /**
8
+ * Reports whether the viewport is at least `md`, as `useBreakpoints('md')` does, but `false` on the server and while
9
+ * hydrating, so the server's HTML and the hydration render pick the same layout. A client-only app gets the real answer
10
+ * on its first render.
11
+ *
12
+ * @returns `true` once the viewport can be measured and is at least `md`.
13
+ */
14
+ const useIsAtLeastMd = () => {
15
+ const canMeasureViewport = React.useSyncExternalStore(subscribeToNothing, () => true, () => false);
16
+ const isAtLeastMd = useBreakpoints.useBreakpoints('md');
17
+ return canMeasureViewport && isAtLeastMd;
18
+ };
19
+
20
+ exports.useIsAtLeastMd = useIsAtLeastMd;
21
+ //# sourceMappingURL=useIsAtLeastMd.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIsAtLeastMd.cjs","sources":["../../../../../src/components/organisms/Table/hooks/useIsAtLeastMd.ts"],"sourcesContent":[null],"names":["useSyncExternalStore","useBreakpoints"],"mappings":";;;;;AAKA,MAAM,kBAAkB,GAAG,MAAM,MAAK,EAAE,CAAC;AAEzC;;;;;;AAMG;AACI,MAAM,cAAc,GAAG,MAAK;AACjC,IAAA,MAAM,kBAAkB,GAAGA,0BAAoB,CAC7C,kBAAkB,EAClB,MAAM,IAAI,EACV,MAAM,KAAK,CACZ;AACD,IAAA,MAAM,WAAW,GAAGC,6BAAc,CAAC,IAAI,CAAC;IACxC,OAAO,kBAAkB,IAAI,WAAW;AAC1C;;"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Reports whether the viewport is at least `md`, as `useBreakpoints('md')` does, but `false` on the server and while
3
+ * hydrating, so the server's HTML and the hydration render pick the same layout. A client-only app gets the real answer
4
+ * on its first render.
5
+ *
6
+ * @returns `true` once the viewport can be measured and is at least `md`.
7
+ */
8
+ export declare const useIsAtLeastMd: () => boolean;
9
+ //# sourceMappingURL=useIsAtLeastMd.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIsAtLeastMd.d.ts","sourceRoot":"","sources":["../../../../../src/components/organisms/Table/hooks/useIsAtLeastMd.ts"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,eAQ1B,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { useBreakpoints } from '@flipdish/ui-library/hooks/useBreakpoints';
2
+ import { useSyncExternalStore } from 'react';
3
+
4
+ const subscribeToNothing = () => () => { };
5
+ /**
6
+ * Reports whether the viewport is at least `md`, as `useBreakpoints('md')` does, but `false` on the server and while
7
+ * hydrating, so the server's HTML and the hydration render pick the same layout. A client-only app gets the real answer
8
+ * on its first render.
9
+ *
10
+ * @returns `true` once the viewport can be measured and is at least `md`.
11
+ */
12
+ const useIsAtLeastMd = () => {
13
+ const canMeasureViewport = useSyncExternalStore(subscribeToNothing, () => true, () => false);
14
+ const isAtLeastMd = useBreakpoints('md');
15
+ return canMeasureViewport && isAtLeastMd;
16
+ };
17
+
18
+ export { useIsAtLeastMd };
19
+ //# sourceMappingURL=useIsAtLeastMd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIsAtLeastMd.js","sources":["../../../../../src/components/organisms/Table/hooks/useIsAtLeastMd.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAKA,MAAM,kBAAkB,GAAG,MAAM,MAAK,EAAE,CAAC;AAEzC;;;;;;AAMG;AACI,MAAM,cAAc,GAAG,MAAK;AACjC,IAAA,MAAM,kBAAkB,GAAG,oBAAoB,CAC7C,kBAAkB,EAClB,MAAM,IAAI,EACV,MAAM,KAAK,CACZ;AACD,IAAA,MAAM,WAAW,GAAG,cAAc,CAAC,IAAI,CAAC;IACxC,OAAO,kBAAkB,IAAI,WAAW;AAC1C;;"}
@@ -0,0 +1,43 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+
5
+ /**
6
+ * Keeps the table's row action off placeholder rows. A placeholder row is disabled, but `disabledBehavior="selection"`
7
+ * leaves a disabled row's action on, so the card list's `onAction` checks this set as well.
8
+ *
9
+ * @param onRowAction The table's `onRowAction`, or `undefined` when it has none.
10
+ * @returns `register`, which a placeholder row calls with its id and whose cleanup drops it, and `onAction`, the row
11
+ * action to give the card list: it skips a registered placeholder, and is `undefined` when the table has no row action.
12
+ */
13
+ const usePlaceholderRows = (onRowAction) => {
14
+ const placeholderIds = React.useRef(new Set());
15
+ const register = React.useCallback((id) => {
16
+ placeholderIds.current.add(id);
17
+ return () => {
18
+ placeholderIds.current.delete(id);
19
+ };
20
+ }, []);
21
+ const onAction = onRowAction
22
+ ? (key) => {
23
+ if (!placeholderIds.current.has(key))
24
+ onRowAction(key);
25
+ }
26
+ : undefined;
27
+ return { register, onAction };
28
+ };
29
+ /**
30
+ * Joins one placeholder row to the table's placeholder set while it carries `Table.RowCard.Skeleton`, in either layout.
31
+ *
32
+ * @param register The table's placeholder registrar; omitted outside a table.
33
+ * @param id The row's id. A row without one cannot be skipped by id, so it is left out.
34
+ * @param isPlaceholder Whether the row carries `Table.RowCard.Skeleton` now; it leaves the set when the skeleton goes.
35
+ * @returns Nothing. Membership is updated while the row is rendered.
36
+ */
37
+ const useRegisterPlaceholderRow = (register, id, isPlaceholder) => {
38
+ React.useEffect(() => (isPlaceholder && id !== undefined ? register?.(id) : undefined), [register, id, isPlaceholder]);
39
+ };
40
+
41
+ exports.usePlaceholderRows = usePlaceholderRows;
42
+ exports.useRegisterPlaceholderRow = useRegisterPlaceholderRow;
43
+ //# sourceMappingURL=usePlaceholderRows.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePlaceholderRows.cjs","sources":["../../../../../src/components/organisms/Table/hooks/usePlaceholderRows.ts"],"sourcesContent":[null],"names":["useRef","useCallback","useEffect"],"mappings":";;;;AAKA;;;;;;;AAOG;AACI,MAAM,kBAAkB,GAAG,CAAC,WAA+C,KAAI;IACpF,MAAM,cAAc,GAAGA,YAAM,CAAC,IAAI,GAAG,EAAS,CAAC;AAE/C,IAAA,MAAM,QAAQ,GAAGC,iBAAW,CAAC,CAAC,EAAS,KAAI;AACzC,QAAA,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;AAC9B,QAAA,OAAO,MAAK;AACV,YAAA,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;AACnC,QAAA,CAAC;IACH,CAAC,EAAE,EAAE,CAAC;IAEN,MAAM,QAAQ,GAAG;AACf,UAAE,CAAC,GAAU,KAAI;YACb,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;gBAAE,WAAW,CAAC,GAAG,CAAC;QACxD;UACA,SAAS;AAEb,IAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE;AAC/B;AAEA;;;;;;;AAOG;AACI,MAAM,yBAAyB,GAAG,CAAC,QAAiD,EAAE,EAAqB,EAAE,aAAsB,KAAI;AAC5I,IAAAC,eAAS,CAAC,OAAO,aAAa,IAAI,EAAE,KAAK,SAAS,GAAG,QAAQ,GAAG,EAAE,CAAC,GAAG,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,EAAE,EAAE,aAAa,CAAC,CAAC;AAClH;;;"}
@@ -0,0 +1,23 @@
1
+ import type { RowId } from '../table.types';
2
+ /**
3
+ * Keeps the table's row action off placeholder rows. A placeholder row is disabled, but `disabledBehavior="selection"`
4
+ * leaves a disabled row's action on, so the card list's `onAction` checks this set as well.
5
+ *
6
+ * @param onRowAction The table's `onRowAction`, or `undefined` when it has none.
7
+ * @returns `register`, which a placeholder row calls with its id and whose cleanup drops it, and `onAction`, the row
8
+ * action to give the card list: it skips a registered placeholder, and is `undefined` when the table has no row action.
9
+ */
10
+ export declare const usePlaceholderRows: (onRowAction: ((key: RowId) => void) | undefined) => {
11
+ register: (id: RowId) => () => void;
12
+ onAction: ((key: RowId) => void) | undefined;
13
+ };
14
+ /**
15
+ * Joins one placeholder row to the table's placeholder set while it carries `Table.RowCard.Skeleton`, in either layout.
16
+ *
17
+ * @param register The table's placeholder registrar; omitted outside a table.
18
+ * @param id The row's id. A row without one cannot be skipped by id, so it is left out.
19
+ * @param isPlaceholder Whether the row carries `Table.RowCard.Skeleton` now; it leaves the set when the skeleton goes.
20
+ * @returns Nothing. Membership is updated while the row is rendered.
21
+ */
22
+ export declare const useRegisterPlaceholderRow: (register: ((id: RowId) => () => void) | undefined, id: RowId | undefined, isPlaceholder: boolean) => void;
23
+ //# sourceMappingURL=usePlaceholderRows.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePlaceholderRows.d.ts","sourceRoot":"","sources":["../../../../../src/components/organisms/Table/hooks/usePlaceholderRows.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,GAAI,aAAa,CAAC,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,CAAC,GAAG,SAAS;mBAG9C,KAAK;qBAQ7B,KAAK;CAMhB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,GAAI,UAAU,CAAC,CAAC,EAAE,EAAE,KAAK,KAAK,MAAM,IAAI,CAAC,GAAG,SAAS,EAAE,IAAI,KAAK,GAAG,SAAS,EAAE,eAAe,OAAO,SAEzI,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { useEffect, useRef, useCallback } from 'react';
2
+
3
+ /**
4
+ * Keeps the table's row action off placeholder rows. A placeholder row is disabled, but `disabledBehavior="selection"`
5
+ * leaves a disabled row's action on, so the card list's `onAction` checks this set as well.
6
+ *
7
+ * @param onRowAction The table's `onRowAction`, or `undefined` when it has none.
8
+ * @returns `register`, which a placeholder row calls with its id and whose cleanup drops it, and `onAction`, the row
9
+ * action to give the card list: it skips a registered placeholder, and is `undefined` when the table has no row action.
10
+ */
11
+ const usePlaceholderRows = (onRowAction) => {
12
+ const placeholderIds = useRef(new Set());
13
+ const register = useCallback((id) => {
14
+ placeholderIds.current.add(id);
15
+ return () => {
16
+ placeholderIds.current.delete(id);
17
+ };
18
+ }, []);
19
+ const onAction = onRowAction
20
+ ? (key) => {
21
+ if (!placeholderIds.current.has(key))
22
+ onRowAction(key);
23
+ }
24
+ : undefined;
25
+ return { register, onAction };
26
+ };
27
+ /**
28
+ * Joins one placeholder row to the table's placeholder set while it carries `Table.RowCard.Skeleton`, in either layout.
29
+ *
30
+ * @param register The table's placeholder registrar; omitted outside a table.
31
+ * @param id The row's id. A row without one cannot be skipped by id, so it is left out.
32
+ * @param isPlaceholder Whether the row carries `Table.RowCard.Skeleton` now; it leaves the set when the skeleton goes.
33
+ * @returns Nothing. Membership is updated while the row is rendered.
34
+ */
35
+ const useRegisterPlaceholderRow = (register, id, isPlaceholder) => {
36
+ useEffect(() => (isPlaceholder && id !== undefined ? register?.(id) : undefined), [register, id, isPlaceholder]);
37
+ };
38
+
39
+ export { usePlaceholderRows, useRegisterPlaceholderRow };
40
+ //# sourceMappingURL=usePlaceholderRows.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePlaceholderRows.js","sources":["../../../../../src/components/organisms/Table/hooks/usePlaceholderRows.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAKA;;;;;;;AAOG;AACI,MAAM,kBAAkB,GAAG,CAAC,WAA+C,KAAI;IACpF,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,GAAG,EAAS,CAAC;AAE/C,IAAA,MAAM,QAAQ,GAAG,WAAW,CAAC,CAAC,EAAS,KAAI;AACzC,QAAA,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;AAC9B,QAAA,OAAO,MAAK;AACV,YAAA,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;AACnC,QAAA,CAAC;IACH,CAAC,EAAE,EAAE,CAAC;IAEN,MAAM,QAAQ,GAAG;AACf,UAAE,CAAC,GAAU,KAAI;YACb,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;gBAAE,WAAW,CAAC,GAAG,CAAC;QACxD;UACA,SAAS;AAEb,IAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE;AAC/B;AAEA;;;;;;;AAOG;AACI,MAAM,yBAAyB,GAAG,CAAC,QAAiD,EAAE,EAAqB,EAAE,aAAsB,KAAI;AAC5I,IAAA,SAAS,CAAC,OAAO,aAAa,IAAI,EAAE,KAAK,SAAS,GAAG,QAAQ,GAAG,EAAE,CAAC,GAAG,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,EAAE,EAAE,aAAa,CAAC,CAAC;AAClH;;"}
@@ -5,18 +5,36 @@ var React = require('react');
5
5
  /**
6
6
  * Remembers which selectable rows are mounted so "select all" can name them instead of react-aria's `'all'`.
7
7
  *
8
- * @returns `register`, whose cleanup drops that row, and `rowIds`, the live set a selection handler reads.
8
+ * @returns `register`, whose cleanup drops that row; `rowIds`, the live set a selection handler reads; and `subscribe` with
9
+ * `getVersion`, the pair `useSyncExternalStore` takes to re-render something, such as a select-all checkbox, whenever a row
10
+ * joins or leaves.
9
11
  */
10
12
  const useSelectableRowRegistry = () => {
11
13
  // react-aria reports "select all" as `'all'`; the rendered rows say which ids that covers, in mount order rather than display order.
12
14
  const rowIds = React.useRef(new Set());
15
+ const listeners = React.useRef(new Set());
16
+ const version = React.useRef(0);
13
17
  const register = React.useCallback((id) => {
18
+ const announce = () => {
19
+ version.current += 1;
20
+ for (const listener of listeners.current)
21
+ listener();
22
+ };
14
23
  rowIds.current.add(id);
24
+ announce();
15
25
  return () => {
16
26
  rowIds.current.delete(id);
27
+ announce();
28
+ };
29
+ }, []);
30
+ const subscribe = React.useCallback((listener) => {
31
+ listeners.current.add(listener);
32
+ return () => {
33
+ listeners.current.delete(listener);
17
34
  };
18
35
  }, []);
19
- return { register, rowIds };
36
+ const getVersion = React.useCallback(() => version.current, []);
37
+ return { register, rowIds, subscribe, getVersion };
20
38
  };
21
39
  /**
22
40
  * Joins one row to the table's selectable-row set for as long as it has an id and is not disabled.
@@ -1 +1 @@
1
- {"version":3,"file":"useSelectableRowRegistry.cjs","sources":["../../../../../src/components/organisms/Table/hooks/useSelectableRowRegistry.ts"],"sourcesContent":[null],"names":["useRef","useCallback","useEffect"],"mappings":";;;;AAOA;;;;AAIG;AACI,MAAM,wBAAwB,GAAG,MAAK;;IAE3C,MAAM,MAAM,GAAGA,YAAM,CAAC,IAAI,GAAG,EAAS,CAAC;AACvC,IAAA,MAAM,QAAQ,GAAGC,iBAAW,CAAC,CAAC,EAAS,KAAI;AACzC,QAAA,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;AACtB,QAAA,OAAO,MAAK;AACV,YAAA,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;AAC3B,QAAA,CAAC;IACH,CAAC,EAAE,EAAE,CAAC;AAEN,IAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE;AAC7B;AAEA;;;;;;;AAOG;AACI,MAAM,wBAAwB,GAAG,CACtC,QAAiD,EACjD,EAAqB,EACrB,UAA+B,KAC7B;AACF,IAAAC,eAAS,CAAC,OAAO,EAAE,KAAK,SAAS,IAAI,UAAU,GAAG,SAAS,GAAG,QAAQ,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,EAAE,EAAE,UAAU,CAAC,CAAC;AAC5G;;;"}
1
+ {"version":3,"file":"useSelectableRowRegistry.cjs","sources":["../../../../../src/components/organisms/Table/hooks/useSelectableRowRegistry.ts"],"sourcesContent":[null],"names":["useRef","useCallback","useEffect"],"mappings":";;;;AAKA;;;;;;AAMG;AACI,MAAM,wBAAwB,GAAG,MAAK;;IAE3C,MAAM,MAAM,GAAGA,YAAM,CAAC,IAAI,GAAG,EAAS,CAAC;IACvC,MAAM,SAAS,GAAGA,YAAM,CAAC,IAAI,GAAG,EAAc,CAAC;AAC/C,IAAA,MAAM,OAAO,GAAGA,YAAM,CAAC,CAAC,CAAC;AAEzB,IAAA,MAAM,QAAQ,GAAGC,iBAAW,CAAC,CAAC,EAAS,KAAI;QACzC,MAAM,QAAQ,GAAG,MAAK;AACpB,YAAA,OAAO,CAAC,OAAO,IAAI,CAAC;AACpB,YAAA,KAAK,MAAM,QAAQ,IAAI,SAAS,CAAC,OAAO;AAAE,gBAAA,QAAQ,EAAE;AACtD,QAAA,CAAC;AACD,QAAA,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;AACtB,QAAA,QAAQ,EAAE;AACV,QAAA,OAAO,MAAK;AACV,YAAA,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;AACzB,YAAA,QAAQ,EAAE;AACZ,QAAA,CAAC;IACH,CAAC,EAAE,EAAE,CAAC;AAEN,IAAA,MAAM,SAAS,GAAGA,iBAAW,CAAC,CAAC,QAAoB,KAAI;AACrD,QAAA,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;AAC/B,QAAA,OAAO,MAAK;AACV,YAAA,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC;AACpC,QAAA,CAAC;IACH,CAAC,EAAE,EAAE,CAAC;AAEN,IAAA,MAAM,UAAU,GAAGA,iBAAW,CAAC,MAAM,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;IAEzD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE;AACpD;AAKA;;;;;;;AAOG;AACI,MAAM,wBAAwB,GAAG,CACtC,QAAiD,EACjD,EAAqB,EACrB,UAA+B,KAC7B;AACF,IAAAC,eAAS,CAAC,OAAO,EAAE,KAAK,SAAS,IAAI,UAAU,GAAG,SAAS,GAAG,QAAQ,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,EAAE,EAAE,UAAU,CAAC,CAAC;AAC5G;;;"}
@@ -1,14 +1,19 @@
1
- /** A row id. Same values as react-aria's `Key`, without importing that package into a hook. */
2
- type RowId = string | number;
1
+ import type { RowId } from '../table.types';
3
2
  /**
4
3
  * Remembers which selectable rows are mounted so "select all" can name them instead of react-aria's `'all'`.
5
4
  *
6
- * @returns `register`, whose cleanup drops that row, and `rowIds`, the live set a selection handler reads.
5
+ * @returns `register`, whose cleanup drops that row; `rowIds`, the live set a selection handler reads; and `subscribe` with
6
+ * `getVersion`, the pair `useSyncExternalStore` takes to re-render something, such as a select-all checkbox, whenever a row
7
+ * joins or leaves.
7
8
  */
8
9
  export declare const useSelectableRowRegistry: () => {
9
10
  register: (id: RowId) => () => void;
10
11
  rowIds: import("react").RefObject<Set<RowId>>;
12
+ subscribe: (listener: () => void) => () => void;
13
+ getVersion: () => number;
11
14
  };
15
+ /** What `useSelectableRowRegistry` returns, for a part that reads the registry without owning it. */
16
+ export type SelectableRowRegistry = ReturnType<typeof useSelectableRowRegistry>;
12
17
  /**
13
18
  * Joins one row to the table's selectable-row set for as long as it has an id and is not disabled.
14
19
  *
@@ -18,5 +23,4 @@ export declare const useSelectableRowRegistry: () => {
18
23
  * @returns Nothing. Membership is updated while the row is rendered.
19
24
  */
20
25
  export declare const useRegisterSelectableRow: (register: ((id: RowId) => () => void) | undefined, id: RowId | undefined, isDisabled: boolean | undefined) => void;
21
- export {};
22
26
  //# sourceMappingURL=useSelectableRowRegistry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSelectableRowRegistry.d.ts","sourceRoot":"","sources":["../../../../../src/components/organisms/Table/hooks/useSelectableRowRegistry.ts"],"names":[],"mappings":"AAIA,+FAA+F;AAC/F,KAAK,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;AAE7B;;;;GAIG;AACH,eAAO,MAAM,wBAAwB;mBAGD,KAAK;;CAQxC,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,GACnC,UAAU,CAAC,CAAC,EAAE,EAAE,KAAK,KAAK,MAAM,IAAI,CAAC,GAAG,SAAS,EACjD,IAAI,KAAK,GAAG,SAAS,EACrB,YAAY,OAAO,GAAG,SAAS,SAGhC,CAAC"}
1
+ {"version":3,"file":"useSelectableRowRegistry.d.ts","sourceRoot":"","sources":["../../../../../src/components/organisms/Table/hooks/useSelectableRowRegistry.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB;mBAMD,KAAK;;0BAaE,MAAM,IAAI;;CAUpD,CAAC;AAEF,qGAAqG;AACrG,MAAM,MAAM,qBAAqB,GAAG,UAAU,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAEhF;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,GACnC,UAAU,CAAC,CAAC,EAAE,EAAE,KAAK,KAAK,MAAM,IAAI,CAAC,GAAG,SAAS,EACjD,IAAI,KAAK,GAAG,SAAS,EACrB,YAAY,OAAO,GAAG,SAAS,SAGhC,CAAC"}
@@ -1,20 +1,38 @@
1
- import { useRef, useCallback, useEffect } from 'react';
1
+ import { useEffect, useRef, useCallback } from 'react';
2
2
 
3
3
  /**
4
4
  * Remembers which selectable rows are mounted so "select all" can name them instead of react-aria's `'all'`.
5
5
  *
6
- * @returns `register`, whose cleanup drops that row, and `rowIds`, the live set a selection handler reads.
6
+ * @returns `register`, whose cleanup drops that row; `rowIds`, the live set a selection handler reads; and `subscribe` with
7
+ * `getVersion`, the pair `useSyncExternalStore` takes to re-render something, such as a select-all checkbox, whenever a row
8
+ * joins or leaves.
7
9
  */
8
10
  const useSelectableRowRegistry = () => {
9
11
  // react-aria reports "select all" as `'all'`; the rendered rows say which ids that covers, in mount order rather than display order.
10
12
  const rowIds = useRef(new Set());
13
+ const listeners = useRef(new Set());
14
+ const version = useRef(0);
11
15
  const register = useCallback((id) => {
16
+ const announce = () => {
17
+ version.current += 1;
18
+ for (const listener of listeners.current)
19
+ listener();
20
+ };
12
21
  rowIds.current.add(id);
22
+ announce();
13
23
  return () => {
14
24
  rowIds.current.delete(id);
25
+ announce();
26
+ };
27
+ }, []);
28
+ const subscribe = useCallback((listener) => {
29
+ listeners.current.add(listener);
30
+ return () => {
31
+ listeners.current.delete(listener);
15
32
  };
16
33
  }, []);
17
- return { register, rowIds };
34
+ const getVersion = useCallback(() => version.current, []);
35
+ return { register, rowIds, subscribe, getVersion };
18
36
  };
19
37
  /**
20
38
  * Joins one row to the table's selectable-row set for as long as it has an id and is not disabled.
@@ -1 +1 @@
1
- {"version":3,"file":"useSelectableRowRegistry.js","sources":["../../../../../src/components/organisms/Table/hooks/useSelectableRowRegistry.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAOA;;;;AAIG;AACI,MAAM,wBAAwB,GAAG,MAAK;;IAE3C,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,GAAG,EAAS,CAAC;AACvC,IAAA,MAAM,QAAQ,GAAG,WAAW,CAAC,CAAC,EAAS,KAAI;AACzC,QAAA,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;AACtB,QAAA,OAAO,MAAK;AACV,YAAA,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;AAC3B,QAAA,CAAC;IACH,CAAC,EAAE,EAAE,CAAC;AAEN,IAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE;AAC7B;AAEA;;;;;;;AAOG;AACI,MAAM,wBAAwB,GAAG,CACtC,QAAiD,EACjD,EAAqB,EACrB,UAA+B,KAC7B;AACF,IAAA,SAAS,CAAC,OAAO,EAAE,KAAK,SAAS,IAAI,UAAU,GAAG,SAAS,GAAG,QAAQ,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,EAAE,EAAE,UAAU,CAAC,CAAC;AAC5G;;"}
1
+ {"version":3,"file":"useSelectableRowRegistry.js","sources":["../../../../../src/components/organisms/Table/hooks/useSelectableRowRegistry.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAKA;;;;;;AAMG;AACI,MAAM,wBAAwB,GAAG,MAAK;;IAE3C,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,GAAG,EAAS,CAAC;IACvC,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,GAAG,EAAc,CAAC;AAC/C,IAAA,MAAM,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC;AAEzB,IAAA,MAAM,QAAQ,GAAG,WAAW,CAAC,CAAC,EAAS,KAAI;QACzC,MAAM,QAAQ,GAAG,MAAK;AACpB,YAAA,OAAO,CAAC,OAAO,IAAI,CAAC;AACpB,YAAA,KAAK,MAAM,QAAQ,IAAI,SAAS,CAAC,OAAO;AAAE,gBAAA,QAAQ,EAAE;AACtD,QAAA,CAAC;AACD,QAAA,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;AACtB,QAAA,QAAQ,EAAE;AACV,QAAA,OAAO,MAAK;AACV,YAAA,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;AACzB,YAAA,QAAQ,EAAE;AACZ,QAAA,CAAC;IACH,CAAC,EAAE,EAAE,CAAC;AAEN,IAAA,MAAM,SAAS,GAAG,WAAW,CAAC,CAAC,QAAoB,KAAI;AACrD,QAAA,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;AAC/B,QAAA,OAAO,MAAK;AACV,YAAA,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC;AACpC,QAAA,CAAC;IACH,CAAC,EAAE,EAAE,CAAC;AAEN,IAAA,MAAM,UAAU,GAAG,WAAW,CAAC,MAAM,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;IAEzD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE;AACpD;AAKA;;;;;;;AAOG;AACI,MAAM,wBAAwB,GAAG,CACtC,QAAiD,EACjD,EAAqB,EACrB,UAA+B,KAC7B;AACF,IAAA,SAAS,CAAC,OAAO,EAAE,KAAK,SAAS,IAAI,UAAU,GAAG,SAAS,GAAG,QAAQ,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,EAAE,EAAE,UAAU,CAAC,CAAC;AAC5G;;"}
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+ var tableSelection_utils = require('../utilities/tableSelection.utils.cjs');
5
+
6
+ // React 18's StrictMode runs a state initialiser twice and keeps the second run, so a one-shot iterator is read once per identity.
7
+ const oneShotDefaults = new WeakMap();
8
+ const defaultSelectionOf = (keys) => {
9
+ // An iterator is its own iterator, and reading it empties it; an array or a Set can be read again.
10
+ const isOneShot = typeof keys === 'object' && Object.is(keys[Symbol.iterator](), keys);
11
+ if (!isOneShot)
12
+ return new Set(keys);
13
+ const snapshot = oneShotDefaults.get(keys) ?? new Set(keys);
14
+ oneShotDefaults.set(keys, snapshot);
15
+ return snapshot;
16
+ };
17
+ /**
18
+ * Holds a table's selection above its layout switch, so a selection the consumer does not control survives the table
19
+ * becoming cards, or cards becoming the table, as the viewport crosses `md`. Every change is reported to each listener.
20
+ *
21
+ * @param options The controlled values, the default, the listeners and the row registry; see `UseTableSelectionOptions`.
22
+ * @returns `selectedKeys`, to pass to whichever layout renders, and `onSelectionChange`, which keeps an uncontrolled
23
+ * change and reports it.
24
+ */
25
+ const useTableSelection = ({ selectedKey, selectedKeys, defaultSelectedKeys, disabledKeys, rowIds, ...listeners }) => {
26
+ // Copied once, so a one-shot iterable still holds its rows for the next render and for the other layout.
27
+ const [ownSelection, setOwnSelection] = React.useState(() => {
28
+ if (defaultSelectedKeys === undefined)
29
+ return [];
30
+ return defaultSelectedKeys === 'all' ? 'all' : defaultSelectionOf(defaultSelectedKeys);
31
+ });
32
+ const isControlled = selectedKey !== undefined || selectedKeys !== undefined;
33
+ const currentSelection = () => {
34
+ if (selectedKey !== undefined)
35
+ return tableSelection_utils.selectionOfKey(selectedKey);
36
+ return selectedKeys ?? ownSelection;
37
+ };
38
+ const onSelectionChange = (selection) => {
39
+ if (!isControlled)
40
+ setOwnSelection(selection);
41
+ tableSelection_utils.reportSelectionChange(selection, rowIds.current ?? [], disabledKeys, listeners);
42
+ };
43
+ return { selectedKeys: currentSelection(), onSelectionChange };
44
+ };
45
+
46
+ exports.useTableSelection = useTableSelection;
47
+ //# sourceMappingURL=useTableSelection.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTableSelection.cjs","sources":["../../../../../src/components/organisms/Table/hooks/useTableSelection.ts"],"sourcesContent":[null],"names":["useState","selectionOfKey","reportSelectionChange"],"mappings":";;;;;AASA;AACA,MAAM,eAAe,GAAG,IAAI,OAAO,EAAsB;AAEzD,MAAM,kBAAkB,GAAG,CAAC,IAAqB,KAAgB;;IAE/D,MAAM,SAAS,GAAG,OAAO,IA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YAAY,EAAE,gBAAgB,EAAE,EAAE,iBAAiB,EAAE;AAChE;;"}
@@ -0,0 +1,31 @@
1
+ import { type RefObject } from 'react';
2
+ import type { RowId } from '../table.types';
3
+ import { type SelectionChangeListeners } from '../utilities/tableSelection.utils';
4
+ /** The selection react-aria takes and reports. */
5
+ type RowSelection = 'all' | Iterable<RowId>;
6
+ export interface UseTableSelectionOptions extends SelectionChangeListeners {
7
+ /** With `selectionMode="single"`: the selected row's id, or `null` for none. Wins over `selectedKeys`. */
8
+ selectedKey?: RowId | null;
9
+ /** The selected rows when the consumer controls them. */
10
+ selectedKeys?: RowSelection;
11
+ /** The rows selected at first when the table holds the selection itself. */
12
+ defaultSelectedKeys?: RowSelection;
13
+ /** Rows "select all" leaves out when it is reported as ids. */
14
+ disabledKeys?: Iterable<RowId>;
15
+ /** The mounted selectable rows, which "select all" is reported as. */
16
+ rowIds: RefObject<Set<RowId>>;
17
+ }
18
+ /**
19
+ * Holds a table's selection above its layout switch, so a selection the consumer does not control survives the table
20
+ * becoming cards, or cards becoming the table, as the viewport crosses `md`. Every change is reported to each listener.
21
+ *
22
+ * @param options The controlled values, the default, the listeners and the row registry; see `UseTableSelectionOptions`.
23
+ * @returns `selectedKeys`, to pass to whichever layout renders, and `onSelectionChange`, which keeps an uncontrolled
24
+ * change and reports it.
25
+ */
26
+ export declare const useTableSelection: ({ selectedKey, selectedKeys, defaultSelectedKeys, disabledKeys, rowIds, ...listeners }: UseTableSelectionOptions) => {
27
+ selectedKeys: RowSelection;
28
+ onSelectionChange: (selection: "all" | Set<RowId>) => void;
29
+ };
30
+ export {};
31
+ //# sourceMappingURL=useTableSelection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTableSelection.d.ts","sourceRoot":"","sources":["../../../../../src/components/organisms/Table/hooks/useTableSelection.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,SAAS,EAAY,MAAM,OAAO,CAAC;AACjD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAyB,KAAK,wBAAwB,EAAkB,MAAM,mCAAmC,CAAC;AAEzH,kDAAkD;AAClD,KAAK,YAAY,GAAG,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;AAc5C,MAAM,WAAW,wBAAyB,SAAQ,wBAAwB;IACxE,0GAA0G;IAC1G,WAAW,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;IAC3B,yDAAyD;IACzD,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,4EAA4E;IAC5E,mBAAmB,CAAC,EAAE,YAAY,CAAC;IACnC,+DAA+D;IAC/D,YAAY,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC/B,sEAAsE;IACtE,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;CAC/B;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,GAAI,wFAO/B,wBAAwB;;mCAaa,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC;CAMzD,CAAC"}
@@ -0,0 +1,45 @@
1
+ import { useState } from 'react';
2
+ import { reportSelectionChange, selectionOfKey } from '../utilities/tableSelection.utils.js';
3
+
4
+ // React 18's StrictMode runs a state initialiser twice and keeps the second run, so a one-shot iterator is read once per identity.
5
+ const oneShotDefaults = new WeakMap();
6
+ const defaultSelectionOf = (keys) => {
7
+ // An iterator is its own iterator, and reading it empties it; an array or a Set can be read again.
8
+ const isOneShot = typeof keys === 'object' && Object.is(keys[Symbol.iterator](), keys);
9
+ if (!isOneShot)
10
+ return new Set(keys);
11
+ const snapshot = oneShotDefaults.get(keys) ?? new Set(keys);
12
+ oneShotDefaults.set(keys, snapshot);
13
+ return snapshot;
14
+ };
15
+ /**
16
+ * Holds a table's selection above its layout switch, so a selection the consumer does not control survives the table
17
+ * becoming cards, or cards becoming the table, as the viewport crosses `md`. Every change is reported to each listener.
18
+ *
19
+ * @param options The controlled values, the default, the listeners and the row registry; see `UseTableSelectionOptions`.
20
+ * @returns `selectedKeys`, to pass to whichever layout renders, and `onSelectionChange`, which keeps an uncontrolled
21
+ * change and reports it.
22
+ */
23
+ const useTableSelection = ({ selectedKey, selectedKeys, defaultSelectedKeys, disabledKeys, rowIds, ...listeners }) => {
24
+ // Copied once, so a one-shot iterable still holds its rows for the next render and for the other layout.
25
+ const [ownSelection, setOwnSelection] = useState(() => {
26
+ if (defaultSelectedKeys === undefined)
27
+ return [];
28
+ return defaultSelectedKeys === 'all' ? 'all' : defaultSelectionOf(defaultSelectedKeys);
29
+ });
30
+ const isControlled = selectedKey !== undefined || selectedKeys !== undefined;
31
+ const currentSelection = () => {
32
+ if (selectedKey !== undefined)
33
+ return selectionOfKey(selectedKey);
34
+ return selectedKeys ?? ownSelection;
35
+ };
36
+ const onSelectionChange = (selection) => {
37
+ if (!isControlled)
38
+ setOwnSelection(selection);
39
+ reportSelectionChange(selection, rowIds.current ?? [], disabledKeys, listeners);
40
+ };
41
+ return { selectedKeys: currentSelection(), onSelectionChange };
42
+ };
43
+
44
+ export { useTableSelection };
45
+ //# sourceMappingURL=useTableSelection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTableSelection.js","sources":["../../../../../src/components/organisms/Table/hooks/useTableSelection.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AASA;AACA,MAAM,eAAe,GAAG,IAAI,OAAO,EAAsB;AAEzD,MAAM,kBAAkB,GAAG,CAAC,IAAqB,KAAgB;;IAE/D,MAAM,SAAS,GAAG,OAAO,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;AACtF,IAAA,IAAI,CAAC,SAAS;AAAE,QAAA,OAAO,IAAI,GAAG,CAAC,IAAI,CAAC;AACpC,IAAA,MAAM,QAAQ,GAAG,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,I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