UNPKG

@wordpress/block-library

Version:
142 lines (141 loc) • 6.12 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); // \0rolldown/runtime.js var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) { key = keys[i]; if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: ((k) => from[k]).bind(null, key), enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod)); let _wordpress_components = require("@wordpress/components"); let _wordpress_i18n = require("@wordpress/i18n"); let _wordpress_block_editor = require("@wordpress/block-editor"); let _wordpress_server_side_render = require("@wordpress/server-side-render"); let _wordpress_compose = require("@wordpress/compose"); let _wordpress_ui = require("@wordpress/ui"); let ___utils_hooks_js = require("../utils/hooks.cjs"); let ___utils_html_renderer_jsx = require("../utils/html-renderer.cjs"); ___utils_html_renderer_jsx = __toESM(___utils_html_renderer_jsx); let react_jsx_runtime = require("react/jsx-runtime"); // packages/block-library/src/archives/edit.jsx const ARCHIVE_TYPE_ITEMS = [ { label: (0, _wordpress_i18n.__)("Year"), value: "yearly" }, { label: (0, _wordpress_i18n.__)("Month"), value: "monthly" }, { label: (0, _wordpress_i18n.__)("Week"), value: "weekly" }, { label: (0, _wordpress_i18n.__)("Day"), value: "daily" } ]; function ArchivesEdit({ attributes, setAttributes, name }) { const { showLabel, showPostCounts, displayAsDropdown, type } = attributes; const dropdownMenuProps = (0, ___utils_hooks_js.useToolsPanelDropdownMenuProps)(); const { content, status, error } = (0, _wordpress_server_side_render.useServerSideRender)({ attributes, skipBlockSupportAttributes: true, block: name }); const disabledRef = (0, _wordpress_compose.useDisabled)(); const blockProps = (0, _wordpress_block_editor.useBlockProps)({ ref: disabledRef }); 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.jsxs)(_wordpress_components.__experimentalToolsPanel, { label: (0, _wordpress_i18n.__)("Settings"), resetAll: () => { setAttributes({ displayAsDropdown: false, showLabel: true, showPostCounts: false, type: "monthly" }); }, dropdownMenuProps, children: [ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, { label: (0, _wordpress_i18n.__)("Display as dropdown"), isShownByDefault: true, hasValue: () => displayAsDropdown, onDeselect: () => setAttributes({ displayAsDropdown: false }), children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToggleControl, { label: (0, _wordpress_i18n.__)("Display as dropdown"), checked: displayAsDropdown, onChange: () => setAttributes({ displayAsDropdown: !displayAsDropdown }) }) }), displayAsDropdown && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, { label: (0, _wordpress_i18n.__)("Show label"), isShownByDefault: true, hasValue: () => !showLabel, onDeselect: () => setAttributes({ showLabel: true }), children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToggleControl, { label: (0, _wordpress_i18n.__)("Show label"), checked: showLabel, onChange: () => setAttributes({ showLabel: !showLabel }) }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, { label: (0, _wordpress_i18n.__)("Show post counts"), isShownByDefault: true, hasValue: () => showPostCounts, onDeselect: () => setAttributes({ showPostCounts: false }), children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToggleControl, { label: (0, _wordpress_i18n.__)("Show post counts"), checked: showPostCounts, onChange: () => setAttributes({ showPostCounts: !showPostCounts }) }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, { label: (0, _wordpress_i18n.__)("Group by"), isShownByDefault: true, hasValue: () => type !== "monthly", onDeselect: () => setAttributes({ type: "monthly" }), children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.SelectControl, { label: (0, _wordpress_i18n.__)("Group by"), items: ARCHIVE_TYPE_ITEMS, value: ARCHIVE_TYPE_ITEMS.find((item) => item.value === type) ?? ARCHIVE_TYPE_ITEMS[0], onValueChange: (item) => item && setAttributes({ type: item.value }) }) }) ] }) }), status === "loading" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { ...blockProps, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Spinner, {}) }), status === "error" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { ...blockProps, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("Error: %s"), error) }) }), status === "success" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(___utils_html_renderer_jsx.default, { wrapperProps: blockProps, html: content }) ] }); } exports.default = ArchivesEdit; //# sourceMappingURL=edit.cjs.map