markdown-flow-ui 0.1.100-beta.2 → 0.1.100-beta.21

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 (90) hide show
  1. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-input@1.8.0_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-input/es/BaseInput.cjs.js +1 -1
  2. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-input@1.8.0_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-input/es/BaseInput.es.js +1 -1
  3. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/ResizableTextArea.cjs.js +1 -1
  4. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/ResizableTextArea.es.js +1 -1
  5. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/TextArea.cjs.js +1 -1
  6. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/TextArea.es.js +1 -1
  7. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/index.cjs.js +1 -1
  8. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/index.es.js +1 -1
  9. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/remark-flow@0.1.6/node_modules/remark-flow/dist/remark-custom-variable.cjs.js +1 -1
  10. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/remark-flow@0.1.6/node_modules/remark-flow/dist/remark-custom-variable.es.js +1 -1
  11. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/remark-flow@0.1.6/node_modules/remark-flow/dist/remark-interaction.cjs.js +1 -1
  12. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/remark-flow@0.1.6/node_modules/remark-flow/dist/remark-interaction.es.js +1 -1
  13. package/dist/_virtual/index.cjs3.js +1 -1
  14. package/dist/_virtual/index.cjs4.js +1 -1
  15. package/dist/_virtual/index.es3.js +4 -5
  16. package/dist/_virtual/index.es3.js.map +1 -1
  17. package/dist/_virtual/index.es4.js +5 -4
  18. package/dist/_virtual/index.es4.js.map +1 -1
  19. package/dist/assets/markdown-flow-ui.css +1 -1
  20. package/dist/components/ContentRender/ContentRender.cjs.js +2 -2
  21. package/dist/components/ContentRender/ContentRender.cjs.js.map +1 -1
  22. package/dist/components/ContentRender/ContentRender.d.ts +13 -10
  23. package/dist/components/ContentRender/ContentRender.es.js +175 -158
  24. package/dist/components/ContentRender/ContentRender.es.js.map +1 -1
  25. package/dist/components/ContentRender/IframeSandbox.cjs.js +3 -3
  26. package/dist/components/ContentRender/IframeSandbox.cjs.js.map +1 -1
  27. package/dist/components/ContentRender/IframeSandbox.d.ts +1 -0
  28. package/dist/components/ContentRender/IframeSandbox.es.js +331 -202
  29. package/dist/components/ContentRender/IframeSandbox.es.js.map +1 -1
  30. package/dist/components/ContentRender/SandboxApp.cjs.js +3 -3
  31. package/dist/components/ContentRender/SandboxApp.cjs.js.map +1 -1
  32. package/dist/components/ContentRender/SandboxApp.d.ts +4 -0
  33. package/dist/components/ContentRender/SandboxApp.es.js +144 -111
  34. package/dist/components/ContentRender/SandboxApp.es.js.map +1 -1
  35. package/dist/components/ContentRender/plugins/CustomVariable.cjs.js +1 -1
  36. package/dist/components/ContentRender/plugins/CustomVariable.cjs.js.map +1 -1
  37. package/dist/components/ContentRender/plugins/CustomVariable.es.js +68 -64
  38. package/dist/components/ContentRender/plugins/CustomVariable.es.js.map +1 -1
  39. package/dist/components/MarkdownFlow/MarkdownFlow.cjs.js +1 -1
  40. package/dist/components/MarkdownFlow/MarkdownFlow.cjs.js.map +1 -1
  41. package/dist/components/MarkdownFlow/MarkdownFlow.d.ts +3 -0
  42. package/dist/components/MarkdownFlow/MarkdownFlow.es.js +19 -16
  43. package/dist/components/MarkdownFlow/MarkdownFlow.es.js.map +1 -1
  44. package/dist/components/Slide/Player.cjs.js +1 -1
  45. package/dist/components/Slide/Player.cjs.js.map +1 -1
  46. package/dist/components/Slide/Player.d.ts +1 -0
  47. package/dist/components/Slide/Player.es.js +208 -168
  48. package/dist/components/Slide/Player.es.js.map +1 -1
  49. package/dist/components/Slide/Slide.cjs.js +1 -1
  50. package/dist/components/Slide/Slide.cjs.js.map +1 -1
  51. package/dist/components/Slide/Slide.d.ts +13 -0
  52. package/dist/components/Slide/Slide.es.js +374 -255
  53. package/dist/components/Slide/Slide.es.js.map +1 -1
  54. package/dist/components/Slide/Slide.stories.d.ts +21 -1
  55. package/dist/components/Slide/index.d.ts +3 -3
  56. package/dist/components/Slide/types.d.ts +6 -6
  57. package/dist/components/Slide/useSlide.cjs.js +1 -1
  58. package/dist/components/Slide/useSlide.cjs.js.map +1 -1
  59. package/dist/components/Slide/useSlide.d.ts +4 -1
  60. package/dist/components/Slide/useSlide.es.js +115 -81
  61. package/dist/components/Slide/useSlide.es.js.map +1 -1
  62. package/dist/components/Slide/useWakePlayerFromIframe.cjs.js +2 -0
  63. package/dist/components/Slide/useWakePlayerFromIframe.cjs.js.map +1 -0
  64. package/dist/components/Slide/useWakePlayerFromIframe.d.ts +7 -0
  65. package/dist/components/Slide/useWakePlayerFromIframe.es.js +89 -0
  66. package/dist/components/Slide/useWakePlayerFromIframe.es.js.map +1 -0
  67. package/dist/components/index.d.ts +4 -2
  68. package/dist/components/ui/inputGroup/textarea.cjs.js +1 -1
  69. package/dist/components/ui/inputGroup/textarea.es.js +1 -1
  70. package/dist/index.cjs.js +1 -1
  71. package/dist/index.es.js +24 -22
  72. package/dist/lib/interaction-defaults.cjs.js +2 -0
  73. package/dist/lib/interaction-defaults.cjs.js.map +1 -0
  74. package/dist/lib/interaction-defaults.es.js +106 -0
  75. package/dist/lib/interaction-defaults.es.js.map +1 -0
  76. package/dist/lib/sandboxInteraction.cjs.js +2 -0
  77. package/dist/lib/sandboxInteraction.cjs.js.map +1 -0
  78. package/dist/lib/sandboxInteraction.d.ts +8 -0
  79. package/dist/lib/sandboxInteraction.es.js +12 -0
  80. package/dist/lib/sandboxInteraction.es.js.map +1 -0
  81. package/dist/markdown-flow-ui-lib.css +1 -1
  82. package/dist/renderer.cjs.js +1 -1
  83. package/dist/renderer.d.ts +5 -3
  84. package/dist/renderer.es.js +18 -16
  85. package/package.json +17 -2
  86. package/dist/components/Slide/interaction-defaults.cjs.js +0 -2
  87. package/dist/components/Slide/interaction-defaults.cjs.js.map +0 -1
  88. package/dist/components/Slide/interaction-defaults.es.js +0 -85
  89. package/dist/components/Slide/interaction-defaults.es.js.map +0 -1
  90. /package/dist/{components/Slide → lib}/interaction-defaults.d.ts +0 -0
