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