UNPKG

ant-design-x-vue-next

Version:

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

140 lines (139 loc) 4.18 kB
import { defineComponent as f, useSlots as w, computed as r, createVNode as o, Fragment as N } from "vue"; import { b as _ } from "../chunks/module-chunk.mjs"; import "../code-highlighter/index.mjs"; import "../mermaid/index.mjs"; import { useStreaming as v } from "./composables/useStreaming.mjs"; import A from "./DebugPanel.mjs"; import { htmlToVNodes as T } from "./htmlToVNodes.mjs"; import { parseMarkdown as x } from "./parser.mjs"; /* empty css */ import D from "../mermaid/Mermaid.mjs"; import B from "../code-highlighter/CodeHighlighter.mjs"; const c = "|", O = /* @__PURE__ */ f({ name: "AXXMarkdown", __name: "XMarkdown", props: { content: null, children: null, components: null, streaming: null, config: null, rootClassName: null, className: null, class: null, style: null, openLinksInNewTab: { type: Boolean, default: !1 }, dompurifyConfig: null, escapeRawHtml: { type: Boolean, default: !1 }, disableDefaultStyles: { type: Boolean }, debug: { type: Boolean, default: !1 } }, setup(d) { const e = d, s = w(), p = /* @__PURE__ */ f({ name: "AXXMarkdownDefaultCode", props: { lang: { type: String, default: "" }, block: { type: Boolean, default: !1 }, content: { type: String, default: "" } }, setup(n) { return () => { const t = n.content || ""; return n.block ? n.lang === "mermaid" ? o(D, { children: t }, null) : n.lang ? o(B, { lang: n.lang, children: t }, null) : o("pre", null, [o("code", null, [t])]) : o("code", { class: n.lang ? `language-${n.lang}` : void 0 }, [t]); }; } }), g = r(() => { var a; if (typeof e.content == "string") return e.content; if (typeof e.children == "string") return e.children; const n = (a = s.default) == null ? void 0 : a.call(s); return n ? (Array.isArray(n) ? n : [n]).map((l) => { if (typeof l == "string" || typeof l == "number") return String(l); if (l && typeof l == "object" && "children" in l) { const i = l.children; if (typeof i == "string" || typeof i == "number") return String(i); } return ""; }).join("") : ""; }), u = r(() => ({ code: p, ...e.components })), y = r(() => ({ streaming: e.streaming, components: u.value })), m = v(g, y), b = r(() => { var n; return (n = e.streaming) != null && n.hasNextChunk ? "loading" : "done"; }), C = r(() => { var t, a; const n = (t = e.streaming) == null ? void 0 : t.tail; return !!((a = e.streaming) != null && a.hasNextChunk && n); }), h = r(() => { var t; const n = (t = e.streaming) == null ? void 0 : t.tail; return n && typeof n == "object" ? n.content ?? c : c; }), S = r(() => { if (e.disableDefaultStyles === !0) return "x-md-disable-all"; if (Array.isArray(e.disableDefaultStyles)) return e.disableDefaultStyles.map((n) => `x-md-disable-${n}`); }), k = r(() => { var a, l; const n = m.value; if (!n) return null; const t = x(n, { markedConfig: e.config, openLinksInNewTab: e.openLinksInNewTab, injectTail: C.value, tailContent: h.value, escapeRawHtml: e.escapeRawHtml }); return T(t, { components: u.value, dompurifyConfig: e.dompurifyConfig, streamStatus: b.value, enableAnimation: (a = e.streaming) == null ? void 0 : a.enableAnimation, animationConfig: (l = e.streaming) == null ? void 0 : l.animationConfig }); }); return () => m.value ? o(N, null, [o("div", { class: _("x-markdown", S.value, e.rootClassName, e.className, e.class), style: e.style }, [k.value]), e.debug ? o(A, null, null) : null]) : null; } }); export { O as default };