Skip to content

Commit

Permalink
Merge pull request #4 from alleyinteractive/feature/panel-remember
Browse files Browse the repository at this point in the history
Collapse panel by default, and remember state
  • Loading branch information
dlh01 authored Feb 7, 2025
2 parents d807b0d + 3cc2155 commit 03d9d37
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

This library adheres to [Semantic Versioning](https://semver.org/) and [Keep a CHANGELOG](https://keepachangelog.com/en/1.0.0/).

## Unreleased

Nothing yet.

## 0.2.0

### Changed

- Collapse the debug panel by default.

## 0.1.0

- Initial release
17 changes: 11 additions & 6 deletions entries/panel/panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface EditProps extends BlockEditProps<any> {
}

// Local helpers.
const PANEL_NAME = 'wp-block-debug';
const toEditableProperties = (carry: any, [key, value]: [string, any]) => {
const allowedTypes = ['string', 'number', 'integer', 'boolean', 'object', 'array', 'null'];

Expand Down Expand Up @@ -58,18 +59,18 @@ function Panel({
clientId,
}: EditProps) {
// Core selectors.
// @ts-ignore
const blockInstance = useSelect((select) => select('core/block-editor').getBlock(clientId));
// @ts-ignore
const blockType = useSelect((select) => select('core/blocks').getBlockType(blockInstance.name));
const panelOpen = useSelect((select) => (select('core/editor') as any).isEditorPanelOpened(PANEL_NAME), []);
const blockInstance = useSelect((select) => (select('core/block-editor') as any).getBlock(clientId), [clientId]);
const blockType = useSelect((select) => (select('core/blocks') as any).getBlockType(blockInstance.name), [blockInstance.name]);
const blockProps = useBlockProps();
const serializedBlock = serialize(blockInstance);

// Core dispatchers.
const { toggleEditorPanelOpened } = useDispatch('core/editor');
const { createNotice } = useDispatch('core/notices');

// Local state.
const [modalOpen, setModalOpen] = useState(false);
const [modalOpen, setModalOpen] = useState<boolean>(false);
const [modalContent, setModalContent] = useState<string>('');

// Helper values.
Expand All @@ -82,7 +83,11 @@ function Panel({
return (
<>
<InspectorControls>
<PanelBody title={__('Debug', 'wp-block-debug')}>
<PanelBody
title={__('Debug', 'wp-block-debug')}
opened={panelOpen}
onToggle={() => toggleEditorPanelOpened(PANEL_NAME)}
>
<section>
<h3 className="screen-reader-text">{__('Copy', 'wp-block-debug')}</h3>

Expand Down
2 changes: 1 addition & 1 deletion wp-block-debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Alley Block Debug
* Plugin URI: https://github.com/alleyinteractive/wp-block-debug
* Description: Block debug panel.
* Version: 0.1.0
* Version: 0.2.0
* Author: Alley
* Author URI: https://github.com/alleyinteractive/wp-block-debug
* Requires at least: 6.7
Expand Down

0 comments on commit 03d9d37

Please sign in to comment.