Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style book: Fix critical error when blocks are not registered #67703

Merged
merged 1 commit into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading