musae 1.3.1-beta.24 → 1.3.1-beta.25
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/input/styles.stylex.cjs +1 -2
- package/dist/components/input/styles.stylex.d.ts +0 -1
- package/dist/components/input/styles.stylex.mjs +1 -2
- package/dist/components/table/body.cjs +1 -1
- package/dist/components/table/body.mjs +2 -2
- package/dist/components/table/context.cjs +3 -0
- package/dist/components/table/context.d.ts +2 -0
- package/dist/components/table/context.mjs +3 -1
- package/dist/components/table/header/header.cjs +1 -1
- package/dist/components/table/header/header.mjs +2 -2
- package/dist/components/table/hooks.cjs +54 -23
- package/dist/components/table/hooks.d.ts +2 -1
- package/dist/components/table/hooks.mjs +55 -24
- package/dist/components/table/table.cjs +48 -8
- package/dist/components/table/table.d.ts +1 -1
- package/dist/components/table/table.mjs +48 -8
- package/dist/styles.css +4 -0
- package/dist/types/table.d.ts +17 -0
- package/package.json +1 -1
|
@@ -16,9 +16,8 @@ var root = {
|
|
|
16
16
|
kXLuUW: "musaex-3ajldb",
|
|
17
17
|
kI3sdo: "musaex-4fx59i",
|
|
18
18
|
kZKoxP: "musaex-1s2k5h2",
|
|
19
|
-
kmuXW: "musaex-2lah0s",
|
|
20
19
|
k7Eaqz: "musaex-1rdiejn",
|
|
21
|
-
kzqmXN: "musaex-
|
|
20
|
+
kzqmXN: "musaex-mz87aw",
|
|
22
21
|
kB7OPa: "musaex-9f619",
|
|
23
22
|
kogj98: "musaex-q3gua8",
|
|
24
23
|
k8WAf4: "musaex-11owsmz",
|
|
@@ -12,7 +12,6 @@ declare const styles: {
|
|
|
12
12
|
readonly verticalAlign: import("@stylexjs/stylex").StyleXClassNameFor<"verticalAlign", "bottom">;
|
|
13
13
|
readonly outline: import("@stylexjs/stylex").StyleXClassNameFor<"outline", string>;
|
|
14
14
|
readonly height: import("@stylexjs/stylex").StyleXClassNameFor<"height", string>;
|
|
15
|
-
readonly flexShrink: import("@stylexjs/stylex").StyleXClassNameFor<"flexShrink", 0>;
|
|
16
15
|
readonly minWidth: import("@stylexjs/stylex").StyleXClassNameFor<"minWidth", string>;
|
|
17
16
|
readonly width: import("@stylexjs/stylex").StyleXClassNameFor<"width", string>;
|
|
18
17
|
readonly boxSizing: import("@stylexjs/stylex").StyleXClassNameFor<"boxSizing", "border-box">;
|
|
@@ -12,9 +12,8 @@ var root = {
|
|
|
12
12
|
kXLuUW: "musaex-3ajldb",
|
|
13
13
|
kI3sdo: "musaex-4fx59i",
|
|
14
14
|
kZKoxP: "musaex-1s2k5h2",
|
|
15
|
-
kmuXW: "musaex-2lah0s",
|
|
16
15
|
k7Eaqz: "musaex-1rdiejn",
|
|
17
|
-
kzqmXN: "musaex-
|
|
16
|
+
kzqmXN: "musaex-mz87aw",
|
|
18
17
|
kB7OPa: "musaex-9f619",
|
|
19
18
|
kogj98: "musaex-q3gua8",
|
|
20
19
|
k8WAf4: "musaex-11owsmz",
|
|
@@ -38,7 +38,7 @@ var Body = function Body() {
|
|
|
38
38
|
var cellStyled = stylex.props(isFirstChildDataCell && styles.default.body.child);
|
|
39
39
|
return /*#__PURE__*/React.createElement("td", {
|
|
40
40
|
key: cell.id,
|
|
41
|
-
className: className.stringify(styled.className, cellStyled.className, cell.column.id === context.EXPAND_COLUMN_ID && classNames.expandColumn),
|
|
41
|
+
className: className.stringify(styled.className, cellStyled.className, cell.column.id === context.EXPAND_COLUMN_ID && classNames.expandColumn, cell.column.id === context.SELECT_COLUMN_ID && classNames.selectColumn),
|
|
42
42
|
style: _objectSpread(_objectSpread(_objectSpread({}, styled.style), cellStyled.style), isFirstChildDataCell && {
|
|
43
43
|
"--depth": row.depth
|
|
44
44
|
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
2
|
import styles from './styles.mjs';
|
|
3
3
|
import React from 'react';
|
|
4
|
-
import { useTable, EXPAND_COLUMN_ID } from './context.mjs';
|
|
4
|
+
import { useTable, EXPAND_COLUMN_ID, SELECT_COLUMN_ID } from './context.mjs';
|
|
5
5
|
import { flexRender } from '@tanstack/react-table';
|
|
6
6
|
import { props } from '../../node_modules/.pnpm/@stylexjs_stylex@0.19.0/node_modules/@stylexjs/stylex/lib/es/stylex.mjs';
|
|
7
7
|
import { isEmpty } from '@aiszlab/relax';
|
|
@@ -34,7 +34,7 @@ var Body = function Body() {
|
|
|
34
34
|
var cellStyled = props(isFirstChildDataCell && styles.body.child);
|
|
35
35
|
return /*#__PURE__*/React.createElement("td", {
|
|
36
36
|
key: cell.id,
|
|
37
|
-
className: stringify(styled.className, cellStyled.className, cell.column.id === EXPAND_COLUMN_ID && classNames.expandColumn),
|
|
37
|
+
className: stringify(styled.className, cellStyled.className, cell.column.id === EXPAND_COLUMN_ID && classNames.expandColumn, cell.column.id === SELECT_COLUMN_ID && classNames.selectColumn),
|
|
38
38
|
style: _objectSpread(_objectSpread(_objectSpread({}, styled.style), cellStyled.style), isFirstChildDataCell && {
|
|
39
39
|
"--depth": row.depth
|
|
40
40
|
})
|
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
var React = require('react');
|
|
4
4
|
|
|
5
5
|
var EXPAND_COLUMN_ID = "__table_expand";
|
|
6
|
+
var SELECT_COLUMN_ID = "__table_select";
|
|
6
7
|
var CLASS_NAMES = {
|
|
7
8
|
table: "table",
|
|
8
9
|
header: "table__header",
|
|
9
10
|
body: "table__body",
|
|
10
11
|
expandColumn: "table__expand-column",
|
|
12
|
+
selectColumn: "table__select-column",
|
|
11
13
|
expandableRow: "table__row--expandable",
|
|
12
14
|
childRow: "table__row--child"
|
|
13
15
|
};
|
|
@@ -27,4 +29,5 @@ var useTable = function useTable() {
|
|
|
27
29
|
exports.CLASS_NAMES = CLASS_NAMES;
|
|
28
30
|
exports.Context = Context;
|
|
29
31
|
exports.EXPAND_COLUMN_ID = EXPAND_COLUMN_ID;
|
|
32
|
+
exports.SELECT_COLUMN_ID = SELECT_COLUMN_ID;
|
|
30
33
|
exports.useTable = useTable;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { ContextValue } from "../../types/table";
|
|
2
2
|
export declare const EXPAND_COLUMN_ID = "__table_expand";
|
|
3
|
+
export declare const SELECT_COLUMN_ID = "__table_select";
|
|
3
4
|
export declare const CLASS_NAMES: {
|
|
4
5
|
readonly table: "table";
|
|
5
6
|
readonly header: "table__header";
|
|
6
7
|
readonly body: "table__body";
|
|
7
8
|
readonly expandColumn: "table__expand-column";
|
|
9
|
+
readonly selectColumn: "table__select-column";
|
|
8
10
|
readonly expandableRow: "table__row--expandable";
|
|
9
11
|
readonly childRow: "table__row--child";
|
|
10
12
|
};
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { createContext, useContext } from 'react';
|
|
2
2
|
|
|
3
3
|
var EXPAND_COLUMN_ID = "__table_expand";
|
|
4
|
+
var SELECT_COLUMN_ID = "__table_select";
|
|
4
5
|
var CLASS_NAMES = {
|
|
5
6
|
table: "table",
|
|
6
7
|
header: "table__header",
|
|
7
8
|
body: "table__body",
|
|
8
9
|
expandColumn: "table__expand-column",
|
|
10
|
+
selectColumn: "table__select-column",
|
|
9
11
|
expandableRow: "table__row--expandable",
|
|
10
12
|
childRow: "table__row--child"
|
|
11
13
|
};
|
|
@@ -22,4 +24,4 @@ var useTable = function useTable() {
|
|
|
22
24
|
return useContext(Context);
|
|
23
25
|
};
|
|
24
26
|
|
|
25
|
-
export { CLASS_NAMES, Context, EXPAND_COLUMN_ID, useTable };
|
|
27
|
+
export { CLASS_NAMES, Context, EXPAND_COLUMN_ID, SELECT_COLUMN_ID, useTable };
|
|
@@ -30,7 +30,7 @@ var Header = function Header(props) {
|
|
|
30
30
|
}, headerGroup.headers.map(function (header) {
|
|
31
31
|
return /*#__PURE__*/React.createElement("th", {
|
|
32
32
|
key: header.id,
|
|
33
|
-
className: className.stringify(styled.className, header.column.id === context.EXPAND_COLUMN_ID && classNames.expandColumn),
|
|
33
|
+
className: className.stringify(styled.className, header.column.id === context.EXPAND_COLUMN_ID && classNames.expandColumn, header.column.id === context.SELECT_COLUMN_ID && classNames.selectColumn),
|
|
34
34
|
style: styled.style
|
|
35
35
|
}, header.isPlaceholder ? null : reactTable.flexRender(header.column.columnDef.header, header.getContext()));
|
|
36
36
|
}));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
2
|
import styles from '../styles.mjs';
|
|
3
3
|
import React from 'react';
|
|
4
|
-
import { useTable, EXPAND_COLUMN_ID } from '../context.mjs';
|
|
4
|
+
import { useTable, EXPAND_COLUMN_ID, SELECT_COLUMN_ID } from '../context.mjs';
|
|
5
5
|
import { flexRender } from '@tanstack/react-table';
|
|
6
6
|
import { props } from '../../../node_modules/.pnpm/@stylexjs_stylex@0.19.0/node_modules/@stylexjs/stylex/lib/es/stylex.mjs';
|
|
7
7
|
import { stringify } from '@aiszlab/relax/class-name';
|
|
@@ -26,7 +26,7 @@ var Header = function Header(props$1) {
|
|
|
26
26
|
}, headerGroup.headers.map(function (header) {
|
|
27
27
|
return /*#__PURE__*/React.createElement("th", {
|
|
28
28
|
key: header.id,
|
|
29
|
-
className: stringify(styled.className, header.column.id === EXPAND_COLUMN_ID && classNames.expandColumn),
|
|
29
|
+
className: stringify(styled.className, header.column.id === EXPAND_COLUMN_ID && classNames.expandColumn, header.column.id === SELECT_COLUMN_ID && classNames.selectColumn),
|
|
30
30
|
style: styled.style
|
|
31
31
|
}, header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext()));
|
|
32
32
|
}));
|
|
@@ -7,6 +7,7 @@ var React = require('react');
|
|
|
7
7
|
var cell = require('./header/cell.cjs');
|
|
8
8
|
var relax = require('@aiszlab/relax');
|
|
9
9
|
var context = require('./context.cjs');
|
|
10
|
+
var index = require('../checkbox/index.cjs');
|
|
10
11
|
var button = require('../button/button.cjs');
|
|
11
12
|
var expandLess = require('../icon/icons/navigation/expand-less.cjs');
|
|
12
13
|
var expandMore = require('../icon/icons/navigation/expand-more.cjs');
|
|
@@ -18,7 +19,9 @@ var expandMore = require('../icon/icons/navigation/expand-more.cjs');
|
|
|
18
19
|
var useColumns = function useColumns(_ref) {
|
|
19
20
|
var columns = _ref.columns,
|
|
20
21
|
_ref$expandable = _ref.expandable,
|
|
21
|
-
expandable = _ref$expandable === void 0 ? false : _ref$expandable
|
|
22
|
+
expandable = _ref$expandable === void 0 ? false : _ref$expandable,
|
|
23
|
+
_ref$selectable = _ref.selectable,
|
|
24
|
+
selectable = _ref$selectable === void 0 ? false : _ref$selectable;
|
|
22
25
|
var helper = React.useRef(reactTable.createColumnHelper());
|
|
23
26
|
return React.useMemo(function () {
|
|
24
27
|
var dataColumns = columns.map(function (_ref2, index) {
|
|
@@ -48,34 +51,62 @@ var useColumns = function useColumns(_ref) {
|
|
|
48
51
|
}
|
|
49
52
|
});
|
|
50
53
|
});
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
},
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
54
|
+
var leadingColumns = [];
|
|
55
|
+
if (selectable) {
|
|
56
|
+
leadingColumns.push(helper.current.display({
|
|
57
|
+
id: context.SELECT_COLUMN_ID,
|
|
58
|
+
header: function header(_ref4) {
|
|
59
|
+
var table = _ref4.table;
|
|
60
|
+
return /*#__PURE__*/React.createElement(index.Checkbox, {
|
|
61
|
+
checked: table.getIsAllPageRowsSelected(),
|
|
62
|
+
indeterminate: table.getIsSomePageRowsSelected(),
|
|
63
|
+
onChange: table.getToggleAllPageRowsSelectedHandler(),
|
|
64
|
+
ripple: false
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
cell: function cell(_ref5) {
|
|
68
|
+
var row = _ref5.row;
|
|
69
|
+
return /*#__PURE__*/React.createElement(index.Checkbox, {
|
|
70
|
+
checked: row.getIsSelected(),
|
|
71
|
+
disabled: !row.getCanSelect(),
|
|
72
|
+
onChange: row.getToggleSelectedHandler(),
|
|
73
|
+
ripple: false
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
if (expandable) {
|
|
79
|
+
leadingColumns.push(helper.current.display({
|
|
80
|
+
id: context.EXPAND_COLUMN_ID,
|
|
81
|
+
header: function header() {
|
|
82
|
+
return null;
|
|
83
|
+
},
|
|
84
|
+
cell: function cell(_ref6) {
|
|
85
|
+
var row = _ref6.row;
|
|
86
|
+
return row.getCanExpand() ? (/*#__PURE__*/React.createElement(button.Button, {
|
|
87
|
+
variant: "text",
|
|
88
|
+
size: "small",
|
|
89
|
+
"aria-label": row.getIsExpanded() ? "收起" : "展开",
|
|
90
|
+
"aria-expanded": row.getIsExpanded(),
|
|
91
|
+
onClick: row.getToggleExpandedHandler()
|
|
92
|
+
}, row.getIsExpanded() ? /*#__PURE__*/React.createElement(expandLess.default, null) : /*#__PURE__*/React.createElement(expandMore.default, null))) : null;
|
|
93
|
+
}
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
return [].concat(leadingColumns, _toConsumableArray(dataColumns));
|
|
97
|
+
}, [columns, expandable, selectable]);
|
|
67
98
|
};
|
|
68
99
|
/**
|
|
69
100
|
* @author murukal
|
|
70
101
|
* @description
|
|
71
102
|
* for context value
|
|
72
103
|
*/
|
|
73
|
-
var useContextValue = function useContextValue(
|
|
74
|
-
var _table =
|
|
75
|
-
bordered =
|
|
76
|
-
_sortDescriptor =
|
|
77
|
-
_onSortChange =
|
|
78
|
-
classNames =
|
|
104
|
+
var useContextValue = function useContextValue(_ref7) {
|
|
105
|
+
var _table = _ref7.table,
|
|
106
|
+
bordered = _ref7.bordered,
|
|
107
|
+
_sortDescriptor = _ref7.sortDescriptor,
|
|
108
|
+
_onSortChange = _ref7.onSortChange,
|
|
109
|
+
classNames = _ref7.classNames;
|
|
79
110
|
var _useControlledState = relax.useControlledState(_sortDescriptor),
|
|
80
111
|
_useControlledState2 = _slicedToArray(_useControlledState, 2),
|
|
81
112
|
sortDescriptor = _useControlledState2[0],
|
|
@@ -5,9 +5,10 @@ import { type CLASS_NAMES } from "./context";
|
|
|
5
5
|
* @description
|
|
6
6
|
* use columns
|
|
7
7
|
*/
|
|
8
|
-
export declare const useColumns: <T>({ columns, expandable, }: {
|
|
8
|
+
export declare const useColumns: <T>({ columns, expandable, selectable, }: {
|
|
9
9
|
columns: Column<T>[];
|
|
10
10
|
expandable?: boolean;
|
|
11
|
+
selectable?: boolean;
|
|
11
12
|
}) => ColumnDef<T, DeepValue<T, DeepKeys<T>>>[];
|
|
12
13
|
/**
|
|
13
14
|
* @author murukal
|
|
@@ -4,7 +4,8 @@ import { createColumnHelper } from '@tanstack/react-table';
|
|
|
4
4
|
import React, { useRef, useMemo } from 'react';
|
|
5
5
|
import Cell from './header/cell.mjs';
|
|
6
6
|
import { useControlledState, useEvent } from '@aiszlab/relax';
|
|
7
|
-
import { EXPAND_COLUMN_ID } from './context.mjs';
|
|
7
|
+
import { SELECT_COLUMN_ID, EXPAND_COLUMN_ID } from './context.mjs';
|
|
8
|
+
import { Checkbox } from '../checkbox/index.mjs';
|
|
8
9
|
import { Button } from '../button/button.mjs';
|
|
9
10
|
import IconExpandLess from '../icon/icons/navigation/expand-less.mjs';
|
|
10
11
|
import IconExpandMore from '../icon/icons/navigation/expand-more.mjs';
|
|
@@ -16,7 +17,9 @@ import IconExpandMore from '../icon/icons/navigation/expand-more.mjs';
|
|
|
16
17
|
var useColumns = function useColumns(_ref) {
|
|
17
18
|
var columns = _ref.columns,
|
|
18
19
|
_ref$expandable = _ref.expandable,
|
|
19
|
-
expandable = _ref$expandable === void 0 ? false : _ref$expandable
|
|
20
|
+
expandable = _ref$expandable === void 0 ? false : _ref$expandable,
|
|
21
|
+
_ref$selectable = _ref.selectable,
|
|
22
|
+
selectable = _ref$selectable === void 0 ? false : _ref$selectable;
|
|
20
23
|
var helper = useRef(createColumnHelper());
|
|
21
24
|
return useMemo(function () {
|
|
22
25
|
var dataColumns = columns.map(function (_ref2, index) {
|
|
@@ -46,34 +49,62 @@ var useColumns = function useColumns(_ref) {
|
|
|
46
49
|
}
|
|
47
50
|
});
|
|
48
51
|
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
},
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
52
|
+
var leadingColumns = [];
|
|
53
|
+
if (selectable) {
|
|
54
|
+
leadingColumns.push(helper.current.display({
|
|
55
|
+
id: SELECT_COLUMN_ID,
|
|
56
|
+
header: function header(_ref4) {
|
|
57
|
+
var table = _ref4.table;
|
|
58
|
+
return /*#__PURE__*/React.createElement(Checkbox, {
|
|
59
|
+
checked: table.getIsAllPageRowsSelected(),
|
|
60
|
+
indeterminate: table.getIsSomePageRowsSelected(),
|
|
61
|
+
onChange: table.getToggleAllPageRowsSelectedHandler(),
|
|
62
|
+
ripple: false
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
cell: function cell(_ref5) {
|
|
66
|
+
var row = _ref5.row;
|
|
67
|
+
return /*#__PURE__*/React.createElement(Checkbox, {
|
|
68
|
+
checked: row.getIsSelected(),
|
|
69
|
+
disabled: !row.getCanSelect(),
|
|
70
|
+
onChange: row.getToggleSelectedHandler(),
|
|
71
|
+
ripple: false
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
if (expandable) {
|
|
77
|
+
leadingColumns.push(helper.current.display({
|
|
78
|
+
id: EXPAND_COLUMN_ID,
|
|
79
|
+
header: function header() {
|
|
80
|
+
return null;
|
|
81
|
+
},
|
|
82
|
+
cell: function cell(_ref6) {
|
|
83
|
+
var row = _ref6.row;
|
|
84
|
+
return row.getCanExpand() ? (/*#__PURE__*/React.createElement(Button, {
|
|
85
|
+
variant: "text",
|
|
86
|
+
size: "small",
|
|
87
|
+
"aria-label": row.getIsExpanded() ? "收起" : "展开",
|
|
88
|
+
"aria-expanded": row.getIsExpanded(),
|
|
89
|
+
onClick: row.getToggleExpandedHandler()
|
|
90
|
+
}, row.getIsExpanded() ? /*#__PURE__*/React.createElement(IconExpandLess, null) : /*#__PURE__*/React.createElement(IconExpandMore, null))) : null;
|
|
91
|
+
}
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
return [].concat(leadingColumns, _toConsumableArray(dataColumns));
|
|
95
|
+
}, [columns, expandable, selectable]);
|
|
65
96
|
};
|
|
66
97
|
/**
|
|
67
98
|
* @author murukal
|
|
68
99
|
* @description
|
|
69
100
|
* for context value
|
|
70
101
|
*/
|
|
71
|
-
var useContextValue = function useContextValue(
|
|
72
|
-
var _table =
|
|
73
|
-
bordered =
|
|
74
|
-
_sortDescriptor =
|
|
75
|
-
_onSortChange =
|
|
76
|
-
classNames =
|
|
102
|
+
var useContextValue = function useContextValue(_ref7) {
|
|
103
|
+
var _table = _ref7.table,
|
|
104
|
+
bordered = _ref7.bordered,
|
|
105
|
+
_sortDescriptor = _ref7.sortDescriptor,
|
|
106
|
+
_onSortChange = _ref7.onSortChange,
|
|
107
|
+
classNames = _ref7.classNames;
|
|
77
108
|
var _useControlledState = useControlledState(_sortDescriptor),
|
|
78
109
|
_useControlledState2 = _slicedToArray(_useControlledState, 2),
|
|
79
110
|
sortDescriptor = _useControlledState2[0],
|
|
@@ -40,20 +40,31 @@ var Table = function Table(_ref) {
|
|
|
40
40
|
defaultExpandedKeys = _ref$defaultExpandedK === void 0 ? [] : _ref$defaultExpandedK,
|
|
41
41
|
onExpandedKeysChange = _ref.onExpandedKeysChange,
|
|
42
42
|
rowKey = _ref.rowKey,
|
|
43
|
-
_pagination = _ref.pagination
|
|
43
|
+
_pagination = _ref.pagination,
|
|
44
|
+
rowSelection = _ref.rowSelection;
|
|
44
45
|
var classNames = useClassNames.useClassNames(context.CLASS_NAMES);
|
|
45
46
|
var columns = hooks.useColumns({
|
|
46
47
|
columns: _columns,
|
|
47
|
-
expandable: expandable
|
|
48
|
+
expandable: expandable,
|
|
49
|
+
selectable: Boolean(rowSelection)
|
|
48
50
|
});
|
|
49
51
|
var _useState = React.useState(function () {
|
|
50
|
-
|
|
52
|
+
var _rowSelection$default;
|
|
53
|
+
return Object.fromEntries(((_rowSelection$default = rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.defaultSelectedRowKeys) !== null && _rowSelection$default !== void 0 ? _rowSelection$default : []).map(function (key) {
|
|
51
54
|
return [String(key), true];
|
|
52
55
|
}));
|
|
53
56
|
}),
|
|
54
57
|
_useState2 = _slicedToArray(_useState, 2),
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
uncontrolledSelection = _useState2[0],
|
|
59
|
+
setUncontrolledSelection = _useState2[1];
|
|
60
|
+
var _useState3 = React.useState(function () {
|
|
61
|
+
return Object.fromEntries(defaultExpandedKeys.map(function (key) {
|
|
62
|
+
return [String(key), true];
|
|
63
|
+
}));
|
|
64
|
+
}),
|
|
65
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
66
|
+
uncontrolledExpanded = _useState4[0],
|
|
67
|
+
setUncontrolledExpanded = _useState4[1];
|
|
57
68
|
var _usePagination = usePagination_hook.usePagination({
|
|
58
69
|
pagination: _pagination
|
|
59
70
|
}),
|
|
@@ -67,11 +78,15 @@ var Table = function Table(_ref) {
|
|
|
67
78
|
return [String(key), true];
|
|
68
79
|
}));
|
|
69
80
|
}, [expandedKeys, uncontrolledExpanded]);
|
|
70
|
-
var table = reactTable.useReactTable(_objectSpread(_objectSpread(_objectSpread({
|
|
81
|
+
var table = reactTable.useReactTable(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
71
82
|
columns: columns,
|
|
72
83
|
data: dataSource,
|
|
73
84
|
getCoreRowModel: reactTable.getCoreRowModel(),
|
|
74
|
-
state: _objectSpread(_objectSpread({},
|
|
85
|
+
state: _objectSpread(_objectSpread(_objectSpread({}, rowSelection && {
|
|
86
|
+
rowSelection: relax.isUndefined(rowSelection.selectedRowKeys) ? uncontrolledSelection : Object.fromEntries(rowSelection.selectedRowKeys.map(function (key) {
|
|
87
|
+
return [String(key), true];
|
|
88
|
+
}))
|
|
89
|
+
}), expandable && {
|
|
75
90
|
expanded: expanded
|
|
76
91
|
}), !isPaginationHidden && {
|
|
77
92
|
pagination: {
|
|
@@ -79,7 +94,32 @@ var Table = function Table(_ref) {
|
|
|
79
94
|
pageSize: pagination$1.pageSize
|
|
80
95
|
}
|
|
81
96
|
})
|
|
82
|
-
},
|
|
97
|
+
}, rowSelection && {
|
|
98
|
+
enableRowSelection: true,
|
|
99
|
+
onRowSelectionChange: function onRowSelectionChange(updater) {
|
|
100
|
+
var _rowSelection$onChang;
|
|
101
|
+
var current = relax.isUndefined(rowSelection.selectedRowKeys) ? uncontrolledSelection : Object.fromEntries(rowSelection.selectedRowKeys.map(function (key) {
|
|
102
|
+
return [String(key), true];
|
|
103
|
+
}));
|
|
104
|
+
var next = relax.isFunction(updater) ? updater(current) : updater;
|
|
105
|
+
if (relax.isUndefined(rowSelection.selectedRowKeys)) setUncontrolledSelection(next);
|
|
106
|
+
var selectedRowIds = Object.keys(next);
|
|
107
|
+
var rowsById = table.getCoreRowModel().rowsById;
|
|
108
|
+
var selectedRows = selectedRowIds.flatMap(function (key) {
|
|
109
|
+
return rowsById[key] ? [rowsById[key].original] : [];
|
|
110
|
+
});
|
|
111
|
+
var selectedRowKeys = selectedRowIds.map(function (key) {
|
|
112
|
+
var row = rowsById[key];
|
|
113
|
+
if (!row || !rowKey) return key;
|
|
114
|
+
if (relax.isFunction(rowKey)) {
|
|
115
|
+
var _rowsById$row$parentI;
|
|
116
|
+
return rowKey(row.original, row.index, row.parentId ? (_rowsById$row$parentI = rowsById[row.parentId]) === null || _rowsById$row$parentI === void 0 ? void 0 : _rowsById$row$parentI.original : undefined);
|
|
117
|
+
}
|
|
118
|
+
return relax.get(row.original, rowKey);
|
|
119
|
+
});
|
|
120
|
+
(_rowSelection$onChang = rowSelection.onChange) === null || _rowSelection$onChang === void 0 || _rowSelection$onChang.call(rowSelection, selectedRowKeys, selectedRows);
|
|
121
|
+
}
|
|
122
|
+
}), !isPaginationHidden && {
|
|
83
123
|
getPaginationRowModel: reactTable.getPaginationRowModel(),
|
|
84
124
|
onPaginationChange: function onPaginationChange(updater) {
|
|
85
125
|
var next = relax.isFunction(updater) ? updater(pagination$1) : updater;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { TableProps } from "../../types/table";
|
|
3
|
-
declare const Table: <T>({ bordered, dataSource, columns: _columns, sortDescriptor, onSortChange, className, style, loading, expandable, expandedKeys, defaultExpandedKeys, onExpandedKeysChange, rowKey, pagination: _pagination, }: TableProps<T>) => React.JSX.Element;
|
|
3
|
+
declare const Table: <T>({ bordered, dataSource, columns: _columns, sortDescriptor, onSortChange, className, style, loading, expandable, expandedKeys, defaultExpandedKeys, onExpandedKeysChange, rowKey, pagination: _pagination, rowSelection, }: TableProps<T>) => React.JSX.Element;
|
|
4
4
|
export default Table;
|
|
@@ -36,20 +36,31 @@ var Table = function Table(_ref) {
|
|
|
36
36
|
defaultExpandedKeys = _ref$defaultExpandedK === void 0 ? [] : _ref$defaultExpandedK,
|
|
37
37
|
onExpandedKeysChange = _ref.onExpandedKeysChange,
|
|
38
38
|
rowKey = _ref.rowKey,
|
|
39
|
-
_pagination = _ref.pagination
|
|
39
|
+
_pagination = _ref.pagination,
|
|
40
|
+
rowSelection = _ref.rowSelection;
|
|
40
41
|
var classNames = useClassNames(CLASS_NAMES);
|
|
41
42
|
var columns = useColumns({
|
|
42
43
|
columns: _columns,
|
|
43
|
-
expandable: expandable
|
|
44
|
+
expandable: expandable,
|
|
45
|
+
selectable: Boolean(rowSelection)
|
|
44
46
|
});
|
|
45
47
|
var _useState = useState(function () {
|
|
46
|
-
|
|
48
|
+
var _rowSelection$default;
|
|
49
|
+
return Object.fromEntries(((_rowSelection$default = rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.defaultSelectedRowKeys) !== null && _rowSelection$default !== void 0 ? _rowSelection$default : []).map(function (key) {
|
|
47
50
|
return [String(key), true];
|
|
48
51
|
}));
|
|
49
52
|
}),
|
|
50
53
|
_useState2 = _slicedToArray(_useState, 2),
|
|
51
|
-
|
|
52
|
-
|
|
54
|
+
uncontrolledSelection = _useState2[0],
|
|
55
|
+
setUncontrolledSelection = _useState2[1];
|
|
56
|
+
var _useState3 = useState(function () {
|
|
57
|
+
return Object.fromEntries(defaultExpandedKeys.map(function (key) {
|
|
58
|
+
return [String(key), true];
|
|
59
|
+
}));
|
|
60
|
+
}),
|
|
61
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
62
|
+
uncontrolledExpanded = _useState4[0],
|
|
63
|
+
setUncontrolledExpanded = _useState4[1];
|
|
53
64
|
var _usePagination = usePagination({
|
|
54
65
|
pagination: _pagination
|
|
55
66
|
}),
|
|
@@ -63,11 +74,15 @@ var Table = function Table(_ref) {
|
|
|
63
74
|
return [String(key), true];
|
|
64
75
|
}));
|
|
65
76
|
}, [expandedKeys, uncontrolledExpanded]);
|
|
66
|
-
var table = useReactTable(_objectSpread(_objectSpread(_objectSpread({
|
|
77
|
+
var table = useReactTable(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
67
78
|
columns: columns,
|
|
68
79
|
data: dataSource,
|
|
69
80
|
getCoreRowModel: getCoreRowModel(),
|
|
70
|
-
state: _objectSpread(_objectSpread({},
|
|
81
|
+
state: _objectSpread(_objectSpread(_objectSpread({}, rowSelection && {
|
|
82
|
+
rowSelection: isUndefined(rowSelection.selectedRowKeys) ? uncontrolledSelection : Object.fromEntries(rowSelection.selectedRowKeys.map(function (key) {
|
|
83
|
+
return [String(key), true];
|
|
84
|
+
}))
|
|
85
|
+
}), expandable && {
|
|
71
86
|
expanded: expanded
|
|
72
87
|
}), !isPaginationHidden && {
|
|
73
88
|
pagination: {
|
|
@@ -75,7 +90,32 @@ var Table = function Table(_ref) {
|
|
|
75
90
|
pageSize: pagination.pageSize
|
|
76
91
|
}
|
|
77
92
|
})
|
|
78
|
-
},
|
|
93
|
+
}, rowSelection && {
|
|
94
|
+
enableRowSelection: true,
|
|
95
|
+
onRowSelectionChange: function onRowSelectionChange(updater) {
|
|
96
|
+
var _rowSelection$onChang;
|
|
97
|
+
var current = isUndefined(rowSelection.selectedRowKeys) ? uncontrolledSelection : Object.fromEntries(rowSelection.selectedRowKeys.map(function (key) {
|
|
98
|
+
return [String(key), true];
|
|
99
|
+
}));
|
|
100
|
+
var next = isFunction(updater) ? updater(current) : updater;
|
|
101
|
+
if (isUndefined(rowSelection.selectedRowKeys)) setUncontrolledSelection(next);
|
|
102
|
+
var selectedRowIds = Object.keys(next);
|
|
103
|
+
var rowsById = table.getCoreRowModel().rowsById;
|
|
104
|
+
var selectedRows = selectedRowIds.flatMap(function (key) {
|
|
105
|
+
return rowsById[key] ? [rowsById[key].original] : [];
|
|
106
|
+
});
|
|
107
|
+
var selectedRowKeys = selectedRowIds.map(function (key) {
|
|
108
|
+
var row = rowsById[key];
|
|
109
|
+
if (!row || !rowKey) return key;
|
|
110
|
+
if (isFunction(rowKey)) {
|
|
111
|
+
var _rowsById$row$parentI;
|
|
112
|
+
return rowKey(row.original, row.index, row.parentId ? (_rowsById$row$parentI = rowsById[row.parentId]) === null || _rowsById$row$parentI === void 0 ? void 0 : _rowsById$row$parentI.original : undefined);
|
|
113
|
+
}
|
|
114
|
+
return get(row.original, rowKey);
|
|
115
|
+
});
|
|
116
|
+
(_rowSelection$onChang = rowSelection.onChange) === null || _rowSelection$onChang === void 0 || _rowSelection$onChang.call(rowSelection, selectedRowKeys, selectedRows);
|
|
117
|
+
}
|
|
118
|
+
}), !isPaginationHidden && {
|
|
79
119
|
getPaginationRowModel: getPaginationRowModel(),
|
|
80
120
|
onPaginationChange: function onPaginationChange(updater) {
|
|
81
121
|
var next = isFunction(updater) ? updater(pagination) : updater;
|
package/dist/styles.css
CHANGED
package/dist/types/table.d.ts
CHANGED
|
@@ -8,6 +8,18 @@ export type SortDescriptor = {
|
|
|
8
8
|
key: Key;
|
|
9
9
|
direction: SortDirection;
|
|
10
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* @zh 表格行选择配置。
|
|
13
|
+
* @en Table row selection configuration.
|
|
14
|
+
*/
|
|
15
|
+
export type RowSelection<T> = {
|
|
16
|
+
/** @zh 受控的已选行标识。 @en Controlled selected row keys. */
|
|
17
|
+
selectedRowKeys?: Key[];
|
|
18
|
+
/** @zh 非受控模式下的初始已选行标识。 @en Initial selected row keys in uncontrolled mode. */
|
|
19
|
+
defaultSelectedRowKeys?: Key[];
|
|
20
|
+
/** @zh 已选行变化时触发。 @en Called when selected rows change. */
|
|
21
|
+
onChange?: (selectedRowKeys: Key[], selectedRows: T[]) => void;
|
|
22
|
+
};
|
|
11
23
|
/**
|
|
12
24
|
* @description
|
|
13
25
|
* column def
|
|
@@ -104,6 +116,11 @@ export type TableProps<T> = ComponentProps & {
|
|
|
104
116
|
* @en Configure built-in pagination. Set to `false` or omit to hide it.
|
|
105
117
|
*/
|
|
106
118
|
pagination?: false | PagiantionProps;
|
|
119
|
+
/**
|
|
120
|
+
* @zh 配置行选择;设置后表格会显示选择框列。
|
|
121
|
+
* @en Configure row selection. A selection column is shown when provided.
|
|
122
|
+
*/
|
|
123
|
+
rowSelection?: RowSelection<T>;
|
|
107
124
|
};
|
|
108
125
|
/** Recursive record shape used by the built-in hierarchical-row reader. */
|
|
109
126
|
export type ExpandableRecord<T> = T & {
|