import { __ } from "@wordpress/i18n"; import "./editor.scss"; import "./timeline-step"; import { useBlockProps, RichText, InnerBlocks, InspectorControls, MediaReplaceFlow, MediaPlaceholder, BlockControls, } from "@wordpress/block-editor"; import { useEffect } from "@wordpress/element"; import { useSelect, dispatch } from "@wordpress/data"; import { PanelBody, PanelRow, Button, RadioControl, ToggleControl, ToolbarGroup, ToolbarButton, __experimentalToggleGroupControl as ToggleGroupControl, __experimentalToggleGroupControlOption as ToggleGroupControlOption, } from "@wordpress/components"; import { trash } from "@wordpress/icons"; import { headingLevel1, headingLevel2, headingLevel3, headingLevel4, headingLevel5, } from "@wordpress/icons"; export default function Edit({ attributes, setAttributes, clientId }) { let { hasStepPictures, lateralPicturesFormat, hasStepIcons, hasLateralCover, lateralCoverId, lateralCoverAlt, lateralCoverUrl, lateralCoverDescription, lateralCoverCaption, blockTitle, blockSubtitle, hasTitle, headingLevel, } = attributes; let children = useSelect( (select) => select("core/block-editor").getBlocksByClientId(clientId)[0].innerBlocks, ); function onChangeBlockTitle(blockTitle) { setAttributes({ blockTitle }); } function onChangeBlockSubtitle(blockSubtitle) { setAttributes({ blockSubtitle }); } function onChangeHeadingLevel(newHeadingLevel) { setAttributes({ headingLevel: newHeadingLevel }); } function onChangeImagesDispositionType(disposition) { if (disposition === "hasStepPictures") { setAttributes({ hasStepPictures: true, hasLateralCover: false }); removeLateralCoverAttributes(); } if (disposition === "hasLateralCover") { setAttributes({ hasStepPictures: false, hasLateralCover: true }); } } function handlelateralPicturesFormatChange(lateralPicturesFormat) { setAttributes({ lateralPicturesFormat }); } function onChangehasStepIcons() { setAttributes({ hasStepIcons: !hasStepIcons }); } function onChangeHasTitle(newHasTitle) { setAttributes({ hasTitle: !hasTitle }); if (!newHasTitle) { setAttributes({ blockTitle: "", blockSubtitle: "" }); } } function setLateralCoverAttributes(cover) { console.log(cover); setAttributes({ lateralCoverId: cover.id, lateralCoverAlt: cover.alt, lateralCoverUrl: cover.url, lateralCoverCaption: cover?.caption, lateralCoverDescription: cover?.description, }); } function removeLateralCoverAttributes() { setAttributes({ lateralCoverId: null, lateralCoverAlt: null, lateralCoverUrl: null, lateralCoverCaption: null, lateralCoverDescription: null, }); } function updateChildrensProps(children) { children.forEach((child) => { dispatch("core/block-editor").updateBlockAttributes(child.clientId, { hasStepIcon: hasStepIcons, hasStepPicture: hasStepPictures, }); }); } useEffect(() => { if (children && children.length > 0) { updateChildrensProps(children); } }, [children, hasStepPictures, hasStepIcons]); const TEMPLATE = [ [ "homegrade-content-blocks/timeline-step", { timelineStepTitle: "Etape 1", timelineStepSubtitle: "sous titre", }, ], [ "homegrade-content-blocks/timeline-step", { timelineStepTitle: "Etape 2", timelineStepSubtitle: "sous titre", }, ], ]; return ( <> {lateralCoverUrl && ( )} {hasLateralCover && ( {lateralCoverUrl && ( <> > )} )} { onChangeHeadingLevel("h1"); }} /> { onChangeHeadingLevel("h2"); }} /> { onChangeHeadingLevel("h3"); }} /> { onChangeHeadingLevel("h4"); }} /> { onChangeHeadingLevel("h5"); }} /> {hasTitle && ( <> > )} {hasLateralCover && !lateralCoverUrl && ( )} {hasLateralCover && lateralCoverUrl && ( {(lateralCoverDescription || lateralCoverCaption) && ( {lateralCoverDescription && ( {lateralCoverDescription} )} {lateralCoverCaption && ( {lateralCoverCaption} )} )} )} > ); }
{lateralCoverDescription}
{lateralCoverCaption}