@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.
Files changed (2) hide show
  1. package/dist/index.js +95 -85
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- import { jsx as u, jsxs as M } from "react/jsx-runtime";
2
- import { useContext as N, createContext as O, useMemo as g, useState as C, useEffect as F } from "react";
3
- import { createRenderSchema as j, FormRenderer as k } from "@reformer/renderer-react";
4
- import { i as f, a as R, p as m, b as A } from "./index-BZLcW0SX.js";
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 h {
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 h();
29
- return n.parent = e, t.own.forEach((o, i) => {
30
- n.own.set(i, o);
31
- }), n;
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 h();
41
+ const e = new l();
36
42
  return r({
37
- component(n, o, i) {
38
- e._set(n, { component: o, type: "component", description: i });
43
+ component(n, o, s) {
44
+ e._set(n, { component: o, type: "component", description: s });
39
45
  },
40
- dataSource(n, o, i) {
41
- e._set(n, { component: o, type: "dataSource", description: i });
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", w = O({});
51
+ const v = "$fieldWrapper", S = O({});
46
52
  function Q({ settings: r, children: e }) {
47
- const t = N(w), n = g(() => t.registry && r.registry ? h.withParent(t.registry, r.registry) : r.registry ?? t.registry, [t.registry, r.registry]), o = g(() => {
48
- const i = n?.get(v)?.component;
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 ?? i ?? t.fieldWrapper
59
+ fieldWrapper: r.fieldWrapper ?? s ?? t.fieldWrapper
54
60
  };
55
61
  }, [t, r, n]);
56
- return /* @__PURE__ */ u(w.Provider, { value: o, children: e });
62
+ return /* @__PURE__ */ m(S.Provider, { value: o, children: e });
57
63
  }
58
64
  function D() {
59
- return N(w);
65
+ return J(S);
60
66
  }
61
- function $(r) {
67
+ function M(r) {
62
68
  const e = r;
63
- return f(e.array) && typeof e.item == "object" && e.item !== null && "$template" in e.item;
69
+ return p(e.array) && typeof e.item == "object" && e.item !== null && "$template" in e.item;
64
70
  }
65
- function E(r) {
66
- return f(r.value);
71
+ function N(r) {
72
+ return p(r.value);
67
73
  }
68
74
  function W(r) {
69
- return R(r.component) && !E(r) && !$(r);
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 = m(r)?.arg;
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 I(r, e) {
98
+ function V(r, e) {
93
99
  return e.split(".").reduce((t, n) => t == null ? t : t[n], r);
94
100
  }
95
- function V(r) {
101
+ function q(r) {
96
102
  if (r === null || typeof r != "object") return !1;
97
103
  const e = r;
98
- return f(e.value) || f(e.array) || R(e.component);
104
+ return p(e.value) || p(e.array) || b(e.component);
99
105
  }
100
- function _(r) {
106
+ function T(r) {
101
107
  return r == null ? r : JSON.parse(JSON.stringify(r));
102
108
  }
103
- function b(r, e, t) {
104
- if (A(r)) return L(m(r).arg, t);
105
- if (R(r)) return P(r, t);
106
- if (f(r)) return e.signalAt(m(r).arg);
107
- if (V(r)) return p(r, e, t);
108
- if (Array.isArray(r)) return r.map((n) => b(n, e, t));
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 i of Object.keys(n)) o[i] = b(n[i], e, t);
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 S(r, e, t) {
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] = b(r[o], e, t);
125
+ for (const o of Object.keys(r)) n[o] = R(r[o], e, t);
120
126
  return n;
121
127
  }
122
- function p(r, e, t) {
123
- if ($(r)) {
124
- const n = I(e, m(r.array).arg), o = r.item.$template, i = r.initialValue;
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: () => i ? _(i) : {},
129
- item: (y) => p(o, y, t),
130
- componentProps: S(r.componentProps, e, t)
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 (E(r)) {
134
- const n = m(r.value).arg, o = e.signalAt(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: S(r.componentProps, e, t)
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: S(r.componentProps, e, t),
147
- children: r.children?.map((n) => p(n, e, t))
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 p(r.root, t, e);
158
+ return g(r.root, t, e);
153
159
  }
154
- function T(r, e, t) {
155
- return () => p(r.root, t, e);
160
+ function z(r, e, t) {
161
+ return () => g(r.root, t, e);
156
162
  }
157
- function q({ errors: r }) {
158
- return /* @__PURE__ */ M(
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__ */ M("strong", { style: { display: "block", marginBottom: 8, fontSize: 15 }, children: [
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__ */ u("ul", { style: { margin: 0, paddingLeft: 20 }, children: r.map((e, t) => /* @__PURE__ */ u("li", { style: { marginBottom: 4 }, children: e }, t)) })
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: i, ...y } = D(), [a, d] = C(
194
+ const { registry: o, model: s, ...a } = D(), [i, h] = F(
189
195
  n ? void 0 : null
190
196
  );
191
- F(() => {
197
+ j(() => {
192
198
  if (!n) {
193
- d(null);
199
+ h(null);
194
200
  return;
195
201
  }
196
- let l = !1;
197
- return d(void 0), import("./validate.js").then(({ validateFormSchema: s }) => {
198
- if (l) return;
199
- const { valid: J, errors: x } = s(r, { registry: o });
200
- d(J ? null : x);
201
- }).catch((s) => {
202
- l || d([`Schema validator failed to load: ${String(s)}`]);
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
- l = !0;
210
+ f = !0;
205
211
  };
206
212
  }, [n, r, o]);
207
- const c = g(() => {
208
- if (!i)
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 (a !== null) return null;
213
- const l = T(r, o, i), s = j(l);
214
- return e && e(s), s;
215
- }, [r, o, e, i, a]);
216
- return g(() => {
217
- c && t && t(c);
218
- }, [c]), a && a.length > 0 ? /* @__PURE__ */ u(q, { errors: a }) : c ? /* @__PURE__ */ u(k, { render: c, settings: y }) : null;
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
- q as SchemaErrorPanel,
234
+ I as SchemaErrorPanel,
225
235
  rr as buildFormSchemaMetaSchema,
226
236
  U as convertJsonToM1Tree,
227
- T as createRenderSchemaFromJsonM1,
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
- $ as isArrayNode,
233
- R as isComponentOp,
242
+ M as isArrayNode,
243
+ b as isComponentOp,
234
244
  W as isContainerNode,
235
- A as isDataSourceOp,
236
- E as isFieldNode,
237
- f as isModelOp,
238
- m as parseOperator,
245
+ C as isDataSourceOp,
246
+ N as isFieldNode,
247
+ p as isModelOp,
248
+ d as parseOperator,
239
249
  D as useJsonRendererSettings
240
250
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reformer/renderer-json",
3
- "version": "7.0.0",
3
+ "version": "9.0.0",
4
4
  "description": "JSON-based form renderer for @reformer ecosystem",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",