@companix/formkit 0.0.19 → 0.0.21
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 +17 -14
- package/dist/index.d.ts +1 -1
- package/dist/manager/manager.d.ts +2 -2
- package/dist/useForm.d.ts +2 -2
- package/package.json +1 -1
package/dist/bundle.es.js
CHANGED
|
@@ -39,7 +39,7 @@ const D = M({}), q = (n) => {
|
|
|
39
39
|
S(() => () => {
|
|
40
40
|
t();
|
|
41
41
|
}, []);
|
|
42
|
-
const { value: b, error:
|
|
42
|
+
const { value: b, error: x } = s.getForm(e);
|
|
43
43
|
return /* @__PURE__ */ h(
|
|
44
44
|
n,
|
|
45
45
|
{
|
|
@@ -53,7 +53,7 @@ const D = M({}), q = (n) => {
|
|
|
53
53
|
ref: f
|
|
54
54
|
},
|
|
55
55
|
isDirty: !1,
|
|
56
|
-
error:
|
|
56
|
+
error: x,
|
|
57
57
|
disabled: s.disabled
|
|
58
58
|
}
|
|
59
59
|
);
|
|
@@ -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
|
-
}, []),
|
|
71
|
+
}, []), x = p(() => b(), []), [y, v] = w(x);
|
|
72
72
|
S(() => {
|
|
73
73
|
const { unregistry: l } = t.registryExtraForm(
|
|
74
74
|
s.map(({ name: g }) => [...e, g].join(".")),
|
|
@@ -167,7 +167,7 @@ const D = M({}), q = (n) => {
|
|
|
167
167
|
const r = {};
|
|
168
168
|
return E({ scheme: n, path: [], values: r, forms: e }), r;
|
|
169
169
|
}, G = (n, e) => {
|
|
170
|
-
const { onSubmit: r, onEqual: s, disabled: t, onDirty: f, onFormDirty: b, onChangeEvent:
|
|
170
|
+
const { onSubmit: r, onEqual: s, disabled: t, onDirty: f, onFormDirty: b, onChangeEvent: x, defaultValues: y } = e, v = { onSubmit: r }, d = {
|
|
171
171
|
isActive: !1,
|
|
172
172
|
isSubmitted: !1,
|
|
173
173
|
dirtyCount: 0
|
|
@@ -242,11 +242,11 @@ const D = M({}), q = (n) => {
|
|
|
242
242
|
const u = T(n, a);
|
|
243
243
|
await v.onSubmit(u, {
|
|
244
244
|
setError: (c, F) => {
|
|
245
|
-
const
|
|
246
|
-
|
|
245
|
+
const m = this.getForm(c);
|
|
246
|
+
m.error = {
|
|
247
247
|
error: !0,
|
|
248
248
|
messages: [F.message]
|
|
249
|
-
},
|
|
249
|
+
}, m.rerender();
|
|
250
250
|
}
|
|
251
251
|
});
|
|
252
252
|
}
|
|
@@ -259,8 +259,8 @@ const D = M({}), q = (n) => {
|
|
|
259
259
|
a[c].value = void 0;
|
|
260
260
|
return;
|
|
261
261
|
}
|
|
262
|
-
const
|
|
263
|
-
i || (a[c].startValue =
|
|
262
|
+
const m = F ?? u.defaultValue;
|
|
263
|
+
i || (a[c].startValue = m, a[c].isDirty = !1), a[c].value !== m && this.onChange(c, m);
|
|
264
264
|
}), i || (d.dirtyCount = 0, d.isSubmitted = !1), l.subscribers.forEach(({ visualizeEvalueatedForms: u }) => {
|
|
265
265
|
u();
|
|
266
266
|
});
|
|
@@ -303,8 +303,10 @@ const D = M({}), q = (n) => {
|
|
|
303
303
|
},
|
|
304
304
|
onChange(o, i) {
|
|
305
305
|
const u = this.getForm(o), c = !L(i, u.startValue);
|
|
306
|
-
u.isDirty !== c && g(o, c), u.isDirty = c,
|
|
307
|
-
|
|
306
|
+
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 F = u.value;
|
|
308
|
+
u.value = i, u.rerender(), u.subscribers.forEach(({ callback: m }) => {
|
|
309
|
+
m(i, F);
|
|
308
310
|
});
|
|
309
311
|
}
|
|
310
312
|
};
|
|
@@ -359,14 +361,14 @@ const D = M({}), q = (n) => {
|
|
|
359
361
|
};
|
|
360
362
|
}
|
|
361
363
|
}, X = (n) => (e, r) => {
|
|
362
|
-
const s = n.getRequireCheck(r), { $rules: t = {}, ...f } = r, { validate: b, required:
|
|
364
|
+
const s = n.getRequireCheck(r), { $rules: t = {}, ...f } = r, { validate: b, required: x } = t;
|
|
363
365
|
return {
|
|
364
366
|
type: "form",
|
|
365
367
|
name: e,
|
|
366
368
|
defaultValue: n.defaultValue,
|
|
367
369
|
Form: n.getForm(f),
|
|
368
370
|
validate: (y) => {
|
|
369
|
-
if (
|
|
371
|
+
if (x) {
|
|
370
372
|
const v = $(() => s(y));
|
|
371
373
|
if (v)
|
|
372
374
|
return v;
|
|
@@ -413,5 +415,6 @@ export {
|
|
|
413
415
|
X as createForm,
|
|
414
416
|
Y as createLayout,
|
|
415
417
|
O as createUseValue,
|
|
416
|
-
Q as useForm
|
|
418
|
+
Q as useForm,
|
|
419
|
+
q as useValue
|
|
417
420
|
};
|
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';
|
|
@@ -11,7 +11,7 @@ interface FormItem {
|
|
|
11
11
|
focus?: () => void;
|
|
12
12
|
validate: (value: any) => FieldError | void;
|
|
13
13
|
subscribers: {
|
|
14
|
-
callback: (value: any) => void;
|
|
14
|
+
callback: (value: any, prevValue: any) => void;
|
|
15
15
|
}[];
|
|
16
16
|
}
|
|
17
17
|
export interface Forms {
|
|
@@ -32,7 +32,7 @@ export interface FormManager<Values, FlattenValues, ClonedValues> {
|
|
|
32
32
|
registry: (name: string, callback: () => void) => {
|
|
33
33
|
unregistry: () => void;
|
|
34
34
|
};
|
|
35
|
-
subscribeToForm: <K extends keyof FlattenValues>(name: K & string, callback: (value: FlattenValues[K]) => void) => () => void;
|
|
35
|
+
subscribeToForm: <K extends keyof FlattenValues>(name: K & string, callback: (value: FlattenValues[K], prevValue: FlattenValues[K]) => void) => () => void;
|
|
36
36
|
registryExtraForm: (names: string[], callback: () => void) => {
|
|
37
37
|
unregistry: () => void;
|
|
38
38
|
};
|
package/dist/useForm.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ declare const useDynamicForm: (scheme: SchemeItems.All[], opts: MainOptions<Fiel
|
|
|
50
50
|
[x: string]: any;
|
|
51
51
|
};
|
|
52
52
|
handleSubmit: () => Promise<void>;
|
|
53
|
-
subscribe: <K extends string>(name: K, callback: (value: any) => void) => () => void;
|
|
53
|
+
subscribe: <K extends string>(name: K, callback: (value: any, prevValue: any) => void) => () => void;
|
|
54
54
|
};
|
|
55
55
|
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>) => {
|
|
56
56
|
manager: FormManager<Values, FlattenValues, Cloned>;
|
|
@@ -65,7 +65,7 @@ declare const useForm: <Items extends SchemeItems.All[], Values extends ExtractV
|
|
|
65
65
|
getValue: <K extends keyof FlattenValues>(name: K & string) => FlattenValues[K];
|
|
66
66
|
getValues: () => DeepPartial<Cloned>;
|
|
67
67
|
handleSubmit: () => Promise<void>;
|
|
68
|
-
subscribe: <K extends keyof FlattenValues>(name: K & string, callback: (value: FlattenValues[K]) => void) => () => void;
|
|
68
|
+
subscribe: <K extends keyof FlattenValues>(name: K & string, callback: (value: FlattenValues[K], prevValue: FlattenValues[K]) => void) => () => void;
|
|
69
69
|
};
|
|
70
70
|
interface Props {
|
|
71
71
|
manager: FormManager<any, any, any>;
|