markdown-flow-ui 0.1.82-beta.0 → 0.1.83-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js +1 -1
  2. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/c4Diagram-YG6GDRKO.js +1 -1
  3. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/chunk-S3R3BYOJ.js +1 -1
  4. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/chunk-TZMSLE5B.js +1 -1
  5. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/ganttDiagram-LVOFAZNH.js +1 -1
  6. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/sequenceDiagram-WL72ISMW.js +1 -1
  7. package/dist/_virtual/index7.js +3 -2
  8. package/dist/_virtual/index7.js.map +1 -1
  9. package/dist/_virtual/index8.js +2 -3
  10. package/dist/_virtual/index8.js.map +1 -1
  11. package/dist/components/ContentRender/ContentRender.d.ts +15 -0
  12. package/dist/components/ContentRender/ContentRender.js +146 -109
  13. package/dist/components/ContentRender/ContentRender.js.map +1 -1
  14. package/dist/components/ContentRender/ContentRender.stories.d.ts +2 -0
  15. package/dist/components/ContentRender/IframeSandbox.d.ts +13 -0
  16. package/dist/components/ContentRender/IframeSandbox.js +104 -0
  17. package/dist/components/ContentRender/IframeSandbox.js.map +1 -0
  18. package/dist/components/ContentRender/SandboxApp.d.ts +11 -0
  19. package/dist/components/ContentRender/SandboxApp.js +181 -0
  20. package/dist/components/ContentRender/SandboxApp.js.map +1 -0
  21. package/dist/components/ContentRender/index.d.ts +5 -0
  22. package/dist/components/ContentRender/index.js +2 -1
  23. package/dist/components/ContentRender/index.js.map +1 -1
  24. package/dist/components/ContentRender/utils/split-content.d.ts +8 -0
  25. package/dist/components/ContentRender/utils/split-content.js +35 -0
  26. package/dist/components/ContentRender/utils/split-content.js.map +1 -0
  27. package/dist/components/MarkdownFlow/MarkdownFlow.js +4 -3
  28. package/dist/components/MarkdownFlow/MarkdownFlow.js.map +1 -1
  29. package/dist/index.js +12 -8
  30. package/dist/index.js.map +1 -1
  31. package/dist/markdown-flow-ui-lib.css +1 -1
  32. package/dist/renderer.d.ts +6 -2
  33. package/dist/renderer.js +11 -6
  34. package/dist/renderer.js.map +1 -1
  35. package/package.json +1 -1
