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