es-grid-template 1.7.23 → 1.7.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/es/index.d.ts +1 -0
  2. package/es/index.js +3 -1
  3. package/es/table-component/ColumnsChoose.d.ts +10 -0
  4. package/es/table-component/ColumnsChoose.js +557 -0
  5. package/es/table-component/ContextMenu.d.ts +20 -0
  6. package/es/table-component/ContextMenu.js +75 -0
  7. package/es/table-component/InternalTable.d.ts +9 -0
  8. package/es/table-component/InternalTable.js +295 -0
  9. package/es/table-component/TableContainer.d.ts +22 -0
  10. package/es/table-component/TableContainer.js +130 -0
  11. package/es/table-component/TableContainerEdit.d.ts +28 -0
  12. package/es/table-component/TableContainerEdit.js +1211 -0
  13. package/es/table-component/body/EditableCell.d.ts +16 -0
  14. package/es/table-component/body/EditableCell.js +1036 -0
  15. package/es/table-component/body/TableBody.d.ts +19 -0
  16. package/es/table-component/body/TableBody.js +64 -0
  17. package/es/table-component/body/TableBodyCell.d.ts +10 -0
  18. package/es/table-component/body/TableBodyCell.js +139 -0
  19. package/es/table-component/body/TableBodyCellEdit.d.ts +15 -0
  20. package/es/table-component/body/TableBodyCellEdit.js +814 -0
  21. package/es/table-component/body/TableBodyRow.d.ts +21 -0
  22. package/es/table-component/body/TableBodyRow.js +146 -0
  23. package/es/table-component/components/ControlCheckbox.d.ts +13 -0
  24. package/es/table-component/components/ControlCheckbox.js +87 -0
  25. package/es/table-component/components/EditForm/EditForm.d.ts +27 -0
  26. package/es/table-component/components/EditForm/EditForm.js +395 -0
  27. package/es/table-component/components/EditForm/index.d.ts +1 -0
  28. package/es/table-component/components/EditForm/index.js +1 -0
  29. package/es/table-component/components/InputControl/InputControl.d.ts +27 -0
  30. package/es/table-component/components/InputControl/InputControl.js +121 -0
  31. package/es/table-component/components/InputControl/index.d.ts +1 -0
  32. package/es/table-component/components/InputControl/index.js +1 -0
  33. package/es/table-component/components/async-select/index.d.ts +11 -0
  34. package/es/table-component/components/async-select/index.js +41 -0
  35. package/es/table-component/components/async-table-select/index.d.ts +11 -0
  36. package/es/table-component/components/async-table-select/index.js +43 -0
  37. package/es/table-component/components/checkbox-control/index.d.ts +13 -0
  38. package/es/table-component/components/checkbox-control/index.js +40 -0
  39. package/es/table-component/components/checkbox-filter/CheckboxFilter.d.ts +18 -0
  40. package/es/table-component/components/checkbox-filter/CheckboxFilter.js +240 -0
  41. package/es/table-component/components/checkbox-filter/FilterSearch.d.ts +12 -0
  42. package/es/table-component/components/checkbox-filter/FilterSearch.js +36 -0
  43. package/es/table-component/components/command/Command.d.ts +9 -0
  44. package/es/table-component/components/command/Command.js +28 -0
  45. package/es/table-component/components/number/index.d.ts +10 -0
  46. package/es/table-component/components/number/index.js +42 -0
  47. package/es/table-component/components/number-range/index.d.ts +11 -0
  48. package/es/table-component/components/number-range/index.js +66 -0
  49. package/es/table-component/features/operator.d.ts +24 -0
  50. package/es/table-component/features/operator.js +62 -0
  51. package/es/table-component/footer/TableFooter.d.ts +13 -0
  52. package/es/table-component/footer/TableFooter.js +33 -0
  53. package/es/table-component/footer/TableFooterCell.d.ts +10 -0
  54. package/es/table-component/footer/TableFooterCell.js +24 -0
  55. package/es/table-component/footer/TableFooterRow.d.ts +14 -0
  56. package/es/table-component/footer/TableFooterRow.js +71 -0
  57. package/es/table-component/header/TableHead.d.ts +14 -0
  58. package/es/table-component/header/TableHead.js +60 -0
  59. package/es/table-component/header/TableHeadCell.d.ts +14 -0
  60. package/es/table-component/header/TableHeadCell.js +324 -0
  61. package/es/table-component/header/TableHeadRow.d.ts +16 -0
  62. package/es/table-component/header/TableHeadRow.js +86 -0
  63. package/es/table-component/header/renderFilter.d.ts +20 -0
  64. package/es/table-component/header/renderFilter.js +281 -0
  65. package/es/table-component/hook/constant.d.ts +73 -0
  66. package/es/table-component/hook/constant.js +240 -0
  67. package/es/table-component/hook/useColumns.d.ts +11 -0
  68. package/es/table-component/hook/useColumns.js +209 -0
  69. package/es/table-component/hook/useFilterOperator.d.ts +7 -0
  70. package/es/table-component/hook/useFilterOperator.js +33 -0
  71. package/es/table-component/hook/utils.d.ts +121 -0
  72. package/es/table-component/hook/utils.js +1727 -0
  73. package/es/table-component/index.d.ts +5 -0
  74. package/es/table-component/index.js +2 -0
  75. package/es/table-component/style.scss +1083 -0
  76. package/es/table-component/table/Grid.d.ts +23 -0
  77. package/es/table-component/table/Grid.js +310 -0
  78. package/es/table-component/table/GridEdit.d.ts +23 -0
  79. package/es/table-component/table/GridEdit.js +282 -0
  80. package/es/table-component/type.d.ts +482 -0
  81. package/es/table-component/type.js +1 -0
  82. package/es/table-component/useContext.d.ts +119 -0
  83. package/es/table-component/useContext.js +61 -0
  84. package/lib/index.d.ts +1 -0
  85. package/lib/index.js +8 -1
  86. package/lib/table-component/ColumnsChoose.d.ts +10 -0
  87. package/lib/table-component/ColumnsChoose.js +568 -0
  88. package/lib/table-component/ContextMenu.d.ts +20 -0
  89. package/lib/table-component/ContextMenu.js +85 -0
  90. package/lib/table-component/InternalTable.d.ts +9 -0
  91. package/lib/table-component/InternalTable.js +299 -0
  92. package/lib/table-component/TableContainer.d.ts +22 -0
  93. package/lib/table-component/TableContainer.js +137 -0
  94. package/lib/table-component/TableContainerEdit.d.ts +28 -0
  95. package/lib/table-component/TableContainerEdit.js +1220 -0
  96. package/lib/table-component/body/EditableCell.d.ts +16 -0
  97. package/lib/table-component/body/EditableCell.js +1038 -0
  98. package/lib/table-component/body/TableBody.d.ts +19 -0
  99. package/lib/table-component/body/TableBody.js +72 -0
  100. package/lib/table-component/body/TableBodyCell.d.ts +10 -0
  101. package/lib/table-component/body/TableBodyCell.js +148 -0
  102. package/lib/table-component/body/TableBodyCellEdit.d.ts +15 -0
  103. package/lib/table-component/body/TableBodyCellEdit.js +821 -0
  104. package/lib/table-component/body/TableBodyRow.d.ts +21 -0
  105. package/lib/table-component/body/TableBodyRow.js +153 -0
  106. package/lib/table-component/components/ControlCheckbox.d.ts +13 -0
  107. package/lib/table-component/components/ControlCheckbox.js +95 -0
  108. package/lib/table-component/components/EditForm/EditForm.d.ts +27 -0
  109. package/lib/table-component/components/EditForm/EditForm.js +406 -0
  110. package/lib/table-component/components/EditForm/index.d.ts +1 -0
  111. package/lib/table-component/components/EditForm/index.js +16 -0
  112. package/lib/table-component/components/InputControl/InputControl.d.ts +27 -0
  113. package/lib/table-component/components/InputControl/InputControl.js +131 -0
  114. package/lib/table-component/components/InputControl/index.d.ts +1 -0
  115. package/lib/table-component/components/InputControl/index.js +16 -0
  116. package/lib/table-component/components/async-select/index.d.ts +11 -0
  117. package/lib/table-component/components/async-select/index.js +49 -0
  118. package/lib/table-component/components/async-table-select/index.d.ts +11 -0
  119. package/lib/table-component/components/async-table-select/index.js +51 -0
  120. package/lib/table-component/components/checkbox-control/index.d.ts +13 -0
  121. package/lib/table-component/components/checkbox-control/index.js +48 -0
  122. package/lib/table-component/components/checkbox-filter/CheckboxFilter.d.ts +18 -0
  123. package/lib/table-component/components/checkbox-filter/CheckboxFilter.js +249 -0
  124. package/lib/table-component/components/checkbox-filter/FilterSearch.d.ts +12 -0
  125. package/lib/table-component/components/checkbox-filter/FilterSearch.js +44 -0
  126. package/lib/table-component/components/command/Command.d.ts +9 -0
  127. package/lib/table-component/components/command/Command.js +37 -0
  128. package/lib/table-component/components/number/index.d.ts +10 -0
  129. package/lib/table-component/components/number/index.js +50 -0
  130. package/lib/table-component/components/number-range/index.d.ts +11 -0
  131. package/lib/table-component/components/number-range/index.js +74 -0
  132. package/lib/table-component/features/operator.d.ts +24 -0
  133. package/lib/table-component/features/operator.js +67 -0
  134. package/lib/table-component/footer/TableFooter.d.ts +13 -0
  135. package/lib/table-component/footer/TableFooter.js +42 -0
  136. package/lib/table-component/footer/TableFooterCell.d.ts +10 -0
  137. package/lib/table-component/footer/TableFooterCell.js +32 -0
  138. package/lib/table-component/footer/TableFooterRow.d.ts +14 -0
  139. package/lib/table-component/footer/TableFooterRow.js +79 -0
  140. package/lib/table-component/header/TableHead.d.ts +14 -0
  141. package/lib/table-component/header/TableHead.js +69 -0
  142. package/lib/table-component/header/TableHeadCell.d.ts +14 -0
  143. package/lib/table-component/header/TableHeadCell.js +333 -0
  144. package/lib/table-component/header/TableHeadRow.d.ts +16 -0
  145. package/lib/table-component/header/TableHeadRow.js +94 -0
  146. package/lib/table-component/header/renderFilter.d.ts +20 -0
  147. package/lib/table-component/header/renderFilter.js +291 -0
  148. package/lib/table-component/hook/constant.d.ts +73 -0
  149. package/lib/table-component/hook/constant.js +247 -0
  150. package/lib/table-component/hook/useColumns.d.ts +11 -0
  151. package/lib/table-component/hook/useColumns.js +220 -0
  152. package/lib/table-component/hook/useFilterOperator.d.ts +7 -0
  153. package/lib/table-component/hook/useFilterOperator.js +40 -0
  154. package/lib/table-component/hook/utils.d.ts +121 -0
  155. package/lib/table-component/hook/utils.js +1817 -0
  156. package/lib/table-component/index.d.ts +5 -0
  157. package/lib/table-component/index.js +9 -0
  158. package/lib/table-component/style.scss +1083 -0
  159. package/lib/table-component/table/Grid.d.ts +23 -0
  160. package/lib/table-component/table/Grid.js +313 -0
  161. package/lib/table-component/table/GridEdit.d.ts +23 -0
  162. package/lib/table-component/table/GridEdit.js +284 -0
  163. package/lib/table-component/type.d.ts +482 -0
  164. package/lib/table-component/type.js +5 -0
  165. package/lib/table-component/useContext.d.ts +119 -0
  166. package/lib/table-component/useContext.js +67 -0
  167. package/package.json +3 -1
