UNPKG

@wordpress/block-library

Version:
49 lines (48 loc) • 2.15 kB
import { BlockControls, BlockIcon, store, useBlockProps } from "@wordpress/block-editor"; import { useSelect } from "@wordpress/data"; import { Button, Placeholder, ToolbarButton, ToolbarGroup } from "@wordpress/components"; import { RawHTML, useRef, useState } from "@wordpress/element"; import { __ } from "@wordpress/i18n"; import { classic } from "@wordpress/icons"; import ConvertToBlocksButton from "./convert-to-blocks-button.mjs"; import ModalEdit from "./modal.mjs"; import { Fragment, jsx, jsxs } from "react/jsx-runtime"; // packages/block-library/src/freeform/edit.jsx function FreeformEdit({ attributes, setAttributes, clientId }) { const { content } = attributes; const [isOpen, setOpen] = useState(false); const editButtonRef = useRef(null); const canRemove = useSelect((select) => select(store).canRemoveBlock(clientId), [clientId]); return /* @__PURE__ */ jsxs(Fragment, { children: [ canRemove && /* @__PURE__ */ jsx(BlockControls, { children: /* @__PURE__ */ jsx(ToolbarGroup, { children: /* @__PURE__ */ jsx(ConvertToBlocksButton, { clientId }) }) }), /* @__PURE__ */ jsx(BlockControls, { children: /* @__PURE__ */ jsx(ToolbarGroup, { children: /* @__PURE__ */ jsx(ToolbarButton, { ref: editButtonRef, onClick: () => setOpen(true), children: __("Edit") }) }) }), /* @__PURE__ */ jsxs("div", { ...useBlockProps(), children: [content ? /* @__PURE__ */ jsx(RawHTML, { children: content }) : /* @__PURE__ */ jsx(Placeholder, { icon: /* @__PURE__ */ jsx(BlockIcon, { icon: classic }), label: __("Classic"), instructions: __("Use the classic editor to add content."), children: /* @__PURE__ */ jsx(Button, { __next40pxDefaultSize: true, variant: "primary", onClick: () => setOpen(true), children: __("Edit contents") }) }), isOpen && /* @__PURE__ */ jsx(ModalEdit, { clientId, content, onClose: () => { setOpen(false); if (editButtonRef.current) editButtonRef.current.focus(); }, onChange: (newContent) => setAttributes({ content: newContent }) })] }) ] }); } export { FreeformEdit as default }; //# sourceMappingURL=edit.mjs.map