@hzab/list-render 1.10.12-beta2 → 1.10.12-beta3

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,5 +1,6 @@
1
1
  # @hzab/list-render@1.10.12
2
2
 
3
+ fix: 首次列表加载携带queryFormInitialValues的参数
3
4
  feat: schema title 支持传入 ReactNode,支持通过 schemaScope 传入
4
5
  fix: table 响应数据 去除 inTable == false 的字段
5
6
  fix: table 响应表单 FormilyField 环境变量 scenario: "tableReactionsForm"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hzab/list-render",
3
- "version": "1.10.12-beta2",
3
+ "version": "1.10.12-beta3",
4
4
  "description": "",
5
5
  "main": "src",
6
6
  "scripts": {
@@ -1,174 +1,174 @@
1
- import { observer } from "@formily/react";
2
- import { autorun, observable } from "@formily/reactive";
3
-
4
- export function handleTableProps(field, { scope, value, record }) {
5
- if (!field) {
6
- return field;
7
- }
8
- const opt = {
9
- scope: scope,
10
- $self: field,
11
- $values: value,
12
- $deps: record,
13
- };
14
- // inTable
15
- // x-table-props
16
- if (typeof field.inTable === "string") {
17
- field.inTable = getStateFunc(field.inTable, opt)(opt);
18
- }
19
- const tableProps = field["x-table-props"];
20
- if (tableProps) {
21
- if (typeof tableProps === "string") {
22
- field["x-table-props"] = getStateFunc(field.inTable, opt)(opt);
23
- } else if (tableProps && typeof tableProps === "object") {
24
- Object.keys(tableProps).forEach((key) => {
25
- if (typeof field["x-table-props"][key] === "string") {
26
- field["x-table-props"][key] = getStateFunc(field["x-table-props"][key], opt)(opt);
27
- }
28
- });
29
- }
30
- }
31
- return field;
32
- }
33
-
34
- /**
35
- * 解决 render 中无法响应数据的情况
36
- * @param {Function} render
37
- * @returns
38
- */
39
- export function getColRender(render) {
40
- return function (...args) {
41
- const Observer = observer(function () {
42
- return render(...args);
43
- });
44
- return <Observer />;
45
- };
46
- }
47
-
48
- /**
49
- * 根据 formily 函数字符串 {{xxx}},获取变量或可执行函数
50
- * @param {*} funcStr
51
- * @param {*} opt
52
- * @returns
53
- */
54
- export const getScopeVal = function (funcStr = "", opt = {}) {
55
- if (typeof funcStr !== "string" || !funcStr.startsWith("{{")) {
56
- return funcStr;
57
- }
58
- const stateStr = funcStr.replace(/^\{\{/, "").replace(/\}\}$/, "");
59
- const res = opt?.scope?.[stateStr];
60
- // 存在对应变量直接返回
61
- if (res) {
62
- return res;
63
- }
64
- return getFunc(stateStr, opt);
65
- };
66
-
67
- /**
68
- * 根据 formily 函数字符串 {{xxx}},获取可执行函数
69
- * @param {string} funcStr
70
- * @param {Object} opt
71
- * @returns
72
- */
73
- export function getStateFunc(funcStr = "", opt) {
74
- if (typeof funcStr !== "string" || !funcStr.startsWith("{{")) {
75
- return funcStr;
76
- }
77
- const stateStr = funcStr.replace(/^\{\{/, "").replace(/\}\}$/, "");
78
- return getFunc(stateStr, opt);
79
- }
80
-
81
- /**
82
- * 根据函数字符串,获取可执行函数
83
- * @param {string} funcStr
84
- * @param {Object} opt
85
- * @returns
86
- */
87
- export function getFunc(
88
- funcStr = "",
89
- // opt = {"scope", "$self", "$values"},
90
- opt = {},
91
- ) {
92
- const _opt = {
93
- // opt = ["scope", "$self", "$deps", "$values", "$observable", "$memo", "$effect"],
94
- $observable: observable,
95
- $memo: autorun.memo,
96
- $effect: autorun.effect,
97
- scope: {},
98
- ...opt,
99
- };
100
- const fn = new Function(
101
- "opt",
102
- `const { ${Object.keys(_opt).join(", ")} } = opt || {}; const {${Object.keys(_opt.scope || {}).join(
103
- ", ",
104
- )}} = scope || {}; return ${funcStr}; `,
105
- );
106
-
107
- return function (opt) {
108
- return fn.call(this, {
109
- // opt = ["scope", "$self", "$deps", "$values", "$observable", "$memo", "$effect"],
110
- $observable: observable,
111
- $memo: autorun.memo,
112
- $effect: autorun.effect,
113
- ...opt,
114
- });
115
- };
116
- }
117
-
118
- /**
119
- * 根据 formily 函数字符串 {{xxx}},获取可执行的异步函数
120
- * @param {string} funcStr
121
- * @param {Object} opt
122
- * @returns
123
- */
124
- export function getStateSyncFunc(funcStr = "", opt) {
125
- if (typeof funcStr !== "string" || !funcStr.startsWith("{{")) {
126
- return funcStr;
127
- }
128
- const stateStr = funcStr.replace(/^\{\{/, "").replace(/\}\}$/, "");
129
- return getFuncSync(stateStr, opt);
130
- }
131
-
132
- /**
133
- * 根据函数字符串,获取可执行的异步函数
134
- * @param {string} funcStr
135
- * @param {Object} opt
136
- * @returns
137
- */
138
- export function getFuncSync(
139
- funcStr = "",
140
- // opt = {"scope", "$self", "$values"},
141
- opt = {},
142
- ) {
143
- const _opt = {
144
- // opt = ["scope", "$self", "$deps", "$values", "$observable", "$memo", "$effect"],
145
- $observable: observable,
146
- $memo: autorun.memo,
147
- $effect: autorun.effect,
148
- scope: {},
149
- ...opt,
150
- };
151
-
152
- // 把 effectFn 字符串转为可执行函数,并传入所需的参数,支持异步
153
- const getAsyncFunction = new Function(`return Object.getPrototypeOf(async function(){}).constructor;`);
154
- const AsyncFunction = getAsyncFunction();
155
- // 只能这样拿到 AsyncFunction
156
- // 直接写 Object.getPrototypeOf(async function(){}).constructor
157
- // 会被 babel 转成 Function
158
- const asyncFunc = new AsyncFunction(
159
- "opt",
160
- `try {const {${Object.keys(_opt).join(", ")}} = opt || {}; const {${Object.keys(_opt.scope || {}).join(
161
- ", ",
162
- )}} = scope || {}; return ${funcStr}; } catch(err) {console.error("Error Formily Reactive Function: ", err);}`,
163
- );
164
-
165
- return function (opt) {
166
- return asyncFunc.call(this, {
167
- // opt = ["scope", "$self", "$deps", "$values", "$observable", "$memo", "$effect"],
168
- $observable: observable,
169
- $memo: autorun.memo,
170
- $effect: autorun.effect,
171
- ...opt,
172
- });
173
- };
174
- }
1
+ import { observer } from "@formily/react";
2
+ import { autorun, observable } from "@formily/reactive";
3
+
4
+ export function handleTableProps(field, { scope, value, record }) {
5
+ if (!field) {
6
+ return field;
7
+ }
8
+ const opt = {
9
+ scope: scope,
10
+ $self: field,
11
+ $values: value,
12
+ $deps: record,
13
+ };
14
+ // inTable
15
+ // x-table-props
16
+ if (typeof field.inTable === "string") {
17
+ field.inTable = getStateFunc(field.inTable, opt)(opt);
18
+ }
19
+ const tableProps = field["x-table-props"];
20
+ if (tableProps) {
21
+ if (typeof tableProps === "string") {
22
+ field["x-table-props"] = getStateFunc(field.inTable, opt)(opt);
23
+ } else if (tableProps && typeof tableProps === "object") {
24
+ Object.keys(tableProps).forEach((key) => {
25
+ if (typeof field["x-table-props"][key] === "string") {
26
+ field["x-table-props"][key] = getStateFunc(field["x-table-props"][key], opt)(opt);
27
+ }
28
+ });
29
+ }
30
+ }
31
+ return field;
32
+ }
33
+
34
+ /**
35
+ * 解决 render 中无法响应数据的情况
36
+ * @param {Function} render
37
+ * @returns
38
+ */
39
+ export function getColRender(render) {
40
+ return function (...args) {
41
+ const Observer = observer(function () {
42
+ return render(...args);
43
+ });
44
+ return <Observer />;
45
+ };
46
+ }
47
+
48
+ /**
49
+ * 根据 formily 函数字符串 {{xxx}},获取变量或可执行函数
50
+ * @param {*} funcStr
51
+ * @param {*} opt
52
+ * @returns
53
+ */
54
+ export const getScopeVal = function (funcStr = "", opt = {}) {
55
+ if (typeof funcStr !== "string" || !funcStr.startsWith("{{")) {
56
+ return funcStr;
57
+ }
58
+ const stateStr = funcStr.replace(/^\{\{/, "").replace(/\}\}$/, "");
59
+ const res = opt?.scope?.[stateStr];
60
+ // 存在对应变量直接返回
61
+ if (res) {
62
+ return res;
63
+ }
64
+ return getFunc(stateStr, opt);
65
+ };
66
+
67
+ /**
68
+ * 根据 formily 函数字符串 {{xxx}},获取可执行函数
69
+ * @param {string} funcStr
70
+ * @param {Object} opt
71
+ * @returns
72
+ */
73
+ export function getStateFunc(funcStr = "", opt) {
74
+ if (typeof funcStr !== "string" || !funcStr.startsWith("{{")) {
75
+ return funcStr;
76
+ }
77
+ const stateStr = funcStr.replace(/^\{\{/, "").replace(/\}\}$/, "");
78
+ return getFunc(stateStr, opt);
79
+ }
80
+
81
+ /**
82
+ * 根据函数字符串,获取可执行函数
83
+ * @param {string} funcStr
84
+ * @param {Object} opt
85
+ * @returns
86
+ */
87
+ export function getFunc(
88
+ funcStr = "",
89
+ // opt = {"scope", "$self", "$values"},
90
+ opt = {},
91
+ ) {
92
+ const _opt = {
93
+ // opt = ["scope", "$self", "$deps", "$values", "$observable", "$memo", "$effect"],
94
+ $observable: observable,
95
+ $memo: autorun.memo,
96
+ $effect: autorun.effect,
97
+ scope: {},
98
+ ...opt,
99
+ };
100
+ const fn = new Function(
101
+ "opt",
102
+ `const { ${Object.keys(_opt).join(", ")} } = opt || {}; const {${Object.keys(_opt.scope || {}).join(
103
+ ", ",
104
+ )}} = scope || {}; return ${funcStr}; `,
105
+ );
106
+
107
+ return function (opt) {
108
+ return fn.call(this, {
109
+ // opt = ["scope", "$self", "$deps", "$values", "$observable", "$memo", "$effect"],
110
+ $observable: observable,
111
+ $memo: autorun.memo,
112
+ $effect: autorun.effect,
113
+ ...opt,
114
+ });
115
+ };
116
+ }
117
+
118
+ /**
119
+ * 根据 formily 函数字符串 {{xxx}},获取可执行的异步函数
120
+ * @param {string} funcStr
121
+ * @param {Object} opt
122
+ * @returns
123
+ */
124
+ export function getStateSyncFunc(funcStr = "", opt) {
125
+ if (typeof funcStr !== "string" || !funcStr.startsWith("{{")) {
126
+ return funcStr;
127
+ }
128
+ const stateStr = funcStr.replace(/^\{\{/, "").replace(/\}\}$/, "");
129
+ return getFuncSync(stateStr, opt);
130
+ }
131
+
132
+ /**
133
+ * 根据函数字符串,获取可执行的异步函数
134
+ * @param {string} funcStr
135
+ * @param {Object} opt
136
+ * @returns
137
+ */
138
+ export function getFuncSync(
139
+ funcStr = "",
140
+ // opt = {"scope", "$self", "$values"},
141
+ opt = {},
142
+ ) {
143
+ const _opt = {
144
+ // opt = ["scope", "$self", "$deps", "$values", "$observable", "$memo", "$effect"],
145
+ $observable: observable,
146
+ $memo: autorun.memo,
147
+ $effect: autorun.effect,
148
+ scope: {},
149
+ ...opt,
150
+ };
151
+
152
+ // 把 effectFn 字符串转为可执行函数,并传入所需的参数,支持异步
153
+ const getAsyncFunction = new Function(`return Object.getPrototypeOf(async function(){}).constructor;`);
154
+ const AsyncFunction = getAsyncFunction();
155
+ // 只能这样拿到 AsyncFunction
156
+ // 直接写 Object.getPrototypeOf(async function(){}).constructor
157
+ // 会被 babel 转成 Function
158
+ const asyncFunc = new AsyncFunction(
159
+ "opt",
160
+ `try {const {${Object.keys(_opt).join(", ")}} = opt || {}; const {${Object.keys(_opt.scope || {}).join(
161
+ ", ",
162
+ )}} = scope || {}; return ${funcStr}; } catch(err) {console.error("Error Formily Reactive Function: ", err);}`,
163
+ );
164
+
165
+ return function (opt) {
166
+ return asyncFunc.call(this, {
167
+ // opt = ["scope", "$self", "$deps", "$values", "$observable", "$memo", "$effect"],
168
+ $observable: observable,
169
+ $memo: autorun.memo,
170
+ $effect: autorun.effect,
171
+ ...opt,
172
+ });
173
+ };
174
+ }
package/src/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import ListRender from "./list-render.jsx";
2
-
3
- export * from "@hzab/data-model";
4
-
5
- export default ListRender;
1
+ import ListRender from "./list-render.jsx";
2
+
3
+ export * from "@hzab/data-model";
4
+
5
+ export default ListRender;
@@ -130,7 +130,7 @@ const ListRender = forwardRef(function (props, parentRef) {
130
130
  }
131
131
  });
132
132
 
133
- !props.closeAutoRequest && getList({ ...(modelQueryRef.current || {}), ...getUrlQuery });
133
+ !props.closeAutoRequest && getList({ ...queryFormInitialValues, ...(modelQueryRef.current || {}), ...getUrlQuery });
134
134
  }, []);
135
135
 
136
136
  useEffect(() => {