@@ -28,7 +28,7 @@ import {
2828} from '@mui/icons-material' ;
2929import { PatternLibraryElement } from '../../models/listingFlow' ;
3030import { UIElement , GroupUIElement } from '../../models/uiElements' ;
31- import { getElementByPath } from '../../context/EditorContext' ;
31+ import { useEditor , getElementByPath } from '../../context/EditorContext' ; // useEditor importieren
3232import { useFieldValues } from '../../context/FieldValuesContext' ;
3333import { evaluateVisibilityCondition } from '../../utils/visibilityUtils' ;
3434// Import der react-dnd Hooks
@@ -88,7 +88,8 @@ const ChildrenContainer = styled(Box)<{ depth: number }>`
8888 margin-top: 1rem;
8989` ;
9090
91- const EmptyState = styled ( Box ) < { isOver ?: boolean } > `
91+ // Filter transient props for EmptyState
92+ const EmptyState = styled ( ( { $isOver, ...props } ) => < Box { ...props } /> ) < { $isOver ?: boolean } > `
9293 display: flex;
9394 flex-direction: column;
9495 align-items: center;
@@ -97,20 +98,21 @@ const EmptyState = styled(Box)<{ isOver?: boolean }>`
9798 text-align: center;
9899 color: #343951;
99100 padding: 2rem;
100- background-color: ${ props => props . isOver ? 'rgba(0, 159, 100, 0.05)' : 'rgba(0, 159, 100, 0.02)' } ;
101+ background-color: ${ props => props . $ isOver ? 'rgba(0, 159, 100, 0.05)' : 'rgba(0, 159, 100, 0.02)' } ;
101102 border-radius: 8px;
102- border: 2px dashed ${ props => props . isOver ? '#009F64' : 'rgba(0, 159, 100, 0.2)' } ;
103+ border: 2px dashed ${ props => props . $ isOver ? '#009F64' : 'rgba(0, 159, 100, 0.2)' } ;
103104 transition: all 0.2s ease;
104105` ;
105106
106- const DropZone = styled ( Box ) < { isOver ?: boolean } > `
107- border: 2px dashed ${ props => props . isOver ? '#009F64' : 'rgba(0, 159, 100, 0.3)' } ;
107+ // Filter transient props for DropZone
108+ const DropZone = styled ( ( { $isOver, ...props } ) => < Box { ...props } /> ) < { $isOver ?: boolean } > `
109+ border: 2px dashed ${ props => props . $isOver ? '#009F64' : 'rgba(0, 159, 100, 0.3)' } ;
108110 border-radius: 8px;
109111 padding: 1rem;
110112 margin: 0.5rem 0;
111113 text-align: center;
112114 color: #343951;
113- background-color: ${ props => props . isOver ? 'rgba(0, 159, 100, 0.05)' : 'transparent' } ;
115+ background-color: ${ props => props . $ isOver ? 'rgba(0, 159, 100, 0.05)' : 'transparent' } ;
114116 transition: all 0.2s ease;
115117` ;
116118
@@ -417,7 +419,7 @@ const ElementRenderer: React.FC<{
417419 onDuplicateElement : ( path : number [ ] ) => void ;
418420 onAddSubElement ?: ( parentPath : number [ ] , type : string ) => void ;
419421 onMoveElement ?: ( sourceIndex : number , targetIndex : number , parentPath ?: number [ ] , sourcePath ?: number [ ] ) => void ;
420- setShowElementTypeModal : React . Dispatch < React . SetStateAction < boolean > > ;
422+ setShowElementTypeModal : ( open : boolean ) => void ; // Typ angepasst
421423 setTargetParentPath : React . Dispatch < React . SetStateAction < number [ ] | undefined > > ;
422424} > = ( {
423425 element,
@@ -508,7 +510,7 @@ const ElementRenderer: React.FC<{
508510
509511 { isCollapsible && (
510512 < IconButton
511- onClick = { ( e ) => {
513+ onClick = { ( e : React . MouseEvent ) => { // Typ hinzugefügt
512514 e . stopPropagation ( ) ;
513515 setIsExpanded ( ! isExpanded ) ;
514516 } }
@@ -541,7 +543,7 @@ const ElementRenderer: React.FC<{
541543 < Tooltip title = "Duplizieren" >
542544 < IconButton
543545 size = "small"
544- onClick = { ( e ) => {
546+ onClick = { ( e : React . MouseEvent ) => { // Typ hinzugefügt
545547 e . stopPropagation ( ) ;
546548 onDuplicateElement ( path ) ;
547549 } }
@@ -552,7 +554,7 @@ const ElementRenderer: React.FC<{
552554 < Tooltip title = "Löschen" >
553555 < IconButton
554556 size = "small"
555- onClick = { ( e ) => {
557+ onClick = { ( e : React . MouseEvent ) => { // Typ hinzugefügt
556558 e . stopPropagation ( ) ;
557559 onRemoveElement ( path ) ;
558560 } }
@@ -715,10 +717,15 @@ const EditorArea: React.FC<EditorAreaProps> = ({
715717 onDropElement,
716718 onMoveElement
717719} ) => {
718- const [ showElementTypeModal , setShowElementTypeModal ] = useState ( false ) ;
720+ const { state : editorState , dispatch : editorDispatch } = useEditor ( ) ; // EditorContext verwenden
719721 const [ targetParentPath , setTargetParentPath ] = useState < number [ ] | undefined > ( undefined ) ;
720722
721- const handleDrop = ( e : React . DragEvent ) => {
723+ const showElementTypeModal = editorState . dialogs ?. elementType || false ;
724+ const setShowElementTypeModal = ( open : boolean ) => {
725+ editorDispatch ( { type : 'TOGGLE_DIALOG' , payload : { dialog : 'elementType' , open } } ) ;
726+ } ;
727+
728+ const handleDrop = ( e : React . DragEvent < HTMLDivElement > ) => {
722729 e . preventDefault ( ) ;
723730 const elementType = e . dataTransfer . getData ( 'element_type' ) ;
724731 if ( elementType && onDropElement ) {
@@ -728,7 +735,7 @@ const EditorArea: React.FC<EditorAreaProps> = ({
728735
729736 const [ isDropZoneActive , setIsDropZoneActive ] = useState ( false ) ;
730737
731- const handleDragOver = ( e : React . DragEvent ) => {
738+ const handleDragOver = ( e : React . DragEvent < HTMLDivElement > ) => {
732739 e . preventDefault ( ) ;
733740 setIsDropZoneActive ( true ) ;
734741 } ;
@@ -741,6 +748,8 @@ const EditorArea: React.FC<EditorAreaProps> = ({
741748 const handleSelectElementType = ( type : string ) => {
742749 if ( targetParentPath && onAddSubElement ) {
743750 onAddSubElement ( targetParentPath , type ) ;
751+ } else if ( ! targetParentPath && onAddSubElement ) { // Hinzufügen auf Root-Ebene
752+ onAddSubElement ( [ ] , type ) ;
744753 }
745754 // Dialog schließen
746755 setShowElementTypeModal ( false ) ;
@@ -757,26 +766,41 @@ const EditorArea: React.FC<EditorAreaProps> = ({
757766 open = { showElementTypeModal }
758767 onClose = { ( ) => setShowElementTypeModal ( false ) }
759768 onSelectElementType = { handleSelectElementType }
760- parentElementType = { targetParentPath ?
761- elements [ targetParentPath [ 0 ] ] ?. element . pattern_type : undefined }
769+ parentElementType = {
770+ targetParentPath && targetParentPath . length > 0 && elements [ targetParentPath [ 0 ] ]
771+ ? elements [ targetParentPath [ 0 ] ] . element . pattern_type
772+ : undefined
773+ }
762774 />
763775
764776 { elements . length === 0 ? (
765777 < EmptyState
766- onDrop = { ( e ) => {
778+ onDrop = { ( e : React . DragEvent < HTMLDivElement > ) => { // Typ hinzugefügt
767779 handleDrop ( e ) ;
768780 setIsDropZoneActive ( false ) ;
769781 } }
770782 onDragOver = { handleDragOver }
771783 onDragLeave = { handleDragLeave }
772- isOver = { isDropZoneActive }
784+ $ isOver= { isDropZoneActive }
773785 >
774786 < Typography variant = "body1" gutterBottom >
775787 Ziehen Sie Elemente aus der Palette hierher
776788 </ Typography >
777- < Typography variant = "body2" >
789+ < Typography variant = "body2" sx = { { mb : 1 } } >
778790 Oder klicken Sie, um ein Element hinzuzufügen
779791 </ Typography >
792+ { /* Add IconButton to trigger dialog */ }
793+ < IconButton
794+ data-testid = "icon-add-circle"
795+ color = "primary"
796+ onClick = { ( ) => {
797+ setTargetParentPath ( undefined ) ; // Set parent path for root level
798+ setShowElementTypeModal ( true ) ;
799+ } }
800+ sx = { { mt : 1 } }
801+ >
802+ < AddIcon fontSize = "large" />
803+ </ IconButton >
780804 </ EmptyState >
781805 ) : (
782806 < Box >
@@ -819,13 +843,13 @@ const EditorArea: React.FC<EditorAreaProps> = ({
819843 ) }
820844
821845 < DropZone
822- onDrop = { ( e ) => {
846+ onDrop = { ( e : React . DragEvent < HTMLDivElement > ) => { // Typ hinzugefügt
823847 handleDrop ( e ) ;
824848 setIsDropZoneActive ( false ) ;
825849 } }
826850 onDragOver = { handleDragOver }
827851 onDragLeave = { handleDragLeave }
828- isOver = { isDropZoneActive }
852+ $ isOver= { isDropZoneActive }
829853 >
830854 < Typography >
831855 Element hier ablegen
@@ -837,4 +861,5 @@ const EditorArea: React.FC<EditorAreaProps> = ({
837861 ) ;
838862} ;
839863
840- export default EditorArea ;
864+ const ExportedEditorArea : React . FC < EditorAreaProps > = EditorArea ;
865+ export default ExportedEditorArea ;
0 commit comments