@companix/formkit 0.0.17 → 0.0.19

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: b, error: m } = s.getForm(e);
43
+ return /* @__PURE__ */ h(
44
+ n,
45
45
  {
46
46
  field: {
47
- value: h,
47
+ value: b,
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: g, getForm: o }) => {
64
+ l[g] = o(g, () => a(g));
65
65
  }), l;
66
- }, []), h = A(() => {
66
+ }, []), b = A(() => {
67
67
  const l = [];
68
- return n.forEach(({ name: g }) => {
68
+ return s.forEach(({ name: g }) => {
69
69
  t.getForm([...e, g].join(".")).value !== void 0 && l.push(g);
70
70
  }), l;
71
- }, []), x = p(() => h(), []), [y, v] = w(x);
71
+ }, []), m = p(() => b(), []), [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: g }) => [...e, g].join(".")),
75
75
  () => {
76
- v(h());
76
+ v(b());
77
77
  }
78
78
  );
79
79
  return () => {
@@ -86,88 +86,88 @@ const D = P({}), q = (o) => {
86
86
  },
87
87
  [y]
88
88
  ), a = A((l) => {
89
- v((g) => g.filter((s) => s !== l));
89
+ v((g) => g.filter((o) => o !== l));
90
90
  }, []);
91
- return /* @__PURE__ */ M(j, { children: [
91
+ return /* @__PURE__ */ B(j, { children: [
92
92
  y.map((l) => {
93
93
  const g = f[l];
94
- return /* @__PURE__ */ b(C, { path: e, scheme: [g] }, `param-form--${l}`);
94
+ return /* @__PURE__ */ h(C, { path: e, scheme: [g] }, `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: b }) => {
131
+ V([f(b, () => {
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: b }) => {
162
+ E({ scheme: [f(b, () => {
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: b, 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) => {
179
- a[u] = {
178
+ V(n, [], y ?? {}, (o, i, u) => {
179
+ a[i] = {
180
180
  error: null,
181
181
  isDirty: !1,
182
- value: i,
182
+ value: u,
183
183
  // текущее (динамическое) состояние поля. Значение равно переданному дефолтному, либо: определяется как дефолтное значение компонента формы в момент его монтирования, а до этого - undefined.
184
- startValue: i ?? s.defaultValue,
184
+ startValue: u ?? 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 g = (o, i) => {
195
+ f?.({ name: o, isDirty: i }), i && d.dirtyCount === 0 && b?.(!0), !i && d.dirtyCount === 1 && b?.(!1), d.dirtyCount += i ? 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,148 +204,149 @@ 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);
209
- i && (i.error = {
207
+ setError(o, i) {
208
+ const u = this.getForm(o);
209
+ u && (u.error = {
210
210
  error: !0,
211
- messages: [u.message]
212
- }, i.rerender());
211
+ messages: [i.message]
212
+ }, u.rerender());
213
213
  },
214
- setFocus(s) {
215
- const u = this.getForm(s);
216
- u && u.focus && u.focus();
214
+ setFocus(o) {
215
+ const i = this.getForm(o);
216
+ i && i.focus && i.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, i) {
219
+ const u = this.getForm(o);
220
+ u && u.value !== i && this.onChange(o, i);
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;
230
- for (const i in a) {
231
- const c = a[i];
229
+ let o = !1, i = !1;
230
+ for (const u in a) {
231
+ const c = a[u];
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 && (i = !0, c.error = F, c.rerender(), !o && c.focus && (c.focus(), o = !0));
235
235
  }
236
236
  }
237
- if (!u) {
237
+ if (!i) {
238
238
  if (d.dirtyCount === 0) {
239
- n?.();
239
+ s?.();
240
240
  return;
241
241
  }
242
- const i = B(o, a);
243
- await v.onSubmit(i, {
242
+ const u = T(n, a);
243
+ await v.onSubmit(u, {
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: i }) {
255
+ V(n, [], o, (u, 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);
264
- }), u || (d.dirtyCount = 0, d.isSubmitted = !1), l.subscribers.forEach(({ visualizeEvalueatedForms: i }) => {
265
- i();
262
+ const x = F ?? u.defaultValue;
263
+ i || (a[c].startValue = x, a[c].isDirty = !1), a[c].value !== x && this.onChange(c, x);
264
+ }), i || (d.dirtyCount = 0, d.isSubmitted = !1), l.subscribers.forEach(({ visualizeEvalueatedForms: u }) => {
265
+ u();
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, i) {
274
+ return a[o].rerender = i, 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 u = !L(a[o].startValue, a[o].defaultValue);
280
+ a[o].isDirty !== u && g(o, u), a[o].isDirty = u;
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, i) {
289
+ const u = { callback: i }, c = this.getForm(o);
290
+ return c.subscribers.push(u), () => {
291
+ c.subscribers = c.subscribers.filter((F) => F !== u);
294
292
  };
295
293
  },
296
- registryExtraForm(s, u) {
297
- const i = { visualizeEvalueatedForms: u };
298
- return s.forEach((c) => {
294
+ registryExtraForm(o, i) {
295
+ const u = { visualizeEvalueatedForms: i };
296
+ return o.forEach((c) => {
299
297
  l.names[c] = !0;
300
- }), l.subscribers.push(i), {
298
+ }), l.subscribers.push(u), {
301
299
  unregistry() {
302
- l.subscribers = l.subscribers.filter((c) => c !== i);
300
+ l.subscribers = l.subscribers.filter((c) => c !== u);
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, i) {
305
+ const u = this.getForm(o), c = !L(i, u.startValue);
306
+ u.isDirty !== c && g(o, c), u.isDirty = c, m?.({ name: o, value: i }), (u.error || d.isSubmitted) && (u.error = u.validate(i) || null), u.value = i, u.rerender(), u.subscribers.forEach(({ callback: F }) => {
307
+ F(i);
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
+ getValue: (t) => s.getForm(t).value,
336
+ getValues: () => s.getValues(),
338
337
  handleSubmit: async () => {
339
- await n.handleSubmit();
340
- }
338
+ await s.handleSubmit();
339
+ },
340
+ // prettier-ignore
341
+ subscribe: (t, f) => s.subscribeToForm(t, f)
341
342
  };
342
- }, W = ({ manager: o }) => (p(() => {
343
- o.activate();
343
+ }, W = ({ manager: n }) => (p(() => {
344
+ n.activate();
344
345
  }, []), S(() => () => {
345
- o.disactivate();
346
- }, []), /* @__PURE__ */ b(D.Provider, { value: o, children: /* @__PURE__ */ b(C, { scheme: o.scheme, path: [] }) })), $ = (o) => {
346
+ n.disactivate();
347
+ }, []), /* @__PURE__ */ h(D.Provider, { value: n, children: /* @__PURE__ */ h(C, { scheme: n.scheme, path: [] }) })), $ = (n) => {
347
348
  try {
348
- o();
349
+ n();
349
350
  } catch (e) {
350
351
  return e && typeof e == "string" ? {
351
352
  error: !0,
@@ -357,50 +358,50 @@ const D = P({}), q = (o) => {
357
358
  error: !0
358
359
  };
359
360
  }
360
- }, X = (o) => (e, r) => {
361
- const n = o.getRequireCheck(r), { $rules: t = {}, ...f } = r, { validate: h, required: x } = t;
361
+ }, X = (n) => (e, r) => {
362
+ const s = n.getRequireCheck(r), { $rules: t = {}, ...f } = r, { validate: b, required: m } = t;
362
363
  return {
363
364
  type: "form",
364
365
  name: e,
365
- defaultValue: o.defaultValue,
366
- Form: o.getForm(f),
366
+ defaultValue: n.defaultValue,
367
+ Form: n.getForm(f),
367
368
  validate: (y) => {
368
- if (x) {
369
- const v = $(() => n(y));
369
+ if (m) {
370
+ const v = $(() => s(y));
370
371
  if (v)
371
372
  return v;
372
- if (h) {
373
- const d = $(() => h(y));
373
+ if (b) {
374
+ const d = $(() => b(y));
374
375
  if (d)
375
376
  return d;
376
377
  }
377
378
  return;
378
379
  }
379
- if (h && !$(() => n(y))) {
380
- const d = $(() => h(y));
380
+ if (b && !$(() => s(y))) {
381
+ const d = $(() => b(y));
381
382
  if (d)
382
383
  return d;
383
384
  }
384
385
  }
385
386
  };
386
- }, Y = (o) => (e) => (...r) => ({
387
+ }, Y = (n) => (e) => (...r) => ({
387
388
  type: "layout",
388
- Layout: o(e),
389
+ Layout: n(e),
389
390
  childs: r
390
391
  }), Z = ({
391
- getItems: o,
392
+ getItems: n,
392
393
  getController: e
393
394
  }) => ({
394
395
  type: "extra",
395
- items: o((r) => (n) => ({ type: "registry", name: r, getForm: n })),
396
+ items: n((r) => (s) => ({ type: "registry", name: r, getForm: s })),
396
397
  getController: e
397
- }), _ = (o) => (...e) => ({
398
+ }), _ = (n) => (...e) => ({
398
399
  type: "context",
399
- context: o,
400
+ context: n,
400
401
  childs: e
401
- }), k = (o, e) => (...r) => ({
402
+ }), k = (n, e) => (...r) => ({
402
403
  type: "condition",
403
- depended: o,
404
+ depended: n,
404
405
  canActivate: e.canActivate,
405
406
  childs: r
406
407
  });
@@ -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
@@ -45,10 +45,12 @@ declare const useDynamicForm: (scheme: SchemeItems.All[], opts: MainOptions<Fiel
45
45
  message: string;
46
46
  }) => void;
47
47
  setValue: <K extends string>(name: K, value: any) => void;
48
+ getValue: <K extends string>(name: K) => any;
48
49
  getValues: () => {
49
50
  [x: string]: any;
50
51
  };
51
52
  handleSubmit: () => Promise<void>;
53
+ subscribe: <K extends string>(name: K, callback: (value: any) => void) => () => void;
52
54
  };
53
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>) => {
54
56
  manager: FormManager<Values, FlattenValues, Cloned>;
@@ -60,8 +62,10 @@ declare const useForm: <Items extends SchemeItems.All[], Values extends ExtractV
60
62
  message: string;
61
63
  }) => void;
62
64
  setValue: <K extends keyof FlattenValues>(name: K, value: FlattenValues[K]) => void;
65
+ getValue: <K extends keyof FlattenValues>(name: K & string) => FlattenValues[K];
63
66
  getValues: () => DeepPartial<Cloned>;
64
67
  handleSubmit: () => Promise<void>;
68
+ subscribe: <K extends keyof FlattenValues>(name: K & string, callback: (value: FlattenValues[K]) => void) => () => void;
65
69
  };
66
70
  interface Props {
67
71
  manager: FormManager<any, any, any>;
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@companix/formkit",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "module": "./dist/bundle.es.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "type": "module",
7
- "author": "Pavel Victorov.",
7
+ "author": "Pavel Victorov",
8
8
  "files": [
9
9
  "dist"
10
10
  ],