UNPKG

@wordpress/block-library

Version:
117 lines (116 loc) 3.68 kB
import { Fragment, jsx, jsxs } from "react/jsx-runtime"; import { __ } from "@wordpress/i18n"; import { InspectorControls, useBlockProps, useInnerBlocksProps, store as blockEditorStore } from "@wordpress/block-editor"; import { useDispatch, useSelect } from "@wordpress/data"; import { __experimentalToolsPanel as ToolsPanel, __experimentalToolsPanelItem as ToolsPanelItem } from "@wordpress/components"; import { useEffect } from "@wordpress/element"; import { QueryPaginationArrowControls } from "./query-pagination-arrow-controls"; import { QueryPaginationLabelControl } from "./query-pagination-label-control"; import { useToolsPanelDropdownMenuProps } from "../utils/hooks"; const TEMPLATE = [ ["core/query-pagination-previous"], ["core/query-pagination-numbers"], ["core/query-pagination-next"] ]; function QueryPaginationEdit({ attributes: { paginationArrow, showLabel }, setAttributes, clientId }) { const hasNextPreviousBlocks = useSelect( (select) => { const { getBlocks } = select(blockEditorStore); const innerBlocks = getBlocks(clientId); return innerBlocks?.find((innerBlock) => { return [ "core/query-pagination-next", "core/query-pagination-previous" ].includes(innerBlock.name); }); }, [clientId] ); const { __unstableMarkNextChangeAsNotPersistent } = useDispatch(blockEditorStore); const dropdownMenuProps = useToolsPanelDropdownMenuProps(); const blockProps = useBlockProps(); const innerBlocksProps = useInnerBlocksProps(blockProps, { template: TEMPLATE }); useEffect(() => { if (paginationArrow === "none" && !showLabel) { __unstableMarkNextChangeAsNotPersistent(); setAttributes({ showLabel: true }); } }, [ paginationArrow, setAttributes, showLabel, __unstableMarkNextChangeAsNotPersistent ]); return /* @__PURE__ */ jsxs(Fragment, { children: [ hasNextPreviousBlocks && /* @__PURE__ */ jsx(InspectorControls, { children: /* @__PURE__ */ jsxs( ToolsPanel, { label: __("Settings"), resetAll: () => { setAttributes({ paginationArrow: "none", showLabel: true }); }, dropdownMenuProps, children: [ /* @__PURE__ */ jsx( ToolsPanelItem, { hasValue: () => paginationArrow !== "none", label: __("Pagination arrow"), onDeselect: () => setAttributes({ paginationArrow: "none" }), isShownByDefault: true, children: /* @__PURE__ */ jsx( QueryPaginationArrowControls, { value: paginationArrow, onChange: (value) => { setAttributes({ paginationArrow: value }); } } ) } ), paginationArrow !== "none" && /* @__PURE__ */ jsx( ToolsPanelItem, { hasValue: () => !showLabel, label: __("Show text"), onDeselect: () => setAttributes({ showLabel: true }), isShownByDefault: true, children: /* @__PURE__ */ jsx( QueryPaginationLabelControl, { value: showLabel, onChange: (value) => { setAttributes({ showLabel: value }); } } ) } ) ] } ) }), /* @__PURE__ */ jsx("nav", { ...innerBlocksProps }) ] }); } export { QueryPaginationEdit as default }; //# sourceMappingURL=edit.js.map