@@ -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,146 @@
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
+ isEditing: isEditing,
80
+ rowVirtualizer: rowVirtualizer,
81
+ columnVirtualizer: columnVirtualizer
82
+ }));
83
+ }
84
+ return /*#__PURE__*/React.createElement(TableBodyCell, {
85
+ key: column.id,
86
+ table: table,
87
+ cell: row.getVisibleCells().find(c => c.column.id === column.id),
88
+ commandClick: commandClick
89
+ });
90
+ }) : null, virtualPaddingLeft ? /*#__PURE__*/React.createElement("td", {
91
+ className: "",
92
+ style: {
93
+ display: "flex",
94
+ width: virtualPaddingLeft
95
+ }
96
+ }) : null, virtualColumns.map(vc => {
97
+ const cell = visibleCells[vc.index];
98
+ const isFixed = table.getState().columnPinning.left?.includes(cell.column.id) || table.getState().columnPinning.right?.includes(cell.column.id);
99
+ if (cell && !isFixed) {
100
+ if (editAble) {
101
+ return /*#__PURE__*/React.createElement(TableBodyCellEdit, _extends({}, rest, {
102
+ table: table,
103
+ key: cell.id,
104
+ tableId: tableId,
105
+ cell: cell,
106
+ commandClick: commandClick,
107
+ isEditing: isEditing,
108
+ rowVirtualizer: rowVirtualizer,
109
+ columnVirtualizer: columnVirtualizer
110
+ }));
111
+ }
112
+ return /*#__PURE__*/React.createElement(TableBodyCell, {
113
+ table: table,
114
+ key: cell.id,
115
+ cell: cell,
116
+ commandClick: commandClick
117
+ });
118
+ }
119
+ }), fixedRightColumns.length > 0 ? fixedRightColumns.map(column => {
120
+ if (editAble) {
121
+ return /*#__PURE__*/React.createElement(TableBodyCellEdit, _extends({}, rest, {
122
+ table: table,
123
+ key: column.id,
124
+ tableId: tableId,
125
+ cell: row.getVisibleCells().find(c => c.column.id === column.id),
126
+ commandClick: commandClick,
127
+ isEditing: isEditing,
128
+ rowVirtualizer: rowVirtualizer,
129
+ columnVirtualizer: columnVirtualizer
130
+ }));
131
+ }
132
+ return /*#__PURE__*/React.createElement(TableBodyCell, {
133
+ key: column.id,
134
+ table: table,
135
+ cell: row.getVisibleCells().find(c => c.column.id === column.id),
136
+ commandClick: commandClick
137
+ });
138
+ }) : null, virtualPaddingRight ? /*#__PURE__*/React.createElement("td", {
139
+ className: "",
140
+ style: {
141
+ display: "flex",
142
+ width: virtualPaddingRight
143
+ }
144
+ }) : null);
145
+ };
146
+ 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,87 @@
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
+
20
+ // const isEdit = getEditType(column, record)
21
+
22
+ const isEdit = React.useMemo(() => {
23
+ return isEditable(column, record);
24
+ }, [column, record]);
25
+
26
+ // const [isHover, setIsHover] = useState(false)
27
+
28
+ const inputNode = value => {
29
+ return /*#__PURE__*/React.createElement(Checkbox, {
30
+ checked: Boolean(value),
31
+ defaultChecked: Boolean(checked)
32
+ // style={{ textAlign: column.align ?? 'left' }}
33
+ ,
34
+ onChange: val => {
35
+ const newVal = typeof checkValue === "number" ? parseBooleanToValue(val.target.checked, typeof value) : val.target.checked;
36
+
37
+ // onChange(newVal)
38
+
39
+ const key = record[rowKey];
40
+ // const formState = getValues()
41
+
42
+ handleCellChange?.({
43
+ key: key,
44
+ // @ts-ignore
45
+ record: {
46
+ ...record,
47
+ [column.field]: newVal
48
+ },
49
+ option: value,
50
+ prevState: value,
51
+ newState: newVal,
52
+ field: column.field,
53
+ indexCol: colIndex,
54
+ indexRow: rowIndex,
55
+ type: 'blur'
56
+ });
57
+ },
58
+ disabled: isDisable(column, record) ?? false
59
+ });
60
+ };
61
+ return /*#__PURE__*/React.createElement("div", {
62
+ // onMouseEnter={() => {
63
+ // setIsHover(true)
64
+ // }}
65
+ //
66
+ // onMouseLeave={() => {
67
+ // setIsHover(false)
68
+ // }}
69
+ style: {
70
+ display: 'flex',
71
+ alignItems: 'center',
72
+ justifyContent: column.align ?? 'center',
73
+ paddingInline: 5,
74
+ height: '100%',
75
+ width: '100%'
76
+ }
77
+ }, editAble && isEdit !== false ? inputNode(checkValue) : /*#__PURE__*/React.createElement(Checkbox, {
78
+ checked: checked,
79
+ onChange: e => {
80
+ e.preventDefault();
81
+ },
82
+ style: {
83
+ textAlign: column.align ?? 'left'
84
+ }
85
+ }));
86
+ };
87
+ 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";