UNPKG

@aplus-frontend/ui

Version:

112 lines (111 loc) 2.5 kB
import { ref as E, computed as M, unref as o } from "vue"; import { isFunction as d } from "lodash-unified"; function I(n) { const { rowKey: a, defaultSelectedRowKeys: c, defaultSelectedRows: u } = n; return a ? c?.length ? d(a) ? [] : i(c, n.type).map( (l) => ({ [a]: l }) ) : u?.length ? i(u, n.type).filter( (l) => { const s = d(a) ? a(l) : a; return s && (l[s] === 0 || l[s]); } ) : [] : []; } function i(n, a) { return n.length && a === "radio" ? [n[0]] : n; } const F = (n) => { const a = n.type === "radio", c = E(I(n)), u = (e) => d(n.rowKey) ? n.rowKey(e) : e[n.rowKey], l = M(() => { const e = /* @__PURE__ */ new Map(); return o(c).forEach((t) => { e.set(u(t), t); }), e; }); function s(e) { return o(l).has(u(e)); } function S(e) { if (!f(e)) return; const t = o(l); a && t.clear(), t.set(u(e), e), c.value = [...t.values()]; } function g(e) { const t = o(l); a && t.clear(); for (const r of i(e, n.type)) f(r) && t.set(u(r), r); c.value = [...t.values()]; } function K(e) { if (d(n.rowKey)) return; const t = o(l); a && t.clear(); for (const r of i(e, n.type)) { const v = o(n.dataSource).find( (D) => u(D) === r ), w = { [n.rowKey]: r }; f(v || w) && t.set(r, v || w); } c.value = [...t.values()]; } function y(e) { if (!f(e)) return; const t = o(l); t.delete(u(e)), c.value = [...t.values()]; } function R(e) { const t = o(l); for (const r of i(e, n.type)) f(r) && t.delete(u(r)); c.value = [...t.values()]; } function f(e) { const t = n.disabled; return !(t ? t(e) : !1); } function x() { if (a) return; const e = o(l); o(n.dataSource).forEach((t) => { f(t) && e.set(u(t), t); }), c.value = [...e.values()]; } function h(e) { if (!f(e)) return; const t = o(l), r = u(e); t.has(r) ? y(e) : S(e); } function b() { const e = o(l); o(n.dataSource).forEach((t) => { f(t) && e.delete(u(t)); }), c.value = [...e.values()]; } function A() { c.value = []; } return { select: S, unSelect: y, isSelected: s, selectAll: x, unSelectAll: b, clearAll: A, toggleSelect: h, selectedRows: c, selectedRowKeys: M( () => o(c).map((e) => u(e)) ), selectMulti: g, unSelectMulti: R, selectMultiByKeys: K }; }; export { F as default };