@hzab/form-render 1.3.1 → 1.3.3

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/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # @hzab/form-render@1.3.3
2
+
3
+ fix: 富文本异步数据问题修复
4
+
5
+ # @hzab/form-render@1.3.2
6
+
7
+ fix: schema props 为 schemaScope 字符串的情况
8
+
1
9
  # @hzab/form-render@1.3.1
2
10
 
3
11
  feat: 表单 onChange 事件(目前仅做触发,值计算后续优化)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hzab/form-render",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "description": "",
5
5
  "main": "src",
6
6
  "scripts": {
@@ -19,12 +19,18 @@ export const bindOnChange = (schema, opt) => {
19
19
  _schema = _schema.schema || _schema;
20
20
  Object.keys(_schema.properties || {})?.forEach((key) => {
21
21
  let item = _schema.properties[key];
22
+ if (!item) {
23
+ return;
24
+ }
22
25
  const componentName = item["x-component"];
23
26
  // 解决 name 丢失的问题
24
27
  item.name = key;
25
28
 
26
- if (item && !item["x-component-props"]) {
29
+ const comProps = item?.["x-component-props"];
30
+ if (!comProps) {
27
31
  item["x-component-props"] = {};
32
+ } else if (isScopeKey(comProps)) {
33
+ item["x-component-props"] = getValByScope(comProps, schemaScope) || {};
28
34
  }
29
35
 
30
36
  const bindParams = {
@@ -91,9 +97,9 @@ export const bindCallback = (opt) => {
91
97
  sourceArgs,
92
98
  });
93
99
  // 触发组件 onChange 事件
94
- if (typeof tempFn === "string" && tempFn.startsWith("{{") && tempFn.endsWith("}}")) {
100
+ if (isScopeKey(tempFn)) {
95
101
  // schemaScope 传入方式
96
- const fn = schemaScope && schemaScope[tempFn.replace(/^\{\{/, "").replace(/\}\}$/, "")];
102
+ const fn = schemaScope && schemaScope[getScopeKey(tempFn)];
97
103
  typeof fn === "function" && fn(...sourceArgs, res);
98
104
  } else if (typeof tempFn === "function") {
99
105
  // 直接传入函数的方式
@@ -130,3 +136,41 @@ export const handleChangeValue = (opt) => {
130
136
 
131
137
  return res;
132
138
  };
139
+
140
+ /**
141
+ * 是否是 scope key
142
+ * @param strKey
143
+ * @returns
144
+ */
145
+ export const isScopeKey = (strKey) => {
146
+ if (typeof strKey !== "string") {
147
+ return false;
148
+ }
149
+ const key = strKey.trim();
150
+ return key.startsWith("{{") && key.endsWith("}}");
151
+ };
152
+
153
+ /**
154
+ * 获取 scope key
155
+ * @param strKey
156
+ * @returns
157
+ */
158
+ export const getScopeKey = (strKey) => {
159
+ if (!isScopeKey(strKey)) {
160
+ return "";
161
+ }
162
+ const key = strKey.trim();
163
+ return key.replace(/^\{\{/, "").replace(/\}\}$/, "");
164
+ };
165
+
166
+ /**
167
+ * 通过字符串获取 schemaScope 中的数据
168
+ * @param strKey
169
+ * @param schemaScope
170
+ * @returns
171
+ */
172
+ export const getValByScope = (strKey, schemaScope = {}) => {
173
+ if (isScopeKey(strKey)) {
174
+ return schemaScope && schemaScope[getScopeKey(strKey)];
175
+ }
176
+ };
@@ -129,7 +129,6 @@ export const RichEditor = observer(function (props: PropsType, parentRef) {
129
129
 
130
130
  // 及时销毁 editor ,重要!
131
131
  useEffect(() => {
132
- setEditorContent(value)
133
132
  return () => {
134
133
  if (editor == null) return;
135
134
  editor.destroy();
@@ -137,6 +136,10 @@ export const RichEditor = observer(function (props: PropsType, parentRef) {
137
136
  };
138
137
  }, [editor]);
139
138
 
139
+ useEffect(() => {
140
+ setEditorContent(value)
141
+ }, [value]);
142
+
140
143
  return (
141
144
  <>
142
145
  <div className="wang-editor-warpper" style={{ zIndex }}>