@flipdish/ui-library 0.67.1 → 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 (159) hide show
  1. package/dist/components/molecules/EmptyState/index.cjs +4 -2
  2. package/dist/components/molecules/EmptyState/index.cjs.map +1 -1
  3. package/dist/components/molecules/EmptyState/index.d.ts.map +1 -1
  4. package/dist/components/molecules/EmptyState/index.js +4 -2
  5. package/dist/components/molecules/EmptyState/index.js.map +1 -1
  6. package/dist/components/molecules/Pagination/index.d.ts +1 -1
  7. package/dist/components/molecules/Pagination/index.d.ts.map +1 -1
  8. package/dist/components/molecules/Paginations/Pagination/Pagination.cjs +21 -5
  9. package/dist/components/molecules/Paginations/Pagination/Pagination.cjs.map +1 -1
  10. package/dist/components/molecules/Paginations/Pagination/Pagination.d.ts +7 -1
  11. package/dist/components/molecules/Paginations/Pagination/Pagination.d.ts.map +1 -1
  12. package/dist/components/molecules/Paginations/Pagination/Pagination.js +22 -6
  13. package/dist/components/molecules/Paginations/Pagination/Pagination.js.map +1 -1
  14. package/dist/components/molecules/Paginations/components/PaginationBase.cjs +2 -2
  15. package/dist/components/molecules/Paginations/components/PaginationBase.cjs.map +1 -1
  16. package/dist/components/molecules/Paginations/components/PaginationBase.d.ts +4 -2
  17. package/dist/components/molecules/Paginations/components/PaginationBase.d.ts.map +1 -1
  18. package/dist/components/molecules/Paginations/components/PaginationBase.js +2 -2
  19. package/dist/components/molecules/Paginations/components/PaginationBase.js.map +1 -1
  20. package/dist/components/molecules/Paginations/utilities/paginationScroll.utils.cjs +125 -0
  21. package/dist/components/molecules/Paginations/utilities/paginationScroll.utils.cjs.map +1 -0
  22. package/dist/components/molecules/Paginations/utilities/paginationScroll.utils.d.ts +42 -0
  23. package/dist/components/molecules/Paginations/utilities/paginationScroll.utils.d.ts.map +1 -0
  24. package/dist/components/molecules/Paginations/utilities/paginationScroll.utils.js +118 -0
  25. package/dist/components/molecules/Paginations/utilities/paginationScroll.utils.js.map +1 -0
  26. package/dist/components/organisms/FilterBar/index.cjs +3 -1
  27. package/dist/components/organisms/FilterBar/index.cjs.map +1 -1
  28. package/dist/components/organisms/FilterBar/index.d.ts.map +1 -1
  29. package/dist/components/organisms/FilterBar/index.js +3 -1
  30. package/dist/components/organisms/FilterBar/index.js.map +1 -1
  31. package/dist/components/organisms/Table/components/TableCardList.cjs +27 -0
  32. package/dist/components/organisms/Table/components/TableCardList.cjs.map +1 -0
  33. package/dist/components/organisms/Table/components/TableCardList.d.ts +4 -0
  34. package/dist/components/organisms/Table/components/TableCardList.d.ts.map +1 -0
  35. package/dist/components/organisms/Table/components/TableCardList.js +25 -0
  36. package/dist/components/organisms/Table/components/TableCardList.js.map +1 -0
  37. package/dist/components/organisms/Table/components/TableCardRow.cjs +80 -0
  38. package/dist/components/organisms/Table/components/TableCardRow.cjs.map +1 -0
  39. package/dist/components/organisms/Table/components/TableCardRow.d.ts +4 -0
  40. package/dist/components/organisms/Table/components/TableCardRow.d.ts.map +1 -0
  41. package/dist/components/organisms/Table/components/TableCardRow.js +78 -0
  42. package/dist/components/organisms/Table/components/TableCardRow.js.map +1 -0
  43. package/dist/components/organisms/Table/components/TableCardsSelectAll.cjs +24 -0
  44. package/dist/components/organisms/Table/components/TableCardsSelectAll.cjs.map +1 -0
  45. package/dist/components/organisms/Table/components/TableCardsSelectAll.d.ts +13 -0
  46. package/dist/components/organisms/Table/components/TableCardsSelectAll.d.ts.map +1 -0
  47. package/dist/components/organisms/Table/components/TableCardsSelectAll.js +22 -0
  48. package/dist/components/organisms/Table/components/TableCardsSelectAll.js.map +1 -0
  49. package/dist/components/organisms/Table/components/TableFallbackCard.cjs +12 -0
  50. package/dist/components/organisms/Table/components/TableFallbackCard.cjs.map +1 -0
  51. package/dist/components/organisms/Table/components/TableFallbackCard.d.ts +6 -0
  52. package/dist/components/organisms/Table/components/TableFallbackCard.d.ts.map +1 -0
  53. package/dist/components/organisms/Table/components/TableFallbackCard.js +10 -0
  54. package/dist/components/organisms/Table/components/TableFallbackCard.js.map +1 -0
  55. package/dist/components/organisms/Table/components/TableFocusGuard.cjs +23 -0
  56. package/dist/components/organisms/Table/components/TableFocusGuard.cjs.map +1 -0
  57. package/dist/components/organisms/Table/components/TableFocusGuard.d.ts +2 -0
  58. package/dist/components/organisms/Table/components/TableFocusGuard.d.ts.map +1 -0
  59. package/dist/components/organisms/Table/components/TableFocusGuard.js +21 -0
  60. package/dist/components/organisms/Table/components/TableFocusGuard.js.map +1 -0
  61. package/dist/components/organisms/Table/components/TableLayoutToggle.cjs +27 -0
  62. package/dist/components/organisms/Table/components/TableLayoutToggle.cjs.map +1 -0
  63. package/dist/components/organisms/Table/components/TableLayoutToggle.d.ts +17 -0
  64. package/dist/components/organisms/Table/components/TableLayoutToggle.d.ts.map +1 -0
  65. package/dist/components/organisms/Table/components/TableLayoutToggle.js +25 -0
  66. package/dist/components/organisms/Table/components/TableLayoutToggle.js.map +1 -0
  67. package/dist/components/organisms/Table/components/TableRowCard.cjs +79 -0
  68. package/dist/components/organisms/Table/components/TableRowCard.cjs.map +1 -0
  69. package/dist/components/organisms/Table/components/TableRowCard.d.ts +71 -0
  70. package/dist/components/organisms/Table/components/TableRowCard.d.ts.map +1 -0
  71. package/dist/components/organisms/Table/components/TableRowCard.js +72 -0
  72. package/dist/components/organisms/Table/components/TableRowCard.js.map +1 -0
  73. package/dist/components/organisms/Table/components/TableSortMenu.cjs +48 -0
  74. package/dist/components/organisms/Table/components/TableSortMenu.cjs.map +1 -0
  75. package/dist/components/organisms/Table/components/TableSortMenu.d.ts +35 -0
  76. package/dist/components/organisms/Table/components/TableSortMenu.d.ts.map +1 -0
  77. package/dist/components/organisms/Table/components/TableSortMenu.js +46 -0
  78. package/dist/components/organisms/Table/components/TableSortMenu.js.map +1 -0
  79. package/dist/components/organisms/Table/hooks/useFirstSortDirection.cjs +25 -0
  80. package/dist/components/organisms/Table/hooks/useFirstSortDirection.cjs.map +1 -0
  81. package/dist/components/organisms/Table/hooks/useFirstSortDirection.d.ts +12 -0
  82. package/dist/components/organisms/Table/hooks/useFirstSortDirection.d.ts.map +1 -0
  83. package/dist/components/organisms/Table/hooks/useFirstSortDirection.js +23 -0
  84. package/dist/components/organisms/Table/hooks/useFirstSortDirection.js.map +1 -0
  85. package/dist/components/organisms/Table/hooks/useIsAtLeastMd.cjs +21 -0
  86. package/dist/components/organisms/Table/hooks/useIsAtLeastMd.cjs.map +1 -0
  87. package/dist/components/organisms/Table/hooks/useIsAtLeastMd.d.ts +9 -0
  88. package/dist/components/organisms/Table/hooks/useIsAtLeastMd.d.ts.map +1 -0
  89. package/dist/components/organisms/Table/hooks/useIsAtLeastMd.js +19 -0
  90. package/dist/components/organisms/Table/hooks/useIsAtLeastMd.js.map +1 -0
  91. package/dist/components/organisms/Table/hooks/usePlaceholderRows.cjs +43 -0
  92. package/dist/components/organisms/Table/hooks/usePlaceholderRows.cjs.map +1 -0
  93. package/dist/components/organisms/Table/hooks/usePlaceholderRows.d.ts +23 -0
  94. package/dist/components/organisms/Table/hooks/usePlaceholderRows.d.ts.map +1 -0
  95. package/dist/components/organisms/Table/hooks/usePlaceholderRows.js +40 -0
  96. package/dist/components/organisms/Table/hooks/usePlaceholderRows.js.map +1 -0
  97. package/dist/components/organisms/Table/hooks/useSelectableRowRegistry.cjs +20 -2
  98. package/dist/components/organisms/Table/hooks/useSelectableRowRegistry.cjs.map +1 -1
  99. package/dist/components/organisms/Table/hooks/useSelectableRowRegistry.d.ts +8 -4
  100. package/dist/components/organisms/Table/hooks/useSelectableRowRegistry.d.ts.map +1 -1
  101. package/dist/components/organisms/Table/hooks/useSelectableRowRegistry.js +21 -3
  102. package/dist/components/organisms/Table/hooks/useSelectableRowRegistry.js.map +1 -1
  103. package/dist/components/organisms/Table/hooks/useTableSelection.cjs +47 -0
  104. package/dist/components/organisms/Table/hooks/useTableSelection.cjs.map +1 -0
  105. package/dist/components/organisms/Table/hooks/useTableSelection.d.ts +31 -0
  106. package/dist/components/organisms/Table/hooks/useTableSelection.d.ts.map +1 -0
  107. package/dist/components/organisms/Table/hooks/useTableSelection.js +45 -0
  108. package/dist/components/organisms/Table/hooks/useTableSelection.js.map +1 -0
  109. package/dist/components/organisms/Table/index.cjs +169 -38
  110. package/dist/components/organisms/Table/index.cjs.map +1 -1
  111. package/dist/components/organisms/Table/index.d.ts +57 -20
  112. package/dist/components/organisms/Table/index.d.ts.map +1 -1
  113. package/dist/components/organisms/Table/index.js +162 -33
  114. package/dist/components/organisms/Table/index.js.map +1 -1
  115. package/dist/components/organisms/Table/providers/Table.context.cjs +19 -0
  116. package/dist/components/organisms/Table/providers/Table.context.cjs.map +1 -0
  117. package/dist/components/organisms/Table/providers/Table.context.d.ts +44 -0
  118. package/dist/components/organisms/Table/providers/Table.context.d.ts.map +1 -0
  119. package/dist/components/organisms/Table/providers/Table.context.js +13 -0
  120. package/dist/components/organisms/Table/providers/Table.context.js.map +1 -0
  121. package/dist/components/organisms/Table/table.types.d.ts +35 -0
  122. package/dist/components/organisms/Table/table.types.d.ts.map +1 -0
  123. package/dist/components/organisms/Table/utilities/tableCard.utils.cjs +197 -0
  124. package/dist/components/organisms/Table/utilities/tableCard.utils.cjs.map +1 -0
  125. package/dist/components/organisms/Table/utilities/tableCard.utils.d.ts +161 -0
  126. package/dist/components/organisms/Table/utilities/tableCard.utils.d.ts.map +1 -0
  127. package/dist/components/organisms/Table/utilities/tableCard.utils.js +180 -0
  128. package/dist/components/organisms/Table/utilities/tableCard.utils.js.map +1 -0
  129. package/dist/components/organisms/Table/utilities/tableChildren.utils.cjs +47 -0
  130. package/dist/components/organisms/Table/utilities/tableChildren.utils.cjs.map +1 -0
  131. package/dist/components/organisms/Table/utilities/tableChildren.utils.d.ts +39 -0
  132. package/dist/components/organisms/Table/utilities/tableChildren.utils.d.ts.map +1 -0
  133. package/dist/components/organisms/Table/utilities/tableChildren.utils.js +43 -0
  134. package/dist/components/organisms/Table/utilities/tableChildren.utils.js.map +1 -0
  135. package/dist/components/organisms/Table/utilities/tableSelection.utils.cjs +106 -0
  136. package/dist/components/organisms/Table/utilities/tableSelection.utils.cjs.map +1 -0
  137. package/dist/components/organisms/Table/utilities/tableSelection.utils.d.ts +82 -0
  138. package/dist/components/organisms/Table/utilities/tableSelection.utils.d.ts.map +1 -0
  139. package/dist/components/organisms/Table/utilities/tableSelection.utils.js +98 -0
  140. package/dist/components/organisms/Table/utilities/tableSelection.utils.js.map +1 -0
  141. package/dist/components/organisms/Table/utilities/tableSort.utils.cjs +87 -0
  142. package/dist/components/organisms/Table/utilities/tableSort.utils.cjs.map +1 -0
  143. package/dist/components/organisms/Table/utilities/tableSort.utils.d.ts +67 -0
  144. package/dist/components/organisms/Table/utilities/tableSort.utils.d.ts.map +1 -0
  145. package/dist/components/organisms/Table/utilities/tableSort.utils.js +79 -0
  146. package/dist/components/organisms/Table/utilities/tableSort.utils.js.map +1 -0
  147. package/dist/utilities/searchParamsUtils/index.cjs +2 -9
  148. package/dist/utilities/searchParamsUtils/index.cjs.map +1 -1
  149. package/dist/utilities/searchParamsUtils/index.d.ts +5 -3
  150. package/dist/utilities/searchParamsUtils/index.d.ts.map +1 -1
  151. package/dist/utilities/searchParamsUtils/index.js +2 -9
  152. package/dist/utilities/searchParamsUtils/index.js.map +1 -1
  153. package/package.json +1 -1
  154. package/dist/components/organisms/Table/table.utils.cjs +0 -61
  155. package/dist/components/organisms/Table/table.utils.cjs.map +0 -1
  156. package/dist/components/organisms/Table/table.utils.d.ts +0 -48
  157. package/dist/components/organisms/Table/table.utils.d.ts.map +0 -1
  158. package/dist/components/organisms/Table/table.utils.js +0 -55
  159. package/dist/components/organisms/Table/table.utils.js.map +0 -1
