Skip to content

Commit

Permalink
Style book: Fix critical error when blocks are not registered (#67703)
Browse files Browse the repository at this point in the history
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: ramonjd <[email protected]>
  • Loading branch information
3 people authored Dec 7, 2024
1 parent 959bb6b commit 72417c3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 29 deletions.
75 changes: 47 additions & 28 deletions packages/edit-site/src/components/style-book/examples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import {
/**
* Internal dependencies
*/
import type { BlockExample, ColorOrigin, MultiOriginPalettes } from './types';
import type {
Block,
BlockExample,
ColorOrigin,
MultiOriginPalettes,
} from './types';
import ColorExamples from './color-examples';
import DuotoneExamples from './duotone-examples';
import { STYLE_BOOK_COLOR_GROUPS } from './constants';
Expand Down Expand Up @@ -91,30 +96,33 @@ function getOverviewBlockExamples(
examples.push( themeColorexample );
}

const headingBlock = createBlock( 'core/heading', {
content: __(
`AaBbCcDdEeFfGgHhiiJjKkLIMmNnOoPpQakRrssTtUuVVWwXxxYyZzOl23356789X{(…)},2!*&:/A@HELFO™`
),
level: 1,
} );
const firstParagraphBlock = createBlock( 'core/paragraph', {
content: __(
`A paragraph in a website refers to a distinct block of text that is used to present and organize information. It is a fundamental unit of content in web design and is typically composed of a group of related sentences or thoughts focused on a particular topic or idea. Paragraphs play a crucial role in improving the readability and user experience of a website. They break down the text into smaller, manageable chunks, allowing readers to scan the content more easily.`
),
} );
const secondParagraphBlock = createBlock( 'core/paragraph', {
content: __(
`Additionally, paragraphs help structure the flow of information and provide logical breaks between different concepts or pieces of information. In terms of formatting, paragraphs in websites are commonly denoted by a vertical gap or indentation between each block of text. This visual separation helps visually distinguish one paragraph from another, creating a clear and organized layout that guides the reader through the content smoothly.`
),
} );
// Get examples for typography blocks.
const typographyBlockExamples: Block[] = [];

if ( getBlockType( 'core/heading' ) ) {
const headingBlock = createBlock( 'core/heading', {
content: __(
`AaBbCcDdEeFfGgHhiiJjKkLIMmNnOoPpQakRrssTtUuVVWwXxxYyZzOl23356789X{(…)},2!*&:/A@HELFO™`
),
level: 1,
} );
typographyBlockExamples.push( headingBlock );
}

if ( getBlockType( 'core/paragraph' ) ) {
const firstParagraphBlock = createBlock( 'core/paragraph', {
content: __(
`A paragraph in a website refers to a distinct block of text that is used to present and organize information. It is a fundamental unit of content in web design and is typically composed of a group of related sentences or thoughts focused on a particular topic or idea. Paragraphs play a crucial role in improving the readability and user experience of a website. They break down the text into smaller, manageable chunks, allowing readers to scan the content more easily.`
),
} );
const secondParagraphBlock = createBlock( 'core/paragraph', {
content: __(
`Additionally, paragraphs help structure the flow of information and provide logical breaks between different concepts or pieces of information. In terms of formatting, paragraphs in websites are commonly denoted by a vertical gap or indentation between each block of text. This visual separation helps visually distinguish one paragraph from another, creating a clear and organized layout that guides the reader through the content smoothly.`
),
} );

const textExample = {
name: 'typography',
title: __( 'Typography' ),
category: 'overview',
blocks: [
headingBlock,
createBlock(
if ( getBlockType( 'core/group' ) ) {
const groupBlock = createBlock(
'core/group',
{
layout: {
Expand All @@ -129,10 +137,21 @@ function getOverviewBlockExamples(
},
},
[ firstParagraphBlock, secondParagraphBlock ]
),
],
};
examples.push( textExample );
);
typographyBlockExamples.push( groupBlock );
} else {
typographyBlockExamples.push( firstParagraphBlock );
}
}

if ( !! typographyBlockExamples.length ) {
examples.push( {
name: 'typography',
title: __( 'Typography' ),
category: 'overview',
blocks: typographyBlockExamples,
} );
}

const otherBlockExamples = [
'core/image',
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-site/src/components/style-book/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type Block = {
export type Block = {
name: string;
attributes: Record< string, unknown >;
innerBlocks?: Block[];
Expand Down

1 comment on commit 72417c3

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 72417c3.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12210769557
📝 Reported issues:

Please sign in to comment.