@companix/formkit 0.0.23 → 0.0.25

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