UNPKG

@wordpress/block-library

Version:
86 lines (85 loc) • 4.01 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); let _wordpress_block_editor = require("@wordpress/block-editor"); let _wordpress_components = require("@wordpress/components"); let _wordpress_i18n = require("@wordpress/i18n"); let _wordpress_element = require("@wordpress/element"); let _wordpress_data = require("@wordpress/data"); let _wordpress_keycodes = require("@wordpress/keycodes"); let ___utils_hooks_js = require("../utils/hooks.cjs"); let react_jsx_runtime = require("react/jsx-runtime"); // packages/block-library/src/details/edit.jsx function DetailsEdit({ attributes, setAttributes, clientId }) { const { name, showContent, summary, allowedBlocks, placeholder } = attributes; const blockProps = (0, _wordpress_block_editor.useBlockProps)(); const innerBlocksProps = (0, _wordpress_block_editor.useInnerBlocksProps)(blockProps, { __experimentalCaptureToolbars: true, allowedBlocks }); const [isOpen, setIsOpen] = (0, _wordpress_element.useState)(showContent); const dropdownMenuProps = (0, ___utils_hooks_js.useToolsPanelDropdownMenuProps)(); const hasSelectedInnerBlock = (0, _wordpress_data.useSelect)((select) => select(_wordpress_block_editor.store).hasSelectedInnerBlock(clientId, true), [clientId]); const handleSummaryKeyDown = (event) => { if (event.key === "Enter" && !event.shiftKey) { setIsOpen((prevIsOpen) => !prevIsOpen); event.preventDefault(); } }; const handleSummaryKeyUp = (event) => { if (event.key === " ") event.preventDefault(); }; 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({ showContent: false }); }, dropdownMenuProps, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, { isShownByDefault: true, label: (0, _wordpress_i18n.__)("Open by default"), hasValue: () => showContent, onDeselect: () => { setAttributes({ showContent: false }); }, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToggleControl, { label: (0, _wordpress_i18n.__)("Open by default"), checked: showContent, onChange: () => setAttributes({ showContent: !showContent }) }) }) }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.InspectorControls, { group: "advanced", children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.TextControl, { label: (0, _wordpress_i18n.__)("Name attribute"), value: name || "", onChange: (newName) => setAttributes({ name: newName }), help: (0, _wordpress_i18n.__)("Enables multiple Details blocks with the same name attribute to be connected, with only one open at a time.") }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("details", { ...innerBlocksProps, open: isOpen || hasSelectedInnerBlock, onToggle: (event) => setIsOpen(event.target.open), name: name || "", children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("summary", { onKeyDown: (0, _wordpress_keycodes.withIgnoreIMEEvents)(handleSummaryKeyDown), onKeyUp: handleSummaryKeyUp, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.RichText, { identifier: "summary", "aria-label": (0, _wordpress_i18n.__)("Write summary. Press Enter to expand or collapse the details."), placeholder: placeholder || (0, _wordpress_i18n.__)("Write summary…"), withoutInteractiveFormatting: true, value: summary, onChange: (newSummary) => setAttributes({ summary: newSummary }) }) }), innerBlocksProps.children] }) ] }); } exports.default = DetailsEdit; //# sourceMappingURL=edit.cjs.map