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 @@ -24,7 +24,7 @@ import { store as blockEditorStore } from '../../store';
import BlockIcon from '../block-icon';
import useBlockDisplayTitle from '../block-title/use-block-display-title';
import useBlockDisplayInformation from '../use-block-display-information';
const { fieldsKey } = unlock( blocksPrivateApis );
const { fieldsKey, formKey } = unlock( blocksPrivateApis );
import FieldsDropdownMenu from './fields-dropdown-menu';

// controls
Expand Down Expand Up @@ -197,14 +197,8 @@ function BlockFields( { clientId } ) {

const blockTypeFields = blockType?.[ fieldsKey ];

// Track visible fields
const [ visibleFields, setVisibleFields ] = useState( () => {
// Show fields that have shownByDefault: true by default
return (
blockTypeFields
?.filter( ( field ) => field.shownByDefault )
.map( ( field ) => field.id ) || []
);
const [ form, setForm ] = useState( () => {
return blockType?.[ formKey ];
} );

// Build DataForm fields with proper structure
Expand Down Expand Up @@ -315,22 +309,19 @@ function BlockFields( { clientId } ) {
updateBlockAttributes,
] );

// Build form config showing only visible fields
const form = useMemo(
() => ( {
fields: dataFormFields
.filter( ( field ) => visibleFields.includes( field.id ) )
.map( ( field ) => field.id ),
} ),
[ dataFormFields, visibleFields ]
);

const handleToggleField = ( fieldId ) => {
setVisibleFields( ( prev ) => {
if ( prev.includes( fieldId ) ) {
return prev.filter( ( id ) => id !== fieldId );
setForm( ( prev ) => {
if ( prev.fields?.includes( fieldId ) ) {
return {
...prev,
fields: prev.fields.filter( ( id ) => id !== fieldId ),
};
}
return [ ...prev, fieldId ];

return {
...prev,
fields: [ ...( prev.fields || [] ), fieldId ],
};
} );
};

Expand All @@ -350,7 +341,7 @@ function BlockFields( { clientId } ) {
</HStack>
<FieldsDropdownMenu
fields={ dataFormFields }
visibleFields={ visibleFields }
visibleFields={ form.fields }
onToggleField={ handleToggleField }
/>
</HStack>
Expand Down
7 changes: 4 additions & 3 deletions packages/block-library/src/audio/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import save from './save';
import transforms from './transforms';
import { unlock } from '../lock-unlock';

const { fieldsKey } = unlock( blocksPrivateApis );
const { fieldsKey, formKey } = unlock( blocksPrivateApis );

const { name } = metadata;

Expand All @@ -42,7 +42,6 @@ if ( window.__experimentalContentOnlyPatternInsertion ) {
id: 'audio',
label: __( 'Audio' ),
type: 'media',
shownByDefault: true,
mapping: {
id: 'id',
url: 'src',
Expand All @@ -56,9 +55,11 @@ if ( window.__experimentalContentOnlyPatternInsertion ) {
id: 'caption',
label: __( 'Caption' ),
type: 'richtext',
shownByDefault: false,
},
];
settings[ formKey ] = {
fields: [ 'audio' ],
};
}

export const init = () => initBlock( { name, metadata, settings } );
7 changes: 4 additions & 3 deletions packages/block-library/src/button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import metadata from './block.json';
import save from './save';
import { unlock } from '../lock-unlock';

const { fieldsKey } = unlock( blocksPrivateApis );
const { fieldsKey, formKey } = unlock( blocksPrivateApis );

const { name } = metadata;

Expand Down Expand Up @@ -44,20 +44,21 @@ if ( window.__experimentalContentOnlyPatternInsertion ) {
id: 'text',
label: __( 'Content' ),
type: 'richtext',
shownByDefault: true,
},
{
id: 'link',
label: __( 'Link' ),
type: 'link',
shownByDefault: false,
mapping: {
url: 'url',
rel: 'rel',
linkTarget: 'linkTarget',
},
},
];
settings[ formKey ] = {
fields: [ 'text' ],
};
}

export const init = () => initBlock( { name, metadata, settings } );
6 changes: 4 additions & 2 deletions packages/block-library/src/code/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import save from './save';
import transforms from './transforms';
import { unlock } from '../lock-unlock';

const { fieldsKey } = unlock( blocksPrivateApis );
const { fieldsKey, formKey } = unlock( blocksPrivateApis );

const { name } = metadata;

Expand Down Expand Up @@ -49,9 +49,11 @@ if ( window.__experimentalContentOnlyPatternInsertion ) {
id: 'content',
label: __( 'Code' ),
type: 'richtext',
shownByDefault: true,
},
];
settings[ formKey ] = {
fields: [ 'content' ],
};
}

export const init = () => initBlock( { name, metadata, settings } );
6 changes: 4 additions & 2 deletions packages/block-library/src/cover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import transforms from './transforms';
import variations from './variations';
import { unlock } from '../lock-unlock';

const { fieldsKey } = unlock( blocksPrivateApis );
const { fieldsKey, formKey } = unlock( blocksPrivateApis );

const { name } = metadata;

Expand Down Expand Up @@ -62,7 +62,6 @@ if ( window.__experimentalContentOnlyPatternInsertion ) {
id: 'background',
label: __( 'Background' ),
type: 'media',
shownByDefault: true,
mapping: {
type: 'backgroundType',
id: 'id',
Expand All @@ -78,6 +77,9 @@ if ( window.__experimentalContentOnlyPatternInsertion ) {
},
},
];
settings[ formKey ] = {
fields: [ 'content' ],
};
}

export const init = () => initBlock( { name, metadata, settings } );
6 changes: 4 additions & 2 deletions packages/block-library/src/details/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import save from './save';
import transforms from './transforms';
import { unlock } from '../lock-unlock';

const { fieldsKey } = unlock( blocksPrivateApis );
const { fieldsKey, formKey } = unlock( blocksPrivateApis );

const { name } = metadata;
export { metadata, name };
Expand Down Expand Up @@ -71,9 +71,11 @@ if ( window.__experimentalContentOnlyPatternInsertion ) {
id: 'summary',
label: __( 'Summary' ),
type: 'richtext',
shownByDefault: true,
},
];
settings[ formKey ] = {
fields: [ 'summary' ],
};
}

