@companix/formkit 0.0.4 → 0.0.6
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/README.md +29 -15
- package/dist/SchemeBuilder.d.ts +2 -2
- package/dist/bundle.es.js +144 -142
- package/dist/index.d.ts +2 -1
- package/dist/manager/manager.d.ts +1 -0
- package/dist/useForm.d.ts +8 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,26 +1,39 @@
|
|
|
1
|
-
|
|
1
|
+
## Create form primitives
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
```tsx
|
|
4
|
+
const SelectForm = (name: string) => {
|
|
5
|
+
// select form code
|
|
6
|
+
}
|
|
7
|
+
const InputForm = (name: string) => {
|
|
8
|
+
// input form code
|
|
9
|
+
}
|
|
10
|
+
```
|
|
7
11
|
|
|
8
|
-
|
|
12
|
+
## Create layouts
|
|
9
13
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
14
|
+
```tsx
|
|
15
|
+
export const Label = createLayout((label: React.ReactNode) => {
|
|
16
|
+
return ({ children }) => {
|
|
17
|
+
return <FormGroup label={label}>{children}</FormGroup>
|
|
18
|
+
}
|
|
19
|
+
})
|
|
13
20
|
|
|
14
|
-
const Double = () => {
|
|
15
|
-
return (
|
|
16
|
-
|
|
21
|
+
export const Double = createLayout(() => {
|
|
22
|
+
return ({ children }) => {
|
|
23
|
+
return <div className="form-double-primitive">{children}</div>
|
|
17
24
|
}
|
|
18
|
-
}
|
|
25
|
+
})
|
|
19
26
|
|
|
20
|
-
const Splitter = () => {
|
|
27
|
+
export const Splitter = createLayout(() => {
|
|
28
|
+
return () => {
|
|
29
|
+
return <div className="form-splitter" />
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
```
|
|
21
33
|
|
|
22
|
-
|
|
34
|
+
## Create a scheme
|
|
23
35
|
|
|
36
|
+
```ts
|
|
24
37
|
const scheme = [
|
|
25
38
|
Label('Имя')(
|
|
26
39
|
SelectForm('name', {
|
|
@@ -42,3 +55,4 @@ const scheme = [
|
|
|
42
55
|
)
|
|
43
56
|
)
|
|
44
57
|
]
|
|
58
|
+
```
|
package/dist/SchemeBuilder.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ import { SchemeItems } from './core/types';
|
|
|
2
2
|
export interface SchemeBuilderProps {
|
|
3
3
|
scheme: SchemeItems.All[];
|
|
4
4
|
path: string[];
|
|
5
|
+
className?: string;
|
|
5
6
|
}
|
|
6
|
-
declare const SchemeBuilder: ({ scheme, path }: SchemeBuilderProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
-
export { SchemeBuilder };
|
|
7
|
+
export declare const SchemeBuilder: ({ scheme, path, className }: SchemeBuilderProps) => import("react/jsx-runtime").JSX.Element;
|
package/dist/bundle.es.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as N, useState as
|
|
3
|
-
import
|
|
4
|
-
const j = N({}), M = (
|
|
5
|
-
const [, r] =
|
|
1
|
+
import { jsx as h, Fragment as B, jsxs as T } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as N, useState as q, useContext as L, useEffect as D, useMemo as A, useCallback as S, useRef as P } from "react";
|
|
3
|
+
import R from "fast-deep-equal";
|
|
4
|
+
const j = N({}), M = (s) => {
|
|
5
|
+
const [, r] = q([]), o = L(j), t = o.getForm(s);
|
|
6
6
|
return D(() => {
|
|
7
|
-
const { unsubscribe:
|
|
7
|
+
const { unsubscribe: e } = o.subscribeToForm(s, () => {
|
|
8
8
|
r([]);
|
|
9
9
|
});
|
|
10
10
|
return () => {
|
|
11
|
-
|
|
11
|
+
e();
|
|
12
12
|
};
|
|
13
|
-
}, []),
|
|
14
|
-
}, _ = ({ canActivate:
|
|
15
|
-
const
|
|
16
|
-
return
|
|
17
|
-
}, z = ({ item: { Form:
|
|
18
|
-
const [,
|
|
19
|
-
|
|
13
|
+
}, []), t?.value;
|
|
14
|
+
}, _ = ({ canActivate: s, name: r, children: o }) => {
|
|
15
|
+
const t = M(r);
|
|
16
|
+
return s(t) ? /* @__PURE__ */ h(B, { children: o }) : null;
|
|
17
|
+
}, z = ({ item: { Form: s }, name: r }) => {
|
|
18
|
+
const [, o] = q([]), t = L(j), { unregistry: e } = A(() => t.registry(r, () => {
|
|
19
|
+
o([]);
|
|
20
20
|
}), []), l = S(
|
|
21
21
|
(d) => {
|
|
22
22
|
if (d && d.focus) {
|
|
23
|
-
const v =
|
|
23
|
+
const v = t.getForm(r);
|
|
24
24
|
v.focus = () => {
|
|
25
25
|
d.focus();
|
|
26
26
|
};
|
|
@@ -29,16 +29,16 @@ const j = N({}), M = (o) => {
|
|
|
29
29
|
[r]
|
|
30
30
|
);
|
|
31
31
|
D(() => () => {
|
|
32
|
-
|
|
32
|
+
e();
|
|
33
33
|
}, []);
|
|
34
|
-
const { value: y, error: b } =
|
|
35
|
-
return /* @__PURE__ */
|
|
36
|
-
|
|
34
|
+
const { value: y, error: b } = t.getForm(r);
|
|
35
|
+
return /* @__PURE__ */ h(
|
|
36
|
+
s,
|
|
37
37
|
{
|
|
38
38
|
field: {
|
|
39
39
|
value: y,
|
|
40
40
|
onChange: (d) => {
|
|
41
|
-
|
|
41
|
+
t.onChange(r, d);
|
|
42
42
|
},
|
|
43
43
|
onBlur: () => {
|
|
44
44
|
},
|
|
@@ -46,24 +46,24 @@ const j = N({}), M = (o) => {
|
|
|
46
46
|
},
|
|
47
47
|
isDirty: !1,
|
|
48
48
|
error: b,
|
|
49
|
-
disabled:
|
|
49
|
+
disabled: t.disabled
|
|
50
50
|
}
|
|
51
51
|
);
|
|
52
|
-
}, G = ({ item:
|
|
53
|
-
const { getController:
|
|
52
|
+
}, G = ({ item: s, path: r }) => {
|
|
53
|
+
const { getController: o, items: t } = s, e = L(j), l = A(() => {
|
|
54
54
|
const i = {};
|
|
55
|
-
return
|
|
55
|
+
return t.forEach(({ name: f, getForm: F }) => {
|
|
56
56
|
i[f] = F(f, () => x(f));
|
|
57
57
|
}), i;
|
|
58
58
|
}, []), y = S(() => {
|
|
59
59
|
const i = [];
|
|
60
|
-
return
|
|
61
|
-
|
|
60
|
+
return t.forEach(({ name: f }) => {
|
|
61
|
+
e.getForm([...r, f].join(".")).value !== void 0 && i.push(f);
|
|
62
62
|
}), i;
|
|
63
|
-
}, []), b = A(() => y(), []), [d, v] =
|
|
63
|
+
}, []), b = A(() => y(), []), [d, v] = q(b);
|
|
64
64
|
D(() => {
|
|
65
|
-
const { unregistry: i } =
|
|
66
|
-
|
|
65
|
+
const { unregistry: i } = e.registryExtraForm(
|
|
66
|
+
t.map(({ name: f }) => [...r, f].join(".")),
|
|
67
67
|
() => {
|
|
68
68
|
v(y());
|
|
69
69
|
}
|
|
@@ -80,92 +80,92 @@ const j = N({}), M = (o) => {
|
|
|
80
80
|
), x = S((i) => {
|
|
81
81
|
v((f) => f.filter((F) => F !== i));
|
|
82
82
|
}, []);
|
|
83
|
-
return /* @__PURE__ */ T(
|
|
83
|
+
return /* @__PURE__ */ T(B, { children: [
|
|
84
84
|
d.map((i) => {
|
|
85
85
|
const f = l[i];
|
|
86
|
-
return /* @__PURE__ */
|
|
86
|
+
return /* @__PURE__ */ h(V, { path: r, scheme: [f] }, `param-form--${i}`);
|
|
87
87
|
}),
|
|
88
|
-
|
|
88
|
+
o(C, d)
|
|
89
89
|
] });
|
|
90
|
-
}, V = ({ scheme:
|
|
90
|
+
}, V = ({ scheme: s, path: r, className: o }) => /* @__PURE__ */ h("div", { className: o, children: s.map((t, e) => t.type === "layout" ? /* @__PURE__ */ h(t.Layout, { children: /* @__PURE__ */ h(V, { path: r, scheme: t.childs }) }, `layout-form--${e}-${r.length}`) : t.type === "context" ? /* @__PURE__ */ h(
|
|
91
91
|
V,
|
|
92
92
|
{
|
|
93
|
-
path: [...r,
|
|
94
|
-
scheme:
|
|
93
|
+
path: [...r, t.context],
|
|
94
|
+
scheme: t.childs
|
|
95
95
|
},
|
|
96
|
-
`context-form--${
|
|
97
|
-
) :
|
|
96
|
+
`context-form--${e}-${t.context}-${r.length}`
|
|
97
|
+
) : t.type === "condition" ? /* @__PURE__ */ h(
|
|
98
98
|
_,
|
|
99
99
|
{
|
|
100
|
-
name:
|
|
101
|
-
canActivate:
|
|
102
|
-
children: /* @__PURE__ */
|
|
100
|
+
name: t.depended,
|
|
101
|
+
canActivate: t.canActivate,
|
|
102
|
+
children: /* @__PURE__ */ h(V, { path: r, scheme: t.childs })
|
|
103
103
|
},
|
|
104
|
-
`condition--${
|
|
105
|
-
) :
|
|
104
|
+
`condition--${e}-${t.depended}-${r.length}`
|
|
105
|
+
) : t.type === "extra" ? /* @__PURE__ */ h(G, { path: r, item: t }, `partial-item--${e}-${r.length}`) : /* @__PURE__ */ h(
|
|
106
106
|
z,
|
|
107
107
|
{
|
|
108
|
-
name: [...r,
|
|
109
|
-
item:
|
|
108
|
+
name: [...r, t.name].join("."),
|
|
109
|
+
item: t
|
|
110
110
|
},
|
|
111
|
-
`form-item--${
|
|
112
|
-
)) }), m = (
|
|
113
|
-
|
|
114
|
-
if (
|
|
115
|
-
m(
|
|
111
|
+
`form-item--${e}-${t.name}-${r.length}`
|
|
112
|
+
)) }), m = (s, r, o, t) => {
|
|
113
|
+
s.forEach((e) => {
|
|
114
|
+
if (e.type === "form" && t(e, [...r, e.name].join("."), o[e.name]), e.type === "context") {
|
|
115
|
+
m(e.childs, [...r, e.context], o[e.context] ?? {}, t);
|
|
116
116
|
return;
|
|
117
117
|
}
|
|
118
|
-
if (
|
|
119
|
-
m(
|
|
118
|
+
if (e.type === "layout" || e.type === "condition") {
|
|
119
|
+
m(e.childs, r, o, t);
|
|
120
120
|
return;
|
|
121
121
|
}
|
|
122
|
-
|
|
122
|
+
e.type === "extra" && e.items.forEach(({ getForm: l, name: y }) => {
|
|
123
123
|
m([l(y, () => {
|
|
124
|
-
})], r,
|
|
124
|
+
})], r, o, t);
|
|
125
125
|
});
|
|
126
126
|
});
|
|
127
|
-
}, E = ({ scheme:
|
|
128
|
-
|
|
129
|
-
if (
|
|
130
|
-
const l = [...
|
|
131
|
-
|
|
127
|
+
}, E = ({ scheme: s, values: r, path: o, forms: t }) => {
|
|
128
|
+
s.forEach((e) => {
|
|
129
|
+
if (e.type === "form") {
|
|
130
|
+
const l = [...o, e.name].join(".");
|
|
131
|
+
t[l].value !== void 0 && (r[e.name] = t[l].value);
|
|
132
132
|
}
|
|
133
|
-
if (
|
|
134
|
-
r[
|
|
135
|
-
scheme:
|
|
136
|
-
path: [...
|
|
137
|
-
values: r[
|
|
138
|
-
forms:
|
|
133
|
+
if (e.type === "context") {
|
|
134
|
+
r[e.context] = {}, E({
|
|
135
|
+
scheme: e.childs,
|
|
136
|
+
path: [...o, e.context],
|
|
137
|
+
values: r[e.context],
|
|
138
|
+
forms: t
|
|
139
139
|
});
|
|
140
140
|
return;
|
|
141
141
|
}
|
|
142
|
-
if (
|
|
143
|
-
E({ scheme:
|
|
142
|
+
if (e.type === "layout") {
|
|
143
|
+
E({ scheme: e.childs, path: o, values: r, forms: t });
|
|
144
144
|
return;
|
|
145
145
|
}
|
|
146
|
-
if (
|
|
147
|
-
const l =
|
|
148
|
-
if (
|
|
149
|
-
E({ scheme:
|
|
146
|
+
if (e.type === "condition") {
|
|
147
|
+
const l = t[e.depended]?.value;
|
|
148
|
+
if (e.canActivate(l)) {
|
|
149
|
+
E({ scheme: e.childs, path: o, values: r, forms: t });
|
|
150
150
|
return;
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
-
|
|
153
|
+
e.type === "extra" && e.items.forEach(({ getForm: l, name: y }) => {
|
|
154
154
|
E({ scheme: [l(y, () => {
|
|
155
|
-
})], path:
|
|
155
|
+
})], path: o, values: r, forms: t });
|
|
156
156
|
});
|
|
157
157
|
});
|
|
158
|
-
},
|
|
159
|
-
const
|
|
160
|
-
return E({ scheme:
|
|
161
|
-
}, H = (
|
|
162
|
-
const { onSubmit:
|
|
158
|
+
}, w = (s, r) => {
|
|
159
|
+
const o = {};
|
|
160
|
+
return E({ scheme: s, path: [], values: o, forms: r }), o;
|
|
161
|
+
}, H = (s, r) => {
|
|
162
|
+
const { onSubmit: o, onEqual: t, disabled: e, onDirty: l, onFormDirty: y, onChangeEvent: b, defaultValues: d } = r;
|
|
163
163
|
let v = !1, C = !1, x = 0;
|
|
164
164
|
const i = {}, f = {
|
|
165
165
|
subscribers: [],
|
|
166
166
|
names: {}
|
|
167
167
|
};
|
|
168
|
-
m(
|
|
168
|
+
m(s, [], d ?? {}, (n, c, u) => {
|
|
169
169
|
i[c] = {
|
|
170
170
|
error: null,
|
|
171
171
|
isDirty: !1,
|
|
@@ -182,7 +182,8 @@ const j = N({}), M = (o) => {
|
|
|
182
182
|
l?.({ name: n, isDirty: c }), c && x === 0 && y?.(!0), !c && x === 1 && y?.(!1), x += c ? 1 : -1;
|
|
183
183
|
};
|
|
184
184
|
return {
|
|
185
|
-
|
|
185
|
+
scheme: s,
|
|
186
|
+
disabled: e,
|
|
186
187
|
activate() {
|
|
187
188
|
v = !0;
|
|
188
189
|
},
|
|
@@ -205,32 +206,32 @@ const j = N({}), M = (o) => {
|
|
|
205
206
|
u && u.value !== c && this.onChange(n, c);
|
|
206
207
|
},
|
|
207
208
|
getValues() {
|
|
208
|
-
return
|
|
209
|
+
return w(s, i);
|
|
209
210
|
},
|
|
210
211
|
async handleSubmit() {
|
|
211
|
-
if (
|
|
212
|
+
if (e)
|
|
212
213
|
return;
|
|
213
214
|
C = !0;
|
|
214
215
|
let n = !1, c = !1;
|
|
215
216
|
for (const u in i) {
|
|
216
217
|
const a = i[u];
|
|
217
218
|
if (a.value !== void 0) {
|
|
218
|
-
const
|
|
219
|
-
|
|
219
|
+
const g = a.validate(a.value);
|
|
220
|
+
g && (c = !0, a.error = g, a.rerender(), !n && a.focus && (a.focus(), n = !0));
|
|
220
221
|
}
|
|
221
222
|
}
|
|
222
223
|
if (!c) {
|
|
223
224
|
if (x === 0) {
|
|
224
|
-
|
|
225
|
+
t?.();
|
|
225
226
|
return;
|
|
226
227
|
}
|
|
227
|
-
const u =
|
|
228
|
-
await
|
|
229
|
-
setError: (a,
|
|
228
|
+
const u = w(s, i);
|
|
229
|
+
await o(u, {
|
|
230
|
+
setError: (a, g) => {
|
|
230
231
|
const p = this.getForm(a);
|
|
231
232
|
p.error = {
|
|
232
233
|
error: !0,
|
|
233
|
-
messages: [
|
|
234
|
+
messages: [g.message]
|
|
234
235
|
}, p.rerender();
|
|
235
236
|
}
|
|
236
237
|
});
|
|
@@ -238,14 +239,14 @@ const j = N({}), M = (o) => {
|
|
|
238
239
|
},
|
|
239
240
|
reset(n) {
|
|
240
241
|
const c = [];
|
|
241
|
-
m(
|
|
242
|
-
if (
|
|
242
|
+
m(s, [], n, (u, a, g) => {
|
|
243
|
+
if (g === void 0 && i[a].value === void 0)
|
|
243
244
|
return;
|
|
244
|
-
if (f.names[a] &&
|
|
245
|
-
c.push(a), i[a].value =
|
|
245
|
+
if (f.names[a] && g === void 0) {
|
|
246
|
+
c.push(a), i[a].value = g;
|
|
246
247
|
return;
|
|
247
248
|
}
|
|
248
|
-
const p =
|
|
249
|
+
const p = g ?? u.defaultValue;
|
|
249
250
|
i[a].value !== p && (c.push(a), this.onChange(a, p));
|
|
250
251
|
}), c.some((u) => f.names[u]) && f.subscribers.forEach(({ callback: u }) => {
|
|
251
252
|
u();
|
|
@@ -257,7 +258,7 @@ const j = N({}), M = (o) => {
|
|
|
257
258
|
if (i[n].rerender = () => {
|
|
258
259
|
}, i[n].focus = void 0, v) {
|
|
259
260
|
i[n].value = void 0;
|
|
260
|
-
const u = !
|
|
261
|
+
const u = !R(i[n].defaultValue, i[n].initValue);
|
|
261
262
|
i[n].isDirty !== u && F(n, u), i[n].isDirty = u;
|
|
262
263
|
}
|
|
263
264
|
}
|
|
@@ -270,7 +271,7 @@ const j = N({}), M = (o) => {
|
|
|
270
271
|
const u = { callback: c }, a = this.getForm(n);
|
|
271
272
|
return a.subscribers.push(u), {
|
|
272
273
|
unsubscribe: () => {
|
|
273
|
-
a.subscribers = a.subscribers.filter((
|
|
274
|
+
a.subscribers = a.subscribers.filter((g) => g !== u);
|
|
274
275
|
}
|
|
275
276
|
};
|
|
276
277
|
},
|
|
@@ -285,110 +286,111 @@ const j = N({}), M = (o) => {
|
|
|
285
286
|
};
|
|
286
287
|
},
|
|
287
288
|
onChange(n, c) {
|
|
288
|
-
const u = this.getForm(n), a = !
|
|
289
|
-
u.isDirty !== a && F(n, a), u.isDirty = a, b?.({ name: n, value: c }), (u.error || C) && (u.error = u.validate(c) || null), u.value = c, u.rerender(), u.subscribers.forEach(({ callback:
|
|
290
|
-
|
|
289
|
+
const u = this.getForm(n), a = !R(c, u.initValue);
|
|
290
|
+
u.isDirty !== a && F(n, a), u.isDirty = a, b?.({ name: n, value: c }), (u.error || C) && (u.error = u.validate(c) || null), u.value = c, u.rerender(), u.subscribers.forEach(({ callback: g }) => {
|
|
291
|
+
g();
|
|
291
292
|
});
|
|
292
293
|
}
|
|
293
294
|
};
|
|
294
|
-
},
|
|
295
|
-
const
|
|
296
|
-
|
|
297
|
-
const
|
|
295
|
+
}, Q = (s, r) => {
|
|
296
|
+
const o = P(null);
|
|
297
|
+
o.current === null && (o.current = H(s, r));
|
|
298
|
+
const t = o.current;
|
|
298
299
|
return {
|
|
299
|
-
useValue: (
|
|
300
|
-
reset: (
|
|
301
|
-
|
|
300
|
+
useValue: (e) => M(e),
|
|
301
|
+
reset: (e) => {
|
|
302
|
+
t.reset(e);
|
|
302
303
|
},
|
|
303
|
-
setFocus: (
|
|
304
|
-
|
|
304
|
+
setFocus: (e) => {
|
|
305
|
+
t.setFocus(e);
|
|
305
306
|
},
|
|
306
|
-
setError: (
|
|
307
|
-
|
|
307
|
+
setError: (e, l) => {
|
|
308
|
+
t.setError(e, l);
|
|
308
309
|
},
|
|
309
|
-
setValue: (
|
|
310
|
-
|
|
310
|
+
setValue: (e, l) => {
|
|
311
|
+
t.setValue(e, l);
|
|
311
312
|
},
|
|
312
|
-
getValues: () =>
|
|
313
|
+
getValues: () => t.getValues(),
|
|
313
314
|
handleSubmit: async () => {
|
|
314
|
-
await
|
|
315
|
+
await t.handleSubmit();
|
|
315
316
|
},
|
|
316
|
-
|
|
317
|
+
manager: t
|
|
317
318
|
};
|
|
318
|
-
},
|
|
319
|
-
|
|
319
|
+
}, U = ({ manager: s, className: r }) => (A(() => {
|
|
320
|
+
s.activate();
|
|
320
321
|
}, []), D(() => () => {
|
|
321
|
-
|
|
322
|
-
}, []), /* @__PURE__ */
|
|
322
|
+
s.disactivate();
|
|
323
|
+
}, []), /* @__PURE__ */ h(j.Provider, { value: s, children: /* @__PURE__ */ h(V, { className: r, scheme: s.scheme, path: [] }) })), $ = (s) => {
|
|
323
324
|
try {
|
|
324
|
-
|
|
325
|
+
s();
|
|
325
326
|
} catch (r) {
|
|
326
327
|
return r && typeof r == "string" ? {
|
|
327
328
|
error: !0,
|
|
328
329
|
messages: [r]
|
|
329
|
-
} : r instanceof Array && r.every((
|
|
330
|
+
} : r instanceof Array && r.every((o) => o && typeof o == "string") ? {
|
|
330
331
|
error: !0,
|
|
331
332
|
messages: r
|
|
332
333
|
} : {
|
|
333
334
|
error: !0
|
|
334
335
|
};
|
|
335
336
|
}
|
|
336
|
-
}, W = (
|
|
337
|
-
const
|
|
337
|
+
}, W = (s) => (r, o) => {
|
|
338
|
+
const t = s.getRequireCheck(o), { validate: e, required: l } = o.$rules ?? {};
|
|
338
339
|
return {
|
|
339
340
|
type: "form",
|
|
340
341
|
name: r,
|
|
341
|
-
defaultValue:
|
|
342
|
-
Form:
|
|
342
|
+
defaultValue: s.defaultValue,
|
|
343
|
+
Form: s.getForm(o),
|
|
343
344
|
validate: (y) => {
|
|
344
345
|
if (l) {
|
|
345
|
-
const b = $(() =>
|
|
346
|
+
const b = $(() => t(y));
|
|
346
347
|
if (b)
|
|
347
348
|
return b;
|
|
348
|
-
if (
|
|
349
|
-
const d = $(() =>
|
|
349
|
+
if (e) {
|
|
350
|
+
const d = $(() => e(y));
|
|
350
351
|
if (d)
|
|
351
352
|
return d;
|
|
352
353
|
}
|
|
353
354
|
return;
|
|
354
355
|
}
|
|
355
|
-
if (
|
|
356
|
-
const d = $(() =>
|
|
356
|
+
if (e && !$(() => t(y))) {
|
|
357
|
+
const d = $(() => e(y));
|
|
357
358
|
if (d)
|
|
358
359
|
return d;
|
|
359
360
|
}
|
|
360
361
|
}
|
|
361
362
|
};
|
|
362
|
-
}, X = (
|
|
363
|
+
}, X = (s) => (r) => (...o) => ({
|
|
363
364
|
type: "layout",
|
|
364
|
-
Layout:
|
|
365
|
-
childs:
|
|
365
|
+
Layout: s(r),
|
|
366
|
+
childs: o
|
|
366
367
|
}), Y = ({
|
|
367
|
-
getItems:
|
|
368
|
+
getItems: s,
|
|
368
369
|
getController: r
|
|
369
370
|
}) => ({
|
|
370
371
|
type: "extra",
|
|
371
|
-
items:
|
|
372
|
+
items: s((o) => (t) => ({
|
|
372
373
|
type: "registry",
|
|
373
|
-
name:
|
|
374
|
-
getForm:
|
|
374
|
+
name: o,
|
|
375
|
+
getForm: t
|
|
375
376
|
})),
|
|
376
377
|
getController: r
|
|
377
|
-
}), Z = (
|
|
378
|
+
}), Z = (s) => (...r) => ({
|
|
378
379
|
type: "context",
|
|
379
|
-
context:
|
|
380
|
+
context: s,
|
|
380
381
|
childs: r
|
|
381
|
-
}), k = (
|
|
382
|
+
}), k = (s, r) => (...o) => ({
|
|
382
383
|
type: "condition",
|
|
383
|
-
depended:
|
|
384
|
+
depended: s,
|
|
384
385
|
canActivate: r.canActivate,
|
|
385
|
-
childs:
|
|
386
|
+
childs: o
|
|
386
387
|
});
|
|
387
388
|
export {
|
|
388
389
|
k as Condition,
|
|
389
390
|
Z as Context,
|
|
391
|
+
U as FormLayout,
|
|
390
392
|
Y as createExtraForm,
|
|
391
393
|
W as createForm,
|
|
392
394
|
X as createLayout,
|
|
393
|
-
|
|
395
|
+
Q as useForm
|
|
394
396
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export { useForm } from './useForm';
|
|
1
|
+
export { useForm, FormLayout } from './useForm';
|
|
2
2
|
export { createForm } from './core/builders/create-form';
|
|
3
3
|
export { createLayout } from './core/builders/create-layout';
|
|
4
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
|
+
export type { FormManager } from './manager/manager';
|
package/dist/useForm.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ExtractValues, ExtractFlatValues } from './core/extract';
|
|
2
2
|
import { SchemeItems } from './core/types';
|
|
3
|
+
import { FormManager } from './manager/manager';
|
|
3
4
|
import { DeepPartial, FieldValues } from './types';
|
|
4
5
|
export type Copy<T> = {
|
|
5
6
|
[K in keyof T]: T[K];
|
|
@@ -44,7 +45,7 @@ declare const useDynamicForm: (scheme: SchemeItems.All[], opts: MainOptions<Fiel
|
|
|
44
45
|
[x: string]: any;
|
|
45
46
|
};
|
|
46
47
|
handleSubmit: () => Promise<void>;
|
|
47
|
-
|
|
48
|
+
manager: FormManager<FieldValues, FieldValues>;
|
|
48
49
|
};
|
|
49
50
|
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>) => {
|
|
50
51
|
useValue: <K extends keyof FlattenValues>(name: K) => FlattenValues[K];
|
|
@@ -56,6 +57,11 @@ declare const useForm: <Items extends SchemeItems.All[], Values extends ExtractV
|
|
|
56
57
|
setValue: <K extends keyof FlattenValues>(name: K, value: FlattenValues[K]) => void;
|
|
57
58
|
getValues: () => DeepPartial<Cloned>;
|
|
58
59
|
handleSubmit: () => Promise<void>;
|
|
59
|
-
|
|
60
|
+
manager: FormManager<FlattenValues, Cloned>;
|
|
60
61
|
};
|
|
62
|
+
interface Props {
|
|
63
|
+
className?: string;
|
|
64
|
+
manager: FormManager<any, any>;
|
|
65
|
+
}
|
|
66
|
+
export declare const FormLayout: ({ manager, className }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
61
67
|
export { useForm, useDynamicForm };
|