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