@wordpress/block-library
Version:
Block library for the WordPress editor.
78 lines (77 loc) • 3.66 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
let _wordpress_i18n = require("@wordpress/i18n");
let _wordpress_block_editor = require("@wordpress/block-editor");
let _wordpress_data = require("@wordpress/data");
let _wordpress_components = require("@wordpress/components");
let _wordpress_element = require("@wordpress/element");
let __query_pagination_arrow_controls_jsx = require("./query-pagination-arrow-controls.cjs");
let __query_pagination_label_control_jsx = require("./query-pagination-label-control.cjs");
let ___utils_hooks_js = require("../utils/hooks.cjs");
let react_jsx_runtime = require("react/jsx-runtime");
// packages/block-library/src/query-pagination/edit.jsx
function QueryPaginationEdit({ attributes: { paginationArrow, showLabel }, setAttributes, clientId }) {
const hasNextPreviousBlocks = (0, _wordpress_data.useSelect)((select) => {
const { getBlocks } = select(_wordpress_block_editor.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 } = (0, _wordpress_data.useDispatch)(_wordpress_block_editor.store);
const dropdownMenuProps = (0, ___utils_hooks_js.useToolsPanelDropdownMenuProps)();
const blockProps = (0, _wordpress_block_editor.useBlockProps)();
const innerBlocksProps = (0, _wordpress_block_editor.useInnerBlocksProps)(blockProps);
(0, _wordpress_element.useEffect)(() => {
if (paginationArrow === "none" && !showLabel) {
__unstableMarkNextChangeAsNotPersistent();
setAttributes({ showLabel: true });
}
}, [
paginationArrow,
setAttributes,
showLabel,
__unstableMarkNextChangeAsNotPersistent
]);
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [hasNextPreviousBlocks && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.InspectorControls, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_components.__experimentalToolsPanel, {
label: (0, _wordpress_i18n.__)("Settings"),
resetAll: () => {
setAttributes({
paginationArrow: "none",
showLabel: true
});
},
dropdownMenuProps,
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, {
hasValue: () => paginationArrow !== "none",
label: (0, _wordpress_i18n.__)("Pagination arrow"),
onDeselect: () => setAttributes({ paginationArrow: "none" }),
isShownByDefault: true,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__query_pagination_arrow_controls_jsx.QueryPaginationArrowControls, {
value: paginationArrow,
onChange: (value) => {
setAttributes({ paginationArrow: value });
}
})
}), paginationArrow !== "none" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, {
hasValue: () => !showLabel,
label: (0, _wordpress_i18n.__)("Show text"),
onDeselect: () => setAttributes({ showLabel: true }),
isShownByDefault: true,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__query_pagination_label_control_jsx.QueryPaginationLabelControl, {
value: showLabel,
onChange: (value) => {
setAttributes({ showLabel: value });
}
})
})]
}) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("nav", { ...innerBlocksProps })] });
}
exports.default = QueryPaginationEdit;
//# sourceMappingURL=edit.cjs.map