Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -295,19 +295,13 @@ function BlockFields( { clientId } ) {
field.Edit = createConfiguredControl( {
control: fieldDef.type,
clientId,
updateBlockAttributes,
fieldDef,
} );
}

return field;
} );
}, [
blockTypeFields,
blockType?.attributes,
clientId,
updateBlockAttributes,
] );
}, [ blockTypeFields, blockType?.attributes, clientId ] );

const handleToggleField = ( fieldId ) => {
setForm( ( prev ) => {
Expand Down Expand Up @@ -351,26 +345,7 @@ function BlockFields( { clientId } ) {
fields={ dataFormFields }
form={ form }
onChange={ ( changes ) => {
// Map field values to block attributes using field.setValue
const mappedChanges = {};
Object.entries( changes ).forEach(
( [ fieldId, fieldValue ] ) => {
const field = dataFormFields.find(
( f ) => f.id === fieldId
);
if ( field && field.setValue ) {
const updates = field.setValue( {
item: attributes,
value: fieldValue,
} );
Object.assign( mappedChanges, updates );
} else {
// For fields without setValue, use the value directly
mappedChanges[ fieldId ] = fieldValue;
}
}
);
updateBlockAttributes( clientId, mappedChanges );
updateBlockAttributes( clientId, changes );
} }
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ export function getUpdatedLinkAttributes( {
};
}

export default function Link( { data, field, config = {} } ) {
export default function Link( { data, field, onChange, config = {} } ) {
const [ isLinkControlOpen, setIsLinkControlOpen ] = useState( false );
const { popoverProps } = useInspectorPopoverPlacement( {
isControl: true,
} );
const { clientId, updateBlockAttributes, fieldDef } = config;
const { fieldDef } = config;
const updateAttributes = ( newValue ) => {
const mappedChanges = field.setValue( { item: data, value: newValue } );
updateBlockAttributes( clientId, mappedChanges );
onChange( mappedChanges );
};

const value = field.getValue( { item: data } );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,19 @@ function MediaThumbnail( { data, field, attachment } ) {
return <Icon icon={ mediaIcon } size={ 24 } />;
}

export default function Media( { data, field, config = {} } ) {
export default function Media( { data, field, onChange, config = {} } ) {
const { popoverProps } = useInspectorPopoverPlacement( {
isControl: true,
} );
const value = field.getValue( { item: data } );
const { allowedTypes = [], multiple = false } = field.config || {};
const { clientId, updateBlockAttributes, fieldDef } = config;
const { fieldDef } = config;
const updateAttributes = ( newFieldValue ) => {
const mappedChanges = field.setValue( {
item: data,
value: newFieldValue,
} );
updateBlockAttributes( clientId, mappedChanges );
onChange( mappedChanges );
};

// Check if featured image is supported by checking if it's in the mapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ export default function RichTextControl( {
data,
field,
hideLabelFromVision,
onChange,
config = {},
} ) {
const registry = useRegistry();
const attrValue = field.getValue( { item: data } );
const fieldConfig = field.config || {};
const { clientId, updateBlockAttributes } = config;
const { clientId } = config;
const updateAttributes = ( html ) => {
const mappedChanges = field.setValue( { item: data, value: html } );
updateBlockAttributes( clientId, mappedChanges );
onChange( mappedChanges );
};
const [ selection, setSelection ] = useState( {
start: undefined,
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/cover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ if ( window.__experimentalContentOnlyPatternInsertion ) {
},
];
settings[ formKey ] = {
fields: [ 'content' ],
fields: [ 'background' ],
};
}

Expand Down
Loading