From 45ff8ba411a9cfd87aa216aa3adbbff6959b5475 Mon Sep 17 00:00:00 2001 From: ray Date: Fri, 22 Jul 2022 15:19:36 +0100 Subject: [PATCH] tidy up settings, add view control --- src/block.json | 6 +++++- src/edit.js | 55 +++++++++++++++++++++++++++++++++++++++----------- src/save.js | 3 +-- 3 files changed, 49 insertions(+), 15 deletions(-) diff --git a/src/block.json b/src/block.json index b23a5c0..dc8245f 100644 --- a/src/block.json +++ b/src/block.json @@ -14,5 +14,9 @@ "editorScript": "file:./index.js", "editorStyle": "file:./index.css", "style": "file:./style-index.css", - "attributes": {} + "attributes": { + "count": { + "type": "number" + } + } } diff --git a/src/edit.js b/src/edit.js index 1fb4926..3f17258 100644 --- a/src/edit.js +++ b/src/edit.js @@ -6,23 +6,29 @@ import { InnerBlocks, InspectorControls, } from "@wordpress/block-editor"; -import { __experimentalNumberControl as NumberControl } from "@wordpress/components"; +import { __experimentalNumberControl as NumberControl, ToggleControl, Panel, PanelBody, PanelRow } from "@wordpress/components"; import { getSaveElement, createBlock } from "@wordpress/blocks"; import "./editor.scss"; import Orbiter from "./orbiter.js"; -export default function Edit({ clientId }) { +export default function Edit({ attributes, setAttributes, clientId }) { const { innerBlocks } = useSelect((select) => select("core/block-editor").getBlock(clientId) ); + if (isNaN(parseInt(attributes.count, 10))) { + setAttributes({count: innerBlocks.length}); + } + const [removedBlocks, setRemovedBlocks] = useState([]); + const [isAnimating, setIsAnimating] = useState(false); + + const animatingClass = ' clockwise'; const addBlock = () => { const index = innerBlocks.length - 1; - console.log(index); let block; if (removedBlocks.length > 0) { @@ -33,6 +39,7 @@ export default function Edit({ clientId }) { } dispatch("core/block-editor").insertBlock(block, index, clientId, false); + setAttributes({count: parseInt(attributes.count, 10) + 1}); }; const removeBlock = () => { @@ -44,6 +51,8 @@ export default function Edit({ clientId }) { const removedBlocksUpdate = removedBlocks; removedBlocksUpdate.push(block); setRemovedBlocks(removedBlocksUpdate); + + setAttributes({count: parseInt(attributes.count, 10) - 1}); }; const onCountChange = (value) => { @@ -81,20 +90,42 @@ export default function Edit({ clientId }) { return ( <> - -
- + +
+ + + + + { __( 'Orbital count', 'red-orbital' ) } + + + + + + + + + { + setIsAnimating( ( state ) => ! state ); + } } + /> + + +
-
    {viewList}
+
    {viewList}
diff --git a/src/save.js b/src/save.js index 590dcc6..ee32180 100644 --- a/src/save.js +++ b/src/save.js @@ -23,14 +23,13 @@ import { useBlockProps, InnerBlocks } from "@wordpress/block-editor"; * @return {WPElement} Element to render. */ export default function save({ attributes }) { - const blockProps = useBlockProps.save({ className: "pulse", }); return (
-
    +