@mezzanine-ui/react 1.0.0-alpha.0 → 1.0.0-beta.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 (138) hide show
  1. package/Breadcrumb/Breadcrumb.js +40 -12
  2. package/Breadcrumb/typings.d.ts +8 -3
  3. package/Drawer/Drawer.d.ts +47 -6
  4. package/Drawer/Drawer.js +36 -11
  5. package/Empty/Empty.js +26 -3
  6. package/Empty/typings.d.ts +16 -7
  7. package/PageHeader/PageHeader.d.ts +5 -1
  8. package/PageHeader/PageHeader.js +8 -3
  9. package/PageToolbar/PageToolbar.d.ts +73 -26
  10. package/PageToolbar/PageToolbar.js +10 -101
  11. package/PageToolbar/utils.d.ts +23 -0
  12. package/PageToolbar/utils.js +165 -0
  13. package/Pagination/PaginationItem.js +1 -3
  14. package/Pagination/usePagination.js +0 -18
  15. package/Radio/Radio.d.ts +36 -3
  16. package/Radio/Radio.js +21 -11
  17. package/Radio/RadioGroup.d.ts +36 -7
  18. package/Radio/RadioGroup.js +5 -4
  19. package/Radio/RadioGroupContext.d.ts +2 -1
  20. package/Radio/index.d.ts +3 -3
  21. package/Tab/Tab.d.ts +32 -0
  22. package/Tab/Tab.js +57 -0
  23. package/Tab/TabItem.d.ts +27 -0
  24. package/Tab/TabItem.js +18 -0
  25. package/Tab/index.d.ts +4 -0
  26. package/Tab/index.js +2 -0
  27. package/Table/Table.d.ts +75 -94
  28. package/Table/Table.js +216 -161
  29. package/Table/TableContext.d.ts +114 -51
  30. package/Table/TableContext.js +21 -3
  31. package/Table/components/TableBody.d.ts +5 -0
  32. package/Table/components/TableBody.js +102 -0
  33. package/Table/components/TableCell.d.ts +17 -0
  34. package/Table/components/TableCell.js +74 -0
  35. package/Table/components/TableColGroup.d.ts +4 -0
  36. package/Table/components/TableColGroup.js +206 -0
  37. package/Table/components/TableDragHandleCell.d.ts +9 -0
  38. package/Table/components/TableDragHandleCell.js +37 -0
  39. package/Table/components/TableExpandCell.d.ts +11 -0
  40. package/Table/components/TableExpandCell.js +44 -0
  41. package/Table/components/TableExpandedRow.d.ts +9 -0
  42. package/Table/components/TableExpandedRow.js +46 -0
  43. package/Table/components/TableHeader.d.ts +4 -0
  44. package/Table/components/TableHeader.js +125 -0
  45. package/Table/components/TablePagination.d.ts +3 -0
  46. package/Table/components/TablePagination.js +11 -0
  47. package/Table/components/TableResizeHandle.d.ts +13 -0
  48. package/Table/components/TableResizeHandle.js +115 -0
  49. package/Table/components/TableRow.d.ts +12 -0
  50. package/Table/components/TableRow.js +126 -0
  51. package/Table/components/TableSelectionCell.d.ts +13 -0
  52. package/Table/components/TableSelectionCell.js +35 -0
  53. package/Table/components/index.d.ts +10 -0
  54. package/Table/components/index.js +10 -0
  55. package/Table/hooks/index.d.ts +9 -0
  56. package/Table/hooks/index.js +8 -0
  57. package/Table/hooks/typings.d.ts +14 -0
  58. package/Table/hooks/useTableColumns.d.ts +8 -0
  59. package/Table/hooks/useTableColumns.js +91 -0
  60. package/Table/hooks/useTableDataSource.d.ts +57 -0
  61. package/Table/hooks/useTableDataSource.js +183 -0
  62. package/Table/hooks/useTableExpansion.d.ts +7 -0
  63. package/Table/hooks/useTableExpansion.js +52 -0
  64. package/Table/hooks/useTableFixedOffsets.d.ts +29 -0
  65. package/Table/hooks/useTableFixedOffsets.js +241 -0
  66. package/Table/hooks/useTableScroll.d.ts +12 -0
  67. package/Table/hooks/useTableScroll.js +58 -0
  68. package/Table/hooks/useTableSelection.d.ts +7 -0
  69. package/Table/hooks/useTableSelection.js +94 -0
  70. package/Table/hooks/useTableSorting.d.ts +6 -0
  71. package/Table/hooks/useTableSorting.js +32 -0
  72. package/Table/hooks/useTableVirtualization.d.ts +22 -0
  73. package/Table/hooks/useTableVirtualization.js +115 -0
  74. package/Table/index.d.ts +7 -10
  75. package/Table/index.js +22 -6
  76. package/Table/utils/index.d.ts +2 -0
  77. package/Table/utils/index.js +1 -0
  78. package/Table/utils/useTableRowSelection.d.ts +18 -0
  79. package/Table/utils/useTableRowSelection.js +63 -0
  80. package/_internal/InputCheck/InputCheck.d.ts +15 -1
  81. package/_internal/InputCheck/InputCheck.js +6 -2
  82. package/_internal/InputCheck/InputCheckGroup.d.ts +11 -1
  83. package/_internal/InputCheck/InputCheckGroup.js +4 -2
  84. package/_internal/SlideFadeOverlay/SlideFadeOverlay.d.ts +1 -1
  85. package/_internal/SlideFadeOverlay/SlideFadeOverlay.js +1 -1
  86. package/index.d.ts +7 -5
  87. package/index.js +6 -9
  88. package/package.json +5 -4
  89. package/utils/flatten-children.d.ts +12 -0
  90. package/utils/flatten-children.js +37 -0
  91. package/utils/get-css-variable-value.d.ts +1 -0
  92. package/utils/get-css-variable-value.js +4 -1
  93. package/Table/TableBody.d.ts +0 -10
  94. package/Table/TableBody.js +0 -31
  95. package/Table/TableBodyRow.d.ts +0 -11
  96. package/Table/TableBodyRow.js +0 -65
  97. package/Table/TableCell.d.ts +0 -19
  98. package/Table/TableCell.js +0 -24
  99. package/Table/TableExpandedTable.d.ts +0 -11
  100. package/Table/TableExpandedTable.js +0 -29
  101. package/Table/TableHeader.d.ts +0 -3
  102. package/Table/TableHeader.js +0 -36
  103. package/Table/draggable/useTableDraggable.d.ts +0 -14
  104. package/Table/draggable/useTableDraggable.js +0 -64
  105. package/Table/editable/TableEditRenderWrapper.d.ts +0 -7
  106. package/Table/editable/TableEditRenderWrapper.js +0 -16
  107. package/Table/expandable/TableExpandable.d.ts +0 -27
  108. package/Table/expandable/TableExpandable.js +0 -24
  109. package/Table/pagination/TablePagination.d.ts +0 -10
  110. package/Table/pagination/TablePagination.js +0 -26
  111. package/Table/pagination/useTablePagination.d.ts +0 -8
  112. package/Table/pagination/useTablePagination.js +0 -30
  113. package/Table/refresh/TableRefresh.d.ts +0 -10
  114. package/Table/refresh/TableRefresh.js +0 -22
  115. package/Table/rowSelection/TableRowSelection.d.ts +0 -18
  116. package/Table/rowSelection/TableRowSelection.js +0 -93
  117. package/Table/rowSelection/useTableRowSelection.d.ts +0 -6
  118. package/Table/rowSelection/useTableRowSelection.js +0 -53
  119. package/Table/sorting/TableSortingIcon.d.ts +0 -10
  120. package/Table/sorting/TableSortingIcon.js +0 -33
  121. package/Table/sorting/useTableSorting.d.ts +0 -11
  122. package/Table/sorting/useTableSorting.js +0 -121
  123. package/Table/useTableFetchMore.d.ts +0 -10
  124. package/Table/useTableFetchMore.js +0 -50
  125. package/Table/useTableLoading.d.ts +0 -5
  126. package/Table/useTableLoading.js +0 -19
  127. package/Table/useTableScroll.d.ts +0 -592
  128. package/Table/useTableScroll.js +0 -296
  129. package/Tabs/Tab.d.ts +0 -18
  130. package/Tabs/Tab.js +0 -16
  131. package/Tabs/TabPane.d.ts +0 -14
  132. package/Tabs/TabPane.js +0 -19
  133. package/Tabs/Tabs.d.ts +0 -39
  134. package/Tabs/Tabs.js +0 -52
  135. package/Tabs/index.d.ts +0 -6
  136. package/Tabs/index.js +0 -3
  137. package/Tabs/useTabsOverflow.d.ts +0 -8
  138. package/Tabs/useTabsOverflow.js +0 -62
