@rainbow-oh/yee-c 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Table/demo/components-override.d.ts +3 -0
- package/dist/cjs/Table/demo/components-override.js +54 -0
- package/dist/cjs/Table/demo/grouping.d.ts +3 -0
- package/dist/cjs/Table/demo/grouping.js +129 -0
- package/dist/cjs/Table/hooks/useColumns.d.ts +2 -2
- package/dist/cjs/Table/hooks/useColumns.js +15 -37
- package/dist/cjs/Table/index.d.ts +1 -1
- package/dist/cjs/Table/interface.d.ts +59 -8
- package/dist/cjs/Table/style/index.less +19 -1
- package/dist/cjs/Table/table.js +5 -7
- package/dist/cjs/Table/tbody/cell.d.ts +0 -1
- package/dist/cjs/Table/tbody/cell.js +0 -4
- package/dist/cjs/Table/tbody/index.js +19 -2
- package/dist/cjs/Table/tbody/row.js +15 -11
- package/dist/cjs/Table/theader/cell.js +7 -1
- package/dist/cjs/Table/theader/index.d.ts +5 -5
- package/dist/cjs/Table/theader/index.js +41 -27
- package/dist/cjs/Table/util/header.d.ts +23 -0
- package/dist/cjs/Table/util/header.js +109 -0
- package/dist/cjs/style/themes.css +1 -1
- package/dist/cjs/style/variables.css +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/Table/demo/components-override.d.ts +3 -0
- package/dist/esm/Table/demo/components-override.js +86 -0
- package/dist/esm/Table/demo/grouping.d.ts +3 -0
- package/dist/esm/Table/demo/grouping.js +102 -0
- package/dist/esm/Table/hooks/useColumns.d.ts +2 -2
- package/dist/esm/Table/hooks/useColumns.js +24 -50
- package/dist/esm/Table/index.d.ts +1 -1
- package/dist/esm/Table/interface.d.ts +59 -8
- package/dist/esm/Table/style/index.less +19 -1
- package/dist/esm/Table/table.js +5 -7
- package/dist/esm/Table/tbody/cell.d.ts +0 -1
- package/dist/esm/Table/tbody/cell.js +0 -5
- package/dist/esm/Table/tbody/index.js +21 -2
- package/dist/esm/Table/tbody/row.js +19 -15
- package/dist/esm/Table/theader/cell.js +6 -2
- package/dist/esm/Table/theader/index.d.ts +5 -5
- package/dist/esm/Table/theader/index.js +48 -35
- package/dist/esm/Table/util/header.d.ts +23 -0
- package/dist/esm/Table/util/header.js +107 -0
- package/dist/esm/style/themes.css +1 -1
- package/dist/esm/style/variables.css +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/umd/yee-c.min.css +1 -1
- package/dist/umd/yee-c.min.js +1 -1
- package/package.json +1 -1
- package/src/Table/demo/components-override.tsx +49 -0
- package/src/Table/demo/grouping.tsx +104 -0
- package/src/Table/hooks/useColumns.ts +29 -46
- package/src/Table/index.en-US.md +31 -3
- package/src/Table/index.ts +4 -0
- package/src/Table/index.zh-CN.md +30 -2
- package/src/Table/interface.ts +66 -8
- package/src/Table/style/index.less +19 -1
- package/src/Table/table.tsx +5 -7
- package/src/Table/tbody/cell.tsx +0 -6
- package/src/Table/tbody/index.tsx +21 -2
- package/src/Table/tbody/row.tsx +25 -14
- package/src/Table/theader/cell.tsx +4 -0
- package/src/Table/theader/index.tsx +61 -42
- package/src/Table/util/header.ts +111 -0
- package/src/version.ts +1 -1
|
@@ -67,39 +67,53 @@ var import_Checkbox = __toESM(require("../../Checkbox"));
|
|
|
67
67
|
var import_table = require("../table");
|
|
68
68
|
var import_cell = __toESM(require("./cell"));
|
|
69
69
|
var TableHead = (props) => {
|
|
70
|
-
const _a = props, {
|
|
70
|
+
const _a = props, { headerRows = [], onCheckAll, checkedAll, onHeaderRow } = _a, rest = __objRest(_a, ["headerRows", "onCheckAll", "checkedAll", "onHeaderRow"]);
|
|
71
71
|
const { prefixCls } = (0, import_react.useContext)(import_table.TableCtx);
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
const renderCell = (cell, rowIndex, colIndex) => {
|
|
73
|
+
const { column, colSpan, rowSpan } = cell;
|
|
74
|
+
const { key, type, visible } = column;
|
|
75
|
+
const cellKey = "title-column-" + (column.key || column.dataIndex || `${rowIndex}-${colIndex}`);
|
|
76
|
+
if (key === "YEE_SELECTION_COL") {
|
|
77
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
78
|
+
"th",
|
|
79
|
+
{
|
|
77
80
|
className: `${prefixCls}-cell ${prefixCls}-selection-col`,
|
|
78
81
|
scope: "col",
|
|
79
|
-
key:
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
className: (0, import_clsx.default)(`${prefixCls}-cell`, `${prefixCls}-expand-col`),
|
|
88
|
-
scope: "col",
|
|
89
|
-
key: "title-column-expandable"
|
|
90
|
-
}
|
|
91
|
-
);
|
|
92
|
-
}
|
|
82
|
+
key: cellKey,
|
|
83
|
+
colSpan,
|
|
84
|
+
rowSpan
|
|
85
|
+
},
|
|
86
|
+
type === "checkbox" ? /* @__PURE__ */ import_react.default.createElement(import_Checkbox.default, { checked: checkedAll, onChange: onCheckAll }) : null
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
if (key === "YEE_EXPAND_COL" && visible !== false) {
|
|
93
90
|
return /* @__PURE__ */ import_react.default.createElement(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
91
|
+
"th",
|
|
92
|
+
{
|
|
93
|
+
className: (0, import_clsx.default)(`${prefixCls}-cell`, `${prefixCls}-expand-col`),
|
|
94
|
+
scope: "col",
|
|
95
|
+
key: cellKey,
|
|
96
|
+
colSpan,
|
|
97
|
+
rowSpan
|
|
98
|
+
}
|
|
98
99
|
);
|
|
99
|
-
}
|
|
100
|
+
}
|
|
101
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
102
|
+
import_cell.default,
|
|
103
|
+
__spreadProps(__spreadValues(__spreadValues({}, rest), column), {
|
|
104
|
+
colSpan,
|
|
105
|
+
rowSpan,
|
|
106
|
+
key: cellKey
|
|
107
|
+
})
|
|
108
|
+
);
|
|
100
109
|
};
|
|
101
|
-
|
|
102
|
-
|
|
110
|
+
return /* @__PURE__ */ import_react.default.createElement("thead", { className: (0, import_clsx.default)(`${prefixCls}-thead`) }, headerRows.map((row, rowIndex) => {
|
|
111
|
+
const rowColumns = row.map((cell) => cell.column);
|
|
112
|
+
const rowProps = onHeaderRow ? onHeaderRow(rowColumns) : {};
|
|
113
|
+
return /* @__PURE__ */ import_react.default.createElement("tr", __spreadProps(__spreadValues({}, rowProps), { key: `thead-row-${rowIndex}` }), row.map(
|
|
114
|
+
(cell, colIndex) => renderCell(cell, rowIndex, colIndex)
|
|
115
|
+
));
|
|
116
|
+
}));
|
|
103
117
|
};
|
|
104
118
|
var Row = (props) => {
|
|
105
119
|
const _a = props, { children } = _a, rest = __objRest(_a, ["children"]);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ColumnProps, ExpandableType, HeaderCell, RowSelectionType, WrapedColumnProps } from '../interface';
|
|
2
|
+
type FixedType = ColumnProps['fixed'];
|
|
3
|
+
/**
|
|
4
|
+
* Recursively flatten a (possibly grouped) column tree into its leaf columns.
|
|
5
|
+
* A parent's `fixed` is inherited by its children when the child does not set its own.
|
|
6
|
+
*/
|
|
7
|
+
export declare function flattenLeafColumns(columns: WrapedColumnProps[], parentFixed?: FixedType): WrapedColumnProps[];
|
|
8
|
+
/**
|
|
9
|
+
* Convert a column tree into a 2D array of header cells (one array per header row),
|
|
10
|
+
* computing each cell's colSpan/rowSpan. Mirrors rc-table's parseHeaderRows.
|
|
11
|
+
*
|
|
12
|
+
* - Pass 1 (DFS): place each column into the row matching its depth; a group's
|
|
13
|
+
* colSpan equals the sum of its children's colSpans.
|
|
14
|
+
* - Pass 2: leaf cells (no sub-columns) get rowSpan = rowCount - rowIndex so
|
|
15
|
+
* they stretch down to the last header row; group cells keep rowSpan = 1.
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseHeaderRows(rootColumns: WrapedColumnProps[]): HeaderCell[][];
|
|
18
|
+
/**
|
|
19
|
+
* Inject selection / expand columns into the top level of the column tree.
|
|
20
|
+
* `index` is a 1-based position among the top-level columns.
|
|
21
|
+
*/
|
|
22
|
+
export declare function injectSelectionExpand(columns: WrapedColumnProps[], rowSelection?: RowSelectionType, expandable?: ExpandableType): WrapedColumnProps[];
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __spreadValues = (a, b) => {
|
|
11
|
+
for (var prop in b || (b = {}))
|
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
if (__getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
};
|
|
21
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
|
+
var __export = (target, all) => {
|
|
23
|
+
for (var name in all)
|
|
24
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
25
|
+
};
|
|
26
|
+
var __copyProps = (to, from, except, desc) => {
|
|
27
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
28
|
+
for (let key of __getOwnPropNames(from))
|
|
29
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
30
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
31
|
+
}
|
|
32
|
+
return to;
|
|
33
|
+
};
|
|
34
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
35
|
+
|
|
36
|
+
// src/Table/util/header.ts
|
|
37
|
+
var header_exports = {};
|
|
38
|
+
__export(header_exports, {
|
|
39
|
+
flattenLeafColumns: () => flattenLeafColumns,
|
|
40
|
+
injectSelectionExpand: () => injectSelectionExpand,
|
|
41
|
+
parseHeaderRows: () => parseHeaderRows
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(header_exports);
|
|
44
|
+
function flattenLeafColumns(columns, parentFixed) {
|
|
45
|
+
return columns.reduce((list, column) => {
|
|
46
|
+
var _a;
|
|
47
|
+
const fixed = (_a = column.fixed) != null ? _a : parentFixed;
|
|
48
|
+
const subColumns = column.children;
|
|
49
|
+
if (subColumns && subColumns.length > 0) {
|
|
50
|
+
return [...list, ...flattenLeafColumns(subColumns, fixed)];
|
|
51
|
+
}
|
|
52
|
+
return [...list, __spreadProps(__spreadValues({}, column), { fixed })];
|
|
53
|
+
}, []);
|
|
54
|
+
}
|
|
55
|
+
function parseHeaderRows(rootColumns) {
|
|
56
|
+
const rows = [];
|
|
57
|
+
const fillRowCells = (columns, rowIndex) => {
|
|
58
|
+
rows[rowIndex] = rows[rowIndex] || [];
|
|
59
|
+
let colSpanTotal = 0;
|
|
60
|
+
columns.filter(Boolean).forEach((column) => {
|
|
61
|
+
const cell = {
|
|
62
|
+
column,
|
|
63
|
+
colSpan: 1,
|
|
64
|
+
rowSpan: 1
|
|
65
|
+
};
|
|
66
|
+
const subColumns = column.children;
|
|
67
|
+
if (subColumns && subColumns.length > 0) {
|
|
68
|
+
cell.colSpan = fillRowCells(subColumns, rowIndex + 1);
|
|
69
|
+
cell.hasSubColumns = true;
|
|
70
|
+
}
|
|
71
|
+
rows[rowIndex].push(cell);
|
|
72
|
+
colSpanTotal += cell.colSpan;
|
|
73
|
+
});
|
|
74
|
+
return colSpanTotal;
|
|
75
|
+
};
|
|
76
|
+
fillRowCells(rootColumns, 0);
|
|
77
|
+
const rowCount = rows.length;
|
|
78
|
+
for (let rowIndex = 0; rowIndex < rowCount; rowIndex += 1) {
|
|
79
|
+
rows[rowIndex].forEach((cell) => {
|
|
80
|
+
if (!cell.hasSubColumns) {
|
|
81
|
+
cell.rowSpan = rowCount - rowIndex;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return rows;
|
|
86
|
+
}
|
|
87
|
+
function injectSelectionExpand(columns, rowSelection, expandable) {
|
|
88
|
+
const result = [...columns];
|
|
89
|
+
if (rowSelection) {
|
|
90
|
+
const { index = 1 } = rowSelection;
|
|
91
|
+
result.splice(index - 1, 0, __spreadProps(__spreadValues({
|
|
92
|
+
width: 50
|
|
93
|
+
}, rowSelection), {
|
|
94
|
+
key: "YEE_SELECTION_COL"
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
if (expandable) {
|
|
98
|
+
const { index = 1, visible = true } = expandable;
|
|
99
|
+
const loc = index ? index - 1 : rowSelection ? 1 : 0;
|
|
100
|
+
if (visible !== false) {
|
|
101
|
+
result.splice(loc, 0, __spreadProps(__spreadValues({
|
|
102
|
+
width: 50
|
|
103
|
+
}, expandable), {
|
|
104
|
+
key: "YEE_EXPAND_COL"
|
|
105
|
+
}));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
109
|
+
}
|
package/dist/cjs/version.d.ts
CHANGED
package/dist/cjs/version.js
CHANGED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 自定义表格元素(可被外部接管)
|
|
3
|
+
*
|
|
4
|
+
* Table 暴露两个接缝供外部库(如 dnd-kit)接管行/体渲染:
|
|
5
|
+
* - components.body.tbody —— 替换 <tbody>,外部可在此包 SortableContext 等 Provider;
|
|
6
|
+
* - components.body.row —— 整行接管,消费方自行渲染 <tr> + 单元格,可在任意单元格里放拖拽手柄。
|
|
7
|
+
*
|
|
8
|
+
* Table 本身不依赖任何拖拽库;本 demo 不引入 dnd,仅证明替换点生效。
|
|
9
|
+
*/
|
|
10
|
+
import { Table } from "../..";
|
|
11
|
+
import React from 'react';
|
|
12
|
+
|
|
13
|
+
// 替换 <tbody>:保持渲染 <tbody>,外部库可在此包 SortableContext。
|
|
14
|
+
var CustomTbody = function CustomTbody(props) {
|
|
15
|
+
return /*#__PURE__*/React.createElement("tbody", {
|
|
16
|
+
className: props.className,
|
|
17
|
+
"data-custom-tbody": true
|
|
18
|
+
}, props.children);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// 整行接管:消费方渲染整 <tr> + 单元格,可在此放拖拽手柄等任意内容。
|
|
22
|
+
var CustomRow = function CustomRow(_ref) {
|
|
23
|
+
var record = _ref.record,
|
|
24
|
+
index = _ref.index,
|
|
25
|
+
columns = _ref.columns,
|
|
26
|
+
rowKey = _ref.rowKey;
|
|
27
|
+
return /*#__PURE__*/React.createElement("tr", {
|
|
28
|
+
"data-row-key": rowKey,
|
|
29
|
+
style: {
|
|
30
|
+
background: index % 2 === 0 ? '#f8fafc' : undefined
|
|
31
|
+
}
|
|
32
|
+
}, /*#__PURE__*/React.createElement("td", {
|
|
33
|
+
style: {
|
|
34
|
+
width: 40,
|
|
35
|
+
textAlign: 'center',
|
|
36
|
+
color: '#2563eb',
|
|
37
|
+
fontWeight: 700
|
|
38
|
+
}
|
|
39
|
+
}, index + 1), columns.map(function (col) {
|
|
40
|
+
return /*#__PURE__*/React.createElement("td", {
|
|
41
|
+
key: String(col.key)
|
|
42
|
+
}, record[col.dataIndex || '']);
|
|
43
|
+
}));
|
|
44
|
+
};
|
|
45
|
+
export default (function () {
|
|
46
|
+
var columns = [{
|
|
47
|
+
title: 'Name',
|
|
48
|
+
dataIndex: 'name',
|
|
49
|
+
key: 'name'
|
|
50
|
+
}, {
|
|
51
|
+
title: 'Age',
|
|
52
|
+
dataIndex: 'age',
|
|
53
|
+
key: 'age'
|
|
54
|
+
}, {
|
|
55
|
+
title: 'Address',
|
|
56
|
+
dataIndex: 'address',
|
|
57
|
+
key: 'address'
|
|
58
|
+
}];
|
|
59
|
+
var dataSource = [{
|
|
60
|
+
key: '1',
|
|
61
|
+
name: 'John Brown',
|
|
62
|
+
age: 32,
|
|
63
|
+
address: 'New York No. 1 Lake Park'
|
|
64
|
+
}, {
|
|
65
|
+
key: '2',
|
|
66
|
+
name: 'Jim Green',
|
|
67
|
+
age: 42,
|
|
68
|
+
address: 'London No. 1 Lake Park'
|
|
69
|
+
}, {
|
|
70
|
+
key: '3',
|
|
71
|
+
name: 'Joe Black',
|
|
72
|
+
age: 32,
|
|
73
|
+
address: 'Sidney No. 1 Lake Park'
|
|
74
|
+
}];
|
|
75
|
+
var components = {
|
|
76
|
+
body: {
|
|
77
|
+
tbody: CustomTbody,
|
|
78
|
+
row: CustomRow
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
return /*#__PURE__*/React.createElement(Table, {
|
|
82
|
+
columns: columns,
|
|
83
|
+
dataSource: dataSource,
|
|
84
|
+
components: components
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import { Table } from "../..";
|
|
8
|
+
import React, { useState } from 'react';
|
|
9
|
+
export default (function () {
|
|
10
|
+
var _useState = useState([]),
|
|
11
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
12
|
+
selectedRowKeys = _useState2[0],
|
|
13
|
+
setSelectedRowKeys = _useState2[1];
|
|
14
|
+
var columns = [{
|
|
15
|
+
title: 'Name',
|
|
16
|
+
dataIndex: 'name',
|
|
17
|
+
key: 'name',
|
|
18
|
+
fixed: 'left',
|
|
19
|
+
width: 120,
|
|
20
|
+
sorter: true
|
|
21
|
+
}, {
|
|
22
|
+
title: 'Info',
|
|
23
|
+
key: 'info',
|
|
24
|
+
children: [{
|
|
25
|
+
title: 'Age',
|
|
26
|
+
dataIndex: 'age',
|
|
27
|
+
key: 'age',
|
|
28
|
+
width: 100,
|
|
29
|
+
sorter: true
|
|
30
|
+
}, {
|
|
31
|
+
title: 'Address',
|
|
32
|
+
dataIndex: 'address',
|
|
33
|
+
key: 'address',
|
|
34
|
+
width: 200
|
|
35
|
+
}]
|
|
36
|
+
}, {
|
|
37
|
+
title: 'Company',
|
|
38
|
+
key: 'company',
|
|
39
|
+
children: [{
|
|
40
|
+
title: 'Name',
|
|
41
|
+
dataIndex: 'companyName',
|
|
42
|
+
key: 'companyName',
|
|
43
|
+
width: 180
|
|
44
|
+
}, {
|
|
45
|
+
title: 'Address',
|
|
46
|
+
dataIndex: 'companyAddress',
|
|
47
|
+
key: 'companyAddress',
|
|
48
|
+
width: 220
|
|
49
|
+
}]
|
|
50
|
+
}, {
|
|
51
|
+
title: 'Action',
|
|
52
|
+
key: 'action',
|
|
53
|
+
fixed: 'right',
|
|
54
|
+
width: 100,
|
|
55
|
+
render: function render(record) {
|
|
56
|
+
return /*#__PURE__*/React.createElement("a", {
|
|
57
|
+
onClick: function onClick() {
|
|
58
|
+
return console.log(record);
|
|
59
|
+
}
|
|
60
|
+
}, "Edit");
|
|
61
|
+
}
|
|
62
|
+
}];
|
|
63
|
+
var dataSource = [{
|
|
64
|
+
key: '1',
|
|
65
|
+
name: 'John Brown',
|
|
66
|
+
age: 32,
|
|
67
|
+
address: 'New York No. 1 Lake Park',
|
|
68
|
+
companyName: 'Acme Inc.',
|
|
69
|
+
companyAddress: 'NY Office'
|
|
70
|
+
}, {
|
|
71
|
+
key: '2',
|
|
72
|
+
name: 'Jim Green',
|
|
73
|
+
age: 42,
|
|
74
|
+
address: 'London No. 1 Lake Park',
|
|
75
|
+
companyName: 'Globex',
|
|
76
|
+
companyAddress: 'London Office'
|
|
77
|
+
}, {
|
|
78
|
+
key: '3',
|
|
79
|
+
name: 'Joe Black',
|
|
80
|
+
age: 28,
|
|
81
|
+
address: 'Sidney No. 1 Lake Park',
|
|
82
|
+
companyName: 'Initech',
|
|
83
|
+
companyAddress: 'Sidney Office'
|
|
84
|
+
}];
|
|
85
|
+
var rowSelection = {
|
|
86
|
+
type: 'checkbox',
|
|
87
|
+
selectedRowKeys: selectedRowKeys,
|
|
88
|
+
onChange: function onChange(keys) {
|
|
89
|
+
return setSelectedRowKeys(keys);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
return /*#__PURE__*/React.createElement(Table, {
|
|
93
|
+
columns: columns,
|
|
94
|
+
dataSource: dataSource,
|
|
95
|
+
rowKey: "key",
|
|
96
|
+
rowSelection: rowSelection,
|
|
97
|
+
bordered: true,
|
|
98
|
+
scroll: {
|
|
99
|
+
x: 1200
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { ColumnProps, ExpandableType, RowSelectionType } from '../interface';
|
|
2
|
+
import type { ColumnProps, ExpandableType, RowSelectionType } from '../interface';
|
|
3
3
|
export default function useColumns({ children, columns, rowSelection, expandable, }: {
|
|
4
4
|
children?: React.ReactElement<ColumnProps> | React.ReactElement<ColumnProps>[];
|
|
5
5
|
columns: ColumnProps[];
|
|
@@ -7,5 +7,5 @@ export default function useColumns({ children, columns, rowSelection, expandable
|
|
|
7
7
|
expandable?: ExpandableType;
|
|
8
8
|
}): {
|
|
9
9
|
wrapedColumns: any;
|
|
10
|
-
|
|
10
|
+
headerRows: any;
|
|
11
11
|
};
|
|
@@ -8,6 +8,7 @@ import React, { useMemo } from 'react';
|
|
|
8
8
|
import useDeepCompareMemo from "../../hooks/useDeepCompareMemo";
|
|
9
9
|
import deepClone from "../../utils/deepClone";
|
|
10
10
|
import { handleColumns } from "../util";
|
|
11
|
+
import { flattenLeafColumns, injectSelectionExpand, parseHeaderRows } from "../util/header";
|
|
11
12
|
export default function useColumns(_ref) {
|
|
12
13
|
var children = _ref.children,
|
|
13
14
|
columns = _ref.columns,
|
|
@@ -15,64 +16,37 @@ export default function useColumns(_ref) {
|
|
|
15
16
|
expandable = _ref.expandable;
|
|
16
17
|
var shouldRenderSelection = !!rowSelection;
|
|
17
18
|
var shouldRenderExpand = !!expandable;
|
|
18
|
-
var getColumnsFromChild = function getColumnsFromChild(
|
|
19
|
-
var
|
|
20
|
-
React.Children.forEach(
|
|
19
|
+
var getColumnsFromChild = function getColumnsFromChild(childs) {
|
|
20
|
+
var cols = [];
|
|
21
|
+
React.Children.forEach(childs, function (child) {
|
|
21
22
|
if (child) {
|
|
22
|
-
|
|
23
|
+
cols.push(_objectSpread({}, child.props));
|
|
23
24
|
}
|
|
24
25
|
});
|
|
25
|
-
return
|
|
26
|
+
return cols.length ? cols : null;
|
|
26
27
|
};
|
|
27
28
|
var childColumns = useMemo(function () {
|
|
28
29
|
return children ? getColumnsFromChild(children) : null;
|
|
29
30
|
}, [children]);
|
|
30
31
|
|
|
31
|
-
//
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
var
|
|
36
|
-
|
|
37
|
-
var
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
_expandable$visible = expandable.visible,
|
|
48
|
-
visible = _expandable$visible === void 0 ? true : _expandable$visible;
|
|
49
|
-
var _loc = _index ? _index - 1 : rowSelection ? 1 : 0;
|
|
50
|
-
if (visible !== false) {
|
|
51
|
-
result.splice(_loc, 0, _objectSpread(_objectSpread({
|
|
52
|
-
width: 50
|
|
53
|
-
}, expandable), {}, {
|
|
54
|
-
key: 'YEE_EXPAND_COL'
|
|
55
|
-
}));
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
result = handleColumns(result);
|
|
59
|
-
return result;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
// const [mergedColumns, setMergedColumns] = React.useState(
|
|
63
|
-
// wrapColumns(childColumns || columns || []),
|
|
64
|
-
// );
|
|
65
|
-
|
|
66
|
-
// useDeepCompareEffect(() => {
|
|
67
|
-
// const merged = wrapColumns(childColumns || columns || []);
|
|
68
|
-
// setMergedColumns(merged);
|
|
69
|
-
// }, [childColumns, columns, shouldRenderSelection, shouldRenderExpand]);
|
|
70
|
-
|
|
71
|
-
var mergedColumns = useDeepCompareMemo(function () {
|
|
72
|
-
return wrapColumns(childColumns || columns || []);
|
|
73
|
-
}, [childColumns, columns, shouldRenderSelection, shouldRenderExpand]);
|
|
32
|
+
// Build the column tree (with selection/expand injected at the top level),
|
|
33
|
+
// then derive both the flat leaf columns (body/colgroup/summary/sorter) and
|
|
34
|
+
// the 2D header rows (thead multi-level rendering).
|
|
35
|
+
var _useDeepCompareMemo = useDeepCompareMemo(function () {
|
|
36
|
+
var base = deepClone(childColumns || columns || []) || [];
|
|
37
|
+
var tree = injectSelectionExpand(base, rowSelection, expandable);
|
|
38
|
+
var leaves = flattenLeafColumns(tree);
|
|
39
|
+
var wraped = handleColumns(leaves);
|
|
40
|
+
var rows = parseHeaderRows(tree);
|
|
41
|
+
return {
|
|
42
|
+
wrapedColumns: wraped,
|
|
43
|
+
headerRows: rows
|
|
44
|
+
};
|
|
45
|
+
}, [childColumns, columns, shouldRenderSelection, shouldRenderExpand]),
|
|
46
|
+
wrapedColumns = _useDeepCompareMemo.wrapedColumns,
|
|
47
|
+
headerRows = _useDeepCompareMemo.headerRows;
|
|
74
48
|
return {
|
|
75
|
-
wrapedColumns:
|
|
76
|
-
|
|
49
|
+
wrapedColumns: wrapedColumns,
|
|
50
|
+
headerRows: headerRows
|
|
77
51
|
};
|
|
78
52
|
}
|
|
@@ -2,7 +2,7 @@ import Column from './column';
|
|
|
2
2
|
import Summary from './summary';
|
|
3
3
|
import InternalTable from './table';
|
|
4
4
|
import Head from './theader';
|
|
5
|
-
export type { ColumnProps, PaginationType, RowSelectionType, TableProps, onChangeParams, } from './interface';
|
|
5
|
+
export type { ColumnProps, PaginationType, RowSelectionType, TableProps, TableComponents, TableBodyComponents, TableRowRendererProps, HeaderCell, onChangeParams, } from './interface';
|
|
6
6
|
type TableType = typeof InternalTable & {
|
|
7
7
|
Column: typeof Column;
|
|
8
8
|
Summary: typeof Summary;
|