ronds-metadata 1.0.42 → 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,24 +6,38 @@ 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-08 17:22:26
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.input.setSelectionRange(0, inputRef.current.state.value.length); // 选中内容
30
+
31
+ inputRef.current.focus(); // 设置焦点
32
+ }
33
+ }, [editConfig]);
21
34
  return /*#__PURE__*/React.createElement(_Form.Item, {
22
35
  name: dataIndex,
23
36
  style: {
24
37
  margin: 0
25
38
  }
26
39
  }, /*#__PURE__*/React.createElement(_Input, {
40
+ ref: inputRef,
27
41
  disabled: editConfig.type === 'edit' ? disabled : false
28
42
  }));
29
43
  }
@@ -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,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-08 14:06:58
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,12 +17,43 @@ var EditableCell = function EditableCell(props) {
19
17
  restProps = _objectWithoutProperties(props, _excluded);
20
18
 
21
19
  var _ref = React.useContext(EditableContext) || undefined,
20
+ editableStream = _ref.editableStream,
22
21
  editConfig = _ref.editConfig;
23
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
+ };
42
+
24
43
  if (editableType === 'single') {
25
44
  return /*#__PURE__*/React.createElement("td", restProps, editable && editConfig.curRow === rowIndex ? getDataCell(props) : children);
26
45
  }
27
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);
55
+ }
56
+
28
57
  return /*#__PURE__*/React.createElement("td", restProps, editable ? getDataCell(props) : children);
29
58
  };
30
59
 
@@ -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
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
  */
@@ -3,9 +3,9 @@ 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 _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
7
6
  import "antd/es/message/style";
8
7
  import _message from "antd/es/message";
8
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
9
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';
@@ -22,18 +22,14 @@ 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
30
  onRowDelete = props.onRowDelete,
33
31
  onMulChange = props.onMulChange,
34
32
  getStreamInstance = props.getStreamInstance;
35
- var defaultValue = multipleProps.defaultValue,
36
- addPosition = multipleProps.addPosition;
37
33
 
38
34
  var _React$useState = React.useState([]),
39
35
  _React$useState2 = _slicedToArray(_React$useState, 2),
@@ -52,7 +48,13 @@ var Editable = function Editable(props) {
52
48
  editType = _React$useState6[0],
53
49
  setEditType = _React$useState6[1];
54
50
 
55
- var editRowKeyRef = React.useRef(); // 记录上一次发生改变的行值
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
+
56
58
 
57
59
  var lastValueRef = React.useRef(); // 记录上一次的datasource
58
60
 
@@ -69,8 +71,18 @@ var Editable = function Editable(props) {
69
71
 
70
72
  if (type === 'multiple') {
71
73
  var _records = recordsRef.current;
72
- _records[data.payload.rowIdx] = data.payload.allValues;
74
+ _records[data.payload.rowIdx] = _objectSpread(_objectSpread({}, _records[data.payload.rowIdx]), data.payload.allValues);
73
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
+ }));
74
86
  }
75
87
 
76
88
  break;
@@ -86,6 +98,14 @@ var Editable = function Editable(props) {
86
98
  editRowKeyRef.current = data.payload._rowKey_;
87
99
  break;
88
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
+
89
109
  case 'onSingleSave':
90
110
  if (lastValueRef.current && lastValueRef.current.rowIdx === data.payload._rowKey_) {
91
111
  onRowConfirm && onRowConfirm({
@@ -113,12 +133,17 @@ var Editable = function Editable(props) {
113
133
  }
114
134
 
115
135
  if (type === 'multiple') {
116
- var _records2 = recordsRef.current;
136
+ var _records3 = recordsRef.current;
117
137
 
118
- _records2.splice(data.payload._rowKey_, 1);
138
+ _records3.splice(data.payload._rowKey_, 1);
119
139
 
120
- setRecords(_toConsumableArray(_records2));
121
- recordsRef.current = _records2;
140
+ setRecords(_toConsumableArray(_records3));
141
+ recordsRef.current = _records3;
142
+ }
143
+
144
+ if (type === 'freedom') {
145
+ // 正在全行编辑的直接删除,不需要回调
146
+ onRowDelete && onRowDelete(data.payload);
122
147
  }
123
148
 
124
149
  break;
@@ -217,6 +242,19 @@ var Editable = function Editable(props) {
217
242
  _records.push(defaultValue);
218
243
  }
219
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
+
220
258
  setRecords(_toConsumableArray(_records));
221
259
  recordsRef.current = _records;
222
260
  }
@@ -227,7 +265,8 @@ var Editable = function Editable(props) {
227
265
  editableStream: editableStream,
228
266
  editConfig: {
229
267
  curRow: editRowKey,
230
- type: editType
268
+ type: editType,
269
+ editCellKey: editCellKey
231
270
  }
232
271
  }
233
272
  }, /*#__PURE__*/React.createElement(_Table, _extends({
@@ -250,7 +289,7 @@ var Editable = function Editable(props) {
250
289
  index: index
251
290
  };
252
291
  }
253
- })), type === 'multiple' && /*#__PURE__*/React.createElement(_Button, {
292
+ })), (type === 'multiple' || type === 'freedom') && /*#__PURE__*/React.createElement(_Button, {
254
293
  block: true,
255
294
  type: "dashed",
256
295
  style: {
@@ -5,11 +5,11 @@ 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
9
  rowIndex: number;
10
10
  record: any;
11
11
  type: InputType;
12
- editableType: 'single' | 'multiple';
12
+ editableType: 'single' | 'multiple' | 'freedom';
13
13
  enum?: {
14
14
  label: string;
15
15
  value: string;
@@ -38,21 +38,21 @@ export interface IEditableContextProps {
38
38
  /**
39
39
  * 当前编辑的行
40
40
  */
41
- curRow: number;
41
+ curRow: number | string;
42
42
  /**
43
43
  * 当前行是编辑还是新增
44
44
  */
45
45
  type: 'edit' | 'add';
46
+ editCellKey: {
47
+ dataIndex: string;
48
+ rowIndex: number;
49
+ };
46
50
  };
47
51
  }
48
52
  export declare const EditableContext: React.Context<IEditableContextProps>;
49
- export interface IMultipleProps {
50
- /**
51
- * 新增一列 默认的值
52
- */
53
- defaultValue: any;
54
- /**
55
- * 添加行的位置
56
- */
57
- addPosition?: 'top' | 'bottom';
53
+ export interface ICommonProps {
54
+ }
55
+ export interface IMultipleProps extends ICommonProps {
56
+ }
57
+ export interface IFreedomProps extends ICommonProps {
58
58
  }
@@ -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-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.42",
4
+ "version": "1.0.43",
5
5
  "scripts": {
6
6
  "start": "dumi dev",
7
7
  "docs:build": "dumi build",