ronds-metadata 1.0.40 → 1.0.43

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.
@@ -6,18 +6,40 @@ 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-04 15:56:22
9
+ * @LastEditTime: 2022-03-08 17:22:26
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.input.setSelectionRange(0, inputRef.current.state.value.length); // 选中内容
30
+
31
+ inputRef.current.focus(); // 设置焦点
32
+ }
33
+ }, [editConfig]);
15
34
  return /*#__PURE__*/React.createElement(_Form.Item, {
16
35
  name: dataIndex,
17
36
  style: {
18
37
  margin: 0
19
38
  }
20
- }, /*#__PURE__*/React.createElement(_Input, null));
39
+ }, /*#__PURE__*/React.createElement(_Input, {
40
+ ref: inputRef,
41
+ disabled: editConfig.type === 'edit' ? disabled : false
42
+ }));
21
43
  }
22
44
 
23
45
  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-04 14:57:57
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, null));
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-05 08:27:55
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-05 08:53:21
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, null));
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);
@@ -1,5 +1,5 @@
1
1
  interface IEditableActionProps {
2
- type: 'single' | 'multiple';
2
+ type: 'single' | 'multiple' | 'freedom';
3
3
  record: any;
4
4
  }
5
5
  declare const EditableAction: (props: IEditableActionProps) => JSX.Element;
