ronds-metadata 1.0.26 → 1.0.27

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.
@@ -69,7 +69,7 @@ var MetaFieldsEdit = function MetaFieldsEdit(props) {
69
69
 
70
70
  for (var i = 0; i < _fields.length; i++) {
71
71
  if (_fields[i].type === 'ref') {
72
- _fields[i].value = refValues[i];
72
+ _fields[i].value = refValues[i] || _fields[i].value;
73
73
  }
74
74
  }
75
75
 
@@ -16,6 +16,7 @@ import React from 'react';
16
16
  import { MinusCircleOutlined, PlusOutlined, ReloadOutlined } from '@ant-design/icons';
17
17
  import { ARRAY_TYPES_OPTIONS, BASIC_TYPES_OPTIONS, NUMBER_FORMAT_OPTIONS } from '../constant';
18
18
  import { useMetaType } from '../hooks';
19
+ import { guid } from '@/utils';
19
20
 
20
21
  var MetaPropsEdit = function MetaPropsEdit(props) {
21
22
  var form = props.form,
@@ -52,7 +53,7 @@ var MetaPropsEdit = function MetaPropsEdit(props) {
52
53
  remove = _ref.remove;
53
54
  return /*#__PURE__*/React.createElement(React.Fragment, null, fields.map(function (field, index) {
54
55
  return /*#__PURE__*/React.createElement("div", {
55
- key: field.key
56
+ key: guid()
56
57
  }, /*#__PURE__*/React.createElement("div", {
57
58
  style: {
58
59
  display: 'flex',
@@ -42,6 +42,12 @@ var MetadataEdit = function MetadataEdit(props) {
42
42
  metaSchema = _React$useState4[0],
43
43
  setMetaSchema = _React$useState4[1];
44
44
 
45
+ var metaSchemaRef = React.useRef({
46
+ id: '',
47
+ type: 'object'
48
+ });
49
+ var firstLoadRef = React.useRef(true);
50
+
45
51
  var _React$useState5 = React.useState(false),
46
52
  _React$useState6 = _slicedToArray(_React$useState5, 2),
47
53
  isFields = _React$useState6[0],
@@ -66,15 +72,17 @@ var MetadataEdit = function MetadataEdit(props) {
66
72
  });
67
73
  }, [form]);
68
74
  React.useEffect(function () {
69
- if (initialValues) {
75
+ if (initialValues && firstLoadRef.current) {
70
76
  form.setFieldsValue(_objectSpread({}, initialValues));
71
77
  setMetaSchema(_objectSpread({}, initialValues));
78
+ metaSchemaRef.current = initialValues;
72
79
  processFileds(initialValues);
80
+ firstLoadRef.current = false;
73
81
  }
74
82
  }, [form, initialValues]);
75
83
 
76
84
  var onMyFinish = function onMyFinish(values) {
77
- var _metaSchema = metaSchema;
85
+ var _metaSchema = metaSchemaRef.current;
78
86
  _metaSchema.id = values.id;
79
87
  _metaSchema.type = values.type;
80
88
 
@@ -93,6 +101,7 @@ var MetadataEdit = function MetadataEdit(props) {
93
101
  }
94
102
 
95
103
  setMetaSchema(_objectSpread({}, _metaSchema));
104
+ metaSchemaRef.current = _metaSchema;
96
105
  onFinish && onFinish(JSON.stringify(_metaSchema));
97
106
  };
98
107
 
@@ -112,8 +121,7 @@ var MetadataEdit = function MetadataEdit(props) {
112
121
  return;
113
122
  }
114
123
 
115
- var _properties = form.getFieldValue('properties');
116
-
124
+ var _properties = metaSchemaRef.current.properties;
117
125
  var _curFields = _properties[index];
118
126
 
119
127
  if (_curFields && _curFields.id) {
@@ -33,11 +33,6 @@ function Index(props) {
33
33
  color = _React$useState2[0],
34
34
  setColor = _React$useState2[1];
35
35
 
36
- var _React$useState3 = React.useState(null),
37
- _React$useState4 = _slicedToArray(_React$useState3, 2),
38
- date = _React$useState4[0],
39
- setDate = _React$useState4[1];
40
-
41
36
  React.useEffect(function () {
42
37
  if ((extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.type) === 'colorPicker') {
43
38
  setColor(formContext.form.getFieldValue(id));
package/es/utils.d.ts CHANGED
@@ -12,3 +12,4 @@ export declare function useDebounce(fn: Function, delay: number, dep?: Dependenc
12
12
  */
13
13
  export declare function useThrottle(fn: Function, delay: number, dep?: DependencyList): (...args: any[]) => void;
14
14
  export declare function deepClone<T = any>(target: T): T;
15
+ export declare function guid(): string;
package/es/utils.js CHANGED
@@ -1,3 +1,11 @@
1
+ /*
2
+ * @Author: your name
3
+ * @Date: 2021-09-18 14:15:04
4
+ * @LastEditTime: 2021-12-22 14:10:34
5
+ * @LastEditors: your name
6
+ * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
7
+ * @FilePath: \ronds.metadata\src\utils.ts
8
+ */
1
9
  import { useCallback, useEffect, useRef } from 'react';
2
10
  /** 防抖 */
3
11
 
@@ -78,4 +86,23 @@ export function useThrottle(fn, delay) {
78
86
  }
79
87
  export function deepClone(target) {
80
88
  return JSON.parse(JSON.stringify(target));
89
+ }
90
+ export function guid() {
91
+ var id = '',
92
+ i,
93
+ random,
94
+ chars = 'abcdef';
95
+ id += chars[Math.floor(Math.random() * Math.floor(chars.length))];
96
+
97
+ for (i = 1; i < 32; i++) {
98
+ random = Math.random() * 16 | 0;
99
+
100
+ if (i == 8 || i == 12 || i == 16 || i == 20) {
101
+ id += '-';
102
+ }
103
+
104
+ id += (i == 12 ? 4 : i == 16 ? random & 3 | 8 : random).toString(16);
105
+ }
106
+
107
+ return id;
81
108
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "public": true,
3
3
  "name": "ronds-metadata",
4
- "version": "1.0.26",
4
+ "version": "1.0.27",
5
5
  "scripts": {
6
6
  "start": "dumi dev",
7
7
  "docs:build": "dumi build",