ronds-metadata 1.0.39 → 1.0.42

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/README.md CHANGED
@@ -1,25 +1,25 @@
1
- # ronds-metadata
2
-
3
- # 使用前准备
4
-
5
- 在使用之前,推荐学习[容知的元数据规则](http://172.16.0.8:5000/oo/r/634418027609242111)
6
-
7
- # 安装及使用
8
-
9
- ## 安装
10
-
11
- ```
12
- yarn add ronds-metadata
13
- ```
14
-
15
- ## 使用
16
-
17
- ### 引入所需组件
18
-
19
- 在代码中 import 需要的组件并按照文档说明使用
20
-
21
- ```
22
- import { MetadataFrom, MetadataEdit, JsonView, JsonEdit } from 'ronds-metadata';
23
-
24
- import { JsonMetadataProvider } from 'ronds-metadata/es/framework/metadata/index';
25
- ```
1
+ # ronds-metadata
2
+
3
+ # 使用前准备
4
+
5
+ 在使用之前,推荐学习[容知的元数据规则](http://172.16.0.8:5000/oo/r/634418027609242111)
6
+
7
+ # 安装及使用
8
+
9
+ ## 安装
10
+
11
+ ```
12
+ yarn add ronds-metadata
13
+ ```
14
+
15
+ ## 使用
16
+
17
+ ### 引入所需组件
18
+
19
+ 在代码中 import 需要的组件并按照文档说明使用
20
+
21
+ ```
22
+ import { MetadataFrom, MetadataEdit, JsonView, JsonEdit } from 'ronds-metadata';
23
+
24
+ import { JsonMetadataProvider } from 'ronds-metadata/es/framework/metadata/index';
25
+ ```
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import { EditableCellProps } from '../interface';
3
+ declare function Index(props: EditableCellProps): JSX.Element;
4
+ declare const _default: React.MemoExoticComponent<typeof Index>;
5
+ export default _default;
@@ -0,0 +1,31 @@
1
+ import "antd/es/form/style";
2
+ import _Form from "antd/es/form";
3
+ import "antd/es/input/style";
4
+ import _Input from "antd/es/input";
5
+
6
+ /*
7
+ * @Author: wangxian
8
+ * @Date: 2022-03-04 14:53:50
9
+ * @LastEditTime: 2022-03-08 14:16:12
10
+ */
11
+ import React from 'react';
12
+ import { EditableContext } from '../interface';
13
+
14
+ function Index(props) {
15
+ var dataIndex = props.dataIndex,
16
+ disabled = props.disabled;
17
+
18
+ var _ref = React.useContext(EditableContext) || undefined,
19
+ editConfig = _ref.editConfig;
20
+
21
+ return /*#__PURE__*/React.createElement(_Form.Item, {
22
+ name: dataIndex,
23
+ style: {
24
+ margin: 0
25
+ }
26
+ }, /*#__PURE__*/React.createElement(_Input, {
27
+ disabled: editConfig.type === 'edit' ? disabled : false
28
+ }));
29
+ }
30
+
31
+ export default /*#__PURE__*/React.memo(Index);
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ declare function Index(props: any): JSX.Element;
3
+ declare const _default: React.MemoExoticComponent<typeof Index>;
4
+ export default _default;
@@ -0,0 +1,31 @@
1
+ import "antd/es/form/style";
2
+ import _Form from "antd/es/form";
3
+ import "antd/es/input-number/style";
4
+ import _InputNumber from "antd/es/input-number";
5
+
6
+ /*
7
+ * @Author: wangxian
8
+ * @Date: 2022-03-04 14:53:50
9
+ * @LastEditTime: 2022-03-08 14:16:01
10
+ */
11
+ import React from 'react';
12
+ import { EditableContext } from '../interface';
13
+
14
+ function Index(props) {
15
+ var dataIndex = props.dataIndex,
16
+ disabled = props.disabled;
17
+
18
+ var _ref = React.useContext(EditableContext) || undefined,
19
+ editConfig = _ref.editConfig;
20
+
21
+ return /*#__PURE__*/React.createElement(_Form.Item, {
22
+ name: dataIndex,
23
+ style: {
24
+ margin: 0
25
+ }
26
+ }, /*#__PURE__*/React.createElement(_InputNumber, {
27
+ disabled: editConfig.type === 'edit' ? disabled : false
28
+ }));
29
+ }
30
+
31
+ export default /*#__PURE__*/React.memo(Index);
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import { EditableCellProps } from '../interface';
3
+ declare function Index(props: EditableCellProps): JSX.Element;
4
+ declare const _default: React.MemoExoticComponent<typeof Index>;
5
+ export default _default;
@@ -0,0 +1,38 @@
1
+ import "antd/es/form/style";
2
+ import _Form from "antd/es/form";
3
+ import "antd/es/select/style";
4
+ import _Select from "antd/es/select";
5
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
6
+ var _excluded = ["dataIndex", "disabled"];
7
+
8
+ /*
9
+ * @Author: wangxian
10
+ * @Date: 2022-03-04 14:53:50
11
+ * @LastEditTime: 2022-03-08 14:14:18
12
+ */
13
+ import React from 'react';
14
+ import { EditableContext } from '../interface';
15
+
16
+ function Index(props) {
17
+ var dataIndex = props.dataIndex,
18
+ disabled = props.disabled,
19
+ restProps = _objectWithoutProperties(props, _excluded);
20
+
21
+ var _ref = React.useContext(EditableContext) || undefined,
22
+ editConfig = _ref.editConfig;
23
+
24
+ return /*#__PURE__*/React.createElement(_Form.Item, {
25
+ name: dataIndex,
26
+ style: {
27
+ margin: 0
28
+ }
29
+ }, /*#__PURE__*/React.createElement(_Select, {
30
+ disabled: editConfig.type === 'edit' ? disabled : false,
31
+ style: {
32
+ width: '100%'
33
+ },
34
+ options: restProps.enum
35
+ }));
36
+ }
37
+
38
+ export default /*#__PURE__*/React.memo(Index);
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ declare function Index(props: any): JSX.Element;
3
+ declare const _default: React.MemoExoticComponent<typeof Index>;
4
+ export default _default;
@@ -0,0 +1,32 @@
1
+ import "antd/es/form/style";
2
+ import _Form from "antd/es/form";
3
+ import "antd/es/switch/style";
4
+ import _Switch from "antd/es/switch";
5
+
6
+ /*
7
+ * @Author: wangxian
8
+ * @Date: 2022-03-04 14:53:50
9
+ * @LastEditTime: 2022-03-08 14:14:22
10
+ */
11
+ import React from 'react';
12
+ import { EditableContext } from '../interface';
13
+
14
+ function Index(props) {
15
+ var dataIndex = props.dataIndex,
16
+ disabled = props.disabled;
17
+
18
+ var _ref = React.useContext(EditableContext) || undefined,
19
+ editConfig = _ref.editConfig;
20
+
21
+ return /*#__PURE__*/React.createElement(_Form.Item, {
22
+ name: dataIndex,
23
+ valuePropName: "checked",
24
+ style: {
25
+ margin: 0
26
+ }
27
+ }, /*#__PURE__*/React.createElement(_Switch, {
28
+ disabled: editConfig.type === 'edit' ? disabled : false
29
+ }));
30
+ }
31
+
32
+ export default /*#__PURE__*/React.memo(Index);
@@ -0,0 +1,6 @@
1
+ interface IEditableActionProps {
2
+ type: 'single' | 'multiple';
3
+ record: any;
4
+ }
5
+ declare const EditableAction: (props: IEditableActionProps) => JSX.Element;
6
+ export default EditableAction;
@@ -0,0 +1,81 @@
1
+ import "antd/es/divider/style";
2
+ import _Divider from "antd/es/divider";
3
+ import "antd/es/button/style";
4
+ import _Button from "antd/es/button";
5
+ import { EditOutlined, CloseOutlined, CheckOutlined, DeleteOutlined } from '@ant-design/icons';
6
+ import React from 'react';
7
+ import { EditableContext } from '../interface';
8
+
9
+ var EditableAction = function EditableAction(props) {
10
+ var type = props.type,
11
+ record = props.record;
12
+
13
+ var _ref = React.useContext(EditableContext) || undefined,
14
+ editableStream = _ref.editableStream,
15
+ editConfig = _ref.editConfig;
16
+
17
+ var onEdit = function onEdit() {
18
+ editableStream.next({
19
+ type: 'editRowKey',
20
+ payload: record
21
+ });
22
+ };
23
+
24
+ var onCancel = function onCancel() {
25
+ editableStream.next({
26
+ type: 'editRowKey',
27
+ payload: {
28
+ _rowkey_: undefined
29
+ }
30
+ });
31
+ };
32
+
33
+ var onSave = function onSave() {
34
+ editableStream.next({
35
+ type: 'onSingleSave',
36
+ payload: record
37
+ });
38
+ };
39
+
40
+ var onDelete = function onDelete() {
41
+ editableStream.next({
42
+ type: 'onDelete',
43
+ payload: record
44
+ });
45
+ };
46
+
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
+ type: "link",
49
+ disabled: (editConfig.curRow || editConfig.curRow === 0) && editConfig.curRow !== record._rowKey_,
50
+ size: "small",
51
+ icon: /*#__PURE__*/React.createElement(EditOutlined, null),
52
+ onClick: onEdit,
53
+ title: '编辑'
54
+ }), /*#__PURE__*/React.createElement(_Divider, {
55
+ type: "vertical"
56
+ })), editConfig.curRow === record._rowKey_ && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_Button, {
57
+ type: "link",
58
+ size: "small",
59
+ icon: /*#__PURE__*/React.createElement(CheckOutlined, null),
60
+ onClick: onSave,
61
+ title: '确定'
62
+ }), /*#__PURE__*/React.createElement(_Divider, {
63
+ type: "vertical"
64
+ }), /*#__PURE__*/React.createElement(_Button, {
65
+ type: "link",
66
+ size: "small",
67
+ icon: /*#__PURE__*/React.createElement(CloseOutlined, null),
68
+ onClick: onCancel,
69
+ title: '取消'
70
+ }), /*#__PURE__*/React.createElement(_Divider, {
71
+ type: "vertical"
72
+ }))), /*#__PURE__*/React.createElement(_Button, {
73
+ type: "link",
74
+ size: "small",
75
+ icon: /*#__PURE__*/React.createElement(DeleteOutlined, null),
76
+ onClick: onDelete,
77
+ title: '删除'
78
+ }));
79
+ };
80
+
81
+ export default EditableAction;
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import { EditableCellProps } from '../interface';
3
+ declare const EditableCell: React.FC<EditableCellProps>;
4
+ export default EditableCell;
@@ -0,0 +1,31 @@
1
+ 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
+ */
9
+ import React from 'react';
10
+ import { EditableContext } from '../interface';
11
+ import { getDataCell } from '../utils';
12
+
13
+ var EditableCell = function EditableCell(props) {
14
+ var editable = props.editable,
15
+ editableType = props.editableType,
16
+ dataIndex = props.dataIndex,
17
+ rowIndex = props.rowIndex,
18
+ children = props.children,
19
+ restProps = _objectWithoutProperties(props, _excluded);
20
+
21
+ var _ref = React.useContext(EditableContext) || undefined,
22
+ editConfig = _ref.editConfig;
23
+
24
+ if (editableType === 'single') {
25
+ return /*#__PURE__*/React.createElement("td", restProps, editable && editConfig.curRow === rowIndex ? getDataCell(props) : children);
26
+ }
27
+
28
+ return /*#__PURE__*/React.createElement("td", restProps, editable ? getDataCell(props) : children);
29
+ };
30
+
31
+ export default EditableCell;
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import { EditableRowProps } from '../interface';
3
+ declare const EditableRow: React.FC<EditableRowProps>;
4
+ export default EditableRow;
@@ -0,0 +1,50 @@
1
+ import "antd/es/form/style";
2
+ import _Form from "antd/es/form";
3
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
+ import React from 'react';
5
+ import { EditableContext } from '../interface';
6
+
7
+ var EditableRow = function EditableRow(props) {
8
+ var record = props.record;
9
+
10
+ var _Form$useForm = _Form.useForm(),
11
+ _Form$useForm2 = _slicedToArray(_Form$useForm, 1),
12
+ form = _Form$useForm2[0];
13
+
14
+ var _ref = React.useContext(EditableContext) || undefined,
15
+ editableStream = _ref.editableStream;
16
+
17
+ React.useEffect(function () {
18
+ if (!form) return;
19
+ form.setFieldsValue(record);
20
+ }, [record]); // 编辑的时候初始化值
21
+ // React.useEffect(() => {
22
+ // const subscription = editableStream.pipe(filter((p: any) => p?.type === 'editRowKey')).subscribe((p: IEditableStream) => {
23
+ // form.setFieldsValue(p.payload);
24
+ // });
25
+ // return () => subscription.unsubscribe();
26
+ // }, [editableStream]);
27
+
28
+ var onValuesChange = function onValuesChange(values, allValues) {
29
+ if (editableStream) {
30
+ editableStream.next({
31
+ type: 'onValuesChange',
32
+ payload: {
33
+ rowIdx: record === null || record === void 0 ? void 0 : record._rowKey_,
34
+ values: values,
35
+ allValues: allValues
36
+ }
37
+ });
38
+ }
39
+ };
40
+
41
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_Form, {
42
+ name: "editable_".concat(record === null || record === void 0 ? void 0 : record._rowKey_, "_"),
43
+ form: form,
44
+ initialValues: record,
45
+ onValuesChange: onValuesChange,
46
+ component: false
47
+ }, /*#__PURE__*/React.createElement("tr", props)));
48
+ };
49
+
50
+ export default EditableRow;
@@ -0,0 +1,49 @@
1
+ import { TableProps } from 'antd';
2
+ import { BehaviorSubject } from 'rxjs';
3
+ import { EditColumnsType, IEditableStream, IMultipleProps } from './interface';
4
+ interface IEditableProps<R = any> {
5
+ /**
6
+ * 单行编辑或多行编辑。
7
+ * 备注:
8
+ * type为multiple时,一定要设置defaultValue
9
+ */
10
+ type?: 'single' | 'multiple';
11
+ /**
12
+ * 表格列的配置描述
13
+ */
14
+ columns: EditColumnsType;
15
+ /**
16
+ * 当type为multiple的配置
17
+ */
18
+ multipleProps?: IMultipleProps;
19
+ /**
20
+ * 数据数组
21
+ */
22
+ dataSource: object[];
23
+ /**
24
+ * 只读
25
+ */
26
+ readonly?: boolean;
27
+ /**
28
+ * antd自身的属性
29
+ */
30
+ tableProps?: TableProps<R>;
31
+ /**
32
+ * 每行确认回调函数
33
+ */
34
+ onRowConfirm?: (record: any) => void;
35
+ /**
36
+ * 每行删除回调
37
+ */
38
+ onRowDelete?: (record: any) => void;
39
+ /**
40
+ * 表格数据的change触发事件
41
+ */
42
+ onMulChange?: (records: any) => void;
43
+ /**
44
+ * editable的事件流回调
45
+ */
46
+ getStreamInstance?: (subject: BehaviorSubject<IEditableStream | undefined>) => void;
47
+ }
48
+ declare const Editable: (props: IEditableProps) => JSX.Element;
49
+ export default Editable;
@@ -0,0 +1,264 @@
1
+ import "antd/es/button/style";
2
+ import _Button from "antd/es/button";
3
+ import "antd/es/table/style";
4
+ import _Table from "antd/es/table";
5
+ import _extends from "@babel/runtime/helpers/esm/extends";
6
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
7
+ import "antd/es/message/style";
8
+ import _message from "antd/es/message";
9
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
10
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
11
+ import React from 'react';
12
+ import { BehaviorSubject } from 'rxjs';
13
+ import { pick, isArray } from 'lodash';
14
+ import EditableCell from './comps/EditableCell';
15
+ import EditableRow from './comps/EditableRow';
16
+ import { EditableContext } from './interface';
17
+ import EditableAction from './comps/EditableAction';
18
+
19
+ var Editable = function Editable(props) {
20
+ var _props$type = props.type,
21
+ type = _props$type === void 0 ? 'single' : _props$type,
22
+ readonly = props.readonly,
23
+ columns = props.columns,
24
+ dataSource = props.dataSource,
25
+ _props$multipleProps = props.multipleProps,
26
+ multipleProps = _props$multipleProps === void 0 ? {
27
+ defaultValue: '',
28
+ addPosition: 'bottom'
29
+ } : _props$multipleProps,
30
+ tableProps = props.tableProps,
31
+ onRowConfirm = props.onRowConfirm,
32
+ onRowDelete = props.onRowDelete,
33
+ onMulChange = props.onMulChange,
34
+ getStreamInstance = props.getStreamInstance;
35
+ var defaultValue = multipleProps.defaultValue,
36
+ addPosition = multipleProps.addPosition;
37
+
38
+ var _React$useState = React.useState([]),
39
+ _React$useState2 = _slicedToArray(_React$useState, 2),
40
+ records = _React$useState2[0],
41
+ setRecords = _React$useState2[1];
42
+
43
+ var recordsRef = React.useRef([]); // 当type为single的时候 只能编辑该行数据
44
+
45
+ var _React$useState3 = React.useState(),
46
+ _React$useState4 = _slicedToArray(_React$useState3, 2),
47
+ editRowKey = _React$useState4[0],
48
+ setEditRowkey = _React$useState4[1];
49
+
50
+ var _React$useState5 = React.useState('add'),
51
+ _React$useState6 = _slicedToArray(_React$useState5, 2),
52
+ editType = _React$useState6[0],
53
+ setEditType = _React$useState6[1];
54
+
55
+ var editRowKeyRef = React.useRef(); // 记录上一次发生改变的行值
56
+
57
+ var lastValueRef = React.useRef(); // 记录上一次的datasource
58
+
59
+ var lastDataSourceRef = React.useRef();
60
+ var firstLoadRef = React.useRef(true); // 定义处理编辑表格的数据流
61
+
62
+ var editableStream = React.useMemo(function () {
63
+ return new BehaviorSubject(undefined);
64
+ }, []);
65
+ var processStreamFactory = React.useCallback(function (data) {
66
+ switch (data === null || data === void 0 ? void 0 : data.type) {
67
+ case 'onValuesChange':
68
+ lastValueRef.current = data.payload; // type为multiple时候处理records
69
+
70
+ if (type === 'multiple') {
71
+ var _records = recordsRef.current;
72
+ _records[data.payload.rowIdx] = data.payload.allValues;
73
+ onMulChange && onMulChange(_records);
74
+ }
75
+
76
+ break;
77
+
78
+ case 'editRowKey':
79
+ if (Object.keys(data.payload).length > 1) {
80
+ setEditType('edit');
81
+ } else {
82
+ setEditType('add');
83
+ }
84
+
85
+ setEditRowkey(data.payload._rowKey_);
86
+ editRowKeyRef.current = data.payload._rowKey_;
87
+ break;
88
+
89
+ case 'onSingleSave':
90
+ if (lastValueRef.current && lastValueRef.current.rowIdx === data.payload._rowKey_) {
91
+ onRowConfirm && onRowConfirm({
92
+ rowIdx: lastValueRef.current.rowIdx,
93
+ values: lastValueRef.current.values,
94
+ allValues: _objectSpread(_objectSpread({}, recordsRef.current[lastValueRef.current.rowIdx]), lastValueRef.current.allValues)
95
+ });
96
+ editRowKeyRef.current = undefined;
97
+ setEditRowkey(undefined);
98
+ } else {
99
+ _message.warn('当前值无修改');
100
+ }
101
+
102
+ break;
103
+
104
+ case 'onDelete':
105
+ if (type === 'single') {
106
+ // 如果删除的 是正在编辑的 重置状态
107
+ if (editRowKeyRef.current === data.payload._rowKey_) {
108
+ setEditRowkey(undefined);
109
+ editRowKeyRef.current = undefined;
110
+ }
111
+
112
+ onRowDelete && onRowDelete(data.payload);
113
+ }
114
+
115
+ if (type === 'multiple') {
116
+ var _records2 = recordsRef.current;
117
+
118
+ _records2.splice(data.payload._rowKey_, 1);
119
+
120
+ setRecords(_toConsumableArray(_records2));
121
+ recordsRef.current = _records2;
122
+ }
123
+
124
+ break;
125
+ }
126
+ }, [type]); // 返回stream的实例
127
+
128
+ React.useEffect(function () {
129
+ if (firstLoadRef && editableStream) {
130
+ getStreamInstance && getStreamInstance(editableStream);
131
+ firstLoadRef.current = false;
132
+ }
133
+ }, [editableStream]); // 定义内部的record
134
+
135
+ React.useEffect(function () {
136
+ if (dataSource) {
137
+ setRecords(_toConsumableArray(dataSource));
138
+ recordsRef.current = dataSource;
139
+ }
140
+ }, [dataSource]); // 集中处理数据流
141
+
142
+ React.useEffect(function () {
143
+ var subscription = editableStream.subscribe(function (p) {
144
+ processStreamFactory(p);
145
+ });
146
+ return function () {
147
+ return subscription.unsubscribe();
148
+ };
149
+ }, [editableStream, processStreamFactory]);
150
+ var getEditColumn = React.useCallback(function (column) {
151
+ var _column = _objectSpread(_objectSpread({}, column), {}, {
152
+ children: isArray(column === null || column === void 0 ? void 0 : column.children) ? column.children.map(getEditColumn) : undefined
153
+ });
154
+
155
+ if (column.editable && !readonly) {
156
+ _column.onCell = function (record, rowIndex) {
157
+ return _objectSpread(_objectSpread({
158
+ record: record,
159
+ editableType: type
160
+ }, pick(column, ['editable', 'title', 'dataIndex', 'type', 'enum', 'disabled'])), {}, {
161
+ rowIndex: rowIndex
162
+ });
163
+ };
164
+ }
165
+
166
+ return _column;
167
+ }, [readonly, type]); // 处理一下编辑表格的数据
168
+
169
+ var _columns = React.useMemo(function () {
170
+ var res = columns.map(getEditColumn);
171
+
172
+ if (!readonly) {
173
+ var _aciton_ = {
174
+ dataKey: '_aciton_',
175
+ title: '操作',
176
+ width: 60,
177
+ maxWidth: 60,
178
+ export: false,
179
+ minWidth: 60,
180
+ frozen: 'right',
181
+ render: function render(val, record) {
182
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(EditableAction, {
183
+ type: type,
184
+ record: record
185
+ }));
186
+ }
187
+ };
188
+ res.push(_aciton_);
189
+ }
190
+
191
+ return res;
192
+ }, [columns, readonly, type]); // 主要是自己加一层rowkey
193
+
194
+
195
+ var _dataSource = React.useMemo(function () {
196
+ var res = records.map(function (it, idx) {
197
+ return _objectSpread({
198
+ _rowKey_: idx
199
+ }, it);
200
+ });
201
+
202
+ if (res.length > 0) {
203
+ firstLoadRef.current = false;
204
+ }
205
+
206
+ lastDataSourceRef.current = res;
207
+ return res;
208
+ }, [records, type]);
209
+
210
+ var onAddRow = function onAddRow() {
211
+ if (defaultValue) {
212
+ var _records = recordsRef.current;
213
+
214
+ if (addPosition === 'top') {
215
+ _records.unshift(defaultValue);
216
+ } else {
217
+ _records.push(defaultValue);
218
+ }
219
+
220
+ setRecords(_toConsumableArray(_records));
221
+ recordsRef.current = _records;
222
+ }
223
+ };
224
+
225
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(EditableContext.Provider, {
226
+ value: {
227
+ editableStream: editableStream,
228
+ editConfig: {
229
+ curRow: editRowKey,
230
+ type: editType
231
+ }
232
+ }
233
+ }, /*#__PURE__*/React.createElement(_Table, _extends({
234
+ bordered: true
235
+ }, tableProps, {
236
+ pagination: false,
237
+ rowKey: "_rowKey_",
238
+ size: "small",
239
+ columns: _columns,
240
+ dataSource: _dataSource,
241
+ components: {
242
+ body: {
243
+ row: EditableRow,
244
+ cell: EditableCell
245
+ }
246
+ },
247
+ onRow: function onRow(record, index) {
248
+ return {
249
+ record: record,
250
+ index: index
251
+ };
252
+ }
253
+ })), type === 'multiple' && /*#__PURE__*/React.createElement(_Button, {
254
+ block: true,
255
+ type: "dashed",
256
+ style: {
257
+ marginBottom: 16,
258
+ marginTop: 16
259
+ },
260
+ onClick: onAddRow
261
+ }, "\u6DFB\u52A0\u4E00\u884C")));
262
+ };
263
+
264
+ export default Editable;
@@ -0,0 +1,58 @@
1
+ import { ColumnsType } from 'antd/lib/table/interface';
2
+ import React from 'react';
3
+ import { BehaviorSubject } from 'rxjs';
4
+ export interface EditableCellProps extends React.HTMLAttributes<HTMLElement> {
5
+ title: any;
6
+ editable: boolean;
7
+ disabled?: boolean;
8
+ dataIndex: number;
9
+ rowIndex: number;
10
+ record: any;
11
+ type: InputType;
12
+ editableType: 'single' | 'multiple';
13
+ enum?: {
14
+ label: string;
15
+ value: string;
16
+ }[];
17
+ children: React.ReactNode;
18
+ }
19
+ export interface EditableRowProps extends React.HTMLAttributes<HTMLElement> {
20
+ rowIndex: number;
21
+ record?: any;
22
+ }
23
+ export declare type InputType = 'bool' | 'number' | 'text' | 'enum' | string;
24
+ export interface EditColumnsType extends ColumnsType<any> {
25
+ type?: InputType;
26
+ enum?: {
27
+ label: string;
28
+ value: string;
29
+ }[];
30
+ }
31
+ export interface IEditableStream {
32
+ type: string;
33
+ payload: any;
34
+ }
35
+ export interface IEditableContextProps {
36
+ editableStream: BehaviorSubject<IEditableStream | undefined>;
37
+ editConfig: {
38
+ /**
39
+ * 当前编辑的行
40
+ */
41
+ curRow: number;
42
+ /**
43
+ * 当前行是编辑还是新增
44
+ */
45
+ type: 'edit' | 'add';
46
+ };
47
+ }
48
+ export declare const EditableContext: React.Context<IEditableContextProps>;
49
+ export interface IMultipleProps {
50
+ /**
51
+ * 新增一列 默认的值
52
+ */
53
+ defaultValue: any;
54
+ /**
55
+ * 添加行的位置
56
+ */
57
+ addPosition?: 'top' | 'bottom';
58
+ }
@@ -0,0 +1,7 @@
1
+ /*
2
+ * @Author: wangxian
3
+ * @Date: 2022-03-04 15:07:57
4
+ * @LastEditTime: 2022-03-08 13:59:06
5
+ */
6
+ import React from 'react';
7
+ export var EditableContext = /*#__PURE__*/React.createContext(null);
@@ -0,0 +1,2 @@
1
+ import { EditableCellProps } from './interface';
2
+ export declare function getDataCell(item: EditableCellProps): JSX.Element;
@@ -0,0 +1,24 @@
1
+ /*
2
+ * @Author: wangxian
3
+ * @Date: 2022-03-04 14:59:04
4
+ * @LastEditTime: 2022-03-04 15:28:47
5
+ */
6
+ import React from 'react';
7
+ import Input from './DataCell/Input';
8
+ import Number from './DataCell/Number';
9
+ import Select from './DataCell/Select';
10
+ import Switch from './DataCell/Switch';
11
+ var DataCellMap = {
12
+ text: Input,
13
+ number: Number,
14
+ enum: Select,
15
+ bool: Switch
16
+ };
17
+ export function getDataCell(item) {
18
+ if (item.type && DataCellMap[item.type]) {
19
+ var Comm = DataCellMap[item.type];
20
+ return /*#__PURE__*/React.createElement(Comm, item);
21
+ }
22
+
23
+ return null;
24
+ }
@@ -1,5 +1,4 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import _createClass from "@babel/runtime/helpers/esm/createClass";
3
2
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
4
3
  import { cloneDeep } from 'lodash';
