Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | import { VSCodeLink } from "@vscode/webview-ui-toolkit/react" import { memo, useEffect, useRef, useState } from "react" import { useRemark } from "react-remark" import styled from "styled-components" import { CODE_BLOCK_BG_COLOR } from "@/components/common/CodeBlock" const StyledMarkdown = styled.div` font-family: var(--vscode-font-family), system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif; font-size: 12px; color: var(--vscode-descriptionForeground); p, li, ol, ul { line-height: 1.25; margin: 0; } ol, ul { padding-left: 1.5em; margin-left: 0; } p { white-space: pre-wrap; } a { text-decoration: none; } a { &:hover { text-decoration: underline; } } ` export const ModelDescriptionMarkdown = memo( ({ markdown, key, isExpanded, setIsExpanded, isPopup, }: { markdown?: string key: string isExpanded: boolean setIsExpanded: (isExpanded: boolean) => void isPopup?: boolean }) => { const [reactContent, setMarkdown] = useRemark() const [showSeeMore, setShowSeeMore] = useState(false) const textContainerRef = useRef<HTMLDivElement>(null) const textRef = useRef<HTMLDivElement>(null) useEffect(() => { setMarkdown(markdown || "") }, [markdown, setMarkdown]) useEffect(() => { if (textRef.current && textContainerRef.current) { const { scrollHeight } = textRef.current const { clientHeight } = textContainerRef.current const isOverflowing = scrollHeight > clientHeight setShowSeeMore(isOverflowing) } }, [reactContent, setIsExpanded]) return ( <StyledMarkdown key={key} style={{ display: "inline-block", marginBottom: 0 }}> <div ref={textContainerRef} style={{ overflowY: isExpanded ? "auto" : "hidden", position: "relative", wordBreak: "break-word", overflowWrap: "anywhere", }}> <div ref={textRef} style={{ display: "-webkit-box", WebkitLineClamp: isExpanded ? "unset" : 3, WebkitBoxOrient: "vertical", overflow: "hidden", }}> {reactContent} </div> {!isExpanded && showSeeMore && ( <div style={{ position: "absolute", right: 0, bottom: 0, display: "flex", alignItems: "center", }}> <div style={{ width: 30, height: "1.2em", background: "linear-gradient(to right, transparent, var(--vscode-sideBar-background))", }} /> <VSCodeLink onClick={() => setIsExpanded(true)} style={{ fontSize: "inherit", paddingRight: 0, paddingLeft: 3, backgroundColor: isPopup ? CODE_BLOCK_BG_COLOR : "var(--vscode-sideBar-background)", }}> See more </VSCodeLink> </div> )} </div> </StyledMarkdown> ) }, ) export default ModelDescriptionMarkdown |