@companix/formkit 0.0.17 → 0.0.19
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 +165 -164
- package/dist/manager/manager.d.ts +2 -4
- package/dist/useForm.d.ts +4 -0
- package/package.json +2 -2
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: b, error: m } = s.getForm(e);
|
|
43
|
+
return /* @__PURE__ */ h(
|
|
44
|
+
n,
|
|
45
45
|
{
|
|
46
46
|
field: {
|
|
47
|
-
value:
|
|
47
|
+
value: b,
|
|
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[g] =
|
|
63
|
+
return s.forEach(({ name: g, getForm: o }) => {
|
|
64
|
+
l[g] = o(g, () => a(g));
|
|
65
65
|
}), l;
|
|
66
|
-
}, []),
|
|
66
|
+
}, []), b = A(() => {
|
|
67
67
|
const l = [];
|
|
68
|
-
return
|
|
68
|
+
return s.forEach(({ name: g }) => {
|
|
69
69
|
t.getForm([...e, g].join(".")).value !== void 0 && l.push(g);
|
|
70
70
|
}), l;
|
|
71
|
-
}, []),
|
|
71
|
+
}, []), m = p(() => b(), []), [y, v] = w(m);
|
|
72
72
|
S(() => {
|
|
73
73
|
const { unregistry: l } = t.registryExtraForm(
|
|
74
|
-
|
|
74
|
+
s.map(({ name: g }) => [...e, g].join(".")),
|
|
75
75
|
() => {
|
|
76
|
-
v(
|
|
76
|
+
v(b());
|
|
77
77
|
}
|
|
78
78
|
);
|
|
79
79
|
return () => {
|
|
@@ -86,88 +86,88 @@ const D = P({}), q = (o) => {
|
|
|
86
86
|
},
|
|
87
87
|
[y]
|
|
88
88
|
), a = A((l) => {
|
|
89
|
-
v((g) => g.filter((
|
|
89
|
+
v((g) => g.filter((o) => o !== l));
|
|
90
90
|
}, []);
|
|
91
|
-
return /* @__PURE__ */
|
|
91
|
+
return /* @__PURE__ */ B(j, { children: [
|
|
92
92
|
y.map((l) => {
|
|
93
93
|
const g = f[l];
|
|
94
|
-
return /* @__PURE__ */
|
|
94
|
+
return /* @__PURE__ */ h(C, { path: e, scheme: [g] }, `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: b }) => {
|
|
131
|
+
V([f(b, () => {
|
|
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: b }) => {
|
|
162
|
+
E({ scheme: [f(b, () => {
|
|
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: b, 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(
|
|
179
|
-
a[
|
|
178
|
+
V(n, [], y ?? {}, (o, i, u) => {
|
|
179
|
+
a[i] = {
|
|
180
180
|
error: null,
|
|
181
181
|
isDirty: !1,
|
|
182
|
-
value:
|
|
182
|
+
value: u,
|
|
183
183
|
// текущее (динамическое) состояние поля. Значение равно переданному дефолтному, либо: определяется как дефолтное значение компонента формы в момент его монтирования, а до этого - undefined.
|
|
184
|
-
startValue:
|
|
184
|
+
startValue: u ?? 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 g = (
|
|
195
|
-
f?.({ name:
|
|
194
|
+
const g = (o, i) => {
|
|
195
|
+
f?.({ name: o, isDirty: i }), i && d.dirtyCount === 0 && b?.(!0), !i && d.dirtyCount === 1 && b?.(!1), d.dirtyCount += i ? 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,148 +204,149 @@ const D = P({}), q = (o) => {
|
|
|
204
204
|
disactivate() {
|
|
205
205
|
d.isActive = !1;
|
|
206
206
|
},
|
|
207
|
-
setError(
|
|
208
|
-
const
|
|
209
|
-
|
|
207
|
+
setError(o, i) {
|
|
208
|
+
const u = this.getForm(o);
|
|
209
|
+
u && (u.error = {
|
|
210
210
|
error: !0,
|
|
211
|
-
messages: [
|
|
212
|
-
},
|
|
211
|
+
messages: [i.message]
|
|
212
|
+
}, u.rerender());
|
|
213
213
|
},
|
|
214
|
-
setFocus(
|
|
215
|
-
const
|
|
216
|
-
|
|
214
|
+
setFocus(o) {
|
|
215
|
+
const i = this.getForm(o);
|
|
216
|
+
i && i.focus && i.focus();
|
|
217
217
|
},
|
|
218
|
-
setValue(
|
|
219
|
-
const
|
|
220
|
-
|
|
218
|
+
setValue(o, i) {
|
|
219
|
+
const u = this.getForm(o);
|
|
220
|
+
u && u.value !== i && this.onChange(o, i);
|
|
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
|
|
230
|
-
for (const
|
|
231
|
-
const c = a[
|
|
229
|
+
let o = !1, i = !1;
|
|
230
|
+
for (const u in a) {
|
|
231
|
+
const c = a[u];
|
|
232
232
|
if (c.value !== void 0) {
|
|
233
233
|
const F = c.validate(c.value);
|
|
234
|
-
F && (
|
|
234
|
+
F && (i = !0, c.error = F, c.rerender(), !o && c.focus && (c.focus(), o = !0));
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
|
-
if (!
|
|
237
|
+
if (!i) {
|
|
238
238
|
if (d.dirtyCount === 0) {
|
|
239
|
-
|
|
239
|
+
s?.();
|
|
240
240
|
return;
|
|
241
241
|
}
|
|
242
|
-
const
|
|
243
|
-
await v.onSubmit(
|
|
242
|
+
const u = T(n, a);
|
|
243
|
+
await v.onSubmit(u, {
|
|
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: i }) {
|
|
255
|
+
V(n, [], o, (u, 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
|
-
|
|
264
|
-
}),
|
|
265
|
-
|
|
262
|
+
const x = F ?? u.defaultValue;
|
|
263
|
+
i || (a[c].startValue = x, a[c].isDirty = !1), a[c].value !== x && this.onChange(c, x);
|
|
264
|
+
}), i || (d.dirtyCount = 0, d.isSubmitted = !1), l.subscribers.forEach(({ visualizeEvalueatedForms: u }) => {
|
|
265
|
+
u();
|
|
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, i) {
|
|
274
|
+
return a[o].rerender = i, a[o].value === void 0 && (a[o].value = a[o].defaultValue), {
|
|
275
275
|
unregistry() {
|
|
276
|
-
if (a[
|
|
277
|
-
}, a[
|
|
278
|
-
a[
|
|
279
|
-
const
|
|
280
|
-
a[
|
|
276
|
+
if (a[o].rerender = () => {
|
|
277
|
+
}, a[o].focus = void 0, d.isActive) {
|
|
278
|
+
a[o].value = void 0;
|
|
279
|
+
const u = !L(a[o].startValue, a[o].defaultValue);
|
|
280
|
+
a[o].isDirty !== u && g(o, u), a[o].isDirty = u;
|
|
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
|
|
290
|
-
return c.subscribers.push(
|
|
291
|
-
|
|
292
|
-
c.subscribers = c.subscribers.filter((F) => F !== i);
|
|
293
|
-
}
|
|
288
|
+
subscribeToForm(o, i) {
|
|
289
|
+
const u = { callback: i }, c = this.getForm(o);
|
|
290
|
+
return c.subscribers.push(u), () => {
|
|
291
|
+
c.subscribers = c.subscribers.filter((F) => F !== u);
|
|
294
292
|
};
|
|
295
293
|
},
|
|
296
|
-
registryExtraForm(
|
|
297
|
-
const
|
|
298
|
-
return
|
|
294
|
+
registryExtraForm(o, i) {
|
|
295
|
+
const u = { visualizeEvalueatedForms: i };
|
|
296
|
+
return o.forEach((c) => {
|
|
299
297
|
l.names[c] = !0;
|
|
300
|
-
}), l.subscribers.push(
|
|
298
|
+
}), l.subscribers.push(u), {
|
|
301
299
|
unregistry() {
|
|
302
|
-
l.subscribers = l.subscribers.filter((c) => c !==
|
|
300
|
+
l.subscribers = l.subscribers.filter((c) => c !== u);
|
|
303
301
|
}
|
|
304
302
|
};
|
|
305
303
|
},
|
|
306
|
-
onChange(
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
F();
|
|
304
|
+
onChange(o, i) {
|
|
305
|
+
const u = this.getForm(o), c = !L(i, u.startValue);
|
|
306
|
+
u.isDirty !== c && g(o, c), u.isDirty = c, m?.({ name: o, value: i }), (u.error || d.isSubmitted) && (u.error = u.validate(i) || null), u.value = i, u.rerender(), u.subscribers.forEach(({ callback: F }) => {
|
|
307
|
+
F(i);
|
|
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
|
-
|
|
335
|
+
getValue: (t) => s.getForm(t).value,
|
|
336
|
+
getValues: () => s.getValues(),
|
|
338
337
|
handleSubmit: async () => {
|
|
339
|
-
await
|
|
340
|
-
}
|
|
338
|
+
await s.handleSubmit();
|
|
339
|
+
},
|
|
340
|
+
// prettier-ignore
|
|
341
|
+
subscribe: (t, f) => s.subscribeToForm(t, f)
|
|
341
342
|
};
|
|
342
|
-
}, W = ({ manager:
|
|
343
|
-
|
|
343
|
+
}, W = ({ manager: n }) => (p(() => {
|
|
344
|
+
n.activate();
|
|
344
345
|
}, []), S(() => () => {
|
|
345
|
-
|
|
346
|
-
}, []), /* @__PURE__ */
|
|
346
|
+
n.disactivate();
|
|
347
|
+
}, []), /* @__PURE__ */ h(D.Provider, { value: n, children: /* @__PURE__ */ h(C, { scheme: n.scheme, path: [] }) })), $ = (n) => {
|
|
347
348
|
try {
|
|
348
|
-
|
|
349
|
+
n();
|
|
349
350
|
} catch (e) {
|
|
350
351
|
return e && typeof e == "string" ? {
|
|
351
352
|
error: !0,
|
|
@@ -357,50 +358,50 @@ const D = P({}), q = (o) => {
|
|
|
357
358
|
error: !0
|
|
358
359
|
};
|
|
359
360
|
}
|
|
360
|
-
}, X = (
|
|
361
|
-
const
|
|
361
|
+
}, X = (n) => (e, r) => {
|
|
362
|
+
const s = n.getRequireCheck(r), { $rules: t = {}, ...f } = r, { validate: b, required: m } = t;
|
|
362
363
|
return {
|
|
363
364
|
type: "form",
|
|
364
365
|
name: e,
|
|
365
|
-
defaultValue:
|
|
366
|
-
Form:
|
|
366
|
+
defaultValue: n.defaultValue,
|
|
367
|
+
Form: n.getForm(f),
|
|
367
368
|
validate: (y) => {
|
|
368
|
-
if (
|
|
369
|
-
const v = $(() =>
|
|
369
|
+
if (m) {
|
|
370
|
+
const v = $(() => s(y));
|
|
370
371
|
if (v)
|
|
371
372
|
return v;
|
|
372
|
-
if (
|
|
373
|
-
const d = $(() =>
|
|
373
|
+
if (b) {
|
|
374
|
+
const d = $(() => b(y));
|
|
374
375
|
if (d)
|
|
375
376
|
return d;
|
|
376
377
|
}
|
|
377
378
|
return;
|
|
378
379
|
}
|
|
379
|
-
if (
|
|
380
|
-
const d = $(() =>
|
|
380
|
+
if (b && !$(() => s(y))) {
|
|
381
|
+
const d = $(() => b(y));
|
|
381
382
|
if (d)
|
|
382
383
|
return d;
|
|
383
384
|
}
|
|
384
385
|
}
|
|
385
386
|
};
|
|
386
|
-
}, Y = (
|
|
387
|
+
}, Y = (n) => (e) => (...r) => ({
|
|
387
388
|
type: "layout",
|
|
388
|
-
Layout:
|
|
389
|
+
Layout: n(e),
|
|
389
390
|
childs: r
|
|
390
391
|
}), Z = ({
|
|
391
|
-
getItems:
|
|
392
|
+
getItems: n,
|
|
392
393
|
getController: e
|
|
393
394
|
}) => ({
|
|
394
395
|
type: "extra",
|
|
395
|
-
items:
|
|
396
|
+
items: n((r) => (s) => ({ type: "registry", name: r, getForm: s })),
|
|
396
397
|
getController: e
|
|
397
|
-
}), _ = (
|
|
398
|
+
}), _ = (n) => (...e) => ({
|
|
398
399
|
type: "context",
|
|
399
|
-
context:
|
|
400
|
+
context: n,
|
|
400
401
|
childs: e
|
|
401
|
-
}), k = (
|
|
402
|
+
}), k = (n, e) => (...r) => ({
|
|
402
403
|
type: "condition",
|
|
403
|
-
depended:
|
|
404
|
+
depended: n,
|
|
404
405
|
canActivate: e.canActivate,
|
|
405
406
|
childs: r
|
|
406
407
|
});
|
|
@@ -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
|
@@ -45,10 +45,12 @@ declare const useDynamicForm: (scheme: SchemeItems.All[], opts: MainOptions<Fiel
|
|
|
45
45
|
message: string;
|
|
46
46
|
}) => void;
|
|
47
47
|
setValue: <K extends string>(name: K, value: any) => void;
|
|
48
|
+
getValue: <K extends string>(name: K) => any;
|
|
48
49
|
getValues: () => {
|
|
49
50
|
[x: string]: any;
|
|
50
51
|
};
|
|
51
52
|
handleSubmit: () => Promise<void>;
|
|
53
|
+
subscribe: <K extends string>(name: K, callback: (value: any) => void) => () => void;
|
|
52
54
|
};
|
|
53
55
|
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
56
|
manager: FormManager<Values, FlattenValues, Cloned>;
|
|
@@ -60,8 +62,10 @@ declare const useForm: <Items extends SchemeItems.All[], Values extends ExtractV
|
|
|
60
62
|
message: string;
|
|
61
63
|
}) => void;
|
|
62
64
|
setValue: <K extends keyof FlattenValues>(name: K, value: FlattenValues[K]) => void;
|
|
65
|
+
getValue: <K extends keyof FlattenValues>(name: K & string) => FlattenValues[K];
|
|
63
66
|
getValues: () => DeepPartial<Cloned>;
|
|
64
67
|
handleSubmit: () => Promise<void>;
|
|
68
|
+
subscribe: <K extends keyof FlattenValues>(name: K & string, callback: (value: FlattenValues[K]) => void) => () => void;
|
|
65
69
|
};
|
|
66
70
|
interface Props {
|
|
67
71
|
manager: FormManager<any, any, any>;
|
package/package.json
CHANGED