MCPcopy
hub / github.com/027xiguapi/code-box / CustomDomSelector

Function CustomDomSelector

component/ui/customDomSelector.tsx:16–197  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14const turndownService = Turndown()
15
16export default function CustomDomSelector() {
17 const [aiType, setAiType] = useStorage("app-aiType")
18 const [position, setPosition] = useState({ top: 0, left: 0 })
19 const [isReady, setIsReady] = useState(false)
20 const [isSelect, setIsSelect] = useState(false)
21 const downloadType = useRef("")
22 const [editContent, setEditContent] = useEditMarkdown()
23 const [parseContent, setParseContent] = useParseMarkdown()
24
25 const articleTitle = document
26 .querySelector<HTMLElement>("head title")
27 ?.innerText.trim()
28
29 useEffect(() => {
30 if (aiType) {
31 addCss(`.codebox-current { outline: 2px solid #42b88350 !important; }`)
32 if (isReady) {
33 addEventListeners()
34 } else {
35 removeEventListeners()
36 }
37 }
38 return () => {
39 removeEventListeners()
40 }
41 }, [aiType, isReady, isSelect])
42
43 const addEventListeners = () => {
44 document.addEventListener("mousemove", handleMouseMove)
45 document.addEventListener("click", handleClick)
46 }
47
48 const removeEventListeners = () => {
49 document.removeEventListener("mousemove", handleMouseMove)
50 document.removeEventListener("click", handleClick)
51 }
52
53 const handleMouseMove = (event: MouseEvent) => {
54 if (isReady && !isSelect) {
55 const target = event.target as HTMLElement
56 highlightElement(target)
57 }
58 }
59
60 const handleClick = (event: MouseEvent) => {
61 if (isReady) {
62 const target = event.target as HTMLElement
63 const tooltip = target.closest(".codebox-tooltip")
64 const modal = target.closest(".codebox-modal")
65 const csui = target.closest("#codebox-csui")
66
67 if (!tooltip && !modal && !csui) {
68 setIsSelect(true)
69 highlightElement(target)
70 updateTooltipPosition(target)
71 event.stopPropagation()
72 event.preventDefault()
73 }

Callers

nothing calls this directly

Calls 6

useEditMarkdownFunction · 0.90
useParseMarkdownFunction · 0.90
addCssFunction · 0.85
addEventListenersFunction · 0.85
removeEventListenersFunction · 0.85
setCustomFunction · 0.85

Tested by

no test coverage detected