From c1b204438af8e3cac98caa675ad05208e8feacdd Mon Sep 17 00:00:00 2001 From: ramonjd Date: Thu, 25 Aug 2022 15:15:24 +1000 Subject: [PATCH] Reinstating default "constrained" layout type, but adding an extra ephemeral property to identify blocks that have been inserted. --- packages/block-library/src/group/block.json | 6 +++++- packages/block-library/src/group/edit.js | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/group/block.json b/packages/block-library/src/group/block.json index 771405bddcde5d..2bc133118cc3d4 100644 --- a/packages/block-library/src/group/block.json +++ b/packages/block-library/src/group/block.json @@ -17,7 +17,11 @@ "enum": [ "all", "insert", "noContent", false ] }, "layout": { - "type": "object" + "type": "object", + "default": { + "type": "constrained", + "isDefault": true + } } }, "supports": { diff --git a/packages/block-library/src/group/edit.js b/packages/block-library/src/group/edit.js index 92b1286e7c1c3c..cacfb9de594a67 100644 --- a/packages/block-library/src/group/edit.js +++ b/packages/block-library/src/group/edit.js @@ -124,10 +124,13 @@ function GroupEdit( { attributes, name, setAttributes, clientId } ) { ); const { tagName: TagName = 'div', templateLock, layout = {} } = attributes; - const { type: layoutType = null } = layout; + const { type: layoutType = null, isDefault = false } = layout; // Whether to show the variations placeholder. - const showPlaceholder = ! layoutType && ! hasInnerBlocks; + // `isDefault: true` only exists in the default layout attributes in block.json + // in order to identify blocks that have been inserted, programmatically or otherwise, with no changes. + // When a user selects a layout `isDefault` won't appear in the block's attributes. + const showPlaceholder = isDefault && ! hasInnerBlocks; // Layout settings. const defaultLayout = useSetting( 'layout' ) || {};