import { __ } from '@wordpress/i18n'; import { InspectorControls, BlockControls, useBlockProps, } from '@wordpress/block-editor'; import ServerSideRender from '@wordpress/server-side-render'; import { formatListBullets, formatOutdent, formatIndent, formatListNumbered, } from '@wordpress/icons'; import { SelectControl, ToolbarButton, ToggleControl, TextControl, Panel, PanelBody, PanelRow, ExternalLink, } from '@wordpress/components'; import { select, subscribe } from '@wordpress/data'; import { useEffect, useState } from 'react'; export default function Edit( { attributes, setAttributes } ) { const blockProps = useBlockProps(); /* Update SimpleTOC if the post is saved successfully. */ /* Source: https://github.com/WordPress/gutenberg/issues/17632 */ const { isSavingPost } = select( 'core/editor' ); const [ isSavingProcess, setSavingProcess ] = useState( false ); const advpanelicon = 'settings'; const updatePost = function () { if ( attributes.autorefresh === true ) { /* refresh block with changed attribute */ /* There is no better way at the moment https://github.com/WordPress/gutenberg/issues/44469 */ setAttributes( { updated: new Date().getTime() } ); } }; const controls = ( { setAttributes( { use_ol: false } ); } } /> { setAttributes( { use_ol: true } ); } } /> { setAttributes( { remove_indent: true } ); } } /> { setAttributes( { remove_indent: false } ); } } /> ); const controlssidebar = ( { ! attributes.no_title && ( setAttributes( { title_text: value || __( 'Table of Contents', 'simpletoc' ), } ) } /> ) } setAttributes( { no_title: ! attributes.no_title, } ) } /> setAttributes( { min_level: Number( level ), } ) } /> setAttributes( { max_level: Number( level ), } ) } />

{ __( 'Think about making a donation if you use any of these features.', 'simpletoc' ) }

{ __( 'Donate here!', 'simpletoc' ) }
setAttributes( { add_smooth: ! attributes.add_smooth, } ) } /> setAttributes( { use_absolute_urls: ! attributes.use_absolute_urls, } ) } /> setAttributes( { autorefresh: ! attributes.autorefresh, } ) } />
); subscribe( () => { if ( isSavingPost() ) { setSavingProcess( true ); } else { setSavingProcess( false ); } } ); useEffect( () => { if ( isSavingProcess ) { updatePost(); } }, [ isSavingProcess ] ); return (
{ controls } { controlssidebar }
); }