@@ -0,0 +1,104 @@
1
+ import { j as l } from "../../_virtual/jsx-runtime.js";
2
+ import D, { useRef as i, useState as y, useEffect as b } from "react";
3
+ import { createRoot as F } from "react-dom/client";
4
+ import I from "./SandboxApp.js";
5
+ import { splitContentSegments as _ } from "./utils/split-content.js";
6
+ import q from "./ContentRender.js";
7
+ const J = ({
8
+ content: c,
9
+ type: w,
10
+ className: C,
11
+ loadingText: g,
12
+ styleLoadingText: p,
13
+ scriptLoadingText: x,
14
+ fullScreenButtonText: H,
15
+ mode: s = "content"
16
+ }) => {
17
+ const u = i(null), a = i(null), R = i(null), m = i(() => {
18
+ }), [j, S] = y(480), [v, k] = y(0), d = i(""), o = D.useMemo(() => {
19
+ const t = _(c).filter((r) => r.type === "sandbox");
20
+ return (s === "blackboard" ? t[t.length - 1]?.value || "" : t.map((r) => r.value).join(`
21
+ `)) || "";
22
+ }, [c, s]);
23
+ return b(() => {
24
+ if (s !== "blackboard") {
25
+ d.current = o;
26
+ return;
27
+ }
28
+ const e = d.current;
29
+ !(e && o.startsWith(e)) && e && k((n) => n + 1), d.current = o;
30
+ }, [o, s]), b(() => {
31
+ const e = u.current;
32
+ if (!e) return;
33
+ const t = e.contentDocument;
34
+ if (!t) return;
35
+ t.open(), t.write(`<!DOCTYPE html>
36
+ <html>
37
+ <head>
38
+ <meta charset="utf-8" />
39
+ <style>
40
+ html, body { margin: 0; padding: 0; }
41
+ </style>
42
+ </head>
43
+ <body>
44
+ <div id="root"></div>
45
+ </body>
46
+ </html>`), t.close(), R.current = t;
47
+ const n = t.getElementById("root");
48
+ if (!n) return;
49
+ const r = F(n);
50
+ a.current = r;
51
+ const h = () => {
52
+ if (!u.current || !t.body) return;
53
+ const E = t.body.getBoundingClientRect(), M = t.documentElement?.getBoundingClientRect(), B = E.height, O = M?.height || 0, z = Math.max(B, O), A = Math.max(200, Math.ceil(z));
54
+ S(A);
55
+ };
56
+ m.current = h, h();
57
+ const f = new ResizeObserver(() => h());
58
+ return f.observe(t.body), n && f.observe(n), () => {
59
+ f.disconnect(), r.unmount(), a.current = null, R.current = null, m.current = () => {
60
+ };
61
+ };
62
+ }, []), b(() => {
63
+ const e = a.current;
64
+ e && (e.render(
65
+ /* @__PURE__ */ l.jsx(
66
+ I,
67
+ {
68
+ html: o,
69
+ loadingText: g,
70
+ styleLoadingText: p,
71
+ scriptLoadingText: x,
72
+ resetToken: v
73
+ }
74
+ )
75
+ ), requestAnimationFrame(() => m.current?.()));
76
+ }, [
77
+ c,
78
+ o,
79
+ g,
80
+ p,
81
+ x,
82
+ H,
83
+ v
84
+ ]), /* @__PURE__ */ l.jsx("div", { style: { width: "100%", height: "100%", overflow: "auto" }, children: s === "blackboard" && w === "markdown" ? /* @__PURE__ */ l.jsx(q, { content: c }) : /* @__PURE__ */ l.jsx(
85
+ "iframe",
86
+ {
87
+ ref: u,
88
+ sandbox: "allow-scripts allow-same-origin",
89
+ allow: "fullscreen",
90
+ allowFullScreen: !0,
91
+ className: C,
92
+ style: {
93
+ width: "100%",
94
+ height: `${j}px`
95
+ // margin: "16px 0",
96
+ },
97
+ title: "HTML Sandbox"
98
+ }
99
+ ) });
100
+ };
101
+ export {
102
+ J as default
103
+ };
104
+ //# sourceMappingURL=IframeSandbox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IframeSandbox.js","sources":["../../../src/components/ContentRender/IframeSandbox.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from \"react\";\nimport { createRoot, Root } from \"react-dom/client\";\nimport SandboxApp from \"./SandboxApp\";\nimport { splitContentSegments } from \"./utils/split-content\";\nimport ContentRender from \"./ContentRender\";\nexport interface IframeSandboxProps {\n content: string;\n className?: string;\n loadingText?: string;\n styleLoadingText?: string;\n scriptLoadingText?: string;\n fullScreenButtonText?: string;\n mode?: \"content\" | \"blackboard\";\n type: \"sandbox\" | \"markdown\";\n}\n\nconst IframeSandbox: React.FC<IframeSandboxProps> = ({\n content,\n type,\n className,\n loadingText,\n styleLoadingText,\n scriptLoadingText,\n fullScreenButtonText,\n mode = \"content\",\n}) => {\n const iframeRef = useRef<HTMLIFrameElement>(null);\n const rootRef = useRef<Root | null>(null);\n const docRef = useRef<Document | null>(null);\n const updateHeightRef = useRef<() => void>(() => {});\n const [height, setHeight] = useState(480);\n const [resetToken, setResetToken] = useState(0);\n const prevHtmlRef = useRef<string>(\"\");\n const htmlContent = React.useMemo(() => {\n const segments = splitContentSegments(content);\n const sandboxSegments = segments.filter((seg) => seg.type === \"sandbox\");\n const sandboxContent =\n mode === \"blackboard\"\n ? sandboxSegments[sandboxSegments.length - 1]?.value || \"\"\n : sandboxSegments.map((seg) => seg.value).join(\"\\n\");\n return sandboxContent || \"\";\n }, [content, mode]);\n\n useEffect(() => {\n if (mode !== \"blackboard\") {\n prevHtmlRef.current = htmlContent;\n return;\n }\n const prev = prevHtmlRef.current;\n const isContinuation = prev && htmlContent.startsWith(prev);\n if (!isContinuation && prev) {\n setResetToken((token) => token + 1);\n }\n prevHtmlRef.current = htmlContent;\n }, [htmlContent, mode]);\n\n useEffect(() => {\n const iframe = iframeRef.current;\n if (!iframe) return undefined;\n\n const doc = iframe.contentDocument;\n if (!doc) return undefined;\n\n doc.open();\n doc.write(`<!DOCTYPE html>\n<html>\n <head>\n <meta charset=\"utf-8\" />\n <style>\n html, body { margin: 0; padding: 0; }\n </style>\n </head>\n <body>\n <div id=\"root\"></div>\n </body>\n</html>`);\n doc.close();\n docRef.current = doc;\n\n const rootEl = doc.getElementById(\"root\");\n if (!rootEl) return undefined;\n\n const root = createRoot(rootEl);\n rootRef.current = root;\n\n const updateHeight = () => {\n if (!iframeRef.current || !doc.body) return;\n const bodyRect = doc.body.getBoundingClientRect();\n const htmlRect = doc.documentElement?.getBoundingClientRect();\n const bodyHeight = bodyRect.height;\n const htmlHeight = htmlRect?.height || 0;\n const contentHeight = Math.max(bodyHeight, htmlHeight);\n const nextHeight = Math.max(200, Math.ceil(contentHeight));\n setHeight(nextHeight);\n };\n updateHeightRef.current = updateHeight;\n\n updateHeight();\n\n const resizeObserver = new ResizeObserver(() => updateHeight());\n resizeObserver.observe(doc.body);\n if (rootEl) {\n resizeObserver.observe(rootEl);\n }\n\n return () => {\n resizeObserver.disconnect();\n root.unmount();\n rootRef.current = null;\n docRef.current = null;\n updateHeightRef.current = () => {};\n };\n }, []);\n\n useEffect(() => {\n const root = rootRef.current;\n if (!root) return;\n\n root.render(\n <SandboxApp\n html={htmlContent}\n loadingText={loadingText}\n styleLoadingText={styleLoadingText}\n scriptLoadingText={scriptLoadingText}\n // fullScreenButtonText={fullScreenButtonText}\n resetToken={resetToken}\n />\n );\n requestAnimationFrame(() => updateHeightRef.current?.());\n }, [\n content,\n htmlContent,\n loadingText,\n styleLoadingText,\n scriptLoadingText,\n fullScreenButtonText,\n resetToken,\n ]);\n\n return (\n <div style={{ width: \"100%\", height: \"100%\", overflow: \"auto\" }}>\n {mode === \"blackboard\" && type === \"markdown\" ? (\n <ContentRender content={content} />\n ) : (\n <iframe\n ref={iframeRef}\n sandbox=\"allow-scripts allow-same-origin\"\n allow=\"fullscreen\"\n allowFullScreen\n className={className}\n style={{\n width: \"100%\",\n height: `${height}px`,\n // margin: \"16px 0\",\n }}\n title=\"HTML Sandbox\"\n />\n )}\n </div>\n );\n};\n\nexport default IframeSandbox;\n"],"names":["IframeSandbox","content","type","className","loadingText","styleLoadingText","scriptLoadingText","fullScreenButtonText","mode","iframeRef","useRef","rootRef","docRef","updateHeightRef","height","setHeight","useState","resetToken","setResetToken","prevHtmlRef","htmlContent","React","sandboxSegments","splitContentSegments","seg","useEffect","prev","token","iframe","doc","rootEl","root","createRoot","updateHeight","bodyRect","htmlRect","bodyHeight","htmlHeight","contentHeight","nextHeight","resizeObserver","jsx","SandboxApp","ContentRender"],"mappings":";;;;;;AAgBA,MAAMA,IAA8C,CAAC;AAAA,EACnD,SAAAC;AAAA,EACA,MAAAC;AAAA,EACA,WAAAC;AAAA,EACA,aAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,mBAAAC;AAAA,EACA,sBAAAC;AAAA,EACA,MAAAC,IAAO;AACT,MAAM;AACJ,QAAMC,IAAYC,EAA0B,IAAI,GAC1CC,IAAUD,EAAoB,IAAI,GAClCE,IAASF,EAAwB,IAAI,GACrCG,IAAkBH,EAAmB,MAAM;AAAA,EAAC,CAAC,GAC7C,CAACI,GAAQC,CAAS,IAAIC,EAAS,GAAG,GAClC,CAACC,GAAYC,CAAa,IAAIF,EAAS,CAAC,GACxCG,IAAcT,EAAe,EAAE,GAC/BU,IAAcC,EAAM,QAAQ,MAAM;AAEtC,UAAMC,IADWC,EAAqBtB,CAAO,EACZ,OAAO,CAACuB,MAAQA,EAAI,SAAS,SAAS;AAKvE,YAHEhB,MAAS,eACLc,EAAgBA,EAAgB,SAAS,CAAC,GAAG,SAAS,KACtDA,EAAgB,IAAI,CAACE,MAAQA,EAAI,KAAK,EAAE,KAAK;AAAA,CAAI,MAC9B;AAAA,EAC3B,GAAG,CAACvB,GAASO,CAAI,CAAC;AAElB,SAAAiB,EAAU,MAAM;AACd,QAAIjB,MAAS,cAAc;AACzB,MAAAW,EAAY,UAAUC;AACtB;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AAC;AAAA,IACnC;AAAA,EACF,GAAG,CAAA,CAAE,GAELY,EAAU,MAAM;AACd,UAAMM,IAAOpB,EAAQ;AACrB,IAAKoB,MAELA,EAAK;AAAA,MACHU,gBAAAA,EAAAA;AAAAA,QAACC;AAAA,QAAA;AAAA,UACC,MAAMtB;AAAA,UACN,aAAAhB;AAAA,UACA,kBAAAC;AAAA,UACA,mBAAAC;AAAA,UAEA,YAAAW;AAAA,QAAA;AAAA,MAAA;AAAA,IACF,GAEF,sBAAsB,MAAMJ,EAAgB,WAAW;AAAA,EACzD,GAAG;AAAA,IACDZ;AAAA,IACAmB;AAAA,IACAhB;AAAA,IACAC;AAAA,IACAC;AAAA,IACAC;AAAA,IACAU;AAAA,EAAA,CACD,yBAGE,OAAA,EAAI,OAAO,EAAE,OAAO,QAAQ,QAAQ,QAAQ,UAAU,OAAA,GACpD,gBAAS,gBAAgBf,MAAS,aACjCuC,gBAAAA,EAAAA,IAACE,GAAA,EAAc,SAAA1C,GAAkB,IAEjCwC,gBAAAA,EAAAA;AAAAA,IAAC;AAAA,IAAA;AAAA,MACC,KAAKhC;AAAA,MACL,SAAQ;AAAA,MACR,OAAM;AAAA,MACN,iBAAe;AAAA,MACf,WAAAN;AAAA,MACA,OAAO;AAAA,QACL,OAAO;AAAA,QACP,QAAQ,GAAGW,CAAM;AAAA;AAAA,MAAA;AAAA,MAGnB,OAAM;AAAA,IAAA;AAAA,EAAA,GAGZ;AAEJ;"}
@@ -0,0 +1,11 @@
1
+ import { default as React } from 'react';
2
+ export interface SandboxAppProps {
3
+ html: string;
4
+ loadingText?: string;
5
+ styleLoadingText?: string;
6
+ scriptLoadingText?: string;
7
+ fullScreenButtonText?: string;
8
+ resetToken?: number;
9
+ }
10
+ declare const SandboxApp: React.FC<SandboxAppProps>;
11
+ export default SandboxApp;
@@ -0,0 +1,181 @@
1
+ import { j as v } from "../../_virtual/jsx-runtime.js";
2
+ import { useRef as n, useState as E, useEffect as S } from "react";
3
+ import X from "../../Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/loader-circle.js";
4
+ const re = ({
5
+ html: u,
6
+ loadingText: W,
7
+ styleLoadingText: q,
8
+ scriptLoadingText: z,
9
+ fullScreenButtonText: H,
10
+ resetToken: f = 0
11
+ }) => {
12
+ const A = n(null), C = n(null), [V, I] = E(!0), [_, w] = E(!1), [O, b] = E(!1), [Q, k] = E(!1), R = n([]), F = n([]), N = n(0), T = n(0), p = n(null), d = n(null), m = n(!1), h = n(!1), L = n(!1), j = n(f), J = 200, o = (e) => {
13
+ e.current && (clearTimeout(e.current), e.current = null);
14
+ }, M = (e, s, c, g) => {
15
+ const i = performance.now() - c.current, x = Math.max(0, J - i);
16
+ o(s), s.current = window.setTimeout(() => {
17
+ e(!1), g?.(), s.current = null;
18
+ }, x);
19
+ };
20
+ S(() => {
21
+ const e = () => {
22
+ k(!!document.fullscreenElement);
23
+ };
24
+ return document.addEventListener("fullscreenchange", e), () => {
25
+ document.removeEventListener("fullscreenchange", e);
26
+ };
27
+ }, []), S(() => {
28
+ const e = C.current?.ownerDocument;
29
+ if (!e) return;
30
+ const s = "sandbox-spinner-style";
31
+ let c = e.getElementById(s);
32
+ c || (c = e.createElement("style"), c.id = s, c.textContent = "@keyframes sandbox-spin { from { transform: rotate(0deg);} to { transform: rotate(360deg);} }", e.head?.appendChild(c));
33
+ }, []), S(() => {
34
+ f !== j.current && (L.current = !1, j.current = f), o(p), o(d), m.current = !1, h.current = !1;
35
+ const e = C.current;
36
+ if (!e) return;
37
+ const s = e.ownerDocument, c = s?.body;
38
+ if (!c) return;
39
+ R.current.forEach((t) => t.remove()), R.current = [], F.current.forEach((t) => t.remove()), F.current = [];
40
+ const g = L.current;
41
+ I(!g), w(!1), b(!1), e.innerHTML = "";
42
+ const i = document.createElement("div");
43
+ i.innerHTML = u;
44
+ const x = (u.match(/<script[\s>]/gi) || []).length, K = (u.match(/<\/script>/gi) || []).length, P = x > 0 && x === K, l = [];
45
+ Array.from(i.querySelectorAll("style, script")).forEach((t) => {
46
+ if (t.tagName.toLowerCase() === "style") {
47
+ const r = s.createElement("style");
48
+ r.textContent = t.textContent || "", Array.from(t.attributes).forEach((a) => {
49
+ r.setAttribute(a.name, a.value);
50
+ }), l.push(r);
51
+ } else {
52
+ const r = s.createElement("script");
53
+ Array.from(t.attributes).forEach((a) => {
54
+ r.setAttribute(a.name, a.value);
55
+ }), r.textContent = t.textContent || "", l.push(r);
56
+ }
57
+ t.remove();
58
+ });
59
+ const D = l.some(
60
+ (t) => t.tagName.toLowerCase() === "style"
61
+ ), B = l.some(
62
+ (t) => t.tagName.toLowerCase() === "script"
63
+ );
64
+ D && (m.current = !0, N.current = performance.now(), o(p), w(!0)), B && (h.current = !0, T.current = performance.now(), o(d), b(!0));
65
+ const G = !!i.firstElementChild;
66
+ I(!G && !g), G && (L.current = !0);
67
+ const U = Array.from(i.childNodes);
68
+ e.append(...U), l.forEach((t) => {
69
+ if (t.tagName.toLowerCase() === "style") {
70
+ s.head?.appendChild(t), R.current.push(t);
71
+ return;
72
+ }
73
+ if (P) {
74
+ const r = t, a = r.textContent || "";
75
+ if (!r.src)
76
+ try {
77
+ new Function(a);
78
+ } catch {
79
+ r.remove();
80
+ return;
81
+ }
82
+ try {
83
+ c.appendChild(r), F.current.push(r);
84
+ } catch {
85
+ r.remove();
86
+ }
87
+ } else
88
+ t.remove();
89
+ }), requestAnimationFrame(() => {
90
+ D && M(
91
+ w,
92
+ p,
93
+ N,
94
+ () => {
95
+ m.current = !1;
96
+ }
97
+ ), B && M(
98
+ b,
99
+ d,
100
+ T,
101
+ () => {
102
+ h.current = !1;
103
+ }
104
+ );
105
+ });
106
+ }, [u, f]), S(
107
+ () => () => {
108
+ o(p), o(d);
109
+ },
110
+ []
111
+ );
112
+ const y = O || h.current ? z || "Building scripts cache..." : _ || m.current ? q || "Building styles..." : V ? W || "Loading..." : null;
113
+ return console.log(
114
+ "fullScreenButtonText",
115
+ H,
116
+ Q,
117
+ () => {
118
+ const e = A.current;
119
+ if (e) {
120
+ if (!document.fullscreenElement) {
121
+ e.requestFullscreen?.().catch(() => {
122
+ });
123
+ return;
124
+ }
125
+ document.exitFullscreen?.();
126
+ }
127
+ }
128
+ ), /* @__PURE__ */ v.jsxs(
129
+ "div",
130
+ {
131
+ ref: A,
132
+ style: { position: "relative", minHeight: 120 },
133
+ "aria-busy": !!y,
134
+ children: [
135
+ /* @__PURE__ */ v.jsx(
136
+ "div",
137
+ {
138
+ ref: C,
139
+ style: {
140
+ pointerEvents: y ? "none" : void 0
141
+ }
142
+ }
143
+ ),
144
+ y && /* @__PURE__ */ v.jsxs(
145
+ "div",
146
+ {
147
+ style: {
148
+ position: "absolute",
149
+ inset: 0,
150
+ display: "flex",
151
+ alignItems: "center",
152
+ justifyContent: "center",
153
+ background: "rgba(51, 51, 51, 0.80)",
154
+ color: "#ffffff",
155
+ fontSize: 16,
156
+ fontWeight: 700,
157
+ gap: 10,
158
+ pointerEvents: "auto",
159
+ zIndex: 20
160
+ },
161
+ children: [
162
+ /* @__PURE__ */ v.jsx(
163
+ X,
164
+ {
165
+ "aria-hidden": !0,
166
+ size: 20,
167
+ style: { animation: "sandbox-spin 1s linear infinite" }
168
+ }
169
+ ),
170
+ y
171
+ ]
172
+ }
173
+ )
174
+ ]
175
+ }
176
+ );
177
+ };
178
+ export {
179
+ re as default
180
+ };
181
+ //# sourceMappingURL=SandboxApp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SandboxApp.js","sources":["../../../src/components/ContentRender/SandboxApp.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from \"react\";\nimport { Loader2 } from \"lucide-react\";\n\nexport interface SandboxAppProps {\n html: string;\n loadingText?: string;\n styleLoadingText?: string;\n scriptLoadingText?: string;\n fullScreenButtonText?: string;\n resetToken?: number;\n}\n\nconst SandboxApp: React.FC<SandboxAppProps> = ({\n html,\n loadingText,\n styleLoadingText,\n scriptLoadingText,\n fullScreenButtonText,\n resetToken = 0,\n}) => {\n const wrapperRef = useRef<HTMLDivElement>(null);\n const containerRef = useRef<HTMLDivElement>(null);\n const [isWaitingFirstDiv, setIsWaitingFirstDiv] = useState(true);\n const [isGeneratingStyles, setIsGeneratingStyles] = useState(false);\n const [isGeneratingScripts, setIsGeneratingScripts] = useState(false);\n const [isFullscreen, setIsFullscreen] = useState(false);\n const appendedStylesRef = useRef<HTMLStyleElement[]>([]);\n const appendedScriptsRef = useRef<HTMLScriptElement[]>([]);\n const styleStartRef = useRef(0);\n const scriptStartRef = useRef(0);\n const styleTimerRef = useRef<number | null>(null);\n const scriptTimerRef = useRef<number | null>(null);\n const hasStylesRef = useRef(false);\n const hasScriptsRef = useRef(false);\n const hasRenderedContentRef = useRef(false);\n const prevResetTokenRef = useRef(resetToken);\n const MIN_LOADING_MS = 200;\n\n const clearTimer = (timerRef: React.MutableRefObject<number | null>) => {\n if (timerRef.current) {\n clearTimeout(timerRef.current);\n timerRef.current = null;\n }\n };\n\n const settleStateWithMinimumDelay = (\n setter: React.Dispatch<React.SetStateAction<boolean>>,\n timerRef: React.MutableRefObject<number | null>,\n startRef: React.MutableRefObject<number>,\n onDone?: () => void\n ) => {\n const elapsed = performance.now() - startRef.current;\n const delay = Math.max(0, MIN_LOADING_MS - elapsed);\n clearTimer(timerRef);\n timerRef.current = window.setTimeout(() => {\n setter(false);\n onDone?.();\n timerRef.current = null;\n }, delay);\n };\n\n useEffect(() => {\n const onFullscreenChange = () => {\n setIsFullscreen(!!document.fullscreenElement);\n };\n document.addEventListener(\"fullscreenchange\", onFullscreenChange);\n return () => {\n document.removeEventListener(\"fullscreenchange\", onFullscreenChange);\n };\n }, []);\n\n useEffect(() => {\n const doc = containerRef.current?.ownerDocument;\n if (!doc) return;\n const styleId = \"sandbox-spinner-style\";\n let styleEl = doc.getElementById(styleId) as HTMLStyleElement | null;\n if (!styleEl) {\n styleEl = doc.createElement(\"style\");\n styleEl.id = styleId;\n styleEl.textContent =\n \"@keyframes sandbox-spin { from { transform: rotate(0deg);} to { transform: rotate(360deg);} }\";\n doc.head?.appendChild(styleEl);\n }\n }, []);\n\n useEffect(() => {\n if (resetToken !== prevResetTokenRef.current) {\n hasRenderedContentRef.current = false;\n prevResetTokenRef.current = resetToken;\n }\n clearTimer(styleTimerRef);\n clearTimer(scriptTimerRef);\n hasStylesRef.current = false;\n hasScriptsRef.current = false;\n\n const container = containerRef.current;\n if (!container) return;\n const doc = container.ownerDocument;\n const body = doc?.body;\n if (!body) return;\n\n appendedStylesRef.current.forEach((node) => node.remove());\n appendedStylesRef.current = [];\n appendedScriptsRef.current.forEach((node) => node.remove());\n appendedScriptsRef.current = [];\n\n const hasRenderedBefore = hasRenderedContentRef.current;\n setIsWaitingFirstDiv(!hasRenderedBefore);\n setIsGeneratingStyles(false);\n setIsGeneratingScripts(false);\n container.innerHTML = \"\";\n const wrapper = document.createElement(\"div\");\n wrapper.innerHTML = html;\n\n const openScriptCount = (html.match(/<script[\\s>]/gi) || []).length;\n const closeScriptCount = (html.match(/<\\/script>/gi) || []).length;\n const shouldExecuteScripts =\n openScriptCount > 0 && openScriptCount === closeScriptCount;\n\n const resourceQueue: HTMLElement[] = [];\n\n Array.from(wrapper.querySelectorAll(\"style, script\")).forEach((node) => {\n if (node.tagName.toLowerCase() === \"style\") {\n const cloned = doc.createElement(\"style\");\n cloned.textContent = node.textContent || \"\";\n Array.from(node.attributes).forEach((attr) => {\n cloned.setAttribute(attr.name, attr.value);\n });\n resourceQueue.push(cloned);\n } else {\n const replacement = doc.createElement(\"script\");\n Array.from(node.attributes).forEach((attr) => {\n replacement.setAttribute(attr.name, attr.value);\n });\n replacement.textContent = node.textContent || \"\";\n resourceQueue.push(replacement);\n }\n node.remove();\n });\n\n const hasStyles = resourceQueue.some(\n (node) => node.tagName.toLowerCase() === \"style\"\n );\n const hasScripts = resourceQueue.some(\n (node) => node.tagName.toLowerCase() === \"script\"\n );\n if (hasStyles) {\n hasStylesRef.current = true;\n styleStartRef.current = performance.now();\n clearTimer(styleTimerRef);\n setIsGeneratingStyles(true);\n }\n if (hasScripts) {\n hasScriptsRef.current = true;\n scriptStartRef.current = performance.now();\n clearTimer(scriptTimerRef);\n setIsGeneratingScripts(true);\n }\n\n const hasFirstElement = !!wrapper.firstElementChild;\n setIsWaitingFirstDiv(!hasFirstElement && !hasRenderedBefore);\n if (hasFirstElement) {\n hasRenderedContentRef.current = true;\n }\n\n const contentNodes = Array.from(wrapper.childNodes);\n container.append(...contentNodes);\n\n resourceQueue.forEach((node) => {\n if (node.tagName.toLowerCase() === \"style\") {\n doc.head?.appendChild(node);\n appendedStylesRef.current.push(node as HTMLStyleElement);\n return;\n }\n\n if (shouldExecuteScripts) {\n const scriptNode = node as HTMLScriptElement;\n const scriptText = scriptNode.textContent || \"\";\n const shouldValidate = !scriptNode.src;\n\n if (shouldValidate) {\n try {\n // Validate script is syntactically complete before executing\n\n new Function(scriptText);\n } catch {\n scriptNode.remove();\n return;\n }\n }\n\n try {\n body.appendChild(scriptNode);\n appendedScriptsRef.current.push(scriptNode);\n } catch {\n scriptNode.remove();\n }\n } else {\n // Defer execution until all script tags are fully received\n node.remove();\n }\n });\n requestAnimationFrame(() => {\n if (hasStyles) {\n settleStateWithMinimumDelay(\n setIsGeneratingStyles,\n styleTimerRef,\n styleStartRef,\n () => {\n hasStylesRef.current = false;\n }\n );\n }\n if (hasScripts) {\n settleStateWithMinimumDelay(\n setIsGeneratingScripts,\n scriptTimerRef,\n scriptStartRef,\n () => {\n hasScriptsRef.current = false;\n }\n );\n }\n });\n }, [html, resetToken]);\n\n useEffect(\n () => () => {\n clearTimer(styleTimerRef);\n clearTimer(scriptTimerRef);\n },\n []\n );\n\n const overlayMessage = (() => {\n if (isGeneratingScripts || hasScriptsRef.current)\n return scriptLoadingText || \"Building scripts cache...\";\n if (isGeneratingStyles || hasStylesRef.current)\n return styleLoadingText || \"Building styles...\";\n if (isWaitingFirstDiv) return loadingText || \"Loading...\";\n return null;\n })();\n\n const handleToggleFullscreen = () => {\n const wrapper = wrapperRef.current;\n if (!wrapper) return;\n if (!document.fullscreenElement) {\n wrapper.requestFullscreen?.().catch(() => {});\n return;\n }\n document.exitFullscreen?.();\n };\n\n console.log(\n \"fullScreenButtonText\",\n fullScreenButtonText,\n isFullscreen,\n handleToggleFullscreen\n );\n\n return (\n <div\n ref={wrapperRef}\n style={{ position: \"relative\", minHeight: 120 }}\n aria-busy={!!overlayMessage}\n >\n <div\n ref={containerRef}\n style={{\n pointerEvents: overlayMessage ? \"none\" : undefined,\n }}\n />\n {/* <button\n type=\"button\"\n onClick={handleToggleFullscreen}\n style={{\n position: \"absolute\",\n top: 8,\n right: 8,\n zIndex: 30,\n padding: \"6px 10px\",\n borderRadius: 6,\n border: \"1px solid #cbd5e1\",\n background: \"#ffffffcc\",\n color: \"#0f172a\",\n fontSize: 12,\n fontWeight: 600,\n cursor: \"pointer\",\n boxShadow: \"0 4px 10px rgba(15, 23, 42, 0.08)\",\n }}\n >\n {isFullscreen\n ? fullScreenButtonText || \"Exit Fullscreen\"\n : fullScreenButtonText || \"Fullscreen\"}\n </button> */}\n {overlayMessage && (\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n background: \"rgba(51, 51, 51, 0.80)\",\n color: \"#ffffff\",\n fontSize: 16,\n fontWeight: 700,\n gap: 10,\n pointerEvents: \"auto\",\n zIndex: 20,\n }}\n >\n <Loader2\n aria-hidden\n size={20}\n style={{ animation: \"sandbox-spin 1s linear infinite\" }}\n />\n {overlayMessage}\n </div>\n )}\n </div>\n );\n};\n\nexport default SandboxApp;\n"],"names":["SandboxApp","html","loadingText","styleLoadingText","scriptLoadingText","fullScreenButtonText","resetToken","wrapperRef","useRef","containerRef","isWaitingFirstDiv","setIsWaitingFirstDiv","useState","isGeneratingStyles","setIsGeneratingStyles","isGeneratingScripts","setIsGeneratingScripts","isFullscreen","setIsFullscreen","appendedStylesRef","appendedScriptsRef","styleStartRef","scriptStartRef","styleTimerRef","scriptTimerRef","hasStylesRef","hasScriptsRef","hasRenderedContentRef","prevResetTokenRef","MIN_LOADING_MS","clearTimer","timerRef","settleStateWithMinimumDelay","setter","startRef","onDone","elapsed","delay","useEffect","onFullscreenChange","doc","styleId","styleEl","container","body","node","hasRenderedBefore","wrapper","openScriptCount","closeScriptCount","shouldExecuteScripts","resourceQueue","cloned","attr","replacement","hasStyles","hasScripts","hasFirstElement","contentNodes","scriptNode","scriptText","overlayMessage","jsxs","jsx","Loader2"],"mappings":";;;AAYA,MAAMA,KAAwC,CAAC;AAAA,EAC7C,MAAAC;AAAA,EACA,aAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,mBAAAC;AAAA,EACA,sBAAAC;AAAA,EACA,YAAAC,IAAa;AACf,MAAM;AACJ,QAAMC,IAAaC,EAAuB,IAAI,GACxCC,IAAeD,EAAuB,IAAI,GAC1C,CAACE,GAAmBC,CAAoB,IAAIC,EAAS,EAAI,GACzD,CAACC,GAAoBC,CAAqB,IAAIF,EAAS,EAAK,GAC5D,CAACG,GAAqBC,CAAsB,IAAIJ,EAAS,EAAK,GAC9D,CAACK,GAAcC,CAAe,IAAIN,EAAS,EAAK,GAChDO,IAAoBX,EAA2B,EAAE,GACjDY,IAAqBZ,EAA4B,EAAE,GACnDa,IAAgBb,EAAO,CAAC,GACxBc,IAAiBd,EAAO,CAAC,GACzBe,IAAgBf,EAAsB,IAAI,GAC1CgB,IAAiBhB,EAAsB,IAAI,GAC3CiB,IAAejB,EAAO,EAAK,GAC3BkB,IAAgBlB,EAAO,EAAK,GAC5BmB,IAAwBnB,EAAO,EAAK,GACpCoB,IAAoBpB,EAAOF,CAAU,GACrCuB,IAAiB,KAEjBC,IAAa,CAACC,MAAoD;AACtE,IAAIA,EAAS,YACX,aAAaA,EAAS,OAAO,GAC7BA,EAAS,UAAU;AAAA,EAEvB,GAEMC,IAA8B,CAClCC,GACAF,GACAG,GACAC,MACG;AACH,UAAMC,I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AAAA,gBAAA;AAAA,kBACC,eAAW;AAAA,kBACX,MAAM;AAAA,kBACN,OAAO,EAAE,WAAW,kCAAA;AAAA,gBAAkC;AAAA,cAAA;AAAA,cAEvDH;AAAA,YAAA;AAAA,UAAA;AAAA,QAAA;AAAA,MACH;AAAA,IAAA;AAAA,EAAA;AAIR;"}
@@ -1,5 +1,10 @@
1
1
  import { default as ContentRender } from './ContentRender';