@@ -1,7 +1,7 @@
1
- import { j as w } from "../../_virtual/jsx-runtime.es.js";
2
- import { useRef as i, useState as L, useEffect as M } from "react";
3
- import Y 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.es.js";
4
- const Z = [
1
+ import { j as I } from "../../_virtual/jsx-runtime.es.js";
2
+ import { useRef as l, useState as D, useEffect as M } from "react";
3
+ import te 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.es.js";
4
+ const re = [
5
5
  "src",
6
6
  "srcset",
7
7
  "sizes",
@@ -13,54 +13,78 @@ const Z = [
13
13
  "loading",
14
14
  "decoding",
15
15
  "crossorigin",
16
- "referrerpolicy"
17
- ], U = (c) => Z.map(
18
- (t) => `${t}:${c.getAttribute(t) || ""}`
19
- ).join("|"), ee = (c) => {
16
+ "referrerpolicy",
17
+ "fetchpriority"
18
+ ], O = (o) => re.map(
19
+ (t) => `${t}:${o.getAttribute(t) || ""}`
20
+ ).join("|"), ne = (o) => {
20
21
  const t = /* @__PURE__ */ new Map();
21
- return c.querySelectorAll("img").forEach((u) => {
22
- const o = u, n = U(o), f = t.get(n) || [];
23
- f.push(o), t.set(n, f);
22
+ return o.querySelectorAll("img").forEach((e) => {
23
+ const i = e, s = O(i), u = t.get(s) || [];
24
+ u.push(i), t.set(s, u);
24
25
  }), t;
25
- }, te = (c, t) => {
26
- const u = Array.from(c.attributes), o = new Set(
27
- u.map((n) => n.name)
26
+ }, se = (o) => {
27
+ o.querySelectorAll("img").forEach((t) => {
28
+ const e = t;
29
+ e.getAttribute("loading") || e.setAttribute("loading", "eager"), e.getAttribute("decoding") || e.setAttribute("decoding", "async"), e.getAttribute("fetchpriority") || e.setAttribute("fetchpriority", "high");
30
+ });
31
+ }, oe = (o, t) => {
32
+ const e = Array.from(o.attributes), i = new Set(
33
+ e.map((s) => s.name)
28
34
  );
29
- Array.from(t.attributes).forEach((n) => {
30
- o.has(n.name) || t.removeAttribute(n.name);
31
- }), u.forEach((n) => {
32
- t.setAttribute(n.name, n.value);
35
+ Array.from(t.attributes).forEach((s) => {
36
+ i.has(s.name) || t.removeAttribute(s.name);
37
+ }), e.forEach((s) => {
38
+ t.setAttribute(s.name, s.value);
39
+ });
40
+ }, ie = (o) => {
41
+ const t = Array.from(o.querySelectorAll("img"));
42
+ return t.length === 0 ? Promise.resolve() : Promise.allSettled(
43
+ t.map((e) => {
44
+ const i = () => typeof e.decode != "function" ? Promise.resolve() : e.decode().catch(() => {
45
+ });
46
+ return e.complete && e.naturalWidth > 0 ? i() : new Promise((s) => {
47
+ const u = () => {
48
+ i().finally(() => s());
49
+ };
50
+ e.addEventListener("load", u, { once: !0 }), e.addEventListener("error", () => s(), { once: !0 });
51
+ });
52
+ })
53
+ ).then(() => {
33
54
  });
34
- }, re = (c, t) => {
35
- t.size && c.querySelectorAll("img").forEach((u) => {
36
- const o = u, n = U(o), f = t.get(n), h = f?.shift();
37
- h && (te(o, h), o.replaceWith(h), f && f.length === 0 && t.delete(n));
55
+ }, ce = (o, t) => {
56
+ t.size && o.querySelectorAll("img").forEach((e) => {
57
+ const i = e, s = O(i), u = t.get(s), b = u?.shift();
58
+ if (!b) return;
59
+ const v = b.cloneNode(!0);
60
+ oe(i, v), i.replaceWith(v), u && u.length === 0 && t.delete(s);
38
61
  });
39
- }, ae = ({
40
- html: c,
62
+ }, pe = ({
63
+ html: o,
41
64
  styleLoadingText: t,
42
- scriptLoadingText: u,
43
- resetToken: o = 0,
44
- mode: n = "content",
45
- hasRootVhHeight: f = !1
65
+ scriptLoadingText: e,
66
+ resetToken: i = 0,
67
+ mode: s = "content",
68
+ hasRootVhHeight: u = !1,
69
+ stretchRootHeight: b = !1
46
70
  }) => {
47
- const h = i(null), A = i(null), [, k] = L(!0), [V, C] = L(!1), [$, R] = L(!1), I = i([]), N = i([]), B = i(0), D = i(0), g = i(null), b = i(null), x = i(!1), S = i(!1), j = i(!1), G = i(o), K = 200, d = (r) => {
48
- r.current && (clearTimeout(r.current), r.current = null);
49
- }, z = (r, a, l, T) => {
50
- const v = performance.now() - l.current, p = Math.max(0, K - v);
51
- d(a), a.current = window.setTimeout(() => {
52
- r(!1), T?.(), a.current = null;
71
+ const v = l(null), R = l(null), [, z] = D(!0), [U, N] = D(!1), [$, j] = D(!1), F = l([]), L = l([]), B = l(0), G = l(0), x = l(null), A = l(null), S = l(!1), E = l(!1), k = l(!1), P = l(i), Q = 200, m = (n) => {
72
+ n.current && (clearTimeout(n.current), n.current = null);
73
+ }, W = (n, a, f, T) => {
74
+ const y = performance.now() - f.current, p = Math.max(0, Q - y);
75
+ m(a), a.current = window.setTimeout(() => {
76
+ n(!1), T?.(), a.current = null;
53
77
  }, p);
54
78
  };
55
79
  M(() => {
56
- const r = A.current?.ownerDocument;
57
- if (!r) return;
80
+ const n = R.current?.ownerDocument;
81
+ if (!n) return;
58
82
  const a = "sandbox-spinner-style";
59
- let l = r.getElementById(a);
60
- l || (l = r.createElement("style"), l.id = a, r.head?.appendChild(l)), l.textContent = `
83
+ let f = n.getElementById(a);
84
+ f || (f = n.createElement("style"), f.id = a, n.head?.appendChild(f)), f.textContent = `
61
85
  @keyframes sandbox-spin { from { transform: rotate(0deg);} to { transform: rotate(360deg);} }
62
86
  .sandbox-wrapper { align-items: center; }
63
- .sandbox-container { width: 100%; }
87
+ .sandbox-container { position: relative; width: 100%; }
64
88
  .sandbox-container svg,
65
89
  .sandbox-container img { display: block; margin-left: auto; margin-right: auto; }
66
90
  .justify-\\[safe_center\\]{
@@ -68,116 +92,125 @@ const Z = [
68
92
  }
69
93
  `;
70
94
  }, []), M(() => {
71
- o !== G.current && (j.current = !1, G.current = o), d(g), d(b), x.current = !1, S.current = !1;
72
- const r = A.current;
73
- if (!r) return;
74
- const a = r.ownerDocument, l = a?.body;
75
- if (!l) return;
76
- const T = ee(r);
77
- I.current.forEach((e) => e.remove()), I.current = [], N.current.forEach((e) => e.remove()), N.current = [];
78
- const v = j.current;
79
- k(!v), C(!1), R(!1);
95
+ i !== P.current && (k.current = !1, P.current = i), m(x), m(A), S.current = !1, E.current = !1;
96
+ const n = R.current;
97
+ if (!n) return;
98
+ const a = n.ownerDocument, f = a?.body;
99
+ if (!f) return;
100
+ const T = ne(n);
101
+ F.current.forEach((r) => r.remove()), F.current = [], L.current.forEach((r) => r.remove()), L.current = [];
102
+ const y = k.current;
103
+ z(!y), N(!1), j(!1);
80
104
  const p = a.createElement("div");
81
- p.innerHTML = c;
82
- const _ = (c.match(/<script[\s>]/gi) || []).length, J = (c.match(/<\/script>/gi) || []).length, P = _ > 0 && _ === J, y = [];
83
- Array.from(p.querySelectorAll("style, script")).forEach((e) => {
84
- if (e.tagName.toLowerCase() === "style") {
85
- const s = a.createElement("style");
86
- s.textContent = e.textContent || "", Array.from(e.attributes).forEach((m) => {
87
- s.setAttribute(m.name, m.value);
88
- }), y.push(s);
105
+ p.innerHTML = o;
106
+ const _ = (o.match(/<script[\s>]/gi) || []).length, Y = (o.match(/<\/script>/gi) || []).length, Z = _ > 0 && _ === Y, g = [];
107
+ Array.from(p.querySelectorAll("style, script")).forEach((r) => {
108
+ if (r.tagName.toLowerCase() === "style") {
109
+ const c = a.createElement("style");
110
+ c.textContent = r.textContent || "", Array.from(r.attributes).forEach((h) => {
111
+ c.setAttribute(h.name, h.value);
112
+ }), g.push(c);
89
113
  } else {
90
- const s = a.createElement("script");
91
- Array.from(e.attributes).forEach((m) => {
92
- s.setAttribute(m.name, m.value);
93
- }), s.textContent = e.textContent || "", y.push(s);
114
+ const c = a.createElement("script");
115
+ Array.from(r.attributes).forEach((h) => {
116
+ c.setAttribute(h.name, h.value);
117
+ }), c.textContent = r.textContent || "", g.push(c);
94
118
  }
95
- e.remove();
96
- }), re(p, T);
97
- const q = y.some(
98
- (e) => e.tagName.toLowerCase() === "style"
99
- ), F = y.some(
100
- (e) => e.tagName.toLowerCase() === "script"
119
+ r.remove();
120
+ }), se(p), ce(p, T);
121
+ const H = g.some(
122
+ (r) => r.tagName.toLowerCase() === "style"
123
+ ), V = g.some(
124
+ (r) => r.tagName.toLowerCase() === "script"
101
125
  );
102
- q && (x.current = !0, B.current = performance.now(), d(g), C(!0)), F && (S.current = !0, D.current = performance.now(), d(b), R(!0));
103
- const H = !!p.firstElementChild;
104
- k(!H && !v), H && (j.current = !0), r.innerHTML = "";
105
- const X = Array.from(p.childNodes);
106
- r.append(...X), y.forEach((e) => {
107
- if (e.tagName.toLowerCase() === "style") {
108
- a.head?.appendChild(e), I.current.push(e);
126
+ H && (S.current = !0, B.current = performance.now(), m(x), N(!0)), V && (E.current = !0, G.current = performance.now(), m(A), j(!0));
127
+ const K = !!p.firstElementChild;
128
+ z(!K && !y), K && (k.current = !0);
129
+ const d = y && n.childNodes.length > 0 && p.querySelector("img") !== null ? n.cloneNode(!0) : null;
130
+ d && (d.setAttribute("aria-hidden", "true"), d.style.position = "absolute", d.style.inset = "0", d.style.zIndex = "2", d.style.pointerEvents = "none", d.style.background = "transparent");
131
+ const ee = Array.from(p.childNodes);
132
+ n.replaceChildren(...ee), d && (n.appendChild(d), ie(n).finally(() => {
133
+ requestAnimationFrame(() => {
134
+ d.remove();
135
+ });
136
+ })), g.forEach((r) => {
137
+ if (r.tagName.toLowerCase() === "style") {
138
+ a.head?.appendChild(r), F.current.push(r);
109
139
  return;
110
140
  }
111
- if (P) {
112
- const s = e, m = s.textContent || "";
113
- if (!s.src)
141
+ if (Z) {
142
+ const c = r, h = c.textContent || "";
143
+ if (!c.src)
114
144
  try {
115
- new Function(m);
145
+ new Function(h);
116
146
  } catch {
117
- s.remove();
147
+ c.remove();
118
148
  return;
119
149
  }
120
150
  try {
121
- l.appendChild(s), N.current.push(s);
151
+ f.appendChild(c), L.current.push(c);
122
152
  } catch {
123
- s.remove();
153
+ c.remove();
124
154
  }
125
155
  } else
126
- e.remove();
156
+ r.remove();
127
157
  }), requestAnimationFrame(() => {
128
- q && z(
129
- C,
130
- g,
158
+ H && W(
159
+ N,
160
+ x,
131
161
  B,
132
162
  () => {
133
- x.current = !1;
163
+ S.current = !1;
134
164
  }
135
- ), F && z(
136
- R,
137
- b,
138
- D,
165
+ ), V && W(
166
+ j,
167
+ A,
168
+ G,
139
169
  () => {
140
- S.current = !1;
170
+ E.current = !1;
141
171
  }
142
172
  );
143
173
  });
144
- }, [c, o]), M(
174
+ }, [o, i]), M(
145
175
  () => () => {
146
- d(g), d(b);
176
+ m(x), m(A);
147
177
  },
148
178
  []
149
179
  );
150
- const E = $ || S.current ? u || "Building scripts cache..." : V || x.current ? t || "Building styles..." : null, W = n === "blackboard", O = {
180
+ const w = $ || E.current ? e || "Building scripts cache..." : U || S.current ? t || "Building styles..." : null, q = s === "blackboard", C = q && b, J = {
151
181
  position: "relative",
152
182
  width: "100%",
153
183
  height: "100%",
154
184
  display: "flex",
155
185
  flexDirection: "column",
156
186
  // Keep blackboard scroll behavior while centering content in non-blackboard mode
157
- justifyContent: W ? "space-around" : "flex-start"
158
- }, Q = {
159
- pointerEvents: E ? "none" : void 0,
160
- margin: W ? void 0 : "auto 0",
161
- width: "100%"
187
+ justifyContent: C ? "flex-start" : q ? "space-around" : "flex-start"
188
+ }, X = {
189
+ pointerEvents: w ? "none" : void 0,
190
+ margin: q ? void 0 : "auto 0",
191
+ width: "100%",
192
+ height: C ? "100%" : void 0,
193
+ minHeight: C ? 0 : void 0,
194
+ flex: C ? "1 1 auto" : void 0
162
195
  };
163
- return /* @__PURE__ */ w.jsxs(
196
+ return /* @__PURE__ */ I.jsxs(
164
197
  "div",
165
198
  {
166
- ref: h,
167
- "data-root-vh": f ? "true" : "false",
199
+ ref: v,
200
+ "data-root-vh": u ? "true" : "false",
168
201
  className: "sandbox-wrapper",
169
- style: O,
170
- "aria-busy": !!E,
202
+ style: J,
203
+ "aria-busy": !!w,
171
204
  children: [
172
- /* @__PURE__ */ w.jsx(
205
+ /* @__PURE__ */ I.jsx(
173
206
  "div",
174
207
  {
175
- ref: A,
208
+ ref: R,
176
209
  className: "sandbox-container",
177
- style: Q
210
+ style: X
178
211
  }
179
212
  ),
180
- E && /* @__PURE__ */ w.jsxs(
213
+ w && /* @__PURE__ */ I.jsxs(
181
214
  "div",
182
215
  {
183
216
  style: {
@@ -195,15 +228,15 @@ const Z = [
195
228
  zIndex: 20
196
229
  },
197
230
  children: [
198
- /* @__PURE__ */ w.jsx(
199
- Y,
231
+ /* @__PURE__ */ I.jsx(
232
+ te,
200
233
  {
201
234
  "aria-hidden": !0,
202
235
  size: 20,
203
236
  style: { animation: "sandbox-spin 1s linear infinite" }
204
237
  }
205
238
  ),
206
- E
239
+ w
207
240
  ]
208
241
  }
209
242
  )
@@ -212,6 +245,6 @@ const Z = [
212
245
  );
213
246
  };
214
247
  export {
215
- ae as default
248
+ pe as default
216
249
  };
217
250
  //# sourceMappingURL=SandboxApp.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SandboxApp.es.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 styleLoadingText?: string;\n scriptLoadingText?: string;\n resetToken?: number;\n mode?: \"content\" | \"blackboard\";\n hasRootVhHeight?: boolean;\n}\n\nconst IMAGE_REUSE_ATTRIBUTES = [\n \"src\",\n \"srcset\",\n \"sizes\",\n \"alt\",\n \"class\",\n \"width\",\n \"height\",\n \"style\",\n \"loading\",\n \"decoding\",\n \"crossorigin\",\n \"referrerpolicy\",\n];\n\nconst getImageReuseKey = (image: HTMLImageElement) =>\n IMAGE_REUSE_ATTRIBUTES.map(\n (attribute) => `${attribute}:${image.getAttribute(attribute) || \"\"}`\n ).join(\"|\");\n\nconst collectReusableImages = (root: ParentNode) => {\n const imageMap = new Map<string, HTMLImageElement[]>();\n root.querySelectorAll(\"img\").forEach((node) => {\n const image = node as HTMLImageElement;\n const key = getImageReuseKey(image);\n const bucket = imageMap.get(key) || [];\n bucket.push(image);\n imageMap.set(key, bucket);\n });\n return imageMap;\n};\n\nconst syncImageAttributes = (\n sourceImage: HTMLImageElement,\n targetImage: HTMLImageElement\n) => {\n const sourceAttributes = Array.from(sourceImage.attributes);\n const sourceAttributeNames = new Set(\n sourceAttributes.map((attribute) => attribute.name)\n );\n\n Array.from(targetImage.attributes).forEach((attribute) => {\n if (!sourceAttributeNames.has(attribute.name)) {\n targetImage.removeAttribute(attribute.name);\n }\n });\n\n sourceAttributes.forEach((attribute) => {\n targetImage.setAttribute(attribute.name, attribute.value);\n });\n};\n\nconst reuseRenderedImages = (\n root: ParentNode,\n imageMap: Map<string, HTMLImageElement[]>\n) => {\n if (!imageMap.size) return;\n\n root.querySelectorAll(\"img\").forEach((node) => {\n const nextImage = node as HTMLImageElement;\n const key = getImageReuseKey(nextImage);\n const bucket = imageMap.get(key);\n const preservedImage = bucket?.shift();\n if (!preservedImage) return;\n\n syncImageAttributes(nextImage, preservedImage);\n nextImage.replaceWith(preservedImage);\n\n if (bucket && bucket.length === 0) {\n imageMap.delete(key);\n }\n });\n};\n\nconst SandboxApp: React.FC<SandboxAppProps> = ({\n html,\n styleLoadingText,\n scriptLoadingText,\n resetToken = 0,\n mode = \"content\",\n hasRootVhHeight = false,\n}) => {\n const wrapperRef = useRef<HTMLDivElement>(null);\n const containerRef = useRef<HTMLDivElement>(null);\n const [, setIsWaitingFirstDiv] = useState(true);\n const [isGeneratingStyles, setIsGeneratingStyles] = useState(false);\n const [isGeneratingScripts, setIsGeneratingScripts] = 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 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 doc.head?.appendChild(styleEl);\n }\n styleEl.textContent = `\n @keyframes sandbox-spin { from { transform: rotate(0deg);} to { transform: rotate(360deg);} }\n .sandbox-wrapper { align-items: center; }\n .sandbox-container { width: 100%; }\n .sandbox-container svg,\n .sandbox-container img { display: block; margin-left: auto; margin-right: auto; }\n .justify-\\\\[safe_center\\\\]{\n justify-content: safe center;\n }\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 const reusableImages = collectReusableImages(container);\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 const wrapper = doc.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 reuseRenderedImages(wrapper, reusableImages);\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 container.innerHTML = \"\";\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 return null;\n })();\n\n const isBlackboard = mode === \"blackboard\";\n const sandboxWrapperStyle: React.CSSProperties = {\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n flexDirection: \"column\",\n // Keep blackboard scroll behavior while centering content in non-blackboard mode\n justifyContent: isBlackboard ? \"space-around\" : \"flex-start\",\n };\n const sandboxContainerStyle: React.CSSProperties = {\n pointerEvents: overlayMessage ? \"none\" : undefined,\n margin: isBlackboard ? undefined : \"auto 0\",\n width: \"100%\",\n };\n\n return (\n <div\n ref={wrapperRef}\n data-root-vh={hasRootVhHeight ? \"true\" : \"false\"}\n className=\"sandbox-wrapper\"\n style={sandboxWrapperStyle}\n aria-busy={!!overlayMessage}\n >\n <div\n ref={containerRef}\n className=\"sandbox-container\"\n style={sandboxContainerStyle}\n />\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":["IMAGE_REUSE_ATTRIBUTES","getImageReuseKey","image","attribute","collectReusableImages","root","imageMap","node","key","bucket","syncImageAttributes","sourceImage","targetImage","sourceAttributes","sourceAttributeNames","reuseRenderedImages","nextImage","preservedImage","SandboxApp","html","styleLoadingText","scriptLoadingText","resetToken","mode","hasRootVhHeight","wrapperRef","useRef","containerRef","setIsWaitingFirstDiv","useState","isGeneratingStyles","setIsGeneratingStyles","isGeneratingScripts","setIsGeneratingScripts","appendedStylesRef","appendedScriptsRef","styleStartRef","scriptStartRef","styleTimerRef","scriptTimerRef","hasStylesRef","hasScriptsRef","hasRenderedContentRef","prevResetTokenRef","MIN_LOADING_MS","clearTimer","timerRef","settleStateWithMinimumDelay","setter","startRef","onDone","elapsed","delay","useEffect","doc","styleId","styleEl","container","body","reusableImages","hasRenderedBefore","wrapper","openScriptCount","closeScriptCount","shouldExecuteScripts","resourceQueue","cloned","attr","replacement","hasStyles","hasScripts","hasFirstElement","contentNodes","scriptNode","scriptText","overlayMessage","isBlackboard","sandboxWrapperStyle","sandboxContainerStyle","jsxs","jsx","Loader2"],"mappings":";;;AAYA,MAAMA,IAAyB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAEMC,IAAmB,CAACC,MACxBF,EAAuB;AAAA,EACrB,CAACG,MAAc,GAAGA,CAAS,IAAID,EAAM,aAAaC,CAAS,KAAK,EAAE;AACpE,EAAE,KAAK,GAAG,GAENC,KAAwB,CAACC,MAAqB;AAClD,QAAMC,wBAAe,IAAA;AACrB,SAAAD,EAAK,iBAAiB,KAAK,EAAE,QAAQ,CAACE,MAAS;AAC7C,UAAML,IAAQK,GACRC,IAAMP,EAAiBC,CAAK,GAC5BO,IAASH,EAAS,IAAIE,CAAG,KAAK,CAAA;AACpC,IAAAC,EAAO,KAAKP,CAAK,GACjBI,EAAS,IAAIE,GAAKC,CAAM;AAAA,EAC1B,CAAC,GACMH;AACT,GAEMI,KAAsB,CAC1BC,GACAC,MACG;AACH,QAAMC,IAAm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V,OAAO;AAAA,cACP,SAAS;AAAA,cACT,YAAY;AAAA,cACZ,gBAAgB;AAAA,cAChB,YAAY;AAAA,cACZ,OAAO;AAAA,cACP,UAAU;AAAA,cACV,YAAY;AAAA,cACZ,KAAK;AAAA,cACL,eAAe;AAAA,cACf,QAAQ;AAAA,YAAA;AAAA,YAGV,UAAA;AAAA,cAAAC,gBAAAA,EAAAA;AAAAA,gBAACC;AAAAA,gBAAA;AAAA,kBACC,eAAW;AAAA,kBACX,MAAM;AAAA,kBACN,OAAO,EAAE,WAAW,kCAAA;AAAA,gBAAkC;AAAA,cAAA;AAAA,cAEvDN;AAAA,YAAA;AAAA,UAAA;AAAA,QAAA;AAAA,MACH;AAAA,IAAA;AAAA,EAAA;AAIR;"}
1
+ {"version":3,"file":"SandboxApp.es.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 hideFullScreen?: boolean;\n resetToken?: number;\n mode?: \"content\" | \"blackboard\";\n hasRootVhHeight?: boolean;\n stretchRootHeight?: boolean;\n}\n\nconst IMAGE_REUSE_ATTRIBUTES = [\n \"src\",\n \"srcset\",\n \"sizes\",\n \"alt\",\n \"class\",\n \"width\",\n \"height\",\n \"style\",\n \"loading\",\n \"decoding\",\n \"crossorigin\",\n \"referrerpolicy\",\n \"fetchpriority\",\n];\n\nconst getImageReuseKey = (image: HTMLImageElement) =>\n IMAGE_REUSE_ATTRIBUTES.map(\n (attribute) => `${attribute}:${image.getAttribute(attribute) || \"\"}`\n ).join(\"|\");\n\nconst collectReusableImages = (root: ParentNode) => {\n const imageMap = new Map<string, HTMLImageElement[]>();\n root.querySelectorAll(\"img\").forEach((node) => {\n const image = node as HTMLImageElement;\n const key = getImageReuseKey(image);\n const bucket = imageMap.get(key) || [];\n bucket.push(image);\n imageMap.set(key, bucket);\n });\n return imageMap;\n};\n\nconst applyImageLoadingHints = (root: ParentNode) => {\n root.querySelectorAll(\"img\").forEach((node) => {\n const image = node as HTMLImageElement;\n\n if (!image.getAttribute(\"loading\")) {\n image.setAttribute(\"loading\", \"eager\");\n }\n\n if (!image.getAttribute(\"decoding\")) {\n image.setAttribute(\"decoding\", \"async\");\n }\n\n if (!image.getAttribute(\"fetchpriority\")) {\n image.setAttribute(\"fetchpriority\", \"high\");\n }\n });\n};\n\nconst syncImageAttributes = (\n sourceImage: HTMLImageElement,\n targetImage: HTMLImageElement\n) => {\n const sourceAttributes = Array.from(sourceImage.attributes);\n const sourceAttributeNames = new Set(\n sourceAttributes.map((attribute) => attribute.name)\n );\n\n Array.from(targetImage.attributes).forEach((attribute) => {\n if (!sourceAttributeNames.has(attribute.name)) {\n targetImage.removeAttribute(attribute.name);\n }\n });\n\n sourceAttributes.forEach((attribute) => {\n targetImage.setAttribute(attribute.name, attribute.value);\n });\n};\n\nconst waitForImagesReady = (root: ParentNode) => {\n const images = Array.from(root.querySelectorAll(\"img\")) as HTMLImageElement[];\n\n if (images.length === 0) {\n return Promise.resolve();\n }\n\n return Promise.allSettled(\n images.map((image) => {\n const waitForDecode = () => {\n if (typeof image.decode !== \"function\") {\n return Promise.resolve();\n }\n\n return image.decode().catch(() => undefined);\n };\n\n if (image.complete && image.naturalWidth > 0) {\n return waitForDecode();\n }\n\n return new Promise<void>((resolve) => {\n const settle = () => {\n void waitForDecode().finally(() => resolve());\n };\n\n image.addEventListener(\"load\", settle, { once: true });\n image.addEventListener(\"error\", () => resolve(), { once: true });\n });\n })\n ).then(() => undefined);\n};\n\nconst reuseRenderedImages = (\n root: ParentNode,\n imageMap: Map<string, HTMLImageElement[]>\n) => {\n if (!imageMap.size) return;\n\n root.querySelectorAll(\"img\").forEach((node) => {\n const nextImage = node as HTMLImageElement;\n const key = getImageReuseKey(nextImage);\n const bucket = imageMap.get(key);\n const preservedImage = bucket?.shift();\n if (!preservedImage) return;\n\n // Clone the already-rendered image instead of moving the live node out of\n // the visible tree before the next DOM commit.\n const clonedImage = preservedImage.cloneNode(true) as HTMLImageElement;\n syncImageAttributes(nextImage, clonedImage);\n nextImage.replaceWith(clonedImage);\n\n if (bucket && bucket.length === 0) {\n imageMap.delete(key);\n }\n });\n};\n\nconst SandboxApp: React.FC<SandboxAppProps> = ({\n html,\n styleLoadingText,\n scriptLoadingText,\n resetToken = 0,\n mode = \"content\",\n hasRootVhHeight = false,\n stretchRootHeight = false,\n}) => {\n const wrapperRef = useRef<HTMLDivElement>(null);\n const containerRef = useRef<HTMLDivElement>(null);\n const [, setIsWaitingFirstDiv] = useState(true);\n const [isGeneratingStyles, setIsGeneratingStyles] = useState(false);\n const [isGeneratingScripts, setIsGeneratingScripts] = 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 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 doc.head?.appendChild(styleEl);\n }\n styleEl.textContent = `\n @keyframes sandbox-spin { from { transform: rotate(0deg);} to { transform: rotate(360deg);} }\n .sandbox-wrapper { align-items: center; }\n .sandbox-container { position: relative; width: 100%; }\n .sandbox-container svg,\n .sandbox-container img { display: block; margin-left: auto; margin-right: auto; }\n .justify-\\\\[safe_center\\\\]{\n justify-content: safe center;\n }\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 const reusableImages = collectReusableImages(container);\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 const wrapper = doc.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 applyImageLoadingHints(wrapper);\n reuseRenderedImages(wrapper, reusableImages);\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 shouldKeepPreviousFrameVisible =\n hasRenderedBefore &&\n container.childNodes.length > 0 &&\n wrapper.querySelector(\"img\") !== null;\n const previousFrameOverlay = shouldKeepPreviousFrameVisible\n ? (container.cloneNode(true) as HTMLDivElement)\n : null;\n\n if (previousFrameOverlay) {\n previousFrameOverlay.setAttribute(\"aria-hidden\", \"true\");\n previousFrameOverlay.style.position = \"absolute\";\n previousFrameOverlay.style.inset = \"0\";\n previousFrameOverlay.style.zIndex = \"2\";\n previousFrameOverlay.style.pointerEvents = \"none\";\n previousFrameOverlay.style.background = \"transparent\";\n }\n\n const contentNodes = Array.from(wrapper.childNodes);\n container.replaceChildren(...contentNodes);\n\n if (previousFrameOverlay) {\n container.appendChild(previousFrameOverlay);\n void waitForImagesReady(container).finally(() => {\n requestAnimationFrame(() => {\n previousFrameOverlay.remove();\n });\n });\n }\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 return null;\n })();\n\n const isBlackboard = mode === \"blackboard\";\n const shouldStretchRootHeight = isBlackboard && stretchRootHeight;\n const sandboxWrapperStyle: React.CSSProperties = {\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n flexDirection: \"column\",\n // Keep blackboard scroll behavior while centering content in non-blackboard mode\n justifyContent: shouldStretchRootHeight\n ? \"flex-start\"\n : isBlackboard\n ? \"space-around\"\n : \"flex-start\",\n };\n const sandboxContainerStyle: React.CSSProperties = {\n pointerEvents: overlayMessage ? \"none\" : undefined,\n margin: isBlackboard ? undefined : \"auto 0\",\n width: \"100%\",\n height: shouldStretchRootHeight ? \"100%\" : undefined,\n minHeight: shouldStretchRootHeight ? 0 : undefined,\n flex: shouldStretchRootHeight ? \"1 1 auto\" : undefined,\n };\n\n return (\n <div\n ref={wrapperRef}\n data-root-vh={hasRootVhHeight ? \"true\" : \"false\"}\n className=\"sandbox-wrapper\"\n style={sandboxWrapperStyle}\n aria-busy={!!overlayMessage}\n >\n <div\n ref={containerRef}\n className=\"sandbox-container\"\n style={sandboxContainerStyle}\n />\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":["IMAGE_REUSE_ATTRIBUTES","getImageReuseKey","image","attribute","collectReusableImages","root","imageMap","node","key","bucket","applyImageLoadingHints","syncImageAttributes","sourceImage","targetImage","sourceAttributes","sourceAttributeNames","waitForImagesReady","images","waitForDecode","resolve","settle","reuseRenderedImages","nextImage","preservedImage","clonedImage","SandboxApp","html","styleLoadingText","scriptLoadingText","resetToken","mode","hasRootVhHeight","stretchRootHeight","wrapperRef","useRef","containerRef","setIsWaitingFirstDiv","useState","isGeneratingStyles","setIsGeneratingStyles","isGeneratingScripts","setIsGeneratingScripts","appendedStylesRef","appendedScriptsRef","styleStartRef","scriptStartRef","styleTimerRef","scriptTimerRef","hasStylesRef","hasScriptsRef","hasRenderedContentRef","prevResetTokenRef","MIN_LOADING_MS","clearTimer","timerRef","settleStateWithMinimumDelay","setter","startRef","onDone","elapsed","delay","useEffect","doc","styleId","styleEl","container","body","reusableImages","hasRenderedBefore","wrapper","openScriptCount","closeScriptCount","shouldExecuteScripts","resourceQueue","cloned","attr","replacement","hasStyles","hasScripts","hasFirstElement","previousFrameOverlay","contentNodes","scriptNode","scriptText","overlayMessage","isBlackboard","shou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B;AAAA,cAChB,YAAY;AAAA,cACZ,OAAO;AAAA,cACP,UAAU;AAAA,cACV,YAAY;AAAA,cACZ,KAAK;AAAA,cACL,eAAe;AAAA,cACf,QAAQ;AAAA,YAAA;AAAA,YAGV,UAAA;AAAA,cAAAC,gBAAAA,EAAAA;AAAAA,gBAACC;AAAAA,gBAAA;AAAA,kBACC,eAAW;AAAA,kBACX,MAAM;AAAA,kBACN,OAAO,EAAE,WAAW,kCAAA;AAAA,gBAAkC;AAAA,cAAA;AAAA,cAEvDP;AAAA,YAAA;AAAA,UAAA;AAAA,QAAA;AAAA,MACH;AAAA,IAAA;AAAA,EAAA;AAIR;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("../../../_virtual/jsx-runtime.cjs.js"),N=require("react"),D=require("../../ui/button.cjs.js"),G=require("../../ui/checkbox.cjs.js"),I=require("../MarkdownFlowInput.cjs.js"),V=require("../../ui/inputGroup/input-group.cjs.js"),K=require("../../../lib/utils.cjs.js"),O=({node:e,readonly:r,selectedValues:n,inputValue:u,confirmButtonText:x,handleCheckboxChange:m,handleInputChange:h,handleKeyDown:a,handleConfirmClick:i})=>{const p=e.properties?.placeholder,c=r||n.length===0&&!u?.trim(),g=l=>s.jsxRuntimeExports.jsx("span",{className:K.cn("multi-select-confirm-wrapper flex flex-col items-center",c?"opacity-50 cursor-not-allowed":"cursor-pointer",l),children:s.jsxRuntimeExports.jsx("button",{type:"button",className:"multi-select-confirm-button text-sm font-medium text-primary",disabled:c,onClick:i,children:x})});return s.jsxRuntimeExports.jsxs("span",{className:"multi-select-container flex w-full flex-col",children:[s.jsxRuntimeExports.jsx("span",{className:"flex flex-wrap gap-y-[9px] gap-x-6",children:e.properties?.buttonTexts?.map((l,v)=>{const f=e.properties?.buttonValues?.[v],b=f!==void 0?f:l;return s.jsxRuntimeExports.jsx(G.Checkbox,{label:l,disabled:r,checked:n.includes(b),onCheckedChange:j=>m(b,j),className:"text-sm"},v)})}),p?s.jsxRuntimeExports.jsx("span",{className:"block mb-1 w-full max-w-[500px]",children:s.jsxRuntimeExports.jsxs("span",{className:"multi-select-input-row flex w-full items-end gap-3",children:[s.jsxRuntimeExports.jsx(V.InputGroup,{"data-disabled":r,className:"flex-1",children:s.jsxRuntimeExports.jsx(V.InputGroupTextarea,{disabled:r,placeholder:p,value:u,onChange:h,onKeyDown:a,className:"text-sm px-3",title:p})}),g("shrink-0")]})}):g("self-start multi-select-confirm-wrapper--stacked")]})},F=({node:e,readonly:r,resolvedDefaultButtonText:n,handleButtonClick:u,inputValue:x,handleInputChange:m,handleSendClick:h})=>s.jsxRuntimeExports.jsxs("span",{className:"single-select-container inline-flex w-full flex-col",children:[s.jsxRuntimeExports.jsx("span",{className:"flex flex-wrap gap-y-[9px] gap-x-2",children:e.properties?.buttonTexts?.map((a,i)=>{const p=e.properties?.buttonValues?.[i],c=p!==void 0?p:a;return s.jsxRuntimeExports.jsx(D.Button,{disabled:r,variant:"outline",type:"button",size:"sm",onClick:()=>u(c),className:`cursor-pointer h-8 text-sm hover:bg-gray-200 ${n===a?"select":""}`,children:a},i)})}),e.properties?.placeholder&&s.jsxRuntimeExports.jsx("span",{className:"mt-[9px] mb-1",children:s.jsxRuntimeExports.jsx(I.default,{disabled:r,placeholder:e.properties.placeholder,value:x,onChange:m,onSend:h,title:e.properties.placeholder})})]}),_=({readonly:e,placeholder:r,value:n,onChange:u,onSend:x})=>r?s.jsxRuntimeExports.jsx(I.default,{disabled:e,placeholder:r,value:n,onChange:u,onSend:x,title:r}):null,z=({node:e,readonly:r,defaultButtonText:n,defaultInputText:u,defaultSelectedValues:x,onSend:m,confirmButtonText:h="Submit",beforeSend:a=()=>!0})=>{const[i,p]=N.useState(u||""),[c,g]=N.useState(x||[]),l=e.properties?.isMultiSelect??!1,v=e.properties?.buttonTexts||[],f=!l&&v.length===0&&!e.properties?.placeholder,b=e.properties?.variableName?.trim()||n||"Submit",j=N.useMemo(()=>f?{...e,properties:{...e.properties||{},buttonTexts:[b],buttonValues:[b]}}:e,[b,e,f]),d=j.properties?.buttonTexts||[],R=j.properties?.buttonValues||[],C=!l&&d.length>0,M=t=>{const o={variableName:e.properties?.variableName||"",buttonText:t};a?.(o)&&m?.(o)},T=(t,o)=>{g(w=>o?[...w,t]:w.filter(B=>B!==t))},k=()=>{const t=c.length===0&&!i?.trim(),o={variableName:e.properties?.variableName||"",selectedValues:c,inputText:i?.trim()||void 0};r||t||a?.(o)&&m?.(o)},S=t=>{p(t.target.value)},q=t=>{t.nativeEvent.isComposing||t.keyCode===229||t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),l?c.length===0&&!i.trim()||k():E())},E=()=>{const t={variableName:e.properties?.variableName||"",inputText:i};a?.(t)&&m?.(t)},y=N.useMemo(()=>{if(!n)return;const t=R.indexOf(n);if(t>-1)return d[t]??n;const o=d.indexOf(n);if(o>-1)return d[o]},[n,d,R]);return s.jsxRuntimeExports.jsxs("span",{className:"custom-variable-container inline-flex items-center flex-wrap",children:[l&&s.jsxRuntimeExports.jsx(O,{node:e,readonly:r,selectedValues:c,inputValue:i,confirmButtonText:h,handleCheckboxChange:T,handleInputChange:S,handleKeyDown:q,handleConfirmClick:k}),!l&&C&&s.jsxRuntimeExports.jsx(F,{node:j,readonly:r,resolvedDefaultButtonText:y,handleButtonClick:M,inputValue:i,handleInputChange:S,handleSendClick:E}),!l&&!C&&e.properties?.placeholder&&s.jsxRuntimeExports.jsx(_,{readonly:r,placeholder:e.properties.placeholder,value:i,onChange:S,onSend:E})]})};exports.default=z;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("../../../_virtual/jsx-runtime.cjs.js"),N=require("react"),G=require("../../ui/button.cjs.js"),K=require("../../ui/checkbox.cjs.js"),I=require("../MarkdownFlowInput.cjs.js"),V=require("../../ui/inputGroup/input-group.cjs.js"),M=require("../../../lib/utils.cjs.js"),O=({node:e,readonly:n,selectedValues:r,inputValue:u,confirmButtonText:x,handleCheckboxChange:m,handleInputChange:b,handleKeyDown:a,handleConfirmClick:l})=>{const p=e.properties?.placeholder,c=n||r.length===0&&!u?.trim(),g=i=>s.jsxRuntimeExports.jsx("span",{className:M.cn("multi-select-confirm-wrapper flex flex-col items-center",c?"opacity-50 cursor-not-allowed":"cursor-pointer",i),children:s.jsxRuntimeExports.jsx("button",{type:"button",className:"multi-select-confirm-button text-sm font-medium text-primary",disabled:c,onClick:l,children:x})});return s.jsxRuntimeExports.jsxs("span",{className:"multi-select-container flex w-full flex-col",children:[s.jsxRuntimeExports.jsx("span",{className:"flex flex-wrap gap-y-[9px] gap-x-6",children:e.properties?.buttonTexts?.map((i,v)=>{const f=e.properties?.buttonValues?.[v],h=f!==void 0?f:i;return s.jsxRuntimeExports.jsx(K.Checkbox,{label:i,disabled:n,checked:r.includes(h),onCheckedChange:d=>m(h,d),className:"text-sm"},v)})}),p?s.jsxRuntimeExports.jsx("span",{className:"block mb-1 w-full max-w-[500px]",children:s.jsxRuntimeExports.jsxs("span",{className:"multi-select-input-row flex w-full items-end gap-3",children:[s.jsxRuntimeExports.jsx(V.InputGroup,{"data-disabled":n,className:"flex-1",children:s.jsxRuntimeExports.jsx(V.InputGroupTextarea,{disabled:n,placeholder:p,value:u,onChange:b,onKeyDown:a,className:"text-sm px-3",title:p})}),g("shrink-0")]})}):g("self-start multi-select-confirm-wrapper--stacked")]})},F=({node:e,readonly:n,resolvedDefaultButtonText:r,handleButtonClick:u,inputValue:x,handleInputChange:m,handleSendClick:b})=>s.jsxRuntimeExports.jsxs("span",{className:"single-select-container inline-flex w-full flex-col",children:[s.jsxRuntimeExports.jsx("span",{className:"flex flex-wrap gap-y-[9px] gap-x-2",children:e.properties?.buttonTexts?.map((a,l)=>{const p=e.properties?.buttonValues?.[l],c=p!==void 0?p:a;return s.jsxRuntimeExports.jsx(G.Button,{disabled:n,variant:"outline",type:"button",size:"sm",onClick:()=>u(c),className:M.cn("max-w-full shrink whitespace-normal break-words text-left leading-5 h-auto min-h-8 px-3 py-1.5","hover:bg-gray-200",r===a&&"select"),children:a},l)})}),e.properties?.placeholder&&s.jsxRuntimeExports.jsx("span",{className:"mt-[9px] mb-1",children:s.jsxRuntimeExports.jsx(I.default,{disabled:n,placeholder:e.properties.placeholder,value:x,onChange:m,onSend:b,title:e.properties.placeholder})})]}),_=({readonly:e,placeholder:n,value:r,onChange:u,onSend:x})=>n?s.jsxRuntimeExports.jsx(I.default,{disabled:e,placeholder:n,value:r,onChange:u,onSend:x,title:n}):null,z=({node:e,readonly:n,defaultButtonText:r,defaultInputText:u,defaultSelectedValues:x,onSend:m,confirmButtonText:b="Submit",beforeSend:a=()=>!0})=>{const[l,p]=N.useState(u||""),[c,g]=N.useState(x||[]),i=e.properties?.isMultiSelect??!1,v=e.properties?.buttonTexts||[],f=!i&&v.length===0&&!e.properties?.placeholder,h=e.properties?.variableName?.trim()||r||"Submit",d=N.useMemo(()=>f?{...e,properties:{...e.properties||{},buttonTexts:[h],buttonValues:[h]}}:e,[h,e,f]),j=d.properties?.buttonTexts||[],R=d.properties?.buttonValues||[],k=!i&&j.length>0,T=t=>{const o={variableName:e.properties?.variableName||"",buttonText:t};a?.(o)&&m?.(o)},q=(t,o)=>{g(C=>o?[...C,t]:C.filter(D=>D!==t))},w=()=>{const t=c.length===0&&!l?.trim(),o={variableName:e.properties?.variableName||"",selectedValues:c,inputText:l?.trim()||void 0};n||t||a?.(o)&&m?.(o)},S=t=>{p(t.target.value)},y=t=>{t.nativeEvent.isComposing||t.keyCode===229||t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),i?c.length===0&&!l.trim()||w():E())},E=()=>{const t={variableName:e.properties?.variableName||"",inputText:l};a?.(t)&&m?.(t)},B=N.useMemo(()=>{if(!r)return;const t=R.indexOf(r);if(t>-1)return j[t]??r;const o=j.indexOf(r);if(o>-1)return j[o]},[r,j,R]);return s.jsxRuntimeExports.jsxs("span",{className:"custom-variable-container inline-flex items-center flex-wrap",children:[i&&s.jsxRuntimeExports.jsx(O,{node:e,readonly:n,selectedValues:c,inputValue:l,confirmButtonText:b,handleCheckboxChange:q,handleInputChange:S,handleKeyDown:y,handleConfirmClick:w}),!i&&k&&s.jsxRuntimeExports.jsx(F,{node:d,readonly:n,resolvedDefaultButtonText:B,handleButtonClick:T,inputValue:l,handleInputChange:S,handleSendClick:E}),!i&&!k&&e.properties?.placeholder&&s.jsxRuntimeExports.jsx(_,{readonly:n,placeholder:e.properties.placeholder,value:l,onChange:S,onSend:E})]})};exports.default=z;
2
2
  //# sourceMappingURL=CustomVariable.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CustomVariable.cjs.js","sources":["../../../../src/components/ContentRender/plugins/CustomVariable.tsx"],"sourcesContent":["import React from \"react\";\nimport type { Components } from \"react-markdown\";\nimport { OnSendContentParams } from \"../../types\";\nimport { Button } from \"../../ui/button\";\nimport { Checkbox } from \"../../ui/checkbox\";\nimport MarkdownFlowInput from \"../MarkdownFlowInput\";\nimport {\n InputGroup,\n InputGroupTextarea,\n} from \"../../ui/inputGroup/input-group\";\nimport { cn } from \"../../../lib/utils\";\n\n// Define custom variable node type\ninterface CustomVariableNode {\n tagName: \"custom-variable\";\n properties?: {\n variableName?: string;\n buttonTexts?: string[];\n buttonValues?: string[];\n placeholder?: string;\n isMultiSelect?: boolean;\n };\n}\n\n// Define custom variable component Props type\ninterface CustomVariableProps {\n node: CustomVariableNode;\n defaultButtonText?: string;\n defaultInputText?: string;\n defaultSelectedValues?: string[];\n readonly?: boolean;\n onSend?: (content: OnSendContentParams) => void;\n // Multi-select confirm button text (i18n support)\n confirmButtonText?: string;\n beforeSend?: (param: OnSendContentParams) => boolean;\n}\n\ninterface ComponentsWithCustomVariable extends Components {\n \"custom-variable\"?: React.ComponentType<CustomVariableProps>;\n}\n\n// Multi select section( with checkboxes and input)\ninterface MultiSelectSectionProps {\n node: CustomVariableNode;\n readonly?: boolean;\n selectedValues: string[];\n inputValue: string;\n confirmButtonText: string;\n handleCheckboxChange: (value: string, checked: boolean) => void;\n handleInputChange: (event: React.ChangeEvent<HTMLTextAreaElement>) => void;\n handleKeyDown: (event: React.KeyboardEvent<HTMLTextAreaElement>) => void;\n handleConfirmClick: () => void;\n}\n\nconst MultiSelectSection = ({\n node,\n readonly,\n selectedValues,\n inputValue,\n confirmButtonText,\n handleCheckboxChange,\n handleInputChange,\n handleKeyDown,\n handleConfirmClick,\n}: MultiSelectSectionProps) => {\n const placeholder = node.properties?.placeholder;\n const confirmDisabled =\n readonly || (selectedValues.length === 0 && !inputValue?.trim());\n\n const renderConfirmButton = (extraWrapperClassName?: string) => (\n <span\n className={cn(\n \"multi-select-confirm-wrapper flex flex-col items-center\",\n confirmDisabled ? \"opacity-50 cursor-not-allowed\" : \"cursor-pointer\",\n extraWrapperClassName\n )}\n >\n <button\n type=\"button\"\n className=\"multi-select-confirm-button text-sm font-medium text-primary\"\n disabled={confirmDisabled}\n onClick={handleConfirmClick}\n >\n {confirmButtonText}\n </button>\n </span>\n );\n\n return (\n <span className=\"multi-select-container flex w-full flex-col\">\n <span className=\"flex flex-wrap gap-y-[9px] gap-x-6\">\n {node.properties?.buttonTexts?.map((text, index) => {\n const value = node.properties?.buttonValues?.[index];\n const buttonValue = value !== undefined ? value : text;\n return (\n <Checkbox\n key={index}\n label={text}\n disabled={readonly}\n checked={selectedValues.includes(buttonValue)}\n onCheckedChange={(checked) =>\n handleCheckboxChange(buttonValue, checked)\n }\n className=\"text-sm\"\n />\n );\n })}\n </span>\n {placeholder ? (\n <span className=\"block mb-1 w-full max-w-[500px]\">\n <span className=\"multi-select-input-row flex w-full items-end gap-3\">\n <InputGroup data-disabled={readonly} className=\"flex-1\">\n <InputGroupTextarea\n disabled={readonly}\n placeholder={placeholder}\n value={inputValue}\n onChange={handleInputChange}\n onKeyDown={handleKeyDown}\n className=\"text-sm px-3\"\n title={placeholder}\n />\n </InputGroup>\n {renderConfirmButton(\"shrink-0\")}\n </span>\n </span>\n ) : (\n renderConfirmButton(\"self-start multi-select-confirm-wrapper--stacked\")\n )}\n </span>\n );\n};\n\n// Single select section( with buttons and input)\ninterface SingleSelectSectionProps {\n node: CustomVariableNode;\n readonly?: boolean;\n resolvedDefaultButtonText?: string;\n handleButtonClick: (value: string) => void;\n inputValue: string;\n handleInputChange: (event: React.ChangeEvent<HTMLTextAreaElement>) => void;\n handleSendClick: () => void;\n}\n\nconst SingleSelectSection = ({\n node,\n readonly,\n resolvedDefaultButtonText,\n handleButtonClick,\n inputValue,\n handleInputChange,\n handleSendClick,\n}: SingleSelectSectionProps) => (\n <span className=\"single-select-container inline-flex w-full flex-col\">\n <span className=\"flex flex-wrap gap-y-[9px] gap-x-2\">\n {node.properties?.buttonTexts?.map((text, index) => {\n const value = node.properties?.buttonValues?.[index];\n const buttonValue = value !== undefined ? value : text;\n return (\n <Button\n key={index}\n disabled={readonly}\n variant=\"outline\"\n type=\"button\"\n size=\"sm\"\n onClick={() => handleButtonClick(buttonValue)}\n className={`cursor-pointer h-8 text-sm hover:bg-gray-200 ${resolvedDefaultButtonText === text ? \"select\" : \"\"}`}\n >\n {text}\n </Button>\n );\n })}\n </span>\n {node.properties?.placeholder && (\n <span className=\"mt-[9px] mb-1\">\n <MarkdownFlowInput\n disabled={readonly}\n placeholder={node.properties.placeholder}\n value={inputValue}\n onChange={handleInputChange}\n onSend={handleSendClick}\n title={node.properties.placeholder}\n />\n </span>\n )}\n </span>\n);\n\n// Pure input\ninterface InputSectionProps {\n readonly?: boolean;\n placeholder?: string;\n value: string;\n onChange: (event: React.ChangeEvent<HTMLTextAreaElement>) => void;\n onSend: () => void;\n}\n\nconst InputSection = ({\n readonly,\n placeholder,\n value,\n onChange,\n onSend,\n}: InputSectionProps) => {\n if (!placeholder) {\n return null;\n }\n\n return (\n <MarkdownFlowInput\n disabled={readonly}\n placeholder={placeholder}\n value={value}\n onChange={onChange}\n onSend={onSend}\n title={placeholder}\n />\n );\n};\n\n// Define custom variable component\nconst CustomButtonInputVariable = ({\n node,\n readonly,\n defaultButtonText,\n defaultInputText,\n defaultSelectedValues,\n onSend,\n confirmButtonText = \"Submit\", // Default to English, can be overridden\n beforeSend = () => true,\n}: CustomVariableProps) => {\n const [inputValue, setInputValue] = React.useState(defaultInputText || \"\");\n const [selectedValues, setSelectedValues] = React.useState<string[]>(\n defaultSelectedValues || []\n );\n const isMultiSelect = node.properties?.isMultiSelect ?? false;\n const baseButtonTexts = node.properties?.buttonTexts || [];\n const shouldUseFallbackButton =\n !isMultiSelect &&\n baseButtonTexts.length === 0 &&\n !node.properties?.placeholder;\n const fallbackButtonLabel =\n node.properties?.variableName?.trim() || defaultButtonText || \"Submit\";\n\n const singleSelectNode = React.useMemo<CustomVariableNode>(() => {\n if (!shouldUseFallbackButton) {\n return node;\n }\n return {\n ...node,\n properties: {\n ...(node.properties || {}),\n buttonTexts: [fallbackButtonLabel],\n buttonValues: [fallbackButtonLabel],\n },\n };\n }, [fallbackButtonLabel, node, shouldUseFallbackButton]);\n\n const singleSelectButtonTexts =\n singleSelectNode.properties?.buttonTexts || [];\n const singleSelectButtonValues =\n singleSelectNode.properties?.buttonValues || [];\n const isSingleSelect = !isMultiSelect && singleSelectButtonTexts.length > 0;\n\n const handleButtonClick = (value: string) => {\n const param = {\n variableName: node.properties?.variableName || \"\",\n buttonText: value,\n };\n if (!beforeSend?.(param)) return;\n onSend?.(param);\n };\n\n const handleCheckboxChange = (value: string, checked: boolean) => {\n setSelectedValues((prev) => {\n if (checked) {\n return [...prev, value];\n } else {\n return prev.filter((v) => v !== value);\n }\n });\n };\n\n const handleConfirmClick = () => {\n const noSelection = selectedValues.length === 0 && !inputValue?.trim();\n const param = {\n variableName: node.properties?.variableName || \"\",\n selectedValues,\n inputText: inputValue?.trim() || undefined,\n };\n if (readonly || noSelection) return;\n if (!beforeSend?.(param)) return;\n onSend?.(param);\n };\n\n const handleInputChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {\n setInputValue(e.target.value);\n };\n const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {\n if (e.nativeEvent.isComposing || e.keyCode === 229) {\n return;\n }\n if (e.key === \"Enter\" && !e.shiftKey) {\n e.preventDefault();\n if (isMultiSelect) {\n const noSelection = selectedValues.length === 0 && !inputValue.trim();\n if (!noSelection) handleConfirmClick();\n } else {\n handleSendClick();\n }\n }\n };\n const handleSendClick = () => {\n const param = {\n variableName: node.properties?.variableName || \"\",\n inputText: inputValue,\n };\n if (!beforeSend?.(param)) return;\n onSend?.(param);\n };\n\n const resolvedDefaultButtonText = React.useMemo(() => {\n if (!defaultButtonText) {\n return undefined;\n }\n const valueIndex = singleSelectButtonValues.indexOf(defaultButtonText);\n if (valueIndex > -1) {\n return singleSelectButtonTexts[valueIndex] ?? defaultButtonText;\n }\n const textIndex = singleSelectButtonTexts.indexOf(defaultButtonText);\n if (textIndex > -1) {\n return singleSelectButtonTexts[textIndex];\n }\n return undefined;\n }, [defaultButtonText, singleSelectButtonTexts, singleSelectButtonValues]);\n\n return (\n <span className=\"custom-variable-container inline-flex items-center flex-wrap\">\n {isMultiSelect && (\n <MultiSelectSection\n node={node}\n readonly={readonly}\n selectedValues={selectedValues}\n inputValue={inputValue}\n confirmButtonText={confirmButtonText}\n handleCheckboxChange={handleCheckboxChange}\n handleInputChange={handleInputChange}\n handleKeyDown={handleKeyDown}\n handleConfirmClick={handleConfirmClick}\n />\n )}\n\n {!isMultiSelect && isSingleSelect && (\n <SingleSelectSection\n node={singleSelectNode}\n readonly={readonly}\n resolvedDefaultButtonText={resolvedDefaultButtonText}\n handleButtonClick={handleButtonClick}\n inputValue={inputValue}\n handleInputChange={handleInputChange}\n handleSendClick={handleSendClick}\n />\n )}\n\n {!isMultiSelect && !isSingleSelect && node.properties?.placeholder && (\n <InputSection\n readonly={readonly}\n placeholder={node.properties.placeholder}\n value={inputValue}\n onChange={handleInputChange}\n onSend={handleSendClick}\n />\n )}\n </span>\n );\n};\n\nexport default CustomButtonInputVariable;\nexport type {\n ComponentsWithCustomVariable,\n CustomVariableNode,\n CustomVariableProps,\n};\n"],"names":["MultiSelectSection","node","readonly","selectedValues","inputValue","confirmButtonText","handleCheckboxChange","handleInputChange","handleKeyDown","handleConfirmClick","placeholder","confirmDisabled","renderConfirmButton","extraWrapperClassName","jsx","cn","jsxs","text","index","value","buttonValue","Checkbox","checked","InputGroup","InputGroupTextarea","SingleSelectSection","resolvedDefaultButtonText","handleButtonClick","handleSendClick","Button","MarkdownFlowInput","InputSection","onChange","onSend","CustomButtonInputVariable","defaultButtonText","defaultInputText","defaultSelectedValues","beforeSend","setInputValue","React","setSelectedValues","isMultiSelect","baseButtonTexts","shouldUseFallbackButton","fallbackButtonLabel","singleSelectNode","singleSelectButtonTexts","singleSelectButtonValues","isSingleSelect","param","prev","v","noSelection","e","valueIndex","textIndex"],"mappings":"qYAsDMA,EAAqB,CAAC,CAC1B,KAAAC,EACA,SAAAC,EACA,eAAAC,EACA,WAAAC,EACA,kBAAAC,EACA,qBAAAC,EACA,kBAAAC,EACA,cAAAC,EACA,mBAAAC,CACF,IAA+B,CAC7B,MAAMC,EAAcT,EAAK,YAAY,YAC/BU,EACJT,GAAaC,EAAe,SAAW,GAAK,CAACC,GAAY,KAAA,EAErDQ,EAAuBC,GAC3BC,EAAAA,kBAAAA,IAAC,OAAA,CACC,UAAWC,EAAAA,GACT,0DACAJ,EAAkB,gCAAkC,iBACpDE,CAAA,EAGF,SAAAC,EAAAA,kBAAAA,IAAC,SAAA,CACC,KAAK,SACL,UAAU,+DACV,SAAUH,EACV,QAASF,EAER,SAAAJ,CAAA,CAAA,CACH,CAAA,EAIJ,OACEW,EAAAA,kBAAAA,KAAC,OAAA,CAAK,UAAU,8CACd,SAAA,CAAAF,EAAAA,kBAAAA,IAAC,OAAA,CAAK,UAAU,qCACb,SAAAb,EAAK,YAAY,aAAa,IAAI,CAACgB,EAAMC,IAAU,CAClD,MAAMC,EAAQlB,EAAK,YAAY,eAAeiB,CAAK,EAC7CE,EA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AAYT,EAAwB,QAAQZ,CAAiB,EACnE,GAAIqB,EAAY,GACd,OAAOT,EAAwBS,CAAS,CAG5C,EAAG,CAACrB,EAAmBY,EAAyBC,CAAwB,CAAC,EAEzE,OACEhC,EAAAA,kBAAAA,KAAC,OAAA,CAAK,UAAU,+DACb,SAAA,CAAA0B,GACC5B,EAAAA,kBAAAA,IAACd,EAAA,CACC,KAAAC,EACA,SAAAC,EACA,eAAAC,EACA,WAAAC,EACA,kBAAAC,EACA,qBAAAC,EACA,kBAAAC,EACA,cAAAC,EACA,mBAAAC,CAAA,CAAA,EAIH,CAACiC,GAAiBO,GACjBnC,EAAAA,kBAAAA,IAACW,EAAA,CACC,KAAMqB,EACN,SAAA5C,EACA,0BAAAwB,EACA,kBAAAC,EACA,WAAAvB,EACA,kBAAAG,EACA,gBAAAqB,CAAA,CAAA,EAIH,CAACc,GAAiB,CAACO,GAAkBhD,EAAK,YAAY,aACrDa,EAAAA,kBAAAA,IAACiB,EAAA,CACC,SAAA7B,EACA,YAAaD,EAAK,WAAW,YAC7B,MAAOG,EACP,SAAUG,EACV,OAAQqB,CAAA,CAAA,CACV,EAEJ,CAEJ"}
1
+ {"version":3,"file":"CustomVariable.cjs.js","sources":["../../../../src/components/ContentRender/plugins/CustomVariable.tsx"],"sourcesContent":["import React from \"react\";\nimport type { Components } from \"react-markdown\";\nimport { OnSendContentParams } from \"../../types\";\nimport { Button } from \"../../ui/button\";\nimport { Checkbox } from \"../../ui/checkbox\";\nimport MarkdownFlowInput from \"../MarkdownFlowInput\";\nimport {\n InputGroup,\n InputGroupTextarea,\n} from \"../../ui/inputGroup/input-group\";\nimport { cn } from \"../../../lib/utils\";\n\n// Define custom variable node type\ninterface CustomVariableNode {\n tagName: \"custom-variable\";\n properties?: {\n variableName?: string;\n buttonTexts?: string[];\n buttonValues?: string[];\n placeholder?: string;\n isMultiSelect?: boolean;\n };\n}\n\n// Define custom variable component Props type\ninterface CustomVariableProps {\n node: CustomVariableNode;\n defaultButtonText?: string;\n defaultInputText?: string;\n defaultSelectedValues?: string[];\n readonly?: boolean;\n onSend?: (content: OnSendContentParams) => void;\n // Multi-select confirm button text (i18n support)\n confirmButtonText?: string;\n beforeSend?: (param: OnSendContentParams) => boolean;\n}\n\ninterface ComponentsWithCustomVariable extends Components {\n \"custom-variable\"?: React.ComponentType<CustomVariableProps>;\n}\n\n// Multi select section( with checkboxes and input)\ninterface MultiSelectSectionProps {\n node: CustomVariableNode;\n readonly?: boolean;\n selectedValues: string[];\n inputValue: string;\n confirmButtonText: string;\n handleCheckboxChange: (value: string, checked: boolean) => void;\n handleInputChange: (event: React.ChangeEvent<HTMLTextAreaElement>) => void;\n handleKeyDown: (event: React.KeyboardEvent<HTMLTextAreaElement>) => void;\n handleConfirmClick: () => void;\n}\n\nconst MultiSelectSection = ({\n node,\n readonly,\n selectedValues,\n inputValue,\n confirmButtonText,\n handleCheckboxChange,\n handleInputChange,\n handleKeyDown,\n handleConfirmClick,\n}: MultiSelectSectionProps) => {\n const placeholder = node.properties?.placeholder;\n const confirmDisabled =\n readonly || (selectedValues.length === 0 && !inputValue?.trim());\n\n const renderConfirmButton = (extraWrapperClassName?: string) => (\n <span\n className={cn(\n \"multi-select-confirm-wrapper flex flex-col items-center\",\n confirmDisabled ? \"opacity-50 cursor-not-allowed\" : \"cursor-pointer\",\n extraWrapperClassName\n )}\n >\n <button\n type=\"button\"\n className=\"multi-select-confirm-button text-sm font-medium text-primary\"\n disabled={confirmDisabled}\n onClick={handleConfirmClick}\n >\n {confirmButtonText}\n </button>\n </span>\n );\n\n return (\n <span className=\"multi-select-container flex w-full flex-col\">\n <span className=\"flex flex-wrap gap-y-[9px] gap-x-6\">\n {node.properties?.buttonTexts?.map((text, index) => {\n const value = node.properties?.buttonValues?.[index];\n const buttonValue = value !== undefined ? value : text;\n return (\n <Checkbox\n key={index}\n label={text}\n disabled={readonly}\n checked={selectedValues.includes(buttonValue)}\n onCheckedChange={(checked) =>\n handleCheckboxChange(buttonValue, checked)\n }\n className=\"text-sm\"\n />\n );\n })}\n </span>\n {placeholder ? (\n <span className=\"block mb-1 w-full max-w-[500px]\">\n <span className=\"multi-select-input-row flex w-full items-end gap-3\">\n <InputGroup data-disabled={readonly} className=\"flex-1\">\n <InputGroupTextarea\n disabled={readonly}\n placeholder={placeholder}\n value={inputValue}\n onChange={handleInputChange}\n onKeyDown={handleKeyDown}\n className=\"text-sm px-3\"\n title={placeholder}\n />\n </InputGroup>\n {renderConfirmButton(\"shrink-0\")}\n </span>\n </span>\n ) : (\n renderConfirmButton(\"self-start multi-select-confirm-wrapper--stacked\")\n )}\n </span>\n );\n};\n\n// Single select section( with buttons and input)\ninterface SingleSelectSectionProps {\n node: CustomVariableNode;\n readonly?: boolean;\n resolvedDefaultButtonText?: string;\n handleButtonClick: (value: string) => void;\n inputValue: string;\n handleInputChange: (event: React.ChangeEvent<HTMLTextAreaElement>) => void;\n handleSendClick: () => void;\n}\n\nconst SingleSelectSection = ({\n node,\n readonly,\n resolvedDefaultButtonText,\n handleButtonClick,\n inputValue,\n handleInputChange,\n handleSendClick,\n}: SingleSelectSectionProps) => (\n <span className=\"single-select-container inline-flex w-full flex-col\">\n <span className=\"flex flex-wrap gap-y-[9px] gap-x-2\">\n {node.properties?.buttonTexts?.map((text, index) => {\n const value = node.properties?.buttonValues?.[index];\n const buttonValue = value !== undefined ? value : text;\n return (\n <Button\n key={index}\n disabled={readonly}\n variant=\"outline\"\n type=\"button\"\n size=\"sm\"\n onClick={() => handleButtonClick(buttonValue)}\n className={cn(\n \"max-w-full shrink whitespace-normal break-words text-left leading-5 h-auto min-h-8 px-3 py-1.5\",\n \"hover:bg-gray-200\",\n resolvedDefaultButtonText === text && \"select\"\n )}\n >\n {text}\n </Button>\n );\n })}\n </span>\n {node.properties?.placeholder && (\n <span className=\"mt-[9px] mb-1\">\n <MarkdownFlowInput\n disabled={readonly}\n placeholder={node.properties.placeholder}\n value={inputValue}\n onChange={handleInputChange}\n onSend={handleSendClick}\n title={node.properties.placeholder}\n />\n </span>\n )}\n </span>\n);\n\n// Pure input\ninterface InputSectionProps {\n readonly?: boolean;\n placeholder?: string;\n value: string;\n onChange: (event: React.ChangeEvent<HTMLTextAreaElement>) => void;\n onSend: () => void;\n}\n\nconst InputSection = ({\n readonly,\n placeholder,\n value,\n onChange,\n onSend,\n}: InputSectionProps) => {\n if (!placeholder) {\n return null;\n }\n\n return (\n <MarkdownFlowInput\n disabled={readonly}\n placeholder={placeholder}\n value={value}\n onChange={onChange}\n onSend={onSend}\n title={placeholder}\n />\n );\n};\n\n// Define custom variable component\nconst CustomButtonInputVariable = ({\n node,\n readonly,\n defaultButtonText,\n defaultInputText,\n defaultSelectedValues,\n onSend,\n confirmButtonText = \"Submit\", // Default to English, can be overridden\n beforeSend = () => true,\n}: CustomVariableProps) => {\n const [inputValue, setInputValue] = React.useState(defaultInputText || \"\");\n const [selectedValues, setSelectedValues] = React.useState<string[]>(\n defaultSelectedValues || []\n );\n const isMultiSelect = node.properties?.isMultiSelect ?? false;\n const baseButtonTexts = node.properties?.buttonTexts || [];\n const shouldUseFallbackButton =\n !isMultiSelect &&\n baseButtonTexts.length === 0 &&\n !node.properties?.placeholder;\n const fallbackButtonLabel =\n node.properties?.variableName?.trim() || defaultButtonText || \"Submit\";\n\n const singleSelectNode = React.useMemo<CustomVariableNode>(() => {\n if (!shouldUseFallbackButton) {\n return node;\n }\n return {\n ...node,\n properties: {\n ...(node.properties || {}),\n buttonTexts: [fallbackButtonLabel],\n buttonValues: [fallbackButtonLabel],\n },\n };\n }, [fallbackButtonLabel, node, shouldUseFallbackButton]);\n\n const singleSelectButtonTexts =\n singleSelectNode.properties?.buttonTexts || [];\n const singleSelectButtonValues =\n singleSelectNode.properties?.buttonValues || [];\n const isSingleSelect = !isMultiSelect && singleSelectButtonTexts.length > 0;\n\n const handleButtonClick = (value: string) => {\n const param = {\n variableName: node.properties?.variableName || \"\",\n buttonText: value,\n };\n if (!beforeSend?.(param)) return;\n onSend?.(param);\n };\n\n const handleCheckboxChange = (value: string, checked: boolean) => {\n setSelectedValues((prev) => {\n if (checked) {\n return [...prev, value];\n } else {\n return prev.filter((v) => v !== value);\n }\n });\n };\n\n const handleConfirmClick = () => {\n const noSelection = selectedValues.length === 0 && !inputValue?.trim();\n const param = {\n variableName: node.properties?.variableName || \"\",\n selectedValues,\n inputText: inputValue?.trim() || undefined,\n };\n if (readonly || noSelection) return;\n if (!beforeSend?.(param)) return;\n onSend?.(param);\n };\n\n const handleInputChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {\n setInputValue(e.target.value);\n };\n const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {\n if (e.nativeEvent.isComposing || e.keyCode === 229) {\n return;\n }\n if (e.key === \"Enter\" && !e.shiftKey) {\n e.preventDefault();\n if (isMultiSelect) {\n const noSelection = selectedValues.length === 0 && !inputValue.trim();\n if (!noSelection) handleConfirmClick();\n } else {\n handleSendClick();\n }\n }\n };\n const handleSendClick = () => {\n const param = {\n variableName: node.properties?.variableName || \"\",\n inputText: inputValue,\n };\n if (!beforeSend?.(param)) return;\n onSend?.(param);\n };\n\n const resolvedDefaultButtonText = React.useMemo(() => {\n if (!defaultButtonText) {\n return undefined;\n }\n const valueIndex = singleSelectButtonValues.indexOf(defaultButtonText);\n if (valueIndex > -1) {\n return singleSelectButtonTexts[valueIndex] ?? defaultButtonText;\n }\n const textIndex = singleSelectButtonTexts.indexOf(defaultButtonText);\n if (textIndex > -1) {\n return singleSelectButtonTexts[textIndex];\n }\n return undefined;\n }, [defaultButtonText, singleSelectButtonTexts, singleSelectButtonValues]);\n\n return (\n <span className=\"custom-variable-container inline-flex items-center flex-wrap\">\n {isMultiSelect && (\n <MultiSelectSection\n node={node}\n readonly={readonly}\n selectedValues={selectedValues}\n inputValue={inputValue}\n confirmButtonText={confirmButtonText}\n handleCheckboxChange={handleCheckboxChange}\n handleInputChange={handleInputChange}\n handleKeyDown={handleKeyDown}\n handleConfirmClick={handleConfirmClick}\n />\n )}\n\n {!isMultiSelect && isSingleSelect && (\n <SingleSelectSection\n node={singleSelectNode}\n readonly={readonly}\n resolvedDefaultButtonText={resolvedDefaultButtonText}\n handleButtonClick={handleButtonClick}\n inputValue={inputValue}\n handleInputChange={handleInputChange}\n handleSendClick={handleSendClick}\n />\n )}\n\n {!isMultiSelect && !isSingleSelect && node.properties?.placeholder && (\n <InputSection\n readonly={readonly}\n placeholder={node.properties.placeholder}\n value={inputValue}\n onChange={handleInputChange}\n onSend={handleSendClick}\n />\n )}\n </span>\n );\n};\n\nexport default CustomButtonInputVariable;\nexport type {\n ComponentsWithCustomVariable,\n CustomVariableNode,\n CustomVariableProps,\n};\n"],"names":["MultiSelectSection","node","readonly","selectedValues","inputValue","confirmButtonText","handleCheckboxChange","handleInputChange","handleKeyDown","handleConfirmClick","placeholder","confirmDisabled","renderConfirmButton","extraWrapperClassName","jsx","cn","jsxs","text","index","value","buttonValue","Checkbox","checked","InputGroup","InputGroupTextarea","SingleSelectSection","resolvedDefaultButtonText","handleButtonClick","handleSendClick","Button","MarkdownFlowInput","InputSection","onChange","onSend","CustomButtonInputVariable","defaultButtonText","defaultInputText","defaultSelectedValues","beforeSend","setInputValue","React","setSelectedValues","isMultiSelect","baseButtonTexts","shouldUseFallbackButton","fallbackButtonLabel","singleSelectNode","singleSelectButtonTexts","singleSelectButtonValues","isSingleSelect","param","prev","v","noSelection","e","valueIndex","textIndex"],"mappings":"qYAsDMA,EAAqB,CAAC,CAC1B,KAAAC,EACA,SAAAC,EACA,eAAAC,EACA,WAAAC,EACA,kBAAAC,EACA,qBAAAC,EACA,kBAAAC,EACA,cAAAC,EACA,mBAAAC,CACF,IAA+B,CAC7B,MAAMC,EAAcT,EAAK,YAAY,YAC/BU,EACJT,GAAaC,EAAe,SAAW,GAAK,CAACC,GAAY,KAAA,EAErDQ,EAAuBC,GAC3BC,EAAAA,kBAAAA,IAAC,OAAA,CACC,UAAWC,EAAAA,GACT,0DACAJ,EAAkB,gCAAkC,iBACpD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