@schwarzdavid/ui-kit 0.0.1-alpha.10 → 0.0.1-alpha.11

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/README.md CHANGED
@@ -1 +1,5 @@
1
1
  # @schwarzdavid/ui-kit
2
+
3
+ ## TODOs
4
+
5
+ - Check `useVuelidateErrors` for $each validator
@@ -1,4 +1,7 @@
1
+ import { ComputedRef } from 'vue';
1
2
  import { Ref } from 'vue';
3
+ import { Validation } from '@vuelidate/core';
4
+ import { ValidationArgs } from '@vuelidate/core';
2
5
  import { ValidationRuleWithoutParams } from '@vuelidate/core';
3
6
  import { ValidationRuleWithParams } from '@vuelidate/core';
4
7
 
@@ -54,4 +57,10 @@ otherName: string;
54
57
 
55
58
  export declare const url: ValidationRuleWithoutParams<any>;
56
59
 
60
+ export declare const useVuelidateErrors: <T extends object>(validation: Ref<Validation<ValidationArgs<T>, T>>) => ComputedRef<ValidationErrors<T>>;
61
+
62
+ export declare type ValidationErrors<T extends object> = {
63
+ [key in keyof T]: T[key] extends object ? ValidationErrors<T[key]> : string[];
64
+ };
65
+
57
66
  export { }
@@ -1,39 +1,56 @@
1
- import * as e from "@vuelidate/validators";
2
- import { helpers as n } from "@vuelidate/validators";
3
- import { useI18n as i } from "vue-i18n";
4
- const t = e.createI18nMessage({
5
- t: (...r) => {
6
- const { t: s } = i({ useScope: "global" });
7
- return s(...r);
1
+ import * as r from "@vuelidate/validators";
2
+ import { helpers as o } from "@vuelidate/validators";
3
+ import { useI18n as a } from "vue-i18n";
4
+ import { computed as m, unref as l } from "vue";
5
+ const n = r.createI18nMessage({
6
+ t: (...e) => {
7
+ const { t } = a({ useScope: "global" });
8
+ return t(...e);
8
9
  },
9
- messagePath(r) {
10
- return console.log(r.$validator), "validation." + r.$validator;
10
+ messagePath(e) {
11
+ return console.log(e.$validator), "validation." + e.$validator;
11
12
  }
12
- }), m = t(e.required), c = t(e.requiredIf, { withArguments: !0 }), l = t(e.requiredUnless, { withArguments: !0 }), d = t(e.minLength, { withArguments: !0 }), h = t(e.maxLength, { withArguments: !0 }), g = t(e.minValue, { withArguments: !0 }), A = t(e.maxValue, { withArguments: !0 }), w = t(e.between, { withArguments: !0 }), p = t(e.alpha), f = t(e.alphaNum), q = t(e.numeric), x = t(e.integer), I = t(e.decimal), V = t(e.email), b = t(e.ipAddress), y = t(e.macAddress), L = t(e.sameAs, { withArguments: !0 }), O = t(e.url), M = t((r) => n.withParams({
13
+ }), A = n(r.required), b = n(r.requiredIf, { withArguments: !0 }), V = n(r.requiredUnless, { withArguments: !0 }), O = n(r.minLength, { withArguments: !0 }), j = n(r.maxLength, { withArguments: !0 }), $ = n(r.minValue, { withArguments: !0 }), q = n(r.maxValue, { withArguments: !0 }), x = n(r.between, { withArguments: !0 }), I = n(r.alpha), y = n(r.alphaNum), L = n(r.numeric), E = n(r.integer), N = n(r.decimal), U = n(r.email), W = n(r.ipAddress), B = n(r.macAddress), M = n(r.sameAs, { withArguments: !0 }), P = n(r.url), T = n((e) => o.withParams({
13
14
  type: "oneOf",
14
- values: r
15
- }, (s) => {
16
- const a = Array.isArray(r) ? r : Object.values(r);
17
- return !n.req(s) || a.includes(s);
18
- }), { withArguments: !0 });
15
+ values: e
16
+ }, (t) => {
17
+ const s = Array.isArray(e) ? e : Object.values(e);
18
+ return !o.req(t) || s.includes(t);
19
+ }), { withArguments: !0 }), R = (e) => m(() => i(e.value));
20
+ function i(e) {
21
+ return Object.entries(e).map(([t, s]) => t.startsWith("$") ? [t, null] : f(s) ? [t, d(s)] : h(s) ? [t, i(s)] : (console.warn("Unknown validation type.", t, s), [t, null])).reduce((t, [s, u]) => (u && (t[s] = u), t), {});
22
+ }
23
+ function f(e) {
24
+ return typeof e != "object" || e === null ? !1 : Object.hasOwn(e, "$model") && Object.entries(e).filter(([t]) => !t.startsWith("$")).every(([, t]) => c(t));
25
+ }
26
+ function h(e) {
27
+ return typeof e != "object" || e === null ? !1 : Object.entries(e).filter(([t]) => !t.startsWith("$")).some(([, t]) => !c(t));
28
+ }
29
+ function c(e) {
30
+ return typeof e == "object" && e !== null && Object.hasOwn(e, "$params");
31
+ }
32
+ function d(e) {
33
+ return e.$errors.map((t) => l(t.$message));
34
+ }
19
35
  export {
20
- p as alpha,
21
- f as alphaNum,
22
- w as between,
23
- I as decimal,
24
- V as email,
25
- x as integer,
26
- b as ipAddress,
27
- y as maxAddress,
28
- h as maxLength,
29
- A as maxValue,
30
- d as minLength,
31
- g as minValue,
32
- q as numeric,
33
- M as oneOf,
34
- m as required,
35
- c as requiredIf,
36
- l as requiredUnless,
37
- L as sameAs,
38
- O as url
36
+ I as alpha,
37
+ y as alphaNum,
38
+ x as between,
39
+ N as decimal,
40
+ U as email,
41
+ E as integer,
42
+ W as ipAddress,
43
+ B as maxAddress,
44
+ j as maxLength,
45
+ q as maxValue,
46
+ O as minLength,
47
+ $ as minValue,
48
+ L as numeric,
49
+ T as oneOf,
50
+ A as required,
51
+ b as requiredIf,
52
+ V as requiredUnless,
53
+ M as sameAs,
54
+ P as url,
55
+ R as useVuelidateErrors
39
56
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schwarzdavid/ui-kit",
3
- "version": "0.0.1-alpha.10",
3
+ "version": "0.0.1-alpha.11",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "preview": "vite preview",