From 195802f316bf2e0bb7b220b67c28348605fed01c Mon Sep 17 00:00:00 2001 From: Marc Toensing Date: Wed, 15 Nov 2023 17:09:23 +0100 Subject: [PATCH] linted --- src/accordion.js | 20 ++-- src/edit.js | 282 +++++++++++++++++++++++++---------------------- src/index.js | 4 +- 3 files changed, 161 insertions(+), 145 deletions(-) diff --git a/src/accordion.js b/src/accordion.js index 9099324..8563f25 100644 --- a/src/accordion.js +++ b/src/accordion.js @@ -1,18 +1,18 @@ -const buttons = document.querySelectorAll('button.simpletoc-collapsible'); +const buttons = document.querySelectorAll( 'button.simpletoc-collapsible' ); -buttons.forEach((button) => { - button.addEventListener('click', function () { - this.classList.toggle('active'); +buttons.forEach( ( button ) => { + button.addEventListener( 'click', function () { + this.classList.toggle( 'active' ); const content = this.parentElement.nextElementSibling; content.style.display = content.style.display === 'block' ? 'none' : 'block'; // Toggle aria-expanded attribute on the button - const ariaExpanded = this.getAttribute('aria-expanded'); - if (ariaExpanded === 'true') { - this.setAttribute('aria-expanded', 'false'); + const ariaExpanded = this.getAttribute( 'aria-expanded' ); + if ( ariaExpanded === 'true' ) { + this.setAttribute( 'aria-expanded', 'false' ); } else { - this.setAttribute('aria-expanded', 'true'); + this.setAttribute( 'aria-expanded', 'true' ); } - }); -}); + } ); +} ); diff --git a/src/edit.js b/src/edit.js index f4405f2..cfae3ad 100644 --- a/src/edit.js +++ b/src/edit.js @@ -28,13 +28,13 @@ import { useSelect } from '@wordpress/data'; import './editor.scss'; import './accordion.css'; -export default function Edit({ attributes, setAttributes }) { +export default function Edit( { attributes, setAttributes } ) { const blockProps = useBlockProps(); const { returnisSaving, returnisSavingNonPostEntityChanges } = useSelect( - (select) => { + ( select ) => { const { isSavingPost, isSavingNonPostEntityChanges } = - select(editorStore); + select( editorStore ); return { returnisSaving: isSavingPost(), returnisSavingNonPostEntityChanges: @@ -47,51 +47,51 @@ export default function Edit({ attributes, setAttributes }) { const controls = ( - {!(attributes.no_title || attributes.accordion) && ( + { ! ( attributes.no_title || attributes.accordion ) && ( - setAttributes({ - title_level: Number(level), - }) + selectedLevel={ attributes.title_level } + onChange={ ( level ) => + setAttributes( { + title_level: Number( level ), + } ) } /> - )} + ) } { - setAttributes({ use_ol: false }); - }} + icon={ formatListBullets } + title={ __( 'Convert to unordered list', 'simpletoc' ) } + describedBy={ __( 'Convert to unordered list', 'simpletoc' ) } + isActive={ attributes.use_ol === false } + onClick={ () => { + setAttributes( { use_ol: false } ); + } } /> { - setAttributes({ use_ol: true }); - }} + icon={ formatListNumbered } + title={ __( 'Convert to ordered list', 'simpletoc' ) } + describedBy={ __( 'Convert to ordered list', 'simpletoc' ) } + isActive={ attributes.use_ol === true } + onClick={ () => { + setAttributes( { use_ol: true } ); + } } /> { - setAttributes({ remove_indent: true }); - }} + icon={ formatOutdent } + title={ __( 'Indent list', 'simpletoc' ) } + describedBy={ __( 'Indent list', 'simpletoc' ) } + isActive={ attributes.remove_indent === true } + onClick={ () => { + setAttributes( { remove_indent: true } ); + } } /> { - setAttributes({ remove_indent: false }); - }} + icon={ formatIndent } + title={ __( 'Outdent list', 'simpletoc' ) } + describedBy={ __( 'Outdent list', 'simpletoc' ) } + isActive={ attributes.remove_indent === false } + onClick={ () => { + setAttributes( { remove_indent: false } ); + } } /> ); @@ -100,132 +100,142 @@ export default function Edit({ attributes, setAttributes }) { - {!attributes.no_title && ( + { ! attributes.no_title && ( - setAttributes({ + value={ attributes.title_text } + onChange={ ( value ) => + setAttributes( { title_text: value || __( 'Table of Contents', 'simpletoc' ), - }) + } ) } /> - )} + ) } - setAttributes({ - no_title: !attributes.no_title, - }) + label={ __( 'Remove heading', 'simpletoc' ) } + checked={ attributes.no_title } + onChange={ () => + setAttributes( { + no_title: ! attributes.no_title, + } ) } /> - setAttributes({ - min_level: Number(level), - }) + ] } + onChange={ ( level ) => + setAttributes( { + min_level: Number( level ), + } ) } /> - setAttributes({ - max_level: Number(level), - }) + ] } + onChange={ ( level ) => + setAttributes( { + max_level: Number( level ), + } ) } /> @@ -233,90 +243,96 @@ export default function Edit({ attributes, setAttributes }) {

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

- {__('Donate here!', 'simpletoc')} + { __( 'Donate here!', 'simpletoc' ) }
- setAttributes({ - accordion: !attributes.accordion, - }) + ) } + checked={ attributes.accordion } + onChange={ () => + setAttributes( { + accordion: ! attributes.accordion, + } ) } /> - setAttributes({ - add_smooth: !attributes.add_smooth, - }) + ) } + checked={ attributes.add_smooth } + onChange={ () => + setAttributes( { + add_smooth: ! attributes.add_smooth, + } ) } /> - setAttributes({ + ) } + checked={ attributes.use_absolute_urls } + onChange={ () => + setAttributes( { use_absolute_urls: - !attributes.use_absolute_urls, - }) + ! attributes.use_absolute_urls, + } ) } /> - setAttributes({ - wrapper: !attributes.wrapper, - }) + ) } + checked={ attributes.wrapper } + onChange={ () => + setAttributes( { + wrapper: ! attributes.wrapper, + } ) } /> @@ -326,17 +342,17 @@ export default function Edit({ attributes, setAttributes }) { ); return ( -
- {controls} - {controlssidebar} - {returnisSaving || returnisSavingNonPostEntityChanges ? ( +
+ { controls } + { controlssidebar } + { returnisSaving || returnisSavingNonPostEntityChanges ? ( ) : ( - )} + ) }
); } diff --git a/src/index.js b/src/index.js index 10b2714..c1c2475 100644 --- a/src/index.js +++ b/src/index.js @@ -20,7 +20,7 @@ const simpletocicon = ( import Edit from './edit'; import save from './save'; -registerBlockType(metadata, { +registerBlockType( metadata, { icon: simpletocicon, /** * @see ./edit.js @@ -31,4 +31,4 @@ registerBlockType(metadata, { * @see ./save.js */ save, -}); +} );