Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/styles indicator #1156

Merged
merged 52 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
3104025
Update PanelArea, start POC test for filtering labels
iansvo Dec 5, 2023
a7ceb19
Apply additional label filters for testing
iansvo Dec 5, 2023
9bee16b
Update context to use original blockName key instead of ID
iansvo Dec 6, 2023
87de477
WIP refactor to use new ids and blockName pattern
iansvo Dec 6, 2023
bd90857
Update IconPicker to use blockName
iansvo Dec 6, 2023
919f3d0
Remove extra import
iansvo Dec 6, 2023
65c4368
Revert context changes
iansvo Dec 6, 2023
375f82f
Update ApplyFilters pattern to be more flexible
iansvo Dec 6, 2023
2bd9a62
Adds necessary updates for styles indicator to function
iansvo Dec 7, 2023
affc73e
Remove unused import
iansvo Dec 7, 2023
329c249
Added additional position example
iansvo Dec 7, 2023
8c061fb
WIP testing new state pattern
iansvo Dec 9, 2023
296bf02
Change way we get computed styles
iansvo Dec 10, 2023
1e33e94
Fix runtime error
iansvo Dec 10, 2023
a548d4b
lint fixes
iansvo Dec 10, 2023
84a02ba
Remove extra test change
iansvo Dec 11, 2023
ba9e80a
Minor cleanup, fix zIndex
iansvo Dec 11, 2023
d4b294b
Remove extra console.log
iansvo Dec 11, 2023
e54d9a9
Fix: Selected block element
tomusborne Dec 11, 2023
9d41b8d
Adds indicator for Sizing panel
iansvo Dec 11, 2023
86f89b7
Tweak: Add `useStyleIndicator` hook
tomusborne Dec 12, 2023
ca07dae
Merge pull request #1158 from tomusborne/tweak/add-use-style-indicato…
iansvo Dec 12, 2023
8022055
WIP - adding spacing
iansvo Dec 12, 2023
92ba8ed
Merge branch 'feature/styles-indicator' into feature/styles-indicator…
iansvo Dec 12, 2023
b8c33e3
Modify to use new hook, add hook import/export to index
iansvo Dec 12, 2023
c4be5d5
Add original legacy filter for backwards compat
iansvo Dec 12, 2023
e25c570
Merge branch 'feature/styles-indicator-sizing' into feature/styles-in…
iansvo Dec 13, 2023
d86354a
WIP - testing
iansvo Dec 13, 2023
18ec499
Refactor state to reducer
iansvo Dec 13, 2023
6ca599b
Updated check pattern
iansvo Dec 14, 2023
4ef9da6
Merge pull request #1159 from tomusborne/feature/styles-indicator-spa…
iansvo Dec 15, 2023
f0bd8b7
Merge branch 'feature/styles-indicator' into feature/styles-indicator…
iansvo Dec 15, 2023
b33799a
WIP working on borders panel
iansvo Dec 15, 2023
f880868
Merge branch 'release/1.9.0' into feature/styles-indicator
tomusborne Dec 17, 2023
ae72845
Fix: Panel IDs
tomusborne Dec 17, 2023
0604edf
Add has-global-style via props instead of a filter
iansvo Dec 18, 2023
2d1324f
Merge branch 'feature/styles-indicator' into feature/styles-indicator…
iansvo Dec 18, 2023
091af98
Add indicator to typography panel
iansvo Dec 18, 2023
448fc36
Merge pull request #1161 from tomusborne/fix/panel-ids
iansvo Dec 18, 2023
7752c6b
Merge branch 'feature/styles-indicator' into feature/styles-indicator…
iansvo Dec 19, 2023
2da3bc9
Merge branch 'feature/styles-indicator-borders' into feature/styles-i…
iansvo Dec 19, 2023
5d45edd
Fix indentation
iansvo Dec 21, 2023
9c19c0c
Merge branch 'feature/styles-indicator' into feature/styles-indicator…
iansvo Dec 22, 2023
95da902
Merge pull request #1163 from tomusborne/feature/styles-indicator-bor…
iansvo Dec 22, 2023
b457854
Fix indentation
iansvo Dec 22, 2023
4c177a4
Fix indentation
iansvo Dec 22, 2023
e3179a2
Merge branch 'feature/styles-indicator' of https://github.com/tomusbo…
iansvo Dec 22, 2023
69ae236
Additional fixes unstaged
iansvo Dec 22, 2023
06a0d03
Merge branch 'feature/styles-indicator' into feature/styles-indicator…
iansvo Dec 22, 2023
5ef690e
Merge pull request #1165 from tomusborne/feature/styles-indicator-typ…
iansvo Dec 22, 2023
37232ed
Added placeholder prop as an effect dep
iansvo Dec 22, 2023
8b46883
Lint fixes
iansvo Dec 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"no-alert": "error",
"no-bitwise": "error",
"no-caller": "error",
"no-console": "error",
"no-console": "warn",
"no-const-assign": "error",
"no-debugger": "error",
"no-dupe-args": "error",
Expand Down
12 changes: 1 addition & 11 deletions src/blocks/button/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import BlockControls from './components/BlockControls';
import InspectorAdvancedControls from './components/InspectorAdvancedControls';
import ComponentCSS from './components/ComponentCSS';
import GoogleFontLink from '../../components/google-font-link';
import { Fragment, useRef, useState, useEffect } from '@wordpress/element';
import { Fragment, useRef, useEffect } from '@wordpress/element';
import { compose } from '@wordpress/compose';
import { withButtonLegacyMigration, withDeviceType, withUniqueId } from '../../hoc';
import withDynamicContent from '../../extend/dynamic-content/hoc/withDynamicContent';
Expand Down Expand Up @@ -38,21 +38,12 @@ const ButtonEdit = ( props ) => {
} = attributes;

