ant-design-x-vue-next
Version:
Ant Design X for Vue — community continuation aligned with @ant-design/x
109 lines (108 loc) • 2.93 kB
JavaScript
import { computed as f, toValue as u } from "vue";
import { isDividerItem as g } from "../interface.mjs";
const r = "__ungrouped", m = (s, n) => !s || !n ? !1 : typeof s == "function" ? !!s(n) : !!s, h = (s, n = []) => {
const l = f(() => {
if (!u(s))
return {
enableGroup: !1,
sort: void 0,
title: void 0,
label: void 0,
collapsibleHandle: void 0,
collapsibleOptions: {
defaultExpandedKeys: void 0,
expandedKeys: void 0,
onExpand: void 0
}
};
let t = {};
typeof u(s) == "object" && (t = { ...u(s) });
const {
collapsible: b,
defaultExpandedKeys: p,
expandedKeys: d,
onExpand: c,
...e
} = t;
return {
enableGroup: !0,
sort: e.sort,
title: e.title,
label: e.label,
collapsibleHandle: b,
collapsibleOptions: {
defaultExpandedKeys: p,
expandedKeys: d,
onExpand: c
}
};
});
return f(() => {
const t = u(n) || [];
if (!l.value.enableGroup)
return {
groupList: [
{
name: r,
data: t,
title: void 0,
label: void 0,
collapsible: !1,
enableGroup: !1
}
],
enableGroup: !1,
collapsibleOptions: l.value.collapsibleOptions,
hasCollapsible: !1
};
if (t.some((e) => g(e)))
return {
groupList: t.reduce((o, i) => {
if (g(i) || !i.group)
return o.push({
data: [i],
name: void 0,
title: void 0,
label: void 0,
enableGroup: !1,
collapsible: !1
}), o;
const a = i, v = o.find((O) => O.name === a.group);
return v ? (v.data.push(a), o) : (o.push({
data: [a],
name: a.group,
title: l.value.title,
label: l.value.label,
enableGroup: !0,
collapsible: m(l.value.collapsibleHandle, a.group)
}), o);
}, []),
enableGroup: !0,
collapsibleOptions: l.value.collapsibleOptions,
hasCollapsible: !!l.value.collapsibleHandle
};
const p = t.reduce((e, o) => {
const i = o, a = i.group || r;
return e[a] || (e[a] = []), e[a].push(i), e;
}, {});
return {
groupList: (l.value.sort ? Object.keys(p).sort(l.value.sort) : Object.keys(p)).map((e) => {
const o = e === r ? void 0 : e;
return {
name: o,
title: l.value.title,
label: l.value.label,
data: p[e],
enableGroup: !0,
collapsible: m(l.value.collapsibleHandle, o)
};
}),
enableGroup: !0,
collapsibleOptions: l.value.collapsibleOptions,
hasCollapsible: !!l.value.collapsibleHandle
};
});
};
export {
h as default
};