export const init = () => initBlock( { name, metadata, settings } );
8 changes: 4 additions & 4 deletions packages/block-library/src/file/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import save from './save';
import transforms from './transforms';
import { unlock } from '../lock-unlock';

const { fieldsKey } = unlock( blocksPrivateApis );
const { fieldsKey, formKey } = unlock( blocksPrivateApis );

const { name } = metadata;

Expand All @@ -42,7 +42,6 @@ if ( window.__experimentalContentOnlyPatternInsertion ) {
id: 'file',
label: __( 'File' ),
type: 'media',
shownByDefault: true,
mapping: {
id: 'id',
url: 'href',
Expand All @@ -56,15 +55,16 @@ if ( window.__experimentalContentOnlyPatternInsertion ) {
id: 'fileName',
label: __( 'Filename' ),
type: 'richtext',
shownByDefault: false,
},
{
id: 'downloadButtonText',
label: __( 'Button Text' ),
type: 'richtext',
shownByDefault: false,
},
];
settings[ formKey ] = {
fields: [ 'file' ],
};
}

export const init = () => initBlock( { name, metadata, settings } );
6 changes: 4 additions & 2 deletions packages/block-library/src/heading/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import transforms from './transforms';
import variations from './variations';
import { unlock } from '../lock-unlock';

const { fieldsKey } = unlock( blocksPrivateApis );
const { fieldsKey, formKey } = unlock( blocksPrivateApis );

const { name } = metadata;

Expand Down Expand Up @@ -79,9 +79,11 @@ if ( window.__experimentalContentOnlyPatternInsertion ) {
id: 'content',
label: __( 'Content' ),
type: 'richtext',
shownByDefault: true,
},
];
settings[ formKey ] = {
fields: [ 'content' ],
};
}

