Skip to content

Commit

Permalink
worked on svg
Browse files Browse the repository at this point in the history
  • Loading branch information
LiveDuo committed Nov 8, 2023
1 parent 5f91d22 commit 377ca5f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/client/vanilla/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ function Editor({ standaloneServer = false }) {
setOpenLink(true)
} else if (target.tagName === 'path') {
setOpenSvg(true)
} else if (target.tagName === 'svg') {
setOpenSvg(true)
}

// handle popover clicks
Expand Down
22 changes: 19 additions & 3 deletions lib/client/vanilla/svg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,36 @@ import cx from 'classnames'
type DialogProps = {
open: boolean
setOpen: any
selectedElement: SVGTextPathElement
selectedElement: SVGTextPathElement | SVGElement
}

const Dialog: React.FC<DialogProps> = ({ open, setOpen, selectedElement }) => {
const [path, setPath] = useState('')

useEffect(() => {
if (open) setPath(selectedElement?.getAttribute('d') ?? '')
if (open) {
if (selectedElement.tagName === 'path') {
setPath(selectedElement?.getAttribute('d') ?? '')
} else if (selectedElement.tagName === 'svg') {
const pathElement = selectedElement.querySelector('path')
setPath(pathElement?.getAttribute('d') ?? '')
} else {
setPath('')
}
} else {
setPath('')
}
}, [open])

const onSave = () => {
setOpen(false)

selectedElement.setAttribute('d', path)
if (selectedElement.tagName === 'path') {
selectedElement.setAttribute('d', path)
} else if (selectedElement.tagName === 'svg') {
const pathElement = selectedElement.querySelector('path')
pathElement!.setAttribute('d', path)
}
}

return (
Expand Down

0 comments on commit 377ca5f

Please sign in to comment.