Skip to content

Commit

Permalink
rollback useBlockProp and paragraph edit changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gwwar committed Jun 8, 2021
1 parent 141f411 commit 9066a9b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { useContext, useMemo } from '@wordpress/element';
import { useContext } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
import {
__unstableGetBlockProps as getBlockProps,
Expand Down Expand Up @@ -128,11 +128,6 @@ export function useBlockProps( props = {}, { __unstableIsHtml } = {} ) {
} ),
] );

const updatedStyle = { ...wrapperProps.style, ...props.style };
const style = useMemo( () => updatedStyle, [
JSON.stringify( updatedStyle ),
] );

return {
...wrapperProps,
...props,
Expand All @@ -157,7 +152,7 @@ export function useBlockProps( props = {}, { __unstableIsHtml } = {} ) {
useBlockCustomClassName( clientId ),
useBlockMovingModeClassNames( clientId )
),
style,
style: { ...wrapperProps.style, ...props.style },
};
}

Expand Down
80 changes: 33 additions & 47 deletions packages/block-library/src/paragraph/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
} from '@wordpress/block-editor';
import { createBlock } from '@wordpress/blocks';
import { formatLtr } from '@wordpress/icons';
import { useCallback } from '@wordpress/element';

const name = 'core/paragraph';

Expand Down Expand Up @@ -65,54 +64,20 @@ function ParagraphBlock( {
style: { direction },
} );

const updateContent = useCallback(
( newContent ) => setAttributes( { content: newContent } ),
[ setAttributes ]
);

const splitParagraph = useCallback(
( value, isOriginal ) => {
let newAttributes;

if ( isOriginal || value ) {
newAttributes = {
...attributes,
content: value,
};
}

const block = createBlock( name, newAttributes );

if ( isOriginal ) {
block.clientId = clientId;
}

return block;
},
[ attributes, createBlock ]
);

const updateAlign = useCallback( ( newAlign ) =>
setAttributes( { align: newAlign }, [ setAttributes ] )
);

const setDirection = useCallback(
( newDirection ) => setAttributes( { direction: newDirection } ),
[]
);

const setDropCap = useCallback(
() => setAttributes( { dropCap: ! dropCap } ),
[ setAttributes ]
);

return (
<>
<BlockControls group="block">
<AlignmentControl value={ align } onChange={ updateAlign } />
<AlignmentControl
value={ align }
onChange={ ( newAlign ) =>
setAttributes( { align: newAlign } )
}
/>
<ParagraphRTLControl
direction={ direction }
setDirection={ setDirection }
setDirection={ ( newDirection ) =>
setAttributes( { direction: newDirection } )
}
/>
</BlockControls>
{ isDropCapFeatureEnabled && (
Expand All @@ -121,7 +86,9 @@ function ParagraphBlock( {
<ToggleControl
label={ __( 'Drop cap' ) }
checked={ !! dropCap }
onChange={ setDropCap }
onChange={ () =>
setAttributes( { dropCap: ! dropCap } )
}
help={
dropCap
? __( 'Showing large initial letter.' )
Expand All @@ -138,8 +105,27 @@ function ParagraphBlock( {
tagName="p"
{ ...blockProps }
value={ content }
onChange={ updateContent }
onSplit={ splitParagraph }
onChange={ ( newContent ) =>
setAttributes( { content: newContent } )
}
onSplit={ ( value, isOriginal ) => {
let newAttributes;

if ( isOriginal || value ) {
newAttributes = {
...attributes,
content: value,
};
}

const block = createBlock( name, newAttributes );

if ( isOriginal ) {
block.clientId = clientId;
}

return block;
} }
onMerge={ mergeBlocks }
onReplace={ onReplace }
onRemove={ onRemove }
Expand Down

0 comments on commit 9066a9b

Please sign in to comment.