ronds-metadata 1.0.42 → 1.0.45

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,24 +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-08 14:16:12
9
+ * @LastEditTime: 2022-03-10 14:38:32
10
10
  */
11
11
  import React from 'react';
12
12
  import { EditableContext } from '../interface';
13
13
 
14
14
  function Index(props) {
15
15
  var dataIndex = props.dataIndex,
16
+ rowIndex = props.rowIndex,
16
17
  disabled = props.disabled;
17
18
 
18
19
  var _ref = React.useContext(EditableContext) || undefined,
19
20
  editConfig = _ref.editConfig;
20
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
+ var _inputRef$current$sta, _inputRef$current$sta2;
32
+
33
+ // 选中内容
34
+ inputRef.current.input.setSelectionRange(0, ((_inputRef$current$sta = inputRef.current.state) === null || _inputRef$current$sta === void 0 ? void 0 : (_inputRef$current$sta2 = _inputRef$current$sta.value) === null || _inputRef$current$sta2 === void 0 ? void 0 : _inputRef$current$sta2.length) || 0);
35
+ firstLoadRef.current = false;
36
+ } // 设置焦点
37
+
38
+
39
+ inputRef.current.focus();
40
+ }
41
+ }, [editConfig]);
21
42
  return /*#__PURE__*/React.createElement(_Form.Item, {
22
43
  name: dataIndex,
23
44
  style: {
24
45
  margin: 0
25
46
  }
26
47
  }, /*#__PURE__*/React.createElement(_Input, {
48
+ ref: inputRef,
27
49
  disabled: editConfig.type === 'edit' ? disabled : false
28
50
  }));
29
51
  }
@@ -6,24 +6,36 @@ 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-08 14:16:01
9
+ * @LastEditTime: 2022-03-08 17:26:48
10
10
  */
11
11
  import React from 'react';
12
12
  import { EditableContext } from '../interface';
13
13
 
14
14
  function Index(props) {
15
15
  var dataIndex = props.dataIndex,
16
+ rowIndex = props.rowIndex,
16
17
  disabled = props.disabled;
17
18
 
18
19
  var _ref = React.useContext(EditableContext) || undefined,
19
20
  editConfig = _ref.editConfig;
20
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]);
21
32
  return /*#__PURE__*/React.createElement(_Form.Item, {
22
33
  name: dataIndex,
23
34
  style: {
24
35
  margin: 0
25
36
  }
26
37
  }, /*#__PURE__*/React.createElement(_InputNumber, {
38
+ ref: inputRef,
27
39
  disabled: editConfig.type === 'edit' ? disabled : false
28
40
  }));
29
41
  }
@@ -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;
@@ -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,4 +1,5 @@
1
1
  import React from 'react';
2
2
  import { EditableCellProps } from '../interface';
3
+ import './index.less';
3
4
  declare const EditableCell: React.FC<EditableCellProps>;
4
5
  export default EditableCell;
