@companix/formkit 0.0.25 → 0.0.27

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
@@ -39,7 +39,7 @@ const D = M({}), q = (o) => {
39
39
  $(() => () => {
40
40
  t();
41
41
  }, []);
42
- const { value: g, error: m } = s.getForm(r);
42
+ const { value: g, error: V } = s.getForm(r);
43
43
  return /* @__PURE__ */ h(
44
44
  o,
45
45
  {
@@ -53,7 +53,7 @@ const D = M({}), q = (o) => {
53
53
  ref: l
54
54
  },
55
55
  isDirty: !1,
56
- error: m,
56
+ error: V,
57
57
  disabled: s.disabled
58
58
  }
59
59
  );
@@ -68,7 +68,7 @@ const D = M({}), q = (o) => {
68
68
  return s.forEach(({ name: b }) => {
69
69
  t.getForm([...r, b].join(".")).value !== void 0 && f.push(b);
70
70
  }), f;
71
- }, []), m = C(() => g(), []), [y, v] = w(m);
71
+ }, []), V = C(() => g(), []), [y, v] = w(V);
72
72
  $(() => {
73
73
  const { unregistry: f } = t.registryExtraForm(
74
74
  s.map(({ name: b }) => [...r, b].join(".")),
@@ -91,12 +91,12 @@ const D = M({}), q = (o) => {
91
91
  return /* @__PURE__ */ B(j, { children: [
92
92
  y.map((f) => {
93
93
  const b = l[f];
94
- return /* @__PURE__ */ h(V, { path: r, scheme: [b] }, `param-form--${f}`);
94
+ return /* @__PURE__ */ h(E, { path: r, scheme: [b] }, `param-form--${f}`);
95
95
  }),
96
96
  e(d, y)
97
97
  ] });
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,
98
+ }, E = ({ scheme: o, path: r }) => /* @__PURE__ */ h(j, { children: o.map((e, s) => e.type === "layout" ? /* @__PURE__ */ h(e.Layout, { children: /* @__PURE__ */ h(E, { path: r, scheme: e.childs }) }, `layout-form--${s}-${r.length}`) : e.type === "context" ? /* @__PURE__ */ h(
99
+ E,
100
100
  {
101
101
  path: [...r, e.context],
102
102
  scheme: e.childs
@@ -107,39 +107,39 @@ const D = M({}), q = (o) => {
107
107
  {
108
108
  name: e.depended,
109
109
  canActivate: e.canActivate,
110
- children: /* @__PURE__ */ h(V, { path: r, scheme: e.childs })
110
+ children: /* @__PURE__ */ h(E, { path: r, scheme: e.childs })
111
111
  },
112
112
  `condition--${s}-${e.depended}-${r.length}`
113
- ) : e.type === "extra" ? /* @__PURE__ */ h(z, { path: r, item: e }, `partial-item--${s}-${r.length}`) : e.type === "visability" ? e.hidden ? null : /* @__PURE__ */ h(V, { path: r, scheme: e.childs }, `visability--${s}-${r.length}`) : /* @__PURE__ */ h(
113
+ ) : e.type === "extra" ? /* @__PURE__ */ h(z, { path: r, item: e }, `partial-item--${s}-${r.length}`) : e.type === "visability" ? e.hidden ? null : /* @__PURE__ */ h(E, { path: r, scheme: e.childs }, `visability--${s}-${r.length}`) : /* @__PURE__ */ h(
114
114
  U,
115
115
  {
116
116
  name: [...r, e.name].join("."),
117
117
  item: e
118
118
  },
119
119
  `form-item--${s}-${e.name}-${r.length}`
120
- )) }), E = (o, r, e, s) => {
120
+ )) }), p = (o, r, e, s) => {
121
121
  o.forEach((t) => {
122
122
  if (t.type === "form" && s(t, [...r, t.name].join("."), e[t.name]), t.type === "context") {
123
- E(t.childs, [...r, t.context], e[t.context] ?? {}, s);
123
+ p(t.childs, [...r, t.context], e[t.context] ?? {}, s);
124
124
  return;
125
125
  }
126
126
  if (t.type === "layout" || t.type === "condition" || t.type === "visability") {
127
- E(t.childs, r, e, s);
127
+ p(t.childs, r, e, s);
128
128
  return;
129
129
  }
130
130
  t.type === "extra" && t.items.forEach(({ getForm: l, name: g }) => {
131
- E([l(g, () => {
131
+ p([l(g, () => {
132
132
  })], r, e, s);
133
133
  });
134
134
  });
135
- }, p = ({ scheme: o, values: r, path: e, forms: s }) => {
135
+ }, m = ({ scheme: o, values: r, path: e, forms: s }) => {
136
136
  o.forEach((t) => {
137
137
  if (t.type === "form") {
138
138
  const l = [...e, t.name].join(".");
139
139
  s[l].value !== void 0 && (r[t.name] = s[l].value);
140
140
  }
141
141
  if (t.type === "context") {
142
- r[t.context] = {}, p({
142
+ r[t.context] = {}, m({
143
143
  scheme: t.childs,
144
144
  path: [...e, t.context],
145
145
  values: r[t.context],
@@ -148,26 +148,30 @@ const D = M({}), q = (o) => {
148
148
  return;
149
149
  }
150
150
  if (t.type === "layout") {
151
- p({ scheme: t.childs, path: e, values: r, forms: s });
151
+ m({ scheme: t.childs, path: e, values: r, forms: s });
152
+ return;
153
+ }
154
+ if (t.type === "visability") {
155
+ m({ scheme: t.childs, path: e, values: r, forms: s });
152
156
  return;
153
157
  }
154
158
  if (t.type === "condition") {
155
159
  const l = s[t.depended]?.value;
156
160
  if (t.canActivate(l)) {
157
- p({ scheme: t.childs, path: e, values: r, forms: s });
161
+ m({ scheme: t.childs, path: e, values: r, forms: s });
158
162
  return;
159
163
  }
160
164
  }
161
165
  t.type === "extra" && t.items.forEach(({ getForm: l, name: g }) => {
162
- p({ scheme: [l(g, () => {
166
+ m({ scheme: [l(g, () => {
163
167
  })], path: e, values: r, forms: s });
164
168
  });
165
169
  });
166
170
  }, T = (o, r) => {
167
171
  const e = {};
168
- return p({ scheme: o, path: [], values: e, forms: r }), e;
172
+ return m({ scheme: o, path: [], values: e, forms: r }), e;
169
173
  }, G = (o, r) => {
170
- const { onSubmit: e, onEqual: s, disabled: t, onDirty: l, onFormDirty: g, onChangeEvent: m, defaultValues: y } = r, v = { onSubmit: e }, d = {
174
+ const { onSubmit: e, onEqual: s, disabled: t, onDirty: l, onFormDirty: g, onChangeEvent: V, defaultValues: y } = r, v = { onSubmit: e }, d = {
171
175
  isActive: !1,
172
176
  isSubmitted: !1,
173
177
  dirtyCount: 0
@@ -175,7 +179,7 @@ const D = M({}), q = (o) => {
175
179
  subscribers: [],
176
180
  names: {}
177
181
  };
178
- E(o, [], y ?? {}, (n, u, i) => {
182
+ p(o, [], y ?? {}, (n, u, i) => {
179
183
  a[u] = {
180
184
  error: null,
181
185
  isDirty: !1,
@@ -254,7 +258,7 @@ const D = M({}), q = (o) => {
254
258
  }
255
259
  },
256
260
  reset(n, { asDirty: u }) {
257
- E(o, [], n, (i, c, F) => {
261
+ p(o, [], n, (i, c, F) => {
258
262
  if (F === void 0 && a[c].value === void 0)
259
263
  return;
260
264
  if (f.names[c] && F === void 0) {
@@ -268,7 +272,7 @@ const D = M({}), q = (o) => {
268
272
  });
269
273
  },
270
274
  setAsDefault() {
271
- E(o, [], {}, ({}, n) => {
275
+ p(o, [], {}, ({}, n) => {
272
276
  a[n].startValue = a[n].value, a[n].isDirty = !1;
273
277
  }), d.dirtyCount = 0, d.isSubmitted = !1;
274
278
  },
@@ -305,7 +309,7 @@ const D = M({}), q = (o) => {
305
309
  },
306
310
  onChange(n, u) {
307
311
  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);
312
+ i.isDirty !== c && b(n, c), i.isDirty = c, V?.({ name: n, value: u }), (i.error || d.isSubmitted) && (i.error = i.validate(u) || null);
309
313
  const F = i.value;
310
314
  i.value = u, i.rerender(), i.subscribers.forEach(({ callback: x }) => {
311
315
  x(u, F);
@@ -348,7 +352,7 @@ const D = M({}), q = (o) => {
348
352
  o.activate();
349
353
  }, []), $(() => () => {
350
354
  o.disactivate();
351
- }, []), /* @__PURE__ */ h(D.Provider, { value: o, children: /* @__PURE__ */ h(V, { scheme: o.scheme, path: [] }) })), S = (o) => {
355
+ }, []), /* @__PURE__ */ h(D.Provider, { value: o, children: /* @__PURE__ */ h(E, { scheme: o.scheme, path: [] }) })), S = (o) => {
352
356
  try {
353
357
  o();
354
358
  } catch (r) {
@@ -363,14 +367,14 @@ const D = M({}), q = (o) => {
363
367
  };
364
368
  }
365
369
  }, X = (o) => (r, e) => {
366
- const s = o.getRequireCheck(e), { $rules: t = {}, ...l } = e, { validate: g, required: m } = t;
370
+ const s = o.getRequireCheck(e), { $rules: t = {}, ...l } = e, { validate: g, required: V } = t;
367
371
  return {
368
372
  type: "form",
369
373
  name: r,
370
374
  defaultValue: o.defaultValue,
371
375
  Form: o.getForm(l),
372
376
  validate: (y) => {
373
- if (m) {
377
+ if (V) {
374
378
  const v = S(() => s(y));
375
379
  if (v)
376
380
  return v;
@@ -4,10 +4,10 @@ type ExtractValue<T> = T extends SchemeItems.Form<infer N, infer V> ? {
4
4
  [K in N]: V;
5
5
  } : T extends SchemeItems.Layout<infer C> ? ExtractValue<C[number]> : T extends SchemeItems.Context<infer N, infer C> ? {
6
6
  [K in N]: Compute<UnionToIntersection<ExtractValue<C[number]>>>;
7
- } : T extends SchemeItems.Condition<infer C> ? Partial<ExtractValue<C[number]>> : T extends SchemeItems.Extra<string, infer C> ? Partial<ExtractValue<ReturnType<C[number]['getForm']>>> : never;
7
+ } : T extends SchemeItems.Condition<infer C> ? Partial<ExtractValue<C[number]>> : T extends SchemeItems.Visablility<infer C> ? Partial<ExtractValue<C[number]>> : T extends SchemeItems.Extra<string, infer C> ? Partial<ExtractValue<ReturnType<C[number]['getForm']>>> : never;
8
8
  type ExtractValues<T> = Compute<UnionToIntersection<ExtractValue<T>>>;
9
9
  type ExtractFlatValue<T, A extends string | null> = T extends SchemeItems.Form<infer N, infer V> ? {
10
10
  [K in A extends null ? N : `${A}.${N}`]: V;
11
- } : T extends SchemeItems.Layout<infer C> ? ExtractFlatValue<C[number], A> : T extends SchemeItems.Context<infer N, infer C> ? ExtractFlatValue<C[number], A extends null ? N : `${A}.${N}`> : T extends SchemeItems.Condition<infer C> ? Partial<ExtractFlatValue<C[number], A>> : T extends SchemeItems.Extra<string, infer C> ? Partial<ExtractValue<ReturnType<C[number]['getForm']>>> : never;
11
+ } : T extends SchemeItems.Layout<infer C> ? ExtractFlatValue<C[number], A> : T extends SchemeItems.Context<infer N, infer C> ? ExtractFlatValue<C[number], A extends null ? N : `${A}.${N}`> : T extends SchemeItems.Condition<infer C> ? Partial<ExtractFlatValue<C[number], A>> : T extends SchemeItems.Visablility<infer C> ? Partial<ExtractFlatValue<C[number], A>> : T extends SchemeItems.Extra<string, infer C> ? Partial<ExtractValue<ReturnType<C[number]['getForm']>>> : never;
12
12
  type ExtractFlatValues<T> = Compute<UnionToIntersection<ExtractFlatValue<T, null>>>;
13
13
  export type { ExtractValues, ExtractFlatValues };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@companix/formkit",
3
- "version": "0.0.25",
3
+ "version": "0.0.27",
4
4
  "module": "./dist/bundle.es.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "type": "module",