@@ -0,0 +1,72 @@
1
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
+ import { Checkbox } from '@flipdish/ui-library/components/atoms/Checkboxes';
3
+ import { Skeleton } from '@flipdish/ui-library/components/atoms/Skeleton';
4
+ import { cx } from '@flipdish/ui-library/utilities/cx';
5
+ import { isProductionBuild } from '@flipdish/ui-library/utilities/renderUtils';
6
+ import { joinTestId } from '@flipdish/ui-library/utilities/testIdUtils';
7
+ import { useContext, useEffect, isValidElement } from 'react';
8
+ import { flattenChildren } from '../../../../utilities/__internal__/childrenUtils/children.utils.js';
9
+ import { warnOnce } from '../../../../utilities/__internal__/logUtils/log.utils.js';
10
+ import { TableContext, TableRowCardContext, TableRowCardSurfaceContext, TableRowCardHeaderCheckboxContext } from '../providers/Table.context.js';
11
+ import { isSlotShown } from '../utilities/tableCard.utils.js';
12
+
13
+ // The row's own selection checkbox, react-aria's `selection` slot, centred on the title's 20px line.
14
+ const TableRowCardSelectionCheckbox = ({ rowTestId, isPlaceholder }) => (jsx("div", { className: "flex h-5 shrink-0 items-center", children: isPlaceholder ? (
15
+ // A placeholder holds the box's place, so its title sits where the loaded row's will.
16
+ jsx(Skeleton, { width: 20, height: 20, radius: "md" })) : (
17
+ // 12px of padding, taken back by a negative margin: a 44px touch target around the 20px box that moves nothing.
18
+ jsx(Checkbox, { slot: "selection", size: "md", className: "-m-3 p-3", "data-testid": rowTestId ? joinTestId(rowTestId, 'selection') : undefined })) }));
19
+ /** The card a `Table.Row` renders in place of its cells in the cards layout; a direct child of the row, and nothing in the table. */
20
+ const TableRowCard = ({ children, className, 'data-testid': dataTestId }) => {
21
+ const { layout } = useContext(TableContext);
22
+ const row = useContext(TableRowCardContext);
23
+ // Inside another card's surface this is not the row's own card: one wrapped in another element lands among the cells.
24
+ const isNested = useContext(TableRowCardSurfaceContext);
25
+ const isMisplaced = layout === 'cards' && isNested;
26
+ useEffect(() => {
27
+ if (!isMisplaced || isProductionBuild())
28
+ return;
29
+ warnOnce('Table:nested-card', 'Table: a `Table.RowCard` renders only as a direct child of `Table.Row`; one inside another element renders nothing.');
30
+ }, [isMisplaced]);
31
+ if (layout !== 'cards' || !row || isNested)
32
+ return null;
33
+ // Only the card's first direct header takes the checkbox; without one, the card gives it a row of its own.
34
+ const parts = flattenChildren(children);
35
+ const headerIndex = row.showsSelection ? parts.findIndex((part) => isValidElement(part) && part.type === TableRowCardHeader) : -1;
36
+ const renderPart = (part, index) => index === headerIndex && isValidElement(part) ? (jsx(TableRowCardHeaderCheckboxContext.Provider, { value: true, children: part }, part.key)) : (part);
37
+ return (jsx(TableRowCardSurfaceContext.Provider, { value: true, children: jsxs("div", { "data-testid": dataTestId ?? (row.testId ? joinTestId(row.testId, 'card') : undefined), className: cx(
38
+ // `flex-1` fills a row of cards to the height of the tallest.
39
+ 'flex flex-1 flex-col overflow-hidden rounded-xl border border-secondary bg-primary text-left outline-focus-ring transition-colors duration-100 ease-linear', row.isInteractive ? 'cursor-pointer' : 'cursor-default',
40
+ // Before the states, so a tinted card still shows hover, press and highlight.
41
+ className, row.isHovered && 'bg-primary_hover', row.isPressed && 'bg-secondary_hover',
42
+ // `_alt` is brand-50 in light, like `bg-brand-primary`, and stays a surface in dark, where `bg-brand-primary` is solid brand-500.
43
+ row.isHighlighted && 'border-brand bg-brand-primary_alt', row.isFocusVisible && 'outline-2 outline-offset-2'), children: [row.showsSelection && headerIndex === -1 && (jsx("div", { className: "flex px-4 pt-4 last:pb-4", children: jsx(TableRowCardSelectionCheckbox, { rowTestId: row.testId, isPlaceholder: row.isPlaceholder }) })), parts.map(renderPart)] }) }));
44
+ };
45
+ TableRowCard.displayName = 'TableRowCard';
46
+ /** The card's first row: the selection checkbox on a selectable table, an optional avatar, the title over its description, and a trailing badge. */
47
+ const TableRowCardHeader = ({ title, description, badge, avatar, className }) => {
48
+ const showsCheckbox = useContext(TableRowCardHeaderCheckboxContext);
49
+ const row = useContext(TableRowCardContext);
50
+ return (jsxs("div", { className: cx('flex items-start gap-3 px-4 pt-4 last:pb-4', className), children: [showsCheckbox && jsx(TableRowCardSelectionCheckbox, { rowTestId: row?.testId, isPlaceholder: row?.isPlaceholder }), jsxs(TableRowCardHeaderCheckboxContext.Provider, { value: false, children: [isSlotShown(avatar) && jsx("div", { className: "flex shrink-0", children: avatar }), jsxs("div", { className: "flex min-w-0 flex-1 flex-col", children: [jsx("div", { className: "truncate text-sm font-semibold text-primary", children: title }), isSlotShown(description) && jsx("div", { className: "text-xs text-tertiary", children: description })] }), isSlotShown(badge) && jsx("div", { className: "flex shrink-0 items-center gap-2 whitespace-nowrap", children: badge })] })] }));
51
+ };
52
+ TableRowCardHeader.displayName = 'TableRowCardHeader';
53
+ /** A wrapping row under the header for badges and icons; give an icon-only item an accessible name. */
54
+ const TableRowCardContent = ({ children, className }) => (jsx("div", { className: cx('flex flex-wrap items-center gap-2 px-4 pt-3 last:pb-4', className), children: children }));
55
+ TableRowCardContent.displayName = 'TableRowCardContent';
56
+ /** A tinted strip across the bottom of the card, under a divider, with a start and an end value. */
57
+ const TableRowCardFooter = ({ start, end, className }) => (
58
+ // `mt-auto` keeps the strip at the bottom of a card stretched to its row's height; `pt-4` keeps 16px above it.
59
+ jsx("div", { className: "mt-auto pt-4", children: jsxs("div", { className: cx('flex items-center gap-3 border-t border-secondary bg-secondary px-4 py-3 text-sm font-semibold text-primary', className), children: [isSlotShown(start) && jsx("div", { className: "min-w-0 flex-1 truncate", children: start }), isSlotShown(end) && jsx("div", { className: "ml-auto shrink-0 whitespace-nowrap", children: end })] }) }));
60
+ TableRowCardFooter.displayName = 'TableRowCardFooter';
61
+ /** A placeholder card for a loading row; the row carrying it is disabled and the table's row action skips it. */
62
+ const TableRowCardSkeleton = ({ children }) => (jsx(TableRowCard, { children: children ?? (jsxs(Fragment, { children: [jsx(TableRowCardHeader, { title: jsx(Skeleton, { width: 96, height: 14, radius: "sm", className: "my-[3px]" }), description: jsx(Skeleton, { width: 128, height: 12, radius: "sm", className: "mt-1" }), badge: jsx(Skeleton, { width: 64, height: 22, radius: "full" }) }), jsxs(TableRowCardContent, { children: [jsx(Skeleton, { width: 20, height: 20, radius: "sm" }), jsx(Skeleton, { width: 20, height: 20, radius: "sm" }), jsx(Skeleton, { width: 72, height: 22, radius: "full" })] }), jsx(TableRowCardFooter, { start: jsx(Skeleton, { width: 120, height: 14, radius: "sm" }), end: jsx(Skeleton, { width: 56, height: 14, radius: "sm" }) })] })) }));
63
+ TableRowCardSkeleton.displayName = 'TableRowCardSkeleton';
64
+ /**
65
+ * Tells a row's card apart from its cells.
66
+ * @param element - One of the row's direct children.
67
+ * @returns `true` for a `Table.RowCard` or a `Table.RowCard.Skeleton`.
68
+ */
69
+ const isRowCardElement = (element) => element.type === TableRowCard || element.type === TableRowCardSkeleton;
70
+
71
+ export { TableRowCard, TableRowCardContent, TableRowCardFooter, TableRowCardHeader, TableRowCardSkeleton, isRowCardElement };
72
+ //# sourceMappingURL=TableRowCard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TableRowCard.js","sources":["../../../../../src/components/organisms/Table/components/TableRowCard.tsx"],"sourcesContent":[null],"names":["_jsx","_jsxs"],"mappings":";;;;;;;;;;;;AAaA;AACA,MAAM,6BAA6B,GAAG,CAAC,EAAE,SAAS,EAAE,aAAa,EAAmD,MAClHA,GAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAC,gCAAgC,YAC5C,aAAa;;AAEZ,IAAAA,GAAA,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAC,IAAI,GAAG;;AAG/C,IAAAA,GAAA,CAAC,QAAQ,EAAA,EAAC,IAAI,EAAC,WAAW,EAAC,IAAI,EAAC,IAAI,EAAC,SAAS,EAAC,UAAU,iBAAc,SAAS,GAAG,UAAU,CAAC,SAAS,EAAE,WAAW,CAAC,GAAG,SAAS,EAAA,CAAI,CACtI,EAAA,CACG,CACP;AAWD;AACO,MAAM,YAAY,GAAG,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAqB,KAAI;IACpG,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,YAAY,CAAC;AAC3C,IAAA,MAAM,GAAG,GAAG,UAAU,CAAC,mBAAmB,CAAC;;AAE3C,IAAA,MAA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,YAAY,IAAI,OAAO,CAAC,IAAI,KAAK;;"}
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var uiIcons = require('@flipdish/ui-icons');
5
+ var Buttons = require('@flipdish/ui-library/components/atoms/Buttons');
6
+ var Dropdown = require('@flipdish/ui-library/components/molecules/Dropdown');
7
+ var cx = require('@flipdish/ui-library/utilities/cx');
8
+ var testIdUtils = require('@flipdish/ui-library/utilities/testIdUtils');
9
+ var useIsAtLeastMd = require('../hooks/useIsAtLeastMd.cjs');
10
+ var tableCard_utils = require('../utilities/tableCard.utils.cjs');
11
+ var tableSort_utils = require('../utilities/tableSort.utils.cjs');
12
+
13
+ const firstKeyOf = (selection) => (selection === 'all' ? undefined : [...selection][0]);
14
+ /** 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`. */
15
+ const TableSortMenu = ({ columns, sortDescriptor, defaultSortDescriptor, onSortChange, mobileLayout = 'cards', desktopLayout = 'table', size = 'md', className, 'data-testid': dataTestId, }) => {
16
+ const rootTestId = testIdUtils.useResolvedTestId({ testId: dataTestId, segment: 'table-sort-menu', rootName: 'table-sort-menu' });
17
+ // Icon-only on the server and while hydrating too, so the two renders agree; the label comes once the viewport is known.
18
+ const isAtLeastMd = useIsAtLeastMd.useIsAtLeastMd();
19
+ const isIconOnly = !isAtLeastMd;
20
+ const sortedColumn = sortDescriptor ? columns.find((column) => column.id === sortDescriptor.column) : undefined;
21
+ const sortName = sortedColumn && sortDescriptor ? `Sort by ${sortedColumn.label}, ${sortDescriptor.direction}` : undefined;
22
+ // The order differs from the one the page rests at, so there is something to clear and the icon marks it.
23
+ const isAwayFromRest = !tableSort_utils.isSameSort(sortDescriptor, defaultSortDescriptor);
24
+ const chooseColumn = (selection) => {
25
+ const column = tableSort_utils.columnOfSortMenuKey(columns, firstKeyOf(selection));
26
+ if (column)
27
+ onSortChange(tableSort_utils.sortOfColumnChoice(sortDescriptor, column.id));
28
+ };
29
+ const chooseDirection = (selection) => {
30
+ const direction = firstKeyOf(selection);
31
+ if (direction === 'ascending' || direction === 'descending')
32
+ onSortChange(tableSort_utils.sortOfDirectionChoice(sortDescriptor, direction));
33
+ };
34
+ const clearSort = () => onSortChange(defaultSortDescriptor);
35
+ const renderColumnItem = (column) => (jsxRuntime.jsx(Dropdown.Dropdown.Item, { id: tableSort_utils.sortMenuColumnKeyOf(column.id), label: column.label }, tableSort_utils.sortMenuColumnKeyOf(column.id)));
36
+ // Read as the table reads it, so the two always agree, on the server and while hydrating too.
37
+ if (tableCard_utils.tableLayoutOf(isAtLeastMd, mobileLayout, desktopLayout) === 'table')
38
+ return null;
39
+ return (jsxRuntime.jsxs(Dropdown.Dropdown.Root, { "data-testid": rootTestId, children: [isIconOnly ? (jsxRuntime.jsx(Buttons.Button, { color: "secondary", size: size, iconLeading: uiIcons.SwitchVertical01, className: cx.cx('shrink-0',
40
+ // A decorative dot while the sort differs from the resting one; the name already states what the sort is.
41
+ 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": testIdUtils.joinTestId(rootTestId, 'trigger') })) : (jsxRuntime.jsxs(Buttons.Button, { color: "secondary", size: size, iconLeading: uiIcons.SwitchVertical01,
42
+ // The label truncates, so the trigger never grows wider than the space it is given.
43
+ className: cx.cx('max-w-full min-w-0 *:data-text:min-w-0 *:data-text:truncate', className), "aria-label": sortName, "data-testid": testIdUtils.joinTestId(rootTestId, 'trigger'), children: ["Sort by", sortedColumn && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [' ', jsxRuntime.jsx("span", { className: "text-tertiary", children: sortedColumn.label })] }))] })), jsxRuntime.jsx(Dropdown.Dropdown.Popover, { children: jsxRuntime.jsxs(Dropdown.Dropdown.Menu, { "aria-label": "Sort by", children: [jsxRuntime.jsx(Dropdown.Dropdown.Section, { "aria-label": "Column", selectionMode: "single", disallowEmptySelection: true, selectedKeys: sortedColumn ? [tableSort_utils.sortMenuColumnKeyOf(sortedColumn.id)] : [], onSelectionChange: chooseColumn, children: columns.map(renderColumnItem) }), jsxRuntime.jsx(Dropdown.Dropdown.Separator, {}), jsxRuntime.jsxs(Dropdown.Dropdown.Section, { "aria-label": "Direction", selectionMode: "single", disallowEmptySelection: true, selectedKeys: sortedColumn && sortDescriptor ? [sortDescriptor.direction] : [], onSelectionChange: chooseDirection, children: [jsxRuntime.jsx(Dropdown.Dropdown.Item, { id: "ascending", label: "Ascending", isDisabled: !sortedColumn }), jsxRuntime.jsx(Dropdown.Dropdown.Item, { id: "descending", label: "Descending", isDisabled: !sortedColumn })] }), isAwayFromRest && jsxRuntime.jsx(Dropdown.Dropdown.Separator, {}), isAwayFromRest && jsxRuntime.jsx(Dropdown.Dropdown.Item, { id: "clear", label: "Clear sort", onAction: clearSort })] }) })] }));
44
+ };
45
+ TableSortMenu.displayName = 'TableSortMenu';
46
+
47
+ exports.TableSortMenu = TableSortMenu;
48
+ //# sourceMappingURL=TableSortMenu.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TableSortMenu.cjs","sources":["../../../../../src/components/organisms/Table/components/TableSortMenu.tsx"],"sourcesContent":[null],"names":["useResolvedTestId","useIsAtLeastMd","isSameSort","columnOfSortMenuKey","sortOfColumnChoice","sortOfDirectionChoice","_jsx","Dropdown","sortMenuColumnKeyOf","tableLayoutOf","_jsxs","Button","SwitchVertical01","cx","joinTestId","_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,GAA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AC,WAAW,GAAG,eAAe;;"}
@@ -0,0 +1,35 @@
1
+ import type { Key, SortDescriptor } from 'react-aria-components';
2
+ import type { TableLayout } from '../table.types';
3
+ export interface TableSortMenuProps {
4
+ /** The columns a user can sort by, in menu order: each `id` is its `Table.Head`'s `id`, and `label` names it in the menu. */
5
+ columns: readonly {
6
+ id: Key;
7
+ label: string;
8
+ }[];
9
+ /** The table's current sort; unset while nothing is sorted. */
10
+ sortDescriptor?: SortDescriptor;
11
+ /**
12
+ * What "Clear sort" reports, the table's own `defaultSortDescriptor`: the page's resting sort, which the page starts its
13
+ * `sortDescriptor` from. While the sort matches it the icon-only trigger has no dot and the menu no "Clear sort". Omitted,
14
+ * a clear reports `undefined`.
15
+ */
16
+ defaultSortDescriptor?: SortDescriptor;
17
+ /** Called with the sort the user picks, or `defaultSortDescriptor` from "Clear sort"; pass the handler the table's `onSortChange` gets. */
18
+ onSortChange: (descriptor: SortDescriptor | undefined) => void;
19
+ /** The table's `mobileLayout`: the menu renders nothing below `md` while that is the table, which its headers sort. */
20
+ mobileLayout?: TableLayout;
21
+ /** The table's `desktopLayout`: the menu renders nothing from `md` up while that is the table, as it is by default. */
22
+ desktopLayout?: TableLayout;
23
+ /** The trigger's size, as a `Button`'s. */
24
+ size?: 'sm' | 'md';
25
+ /** Classes for the trigger button, such as `w-full` to fill a row. */
26
+ className?: string;
27
+ /** Overrides the root `data-testid` (defaults to `fd-table-sort-menu`); the trigger derives `<root>--trigger` and each item `<root>--item-<key>`. */
28
+ 'data-testid'?: string;
29
+ }
30
+ /** 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`. */
31
+ export declare const TableSortMenu: {
32
+ ({ columns, sortDescriptor, defaultSortDescriptor, onSortChange, mobileLayout, desktopLayout, size, className, "data-testid": dataTestId, }: TableSortMenuProps): import("react").JSX.Element | null;
33
+ displayName: string;
34
+ };
35
+ //# sourceMappingURL=TableSortMenu.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TableSortMenu.d.ts","sourceRoot":"","sources":["../../../../../src/components/organisms/Table/components/TableSortMenu.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,GAAG,EAAa,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAIlD,MAAM,WAAW,kBAAkB;IACjC,6HAA6H;IAC7H,OAAO,EAAE,SAAS;QAAE,EAAE,EAAE,GAAG,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC/C,+DAA+D;IAC/D,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,cAAc,CAAC;IACvC,2IAA2I;IAC3I,YAAY,EAAE,CAAC,UAAU,EAAE,cAAc,GAAG,SAAS,KAAK,IAAI,CAAC;IAC/D,uHAAuH;IACvH,YAAY,CAAC,EAAE,WAAW,CAAC;IAC3B,uHAAuH;IACvH,aAAa,CAAC,EAAE,WAAW,CAAC;IAC5B,2CAA2C;IAC3C,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACnB,sEAAsE;IACtE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qJAAqJ;IACrJ,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAID,iJAAiJ;AACjJ,eAAO,MAAM,aAAa;iJAUvB,kBAAkB;;CA2FpB,CAAC"}
@@ -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,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,iBAAiB,EAAE,CAAC;;AAErH,IAAA,MAAM,WAAW,GAAG,cAAc,EAAE;AACpC,IAAA,MAAM,UAAU,GAAG,CAAC,WAAW;IAC/B,MAAM,YAAY,GAAG,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,EAAE,KAAK,cAAc,CAAC,MAAM,CAAC,GAAG,SAAS;IAC/G,MAAM,QAAQ,GAAG,YAAY,IAAI,cAAc,GAAG,CAAA,QAAA,EAAW,YAAY,CAAC,KAAK,CAAA,EAAA,EAAK,cAAc,CAAC,SAAS,EAAE,GAAG,SAAS;;IAE1H,MAAM,cAAc,GAAG,CAAC,UAAU,CAAC,cAAc,EAAE,qBAAqB,CAAC;AAEzE,IAAA,MAAM,YAAY,GAAG,CAAC,SAAoB,KAAI;QAC5C,MAAM,MAAM,GAAG,mBAAmB,CAAC,OAAO,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC;AAClE,QAAA,IAAI,MAAM;YAAE,YAAY,CAAC,kBAAkB,CAAC,cAAc,EAAE,MAAM,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AC,EAAE,EAAC,YAAY,EAAC,KAAK,EAAC,YAAY,EAAC,UAAU,EAAE,CAAC,YAAY,GAAI,CAAA,EAAA,CAC9D,EAClB,cAAc,IAAIA,GAAA,CAAC,QAAQ,CAAC,SAAS,EAAA,EAAA,CAAG,EACxC,cAAc,IAAIA,IAAC,QAAQ,CAAC,IAAI,EAAA,EAAC,EAAE,EAAC,OAAO,EAAC,KAAK,EAAC,YAAY,EAAC,QAAQ,EAAE,SAAS,GAAI,CAAA,EAAA,CACzE,EAAA,CACC,CAAA,EAAA,CACL;AAEpB;AACA,aAAa,CAAC,WAAW,GAAG,eAAe;;"}
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+ var tableSort_utils = require('../utilities/tableSort.utils.cjs');
5
+
6
+ /**
7
+ * Remembers 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,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
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