@agrotools1/at-components 2.0.30 → 2.0.32

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.
@@ -1,21 +1,21 @@
1
- import { defineComponent as te, useId as ae, ref as k, computed as A, watch as le, createElementBlock as v, openBlock as f, normalizeClass as x, unref as p, createBlock as b, createCommentVNode as m, createElementVNode as E, withCtx as re, createTextVNode as ne, toDisplayString as j, createVNode as R, mergeProps as ce } from "vue";
2
- import { cn as C } from "../lib/utils.js";
3
- import { AtCheckCircleRegularIcon as oe } from "../packages/at-icons/dist/AtCheckCircleRegularIcon/index.js";
1
+ import { defineComponent as te, useId as le, ref as k, computed as x, watch as ae, createElementBlock as h, openBlock as d, normalizeClass as b, unref as p, createBlock as w, createCommentVNode as m, createElementVNode as R, withCtx as ne, createTextVNode as re, toDisplayString as V, createVNode as E, mergeProps as oe } from "vue";
2
+ import { cn as T } from "../lib/utils.js";
3
+ import { AtCheckCircleRegularIcon as ce } from "../packages/at-icons/dist/AtCheckCircleRegularIcon/index.js";
4
4
  import { AtCircleXMarkRegularIcon as se } from "../packages/at-icons/dist/AtCircleXMarkRegularIcon/index.js";
5
5
  import { AtCircleXMarkSolidIcon as ie } from "../packages/at-icons/dist/AtCircleXMarkSolidIcon/index.js";
6
6
  import ue from "../input/Input.vue.js";
7
7
  import pe from "../label/Label.vue.js";