@@ -1,17 +1,17 @@
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-08 14:06:58
8
- */
5
+ var _excluded = ["isAddColumn", "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
- var editable = props.editable,
12
+ var isAddColumn = props.isAddColumn,
13
+ editable = props.editable,
14
+ record = props.record,
15
15
  editableType = props.editableType,
16
16
  dataIndex = props.dataIndex,
17
17
  rowIndex = props.rowIndex,
@@ -19,13 +19,65 @@ var EditableCell = function EditableCell(props) {
19
19
  restProps = _objectWithoutProperties(props, _excluded);
20
20
 
21
21
  var _ref = React.useContext(EditableContext) || undefined,
22
- editConfig = _ref.editConfig;
22
+ editableStream = _ref.editableStream,
23
+ editConfig = _ref.editConfig; // console.log('EditableCell', props, editConfig);
24
+
25
+
26
+ var onCellDoubleClick = function onCellDoubleClick() {
27
+ if ((editConfig === null || editConfig === void 0 ? void 0 : editConfig.curRow) && (editConfig === null || editConfig === void 0 ? void 0 : editConfig.curRow) !== 'undefined') {
28
+ if (isFreeEditRow(editConfig.curRow, rowIndex)) 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
+
55
+ if (isAddColumn) {
56
+ editableStream.next({
57
+ type: 'editHeardCellKey',
58
+ payload: undefined
59
+ });
60
+ }
61
+ };
23
62
 
24
63
  if (editableType === 'single') {
25
- return /*#__PURE__*/React.createElement("td", restProps, editable && editConfig.curRow === rowIndex ? getDataCell(props) : children);
64
+ return /*#__PURE__*/React.createElement("td", _extends({}, restProps, {
65
+ className: "ant-table-cell ".concat(isAddColumn && editConfig.editHeardCellKey === dataIndex ? 'border-right' : '', " ")
66
+ }), editable && editConfig.curRow === rowIndex ? getDataCell(props) : children);
67
+ }
68
+
69
+ if (editableType === 'freedom') {
70
+ return /*#__PURE__*/React.createElement("td", _extends({
71
+ onDoubleClick: onCellDoubleClick,
72
+ onClick: onCellClick
73
+ }, restProps, {
74
+ className: "ant-table-cell ".concat(isAddColumn && editConfig.editHeardCellKey === dataIndex ? 'border-right' : '', " ")
75
+ }), editable && (isFreeEditRow(editConfig.curRow, rowIndex) || isFreeEditCell(editConfig.editCellKey, dataIndex, rowIndex)) ? getDataCell(props) : children);
26
76
  }
27
77
 
28
- return /*#__PURE__*/React.createElement("td", restProps, editable ? getDataCell(props) : children);
78
+ return /*#__PURE__*/React.createElement("td", _extends({}, restProps, {
79
+ className: "ant-table-cell ".concat(isAddColumn && editConfig.editHeardCellKey === dataIndex ? 'border-right' : '', " ")
80
+ }), editable ? getDataCell(props) : children);
29
81
  };
30
82
 
31
83
  export default EditableCell;
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import { EditableHeardCellProps } from '../interface';
3
+ import './index.less';
4
+ declare const EditableHeardCell: React.FC<EditableHeardCellProps>;
5
+ export default EditableHeardCell;
@@ -0,0 +1,141 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import "antd/es/popover/style";
3
+ import _Popover from "antd/es/popover";
4
+ import "antd/es/button/style";
5
+ import _Button from "antd/es/button";
6
+ import "antd/es/input/style";
7
+ import _Input from "antd/es/input";
8
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
9
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
10
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
11
+ var _excluded = ["title", "dataIndex", "isAddColumn", "children"];
12
+ import { PlusSquareOutlined, DeleteOutlined } from '@ant-design/icons';
13
+ import React from 'react';
14
+ import { EditableContext } from '../interface';
15
+ import "./index.css";
16
+
17
+ var EditableHeardCell = function EditableHeardCell(props) {
18
+ var title = props.title,
19
+ dataIndex = props.dataIndex,
20
+ isAddColumn = props.isAddColumn,
21
+ children = props.children,
22
+ restProps = _objectWithoutProperties(props, _excluded);
23
+
24
+ var _ref = React.useContext(EditableContext) || undefined,
25
+ editableStream = _ref.editableStream,
26
+ editConfig = _ref.editConfig;
27
+
28
+ var addColumnRef = React.useRef({
29
+ key: '',
30
+ title: ''
31
+ });
32
+
33
+ var _React$useState = React.useState({
34
+ key: '',
35
+ title: ''
36
+ }),
37
+ _React$useState2 = _slicedToArray(_React$useState, 2),
38
+ addColumn = _React$useState2[0],
39
+ setAddColumn = _React$useState2[1];
40
+
41
+ var _React$useState3 = React.useState(false),
42
+ _React$useState4 = _slicedToArray(_React$useState3, 2),
43
+ visible = _React$useState4[0],
44
+ setVisible = _React$useState4[1];
45
+
46
+ var onMouseOver = function onMouseOver() {
47
+ editableStream.next({
48
+ type: 'editHeardCellKey',
49
+ payload: dataIndex
50
+ });
51
+ };
52
+
53
+ var onMouseLeave = function onMouseLeave() {};
54
+
55
+ var onAddColumn = function onAddColumn() {
56
+ setVisible(false);
57
+ editableStream.next({
58
+ type: 'onAddColumn',
59
+ payload: _objectSpread({
60
+ dataIndex: dataIndex
61
+ }, addColumnRef.current)
62
+ });
63
+ setAddColumn({
64
+ key: '',
65
+ title: ''
66
+ });
67
+ addColumnRef.current = {
68
+ key: '',
69
+ title: ''
70
+ };
71
+ };
72
+
73
+ var content = /*#__PURE__*/React.createElement("div", {
74
+ style: {
75
+ width: '100px'
76
+ }
77
+ }, /*#__PURE__*/React.createElement("div", {
78
+ style: {
79
+ marginBottom: '10px'
80
+ }
81
+ }, /*#__PURE__*/React.createElement(_Input, {
82
+ value: addColumn.key,
83
+ style: {
84
+ width: '100%',
85
+ marginBottom: '5px'
86
+ },
87
+ onChange: function onChange(e) {
88
+ var _ = addColumnRef.current;
89
+ _.key = e.target.value;
90
+ setAddColumn(_objectSpread({}, _));
91
+ addColumnRef.current = _;
92
+ },
93
+ placeholder: "\u8BF7\u8F93\u5165key"
94
+ }), /*#__PURE__*/React.createElement(_Input, {
95
+ value: addColumn.title,
96
+ style: {
97
+ width: '100%'
98
+ },
99
+ onChange: function onChange(e) {
100
+ var _ = addColumnRef.current;
101
+ _.title = e.target.value;
102
+ setAddColumn(_objectSpread({}, _));
103
+ addColumnRef.current = _;
104
+ },
105
+ placeholder: "\u8BF7\u8F93\u5165title",
106
+ onPressEnter: onAddColumn
107
+ })), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(_Button, {
108
+ type: "primary",
109
+ block: true,
110
+ onClick: onAddColumn
111
+ }, "\u786E\u5B9A")));
112
+
113
+ var onVisibleChange = function onVisibleChange(b) {
114
+ setVisible(b);
115
+ };
116
+
117
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("th", _extends({}, restProps, {
118
+ className: "ant-table-cell ".concat(isAddColumn && editConfig.editHeardCellKey === dataIndex ? 'border-right ' : '', " ")
119
+ }), isAddColumn && /*#__PURE__*/React.createElement(_Popover, {
120
+ placement: "rightTop",
121
+ content: content,
122
+ trigger: "click",
123
+ visible: visible,
124
+ onVisibleChange: onVisibleChange
125
+ }, /*#__PURE__*/React.createElement("div", {
126
+ className: "".concat(editConfig.editHeardCellKey === dataIndex ? 'editable-th-hover-add' : 'display-none')
127
+ }, /*#__PURE__*/React.createElement(_Button, {
128
+ type: "link",
129
+ icon: /*#__PURE__*/React.createElement(PlusSquareOutlined, null)
130
+ }))), isAddColumn && /*#__PURE__*/React.createElement("div", {
131
+ className: "".concat(editConfig.editHeardCellKey === dataIndex ? 'editable-th-hover-delete' : 'display-none')
132
+ }, /*#__PURE__*/React.createElement(_Button, {
133
+ type: "link",
134
+ icon: /*#__PURE__*/React.createElement(DeleteOutlined, null)
135
+ })), /*#__PURE__*/React.createElement("div", {
136
+ onMouseOver: onMouseOver,
137
+ onMouseLeave: onMouseLeave
138
+ }, children)));
139
+ };
140
+
141
+ export default EditableHeardCell;
@@ -0,0 +1,19 @@
1
+ .editable-th-hover-add {
2
+ position: absolute;
3
+ right: -16px;
4
+ top: -30px;
5
+ }
6
+ .editable-th-hover-delete {
7
+ position: absolute;
8
+ left: 49%;
9
+ top: -30px;
10
+ }
11
+ .display-none {
12
+ display: none;
13
+ }
14
+ .border-right {
15
+ border-right: 1px solid var(--antd-wave-shadow-color) !important;
16
+ }
17
+ .border-top {
18
+ border-top: 1px solid var(--antd-wave-shadow-color) !important;
19
+ }
@@ -1,21 +1,25 @@
1
1
  import { TableProps } from 'antd';
