@companix/formkit 0.0.26 → 0.0.28

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,11 +1,11 @@
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 C, useEffect as $, useCallback as A, useRef as P } from "react";
1
+ import { jsx as h, Fragment as w, jsxs as B } from "react/jsx-runtime";
2
+ import { createContext as M, useState as R, useContext as T, useMemo as S, useEffect as $, useCallback as D, useRef as P } from "react";
3
3
  import L from "fast-deep-equal";
4
- const D = M({}), q = (o) => {
5
- const [, r] = w([]), e = R(D);
4
+ const j = M({}), q = (o) => {
5
+ const [, r] = R([]), e = T(j);
6
6
  if (!e)
7
7
  throw new Error("useValue cannot be used outside Form context");
8
- const s = C(() => {
8
+ const s = S(() => {
9
9
  const t = e.getForm(o);
10
10
  if (!t)
11
11
  throw new Error(`form with name "${o}" doesnt exist in form`);
@@ -19,18 +19,18 @@ const D = M({}), q = (o) => {
19
19
  t();
20
20
  };
21
21
  }, []), s.value;
22
- }, O = () => (o) => q(o), N = ({ canActivate: o, name: r, children: e }) => {
22
+ }, K = () => (o) => q(o), O = ({ canActivate: o, name: r, children: e }) => {
23
23
  const s = q(r);
24
- return o(s) ? /* @__PURE__ */ h(j, { children: e }) : null;
24
+ return o(s) ? /* @__PURE__ */ h(w, { children: e }) : null;
25
25
  }, U = ({ item: { Form: o }, name: r }) => {
26
- const [, e] = w([]), s = R(D), { unregistry: t } = C(() => s.registry(r, () => {
26
+ const [, e] = R([]), s = T(j), { unregistry: t } = S(() => s.registry(r, () => {
27
27
  e([]);
28
- }), []), l = A(
29
- (y) => {
30
- if (y && y.focus) {
28
+ }), []), l = D(
29
+ (b) => {
30
+ if (b && b.focus) {
31
31
  const v = s.getForm(r);
32
32
  v.focus = () => {
33
- y.focus();
33
+ b.focus();
34
34
  };
35
35
  }
36
36
  },
@@ -39,107 +39,107 @@ const D = M({}), q = (o) => {
39
39
  $(() => () => {
40
40
  t();
41
41
  }, []);
42
- const { value: g, error: V } = s.getForm(r);
42
+ const { value: g, error: x } = s.getForm(r);
43
43
  return /* @__PURE__ */ h(
44
44
  o,
45
45
  {
46
46
  field: {
47
47
  value: g,
48
- onChange: (y) => {
49
- s.onChange(r, y);
48
+ onChange: (b) => {
49
+ s.onChange(r, b);
50
50
  },
51
51
  onBlur: () => {
52
52
  },
53
53
  ref: l
54
54
  },
55
55
  isDirty: !1,
56
- error: V,
56
+ error: x,
57
57
  disabled: s.disabled
58
58
  }
59
59
  );
60
- }, z = ({ item: o, path: r }) => {
61
- const { getController: e, items: s } = o, t = R(D), l = C(() => {
62
- const f = {};
63
- return s.forEach(({ name: b, getForm: n }) => {
64
- f[b] = n(b, () => a(b));
65
- }), f;
66
- }, []), g = A(() => {
67
- const f = [];
68
- return s.forEach(({ name: b }) => {
69
- t.getForm([...r, b].join(".")).value !== void 0 && f.push(b);
70
- }), f;
71
- }, []), V = C(() => g(), []), [y, v] = w(V);
60
+ }, _ = ({ item: o, path: r }) => {
61
+ const { getController: e, items: s } = o, t = T(j), l = S(() => {
62
+ const y = {};
63
+ return s.forEach(({ name: d, getForm: V }) => {
64
+ y[d] = V(d, () => a(d));
65
+ }), y;
66
+ }, []), g = D(() => {
67
+ const y = [];
68
+ return s.forEach(({ name: d }) => {
69
+ t.getForm([...r, d].join(".")).value !== void 0 && y.push(d);
70
+ }), y;
71
+ }, []), x = S(() => g(), []), [b, v] = R(x);
72
72
  $(() => {
73
- const { unregistry: f } = t.registryExtraForm(
74
- s.map(({ name: b }) => [...r, b].join(".")),
73
+ const { unregistry: y } = t.registryExtraForm(
74
+ s.map(({ name: d }) => [...r, d].join(".")),
75
75
  () => {
76
76
  v(g());
77
77
  }
78
78
  );
79
79
  return () => {
80
- f();
80
+ y();
81
81
  };
82
82
  }, []);
83
- const d = A(
84
- (f) => {
85
- l[f] && !y.includes(f) && v((b) => [...b, f]);
83
+ const f = D(
84
+ (y) => {
85
+ l[y] && !b.includes(y) && v((d) => [...d, y]);
86
86
  },
87
- [y]
88
- ), a = A((f) => {
89
- v((b) => b.filter((n) => n !== f));
87
+ [b]
88
+ ), a = D((y) => {
89
+ v((d) => d.filter((V) => V !== y));
90
90
  }, []);
91
- return /* @__PURE__ */ B(j, { children: [
92
- y.map((f) => {
93
- const b = l[f];
94
- return /* @__PURE__ */ h(E, { path: r, scheme: [b] }, `param-form--${f}`);
91
+ return /* @__PURE__ */ B(w, { children: [
92
+ b.map((y) => {
93
+ const d = l[y];
94
+ return /* @__PURE__ */ h(p, { path: r, scheme: [d] }, `param-form--${y}`);
95
95
  }),
96
- e(d, y)
96
+ e(f, b)
97
97
  ] });
98
- }, E = ({ scheme: o, path: r }) => /* @__PURE__ */ h(j, { children: o.map((e, s) => e.type === "layout" ? /* @__PURE__ */ h(e.Layout, { children: /* @__PURE__ */ h(E, { path: r, scheme: e.childs }) }, `layout-form--${s}-${r.length}`) : e.type === "context" ? /* @__PURE__ */ h(
99
- E,
98
+ }, p = ({ scheme: o, path: r }) => /* @__PURE__ */ h(w, { children: o.map((e, s) => e.type === "layout" ? /* @__PURE__ */ h(e.Layout, { children: /* @__PURE__ */ h(p, { path: r, scheme: e.childs }) }, `layout-form--${s}-${r.length}`) : e.type === "context" ? /* @__PURE__ */ h(
99
+ p,
100
100
  {
101
101
  path: [...r, e.context],
102
102
  scheme: e.childs
103
103
  },
104
104
  `context-form--${s}-${e.context}-${r.length}`
105
105
  ) : e.type === "condition" ? /* @__PURE__ */ h(
106
- N,
106
+ O,
107
107
  {
108
108
  name: e.depended,
109
109
  canActivate: e.canActivate,
110
- children: /* @__PURE__ */ h(E, { path: r, scheme: e.childs })
110
+ children: /* @__PURE__ */ h(p, { path: r, scheme: e.childs })
111
111
  },
112
112
  `condition--${s}-${e.depended}-${r.length}`
113
- ) : e.type === "extra" ? /* @__PURE__ */ h(z, { path: r, item: e }, `partial-item--${s}-${r.length}`) : e.type === "visability" ? e.hidden ? null : /* @__PURE__ */ h(E, { path: r, scheme: e.childs }, `visability--${s}-${r.length}`) : /* @__PURE__ */ h(
113
+ ) : e.type === "extra" ? /* @__PURE__ */ h(_, { path: r, item: e }, `partial-item--${s}-${r.length}`) : e.type === "visability" ? e.hidden ? null : /* @__PURE__ */ h(p, { path: r, scheme: e.childs }, `visability--${s}-${r.length}`) : /* @__PURE__ */ h(
114
114
  U,
115
115
  {
116
116
  name: [...r, e.name].join("."),
117
117
  item: e
118
118
  },
119
119
  `form-item--${s}-${e.name}-${r.length}`
120
- )) }), p = (o, r, e, s) => {
120
+ )) }), C = (o, r, e, s) => {
121
121
  o.forEach((t) => {
122
122
  if (t.type === "form" && s(t, [...r, t.name].join("."), e[t.name]), t.type === "context") {
123
- p(t.childs, [...r, t.context], e[t.context] ?? {}, s);
123
+ C(t.childs, [...r, t.context], e[t.context] ?? {}, s);
124
124
  return;
125
125
  }
126
126
  if (t.type === "layout" || t.type === "condition" || t.type === "visability") {
127
- p(t.childs, r, e, s);
127
+ C(t.childs, r, e, s);
128
128
  return;
129
129
  }
130
130
  t.type === "extra" && t.items.forEach(({ getForm: l, name: g }) => {
131
- p([l(g, () => {
131
+ C([l(g, () => {
132
132
  })], r, e, s);
133
133
  });
134
134
  });
135
- }, m = ({ scheme: o, values: r, path: e, forms: s }) => {
135
+ }, E = ({ scheme: o, values: r, path: e, forms: s }) => {
136
136
  o.forEach((t) => {
137
137
  if (t.type === "form") {
138
138
  const l = [...e, t.name].join(".");
139
139
  s[l].value !== void 0 && (r[t.name] = s[l].value);
140
140
  }
141
141
  if (t.type === "context") {
142
- r[t.context] = {}, m({
142
+ r[t.context] = {}, E({
143
143
  scheme: t.childs,
144
144
  path: [...e, t.context],
145
145
  values: r[t.context],
@@ -148,38 +148,38 @@ const D = M({}), q = (o) => {
148
148
  return;
149
149
  }
150
150
  if (t.type === "layout") {
151
- m({ scheme: t.childs, path: e, values: r, forms: s });
151
+ E({ scheme: t.childs, path: e, values: r, forms: s });
152
152
  return;
153
153
  }
154
154
  if (t.type === "visability") {
155
- m({ scheme: t.childs, path: e, values: r, forms: s });
155
+ E({ scheme: t.childs, path: e, values: r, forms: s });
156
156
  return;
157
157
  }
158
158
  if (t.type === "condition") {
159
159
  const l = s[t.depended]?.value;
160
160
  if (t.canActivate(l)) {
161
- m({ scheme: t.childs, path: e, values: r, forms: s });
161
+ E({ scheme: t.childs, path: e, values: r, forms: s });
162
162
  return;
163
163
  }
164
164
  }
165
165
  t.type === "extra" && t.items.forEach(({ getForm: l, name: g }) => {
166
- m({ scheme: [l(g, () => {
166
+ E({ scheme: [l(g, () => {
167
167
  })], path: e, values: r, forms: s });
168
168
  });
169
169
  });
170
- }, T = (o, r) => {
170
+ }, N = (o, r) => {
171
171
  const e = {};
172
- return m({ scheme: o, path: [], values: e, forms: r }), e;
173
- }, G = (o, r) => {
174
- const { onSubmit: e, onEqual: s, disabled: t, onDirty: l, onFormDirty: g, onChangeEvent: V, defaultValues: y } = r, v = { onSubmit: e }, d = {
172
+ return E({ scheme: o, path: [], values: e, forms: r }), e;
173
+ }, z = (o, r) => {
174
+ const { onSubmit: e, onEqual: s, disabled: t, onDirty: l, onFormDirty: g, onChangeEvent: x, defaultValues: b } = r, v = { onSubmit: e }, f = {
175
175
  isActive: !1,
176
176
  isSubmitted: !1,
177
177
  dirtyCount: 0
178
- }, a = {}, f = {
178
+ }, a = {}, y = /* @__PURE__ */ new Set(), d = {
179
179
  subscribers: [],
180
180
  names: {}
181
181
  };
182
- p(o, [], y ?? {}, (n, u, i) => {
182
+ C(o, [], b ?? {}, (n, u, i) => {
183
183
  a[u] = {
184
184
  error: null,
185
185
  isDirty: !1,
@@ -195,18 +195,18 @@ const D = M({}), q = (o) => {
195
195
  validate: n.validate
196
196
  };
197
197
  });
198
- const b = (n, u) => {
199
- l?.({ name: n, isDirty: u }), u && d.dirtyCount === 0 && g?.(!0), !u && d.dirtyCount === 1 && g?.(!1), d.dirtyCount += u ? 1 : -1;
198
+ const V = (n, u) => {
199
+ l?.({ name: n, isDirty: u }), u && f.dirtyCount === 0 && g?.(!0), !u && f.dirtyCount === 1 && g?.(!1), f.dirtyCount += u ? 1 : -1;
200
200
  };
201
201
  return {
202
202
  submitRef: v,
203
203
  scheme: o,
204
204
  disabled: t,
205
205
  activate() {
206
- d.isActive = !0;
206
+ f.isActive = !0;
207
207
  },
208
208
  disactivate() {
209
- d.isActive = !1;
209
+ f.isActive = !1;
210
210
  },
211
211
  setError(n, u) {
212
212
  const i = this.getForm(n);
@@ -224,12 +224,12 @@ const D = M({}), q = (o) => {
224
224
  i && i.value !== u && this.onChange(n, u);
225
225
  },
226
226
  getValues() {
227
- return T(o, a);
227
+ return N(o, a);
228
228
  },
229
229
  async handleSubmit() {
230
230
  if (t)
231
231
  return;
232
- d.isSubmitted = !0;
232
+ f.isSubmitted = !0;
233
233
  let n = !1, u = !1;
234
234
  for (const i in a) {
235
235
  const c = a[i];
@@ -239,18 +239,18 @@ const D = M({}), q = (o) => {
239
239
  }
240
240
  }
241
241
  if (!u) {
242
- if (d.dirtyCount === 0 && s) {
242
+ if (f.dirtyCount === 0 && s) {
243
243
  s();
244
244
  return;
245
245
  }
246
- const i = T(o, a);
246
+ const i = N(o, a);
247
247
  await v.onSubmit(i, {
248
248
  setError: (c, F) => {
249
- const x = this.getForm(c);
250
- x.error = {
249
+ const m = this.getForm(c);
250
+ m.error = {
251
251
  error: !0,
252
252
  messages: [F.message]
253
- }, x.rerender();
253
+ }, m.rerender();
254
254
  }
255
255
  }).catch((c) => {
256
256
  console.log("[formkit] submit exception:", c);
@@ -258,32 +258,32 @@ const D = M({}), q = (o) => {
258
258
  }
259
259
  },
260
260
  reset(n, { asDirty: u }) {
261
- p(o, [], n, (i, c, F) => {
261
+ C(o, [], n, (i, c, F) => {
262
262
  if (F === void 0 && a[c].value === void 0)
263
263
  return;
264
- if (f.names[c] && F === void 0) {
264
+ if (d.names[c] && F === void 0) {
265
265
  a[c].value = void 0;
266
266
  return;
267
267
  }
268
- const x = F ?? i.defaultValue;
269
- u || (a[c].startValue = x, a[c].isDirty = !1), a[c].value !== x && this.onChange(c, x);
270
- }), u || (d.dirtyCount = 0, d.isSubmitted = !1), f.subscribers.forEach(({ visualizeEvalueatedForms: i }) => {
268
+ const m = F ?? i.defaultValue;
269
+ u || (a[c].startValue = m, a[c].isDirty = !1), a[c].value !== m && this.onChange(c, m);
270
+ }), u || (f.dirtyCount = 0, f.isSubmitted = !1), d.subscribers.forEach(({ visualizeEvalueatedForms: i }) => {
271
271
  i();
272
272
  });
273
273
  },
274
274
  setAsDefault() {
275
- p(o, [], {}, ({}, n) => {
276
- a[n].startValue = a[n].value, a[n].isDirty = !1;
277
- }), d.dirtyCount = 0, d.isSubmitted = !1;
275
+ C(o, [], {}, (n, u) => {
276
+ a[u].startValue = a[u].value, a[u].isDirty = !1;
277
+ }), f.dirtyCount = 0, f.isSubmitted = !1;
278
278
  },
279
279
  registry(n, u) {
280
280
  return a[n].rerender = u, a[n].value === void 0 && (a[n].value = a[n].defaultValue), {
281
281
  unregistry() {
282
282
  if (a[n].rerender = () => {
283
- }, a[n].focus = void 0, d.isActive) {
283
+ }, a[n].focus = void 0, f.isActive) {
284
284
  a[n].value = void 0;
285
285
  const i = !L(a[n].startValue, a[n].defaultValue);
286
- a[n].isDirty !== i && b(n, i), a[n].isDirty = i;
286
+ a[n].isDirty !== i && V(n, i), a[n].isDirty = i;
287
287
  }
288
288
  }
289
289
  };
@@ -297,28 +297,38 @@ const D = M({}), q = (o) => {
297
297
  c.subscribers = c.subscribers.filter((F) => F !== i);
298
298
  };
299
299
  },
300
+ subscribeToAny(n) {
301
+ return y.add(n), () => {
302
+ y.delete(n);
303
+ };
304
+ },
305
+ getNames() {
306
+ return Object.keys(a);
307
+ },
300
308
  registryExtraForm(n, u) {
301
309
  const i = { visualizeEvalueatedForms: u };
302
310
  return n.forEach((c) => {
303
- f.names[c] = !0;
304
- }), f.subscribers.push(i), {
311
+ d.names[c] = !0;
312
+ }), d.subscribers.push(i), {
305
313
  unregistry() {
306
- f.subscribers = f.subscribers.filter((c) => c !== i);
314
+ d.subscribers = d.subscribers.filter((c) => c !== i);
307
315
  }
308
316
  };
309
317
  },
310
318
  onChange(n, u) {
311
319
  const i = this.getForm(n), c = !L(u, i.startValue);
312
- i.isDirty !== c && b(n, c), i.isDirty = c, V?.({ name: n, value: u }), (i.error || d.isSubmitted) && (i.error = i.validate(u) || null);
320
+ i.isDirty !== c && V(n, c), i.isDirty = c, x?.({ name: n, value: u }), (i.error || f.isSubmitted) && (i.error = i.validate(u) || null);
313
321
  const F = i.value;
314
- i.value = u, i.rerender(), i.subscribers.forEach(({ callback: x }) => {
315
- x(u, F);
322
+ i.value = u, i.rerender(), i.subscribers.forEach(({ callback: m }) => {
323
+ m(u, F);
324
+ }), y.forEach((m) => {
325
+ m();
316
326
  });
317
327
  }
318
328
  };
319
329
  }, Q = (o, r) => {
320
330
  const e = P(null);
321
- e.current === null && (e.current = G(o, r));
331
+ e.current === null && (e.current = z(o, r));
322
332
  const s = e.current;
323
333
  return $(() => {
324
334
  e.current && (e.current.submitRef.onSubmit = r.onSubmit);
@@ -346,13 +356,17 @@ const D = M({}), q = (o) => {
346
356
  await s.handleSubmit();
347
357
  },
348
358
  // prettier-ignore
349
- subscribe: (t, l) => s.subscribeToForm(t, l)
359
+ subscribe: (t, l) => s.subscribeToForm(t, l),
360
+ // подписка на любое изменение значений формы (для гейтов поверх всех полей)
361
+ subscribeAny: (t) => s.subscribeToAny(t),
362
+ // плоский список имён всех полей (dotted-пути; вложенные context раскрыты)
363
+ getNames: () => s.getNames()
350
364
  };
351
- }, W = ({ manager: o }) => (C(() => {
365
+ }, W = ({ manager: o }) => (S(() => {
352
366
  o.activate();
353
367
  }, []), $(() => () => {
354
368
  o.disactivate();
355
- }, []), /* @__PURE__ */ h(D.Provider, { value: o, children: /* @__PURE__ */ h(E, { scheme: o.scheme, path: [] }) })), S = (o) => {
369
+ }, []), /* @__PURE__ */ h(j.Provider, { value: o, children: /* @__PURE__ */ h(p, { scheme: o.scheme, path: [] }) })), A = (o) => {
356
370
  try {
357
371
  o();
358
372
  } catch (r) {
@@ -367,28 +381,28 @@ const D = M({}), q = (o) => {
367
381
  };
368
382
  }
369
383
  }, X = (o) => (r, e) => {
370
- const s = o.getRequireCheck(e), { $rules: t = {}, ...l } = e, { validate: g, required: V } = t;
384
+ const s = o.getRequireCheck(e), { $rules: t = {}, ...l } = e, { validate: g, required: x } = t;
371
385
  return {
372
386
  type: "form",
373
387
  name: r,
374
388
  defaultValue: o.defaultValue,
375
389
  Form: o.getForm(l),
376
- validate: (y) => {
377
- if (V) {
378
- const v = S(() => s(y));
390
+ validate: (b) => {
391
+ if (x) {
392
+ const v = A(() => s(b));
379
393
  if (v)
380
394
  return v;
381
395
  if (g) {
382
- const d = S(() => g(y));
383
- if (d)
384
- return d;
396
+ const f = A(() => g(b));
397
+ if (f)
398
+ return f;
385
399
  }
386
400
  return;
387
401
  }
388
- if (g && !S(() => s(y))) {
389
- const d = S(() => g(y));
390
- if (d)
391
- return d;
402
+ if (g && !A(() => s(b))) {
403
+ const f = A(() => g(b));
404
+ if (f)
405
+ return f;
392
406
  }
393
407
  }
394
408
  };
@@ -403,29 +417,29 @@ const D = M({}), q = (o) => {
403
417
  type: "extra",
404
418
  items: o((e) => (s) => ({ type: "registry", name: e, getForm: s })),
405
419
  getController: r
406
- }), _ = (o) => (...r) => ({
420
+ }), k = (o) => (...r) => ({
407
421
  type: "context",
408
422
  context: o,
409
423
  childs: r
410
- }), k = (o, r) => (...e) => ({
424
+ }), I = (o, r) => (...e) => ({
411
425
  type: "condition",
412
426
  depended: o,
413
427
  canActivate: r.canActivate,
414
428
  childs: e
415
- }), I = ({ hidden: o }) => (...r) => ({
429
+ }), rr = ({ hidden: o }) => (...r) => ({
416
430
  type: "visability",
417
431
  hidden: o ?? !1,
418
432
  childs: r
419
433
  });
420
434
  export {
421
- k as Condition,
422
- _ as Context,
435
+ I as Condition,
436
+ k as Context,
423
437
  W as FormLayout,
424
- I as Visablility,
438
+ rr as Visablility,
425
439
  Z as createExtraForm,
426
440
  X as createForm,
427
441
  Y as createLayout,
428
- O as createUseValue,
442
+ K as createUseValue,
429
443
  Q as useForm,
430
444
  q as useValue
431
445
  };
@@ -4,10 +4,10 @@ type ExtractValue<T> = T extends SchemeItems.Form<infer N, infer V> ? {
4
4
  [K in N]: V;
5
5
  } : T extends SchemeItems.Layout<infer C> ? ExtractValue<C[number]> : T extends SchemeItems.Context<infer N, infer C> ? {
6
6
  [K in N]: Compute<UnionToIntersection<ExtractValue<C[number]>>>;
7
- } : T extends SchemeItems.Condition<infer C> ? Partial<ExtractValue<C[number]>> : T extends SchemeItems.Extra<string, infer C> ? Partial<ExtractValue<ReturnType<C[number]['getForm']>>> : never;
7
+ } : T extends SchemeItems.Condition<infer C> ? Partial<ExtractValue<C[number]>> : T extends SchemeItems.Visablility<infer C> ? Partial<ExtractValue<C[number]>> : T extends SchemeItems.Extra<string, infer C> ? Partial<ExtractValue<ReturnType<C[number]['getForm']>>> : never;
8
8
  type ExtractValues<T> = Compute<UnionToIntersection<ExtractValue<T>>>;
9
9
  type ExtractFlatValue<T, A extends string | null> = T extends SchemeItems.Form<infer N, infer V> ? {
10
10
  [K in A extends null ? N : `${A}.${N}`]: V;
11
- } : T extends SchemeItems.Layout<infer C> ? ExtractFlatValue<C[number], A> : T extends SchemeItems.Context<infer N, infer C> ? ExtractFlatValue<C[number], A extends null ? N : `${A}.${N}`> : T extends SchemeItems.Condition<infer C> ? Partial<ExtractFlatValue<C[number], A>> : T extends SchemeItems.Extra<string, infer C> ? Partial<ExtractValue<ReturnType<C[number]['getForm']>>> : never;
11
+ } : T extends SchemeItems.Layout<infer C> ? ExtractFlatValue<C[number], A> : T extends SchemeItems.Context<infer N, infer C> ? ExtractFlatValue<C[number], A extends null ? N : `${A}.${N}`> : T extends SchemeItems.Condition<infer C> ? Partial<ExtractFlatValue<C[number], A>> : T extends SchemeItems.Visablility<infer C> ? Partial<ExtractFlatValue<C[number], A>> : T extends SchemeItems.Extra<string, infer C> ? Partial<ExtractValue<ReturnType<C[number]['getForm']>>> : never;
12
12
  type ExtractFlatValues<T> = Compute<UnionToIntersection<ExtractFlatValue<T, null>>>;
13
13
  export type { ExtractValues, ExtractFlatValues };
@@ -33,6 +33,8 @@ export interface FormManager<Values, FlattenValues, ClonedValues> {
33
33
  unregistry: () => void;
34
34
  };
35
35
  subscribeToForm: <K extends keyof FlattenValues>(name: K & string, callback: (value: FlattenValues[K], prevValue: FlattenValues[K]) => void) => () => void;
36
+ subscribeToAny: (callback: () => void) => () => void;
37
+ getNames: () => string[];
36
38
  registryExtraForm: (names: string[], callback: () => void) => {
37
39
  unregistry: () => void;
38
40
  };
package/dist/useForm.d.ts CHANGED
@@ -51,6 +51,8 @@ declare const useDynamicForm: (scheme: SchemeItems.All[], opts: MainOptions<Fiel
51
51
  };
52
52
  handleSubmit: () => Promise<void>;
53
53
  subscribe: <K extends string>(name: K, callback: (value: any, prevValue: any) => void) => () => void;
54
+ subscribeAny: (callback: () => void) => () => void;
55
+ getNames: () => string[];
54
56
  };
55
57
  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
58
  manager: FormManager<Values, FlattenValues, Cloned>;
@@ -66,6 +68,8 @@ declare const useForm: <Items extends SchemeItems.All[], Values extends ExtractV
66
68
  getValues: () => DeepPartial<Cloned>;
67
69
  handleSubmit: () => Promise<void>;
68
70
  subscribe: <K extends keyof FlattenValues>(name: K & string, callback: (value: FlattenValues[K], prevValue: FlattenValues[K]) => void) => () => void;
71
+ subscribeAny: (callback: () => void) => () => void;
72
+ getNames: () => string[];
69
73
  };
70
74
  interface Props {
71
75
  manager: FormManager<any, any, any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@companix/formkit",
3
- "version": "0.0.26",
3
+ "version": "0.0.28",
4
4
  "module": "./dist/bundle.es.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "type": "module",