diff --git a/lib/client/vanilla/image.tsx b/lib/client/vanilla/image.tsx index 8da8ea98..f87f98ba 100644 --- a/lib/client/vanilla/image.tsx +++ b/lib/client/vanilla/image.tsx @@ -22,7 +22,7 @@ const Dialog: React.FC = ({ open, setOpen, selectedElement, baseUrl useEffect(() => { setUrl(selectedElement?.getAttribute('src') ?? '') - }, [open]) + }, [selectedElement]) const onUpload = async (e: React.ChangeEvent) => { e.preventDefault() diff --git a/lib/client/vanilla/link.tsx b/lib/client/vanilla/link.tsx index 38cf5ffe..f93ca59a 100644 --- a/lib/client/vanilla/link.tsx +++ b/lib/client/vanilla/link.tsx @@ -17,11 +17,21 @@ const Dialog: React.FC = ({ open, setOpen, selectedElement }) => { const [newTab, setNewTab] = useState(true) useEffect(() => { - setLink(selectedElement?.href ?? '') - }, [open]) + if (selectedElement) { + const url = new URL(selectedElement.href) + const linkNew = url.hostname === 'localhost' ? url.pathname.replace('/', '') + url.hash : selectedElement.href + setLink(linkNew) + console.log('changed', linkNew) + } else { + console.log('changed', null) + + setLink('') + } + }, [selectedElement]) const onSave = () => { setOpen(false) + setLink('') selectedElement.href = link selectedElement.target = newTab ? '_blank' : '_self' @@ -48,7 +58,7 @@ const Dialog: React.FC = ({ open, setOpen, selectedElement }) => { type="text" className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg block w-full p-2.5 mb-4" placeholder="Eg. https://github.com/LiveDuo/destack" - defaultValue={link as string} + value={link as string} onChange={(e) => setLink(e.target.value)} />
diff --git a/lib/client/vanilla/svg.tsx b/lib/client/vanilla/svg.tsx index 4cbdd401..288472bf 100644 --- a/lib/client/vanilla/svg.tsx +++ b/lib/client/vanilla/svg.tsx @@ -16,7 +16,7 @@ const Dialog: React.FC = ({ open, setOpen, selectedElement }) => { const [path, setPath] = useState('') useEffect(() => { - if (open) { + if (selectedElement) { if (selectedElement.tagName === 'path') { setPath(selectedElement?.getAttribute('d') ?? '') } else if (selectedElement.tagName === 'svg') { @@ -28,7 +28,7 @@ const Dialog: React.FC = ({ open, setOpen, selectedElement }) => { } else { setPath('') } - }, [open]) + }, [selectedElement]) const onSave = () => { setOpen(false)