@wordpress/block-library
Version:
Block library for the WordPress editor.
87 lines (86 loc) • 2.88 kB
JavaScript
// packages/block-library/src/comments-pagination/edit.js
import { __ } from "@wordpress/i18n";
import {
InspectorControls,
useBlockProps,
useInnerBlocksProps,
store as blockEditorStore,
Warning
} from "@wordpress/block-editor";
import { useSelect } from "@wordpress/data";
import {
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem
} from "@wordpress/components";
import { CommentsPaginationArrowControls } from "./comments-pagination-arrow-controls";
import { useToolsPanelDropdownMenuProps } from "../utils/hooks";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
var TEMPLATE = [
["core/comments-pagination-previous"],
["core/comments-pagination-numbers"],
["core/comments-pagination-next"]
];
function QueryPaginationEdit({
attributes: { paginationArrow },
setAttributes,
clientId
}) {
const hasNextPreviousBlocks = useSelect((select) => {
const { getBlocks } = select(blockEditorStore);
const innerBlocks = getBlocks(clientId);
return innerBlocks?.find((innerBlock) => {
return [
"core/comments-pagination-previous",
"core/comments-pagination-next"
].includes(innerBlock.name);
});
}, []);
const blockProps = useBlockProps();
const dropdownMenuProps = useToolsPanelDropdownMenuProps();
const innerBlocksProps = useInnerBlocksProps(blockProps, {
template: TEMPLATE
});
const pageComments = useSelect((select) => {
const { getSettings } = select(blockEditorStore);
const { __experimentalDiscussionSettings } = getSettings();
return __experimentalDiscussionSettings?.pageComments;
}, []);
if (!pageComments) {
return /* @__PURE__ */ jsx(Warning, { children: __(
"Comments Pagination block: paging comments is disabled in the Discussion Settings"
) });
}
return /* @__PURE__ */ jsxs(Fragment, { children: [
hasNextPreviousBlocks && /* @__PURE__ */ jsx(InspectorControls, { children: /* @__PURE__ */ jsx(
ToolsPanel,
{
label: __("Settings"),
dropdownMenuProps,
resetAll: () => setAttributes({ paginationArrow: "none" }),
children: /* @__PURE__ */ jsx(
ToolsPanelItem,
{
label: __("Arrow"),
hasValue: () => paginationArrow !== "none",
onDeselect: () => setAttributes({ paginationArrow: "none" }),
isShownByDefault: true,
children: /* @__PURE__ */ jsx(
CommentsPaginationArrowControls,
{
value: paginationArrow,
onChange: (value) => {
setAttributes({ paginationArrow: value });
}
}
)
}
)
}
) }),
/* @__PURE__ */ jsx("div", { ...innerBlocksProps })
] });
}
export {
QueryPaginationEdit as default
};
//# sourceMappingURL=edit.js.map