es-grid-template 1.6.0 → 1.6.2
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/grid-component/EditForm/EditForm.d.ts +27 -0
- package/es/grid-component/EditForm/EditForm.js +394 -0
- package/es/grid-component/EditForm/index.d.ts +1 -0
- package/es/grid-component/EditForm/index.js +1 -0
- package/es/grid-component/EditableCell.js +46 -43
- package/es/grid-component/InternalTable.js +11 -4
- package/es/grid-component/control/InputControl/InputControl.d.ts +27 -0
- package/es/grid-component/control/InputControl/InputControl.js +121 -0
- package/es/grid-component/control/InputControl/index.d.ts +1 -0
- package/es/grid-component/control/InputControl/index.js +1 -0
- package/es/grid-component/table/GridEdit.js +6 -6
- package/es/grid-component/type.d.ts +28 -0
- package/es/grid-component/useContext.d.ts +0 -1
- package/lib/grid-component/EditForm/EditForm.d.ts +27 -0
- package/lib/grid-component/EditForm/EditForm.js +404 -0
- package/lib/grid-component/EditForm/index.d.ts +1 -0
- package/lib/grid-component/EditForm/index.js +16 -0
- package/lib/grid-component/EditableCell.js +46 -43
- package/lib/grid-component/InternalTable.js +8 -3
- package/lib/grid-component/control/InputControl/InputControl.d.ts +27 -0
- package/lib/grid-component/control/InputControl/InputControl.js +131 -0
- package/lib/grid-component/control/InputControl/index.d.ts +1 -0
- package/lib/grid-component/control/InputControl/index.js +16 -0
- package/lib/grid-component/table/GridEdit.js +6 -5
- package/lib/grid-component/type.d.ts +28 -0
- package/lib/grid-component/useContext.d.ts +0 -1
- package/package.json +3 -2
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { Controller } from "react-hook-form";
|
|
3
|
+
import { Input } from "rc-master-ui";
|
|
4
|
+
import { Typography } from "antd";
|
|
5
|
+
import classnames from "classnames";
|
|
6
|
+
import React, { Fragment } from "react";
|
|
7
|
+
// import type { InputType } from "reactstrap/types/lib/Input"
|
|
8
|
+
import { isNullOrUndefined } from "../../hooks";
|
|
9
|
+
import { Col, Row } from "rc-master-ui/es/grid";
|
|
10
|
+
// import {isNullOrUndefined} from "../../../hooks"
|
|
11
|
+
|
|
12
|
+
const {
|
|
13
|
+
Text
|
|
14
|
+
} = Typography;
|
|
15
|
+
const InputControl = props => {
|
|
16
|
+
const {
|
|
17
|
+
id,
|
|
18
|
+
control,
|
|
19
|
+
name,
|
|
20
|
+
type,
|
|
21
|
+
label,
|
|
22
|
+
labelSize,
|
|
23
|
+
required,
|
|
24
|
+
errors,
|
|
25
|
+
height,
|
|
26
|
+
disabled,
|
|
27
|
+
row,
|
|
28
|
+
isLabel,
|
|
29
|
+
placeholder,
|
|
30
|
+
autoFocus,
|
|
31
|
+
inLine,
|
|
32
|
+
callback,
|
|
33
|
+
readOnly,
|
|
34
|
+
classes,
|
|
35
|
+
isView,
|
|
36
|
+
t,
|
|
37
|
+
onKeyDown,
|
|
38
|
+
...rest
|
|
39
|
+
} = props;
|
|
40
|
+
const renderLabel = () => {
|
|
41
|
+
return /*#__PURE__*/React.createElement(Col, {
|
|
42
|
+
span: 8
|
|
43
|
+
}, isLabel === false ? '' : /*#__PURE__*/React.createElement("label", {
|
|
44
|
+
className: "form-label"
|
|
45
|
+
}, t ? t(label ? label : '') : label ? label : '', " ", required ? /*#__PURE__*/React.createElement("span", {
|
|
46
|
+
className: "text-danger"
|
|
47
|
+
}, "*") : '', " "));
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// const renderText = () => {
|
|
51
|
+
// return (
|
|
52
|
+
// <Fragment>
|
|
53
|
+
// <Controller
|
|
54
|
+
// name={name}
|
|
55
|
+
// control={control}
|
|
56
|
+
// render={({ field: { value } }) => (
|
|
57
|
+
// <span>{value}</span>
|
|
58
|
+
// )}
|
|
59
|
+
// />
|
|
60
|
+
// </Fragment>
|
|
61
|
+
// )
|
|
62
|
+
// }
|
|
63
|
+
|
|
64
|
+
const renderInput = () => {
|
|
65
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
66
|
+
style: {
|
|
67
|
+
display: 'flex',
|
|
68
|
+
flexDirection: 'column'
|
|
69
|
+
}
|
|
70
|
+
}, /*#__PURE__*/React.createElement(Controller, {
|
|
71
|
+
name: name,
|
|
72
|
+
control: control,
|
|
73
|
+
render: ({
|
|
74
|
+
field: {
|
|
75
|
+
value,
|
|
76
|
+
onChange
|
|
77
|
+
}
|
|
78
|
+
}) => /*#__PURE__*/React.createElement(Input, _extends({}, rest, {
|
|
79
|
+
id: id,
|
|
80
|
+
value: !isNullOrUndefined(value) ? value : '',
|
|
81
|
+
onChange: val => {
|
|
82
|
+
onChange(val.target.value);
|
|
83
|
+
if (callback) {
|
|
84
|
+
callback(val);
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
style: {
|
|
88
|
+
height: `${height}px`
|
|
89
|
+
},
|
|
90
|
+
autoFocus: autoFocus,
|
|
91
|
+
disabled: disabled,
|
|
92
|
+
placeholder: placeholder,
|
|
93
|
+
type: type ? type : 'text'
|
|
94
|
+
// invalid={errors && true}
|
|
95
|
+
,
|
|
96
|
+
status: errors && true ? 'error' : undefined
|
|
97
|
+
// rows={row}
|
|
98
|
+
,
|
|
99
|
+
readOnly: readOnly,
|
|
100
|
+
onKeyDown: onKeyDown
|
|
101
|
+
}))
|
|
102
|
+
}), errors && /*#__PURE__*/React.createElement(Text, {
|
|
103
|
+
type: "danger"
|
|
104
|
+
}, errors?.message));
|
|
105
|
+
};
|
|
106
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(Row, {
|
|
107
|
+
gutter: [4, 4]
|
|
108
|
+
// className={classnames(' align', {
|
|
109
|
+
// [labelSize ? labelSize : '']: labelSize,
|
|
110
|
+
// [classes ? classes : '']: classes,
|
|
111
|
+
// 'form-row-inline-error': errors
|
|
112
|
+
// }, inLine === false ? 'form-group ' : 'form-row-inline d-flex'
|
|
113
|
+
// )}
|
|
114
|
+
}, renderLabel(), /*#__PURE__*/React.createElement(Col, {
|
|
115
|
+
span: 16,
|
|
116
|
+
className: classnames('', {
|
|
117
|
+
'hidden-label': isLabel === false
|
|
118
|
+
})
|
|
119
|
+
}, renderInput())));
|
|
120
|
+
};
|
|
121
|
+
export default InputControl;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './InputControl';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./InputControl";
|
|
@@ -2,7 +2,8 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import React, { Fragment, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
4
4
|
import classNames from "classnames";
|
|
5
|
-
import {
|
|
5
|
+
// import {Button, Dropdown, Form, Modal, Typography} from "antd"
|
|
6
|
+
import { Button, Dropdown, Modal, Typography } from "antd";
|
|
6
7
|
import { useForm } from 'react-hook-form';
|
|
7
8
|
import { Toaster } from "react-hot-toast";
|
|
8
9
|
import { yupResolver } from "@hookform/resolvers/yup";
|
|
@@ -417,7 +418,8 @@ const GridEdit = props => {
|
|
|
417
418
|
})
|
|
418
419
|
}];
|
|
419
420
|
}, [t, locale]);
|
|
420
|
-
|
|
421
|
+
|
|
422
|
+
// const [form] = Form.useForm()
|
|
421
423
|
|
|
422
424
|
// const [editingKey, setEditingKey] = useState<string | number>('')
|
|
423
425
|
|
|
@@ -1369,7 +1371,7 @@ const GridEdit = props => {
|
|
|
1369
1371
|
const pasteData = e.clipboardData.getData("text/plain");
|
|
1370
1372
|
|
|
1371
1373
|
// Chuyển đổi dữ liệu từ clipboard thành mảng
|
|
1372
|
-
const rowsPasted = pasteData.split("\n").map(row =>
|
|
1374
|
+
const rowsPasted = pasteData.split("\n").filter(row => row !== '').map(row =>
|
|
1373
1375
|
// const rows = pasteData.split("\n").map((row: any) =>
|
|
1374
1376
|
row.replace(/\r/g, "").split("\t"));
|
|
1375
1377
|
if (rowsPasted.length > (onCellPaste?.maxRowsPaste ?? 200)) {
|
|
@@ -1838,7 +1840,6 @@ const GridEdit = props => {
|
|
|
1838
1840
|
indexRow,
|
|
1839
1841
|
key
|
|
1840
1842
|
} = args;
|
|
1841
|
-
if (changeType === 'enter') {}
|
|
1842
1843
|
if (changeType === 'blur') {
|
|
1843
1844
|
const handleChangeCallback = callbackData => {
|
|
1844
1845
|
const callbackRecord = callbackData;
|
|
@@ -2336,7 +2337,6 @@ const GridEdit = props => {
|
|
|
2336
2337
|
// // },
|
|
2337
2338
|
// //
|
|
2338
2339
|
// // onPaste: (event: any) => {
|
|
2339
|
-
// // console.log('3333', event)
|
|
2340
2340
|
// //
|
|
2341
2341
|
// // if (editingKey.current === '') {
|
|
2342
2342
|
// //
|
|
@@ -2555,7 +2555,7 @@ const GridEdit = props => {
|
|
|
2555
2555
|
value: {
|
|
2556
2556
|
id: id ?? '',
|
|
2557
2557
|
rowKey,
|
|
2558
|
-
form,
|
|
2558
|
+
// form,
|
|
2559
2559
|
format,
|
|
2560
2560
|
control,
|
|
2561
2561
|
trigger,
|
|
@@ -132,9 +132,37 @@ export type ColumnTable<RecordType = AnyObject> = Omit<RcColumnType<RecordType>,
|
|
|
132
132
|
max?: number;
|
|
133
133
|
min?: number;
|
|
134
134
|
editSelectSettings?: IEditSelectSettings;
|
|
135
|
+
editFromSettings?: IEditFromSettings;
|
|
135
136
|
fixedType?: FixedType;
|
|
136
137
|
headerTextWrap?: boolean;
|
|
137
138
|
};
|
|
139
|
+
export type IFormOpen = {
|
|
140
|
+
value?: any;
|
|
141
|
+
setValue?: any;
|
|
142
|
+
getValues?: any;
|
|
143
|
+
reset?: any;
|
|
144
|
+
rowData?: any;
|
|
145
|
+
};
|
|
146
|
+
export type IEditFromSettings = {
|
|
147
|
+
fieldKey: string;
|
|
148
|
+
formOpen?: (props: IFormOpen) => void;
|
|
149
|
+
formClose?: (props: IFormOpen) => void;
|
|
150
|
+
formatLabel?: (value: any) => string;
|
|
151
|
+
menuWidth?: number;
|
|
152
|
+
menuHeight?: number;
|
|
153
|
+
labelWith?: number;
|
|
154
|
+
items: any[];
|
|
155
|
+
layout?: {
|
|
156
|
+
xl?: IGrid;
|
|
157
|
+
lg?: IGrid;
|
|
158
|
+
md?: IGrid;
|
|
159
|
+
sm?: IGrid;
|
|
160
|
+
xs?: IGrid;
|
|
161
|
+
};
|
|
162
|
+
defaultValues?: Record<string, any>;
|
|
163
|
+
schema?: any;
|
|
164
|
+
};
|
|
165
|
+
type IGrid = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24;
|
|
138
166
|
export type ColumnTemplate<RecordType> = {
|
|
139
167
|
value: any;
|
|
140
168
|
rowData: RecordType;
|
|
@@ -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,404 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.SelectStyle = exports.EditForm = void 0;
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
10
|
+
var _reactHookForm = require("react-hook-form");
|
|
11
|
+
var _yup = require("@hookform/resolvers/yup");
|
|
12
|
+
var _grid = require("rc-master-ui/es/grid");
|
|
13
|
+
var _InputControl = _interopRequireDefault(require("../control/InputControl/InputControl"));
|
|
14
|
+
var _hooks = require("../hooks");
|
|
15
|
+
var _rcMasterUi = require("rc-master-ui");
|
|
16
|
+
var _antd = require("antd");
|
|
17
|
+
var _divider = _interopRequireDefault(require("rc-master-ui/es/divider"));
|
|
18
|
+
var _button = _interopRequireDefault(require("rc-master-ui/es/button"));
|
|
19
|
+
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); }
|
|
20
|
+
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; }
|
|
21
|
+
const SelectStyle = exports.SelectStyle = _styledComponents.default.div.withConfig({
|
|
22
|
+
displayName: "SelectStyle",
|
|
23
|
+
componentId: "es-grid-template__sc-7ba05m-0"
|
|
24
|
+
})(["width:100%;&.be-select{.input-group-merge{flex-wrap:nowrap;}}"]);
|
|
25
|
+
const EditForm = props => {
|
|
26
|
+
const {
|
|
27
|
+
id,
|
|
28
|
+
// menuPortalTarget,
|
|
29
|
+
value,
|
|
30
|
+
fieldKey,
|
|
31
|
+
placeholder,
|
|
32
|
+
// invalid,
|
|
33
|
+
menuHeight,
|
|
34
|
+
menuWidth,
|
|
35
|
+
// classNamePrefix,
|
|
36
|
+
onChange,
|
|
37
|
+
rowData,
|
|
38
|
+
// onKeyDown,
|
|
39
|
+
t,
|
|
40
|
+
cellFocus,
|
|
41
|
+
column
|
|
42
|
+
} = props;
|
|
43
|
+
const formRef = (0, _react.useRef)();
|
|
44
|
+
const divRef = (0, _react.useRef)(null);
|
|
45
|
+
const inputRef = (0, _react.useRef)(null);
|
|
46
|
+
const defaultValue = !(0, _hooks.isNullOrUndefined)(value) ? column?.editFromSettings?.formatLabel ? column?.editFromSettings?.formatLabel(value) : value[fieldKey] : '';
|
|
47
|
+
const {
|
|
48
|
+
control,
|
|
49
|
+
handleSubmit,
|
|
50
|
+
getValues,
|
|
51
|
+
reset,
|
|
52
|
+
setValue,
|
|
53
|
+
setError,
|
|
54
|
+
formState: {
|
|
55
|
+
errors
|
|
56
|
+
}
|
|
57
|
+
} = (0, _reactHookForm.useForm)({
|
|
58
|
+
mode: 'onChange',
|
|
59
|
+
defaultValues: column.editFromSettings?.defaultValues,
|
|
60
|
+
resolver: column.editFromSettings?.schema ? (0, _yup.yupResolver)(column.editFromSettings?.schema) : undefined
|
|
61
|
+
});
|
|
62
|
+
const handleToggle = () => {
|
|
63
|
+
divRef?.current?.click(); // Giả lập click vào nút để mở dropdown
|
|
64
|
+
};
|
|
65
|
+
_react.default.useEffect(() => {
|
|
66
|
+
if (cellFocus) {
|
|
67
|
+
handleToggle();
|
|
68
|
+
}
|
|
69
|
+
}, [cellFocus]);
|
|
70
|
+
const handleOnSubmit = val => {
|
|
71
|
+
handleToggle();
|
|
72
|
+
onChange(val);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// const handleOnKeyDown = (e: any) => {
|
|
76
|
+
//
|
|
77
|
+
// if (dropdownOpen) {
|
|
78
|
+
// e.preventDefault()
|
|
79
|
+
//
|
|
80
|
+
// if (e.code === 'Tab') {
|
|
81
|
+
// e.stopPropagation()
|
|
82
|
+
// const formElement = document.getElementById('edit-form')
|
|
83
|
+
//
|
|
84
|
+
// if (formElement) {
|
|
85
|
+
//
|
|
86
|
+
// formElement.getElementsByTagName('input')[0]?.focus()
|
|
87
|
+
//
|
|
88
|
+
// }
|
|
89
|
+
//
|
|
90
|
+
// }
|
|
91
|
+
//
|
|
92
|
+
// if (e.code === "Escape") {
|
|
93
|
+
// e.preventDefault()
|
|
94
|
+
// e.stopPropagation()
|
|
95
|
+
// return e
|
|
96
|
+
// }
|
|
97
|
+
//
|
|
98
|
+
// const formElement = document.getElementById('edit-form')
|
|
99
|
+
//
|
|
100
|
+
// if (formElement) {
|
|
101
|
+
//
|
|
102
|
+
// formElement.getElementsByTagName('input')[0]?.focus()
|
|
103
|
+
//
|
|
104
|
+
// }
|
|
105
|
+
// return e.code
|
|
106
|
+
//
|
|
107
|
+
//
|
|
108
|
+
// } else {
|
|
109
|
+
// if (e.code === 'ArrowDown') {
|
|
110
|
+
// e.preventDefault()
|
|
111
|
+
//
|
|
112
|
+
// setTimeout(() => {
|
|
113
|
+
// const formElement = document.getElementById('edit-form')
|
|
114
|
+
// if (formElement) {
|
|
115
|
+
// formElement.getElementsByTagName('input')[0]?.focus()
|
|
116
|
+
//
|
|
117
|
+
// }
|
|
118
|
+
//
|
|
119
|
+
// }, 100)
|
|
120
|
+
//
|
|
121
|
+
//
|
|
122
|
+
// }
|
|
123
|
+
// }
|
|
124
|
+
//
|
|
125
|
+
// if (onKeyDown) {
|
|
126
|
+
// onKeyDown(e)
|
|
127
|
+
// }
|
|
128
|
+
//
|
|
129
|
+
//
|
|
130
|
+
// }
|
|
131
|
+
//
|
|
132
|
+
|
|
133
|
+
const handleOnFocus = e => {
|
|
134
|
+
e.target.setSelectionRange(0, e.target.innerText.length - 1);
|
|
135
|
+
};
|
|
136
|
+
const formItemKeyDown = (e, index, length) => {
|
|
137
|
+
if (e.code === 'Tab' || e.code === 'ArrowDown') {
|
|
138
|
+
const itemElement = document.getElementById(`edit-form-${index + 1}`);
|
|
139
|
+
if (itemElement && index < length) {
|
|
140
|
+
if (itemElement.className.includes('be-select')) {
|
|
141
|
+
itemElement.getElementsByTagName('input')[0]?.focus();
|
|
142
|
+
} else {
|
|
143
|
+
itemElement.focus();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
e.preventDefault();
|
|
147
|
+
}
|
|
148
|
+
if (e.code === 'ArrowUp') {
|
|
149
|
+
const itemElement = document.getElementById(`edit-form-${index - 1}`);
|
|
150
|
+
if (itemElement && index !== 0) {
|
|
151
|
+
if (itemElement.className.includes('be-select')) {
|
|
152
|
+
itemElement.getElementsByTagName('input')[0]?.focus();
|
|
153
|
+
} else {
|
|
154
|
+
itemElement.focus();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
e.preventDefault();
|
|
158
|
+
}
|
|
159
|
+
if (e.code === 'Enter') {
|
|
160
|
+
if ((0, _hooks.isObjEmpty)(errors)) {
|
|
161
|
+
const rs = getValues();
|
|
162
|
+
if (column.editFromSettings?.schema) {
|
|
163
|
+
column.editFromSettings?.schema.validate(rs, {
|
|
164
|
+
abortEarly: false
|
|
165
|
+
}).then(() => {
|
|
166
|
+
handleToggle();
|
|
167
|
+
onChange(rs);
|
|
168
|
+
if (column.editFromSettings && column?.editFromSettings?.formClose) {
|
|
169
|
+
column?.editFromSettings?.formClose({
|
|
170
|
+
value,
|
|
171
|
+
setValue,
|
|
172
|
+
getValues,
|
|
173
|
+
reset
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
if (inputRef) {
|
|
177
|
+
inputRef.current.focus();
|
|
178
|
+
}
|
|
179
|
+
}).catch(err => {
|
|
180
|
+
e.preventDefault();
|
|
181
|
+
e.stopPropagation();
|
|
182
|
+
err.inner.forEach(error => {
|
|
183
|
+
setError(error.path ? error.path : '', {
|
|
184
|
+
type: "manual",
|
|
185
|
+
message: error.message
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
} else {
|
|
191
|
+
e.preventDefault();
|
|
192
|
+
e.stopPropagation();
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
// const checkErrors = () => {
|
|
198
|
+
//
|
|
199
|
+
//
|
|
200
|
+
// if (isObjEmpty(errors)) {
|
|
201
|
+
// const rs = getValues()
|
|
202
|
+
// if (column.editFromSettings?.schema) {
|
|
203
|
+
// column.editFromSettings?.schema.validate(rs, { abortEarly: false })
|
|
204
|
+
// .then(() => {
|
|
205
|
+
// handleToggle()
|
|
206
|
+
// onChange(rs)
|
|
207
|
+
//
|
|
208
|
+
// if (column.editFromSettings && column?.editFromSettings?.formClose) {
|
|
209
|
+
// column?.editFromSettings?.formClose({value, setValue, getValues, reset})
|
|
210
|
+
// }
|
|
211
|
+
// if (inputRef) {
|
|
212
|
+
// inputRef.current.focus()
|
|
213
|
+
// }
|
|
214
|
+
// })
|
|
215
|
+
// .catch((err: ValidationError) => {
|
|
216
|
+
//
|
|
217
|
+
// err.inner.forEach((error: ValidationError) => {
|
|
218
|
+
//
|
|
219
|
+
// setError(error.path ? error.path : '', {
|
|
220
|
+
// type: "manual",
|
|
221
|
+
// message: error.message
|
|
222
|
+
// })
|
|
223
|
+
// })
|
|
224
|
+
// })
|
|
225
|
+
// }
|
|
226
|
+
//
|
|
227
|
+
//
|
|
228
|
+
// } else {
|
|
229
|
+
//
|
|
230
|
+
// }
|
|
231
|
+
// }
|
|
232
|
+
|
|
233
|
+
const handleFormKeydown = e => {
|
|
234
|
+
// if (dropdownOpen) {
|
|
235
|
+
|
|
236
|
+
if (e.code === 'Tab' || e.code === 'ArrowUp' || e.code === 'ArrowDown') {
|
|
237
|
+
e.preventDefault();
|
|
238
|
+
e.stopPropagation();
|
|
239
|
+
// if (formElement && indexRowForm <= totalRowFrom) {
|
|
240
|
+
// setIndexRowForm((prevState) => prevState + 1)
|
|
241
|
+
// formElement.getElementsByTagName('input')[indexRowForm + 1]?.focus()
|
|
242
|
+
// }
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// if (e.code === 'Enter') {
|
|
246
|
+
// const rs = getValues()
|
|
247
|
+
//
|
|
248
|
+
//
|
|
249
|
+
// onChange(rs)
|
|
250
|
+
//
|
|
251
|
+
// if (column.editFromSettings && column?.editFromSettings?.formClose) {
|
|
252
|
+
// column?.editFromSettings?.formClose({value, setValue, getValues, reset})
|
|
253
|
+
// }
|
|
254
|
+
// if (inputRef) {
|
|
255
|
+
// inputRef.current.focus()
|
|
256
|
+
// }
|
|
257
|
+
//
|
|
258
|
+
// e.preventDefault()
|
|
259
|
+
// e.stopPropagation()
|
|
260
|
+
// }
|
|
261
|
+
|
|
262
|
+
if (e.code === "Escape") {
|
|
263
|
+
handleToggle();
|
|
264
|
+
if (inputRef) {
|
|
265
|
+
inputRef.current.focus();
|
|
266
|
+
}
|
|
267
|
+
e.preventDefault();
|
|
268
|
+
e.stopPropagation();
|
|
269
|
+
}
|
|
270
|
+
return e.code;
|
|
271
|
+
// }
|
|
272
|
+
};
|
|
273
|
+
const renderForm = rows => {
|
|
274
|
+
return /*#__PURE__*/_react.default.createElement(_grid.Row, {
|
|
275
|
+
gutter: [0, 10]
|
|
276
|
+
}, rows.map((item, index) => {
|
|
277
|
+
return /*#__PURE__*/_react.default.createElement(_grid.Col, {
|
|
278
|
+
key: `${index}`,
|
|
279
|
+
xl: column.editFromSettings?.layout?.xl ? column.editFromSettings?.layout?.xl : 24,
|
|
280
|
+
lg: column.editFromSettings?.layout?.lg ? column.editFromSettings?.layout?.lg : 24,
|
|
281
|
+
md: column.editFromSettings?.layout?.md ? column.editFromSettings?.layout?.md : 24,
|
|
282
|
+
sm: column.editFromSettings?.layout?.sm ? column.editFromSettings?.layout?.sm : 24,
|
|
283
|
+
xs: column.editFromSettings?.layout?.xs ? column.editFromSettings?.layout?.xs : 24,
|
|
284
|
+
className: 'mb-1'
|
|
285
|
+
}, /*#__PURE__*/_react.default.createElement(_InputControl.default, {
|
|
286
|
+
id: `edit-form-${index}`,
|
|
287
|
+
t: t,
|
|
288
|
+
control: control
|
|
289
|
+
// name={`specificationCode${index + 1}`}
|
|
290
|
+
,
|
|
291
|
+
name: item.name,
|
|
292
|
+
label: item.label ? item.label : '',
|
|
293
|
+
labelSize: "label-medium",
|
|
294
|
+
errors: errors[item.name],
|
|
295
|
+
onKeyDown: e => formItemKeyDown(e, index, column.editFromSettings?.items ? column.editFromSettings?.items.length : 0)
|
|
296
|
+
}));
|
|
297
|
+
}));
|
|
298
|
+
};
|
|
299
|
+
const contentStyle = {
|
|
300
|
+
padding: 6,
|
|
301
|
+
width: menuWidth,
|
|
302
|
+
backgroundColor: '#fff',
|
|
303
|
+
borderRadius: '6px',
|
|
304
|
+
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)'
|
|
305
|
+
};
|
|
306
|
+
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(SelectStyle, {
|
|
307
|
+
ref: formRef,
|
|
308
|
+
id: id ? id : ''
|
|
309
|
+
}, /*#__PURE__*/_react.default.createElement(_antd.Dropdown, {
|
|
310
|
+
menu: {
|
|
311
|
+
items: []
|
|
312
|
+
},
|
|
313
|
+
autoFocus: true,
|
|
314
|
+
onOpenChange: open => {
|
|
315
|
+
if (open) {
|
|
316
|
+
setTimeout(() => {
|
|
317
|
+
const formElement = document.getElementById('edit-form-0');
|
|
318
|
+
if (formElement) {
|
|
319
|
+
formElement.focus();
|
|
320
|
+
}
|
|
321
|
+
}, 10);
|
|
322
|
+
if (column.editFromSettings && column?.editFromSettings?.formOpen) {
|
|
323
|
+
column?.editFromSettings?.formOpen({
|
|
324
|
+
value,
|
|
325
|
+
setValue,
|
|
326
|
+
getValues,
|
|
327
|
+
reset,
|
|
328
|
+
rowData
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
} else {
|
|
332
|
+
if (column.editFromSettings && column?.editFromSettings?.formClose) {
|
|
333
|
+
column?.editFromSettings?.formClose({
|
|
334
|
+
value,
|
|
335
|
+
setValue,
|
|
336
|
+
getValues,
|
|
337
|
+
reset,
|
|
338
|
+
rowData
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
trigger: ['click'],
|
|
344
|
+
destroyPopupOnHide: true,
|
|
345
|
+
rootClassName: 'be-popup-container',
|
|
346
|
+
dropdownRender: () => /*#__PURE__*/_react.default.createElement("div", {
|
|
347
|
+
style: contentStyle,
|
|
348
|
+
onKeyDown: e => handleFormKeydown(e),
|
|
349
|
+
onClick: e => {
|
|
350
|
+
e.preventDefault();
|
|
351
|
+
e.stopPropagation();
|
|
352
|
+
}
|
|
353
|
+
}, /*#__PURE__*/_react.default.createElement("form", {
|
|
354
|
+
className: "todo-modal",
|
|
355
|
+
onSubmit: handleSubmit(handleOnSubmit)
|
|
356
|
+
}, /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("div", {
|
|
357
|
+
className: 'p-1',
|
|
358
|
+
style: {
|
|
359
|
+
maxHeight: menuHeight ? menuHeight : 300,
|
|
360
|
+
overflow: "auto"
|
|
361
|
+
}
|
|
362
|
+
}, column.editFromSettings?.items ? renderForm(column.editFromSettings?.items) : ''), /*#__PURE__*/_react.default.createElement(_divider.default, {
|
|
363
|
+
style: {
|
|
364
|
+
margin: 0
|
|
365
|
+
}
|
|
366
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
367
|
+
className: "d-flex justify-content-end p-1"
|
|
368
|
+
// style={{ boxShadow: "0 4px 24px 0 rgb(34 41 47 / 10%)" }}
|
|
369
|
+
}, /*#__PURE__*/_react.default.createElement(_button.default, {
|
|
370
|
+
variant: "solid",
|
|
371
|
+
className: ""
|
|
372
|
+
// onSubmit={handleSubmit(handleOnSubmit)}
|
|
373
|
+
,
|
|
374
|
+
onClick: handleSubmit(handleOnSubmit),
|
|
375
|
+
color: "primary",
|
|
376
|
+
style: {}
|
|
377
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
378
|
+
className: "d-flex "
|
|
379
|
+
}, t ? t('Save') : 'Save'))))))
|
|
380
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
381
|
+
ref: divRef,
|
|
382
|
+
style: {
|
|
383
|
+
height: '100%'
|
|
384
|
+
}
|
|
385
|
+
}, /*#__PURE__*/_react.default.createElement(_rcMasterUi.Input, {
|
|
386
|
+
style: {
|
|
387
|
+
borderRadius: 0,
|
|
388
|
+
height: '100%'
|
|
389
|
+
},
|
|
390
|
+
ref: inputRef,
|
|
391
|
+
defaultValue: defaultValue,
|
|
392
|
+
value: defaultValue,
|
|
393
|
+
placeholder: placeholder,
|
|
394
|
+
className: 'be-select__input'
|
|
395
|
+
// onChange={handleOnChange}
|
|
396
|
+
,
|
|
397
|
+
onFocus: handleOnFocus
|
|
398
|
+
// onClick={handleOnClick}
|
|
399
|
+
// onKeyDown={handleOnKeyDown}
|
|
400
|
+
,
|
|
401
|
+
readOnly: true
|
|
402
|
+
})))));
|
|
403
|
+
};
|
|
404
|
+
exports.EditForm = EditForm;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './EditForm';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _EditForm = require("./EditForm");
|
|
7
|
+
Object.keys(_EditForm).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _EditForm[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _EditForm[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|