es-grid-template 1.7.23 → 1.7.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/es/index.d.ts +1 -0
- package/es/index.js +3 -1
- package/es/table-component/ColumnsChoose.d.ts +13 -0
- package/es/table-component/ColumnsChoose.js +206 -0
- package/es/table-component/ContextMenu.d.ts +20 -0
- package/es/table-component/ContextMenu.js +75 -0
- package/es/table-component/InternalTable.d.ts +9 -0
- package/es/table-component/InternalTable.js +308 -0
- package/es/table-component/TableContainer.d.ts +31 -0
- package/es/table-component/TableContainer.js +249 -0
- package/es/table-component/TableContainerEdit.d.ts +31 -0
- package/es/table-component/TableContainerEdit.js +1301 -0
- package/es/table-component/body/EditableCell.d.ts +16 -0
- package/es/table-component/body/EditableCell.js +1039 -0
- package/es/table-component/body/TableBody.d.ts +19 -0
- package/es/table-component/body/TableBody.js +64 -0
- package/es/table-component/body/TableBodyCell.d.ts +12 -0
- package/es/table-component/body/TableBodyCell.js +149 -0
- package/es/table-component/body/TableBodyCellEdit.d.ts +16 -0
- package/es/table-component/body/TableBodyCellEdit.js +931 -0
- package/es/table-component/body/TableBodyRow.d.ts +21 -0
- package/es/table-component/body/TableBodyRow.js +151 -0
- package/es/table-component/components/ControlCheckbox.d.ts +13 -0
- package/es/table-component/components/ControlCheckbox.js +84 -0
- package/es/table-component/components/EditForm/EditForm.d.ts +27 -0
- package/es/table-component/components/EditForm/EditForm.js +395 -0
- package/es/table-component/components/EditForm/index.d.ts +1 -0
- package/es/table-component/components/EditForm/index.js +1 -0
- package/es/table-component/components/InputControl/InputControl.d.ts +27 -0
- package/es/table-component/components/InputControl/InputControl.js +121 -0
- package/es/table-component/components/InputControl/index.d.ts +1 -0
- package/es/table-component/components/InputControl/index.js +1 -0
- package/es/table-component/components/async-select/index.d.ts +11 -0
- package/es/table-component/components/async-select/index.js +41 -0
- package/es/table-component/components/async-table-select/index.d.ts +11 -0
- package/es/table-component/components/async-table-select/index.js +44 -0
- package/es/table-component/components/checkbox-control/index.d.ts +13 -0
- package/es/table-component/components/checkbox-control/index.js +40 -0
- package/es/table-component/components/checkbox-filter/CheckboxFilter.d.ts +18 -0
- package/es/table-component/components/checkbox-filter/CheckboxFilter.js +240 -0
- package/es/table-component/components/checkbox-filter/FilterSearch.d.ts +12 -0
- package/es/table-component/components/checkbox-filter/FilterSearch.js +36 -0
- package/es/table-component/components/command/Command.d.ts +10 -0
- package/es/table-component/components/command/Command.js +33 -0
- package/es/table-component/components/number/index.d.ts +10 -0
- package/es/table-component/components/number/index.js +42 -0
- package/es/table-component/components/number-range/index.d.ts +11 -0
- package/es/table-component/components/number-range/index.js +66 -0
- package/es/table-component/features/operator.d.ts +24 -0
- package/es/table-component/features/operator.js +62 -0
- package/es/table-component/footer/TableFooter.d.ts +13 -0
- package/es/table-component/footer/TableFooter.js +33 -0
- package/es/table-component/footer/TableFooterCell.d.ts +10 -0
- package/es/table-component/footer/TableFooterCell.js +66 -0
- package/es/table-component/footer/TableFooterRow.d.ts +14 -0
- package/es/table-component/footer/TableFooterRow.js +73 -0
- package/es/table-component/header/TableHead.d.ts +14 -0
- package/es/table-component/header/TableHead.js +60 -0
- package/es/table-component/header/TableHeadCell.d.ts +14 -0
- package/es/table-component/header/TableHeadCell.js +343 -0
- package/es/table-component/header/TableHeadRow.d.ts +16 -0
- package/es/table-component/header/TableHeadRow.js +76 -0
- package/es/table-component/header/renderFilter.d.ts +20 -0
- package/es/table-component/header/renderFilter.js +281 -0
- package/es/table-component/hook/constant.d.ts +73 -0
- package/es/table-component/hook/constant.js +240 -0
- package/es/table-component/hook/useColumns.d.ts +9 -0
- package/es/table-component/hook/useColumns.js +169 -0
- package/es/table-component/hook/useFilterOperator.d.ts +7 -0
- package/es/table-component/hook/useFilterOperator.js +33 -0
- package/es/table-component/hook/utils.d.ts +133 -0
- package/es/table-component/hook/utils.js +1870 -0
- package/es/table-component/index.d.ts +5 -0
- package/es/table-component/index.js +2 -0
- package/es/table-component/style.scss +1129 -0
- package/es/table-component/table/Grid.d.ts +24 -0
- package/es/table-component/table/Grid.js +234 -0
- package/es/table-component/type.d.ts +513 -0
- package/es/table-component/type.js +1 -0
- package/es/table-component/useContext.d.ts +74 -0
- package/es/table-component/useContext.js +15 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +8 -1
- package/lib/table-component/ColumnsChoose.d.ts +13 -0
- package/lib/table-component/ColumnsChoose.js +216 -0
- package/lib/table-component/ContextMenu.d.ts +20 -0
- package/lib/table-component/ContextMenu.js +85 -0
- package/lib/table-component/InternalTable.d.ts +9 -0
- package/lib/table-component/InternalTable.js +313 -0
- package/lib/table-component/TableContainer.d.ts +31 -0
- package/lib/table-component/TableContainer.js +257 -0
- package/lib/table-component/TableContainerEdit.d.ts +31 -0
- package/lib/table-component/TableContainerEdit.js +1310 -0
- package/lib/table-component/body/EditableCell.d.ts +16 -0
- package/lib/table-component/body/EditableCell.js +1041 -0
- package/lib/table-component/body/TableBody.d.ts +19 -0
- package/lib/table-component/body/TableBody.js +72 -0
- package/lib/table-component/body/TableBodyCell.d.ts +12 -0
- package/lib/table-component/body/TableBodyCell.js +158 -0
- package/lib/table-component/body/TableBodyCellEdit.d.ts +16 -0
- package/lib/table-component/body/TableBodyCellEdit.js +938 -0
- package/lib/table-component/body/TableBodyRow.d.ts +21 -0
- package/lib/table-component/body/TableBodyRow.js +158 -0
- package/lib/table-component/components/ControlCheckbox.d.ts +13 -0
- package/lib/table-component/components/ControlCheckbox.js +92 -0
- package/lib/table-component/components/EditForm/EditForm.d.ts +27 -0
- package/lib/table-component/components/EditForm/EditForm.js +406 -0
- package/lib/table-component/components/EditForm/index.d.ts +1 -0
- package/lib/table-component/components/EditForm/index.js +16 -0
- package/lib/table-component/components/InputControl/InputControl.d.ts +27 -0
- package/lib/table-component/components/InputControl/InputControl.js +131 -0
- package/lib/table-component/components/InputControl/index.d.ts +1 -0
- package/lib/table-component/components/InputControl/index.js +16 -0
- package/lib/table-component/components/async-select/index.d.ts +11 -0
- package/lib/table-component/components/async-select/index.js +49 -0
- package/lib/table-component/components/async-table-select/index.d.ts +11 -0
- package/lib/table-component/components/async-table-select/index.js +53 -0
- package/lib/table-component/components/checkbox-control/index.d.ts +13 -0
- package/lib/table-component/components/checkbox-control/index.js +48 -0
- package/lib/table-component/components/checkbox-filter/CheckboxFilter.d.ts +18 -0
- package/lib/table-component/components/checkbox-filter/CheckboxFilter.js +249 -0
- package/lib/table-component/components/checkbox-filter/FilterSearch.d.ts +12 -0
- package/lib/table-component/components/checkbox-filter/FilterSearch.js +44 -0
- package/lib/table-component/components/command/Command.d.ts +10 -0
- package/lib/table-component/components/command/Command.js +42 -0
- package/lib/table-component/components/number/index.d.ts +10 -0
- package/lib/table-component/components/number/index.js +50 -0
- package/lib/table-component/components/number-range/index.d.ts +11 -0
- package/lib/table-component/components/number-range/index.js +74 -0
- package/lib/table-component/features/operator.d.ts +24 -0
- package/lib/table-component/features/operator.js +67 -0
- package/lib/table-component/footer/TableFooter.d.ts +13 -0
- package/lib/table-component/footer/TableFooter.js +42 -0
- package/lib/table-component/footer/TableFooterCell.d.ts +10 -0
- package/lib/table-component/footer/TableFooterCell.js +76 -0
- package/lib/table-component/footer/TableFooterRow.d.ts +14 -0
- package/lib/table-component/footer/TableFooterRow.js +81 -0
- package/lib/table-component/header/TableHead.d.ts +14 -0
- package/lib/table-component/header/TableHead.js +69 -0
- package/lib/table-component/header/TableHeadCell.d.ts +14 -0
- package/lib/table-component/header/TableHeadCell.js +352 -0
- package/lib/table-component/header/TableHeadRow.d.ts +16 -0
- package/lib/table-component/header/TableHeadRow.js +84 -0
- package/lib/table-component/header/renderFilter.d.ts +20 -0
- package/lib/table-component/header/renderFilter.js +291 -0
- package/lib/table-component/hook/constant.d.ts +73 -0
- package/lib/table-component/hook/constant.js +247 -0
- package/lib/table-component/hook/useColumns.d.ts +9 -0
- package/lib/table-component/hook/useColumns.js +180 -0
- package/lib/table-component/hook/useFilterOperator.d.ts +7 -0
- package/lib/table-component/hook/useFilterOperator.js +40 -0
- package/lib/table-component/hook/utils.d.ts +133 -0
- package/lib/table-component/hook/utils.js +1969 -0
- package/lib/table-component/index.d.ts +5 -0
- package/lib/table-component/index.js +9 -0
- package/lib/table-component/style.scss +1129 -0
- package/lib/table-component/table/Grid.d.ts +24 -0
- package/lib/table-component/table/Grid.js +236 -0
- package/lib/table-component/type.d.ts +513 -0
- package/lib/table-component/type.js +5 -0
- package/lib/table-component/useContext.d.ts +74 -0
- package/lib/table-component/useContext.js +21 -0
- package/package.json +4 -2
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { VirtualItem, Virtualizer } from "@tanstack/react-virtual";
|
|
2
|
+
import type { Column, Row, Table } from "@tanstack/react-table";
|
|
3
|
+
import type { CommandClick } from "../type";
|
|
4
|
+
import React from "react";
|
|
5
|
+
interface TableBodyRowProps<T> {
|
|
6
|
+
tableId: string;
|
|
7
|
+
table: Table<T>;
|
|
8
|
+
columnVirtualizer: Virtualizer<HTMLDivElement, HTMLTableCellElement>;
|
|
9
|
+
row: Row<T>;
|
|
10
|
+
rowVirtualizer: Virtualizer<HTMLDivElement, HTMLTableRowElement>;
|
|
11
|
+
virtualPaddingLeft: number | undefined;
|
|
12
|
+
virtualPaddingRight: number | undefined;
|
|
13
|
+
virtualRow: VirtualItem;
|
|
14
|
+
fixedLeftColumns: Column<T, unknown>[];
|
|
15
|
+
fixedRightColumns: Column<T, unknown>[];
|
|
16
|
+
commandClick?: (args: CommandClick) => void;
|
|
17
|
+
editAble?: boolean;
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
}
|
|
20
|
+
declare const TableBodyRow: <RecordType extends object>({ tableId, table, columnVirtualizer, row, rowVirtualizer, virtualPaddingLeft, virtualPaddingRight, virtualRow, fixedLeftColumns, fixedRightColumns, commandClick, editAble, isEditing, contextMenuItems, ...rest }: TableBodyRowProps<RecordType>) => React.JSX.Element;
|
|
21
|
+
export default TableBodyRow;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import TableBodyCell from "./TableBodyCell";
|
|
3
|
+
import TableBodyCellEdit from "./TableBodyCellEdit";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import { TableContext } from "../useContext";
|
|
6
|
+
import classNames from "classnames";
|
|
7
|
+
const TableBodyRow = ({
|
|
8
|
+
tableId,
|
|
9
|
+
table,
|
|
10
|
+
columnVirtualizer,
|
|
11
|
+
row,
|
|
12
|
+
rowVirtualizer,
|
|
13
|
+
virtualPaddingLeft,
|
|
14
|
+
virtualPaddingRight,
|
|
15
|
+
virtualRow,
|
|
16
|
+
fixedLeftColumns,
|
|
17
|
+
fixedRightColumns,
|
|
18
|
+
commandClick,
|
|
19
|
+
editAble,
|
|
20
|
+
isEditing,
|
|
21
|
+
contextMenuItems,
|
|
22
|
+
...rest
|
|
23
|
+
}) => {
|
|
24
|
+
const {
|
|
25
|
+
prefix,
|
|
26
|
+
recordDoubleClick,
|
|
27
|
+
onContextMenu
|
|
28
|
+
} = React.useContext(TableContext);
|
|
29
|
+
const visibleCells = row.getVisibleCells();
|
|
30
|
+
const virtualColumns = columnVirtualizer.getVirtualItems();
|
|
31
|
+
|
|
32
|
+
// table.options.set
|
|
33
|
+
|
|
34
|
+
return /*#__PURE__*/React.createElement("tr", {
|
|
35
|
+
"data-index": virtualRow.index //needed for dynamic row height measurement
|
|
36
|
+
,
|
|
37
|
+
ref: node => rowVirtualizer.measureElement(node) //measure dynamic row height
|
|
38
|
+
,
|
|
39
|
+
key: row.id
|
|
40
|
+
|
|
41
|
+
// className={} ui-rc-table-row-selected
|
|
42
|
+
,
|
|
43
|
+
className: classNames(`${prefix}-grid-row`, {
|
|
44
|
+
[`${prefix}-grid-row-selected`]: row.getIsSelected()
|
|
45
|
+
}),
|
|
46
|
+
style: {
|
|
47
|
+
// display: 'flex',
|
|
48
|
+
// position: 'absolute',
|
|
49
|
+
transform: `translateY(${virtualRow.start}px)`,
|
|
50
|
+
//this should always be a `style` as it changes on scroll
|
|
51
|
+
// width: '100%',
|
|
52
|
+
// height: isEditing ? '36px' : undefined,
|
|
53
|
+
height: isEditing ? virtualRow.size : undefined,
|
|
54
|
+
minHeight: isEditing ? undefined : virtualRow.size
|
|
55
|
+
},
|
|
56
|
+
onDoubleClick: e => {
|
|
57
|
+
recordDoubleClick?.({
|
|
58
|
+
e,
|
|
59
|
+
rowData: row.original,
|
|
60
|
+
rowIndex: row.index
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
onContextMenu: e => {
|
|
64
|
+
if (contextMenuItems && contextMenuItems.length) {
|
|
65
|
+
onContextMenu?.(row.original)(e);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// onContextMenu={onContextMenu(row.original)}
|
|
70
|
+
}, fixedLeftColumns.length > 0 ? fixedLeftColumns.map(column => {
|
|
71
|
+
const cell = row.getVisibleCells().find(c => c.column.id === column.id);
|
|
72
|
+
if (editAble) {
|
|
73
|
+
return /*#__PURE__*/React.createElement(TableBodyCellEdit, _extends({}, rest, {
|
|
74
|
+
table: table,
|
|
75
|
+
tableId: tableId,
|
|
76
|
+
key: cell.id,
|
|
77
|
+
cell: cell,
|
|
78
|
+
commandClick: commandClick,
|
|
79
|
+
virtualRow: virtualRow,
|
|
80
|
+
isEditing: isEditing,
|
|
81
|
+
rowVirtualizer: rowVirtualizer,
|
|
82
|
+
columnVirtualizer: columnVirtualizer
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
85
|
+
return /*#__PURE__*/React.createElement(TableBodyCell, {
|
|
86
|
+
key: column.id,
|
|
87
|
+
table: table,
|
|
88
|
+
cell: row.getVisibleCells().find(c => c.column.id === column.id),
|
|
89
|
+
commandClick: commandClick,
|
|
90
|
+
virtualRow: virtualRow
|
|
91
|
+
});
|
|
92
|
+
}) : null, virtualPaddingLeft ? /*#__PURE__*/React.createElement("td", {
|
|
93
|
+
className: "",
|
|
94
|
+
style: {
|
|
95
|
+
display: "flex",
|
|
96
|
+
width: virtualPaddingLeft
|
|
97
|
+
}
|
|
98
|
+
}) : null, virtualColumns.map(vc => {
|
|
99
|
+
const cell = visibleCells[vc.index];
|
|
100
|
+
const isFixed = table.getState().columnPinning.left?.includes(cell.column.id) || table.getState().columnPinning.right?.includes(cell.column.id);
|
|
101
|
+
if (cell && !isFixed) {
|
|
102
|
+
if (editAble) {
|
|
103
|
+
return /*#__PURE__*/React.createElement(TableBodyCellEdit, _extends({}, rest, {
|
|
104
|
+
table: table,
|
|
105
|
+
key: cell.id,
|
|
106
|
+
tableId: tableId,
|
|
107
|
+
cell: cell,
|
|
108
|
+
commandClick: commandClick,
|
|
109
|
+
isEditing: isEditing,
|
|
110
|
+
rowVirtualizer: rowVirtualizer,
|
|
111
|
+
columnVirtualizer: columnVirtualizer,
|
|
112
|
+
virtualRow: virtualRow
|
|
113
|
+
}));
|
|
114
|
+
}
|
|
115
|
+
return /*#__PURE__*/React.createElement(TableBodyCell, {
|
|
116
|
+
table: table,
|
|
117
|
+
key: cell.id,
|
|
118
|
+
cell: cell,
|
|
119
|
+
commandClick: commandClick,
|
|
120
|
+
virtualRow: virtualRow
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}), fixedRightColumns.length > 0 ? fixedRightColumns.map(column => {
|
|
124
|
+
if (editAble) {
|
|
125
|
+
return /*#__PURE__*/React.createElement(TableBodyCellEdit, _extends({}, rest, {
|
|
126
|
+
table: table,
|
|
127
|
+
key: column.id,
|
|
128
|
+
tableId: tableId,
|
|
129
|
+
cell: row.getVisibleCells().find(c => c.column.id === column.id),
|
|
130
|
+
commandClick: commandClick,
|
|
131
|
+
isEditing: isEditing,
|
|
132
|
+
rowVirtualizer: rowVirtualizer,
|
|
133
|
+
columnVirtualizer: columnVirtualizer,
|
|
134
|
+
virtualRow: virtualRow
|
|
135
|
+
}));
|
|
136
|
+
}
|
|
137
|
+
return /*#__PURE__*/React.createElement(TableBodyCell, {
|
|
138
|
+
key: column.id,
|
|
139
|
+
table: table,
|
|
140
|
+
cell: row.getVisibleCells().find(c => c.column.id === column.id),
|
|
141
|
+
commandClick: commandClick
|
|
142
|
+
});
|
|
143
|
+
}) : null, virtualPaddingRight ? /*#__PURE__*/React.createElement("td", {
|
|
144
|
+
className: "",
|
|
145
|
+
style: {
|
|
146
|
+
display: "flex",
|
|
147
|
+
width: virtualPaddingRight
|
|
148
|
+
}
|
|
149
|
+
}) : null);
|
|
150
|
+
};
|
|
151
|
+
export default TableBodyRow;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { ColumnTable } from "../type";
|
|
3
|
+
type Props = {
|
|
4
|
+
column: ColumnTable;
|
|
5
|
+
record?: any;
|
|
6
|
+
rowIndex: number;
|
|
7
|
+
colIndex: number;
|
|
8
|
+
checkValue: any;
|
|
9
|
+
checked: boolean;
|
|
10
|
+
editAble?: boolean;
|
|
11
|
+
};
|
|
12
|
+
declare const ControlCheckbox: (props: Props) => React.JSX.Element;
|
|
13
|
+
export default ControlCheckbox;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import React, { useContext } from "react";
|
|
2
|
+
import { Checkbox } from "rc-master-ui";
|
|
3
|
+
import { TableContext } from "../useContext";
|
|
4
|
+
import { isEditable, isDisable, parseBooleanToValue } from "../hook/utils";
|
|
5
|
+
const ControlCheckbox = props => {
|
|
6
|
+
const {
|
|
7
|
+
column,
|
|
8
|
+
record,
|
|
9
|
+
rowIndex,
|
|
10
|
+
colIndex,
|
|
11
|
+
checkValue,
|
|
12
|
+
editAble,
|
|
13
|
+
checked
|
|
14
|
+
} = props;
|
|
15
|
+
const {
|
|
16
|
+
handleCellChange,
|
|
17
|
+
rowKey
|
|
18
|
+
} = useContext(TableContext);
|
|
19
|
+
const isEdit = React.useMemo(() => {
|
|
20
|
+
return isEditable(column, record);
|
|
21
|
+
}, [column, record]);
|
|
22
|
+
|
|
23
|
+
// const [isHover, setIsHover] = useState(false)
|
|
24
|
+
|
|
25
|
+
const inputNode = value => {
|
|
26
|
+
return /*#__PURE__*/React.createElement(Checkbox, {
|
|
27
|
+
checked: Boolean(value),
|
|
28
|
+
defaultChecked: Boolean(checked)
|
|
29
|
+
// style={{ textAlign: column.align ?? 'left' }}
|
|
30
|
+
,
|
|
31
|
+
onChange: val => {
|
|
32
|
+
const newVal = typeof checkValue === "number" ? parseBooleanToValue(val.target.checked, typeof value) : val.target.checked;
|
|
33
|
+
|
|
34
|
+
// onChange(newVal)
|
|
35
|
+
|
|
36
|
+
const key = record[rowKey];
|
|
37
|
+
// const formState = getValues()
|
|
38
|
+
|
|
39
|
+
handleCellChange?.({
|
|
40
|
+
key: key,
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
record: {
|
|
43
|
+
...record,
|
|
44
|
+
[column.field]: newVal
|
|
45
|
+
},
|
|
46
|
+
option: value,
|
|
47
|
+
prevState: value,
|
|
48
|
+
newState: newVal,
|
|
49
|
+
field: column.field,
|
|
50
|
+
indexCol: colIndex,
|
|
51
|
+
indexRow: rowIndex,
|
|
52
|
+
type: 'blur'
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
disabled: isDisable(column, record) ?? false
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
59
|
+
// onMouseEnter={() => {
|
|
60
|
+
// setIsHover(true)
|
|
61
|
+
// }}
|
|
62
|
+
//
|
|
63
|
+
// onMouseLeave={() => {
|
|
64
|
+
// setIsHover(false)
|
|
65
|
+
// }}
|
|
66
|
+
style: {
|
|
67
|
+
display: 'flex',
|
|
68
|
+
alignItems: 'center',
|
|
69
|
+
justifyContent: column.align ?? 'center',
|
|
70
|
+
paddingInline: 5,
|
|
71
|
+
height: '100%',
|
|
72
|
+
width: '100%'
|
|
73
|
+
}
|
|
74
|
+
}, editAble && isEdit !== false ? inputNode(checkValue) : /*#__PURE__*/React.createElement(Checkbox, {
|
|
75
|
+
checked: checked,
|
|
76
|
+
onChange: e => {
|
|
77
|
+
e.preventDefault();
|
|
78
|
+
},
|
|
79
|
+
style: {
|
|
80
|
+
textAlign: column.align ?? 'left'
|
|
81
|
+
}
|
|
82
|
+
}));
|
|
83
|
+
};
|
|
84
|
+
export default ControlCheckbox;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
type Props = {
|
|
3
|
+
id?: string;
|
|
4
|
+
externalClick?: any;
|
|
5
|
+
menuPortalTarget?: any;
|
|
6
|
+
value: any;
|
|
7
|
+
onChange: (props: any) => void;
|
|
8
|
+
filterKey?: string;
|
|
9
|
+
customRender?: any;
|
|
10
|
+
filterHeaderKey?: string;
|
|
11
|
+
placeholder?: string;
|
|
12
|
+
invalid?: any;
|
|
13
|
+
menuHeight?: number;
|
|
14
|
+
menuWidth?: number;
|
|
15
|
+
classNamePrefix?: string;
|
|
16
|
+
cellFocus?: boolean;
|
|
17
|
+
t?: any;
|
|
18
|
+
column: any;
|
|
19
|
+
fieldKey?: any;
|
|
20
|
+
rowData: any;
|
|
21
|
+
indexRow: any;
|
|
22
|
+
template?: any;
|
|
23
|
+
onKeyDown?: (event: any) => void;
|
|
24
|
+
};
|
|
25
|
+
export declare const SelectStyle: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
|
|
26
|
+
export declare const EditForm: (props: Props) => React.JSX.Element;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import React, { Fragment, useRef } from "react";
|
|
2
|
+
import styled from "styled-components";
|
|
3
|
+
import { useForm } from "react-hook-form";
|
|
4
|
+
import { yupResolver } from "@hookform/resolvers/yup";
|
|
5
|
+
import { Col, Row } from "rc-master-ui/es/grid";
|
|
6
|
+
// import InputControl from "../control/InputControl/InputControl";
|
|
7
|
+
import { isNullOrUndefined, isObjEmpty } from "../../hook/utils";
|
|
8
|
+
import { Input } from "rc-master-ui";
|
|
9
|
+
import { Dropdown } from "antd";
|
|
10
|
+
import Divider from "rc-master-ui/es/divider";
|
|
11
|
+
import Button from "rc-master-ui/es/button";
|
|
12
|
+
import InputControl from "../InputControl/InputControl";
|
|
13
|
+
export const SelectStyle = styled.div.withConfig({
|
|
14
|
+
displayName: "SelectStyle",
|
|
15
|
+
componentId: "es-grid-template__sc-18plqpt-0"
|
|
16
|
+
})(["width:100%;&.be-select{.input-group-merge{flex-wrap:nowrap;}}"]);
|
|
17
|
+
export const EditForm = props => {
|
|
18
|
+
const {
|
|
19
|
+
id,
|
|
20
|
+
// menuPortalTarget,
|
|
21
|
+
value,
|
|
22
|
+
fieldKey,
|
|
23
|
+
placeholder,
|
|
24
|
+
// invalid,
|
|
25
|
+
menuHeight,
|
|
26
|
+
menuWidth,
|
|
27
|
+
// classNamePrefix,
|
|
28
|
+
onChange,
|
|
29
|
+
rowData,
|
|
30
|
+
// onKeyDown,
|
|
31
|
+
t,
|
|
32
|
+
cellFocus,
|
|
33
|
+
column
|
|
34
|
+
} = props;
|
|
35
|
+
const formRef = useRef();
|
|
36
|
+
const divRef = useRef(null);
|
|
37
|
+
const inputRef = useRef(null);
|
|
38
|
+
const defaultValue = !isNullOrUndefined(value) ? column?.editFromSettings?.formatLabel ? column?.editFromSettings?.formatLabel(value) : value[fieldKey] : '';
|
|
39
|
+
const {
|
|
40
|
+
control,
|
|
41
|
+
handleSubmit,
|
|
42
|
+
getValues,
|
|
43
|
+
reset,
|
|
44
|
+
setValue,
|
|
45
|
+
setError,
|
|
46
|
+
formState: {
|
|
47
|
+
errors
|
|
48
|
+
}
|
|
49
|
+
} = useForm({
|
|
50
|
+
mode: 'onChange',
|
|
51
|
+
defaultValues: column.editFromSettings?.defaultValues,
|
|
52
|
+
resolver: column.editFromSettings?.schema ? yupResolver(column.editFromSettings?.schema) : undefined
|
|
53
|
+
});
|
|
54
|
+
const handleToggle = () => {
|
|
55
|
+
divRef?.current?.click(); // Giả lập click vào nút để mở dropdown
|
|
56
|
+
};
|
|
57
|
+
React.useEffect(() => {
|
|
58
|
+
if (cellFocus) {
|
|
59
|
+
handleToggle();
|
|
60
|
+
}
|
|
61
|
+
}, [cellFocus]);
|
|
62
|
+
const handleOnSubmit = val => {
|
|
63
|
+
handleToggle();
|
|
64
|
+
onChange(val);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// const handleOnKeyDown = (e: any) => {
|
|
68
|
+
//
|
|
69
|
+
// if (dropdownOpen) {
|
|
70
|
+
// e.preventDefault()
|
|
71
|
+
//
|
|
72
|
+
// if (e.code === 'Tab') {
|
|
73
|
+
// e.stopPropagation()
|
|
74
|
+
// const formElement = document.getElementById('edit-form')
|
|
75
|
+
//
|
|
76
|
+
// if (formElement) {
|
|
77
|
+
//
|
|
78
|
+
// formElement.getElementsByTagName('input')[0]?.focus()
|
|
79
|
+
//
|
|
80
|
+
// }
|
|
81
|
+
//
|
|
82
|
+
// }
|
|
83
|
+
//
|
|
84
|
+
// if (e.code === "Escape") {
|
|
85
|
+
// e.preventDefault()
|
|
86
|
+
// e.stopPropagation()
|
|
87
|
+
// return e
|
|
88
|
+
// }
|
|
89
|
+
//
|
|
90
|
+
// const formElement = document.getElementById('edit-form')
|
|
91
|
+
//
|
|
92
|
+
// if (formElement) {
|
|
93
|
+
//
|
|
94
|
+
// formElement.getElementsByTagName('input')[0]?.focus()
|
|
95
|
+
//
|
|
96
|
+
// }
|
|
97
|
+
// return e.code
|
|
98
|
+
//
|
|
99
|
+
//
|
|
100
|
+
// } else {
|
|
101
|
+
// if (e.code === 'ArrowDown') {
|
|
102
|
+
// e.preventDefault()
|
|
103
|
+
//
|
|
104
|
+
// setTimeout(() => {
|
|
105
|
+
// const formElement = document.getElementById('edit-form')
|
|
106
|
+
// if (formElement) {
|
|
107
|
+
// formElement.getElementsByTagName('input')[0]?.focus()
|
|
108
|
+
//
|
|
109
|
+
// }
|
|
110
|
+
//
|
|
111
|
+
// }, 100)
|
|
112
|
+
//
|
|
113
|
+
//
|
|
114
|
+
// }
|
|
115
|
+
// }
|
|
116
|
+
//
|
|
117
|
+
// if (onKeyDown) {
|
|
118
|
+
// onKeyDown(e)
|
|
119
|
+
// }
|
|
120
|
+
//
|
|
121
|
+
//
|
|
122
|
+
// }
|
|
123
|
+
//
|
|
124
|
+
|
|
125
|
+
const handleOnFocus = e => {
|
|
126
|
+
e.target.setSelectionRange(0, e.target.innerText.length - 1);
|
|
127
|
+
};
|
|
128
|
+
const formItemKeyDown = (e, index, length) => {
|
|
129
|
+
if (e.code === 'Tab' || e.code === 'ArrowDown') {
|
|
130
|
+
const itemElement = document.getElementById(`edit-form-${index + 1}`);
|
|
131
|
+
if (itemElement && index < length) {
|
|
132
|
+
if (itemElement.className.includes('be-select')) {
|
|
133
|
+
itemElement.getElementsByTagName('input')[0]?.focus();
|
|
134
|
+
} else {
|
|
135
|
+
itemElement.focus();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
e.preventDefault();
|
|
139
|
+
}
|
|
140
|
+
if (e.code === 'ArrowUp') {
|
|
141
|
+
const itemElement = document.getElementById(`edit-form-${index - 1}`);
|
|
142
|
+
if (itemElement && index !== 0) {
|
|
143
|
+
if (itemElement.className.includes('be-select')) {
|
|
144
|
+
itemElement.getElementsByTagName('input')[0]?.focus();
|
|
145
|
+
} else {
|
|
146
|
+
itemElement.focus();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
e.preventDefault();
|
|
150
|
+
}
|
|
151
|
+
if (e.code === 'Enter') {
|
|
152
|
+
if (isObjEmpty(errors)) {
|
|
153
|
+
const rs = getValues();
|
|
154
|
+
if (column.editFromSettings?.schema) {
|
|
155
|
+
column.editFromSettings?.schema.validate(rs, {
|
|
156
|
+
abortEarly: false
|
|
157
|
+
}).then(() => {
|
|
158
|
+
handleToggle();
|
|
159
|
+
onChange(rs);
|
|
160
|
+
if (column.editFromSettings && column?.editFromSettings?.formClose) {
|
|
161
|
+
column?.editFromSettings?.formClose({
|
|
162
|
+
value,
|
|
163
|
+
setValue,
|
|
164
|
+
getValues,
|
|
165
|
+
reset
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
if (inputRef) {
|
|
169
|
+
inputRef.current.focus();
|
|
170
|
+
}
|
|
171
|
+
}).catch(err => {
|
|
172
|
+
e.preventDefault();
|
|
173
|
+
e.stopPropagation();
|
|
174
|
+
err.inner.forEach(error => {
|
|
175
|
+
setError(error.path ? error.path : '', {
|
|
176
|
+
type: "manual",
|
|
177
|
+
message: error.message
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
} else {
|
|
183
|
+
e.preventDefault();
|
|
184
|
+
e.stopPropagation();
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
// const checkErrors = () => {
|
|
190
|
+
//
|
|
191
|
+
//
|
|
192
|
+
// if (isObjEmpty(errors)) {
|
|
193
|
+
// const rs = getValues()
|
|
194
|
+
// if (column.editFromSettings?.schema) {
|
|
195
|
+
// column.editFromSettings?.schema.validate(rs, { abortEarly: false })
|
|
196
|
+
// .then(() => {
|
|
197
|
+
// handleToggle()
|
|
198
|
+
// onChange(rs)
|
|
199
|
+
//
|
|
200
|
+
// if (column.editFromSettings && column?.editFromSettings?.formClose) {
|
|
201
|
+
// column?.editFromSettings?.formClose({value, setValue, getValues, reset})
|
|
202
|
+
// }
|
|
203
|
+
// if (inputRef) {
|
|
204
|
+
// inputRef.current.focus()
|
|
205
|
+
// }
|
|
206
|
+
// })
|
|
207
|
+
// .catch((err: ValidationError) => {
|
|
208
|
+
//
|
|
209
|
+
// err.inner.forEach((error: ValidationError) => {
|
|
210
|
+
//
|
|
211
|
+
// setError(error.path ? error.path : '', {
|
|
212
|
+
// type: "manual",
|
|
213
|
+
// message: error.message
|
|
214
|
+
// })
|
|
215
|
+
// })
|
|
216
|
+
// })
|
|
217
|
+
// }
|
|
218
|
+
//
|
|
219
|
+
//
|
|
220
|
+
// } else {
|
|
221
|
+
//
|
|
222
|
+
// }
|
|
223
|
+
// }
|
|
224
|
+
|
|
225
|
+
const handleFormKeydown = e => {
|
|
226
|
+
// if (dropdownOpen) {
|
|
227
|
+
|
|
228
|
+
if (e.code === 'Tab' || e.code === 'ArrowUp' || e.code === 'ArrowDown') {
|
|
229
|
+
e.preventDefault();
|
|
230
|
+
e.stopPropagation();
|
|
231
|
+
// if (formElement && indexRowForm <= totalRowFrom) {
|
|
232
|
+
// setIndexRowForm((prevState) => prevState + 1)
|
|
233
|
+
// formElement.getElementsByTagName('input')[indexRowForm + 1]?.focus()
|
|
234
|
+
// }
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// if (e.code === 'Enter') {
|
|
238
|
+
// const rs = getValues()
|
|
239
|
+
//
|
|
240
|
+
//
|
|
241
|
+
// onChange(rs)
|
|
242
|
+
//
|
|
243
|
+
// if (column.editFromSettings && column?.editFromSettings?.formClose) {
|
|
244
|
+
// column?.editFromSettings?.formClose({value, setValue, getValues, reset})
|
|
245
|
+
// }
|
|
246
|
+
// if (inputRef) {
|
|
247
|
+
// inputRef.current.focus()
|
|
248
|
+
// }
|
|
249
|
+
//
|
|
250
|
+
// e.preventDefault()
|
|
251
|
+
// e.stopPropagation()
|
|
252
|
+
// }
|
|
253
|
+
|
|
254
|
+
if (e.code === "Escape") {
|
|
255
|
+
handleToggle();
|
|
256
|
+
if (inputRef) {
|
|
257
|
+
inputRef.current.focus();
|
|
258
|
+
}
|
|
259
|
+
e.preventDefault();
|
|
260
|
+
e.stopPropagation();
|
|
261
|
+
}
|
|
262
|
+
return e.code;
|
|
263
|
+
// }
|
|
264
|
+
};
|
|
265
|
+
const renderForm = rows => {
|
|
266
|
+
return /*#__PURE__*/React.createElement(Row, {
|
|
267
|
+
gutter: [0, 10]
|
|
268
|
+
}, rows.map((item, index) => {
|
|
269
|
+
return /*#__PURE__*/React.createElement(Col, {
|
|
270
|
+
key: `${index}`,
|
|
271
|
+
xl: column.editFromSettings?.layout?.xl ? column.editFromSettings?.layout?.xl : 24,
|
|
272
|
+
lg: column.editFromSettings?.layout?.lg ? column.editFromSettings?.layout?.lg : 24,
|
|
273
|
+
md: column.editFromSettings?.layout?.md ? column.editFromSettings?.layout?.md : 24,
|
|
274
|
+
sm: column.editFromSettings?.layout?.sm ? column.editFromSettings?.layout?.sm : 24,
|
|
275
|
+
xs: column.editFromSettings?.layout?.xs ? column.editFromSettings?.layout?.xs : 24,
|
|
276
|
+
className: 'mb-1'
|
|
277
|
+
}, /*#__PURE__*/React.createElement(InputControl, {
|
|
278
|
+
id: `edit-form-${index}`,
|
|
279
|
+
t: t,
|
|
280
|
+
control: control
|
|
281
|
+
// name={`specificationCode${index + 1}`}
|
|
282
|
+
,
|
|
283
|
+
name: item.name,
|
|
284
|
+
label: item.label ? item.label : '',
|
|
285
|
+
labelSize: "label-medium",
|
|
286
|
+
errors: errors[item.name],
|
|
287
|
+
onKeyDown: e => formItemKeyDown(e, index, column.editFromSettings?.items ? column.editFromSettings?.items.length : 0)
|
|
288
|
+
}));
|
|
289
|
+
}));
|
|
290
|
+
};
|
|
291
|
+
const contentStyle = {
|
|
292
|
+
padding: 6,
|
|
293
|
+
width: menuWidth,
|
|
294
|
+
backgroundColor: '#fff',
|
|
295
|
+
borderRadius: '6px',
|
|
296
|
+
boxShadow: '0 6px 16px 0 rgba(0, 0, 0, 0.08), 0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 9px 28px 8px rgba(0, 0, 0, 0.05)'
|
|
297
|
+
};
|
|
298
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(SelectStyle, {
|
|
299
|
+
ref: formRef,
|
|
300
|
+
id: id ? id : ''
|
|
301
|
+
}, /*#__PURE__*/React.createElement(Dropdown, {
|
|
302
|
+
menu: {
|
|
303
|
+
items: []
|
|
304
|
+
},
|
|
305
|
+
autoFocus: true,
|
|
306
|
+
onOpenChange: open => {
|
|
307
|
+
if (open) {
|
|
308
|
+
setTimeout(() => {
|
|
309
|
+
const formElement = document.getElementById('edit-form-0');
|
|
310
|
+
if (formElement) {
|
|
311
|
+
formElement.focus();
|
|
312
|
+
}
|
|
313
|
+
}, 10);
|
|
314
|
+
if (column.editFromSettings && column?.editFromSettings?.formOpen) {
|
|
315
|
+
column?.editFromSettings?.formOpen({
|
|
316
|
+
value,
|
|
317
|
+
setValue,
|
|
318
|
+
getValues,
|
|
319
|
+
reset,
|
|
320
|
+
rowData
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
} else {
|
|
324
|
+
if (column.editFromSettings && column?.editFromSettings?.formClose) {
|
|
325
|
+
column?.editFromSettings?.formClose({
|
|
326
|
+
value,
|
|
327
|
+
setValue,
|
|
328
|
+
getValues,
|
|
329
|
+
reset,
|
|
330
|
+
rowData
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
trigger: ['click'],
|
|
336
|
+
destroyPopupOnHide: true,
|
|
337
|
+
rootClassName: 'be-popup-container',
|
|
338
|
+
dropdownRender: () => /*#__PURE__*/React.createElement("div", {
|
|
339
|
+
style: contentStyle,
|
|
340
|
+
onKeyDown: e => handleFormKeydown(e),
|
|
341
|
+
onClick: e => {
|
|
342
|
+
e.preventDefault();
|
|
343
|
+
e.stopPropagation();
|
|
344
|
+
}
|
|
345
|
+
}, /*#__PURE__*/React.createElement("form", {
|
|
346
|
+
className: "todo-modal",
|
|
347
|
+
onSubmit: handleSubmit(handleOnSubmit)
|
|
348
|
+
}, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
|
|
349
|
+
className: 'p-1',
|
|
350
|
+
style: {
|
|
351
|
+
maxHeight: menuHeight ? menuHeight : 300,
|
|
352
|
+
overflow: "auto"
|
|
353
|
+
}
|
|
354
|
+
}, column.editFromSettings?.items ? renderForm(column.editFromSettings?.items) : ''), /*#__PURE__*/React.createElement(Divider, {
|
|
355
|
+
style: {
|
|
356
|
+
margin: 0
|
|
357
|
+
}
|
|
358
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
359
|
+
className: "d-flex justify-content-end p-1"
|
|
360
|
+
// style={{ boxShadow: "0 4px 24px 0 rgb(34 41 47 / 10%)" }}
|
|
361
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
362
|
+
variant: "solid",
|
|
363
|
+
className: ""
|
|
364
|
+
// onSubmit={handleSubmit(handleOnSubmit)}
|
|
365
|
+
,
|
|
366
|
+
onClick: handleSubmit(handleOnSubmit),
|
|
367
|
+
color: "primary",
|
|
368
|
+
style: {}
|
|
369
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
370
|
+
className: "d-flex "
|
|
371
|
+
}, t ? t('Save') : 'Save'))))))
|
|
372
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
373
|
+
ref: divRef,
|
|
374
|
+
style: {
|
|
375
|
+
height: '100%'
|
|
376
|
+
}
|
|
377
|
+
}, /*#__PURE__*/React.createElement(Input, {
|
|
378
|
+
style: {
|
|
379
|
+
borderRadius: 0,
|
|
380
|
+
height: '100%'
|
|
381
|
+
},
|
|
382
|
+
ref: inputRef,
|
|
383
|
+
defaultValue: defaultValue,
|
|
384
|
+
value: defaultValue,
|
|
385
|
+
placeholder: placeholder,
|
|
386
|
+
className: 'be-select__input'
|
|
387
|
+
// onChange={handleOnChange}
|
|
388
|
+
,
|
|
389
|
+
onFocus: handleOnFocus
|
|
390
|
+
// onClick={handleOnClick}
|
|
391
|
+
// onKeyDown={handleOnKeyDown}
|
|
392
|
+
,
|
|
393
|
+
readOnly: true
|
|
394
|
+
})))));
|
|
395
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './EditForm';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./EditForm";
|