2
2
  export default ContentRender;
3
+ export { default as IframeSandbox } from './IframeSandbox';
4
+ export type { IframeSandboxProps } from './IframeSandbox';
5
+ export type { SandboxAppProps } from './SandboxApp';
6
+ export type { RenderSegment } from './utils/split-content';
7
+ export { splitContentSegments } from './utils/split-content';
3
8
  export { default as ContentRender } from './ContentRender';
4
9
  export { default as MarkdownFlowInput } from './MarkdownFlowInput';
5
10
  export { default as useTypewriter } from './useTypewriter';
@@ -1,7 +1,8 @@
1
1
  import o from "./ContentRender.js";
2
2
  import "../../_virtual/jsx-runtime.js";
3
- import "../ui/inputGroup/input-group.js";
4
3
  import "react";
4
+ import "react-dom/client";
5
+ import "../ui/inputGroup/input-group.js";
5
6
  export {
6
7
  o as ContentRender,
7
8
  o as default
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
@@ -0,0 +1,8 @@
1
+ export type RenderSegment = {
2
+ type: "markdown";
3
+ value: string;
4
+ } | {
5
+ type: "sandbox";
6
+ value: string;
7
+ };
8
+ export declare const splitContentSegments: (raw: string) => RenderSegment[];
@@ -0,0 +1,35 @@
1
+ const m = /<(script|style|link|iframe|html|head|body|meta|title|base|template|div|section|article|main)[\s>]/i, h = [
2
+ /<svg[\s\S]*?<\/svg>/i,
3
+ /<img\b[^>]*?>/i,
4
+ /```mermaid[\s\S]*?```/i,
5
+ /```[a-zA-Z0-9]+[\s\S]*?```/i
6
+ ], d = /<\/[a-z][^>]*>\s*\n(?=[^\s<])/gi, u = (e, n) => {
7
+ let s = e.length, t;
8
+ for (d.lastIndex = 0; t = d.exec(e); )
9
+ if (!(t.index <= n)) {
10
+ s = t.index + t[0].length;
11
+ break;
12
+ }
13
+ return s;
14
+ }, x = (e) => {
15
+ let n = null;
16
+ return h.forEach((s) => {
17
+ const t = s.exec(e);
18
+ if (!t || typeof t.index != "number") return;
19
+ const i = t.index, c = t.index + t[0].length;
20
+ (!n || i < n.start) && (n = { start: i, end: c });
21
+ }), n;
22
+ }, f = (e) => {
23
+ const n = e.search(m), s = x(e);
24
+ if (n === -1 && !s)
25
+ return [{ type: "markdown", value: e }];
26
+ const t = !!s && (n === -1 || s.start < n), i = t ? s.start : n, c = t ? s.end : u(e, i), o = [], l = e.slice(0, i), r = e.slice(i, c), a = e.slice(c);
27
+ return l.trim() && o.push({ type: "markdown", value: l }), o.push({
28
+ type: t ? "markdown" : "sandbox",
29
+ value: r
30
+ }), a.trim() && o.push(...f(a)), console.log("segments", o), o;
31
+ };
32
+ export {
33
+ f as splitContentSegments
34
+ };
35
+ //# sourceMappingURL=split-content.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"split-content.js","sources":["../../../../src/components/ContentRender/utils/split-content.ts"],"sourcesContent":["export type RenderSegment =\n | { type: \"markdown\"; value: string }\n | { type: \"sandbox\"; value: string };\n\nconst SANDBOX_START_PATTERN =\n /<(script|style|link|iframe|html|head|body|meta|title|base|template|div|section|article|main)[\\s>]/i;\n\nconst INLINE_SANDBOX_PATTERNS: RegExp[] = [\n /<svg[\\s\\S]*?<\\/svg>/i,\n /<img\\b[^>]*?>/i,\n /```mermaid[\\s\\S]*?```/i,\n /```[a-zA-Z0-9]+[\\s\\S]*?```/i,\n];\n\nconst closingBoundary = /<\\/[a-z][^>]*>\\s*\\n(?=[^\\s<])/gi;\n\ntype MatchResult = { start: number; end: number };\n\nconst findHtmlBlockEnd = (raw: string, startIndex: number) => {\n let blockEnd = raw.length;\n let match: RegExpExecArray | null;\n closingBoundary.lastIndex = 0;\n\n while ((match = closingBoundary.exec(raw))) {\n if (match.index <= startIndex) continue;\n blockEnd = match.index + match[0].length;\n break;\n }\n\n return blockEnd;\n};\n\nconst findInlineSandboxMatch = (raw: string): MatchResult | null => {\n let earliest: MatchResult | null = null;\n\n INLINE_SANDBOX_PATTERNS.forEach((pattern) => {\n const match = pattern.exec(raw);\n if (!match || typeof match.index !== \"number\") return;\n const start = match.index;\n const end = match.index + match[0].length;\n\n if (!earliest || start < earliest.start) {\n earliest = { start, end };\n }\n });\n\n return earliest;\n};\n\n// Split incoming markdown content into markdown and sandbox HTML segments\nexport const splitContentSegments = (raw: string): RenderSegment[] => {\n const sandboxStartIndex = raw.search(SANDBOX_START_PATTERN);\n const inlineMatch = findInlineSandboxMatch(raw);\n\n if (sandboxStartIndex === -1 && !inlineMatch) {\n return [{ type: \"markdown\", value: raw }];\n }\n\n const shouldUseInline =\n !!inlineMatch &&\n (sandboxStartIndex === -1 || inlineMatch.start < sandboxStartIndex);\n\n const startIndex = shouldUseInline ? inlineMatch!.start : sandboxStartIndex;\n const blockEnd = shouldUseInline\n ? inlineMatch!.end\n : findHtmlBlockEnd(raw, startIndex);\n\n const segments: RenderSegment[] = [];\n const before = raw.slice(0, startIndex);\n const htmlBlock = raw.slice(startIndex, blockEnd);\n const after = raw.slice(blockEnd);\n\n if (before.trim()) {\n segments.push({ type: \"markdown\", value: before });\n }\n\n segments.push({\n type: shouldUseInline ? \"markdown\" : \"sandbox\",\n value: htmlBlock,\n });\n\n if (after.trim()) {\n segments.push(...splitContentSegments(after));\n }\n console.log(\"segments\", segments);\n return segments;\n};\n"],"names":["SANDBOX_START_PATTERN","INLINE_SANDBOX_PATTERNS","closingBoundary","findHtmlBlockEnd","raw","startIndex","blockEnd","match","findInlineSandboxMatch","earliest","pattern","start","end","splitContentSegments","sandboxStartIndex","inlineMatch","shouldUseInline","segments","before","htmlBlock","after"],"mappings":"AAIA,MAAMA,IACJ,sGAEIC,IAAo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AAOC,GAAQ,GAGnDD,EAAS,KAAK;AAAA,IACZ,MAAMD,IAAkB,aAAa;AAAA,IACrC,OAAOG;AAAA,EAAA,CACR,GAEGC,EAAM,UACRH,EAAS,KAAK,GAAGJ,EAAqBO,CAAK,CAAC,GAE9C,QAAQ,IAAI,YAAYH,CAAQ,GACzBA;AACT;"}
@@ -1,9 +1,10 @@
1
1
  import { j as o } from "../../_virtual/jsx-runtime.js";
2
2
  import B from "../ContentRender/ContentRender.js";
3
- import "../ui/inputGroup/input-group.js";
4
3
  import "react";
4
+ import "react-dom/client";
5
+ import "../ui/inputGroup/input-group.js";
5
6
  /* empty css */
6
- const b = ({
7
+ const h = ({
7
8
  initialContentList: a = [],
8
9
  customRenderBar: d,
9
10
  onSend: n,
@@ -42,6 +43,6 @@ const b = ({
42
43
  );
43
44
  }) });
44
45
  export {
45
- b as default
46
+ h as default
46
47
  };
47
48
  //# sourceMappingURL=MarkdownFlow.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"MarkdownFlow.js","sources":["../../../src/components/MarkdownFlow/MarkdownFlow.tsx"],"sourcesContent":["import React from \"react\";\nimport ContentRender from \"../ContentRender\";\nimport { CustomRenderBarProps, OnSendContentParams } from \"../types\";\nimport \"./markdownFlow.css\";\n\nexport interface MarkdownFlowProps {\n initialContentList?: {\n content: string;\n isFinished?: boolean;\n defaultInputText?: string;\n defaultButtonText?: string;\n defaultSelectedValues?: string[];\n readonly?: boolean;\n customRenderBar?: CustomRenderBarProps;\n onClickCustomButtonAfterContent?: () => void;\n dynamicInteractionFormat?: string;\n }[];\n customRenderBar?: CustomRenderBarProps;\n onSend?: (content: OnSendContentParams) => void;\n typingSpeed?: number;\n enableTypewriter?: boolean;\n onBlockComplete?: (blockIndex: number) => void;\n // Multi-select confirm button text (i18n support)\n confirmButtonText?: string;\n // Copy button text for code blocks\n copyButtonText?: string;\n // Copied state text for code blocks\n copiedButtonText?: string;\n beforeSend?: (content: OnSendContentParams) => boolean;\n}\n\nconst MarkdownFlow: React.FC<MarkdownFlowProps> = ({\n initialContentList = [],\n customRenderBar,\n onSend: onSendProp,\n typingSpeed: typingSpeedProp,\n enableTypewriter = false,\n onBlockComplete,\n confirmButtonText,\n copyButtonText,\n copiedButtonText,\n beforeSend: beforeSendProp,\n}) => {\n return (\n <div className=\"markdown-flow\">\n {initialContentList.map((contentInfo, index) => {\n const isFinished = contentInfo.isFinished ?? false;\n const enableTypewriterForBlock = !isFinished && enableTypewriter;\n const onSend = isFinished ? undefined : onSendProp;\n const typingSpeed = isFinished ? undefined : typingSpeedProp;\n const beforeSend = beforeSendProp ?? (() => true);\n return (\n <ContentRender\n key={index}\n content={contentInfo.content}\n defaultInputText={contentInfo.defaultInputText}\n defaultButtonText={contentInfo.defaultButtonText}\n defaultSelectedValues={contentInfo.defaultSelectedValues}\n readonly={contentInfo.readonly}\n enableTypewriter={enableTypewriterForBlock}\n customRenderBar={contentInfo.customRenderBar || customRenderBar}\n onSend={onSend}\n beforeSend={beforeSend}\n onClickCustomButtonAfterContent={\n contentInfo.onClickCustomButtonAfterContent\n }\n typingSpeed={typingSpeed}\n confirmButtonText={confirmButtonText}\n copyButtonText={copyButtonText}\n copiedButtonText={copiedButtonText}\n dynamicInteractionFormat={contentInfo.dynamicInteractionFormat}\n onTypeFinished={() => {\n onBlockComplete?.(index);\n }}\n />\n );\n })}\n </div>\n );\n};\n\nexport default MarkdownFlow;\n"],"names":["MarkdownFlow","initialContentList","customRenderBar","onSendProp","typingSpeedProp","enableTypewriter","onBlockComplete","confirmButtonText","copyButtonText","copiedButtonText","beforeSendProp","jsx","contentInfo","index","isFinished","enableTypewriterForBlock","onSend","typingSpeed","beforeSend","ContentRender"],"mappings":";;;;;AA+BA,MAAMA,IAA4C,CAAC;AAAA,EACjD,oBAAAC,IAAqB,CAAA;AAAA,EACrB,iBAAAC;AAAA,EACA,QAAQC;AAAA,EACR,aAAaC;AAAA,EACb,kBAAAC,IAAmB;AAAA,EACnB,iBAAAC;AAAA,EACA,mBAAAC;AAAA,EACA,gBAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,YAAYC;AACd,MAEIC,gBAAAA,MAAC,SAAI,WAAU,iBACZ,YAAmB,IAAI,CAACC,GAAaC,MAAU;AAC9C,QAAMC,IAAaF,EAAY,cAAc,IACvCG,IAA2B,CAACD,KAAcT,GAC1CW,IAASF,IAAa,SAAYX,GAClCc,IAAcH,IAAa,SAAYV,GACvCc,IAAaR,MAAmB,MAAM;AAC5C,SACEC,gBAAAA,EAAAA;AAAAA,IAACQ;AAAA,IAAA;AAAA,MAEC,SAASP,EAAY;AAAA,MACrB,kBAAkBA,EAAY;AAAA,MAC9B,mBAAmBA,EAAY;AAAA,MAC/B,uBAAuBA,EAAY;AAAA,MACnC,UAAUA,EAAY;AAAA,MACtB,kBAAkBG;AAAA,MAClB,iBAAiBH,EAAY,mBAAmBV;AAAA,MAChD,QAAAc;AAAA,MACA,YAAAE;AAAA,MACA,iCACEN,EAAY;AAAA,MAEd,aAAAK;AAAA,MACA,mBAAAV;AAAA,MACA,gBAAAC;AAAA,MACA,kBAAAC;AAAA,MACA,0BAA0BG,EAAY;AAAA,MACtC,gBAAgB,MAAM;AACpB,QAAAN,IAAkBO,CAAK;AAAA,MACzB;AAAA,IAAA;AAAA,IApBKA;AAAA,EAAA;AAuBX,CAAC,EAAA,CACH;"}
1
+ {"version":3,"file":"MarkdownFlow.js","sources":["../../../src/components/MarkdownFlow/MarkdownFlow.tsx"],"sourcesContent":["import React from \"react\";\nimport ContentRender from \"../ContentRender\";\nimport { CustomRenderBarProps, OnSendContentParams } from \"../types\";\nimport \"./markdownFlow.css\";\n\nexport interface MarkdownFlowProps {\n initialContentList?: {\n content: string;\n isFinished?: boolean;\n defaultInputText?: string;\n defaultButtonText?: string;\n defaultSelectedValues?: string[];\n readonly?: boolean;\n customRenderBar?: CustomRenderBarProps;\n onClickCustomButtonAfterContent?: () => void;\n dynamicInteractionFormat?: string;\n }[];\n customRenderBar?: CustomRenderBarProps;\n onSend?: (content: OnSendContentParams) => void;\n typingSpeed?: number;\n enableTypewriter?: boolean;\n onBlockComplete?: (blockIndex: number) => void;\n // Multi-select confirm button text (i18n support)\n confirmButtonText?: string;\n // Copy button text for code blocks\n copyButtonText?: string;\n // Copied state text for code blocks\n copiedButtonText?: string;\n beforeSend?: (content: OnSendContentParams) => boolean;\n}\n\nconst MarkdownFlow: React.FC<MarkdownFlowProps> = ({\n initialContentList = [],\n customRenderBar,\n onSend: onSendProp,\n typingSpeed: typingSpeedProp,\n enableTypewriter = false,\n onBlockComplete,\n confirmButtonText,\n copyButtonText,\n copiedButtonText,\n beforeSend: beforeSendProp,\n}) => {\n return (\n <div className=\"markdown-flow\">\n {initialContentList.map((contentInfo, index) => {\n const isFinished = contentInfo.isFinished ?? false;\n const enableTypewriterForBlock = !isFinished && enableTypewriter;\n const onSend = isFinished ? undefined : onSendProp;\n const typingSpeed = isFinished ? undefined : typingSpeedProp;\n const beforeSend = beforeSendProp ?? (() => true);\n return (\n <ContentRender\n key={index}\n content={contentInfo.content}\n defaultInputText={contentInfo.defaultInputText}\n defaultButtonText={contentInfo.defaultButtonText}\n defaultSelectedValues={contentInfo.defaultSelectedValues}\n readonly={contentInfo.readonly}\n enableTypewriter={enableTypewriterForBlock}\n customRenderBar={contentInfo.customRenderBar || customRenderBar}\n onSend={onSend}\n beforeSend={beforeSend}\n onClickCustomButtonAfterContent={\n contentInfo.onClickCustomButtonAfterContent\n }\n typingSpeed={typingSpeed}\n confirmButtonText={confirmButtonText}\n copyButtonText={copyButtonText}\n copiedButtonText={copiedButtonText}\n dynamicInteractionFormat={contentInfo.dynamicInteractionFormat}\n onTypeFinished={() => {\n onBlockComplete?.(index);\n }}\n />\n );\n })}\n </div>\n );\n};\n\nexport default MarkdownFlow;\n"],"names":["MarkdownFlow","initialContentList","customRenderBar","onSendProp","typingSpeedProp","enableTypewriter","onBlockComplete","confirmButtonText","copyButtonText","copiedButtonText","beforeSendProp","jsx","contentInfo","index","isFinished","enableTypewriterForBlock","onSend","typingSpeed","beforeSend","ContentRender"],"mappings":";;;;;;AA+BA,MAAMA,IAA4C,CAAC;AAAA,EACjD,oBAAAC,IAAqB,CAAA;AAAA,EACrB,iBAAAC;AAAA,EACA,QAAQC;AAAA,EACR,aAAaC;AAAA,EACb,kBAAAC,IAAmB;AAAA,EACnB,iBAAAC;AAAA,EACA,mBAAAC;AAAA,EACA,gBAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,YAAYC;AACd,MAEIC,gBAAAA,MAAC,SAAI,WAAU,iBACZ,YAAmB,IAAI,CAACC,GAAaC,MAAU;AAC9C,QAAMC,IAAaF,EAAY,cAAc,IACvCG,IAA2B,CAACD,KAAcT,GAC1CW,IAASF,IAAa,SAAYX,GAClCc,IAAcH,IAAa,SAAYV,GACvCc,IAAaR,MAAmB,MAAM;AAC5C,SACEC,gBAAAA,EAAAA;AAAAA,IAACQ;AAAA,IAAA;AAAA,MAEC,SAASP,EAAY;AAAA,MACrB,kBAAkBA,EAAY;AAAA,MAC9B,mBAAmBA,EAAY;AAAA,MAC/B,uBAAuBA,EAAY;AAAA,MACnC,UAAUA,EAAY;AAAA,MACtB,kBAAkBG;AAAA,MAClB,iBAAiBH,EAAY,mBAAmBV;AAAA,MAChD,QAAAc;AAAA,MACA,YAAAE;AAAA,MACA,iCACEN,EAAY;AAAA,MAEd,aAAAK;AAAA,MACA,mBAAAV;AAAA,MACA,gBAAAC;AAAA,MACA,kBAAAC;AAAA,MACA,0BAA0BG,EAAY;AAAA,MACtC,gBAAgB,MAAM;AACpB,QAAAN,IAAkBO,CAAK;AAAA,MACzB;AAAA,IAAA;AAAA,IApBKA;AAAA,EAAA;AAuBX,CAAC,EAAA,CACH;"}
package/dist/index.js CHANGED
@@ -1,14 +1,18 @@
1
- import { default as d } from "./components/MarkdownFlowEditor/MarkdownFlowEditor.js";
2
- import { default as p } from "./components/MarkdownFlow/MarkdownFlow.js";
1
+ import { default as f } from "./components/MarkdownFlowEditor/MarkdownFlowEditor.js";
2
+ import { default as m } from "./components/MarkdownFlow/MarkdownFlow.js";
3
3
  import "./_virtual/jsx-runtime.js";
4
4
  import "react";
5
5
  /* empty css */
6
- import { default as m } from "./components/ContentRender/ContentRender.js";
7
- import { default as w } from "./components/ContentRender/MarkdownFlowInput.js";
6
+ import { default as p } from "./components/ContentRender/ContentRender.js";
7
+ import { default as s } from "./components/ContentRender/IframeSandbox.js";
8
+ import { splitContentSegments as u } from "./components/ContentRender/utils/split-content.js";
9
+ import { default as i } from "./components/ContentRender/MarkdownFlowInput.js";
8
10
  export {
9
- m as ContentRender,
10
- p as MarkdownFlow,
11
- d as MarkdownFlowEditor,
12
- w as MarkdownFlowInput
11
+ p as ContentRender,
12
+ s as IframeSandbox,
13
+ m as MarkdownFlow,
14
+ f as MarkdownFlowEditor,
15
+ i as MarkdownFlowInput,
16
+ u as splitContentSegments
13
17
  };
14
18
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}