2023-08-28 01:28:05 +00:00
|
|
|
// Reference: https://github.com/WordPress/gutenberg/blob/release/16.4/packages/block-editor/src/components/block-preview/index.js
|
|
|
|
|
|
|
|
/* eslint-disable @woocommerce/dependency-group */
|
|
|
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
// @ts-ignore No types for this exist yet.
|
|
|
|
import { BlockEditorProvider } from '@wordpress/block-editor';
|
|
|
|
import { memo, useMemo } from '@wordpress/element';
|
|
|
|
import { BlockInstance } from '@wordpress/blocks';
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import {
|
|
|
|
AutoHeightBlockPreview,
|
|
|
|
ScaledBlockPreviewProps,
|
|
|
|
} from './auto-block-preview';
|
|
|
|
|
|
|
|
export const BlockPreview = ( {
|
|
|
|
blocks,
|
|
|
|
settings,
|
2023-09-05 06:21:19 +00:00
|
|
|
useSubRegistry = true,
|
2023-08-28 01:28:05 +00:00
|
|
|
...props
|
|
|
|
}: {
|
|
|
|
blocks: BlockInstance | BlockInstance[];
|
|
|
|
settings: Record< string, unknown >;
|
2023-09-05 06:21:19 +00:00
|
|
|
useSubRegistry?: boolean;
|
2023-08-28 01:28:05 +00:00
|
|
|
} & Omit< ScaledBlockPreviewProps, 'containerWidth' > ) => {
|
|
|
|
const renderedBlocks = useMemo(
|
|
|
|
() => ( Array.isArray( blocks ) ? blocks : [ blocks ] ),
|
|
|
|
[ blocks ]
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
2023-09-05 06:21:19 +00:00
|
|
|
<BlockEditorProvider
|
|
|
|
value={ renderedBlocks }
|
|
|
|
settings={ settings }
|
|
|
|
useSubRegistry={ useSubRegistry }
|
|
|
|
>
|
2023-08-28 01:28:05 +00:00
|
|
|
<AutoHeightBlockPreview settings={ settings } { ...props } />
|
|
|
|
</BlockEditorProvider>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default memo( BlockPreview );
|