setShow((i) => !i)}
className={`h-12 cursor-pointer bg-white border-b last:border-b-0 flex items-center px-2 ${
@@ -215,15 +215,30 @@ function Editor({ standaloneServer = false }) {
const onCanvasClick = (e) => {
if (isEventOnElement(deleteRef.current, e)) {
- canvasRef.current.removeChild(hoveredComponent)
- setHoveredComponent()
+ const clickEvent = new MouseEvent('click', { bubbles: true })
+ deleteRef.current.dispatchEvent(clickEvent)
} else if (isEventOnElement(moveUpRef.current, e)) {
- canvasRef.current.insertBefore(hoveredComponent, hoveredComponent.previousElementSibling)
+ const clickEvent = new MouseEvent('click', { bubbles: true })
+ moveUpRef.current.dispatchEvent(clickEvent)
} else if (isEventOnElement(moveDownRef.current, e)) {
- canvasRef.current.insertBefore(hoveredComponent.nextElementSibling, hoveredComponent)
+ const clickEvent = new MouseEvent('click', { bubbles: true })
+ moveDownRef.current.dispatchEvent(clickEvent)
}
}
+ const onComponentDelete = () => {
+ canvasRef.current.removeChild(hoveredComponent)
+ setHoveredComponent()
+ }
+
+ const onComponentMoveUp = () => {
+ canvasRef.current.insertBefore(hoveredComponent, hoveredComponent.previousElementSibling)
+ }
+
+ const onComponentMoveDown = () => {
+ canvasRef.current.insertBefore(hoveredComponent.nextElementSibling, hoveredComponent)
+ }
+
const isElementTopHalf = (element, event) => {
const rect = element.getBoundingClientRect()
return rect.top + (rect.bottom - rect.top) / 2 > event.clientY
@@ -274,12 +289,25 @@ function Editor({ standaloneServer = false }) {
>
{getComponents().indexOf(hoveredComponent) < getComponents().length - 1 && (
-
+
)}
{getComponents().indexOf(hoveredComponent) > 0 && (
-
+
)}
-
+