2
2
  import { BehaviorSubject } from 'rxjs';
3
- import { EditColumnsType, IEditableStream, IMultipleProps } from './interface';
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
- columns: EditColumnsType;
14
+ columns: EditColumnsType[];
15
15
  /**
16
- * 当type为multiple的配置
16
+ * 新增一列 默认的值
17
17
  */
18
- multipleProps?: IMultipleProps;
18
+ defaultValue?: any;
19
+ /**
20
+ * 添加行的位置
21
+ */
22
+ addPosition?: 'top' | 'bottom';
19
23
  /**
20
24
  * 数据数组
21
25
  */
@@ -24,6 +28,10 @@ interface IEditableProps<R = any> {
24
28
  * 只读
25
29
  */
26
30
  readonly?: boolean;
31
+ /**
32
+ * 是否可以添加列
33
+ */
34
+ isAddColumn?: boolean;
27
35
  /**
28
36
  * antd自身的属性
29
37
  */
@@ -4,9 +4,9 @@ import "antd/es/table/style";
4
4
  import _Table from "antd/es/table";
5
5
  import _extends from "@babel/runtime/helpers/esm/extends";
6
6
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
7
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
7
8
  import "antd/es/message/style";
8
9
  import _message from "antd/es/message";
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,8 @@ 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';
19
+ import EditableHeardCell from './comps/EditableHeardCell';
18
20
 
19
21
  var Editable = function Editable(props) {
20
22
  var _props$type = props.type,
@@ -22,18 +24,16 @@ var Editable = function Editable(props) {
22
24
  readonly = props.readonly,
23
25
  columns = props.columns,
24
26
  dataSource = props.dataSource,
25
- _props$multipleProps = props.multipleProps,
26
- multipleProps = _props$multipleProps === void 0 ? {
27
- defaultValue: '',
28
- addPosition: 'bottom'
29
- } : _props$multipleProps,
27
+ defaultValue = props.defaultValue,
28
+ _props$addPosition = props.addPosition,
29
+ addPosition = _props$addPosition === void 0 ? 'bottom' : _props$addPosition,
30
+ _props$isAddColumn = props.isAddColumn,
31
+ isAddColumn = _props$isAddColumn === void 0 ? false : _props$isAddColumn,
30
32
  tableProps = props.tableProps,
31
33
  onRowConfirm = props.onRowConfirm,
32
34
  onRowDelete = props.onRowDelete,
33
35
  onMulChange = props.onMulChange,
34
36
  getStreamInstance = props.getStreamInstance;
35
- var defaultValue = multipleProps.defaultValue,
36
- addPosition = multipleProps.addPosition;
37
37
 
38
38
  var _React$useState = React.useState([]),
39
39
  _React$useState2 = _slicedToArray(_React$useState, 2),
@@ -52,7 +52,26 @@ var Editable = function Editable(props) {
52
52
  editType = _React$useState6[0],
53
53
  setEditType = _React$useState6[1];
54
54
 
55
- var editRowKeyRef = React.useRef(); // 记录上一次发生改变的行值
55
+ var editRowKeyRef = React.useRef(); // 当type为freedom的时候可以编辑指定cell
56
+
57
+ var _React$useState7 = React.useState(),
58
+ _React$useState8 = _slicedToArray(_React$useState7, 2),
59
+ editCellKey = _React$useState8[0],
60
+ setEditCellkey = _React$useState8[1]; // 添加一列表头
61
+
62
+
63
+ var _React$useState9 = React.useState(),
64
+ _React$useState10 = _slicedToArray(_React$useState9, 2),
65
+ editHeardCellKey = _React$useState10[0],
66
+ setEditHeardCellkey = _React$useState10[1]; // 记录临时加的列头
67
+
68
+
69
+ var _React$useState11 = React.useState([]),
70
+ _React$useState12 = _slicedToArray(_React$useState11, 2),
71
+ addColumns = _React$useState12[0],
72
+ setAddColumns = _React$useState12[1];
73
+
74
+ var addColumnsRef = React.useRef([]); // 记录上一次发生改变的行值
56
75
 
57
76
  var lastValueRef = React.useRef(); // 记录上一次的datasource
58
77
 
@@ -62,6 +81,35 @@ var Editable = function Editable(props) {
62
81
  var editableStream = React.useMemo(function () {
63
82
  return new BehaviorSubject(undefined);
64
83
  }, []);
84
+
85
+ var processAddColumnsData = function processAddColumnsData(data) {
86
+ var _columns = addColumnsRef.current.length > 0 ? addColumnsRef.current : columns; // 判断key是否重复
87
+
88
+
89
+ if (_columns.findIndex(function (v) {
90
+ return v.key === data.key;
91
+ }) > -1) {
92
+ _message.warning('表格的key不可以重复');
93
+
94
+ return;
95
+ }
96
+
97
+ var idx = _columns.findIndex(function (v) {
98
+ return v.dataIndex === data.dataIndex;
99
+ });
100
+
101
+ var obj = {
102
+ title: data.title,
103
+ key: data.key,
104
+ dataIndex: data.key
105
+ };
106
+
107
+ _columns.splice(idx + 1, 0, _objectSpread(_objectSpread({}, _columns[0]), obj));
108
+
109
+ setAddColumns(_toConsumableArray(_columns));
110
+ addColumnsRef.current = _columns; // editableStream.next({ type: 'editHeardCellKey', payload: undefined });
111
+ };
112
+
65
113
  var processStreamFactory = React.useCallback(function (data) {
66
114
  switch (data === null || data === void 0 ? void 0 : data.type) {
67
115
  case 'onValuesChange':
@@ -69,8 +117,18 @@ var Editable = function Editable(props) {
69
117
 
70
118
  if (type === 'multiple') {
71
119
  var _records = recordsRef.current;
72
- _records[data.payload.rowIdx] = data.payload.allValues;
120
+ _records[data.payload.rowIdx] = _objectSpread(_objectSpread({}, _records[data.payload.rowIdx]), data.payload.allValues);
73
121
  onMulChange && onMulChange(_records);
122
+ } // type为freedom时候处理records
123
+
124
+
125
+ if (type === 'freedom') {
126
+ var _records2 = recordsRef.current;
127
+ _records2[data.payload.rowIdx] = _objectSpread(_objectSpread({}, _records2[data.payload.rowIdx]), data.payload.allValues);
128
+ setRecords(_toConsumableArray(_records2));
129
+ onMulChange && onMulChange(_objectSpread(_objectSpread({}, data.payload), {}, {
130
+ records: _records2
131
+ }));
74
132
  }
75
133
 
76
134
  break;
@@ -86,6 +144,21 @@ var Editable = function Editable(props) {
86
144
  editRowKeyRef.current = data.payload._rowKey_;
87
145
  break;
88
146
 
147
+ case 'editCellKey':
148
+ setEditCellkey({
149
+ dataIndex: data.payload.dataIndex,
150
+ rowIndex: data.payload.rowIndex
151
+ });
152
+ break;
153
+
154
+ case 'editHeardCellKey':
155
+ setEditHeardCellkey(data.payload);
156
+ break;
157
+
158
+ case 'onAddColumn':
159
+ processAddColumnsData(data.payload);
160
+ break;
161
+
89
162
  case 'onSingleSave':
90
163
  if (lastValueRef.current && lastValueRef.current.rowIdx === data.payload._rowKey_) {
91
164
  onRowConfirm && onRowConfirm({
@@ -113,12 +186,32 @@ var Editable = function Editable(props) {
113
186
  }
114
187
 
115
188
  if (type === 'multiple') {
116
- var _records2 = recordsRef.current;
189
+ var _records3 = recordsRef.current;
117
190
 
118
- _records2.splice(data.payload._rowKey_, 1);
191
+ _records3.splice(data.payload._rowKey_, 1);
119
192
 
120
- setRecords(_toConsumableArray(_records2));
121
- recordsRef.current = _records2;
193
+ setRecords(_toConsumableArray(_records3));
194
+ recordsRef.current = _records3;
195
+ }
196
+
197
+ if (type === 'freedom') {
198
+ // 正在全行编辑的直接删除,不需要回调
199
+ if (isFreeEditRow(editRowKeyRef.current, data.payload._rowKey_)) {
200
+ var _records4 = recordsRef.current;
201
+
202
+ _records4.splice(data.payload._rowKey_, 1);
203
+
204
+ setRecords(_toConsumableArray(_records4));
205
+ recordsRef.current = _records4; // 移除当前的行的编辑状态
206
+
207
+ var _editRowKey = removeCurKeyFromEditRow(editRowKeyRef.current, data.payload._rowKey_);
208
+
209
+ setEditRowkey(_editRowKey);
210
+ editRowKeyRef.current = _editRowKey;
211
+ return;
212
+ }
213
+
214
+ onRowDelete && onRowDelete(data.payload);
122
215
  }
123
216
 
124
217
  break;
@@ -156,18 +249,30 @@ var Editable = function Editable(props) {
156
249
  _column.onCell = function (record, rowIndex) {
157
250
  return _objectSpread(_objectSpread({
158
251
  record: record,
159
- editableType: type
252
+ editableType: type,
253
+ isAddColumn: isAddColumn
160
254
  }, pick(column, ['editable', 'title', 'dataIndex', 'type', 'enum', 'disabled'])), {}, {
161
255
  rowIndex: rowIndex
162
256
  });
163
257
  };
164
258
  }
165
259
 
260
+ if (isAddColumn) {
261
+ _column.onHeaderCell = function (col) {
262
+ return _objectSpread({
263
+ width: col.width,
264
+ isAddColumn: isAddColumn
265
+ }, pick(column, ['title', 'dataIndex']));
266
+ };
267
+ }
268
+
166
269
  return _column;
167
270
  }, [readonly, type]); // 处理一下编辑表格的数据
168
271
 
169
272
  var _columns = React.useMemo(function () {
170
- var res = columns.map(getEditColumn);
273
+ var __columns__ = addColumns && addColumns.length > 0 ? addColumns : columns;
274
+
275
+ var res = __columns__.map(getEditColumn);
171
276
 
172
277
  if (!readonly) {
173
278
  var _aciton_ = {
@@ -189,7 +294,7 @@ var Editable = function Editable(props) {
189
294
  }
190
295
 
191
296
  return res;
192
- }, [columns, readonly, type]); // 主要是自己加一层rowkey
297
+ }, [columns, readonly, type, addColumns]); // 主要是自己加一层rowkey
193
298
 
194
299
 
195
300
  var _dataSource = React.useMemo(function () {
@@ -217,6 +322,19 @@ var Editable = function Editable(props) {
217
322
  _records.push(defaultValue);
218
323
  }
219
324
 
325
+ if (type === 'freedom') {
326
+ var _editRowKeyRef$curren;
327
+
328
+ var _editRowKeyArr = ((_editRowKeyRef$curren = editRowKeyRef.current) === null || _editRowKeyRef$curren === void 0 ? void 0 : _editRowKeyRef$curren.toString().split(',')) || ['undefined'];
329
+
330
+ var _curKey = addPosition === 'top' ? _editRowKeyArr.length - 1 : _records.length - 1;
331
+
332
+ var _editRowKey = "".concat(editRowKeyRef.current, ",").concat(_curKey);
333
+
334
+ setEditRowkey(_editRowKey);
335
+ editRowKeyRef.current = _editRowKey;
336
+ }
337
+
220
338
  setRecords(_toConsumableArray(_records));
221
339
  recordsRef.current = _records;
222
340
  }
@@ -227,7 +345,9 @@ var Editable = function Editable(props) {
227
345
  editableStream: editableStream,
228
346
  editConfig: {
229
347
  curRow: editRowKey,
230
- type: editType
348
+ type: editType,
349
+ editCellKey: editCellKey,
350
+ editHeardCellKey: editHeardCellKey
231
351
  }
232
352
  }
233
353
  }, /*#__PURE__*/React.createElement(_Table, _extends({
@@ -239,6 +359,9 @@ var Editable = function Editable(props) {
239
359
  columns: _columns,
240
360
  dataSource: _dataSource,
241
361
  components: {
362
+ header: {
363
+ cell: EditableHeardCell
364
+ },
242
365
  body: {
243
366
  row: EditableRow,
244
367
  cell: EditableCell
@@ -250,7 +373,7 @@ var Editable = function Editable(props) {
250
373
  index: index
251
374
  };
252
375
  }
253
- })), type === 'multiple' && /*#__PURE__*/React.createElement(_Button, {
376
+ })), (type === 'multiple' || type === 'freedom') && /*#__PURE__*/React.createElement(_Button, {
254
377
  block: true,
255
378
  type: "dashed",
256
379
  style: {
@@ -5,17 +5,25 @@ export interface EditableCellProps extends React.HTMLAttributes<HTMLElement> {
5
5
  title: any;
6
6
  editable: boolean;
7
7
  disabled?: boolean;
8
- dataIndex: number;
8
+ dataIndex: string;
9
+ isAddColumn: boolean;
9
10
  rowIndex: number;
10
11
  record: any;
11
12
  type: InputType;
12
- editableType: 'single' | 'multiple';
13
+ editableType: 'single' | 'multiple' | 'freedom';
13
14
  enum?: {
14
15
  label: string;
15
16
  value: string;
16
17
  }[];
17
18
  children: React.ReactNode;
18
19
  }
20
+ export interface EditableHeardCellProps extends React.HTMLAttributes<HTMLElement> {
21
+ title: any;
22
+ width: number;
23
+ isAddColumn: boolean;
24
+ dataIndex: string;
25
+ children: React.ReactNode;
26
+ }
19
27
  export interface EditableRowProps extends React.HTMLAttributes<HTMLElement> {
20
28
  rowIndex: number;
21
29
  record?: any;
@@ -38,21 +46,22 @@ export interface IEditableContextProps {
38
46
  /**
39
47
  * 当前编辑的行
40
48
  */
41
- curRow: number;
49
+ curRow: number | string;
42
50
  /**
43
51
  * 当前行是编辑还是新增
44
52
  */
45
53
  type: 'edit' | 'add';
54
+ editCellKey: {
55
+ dataIndex: string;
56
+ rowIndex: number;
57
+ };
58
+ editHeardCellKey: string;
46
59
  };
47
60
  }
48
61
  export declare const EditableContext: React.Context<IEditableContextProps>;
49
- export interface IMultipleProps {
50
- /**
51
- * 新增一列 默认的值
52
- */
53
- defaultValue: any;
54
- /**
55
- * 添加行的位置
56
- */
57
- addPosition?: 'top' | 'bottom';
62
+ export interface ICommonProps {
63
+ }
64
+ export interface IMultipleProps extends ICommonProps {
65
+ }
66
+ export interface IFreedomProps extends ICommonProps {
58
67
  }
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * @Author: wangxian
3
3
  * @Date: 2022-03-04 15:07:57
4
- * @LastEditTime: 2022-03-08 13:59:06
4
+ * @LastEditTime: 2022-03-10 13:49:40
5
5
  */
6
6
  import React from 'react';
7
7
  export var EditableContext = /*#__PURE__*/React.createContext(null);
@@ -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-04 15:28:47
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
  }
@@ -5,6 +5,7 @@ interface IMetaPropsEditProps {
5
5
  metadataTag?: string;
6
6
  name: string;
7
7
  isEdit?: boolean;
8
+ isAddFields?: boolean;
8
9
  onAddFields?: (idx: number) => void;
9
10
  onNewRefClick?: () => void;
10
11
  }
@@ -23,6 +23,8 @@ var MetaPropsEdit = function MetaPropsEdit(props) {
23
23
  id = props.id,
24
24
  metadataTag = props.metadataTag,
25
25
  name = props.name,
26
+ _props$isAddFields = props.isAddFields,
27
+ isAddFields = _props$isAddFields === void 0 ? true : _props$isAddFields,
26
28
  onAddFields = props.onAddFields,
27
29
  onNewRefClick = props.onNewRefClick;
28
30
 
@@ -320,7 +322,7 @@ var MetaPropsEdit = function MetaPropsEdit(props) {
320
322
  },
321
323
  block: true,
322
324
  icon: /*#__PURE__*/React.createElement(PlusOutlined, null)
323
- }, "\u6DFB\u52A0".concat(name, "\u540D\u79F0"))), /*#__PURE__*/React.createElement(_Form.Item, null, /*#__PURE__*/React.createElement(_Button, {
325
+ }, "\u6DFB\u52A0".concat(name, "\u540D\u79F0"))), isAddFields && /*#__PURE__*/React.createElement(_Form.Item, null, /*#__PURE__*/React.createElement(_Button, {
324
326
  type: "dashed",
325
327
  onClick: function onClick() {
326
328
  onAddFields(-1);
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.42",
4
+ "version": "1.0.45",
5
5
  "scripts": {
6
6
  "start": "dumi dev",
7
7
  "docs:build": "dumi build",