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