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