text stringlengths 0 1.47k |
|---|
background: "transparent", |
colorScheme: "normal" |
}; |
/** First text line of the durable result content, for the error row. */ |
function firstResultLine(content) { |
for (const block of content) if (block.type === "text" && typeof block.text === "string" && block.text.length > 0) { |
const newline = block.text.indexOf("\n"); |
return newline === -1 ? block.text : block.text.slice(0, newline); |
} |
return "visualization failed"; |
} |
/** The settled, well-formed card: header line plus the sandboxed frame. */ |
function Frame({ meta, callId }) { |
const [themeTick, setThemeTick] = (0, react.useState)(0); |
const [height, setHeight] = (0, react.useState)(MIN_HEIGHT); |
(0, react.useEffect)(() => { |
const bump = () => setThemeTick((tick) => tick + 1); |
const observer = new MutationObserver(bump); |
observer.observe(document.documentElement, { attributes: true }); |
observer.observe(document.body, { attributes: true }); |
const media = matchMedia("(prefers-color-scheme: dark)"); |
media.addEventListener("change", bump); |
return () => { |
observer.disconnect(); |
media.removeEventListener("change", bump); |
}; |
}, []); |
(0, react.useEffect)(() => { |
const onMessage = (event) => { |
const data = event.data; |
if (typeof data !== "object" || data === null) return; |
const report = data; |
if (report.type !== "dsh-visualize:height" || report.token !== callId) return; |
if (typeof report.height !== "number" || !Number.isFinite(report.height)) return; |
setHeight(Math.max(MIN_HEIGHT, Math.min(Math.ceil(report.height), HEIGHT_CAP[meta.mode]))); |
}; |
addEventListener("message", onMessage); |
return () => removeEventListener("message", onMessage); |
}, [callId, meta.mode]); |
const doc = (0, react.useMemo)(() => { |
const { themeVars, colorScheme } = resolveTheme(); |
return buildFrameDoc({ |
fragment: meta.fragment, |
title: meta.title, |
themeVars, |
colorScheme, |
reportToken: callId |
}); |
}, [ |
meta, |
callId, |
themeTick |
]); |
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { |
style: headerStyle, |
title: meta.path === "" ? meta.title : meta.path, |
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { |
style: { fontWeight: 500 }, |
children: meta.title |
}), meta.path !== "" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { |
style: { |
overflow: "hidden", |
textOverflow: "ellipsis" |
}, |
children: meta.path |
})] |
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("iframe", { |
sandbox: "allow-scripts", |
referrerPolicy: "no-referrer", |
title: meta.title, |
srcDoc: doc, |
style: { |
...frameStyle$1, |
height |
} |
})] }); |
} |
/** |
* Keyed toolview for the `visualize` tool. Running calls and malformed or |
* failed results stay quiet single lines; a well-formed persisted meta — or |
* the fragment in the call's own arguments for nested dispatches — mounts |
* the frame. |
*/ |
function VisualizeCard({ callId, block }) { |
const argsRaw = "kind" in block ? block.call?.argsRaw : "argsRaw" in block ? block.argsRaw : void 0; |
if (!("kind" in block)) { |
const live = visualizeMetaFromArgs(argsRaw); |
if (live !== void 0) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Frame, { |
meta: live, |
callId |
}); |
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { |
style: headerStyle, |
children: "Visualize · rendering…" |
}); |
} |
if (block.isError) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { |
style: headerStyle, |
children: ["Visualize · ", firstResultLine(block.content)] |
}); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.