@redis-ui/table 2.12.0 → 2.22.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 (166) hide show
  1. package/dist/Table/Table.cjs +95 -146
  2. package/dist/Table/Table.context.cjs +16 -1
  3. package/dist/Table/Table.context.d.ts +23 -4
  4. package/dist/Table/Table.context.js +16 -1
  5. package/dist/Table/Table.d.ts +88 -5
  6. package/dist/Table/Table.js +95 -146
  7. package/dist/Table/Table.style.cjs +43 -13
  8. package/dist/Table/Table.style.d.ts +6 -6
  9. package/dist/Table/Table.style.js +43 -13
  10. package/dist/Table/Table.types.d.ts +22 -38
  11. package/dist/Table/components/Compose/Compose.cjs +45 -0
  12. package/dist/Table/components/Compose/Compose.d.ts +13 -0
  13. package/dist/Table/components/Compose/Compose.js +45 -0
  14. package/dist/Table/components/EmptyState/EmptyState.cjs +31 -0
  15. package/dist/Table/components/EmptyState/EmptyState.d.ts +6 -0
  16. package/dist/Table/components/EmptyState/EmptyState.js +31 -0
  17. package/dist/Table/components/ExpandRowButton/ExpandAllRowsButton.cjs +20 -0
  18. package/dist/Table/components/ExpandRowButton/ExpandAllRowsButton.d.ts +8 -0
  19. package/dist/Table/components/ExpandRowButton/ExpandAllRowsButton.js +20 -0
  20. package/dist/Table/components/ExpandRowButton/ExpandAllRowsButton.test.d.ts +1 -0
  21. package/dist/Table/components/ExpandRowButton/useExpanderColumn.cjs +19 -0
  22. package/dist/Table/components/ExpandRowButton/useExpanderColumn.d.ts +6 -0
  23. package/dist/Table/components/ExpandRowButton/useExpanderColumn.js +19 -0
  24. package/dist/Table/components/ExpandRowButton/useExpanderColumn.test.d.ts +1 -0
  25. package/dist/Table/components/HiddenCaption/HiddenCaption.cjs +13 -0
  26. package/dist/Table/components/HiddenCaption/HiddenCaption.d.ts +3 -0
  27. package/dist/Table/components/HiddenCaption/HiddenCaption.js +13 -0
  28. package/dist/Table/components/PluggableTable/PluggableTable.cjs +19 -0
  29. package/dist/Table/components/PluggableTable/PluggableTable.d.ts +10 -0
  30. package/dist/Table/components/PluggableTable/PluggableTable.js +19 -0
  31. package/dist/Table/components/PluggableTable/compositionComponents.cjs +21 -0
  32. package/dist/Table/components/PluggableTable/compositionComponents.d.ts +67 -0
  33. package/dist/Table/components/PluggableTable/compositionComponents.js +21 -0
  34. package/dist/Table/components/RowSelection/HeaderMultiRowSelectionButton.cjs +1 -0
  35. package/dist/Table/components/RowSelection/HeaderMultiRowSelectionButton.d.ts +1 -1
  36. package/dist/Table/components/RowSelection/HeaderMultiRowSelectionButton.js +1 -0
  37. package/dist/Table/components/RowSelection/useRowSelectionColumn.cjs +26 -0
  38. package/dist/Table/components/RowSelection/useRowSelectionColumn.d.ts +8 -0
  39. package/dist/Table/components/RowSelection/useRowSelectionColumn.js +26 -0
  40. package/dist/Table/components/RowSelection/useRowSelectionColumn.test.d.ts +1 -0
  41. package/dist/Table/components/ShowOnRowHover/ShowOnRowHover.style.cjs +3 -1
  42. package/dist/Table/components/ShowOnRowHover/ShowOnRowHover.style.js +3 -1
  43. package/dist/Table/components/TableBody/TableBody.cjs +33 -0
  44. package/dist/Table/components/TableBody/TableBody.d.ts +23 -0
  45. package/dist/Table/components/TableBody/TableBody.js +33 -0
  46. package/dist/Table/components/TableBody/components/Compose/Compose.cjs +8 -0
  47. package/dist/Table/components/TableBody/components/Compose/Compose.d.ts +3 -0
  48. package/dist/Table/components/TableBody/components/Compose/Compose.js +8 -0
  49. package/dist/Table/components/TableBodyCell/TableBodyCell.cjs +18 -0
  50. package/dist/Table/components/TableBodyCell/TableBodyCell.d.ts +9 -0
  51. package/dist/Table/components/TableBodyCell/TableBodyCell.js +18 -0
  52. package/dist/Table/components/TableBodyCell/components/Compose/Compose.cjs +25 -0
  53. package/dist/Table/components/TableBodyCell/components/Compose/Compose.d.ts +9 -0
  54. package/dist/Table/components/TableBodyCell/components/Compose/Compose.js +25 -0
  55. package/dist/Table/components/TableBodyCell/components/Compose/Compose.test.d.ts +1 -0
  56. package/dist/Table/components/TableBodyRow/TableBodyRow.cjs +48 -0
  57. package/dist/Table/components/TableBodyRow/TableBodyRow.d.ts +20 -0
  58. package/dist/Table/components/TableBodyRow/TableBodyRow.js +48 -0
  59. package/dist/Table/components/TableBodyRow/TableBodyRowExpandable.cjs +33 -0
  60. package/dist/Table/components/TableBodyRow/TableBodyRowExpandable.d.ts +2 -0
  61. package/dist/Table/components/TableBodyRow/TableBodyRowExpandable.js +33 -0
  62. package/dist/Table/components/TableBodyRow/components/Compose/Compose.cjs +17 -0
  63. package/dist/Table/components/TableBodyRow/components/Compose/Compose.d.ts +5 -0
  64. package/dist/Table/components/TableBodyRow/components/Compose/Compose.js +17 -0
  65. package/dist/Table/components/TableExpandedRow/TableAnimatedExpandedRow.cjs +3 -4
  66. package/dist/Table/components/TableExpandedRow/TableAnimatedExpandedRow.d.ts +1 -1
  67. package/dist/Table/components/TableExpandedRow/TableAnimatedExpandedRow.js +3 -4
  68. package/dist/Table/components/TableExpandedRow/TableExpandedRow.cjs +9 -4
  69. package/dist/Table/components/TableExpandedRow/TableExpandedRow.d.ts +1 -1
  70. package/dist/Table/components/TableExpandedRow/TableExpandedRow.js +9 -4
  71. package/dist/Table/components/TableExpandedRow/TableExpandedRow.types.d.ts +3 -5
  72. package/dist/Table/components/TableHeader/TableHeader.cjs +28 -0
  73. package/dist/Table/components/TableHeader/TableHeader.d.ts +21 -0
  74. package/dist/Table/components/TableHeader/TableHeader.js +28 -0
  75. package/dist/Table/components/TableHeader/components/Compose/Compose.cjs +5 -0
  76. package/dist/Table/components/TableHeader/components/Compose/Compose.d.ts +3 -0
  77. package/dist/Table/components/TableHeader/components/Compose/Compose.js +5 -0
  78. package/dist/Table/components/TableHeaderCell/SRSortingNotification.cjs +18 -0
  79. package/dist/Table/components/TableHeaderCell/SRSortingNotification.d.ts +1 -0
  80. package/dist/Table/components/TableHeaderCell/SRSortingNotification.js +18 -0
  81. package/dist/Table/components/TableHeaderCell/TableHeaderCell.cjs +15 -33
  82. package/dist/Table/components/TableHeaderCell/TableHeaderCell.context.cjs +15 -0
  83. package/dist/Table/components/TableHeaderCell/TableHeaderCell.context.d.ts +8 -0
  84. package/dist/Table/components/TableHeaderCell/TableHeaderCell.context.js +15 -0
  85. package/dist/Table/components/TableHeaderCell/TableHeaderCell.d.ts +16 -4
  86. package/dist/Table/components/TableHeaderCell/TableHeaderCell.js +15 -33
  87. package/dist/Table/components/TableHeaderCell/TableHeaderCell.test.d.ts +1 -0
  88. package/dist/Table/components/TableHeaderCell/TableHeaderCell.utils.cjs +0 -22
  89. package/dist/Table/components/TableHeaderCell/TableHeaderCell.utils.d.ts +0 -1
  90. package/dist/Table/components/TableHeaderCell/TableHeaderCell.utils.js +1 -23
  91. package/dist/Table/components/TableHeaderCell/components/Compose/Compose.cjs +48 -0
  92. package/dist/Table/components/TableHeaderCell/components/Compose/Compose.d.ts +9 -0
  93. package/dist/Table/components/TableHeaderCell/components/Compose/Compose.js +48 -0
  94. package/dist/Table/components/TableHeaderCell/components/Compose/Compose.test.d.ts +1 -0
  95. package/dist/Table/components/TableHeaderCell/components/Heading/Heading.cjs +35 -0
  96. package/dist/Table/components/TableHeaderCell/components/Heading/Heading.d.ts +5 -0
  97. package/dist/Table/components/TableHeaderCell/components/Heading/Heading.js +35 -0
  98. package/dist/Table/components/TableHeaderCell/components/SortableHeading/SortableHeading.cjs +16 -0
  99. package/dist/Table/components/TableHeaderCell/components/SortableHeading/SortableHeading.d.ts +8 -0
  100. package/dist/Table/components/TableHeaderCell/components/SortableHeading/SortableHeading.js +16 -0
  101. package/dist/Table/components/TableHeaderCell/components/SortableHeading/components/Compose/Compose.cjs +24 -0
  102. package/dist/Table/components/TableHeaderCell/components/SortableHeading/components/Compose/Compose.d.ts +5 -0
  103. package/dist/Table/components/TableHeaderCell/components/SortableHeading/components/Compose/Compose.js +24 -0
  104. package/dist/Table/components/TableHeaderCell/components/SortableHeading/components/SortIndicator/SortIndicator.cjs +6 -0
  105. package/dist/Table/components/TableHeaderCell/components/SortableHeading/components/SortIndicator/SortIndicator.d.ts +2 -0
  106. package/dist/Table/components/TableHeaderCell/components/SortableHeading/components/SortIndicator/SortIndicator.js +6 -0
  107. package/dist/Table/components/TableHeaderRow/TableHeaderRow.cjs +27 -0
  108. package/dist/Table/components/TableHeaderRow/TableHeaderRow.d.ts +12 -0
  109. package/dist/Table/components/TableHeaderRow/TableHeaderRow.js +27 -0
  110. package/dist/Table/components/TableHeaderRow/components/Compose/Compose.cjs +5 -0
  111. package/dist/Table/components/TableHeaderRow/components/Compose/Compose.d.ts +3 -0
  112. package/dist/Table/components/TableHeaderRow/components/Compose/Compose.js +5 -0
  113. package/dist/Table/components/TablePagination/TablePagination.cjs +65 -99
  114. package/dist/Table/components/TablePagination/TablePagination.d.ts +23 -3
  115. package/dist/Table/components/TablePagination/TablePagination.js +66 -100
  116. package/dist/Table/components/TablePagination/TablePagination.style.cjs +70 -50
  117. package/dist/Table/components/TablePagination/TablePagination.style.d.ts +17 -50
  118. package/dist/Table/components/TablePagination/TablePagination.style.js +72 -52
  119. package/dist/Table/components/TablePagination/components/Compose/Compose.cjs +41 -0
  120. package/dist/Table/components/TablePagination/components/Compose/Compose.d.ts +3 -0
  121. package/dist/Table/components/TablePagination/components/Compose/Compose.js +41 -0
  122. package/dist/Table/components/TableRoot/TableRoot.cjs +13 -0
  123. package/dist/Table/components/TableRoot/TableRoot.d.ts +2 -0
  124. package/dist/Table/components/TableRoot/TableRoot.js +13 -0
  125. package/dist/Table/index.d.ts +3 -6
  126. package/dist/Table/plugins/ClickableRowPlugin.cjs +48 -0
  127. package/dist/Table/plugins/ClickableRowPlugin.d.ts +25 -0
  128. package/dist/Table/plugins/ClickableRowPlugin.js +48 -0
  129. package/dist/Table/plugins/ExpandableRowPlugin.cjs +44 -0
  130. package/dist/Table/plugins/ExpandableRowPlugin.d.ts +28 -0
  131. package/dist/Table/plugins/ExpandableRowPlugin.js +44 -0
  132. package/dist/Table/plugins/PaginationPlugin.cjs +45 -0
  133. package/dist/Table/plugins/PaginationPlugin.d.ts +16 -0
  134. package/dist/Table/plugins/PaginationPlugin.js +45 -0
  135. package/dist/Table/plugins/RowNavigationPlugin.cjs +139 -0
  136. package/dist/Table/plugins/RowNavigationPlugin.d.ts +44 -0
  137. package/dist/Table/plugins/RowNavigationPlugin.js +139 -0
  138. package/dist/Table/plugins/RowSelectionPlugin.cjs +28 -0
  139. package/dist/Table/plugins/RowSelectionPlugin.d.ts +12 -0
  140. package/dist/Table/plugins/RowSelectionPlugin.js +28 -0
  141. package/dist/Table/plugins/SortingPlugin.cjs +44 -0
  142. package/dist/Table/plugins/SortingPlugin.d.ts +18 -0
  143. package/dist/Table/plugins/SortingPlugin.js +44 -0
  144. package/dist/Table/tanStackExtendedTypes.d.ts +20 -0
  145. package/dist/Table/utils/plugin.utils.cjs +49 -0
  146. package/dist/Table/utils/plugin.utils.d.ts +17 -0
  147. package/dist/Table/utils/plugin.utils.js +49 -0
  148. package/dist/Table/utils/plugin.utils.test.d.ts +1 -0
  149. package/dist/Table/utils/table.utils.cjs +13 -0
  150. package/dist/Table/utils/table.utils.d.ts +2 -0
  151. package/dist/Table/utils/table.utils.js +13 -0
  152. package/dist/Table/utils/table.utils.test.d.ts +1 -0
  153. package/dist/index.cjs +60 -0
  154. package/dist/index.js +61 -1
  155. package/dist/node_modules/@tanstack/react-table/build/lib/index.cjs +7 -0
  156. package/dist/node_modules/@tanstack/react-table/build/lib/index.js +8 -1
  157. package/dist/node_modules/@tanstack/table-core/build/lib/index.cjs +361 -4
  158. package/dist/node_modules/@tanstack/table-core/build/lib/index.js +361 -4
  159. package/package.json +6 -5
  160. package/dist/Table/components/EmptyStateRow/EmptyStateRow.cjs +0 -16
  161. package/dist/Table/components/EmptyStateRow/EmptyStateRow.d.ts +0 -8
  162. package/dist/Table/components/EmptyStateRow/EmptyStateRow.js +0 -16
  163. package/dist/node_modules/@radix-ui/react-id/dist/index.cjs +0 -32
  164. package/dist/node_modules/@radix-ui/react-id/dist/index.js +0 -14
  165. package/dist/node_modules/@radix-ui/react-use-layout-effect/dist/index.cjs +0 -24
  166. package/dist/node_modules/@radix-ui/react-use-layout-effect/dist/index.js +0 -6
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const plugin_utils = require("../utils/plugin.utils.cjs");
4
+ const ClickableRowPlugin = require("./ClickableRowPlugin.cjs");
5
+ const Table_context = require("../Table.context.cjs");
6
+ const index = require("../../node_modules/@tanstack/table-core/build/lib/index.cjs");
7
+ const getTrue = () => true;
8
+ const TableExpandableRowContextKey = "expandableRow";
9
+ const useExpandableRowPlugin = ({
10
+ defaultExpanded,
11
+ getRowCanExpand,
12
+ renderExpandedRow,
13
+ expandRowOnClick,
14
+ expandedRowComponent,
15
+ getSubRows
16
+ }) => {
17
+ const clickablePluginData = ClickableRowPlugin.useClickableRowPlugin({
18
+ getCanRowClick: (row) => !!(expandRowOnClick && row.getCanExpand()),
19
+ onRowClick: (row) => row.toggleExpanded(),
20
+ shouldClickOnEnter: true
21
+ });
22
+ if (!renderExpandedRow && !getSubRows) return void 0;
23
+ return {
24
+ tableOptions: {
25
+ getExpandedRowModel: index.getExpandedRowModel(),
26
+ getRowCanExpand: getRowCanExpand || (getSubRows ? void 0 : getTrue),
27
+ getSubRows,
28
+ initialState: defaultExpanded ? {
29
+ expanded: defaultExpanded
30
+ } : void 0
31
+ },
32
+ context: {
33
+ ...plugin_utils.buildPluginContext(TableExpandableRowContextKey, {
34
+ renderExpandedRow,
35
+ expandedRowComponent
36
+ }),
37
+ ...expandRowOnClick ? clickablePluginData == null ? void 0 : clickablePluginData.context : null
38
+ }
39
+ };
40
+ };
41
+ const useExpandableRowContext = () => Table_context.usePluginContext(TableExpandableRowContextKey);
42
+ exports.TableExpandableRowContextKey = TableExpandableRowContextKey;
43
+ exports.useExpandableRowContext = useExpandableRowContext;
44
+ exports.useExpandableRowPlugin = useExpandableRowPlugin;
@@ -0,0 +1,28 @@
1
+ import { ComponentType, ReactNode } from 'react';
2
+ import { type Row } from '@tanstack/react-table';
3
+ import { ExpandedState } from '@tanstack/table-core/src/features/RowExpanding';
4
+ import { TablePluginData } from '../utils/plugin.utils';
5
+ import type { TableExpandedRowProps } from '../components/TableExpandedRow';
6
+ export declare const TableExpandableRowContextKey = "expandableRow";
7
+ export type TableExpandableRowContext<T extends object> = {
8
+ /** Renders content of expanded part */
9
+ renderExpandedRow?: (row: Row<T>) => ReactNode;
10
+ /**
11
+ * Overrides whole expanded part component.<br/>
12
+ * There are 2 predefined components `Table.ExpandedRow` (default) and `Table.AnimatedExpandedRow`
13
+ */
14
+ expandedRowComponent?: ComponentType<TableExpandedRowProps<T>>;
15
+ };
16
+ export interface TableExpandableRowParams<T extends object> extends TableExpandableRowContext<T> {
17
+ /** Allows expanding row by Click on whole row and by pressing Enter, when row is focused */
18
+ expandRowOnClick?: boolean;
19
+ /** Allows individual rows to be expandable */
20
+ getRowCanExpand?: (row: Row<T>) => boolean;
21
+ /**
22
+ * Enables tree-list (hierarchical) data.<br/>
23
+ * When this prop is set, the `renderExpandedRow` and `expandedRowComponent` parameters are not used. */
24
+ getSubRows?: (rowData: T, index: number) => T[] | undefined;
25
+ defaultExpanded?: ExpandedState;
26
+ }
27
+ export declare const useExpandableRowPlugin: <T extends object>({ defaultExpanded, getRowCanExpand, renderExpandedRow, expandRowOnClick, expandedRowComponent, getSubRows }: TableExpandableRowParams<T>) => TablePluginData<T>;
28
+ export declare const useExpandableRowContext: <T extends object>() => TableExpandableRowContext<T> | undefined;
@@ -0,0 +1,44 @@
1
+ import { buildPluginContext } from "../utils/plugin.utils.js";
2
+ import { useClickableRowPlugin } from "./ClickableRowPlugin.js";
3
+ import { usePluginContext } from "../Table.context.js";
4
+ import { getExpandedRowModel } from "../../node_modules/@tanstack/table-core/build/lib/index.js";
5
+ const getTrue = () => true;
6
+ const TableExpandableRowContextKey = "expandableRow";
7
+ const useExpandableRowPlugin = ({
8
+ defaultExpanded,
9
+ getRowCanExpand,
10
+ renderExpandedRow,
11
+ expandRowOnClick,
12
+ expandedRowComponent,
13
+ getSubRows
14
+ }) => {
15
+ const clickablePluginData = useClickableRowPlugin({
16
+ getCanRowClick: (row) => !!(expandRowOnClick && row.getCanExpand()),
17
+ onRowClick: (row) => row.toggleExpanded(),
18
+ shouldClickOnEnter: true
19
+ });
20
+ if (!renderExpandedRow && !getSubRows) return void 0;
21
+ return {
22
+ tableOptions: {
23
+ getExpandedRowModel: getExpandedRowModel(),
24
+ getRowCanExpand: getRowCanExpand || (getSubRows ? void 0 : getTrue),
25
+ getSubRows,
26
+ initialState: defaultExpanded ? {
27
+ expanded: defaultExpanded
28
+ } : void 0
29
+ },
30
+ context: {
31
+ ...buildPluginContext(TableExpandableRowContextKey, {
32
+ renderExpandedRow,
33
+ expandedRowComponent
34
+ }),
35
+ ...expandRowOnClick ? clickablePluginData == null ? void 0 : clickablePluginData.context : null
36
+ }
37
+ };
38
+ };
39
+ const useExpandableRowContext = () => usePluginContext(TableExpandableRowContextKey);
40
+ export {
41
+ TableExpandableRowContextKey,
42
+ useExpandableRowContext,
43
+ useExpandableRowPlugin
44
+ };
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const index = require("../../node_modules/@radix-ui/react-use-controllable-state/dist/index.cjs");
4
+ const plugin_utils = require("../utils/plugin.utils.cjs");
5
+ const Table_context = require("../Table.context.cjs");
6
+ const index$1 = require("../../node_modules/@tanstack/table-core/build/lib/index.cjs");
7
+ const DEFAULT_PAGINATION = {
8
+ pageIndex: 0,
9
+ pageSize: 10
10
+ };
11
+ const TablePaginationContextKey = "pagination";
12
+ const usePaginationPlugin = ({
13
+ pagination,
14
+ defaultPagination,
15
+ onPaginationChange,
16
+ manualPagination,
17
+ totalRowCount,
18
+ pageSizes,
19
+ paginationEnabled = (pagination || defaultPagination || onPaginationChange || pageSizes) !== void 0 || manualPagination !== void 0
20
+ }) => {
21
+ const [paginationState, setPaginationState] = index.useControllableState({
22
+ prop: pagination,
23
+ defaultProp: defaultPagination ?? DEFAULT_PAGINATION,
24
+ onChange: onPaginationChange
25
+ });
26
+ return paginationEnabled ? {
27
+ tableOptions: {
28
+ state: {
29
+ pagination: paginationState
30
+ },
31
+ getPaginationRowModel: index$1.getPaginationRowModel(),
32
+ onPaginationChange: setPaginationState,
33
+ manualPagination,
34
+ rowCount: totalRowCount,
35
+ autoResetPageIndex: false
36
+ },
37
+ context: plugin_utils.buildPluginContext(TablePaginationContextKey, {
38
+ pageSizes
39
+ })
40
+ } : void 0;
41
+ };
42
+ const usePaginationContext = () => Table_context.usePluginContext(TablePaginationContextKey);
43
+ exports.TablePaginationContextKey = TablePaginationContextKey;
44
+ exports.usePaginationContext = usePaginationContext;
45
+ exports.usePaginationPlugin = usePaginationPlugin;
@@ -0,0 +1,16 @@
1
+ import { PaginationState } from '@tanstack/react-table';
2
+ import { TablePluginData } from '../utils/plugin.utils';
3
+ export declare const TablePaginationContextKey = "pagination";
4
+ export interface TablePaginationContext {
5
+ pageSizes?: number[];
6
+ paginationEnabled?: boolean;
7
+ }
8
+ export interface TablePaginationParams extends TablePaginationContext {
9
+ pagination?: PaginationState;
10
+ defaultPagination?: PaginationState;
11
+ onPaginationChange?: (state: PaginationState) => void;
12
+ manualPagination?: boolean;
13
+ totalRowCount?: number;
14
+ }
15
+ export declare const usePaginationPlugin: <T extends object>({ pagination, defaultPagination, onPaginationChange, manualPagination, totalRowCount, pageSizes, paginationEnabled }: TablePaginationParams) => TablePluginData<T>;
16
+ export declare const usePaginationContext: () => TablePaginationContext | undefined;
@@ -0,0 +1,45 @@
1
+ import { useControllableState } from "../../node_modules/@radix-ui/react-use-controllable-state/dist/index.js";
2
+ import { buildPluginContext } from "../utils/plugin.utils.js";
3
+ import { usePluginContext } from "../Table.context.js";
4
+ import { getPaginationRowModel } from "../../node_modules/@tanstack/table-core/build/lib/index.js";
5
+ const DEFAULT_PAGINATION = {
6
+ pageIndex: 0,
7
+ pageSize: 10
8
+ };
9
+ const TablePaginationContextKey = "pagination";
10
+ const usePaginationPlugin = ({
11
+ pagination,
12
+ defaultPagination,
13
+ onPaginationChange,
14
+ manualPagination,
15
+ totalRowCount,
16
+ pageSizes,
17
+ paginationEnabled = (pagination || defaultPagination || onPaginationChange || pageSizes) !== void 0 || manualPagination !== void 0
18
+ }) => {
19
+ const [paginationState, setPaginationState] = useControllableState({
20
+ prop: pagination,
21
+ defaultProp: defaultPagination ?? DEFAULT_PAGINATION,
22
+ onChange: onPaginationChange
23
+ });
24
+ return paginationEnabled ? {
25
+ tableOptions: {
26
+ state: {
27
+ pagination: paginationState
28
+ },
29
+ getPaginationRowModel: getPaginationRowModel(),
30
+ onPaginationChange: setPaginationState,
31
+ manualPagination,
32
+ rowCount: totalRowCount,
33
+ autoResetPageIndex: false
34
+ },
35
+ context: buildPluginContext(TablePaginationContextKey, {
36
+ pageSizes
37
+ })
38
+ } : void 0;
39
+ };
40
+ const usePaginationContext = () => usePluginContext(TablePaginationContextKey);
41
+ export {
42
+ TablePaginationContextKey,
43
+ usePaginationContext,
44
+ usePaginationPlugin
45
+ };
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const React = require("react");
4
+ const redisUiComponents = require("@redislabsdev/redis-ui-components");
5
+ const index = require("../../node_modules/@radix-ui/react-compose-refs/dist/index.cjs");
6
+ const plugin_utils = require("../utils/plugin.utils.cjs");
7
+ const Table_context = require("../Table.context.cjs");
8
+ const TableRowNavigationContextKey = "RowNavigation";
9
+ const useRowNavigationPlugin = ({
10
+ enableRowNavigation = true
11
+ }) => {
12
+ const [activeRowId, setActiveRowId] = React.useState();
13
+ const rowRefs = React.useRef(/* @__PURE__ */ new Map());
14
+ const unregisterRow = React.useCallback((rowId) => {
15
+ rowRefs.current.delete(rowId);
16
+ }, []);
17
+ const registerRow = React.useCallback((rowId, rowEl) => {
18
+ if (rowEl) rowRefs.current.set(rowId, rowEl);
19
+ else unregisterRow(rowId);
20
+ }, [unregisterRow]);
21
+ const goToRowId = (rowId, noScroll) => {
22
+ var _a;
23
+ return rowId && ((_a = rowRefs.current.get(rowId)) == null ? void 0 : _a.focus({
24
+ preventScroll: noScroll
25
+ }));
26
+ };
27
+ const getGoToRow = (getTargetRow) => (table) => {
28
+ const {
29
+ rows
30
+ } = table.getRowModel();
31
+ if (!rows.length) return false;
32
+ const targetRow = getTargetRow(rows);
33
+ if (!targetRow) return false;
34
+ setActiveRowId(targetRow.id);
35
+ goToRowId(targetRow.id);
36
+ return true;
37
+ };
38
+ const findActiveIndex = (rows) => rows.findIndex((row) => row.id === activeRowId);
39
+ const goToNextRow = getGoToRow((rows) => activeRowId && rows[findActiveIndex(rows) + 1] || rows.at(0));
40
+ const goToPrevRow = getGoToRow((rows) => activeRowId && rows[findActiveIndex(rows) - 1] || rows.at(-1));
41
+ const goToFirstRow = getGoToRow((rows) => rows.at(0));
42
+ const goToLastRow = getGoToRow((rows) => rows.at(-1));
43
+ return enableRowNavigation ? {
44
+ tableOptions: {},
45
+ context: plugin_utils.buildPluginContext(TableRowNavigationContextKey, {
46
+ registerRow,
47
+ unregisterRow,
48
+ activeRowId,
49
+ setActiveRowId,
50
+ goToNextRow,
51
+ goToPrevRow,
52
+ goToFirstRow,
53
+ goToLastRow,
54
+ goToRowId
55
+ })
56
+ } : void 0;
57
+ };
58
+ const useRowNavigationContext = () => Table_context.usePluginContext(TableRowNavigationContextKey);
59
+ const useHandleRowNavigationOnRow = ({
60
+ row,
61
+ onFocus,
62
+ ref
63
+ }) => {
64
+ const {
65
+ registerRow,
66
+ setActiveRowId,
67
+ activeRowId
68
+ } = useRowNavigationContext() || {};
69
+ const innerRowRef = registerRow && ((rowEl) => registerRow(row.id, rowEl));
70
+ const composedRowRef = index.useComposedRefs(ref, innerRowRef);
71
+ const handleFocus = redisUiComponents.combineHandlers(setActiveRowId && (() => setActiveRowId(row.id)), onFocus);
72
+ return {
73
+ ref: composedRowRef,
74
+ onFocus: handleFocus,
75
+ ...setActiveRowId && {
76
+ tabIndex: activeRowId === row.id ? 0 : -1
77
+ }
78
+ };
79
+ };
80
+ const useHandleRowNavigationOnTable = ({
81
+ onKeyDown,
82
+ onFocus
83
+ }) => {
84
+ const {
85
+ table
86
+ } = Table_context.useTableContext();
87
+ const nav = useRowNavigationContext();
88
+ if (!nav) {
89
+ return {
90
+ ...onKeyDown && {
91
+ onKeyDown
92
+ },
93
+ ...onFocus && {
94
+ onFocus
95
+ }
96
+ };
97
+ }
98
+ const {
99
+ goToNextRow,
100
+ goToPrevRow,
101
+ goToFirstRow,
102
+ goToLastRow,
103
+ goToRowId,
104
+ activeRowId
105
+ } = nav;
106
+ const handleKeyDown = redisUiComponents.combineHandlers((e) => {
107
+ if (e.key === "ArrowDown") {
108
+ e.preventDefault();
109
+ goToNextRow(table);
110
+ }
111
+ if (e.key === "ArrowUp") {
112
+ e.preventDefault();
113
+ goToPrevRow(table);
114
+ }
115
+ if (e.key === "Home") {
116
+ e.preventDefault();
117
+ goToFirstRow(table);
118
+ }
119
+ if (e.key === "End") {
120
+ e.preventDefault();
121
+ goToLastRow(table);
122
+ }
123
+ }, onKeyDown);
124
+ const handleFocus = redisUiComponents.combineHandlers((e) => {
125
+ if (e.target === e.currentTarget) {
126
+ goToRowId(activeRowId, !e.target.matches(":focus-visible"));
127
+ }
128
+ }, onFocus);
129
+ return {
130
+ onKeyDown: handleKeyDown,
131
+ onFocus: handleFocus,
132
+ tabIndex: 0
133
+ };
134
+ };
135
+ exports.TableRowNavigationContextKey = TableRowNavigationContextKey;
136
+ exports.useHandleRowNavigationOnRow = useHandleRowNavigationOnRow;
137
+ exports.useHandleRowNavigationOnTable = useHandleRowNavigationOnTable;
138
+ exports.useRowNavigationContext = useRowNavigationContext;
139
+ exports.useRowNavigationPlugin = useRowNavigationPlugin;
@@ -0,0 +1,44 @@
1
+ import { FocusEventHandler, KeyboardEventHandler, Ref } from 'react';
2
+ import { Row, Table } from '@tanstack/react-table';
3
+ import { TablePluginData } from '../utils/plugin.utils';
4
+ export declare const TableRowNavigationContextKey = "RowNavigation";
5
+ export type TableRowNavigationContext = {
6
+ registerRow: (rowId: string, rowEl: HTMLTableRowElement | null) => void;
7
+ unregisterRow: (rowId: string) => void;
8
+ activeRowId: string | undefined;
9
+ setActiveRowId: (rowId: string) => void;
10
+ goToNextRow: (table: Table<object>) => void;
11
+ goToPrevRow: (table: Table<object>) => void;
12
+ goToFirstRow: (table: Table<object>) => void;
13
+ goToLastRow: (table: Table<object>) => void;
14
+ goToRowId: (rowId: string | undefined, noScroll?: boolean) => void;
15
+ };
16
+ export type TableRowNavigationParams = {
17
+ enableRowNavigation?: boolean;
18
+ };
19
+ export declare const useRowNavigationPlugin: <T extends object>({ enableRowNavigation }: TableRowNavigationParams) => TablePluginData<T>;
20
+ export declare const useRowNavigationContext: () => TableRowNavigationContext | undefined;
21
+ type UseHandleRowNavigationOnRowParams<T extends object> = {
22
+ row: Row<T>;
23
+ onFocus?: FocusEventHandler<HTMLTableRowElement>;
24
+ ref?: Ref<HTMLTableRowElement>;
25
+ };
26
+ export declare const useHandleRowNavigationOnRow: <T extends object>({ row, onFocus, ref }: UseHandleRowNavigationOnRowParams<T>) => {
27
+ tabIndex?: number | undefined;
28
+ ref: (node: HTMLTableRowElement) => void;
29
+ onFocus: FocusEventHandler<HTMLTableRowElement> | undefined;
30
+ };
31
+ type UseHandleRowNavigationOnTableParams = {
32
+ onKeyDown?: KeyboardEventHandler<HTMLTableElement>;
33
+ onFocus?: FocusEventHandler<HTMLTableElement>;
34
+ };
35
+ export declare const useHandleRowNavigationOnTable: ({ onKeyDown, onFocus }: UseHandleRowNavigationOnTableParams) => {
36
+ onFocus?: FocusEventHandler<HTMLTableElement> | undefined;
37
+ onKeyDown?: KeyboardEventHandler<HTMLTableElement> | undefined;
38
+ tabIndex?: undefined;
39
+ } | {
40
+ onKeyDown: KeyboardEventHandler<HTMLTableElement> | undefined;
41
+ onFocus: FocusEventHandler<HTMLTableElement> | undefined;
42
+ tabIndex: number;
43
+ };
44
+ export {};
@@ -0,0 +1,139 @@
1
+ import { useState, useRef, useCallback } from "react";
2
+ import { combineHandlers } from "@redislabsdev/redis-ui-components";
3
+ import { useComposedRefs } from "../../node_modules/@radix-ui/react-compose-refs/dist/index.js";
4
+ import { buildPluginContext } from "../utils/plugin.utils.js";
5
+ import { usePluginContext, useTableContext } from "../Table.context.js";
6
+ const TableRowNavigationContextKey = "RowNavigation";
7
+ const useRowNavigationPlugin = ({
8
+ enableRowNavigation = true
9
+ }) => {
10
+ const [activeRowId, setActiveRowId] = useState();
11
+ const rowRefs = useRef(/* @__PURE__ */ new Map());
12
+ const unregisterRow = useCallback((rowId) => {
13
+ rowRefs.current.delete(rowId);
14
+ }, []);
15
+ const registerRow = useCallback((rowId, rowEl) => {
16
+ if (rowEl) rowRefs.current.set(rowId, rowEl);
17
+ else unregisterRow(rowId);
18
+ }, [unregisterRow]);
19
+ const goToRowId = (rowId, noScroll) => {
20
+ var _a;
21
+ return rowId && ((_a = rowRefs.current.get(rowId)) == null ? void 0 : _a.focus({
22
+ preventScroll: noScroll
23
+ }));
24
+ };
25
+ const getGoToRow = (getTargetRow) => (table) => {
26
+ const {
27
+ rows
28
+ } = table.getRowModel();
29
+ if (!rows.length) return false;
30
+ const targetRow = getTargetRow(rows);
31
+ if (!targetRow) return false;
32
+ setActiveRowId(targetRow.id);
33
+ goToRowId(targetRow.id);
34
+ return true;
35
+ };
36
+ const findActiveIndex = (rows) => rows.findIndex((row) => row.id === activeRowId);
37
+ const goToNextRow = getGoToRow((rows) => activeRowId && rows[findActiveIndex(rows) + 1] || rows.at(0));
38
+ const goToPrevRow = getGoToRow((rows) => activeRowId && rows[findActiveIndex(rows) - 1] || rows.at(-1));
39
+ const goToFirstRow = getGoToRow((rows) => rows.at(0));
40
+ const goToLastRow = getGoToRow((rows) => rows.at(-1));
41
+ return enableRowNavigation ? {
42
+ tableOptions: {},
43
+ context: buildPluginContext(TableRowNavigationContextKey, {
44
+ registerRow,
45
+ unregisterRow,
46
+ activeRowId,
47
+ setActiveRowId,
48
+ goToNextRow,
49
+ goToPrevRow,
50
+ goToFirstRow,
51
+ goToLastRow,
52
+ goToRowId
53
+ })
54
+ } : void 0;
55
+ };
56
+ const useRowNavigationContext = () => usePluginContext(TableRowNavigationContextKey);
57
+ const useHandleRowNavigationOnRow = ({
58
+ row,
59
+ onFocus,
60
+ ref
61
+ }) => {
62
+ const {
63
+ registerRow,
64
+ setActiveRowId,
65
+ activeRowId
66
+ } = useRowNavigationContext() || {};
67
+ const innerRowRef = registerRow && ((rowEl) => registerRow(row.id, rowEl));
68
+ const composedRowRef = useComposedRefs(ref, innerRowRef);
69
+ const handleFocus = combineHandlers(setActiveRowId && (() => setActiveRowId(row.id)), onFocus);
70
+ return {
71
+ ref: composedRowRef,
72
+ onFocus: handleFocus,
73
+ ...setActiveRowId && {
74
+ tabIndex: activeRowId === row.id ? 0 : -1
75
+ }
76
+ };
77
+ };
78
+ const useHandleRowNavigationOnTable = ({
79
+ onKeyDown,
80
+ onFocus
81
+ }) => {
82
+ const {
83
+ table
84
+ } = useTableContext();
85
+ const nav = useRowNavigationContext();
86
+ if (!nav) {
87
+ return {
88
+ ...onKeyDown && {
89
+ onKeyDown
90
+ },
91
+ ...onFocus && {
92
+ onFocus
93
+ }
94
+ };
95
+ }
96
+ const {
97
+ goToNextRow,
98
+ goToPrevRow,
99
+ goToFirstRow,
100
+ goToLastRow,
101
+ goToRowId,
102
+ activeRowId
103
+ } = nav;
104
+ const handleKeyDown = combineHandlers((e) => {
105
+ if (e.key === "ArrowDown") {
106
+ e.preventDefault();
107
+ goToNextRow(table);
108
+ }
109
+ if (e.key === "ArrowUp") {
110
+ e.preventDefault();
111
+ goToPrevRow(table);
112
+ }
113
+ if (e.key === "Home") {
114
+ e.preventDefault();
115
+ goToFirstRow(table);
116
+ }
117
+ if (e.key === "End") {
118
+ e.preventDefault();
119
+ goToLastRow(table);
120
+ }
121
+ }, onKeyDown);
122
+ const handleFocus = combineHandlers((e) => {
123
+ if (e.target === e.currentTarget) {
124
+ goToRowId(activeRowId, !e.target.matches(":focus-visible"));
125
+ }
126
+ }, onFocus);
127
+ return {
128
+ onKeyDown: handleKeyDown,
129
+ onFocus: handleFocus,
130
+ tabIndex: 0
131
+ };
132
+ };
133
+ export {
134
+ TableRowNavigationContextKey,
135
+ useHandleRowNavigationOnRow,
136
+ useHandleRowNavigationOnTable,
137
+ useRowNavigationContext,
138
+ useRowNavigationPlugin
139
+ };
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const index = require("../../node_modules/@radix-ui/react-use-controllable-state/dist/index.cjs");
4
+ const DEFAULT_ROW_SELECTION = {};
5
+ const useRowSelectionPlugin = ({
6
+ rowSelection,
7
+ defaultRowSelection,
8
+ onRowSelectionChange,
9
+ rowSelectionMode,
10
+ getRowCanSelect
11
+ }) => {
12
+ const [rowSelectionState = DEFAULT_ROW_SELECTION, setRowSelectionState] = index.useControllableState({
13
+ prop: rowSelection,
14
+ defaultProp: defaultRowSelection,
15
+ onChange: onRowSelectionChange
16
+ });
17
+ return rowSelectionMode && {
18
+ tableOptions: {
19
+ state: {
20
+ rowSelection: rowSelectionState
21
+ },
22
+ enableRowSelection: getRowCanSelect ?? true,
23
+ enableMultiRowSelection: rowSelectionMode === "multiple",
24
+ onRowSelectionChange: setRowSelectionState
25
+ }
26
+ };
27
+ };
28
+ exports.useRowSelectionPlugin = useRowSelectionPlugin;
@@ -0,0 +1,12 @@
1
+ import type { Row, RowSelectionState } from '@tanstack/react-table';
2
+ import { TablePluginData } from '../utils/plugin.utils';
3
+ export interface TableRowSelectionParams<T extends object> {
4
+ rowSelection?: RowSelectionState;
5
+ defaultRowSelection?: RowSelectionState;
6
+ onRowSelectionChange?: (state: RowSelectionState) => void;
7
+ /** Enables row selection sets selection mode */
8
+ rowSelectionMode?: 'single' | 'multiple';
9
+ /** Allows individual rows to be selectable */
10
+ getRowCanSelect?: (row: Row<T>) => boolean;
11
+ }
12
+ export declare const useRowSelectionPlugin: <T extends object>({ rowSelection, defaultRowSelection, onRowSelectionChange, rowSelectionMode, getRowCanSelect }: TableRowSelectionParams<T>) => TablePluginData<T>;
@@ -0,0 +1,28 @@
1
+ import { useControllableState } from "../../node_modules/@radix-ui/react-use-controllable-state/dist/index.js";
2
+ const DEFAULT_ROW_SELECTION = {};
3
+ const useRowSelectionPlugin = ({
4
+ rowSelection,
5
+ defaultRowSelection,
6
+ onRowSelectionChange,
7
+ rowSelectionMode,
8
+ getRowCanSelect
9
+ }) => {
10
+ const [rowSelectionState = DEFAULT_ROW_SELECTION, setRowSelectionState] = useControllableState({
11
+ prop: rowSelection,
12
+ defaultProp: defaultRowSelection,
13
+ onChange: onRowSelectionChange
14
+ });
15
+ return rowSelectionMode && {
16
+ tableOptions: {
17
+ state: {
18
+ rowSelection: rowSelectionState
19
+ },
20
+ enableRowSelection: getRowCanSelect ?? true,
21
+ enableMultiRowSelection: rowSelectionMode === "multiple",
22
+ onRowSelectionChange: setRowSelectionState
23
+ }
24
+ };
25
+ };
26
+ export {
27
+ useRowSelectionPlugin
28
+ };
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const index = require("../../node_modules/@radix-ui/react-use-controllable-state/dist/index.cjs");
4
+ const React = require("react");
5
+ const plugin_utils = require("../utils/plugin.utils.cjs");
6
+ const Table_context = require("../Table.context.cjs");
7
+ const index$1 = require("../../node_modules/@tanstack/table-core/build/lib/index.cjs");
8
+ const TableSortingContextKey = "sorting";
9
+ const useSortingPlugin = ({
10
+ defaultSorting,
11
+ onSortingChange,
12
+ sorting,
13
+ manualSorting = false,
14
+ enableSorting = true
15
+ // added plugin is enabled by default
16
+ } = {}) => {
17
+ const [sortedByUser, setSortedByUser] = React.useState(false);
18
+ const [sortingState, setSortingState] = index.useControllableState({
19
+ prop: sorting,
20
+ defaultProp: defaultSorting,
21
+ onChange: onSortingChange
22
+ });
23
+ return enableSorting ? {
24
+ tableOptions: {
25
+ enableSorting: true,
26
+ getSortedRowModel: index$1.getSortedRowModel(),
27
+ state: {
28
+ sorting: sortingState
29
+ },
30
+ manualSorting,
31
+ onSortingChange: (value) => {
32
+ setSortingState(value);
33
+ setSortedByUser(true);
34
+ }
35
+ },
36
+ context: plugin_utils.buildPluginContext(TableSortingContextKey, {
37
+ sortedByUser
38
+ })
39
+ } : void 0;
40
+ };
41
+ const useSortingContext = () => Table_context.usePluginContext(TableSortingContextKey);
42
+ exports.TableSortingContextKey = TableSortingContextKey;
43
+ exports.useSortingContext = useSortingContext;
44
+ exports.useSortingPlugin = useSortingPlugin;