adverich-kun-ui 0.1.582 → 0.1.583
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,13 +1,13 @@
|
|
|
1
|
-
import { reactive as
|
|
2
|
-
import { debounce as
|
|
3
|
-
import { getValue as O, formatValue as
|
|
4
|
-
function
|
|
5
|
-
const
|
|
1
|
+
import { reactive as P, ref as b, computed as g, unref as f, watch as S } from "vue";
|
|
2
|
+
import { debounce as z } from "../../../../utils/utils.js";
|
|
3
|
+
import { getValue as O, formatValue as D } from "../../../../utils/tableFormatters.js";
|
|
4
|
+
function Q(F, E, L, i = !1) {
|
|
5
|
+
const u = P({
|
|
6
6
|
search: "",
|
|
7
7
|
// Búsqueda global
|
|
8
8
|
byColumn: {}
|
|
9
9
|
// Mapa columna -> valor
|
|
10
|
-
}), { items:
|
|
10
|
+
}), { items: m, customFilter: M, searchableKeys: j, headers: G } = F, T = b(!1), y = (e) => {
|
|
11
11
|
if (e == null) return "";
|
|
12
12
|
if (typeof e == "string") return e;
|
|
13
13
|
if (typeof e == "number" || typeof e == "boolean") return String(e);
|
|
@@ -26,96 +26,105 @@ function U(F, E, L, l = !1) {
|
|
|
26
26
|
} catch {
|
|
27
27
|
return "";
|
|
28
28
|
}
|
|
29
|
-
},
|
|
30
|
-
const
|
|
31
|
-
return t ?
|
|
32
|
-
}, p =
|
|
33
|
-
const e =
|
|
29
|
+
}, w = (e, r) => {
|
|
30
|
+
const o = y(e).toLowerCase(), t = y(r).toLowerCase();
|
|
31
|
+
return t ? o === t : !0;
|
|
32
|
+
}, p = g(() => L.value ?? []), A = g(() => {
|
|
33
|
+
const e = f(j);
|
|
34
34
|
return Array.isArray(e) && e.length ? e : p.value.map((r) => r == null ? void 0 : r.value).filter(Boolean);
|
|
35
|
-
}), C =
|
|
36
|
-
function
|
|
35
|
+
}), C = b(/* @__PURE__ */ new Map());
|
|
36
|
+
function R() {
|
|
37
37
|
C.value.clear();
|
|
38
|
-
const e =
|
|
38
|
+
const e = f(m);
|
|
39
39
|
Array.isArray(e) && (e.forEach((r) => {
|
|
40
|
-
const
|
|
40
|
+
const o = {};
|
|
41
41
|
A.value.forEach((t) => {
|
|
42
|
-
const
|
|
43
|
-
let
|
|
42
|
+
const n = p.value.find((l) => l.value === t);
|
|
43
|
+
let s, c;
|
|
44
44
|
try {
|
|
45
|
-
|
|
46
|
-
} catch (
|
|
47
|
-
|
|
45
|
+
s = n ? O(n, r) : r[t];
|
|
46
|
+
} catch (l) {
|
|
47
|
+
s = "", i && console.error("[useFilter] ERROR getValue", { item: r, key: t, err: l });
|
|
48
48
|
}
|
|
49
49
|
try {
|
|
50
|
-
|
|
51
|
-
} catch (
|
|
52
|
-
|
|
50
|
+
c = n ? D(n, s) : s;
|
|
51
|
+
} catch (l) {
|
|
52
|
+
c = s, i && console.error("[useFilter] ERROR formatValue", { header: n, raw: s, err: l });
|
|
53
53
|
}
|
|
54
|
-
|
|
55
|
-
}), C.value.set(r,
|
|
56
|
-
}),
|
|
54
|
+
o[t] = y(c).toLowerCase();
|
|
55
|
+
}), C.value.set(r, o);
|
|
56
|
+
}), i && console.log("[useFilter] Cache reconstruida", C.value));
|
|
57
57
|
}
|
|
58
|
-
|
|
58
|
+
S(() => f(m), () => R(), { immediate: !0 }), S(() => {
|
|
59
59
|
var e;
|
|
60
|
-
return (e =
|
|
61
|
-
}, () =>
|
|
62
|
-
const
|
|
63
|
-
const t =
|
|
64
|
-
if (typeof
|
|
65
|
-
const
|
|
60
|
+
return (e = f(m)) == null ? void 0 : e.length;
|
|
61
|
+
}, () => R());
|
|
62
|
+
const x = (e, r, o) => {
|
|
63
|
+
const t = V(e, r), n = f(M);
|
|
64
|
+
if (typeof n == "function") {
|
|
65
|
+
const a = p.value.find((h) => (h == null ? void 0 : h.value) === r);
|
|
66
66
|
try {
|
|
67
|
-
return
|
|
68
|
-
} catch (
|
|
69
|
-
return
|
|
67
|
+
return n(e, r, o, a);
|
|
68
|
+
} catch (h) {
|
|
69
|
+
return i && console.error("[matchesFilter] ERROR customFilter", { item: e, key: r, value: o, header: a, err: h }), !1;
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
const
|
|
73
|
-
return Array.isArray(
|
|
74
|
-
},
|
|
75
|
-
const e =
|
|
72
|
+
const s = f(F.filters) ?? F.filters, c = Array.isArray(s) ? s.find((a) => a.value === r) : void 0, l = (c == null ? void 0 : c["item-value"]) ?? "id", d = (a) => a != null && typeof a == "object" ? a[l] : a;
|
|
73
|
+
return Array.isArray(o) ? o.some((a) => w(t, d(a))) : w(t, d(o));
|
|
74
|
+
}, K = g(() => {
|
|
75
|
+
const e = f(m);
|
|
76
76
|
return Array.isArray(e) ? e.filter((r) => {
|
|
77
|
-
const
|
|
78
|
-
if (
|
|
79
|
-
const t =
|
|
80
|
-
if (t) {
|
|
81
|
-
|
|
82
|
-
|
|
77
|
+
const o = u.search;
|
|
78
|
+
if (o) {
|
|
79
|
+
const t = o.split(/\s+/).filter((n) => n.length > 0);
|
|
80
|
+
if (t.length > 0) {
|
|
81
|
+
const n = C.value.get(r);
|
|
82
|
+
if (n) {
|
|
83
|
+
if (!t.every((c) => Object.values(n).some((l) => l.includes(c)))) return !1;
|
|
84
|
+
} else {
|
|
85
|
+
const s = A.value;
|
|
86
|
+
if (!t.every((l) => s.some((d) => {
|
|
87
|
+
const a = V(r, d);
|
|
88
|
+
return y(a).toLowerCase().includes(l);
|
|
89
|
+
}))) return !1;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
83
92
|
}
|
|
84
|
-
for (const t in
|
|
85
|
-
const
|
|
86
|
-
if (
|
|
93
|
+
for (const t in u.byColumn) {
|
|
94
|
+
const n = u.byColumn[t], s = Array.isArray(n) && n.length === 0;
|
|
95
|
+
if (n != null && n !== "" && !s && !x(r, t, n)) return !1;
|
|
87
96
|
}
|
|
88
97
|
return !0;
|
|
89
98
|
}) : [];
|
|
90
|
-
}),
|
|
91
|
-
|
|
92
|
-
},
|
|
93
|
-
|
|
94
|
-
},
|
|
99
|
+
}), I = z((e) => {
|
|
100
|
+
u.search = y(e).toLowerCase(), i && console.log("[setSearch]", u.search);
|
|
101
|
+
}, f(E) ?? 150), q = (e, r) => {
|
|
102
|
+
u.byColumn[e] = r, i && console.log("[setColumnFilter]", e, r);
|
|
103
|
+
}, v = (e) => {
|
|
95
104
|
for (const r in e) q(r, e[r]);
|
|
96
|
-
|
|
97
|
-
},
|
|
98
|
-
|
|
99
|
-
},
|
|
105
|
+
i && console.log("[applyColumnFilters]", e);
|
|
106
|
+
}, B = () => {
|
|
107
|
+
u.search = "", u.byColumn = {}, i && console.log("[clearFilters] filtros reseteados");
|
|
108
|
+
}, V = (e, r) => {
|
|
100
109
|
if (Object.prototype.hasOwnProperty.call(e, r)) return e[r];
|
|
101
|
-
const
|
|
110
|
+
const o = p.value.find((t) => (t == null ? void 0 : t.value) === r);
|
|
102
111
|
try {
|
|
103
|
-
return
|
|
112
|
+
return o ? O(o, e) : e[r];
|
|
104
113
|
} catch (t) {
|
|
105
|
-
return
|
|
114
|
+
return i && console.error("[useFilter] ERROR getRawValue", { item: e, key: r, err: t }), null;
|
|
106
115
|
}
|
|
107
116
|
};
|
|
108
117
|
return {
|
|
109
|
-
modalFilter:
|
|
110
|
-
appliedFilters:
|
|
111
|
-
filteredItems:
|
|
112
|
-
setSearch:
|
|
113
|
-
applyColumnFilters:
|
|
114
|
-
clearFilters:
|
|
118
|
+
modalFilter: T,
|
|
119
|
+
appliedFilters: u,
|
|
120
|
+
filteredItems: K,
|
|
121
|
+
setSearch: I,
|
|
122
|
+
applyColumnFilters: v,
|
|
123
|
+
clearFilters: B,
|
|
115
124
|
// 👇 Exponemos también por si querés refrescar manualmente
|
|
116
|
-
refreshCache:
|
|
125
|
+
refreshCache: R
|
|
117
126
|
};
|
|
118
127
|
}
|
|
119
128
|
export {
|
|
120
|
-
|
|
129
|
+
Q as default
|
|
121
130
|
};
|