@companix/formkit 0.0.23 → 0.0.24
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/Visability.d.ts +4 -0
- package/dist/bundle.es.js +214 -209
- package/dist/core/builders/syntax.d.ts +3 -0
- package/dist/core/types.d.ts +6 -1
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/bundle.es.js
CHANGED
|
@@ -1,202 +1,202 @@
|
|
|
1
1
|
import { jsx as h, Fragment as j, jsxs as B } from "react/jsx-runtime";
|
|
2
|
-
import { createContext as M, useState as w, useContext as R, useMemo as C, useEffect as
|
|
2
|
+
import { createContext as M, useState as w, useContext as R, useMemo as C, useEffect as $, useCallback as A, useRef as P } from "react";
|
|
3
3
|
import L from "fast-deep-equal";
|
|
4
|
-
const D = M({}), q = (
|
|
5
|
-
const [,
|
|
6
|
-
if (!
|
|
4
|
+
const D = M({}), q = (o) => {
|
|
5
|
+
const [, r] = w([]), e = R(D);
|
|
6
|
+
if (!e)
|
|
7
7
|
throw new Error("useValue cannot be used outside Form context");
|
|
8
8
|
const s = C(() => {
|
|
9
|
-
const t =
|
|
9
|
+
const t = e.getForm(o);
|
|
10
10
|
if (!t)
|
|
11
|
-
throw new Error(`form with name "${
|
|
11
|
+
throw new Error(`form with name "${o}" doesnt exist in form`);
|
|
12
12
|
return t;
|
|
13
|
-
}, [
|
|
14
|
-
return
|
|
15
|
-
const t =
|
|
16
|
-
|
|
13
|
+
}, [e, o]);
|
|
14
|
+
return $(() => {
|
|
15
|
+
const t = e.subscribeToForm(o, () => {
|
|
16
|
+
r([]);
|
|
17
17
|
});
|
|
18
18
|
return () => {
|
|
19
19
|
t();
|
|
20
20
|
};
|
|
21
21
|
}, []), s.value;
|
|
22
|
-
}, O = () => (
|
|
23
|
-
const s = q(
|
|
24
|
-
return
|
|
25
|
-
}, U = ({ item: { Form:
|
|
26
|
-
const [,
|
|
27
|
-
|
|
28
|
-
}), []),
|
|
22
|
+
}, O = () => (o) => q(o), N = ({ canActivate: o, name: r, children: e }) => {
|
|
23
|
+
const s = q(r);
|
|
24
|
+
return o(s) ? /* @__PURE__ */ h(j, { children: e }) : null;
|
|
25
|
+
}, U = ({ item: { Form: o }, name: r }) => {
|
|
26
|
+
const [, e] = w([]), s = R(D), { unregistry: t } = C(() => s.registry(r, () => {
|
|
27
|
+
e([]);
|
|
28
|
+
}), []), l = A(
|
|
29
29
|
(y) => {
|
|
30
30
|
if (y && y.focus) {
|
|
31
|
-
const v = s.getForm(
|
|
31
|
+
const v = s.getForm(r);
|
|
32
32
|
v.focus = () => {
|
|
33
33
|
y.focus();
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
|
-
[
|
|
37
|
+
[r]
|
|
38
38
|
);
|
|
39
|
-
|
|
39
|
+
$(() => () => {
|
|
40
40
|
t();
|
|
41
41
|
}, []);
|
|
42
|
-
const { value:
|
|
42
|
+
const { value: g, error: x } = s.getForm(r);
|
|
43
43
|
return /* @__PURE__ */ h(
|
|
44
|
-
|
|
44
|
+
o,
|
|
45
45
|
{
|
|
46
46
|
field: {
|
|
47
|
-
value:
|
|
47
|
+
value: g,
|
|
48
48
|
onChange: (y) => {
|
|
49
|
-
s.onChange(
|
|
49
|
+
s.onChange(r, y);
|
|
50
50
|
},
|
|
51
51
|
onBlur: () => {
|
|
52
52
|
},
|
|
53
|
-
ref:
|
|
53
|
+
ref: l
|
|
54
54
|
},
|
|
55
55
|
isDirty: !1,
|
|
56
56
|
error: x,
|
|
57
57
|
disabled: s.disabled
|
|
58
58
|
}
|
|
59
59
|
);
|
|
60
|
-
}, z = ({ item:
|
|
61
|
-
const { getController:
|
|
62
|
-
const
|
|
63
|
-
return s.forEach(({ name:
|
|
64
|
-
|
|
65
|
-
}),
|
|
66
|
-
}, []),
|
|
67
|
-
const
|
|
68
|
-
return s.forEach(({ name:
|
|
69
|
-
t.getForm([...
|
|
70
|
-
}),
|
|
71
|
-
}, []), x = C(() =>
|
|
72
|
-
|
|
73
|
-
const { unregistry:
|
|
74
|
-
s.map(({ name:
|
|
60
|
+
}, z = ({ item: o, path: r }) => {
|
|
61
|
+
const { getController: e, items: s } = o, t = R(D), l = C(() => {
|
|
62
|
+
const f = {};
|
|
63
|
+
return s.forEach(({ name: b, getForm: n }) => {
|
|
64
|
+
f[b] = n(b, () => a(b));
|
|
65
|
+
}), f;
|
|
66
|
+
}, []), g = A(() => {
|
|
67
|
+
const f = [];
|
|
68
|
+
return s.forEach(({ name: b }) => {
|
|
69
|
+
t.getForm([...r, b].join(".")).value !== void 0 && f.push(b);
|
|
70
|
+
}), f;
|
|
71
|
+
}, []), x = C(() => g(), []), [y, v] = w(x);
|
|
72
|
+
$(() => {
|
|
73
|
+
const { unregistry: f } = t.registryExtraForm(
|
|
74
|
+
s.map(({ name: b }) => [...r, b].join(".")),
|
|
75
75
|
() => {
|
|
76
|
-
v(
|
|
76
|
+
v(g());
|
|
77
77
|
}
|
|
78
78
|
);
|
|
79
79
|
return () => {
|
|
80
|
-
|
|
80
|
+
f();
|
|
81
81
|
};
|
|
82
82
|
}, []);
|
|
83
83
|
const d = A(
|
|
84
|
-
(
|
|
85
|
-
f
|
|
84
|
+
(f) => {
|
|
85
|
+
l[f] && !y.includes(f) && v((b) => [...b, f]);
|
|
86
86
|
},
|
|
87
87
|
[y]
|
|
88
|
-
), a = A((
|
|
89
|
-
v((
|
|
88
|
+
), a = A((f) => {
|
|
89
|
+
v((b) => b.filter((n) => n !== f));
|
|
90
90
|
}, []);
|
|
91
91
|
return /* @__PURE__ */ B(j, { children: [
|
|
92
|
-
y.map((
|
|
93
|
-
const
|
|
94
|
-
return /* @__PURE__ */ h(
|
|
92
|
+
y.map((f) => {
|
|
93
|
+
const b = l[f];
|
|
94
|
+
return /* @__PURE__ */ h(V, { path: r, scheme: [b] }, `param-form--${f}`);
|
|
95
95
|
}),
|
|
96
|
-
|
|
96
|
+
e(d, y)
|
|
97
97
|
] });
|
|
98
|
-
},
|
|
99
|
-
|
|
98
|
+
}, V = ({ scheme: o, path: r }) => /* @__PURE__ */ h(j, { children: o.map((e, s) => e.type === "layout" ? /* @__PURE__ */ h(e.Layout, { children: /* @__PURE__ */ h(V, { path: r, scheme: e.childs }) }, `layout-form--${s}-${r.length}`) : e.type === "context" ? /* @__PURE__ */ h(
|
|
99
|
+
V,
|
|
100
100
|
{
|
|
101
|
-
path: [...
|
|
102
|
-
scheme:
|
|
101
|
+
path: [...r, e.context],
|
|
102
|
+
scheme: e.childs
|
|
103
103
|
},
|
|
104
|
-
`context-form--${s}-${
|
|
105
|
-
) :
|
|
104
|
+
`context-form--${s}-${e.context}-${r.length}`
|
|
105
|
+
) : e.type === "condition" ? /* @__PURE__ */ h(
|
|
106
106
|
N,
|
|
107
107
|
{
|
|
108
|
-
name:
|
|
109
|
-
canActivate:
|
|
110
|
-
children: /* @__PURE__ */ h(
|
|
108
|
+
name: e.depended,
|
|
109
|
+
canActivate: e.canActivate,
|
|
110
|
+
children: /* @__PURE__ */ h(V, { path: r, scheme: e.childs })
|
|
111
111
|
},
|
|
112
|
-
`condition--${s}-${
|
|
113
|
-
) :
|
|
112
|
+
`condition--${s}-${e.depended}-${r.length}`
|
|
113
|
+
) : e.type === "extra" ? /* @__PURE__ */ h(z, { path: r, item: e }, `partial-item--${s}-${r.length}`) : e.type === "visability" ? e.hidden ? null : /* @__PURE__ */ h(V, { path: r, scheme: e.childs }, `visability--${s}-${r.length}`) : /* @__PURE__ */ h(
|
|
114
114
|
U,
|
|
115
115
|
{
|
|
116
|
-
name: [...
|
|
117
|
-
item:
|
|
116
|
+
name: [...r, e.name].join("."),
|
|
117
|
+
item: e
|
|
118
118
|
},
|
|
119
|
-
`form-item--${s}-${
|
|
120
|
-
)) }),
|
|
121
|
-
|
|
122
|
-
if (t.type === "form" && s(t, [...
|
|
123
|
-
|
|
119
|
+
`form-item--${s}-${e.name}-${r.length}`
|
|
120
|
+
)) }), E = (o, r, e, s) => {
|
|
121
|
+
o.forEach((t) => {
|
|
122
|
+
if (t.type === "form" && s(t, [...r, t.name].join("."), e[t.name]), t.type === "context") {
|
|
123
|
+
E(t.childs, [...r, t.context], e[t.context] ?? {}, s);
|
|
124
124
|
return;
|
|
125
125
|
}
|
|
126
126
|
if (t.type === "layout" || t.type === "condition") {
|
|
127
|
-
|
|
127
|
+
E(t.childs, r, e, s);
|
|
128
128
|
return;
|
|
129
129
|
}
|
|
130
|
-
t.type === "extra" && t.items.forEach(({ getForm:
|
|
131
|
-
|
|
132
|
-
})],
|
|
130
|
+
t.type === "extra" && t.items.forEach(({ getForm: l, name: g }) => {
|
|
131
|
+
E([l(g, () => {
|
|
132
|
+
})], r, e, s);
|
|
133
133
|
});
|
|
134
134
|
});
|
|
135
|
-
},
|
|
136
|
-
|
|
135
|
+
}, p = ({ scheme: o, values: r, path: e, forms: s }) => {
|
|
136
|
+
o.forEach((t) => {
|
|
137
137
|
if (t.type === "form") {
|
|
138
|
-
const
|
|
139
|
-
s[
|
|
138
|
+
const l = [...e, t.name].join(".");
|
|
139
|
+
s[l].value !== void 0 && (r[t.name] = s[l].value);
|
|
140
140
|
}
|
|
141
141
|
if (t.type === "context") {
|
|
142
|
-
|
|
142
|
+
r[t.context] = {}, p({
|
|
143
143
|
scheme: t.childs,
|
|
144
|
-
path: [...
|
|
145
|
-
values:
|
|
144
|
+
path: [...e, t.context],
|
|
145
|
+
values: r[t.context],
|
|
146
146
|
forms: s
|
|
147
147
|
});
|
|
148
148
|
return;
|
|
149
149
|
}
|
|
150
150
|
if (t.type === "layout") {
|
|
151
|
-
|
|
151
|
+
p({ scheme: t.childs, path: e, values: r, forms: s });
|
|
152
152
|
return;
|
|
153
153
|
}
|
|
154
154
|
if (t.type === "condition") {
|
|
155
|
-
const
|
|
156
|
-
if (t.canActivate(
|
|
157
|
-
|
|
155
|
+
const l = s[t.depended]?.value;
|
|
156
|
+
if (t.canActivate(l)) {
|
|
157
|
+
p({ scheme: t.childs, path: e, values: r, forms: s });
|
|
158
158
|
return;
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
|
-
t.type === "extra" && t.items.forEach(({ getForm:
|
|
162
|
-
|
|
163
|
-
})], path:
|
|
161
|
+
t.type === "extra" && t.items.forEach(({ getForm: l, name: g }) => {
|
|
162
|
+
p({ scheme: [l(g, () => {
|
|
163
|
+
})], path: e, values: r, forms: s });
|
|
164
164
|
});
|
|
165
165
|
});
|
|
166
|
-
}, T = (
|
|
167
|
-
const
|
|
168
|
-
return
|
|
169
|
-
}, G = (
|
|
170
|
-
const { onSubmit:
|
|
166
|
+
}, T = (o, r) => {
|
|
167
|
+
const e = {};
|
|
168
|
+
return p({ scheme: o, path: [], values: e, forms: r }), e;
|
|
169
|
+
}, G = (o, r) => {
|
|
170
|
+
const { onSubmit: e, onEqual: s, disabled: t, onDirty: l, onFormDirty: g, onChangeEvent: x, defaultValues: y } = r, v = { onSubmit: e }, d = {
|
|
171
171
|
isActive: !1,
|
|
172
172
|
isSubmitted: !1,
|
|
173
173
|
dirtyCount: 0
|
|
174
|
-
}, a = {},
|
|
174
|
+
}, a = {}, f = {
|
|
175
175
|
subscribers: [],
|
|
176
176
|
names: {}
|
|
177
177
|
};
|
|
178
|
-
|
|
179
|
-
a[
|
|
178
|
+
E(o, [], y ?? {}, (n, u, i) => {
|
|
179
|
+
a[u] = {
|
|
180
180
|
error: null,
|
|
181
181
|
isDirty: !1,
|
|
182
|
-
value:
|
|
182
|
+
value: i,
|
|
183
183
|
// текущее (динамическое) состояние поля. Значение равно переданному дефолтному, либо: определяется как дефолтное значение компонента формы в момент его монтирования, а до этого - undefined.
|
|
184
|
-
startValue:
|
|
184
|
+
startValue: i ?? n.defaultValue,
|
|
185
185
|
// начальное (стартовое) значение (равно переданному дефолтному, либо значению формы по умолчанию). Исходя из сравнения текущего значения со стартовым, можно понять, модифицированно ли поле
|
|
186
|
-
defaultValue:
|
|
186
|
+
defaultValue: n.defaultValue,
|
|
187
187
|
// дефолтное значение компонента формы
|
|
188
188
|
rerender: () => {
|
|
189
189
|
},
|
|
190
190
|
subscribers: [],
|
|
191
|
-
validate:
|
|
191
|
+
validate: n.validate
|
|
192
192
|
};
|
|
193
193
|
});
|
|
194
|
-
const
|
|
195
|
-
|
|
194
|
+
const b = (n, u) => {
|
|
195
|
+
l?.({ name: n, isDirty: u }), u && d.dirtyCount === 0 && g?.(!0), !u && d.dirtyCount === 1 && g?.(!1), d.dirtyCount += u ? 1 : -1;
|
|
196
196
|
};
|
|
197
197
|
return {
|
|
198
198
|
submitRef: v,
|
|
199
|
-
scheme:
|
|
199
|
+
scheme: o,
|
|
200
200
|
disabled: t,
|
|
201
201
|
activate() {
|
|
202
202
|
d.isActive = !0;
|
|
@@ -204,125 +204,125 @@ const D = M({}), q = (n) => {
|
|
|
204
204
|
disactivate() {
|
|
205
205
|
d.isActive = !1;
|
|
206
206
|
},
|
|
207
|
-
setError(
|
|
208
|
-
const
|
|
209
|
-
|
|
207
|
+
setError(n, u) {
|
|
208
|
+
const i = this.getForm(n);
|
|
209
|
+
i && (i.error = {
|
|
210
210
|
error: !0,
|
|
211
|
-
messages: [
|
|
212
|
-
},
|
|
211
|
+
messages: [u.message]
|
|
212
|
+
}, i.rerender());
|
|
213
213
|
},
|
|
214
|
-
setFocus(
|
|
215
|
-
const
|
|
216
|
-
|
|
214
|
+
setFocus(n) {
|
|
215
|
+
const u = this.getForm(n);
|
|
216
|
+
u && u.focus && u.focus();
|
|
217
217
|
},
|
|
218
|
-
setValue(
|
|
219
|
-
const
|
|
220
|
-
|
|
218
|
+
setValue(n, u) {
|
|
219
|
+
const i = this.getForm(n);
|
|
220
|
+
i && i.value !== u && this.onChange(n, u);
|
|
221
221
|
},
|
|
222
222
|
getValues() {
|
|
223
|
-
return T(
|
|
223
|
+
return T(o, a);
|
|
224
224
|
},
|
|
225
225
|
async handleSubmit() {
|
|
226
226
|
if (t)
|
|
227
227
|
return;
|
|
228
228
|
d.isSubmitted = !0;
|
|
229
|
-
let
|
|
230
|
-
for (const
|
|
231
|
-
const c = a[
|
|
229
|
+
let n = !1, u = !1;
|
|
230
|
+
for (const i in a) {
|
|
231
|
+
const c = a[i];
|
|
232
232
|
if (c.value !== void 0) {
|
|
233
|
-
const
|
|
234
|
-
|
|
233
|
+
const F = c.validate(c.value);
|
|
234
|
+
F && (u = !0, c.error = F, c.rerender(), !n && c.focus && (c.focus(), n = !0));
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
|
-
if (!
|
|
237
|
+
if (!u) {
|
|
238
238
|
if (d.dirtyCount === 0 && s) {
|
|
239
239
|
s();
|
|
240
240
|
return;
|
|
241
241
|
}
|
|
242
|
-
const
|
|
243
|
-
await v.onSubmit(
|
|
244
|
-
setError: (c,
|
|
245
|
-
const
|
|
246
|
-
|
|
242
|
+
const i = T(o, a);
|
|
243
|
+
await v.onSubmit(i, {
|
|
244
|
+
setError: (c, F) => {
|
|
245
|
+
const m = this.getForm(c);
|
|
246
|
+
m.error = {
|
|
247
247
|
error: !0,
|
|
248
|
-
messages: [
|
|
249
|
-
},
|
|
248
|
+
messages: [F.message]
|
|
249
|
+
}, m.rerender();
|
|
250
250
|
}
|
|
251
251
|
}).catch((c) => {
|
|
252
252
|
console.log("[formkit] submit exception:", c);
|
|
253
253
|
});
|
|
254
254
|
}
|
|
255
255
|
},
|
|
256
|
-
reset(
|
|
257
|
-
|
|
258
|
-
if (
|
|
256
|
+
reset(n, { asDirty: u }) {
|
|
257
|
+
E(o, [], n, (i, c, F) => {
|
|
258
|
+
if (F === void 0 && a[c].value === void 0)
|
|
259
259
|
return;
|
|
260
|
-
if (
|
|
260
|
+
if (f.names[c] && F === void 0) {
|
|
261
261
|
a[c].value = void 0;
|
|
262
262
|
return;
|
|
263
263
|
}
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
}),
|
|
267
|
-
|
|
264
|
+
const m = F ?? i.defaultValue;
|
|
265
|
+
u || (a[c].startValue = m, a[c].isDirty = !1), a[c].value !== m && this.onChange(c, m);
|
|
266
|
+
}), u || (d.dirtyCount = 0, d.isSubmitted = !1), f.subscribers.forEach(({ visualizeEvalueatedForms: i }) => {
|
|
267
|
+
i();
|
|
268
268
|
});
|
|
269
269
|
},
|
|
270
270
|
setAsDefault() {
|
|
271
|
-
|
|
272
|
-
a[
|
|
271
|
+
E(o, [], {}, ({}, n) => {
|
|
272
|
+
a[n].startValue = a[n].value, a[n].isDirty = !1;
|
|
273
273
|
}), d.dirtyCount = 0, d.isSubmitted = !1;
|
|
274
274
|
},
|
|
275
|
-
registry(
|
|
276
|
-
return a[
|
|
275
|
+
registry(n, u) {
|
|
276
|
+
return a[n].rerender = u, a[n].value === void 0 && (a[n].value = a[n].defaultValue), {
|
|
277
277
|
unregistry() {
|
|
278
|
-
if (a[
|
|
279
|
-
}, a[
|
|
280
|
-
a[
|
|
281
|
-
const
|
|
282
|
-
a[
|
|
278
|
+
if (a[n].rerender = () => {
|
|
279
|
+
}, a[n].focus = void 0, d.isActive) {
|
|
280
|
+
a[n].value = void 0;
|
|
281
|
+
const i = !L(a[n].startValue, a[n].defaultValue);
|
|
282
|
+
a[n].isDirty !== i && b(n, i), a[n].isDirty = i;
|
|
283
283
|
}
|
|
284
284
|
}
|
|
285
285
|
};
|
|
286
286
|
},
|
|
287
|
-
getForm(
|
|
288
|
-
return a[
|
|
287
|
+
getForm(n) {
|
|
288
|
+
return a[n];
|
|
289
289
|
},
|
|
290
|
-
subscribeToForm(
|
|
291
|
-
const
|
|
292
|
-
return c.subscribers.push(
|
|
293
|
-
c.subscribers = c.subscribers.filter((
|
|
290
|
+
subscribeToForm(n, u) {
|
|
291
|
+
const i = { callback: u }, c = this.getForm(n);
|
|
292
|
+
return c.subscribers.push(i), () => {
|
|
293
|
+
c.subscribers = c.subscribers.filter((F) => F !== i);
|
|
294
294
|
};
|
|
295
295
|
},
|
|
296
|
-
registryExtraForm(
|
|
297
|
-
const
|
|
298
|
-
return
|
|
299
|
-
|
|
300
|
-
}),
|
|
296
|
+
registryExtraForm(n, u) {
|
|
297
|
+
const i = { visualizeEvalueatedForms: u };
|
|
298
|
+
return n.forEach((c) => {
|
|
299
|
+
f.names[c] = !0;
|
|
300
|
+
}), f.subscribers.push(i), {
|
|
301
301
|
unregistry() {
|
|
302
|
-
|
|
302
|
+
f.subscribers = f.subscribers.filter((c) => c !== i);
|
|
303
303
|
}
|
|
304
304
|
};
|
|
305
305
|
},
|
|
306
|
-
onChange(
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
const
|
|
310
|
-
|
|
311
|
-
|
|
306
|
+
onChange(n, u) {
|
|
307
|
+
const i = this.getForm(n), c = !L(u, i.startValue);
|
|
308
|
+
i.isDirty !== c && b(n, c), i.isDirty = c, x?.({ name: n, value: u }), (i.error || d.isSubmitted) && (i.error = i.validate(u) || null);
|
|
309
|
+
const F = i.value;
|
|
310
|
+
i.value = u, i.rerender(), i.subscribers.forEach(({ callback: m }) => {
|
|
311
|
+
m(u, F);
|
|
312
312
|
});
|
|
313
313
|
}
|
|
314
314
|
};
|
|
315
|
-
}, Q = (
|
|
316
|
-
const
|
|
317
|
-
|
|
318
|
-
const s =
|
|
319
|
-
return
|
|
320
|
-
|
|
321
|
-
}, [
|
|
315
|
+
}, Q = (o, r) => {
|
|
316
|
+
const e = P(null);
|
|
317
|
+
e.current === null && (e.current = G(o, r));
|
|
318
|
+
const s = e.current;
|
|
319
|
+
return $(() => {
|
|
320
|
+
e.current && (e.current.submitRef.onSubmit = r.onSubmit);
|
|
321
|
+
}, [r.onSubmit]), {
|
|
322
322
|
manager: s,
|
|
323
323
|
useValue: (t) => q(t),
|
|
324
|
-
reset: (t,
|
|
325
|
-
s.reset(t,
|
|
324
|
+
reset: (t, l = {}) => {
|
|
325
|
+
s.reset(t, l);
|
|
326
326
|
},
|
|
327
327
|
setAsDefault: () => {
|
|
328
328
|
s.setAsDefault();
|
|
@@ -330,11 +330,11 @@ const D = M({}), q = (n) => {
|
|
|
330
330
|
setFocus: (t) => {
|
|
331
331
|
s.setFocus(t);
|
|
332
332
|
},
|
|
333
|
-
setError: (t,
|
|
334
|
-
s.setError(t,
|
|
333
|
+
setError: (t, l) => {
|
|
334
|
+
s.setError(t, l);
|
|
335
335
|
},
|
|
336
|
-
setValue: (t,
|
|
337
|
-
s.setValue(t,
|
|
336
|
+
setValue: (t, l) => {
|
|
337
|
+
s.setValue(t, l);
|
|
338
338
|
},
|
|
339
339
|
getValue: (t) => s.getForm(t).value,
|
|
340
340
|
getValues: () => s.getValues(),
|
|
@@ -342,77 +342,82 @@ const D = M({}), q = (n) => {
|
|
|
342
342
|
await s.handleSubmit();
|
|
343
343
|
},
|
|
344
344
|
// prettier-ignore
|
|
345
|
-
subscribe: (t,
|
|
345
|
+
subscribe: (t, l) => s.subscribeToForm(t, l)
|
|
346
346
|
};
|
|
347
|
-
}, W = ({ manager:
|
|
348
|
-
|
|
349
|
-
}, []),
|
|
350
|
-
|
|
351
|
-
}, []), /* @__PURE__ */ h(D.Provider, { value:
|
|
347
|
+
}, W = ({ manager: o }) => (C(() => {
|
|
348
|
+
o.activate();
|
|
349
|
+
}, []), $(() => () => {
|
|
350
|
+
o.disactivate();
|
|
351
|
+
}, []), /* @__PURE__ */ h(D.Provider, { value: o, children: /* @__PURE__ */ h(V, { scheme: o.scheme, path: [] }) })), S = (o) => {
|
|
352
352
|
try {
|
|
353
|
-
|
|
354
|
-
} catch (
|
|
355
|
-
return
|
|
353
|
+
o();
|
|
354
|
+
} catch (r) {
|
|
355
|
+
return r && typeof r == "string" ? {
|
|
356
356
|
error: !0,
|
|
357
|
-
messages: [
|
|
358
|
-
} :
|
|
357
|
+
messages: [r]
|
|
358
|
+
} : r instanceof Array && r.every((e) => e && typeof e == "string") ? {
|
|
359
359
|
error: !0,
|
|
360
|
-
messages:
|
|
360
|
+
messages: r
|
|
361
361
|
} : {
|
|
362
362
|
error: !0
|
|
363
363
|
};
|
|
364
364
|
}
|
|
365
|
-
}, X = (
|
|
366
|
-
const s =
|
|
365
|
+
}, X = (o) => (r, e) => {
|
|
366
|
+
const s = o.getRequireCheck(e), { $rules: t = {}, ...l } = e, { validate: g, required: x } = t;
|
|
367
367
|
return {
|
|
368
368
|
type: "form",
|
|
369
|
-
name:
|
|
370
|
-
defaultValue:
|
|
371
|
-
Form:
|
|
369
|
+
name: r,
|
|
370
|
+
defaultValue: o.defaultValue,
|
|
371
|
+
Form: o.getForm(l),
|
|
372
372
|
validate: (y) => {
|
|
373
373
|
if (x) {
|
|
374
|
-
const v =
|
|
374
|
+
const v = S(() => s(y));
|
|
375
375
|
if (v)
|
|
376
376
|
return v;
|
|
377
|
-
if (
|
|
378
|
-
const d =
|
|
377
|
+
if (g) {
|
|
378
|
+
const d = S(() => g(y));
|
|
379
379
|
if (d)
|
|
380
380
|
return d;
|
|
381
381
|
}
|
|
382
382
|
return;
|
|
383
383
|
}
|
|
384
|
-
if (
|
|
385
|
-
const d =
|
|
384
|
+
if (g && !S(() => s(y))) {
|
|
385
|
+
const d = S(() => g(y));
|
|
386
386
|
if (d)
|
|
387
387
|
return d;
|
|
388
388
|
}
|
|
389
389
|
}
|
|
390
390
|
};
|
|
391
|
-
}, Y = (
|
|
391
|
+
}, Y = (o) => (r) => (...e) => ({
|
|
392
392
|
type: "layout",
|
|
393
|
-
Layout:
|
|
394
|
-
childs:
|
|
393
|
+
Layout: o(r),
|
|
394
|
+
childs: e
|
|
395
395
|
}), Z = ({
|
|
396
|
-
getItems:
|
|
397
|
-
getController:
|
|
396
|
+
getItems: o,
|
|
397
|
+
getController: r
|
|
398
398
|
}) => ({
|
|
399
399
|
type: "extra",
|
|
400
|
-
items:
|
|
401
|
-
getController:
|
|
402
|
-
}), _ = (
|
|
400
|
+
items: o((e) => (s) => ({ type: "registry", name: e, getForm: s })),
|
|
401
|
+
getController: r
|
|
402
|
+
}), _ = (o) => (...r) => ({
|
|
403
403
|
type: "context",
|
|
404
|
-
context:
|
|
405
|
-
childs:
|
|
406
|
-
}), k = (
|
|
404
|
+
context: o,
|
|
405
|
+
childs: r
|
|
406
|
+
}), k = (o, r) => (...e) => ({
|
|
407
407
|
type: "condition",
|
|
408
|
-
depended:
|
|
409
|
-
canActivate:
|
|
408
|
+
depended: o,
|
|
409
|
+
canActivate: r.canActivate,
|
|
410
|
+
childs: e
|
|
411
|
+
}), I = ({ hidden: o }) => (...r) => ({
|
|
412
|
+
type: "visability",
|
|
413
|
+
hidden: o ?? !1,
|
|
410
414
|
childs: r
|
|
411
415
|
});
|
|
412
416
|
export {
|
|
413
417
|
k as Condition,
|
|
414
418
|
_ as Context,
|
|
415
419
|
W as FormLayout,
|
|
420
|
+
I as Visablility,
|
|
416
421
|
Z as createExtraForm,
|
|
417
422
|
X as createForm,
|
|
418
423
|
Y as createLayout,
|
|
@@ -3,3 +3,6 @@ export declare const Context: <N extends string>(context: N) => <T extends Schem
|
|
|
3
3
|
export declare const Condition: (depended: string, props: {
|
|
4
4
|
canActivate: (value: any) => boolean;
|
|
5
5
|
}) => <T extends SchemeItems.All[]>(...childs: T) => SchemeItems.Condition<T>;
|
|
6
|
+
export declare const Visablility: ({ hidden }: {
|
|
7
|
+
hidden?: boolean;
|
|
8
|
+
}) => <T extends SchemeItems.All[]>(...childs: T) => SchemeItems.Visablility<T>;
|
package/dist/core/types.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export interface FieldError {
|
|
|
5
5
|
messages?: string[];
|
|
6
6
|
}
|
|
7
7
|
export declare namespace SchemeItems {
|
|
8
|
-
type All = Form | Layout | Context | Condition | Extra;
|
|
8
|
+
type All = Form | Layout | Context | Condition | Extra | Visablility;
|
|
9
9
|
interface Form<N extends string = string, V extends any = any, P extends any = any> {
|
|
10
10
|
type: 'form';
|
|
11
11
|
name: N;
|
|
@@ -39,4 +39,9 @@ export declare namespace SchemeItems {
|
|
|
39
39
|
canActivate: (value: any) => boolean;
|
|
40
40
|
childs: T;
|
|
41
41
|
}
|
|
42
|
+
interface Visablility<T extends All[] = All[]> {
|
|
43
|
+
type: 'visability';
|
|
44
|
+
hidden: boolean;
|
|
45
|
+
childs: T;
|
|
46
|
+
}
|
|
42
47
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { useValue, createUseValue } from './useValue';
|
|
|
3
3
|
export { createForm } from './core/builders/create-form';
|
|
4
4
|
export { createLayout } from './core/builders/create-layout';
|
|
5
5
|
export { createExtraForm } from './core/builders/create-extra-form';
|
|
6
|
-
export
|
|
6
|
+
export * from './core/builders/syntax';
|
|
7
7
|
export type { FieldError } from './core/types';
|
|
8
8
|
export type { FormManager } from './manager/manager';
|
|
9
9
|
export type { FormControl } from './core/builders/create-form';
|