@companix/formkit 0.0.11 → 0.0.14

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