es-grid-template 0.0.13 → 0.1.1
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/CHANGELOG.md +6 -6
- package/README.md +1 -1
- package/es/grid-component/ColumnsChoose.d.ts +3 -4
- package/es/grid-component/ColumnsChoose.js +3 -7
- package/es/grid-component/Command.d.ts +8 -0
- package/es/grid-component/Command.js +80 -0
- package/es/grid-component/EditableCell.js +56 -87
- package/es/grid-component/InternalTable.d.ts +1 -0
- package/es/grid-component/InternalTable.js +36 -19
- package/es/grid-component/TableGrid.d.ts +2 -1
- package/es/grid-component/TableGrid.js +63 -18
- package/es/grid-component/index.d.ts +2 -0
- package/es/{table-grid → grid-component}/styles.scss +204 -195
- package/es/grid-component/table/Grid.js +85 -0
- package/{lib/grid-component/rc-table → es/grid-component/table}/GridEdit.d.ts +4 -0
- package/es/grid-component/{rc-table → table}/GridEdit.js +98 -15
- package/es/grid-component/type.d.ts +26 -11
- package/es/grid-component/useContext.d.ts +10 -7
- package/es/grid-component/useContext.js +3 -0
- package/es/index.d.ts +2 -1
- package/es/index.js +1 -2
- package/lib/grid-component/ColumnsChoose.d.ts +3 -4
- package/lib/grid-component/ColumnsChoose.js +3 -7
- package/lib/grid-component/Command.d.ts +8 -0
- package/lib/grid-component/Command.js +88 -0
- package/lib/grid-component/EditableCell.js +56 -87
- package/lib/grid-component/InternalTable.d.ts +1 -0
- package/lib/grid-component/InternalTable.js +35 -18
- package/lib/grid-component/TableGrid.d.ts +2 -1
- package/lib/grid-component/TableGrid.js +62 -17
- package/lib/grid-component/index.d.ts +2 -0
- package/lib/{table-grid → grid-component}/styles.scss +204 -195
- package/lib/grid-component/{rc-table → table}/Grid.js +42 -56
- package/{es/grid-component/rc-table → lib/grid-component/table}/GridEdit.d.ts +4 -0
- package/lib/grid-component/{rc-table → table}/GridEdit.js +98 -15
- package/lib/grid-component/type.d.ts +26 -11
- package/lib/grid-component/useContext.d.ts +10 -7
- package/lib/grid-component/useContext.js +2 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +1 -1
- package/package.json +113 -86
- package/es/grid-component/rc-table/Grid.js +0 -99
- /package/es/{grid-component/Message → Message}/Message.d.ts +0 -0
- /package/es/{grid-component/Message → Message}/Message.js +0 -0
- /package/es/{grid-component/Message → Message}/index.d.ts +0 -0
- /package/es/{grid-component/Message → Message}/index.js +0 -0
- /package/es/grid-component/{rc-table → table}/Grid.d.ts +0 -0
- /package/lib/{grid-component/Message → Message}/Message.d.ts +0 -0
- /package/lib/{grid-component/Message → Message}/Message.js +0 -0
- /package/lib/{grid-component/Message → Message}/index.d.ts +0 -0
- /package/lib/{grid-component/Message → Message}/index.js +0 -0
- /package/lib/grid-component/{rc-table → table}/Grid.d.ts +0 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import React, { Fragment, useMemo } from 'react';
|
|
3
|
+
import { GridStyle } from "../GridStyle";
|
|
4
|
+
import TableGrid from "../TableGrid";
|
|
5
|
+
import EditableCell from "../EditableCell";
|
|
6
|
+
import Command from "../Command";
|
|
7
|
+
const Grid = props => {
|
|
8
|
+
const {
|
|
9
|
+
columns,
|
|
10
|
+
height,
|
|
11
|
+
tableRef,
|
|
12
|
+
className,
|
|
13
|
+
components,
|
|
14
|
+
style,
|
|
15
|
+
...rest
|
|
16
|
+
} = props;
|
|
17
|
+
const transformColumns = React.useCallback(cols => {
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
return cols.map(column => {
|
|
20
|
+
if (!column?.field && !column?.key) {
|
|
21
|
+
return column;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Xử lý đệ quy cho children
|
|
25
|
+
if (column.children?.length) {
|
|
26
|
+
return {
|
|
27
|
+
...column,
|
|
28
|
+
children: transformColumns(column.children)
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const transformedColumn = {
|
|
32
|
+
...column,
|
|
33
|
+
dataIndex: column.field ?? column.dataIndex,
|
|
34
|
+
title: column.headerText ?? column.title,
|
|
35
|
+
ellipsis: column.ellipsis !== false,
|
|
36
|
+
align: column.textAlign ?? column.align,
|
|
37
|
+
fixed: column.frozen ? column.frozen.toLowerCase() : column.fixed
|
|
38
|
+
};
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
if (["index", "#"].includes(transformedColumn.dataIndex)) {
|
|
41
|
+
return {
|
|
42
|
+
...transformedColumn,
|
|
43
|
+
render: (_, __, rowIndex) => rowIndex + 1
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if (transformedColumn.dataIndex === "command") {
|
|
47
|
+
return {
|
|
48
|
+
...transformedColumn,
|
|
49
|
+
onCell: () => ({
|
|
50
|
+
className: "ui-rc-cell-command"
|
|
51
|
+
}),
|
|
52
|
+
render: () => /*#__PURE__*/React.createElement("div", {
|
|
53
|
+
className: "ui-rc-cell-command__content"
|
|
54
|
+
}, column.commandItems?.map((item, index) => item.visible !== false ? /*#__PURE__*/React.createElement(Command, {
|
|
55
|
+
key: `command-${index}`,
|
|
56
|
+
item: item,
|
|
57
|
+
onClick: e => e.preventDefault()
|
|
58
|
+
}) : null))
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return transformedColumn;
|
|
62
|
+
});
|
|
63
|
+
}, []);
|
|
64
|
+
const mergedColumns = useMemo(() => transformColumns(columns ?? []), [transformColumns, columns]);
|
|
65
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(GridStyle, {
|
|
66
|
+
heightTable: height,
|
|
67
|
+
style: {
|
|
68
|
+
position: 'relative'
|
|
69
|
+
}
|
|
70
|
+
}, /*#__PURE__*/React.createElement(TableGrid, _extends({}, rest, {
|
|
71
|
+
tableRef: tableRef,
|
|
72
|
+
components: {
|
|
73
|
+
...components,
|
|
74
|
+
body: {
|
|
75
|
+
cell: EditableCell
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
columns: mergedColumns,
|
|
79
|
+
style: {
|
|
80
|
+
...style,
|
|
81
|
+
minHeight: height
|
|
82
|
+
}
|
|
83
|
+
}))));
|
|
84
|
+
};
|
|
85
|
+
export default Grid;
|
|
@@ -2,8 +2,12 @@ import React from 'react';
|
|
|
2
2
|
import 'dayjs/locale/es';
|
|
3
3
|
import 'dayjs/locale/vi';
|
|
4
4
|
import type { TableEditProps } from "../type";
|
|
5
|
+
import type { GetRowKey } from "../type";
|
|
5
6
|
type Props<RecordType> = TableEditProps<RecordType> & {
|
|
6
7
|
tableRef: any;
|
|
8
|
+
triggerChangeColumns?: () => void;
|
|
9
|
+
triggerChangeData?: () => void;
|
|
10
|
+
getRowKey: GetRowKey<RecordType>;
|
|
7
11
|
};
|
|
8
12
|
declare const GridEdit: <RecordType extends object>(props: Props<RecordType>) => React.JSX.Element;
|
|
9
13
|
export default GridEdit;
|
|
@@ -14,7 +14,8 @@ import 'dayjs/locale/es';
|
|
|
14
14
|
import 'dayjs/locale/vi';
|
|
15
15
|
import TableGrid from "../TableGrid";
|
|
16
16
|
import { getEditType, isObjEmpty, totalFixedWidth } from "../hooks";
|
|
17
|
-
import Message from "
|
|
17
|
+
import Message from "../../Message/Message";
|
|
18
|
+
import Command from "../Command";
|
|
18
19
|
dayjs.extend(customParseFormat);
|
|
19
20
|
const toast = 'top-right';
|
|
20
21
|
const GridEdit = props => {
|
|
@@ -23,6 +24,7 @@ const GridEdit = props => {
|
|
|
23
24
|
t,
|
|
24
25
|
columns,
|
|
25
26
|
dataSource,
|
|
27
|
+
components,
|
|
26
28
|
allowResizing,
|
|
27
29
|
rowKey = 'id',
|
|
28
30
|
selectionSettings,
|
|
@@ -31,9 +33,13 @@ const GridEdit = props => {
|
|
|
31
33
|
onDataChange,
|
|
32
34
|
onCellPaste,
|
|
33
35
|
onCellChange,
|
|
34
|
-
|
|
36
|
+
style,
|
|
37
|
+
getRowKey,
|
|
35
38
|
...rest
|
|
36
39
|
} = props;
|
|
40
|
+
|
|
41
|
+
// const forceUpdate = useForceUpdate();
|
|
42
|
+
const [updateKey, setUpdateKey] = useState(0);
|
|
37
43
|
const isSelecting = useRef(false);
|
|
38
44
|
const startCell = useRef(null);
|
|
39
45
|
const isSelectingRow = useRef(false);
|
|
@@ -116,6 +122,30 @@ const GridEdit = props => {
|
|
|
116
122
|
}
|
|
117
123
|
setSelectedCells(newSelectedCells);
|
|
118
124
|
};
|
|
125
|
+
const handleClickRowHeader = (row, col) => {
|
|
126
|
+
const newSelectedCells = new Set();
|
|
127
|
+
for (let r = Math.min(row, row); r <= Math.max(row, row); r++) {
|
|
128
|
+
for (let c = Math.min(columns.length, col) + 1; c <= Math.max(columns.length, col); c++) {
|
|
129
|
+
newSelectedCells.add(`${r}-${c}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
setSelectedCells(newSelectedCells);
|
|
133
|
+
};
|
|
134
|
+
const handleClickColHeader = (column, indexColumn) => {
|
|
135
|
+
const newSelectedCells = new Set();
|
|
136
|
+
for (let r = Math.min(dataSource.length, 0); r <= Math.max(dataSource.length - 1, 0); r++) {
|
|
137
|
+
for (let c = Math.min(indexColumn, indexColumn); c <= Math.max(indexColumn, indexColumn); c++) {
|
|
138
|
+
newSelectedCells.add(`${r}-${c}`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// console.log('newSelectedCells', newSelectedCells)
|
|
143
|
+
// setSelectedCells(newSelectedCells)
|
|
144
|
+
|
|
145
|
+
setSelectedCells(new Set(newSelectedCells));
|
|
146
|
+
// forceUpdate();
|
|
147
|
+
setUpdateKey(prev => prev + 1); // Cập nhật key để trigger re-render
|
|
148
|
+
};
|
|
119
149
|
const handleMouseDownColIndex = (row, col, e) => {
|
|
120
150
|
if (e.button === 2) {
|
|
121
151
|
e.stopPropagation();
|
|
@@ -338,15 +368,15 @@ const GridEdit = props => {
|
|
|
338
368
|
record,
|
|
339
369
|
type,
|
|
340
370
|
newState,
|
|
341
|
-
prevState
|
|
371
|
+
prevState,
|
|
372
|
+
option
|
|
342
373
|
} = args;
|
|
343
374
|
|
|
344
375
|
// console.log('newState', newState)
|
|
345
376
|
//
|
|
346
377
|
// console.log('getValues()', getValues())
|
|
347
378
|
|
|
348
|
-
|
|
349
|
-
|
|
379
|
+
const newRecord = getValues();
|
|
350
380
|
if (type === 'enter') {
|
|
351
381
|
console.log('aaaaaa enter');
|
|
352
382
|
}
|
|
@@ -357,7 +387,16 @@ const GridEdit = props => {
|
|
|
357
387
|
// const newDataUpdate = updateData(data, callbackData, rowKey as any)
|
|
358
388
|
|
|
359
389
|
console.log('callbackData', callbackData);
|
|
360
|
-
const
|
|
390
|
+
const callbackRecord = callbackData;
|
|
391
|
+
Object.entries(callbackRecord).forEach(([name, value]) => {
|
|
392
|
+
setValue(name, value);
|
|
393
|
+
|
|
394
|
+
// if (listObjectDate.includes(name) && value) {
|
|
395
|
+
// setValue(name, new Date(value))
|
|
396
|
+
// } else {
|
|
397
|
+
// setValue(name, value)
|
|
398
|
+
// }
|
|
399
|
+
});
|
|
361
400
|
onSubmit(newRecord);
|
|
362
401
|
};
|
|
363
402
|
if (onCellChange) {
|
|
@@ -367,8 +406,8 @@ const GridEdit = props => {
|
|
|
367
406
|
field: '',
|
|
368
407
|
indexCol: 1,
|
|
369
408
|
type: 'onChange',
|
|
370
|
-
rows: [],
|
|
371
409
|
value: newState,
|
|
410
|
+
option,
|
|
372
411
|
indexRow: 1,
|
|
373
412
|
rowData: record,
|
|
374
413
|
rowId: '',
|
|
@@ -376,12 +415,14 @@ const GridEdit = props => {
|
|
|
376
415
|
sumValue: []
|
|
377
416
|
}, handleChangeCallback);
|
|
378
417
|
} else {
|
|
418
|
+
// const aaaa = updateData(dataSource, newRecord, rowKey as any)
|
|
419
|
+
|
|
379
420
|
console.log('onCellChange');
|
|
380
421
|
onCellChange({
|
|
381
422
|
field: '',
|
|
382
423
|
indexCol: 1,
|
|
383
424
|
type: 'onChange',
|
|
384
|
-
|
|
425
|
+
option,
|
|
385
426
|
value: newState,
|
|
386
427
|
indexRow: 1,
|
|
387
428
|
rowData: record,
|
|
@@ -546,6 +587,7 @@ const GridEdit = props => {
|
|
|
546
587
|
if (col.dataIndex === 'index' || col.field === 'index' || col.dataIndex === '#' || col.dataIndex === '#') {
|
|
547
588
|
return {
|
|
548
589
|
...col,
|
|
590
|
+
className: 'rc-ui-cell-editable',
|
|
549
591
|
render: (value, record, rowIndex) => {
|
|
550
592
|
return /*#__PURE__*/React.createElement("div", {
|
|
551
593
|
className: classNames('ui-rc_cell-content ui-rc_cell-content--index', {
|
|
@@ -553,13 +595,45 @@ const GridEdit = props => {
|
|
|
553
595
|
focus: selectedCells && Array.from(selectedCells).some(item => item.startsWith(`${rowIndex}-`))
|
|
554
596
|
}),
|
|
555
597
|
onMouseDown: event => handleMouseDownColIndex(rowIndex, colIndex, event),
|
|
556
|
-
onMouseEnter: event => handleMouseEnterColIndex(rowIndex, colIndex, event)
|
|
598
|
+
onMouseEnter: event => handleMouseEnterColIndex(rowIndex, colIndex, event),
|
|
599
|
+
onClick: () => handleClickRowHeader(rowIndex, colIndex)
|
|
557
600
|
}, /*#__PURE__*/React.createElement("div", {
|
|
558
601
|
className: 'ui-rc_content'
|
|
559
602
|
}, rowIndex + 1));
|
|
560
603
|
}
|
|
561
604
|
};
|
|
562
605
|
}
|
|
606
|
+
if (col.dataIndex === 'command' || col.field === 'command') {
|
|
607
|
+
return {
|
|
608
|
+
...col,
|
|
609
|
+
title: col.headerText ?? col.title,
|
|
610
|
+
ellipsis: col.ellipsis !== false,
|
|
611
|
+
onCell: () => ({
|
|
612
|
+
className: 'ui-rc-cell-command'
|
|
613
|
+
}),
|
|
614
|
+
// render: (value: any, record: any, rowIndex: number) => {
|
|
615
|
+
render: () => {
|
|
616
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
617
|
+
className: classNames('ui-rc-cell-command__content', {})
|
|
618
|
+
}, col.commandItems && col.commandItems?.map((item, indexComm) => {
|
|
619
|
+
if (item.visible !== false) {
|
|
620
|
+
// return (
|
|
621
|
+
// <span>{item.title}</span>
|
|
622
|
+
// )
|
|
623
|
+
|
|
624
|
+
return /*#__PURE__*/React.createElement(Command, {
|
|
625
|
+
key: `command-${indexComm}`,
|
|
626
|
+
item: item,
|
|
627
|
+
onClick: e => {
|
|
628
|
+
e.preventDefault();
|
|
629
|
+
// handleCommandClick({command: item, rowData: record, index: rowIndex})
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
}));
|
|
634
|
+
}
|
|
635
|
+
};
|
|
636
|
+
}
|
|
563
637
|
return {
|
|
564
638
|
...col,
|
|
565
639
|
onCell: (record, rowIndex) => ({
|
|
@@ -624,7 +698,7 @@ const GridEdit = props => {
|
|
|
624
698
|
setEditingKey('');
|
|
625
699
|
}
|
|
626
700
|
},
|
|
627
|
-
className: isEditing(record) ? 'cell-editing' : 'cell-editable',
|
|
701
|
+
className: isEditing(record) ? 'rc-ui-cell-editable cell-editing' : 'rc-ui-cell-editable cell-editable',
|
|
628
702
|
record,
|
|
629
703
|
column: col,
|
|
630
704
|
editType: getEditType(col, record),
|
|
@@ -632,20 +706,25 @@ const GridEdit = props => {
|
|
|
632
706
|
title: col.title,
|
|
633
707
|
'data-col-index': colIndex,
|
|
634
708
|
'data-row-index': rowIndex,
|
|
635
|
-
colIndex: colIndex,
|
|
709
|
+
// colIndex: colIndex,
|
|
636
710
|
indexCol: colIndex,
|
|
637
711
|
indexRow: rowIndex,
|
|
638
712
|
editing: isEditing(record),
|
|
639
713
|
tabIndex: (rowIndex ?? 0) * columns.length + colIndex
|
|
640
714
|
}),
|
|
715
|
+
onHeaderCell: data => ({
|
|
716
|
+
...col.onHeaderCell(),
|
|
717
|
+
onClick: () => {
|
|
718
|
+
handleClickColHeader(data, colIndex);
|
|
719
|
+
}
|
|
720
|
+
}),
|
|
641
721
|
render: (value, record, rowIndex) => {
|
|
642
722
|
return /*#__PURE__*/React.createElement("div", {
|
|
643
723
|
className: classNames('ui-rc_cell-content', {
|
|
644
724
|
selected: selectedCells.has(`${rowIndex}-${colIndex}`)
|
|
645
725
|
}),
|
|
646
726
|
onMouseDown: event => handleMouseDown(rowIndex, colIndex, event),
|
|
647
|
-
onMouseEnter: () => handleMouseEnter(rowIndex, colIndex)
|
|
648
|
-
onMouseLeave: () => {}
|
|
727
|
+
onMouseEnter: () => handleMouseEnter(rowIndex, colIndex)
|
|
649
728
|
}, /*#__PURE__*/React.createElement("div", {
|
|
650
729
|
className: 'ui-rc_content'
|
|
651
730
|
}, renderContent(col, value, record, rowIndex)));
|
|
@@ -668,12 +747,14 @@ const GridEdit = props => {
|
|
|
668
747
|
control,
|
|
669
748
|
trigger,
|
|
670
749
|
getValues,
|
|
671
|
-
handleCellChange
|
|
750
|
+
handleCellChange,
|
|
751
|
+
getRowKey
|
|
672
752
|
}
|
|
673
753
|
}, /*#__PURE__*/React.createElement("form", {
|
|
674
754
|
onSubmit: handleSubmit(onSubmit)
|
|
675
755
|
}, /*#__PURE__*/React.createElement(TableGrid, _extends({}, rest, {
|
|
676
756
|
t: t,
|
|
757
|
+
key: updateKey,
|
|
677
758
|
tableRef: tableRef,
|
|
678
759
|
dataSource: dataSource,
|
|
679
760
|
components: {
|
|
@@ -694,8 +775,10 @@ const GridEdit = props => {
|
|
|
694
775
|
checkboxOnly: true
|
|
695
776
|
} : undefined,
|
|
696
777
|
style: {
|
|
778
|
+
...style,
|
|
697
779
|
minHeight: height
|
|
698
|
-
}
|
|
780
|
+
},
|
|
781
|
+
rowHoverable: false
|
|
699
782
|
}))))), /*#__PURE__*/React.createElement(Toaster, {
|
|
700
783
|
position: toast,
|
|
701
784
|
toastOptions: {
|
|
@@ -10,6 +10,7 @@ export type IColumnType = "number" | "time" | "date" | "week" | "month" | "file"
|
|
|
10
10
|
export type AnyObject = Record<PropertyKey, any>;
|
|
11
11
|
export type SelectMode = 'checkbox' | 'radio' | undefined;
|
|
12
12
|
export type ITextAlign = 'center' | 'left' | 'right';
|
|
13
|
+
export type Frozen = 'left' | 'right' | 'Left' | 'Right';
|
|
13
14
|
export type ITemplateColumn = {
|
|
14
15
|
value: any;
|
|
15
16
|
column: any;
|
|
@@ -39,6 +40,7 @@ export type ColumnSelectTable = {
|
|
|
39
40
|
};
|
|
40
41
|
export type IEditSelectSettings = {
|
|
41
42
|
fieldKey?: string;
|
|
43
|
+
options: any[];
|
|
42
44
|
/** get value form other field **/
|
|
43
45
|
fieldValue?: string;
|
|
44
46
|
/** get label form other field **/
|
|
@@ -46,7 +48,6 @@ export type IEditSelectSettings = {
|
|
|
46
48
|
inputKey?: string;
|
|
47
49
|
filterKey?: string[];
|
|
48
50
|
selectMode?: SelectMode;
|
|
49
|
-
options: any[];
|
|
50
51
|
getPasteValue?: (value: any) => Record<string, any> | null;
|
|
51
52
|
validateOption?: (rowData: any, field: string) => any[];
|
|
52
53
|
defaultOptions?: any[];
|
|
@@ -84,14 +85,18 @@ export type ColumnType<RecordType> = Omit<RcColumnType<RecordType>, 'headerTempl
|
|
|
84
85
|
format?: IFormat;
|
|
85
86
|
allowFiltering?: boolean;
|
|
86
87
|
operator?: FilterOperator;
|
|
88
|
+
hideOperator?: boolean;
|
|
87
89
|
placeholder?: string;
|
|
88
90
|
showInColumnChoose?: boolean;
|
|
89
91
|
typeFilter?: TypeFilter;
|
|
90
92
|
headerText?: string;
|
|
93
|
+
textAlign?: ITextAlign;
|
|
94
|
+
frozen?: Frozen;
|
|
91
95
|
template?: ReactNode | ReactElement | ((value: any, record: RecordType, index: number) => ReactNode | ReactElement);
|
|
92
96
|
showTooltip?: boolean;
|
|
93
97
|
tooltipDescription?: ReactNode | ReactElement | ((value: any, record: RecordType, index: number) => ReactNode | ReactElement);
|
|
94
98
|
headerTemplate?: React.ReactNode | React.ReactElement | ((column: ColumnType<RecordType>) => React.ReactNode | React.ReactElement);
|
|
99
|
+
commandItems?: CommandItem[];
|
|
95
100
|
children?: ColumnType<RecordType>[];
|
|
96
101
|
};
|
|
97
102
|
export type ColumnEditType<RecordType> = ColumnType<RecordType> & {
|
|
@@ -140,7 +145,7 @@ export interface TableProps<RecordType> extends Omit<RcTableProps<RecordType>, '
|
|
|
140
145
|
direction: 'Ascending' | 'Descending' | null;
|
|
141
146
|
}) => void;
|
|
142
147
|
selectionSettings?: SelectionSettings;
|
|
143
|
-
rowKey?: string
|
|
148
|
+
rowKey?: string | keyof RecordType | GetRowKey<RecordType>;
|
|
144
149
|
rowSelection?: RowSelection<RecordType>;
|
|
145
150
|
rowSelected?: (args: {
|
|
146
151
|
type: string;
|
|
@@ -156,15 +161,27 @@ export interface TableProps<RecordType> extends Omit<RcTableProps<RecordType>, '
|
|
|
156
161
|
export interface TableEditProps<RecordType = AnyObject> extends Omit<TableProps<RecordType>, 'columns'> {
|
|
157
162
|
columns: ColumnsTable<RecordType>;
|
|
158
163
|
onCellPaste?: ICellPasteModel<RecordType>;
|
|
159
|
-
onCellChange?: (args: CellChangeArgs
|
|
164
|
+
onCellChange?: (args: CellChangeArgs<RecordType>, handleCallback: (rowData: any, index: any, value?: any) => void) => void;
|
|
160
165
|
}
|
|
161
166
|
export type GridTableProps<RecordType = AnyObject> = TableProps<RecordType> | TableEditProps<RecordType>;
|
|
162
|
-
export
|
|
167
|
+
export interface CommandItem {
|
|
168
|
+
id: string;
|
|
169
|
+
type?: string;
|
|
170
|
+
visible?: boolean;
|
|
171
|
+
title: string;
|
|
172
|
+
color?: 'blue' | 'purple' | 'cyan' | 'green' | 'magenta' | 'pink' | 'red' | 'orange' | 'yellow' | 'volcano' | 'geekblue' | 'lime' | 'gold';
|
|
173
|
+
tooltip?: string;
|
|
174
|
+
icon?: ReactNode | ReactElement | (() => ReactNode | ReactElement);
|
|
175
|
+
template?: ReactNode | ReactElement | (() => ReactNode | ReactElement);
|
|
176
|
+
client?: boolean;
|
|
177
|
+
confirmDialog?: boolean;
|
|
178
|
+
}
|
|
179
|
+
export type CellChangeArgs<T> = {
|
|
163
180
|
type: 'onPaste' | 'onChange' | 'onCellPaste';
|
|
164
181
|
value: any;
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
rowsData:
|
|
182
|
+
option: AnyObject;
|
|
183
|
+
rowData: T;
|
|
184
|
+
rowsData: T[];
|
|
168
185
|
indexRow: number;
|
|
169
186
|
rowId?: string;
|
|
170
187
|
field: string;
|
|
@@ -188,13 +205,10 @@ export type SourceFilter = {
|
|
|
188
205
|
loadOptions?: (search: string, callback: (newOptions: any[]) => void) => void;
|
|
189
206
|
};
|
|
190
207
|
export type RowSelection<RecordType> = Omit<TableRowSelection<RecordType>, 'type' | 'columnWidth' | 'hideSelectAll' | 'defaultSelectedRowKeys'>;
|
|
191
|
-
export type SelectionSettings = {
|
|
208
|
+
export type SelectionSettings = Omit<TableRowSelection, 'type' | 'onChange' | 'onSelect' | 'onSelectAll' | 'onSelectNone' | 'onSelectMultiple'> & {
|
|
192
209
|
mode?: 'checkbox' | 'radio';
|
|
193
210
|
type?: 'single' | 'multiple';
|
|
194
211
|
checkboxOnly?: boolean;
|
|
195
|
-
hideSelectAll?: boolean;
|
|
196
|
-
columnWidth?: number | string;
|
|
197
|
-
defaultSelectedRowKeys?: Key[];
|
|
198
212
|
};
|
|
199
213
|
export type RecordDoubleClickEventArgs<RecordType> = {
|
|
200
214
|
rowData: RecordType;
|
|
@@ -223,3 +237,4 @@ export type IFormat = {
|
|
|
223
237
|
monthFormat?: string;
|
|
224
238
|
yearFormat?: string;
|
|
225
239
|
};
|
|
240
|
+
export type GetRowKey<RecordType> = (record: RecordType, index?: number) => Key;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type { IFormat } from "./type";
|
|
2
|
+
import type { AnyObject, IFormat } from "./type";
|
|
3
3
|
import type { SubmitHandler } from "react-hook-form";
|
|
4
|
-
|
|
4
|
+
import type { GetRowKey } from "./type";
|
|
5
|
+
export interface IContext<RecordType> {
|
|
5
6
|
searchValue?: any;
|
|
6
7
|
setSearchValue?: any;
|
|
7
8
|
open?: boolean;
|
|
8
9
|
setOpen?: any;
|
|
9
|
-
rowKey: string
|
|
10
|
+
rowKey: string | keyof RecordType | GetRowKey<RecordType>;
|
|
10
11
|
onSave?: any;
|
|
11
12
|
form?: any;
|
|
12
13
|
format?: IFormat;
|
|
@@ -15,13 +16,15 @@ export interface IContext {
|
|
|
15
16
|
handleSubmit?: any;
|
|
16
17
|
onSubmit?: SubmitHandler<any>;
|
|
17
18
|
getValues?: any;
|
|
18
|
-
handleCellChange?: ({ key, record, type }: ContextCellChange) => void;
|
|
19
|
+
handleCellChange?: ({ key, record, type, option }: ContextCellChange<RecordType>) => void;
|
|
20
|
+
getRowKey?: GetRowKey<RecordType>;
|
|
19
21
|
}
|
|
20
|
-
export type ContextCellChange = {
|
|
21
|
-
key: string
|
|
22
|
+
export type ContextCellChange<RecordType = AnyObject> = {
|
|
23
|
+
key: string | keyof RecordType | GetRowKey<RecordType>;
|
|
22
24
|
record: any;
|
|
25
|
+
option: any;
|
|
23
26
|
newState?: any;
|
|
24
27
|
prevState?: any;
|
|
25
28
|
type: 'enter' | 'blur' | 'outClick';
|
|
26
29
|
};
|
|
27
|
-
export declare const TableContext: import("react").Context<IContext
|
|
30
|
+
export declare const TableContext: import("react").Context<IContext<any>>;
|
package/es/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { default as
|
|
1
|
+
export { default as GridComponent } from './grid-component';
|
|
2
|
+
export type { ColumnsTable, TableProps, ColumnTable } from './grid-component';
|
package/es/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export { default as
|
|
2
|
-
// export type { CheckboxOptionType, CheckboxProps, CheckboxRef } from './checkbox';
|
|
1
|
+
export { default as GridComponent } from "./grid-component";
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import type { Dispatch, SetStateAction } from "react";
|
|
2
1
|
import React from "react";
|
|
3
|
-
import type {
|
|
2
|
+
import type { ColumnsTable } from "./type";
|
|
4
3
|
export type IColumnsChoose<RecordType> = {
|
|
5
|
-
columns:
|
|
6
|
-
|
|
4
|
+
columns: ColumnsTable<RecordType>;
|
|
5
|
+
triggerChangeColumns?: (columns: ColumnsTable<RecordType>) => void;
|
|
7
6
|
t?: any;
|
|
8
7
|
};
|
|
9
8
|
export declare const ColumnsChoose: <RecordType extends object>(props: IColumnsChoose<RecordType>) => React.JSX.Element;
|
|
@@ -14,10 +14,6 @@ var _tree = _interopRequireDefault(require("rc-master-ui/es/tree"));
|
|
|
14
14
|
var _SearchOutlined = _interopRequireDefault(require("@ant-design/icons/SearchOutlined"));
|
|
15
15
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
16
16
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
17
|
-
// import type { TreeDataNode} from "antd";
|
|
18
|
-
|
|
19
|
-
// const { Search } = Input;
|
|
20
|
-
|
|
21
17
|
const BoxAction = _styledComponents.default.div.withConfig({
|
|
22
18
|
displayName: "BoxAction",
|
|
23
19
|
componentId: "es-grid-template__sc-1ix8yky-0"
|
|
@@ -25,7 +21,7 @@ const BoxAction = _styledComponents.default.div.withConfig({
|
|
|
25
21
|
const ColumnsChoose = props => {
|
|
26
22
|
const {
|
|
27
23
|
columns: propsColumns,
|
|
28
|
-
|
|
24
|
+
triggerChangeColumns
|
|
29
25
|
// t,
|
|
30
26
|
} = props;
|
|
31
27
|
|
|
@@ -41,7 +37,7 @@ const ColumnsChoose = props => {
|
|
|
41
37
|
const [columns, setColumns] = (0, _react.useState)([]);
|
|
42
38
|
const [selectedKeys, setSelectedKeys] = (0, _react.useState)([]);
|
|
43
39
|
(0, _react.useEffect)(() => {
|
|
44
|
-
const defaultColumns = propsColumns.filter(it => it.key || it.dataIndex && it.
|
|
40
|
+
const defaultColumns = propsColumns.filter(it => it.key || it.dataIndex && it.showInColumnChoose !== false);
|
|
45
41
|
const defaultSelectedKeys = (0, _hooks.getVisibleColumnKeys)(propsColumns);
|
|
46
42
|
setSelectedKeys(defaultSelectedKeys);
|
|
47
43
|
setColumns(defaultColumns);
|
|
@@ -135,7 +131,7 @@ const ColumnsChoose = props => {
|
|
|
135
131
|
};
|
|
136
132
|
const handleAccept = () => {
|
|
137
133
|
const rs1 = (0, _hooks.updateColumns)(propsColumns, selectedKeys);
|
|
138
|
-
|
|
134
|
+
triggerChangeColumns?.(rs1);
|
|
139
135
|
hide();
|
|
140
136
|
};
|
|
141
137
|
const handleCancel = () => {
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
11
|
+
var _react2 = require("@floating-ui/react");
|
|
12
|
+
var _antd = require("antd");
|
|
13
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
14
|
+
var _hooks = require("./hooks");
|
|
15
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
16
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
17
|
+
// import {getTemplate} from "../../hooks"
|
|
18
|
+
|
|
19
|
+
const TooltipStyle = _styledComponents.default.div.withConfig({
|
|
20
|
+
displayName: "TooltipStyle",
|
|
21
|
+
componentId: "es-grid-template__sc-1iotu11-0"
|
|
22
|
+
})(["width:max-content;background-color:#444;color:white;font-size:90%;padding:4px 8px;border-radius:4px;opacity:0.9;z-index:9999;max-width:450px;"]);
|
|
23
|
+
const Command = props => {
|
|
24
|
+
const {
|
|
25
|
+
item,
|
|
26
|
+
onClick
|
|
27
|
+
} = props;
|
|
28
|
+
const [isOpen, setIsOpen] = (0, _react.useState)(false);
|
|
29
|
+
const {
|
|
30
|
+
refs,
|
|
31
|
+
floatingStyles,
|
|
32
|
+
context
|
|
33
|
+
} = (0, _react2.useFloating)({
|
|
34
|
+
open: isOpen,
|
|
35
|
+
onOpenChange: setIsOpen,
|
|
36
|
+
placement: "top",
|
|
37
|
+
whileElementsMounted: _react2.autoUpdate,
|
|
38
|
+
middleware: [(0, _react2.offset)(5), (0, _react2.flip)({
|
|
39
|
+
fallbackAxisSideDirection: "start"
|
|
40
|
+
}), (0, _react2.shift)()]
|
|
41
|
+
});
|
|
42
|
+
const hover = (0, _react2.useHover)(context, {
|
|
43
|
+
move: false
|
|
44
|
+
});
|
|
45
|
+
const focus = (0, _react2.useFocus)(context);
|
|
46
|
+
const dismiss = (0, _react2.useDismiss)(context);
|
|
47
|
+
const role = (0, _react2.useRole)(context, {
|
|
48
|
+
role: "tooltip"
|
|
49
|
+
});
|
|
50
|
+
const {
|
|
51
|
+
getReferenceProps,
|
|
52
|
+
getFloatingProps
|
|
53
|
+
} = (0, _react2.useInteractions)([hover, focus, dismiss, role]);
|
|
54
|
+
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, item.template ? /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
|
|
55
|
+
ref: refs.setReference
|
|
56
|
+
}, getReferenceProps(), {
|
|
57
|
+
id: item.id,
|
|
58
|
+
onClick: onClick
|
|
59
|
+
}), (0, _hooks.getTemplate)(item.template)) : /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
|
|
60
|
+
ref: refs.setReference
|
|
61
|
+
}, getReferenceProps()), /*#__PURE__*/_react.default.createElement(_antd.Button, {
|
|
62
|
+
id: 'tooltip',
|
|
63
|
+
tabIndex: -1,
|
|
64
|
+
style: {
|
|
65
|
+
padding: '3px',
|
|
66
|
+
maxWidth: 45,
|
|
67
|
+
height: '100%'
|
|
68
|
+
},
|
|
69
|
+
className: (0, _classnames.default)('command-item', {
|
|
70
|
+
'btn-icon': item.title === ''
|
|
71
|
+
}),
|
|
72
|
+
color: item.color ? item.color : 'primary',
|
|
73
|
+
onClick: onClick
|
|
74
|
+
}, item.icon ? (0, _hooks.getTemplate)(item.icon) : item.title))
|
|
75
|
+
|
|
76
|
+
// <span>{item.title}</span>
|
|
77
|
+
, isOpen && item.tooltip && /*#__PURE__*/_react.default.createElement(_react2.FloatingPortal, {
|
|
78
|
+
root: document.body
|
|
79
|
+
}, /*#__PURE__*/_react.default.createElement(TooltipStyle, (0, _extends2.default)({
|
|
80
|
+
className: "Tooltip",
|
|
81
|
+
ref: refs.setFloating,
|
|
82
|
+
style: {
|
|
83
|
+
...floatingStyles,
|
|
84
|
+
zIndex: 99
|
|
85
|
+
}
|
|
86
|
+
}, getFloatingProps()), item.tooltip)));
|
|
87
|
+
};
|
|
88
|
+
var _default = exports.default = Command;
|