MCPcopy Create free account
hub / github.com/editablejs/editable / LinkCreateComponent

Function LinkCreateComponent

packages/plugins/link/src/components/create.tsx:20–101  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18export interface LinkCreateComponentProps extends SlotComponentProps {}
19
20export const LinkCreateComponent: FC<LinkCreateComponentProps> = () => {
21 const editor = useEditableStatic()
22
23 const [url, setUrl] = useState('')
24
25 const [open, setOpen] = useLinkOpen()
26
27 const inputRef = useRef<HTMLInputElement>(null)
28
29 const pointRef = React.useRef({ x: 0, y: 0 })
30
31 const virtualRef = React.useRef({
32 getBoundingClientRect: () => DOMRect.fromRect({ width: 0, height: 0, ...pointRef.current }),
33 })
34
35 useEffect(() => {
36 inputRef.current?.focus()
37 }, [])
38
39 const rects = useSelectionDrawingRects()
40
41 useEffect(() => {
42 if (rects.length > 0) {
43 const rect = rects[rects.length - 1]
44 const [x, y] = Editable.reverseRelativePosition(editor, rect.x, rect.bottom)
45 pointRef.current = {
46 x,
47 y,
48 }
49 } else {
50 pointRef.current = {
51 x: 0,
52 y: 0,
53 }
54 }
55 }, [rects])
56
57 const handleOk = () => {
58 const link: Link = {
59 type: LINK_KEY,
60 href: url,
61 children: [{ text: 'link' }],
62 }
63 if (!editor.selection || Range.isCollapsed(editor.selection)) {
64 Transforms.insertNodes(editor, link)
65 } else {
66 Transforms.wrapNodes(editor, link, {
67 match: n => Text.isText(n),
68 split: true,
69 })
70 Transforms.select(editor, Range.end(editor.selection))
71 }
72 setOpen(false)
73 }
74
75 const locale = useLocale<LinkLocale>('link')
76
77 return (

Callers

nothing calls this directly

Calls 5

useEditableStaticFunction · 0.90
useLinkOpenFunction · 0.90
useSelectionDrawingRectsFunction · 0.90
useLocaleFunction · 0.90
focusMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…