diff --git a/packages/block-editor/src/components/block-bindings/attribute-control.js b/packages/block-editor/src/components/block-bindings/attribute-control.js index b19be9e80187b9..5ea27eda4e3c1d 100644 --- a/packages/block-editor/src/components/block-bindings/attribute-control.js +++ b/packages/block-editor/src/components/block-bindings/attribute-control.js @@ -50,10 +50,12 @@ export default function BlockBindingsAttributeControl( { getBlockType, } = unlock( select( blocksStore ) ); - const _attributeType = - getBlockType( blockName ).attributes?.[ attribute ]?.type; + const blockAttribute = + getBlockType( blockName ).attributes?.[ attribute ]; + const _attributeType = blockAttribute?.type; const attributeType = _attributeType === 'rich-text' ? 'string' : _attributeType; + const attributeFormat = blockAttribute?.format; const sourceFields = {}; Object.entries( getAllBlockBindingsSources() ).forEach( @@ -66,7 +68,11 @@ export default function BlockBindingsAttributeControl( { return; } const compatibleFieldsList = fieldsList.filter( - ( field ) => field.type === attributeType + ( field ) => + attributeType === field.type && + ( attributeFormat + ? attributeFormat === field.format + : true ) ); if ( compatibleFieldsList.length ) { sourceFields[ sourceName ] = compatibleFieldsList; diff --git a/packages/block-editor/src/hooks/block-bindings.js b/packages/block-editor/src/hooks/block-bindings.js index 94cdcce23a3211..4663916e839748 100644 --- a/packages/block-editor/src/hooks/block-bindings.js +++ b/packages/block-editor/src/hooks/block-bindings.js @@ -118,11 +118,7 @@ export const BlockBindingsPanel = ( { name: blockName, metadata } ) => { export default { edit: BlockBindingsPanel, attributeKeys: [ 'metadata' ], - hasSupport( name ) { - return ! [ - 'core/post-date', - 'core/navigation-link', - 'core/navigation-submenu', - ].includes( name ); + hasSupport() { + return true; }, }; diff --git a/packages/block-library/src/navigation-link/block.json b/packages/block-library/src/navigation-link/block.json index 99d893120cea1f..c471245c5f1c14 100644 --- a/packages/block-library/src/navigation-link/block.json +++ b/packages/block-library/src/navigation-link/block.json @@ -35,6 +35,7 @@ }, "url": { "type": "string", + "format": "uri", "role": "content" }, "title": { diff --git a/packages/block-library/src/navigation-submenu/block.json b/packages/block-library/src/navigation-submenu/block.json index 33af205689b9a6..530d7536dc3b03 100644 --- a/packages/block-library/src/navigation-submenu/block.json +++ b/packages/block-library/src/navigation-submenu/block.json @@ -30,6 +30,7 @@ }, "url": { "type": "string", + "format": "uri", "role": "content" }, "title": { diff --git a/packages/block-library/src/post-date/block.json b/packages/block-library/src/post-date/block.json index ea99f6ab5ff8d4..6f88611a04921a 100644 --- a/packages/block-library/src/post-date/block.json +++ b/packages/block-library/src/post-date/block.json @@ -9,6 +9,7 @@ "attributes": { "datetime": { "type": "string", + "format": "date-time", "role": "content" }, "textAlign": { diff --git a/packages/editor/src/bindings/post-data.js b/packages/editor/src/bindings/post-data.js index 398ae2664c7d42..7fcb37339736b8 100644 --- a/packages/editor/src/bindings/post-data.js +++ b/packages/editor/src/bindings/post-data.js @@ -16,16 +16,19 @@ const postDataFields = [ label: __( 'Post Date' ), args: { field: 'date' }, type: 'string', + format: 'date-time', }, { label: __( 'Post Modified Date' ), args: { field: 'modified' }, type: 'string', + format: 'date-time', }, { label: __( 'Post Link' ), args: { field: 'link' }, type: 'string', + format: 'uri', }, ]; diff --git a/packages/editor/src/bindings/test/post-data.js b/packages/editor/src/bindings/test/post-data.js index 4669dfd9852516..6444e90ec3d9a5 100644 --- a/packages/editor/src/bindings/test/post-data.js +++ b/packages/editor/src/bindings/test/post-data.js @@ -163,16 +163,19 @@ describe( 'post-data bindings', () => { label: 'Post Date', args: { field: 'date' }, type: 'string', + format: 'date-time', }, { label: 'Post Modified Date', args: { field: 'modified' }, type: 'string', + format: 'date-time', }, { label: 'Post Link', args: { field: 'link' }, type: 'string', + format: 'uri', }, ] ); } ); diff --git a/schemas/json/block.json b/schemas/json/block.json index 29c7914e6e2caa..3300ab826a2f89 100644 --- a/schemas/json/block.json +++ b/schemas/json/block.json @@ -144,6 +144,18 @@ } ] }, + "format": { + "description": "The format provides additional information about the attribute's shape.", + "type": "string", + "enum": [ + "date-time", + "uri", + "email", + "ip", + "uuid", + "hex-color" + ] + }, "enum": { "description": "An attribute can be defined as one of a fixed set of values. This is specified by an enum, which contains an array of allowed values:", "type": "array", diff --git a/test/e2e/specs/editor/various/block-bindings/post-data.spec.js b/test/e2e/specs/editor/various/block-bindings/post-data.spec.js index 21b55c6e8bb76d..f952a67aac23d7 100644 --- a/test/e2e/specs/editor/various/block-bindings/post-data.spec.js +++ b/test/e2e/specs/editor/various/block-bindings/post-data.spec.js @@ -52,7 +52,7 @@ test.describe( 'Post Data source', () => { // Check the fields registered by other sources are there. } ); - test( 'should not render Attributes panel for date blocks', async ( { + test( 'should include post data fields in UI to connect attributes on date blocks', async ( { editor, page, } ) => { @@ -69,9 +69,15 @@ test.describe( 'Post Data source', () => { }, }, } ); - await expect( - page.getByLabel( 'Attributes options' ) - ).toBeHidden(); + await page + .getByRole( 'button', { + name: 'datetime', + } ) + .click(); + const postDataMenuItem = page.getByRole( 'menuitem', { + name: 'Post Data', + } ); + await expect( postDataMenuItem ).toBeVisible(); } ); } ); } );