ant-design-x-vue-next
Version:
Ant Design X for Vue — community continuation aligned with @ant-design/x
52 lines (51 loc) • 1.5 kB
JavaScript
import { isPathObject as l } from "./utils.mjs";
function s(e) {
return e !== null && typeof e == "object" && typeof e.literalString == "string";
}
function f(e) {
return e !== null && typeof e == "object" && Array.isArray(e.explicitList);
}
function d(e) {
const [c, t] = Object.entries(e.component)[0], n = {};
for (const [r, o] of Object.entries(t))
["child", "children"].includes(r) || (l(o) ? n[r] = o.path : s(o) ? n[r] = o.literalString : n[r] = o);
let i = [];
return t.children ? f(t.children) ? i = t.children.explicitList : Array.isArray(t.children) && (i = t.children) : t.child && (i = [t.child]), {
type: c,
props: n,
...i.length > 0 && { children: i }
};
}
function h(e) {
const c = e.component, t = {};
for (const [i, r] of Object.entries(e))
["id", "component", "child", "children"].includes(i) || (t[i] = l(r) ? r.path : r);
const n = e.children ?? (e.child ? [e.child] : []);
return {
type: c,
props: t,
...n.length > 0 && { children: n }
};
}
function p() {
const e = /* @__PURE__ */ new Map();
function c(t, n = "v0.8") {
if (!Array.isArray(t) || t.length === 0)
return e.get("root") ?? null;
if (n === "v0.8")
for (const i of t)
e.set(i.id, d(i));
else
for (const i of t)
e.set(i.id, h(i));
return e.get("root") ?? null;
}
return {
transform: c,
getById: (t) => e.get(t),
reset: () => e.clear()
};
}
export {
p as createComponentTransformer
};