5
4
  /**
@@ -8,7 +7,7 @@ import { cloneDeep } from 'lodash';
8
7
  * @class httpCache
9
8
  */
10
9
 
11
- var HttpCache = /*#__PURE__*/_createClass(function HttpCache() {
10
+ var HttpCache = function HttpCache() {
12
11
  var _this = this;
13
12
 
14
13
  _classCallCheck(this, HttpCache);
@@ -132,7 +131,7 @@ var HttpCache = /*#__PURE__*/_createClass(function HttpCache() {
132
131
  });
133
132
  }
134
133
  };
135
- });
134
+ };
136
135
 
137
136
  window.rondsGraphCache = window.rondsGraphCache ? window.rondsGraphCache : new HttpCache();
138
137
  export default window.rondsGraphCache;
@@ -64,7 +64,7 @@ httpClient.defaults.timeout = defaultOptions.timeout;
64
64
  * @template T
65
65
  */
66
66
 
67
- export var BaseResData = /*#__PURE__*/_createClass(function BaseResData(data, successed) {
67
+ export var BaseResData = function BaseResData(data, successed) {
68
68
  var msg = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
69
69
  var status = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 200;
70
70
  var errData = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
@@ -94,7 +94,7 @@ export var BaseResData = /*#__PURE__*/_createClass(function BaseResData(data, su
94
94
  if (this.successed === false) {
95
95
  this.data = undefined;
96
96
  }
97
- }); //数据转换拦截器
97
+ }; //数据转换拦截器
98
98
 
99
99
  httpClient.interceptors.response.use(function (response) {
100
100
  //正常数据
@@ -47,12 +47,12 @@ export var Enum = /*#__PURE__*/function () {
47
47
 
48
48
  return Enum;
49
49
  }();
50
- export var Array = /*#__PURE__*/_createClass(function Array(items) {
50
+ export var Array = function Array(items) {
51
51
  _classCallCheck(this, Array);
52
52
 
53
53
  this.items = void 0;
54
54
  this.items = items;
55
- });
55
+ };
56
56
  export var MetaObject = /*#__PURE__*/function () {
57
57
  function MetaObject() {
58
58
  _classCallCheck(this, MetaObject);
@@ -1,87 +1,87 @@
1
- export type IMetaType = 'object' | 'ref' | 'bool' | 'number' | 'text' | 'enum' | 'array' | string;
2
-
3
- export type IMetaData = {
4
- /**
5
- * 类名称/属性名称
6
- */
7
- id: string;
8
- /**
9
- * 类型
10
- */
11
- type: IMetaType;
12
- /**
13
- * 属性
14
- */
15
- properties?: IMetaProperties[];
16
-
17
- /**
18
- * 引用id
19
- */
20
- refId?: string;
21
- /**
22
- * 静态的变量
23
- */
24
- fields?: IMetaFileds[];
25
- };
26
-
27
- export type IMetaProperties = {
28
- /**
29
- * 类规则名称
30
- */
31
- id: string;
32
-
33
- /**
34
- * 类型
35
- */
36
- type: IMetaType;
37
-
38
- /**
39
- * 引用id
40
- */
41
- refId?: string;
42
- /**
43
- * 静态的变量
44
- */
45
- fields?: IMetaFileds[];
46
- /**
47
- * 枚举值
48
- */
49
- enum?: { value: string }[];
50
- /**
51
- * 数组类型
52
- */
53
- items?: { type: IMetaType; refId?: string };
54
- };
55
-
56
- export type IMetaFileds = {
57
- /**
58
- * 规则名称
59
- */
60
- id: string;
61
-
62
- /**
63
- * 类型
64
- */
65
- type: IMetaType;
66
-
67
- /**
68
- * 引用id
69
- */
70
- refId?: string;
71
-
72
- /**
73
- * 规则值
74
- */
75
- value: any;
76
- };
77
-
78
- export interface IAPI {
79
- // 获取元数据列表
80
- GetMetadataList(keyWords?: string[]): Promise<{ id: string; name: string; schema: string }[]>;
81
- // 通过元数据Id获取元数据详情
82
- GetMetadataDetailById(metadataId: string): Promise<any>;
83
- // 新增元数据
84
- SaveMetadata(data: any, metadataTag: string): Promise<any>;
85
- // 获取元数据的值
86
- GetMetadataObjList(data: any): Promise<any[]>;
87
- }
1
+ export type IMetaType = 'object' | 'ref' | 'bool' | 'number' | 'text' | 'enum' | 'array' | string;
2
+
3
+ export type IMetaData = {
4
+ /**
5
+ * 类名称/属性名称
6
+ */
7
+ id: string;
8
+ /**
9
+ * 类型
10
+ */
11
+ type: IMetaType;
12
+ /**
13
+ * 属性
14
+ */
15
+ properties?: IMetaProperties[];
16
+
17
+ /**
18
+ * 引用id
19
+ */
20
+ refId?: string;
21
+ /**
22
+ * 静态的变量
23
+ */
24
+ fields?: IMetaFileds[];
25
+ };
26
+
27
+ export type IMetaProperties = {
28
+ /**
29
+ * 类规则名称
30
+ */
31
+ id: string;
32
+
33
+ /**
34
+ * 类型
35
+ */
36
+ type: IMetaType;
37
+
38
+ /**
39
+ * 引用id
40
+ */
41
+ refId?: string;
42
+ /**
43
+ * 静态的变量
44
+ */
45
+ fields?: IMetaFileds[];
46
+ /**
47
+ * 枚举值
48
+ */
49
+ enum?: { value: string }[];
50
+ /**
51
+ * 数组类型
52
+ */
53
+ items?: { type: IMetaType; refId?: string };
54
+ };
55
+
56
+ export type IMetaFileds = {
57
+ /**
58
+ * 规则名称
59
+ */
60
+ id: string;
61
+
62
+ /**
63
+ * 类型
64
+ */
65
+ type: IMetaType;
66
+
67
+ /**
68
+ * 引用id
69
+ */
70
+ refId?: string;
71
+
72
+ /**
73
+ * 规则值
74
+ */
75
+ value: any;
76
+ };
77
+
78
+ export interface IAPI {
79
+ // 获取元数据列表
80
+ GetMetadataList(keyWords?: string[]): Promise<{ id: string; name: string; schema: string }[]>;
81
+ // 通过元数据Id获取元数据详情
82
+ GetMetadataDetailById(metadataId: string): Promise<any>;
83
+ // 新增元数据
84
+ SaveMetadata(data: any, metadataTag: string): Promise<any>;
85
+ // 获取元数据的值
86
+ GetMetadataObjList(data: any): Promise<any[]>;
87
+ }
package/es/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export { default as MetadataEditV2 } from './comps/MetadataEditV2';
3
3
  export { default as MetadataForm } from './comps/MetadataForm';
4
4
  export { default as JsonView } from './comps/JsonView';
5
5
  export { default as JsonEdit } from './comps/JsonEdit';
6
+ export { default as Editable } from './comps/Editable';
6
7
  export * from './framework/metadata/index';
7
8
  export { default as http, addInterceptor } from './framework/http/index';
8
9
  export { registerMetadataAPI } from './framework/metadata/MetadataService';
package/es/index.js CHANGED
@@ -1,15 +1,14 @@
1
1
  /*
2
2
  * @Author:wangxian
3
3
  * @Date: 2021-09-18 14:15:04
4
- * @LastEditTime: 2022-03-03 17:12:29
5
- * @LastEditors: Please set LastEditors
6
- * @FilePath: \ronds.metadata\src\index.ts
4
+ * @LastEditTime: 2022-03-04 16:53:30
7
5
  */
8
6
  export { default as MetadataEdit } from './comps/MetadataEdit';
9
7
  export { default as MetadataEditV2 } from './comps/MetadataEditV2';
10
8
  export { default as MetadataForm } from './comps/MetadataForm';
11
9
  export { default as JsonView } from './comps/JsonView';
12
10
  export { default as JsonEdit } from './comps/JsonEdit';
11
+ export { default as Editable } from './comps/Editable';
13
12
  export * from './framework/metadata/index';
14
13
  export { default as http, addInterceptor } from './framework/http/index';
15
14
  export { registerMetadataAPI } from './framework/metadata/MetadataService';
package/package.json CHANGED
@@ -1,74 +1,76 @@
1
1
  {
2
- "public": true,
3
- "name": "ronds-metadata",
4
- "version": "1.0.39",
5
- "scripts": {
6
- "start": "dumi dev",
7
- "docs:build": "dumi build",
8
- "docs:deploy": "gh-pages -d docs-dist",
9
- "build": "father-build",
10
- "deploy": "npm run docs:build && npm run docs:deploy",
11
- "release": "npm run build && npm publish",
12
- "prettier": "prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\"",
13
- "test": "umi-test",
14
- "test:coverage": "umi-test --coverage"
15
- },
16
- "main": "es",
17
- "module": "es",
18
- "types": "es/index.d.ts",
19
- "gitHooks": {
20
- "pre-commit": "lint-staged"
21
- },
22
- "lint-staged": {
23
- "*.{js,jsx,less,md,json}": [
24
- "prettier --write"
25
- ],
26
- "*.ts?(x)": [
27
- "prettier --parser=typescript --write"
28
- ]
29
- },
30
- "files": [
31
- "/es"
2
+ "public": true,
3
+ "name": "ronds-metadata",
4
+ "version": "1.0.42",
5
+ "scripts": {
6
+ "start": "dumi dev",
7
+ "docs:build": "dumi build",
8
+ "docs:deploy": "gh-pages -d docs-dist",
9
+ "build": "father-build",
10
+ "deploy": "npm run docs:build && npm run docs:deploy",
11
+ "release": "npm run build && npm publish",
12
+ "prettier": "prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\"",
13
+ "test": "umi-test",
14
+ "test:coverage": "umi-test --coverage"
15
+ },
16
+ "main": "es",
17
+ "module": "es",
18
+ "types": "es/index.d.ts",
19
+ "gitHooks": {
20
+ "pre-commit": "lint-staged"
21
+ },
22
+ "lint-staged": {
23
+ "*.{js,jsx,less,md,json}": [
24
+ "prettier --write"
32
25
  ],
33
- "dependencies": {
34
- "@babel/helper-create-regexp-features-plugin": "^7.12.13",
35
- "@babel/runtime": "^7.11.2",
36
- "@popperjs/core": "^2.4.4",
37
- "axios": "^0.21.4",
38
- "babel-plugin-import": "^1.13.3",
39
- "babel-plugin-transform-remove-console": "^6.9.4",
40
- "bl": "^5.0.0",
41
- "codemirror": "^5.63.0",
42
- "lodash": "^4.17.21",
43
- "qs": "^6.10.1",
44
- "react": "^16.12.0",
45
- "react-color": "^2.19.3"
46
- },
47
- "peerDependencies": {
48
- "antd": ">=4.1.5",
49
- "react": ">=16.12.0",
50
- "react-dom": ">=16.12.0",
51
- "react-router": ">=5.0.0",
52
- "styled-components": ">=4.1.1"
53
- },
54
- "devDependencies": {
55
- "@types/react": "^16.9.48",
56
- "@types/react-dom": "^16.9.8",
57
- "@types/react-router": "^5.1.8",
58
- "@types/react-window": "^1.8.2",
59
- "@types/styled-components": "^5.1.2",
60
- "@umijs/test": "^3.0.5",
61
- "antd": "^4.16.6",
62
- "babel-loader": "^8.1.0",
63
- "css-loader": "^4.2.2",
64
- "dumi": "^1.0.16",
65
- "father-build": "^1.17.2",
66
- "gh-pages": "^3.0.0",
67
- "less-loader": "^7.0.0",
68
- "lint-staged": "^10.0.7",
69
- "prettier": "^2.2.1",
70
- "style-loader": "^1.2.1",
71
- "webpack-cli": "^3.3.12",
72
- "yorkie": "^2.0.0"
73
- }
74
- }
26
+ "*.ts?(x)": [
27
+ "prettier --parser=typescript --write"
28
+ ]
29
+ },
30
+ "files": [
31
+ "/es"
32
+ ],
33
+ "dependencies": {
34
+ "@babel/helper-create-regexp-features-plugin": "^7.12.13",
35
+ "@babel/runtime": "^7.11.2",
36
+ "@popperjs/core": "^2.4.4",
37
+ "axios": "^0.21.4",
38
+ "babel-plugin-import": "^1.13.3",
39
+ "babel-plugin-transform-remove-console": "^6.9.4",
40
+ "bl": "^5.0.0",
41
+ "codemirror": "^5.63.0",
42
+ "lodash": "^4.17.21",
43
+ "qs": "^6.10.1",
44
+ "react": "^16.12.0",
45
+ "react-color": "^2.19.3",
46
+ "rxjs": "^7.5.4"
47
+ },
48
+ "peerDependencies": {
49
+ "antd": ">=4.1.5",
50
+ "react": ">=16.12.0",
51
+ "react-dom": ">=16.12.0",
52
+ "react-router": ">=5.0.0",
53
+ "styled-components": ">=4.1.1"
54
+ },
55
+ "devDependencies": {
56
+ "@types/react": "^16.9.48",
57
+ "@types/react-dom": "^16.9.8",
58
+ "@types/react-router": "^5.1.8",
59
+ "@types/react-window": "^1.8.2",
60
+ "@types/styled-components": "^5.1.2",
61
+ "@umijs/test": "^3.0.5",
62
+ "antd": "^4.16.6",
63
+ "babel-loader": "^8.1.0",
64
+ "css-loader": "^4.2.2",
65
+ "dumi": "^1.0.16",
66
+ "father-build": "^1.17.2",
67
+ "gh-pages": "^3.0.0",
68
+ "less-loader": "^7.0.0",
69
+ "lint-staged": "^10.0.7",
70
+ "prettier": "^2.2.1",
71
+ "style-loader": "^1.2.1",
72
+ "webpack-cli": "^3.3.12",
73
+ "yorkie": "^2.0.0"
74
+ }
75
+ }
76
+