@reformer/renderer-json 7.0.0 → 9.0.0
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/dist/index.js +95 -85
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useContext as
|
|
3
|
-
import { createRenderSchema as
|
|
4
|
-
import { i as
|
|
1
|
+
import { jsx as m, jsxs as E } from "react/jsx-runtime";
|
|
2
|
+
import { useContext as J, createContext as O, useMemo as y, useState as F, useEffect as j } from "react";
|
|
3
|
+
import { createRenderSchema as k, FormRenderer as A } from "@reformer/renderer-react";
|
|
4
|
+
import { i as p, a as b, p as d, b as C } from "./index-BZLcW0SX.js";
|
|
5
5
|
import { c as rr, f as er, g as tr, d as nr } from "./index-BZLcW0SX.js";
|
|
6
|
-
class
|
|
6
|
+
class l {
|
|
7
7
|
own = /* @__PURE__ */ new Map();
|
|
8
8
|
parent = null;
|
|
9
9
|
get(e) {
|
|
@@ -25,52 +25,58 @@ class h {
|
|
|
25
25
|
this.own.has(e) && console.warn(`[ComponentRegistry] Overwriting entry: ${e}`), this.own.set(e, t);
|
|
26
26
|
}
|
|
27
27
|
static withParent(e, t) {
|
|
28
|
-
const n = new
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
const n = new l(), o = (s) => {
|
|
29
|
+
if (s instanceof l)
|
|
30
|
+
s.own.forEach((a, i) => n.own.set(i, a));
|
|
31
|
+
else
|
|
32
|
+
for (const a of s.names()) {
|
|
33
|
+
const i = s.get(a);
|
|
34
|
+
i && n.own.set(a, i);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
return e instanceof l ? n.parent = e : o(e), o(t), n;
|
|
32
38
|
}
|
|
33
39
|
}
|
|
34
40
|
function K(r) {
|
|
35
|
-
const e = new
|
|
41
|
+
const e = new l();
|
|
36
42
|
return r({
|
|
37
|
-
component(n, o,
|
|
38
|
-
e._set(n, { component: o, type: "component", description:
|
|
43
|
+
component(n, o, s) {
|
|
44
|
+
e._set(n, { component: o, type: "component", description: s });
|
|
39
45
|
},
|
|
40
|
-
dataSource(n, o,
|
|
41
|
-
e._set(n, { component: o, type: "dataSource", description:
|
|
46
|
+
dataSource(n, o, s) {
|
|
47
|
+
e._set(n, { component: o, type: "dataSource", description: s });
|
|
42
48
|
}
|
|
43
49
|
}), e;
|
|
44
50
|
}
|
|
45
|
-
const v = "$fieldWrapper",
|
|
51
|
+
const v = "$fieldWrapper", S = O({});
|
|
46
52
|
function Q({ settings: r, children: e }) {
|
|
47
|
-
const t =
|
|
48
|
-
const
|
|
53
|
+
const t = J(S), n = y(() => t.registry && r.registry ? l.withParent(t.registry, r.registry) : r.registry ?? t.registry, [t.registry, r.registry]), o = y(() => {
|
|
54
|
+
const s = n?.get(v)?.component;
|
|
49
55
|
return {
|
|
50
56
|
...t,
|
|
51
57
|
...r,
|
|
52
58
|
registry: n,
|
|
53
|
-
fieldWrapper: r.fieldWrapper ??
|
|
59
|
+
fieldWrapper: r.fieldWrapper ?? s ?? t.fieldWrapper
|
|
54
60
|
};
|
|
55
61
|
}, [t, r, n]);
|
|
56
|
-
return /* @__PURE__ */
|
|
62
|
+
return /* @__PURE__ */ m(S.Provider, { value: o, children: e });
|
|
57
63
|
}
|
|
58
64
|
function D() {
|
|
59
|
-
return
|
|
65
|
+
return J(S);
|
|
60
66
|
}
|
|
61
|
-
function
|
|
67
|
+
function M(r) {
|
|
62
68
|
const e = r;
|
|
63
|
-
return
|
|
69
|
+
return p(e.array) && typeof e.item == "object" && e.item !== null && "$template" in e.item;
|
|
64
70
|
}
|
|
65
|
-
function
|
|
66
|
-
return
|
|
71
|
+
function N(r) {
|
|
72
|
+
return p(r.value);
|
|
67
73
|
}
|
|
68
74
|
function W(r) {
|
|
69
|
-
return
|
|
75
|
+
return b(r.component) && !N(r) && !M(r);
|
|
70
76
|
}
|
|
71
77
|
function P(r, e) {
|
|
72
78
|
if (!r) return;
|
|
73
|
-
const t =
|
|
79
|
+
const t = d(r)?.arg;
|
|
74
80
|
if (!t) throw new Error(`Invalid $component operator: "${r}"`);
|
|
75
81
|
const n = e.get(t);
|
|
76
82
|
if (!n)
|
|
@@ -89,73 +95,73 @@ function L(r, e) {
|
|
|
89
95
|
);
|
|
90
96
|
return t.component;
|
|
91
97
|
}
|
|
92
|
-
function
|
|
98
|
+
function V(r, e) {
|
|
93
99
|
return e.split(".").reduce((t, n) => t == null ? t : t[n], r);
|
|
94
100
|
}
|
|
95
|
-
function
|
|
101
|
+
function q(r) {
|
|
96
102
|
if (r === null || typeof r != "object") return !1;
|
|
97
103
|
const e = r;
|
|
98
|
-
return
|
|
104
|
+
return p(e.value) || p(e.array) || b(e.component);
|
|
99
105
|
}
|
|
100
|
-
function
|
|
106
|
+
function T(r) {
|
|
101
107
|
return r == null ? r : JSON.parse(JSON.stringify(r));
|
|
102
108
|
}
|
|
103
|
-
function
|
|
104
|
-
if (
|
|
105
|
-
if (
|
|
106
|
-
if (
|
|
107
|
-
if (
|
|
108
|
-
if (Array.isArray(r)) return r.map((n) =>
|
|
109
|
+
function R(r, e, t) {
|
|
110
|
+
if (C(r)) return L(d(r).arg, t);
|
|
111
|
+
if (b(r)) return P(r, t);
|
|
112
|
+
if (p(r)) return e.signalAt(d(r).arg);
|
|
113
|
+
if (q(r)) return g(r, e, t);
|
|
114
|
+
if (Array.isArray(r)) return r.map((n) => R(n, e, t));
|
|
109
115
|
if (r !== null && typeof r == "object") {
|
|
110
116
|
const n = r, o = {};
|
|
111
|
-
for (const
|
|
117
|
+
for (const s of Object.keys(n)) o[s] = R(n[s], e, t);
|
|
112
118
|
return o;
|
|
113
119
|
}
|
|
114
120
|
return r;
|
|
115
121
|
}
|
|
116
|
-
function
|
|
122
|
+
function w(r, e, t) {
|
|
117
123
|
if (!r) return;
|
|
118
124
|
const n = {};
|
|
119
|
-
for (const o of Object.keys(r)) n[o] =
|
|
125
|
+
for (const o of Object.keys(r)) n[o] = R(r[o], e, t);
|
|
120
126
|
return n;
|
|
121
127
|
}
|
|
122
|
-
function
|
|
123
|
-
if (
|
|
124
|
-
const n =
|
|
128
|
+
function g(r, e, t) {
|
|
129
|
+
if (M(r)) {
|
|
130
|
+
const n = V(e, d(r.array).arg), o = r.item.$template, s = r.initialValue;
|
|
125
131
|
return {
|
|
126
132
|
...r.selector ? { selector: r.selector } : {},
|
|
127
133
|
array: n,
|
|
128
|
-
initialValue: () =>
|
|
129
|
-
item: (
|
|
130
|
-
componentProps:
|
|
134
|
+
initialValue: () => s ? T(s) : {},
|
|
135
|
+
item: (a) => g(o, a, t),
|
|
136
|
+
componentProps: w(r.componentProps, e, t)
|
|
131
137
|
};
|
|
132
138
|
}
|
|
133
|
-
if (
|
|
134
|
-
const n =
|
|
139
|
+
if (N(r)) {
|
|
140
|
+
const n = d(r.value).arg, o = e.signalAt(n);
|
|
135
141
|
return !o && typeof console < "u" && console.warn(`[JsonRenderer/M1] No model signal for "${n}".`), {
|
|
136
142
|
...r.selector ? { selector: r.selector } : {},
|
|
137
143
|
value: o,
|
|
138
144
|
component: P(r.component, t),
|
|
139
|
-
componentProps:
|
|
145
|
+
componentProps: w(r.componentProps, e, t)
|
|
140
146
|
};
|
|
141
147
|
}
|
|
142
148
|
if (W(r))
|
|
143
149
|
return {
|
|
144
150
|
...r.selector ? { selector: r.selector } : {},
|
|
145
151
|
component: P(r.component, t),
|
|
146
|
-
componentProps:
|
|
147
|
-
children: r.children?.map((n) =>
|
|
152
|
+
componentProps: w(r.componentProps, e, t),
|
|
153
|
+
children: r.children?.map((n) => g(n, e, t))
|
|
148
154
|
};
|
|
149
155
|
throw new Error(`Invalid JSON node (M1): ${JSON.stringify(r)}`);
|
|
150
156
|
}
|
|
151
157
|
function U(r, e, t) {
|
|
152
|
-
return
|
|
158
|
+
return g(r.root, t, e);
|
|
153
159
|
}
|
|
154
|
-
function
|
|
155
|
-
return () =>
|
|
160
|
+
function z(r, e, t) {
|
|
161
|
+
return () => g(r.root, t, e);
|
|
156
162
|
}
|
|
157
|
-
function
|
|
158
|
-
return /* @__PURE__ */
|
|
163
|
+
function I({ errors: r }) {
|
|
164
|
+
return /* @__PURE__ */ E(
|
|
159
165
|
"div",
|
|
160
166
|
{
|
|
161
167
|
role: "alert",
|
|
@@ -169,12 +175,12 @@ function q({ errors: r }) {
|
|
|
169
175
|
font: "14px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace"
|
|
170
176
|
},
|
|
171
177
|
children: [
|
|
172
|
-
/* @__PURE__ */
|
|
178
|
+
/* @__PURE__ */ E("strong", { style: { display: "block", marginBottom: 8, fontSize: 15 }, children: [
|
|
173
179
|
"Невалидная JSON-схема формы (",
|
|
174
180
|
r.length,
|
|
175
181
|
")"
|
|
176
182
|
] }),
|
|
177
|
-
/* @__PURE__ */
|
|
183
|
+
/* @__PURE__ */ m("ul", { style: { margin: 0, paddingLeft: 20 }, children: r.map((e, t) => /* @__PURE__ */ m("li", { style: { marginBottom: 4 }, children: e }, t)) })
|
|
178
184
|
]
|
|
179
185
|
}
|
|
180
186
|
);
|
|
@@ -185,56 +191,60 @@ function X({
|
|
|
185
191
|
onSchemaReady: t,
|
|
186
192
|
validate: n = !1
|
|
187
193
|
}) {
|
|
188
|
-
const { registry: o, model:
|
|
194
|
+
const { registry: o, model: s, ...a } = D(), [i, h] = F(
|
|
189
195
|
n ? void 0 : null
|
|
190
196
|
);
|
|
191
|
-
|
|
197
|
+
j(() => {
|
|
192
198
|
if (!n) {
|
|
193
|
-
|
|
199
|
+
h(null);
|
|
194
200
|
return;
|
|
195
201
|
}
|
|
196
|
-
let
|
|
197
|
-
return
|
|
198
|
-
if (
|
|
199
|
-
const { valid:
|
|
200
|
-
|
|
201
|
-
}).catch((
|
|
202
|
-
|
|
202
|
+
let f = !1;
|
|
203
|
+
return h(void 0), import("./validate.js").then(({ validateFormSchema: c }) => {
|
|
204
|
+
if (f) return;
|
|
205
|
+
const { valid: $, errors: x } = c(r, { registry: o });
|
|
206
|
+
h($ ? null : x);
|
|
207
|
+
}).catch((c) => {
|
|
208
|
+
f || h([`Schema validator failed to load: ${String(c)}`]);
|
|
203
209
|
}), () => {
|
|
204
|
-
|
|
210
|
+
f = !0;
|
|
205
211
|
};
|
|
206
212
|
}, [n, r, o]);
|
|
207
|
-
const
|
|
208
|
-
if (!
|
|
213
|
+
const u = y(() => {
|
|
214
|
+
if (!s)
|
|
209
215
|
throw new Error(
|
|
210
216
|
"JsonFormRenderer: settings.model is required (M1). Pass the FormModel via JsonRendererProvider."
|
|
211
217
|
);
|
|
212
|
-
if (
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
218
|
+
if (i !== null) return null;
|
|
219
|
+
if (!o)
|
|
220
|
+
throw new Error(
|
|
221
|
+
"JsonFormRenderer: settings.registry is required. Pass a ComponentRegistry via JsonRendererProvider."
|
|
222
|
+
);
|
|
223
|
+
const f = z(r, o, s), c = k(f);
|
|
224
|
+
return e && e(c), c;
|
|
225
|
+
}, [r, o, e, s, i]);
|
|
226
|
+
return y(() => {
|
|
227
|
+
u && t && t(u);
|
|
228
|
+
}, [u]), i && i.length > 0 ? /* @__PURE__ */ m(I, { errors: i }) : u ? /* @__PURE__ */ m(A, { render: u, settings: a }) : null;
|
|
219
229
|
}
|
|
220
230
|
export {
|
|
221
231
|
v as FIELD_WRAPPER,
|
|
222
232
|
X as JsonFormRenderer,
|
|
223
233
|
Q as JsonRendererProvider,
|
|
224
|
-
|
|
234
|
+
I as SchemaErrorPanel,
|
|
225
235
|
rr as buildFormSchemaMetaSchema,
|
|
226
236
|
U as convertJsonToM1Tree,
|
|
227
|
-
|
|
237
|
+
z as createRenderSchemaFromJsonM1,
|
|
228
238
|
K as defineRegistry,
|
|
229
239
|
er as formSchemaMetaSchema,
|
|
230
240
|
tr as getComponentNames,
|
|
231
241
|
nr as getDataSourceNames,
|
|
232
|
-
|
|
233
|
-
|
|
242
|
+
M as isArrayNode,
|
|
243
|
+
b as isComponentOp,
|
|
234
244
|
W as isContainerNode,
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
245
|
+
C as isDataSourceOp,
|
|
246
|
+
N as isFieldNode,
|
|
247
|
+
p as isModelOp,
|
|
248
|
+
d as parseOperator,
|
|
239
249
|
D as useJsonRendererSettings
|
|
240
250
|
};
|