UNPKG

ant-design-x-vue-next

Version:

Ant Design X for Vue — community continuation aligned with @ant-design/x

134 lines (133 loc) 5.13 kB
import { defineComponent as P, inject as B, ref as g, computed as w, watch as R, createVNode as S, h as _ } from "vue"; import { applyDataModelUpdateV08 as j, resolvePropsV08 as X, extractDataUpdatesV08 as F } from "./Card.v0.8.mjs"; import { boxContextKey as N } from "./context.mjs"; import { createComponentTransformer as T } from "./format.mjs"; import { applyDataModelUpdateV09 as k, resolvePropsV09 as E, extractDataUpdatesV09 as O } from "./resolveProps.mjs"; import { validateComponentAgainstCatalog as K, setValueByPath as M, isPathObject as C, getValueByPath as D } from "./utils.mjs"; const L = /* @__PURE__ */ P({ name: "AXXCard", __name: "Card", props: { id: null }, setup(U) { const d = U, p = B(N); if (!p) throw new Error("[XCard.Card] must be used inside XCard.Box"); const c = T(), h = g(null), f = g({}), m = g("v0.8"), v = g(!1), V = w(() => { const t = p.surfaceCatalogMap.get(d.id); return t ? p.catalogMap.get(t) : void 0; }); R(() => p.commandQueue, (t) => { if (!t.length) return; const o = t.filter((e) => "createSurface" in e ? e.createSurface.surfaceId === d.id : "updateComponents" in e ? e.updateComponents.surfaceId === d.id : "updateDataModel" in e ? e.updateDataModel.surfaceId === d.id : "deleteSurface" in e ? e.deleteSurface.surfaceId === d.id : "surfaceUpdate" in e ? e.surfaceUpdate.surfaceId === d.id : "dataModelUpdate" in e ? e.dataModelUpdate.surfaceId === d.id : "beginRendering" in e ? e.beginRendering.surfaceId === d.id : !1); if (!o.length) return; let n = f.value, r = h.value, l = m.value, i = !1, a = !1, s = !1; for (const e of o) { if ("version" in e && e.version === "v0.9") { if (l = "v0.9", s = !0, "createSurface" in e && !v.value && (r = null, n = {}, a = !0, i = !0), "updateComponents" in e) { const u = c.transform(e.updateComponents.components, "v0.9"); u && (r = u, v.value = !0, a = !0); } "updateDataModel" in e && (n = k(n, e.updateDataModel.path, e.updateDataModel.value), i = !0), "deleteSurface" in e && (r = null, n = {}, v.value = !1, a = !0, i = !0, c.reset()); continue; } if (l = "v0.8", s = !0, "surfaceUpdate" in e && (c.transform(e.surfaceUpdate.components, "v0.8"), v.value)) { const u = c.getById("root"); u && (r = u, a = !0); } if ("dataModelUpdate" in e && (n = j(n, e.dataModelUpdate.contents), i = !0), "beginRendering" in e) { const u = c.getById(e.beginRendering.root); u && (r = u, v.value = !0, a = !0); } "deleteSurface" in e && (r = null, n = {}, v.value = !1, a = !0, i = !0, c.reset()); } s && (m.value = l), a && (h.value = r), i && (f.value = n); }, { deep: !0, immediate: !0 }); function x(t, o, n) { var i; if (!t) return o; const r = (i = t == null ? void 0 : t.event) == null ? void 0 : i.context; if (r && typeof r == "object" && !Array.isArray(r)) { const a = {}; for (const [s, e] of Object.entries(r)) if (C(e)) { const u = D(n, e.path), { path: W, ...b } = e; a[s] = { ...b, value: u }; } else a[s] = e; return { ...a, ...o }; } const l = t == null ? void 0 : t.context; if (Array.isArray(l)) { const a = {}; for (const s of l) { const { key: e, value: u } = s; e !== void 0 && (C(u) ? a[e] = { value: D(n, u.path) } : a[e] = u); } return { ...a, ...o }; } return o; } function I(t, o, n) { var a; const r = m.value === "v0.9" ? O(n, o) : F(n, o); let l = f.value; r.length > 0 && (l = r.reduce((s, { path: e, value: u }) => M(s, e, u), f.value), f.value = l); const i = x(n, o, l); (a = p.onAction) == null || a.call(p, { name: t, surfaceId: d.id, context: i }); } function A(t, o) { f.value = M(f.value, t, o); } function y(t) { const o = K(V.value, t.type, t.props); o.valid || o.errors.forEach((a) => console.warn(a)); const n = p.components[t.type]; if (!n) return console.warn(`Component "${t.type}" is not registered. Provide it via Box components prop.`), null; const r = m.value === "v0.9" ? E(t.props, f.value) : X(t.props, f.value), l = t.props.value; typeof l == "string" && l.startsWith("/") && (r.valuePath = l), r.onAction = (a, s) => { I(a, s, r.action); }, r.onDataChange = A; const i = (t.children || []).map((a) => { const s = c.getById(a); return s ? y(s) : null; }).filter(Boolean); return _(n, r, () => i); } return () => h.value ? S("div", { class: "ant-x-card" }, [y(h.value)]) : null; } }); export { L as default };