ronds-metadata 1.0.51 → 1.0.54

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.
@@ -3,13 +3,12 @@ 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
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
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
- import { BehaviorSubject } from 'rxjs';
13
12
  import { pick, isArray } from 'lodash';
14
13
  import EditableCell from './comps/EditableCell';
15
14
  import EditableRow from './comps/EditableRow';
@@ -17,6 +16,8 @@ import { EditableContext } from './interface';
17
16
  import EditableAction from './comps/EditableAction';
18
17
  import { isFreeEditRow, removeCurKeyFromEditRow } from './utils';
19
18
  import EditableHeardCell from './comps/EditableHeardCell';
19
+ import useMemoSubject from '../../framework/rxjs-hooks/useMemoSubject';
20
+ import useObservable from '../../framework/rxjs-hooks/useObservable';
20
21
 
21
22
  var Editable = function Editable(props) {
22
23
  var _props$type = props.type,
@@ -78,38 +79,7 @@ var Editable = function Editable(props) {
78
79
  var lastDataSourceRef = React.useRef();
79
80
  var firstLoadRef = React.useRef(true); // 定义处理编辑表格的数据流
80
81
 
81
- var editableStream = React.useMemo(function () {
82
- return new BehaviorSubject(undefined);
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
-
82
+ var editableStream = useMemoSubject();
113
83
  var processStreamFactory = React.useCallback(function (data) {
114
84
  switch (data === null || data === void 0 ? void 0 : data.type) {
115
85
  case 'onValuesChange':
@@ -216,7 +186,38 @@ var Editable = function Editable(props) {
216
186
 
217
187
  break;
218
188
  }
219
- }, [type]); // 返回stream的实例
189
+ }, [type]); // 集中处理数据流
190
+
191
+ useObservable(processStreamFactory, [editableStream]);
192
+
193
+ var processAddColumnsData = function processAddColumnsData(data) {
194
+ var _columns = addColumnsRef.current.length > 0 ? addColumnsRef.current : columns; // 判断key是否重复
195
+
196
+
197
+ if (_columns.findIndex(function (v) {
198
+ return v.key === data.key;
199
+ }) > -1) {
200
+ _message.warning('表格的key不可以重复');
201
+
202
+ return;
203
+ }
204
+
205
+ var idx = _columns.findIndex(function (v) {
206
+ return v.dataIndex === data.dataIndex;
207
+ });
208
+
209
+ var obj = {
210
+ title: data.title,
211
+ key: data.key,
212
+ dataIndex: data.key
213
+ };
214
+
215
+ _columns.splice(idx + 1, 0, _objectSpread(_objectSpread({}, _columns[0]), obj));
216
+
217
+ setAddColumns(_toConsumableArray(_columns));
218
+ addColumnsRef.current = _columns; // editableStream.next({ type: 'editHeardCellKey', payload: undefined });
219
+ }; // 返回stream的实例
220
+
220
221
 
221
222
  React.useEffect(function () {
222
223
  if (firstLoadRef && editableStream) {
@@ -230,16 +231,7 @@ var Editable = function Editable(props) {
230
231
  setRecords(_toConsumableArray(dataSource));
231
232
  recordsRef.current = dataSource;
232
233
  }
233
- }, [dataSource]); // 集中处理数据流
234
-
235
- React.useEffect(function () {
236
- var subscription = editableStream.subscribe(function (p) {
237
- processStreamFactory(p);
238
- });
239
- return function () {
240
- return subscription.unsubscribe();
241
- };
242
- }, [editableStream, processStreamFactory]);
234
+ }, [dataSource]);
243
235
  var getEditColumn = React.useCallback(function (column) {
244
236
  var _column = _objectSpread(_objectSpread({}, column), {}, {
245
237
  children: isArray(column === null || column === void 0 ? void 0 : column.children) ? column.children.map(getEditColumn) : undefined
@@ -124,9 +124,21 @@ function Index(props) {
124
124
  refFieldsRef.current = _fields;
125
125
  setRefFields(_objectSpread({}, _fields));
126
126
  setSchema(_toConsumableArray(mySchema));
127
+ return function () {
128
+ provider = null;
129
+ };
127
130
  }
131
+
132
+ return function () {
133
+ provider = null;
134
+ };
128
135
  });
136
+ return function () {
137
+ server = null;
138
+ };
129
139
  }
140
+
141
+ return function () {};
130
142
  }, [refId]);
131
143
  React.useEffect(function () {
132
144
  if (refId) {
@@ -4,6 +4,13 @@ import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  import "antd/es/select/style";
5
5
  import _Select from "antd/es/select";
6
6
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
7
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
8
+
9
+ /*
10
+ * @Author:wangxian
11
+ * @Date: 2021-09-18 14:15:04
12
+ * @LastEditTime: 2022-04-01 17:07:41
13
+ */
7
14
  import React from 'react';
8
15
  import { MetadataFormContext, MetadataRefContext } from '../interface';
9
16
  import { useGetExtraInfo } from '../hooks';
@@ -22,6 +29,14 @@ function Index(props) {
22
29
  var formContext = React.useContext(MetadataFormContext) || {};
23
30
  var formRefContext = React.useContext(MetadataRefContext);
24
31
  var extraInfo = useGetExtraInfo(formRefContext ? formRefContext.fields : formContext.fields, id, formContext.form);
32
+
33
+ var onSelect = function onSelect(value) {
34
+ formContext.stream$ && formContext.stream$.next({
35
+ type: 'onSelectChange',
36
+ payload: _defineProperty({}, id, value)
37
+ });
38
+ };
39
+
25
40
  var options = React.useMemo(function () {
26
41
  var _options = [];
27
42
 
@@ -69,6 +84,7 @@ function Index(props) {
69
84
  tooltip: extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.tooltip
70
85
  }), /*#__PURE__*/React.createElement(_Select, {
71
86
  mode: extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.mode,
87
+ onSelect: onSelect,
72
88
  disabled: (_extraInfo$disabled = extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.disabled) !== null && _extraInfo$disabled !== void 0 ? _extraInfo$disabled : disabled,
73
89
  placeholder: extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.placeholder,
74
90
  options: options,
@@ -86,6 +102,7 @@ function Index(props) {
86
102
  tooltip: extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.tooltip
87
103
  }, /*#__PURE__*/React.createElement(_Select, {
88
104
  mode: extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.mode,
105
+ onSelect: onSelect,
89
106
  disabled: (_extraInfo$disabled2 = extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.disabled) !== null && _extraInfo$disabled2 !== void 0 ? _extraInfo$disabled2 : disabled,
90
107
  placeholder: extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.placeholder,
91
108
  options: options,
@@ -104,6 +121,7 @@ function Index(props) {
104
121
  tooltip: extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.tooltip
105
122
  }), /*#__PURE__*/React.createElement(_Select, {
106
123
  mode: extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.mode,
124
+ onSelect: onSelect,
107
125
  disabled: (_extraInfo$disabled3 = extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.disabled) !== null && _extraInfo$disabled3 !== void 0 ? _extraInfo$disabled3 : disabled,
108
126
  placeholder: extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.placeholder,
109
127
  options: options,
@@ -1,5 +1,11 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+
4
+ /*
5
+ * @Author: wangxian
6
+ * @Date: 2021-09-18 14:15:04
7
+ * @LastEditTime: 2022-04-01 16:48:49
8
+ */
3
9
  import React from 'react';
4
10
  import { deepClone } from '../../../utils';
5
11
  import "./index.css";
@@ -24,6 +30,8 @@ export function withAddOnAfter(WrappedComponent) {
24
30
  var arr = refId.split(':');
25
31
  setHelp(arr[arr.length - 1]);
26
32
  }
33
+
34
+ return function () {};
27
35
  }, [refId]);
28
36
 
29
37
  var _name = React.useMemo(function () {
@@ -37,6 +45,7 @@ export function withAddOnAfter(WrappedComponent) {
37
45
  }, [id, name]);
38
46
 
39
47
  return /*#__PURE__*/React.createElement("div", {
48
+ key: "".concat(_name.toString(), "_div"),
40
49
  className: "with-add-on-after"
41
50
  }, /*#__PURE__*/React.createElement(WrappedComponent, _extends({
42
51
  key: _name.toString(),
@@ -42,6 +42,10 @@ interface IMetadataFormProps {
42
42
  * 表单值的改变回调
43
43
  */
44
44
  onValuesChange?: (changedValues: any, allValues: any) => void;
45
+ /**
46
+ * select选择的回调
47
+ */
48
+ onSelectChange?: (changedValues: any) => void;
45
49
  }
46
50
  declare const MetadataForm: (props: IMetadataFormProps) => JSX.Element;
47
51
  export default MetadataForm;
@@ -8,6 +8,8 @@ import "./index.css";
8
8
  import { MetadataFormContext } from './interface';
9
9
  import { JsonMetadataProvider } from '../../framework/metadata';
10
10
  import { MetadataService } from '../../framework/metadata/MetadataService';
11
+ import useMemoSubject from '../../framework/rxjs-hooks/useMemoSubject';
12
+ import useObservable from '../../framework/rxjs-hooks/useObservable';
11
13
 
12
14
  var MetadataForm = function MetadataForm(props) {
13
15
  var _Form$useForm = _Form.useForm(),
@@ -26,7 +28,8 @@ var MetadataForm = function MetadataForm(props) {
26
28
  initEnumValue = props.initEnumValue,
27
29
  onFinish = props.onFinish,
28
30
  getFormInstance = props.getFormInstance,
29
- onValuesChange = props.onValuesChange;
31
+ onValuesChange = props.onValuesChange,
32
+ onSelectChange = props.onSelectChange;
30
33
 
31
34
  var _React$useState = React.useState([]),
32
35
  _React$useState2 = _slicedToArray(_React$useState, 2),
@@ -38,6 +41,12 @@ var MetadataForm = function MetadataForm(props) {
38
41
  fields = _React$useState4[0],
39
42
  setFields = _React$useState4[1];
40
43
 
44
+ var stream$ = useMemoSubject();
45
+ useObservable(function (p) {
46
+ if ((p === null || p === void 0 ? void 0 : p.type) === 'onSelectChange') {
47
+ onSelectChange && onSelectChange(p.payload);
48
+ }
49
+ }, [stream$]);
41
50
  var options = React.useMemo(function () {
42
51
  return {
43
52
  disabled: disabled,
@@ -78,12 +87,18 @@ var MetadataForm = function MetadataForm(props) {
78
87
  var formCls = new FormCls();
79
88
  var _fields = formCls.__type__.__fields__;
80
89
  setFields(_fields);
90
+ return function () {
91
+ provider = null;
92
+ };
81
93
  }
94
+
95
+ return function () {};
82
96
  }, [mySchma]);
83
97
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(MetadataFormContext.Provider, {
84
98
  value: {
85
99
  fields: fields,
86
100
  form: form,
101
+ stream$: stream$,
87
102
  initialValues: initialValues,
88
103
  isShowTypeInfo: isShowTypeInfo
89
104
  }
@@ -3,6 +3,7 @@ import { FormInstance } from 'antd/lib/form/hooks/useForm';
3
3
  export interface IMetadataFormContextProps {
4
4
  fields: any;
5
5
  form: FormInstance;
6
+ stream$: any;
6
7
  initialValues: any;
7
8
  isShowTypeInfo: boolean;
8
9
  }
@@ -1,3 +1,8 @@
1
+ /*
2
+ * @Author:wangxian
3
+ * @Date: 2021-09-18 14:15:04
4
+ * @LastEditTime: 2022-04-01 16:58:54
5
+ */
1
6
  import React from 'react';
2
7
  export var MetadataFormContext = /*#__PURE__*/React.createContext(null);
3
8
  export var MetadataRefContext = /*#__PURE__*/React.createContext(null);
@@ -9,6 +9,7 @@ import Switch from './DataCell/Switch';
9
9
  import Array from './DataCell/Array';
10
10
  import Ref from './DataCell/Ref';
11
11
  import { withAddOnAfter } from './HOC';
12
+ import { guid } from '@/utils';
12
13
  var DataCellMap = {
13
14
  text: withAddOnAfter(Input),
14
15
  number: withAddOnAfter(Number),
@@ -20,7 +21,9 @@ var DataCellMap = {
20
21
  export function getDataCell(item, options) {
21
22
  if (item.type && DataCellMap[item.type]) {
22
23
  var Comm = DataCellMap[item.type];
23
- return /*#__PURE__*/React.createElement(Comm, _extends({}, item, {
24
+ return /*#__PURE__*/React.createElement(Comm, _extends({
25
+ key: guid()
26
+ }, item, {
24
27
  disabled: options.disabled,
25
28
  isRefForm: options.isRefForm,
26
29
  isShowTypeInfo: options.isShowTypeInfo,
@@ -0,0 +1,3 @@
1
+ import { BehaviorSubject } from 'rxjs';
2
+ declare const useMemoSubject: <T>() => BehaviorSubject<T>;
3
+ export default useMemoSubject;
@@ -0,0 +1,16 @@
1
+ /*
2
+ * @Author: wangxian
3
+ * @Date: 2022-03-30 10:12:11
4
+ * @LastEditTime: 2022-04-01 08:15:21
5
+ */
6
+ import React from 'react';
7
+ import { BehaviorSubject } from 'rxjs';
8
+
9
+ var useMemoSubject = function useMemoSubject() {
10
+ var subject$ = React.useMemo(function () {
11
+ return new BehaviorSubject(undefined);
12
+ }, []);
13
+ return subject$;
14
+ };
15
+
16
+ export default useMemoSubject;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const useObservable: <T>(fn: Function, dep?: React.DependencyList) => void;
3
+ export default useObservable;
@@ -0,0 +1,20 @@
1
+ /*
2
+ * @Author: wangxian
3
+ * @Date: 2022-03-30 10:12:11
4
+ * @LastEditTime: 2022-03-30 10:52:51
5
+ */
6
+ import React from 'react';
7
+
8
+ var useObservable = function useObservable(fn) {
9
+ var dep = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
10
+ React.useEffect(function () {
11
+ var subscription = dep[0] && dep[0].subscribe(function (p) {
12
+ fn(p);
13
+ });
14
+ return function () {
15
+ return subscription && subscription.unsubscribe();
16
+ };
17
+ }, dep);
18
+ };
19
+
20
+ export default useObservable;
package/es/index.d.ts CHANGED
@@ -8,4 +8,6 @@ export { default as MdEditor } from './comps/MdEdit';
8
8
  export { default as Editable } from './comps/Editable';
9
9
  export * from './framework/metadata/index';
10
10
  export { default as http, addInterceptor } from './framework/http/index';
11
+ export { default as useMemoSubject } from './framework/rxjs-hooks/useMemoSubject';
12
+ export { default as useObservable } from './framework/rxjs-hooks/useObservable';
11
13
  export { registerMetadataAPI } from './framework/metadata/MetadataService';
package/es/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * @Author:wangxian
3
3
  * @Date: 2021-09-18 14:15:04
4
- * @LastEditTime: 2022-03-16 16:51:12
4
+ * @LastEditTime: 2022-03-30 10:55:03
5
5
  */
6
6
  export { default as MetadataEdit } from './comps/MetadataEdit';
7
7
  export { default as MetaPropsEdit } from './comps/MetadataEdit/components/MetaPropsEdit';
@@ -13,4 +13,6 @@ export { default as MdEditor } from './comps/MdEdit';
13
13
  export { default as Editable } from './comps/Editable';
14
14
  export * from './framework/metadata/index';
15
15
  export { default as http, addInterceptor } from './framework/http/index';
16
+ export { default as useMemoSubject } from './framework/rxjs-hooks/useMemoSubject';
17
+ export { default as useObservable } from './framework/rxjs-hooks/useObservable';
16
18
  export { registerMetadataAPI } from './framework/metadata/MetadataService';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "public": true,
3
3
  "name": "ronds-metadata",
4
- "version": "1.0.51",
4
+ "version": "1.0.54",
5
5
  "scripts": {
6
6
  "start": "dumi dev",
7
7
  "docs:build": "dumi build",