From 7f17cf4eaecbbe63391c2f17211d696f46d8186f Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Fri, 19 May 2023 15:02:33 +0200 Subject: [PATCH] Try using slot fill for template content --- docs/reference-guides/core-blocks.md | 6 ++-- lib/blocks.php | 2 +- lib/experimental/pattern.php | 6 ++-- packages/block-editor/src/components/index.js | 1 + .../src/components/rich-text/index.js | 14 +++++++- .../src/components/template-content/index.js | 10 ++++++ packages/block-library/src/index.js | 4 +-- .../block.json | 6 ++-- .../src/template-content/edit.js | 35 +++++++++++++++++++ .../index.js | 0 .../init.js | 0 .../save.js | 2 +- .../block-library/src/template-fill/edit.js | 25 ------------- packages/blocks/src/api/validation/index.js | 4 +-- 14 files changed, 74 insertions(+), 41 deletions(-) create mode 100644 packages/block-editor/src/components/template-content/index.js rename packages/block-library/src/{template-fill => template-content}/block.json (72%) create mode 100644 packages/block-library/src/template-content/edit.js rename packages/block-library/src/{template-fill => template-content}/index.js (100%) rename packages/block-library/src/{template-fill => template-content}/init.js (100%) rename packages/block-library/src/{template-fill => template-content}/save.js (61%) delete mode 100644 packages/block-library/src/template-fill/edit.js diff --git a/docs/reference-guides/core-blocks.md b/docs/reference-guides/core-blocks.md index 56bae08a2ebd5..c4cff0cf5f73e 100644 --- a/docs/reference-guides/core-blocks.md +++ b/docs/reference-guides/core-blocks.md @@ -827,11 +827,11 @@ A cloud of your most used tags. ([Source](https://github.com/WordPress/gutenberg - **Supports:** align, anchor, spacing (margin, padding), typography (lineHeight), ~~html~~ - **Attributes:** largestFontSize, numberOfTags, showTagCounts, smallestFontSize, taxonomy -## Template Fill +## Template Content -Add custom template fill to use with the template slot. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/template-fill)) +Use template content to replace the template placeholder. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/template-content)) -- **Name:** core/template-fill +- **Name:** core/template-content - **Category:** widgets - **Supports:** ~~className~~, ~~customClassName~~, ~~html~~, ~~inserter~~ - **Attributes:** content, name diff --git a/lib/blocks.php b/lib/blocks.php index da2d8447205e6..cf13f4270f2e5 100644 --- a/lib/blocks.php +++ b/lib/blocks.php @@ -40,7 +40,7 @@ function gutenberg_reregister_core_block_types() { 'spacer', 'table', 'table-of-contents', - 'template-fill', + 'template-content', 'text-columns', 'verse', 'video', diff --git a/lib/experimental/pattern.php b/lib/experimental/pattern.php index c305902081f07..4846477153797 100644 --- a/lib/experimental/pattern.php +++ b/lib/experimental/pattern.php @@ -14,7 +14,7 @@ '', array( '', - '

', + '

', '', '', '
', @@ -33,9 +33,9 @@ '', '
', '', - '', + '', esc_html__( 'Get In Touch', 'default' ), - '', + '', ) ), ) diff --git a/packages/block-editor/src/components/index.js b/packages/block-editor/src/components/index.js index f113ad3b05f63..4b2295a7c0fff 100644 --- a/packages/block-editor/src/components/index.js +++ b/packages/block-editor/src/components/index.js @@ -84,6 +84,7 @@ export { RichTextToolbarButton, __unstableRichTextInputEvent, } from './rich-text'; +export { default as __experimentalTemplateContent } from './template-content'; export { default as ToolSelector } from './tool-selector'; export { default as __experimentalUnitControl } from './unit-control'; export { default as URLInput } from './url-input'; diff --git a/packages/block-editor/src/components/rich-text/index.js b/packages/block-editor/src/components/rich-text/index.js index 4217d6de58899..09d3410ae8bfb 100644 --- a/packages/block-editor/src/components/rich-text/index.js +++ b/packages/block-editor/src/components/rich-text/index.js @@ -46,6 +46,7 @@ import { useInsertReplacementText } from './use-insert-replacement-text'; import { useFirefoxCompat } from './use-firefox-compat'; import FormatEdit from './format-edit'; import { getMultilineTag, getAllowedFormats } from './utils'; +import TemplateContent from '../template-content'; export const keyboardShortcutContext = createContext(); export const inputEventContext = createContext(); @@ -318,7 +319,7 @@ function RichTextWrapper( } const TagName = tagName; - return ( + const result = ( <> { isSelected && ( @@ -415,6 +416,17 @@ function RichTextWrapper( /> ); + + if ( ! originalValue.startsWith( '' ); }