@@ -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
- editRowKey = _ref.editRowKey;
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, editRowKey !== record._rowKey_ && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_Button, {
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: (editRowKey || editRowKey === 0) && editRowKey !== record._rowKey_,
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
- })), editRowKey === record._rowKey_ && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_Button, {
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,15 @@
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
8
  import { getDataCell } from '../utils';
12
9
 
13
10
  var EditableCell = function EditableCell(props) {
14
11
  var editable = props.editable,
12
+ record = props.record,
15
13
  editableType = props.editableType,
16
14
  dataIndex = props.dataIndex,
17
15
  rowIndex = props.rowIndex,
@@ -19,10 +17,41 @@ var EditableCell = function EditableCell(props) {
19
17
  restProps = _objectWithoutProperties(props, _excluded);
20
18
 
21
19
  var _ref = React.useContext(EditableContext) || undefined,
22
- editRowKey = _ref.editRowKey;
20
+ editableStream = _ref.editableStream,
21
+ editConfig = _ref.editConfig;
22
+
23
+ var onCellClick = function onCellClick() {
24
+ if (editConfig === null || editConfig === void 0 ? void 0 : editConfig.curRow) {
25
+ var _editConfig$curRow;
26
+
27
+ if (((_editConfig$curRow = editConfig.curRow) === null || _editConfig$curRow === void 0 ? void 0 : _editConfig$curRow.toString().split(',').indexOf("".concat(rowIndex))) > -1) return;
28
+
29
+ _message.warning('请先保存正在编辑的行');
30
+
31
+ return;
32
+ }
33
+
34
+ editableStream.next({
35
+ type: 'editCellKey',
36
+ payload: {
37
+ dataIndex: dataIndex,
38
+ rowIndex: rowIndex
39
+ }
40
+ });
41
+ };
23
42
 
24
43
  if (editableType === 'single') {
25
- return /*#__PURE__*/React.createElement("td", restProps, editable && editRowKey === rowIndex ? getDataCell(props) : children);
44
+ return /*#__PURE__*/React.createElement("td", restProps, editable && editConfig.curRow === rowIndex ? getDataCell(props) : children);
45
+ }
46
+
47
+ if (editableType === 'freedom') {
48
+ var _editConfig$curRow2, _editConfig$editCellK, _editConfig$editCellK2;
49
+
50
+ var isAddRow = editable && ((_editConfig$curRow2 = editConfig.curRow) === null || _editConfig$curRow2 === void 0 ? void 0 : _editConfig$curRow2.toString().split(',').indexOf("".concat(rowIndex))) > -1;
51
+ var isCell = editable && ((_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;
52
+ return /*#__PURE__*/React.createElement("td", _extends({
53
+ onDoubleClick: onCellClick
54
+ }, restProps), isAddRow || isCell ? getDataCell(props) : children);
26
55
  }
27
56
 
28
57
  return /*#__PURE__*/React.createElement("td", restProps, editable ? getDataCell(props) : children);
@@ -1,20 +1,25 @@
1
1
  import { TableProps } from 'antd';
2
- import { EditColumnsType, IMultipleProps } from './interface';
2
+ import { BehaviorSubject } from 'rxjs';
3
+ import { EditColumnsType, IEditableStream } from './interface';
3
4
  interface IEditableProps<R = any> {
4
5
  /**
5
6
  * 单行编辑或多行编辑。
6
7
  * 备注:
7
8
  * type为multiple时,一定要设置defaultValue
8
9
  */
9
- type?: 'single' | 'multiple';
10
+ type?: 'single' | 'multiple' | 'freedom';
10
11
  /**
11
12
  * 表格列的配置描述
12
13
  */
13
14
  columns: EditColumnsType;
14
15
  /**
15
- * 当type为multiple的配置
16
+ * 新增一列 默认的值
16
17
  */
17
- multipleProps?: IMultipleProps;
18
+ defaultValue?: any;
19
+ /**
20
+ * 添加行的位置
21
+ */
22
+ addPosition?: 'top' | 'bottom';
18
23
  /**
19
24
  * 数据数组
20
25
  */
@@ -30,11 +35,19 @@ interface IEditableProps<R = any> {
30
35
  /**
31
36
  * 每行确认回调函数
32
37
  */
33
- onRowConfirm: (record: any) => void;
38
+ onRowConfirm?: (record: any) => void;
34
39
  /**
35
40
  * 每行删除回调
36
41
  */
37
- onRowDelete: (record: any) => void;
42
+ onRowDelete?: (record: any) => void;
43
+ /**
44
+ * 表格数据的change触发事件
45
+ */
46
+ onMulChange?: (records: any) => void;
47
+ /**
48
+ * editable的事件流回调
49
+ */
50
+ getStreamInstance?: (subject: BehaviorSubject<IEditableStream | undefined>) => void;
38
51
  }
39
52
  declare const Editable: (props: IEditableProps) => JSX.Element;
40
53
  export default Editable;
@@ -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';
@@ -22,29 +22,39 @@ var Editable = function Editable(props) {
22
22
  readonly = props.readonly,
23
23
  columns = props.columns,
24
24
  dataSource = props.dataSource,
25
- _props$multipleProps = props.multipleProps,
26
- multipleProps = _props$multipleProps === void 0 ? {
27
- defaultValue: '',
28
- addPosition: 'bottom'
29
- } : _props$multipleProps,
25
+ defaultValue = props.defaultValue,
26
+ _props$addPosition = props.addPosition,
27
+ addPosition = _props$addPosition === void 0 ? 'bottom' : _props$addPosition,
30
28
  tableProps = props.tableProps,
31
29
  onRowConfirm = props.onRowConfirm,
32
- onRowDelete = props.onRowDelete;
33
- var defaultValue = multipleProps.defaultValue,
34
- addPosition = multipleProps.addPosition;
30
+ onRowDelete = props.onRowDelete,
31
+ onMulChange = props.onMulChange,
32
+ getStreamInstance = props.getStreamInstance;
35
33
 
36
34
  var _React$useState = React.useState([]),
37
35
  _React$useState2 = _slicedToArray(_React$useState, 2),
38
36
  records = _React$useState2[0],
39
- setRecords = _React$useState2[1]; // 当type为single的时候 只能编辑该行数据
37
+ setRecords = _React$useState2[1];
40
38
 
39
+ var recordsRef = React.useRef([]); // 当type为single的时候 只能编辑该行数据
41
40
 
42
41
  var _React$useState3 = React.useState(),
43
42
  _React$useState4 = _slicedToArray(_React$useState3, 2),
44
43
  editRowKey = _React$useState4[0],
45
44
  setEditRowkey = _React$useState4[1];
46
45
 
47
- var editRowKeyRef = React.useRef(); // 记录上一次发生改变的行值
46
+ var _React$useState5 = React.useState('add'),
47
+ _React$useState6 = _slicedToArray(_React$useState5, 2),
48
+ editType = _React$useState6[0],
49
+ setEditType = _React$useState6[1];
50
+
51
+ var editRowKeyRef = React.useRef(); // 当type为freedom的时候可以编辑指定cell
52
+
53
+ var _React$useState7 = React.useState(),
54
+ _React$useState8 = _slicedToArray(_React$useState7, 2),
55
+ editCellKey = _React$useState8[0],
56
+ setEditCellkey = _React$useState8[1]; // 记录上一次发生改变的行值
57
+
48
58
 
49
59
  var lastValueRef = React.useRef(); // 记录上一次的datasource
50
60
 
@@ -57,17 +67,52 @@ var Editable = function Editable(props) {
57
67
  var processStreamFactory = React.useCallback(function (data) {
58
68
  switch (data === null || data === void 0 ? void 0 : data.type) {
59
69
  case 'onValuesChange':
60
- lastValueRef.current = data.payload;
70
+ lastValueRef.current = data.payload; // type为multiple时候处理records
71
+
72
+ if (type === 'multiple') {
73
+ var _records = recordsRef.current;
74
+ _records[data.payload.rowIdx] = _objectSpread(_objectSpread({}, _records[data.payload.rowIdx]), data.payload.allValues);
75
+ onMulChange && onMulChange(_records);
76
+ } // type为freedom时候处理records
77
+
78
+
79
+ if (type === 'freedom') {
80
+ var _records2 = recordsRef.current;
81
+ _records2[data.payload.rowIdx] = _objectSpread(_objectSpread({}, _records2[data.payload.rowIdx]), data.payload.allValues);
82
+ setRecords(_toConsumableArray(_records2));
83
+ onMulChange && onMulChange(_objectSpread(_objectSpread({}, data.payload), {}, {
84
+ records: _records2
85
+ }));
86
+ }
87
+
61
88
  break;
62
89
 
63
90
  case 'editRowKey':
91
+ if (Object.keys(data.payload).length > 1) {
92
+ setEditType('edit');
93
+ } else {
94
+ setEditType('add');
95
+ }
96
+
64
97
  setEditRowkey(data.payload._rowKey_);
65
98
  editRowKeyRef.current = data.payload._rowKey_;
66
99
  break;
67
100
 
101
+ case 'editCellKey':
102
+ setEditCellkey({
103
+ dataIndex: data.payload.dataIndex,
104
+ rowIndex: data.payload.rowIndex
105
+ });
106
+ editRowKeyRef.current = data.payload._rowKey_;
107
+ break;
108
+
68
109
  case 'onSingleSave':
69
110
  if (lastValueRef.current && lastValueRef.current.rowIdx === data.payload._rowKey_) {
70
- onRowConfirm && onRowConfirm(lastValueRef.current);
111
+ onRowConfirm && onRowConfirm({
112
+ rowIdx: lastValueRef.current.rowIdx,
113
+ values: lastValueRef.current.values,
114
+ allValues: _objectSpread(_objectSpread({}, recordsRef.current[lastValueRef.current.rowIdx]), lastValueRef.current.allValues)
115
+ });
71
116
  editRowKeyRef.current = undefined;
72
117
  setEditRowkey(undefined);
73
118
  } else {
@@ -87,13 +132,35 @@ var Editable = function Editable(props) {
87
132
  onRowDelete && onRowDelete(data.payload);
88
133
  }
89
134
 
135
+ if (type === 'multiple') {
136
+ var _records3 = recordsRef.current;
137
+
138
+ _records3.splice(data.payload._rowKey_, 1);
139
+
140
+ setRecords(_toConsumableArray(_records3));
141
+ recordsRef.current = _records3;
142
+ }
143
+
144
+ if (type === 'freedom') {
145
+ // 正在全行编辑的直接删除,不需要回调
146
+ onRowDelete && onRowDelete(data.payload);
147
+ }
148
+
90
149
  break;
91
150
  }
92
- }, []); // 定义内部的record
151
+ }, [type]); // 返回stream的实例
152
+
153
+ React.useEffect(function () {
154
+ if (firstLoadRef && editableStream) {
155
+ getStreamInstance && getStreamInstance(editableStream);
156
+ firstLoadRef.current = false;
157
+ }
158
+ }, [editableStream]); // 定义内部的record
93
159
 
94
160
  React.useEffect(function () {
95
161
  if (dataSource) {
96
162
  setRecords(_toConsumableArray(dataSource));
163
+ recordsRef.current = dataSource;
97
164
  }
98
165
  }, [dataSource]); // 集中处理数据流
99
166
 
@@ -115,7 +182,7 @@ var Editable = function Editable(props) {
115
182
  return _objectSpread(_objectSpread({
116
183
  record: record,
117
184
  editableType: type
118
- }, pick(column, ['editable', 'title', 'dataIndex', 'type', 'enum'])), {}, {
185
+ }, pick(column, ['editable', 'title', 'dataIndex', 'type', 'enum', 'disabled'])), {}, {
119
186
  rowIndex: rowIndex
120
187
  });
121
188
  };
@@ -151,18 +218,11 @@ var Editable = function Editable(props) {
151
218
 
152
219
 
153
220
  var _dataSource = React.useMemo(function () {
154
- var _lastDataSourceRef$cu;
155
-
156
221
  var res = records.map(function (it, idx) {
157
222
  return _objectSpread({
158
223
  _rowKey_: idx
159
224
  }, it);
160
- }); // 判断是否是新加行,如果是single类型的编辑框置为新加的一行
161
-
162
- if (type === 'single' && !firstLoadRef.current && res.length > ((_lastDataSourceRef$cu = lastDataSourceRef.current) === null || _lastDataSourceRef$cu === void 0 ? void 0 : _lastDataSourceRef$cu.length)) {
163
- setEditRowkey(res[res.length - 1]._rowKey_);
164
- editRowKeyRef.current = res[res.length - 1]._rowKey_;
165
- }
225
+ });
166
226
 
167
227
  if (res.length > 0) {
168
228
  firstLoadRef.current = false;
@@ -174,7 +234,7 @@ var Editable = function Editable(props) {
174
234
 
175
235
  var onAddRow = function onAddRow() {
176
236
  if (defaultValue) {
177
- var _records = records;
237
+ var _records = recordsRef.current;
178
238
 
179
239
  if (addPosition === 'top') {
180
240
  _records.unshift(defaultValue);
@@ -182,14 +242,32 @@ var Editable = function Editable(props) {
182
242
  _records.push(defaultValue);
183
243
  }
184
244
 
245
+ if (type === 'freedom') {
246
+ var _editRowKeyRef$curren;
247
+
248
+ var _editRowKeyArr = ((_editRowKeyRef$curren = editRowKeyRef.current) === null || _editRowKeyRef$curren === void 0 ? void 0 : _editRowKeyRef$curren.toString().split(',')) || ['undefined'];
249
+
250
+ var _curKey = addPosition === 'top' ? _editRowKeyArr.length - 1 : _records.length - 1;
251
+
252
+ var _editRowKey = "".concat(editRowKeyRef.current, ",").concat(_curKey);
253
+
254
+ setEditRowkey(_editRowKey);
255
+ editRowKeyRef.current = _editRowKey;
256
+ }
257
+
185
258
  setRecords(_toConsumableArray(_records));
259
+ recordsRef.current = _records;
186
260
  }
187
261
  };
188
262
 
189
263
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(EditableContext.Provider, {
190
264
  value: {
191
265
  editableStream: editableStream,
192
- editRowKey: editRowKey
266
+ editConfig: {
267
+ curRow: editRowKey,
268
+ type: editType,
269
+ editCellKey: editCellKey
270
+ }
193
271
  }
194
272
  }, /*#__PURE__*/React.createElement(_Table, _extends({
195
273
  bordered: true
@@ -211,7 +289,7 @@ var Editable = function Editable(props) {
211
289
  index: index
212
290
  };
213
291
  }
214
- })), type === 'multiple' && /*#__PURE__*/React.createElement(_Button, {
292
+ })), (type === 'multiple' || type === 'freedom') && /*#__PURE__*/React.createElement(_Button, {
215
293
  block: true,
216
294
  type: "dashed",
217
295
  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
- dataIndex: number;
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
- editRowKey: number;
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 IMultipleProps {
40
- /**
41
- * 新增一列 默认的值
42
- */
43
- defaultValue: any;
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,7 +1,7 @@
1
1
  /*
2
2
  * @Author: wangxian
3
3
  * @Date: 2022-03-04 15:07:57
4
- * @LastEditTime: 2022-03-07 15:13:45
4
+ * @LastEditTime: 2022-03-08 17:06:55
5
5
  */
6
6
  import React from 'react';
7
7
  export var EditableContext = /*#__PURE__*/React.createContext(null);
@@ -1,2 +1,4 @@
1
1
  import { EditableCellProps } from './interface';
2
2
  export declare function getDataCell(item: EditableCellProps): JSX.Element;
3
+ export declare function isFreeEditRow(): void;
4
+ export declare function isFreeEditCell(): void;
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * @Author: wangxian
3
3
  * @Date: 2022-03-04 14:59:04
4
- * @LastEditTime: 2022-03-04 15:28:47
4
+ * @LastEditTime: 2022-03-09 09:27:01
5
5
  */
6
6
  import React from 'react';
7
7
  import Input from './DataCell/Input';
@@ -21,4 +21,6 @@ export function getDataCell(item) {
21
21
  }
22
22
 
23
23
  return null;
24
- }
24
+ }
25
+ export function isFreeEditRow() {}
26
+ export function isFreeEditCell() {}
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-04 16:53:30
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';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "public": true,
3
3
  "name": "ronds-metadata",
4
- "version": "1.0.40",
4
+ "version": "1.0.43",
5
5
  "scripts": {
6
6
  "start": "dumi dev",
7
7
  "docs:build": "dumi build",