@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.
- package/dist/changelog/versions/components/index.d.ts.map +1 -1
- package/dist/changelog/versions/components/v2.0.31.d.ts +4 -0
- package/dist/changelog/versions/components/v2.0.31.d.ts.map +1 -0
- package/dist/changelog/versions/components/v2.0.32.d.ts +4 -0
- package/dist/changelog/versions/components/v2.0.32.d.ts.map +1 -0
- package/dist/document-input/DocumentAutoComplete.vue.d.ts +43 -1
- package/dist/document-input/DocumentAutoComplete.vue.d.ts.map +1 -1
- package/dist/document-input/DocumentAutoComplete.vue.js +110 -111
- package/dist/document-input/DocumentInput.vue.d.ts +35 -0
- package/dist/document-input/DocumentInput.vue.d.ts.map +1 -1
- package/dist/document-input/DocumentInput.vue.js +124 -108
- package/dist/index.css +1 -1
- package/package.json +1 -1
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { defineComponent as te, useId as
|
|
2
|
-
import { cn as
|
|
3
|
-
import { AtCheckCircleRegularIcon as
|
|
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
|
|
9
|
-
const
|
|
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
|
-
},
|
|
12
|
+
}, Te = /* @__PURE__ */ te({
|
|
13
13
|
inheritAttrs: !1,
|
|
14
14
|
__name: "DocumentInput",
|
|
15
15
|
props: {
|
|
16
16
|
id: {},
|
|
17
17
|
modelValue: {},
|
|
18
|
-
documentType: { default: "
|
|
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(
|
|
36
|
-
const e =
|
|
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
|
-
),
|
|
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
|
-
}),
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
|
78
|
+
function j(t) {
|
|
63
79
|
return t.replace(/[^A-Z0-9]/gi, "");
|
|
64
80
|
}
|
|
65
|
-
function
|
|
66
|
-
const
|
|
67
|
-
return
|
|
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,
|
|
70
|
-
if (!
|
|
71
|
-
let
|
|
72
|
-
if (!
|
|
73
|
-
let
|
|
74
|
-
for (let i = 0; i <
|
|
75
|
-
const
|
|
76
|
-
|
|
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
|
|
94
|
+
return c;
|
|
79
95
|
}
|
|
80
|
-
function
|
|
81
|
-
let
|
|
82
|
-
return e.customMask && e.documentType === "generic" ?
|
|
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
|
|
100
|
+
function z(t) {
|
|
85
101
|
switch (e.documentType) {
|
|
86
102
|
case "cnpj":
|
|
87
|
-
return
|
|
103
|
+
return P(t, e.allowAlpha);
|
|
88
104
|
case "cpf":
|
|
89
|
-
return
|
|
105
|
+
return $(t);
|
|
90
106
|
case "cpf-cnpj": {
|
|
91
|
-
const
|
|
92
|
-
if (!
|
|
93
|
-
const
|
|
94
|
-
return e.allowAlpha &&
|
|
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
|
|
113
|
+
return O(t);
|
|
98
114
|
}
|
|
99
115
|
}
|
|
100
|
-
function
|
|
116
|
+
function G(t) {
|
|
101
117
|
if (e.unmask) {
|
|
102
|
-
if (
|
|
103
|
-
return
|
|
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
|
|
110
|
-
const
|
|
111
|
-
s("update:modelValue",
|
|
125
|
+
function H(t) {
|
|
126
|
+
const l = G(t);
|
|
127
|
+
s("update:modelValue", l), s("change", l);
|
|
112
128
|
}
|
|
113
|
-
function
|
|
129
|
+
function S(t) {
|
|
114
130
|
switch (e.documentType) {
|
|
115
131
|
case "cnpj":
|
|
116
|
-
s("validate",
|
|
132
|
+
s("validate", g(t));
|
|
117
133
|
break;
|
|
118
134
|
case "cpf":
|
|
119
|
-
s("validate",
|
|
135
|
+
s("validate", v(t));
|
|
120
136
|
break;
|
|
121
137
|
case "cpf-cnpj":
|
|
122
|
-
s("validate",
|
|
138
|
+
s("validate", X(t));
|
|
123
139
|
break;
|
|
124
140
|
}
|
|
125
141
|
}
|
|
126
|
-
|
|
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
|
|
132
|
-
|
|
147
|
+
const l = z(t);
|
|
148
|
+
l !== r.value && (r.value = l);
|
|
133
149
|
}
|
|
134
150
|
);
|
|
135
|
-
function J(t,
|
|
136
|
-
const
|
|
137
|
-
let
|
|
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
|
|
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 (;
|
|
142
|
-
|
|
157
|
+
for (; o < n.length && !/[A-Z0-9]/i.test(n[o]); )
|
|
158
|
+
o++;
|
|
143
159
|
}
|
|
144
|
-
t.value !==
|
|
160
|
+
t.value !== n && (t.value = n, t.setSelectionRange(o, o));
|
|
145
161
|
}
|
|
146
|
-
function K(t,
|
|
147
|
-
const
|
|
148
|
-
t.value !==
|
|
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
|
-
|
|
152
|
-
const
|
|
153
|
-
|
|
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),
|
|
173
|
+
_.value = !0, s("blur", t), S(r.value);
|
|
158
174
|
}, ee = () => {
|
|
159
|
-
|
|
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
|
|
177
|
+
return D({
|
|
162
178
|
input: U,
|
|
163
|
-
localValue:
|
|
164
|
-
}), (t,
|
|
165
|
-
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 ? (
|
|
183
|
+
e.label ? (d(), w(p(pe), {
|
|
168
184
|
key: 0,
|
|
169
|
-
for: p(
|
|
170
|
-
class:
|
|
171
|
-
p(
|
|
185
|
+
for: p(y),
|
|
186
|
+
class: b(
|
|
187
|
+
p(T)(
|
|
172
188
|
"text-[#101011] font-normal text-[10px] leading-[10px]",
|
|
173
|
-
|
|
189
|
+
f.value ? "text-[var(--alert-red-dark,#831511)]" : ""
|
|
174
190
|
)
|
|
175
191
|
)
|
|
176
192
|
}, {
|
|
177
|
-
default:
|
|
178
|
-
|
|
179
|
-
e.required ? (
|
|
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
|
-
|
|
184
|
-
|
|
185
|
-
id: p(
|
|
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":
|
|
204
|
+
"model-value": r.value,
|
|
189
205
|
disabled: e.disabled,
|
|
190
|
-
class: p(
|
|
191
|
-
placeholder: e.placeholder ??
|
|
192
|
-
"aria-invalid":
|
|
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 && !
|
|
195
|
-
e.description ?
|
|
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 ||
|
|
203
|
-
Z.value ? (
|
|
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
|
-
})) :
|
|
223
|
+
})) : (f.value || r.value) && !e.disabled && e.withClearIcon ? (d(), w(p(se), {
|
|
208
224
|
key: 1,
|
|
209
225
|
size: "20",
|
|
210
|
-
class:
|
|
211
|
-
p(
|
|
226
|
+
class: b(
|
|
227
|
+
p(T)(
|
|
212
228
|
"cursor-pointer transition-opacity hover:opacity-80",
|
|
213
|
-
|
|
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 ? (
|
|
236
|
+
e.description && !e.error ? (d(), h("div", {
|
|
221
237
|
key: 1,
|
|
222
|
-
id:
|
|
238
|
+
id: I,
|
|
223
239
|
class: "text-gray-500 text-[11px] leading-tight"
|
|
224
|
-
},
|
|
225
|
-
typeof e.error == "string" &&
|
|
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:
|
|
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
|
-
|
|
246
|
+
E(p(ie), {
|
|
231
247
|
size: "14",
|
|
232
248
|
class: "text-[var(--alert-red-dark,#831511)] shrink-0"
|
|
233
249
|
}),
|
|
234
|
-
|
|
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
|
-
|
|
256
|
+
Te as default
|
|
241
257
|
};
|