ronds-metadata 1.0.41 → 1.0.44
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/comps/Editable/DataCell/Input.js +31 -3
- package/es/comps/Editable/DataCell/Number.js +23 -3
- package/es/comps/Editable/DataCell/Select.js +8 -2
- package/es/comps/Editable/DataCell/Switch.js +11 -3
- package/es/comps/Editable/comps/EditableAction.d.ts +1 -1
- package/es/comps/Editable/comps/EditableAction.js +6 -6
- package/es/comps/Editable/comps/EditableCell.d.ts +1 -0
- package/es/comps/Editable/comps/EditableCell.js +49 -10
- package/es/comps/Editable/comps/index.css +0 -0
- package/es/comps/Editable/index.d.ts +8 -4
- package/es/comps/Editable/index.js +94 -20
- package/es/comps/Editable/interface.d.ts +22 -12
- package/es/comps/Editable/interface.js +1 -1
- package/es/comps/Editable/utils.d.ts +3 -0
- package/es/comps/Editable/utils.js +19 -1
- package/es/index.d.ts +1 -0
- package/es/index.js +2 -1
- package/package.json +1 -1
@@ -6,18 +6,46 @@ import _Input from "antd/es/input";
|
|
6
6
|
/*
|
7
7
|
* @Author: wangxian
|
8
8
|
* @Date: 2022-03-04 14:53:50
|
9
|
-
* @LastEditTime: 2022-03-
|
9
|
+
* @LastEditTime: 2022-03-09 11:13:21
|
10
10
|
*/
|
11
11
|
import React from 'react';
|
12
|
+
import { EditableContext } from '../interface';
|
12
13
|
|
13
14
|
function Index(props) {
|
14
|
-
var dataIndex = props.dataIndex
|
15
|
+
var dataIndex = props.dataIndex,
|
16
|
+
rowIndex = props.rowIndex,
|
17
|
+
disabled = props.disabled;
|
18
|
+
|
19
|
+
var _ref = React.useContext(EditableContext) || undefined,
|
20
|
+
editConfig = _ref.editConfig;
|
21
|
+
|
22
|
+
var inputRef = React.useRef();
|
23
|
+
var firstLoadRef = React.useRef(true);
|
24
|
+
React.useEffect(function () {
|
25
|
+
var _editConfig$editCellK, _editConfig$editCellK2;
|
26
|
+
|
27
|
+
if (!inputRef.current) return;
|
28
|
+
|
29
|
+
if (((_editConfig$editCellK = editConfig.editCellKey) === null || _editConfig$editCellK === void 0 ? void 0 : _editConfig$editCellK.dataIndex) === dataIndex && ((_editConfig$editCellK2 = editConfig.editCellKey) === null || _editConfig$editCellK2 === void 0 ? void 0 : _editConfig$editCellK2.rowIndex) === rowIndex) {
|
30
|
+
if (firstLoadRef.current) {
|
31
|
+
// 选中内容
|
32
|
+
inputRef.current.input.setSelectionRange(0, inputRef.current.state.value.length);
|
33
|
+
firstLoadRef.current = false;
|
34
|
+
} // 设置焦点
|
35
|
+
|
36
|
+
|
37
|
+
inputRef.current.focus();
|
38
|
+
}
|
39
|
+
}, [editConfig]);
|
15
40
|
return /*#__PURE__*/React.createElement(_Form.Item, {
|
16
41
|
name: dataIndex,
|
17
42
|
style: {
|
18
43
|
margin: 0
|
19
44
|
}
|
20
|
-
}, /*#__PURE__*/React.createElement(_Input,
|
45
|
+
}, /*#__PURE__*/React.createElement(_Input, {
|
46
|
+
ref: inputRef,
|
47
|
+
disabled: editConfig.type === 'edit' ? disabled : false
|
48
|
+
}));
|
21
49
|
}
|
22
50
|
|
23
51
|
export default /*#__PURE__*/React.memo(Index);
|
@@ -6,18 +6,38 @@ import _InputNumber from "antd/es/input-number";
|
|
6
6
|
/*
|
7
7
|
* @Author: wangxian
|
8
8
|
* @Date: 2022-03-04 14:53:50
|
9
|
-
* @LastEditTime: 2022-03-
|
9
|
+
* @LastEditTime: 2022-03-08 17:26:48
|
10
10
|
*/
|
11
11
|
import React from 'react';
|
12
|
+
import { EditableContext } from '../interface';
|
12
13
|
|
13
14
|
function Index(props) {
|
14
|
-
var dataIndex = props.dataIndex
|
15
|
+
var dataIndex = props.dataIndex,
|
16
|
+
rowIndex = props.rowIndex,
|
17
|
+
disabled = props.disabled;
|
18
|
+
|
19
|
+
var _ref = React.useContext(EditableContext) || undefined,
|
20
|
+
editConfig = _ref.editConfig;
|
21
|
+
|
22
|
+
var inputRef = React.useRef();
|
23
|
+
React.useEffect(function () {
|
24
|
+
var _editConfig$editCellK, _editConfig$editCellK2;
|
25
|
+
|
26
|
+
if (!inputRef.current) return;
|
27
|
+
|
28
|
+
if (((_editConfig$editCellK = editConfig.editCellKey) === null || _editConfig$editCellK === void 0 ? void 0 : _editConfig$editCellK.dataIndex) === dataIndex && ((_editConfig$editCellK2 = editConfig.editCellKey) === null || _editConfig$editCellK2 === void 0 ? void 0 : _editConfig$editCellK2.rowIndex) === rowIndex) {
|
29
|
+
inputRef.current.focus(); // 设置焦点
|
30
|
+
}
|
31
|
+
}, [editConfig]);
|
15
32
|
return /*#__PURE__*/React.createElement(_Form.Item, {
|
16
33
|
name: dataIndex,
|
17
34
|
style: {
|
18
35
|
margin: 0
|
19
36
|
}
|
20
|
-
}, /*#__PURE__*/React.createElement(_InputNumber,
|
37
|
+
}, /*#__PURE__*/React.createElement(_InputNumber, {
|
38
|
+
ref: inputRef,
|
39
|
+
disabled: editConfig.type === 'edit' ? disabled : false
|
40
|
+
}));
|
21
41
|
}
|
22
42
|
|
23
43
|
export default /*#__PURE__*/React.memo(Index);
|
@@ -3,25 +3,31 @@ import _Form from "antd/es/form";
|
|
3
3
|
import "antd/es/select/style";
|
4
4
|
import _Select from "antd/es/select";
|
5
5
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
6
|
-
var _excluded = ["dataIndex"];
|
6
|
+
var _excluded = ["dataIndex", "disabled"];
|
7
7
|
|
8
8
|
/*
|
9
9
|
* @Author: wangxian
|
10
10
|
* @Date: 2022-03-04 14:53:50
|
11
|
-
* @LastEditTime: 2022-03-
|
11
|
+
* @LastEditTime: 2022-03-08 14:14:18
|
12
12
|
*/
|
13
13
|
import React from 'react';
|
14
|
+
import { EditableContext } from '../interface';
|
14
15
|
|
15
16
|
function Index(props) {
|
16
17
|
var dataIndex = props.dataIndex,
|
18
|
+
disabled = props.disabled,
|
17
19
|
restProps = _objectWithoutProperties(props, _excluded);
|
18
20
|
|
21
|
+
var _ref = React.useContext(EditableContext) || undefined,
|
22
|
+
editConfig = _ref.editConfig;
|
23
|
+
|
19
24
|
return /*#__PURE__*/React.createElement(_Form.Item, {
|
20
25
|
name: dataIndex,
|
21
26
|
style: {
|
22
27
|
margin: 0
|
23
28
|
}
|
24
29
|
}, /*#__PURE__*/React.createElement(_Select, {
|
30
|
+
disabled: editConfig.type === 'edit' ? disabled : false,
|
25
31
|
style: {
|
26
32
|
width: '100%'
|
27
33
|
},
|
@@ -6,19 +6,27 @@ import _Switch from "antd/es/switch";
|
|
6
6
|
/*
|
7
7
|
* @Author: wangxian
|
8
8
|
* @Date: 2022-03-04 14:53:50
|
9
|
-
* @LastEditTime: 2022-03-
|
9
|
+
* @LastEditTime: 2022-03-08 14:14:22
|
10
10
|
*/
|
11
11
|
import React from 'react';
|
12
|
+
import { EditableContext } from '../interface';
|
12
13
|
|
13
14
|
function Index(props) {
|
14
|
-
var dataIndex = props.dataIndex
|
15
|
+
var dataIndex = props.dataIndex,
|
16
|
+
disabled = props.disabled;
|
17
|
+
|
18
|
+
var _ref = React.useContext(EditableContext) || undefined,
|
19
|
+
editConfig = _ref.editConfig;
|
20
|
+
|
15
21
|
return /*#__PURE__*/React.createElement(_Form.Item, {
|
16
22
|
name: dataIndex,
|
17
23
|
valuePropName: "checked",
|
18
24
|
style: {
|
19
25
|
margin: 0
|
20
26
|
}
|
21
|
-
}, /*#__PURE__*/React.createElement(_Switch,
|
27
|
+
}, /*#__PURE__*/React.createElement(_Switch, {
|
28
|
+
disabled: editConfig.type === 'edit' ? disabled : false
|
29
|
+
}));
|
22
30
|
}
|
23
31
|
|
24
32
|
export default /*#__PURE__*/React.memo(Index);
|
@@ -12,7 +12,7 @@ var EditableAction = function EditableAction(props) {
|
|
12
12
|
|
13
13
|
var _ref = React.useContext(EditableContext) || undefined,
|
14
14
|
editableStream = _ref.editableStream,
|
15
|
-
|
15
|
+
editConfig = _ref.editConfig;
|
16
16
|
|
17
17
|
var onEdit = function onEdit() {
|
18
18
|
editableStream.next({
|
@@ -44,16 +44,16 @@ var EditableAction = function EditableAction(props) {
|
|
44
44
|
});
|
45
45
|
};
|
46
46
|
|
47
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, type === 'single' && /*#__PURE__*/React.createElement(React.Fragment, null,
|
47
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, type === 'single' && /*#__PURE__*/React.createElement(React.Fragment, null, editConfig.curRow !== record._rowKey_ && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_Button, {
|
48
48
|
type: "link",
|
49
|
-
disabled: (
|
49
|
+
disabled: (editConfig.curRow || editConfig.curRow === 0) && editConfig.curRow !== record._rowKey_,
|
50
50
|
size: "small",
|
51
51
|
icon: /*#__PURE__*/React.createElement(EditOutlined, null),
|
52
52
|
onClick: onEdit,
|
53
53
|
title: '编辑'
|
54
54
|
}), /*#__PURE__*/React.createElement(_Divider, {
|
55
55
|
type: "vertical"
|
56
|
-
})),
|
56
|
+
})), editConfig.curRow === record._rowKey_ && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_Button, {
|
57
57
|
type: "link",
|
58
58
|
size: "small",
|
59
59
|
icon: /*#__PURE__*/React.createElement(CheckOutlined, null),
|
@@ -61,7 +61,7 @@ var EditableAction = function EditableAction(props) {
|
|
61
61
|
title: '确定'
|
62
62
|
}), /*#__PURE__*/React.createElement(_Divider, {
|
63
63
|
type: "vertical"
|
64
|
-
}), /*#__PURE__*/React.createElement(_Button, {
|
64
|
+
}), editConfig.type === 'edit' && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_Button, {
|
65
65
|
type: "link",
|
66
66
|
size: "small",
|
67
67
|
icon: /*#__PURE__*/React.createElement(CloseOutlined, null),
|
@@ -69,7 +69,7 @@ var EditableAction = function EditableAction(props) {
|
|
69
69
|
title: '取消'
|
70
70
|
}), /*#__PURE__*/React.createElement(_Divider, {
|
71
71
|
type: "vertical"
|
72
|
-
}))), /*#__PURE__*/React.createElement(_Button, {
|
72
|
+
})))), /*#__PURE__*/React.createElement(_Button, {
|
73
73
|
type: "link",
|
74
74
|
size: "small",
|
75
75
|
icon: /*#__PURE__*/React.createElement(DeleteOutlined, null),
|
@@ -1,17 +1,16 @@
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
2
|
+
import "antd/es/message/style";
|
3
|
+
import _message from "antd/es/message";
|
1
4
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
2
|
-
var _excluded = ["editable", "editableType", "dataIndex", "rowIndex", "children"];
|
3
|
-
|
4
|
-
/*
|
5
|
-
* @Author: wangxian
|
6
|
-
* @Date: 2022-03-04 10:01:10
|
7
|
-
* @LastEditTime: 2022-03-07 13:40:57
|
8
|
-
*/
|
5
|
+
var _excluded = ["editable", "record", "editableType", "dataIndex", "rowIndex", "children"];
|
9
6
|
import React from 'react';
|
10
7
|
import { EditableContext } from '../interface';
|
11
|
-
import { getDataCell } from '../utils';
|
8
|
+
import { getDataCell, isFreeEditCell, isFreeEditRow } from '../utils';
|
9
|
+
import "./index.css";
|
12
10
|
|
13
11
|
var EditableCell = function EditableCell(props) {
|
14
12
|
var editable = props.editable,
|
13
|
+
record = props.record,
|
15
14
|
editableType = props.editableType,
|
16
15
|
dataIndex = props.dataIndex,
|
17
16
|
rowIndex = props.rowIndex,
|
@@ -19,10 +18,50 @@ var EditableCell = function EditableCell(props) {
|
|
19
18
|
restProps = _objectWithoutProperties(props, _excluded);
|
20
19
|
|
21
20
|
var _ref = React.useContext(EditableContext) || undefined,
|
22
|
-
|
21
|
+
editableStream = _ref.editableStream,
|
22
|
+
editConfig = _ref.editConfig;
|
23
|
+
|
24
|
+
var onCellDoubleClick = function onCellDoubleClick() {
|
25
|
+
if (editConfig === null || editConfig === void 0 ? void 0 : editConfig.curRow) {
|
26
|
+
var _editConfig$curRow;
|
27
|
+
|
28
|
+
if (((_editConfig$curRow = editConfig.curRow) === null || _editConfig$curRow === void 0 ? void 0 : _editConfig$curRow.toString().split(',').indexOf("".concat(rowIndex))) > -1) return;
|
29
|
+
|
30
|
+
_message.warning('请先保存正在编辑的行');
|
31
|
+
|
32
|
+
return;
|
33
|
+
}
|
34
|
+
|
35
|
+
editableStream.next({
|
36
|
+
type: 'editCellKey',
|
37
|
+
payload: {
|
38
|
+
dataIndex: dataIndex,
|
39
|
+
rowIndex: rowIndex
|
40
|
+
}
|
41
|
+
});
|
42
|
+
};
|
43
|
+
|
44
|
+
var onCellClick = function onCellClick() {
|
45
|
+
if (!isFreeEditCell(editConfig.editCellKey, dataIndex, rowIndex)) {
|
46
|
+
editableStream.next({
|
47
|
+
type: 'editCellKey',
|
48
|
+
payload: {
|
49
|
+
dataIndex: undefined,
|
50
|
+
rowIndex: undefined
|
51
|
+
}
|
52
|
+
});
|
53
|
+
}
|
54
|
+
};
|
23
55
|
|
24
56
|
if (editableType === 'single') {
|
25
|
-
return /*#__PURE__*/React.createElement("td", restProps, editable &&
|
57
|
+
return /*#__PURE__*/React.createElement("td", restProps, editable && editConfig.curRow === rowIndex ? getDataCell(props) : children);
|
58
|
+
}
|
59
|
+
|
60
|
+
if (editableType === 'freedom') {
|
61
|
+
return /*#__PURE__*/React.createElement("td", _extends({
|
62
|
+
onDoubleClick: onCellDoubleClick,
|
63
|
+
onClick: onCellClick
|
64
|
+
}, restProps), editable && (isFreeEditRow(editConfig.curRow, rowIndex) || isFreeEditCell(editConfig.editCellKey, dataIndex, rowIndex)) ? getDataCell(props) : children);
|
26
65
|
}
|
27
66
|
|
28
67
|
return /*#__PURE__*/React.createElement("td", restProps, editable ? getDataCell(props) : children);
|
File without changes
|
@@ -1,21 +1,25 @@
|
|
1
1
|
import { TableProps } from 'antd';
|
2
2
|
import { BehaviorSubject } from 'rxjs';
|
3
|
-
import { EditColumnsType, IEditableStream
|
3
|
+
import { EditColumnsType, IEditableStream } from './interface';
|
4
4
|
interface IEditableProps<R = any> {
|
5
5
|
/**
|
6
6
|
* 单行编辑或多行编辑。
|
7
7
|
* 备注:
|
8
8
|
* type为multiple时,一定要设置defaultValue
|
9
9
|
*/
|
10
|
-
type?: 'single' | 'multiple';
|
10
|
+
type?: 'single' | 'multiple' | 'freedom';
|
11
11
|
/**
|
12
12
|
* 表格列的配置描述
|
13
13
|
*/
|
14
14
|
columns: EditColumnsType;
|
15
15
|
/**
|
16
|
-
*
|
16
|
+
* 新增一列 默认的值
|
17
17
|
*/
|
18
|
-
|
18
|
+
defaultValue?: any;
|
19
|
+
/**
|
20
|
+
* 添加行的位置
|
21
|
+
*/
|
22
|
+
addPosition?: 'top' | 'bottom';
|
19
23
|
/**
|
20
24
|
* 数据数组
|
21
25
|
*/
|
@@ -3,10 +3,10 @@ import _Button from "antd/es/button";
|
|
3
3
|
import "antd/es/table/style";
|
4
4
|
import _Table from "antd/es/table";
|
5
5
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
6
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
7
|
-
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
8
6
|
import "antd/es/message/style";
|
9
7
|
import _message from "antd/es/message";
|
8
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
9
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
10
10
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
11
11
|
import React from 'react';
|
12
12
|
import { BehaviorSubject } from 'rxjs';
|
@@ -15,6 +15,7 @@ import EditableCell from './comps/EditableCell';
|
|
15
15
|
import EditableRow from './comps/EditableRow';
|
16
16
|
import { EditableContext } from './interface';
|
17
17
|
import EditableAction from './comps/EditableAction';
|
18
|
+
import { isFreeEditRow, removeCurKeyFromEditRow } from './utils';
|
18
19
|
|
19
20
|
var Editable = function Editable(props) {
|
20
21
|
var _props$type = props.type,
|
@@ -22,18 +23,14 @@ var Editable = function Editable(props) {
|
|
22
23
|
readonly = props.readonly,
|
23
24
|
columns = props.columns,
|
24
25
|
dataSource = props.dataSource,
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
addPosition: 'bottom'
|
29
|
-
} : _props$multipleProps,
|
26
|
+
defaultValue = props.defaultValue,
|
27
|
+
_props$addPosition = props.addPosition,
|
28
|
+
addPosition = _props$addPosition === void 0 ? 'bottom' : _props$addPosition,
|
30
29
|
tableProps = props.tableProps,
|
31
30
|
onRowConfirm = props.onRowConfirm,
|
32
31
|
onRowDelete = props.onRowDelete,
|
33
32
|
onMulChange = props.onMulChange,
|
34
33
|
getStreamInstance = props.getStreamInstance;
|
35
|
-
var defaultValue = multipleProps.defaultValue,
|
36
|
-
addPosition = multipleProps.addPosition;
|
37
34
|
|
38
35
|
var _React$useState = React.useState([]),
|
39
36
|
_React$useState2 = _slicedToArray(_React$useState, 2),
|
@@ -47,7 +44,18 @@ var Editable = function Editable(props) {
|
|
47
44
|
editRowKey = _React$useState4[0],
|
48
45
|
setEditRowkey = _React$useState4[1];
|
49
46
|
|
50
|
-
var
|
47
|
+
var _React$useState5 = React.useState('add'),
|
48
|
+
_React$useState6 = _slicedToArray(_React$useState5, 2),
|
49
|
+
editType = _React$useState6[0],
|
50
|
+
setEditType = _React$useState6[1];
|
51
|
+
|
52
|
+
var editRowKeyRef = React.useRef(); // 当type为freedom的时候可以编辑指定cell
|
53
|
+
|
54
|
+
var _React$useState7 = React.useState(),
|
55
|
+
_React$useState8 = _slicedToArray(_React$useState7, 2),
|
56
|
+
editCellKey = _React$useState8[0],
|
57
|
+
setEditCellkey = _React$useState8[1]; // 记录上一次发生改变的行值
|
58
|
+
|
51
59
|
|
52
60
|
var lastValueRef = React.useRef(); // 记录上一次的datasource
|
53
61
|
|
@@ -64,20 +72,48 @@ var Editable = function Editable(props) {
|
|
64
72
|
|
65
73
|
if (type === 'multiple') {
|
66
74
|
var _records = recordsRef.current;
|
67
|
-
_records[data.payload.rowIdx] = data.payload.allValues;
|
75
|
+
_records[data.payload.rowIdx] = _objectSpread(_objectSpread({}, _records[data.payload.rowIdx]), data.payload.allValues);
|
68
76
|
onMulChange && onMulChange(_records);
|
77
|
+
} // type为freedom时候处理records
|
78
|
+
|
79
|
+
|
80
|
+
if (type === 'freedom') {
|
81
|
+
var _records2 = recordsRef.current;
|
82
|
+
_records2[data.payload.rowIdx] = _objectSpread(_objectSpread({}, _records2[data.payload.rowIdx]), data.payload.allValues);
|
83
|
+
setRecords(_toConsumableArray(_records2));
|
84
|
+
onMulChange && onMulChange(_objectSpread(_objectSpread({}, data.payload), {}, {
|
85
|
+
records: _records2
|
86
|
+
}));
|
69
87
|
}
|
70
88
|
|
71
89
|
break;
|
72
90
|
|
73
91
|
case 'editRowKey':
|
92
|
+
if (Object.keys(data.payload).length > 1) {
|
93
|
+
setEditType('edit');
|
94
|
+
} else {
|
95
|
+
setEditType('add');
|
96
|
+
}
|
97
|
+
|
74
98
|
setEditRowkey(data.payload._rowKey_);
|
75
99
|
editRowKeyRef.current = data.payload._rowKey_;
|
76
100
|
break;
|
77
101
|
|
102
|
+
case 'editCellKey':
|
103
|
+
setEditCellkey({
|
104
|
+
dataIndex: data.payload.dataIndex,
|
105
|
+
rowIndex: data.payload.rowIndex
|
106
|
+
});
|
107
|
+
editRowKeyRef.current = data.payload._rowKey_;
|
108
|
+
break;
|
109
|
+
|
78
110
|
case 'onSingleSave':
|
79
111
|
if (lastValueRef.current && lastValueRef.current.rowIdx === data.payload._rowKey_) {
|
80
|
-
onRowConfirm && onRowConfirm(
|
112
|
+
onRowConfirm && onRowConfirm({
|
113
|
+
rowIdx: lastValueRef.current.rowIdx,
|
114
|
+
values: lastValueRef.current.values,
|
115
|
+
allValues: _objectSpread(_objectSpread({}, recordsRef.current[lastValueRef.current.rowIdx]), lastValueRef.current.allValues)
|
116
|
+
});
|
81
117
|
editRowKeyRef.current = undefined;
|
82
118
|
setEditRowkey(undefined);
|
83
119
|
} else {
|
@@ -98,12 +134,32 @@ var Editable = function Editable(props) {
|
|
98
134
|
}
|
99
135
|
|
100
136
|
if (type === 'multiple') {
|
101
|
-
var
|
137
|
+
var _records3 = recordsRef.current;
|
102
138
|
|
103
|
-
|
139
|
+
_records3.splice(data.payload._rowKey_, 1);
|
104
140
|
|
105
|
-
setRecords(_toConsumableArray(
|
106
|
-
recordsRef.current =
|
141
|
+
setRecords(_toConsumableArray(_records3));
|
142
|
+
recordsRef.current = _records3;
|
143
|
+
}
|
144
|
+
|
145
|
+
if (type === 'freedom') {
|
146
|
+
// 正在全行编辑的直接删除,不需要回调
|
147
|
+
if (isFreeEditRow(editRowKeyRef.current, data.payload._rowKey_)) {
|
148
|
+
var _records4 = recordsRef.current;
|
149
|
+
|
150
|
+
_records4.splice(data.payload._rowKey_, 1);
|
151
|
+
|
152
|
+
setRecords(_toConsumableArray(_records4));
|
153
|
+
recordsRef.current = _records4; // 移除当前的行的编辑状态
|
154
|
+
|
155
|
+
var _editRowKey = removeCurKeyFromEditRow(editRowKeyRef.current, data.payload._rowKey_);
|
156
|
+
|
157
|
+
setEditRowkey(_editRowKey);
|
158
|
+
editRowKeyRef.current = _editRowKey;
|
159
|
+
return;
|
160
|
+
}
|
161
|
+
|
162
|
+
onRowDelete && onRowDelete(data.payload);
|
107
163
|
}
|
108
164
|
|
109
165
|
break;
|
@@ -111,8 +167,9 @@ var Editable = function Editable(props) {
|
|
111
167
|
}, [type]); // 返回stream的实例
|
112
168
|
|
113
169
|
React.useEffect(function () {
|
114
|
-
if (editableStream) {
|
170
|
+
if (firstLoadRef && editableStream) {
|
115
171
|
getStreamInstance && getStreamInstance(editableStream);
|
172
|
+
firstLoadRef.current = false;
|
116
173
|
}
|
117
174
|
}, [editableStream]); // 定义内部的record
|
118
175
|
|
@@ -141,7 +198,7 @@ var Editable = function Editable(props) {
|
|
141
198
|
return _objectSpread(_objectSpread({
|
142
199
|
record: record,
|
143
200
|
editableType: type
|
144
|
-
}, pick(column, ['editable', 'title', 'dataIndex', 'type', 'enum'])), {}, {
|
201
|
+
}, pick(column, ['editable', 'title', 'dataIndex', 'type', 'enum', 'disabled'])), {}, {
|
145
202
|
rowIndex: rowIndex
|
146
203
|
});
|
147
204
|
};
|
@@ -201,6 +258,19 @@ var Editable = function Editable(props) {
|
|
201
258
|
_records.push(defaultValue);
|
202
259
|
}
|
203
260
|
|
261
|
+
if (type === 'freedom') {
|
262
|
+
var _editRowKeyRef$curren;
|
263
|
+
|
264
|
+
var _editRowKeyArr = ((_editRowKeyRef$curren = editRowKeyRef.current) === null || _editRowKeyRef$curren === void 0 ? void 0 : _editRowKeyRef$curren.toString().split(',')) || ['undefined'];
|
265
|
+
|
266
|
+
var _curKey = addPosition === 'top' ? _editRowKeyArr.length - 1 : _records.length - 1;
|
267
|
+
|
268
|
+
var _editRowKey = "".concat(editRowKeyRef.current, ",").concat(_curKey);
|
269
|
+
|
270
|
+
setEditRowkey(_editRowKey);
|
271
|
+
editRowKeyRef.current = _editRowKey;
|
272
|
+
}
|
273
|
+
|
204
274
|
setRecords(_toConsumableArray(_records));
|
205
275
|
recordsRef.current = _records;
|
206
276
|
}
|
@@ -209,7 +279,11 @@ var Editable = function Editable(props) {
|
|
209
279
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(EditableContext.Provider, {
|
210
280
|
value: {
|
211
281
|
editableStream: editableStream,
|
212
|
-
|
282
|
+
editConfig: {
|
283
|
+
curRow: editRowKey,
|
284
|
+
type: editType,
|
285
|
+
editCellKey: editCellKey
|
286
|
+
}
|
213
287
|
}
|
214
288
|
}, /*#__PURE__*/React.createElement(_Table, _extends({
|
215
289
|
bordered: true
|
@@ -231,7 +305,7 @@ var Editable = function Editable(props) {
|
|
231
305
|
index: index
|
232
306
|
};
|
233
307
|
}
|
234
|
-
})), type === 'multiple' && /*#__PURE__*/React.createElement(_Button, {
|
308
|
+
})), (type === 'multiple' || type === 'freedom') && /*#__PURE__*/React.createElement(_Button, {
|
235
309
|
block: true,
|
236
310
|
type: "dashed",
|
237
311
|
style: {
|
@@ -4,11 +4,12 @@ import { BehaviorSubject } from 'rxjs';
|
|
4
4
|
export interface EditableCellProps extends React.HTMLAttributes<HTMLElement> {
|
5
5
|
title: any;
|
6
6
|
editable: boolean;
|
7
|
-
|
7
|
+
disabled?: boolean;
|
8
|
+
dataIndex: string;
|
8
9
|
rowIndex: number;
|
9
10
|
record: any;
|
10
11
|
type: InputType;
|
11
|
-
editableType: 'single' | 'multiple';
|
12
|
+
editableType: 'single' | 'multiple' | 'freedom';
|
12
13
|
enum?: {
|
13
14
|
label: string;
|
14
15
|
value: string;
|
@@ -33,16 +34,25 @@ export interface IEditableStream {
|
|
33
34
|
}
|
34
35
|
export interface IEditableContextProps {
|
35
36
|
editableStream: BehaviorSubject<IEditableStream | undefined>;
|
36
|
-
|
37
|
+
editConfig: {
|
38
|
+
/**
|
39
|
+
* 当前编辑的行
|
40
|
+
*/
|
41
|
+
curRow: number | string;
|
42
|
+
/**
|
43
|
+
* 当前行是编辑还是新增
|
44
|
+
*/
|
45
|
+
type: 'edit' | 'add';
|
46
|
+
editCellKey: {
|
47
|
+
dataIndex: string;
|
48
|
+
rowIndex: number;
|
49
|
+
};
|
50
|
+
};
|
37
51
|
}
|
38
52
|
export declare const EditableContext: React.Context<IEditableContextProps>;
|
39
|
-
export interface
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
/**
|
45
|
-
* 添加行的位置
|
46
|
-
*/
|
47
|
-
addPosition?: 'top' | 'bottom';
|
53
|
+
export interface ICommonProps {
|
54
|
+
}
|
55
|
+
export interface IMultipleProps extends ICommonProps {
|
56
|
+
}
|
57
|
+
export interface IFreedomProps extends ICommonProps {
|
48
58
|
}
|
@@ -1,2 +1,5 @@
|
|
1
1
|
import { EditableCellProps } from './interface';
|
2
2
|
export declare function getDataCell(item: EditableCellProps): JSX.Element;
|
3
|
+
export declare function isFreeEditRow(curRow: any, rowIndex: number): boolean;
|
4
|
+
export declare function isFreeEditCell(editCellKey: any, dataIndex: string, rowIndex: number): boolean;
|
5
|
+
export declare function removeCurKeyFromEditRow(editRowKey: any, curKey: number): string;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
* @Author: wangxian
|
3
3
|
* @Date: 2022-03-04 14:59:04
|
4
|
-
* @LastEditTime: 2022-03-
|
4
|
+
* @LastEditTime: 2022-03-09 10:42:38
|
5
5
|
*/
|
6
6
|
import React from 'react';
|
7
7
|
import Input from './DataCell/Input';
|
@@ -21,4 +21,22 @@ export function getDataCell(item) {
|
|
21
21
|
}
|
22
22
|
|
23
23
|
return null;
|
24
|
+
}
|
25
|
+
export function isFreeEditRow(curRow, rowIndex) {
|
26
|
+
return (curRow === null || curRow === void 0 ? void 0 : curRow.toString().split(',').indexOf("".concat(rowIndex))) > -1;
|
27
|
+
}
|
28
|
+
export function isFreeEditCell(editCellKey, dataIndex, rowIndex) {
|
29
|
+
return (editCellKey === null || editCellKey === void 0 ? void 0 : editCellKey.dataIndex) === dataIndex && (editCellKey === null || editCellKey === void 0 ? void 0 : editCellKey.rowIndex) === rowIndex;
|
30
|
+
}
|
31
|
+
export function removeCurKeyFromEditRow(editRowKey, curKey) {
|
32
|
+
var keys = editRowKey.toString().split(',');
|
33
|
+
var res = [];
|
34
|
+
keys.forEach(function (v) {
|
35
|
+
if (parseInt(v) > curKey) {
|
36
|
+
res.push(parseInt(v) - 1);
|
37
|
+
} else if (v !== "".concat(curKey)) {
|
38
|
+
res.push(v);
|
39
|
+
}
|
40
|
+
});
|
41
|
+
return res.toString();
|
24
42
|
}
|
package/es/index.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
export { default as MetadataEdit } from './comps/MetadataEdit';
|
2
|
+
export { default as MetaPropsEdit } from './comps/MetadataEdit/components/MetaPropsEdit';
|
2
3
|
export { default as MetadataEditV2 } from './comps/MetadataEditV2';
|
3
4
|
export { default as MetadataForm } from './comps/MetadataForm';
|
4
5
|
export { default as JsonView } from './comps/JsonView';
|
package/es/index.js
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
/*
|
2
2
|
* @Author:wangxian
|
3
3
|
* @Date: 2021-09-18 14:15:04
|
4
|
-
* @LastEditTime: 2022-03-
|
4
|
+
* @LastEditTime: 2022-03-09 08:43:55
|
5
5
|
*/
|
6
6
|
export { default as MetadataEdit } from './comps/MetadataEdit';
|
7
|
+
export { default as MetaPropsEdit } from './comps/MetadataEdit/components/MetaPropsEdit';
|
7
8
|
export { default as MetadataEditV2 } from './comps/MetadataEditV2';
|
8
9
|
export { default as MetadataForm } from './comps/MetadataForm';
|
9
10
|
export { default as JsonView } from './comps/JsonView';
|