@agrotools1/at-components 2.0.29 → 2.0.31

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