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

feat: migrate block definitions to Config API #42

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
1 change: 1 addition & 0 deletions examples/nextjs/starter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@snapwp/codegen-config": "file:../../../packages/codegen-config",
"@snapwp/eslint-config": "file:../../../packages/eslint-config",
"@snapwp/prettier-config": "file:../../../packages/prettier-config",
"@snapwp/types": "file:../../../packages/types",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.2.0",
"@types/jest": "^29.5.14",
Expand Down
11 changes: 0 additions & 11 deletions examples/nextjs/starter/src/app/[[...path]]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
import { TemplateRenderer } from '@snapwp/next';
import { EditorBlocksRenderer } from '@snapwp/blocks';

/**
* @todo Add an example of progressively overloading block definitions, e.g.:
*
* const blocks: BlockDefinitions = {
* 'CoreCustom': lazy( () => import( './core-custom' ) ),
* 'CoreParagraph': null, // To use html-react-parser.
* };
*
* This may alternatively be better done in the config.
*/

export default function Page() {
return (
<TemplateRenderer>
Expand Down
5 changes: 3 additions & 2 deletions packages/blocks/src/editor-blocks-renderer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from 'react';
import BlockManager from '@/block-manager';
import { getConfig } from '@snapwp/core/config';

import type { BlockData, BlockDefinitions, BlockTreeNode } from '@snapwp/types';

type EditorBlocksRendererProps = {
Expand All @@ -10,14 +12,13 @@ type EditorBlocksRendererProps = {
/**
* A react component to render editor blocks.
* @param props - Props.
* @param props.blockDefinitions - blocks rendering functions.
* @param props.editorBlocks - A list of blocks to be rendered.
* @return The rendered template
*/
export default function EditorBlocksRenderer( {
editorBlocks,
blockDefinitions,
}: EditorBlocksRendererProps ) {
Comment on lines 18 to 20
Copy link
Collaborator

Choose a reason for hiding this comment

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

Pros vs cons about leaving keeping this prop, and then having a hierarchy of props?.blockDefinitions || getConfig()?.blockDefinitions || defaultBlockDefinitions

const { blockDefinitions } = getConfig();
if ( blockDefinitions ) {
Comment on lines +21 to 22
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nitpick, but whitespace is free ;-)

Suggested change
const { blockDefinitions } = getConfig();
if ( blockDefinitions ) {
const { blockDefinitions } = getConfig();
if ( blockDefinitions ) {

BlockManager.addBlockDefinitions( blockDefinitions );
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/config/snapwp-config-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface SnapWPEnv {
/**
* Flag to enable cors middleware which proxies assets from WP server.
*/
useCorsProxy: boolean;
useCorsProxy?: boolean;
}

export interface SnapWPConfig {
Expand Down