8
- import { isValidCpf as T, isValidCnpj as _, applyCnpjMask as N, applyCpfMask as P } from "./utils.js";
9
- const de = { key: 0 }, fe = { class: "relative flex items-center" }, me = {
8
+ import { isValidCpf as v, isValidCnpj as g, applyCnpjMask as P, applyCpfMask as $ } from "./utils.js";
9
+ const fe = { key: 0 }, de = { class: "relative flex items-center" }, me = {
10
10
  key: 0,
11
11
  class: "absolute right-2.5 flex items-center justify-center"
12
- }, be = /* @__PURE__ */ te({
12
+ }, Te = /* @__PURE__ */ te({
13
13
  inheritAttrs: !1,
14
14
  __name: "DocumentInput",
15
15
  props: {
16
16
  id: {},
17
17
  modelValue: {},
18
- documentType: { default: "generic" },
18
+ documentType: { default: "cpf-cnpj" },
19
19
  label: {},
20
20
  description: {},
21
21
  required: { type: Boolean },
@@ -23,19 +23,21 @@ const de = { key: 0 }, fe = { class: "relative flex items-center" }, me = {
23
23
  error: { type: [Boolean, String], default: !1 },
24
24
  success: { type: Boolean, default: !1 },
25
25
  allowAlpha: { type: Boolean, default: !1 },
26
+ withInternalValidation: { type: Boolean, default: !1 },
26
27
  placeholder: {},
27
28
  maxLength: {},
28
29
  toUpperCase: { type: Boolean, default: !1 },
29
30
  unmask: { type: Boolean, default: !0 },
30
31
  customMask: {},
31
32
  class: {},
32
- inputClass: {}
33
+ inputClass: {},
34
+ withClearIcon: { type: Boolean, default: !0 }
33
35
  },
34
36
  emits: ["update:modelValue", "change", "blur", "focus", "validate", "clear"],
35
- setup($, { expose: L, emit: D }) {
36
- const e = $, s = D, h = e.id || ae(), w = `error-${h}`, V = `desc-${h}`, n = k(e.modelValue || ""), g = k(!1), B = A(
37
+ setup(N, { expose: D, emit: F }) {
38
+ const e = N, s = F, y = e.id || le(), B = `error-${y}`, I = `desc-${y}`, r = k(e.modelValue || ""), A = k(!1), _ = k(!1), M = x(
37
39
  () => e.documentType === "cnpj" || e.documentType === "cpf" || e.documentType === "cpf-cnpj"
38
- ), F = A(() => {
40
+ ), L = x(() => {
39
41
  switch (e.documentType) {
40
42
  case "cnpj":
41
43
  return e.allowAlpha ? "AA.AAA.AAA/AAAA-DV" : "00.000.000/0000-00";
@@ -46,196 +48,210 @@ const de = { key: 0 }, fe = { class: "relative flex items-center" }, me = {
46
48
  default:
47
49
  return;
48
50
  }
49
- }), d = A(() => !!e.error && !g.value), M = { cnpj: 18, cpf: 14 }, Z = A(() => {
50
- if (!e.success || d.value || !n.value) return !1;
51
- switch (e.documentType) {
52
- case "cnpj":
53
- return n.value.length === M.cnpj && _(n.value);
54
- case "cpf":
55
- return n.value.length === M.cpf && T(n.value);
56
- case "cpf-cnpj":
57
- return I(n.value);
58
- default:
51
+ }), f = x(() => {
52
+ if (e.error) return !0;
53
+ if (e.withInternalValidation) {
54
+ if (!r.value || A.value) return !1;
55
+ const t = r.value.replace(/[^A-Z0-9]/gi, "");
56
+ if (!t) return !1;
57
+ if (t.length === 11 && !v(t) || t.length === 14 && !g(t) || _.value && (e.documentType === "cpf" && t.length !== 11 || e.documentType === "cnpj" && t.length !== 14 || e.documentType === "cpf-cnpj" && t.length !== 11 && t.length !== 14))
59
58
  return !0;
60
59
  }
60
+ return !1;
61
+ }), Z = x(() => {
62
+ if (f.value) return !1;
63
+ if (e.success) {
64
+ if (!r.value) return !1;
65
+ const t = j(r.value);
66
+ return !(e.documentType === "cpf" && t.length !== 11 || e.documentType === "cnpj" && t.length !== 14 || e.documentType === "cpf-cnpj" && t.length !== 11 && t.length !== 14);
67
+ }
68
+ if (e.withInternalValidation) {
69
+ if (!r.value) return !1;
70
+ const t = j(r.value);
71
+ if (e.documentType === "cpf") return v(t);
72
+ if (e.documentType === "cnpj") return g(t);
73
+ if (e.documentType === "cpf-cnpj")
74
+ return t.length === 11 ? v(t) : g(t);
75
+ }
76
+ return !1;
61
77
  });
62
- function X(t) {
78
+ function j(t) {
63
79
  return t.replace(/[^A-Z0-9]/gi, "");
64
80
  }
65
- function I(t) {
66
- const a = t.replace(e.allowAlpha ? /[^A-Z0-9]/gi : /[^0-9]/g, "");
67
- return a.length === 11 ? T(a) : a.length === 14 ? _(a) : !1;
81
+ function X(t) {
82
+ const l = t.replace(e.allowAlpha ? /[^A-Z0-9]/gi : /[^0-9]/g, "");
83
+ return l.length === 11 ? v(l) : l.length === 14 ? g(l) : !1;
68
84
  }
69
- function q(t, a) {
70
- if (!a) return t;
71
- let r = t.replace(/[^0-9A-Za-z]/g, "");
72
- if (!r) return "";
73
- let o = "", l = 0;
74
- for (let i = 0; i < a.length && l < r.length; i++) {
75
- const c = a[i], u = r[l];
76
- c === "9" ? /[0-9]/.test(u) ? (o += u, l++) : (l++, i--) : c === "A" ? /[A-Za-z]/.test(u) ? (o += e.toUpperCase ? u.toUpperCase() : u, l++) : (l++, i--) : c === "X" ? /[0-9A-Za-z]/.test(u) ? (o += e.toUpperCase ? u.toUpperCase() : u, l++) : (l++, i--) : o += c;
85
+ function q(t, l) {
86
+ if (!l) return t;
87
+ let n = t.replace(/[^0-9A-Za-z]/g, "");
88
+ if (!n) return "";
89
+ let c = "", a = 0;
90
+ for (let i = 0; i < l.length && a < n.length; i++) {
91
+ const o = l[i], u = n[a];
92
+ o === "9" ? /[0-9]/.test(u) ? (c += u, a++) : (a++, i--) : o === "A" ? /[A-Za-z]/.test(u) ? (c += e.toUpperCase ? u.toUpperCase() : u, a++) : (a++, i--) : o === "X" ? /[0-9A-Za-z]/.test(u) ? (c += e.toUpperCase ? u.toUpperCase() : u, a++) : (a++, i--) : c += o;
77
93
  }
78
- return o;
94
+ return c;
79
95
  }
80
- function G(t) {
81
- let a = t;
82
- return e.customMask && e.documentType === "generic" ? a = q(a, e.customMask) : (e.toUpperCase && (a = a.toUpperCase()), e.maxLength !== void 0 && a.length > e.maxLength && (a = a.slice(0, e.maxLength))), a;
96
+ function O(t) {
97
+ let l = t;
98
+ return e.customMask && e.documentType === "generic" ? l = q(l, e.customMask) : (e.toUpperCase && (l = l.toUpperCase()), e.maxLength !== void 0 && l.length > e.maxLength && (l = l.slice(0, e.maxLength))), l;
83
99
  }
84
- function S(t) {
100
+ function z(t) {
85
101
  switch (e.documentType) {
86
102
  case "cnpj":
87
- return N(t, e.allowAlpha);
103
+ return P(t, e.allowAlpha);
88
104
  case "cpf":
89
- return P(t);
105
+ return $(t);
90
106
  case "cpf-cnpj": {
91
- const a = t.replace(e.allowAlpha ? /[^A-Z0-9]/gi : /[^0-9]/g, "").slice(0, 14);
92
- if (!a) return "";
93
- const r = /[A-Z]/i.test(a);
94
- return e.allowAlpha && r || a.length > 11 ? N(a, e.allowAlpha) : P(a);
107
+ const l = t.replace(e.allowAlpha ? /[^A-Z0-9]/gi : /[^0-9]/g, "").slice(0, 14);
108
+ if (!l) return "";
109
+ const n = /[A-Z]/i.test(l);
110
+ return e.allowAlpha && n || l.length > 11 ? P(l, e.allowAlpha) : $(l);
95
111
  }
96
112
  default:
97
- return G(t);
113
+ return O(t);
98
114
  }
99
115
  }
100
- function H(t) {
116
+ function G(t) {
101
117
  if (e.unmask) {
102
- if (B.value)
103
- return X(t);
118
+ if (M.value)
119
+ return j(t);
104
120
  if (e.documentType === "generic" || e.documentType === "cpf-cnpj")
105
121
  return e.customMask && e.documentType === "generic" || e.documentType === "cpf-cnpj" && e.allowAlpha ? t.replace(/[^0-9A-Za-z]/g, "") : t.replace(/[^0-9]/g, "");
106
122
  }
107
123
  return t;
108
124
  }
109
- function O(t) {
110
- const a = H(t);
111
- s("update:modelValue", a), s("change", a);
125
+ function H(t) {
126
+ const l = G(t);
127
+ s("update:modelValue", l), s("change", l);
112
128
  }
113
- function z(t) {
129
+ function S(t) {
114
130
  switch (e.documentType) {
115
131
  case "cnpj":
116
- s("validate", _(t));
132
+ s("validate", g(t));
117
133
  break;
118
134
  case "cpf":
119
- s("validate", T(t));
135
+ s("validate", v(t));
120
136
  break;
121
137
  case "cpf-cnpj":
122
- s("validate", I(t));
138
+ s("validate", X(t));
123
139
  break;
124
140
  }
125
141
  }
126
- le(
142
+ ae(
127
143
  () => e.modelValue,
128
144
  (t) => {
129
145
  if (t === void 0 || e.unmask && (e.documentType === "generic" || e.documentType === "cpf-cnpj"))
130
146
  return;
131
- const a = S(t);
132
- a !== n.value && (n.value = a);
147
+ const l = z(t);
148
+ l !== r.value && (r.value = l);
133
149
  }
134
150
  );
135
- function J(t, a, r, o) {
136
- const l = e.allowAlpha ? /[A-Z0-9]/gi : /[0-9]/g, i = (a.slice(0, o).match(l) || []).length;
137
- let c = 0, u = 0;
151
+ function J(t, l, n, c) {
152
+ const a = e.allowAlpha ? /[A-Z0-9]/gi : /[0-9]/g, i = (l.slice(0, c).match(a) || []).length;
153
+ let o = 0, u = 0;
138
154
  if (i > 0) {
139
- for (let y = 0; y < r.length && (/[A-Z0-9]/i.test(r[y]) && u++, c = y + 1, !(u >= i)); y++)
155
+ for (let C = 0; C < n.length && (/[A-Z0-9]/i.test(n[C]) && u++, o = C + 1, !(u >= i)); C++)
140
156
  ;
141
- for (; c < r.length && !/[A-Z0-9]/i.test(r[c]); )
142
- c++;
157
+ for (; o < n.length && !/[A-Z0-9]/i.test(n[o]); )
158
+ o++;
143
159
  }
144
- t.value !== r && (t.value = r, t.setSelectionRange(c, c));
160
+ t.value !== n && (t.value = n, t.setSelectionRange(o, o));
145
161
  }
146
- function K(t, a, r, o) {
147
- const l = e.allowAlpha ? /[A-Za-z0-9]/g : /[0-9]/g, i = (a.slice(0, o).match(l) || []).length, c = Math.min(i, r.length);
148
- t.value !== r && (t.value = r, t.setSelectionRange(c, c));
162
+ function K(t, l, n, c) {
163
+ const a = e.allowAlpha ? /[A-Za-z0-9]/g : /[0-9]/g, i = (l.slice(0, c).match(a) || []).length, o = Math.min(i, n.length);
164
+ t.value !== n && (t.value = n, t.setSelectionRange(o, o));
149
165
  }
150
166
  const Q = (t) => {
151
- g.value = !1;
152
- const a = t.target, r = a.value, o = a.selectionStart || 0, l = S(r);
153
- B.value ? J(a, r, l, o) : e.documentType === "cpf-cnpj" ? K(a, r, l, o) : a.value !== l && (a.value = l), n.value !== l && (n.value = l, O(l), z(l));
167
+ A.value = !1;
168
+ const l = t.target, n = l.value, c = l.selectionStart || 0, a = z(n);
169
+ M.value ? J(l, n, a, c) : e.documentType === "cpf-cnpj" ? K(l, n, a, c) : l.value !== a && (l.value = a), r.value !== a && (r.value = a, H(a), S(a));
154
170
  }, W = (t) => {
155
171
  s("focus", t);
156
172
  }, Y = (t) => {
157
- s("blur", t), z(n.value);
173
+ _.value = !0, s("blur", t), S(r.value);
158
174
  }, ee = () => {
159
- n.value = "", g.value = !0, s("update:modelValue", ""), s("change", ""), s("clear"), e.documentType !== "generic" && s("validate", !1);
175
+ r.value = "", A.value = !0, s("update:modelValue", ""), s("change", ""), s("clear"), e.documentType !== "generic" && s("validate", !1);
160
176
  }, U = k(null);
161
- return L({
177
+ return D({
162
178
  input: U,
163
- localValue: n
164
- }), (t, a) => (f(), v("div", {
165
- class: x(p(C)("space-y-1.5 w-full", e.class))
179
+ localValue: r
180
+ }), (t, l) => (d(), h("div", {
181
+ class: b(p(T)("space-y-1.5 w-full", e.class))
166
182
  }, [
167
- e.label ? (f(), b(p(pe), {
183
+ e.label ? (d(), w(p(pe), {
168
184
  key: 0,
169
- for: p(h),
170
- class: x(
171
- p(C)(
185
+ for: p(y),
186
+ class: b(
187
+ p(T)(
172
188
  "text-[#101011] font-normal text-[10px] leading-[10px]",
173
- d.value ? "text-[var(--alert-red-dark,#831511)]" : ""
189
+ f.value ? "text-[var(--alert-red-dark,#831511)]" : ""
174
190
  )
175
191
  )
176
192
  }, {
177
- default: re(() => [
178
- ne(j(e.label), 1),
179
- e.required ? (f(), v("span", de, " (Obrigatório)")) : m("", !0)
193
+ default: ne(() => [
194
+ re(V(e.label), 1),
195
+ e.required ? (d(), h("span", fe, " (Obrigatório)")) : m("", !0)
180
196
  ]),
181
197
  _: 1
182
198
  }, 8, ["for", "class"])) : m("", !0),
183
- E("div", fe, [
184
- R(p(ue), ce({
185
- id: p(h),
199
+ R("div", de, [
200
+ E(p(ue), oe({
201
+ id: p(y),
186
202
  ref_key: "inputRef",
187
203
  ref: U,
188
- "model-value": n.value,
204
+ "model-value": r.value,
189
205
  disabled: e.disabled,
190
- class: p(C)("pr-10", d.value || e.success ? "border-[#3E2E46]" : "", e.inputClass),
191
- placeholder: e.placeholder ?? F.value,
192
- "aria-invalid": d.value,
206
+ class: p(T)("pr-10", f.value || e.success ? "border-[#3E2E46]" : "", e.inputClass),
207
+ placeholder: e.placeholder ?? L.value,
208
+ "aria-invalid": f.value,
193
209
  "aria-describedby": [
194
- e.error && !g.value ? w : void 0,
195
- e.description ? V : void 0
210
+ e.error && !A.value ? B : void 0,
211
+ e.description ? I : void 0
196
212
  ].filter(Boolean).join(" ") || void 0
197
213
  }, t.$attrs, {
198
214
  onInput: Q,
199
215
  onBlur: Y,
200
216
  onFocus: W
201
217
  }), null, 16, ["id", "model-value", "disabled", "class", "placeholder", "aria-invalid", "aria-describedby"]),
202
- Z.value || d.value || n.value ? (f(), v("div", me, [
203
- Z.value ? (f(), b(p(oe), {
218
+ Z.value || f.value || r.value ? (d(), h("div", me, [
219
+ Z.value ? (d(), w(p(ce), {
204
220
  key: 0,
205
221
  size: "20",
206
222
  class: "text-[#4b715c] pointer-events-none"
207
- })) : d.value || n.value ? (f(), b(p(se), {
223
+ })) : (f.value || r.value) && !e.disabled && e.withClearIcon ? (d(), w(p(se), {
208
224
  key: 1,
209
225
  size: "20",
210
- class: x(
211
- p(C)(
226
+ class: b(
227
+ p(T)(
212
228
  "cursor-pointer transition-opacity hover:opacity-80",
213
- d.value ? "text-[var(--alert-red-dark,#831511)]" : "text-gray-400"
229
+ f.value ? "text-[var(--alert-red-dark,#831511)]" : "text-gray-400"
214
230
  )
215
231
  ),
216
232
  onClick: ee
217
233
  }, null, 8, ["class"])) : m("", !0)
218
234
  ])) : m("", !0)
219
235
  ]),
220
- e.description && !e.error ? (f(), v("div", {
236
+ e.description && !e.error ? (d(), h("div", {
221
237
  key: 1,
222
- id: V,
238
+ id: I,
223
239
  class: "text-gray-500 text-[11px] leading-tight"
224
- }, j(e.description), 1)) : m("", !0),
225
- typeof e.error == "string" && d.value ? (f(), v("div", {
240
+ }, V(e.description), 1)) : m("", !0),
241
+ (typeof e.error == "string" || e.withInternalValidation && f.value) && f.value ? (d(), h("div", {
226
242
  key: 2,
227
- id: w,
243
+ id: B,
228
244
  class: "text-[var(--alert-red-dark,#831511)] flex items-center gap-1 text-[11px] font-medium leading-tight pt-0.5"
229
245
  }, [
230
- R(p(ie), {
246
+ E(p(ie), {
231
247
  size: "14",
232
248
  class: "text-[var(--alert-red-dark,#831511)] shrink-0"
233
249
  }),
234
- E("span", null, j(e.error), 1)
250
+ R("span", null, V(typeof e.error == "string" ? e.error : "Documento inválido"), 1)
235
251
  ])) : m("", !0)
236
252
  ], 2));
237
253
  }
238
254
  });
239
255
  export {
240
- be as default
256
+ Te as default
241
257
  };