@wordpress/block-library
Version:
Block library for the WordPress editor.
73 lines (72 loc) • 2.98 kB
JavaScript
import { __ } from "@wordpress/i18n";
import { InspectorControls, store, useBlockProps, useInnerBlocksProps } from "@wordpress/block-editor";
import { useDispatch, useSelect } from "@wordpress/data";
import { __experimentalToolsPanel, __experimentalToolsPanelItem } from "@wordpress/components";
import { useEffect } from "@wordpress/element";
import { QueryPaginationArrowControls } from "./query-pagination-arrow-controls.mjs";
import { QueryPaginationLabelControl } from "./query-pagination-label-control.mjs";
import { useToolsPanelDropdownMenuProps } from "../utils/hooks.mjs";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
// packages/block-library/src/query-pagination/edit.jsx
function QueryPaginationEdit({ attributes: { paginationArrow, showLabel }, setAttributes, clientId }) {
const hasNextPreviousBlocks = useSelect((select) => {
const { getBlocks } = select(store);
/**
* Show the `paginationArrow` and `showLabel` controls only if a
* `QueryPaginationNext/Previous` block exists.
*/
return getBlocks(clientId)?.find((innerBlock) => {
return ["core/query-pagination-next", "core/query-pagination-previous"].includes(innerBlock.name);
});
}, [clientId]);
const { __unstableMarkNextChangeAsNotPersistent } = useDispatch(store);
const dropdownMenuProps = useToolsPanelDropdownMenuProps();
const blockProps = useBlockProps();
const innerBlocksProps = useInnerBlocksProps(blockProps);
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(__experimentalToolsPanel, {
label: __("Settings"),
resetAll: () => {
setAttributes({
paginationArrow: "none",
showLabel: true
});
},
dropdownMenuProps,
children: [/* @__PURE__ */ jsx(__experimentalToolsPanelItem, {
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(__experimentalToolsPanelItem, {
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.mjs.map