import useEditorStore from "./useEditorStore"; import { useState } from "react"; import { DndContext, closestCenter, PointerSensor, useSensor, useSensors } from "@dnd-kit/core"; import { arrayMove, SortableContext, useSortable, verticalListSortingStrategy } from "@dnd-kit/sortable"; import { CSS } from "@dnd-kit/utilities"; function SortableColumnItem({ column, elementId, updateColumnWidth, updateColumnLabel, toggleColumnVisibility }) { const { attributes, listeners, setNodeRef, transform, transition } = useSortable({ id: column.key }); const style = { transform: CSS.Transform.toString(transform), transition, }; return (
⋮⋮
updateColumnLabel(elementId, column.key, e.target.value)} style={{ ...styles.input, width: 70, fontSize: 11 }} placeholder="Label" /> updateColumnWidth(elementId, column.key, Number(e.target.value))} style={{ ...styles.input, width: 50, fontSize: 11 }} placeholder="W" />
); } export default function PropertiesPanel() { const elements = useEditorStore((state) => state.elements); const selectedId = useEditorStore((state) => state.selectedId); const updateElement = useEditorStore((state) => state.updateElement); const duplicateElement = useEditorStore((state) => state.duplicateElement); const deleteElement = useEditorStore((state) => state.deleteElement); const toggleColumnVisibility = useEditorStore((state) => state.toggleColumnVisibility); const updateColumnWidth = useEditorStore((state) => state.updateColumnWidth); const updateColumnLabel = useEditorStore((state) => state.updateColumnLabel); const reorderColumns = useEditorStore((state) => state.reorderColumns); const selected = elements.find((el) => el.id === selectedId); const [imageUpload, setImageUpload] = useState(null); const sensors = useSensors( useSensor(PointerSensor, { activationConstraint: { distance: 8, }, }) ); if (!selected) { return (

Select an element to edit properties

); } const handleImageUpload = (e) => { const file = e.target.files[0]; if (file) { const reader = new FileReader(); reader.onload = (event) => { updateElement(selected.id, { src: event.target.result }); }; reader.readAsDataURL(file); } }; const handleDragEnd = (event) => { const { active, over } = event; if (active.id !== over.id) { const oldIndex = selected.columns.findIndex((col) => col.key === active.id); const newIndex = selected.columns.findIndex((col) => col.key === over.id); const newColumns = arrayMove(selected.columns, oldIndex, newIndex); reorderColumns(selected.id, newColumns); } }; return (

Properties

{selected.type.toUpperCase()}
{/* POSITION */}
X updateElement(selected.id, { x: Number(e.target.value) }) } style={styles.input} />
Y updateElement(selected.id, { y: Number(e.target.value) }) } style={styles.input} />
{/* ROTATION */} {selected.rotation !== undefined && (
updateElement(selected.id, { rotation: Number(e.target.value) }) } style={styles.input} placeholder="Degrees" />
)} {/* TEXT PROPERTIES */} {selected.type === "text" && ( <>