UNPKG

@aplus-frontend/ui

Version:

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