package/Table/Table.d.ts CHANGED
@@ -1,110 +1,91 @@
1
- import { ReactNode } from 'react';
2
- import { TableColumn, TableComponents, TableDataSource, TableRowSelection, TableExpandable, TableFetchMore, TablePagination as TablePaginationType, TableRefresh as TableRefreshType, ExpandRowBySources, TableScrolling, TableDraggable } from '@mezzanine-ui/core/table';
3
- import { EmptyProps } from '../Empty';
4
- import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
5
- export interface TableBaseProps<T> extends Omit<NativeElementPropsWithoutKeyAndRef<'div'>, 'role' | 'draggable'> {
6
- /**
7
- * customized body className
8
- */
9
- bodyClassName?: string;
10
- /**
11
- * customized body row className
12
- */
13
- bodyRowClassName?: string | ((source: T) => string);
14
- /**
15
- * Columns of table <br />
16
- * `column.render` allowed customizing the column body cell rendering. <br />
17
- * `column.renderTitle` allowed customizing the column header cell rendering. <br />
18
- * `column.sorter` is the sorting method that you want to apply to your column. <br />
19
- * `column.onSorted` is the callback triggered whenever sort icon clicked.
20
- */
1
+ import { TableSize, type HighlightMode, type TableColumn, type TableDataSource, type TableDraggable, type TableExpandable, type TableRowSelection, type TableScroll } from '@mezzanine-ui/core/table';
2
+ import type { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
3
+ import { type TableTransitionState } from './TableContext';
4
+ import { TablePaginationProps } from './components/TablePagination';
5
+ import type { EmptyProps } from '../Empty';
6
+ export interface TableBaseProps<T extends TableDataSource = TableDataSource> extends Omit<NativeElementPropsWithoutKeyAndRef<'table'>, 'children' | 'draggable' | 'summary' | 'onChange'> {
7
+ /** Column configuration */
21
8
  columns: TableColumn<T>[];
22
- /**
23
- * Custom table components <br />
24
- */
25
- components?: TableComponents;
26
- /**
27
- * Data record array to be displayed. <br />
28
- * Notice that each source should contain `key` or `id` prop as data primary key.
29
- */
30
- dataSource: TableDataSource[];
31
- /**
32
- * Draggable table row. This feature allows sort items by mouse dragging. Not supported when `fetchMore` is enabled and also buggy when use finger touch (mobile device).
33
- * When `draggable.enabled` is true, draggable will be enabled.
34
- * `draggable.onDragEnd` return new dataSource for you
35
- */
36
- draggable?: TableDraggable;
37
- /**
38
- * props exported from `<Empty />` component.
39
- */
9
+ /** Data source */
10
+ dataSource: T[];
11
+ /** Props for Empty component when no data */
40
12
  emptyProps?: EmptyProps;
41
- /**
42
- * When `expandable.rowExpandable` is given, it will control whether row data is expandable or not
43
- * `expandable.expandedRowRender` is a callback to helps you decides what data should be rendered.
44
- */
45
- expandable?: Omit<TableExpandable<T>, 'expandedRowRender'> & {
46
- expandedRowRender(record: T): ReactNode | ExpandRowBySources;
47
- };
48
- /**
49
- * customized header className
50
- */
51
- headerClassName?: string;
52
- /**
53
- * Whether table is loading or not
13
+ /** Expandable row configuration */
14
+ expandable?: TableExpandable<T>;
15
+ /** Highlight mode for hover effects
16
+ * @default 'row'
54
17
  */
18
+ highlight?: HighlightMode;
19
+ /** Loading state */
55
20
  loading?: boolean;
21
+ /** Number of rows to display when loading */
22
+ loadingRowsCount?: number;
56
23
  /**
57
- * When loading is true, show specific loadingTip
58
- * @default '資料載入中...'
24
+ * Whether the table is nested inside an expanded row content area
59
25
  */
60
- loadingTip?: string;
26
+ nested?: boolean;
27
+ /** Pagination configuration */
28
+ pagination?: TablePaginationProps;
61
29
  /**
62
- * `refresh.show` is true, refresh button will display at the top-start of table. <br />
63
- * `refresh.onClick` is the callback of the refresh button.
30
+ * Whether columns are resizable by user interaction
31
+ * @default false
64
32
  */
65
- refresh?: TableRefreshType;
33
+ resizable?: boolean;
66
34
  /**
67
- * Enable row selection feature <br />
68
- * `rowSelection.selectedRowKey` is the dataSource keys that are currently selected. <br />
69
- * `rowSelection.onChange` is the callback when selection changed. <br />
70
- * `rowSelection.actions` are the actions that you want to do for selected data.
35
+ * Row height preset token.
71
36
  */
72
- rowSelection?: TableRowSelection;
73
- /**
74
- * Enable table scroll feature <br />
75
- * `scroll.x` set horizontal scrolling, can also be used to specify the width of the scroll area <br />
76
- * `scroll.y` Set vertical scrolling, can also be used to specify the height of the scroll area <br />
77
- * `scroll.fixedFirstColumn` set first column fixed when horizontal scrolling.
37
+ rowHeightPreset?: 'base' | 'condensed' | 'detailed' | 'roomy';
38
+ /** Row selection configuration */
39
+ rowSelection?: TableRowSelection<T>;
40
+ /** Show header row */
41
+ showHeader?: boolean;
42
+ /** Custom size variant
43
+ * @default 'main'
78
44
  */
79
- scroll?: TableScrolling;
80
- /**
81
- * customize scroll container className
45
+ size?: TableSize;
46
+ /** Whether to enable sticky header
47
+ * @default true
82
48
  */
83
- scrollContainerClassName?: string;
49
+ sticky?: boolean;
50
+ /** Transition state for row add/remove animations (from useTableDataSource hook) */
51
+ transitionState?: TableTransitionState;
84
52
  }
85
- export interface TableWithFetchMore<T> extends TableBaseProps<T> {
86
- /**
87
- * If `fetchMore.callback` is given, table will automatically trigger it when scrolling position reach end. <br />
88
- * If `fetchMore.isReachEnd` is true, table will stop triggering callback. <br />
89
- * If `fetchMore.isFetching` is true, a loading spinner will display at the end of table and stop triggering callback.
90
- * <br />
91
- * Notice that when `fetchMore.isFetching` is `undefined`, table will take control of it when source length changed.
92
- */
93
- fetchMore?: TableFetchMore;
94
- pagination?: undefined;
53
+ /**
54
+ * Props when virtualized scrolling is enabled.
55
+ * Draggable is not allowed in this mode.
56
+ */
57
+ export interface TableVirtualizedProps<T extends TableDataSource = TableDataSource> extends TableBaseProps<T> {
58
+ /** Draggable row configuration - not available when virtualized is enabled */
59
+ draggable?: never;
60
+ /** Scroll configuration with virtualized enabled */
61
+ scroll: TableScroll & {
62
+ virtualized: true;
63
+ y: number | string;
64
+ };
95
65
  }
96
- export interface TableWithPagination<T> extends TableBaseProps<T> {
97
- /**
98
- * `pagination.current` is the current page number. (required) <br />
99
- * `pagination.onChange` is the callback when page number changed. (required) <br />
100
- * `pagination.disableAutoSlicing` set this to true if you don't want auto data slicing. <br />
101
- * `pagination.total` is the total amount of your data. (default will be dataSource length) <br />
102
- * `pagination.options` is the 'Pagination' component props. <br />
103
- * Notice that if `pagination` object is given, table will disable fetchMore and use pagination instead.
104
- */
105
- pagination?: TablePaginationType;
106
- fetchMore?: undefined;
66
+ /**
67
+ * Props when virtualized scrolling is disabled or not specified.
68
+ * Draggable is allowed in this mode.
69
+ */
70
+ export interface TableNonVirtualizedProps<T extends TableDataSource = TableDataSource> extends TableBaseProps<T> {
71
+ /** Draggable row configuration */
72
+ draggable?: TableDraggable<T>;
73
+ /** Scroll configuration for scrolling (virtualized defaults to false) */
74
+ scroll?: TableScroll & {
75
+ virtualized?: false;
76
+ };
107
77
  }
108
- export type TableProps<T> = TableWithFetchMore<T> | TableWithPagination<T>;
109
- declare const Table: import("react").ForwardRefExoticComponent<TableProps<Record<string, unknown>> & import("react").RefAttributes<HTMLTableElement>>;
78
+ /**
79
+ * TableProps - discriminated union to ensure draggable and virtualized
80
+ * scrolling are mutually exclusive at the type level.
81
+ */
82
+ export type TableProps<T extends TableDataSource = TableDataSource> = TableVirtualizedProps<T> | TableNonVirtualizedProps<T>;
83
+ /**
84
+ * Table is a high-performance data table component with support for
85
+ * virtual scrolling, column resizing, fixed columns, row selection,
86
+ * sorting, expandable rows, and drag-and-drop row reordering.
87
+ */
88
+ export declare const Table: <T extends TableDataSource = TableDataSource>(props: TableProps<T> & {
89
+ ref?: React.ForwardedRef<HTMLDivElement>;
90
+ }) => React.ReactElement;
110
91
  export default Table;
package/Table/Table.js CHANGED
@@ -1,182 +1,237 @@
1
+ 'use client';
1
2
  import { jsx, jsxs } from 'react/jsx-runtime';
2
- import { forwardRef, useRef, useMemo, Fragment } from 'react';
3
- import { DragDropContext, Droppable } from '@hello-pangea/dnd';
3
+ import { forwardRef, useRef, useMemo, useState, useCallback } from 'react';
4
4
  import { tableClasses } from '@mezzanine-ui/core/table';
5
- import { TableContext, TableDataContext, TableComponentContext } from './TableContext.js';
6
- import TableHeader from './TableHeader.js';
7
- import TableBody from './TableBody.js';
8
- import TablePagination from './pagination/TablePagination.js';
9
- import TableRefresh from './refresh/TableRefresh.js';
10
- import { useTableRowSelection } from './rowSelection/useTableRowSelection.js';
11
- import { useTableSorting } from './sorting/useTableSorting.js';
12
- import { useTableLoading } from './useTableLoading.js';
13
- import { useTableFetchMore } from './useTableFetchMore.js';
14
- import { useTableDraggable } from './draggable/useTableDraggable.js';
15
- import useTableScroll from './useTableScroll.js';
16
- import { useComposeRefs } from '../hooks/useComposeRefs.js';
5
+ import { DragDropContext, Droppable } from '@hello-pangea/dnd';
6
+ import { TableContext, TableDataContext, TableSuperContext } from './TableContext.js';
7
+ import { TableBody } from './components/TableBody.js';
8
+ import { TableColGroup } from './components/TableColGroup.js';
9
+ import { TableHeader } from './components/TableHeader.js';
10
+ import { TablePagination } from './components/TablePagination.js';
11
+ import { useTableColumns } from './hooks/useTableColumns.js';
12
+ import { useTableExpansion } from './hooks/useTableExpansion.js';
13
+ import { useTableFixedOffsets } from './hooks/useTableFixedOffsets.js';
14
+ import { useTableScroll } from './hooks/useTableScroll.js';
15
+ import { useTableSelection } from './hooks/useTableSelection.js';
16
+ import { useTableSorting } from './hooks/useTableSorting.js';
17
17
  import { composeRefs } from '../utils/composeRefs.js';
18
- import Spin from '../Spin/Spin.js';
18
+ import { getNumericCSSVariablePixelValue } from '../utils/get-css-variable-value.js';
19
+ import { spacingPrefix } from '@mezzanine-ui/system/spacing';
19
20
  import cx from 'clsx';
20
21
 
21
- const Table = forwardRef(function Table(props, ref) {
22
- var _a;
23
- const { bodyClassName, bodyRowClassName, className, columns, components, dataSource: dataSourceProp, draggable: draggableProp, emptyProps, expandable: expandableProp, fetchMore: fetchMoreProp, headerClassName, loading: loadingProp, loadingTip = '資料載入中...', pagination: paginationProp, refresh: refreshProp, rowSelection: rowSelectionProp, scroll: scrollProp, scrollContainerClassName, ...rest } = props;
24
- const bodyRef = useRef(null);
25
- /** Feature rowSelection */
26
- const [selectedRowKeys, setSelectedRowKey] = useTableRowSelection({
27
- selectedRowKey: rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.selectedRowKey,
28
- onChange: rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.onChange,
29
- dataSource: dataSourceProp,
30
- disabledRowKeys: rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.disabledRowKeys,
31
- });
32
- const rowSelection = useMemo(() => rowSelectionProp
33
- ? {
34
- selectedRowKeys,
35
- onChange: setSelectedRowKey,
36
- actions: rowSelectionProp.actions,
37
- disabledRowKeys: rowSelectionProp.disabledRowKeys,
22
+ function TableInner(props, ref) {
23
+ const { className, columns, dataSource, draggable, emptyProps, expandable, highlight = 'row', loading = false, loadingRowsCount = 10, nested = false, pagination, resizable = false, rowHeightPreset = 'base', rowSelection, scroll, showHeader = true, size = 'main', sticky = true, style, transitionState, ...restProps } = props;
24
+ const hostRef = useRef(null);
25
+ const scrollContainerRef = useRef(null);
26
+ const tableRef = useRef(null);
27
+ // mock loading dataSource
28
+ const dataSourceForRender = loading
29
+ ? Array.from({ length: Math.max(loadingRowsCount, 1) }).map((_, idx) => ({
30
+ key: idx,
31
+ }))
32
+ : dataSource;
33
+ // get row height from preset
34
+ const rowHeight = useMemo(() => {
35
+ switch (rowHeightPreset) {
36
+ case 'condensed':
37
+ return size === 'main'
38
+ ? getNumericCSSVariablePixelValue(`--${spacingPrefix}-size-container-condensed`)
39
+ : getNumericCSSVariablePixelValue(`--${spacingPrefix}-size-container-reduced`);
40
+ case 'detailed':
41
+ return size === 'main'
42
+ ? getNumericCSSVariablePixelValue(`--${spacingPrefix}-size-container-tiny`)
43
+ : getNumericCSSVariablePixelValue(`--${spacingPrefix}-size-container-tightened`);
44
+ case 'roomy':
45
+ return size === 'main'
46
+ ? getNumericCSSVariablePixelValue(`--${spacingPrefix}-size-container-small`)
47
+ : getNumericCSSVariablePixelValue(`--${spacingPrefix}-size-container-medium`);
48
+ case 'base':
49
+ default:
50
+ return size === 'main'
51
+ ? getNumericCSSVariablePixelValue(`--${spacingPrefix}-size-container-minimized`)
52
+ : getNumericCSSVariablePixelValue(`--${spacingPrefix}-size-container-minimal`);
38
53
  }
39
- : undefined, [rowSelectionProp, selectedRowKeys, setSelectedRowKey]);
40
- /** Feature sorting */
41
- const [dataSource, onSort, { sortedOn, sortedType, onResetAll, setDataSource },] = useTableSorting({
42
- dataSource: dataSourceProp,
43
- });
44
- /** Feature loading */
45
- const [loading, setLoading] = useTableLoading({
46
- loading: loadingProp,
54
+ }, [rowHeightPreset, size]);
55
+ // Highlight state for hover effects
56
+ const [hoveredRowIndex, setHoveredRowIndex] = useState(null);
57
+ const [hoveredColumnIndex, setHoveredColumnIndex] = useState(null);
58
+ const setHoveredCell = useCallback((rowIndex, columnIndex) => {
59
+ setHoveredRowIndex(rowIndex);
60
+ setHoveredColumnIndex(columnIndex);
61
+ }, []);
62
+ // Hooks
63
+ const sortingState = useTableSorting({
64
+ columns,
47
65
  });
48
- /** Feature fetchMore */
49
- const { fetchMore: onFetchMore, isFetching, isReachEnd, } = useTableFetchMore({
50
- callback: fetchMoreProp === null || fetchMoreProp === void 0 ? void 0 : fetchMoreProp.callback,
66
+ const selectionState = useTableSelection({
51
67
  dataSource,
52
- /** when pagination is given, fetchMore feature should be disabled */
53
- disabled: !!paginationProp,
54
- isReachEnd: fetchMoreProp === null || fetchMoreProp === void 0 ? void 0 : fetchMoreProp.isReachEnd,
55
- isFetching: fetchMoreProp === null || fetchMoreProp === void 0 ? void 0 : fetchMoreProp.isFetching,
68
+ rowSelection,
56
69
  });
57
- /** Feature refresh */
58
- const isRefreshShow = useMemo(() => { var _a;
59
- /** @default false */
60
- return (_a = refreshProp === null || refreshProp === void 0 ? void 0 : refreshProp.show) !== null && _a !== void 0 ? _a : false; }, [refreshProp === null || refreshProp === void 0 ? void 0 : refreshProp.show]);
61
- /** Feature Scrolling */
62
- const [scrollBody, scrollElement, isHorizontalScrolling] = useTableScroll({
63
- onFetchMore,
64
- loading,
65
- scrollBarSize: 4,
70
+ const expansionState = useTableExpansion({
71
+ expandable,
72
+ hasDragHandle: !!(draggable === null || draggable === void 0 ? void 0 : draggable.enabled),
66
73
  });
67
- /** Feature drag and drop */
68
- const { draggingId, onBeforeDragStart, onDragEnd } = useTableDraggable({
69
- dataSource,
70
- setDataSource,
71
- draggable: draggableProp,
74
+ const actionConfig = useMemo(() => ({
75
+ hasDragHandle: !!(draggable === null || draggable === void 0 ? void 0 : draggable.enabled),
76
+ dragHandleFixed: !!(draggable === null || draggable === void 0 ? void 0 : draggable.fixed),
77
+ hasExpansion: !!expandable,
78
+ expansionFixed: !!(expandable === null || expandable === void 0 ? void 0 : expandable.fixed),
79
+ hasSelection: !!rowSelection,
80
+ selectionFixed: !!(rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.fixed),
81
+ }), [draggable === null || draggable === void 0 ? void 0 : draggable.enabled, draggable === null || draggable === void 0 ? void 0 : draggable.fixed, expandable, rowSelection]);
82
+ const columnState = useTableColumns({
83
+ actionConfig,
84
+ columns,
72
85
  });
73
- /** context */
74
- const tableContextValue = useMemo(() => {
75
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
76
- return ({
77
- emptyProps,
78
- rowSelection,
79
- isHorizontalScrolling,
80
- sorting: {
81
- onSort,
82
- onResetAll,
83
- sortedOn,
84
- sortedType,
85
- },
86
- loading,
87
- setLoading,
88
- expanding: expandableProp,
89
- fetchMore: onFetchMore
90
- ? {
91
- onFetchMore,
92
- isFetching,
93
- isReachEnd,
94
- }
95
- : undefined,
96
- pagination: paginationProp
97
- ? {
98
- current: paginationProp.current,
99
- disableAutoSlicing: (_a = paginationProp.disableAutoSlicing) !== null && _a !== void 0 ? _a : false,
100
- onChange: paginationProp.onChange,
101
- total: (_b = paginationProp.total) !== null && _b !== void 0 ? _b : dataSource.length,
102
- options: {
103
- ...((_c = paginationProp.options) !== null && _c !== void 0 ? _c : {}),
104
- boundaryCount: (_e = (_d = paginationProp.options) === null || _d === void 0 ? void 0 : _d.boundaryCount) !== null && _e !== void 0 ? _e : 1,
105
- pageSize: (_g = (_f = paginationProp.options) === null || _f === void 0 ? void 0 : _f.pageSize) !== null && _g !== void 0 ? _g : 10,
106
- siblingCount: (_j = (_h = paginationProp.options) === null || _h === void 0 ? void 0 : _h.siblingCount) !== null && _j !== void 0 ? _j : 1,
107
- },
108
- }
109
- : undefined,
110
- scroll: scrollProp,
111
- draggable: draggableProp
112
- ? {
113
- ...draggableProp,
114
- draggingId,
115
- }
116
- : undefined,
117
- });
118
- }, [
119
- dataSource,
86
+ const scrollState = useTableScroll({
87
+ enabled: !nested,
88
+ });
89
+ // Fixed column offset calculations
90
+ const fixedOffsetsState = useTableFixedOffsets({
91
+ actionConfig,
92
+ columns: columns,
93
+ getResizedColumnWidth: columnState.getResizedColumnWidth,
94
+ });
95
+ // Stabilize draggable object
96
+ const draggableValue = useMemo(() => draggable
97
+ ? {
98
+ draggingId: null,
99
+ enabled: true,
100
+ fixed: draggable.fixed,
101
+ }
102
+ : undefined, [draggable]);
103
+ // Stabilize highlight object
104
+ const highlightValue = useMemo(() => ({
105
+ columnIndex: hoveredColumnIndex,
106
+ mode: highlight,
107
+ rowIndex: hoveredRowIndex,
108
+ setHoveredCell,
109
+ }), [highlight, hoveredColumnIndex, hoveredRowIndex, setHoveredCell]);
110
+ // Determine if virtual scrolling should be enabled
111
+ // Requires scroll.virtualized to be true AND scroll.y to be set
112
+ const virtualScrollEnabled = !!((scroll === null || scroll === void 0 ? void 0 : scroll.virtualized) && (scroll === null || scroll === void 0 ? void 0 : scroll.y));
113
+ // Context value - cast to any to avoid complex generic issues
114
+ const contextValue = useMemo(() => ({
115
+ columnState,
116
+ columns: columns,
117
+ dataSource: dataSourceForRender,
118
+ draggable: draggableValue,
120
119
  emptyProps,
121
- expandableProp,
122
- rowSelection,
123
- onSort,
124
- onResetAll,
125
- sortedOn,
126
- sortedType,
120
+ expansion: expansionState,
121
+ fixedOffsets: fixedOffsetsState,
122
+ resizable,
123
+ rowHeight,
124
+ highlight: highlightValue,
125
+ isScrollingHorizontally: scrollState.isScrollingHorizontally,
126
+ isInsideExpandedContentArea: nested,
127
127
  loading,
128
- setLoading,
129
- onFetchMore,
130
- isFetching,
131
- isReachEnd,
132
- paginationProp,
133
- isHorizontalScrolling,
134
- scrollProp,
135
- draggableProp,
136
- draggingId,
137
- ]);
138
- const tableDataContextValue = useMemo(() => ({
128
+ pagination: pagination || undefined,
129
+ scroll,
130
+ scrollContainerRef,
131
+ selection: selectionState,
132
+ size,
133
+ sorting: sortingState,
134
+ transitionState,
135
+ virtualScrollEnabled,
136
+ }), [
137
+ columnState,
139
138
  columns,
139
+ dataSourceForRender,
140
+ draggableValue,
141
+ emptyProps,
142
+ expansionState,
143
+ fixedOffsetsState,
144
+ resizable,
145
+ rowHeight,
146
+ highlightValue,
147
+ loading,
148
+ pagination,
149
+ scroll,
150
+ scrollContainerRef,
151
+ scrollState.isScrollingHorizontally,
152
+ selectionState,
153
+ size,
154
+ sortingState,
155
+ transitionState,
156
+ virtualScrollEnabled,
157
+ nested,
158
+ ]);
159
+ const dataContextValue = useMemo(() => ({
160
+ columns: columns,
140
161
  dataSource,
141
162
  }), [columns, dataSource]);
142
- const tableComponentContextValue = useMemo(() => {
163
+ const superContextValue = useMemo(() => {
143
164
  var _a;
144
165
  return ({
145
- bodyCell: (_a = components === null || components === void 0 ? void 0 : components.body) === null || _a === void 0 ? void 0 : _a.cell,
166
+ containerWidth: scrollState.containerWidth,
167
+ getResizedColumnWidth: columnState.getResizedColumnWidth,
168
+ scrollLeft: scrollState.scrollLeft,
169
+ expansionLeftPadding: (_a = expansionState === null || expansionState === void 0 ? void 0 : expansionState.expansionLeftPadding) !== null && _a !== void 0 ? _a : 0,
146
170
  });
147
- }, [(_a = components === null || components === void 0 ? void 0 : components.body) === null || _a === void 0 ? void 0 : _a.cell]);
148
- const tableRefs = useComposeRefs([ref, scrollBody.target]);
149
- const rowClassName = useMemo(() => {
150
- if (bodyRowClassName) {
151
- if (typeof bodyRowClassName === 'string') {
152
- return () => bodyRowClassName;
153
- }
154
- return (source) => bodyRowClassName === null || bodyRowClassName === void 0 ? void 0 : bodyRowClassName(source);
171
+ }, [
172
+ scrollState.scrollLeft,
173
+ expansionState === null || expansionState === void 0 ? void 0 : expansionState.expansionLeftPadding,
174
+ scrollState.containerWidth,
175
+ columnState.getResizedColumnWidth,
176
+ ]);
177
+ // Drag and drop handler
178
+ const handleDragEnd = useCallback((result) => {
179
+ var _a;
180
+ if (!result.destination || !draggable)
181
+ return;
182
+ const sourceIndex = result.source.index;
183
+ const destIndex = result.destination.index;
184
+ if (sourceIndex === destIndex)
185
+ return;
186
+ const newData = [...dataSource];
187
+ const [removed] = newData.splice(sourceIndex, 1);
188
+ newData.splice(destIndex, 0, removed);
189
+ (_a = draggable.onDragEnd) === null || _a === void 0 ? void 0 : _a.call(draggable, newData);
190
+ }, [dataSource, draggable]);
191
+ const sizeClass = size === 'sub' ? tableClasses.sub : tableClasses.main;
192
+ // Scroll container style
193
+ const scrollContainerStyle = useMemo(() => {
194
+ const containerStyle = {};
195
+ if (scroll === null || scroll === void 0 ? void 0 : scroll.y) {
196
+ containerStyle.maxHeight = scroll.y;
197
+ containerStyle.overflowY = 'auto';
198
+ }
199
+ if (scroll === null || scroll === void 0 ? void 0 : scroll.x) {
200
+ containerStyle.overflowX = 'auto';
201
+ }
202
+ if (nested) {
203
+ containerStyle.position = 'unset';
204
+ containerStyle.overflow = 'unset';
205
+ }
206
+ return containerStyle;
207
+ }, [scroll === null || scroll === void 0 ? void 0 : scroll.x, scroll === null || scroll === void 0 ? void 0 : scroll.y, nested]);
208
+ // Table style with min-width for horizontal scroll
209
+ const tableStyle = useMemo(() => {
210
+ const baseStyle = {};
211
+ if (scroll === null || scroll === void 0 ? void 0 : scroll.x) {
212
+ baseStyle.minWidth = scroll.x;
213
+ baseStyle.width = '100%';
155
214
  }
156
- return undefined;
157
- }, [bodyRowClassName]);
158
- return (jsx(TableContext.Provider, { value: tableContextValue, children: jsx(TableDataContext.Provider, { value: tableDataContextValue, children: jsx(TableComponentContext.Provider, { value: tableComponentContextValue, children: jsx(DragDropContext, { onBeforeDragStart: onBeforeDragStart, onDragEnd: onDragEnd, children: jsx(Spin, { loading: loading, stretch: true, description: loadingTip, backdropProps: {
159
- className: tableClasses.loading,
160
- }, children: jsx(Droppable, { droppableId: "mzn-table-dnd", isDropDisabled: !(draggableProp === null || draggableProp === void 0 ? void 0 : draggableProp.enabled), children: (provided) => (jsxs(Fragment, { children: [jsx("div", { ...provided.droppableProps, ref: composeRefs([scrollBody.ref, provided.innerRef]), className: cx(tableClasses.scrollContainer, scrollContainerClassName), onScroll: scrollBody.onScroll, style: tableContextValue.scroll
161
- ? {
162
- '--table-scroll-x': tableContextValue.scroll.x
163
- ? `${tableContextValue.scroll.x}px`
164
- : '100%',
165
- '--table-scroll-y': tableContextValue.scroll.y
166
- ? `${tableContextValue.scroll.y}px`
167
- : 'unset',
168
- }
169
- : undefined, children: jsxs("table", { ref: tableRefs, ...rest, className: cx(tableClasses.host, className), children: [isRefreshShow ? (jsx("tbody", { children: jsx("tr", { children: jsx("td", { "aria-label": "Refresh", children: jsx(TableRefresh, { onClick: refreshProp.onClick }) }) }) })) : null, jsx(TableHeader, { className: headerClassName }), jsx(TableBody, { ref: bodyRef, className: bodyClassName, rowClassName: rowClassName }), jsx("tbody", { children: provided.placeholder })] }) }), paginationProp ? (jsx(TablePagination, { bodyRef: bodyRef })) : null, jsx("div", { ref: scrollElement.trackRef, "aria-label": "Scroll Track", style: scrollElement.trackStyle, onMouseDown: scrollElement.onMouseDown, onMouseUp: scrollElement.onMouseUp, role: "button", tabIndex: -1, className: "mzn-table-scroll-bar-track", children: jsx("div", { style: {
170
- width: '100%',
171
- height: '100%',
172
- position: 'relative',
173
- }, children: jsx("div", { ref: scrollElement.ref, "aria-label": "Scroll Bar", onMouseDown: scrollElement.onMouseDown, onMouseUp: scrollElement.onMouseUp, onMouseEnter: scrollElement.onMouseEnter, onMouseLeave: scrollElement.onMouseLeave, role: "button", style: scrollElement.style, tabIndex: -1, className: "mzn-table-scroll-bar", children: jsx("div", { style: {
174
- width: `${scrollElement.scrollBarSize}px`,
175
- height: '100%',
176
- borderRadius: '10px',
177
- backgroundColor: '#7d7d7d',
178
- transition: '0.1s',
179
- } }) }) }) })] })) }) }) }) }) }) }));
180
- });
215
+ return baseStyle;
216
+ }, [scroll === null || scroll === void 0 ? void 0 : scroll.x]);
217
+ const { setContainerRef } = scrollState;
218
+ const handleScrollContainerRef = useCallback((element) => {
219
+ scrollContainerRef.current = element;
220
+ setContainerRef(element);
221
+ }, [setContainerRef]);
222
+ const mainTable = (jsx(TableContext.Provider, { value: contextValue, children: jsx(TableDataContext.Provider, { value: dataContextValue, children: jsxs("div", { className: cx(tableClasses.host, className), ref: ref, style: style, ...restProps, children: [jsx("div", { className: cx(tableClasses.scrollContainer, {
223
+ [tableClasses.sticky]: !!sticky,
224
+ }), onScroll: scrollState.handleScroll, ref: handleScrollContainerRef, style: scrollContainerStyle, children: jsxs("table", { className: cx(tableClasses.root, sizeClass), ref: tableRef, style: tableStyle, children: [jsx(TableColGroup, {}), showHeader && jsx(TableHeader, {}), jsx(TableBody, {})] }) }), pagination && jsx(TablePagination, { ...pagination })] }) }) }));
225
+ if (nested) {
226
+ return mainTable;
227
+ }
228
+ return (jsx(DragDropContext, { onDragEnd: handleDragEnd, children: jsx(Droppable, { droppableId: "mzn-table-v2-dnd", children: (provided) => (jsxs("div", { ...provided.droppableProps, ref: composeRefs([hostRef, provided.innerRef]), children: [jsx(TableSuperContext.Provider, { value: superContextValue, children: mainTable }), provided.placeholder] })) }) }));
229
+ }
230
+ /**
231
+ * Table is a high-performance data table component with support for
232
+ * virtual scrolling, column resizing, fixed columns, row selection,
233
+ * sorting, expandable rows, and drag-and-drop row reordering.
234
+ */
235
+ const Table = forwardRef(TableInner);
181
236
 
182
- export { Table as default };
237
+ export { Table, Table as default };