UNPKG

@wordpress/block-library

Version:
66 lines (61 loc) 2.4 kB
import { createElement, Fragment } from "@wordpress/element"; /** * WordPress dependencies */ import { __ } from '@wordpress/i18n'; import { InspectorControls, useBlockProps, useInnerBlocksProps, store as blockEditorStore } from '@wordpress/block-editor'; import { useSelect } from '@wordpress/data'; import { getBlockSupport } from '@wordpress/blocks'; import { PanelBody } from '@wordpress/components'; /** * Internal dependencies */ import { QueryPaginationArrowControls } from './query-pagination-arrow-controls'; const TEMPLATE = [['core/query-pagination-previous'], ['core/query-pagination-numbers'], ['core/query-pagination-next']]; const ALLOWED_BLOCKS = ['core/query-pagination-previous', 'core/query-pagination-numbers', 'core/query-pagination-next']; const getDefaultBlockLayout = blockTypeOrName => { const layoutBlockSupportConfig = getBlockSupport(blockTypeOrName, '__experimentalLayout'); return layoutBlockSupportConfig === null || layoutBlockSupportConfig === void 0 ? void 0 : layoutBlockSupportConfig.default; }; export default function QueryPaginationEdit(_ref) { let { attributes: { paginationArrow, layout }, setAttributes, clientId, name } = _ref; const usedLayout = layout || getDefaultBlockLayout(name); const hasNextPreviousBlocks = useSelect(select => { const { getBlocks } = select(blockEditorStore); const innerBlocks = getBlocks(clientId); /** * Show the `paginationArrow` control only if a * `QueryPaginationNext/Previous` block exists. */ return innerBlocks === null || innerBlocks === void 0 ? void 0 : innerBlocks.find(innerBlock => { return ['core/query-pagination-next', 'core/query-pagination-previous'].includes(innerBlock.name); }); }, []); const blockProps = useBlockProps(); const innerBlocksProps = useInnerBlocksProps(blockProps, { template: TEMPLATE, allowedBlocks: ALLOWED_BLOCKS, __experimentalLayout: usedLayout }); return createElement(Fragment, null, hasNextPreviousBlocks && createElement(InspectorControls, null, createElement(PanelBody, { title: __('Settings') }, createElement(QueryPaginationArrowControls, { value: paginationArrow, onChange: value => { setAttributes({ paginationArrow: value }); } }))), createElement("nav", innerBlocksProps)); } //# sourceMappingURL=edit.js.map