@companix/formkit 0.0.17 → 0.0.18

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