@@ -20,12 +20,14 @@ export type FormBuilderProps = {
2020 onChange ?: ( form : FormType ) => void ;
2121 onSaveComponent ?: (
2222 component : Component ,
23- original : Component ,
23+ parent : Component ,
24+ index : number ,
25+ originalComponentSchema : Component ) => void ,
26+ onAddComponent ?: (
27+ component : Component ,
2428 parent : Component ,
2529 path : string ,
2630 index : number ,
27- isNew : boolean ,
28- originalComponentSchema : Component ,
2931 ) => void ;
3032 onEditComponent ?: ( component : Component ) => void ;
3133 onUpdateComponent ?: ( component : Component ) => void ;
@@ -66,6 +68,7 @@ export const FormBuilder = ({
6668 onEditComponent,
6769 onSaveComponent,
6870 onUpdateComponent,
71+ onAddComponent
6972} : FormBuilderProps ) => {
7073 const builder = useRef < FormioFormBuilder | null > ( null ) ;
7174 const renderElement = useRef < HTMLDivElement | null > ( null ) ;
@@ -77,6 +80,7 @@ export const FormBuilder = ({
7780 onEditComponent,
7881 onSaveComponent,
7982 onUpdateComponent,
83+ onAddComponent
8084 } ) ;
8185 useEffect ( ( ) => {
8286 handlersRef . current = {
@@ -85,8 +89,9 @@ export const FormBuilder = ({
8589 onEditComponent,
8690 onSaveComponent,
8791 onUpdateComponent,
92+ onAddComponent
8893 } ;
89- } , [ onChange , onDeleteComponent , onEditComponent , onSaveComponent , onUpdateComponent ] ) ;
94+ } , [ onChange , onDeleteComponent , onEditComponent , onSaveComponent , onUpdateComponent , onAddComponent ] ) ;
9095
9196 useEffect ( ( ) => {
9297 let ignore = false ;
@@ -128,11 +133,8 @@ export const FormBuilder = ({
128133 ) => {
129134 handlersRef . current . onSaveComponent ?.(
130135 component ,
131- original ,
132- parent ,
133- path ,
136+ parent ,
134137 index ,
135- isNew ,
136138 originalComponentSchema ,
137139 ) ;
138140 handlersRef . current . onChange ?.( structuredClone ( inst . form ) ) ;
@@ -157,7 +159,8 @@ export const FormBuilder = ({
157159 handlersRef . current . onEditComponent ?.( component ) ;
158160 } ;
159161
160- const handleAddComponent = ( ) => {
162+ const handleAddComponent = ( component : Component , parent : Component , path : string , index : number ) => {
163+ handlersRef . current . onAddComponent ?.( component , parent , path , index ) ;
161164 handlersRef . current . onChange ?.( structuredClone ( inst . form ) ) ;
162165 } ;
163166
0 commit comments