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