| @@ -16,13 +16,23 @@ | ||
| 16 | 16 | 'core/group', |
| 17 | 17 | 'core/column', |
| 18 | 18 | 'core/spacer', |
| 19 | 19 | 'core/separator', |
| 20 | + 'core/social-link', | |
| 21 | + 'core/navigation-link', | |
| 22 | + // Says the save can nest a link under a menu item; never added on its own. | |
| 23 | + 'core/navigation-submenu', | |
| 20 | 24 | ]; |
| 21 | 25 | |
| 22 | 26 | // One level of explicit children, on containers only. |
| 23 | 27 | const CHILD_BEARING_TYPES = ['core/group', 'core/column']; |
| 24 | 28 | |
| 29 | +// A lone button or social icon is invalid markup. | |
| 30 | +const ROW_ONLY_TYPES = { | |
| 31 | + 'core/button': 'core/buttons', | |
| 32 | + 'core/social-link': 'core/social-links', | |
| 33 | +}; | |
| 34 | + | |
| 25 | 35 | // The model authors `text`; each type stores it under its own attribute. |
| 26 | 36 | const RICH_TEXT_ATTR = { |
| 27 | 37 | 'core/button': 'text', |
| 28 | 38 | 'core/heading': 'content', |
| @@ -30,8 +40,9 @@ | ||
| 30 | 40 | 'core/pullquote': 'value', |
| 31 | 41 | 'core/code': 'content', |
| 32 | 42 | 'core/preformatted': 'content', |
| 33 | 43 | 'core/verse': 'content', |
| 44 | + 'core/navigation-link': 'label', | |
| 34 | 45 | }; |
| 35 | 46 | |
| 36 | 47 | const paragraphChildren = (text) => |
| 37 | 48 | text ? [createBlock('core/paragraph', { content: text })] : []; |
| @@ -40,8 +51,11 @@ | ||
| 40 | 51 | const childBlocks = (children) => |
| 41 | 52 | (children ?? []) |
| 42 | 53 | .filter( |
| 43 | 54 | ({ blockType }) => |
| 55 | + // A composed child only carries text, and neither type is valid on its own. | |
| 56 | + blockType !== 'core/social-link' && | |
| 57 | + blockType !== 'core/navigation-link' && | |
| 44 | 58 | blockType !== 'core/column' && |
| 45 | 59 | INSERTABLE_BLOCK_TYPES.includes(blockType) && |
| 46 | 60 | getBlockType(blockType), |
| 47 | 61 | ) |
| @@ -88,8 +102,9 @@ | ||
| 88 | 102 | blockType, |
| 89 | 103 | patch = {}, |
| 90 | 104 | clear = [], |
| 91 | 105 | presetSlugs = {}, |
| 106 | + { joinsRow = false } = {}, | |
| 92 | 107 | ) => { |
| 93 | 108 | if (!INSERTABLE_BLOCK_TYPES.includes(blockType)) return null; |
| 94 | 109 | if (!getBlockType(blockType)) return null; |
| 95 | 110 | const { text, children, ...attributePatch } = patch ?? {}; |
| @@ -98,8 +113,9 @@ | ||
| 98 | 113 | attributePatch, |
| 99 | 114 | clear ?? [], |
| 100 | 115 | presetSlugs, |
| 101 | 116 | ); |
| 102 | - if (blockType !== 'core/button') return markup; | |
| 103 | - // A lone button never exists in the editor; ship it inside its wrapper. | |
| 104 | - return serialize([createBlock('core/buttons', {}, parse(markup))]); | |
| 117 | + // Landing beside a sibling puts it in that row already; wrapping would nest one. | |
| 118 | + const row = joinsRow ? null : ROW_ONLY_TYPES[blockType]; | |
| 119 | + if (!row) return markup; | |
| 120 | + return serialize([createBlock(row, {}, parse(markup))]); | |
| 105 | 121 | }; |