@flipdish/ui-library 0.67.1 → 0.69.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.
- package/dist/components/atoms/PhoneInput/hooks/usePhoneEntry.cjs +10 -4
- package/dist/components/atoms/PhoneInput/hooks/usePhoneEntry.cjs.map +1 -1
- package/dist/components/atoms/PhoneInput/hooks/usePhoneEntry.d.ts +3 -3
- package/dist/components/atoms/PhoneInput/hooks/usePhoneEntry.d.ts.map +1 -1
- package/dist/components/atoms/PhoneInput/hooks/usePhoneEntry.js +11 -5
- package/dist/components/atoms/PhoneInput/hooks/usePhoneEntry.js.map +1 -1
- package/dist/components/atoms/PhoneInput/utilities/phoneEntry.utils.cjs +13 -0
- package/dist/components/atoms/PhoneInput/utilities/phoneEntry.utils.cjs.map +1 -1
- package/dist/components/atoms/PhoneInput/utilities/phoneEntry.utils.d.ts +9 -0
- package/dist/components/atoms/PhoneInput/utilities/phoneEntry.utils.d.ts.map +1 -1
- package/dist/components/atoms/PhoneInput/utilities/phoneEntry.utils.js +14 -2
- package/dist/components/atoms/PhoneInput/utilities/phoneEntry.utils.js.map +1 -1
- package/dist/components/atoms/PhoneInput/utilities/phoneInput.utils.cjs +51 -16
- package/dist/components/atoms/PhoneInput/utilities/phoneInput.utils.cjs.map +1 -1
- package/dist/components/atoms/PhoneInput/utilities/phoneInput.utils.d.ts +19 -6
- package/dist/components/atoms/PhoneInput/utilities/phoneInput.utils.d.ts.map +1 -1
- package/dist/components/atoms/PhoneInput/utilities/phoneInput.utils.js +51 -17
- package/dist/components/atoms/PhoneInput/utilities/phoneInput.utils.js.map +1 -1
- package/dist/components/forms/Form/index.cjs +5 -3
- package/dist/components/forms/Form/index.cjs.map +1 -1
- package/dist/components/forms/Form/index.d.ts +8 -2
- package/dist/components/forms/Form/index.d.ts.map +1 -1
- package/dist/components/forms/Form/index.js +5 -3
- package/dist/components/forms/Form/index.js.map +1 -1
- package/dist/components/forms/Form/utilities/focusFromCode.utils.cjs +47 -0
- package/dist/components/forms/Form/utilities/focusFromCode.utils.cjs.map +1 -0
- package/dist/components/forms/Form/utilities/focusFromCode.utils.d.ts +12 -0
- package/dist/components/forms/Form/utilities/focusFromCode.utils.d.ts.map +1 -0
- package/dist/components/forms/Form/utilities/focusFromCode.utils.js +45 -0
- package/dist/components/forms/Form/utilities/focusFromCode.utils.js.map +1 -0
- package/dist/components/molecules/EmptyState/index.cjs +4 -2
- package/dist/components/molecules/EmptyState/index.cjs.map +1 -1
- package/dist/components/molecules/EmptyState/index.d.ts.map +1 -1
- package/dist/components/molecules/EmptyState/index.js +4 -2
- package/dist/components/molecules/EmptyState/index.js.map +1 -1
- package/dist/components/molecules/Pagination/index.d.ts +1 -1
- package/dist/components/molecules/Pagination/index.d.ts.map +1 -1
- package/dist/components/molecules/Paginations/Pagination/Pagination.cjs +21 -5
- package/dist/components/molecules/Paginations/Pagination/Pagination.cjs.map +1 -1
- package/dist/components/molecules/Paginations/Pagination/Pagination.d.ts +7 -1
- package/dist/components/molecules/Paginations/Pagination/Pagination.d.ts.map +1 -1
- package/dist/components/molecules/Paginations/Pagination/Pagination.js +22 -6
- package/dist/components/molecules/Paginations/Pagination/Pagination.js.map +1 -1
- package/dist/components/molecules/Paginations/components/PaginationBase.cjs +2 -2
- package/dist/components/molecules/Paginations/components/PaginationBase.cjs.map +1 -1
- package/dist/components/molecules/Paginations/components/PaginationBase.d.ts +4 -2
- package/dist/components/molecules/Paginations/components/PaginationBase.d.ts.map +1 -1
- package/dist/components/molecules/Paginations/components/PaginationBase.js +2 -2
- package/dist/components/molecules/Paginations/components/PaginationBase.js.map +1 -1
- package/dist/components/molecules/Paginations/utilities/paginationScroll.utils.cjs +125 -0
- package/dist/components/molecules/Paginations/utilities/paginationScroll.utils.cjs.map +1 -0
- package/dist/components/molecules/Paginations/utilities/paginationScroll.utils.d.ts +42 -0
- package/dist/components/molecules/Paginations/utilities/paginationScroll.utils.d.ts.map +1 -0
- package/dist/components/molecules/Paginations/utilities/paginationScroll.utils.js +118 -0
- package/dist/components/molecules/Paginations/utilities/paginationScroll.utils.js.map +1 -0
- package/dist/components/organisms/FilterBar/index.cjs +3 -1
- package/dist/components/organisms/FilterBar/index.cjs.map +1 -1
- package/dist/components/organisms/FilterBar/index.d.ts.map +1 -1
- package/dist/components/organisms/FilterBar/index.js +3 -1
- package/dist/components/organisms/FilterBar/index.js.map +1 -1
- package/dist/components/organisms/Table/components/TableCardList.cjs +27 -0
- package/dist/components/organisms/Table/components/TableCardList.cjs.map +1 -0
- package/dist/components/organisms/Table/components/TableCardList.d.ts +4 -0
- package/dist/components/organisms/Table/components/TableCardList.d.ts.map +1 -0
- package/dist/components/organisms/Table/components/TableCardList.js +25 -0
- package/dist/components/organisms/Table/components/TableCardList.js.map +1 -0
- package/dist/components/organisms/Table/components/TableCardRow.cjs +80 -0
- package/dist/components/organisms/Table/components/TableCardRow.cjs.map +1 -0
- package/dist/components/organisms/Table/components/TableCardRow.d.ts +4 -0
- package/dist/components/organisms/Table/components/TableCardRow.d.ts.map +1 -0
- package/dist/components/organisms/Table/components/TableCardRow.js +78 -0
- package/dist/components/organisms/Table/components/TableCardRow.js.map +1 -0
- package/dist/components/organisms/Table/components/TableCardsSelectAll.cjs +24 -0
- package/dist/components/organisms/Table/components/TableCardsSelectAll.cjs.map +1 -0
- package/dist/components/organisms/Table/components/TableCardsSelectAll.d.ts +13 -0
- package/dist/components/organisms/Table/components/TableCardsSelectAll.d.ts.map +1 -0
- package/dist/components/organisms/Table/components/TableCardsSelectAll.js +22 -0
- package/dist/components/organisms/Table/components/TableCardsSelectAll.js.map +1 -0
- package/dist/components/organisms/Table/components/TableFallbackCard.cjs +12 -0
- package/dist/components/organisms/Table/components/TableFallbackCard.cjs.map +1 -0
- package/dist/components/organisms/Table/components/TableFallbackCard.d.ts +6 -0
- package/dist/components/organisms/Table/components/TableFallbackCard.d.ts.map +1 -0
- package/dist/components/organisms/Table/components/TableFallbackCard.js +10 -0
- package/dist/components/organisms/Table/components/TableFallbackCard.js.map +1 -0
- package/dist/components/organisms/Table/components/TableFocusGuard.cjs +23 -0
- package/dist/components/organisms/Table/components/TableFocusGuard.cjs.map +1 -0
- package/dist/components/organisms/Table/components/TableFocusGuard.d.ts +2 -0
- package/dist/components/organisms/Table/components/TableFocusGuard.d.ts.map +1 -0
- package/dist/components/organisms/Table/components/TableFocusGuard.js +21 -0
- package/dist/components/organisms/Table/components/TableFocusGuard.js.map +1 -0
- package/dist/components/organisms/Table/components/TableLayoutToggle.cjs +27 -0
- package/dist/components/organisms/Table/components/TableLayoutToggle.cjs.map +1 -0
- package/dist/components/organisms/Table/components/TableLayoutToggle.d.ts +17 -0
- package/dist/components/organisms/Table/components/TableLayoutToggle.d.ts.map +1 -0
- package/dist/components/organisms/Table/components/TableLayoutToggle.js +25 -0
- package/dist/components/organisms/Table/components/TableLayoutToggle.js.map +1 -0
- package/dist/components/organisms/Table/components/TableRowCard.cjs +79 -0
- package/dist/components/organisms/Table/components/TableRowCard.cjs.map +1 -0
- package/dist/components/organisms/Table/components/TableRowCard.d.ts +71 -0
- package/dist/components/organisms/Table/components/TableRowCard.d.ts.map +1 -0
- package/dist/components/organisms/Table/components/TableRowCard.js +72 -0
- package/dist/components/organisms/Table/components/TableRowCard.js.map +1 -0
- package/dist/components/organisms/Table/components/TableSortMenu.cjs +48 -0
- package/dist/components/organisms/Table/components/TableSortMenu.cjs.map +1 -0
- package/dist/components/organisms/Table/components/TableSortMenu.d.ts +35 -0
- package/dist/components/organisms/Table/components/TableSortMenu.d.ts.map +1 -0
- package/dist/components/organisms/Table/components/TableSortMenu.js +46 -0
- package/dist/components/organisms/Table/components/TableSortMenu.js.map +1 -0
- package/dist/components/organisms/Table/hooks/useFirstSortDirection.cjs +25 -0
- package/dist/components/organisms/Table/hooks/useFirstSortDirection.cjs.map +1 -0
- package/dist/components/organisms/Table/hooks/useFirstSortDirection.d.ts +12 -0
- package/dist/components/organisms/Table/hooks/useFirstSortDirection.d.ts.map +1 -0
- package/dist/components/organisms/Table/hooks/useFirstSortDirection.js +23 -0
- package/dist/components/organisms/Table/hooks/useFirstSortDirection.js.map +1 -0
- package/dist/components/organisms/Table/hooks/useIsAtLeastMd.cjs +21 -0
- package/dist/components/organisms/Table/hooks/useIsAtLeastMd.cjs.map +1 -0
- package/dist/components/organisms/Table/hooks/useIsAtLeastMd.d.ts +9 -0
- package/dist/components/organisms/Table/hooks/useIsAtLeastMd.d.ts.map +1 -0
- package/dist/components/organisms/Table/hooks/useIsAtLeastMd.js +19 -0
- package/dist/components/organisms/Table/hooks/useIsAtLeastMd.js.map +1 -0
- package/dist/components/organisms/Table/hooks/usePlaceholderRows.cjs +43 -0
- package/dist/components/organisms/Table/hooks/usePlaceholderRows.cjs.map +1 -0
- package/dist/components/organisms/Table/hooks/usePlaceholderRows.d.ts +23 -0
- package/dist/components/organisms/Table/hooks/usePlaceholderRows.d.ts.map +1 -0
- package/dist/components/organisms/Table/hooks/usePlaceholderRows.js +40 -0
- package/dist/components/organisms/Table/hooks/usePlaceholderRows.js.map +1 -0
- package/dist/components/organisms/Table/hooks/useSelectableRowRegistry.cjs +20 -2
- package/dist/components/organisms/Table/hooks/useSelectableRowRegistry.cjs.map +1 -1
- package/dist/components/organisms/Table/hooks/useSelectableRowRegistry.d.ts +8 -4
- package/dist/components/organisms/Table/hooks/useSelectableRowRegistry.d.ts.map +1 -1
- package/dist/components/organisms/Table/hooks/useSelectableRowRegistry.js +21 -3
- package/dist/components/organisms/Table/hooks/useSelectableRowRegistry.js.map +1 -1
- package/dist/components/organisms/Table/hooks/useTableSelection.cjs +47 -0
- package/dist/components/organisms/Table/hooks/useTableSelection.cjs.map +1 -0
- package/dist/components/organisms/Table/hooks/useTableSelection.d.ts +31 -0
- package/dist/components/organisms/Table/hooks/useTableSelection.d.ts.map +1 -0
- package/dist/components/organisms/Table/hooks/useTableSelection.js +45 -0
- package/dist/components/organisms/Table/hooks/useTableSelection.js.map +1 -0
- package/dist/components/organisms/Table/index.cjs +169 -38
- package/dist/components/organisms/Table/index.cjs.map +1 -1
- package/dist/components/organisms/Table/index.d.ts +57 -20
- package/dist/components/organisms/Table/index.d.ts.map +1 -1
- package/dist/components/organisms/Table/index.js +162 -33
- package/dist/components/organisms/Table/index.js.map +1 -1
- package/dist/components/organisms/Table/providers/Table.context.cjs +19 -0
- package/dist/components/organisms/Table/providers/Table.context.cjs.map +1 -0
- package/dist/components/organisms/Table/providers/Table.context.d.ts +44 -0
- package/dist/components/organisms/Table/providers/Table.context.d.ts.map +1 -0
- package/dist/components/organisms/Table/providers/Table.context.js +13 -0
- package/dist/components/organisms/Table/providers/Table.context.js.map +1 -0
- package/dist/components/organisms/Table/table.types.d.ts +35 -0
- package/dist/components/organisms/Table/table.types.d.ts.map +1 -0
- package/dist/components/organisms/Table/utilities/tableCard.utils.cjs +197 -0
- package/dist/components/organisms/Table/utilities/tableCard.utils.cjs.map +1 -0
- package/dist/components/organisms/Table/utilities/tableCard.utils.d.ts +161 -0
- package/dist/components/organisms/Table/utilities/tableCard.utils.d.ts.map +1 -0
- package/dist/components/organisms/Table/utilities/tableCard.utils.js +180 -0
- package/dist/components/organisms/Table/utilities/tableCard.utils.js.map +1 -0
- package/dist/components/organisms/Table/utilities/tableChildren.utils.cjs +47 -0
- package/dist/components/organisms/Table/utilities/tableChildren.utils.cjs.map +1 -0
- package/dist/components/organisms/Table/utilities/tableChildren.utils.d.ts +39 -0
- package/dist/components/organisms/Table/utilities/tableChildren.utils.d.ts.map +1 -0
- package/dist/components/organisms/Table/utilities/tableChildren.utils.js +43 -0
- package/dist/components/organisms/Table/utilities/tableChildren.utils.js.map +1 -0
- package/dist/components/organisms/Table/utilities/tableSelection.utils.cjs +106 -0
- package/dist/components/organisms/Table/utilities/tableSelection.utils.cjs.map +1 -0
- package/dist/components/organisms/Table/utilities/tableSelection.utils.d.ts +82 -0
- package/dist/components/organisms/Table/utilities/tableSelection.utils.d.ts.map +1 -0
- package/dist/components/organisms/Table/utilities/tableSelection.utils.js +98 -0
- package/dist/components/organisms/Table/utilities/tableSelection.utils.js.map +1 -0
- package/dist/components/organisms/Table/utilities/tableSort.utils.cjs +87 -0
- package/dist/components/organisms/Table/utilities/tableSort.utils.cjs.map +1 -0
- package/dist/components/organisms/Table/utilities/tableSort.utils.d.ts +67 -0
- package/dist/components/organisms/Table/utilities/tableSort.utils.d.ts.map +1 -0
- package/dist/components/organisms/Table/utilities/tableSort.utils.js +79 -0
- package/dist/components/organisms/Table/utilities/tableSort.utils.js.map +1 -0
- package/dist/hooks/__internal__/useReturnFocus/useReturnFocus.cjs +2 -2
- package/dist/hooks/__internal__/useReturnFocus/useReturnFocus.d.ts +2 -2
- package/dist/hooks/__internal__/useReturnFocus/useReturnFocus.js +2 -2
- package/dist/hooks/useFocusAfterRetry/index.cjs +1 -1
- package/dist/hooks/useFocusAfterRetry/index.d.ts +1 -1
- package/dist/hooks/useFocusAfterRetry/index.js +1 -1
- package/dist/utilities/searchParamsUtils/index.cjs +2 -9
- package/dist/utilities/searchParamsUtils/index.cjs.map +1 -1
- package/dist/utilities/searchParamsUtils/index.d.ts +5 -3
- package/dist/utilities/searchParamsUtils/index.d.ts.map +1 -1
- package/dist/utilities/searchParamsUtils/index.js +2 -9
- package/dist/utilities/searchParamsUtils/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/components/organisms/Table/table.utils.cjs +0 -61
- package/dist/components/organisms/Table/table.utils.cjs.map +0 -1
- package/dist/components/organisms/Table/table.utils.d.ts +0 -48
- package/dist/components/organisms/Table/table.utils.d.ts.map +0 -1
- package/dist/components/organisms/Table/table.utils.js +0 -55
- package/dist/components/organisms/Table/table.utils.js.map +0 -1
|
@@ -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
|
|
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
|
-
|
|
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":";;;;
|
|
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
|
-
|
|
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
|
|
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":"
|
|
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
|
|
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
|
|
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
|
-
|
|
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":";;
|
|
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,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,IAAI,CAAC;AAC3D,IAAA,eAAe,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC;AACnC,IAAA,OAAO,QAAQ;AACjB,CAAC;AAeD;;;;;;;AAOG;MACU,iBAAiB,GAAG,CAAC,EAChC,WAAW,EACX,YAAY,EACZ,mBAAmB,EACnB,YAAY,EACZ,MAAM,EACN,GAAG,SAAS,EACa,KAAI;;IAE7B,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAGA,cAAQ,CAAe,MAAK;QAClE,IAAI,mBAAmB,KAAK,SAAS;AAAE,YAAA,OAAO,EAAE;AAChD,QAAA,OAAO,mBAAmB,KAAK,KAAK,GAAG,KAAK,GAAG,kBAAkB,CAAC,mBAAmB,CAAC;AACxF,IAAA,CAAC,CAAC;IACF,MAAM,YAAY,GAAG,WAAW,KAAK,SAAS,IAAI,YAAY,KAAK,SAAS;IAE5E,MAAM,gBAAgB,GAAG,MAAmB;QAC1C,IAAI,WAAW,KAAK,SAAS;AAAE,YAAA,OAAOC,mCAAc,CAAC,WAAW,CAAC;QACjE,OAAO,YAAY,IAAI,YAAY;AACrC,IAAA,CAAC;AAED,IAAA,MAAM,iBAAiB,GAAG,CAAC,SAA6B,KAAI;AAC1D,QAAA,IAAI,CAAC,YAAY;YAAE,eAAe,CAAC,SAAS,CAAC;AAC7C,QAAAC,0CAAqB,CAAC,SAAS,EAAE,MAAM,CAAC,OAAO,IAAI,EAAE,EAAE,YAAY,EAAE,SAAS,CAAC;AACjF,IAAA,CAAC;IAED,OAAO,EAAE,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,IAAI,CAAC;AAC3D,IAAA,eAAe,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC;AACnC,IAAA,OAAO,QAAQ;AACjB,CAAC;AAeD;;;;;;;AAOG;MACU,iBAAiB,GAAG,CAAC,EAChC,WAAW,EACX,YAAY,EACZ,mBAAmB,EACnB,YAAY,EACZ,MAAM,EACN,GAAG,SAAS,EACa,KAAI;;IAE7B,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAe,MAAK;QAClE,IAAI,mBAAmB,KAAK,SAAS;AAAE,YAAA,OAAO,EAAE;AAChD,QAAA,OAAO,mBAAmB,KAAK,KAAK,GAAG,KAAK,GAAG,kBAAkB,CAAC,mBAAmB,CAAC;AACxF,IAAA,CAAC,CAAC;IACF,MAAM,YAAY,GAAG,WAAW,KAAK,SAAS,IAAI,YAAY,KAAK,SAAS;IAE5E,MAAM,gBAAgB,GAAG,MAAmB;QAC1C,IAAI,WAAW,KAAK,SAAS;AAAE,YAAA,OAAO,cAAc,CAAC,WAAW,CAAC;QACjE,OAAO,YAAY,IAAI,YAAY;AACrC,IAAA,CAAC;AAED,IAAA,MAAM,iBAAiB,GAAG,CAAC,SAA6B,KAAI;AAC1D,QAAA,IAAI,CAAC,YAAY;YAAE,eAAe,CAAC,SAAS,CAAC;AAC7C,QAAA,qBAAqB,CAAC,SAAS,EAAE,MAAM,CAAC,OAAO,IAAI,EAAE,EAAE,YAAY,EAAE,SAAS,CAAC;AACjF,IAAA,CAAC;IAED,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,EAAE,iBAAiB,EAAE;AAChE;;"}
|