@@ -29,9 +29,13 @@ import { FieldSchemaMap } from "../utils/fieldSchemaMap";
2929import { isFieldDisabled } from "../utils/isFieldDisabled" ;
3030import { IReferenceContentTypeSchema } from "../../cms/types/contentTypeSchema.types" ;
3131import { VisualBuilderCslpEventDetails } from "../types/visualBuilder.types" ;
32+ import { FormIcon } from "./icons" ;
33+ import { getDOMEditStack } from "../utils/getCsDataOfElement" ;
3234
3335export type FieldDetails = Pick < VisualBuilderCslpEventDetails , "editableElement" | "fieldMetadata" > ;
34- interface MultipleFieldToolbarProps extends FieldDetails { } ;
36+ interface MultipleFieldToolbarProps {
37+ eventDetails : VisualBuilderCslpEventDetails ;
38+ } ;
3539
3640function handleReplaceAsset ( fieldMetadata : CslpData ) {
3741 // TODO avoid sending whole fieldMetadata
@@ -72,13 +76,26 @@ function handleEdit(fieldMetadata: CslpData) {
7276 ) ;
7377}
7478
79+ function handleFormFieldFocus ( eventDetails : VisualBuilderCslpEventDetails ) {
80+ const { editableElement, fieldMetadata, cslpData } = eventDetails ;
81+ visualBuilderPostMessage ?. send (
82+ VisualBuilderPostMessageEvents . OPEN_QUICK_FORM ,
83+ {
84+ fieldMetadata,
85+ cslpData,
86+ }
87+ ) . then ( ( ) => {
88+ visualBuilderPostMessage ?. send ( VisualBuilderPostMessageEvents . FOCUS_FIELD , {
89+ DOMEditStack : getDOMEditStack ( editableElement ) ,
90+ } ) ;
91+ } ) ;
92+ }
93+
7594function FieldToolbarComponent (
7695 props : MultipleFieldToolbarProps
7796) : JSX . Element | null {
78- const {
79- fieldMetadata,
80- editableElement : targetElement ,
81- } = props ;
97+ const { eventDetails } = props ;
98+ const { fieldMetadata, editableElement : targetElement } = eventDetails ;
8299 const direction = useSignal ( "" ) ;
83100 const parentPath =
84101 fieldMetadata ?. multipleFieldMetadata ?. parentDetails ?. parentCslpValue ||
@@ -151,7 +168,7 @@ function FieldToolbarComponent(
151168 // propagation to be stopped, should ideally only attach onClick to fieldpath dropdown
152169 e . preventDefault ( ) ;
153170 e . stopPropagation ( ) ;
154- handleEdit ( props . fieldMetadata ) ;
171+ handleEdit ( fieldMetadata ) ;
155172 } }
156173 >
157174 < Icon />
@@ -172,10 +189,10 @@ function FieldToolbarComponent(
172189 e . stopPropagation ( ) ;
173190 e . preventDefault ( ) ;
174191 if ( fieldType === FieldDataType . REFERENCE ) {
175- handleReplaceReference ( props . fieldMetadata ) ;
192+ handleReplaceReference ( fieldMetadata ) ;
176193 return ;
177194 } else if ( fieldType === FieldDataType . FILE ) {
178- handleReplaceAsset ( props . fieldMetadata ) ;
195+ handleReplaceAsset ( fieldMetadata ) ;
179196 return ;
180197 }
181198 } }
@@ -184,6 +201,20 @@ function FieldToolbarComponent(
184201 </ button >
185202 ) : null ;
186203
204+ const formButton = < button
205+ className = { classNames (
206+ "visual-builder__replace-button visual-builder__button visual-builder__button--secondary" ,
207+ visualBuilderStyles ( ) [ "visual-builder__button" ] ,
208+ visualBuilderStyles ( ) [ "visual-builder__button--secondary" ] ,
209+ visualBuilderStyles ( ) [ "visual-builder__tooltip" ]
210+ ) }
211+ data-tooltip = { "Form" }
212+ data-testid = { `visual-builder-form` }
213+ onClick = { ( e ) => { handleFormFieldFocus ( eventDetails ) } }
214+ >
215+ < FormIcon />
216+ </ button >
217+
187218 const totalElementCount = targetElement ?. parentNode ?. childElementCount ?? 1 ;
188219 const indexOfElement = fieldMetadata ?. multipleFieldMetadata ?. index ;
189220
@@ -292,6 +323,7 @@ function FieldToolbarComponent(
292323 </ button >
293324
294325 { isModalEditable ? editButton : null }
326+ { formButton }
295327 { isReplaceAllowed ? replaceButton : null }
296328
297329 < button
@@ -320,8 +352,8 @@ function FieldToolbarComponent(
320352 < >
321353 { isModalEditable ? editButton : null }
322354 { isReplaceAllowed ? replaceButton : null }
323- { fieldSchema ? < CommentIcon fieldMetadata = { fieldMetadata } fieldSchema = { fieldSchema } /> : null }
324-
355+ { formButton }
356+ { fieldSchema ? < CommentIcon fieldMetadata = { fieldMetadata } fieldSchema = { fieldSchema } /> : null }
325357 </ >
326358 ) }
327359 </ >
0 commit comments