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