import { __ } from "@wordpress/i18n"; import "./editor.scss"; import { createBlock } from "@wordpress/blocks"; import { dispatch, useSelect } from "@wordpress/data"; import { useBlockProps, RichText, InspectorControls, BlockControls, } from "@wordpress/block-editor"; import { ToggleControl, PanelBody, KeyboardShortcuts, ToolbarGroup, ToolbarButton, } from "@wordpress/components"; import { headingLevel3, headingLevel4, headingLevel5 } from "@wordpress/icons"; export default function Edit({ attributes, setAttributes, clientId, ...blockProps }) { const { title, headingLevel, hasIcon, iconName } = attributes; const blockIndex = useSelect((select) => { const { getBlockIndex } = select("core/block-editor"); return getBlockIndex(clientId); }); function onChangeTitle(newTitle) { setAttributes({ title: newTitle }); } function onChangeHeadingLevel(newHeadingLevel) { setAttributes({ headingLevel: newHeadingLevel }); } function handleIconChange(newIconName) { setAttributes({ iconName: newIconName }); } function onHasIconChange(hasIconToggleValue) { setAttributes({ hasIcon: hasIconToggleValue, }); } function insertParagraphOnEnter(e) { const newBlock = createBlock("core/paragraph", {}); dispatch("core/block-editor").insertBlocks(newBlock, blockIndex + 1); } return ( <> { onChangeHeadingLevel("h3"); }} /> { onChangeHeadingLevel("h4"); }} /> { onChangeHeadingLevel("h5"); }} /> {hasIcon && ( handleIconChange("key")} /> handleIconChange("chain")} /> handleIconChange("house")} /> handleIconChange("bulb")} /> )} insertParagraphOnEnter(e), }} > ); }