Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Artifacts] add preview html code #5092

Merged
merged 30 commits into from
Jul 26, 2024
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3a10f58
add preview html code
lloydzhou Jul 23, 2024
dfd0891
add preview html code
lloydzhou Jul 23, 2024
4199e17
auto height for html preview
lloydzhou Jul 23, 2024
fb60fbb
auto height for html preview
lloydzhou Jul 23, 2024
2e9e20c
auto height for html preview
lloydzhou Jul 23, 2024
1ecefd8
hotfix
lloydzhou Jul 23, 2024
421bf33
save artifact content to cloudflare workers kv
lloydzhou Jul 24, 2024
e31bec3
save artifact content to cloudflare workers kv
lloydzhou Jul 24, 2024
ab9f538
fix typescript
lloydzhou Jul 24, 2024
b4bf11d
add loading icon when upload artifact content
lloydzhou Jul 25, 2024
044116c
add plugin selector on chat
lloydzhou Jul 25, 2024
2efedb1
update
lloydzhou Jul 25, 2024
9f0e16b
hotfix: ts check
lloydzhou Jul 25, 2024
47b33f2
hotfix: auto set height
lloydzhou Jul 25, 2024
763fc89
add fullscreen button on artifact component
lloydzhou Jul 25, 2024
7c1bc1f
hotfix: auto set height
lloydzhou Jul 25, 2024
d8afd1a
add expiration_ttl for kv storage
lloydzhou Jul 25, 2024
21ef9a4
feat: artifacts style
Dogtiti Jul 25, 2024
825929f
merge main
lloydzhou Jul 25, 2024
6a083b2
fix typescript error
lloydzhou Jul 25, 2024
556d563
update
lloydzhou Jul 25, 2024
5ec0311
fix typescript error
lloydzhou Jul 25, 2024
51e8f04
Merge branch 'feature-artifacts' of https://github.com/ConnectAI-E/Ch…
Dogtiti Jul 25, 2024
c27ef6f
feat: artifacts style
Dogtiti Jul 25, 2024
a0f0b4f
Merge pull request #5 from ConnectAI-E/feature/artifacts-style
lloydzhou Jul 25, 2024
72d6f97
fix: ts error
Dogtiti Jul 26, 2024
f2d2622
fix: uploading loading
Dogtiti Jul 26, 2024
6737f01
chore: artifact => artifacts
Dogtiti Jul 26, 2024
715d1dc
fix: default enable artifacts
Dogtiti Jul 26, 2024
3f9f556
fix: iframe bg
Dogtiti Jul 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions app/components/markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,49 @@ export function Mermaid(props: { code: string }) {
);
}

export function HTMLPreview(props: { code: string }) {
const ref = useRef<HTMLDivElement>(null);

return (
<div
className="no-dark html"
style={{
cursor: "pointer",
overflow: "auto",
}}
ref={ref}
onClick={() => console.log("click")}
>
<iframe
frameBorder={0}
sandbox="allow-scripts"
style={{ width: "100%", height: 400 }}
srcdoc={props.code}
></iframe>
</div>
);
}

export function PreCode(props: { children: any }) {
const ref = useRef<HTMLPreElement>(null);
const refText = ref.current?.innerText;
const [mermaidCode, setMermaidCode] = useState("");
const [htmlCode, setHtmlCode] = useState("");

const renderMermaid = useDebouncedCallback(() => {
const renderArtifacts = useDebouncedCallback(() => {
if (!ref.current) return;
const mermaidDom = ref.current.querySelector("code.language-mermaid");
if (mermaidDom) {
setMermaidCode((mermaidDom as HTMLElement).innerText);
}
const htmlDom = ref.current.querySelector("code.language-html");
if (htmlDom) {
setHtmlCode((htmlDom as HTMLElement).innerText);
}
lloydzhou marked this conversation as resolved.
Show resolved Hide resolved
}, 600);

useEffect(() => {
setTimeout(renderMermaid, 1);
setTimeout(renderArtifacts, 1);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [refText]);

Expand All @@ -83,6 +111,7 @@ export function PreCode(props: { children: any }) {
{mermaidCode.length > 0 && (
<Mermaid code={mermaidCode} key={mermaidCode} />
)}
{htmlCode.length > 0 && <HTMLPreview code={htmlCode} key={htmlCode} />}
<pre ref={ref}>
<span
className="copy-code-button"
Expand Down
Loading