const ref = useRef( null );
const [ computedStyles, setComputedStyles ] = useState( {} );
const deviceType = getDeviceType();
const {
getBlockParents,
getBlocksByClientId,
} = useSelect( ( select ) => select( 'core/block-editor' ), [] );

useEffect( () => {
const computedButtonStyles = getComputedStyle( ref.current );

setComputedStyles( {
fontSize: parseInt( computedButtonStyles.fontSize ) || '',
} );
}, [] );

useEffect( () => {
const parentBlockId = getBlockParents( clientId, true );

Expand Down Expand Up @@ -85,7 +76,6 @@ const ButtonEdit = ( props ) => {
<GenerateBlocksInspectorControls
attributes={ attributes }
setAttributes={ setAttributes }
computedStyles={ computedStyles }
>
{ applyFilters( 'generateblocks.editor.settingsPanel', undefined, { ...props, device: deviceType } ) }
</GenerateBlocksInspectorControls>
Expand Down
15 changes: 1 addition & 14 deletions src/blocks/headline/edit.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import './markformat';
import { applyFilters } from '@wordpress/hooks';
import BlockControls from './components/BlockControls';
import { Fragment, useEffect, useRef, useState } from '@wordpress/element';
import { Fragment, useEffect, useRef } from '@wordpress/element';
import InspectorAdvancedControls from './components/InspectorAdvancedControls';
import GoogleFontLink from '../../components/google-font-link';
import ComponentCSS from './components/ComponentCSS';
Expand Down Expand Up @@ -50,12 +50,10 @@ const HeadlineEdit = ( props ) => {
googleFontVariants,
icon,
hasIcon,
element,
isBlockPreview = false,
} = attributes;

const ref = useRef( null );
const [ computedStyles, setComputedStyles ] = useState( {} );
const deviceType = getDeviceType();

useEffect( () => {
Expand All @@ -64,16 +62,6 @@ const HeadlineEdit = ( props ) => {
}
}, [] );

useEffect( () => {
const computedHeadlineStyles = getComputedStyle( ref.current );

setComputedStyles( {
marginTop: parseInt( computedHeadlineStyles.marginTop ) || '',
marginBottom: parseInt( computedHeadlineStyles.marginBottom ) || '',
fontSize: parseInt( computedHeadlineStyles.fontSize ) || '',
} );
}, [ element ] );

return (
<Fragment>
<BlockControls
Expand All @@ -85,7 +73,6 @@ const HeadlineEdit = ( props ) => {
<GenerateBlocksInspectorControls
attributes={ attributes }
setAttributes={ setAttributes }
computedStyles={ computedStyles }
>
{ applyFilters( 'generateblocks.editor.settingsPanel', undefined, { ...props, device: deviceType } ) }
</GenerateBlocksInspectorControls>
Expand Down
31 changes: 11 additions & 20 deletions src/components/apply-filters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,19 @@
*/
import {
applyFilters,
doAction,
} from '@wordpress/hooks';

import {
Component,
} from '@wordpress/element';
export default function ApplyFilters( props ) {
const { name, children } = props;
doAction( 'generateblocks.editor.panel.beforeFilters', props );

/**
* Component Class
*/
export default class ApplyFilters extends Component {
render() {
const {
return (
applyFilters(
name,
children,
} = this.props;

return (
applyFilters(
name,
children || '',
this.props,
)
);
}
children || '',
props,
)
);
}

94 changes: 57 additions & 37 deletions src/components/panel-area/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import ApplyFilters from '../apply-filters/';
import objectIsEmpty from '../../utils/object-is-empty';
import { PanelBody } from '@wordpress/components';
import { applyFilters } from '@wordpress/hooks';
import { forwardRef, useContext } from '@wordpress/element';
import ApplyFilters from '../apply-filters/';
import objectIsEmpty from '../../utils/object-is-empty';
import useLocalStorageState from 'use-local-storage-state';
import ControlsContext from '../../block-context';
import classnames from 'classnames';

export default function PanelArea( props ) {
const PanelArea = forwardRef( function PanelArea( props, ref ) {
const { blockName } = useContext( ControlsContext );
const {
title = false,
initialOpen = false,
icon,
className,
id,
state,
showPanel = true,
children,
title = false,
initialOpen = false,
showPanel = true,
hasGlobalStyle = false,
} = props;

const [ panels, setPanels ] = useLocalStorageState(
Expand All @@ -34,41 +39,56 @@ export default function PanelArea( props ) {
}

return (
<ApplyFilters name={ 'generateblocks.panel.' + id } props={ props } state={ state }>
{ title ? (
<PanelBody
title={ title }
initialOpen={
'undefined' !== typeof panels[ id ]
? panels[ id ]
: initialOpen
}
icon={ icon }
className={ className }
onToggle={ () => {
const isOpen = panels[ id ] ||
<ApplyFilters
name="generateblocks.editor.panel"
blockName={ blockName }
state={ state }
panelRef={ ref }
{ ...props }
>
<ApplyFilters
name={ 'generateblocks.panel.' + id }
props={ props }
state={ state }
>
{ title ? (
<PanelBody
ref={ ref }
title={ title }
initialOpen={
'undefined' !== typeof panels[ id ]
? panels[ id ]
: initialOpen
}
icon={ icon }
className={ classnames( className, hasGlobalStyle && 'has-global-style' ) }
onToggle={ () => {
const isOpen = panels[ id ] ||
(
'undefined' === typeof panels[ id ] &&
initialOpen
);

setPanels( {
...panels,
[ id ]: ! isOpen,
} );
} }
>
{
applyFilters( 'generateblocks.editor.panelContents', children, id, props )
}
</PanelBody>
) : (
<PanelBody>
{
applyFilters( 'generateblocks.editor.panelContents', children, id, props )
}
</PanelBody>
) }
setPanels( {
...panels,
[ id ]: ! isOpen,
} );
} }
>
{
applyFilters( 'generateblocks.editor.panelContents', children, id, props )
}
</PanelBody>
) : (
<PanelBody>
{
applyFilters( 'generateblocks.editor.panelContents', children, id, props )
}
</PanelBody>
) }
</ApplyFilters>
</ApplyFilters>
);
}
} );

export default PanelArea;
4 changes: 2 additions & 2 deletions src/components/unit-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default function UnitControl( props ) {
}

setPlaceholders();
}, [ value, overrideValue ] );
}, [ value, overrideValue, placeholder ] );

useEffect( () => {
// Don't run this on first render.
Expand All @@ -112,7 +112,7 @@ export default function UnitControl( props ) {
if ( ! hasOverride && fullValue !== value ) {
onChange( fullValue );
}
}, [ numericValue, unitValue ] );
}, [ numericValue, unitValue, placeholder ] );

useEffect( () => {
if ( focusOnMount && inputRef?.current ) {
Expand Down
Loading