/** * WordPress dependencies */ import { cloneBlock } from '@safe-wordpress/blocks'; import { useDispatch, useSelect } from '@safe-wordpress/data'; import { PluginDocumentSettingPanel } from '@safe-wordpress/editor'; import { store as BLOCK_EDITOR } from '@safe-wordpress/block-editor'; import { store as NOTICES } from '@safe-wordpress/notices'; import { _x, sprintf } from '@safe-wordpress/i18n'; import type { BlockInstance } from '@safe-wordpress/blocks'; /** * External dependencies */ import { map } from 'lodash'; import type { PopupPattern } from '@nelio/popups/types'; /** * Internal dependencies */ import BlockPatternList from './block-pattern-list'; import { getPopupPatterns } from './get-popup-patterns'; export const PopupPatterns = (): JSX.Element => { const { createSuccessNotice } = useDispatch( NOTICES ); const { replaceBlocks } = useDispatch( BLOCK_EDITOR ); const clientIds = useSelect( ( select ) => map( select( BLOCK_EDITOR ).getBlocks(), ( block ) => block.clientId ) ); const onClickPattern = ( pattern: PopupPattern, blocks: ReadonlyArray< BlockInstance > ) => { void replaceBlocks( clientIds, map( blocks, ( block ) => cloneBlock( block ) ) ); void createSuccessNotice( sprintf( /* translators: %s: block pattern title. */ _x( 'Popup pattern "%s" inserted.', 'text', 'nelio-popups' ), pattern.title ), { type: 'snackbar' } ); }; return ( ); };