UNPKG

@wordpress/block-library

Version:
57 lines (56 loc) • 2.91 kB
"use strict"; 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_components = require("@wordpress/components"); let ___utils_hooks_js = require("../utils/hooks.cjs"); let react_jsx_runtime = require("react/jsx-runtime"); // packages/block-library/src/query-pagination-numbers/edit.jsx const createPaginationItem = (content, Tag = "a", extraClass = "") => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Tag, { className: `page-numbers ${extraClass}`, children: content }, content); const previewPaginationNumbers = (midSize) => { const paginationItems = []; for (let i = 1; i <= midSize; i++) paginationItems.push(createPaginationItem(i)); paginationItems.push(createPaginationItem(midSize + 1, "span", "current")); for (let i = 1; i <= midSize; i++) paginationItems.push(createPaginationItem(midSize + 1 + i)); paginationItems.push(createPaginationItem("...", "span", "dots")); paginationItems.push(createPaginationItem(midSize * 2 + 3)); return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: paginationItems }); }; function QueryPaginationNumbersEdit({ attributes, setAttributes }) { const { midSize } = attributes; const paginationNumbers = previewPaginationNumbers(parseInt(midSize, 10)); const dropdownMenuProps = (0, ___utils_hooks_js.useToolsPanelDropdownMenuProps)(); return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.InspectorControls, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanel, { label: (0, _wordpress_i18n.__)("Settings"), resetAll: () => setAttributes({ midSize: 2 }), dropdownMenuProps, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, { label: (0, _wordpress_i18n.__)("Number of links"), hasValue: () => midSize !== 2, onDeselect: () => setAttributes({ midSize: 2 }), isShownByDefault: true, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.RangeControl, { label: (0, _wordpress_i18n.__)("Number of links"), help: (0, _wordpress_i18n.__)("Specify how many links can appear before and after the current page number. Links to the first, current and last page are always visible."), value: midSize, onChange: (value) => { setAttributes({ midSize: parseInt(value, 10) }); }, min: 0, max: 5, withInputField: false }) }) }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { ...(0, _wordpress_block_editor.useBlockProps)(), children: paginationNumbers })] }); } exports.default = QueryPaginationNumbersEdit; //# sourceMappingURL=edit.cjs.map