export const init = () => initBlock( { name, metadata, settings } );
9 changes: 4 additions & 5 deletions packages/block-library/src/image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import save from './save';
import transforms from './transforms';
import { unlock } from '../lock-unlock';

const { fieldsKey } = unlock( blocksPrivateApis );
const { fieldsKey, formKey } = unlock( blocksPrivateApis );

const { name } = metadata;

Expand Down Expand Up @@ -72,7 +72,6 @@ if ( window.__experimentalContentOnlyPatternInsertion ) {
id: 'image',
label: __( 'Image' ),
type: 'media',
shownByDefault: true,
mapping: {
id: 'id',
url: 'url',
Expand All @@ -88,7 +87,6 @@ if ( window.__experimentalContentOnlyPatternInsertion ) {
id: 'link',
label: __( 'Link' ),
type: 'link',
shownByDefault: false,
mapping: {
url: 'href',
rel: 'rel',
Expand All @@ -100,15 +98,16 @@ if ( window.__experimentalContentOnlyPatternInsertion ) {
id: 'caption',
label: __( 'Caption' ),
type: 'richtext',
shownByDefault: false,
},
{
id: 'alt',
label: __( 'Alt text' ),
type: 'text',
shownByDefault: false,
},
];
settings[ formKey ] = {
fields: [ 'image' ],
};
}

export const init = () => initBlock( { name, metadata, settings } );
6 changes: 4 additions & 2 deletions packages/block-library/src/list-item/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import save from './save';
import transforms from './transforms';
import { unlock } from '../lock-unlock';

const { fieldsKey } = unlock( blocksPrivateApis );
const { fieldsKey, formKey } = unlock( blocksPrivateApis );

const { name } = metadata;

Expand All @@ -42,9 +42,11 @@ if ( window.__experimentalContentOnlyPatternInsertion ) {
id: 'content',
label: __( 'Content' ),
type: 'richtext',
shownByDefault: true,
},
];
settings[ formKey ] = {
fields: [ 'content' ],
};
}

export const init = () => initBlock( { name, metadata, settings } );
7 changes: 4 additions & 3 deletions packages/block-library/src/media-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import save from './save';
import transforms from './transforms';
import { unlock } from '../lock-unlock';

const { fieldsKey } = unlock( blocksPrivateApis );
const { fieldsKey, formKey } = unlock( blocksPrivateApis );

const { name } = metadata;

Expand Down Expand Up @@ -60,7 +60,6 @@ if ( window.__experimentalContentOnlyPatternInsertion ) {
id: 'media',
label: __( 'Media' ),
type: 'media',
shownByDefault: true,
mapping: {
id: 'mediaId',
type: 'mediaType',
Expand All @@ -76,14 +75,16 @@ if ( window.__experimentalContentOnlyPatternInsertion ) {
id: 'link',
label: __( 'Link' ),
type: 'link',
shownByDefault: false,
mapping: {
url: 'href',
rel: 'rel',
linkTarget: 'linkTarget',
},
},
];
settings[ formKey ] = {
fields: [ 'media' ],
};
}

export const init = () => initBlock( { name, metadata, settings } );
6 changes: 4 additions & 2 deletions packages/block-library/src/more/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import save from './save';
import transforms from './transforms';
import { unlock } from '../lock-unlock';

const { fieldsKey } = unlock( blocksPrivateApis );
const { fieldsKey, formKey } = unlock( blocksPrivateApis );

const { name } = metadata;

Expand Down Expand Up @@ -46,9 +46,11 @@ if ( window.__experimentalContentOnlyPatternInsertion ) {
id: 'customText',
label: __( 'Content' ),
type: 'richtext',
shownByDefault: true,
},
];
settings[ formKey ] = {
fields: [ 'customText' ],
};
}

export const init = () => initBlock( { name, metadata, settings } );
Loading
Loading