Skip to content

Commit 75f2801

Browse files
authored
fix (WP 6.7): fixed deprecated warnings (#3363)
* fix: withState to useState * fix: select( 'core/edit-site' ).__experimentalGetPreviewDeviceType to select( 'core/editor' ).getDeviceType * fix: wp.blockEditor.useSetting to wp.blockEditor.useSettings * fix: wp.editPost.PluginSidebar to wp.editor.PluginSidebar * fix: custom components as toolbar controls * fix: onSplit to splitting * fixed compatibility with older versions --------- Co-authored-by: [email protected] <>
1 parent afd519e commit 75f2801

File tree

14 files changed

+48
-98
lines changed

14 files changed

+48
-98
lines changed

src/block/button/edit.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import {
3131
*/
3232
import { __ } from '@wordpress/i18n'
3333
import { compose } from '@wordpress/compose'
34-
import { createBlock } from '@wordpress/blocks'
3534
import { AlignmentToolbar, BlockControls } from '@wordpress/block-editor'
3635
import { memo } from '@wordpress/element'
3736

@@ -113,12 +112,6 @@ const Edit = props => {
113112
placeholder={ __( 'Button text', i18n ) }
114113
withoutInteractiveFormatting={ true }
115114
onReplace={ onReplace }
116-
onSplit={ value => createBlock(
117-
'stackable/button',
118-
{
119-
...props.attributes, text: value,
120-
}
121-
) }
122115
/>
123116
</Button>
124117
</BlockDiv>

src/block/button/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const settings = {
2828
attributes: schema,
2929
supports: {
3030
anchor: true,
31+
splitting: true,
3132
},
3233
transforms,
3334

src/block/icon-list-item/edit.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import blockStyles from './style'
55
import { getUseSvgDef } from '../icon-list/util'
66
import {
77
convertToListItems,
8-
useOnSplit,
98
useOnPaste,
109
useEnter,
1110
} from './util'
@@ -111,7 +110,6 @@ const Edit = props => {
111110
] )
112111

113112
const useEnterRef = useEnter( text, clientId )
114-
const onSplit = useOnSplit( clientId, attributes )
115113
const onPaste = useOnPaste( clientId, parentBlock?.clientId, attributes, setAttributes )
116114

117115
const onMerge = forward => {
@@ -174,7 +172,6 @@ const Edit = props => {
174172
ref={ useEnterRef }
175173
tagName="span"
176174
className={ textClassNames }
177-
onSplit={ onSplit }
178175
onMerge={ onMerge }
179176
onPaste={ onPaste }
180177
onReplace={ onReplace

src/block/icon-list-item/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const settings = {
2222
__experimentalSelector: 'li',
2323
reusable: false,
2424
stkSaveBlockStyle: false,
25+
splitting: true,
2526
},
2627
example,
2728
edit,

src/block/icon-list-item/util.js

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,33 +47,6 @@ export function convertToListItems( blocks ) {
4747
return listItems
4848
}
4949

50-
export const useOnSplit = ( clientId, attributes ) => {
51-
const { getBlock } = useSelect( 'core/block-editor' )
52-
53-
return useCallback( ( value, isOriginal ) => {
54-
const block = getBlock( clientId )
55-
let newBlock
56-
57-
if ( isOriginal || value ) {
58-
newBlock = cloneBlock( block, {
59-
...attributes,
60-
text: value,
61-
} )
62-
} else {
63-
newBlock = cloneBlock( block, {
64-
...attributes,
65-
text: '',
66-
} )
67-
}
68-
69-
if ( isOriginal ) {
70-
newBlock.clientId = clientId
71-
}
72-
73-
return newBlock
74-
}, [ clientId, attributes ] )
75-
}
76-
7750
export const useEnter = ( text, clientId ) => {
7851
const {
7952
removeBlocks, selectionChange, insertBlocks,

src/block/subtitle/edit.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import { createBlockCompleter } from '~stackable/util'
3535
* WordPress dependencies
3636
*/
3737
import { compose } from '@wordpress/compose'
38-
import { createBlock } from '@wordpress/blocks'
3938
import { addFilter } from '@wordpress/hooks'
4039
import { sprintf, __ } from '@wordpress/i18n'
4140
import { memo } from '@wordpress/element'
@@ -106,25 +105,6 @@ const Edit = props => {
106105
onMerge={ mergeBlocks }
107106
onRemove={ onRemove }
108107
onReplace={ onReplace }
109-
onSplit={ ( value, isOriginal ) => {
110-
// @see https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/paragraph/edit.js
111-
let newAttributes
112-
113-
if ( isOriginal || value ) {
114-
newAttributes = {
115-
...props.attributes,
116-
text: value,
117-
}
118-
}
119-
120-
const block = createBlock( 'stackable/subtitle', newAttributes )
121-
122-
if ( isOriginal ) {
123-
block.clientId = props.clientId
124-
}
125-
126-
return block
127-
} }
128108
/>
129109
</BlockDiv>
130110
{ props.isHovered && <MarginBottom /> }

src/block/subtitle/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const settings = {
2424
supports: {
2525
anchor: true,
2626
spacing: true,
27+
splitting: true,
2728
},
2829
example,
2930
deprecated,

src/deprecated/v2/block/columns/edit.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ import {
4949
__, sprintf, _x,
5050
} from '@wordpress/i18n'
5151
import { addFilter, applyFilters } from '@wordpress/hooks'
52-
import { Fragment } from '@wordpress/element'
52+
import { Fragment, useState } from '@wordpress/element'
5353
import { InnerBlocks } from '@wordpress/block-editor'
54-
import { compose, withState } from '@wordpress/compose'
54+
import { compose } from '@wordpress/compose'
5555
import { select, dispatch } from '@wordpress/data'
5656
import { createBlock } from '@wordpress/blocks'
5757

@@ -538,9 +538,21 @@ addFilter( 'stackable.columns.setAttributes', 'stackable/columns/columns-change'
538538
return attributes
539539
} )
540540

541+
// Higher-Order Component to add state to props since withState is deprecated
542+
const withSortColumnHighlight = WrappedComponent => props => {
543+
const [ sortColumnHighlight, setSortColumnHighlight ] = useState( null )
544+
545+
return (
546+
<WrappedComponent
547+
{ ...props }
548+
sortColumnHighlight={ sortColumnHighlight }
549+
setSortColumnHighlight={ setSortColumnHighlight }
550+
/>
551+
)
552+
}
553+
541554
export default compose(
542-
// `withState` is needed to allow higher order functions to access the local state.
543-
withState( { sortColumnHighlight: null } ),
555+
withSortColumnHighlight,
544556
withUniqueClass,
545557
withSetAttributeHook,
546558
withGoogleFont,

src/hooks/use-device-type.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ export const useDeviceType = () => {
66
const { deviceType } = useSelect( select => {
77
let deviceType = 'Desktop'
88

9-
// In some editors, there is no edit-post / preview device type. If that
10-
// happens, we just set our own internal device type.
11-
deviceType = select( 'core/edit-site' )?.__experimentalGetPreviewDeviceType() ||
12-
select( 'core/edit-post' )?.__experimentalGetPreviewDeviceType() ||
9+
deviceType = select( 'core/editor' )?.getDeviceType?.() ||
10+
select( 'core/edit-site' )?.__experimentalGetPreviewDeviceType?.() ||
11+
select( 'core/edit-post' )?.__experimentalGetPreviewDeviceType?.() ||
1312
select( 'stackable/device-type' ).getDeviceType()
1413

1514
return { deviceType }

src/plugins/design-library-button/design-library-button.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*/
44
import { i18n, settings } from 'stackable'
55
import { SVGStackableIcon } from '~stackable/icons'
6-
import { Button } from '~stackable/components'
76

87
/**
98
* WordPress dependencies
@@ -12,6 +11,7 @@ import { createBlock } from '@wordpress/blocks'
1211
import { dispatch, useSelect } from '@wordpress/data'
1312
import { __ } from '@wordpress/i18n'
1413
import { useCallback } from '@wordpress/element'
14+
import { ToolbarButton } from '@wordpress/components'
1515

1616
const DesignLibraryButton = () => {
1717
const { getEditorDom } = useSelect( 'stackable/editor-dom' )
@@ -31,11 +31,11 @@ const DesignLibraryButton = () => {
3131
}, [ getEditorDom ] )
3232

3333
return ( settings.stackable_enable_design_library &&
34-
<Button
34+
<ToolbarButton
3535
onClick={ onClick }
3636
className="ugb-insert-library-button"
3737
icon={ <SVGStackableIcon /> }
38-
>{ __( 'Design Library', i18n ) }</Button>
38+
>{ __( 'Design Library', i18n ) }</ToolbarButton>
3939
)
4040
}
4141

0 commit comments

Comments
 (0)