Skip to content

Commit

Permalink
fix: onSplit to splitting
Browse files Browse the repository at this point in the history
  • Loading branch information
Arukuen committed Oct 31, 2024
1 parent 8c2f7d4 commit 39f1c8d
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 57 deletions.
7 changes: 0 additions & 7 deletions src/block/button/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {
*/
import { __ } from '@wordpress/i18n'
import { compose } from '@wordpress/compose'
import { createBlock } from '@wordpress/blocks'
import { AlignmentToolbar, BlockControls } from '@wordpress/block-editor'
import { memo } from '@wordpress/element'

Expand Down Expand Up @@ -113,12 +112,6 @@ const Edit = props => {
placeholder={ __( 'Button text', i18n ) }
withoutInteractiveFormatting={ true }
onReplace={ onReplace }
onSplit={ value => createBlock(
'stackable/button',
{
...props.attributes, text: value,
}
) }
/>
</Button>
</BlockDiv>
Expand Down
1 change: 1 addition & 0 deletions src/block/button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const settings = {
attributes: schema,
supports: {
anchor: true,
splitting: true,
},
transforms,

Expand Down
3 changes: 0 additions & 3 deletions src/block/icon-list-item/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import blockStyles from './style'
import { getUseSvgDef } from '../icon-list/util'
import {
convertToListItems,
useOnSplit,
useOnPaste,
useEnter,
} from './util'
Expand Down Expand Up @@ -106,7 +105,6 @@ const Edit = props => {
] )

const useEnterRef = useEnter( text, clientId )
const onSplit = useOnSplit( clientId, attributes )
const onPaste = useOnPaste( clientId, parentBlock?.clientId, attributes, setAttributes )

const onMerge = forward => {
Expand Down Expand Up @@ -169,7 +167,6 @@ const Edit = props => {
ref={ useEnterRef }
tagName="span"
className={ textClassNames }
onSplit={ onSplit }
onMerge={ onMerge }
onPaste={ onPaste }
onReplace={ onReplace
Expand Down
1 change: 1 addition & 0 deletions src/block/icon-list-item/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const settings = {
__experimentalSelector: 'li',
reusable: false,
stkSaveBlockStyle: false,
splitting: true,
},
example,
edit,
Expand Down
27 changes: 0 additions & 27 deletions src/block/icon-list-item/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,33 +47,6 @@ export function convertToListItems( blocks ) {
return listItems
}

export const useOnSplit = ( clientId, attributes ) => {
const { getBlock } = useSelect( 'core/block-editor' )

return useCallback( ( value, isOriginal ) => {
const block = getBlock( clientId )
let newBlock

if ( isOriginal || value ) {
newBlock = cloneBlock( block, {
...attributes,
text: value,
} )
} else {
newBlock = cloneBlock( block, {
...attributes,
text: '',
} )
}

if ( isOriginal ) {
newBlock.clientId = clientId
}

return newBlock
}, [ clientId, attributes ] )
}

export const useEnter = ( text, clientId ) => {
const {
removeBlocks, selectionChange, insertBlocks,
Expand Down
20 changes: 0 additions & 20 deletions src/block/subtitle/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import { createBlockCompleter } from '~stackable/util'
* WordPress dependencies
*/
import { compose } from '@wordpress/compose'
import { createBlock } from '@wordpress/blocks'
import { addFilter } from '@wordpress/hooks'
import { sprintf, __ } from '@wordpress/i18n'
import { memo } from '@wordpress/element'
Expand Down Expand Up @@ -106,25 +105,6 @@ const Edit = props => {
onMerge={ mergeBlocks }
onRemove={ onRemove }
onReplace={ onReplace }
onSplit={ ( value, isOriginal ) => {
// @see https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/paragraph/edit.js
let newAttributes

if ( isOriginal || value ) {
newAttributes = {
...props.attributes,
text: value,
}
}

const block = createBlock( 'stackable/subtitle', newAttributes )

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

return block
} }
/>
</BlockDiv>
{ props.isHovered && <MarginBottom /> }
Expand Down
1 change: 1 addition & 0 deletions src/block/subtitle/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const settings = {
supports: {
anchor: true,
spacing: true,
splitting: true,
},
example,
deprecated,
Expand Down

0 comments on commit 39f1c8d

Please sign in to comment.