@companix/formkit 0.0.20 → 0.0.22
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 +31 -28
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/bundle.es.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
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
|
|
2
|
+
import { createContext as M, useState as w, useContext as R, useMemo as C, useEffect as S, useCallback as A, useRef as P } from "react";
|
|
3
3
|
import L from "fast-deep-equal";
|
|
4
4
|
const D = M({}), q = (n) => {
|
|
5
5
|
const [, e] = w([]), r = R(D);
|
|
6
6
|
if (!r)
|
|
7
7
|
throw new Error("useValue cannot be used outside Form context");
|
|
8
|
-
const s =
|
|
8
|
+
const s = C(() => {
|
|
9
9
|
const t = r.getForm(n);
|
|
10
10
|
if (!t)
|
|
11
11
|
throw new Error(`form with name "${n}" doesnt exist in form`);
|
|
@@ -23,7 +23,7 @@ const D = M({}), q = (n) => {
|
|
|
23
23
|
const s = q(e);
|
|
24
24
|
return n(s) ? /* @__PURE__ */ h(j, { children: r }) : null;
|
|
25
25
|
}, U = ({ item: { Form: n }, name: e }) => {
|
|
26
|
-
const [, r] = w([]), s = R(D), { unregistry: t } =
|
|
26
|
+
const [, r] = w([]), s = R(D), { unregistry: t } = C(() => s.registry(e, () => {
|
|
27
27
|
r([]);
|
|
28
28
|
}), []), f = A(
|
|
29
29
|
(y) => {
|
|
@@ -58,7 +58,7 @@ const D = M({}), q = (n) => {
|
|
|
58
58
|
}
|
|
59
59
|
);
|
|
60
60
|
}, z = ({ item: n, path: e }) => {
|
|
61
|
-
const { getController: r, items: s } = n, t = R(D), f =
|
|
61
|
+
const { getController: r, items: s } = n, t = R(D), f = C(() => {
|
|
62
62
|
const l = {};
|
|
63
63
|
return s.forEach(({ name: g, getForm: o }) => {
|
|
64
64
|
l[g] = o(g, () => a(g));
|
|
@@ -68,7 +68,7 @@ const D = M({}), q = (n) => {
|
|
|
68
68
|
return s.forEach(({ name: g }) => {
|
|
69
69
|
t.getForm([...e, g].join(".")).value !== void 0 && l.push(g);
|
|
70
70
|
}), l;
|
|
71
|
-
}, []), x =
|
|
71
|
+
}, []), x = C(() => b(), []), [y, v] = w(x);
|
|
72
72
|
S(() => {
|
|
73
73
|
const { unregistry: l } = t.registryExtraForm(
|
|
74
74
|
s.map(({ name: g }) => [...e, g].join(".")),
|
|
@@ -91,12 +91,12 @@ const D = M({}), q = (n) => {
|
|
|
91
91
|
return /* @__PURE__ */ B(j, { children: [
|
|
92
92
|
y.map((l) => {
|
|
93
93
|
const g = f[l];
|
|
94
|
-
return /* @__PURE__ */ h(
|
|
94
|
+
return /* @__PURE__ */ h(p, { path: e, scheme: [g] }, `param-form--${l}`);
|
|
95
95
|
}),
|
|
96
96
|
r(d, y)
|
|
97
97
|
] });
|
|
98
|
-
},
|
|
99
|
-
|
|
98
|
+
}, p = ({ scheme: n, path: e }) => /* @__PURE__ */ h(j, { children: n.map((r, s) => r.type === "layout" ? /* @__PURE__ */ h(r.Layout, { children: /* @__PURE__ */ h(p, { path: e, scheme: r.childs }) }, `layout-form--${s}-${e.length}`) : r.type === "context" ? /* @__PURE__ */ h(
|
|
99
|
+
p,
|
|
100
100
|
{
|
|
101
101
|
path: [...e, r.context],
|
|
102
102
|
scheme: r.childs
|
|
@@ -107,7 +107,7 @@ const D = M({}), q = (n) => {
|
|
|
107
107
|
{
|
|
108
108
|
name: r.depended,
|
|
109
109
|
canActivate: r.canActivate,
|
|
110
|
-
children: /* @__PURE__ */ h(
|
|
110
|
+
children: /* @__PURE__ */ h(p, { path: e, scheme: r.childs })
|
|
111
111
|
},
|
|
112
112
|
`condition--${s}-${r.depended}-${e.length}`
|
|
113
113
|
) : r.type === "extra" ? /* @__PURE__ */ h(z, { path: e, item: r }, `partial-item--${s}-${e.length}`) : /* @__PURE__ */ h(
|
|
@@ -230,8 +230,8 @@ const D = M({}), q = (n) => {
|
|
|
230
230
|
for (const u in a) {
|
|
231
231
|
const c = a[u];
|
|
232
232
|
if (c.value !== void 0) {
|
|
233
|
-
const
|
|
234
|
-
|
|
233
|
+
const m = c.validate(c.value);
|
|
234
|
+
m && (i = !0, c.error = m, c.rerender(), !o && c.focus && (c.focus(), o = !0));
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
237
|
if (!i) {
|
|
@@ -241,26 +241,28 @@ const D = M({}), q = (n) => {
|
|
|
241
241
|
}
|
|
242
242
|
const u = T(n, a);
|
|
243
243
|
await v.onSubmit(u, {
|
|
244
|
-
setError: (c,
|
|
245
|
-
const
|
|
246
|
-
|
|
244
|
+
setError: (c, m) => {
|
|
245
|
+
const F = this.getForm(c);
|
|
246
|
+
F.error = {
|
|
247
247
|
error: !0,
|
|
248
|
-
messages: [
|
|
249
|
-
},
|
|
248
|
+
messages: [m.message]
|
|
249
|
+
}, F.rerender();
|
|
250
250
|
}
|
|
251
|
+
}).catch((c) => {
|
|
252
|
+
console.log("[formkit] submit exception:", c);
|
|
251
253
|
});
|
|
252
254
|
}
|
|
253
255
|
},
|
|
254
256
|
reset(o, { asDirty: i }) {
|
|
255
|
-
V(n, [], o, (u, c,
|
|
256
|
-
if (
|
|
257
|
+
V(n, [], o, (u, c, m) => {
|
|
258
|
+
if (m === void 0 && a[c].value === void 0)
|
|
257
259
|
return;
|
|
258
|
-
if (l.names[c] &&
|
|
260
|
+
if (l.names[c] && m === void 0) {
|
|
259
261
|
a[c].value = void 0;
|
|
260
262
|
return;
|
|
261
263
|
}
|
|
262
|
-
const
|
|
263
|
-
i || (a[c].startValue =
|
|
264
|
+
const F = m ?? u.defaultValue;
|
|
265
|
+
i || (a[c].startValue = F, a[c].isDirty = !1), a[c].value !== F && this.onChange(c, F);
|
|
264
266
|
}), i || (d.dirtyCount = 0, d.isSubmitted = !1), l.subscribers.forEach(({ visualizeEvalueatedForms: u }) => {
|
|
265
267
|
u();
|
|
266
268
|
});
|
|
@@ -288,7 +290,7 @@ const D = M({}), q = (n) => {
|
|
|
288
290
|
subscribeToForm(o, i) {
|
|
289
291
|
const u = { callback: i }, c = this.getForm(o);
|
|
290
292
|
return c.subscribers.push(u), () => {
|
|
291
|
-
c.subscribers = c.subscribers.filter((
|
|
293
|
+
c.subscribers = c.subscribers.filter((m) => m !== u);
|
|
292
294
|
};
|
|
293
295
|
},
|
|
294
296
|
registryExtraForm(o, i) {
|
|
@@ -304,9 +306,9 @@ const D = M({}), q = (n) => {
|
|
|
304
306
|
onChange(o, i) {
|
|
305
307
|
const u = this.getForm(o), c = !L(i, u.startValue);
|
|
306
308
|
u.isDirty !== c && g(o, c), u.isDirty = c, x?.({ name: o, value: i }), (u.error || d.isSubmitted) && (u.error = u.validate(i) || null);
|
|
307
|
-
const
|
|
308
|
-
u.value = i, u.rerender(), u.subscribers.forEach(({ callback:
|
|
309
|
-
|
|
309
|
+
const m = u.value;
|
|
310
|
+
u.value = i, u.rerender(), u.subscribers.forEach(({ callback: F }) => {
|
|
311
|
+
F(i, m);
|
|
310
312
|
});
|
|
311
313
|
}
|
|
312
314
|
};
|
|
@@ -342,11 +344,11 @@ const D = M({}), q = (n) => {
|
|
|
342
344
|
// prettier-ignore
|
|
343
345
|
subscribe: (t, f) => s.subscribeToForm(t, f)
|
|
344
346
|
};
|
|
345
|
-
}, W = ({ manager: n }) => (
|
|
347
|
+
}, W = ({ manager: n }) => (C(() => {
|
|
346
348
|
n.activate();
|
|
347
349
|
}, []), S(() => () => {
|
|
348
350
|
n.disactivate();
|
|
349
|
-
}, []), /* @__PURE__ */ h(D.Provider, { value: n, children: /* @__PURE__ */ h(
|
|
351
|
+
}, []), /* @__PURE__ */ h(D.Provider, { value: n, children: /* @__PURE__ */ h(p, { scheme: n.scheme, path: [] }) })), $ = (n) => {
|
|
350
352
|
try {
|
|
351
353
|
n();
|
|
352
354
|
} catch (e) {
|
|
@@ -415,5 +417,6 @@ export {
|
|
|
415
417
|
X as createForm,
|
|
416
418
|
Y as createLayout,
|
|
417
419
|
O as createUseValue,
|
|
418
|
-
Q as useForm
|
|
420
|
+
Q as useForm,
|
|
421
|
+
q as useValue
|
|
419
422
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { useForm, FormLayout } from './useForm';
|
|
2
|
-
export { createUseValue } from './useValue';
|
|
2
|
+
export { useValue, 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';
|