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

fix/6.7 deprecation #3363

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
20 changes: 16 additions & 4 deletions src/deprecated/v2/block/columns/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ import {
__, sprintf, _x,
} from '@wordpress/i18n'
import { addFilter, applyFilters } from '@wordpress/hooks'
import { Fragment } from '@wordpress/element'
import { Fragment, useState } from '@wordpress/element'
import { InnerBlocks } from '@wordpress/block-editor'
import { compose, withState } from '@wordpress/compose'
import { compose } from '@wordpress/compose'
import { select, dispatch } from '@wordpress/data'
import { createBlock } from '@wordpress/blocks'

Expand Down Expand Up @@ -538,9 +538,21 @@ addFilter( 'stackable.columns.setAttributes', 'stackable/columns/columns-change'
return attributes
} )

// Higher-Order Component to add state to props since withState is deprecated
const withSortColumnHighlight = WrappedComponent => props => {
const [ sortColumnHighlight, setSortColumnHighlight ] = useState( null )

return (
<WrappedComponent
{ ...props }
sortColumnHighlight={ sortColumnHighlight }
setSortColumnHighlight={ setSortColumnHighlight }
/>
)
}

export default compose(
// `withState` is needed to allow higher order functions to access the local state.
withState( { sortColumnHighlight: null } ),
withSortColumnHighlight,
withUniqueClass,
withSetAttributeHook,
withGoogleFont,
Expand Down
5 changes: 1 addition & 4 deletions src/hooks/use-device-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ export const useDeviceType = () => {
const { deviceType } = useSelect( select => {
let deviceType = 'Desktop'

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

return { deviceType }
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/design-library-button/design-library-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/
import { i18n, settings } from 'stackable'
import { SVGStackableIcon } from '~stackable/icons'
import { Button } from '~stackable/components'

/**
* WordPress dependencies
Expand All @@ -12,6 +11,7 @@ import { createBlock } from '@wordpress/blocks'
import { dispatch, useSelect } from '@wordpress/data'
import { __ } from '@wordpress/i18n'
import { useCallback } from '@wordpress/element'
import { ToolbarButton } from '@wordpress/components'

const DesignLibraryButton = () => {
const { getEditorDom } = useSelect( 'stackable/editor-dom' )
Expand All @@ -31,11 +31,11 @@ const DesignLibraryButton = () => {
}, [ getEditorDom ] )

return ( settings.stackable_enable_design_library &&
<Button
<ToolbarButton
onClick={ onClick }
className="ugb-insert-library-button"
icon={ <SVGStackableIcon /> }
>{ __( 'Design Library', i18n ) }</Button>
>{ __( 'Design Library', i18n ) }</ToolbarButton>
)
}

Expand Down
20 changes: 4 additions & 16 deletions src/plugins/global-settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,18 @@ addAction( 'stackable.global-settings.toggle-sidebar', 'toggle', () => {
} )

const GlobalSettings = () => {
// We need to to this for both, because one might be disabled. E.g. in
// WooCommerce, editSite is loaded and stops the sidebar from showing up.
const SideEditorPluginSidebar = window.wp.editSite?.PluginSidebar
const PostEditorPluginSidebar = window.wp.editPost?.PluginSidebar
const PluginSidebar = window.wp.editor.PluginSidebar

return (
<>
{ SideEditorPluginSidebar &&
<SideEditorPluginSidebar
{ PluginSidebar &&
<PluginSidebar
name="sidebar"
title={ __( 'Stackable Settings', i18n ) }
className="ugb-global-settings__inspector"
icon={ <SVGStackableIcon /> } >
{ applyFilters( 'stackable.global-settings.inspector', null ) }
</SideEditorPluginSidebar>
}
{ PostEditorPluginSidebar &&
<PostEditorPluginSidebar
name="sidebar"
title={ __( 'Stackable Settings', i18n ) }
className="ugb-global-settings__inspector"
icon={ <SVGStackableIcon /> } >
{ applyFilters( 'stackable.global-settings.inspector', null ) }
</PostEditorPluginSidebar>
</PluginSidebar>
}
</>
)
Expand Down
11 changes: 3 additions & 8 deletions src/plugins/global-settings/typography/editor-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,9 @@ export const GlobalTypographyStyles = () => {
const [ styleTimeout, setStyleTimeout ] = useState( null )

const { device } = useSelect(
select => {
const device = select( 'core/edit-site' )?.__experimentalGetPreviewDeviceType() ||
select( 'core/edit-post' )?.__experimentalGetPreviewDeviceType() ||
'Desktop'
return {
device,
}
},
select => ( {
device: select( 'core/editor' ).getDeviceType() || 'Desktop',
} ),
[]
)

Expand Down
4 changes: 1 addition & 3 deletions src/plugins/global-settings/typography/typography-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ const TypographyPreview = props => {
} )
const { device } = useSelect(
select => ( {
device: select( 'core/edit-site' )?.__experimentalGetPreviewDeviceType()?.toLowerCase() ||
select( 'core/edit-post' )?.__experimentalGetPreviewDeviceType()?.toLowerCase() ||
'Desktop',
device: select( 'core/editor' ).getDeviceType().toLowerCase() || 'desktop',
} ),
[]
)
Expand Down
5 changes: 2 additions & 3 deletions src/plugins/theme-block-size/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
*/
import { useDeviceType } from '~stackable/hooks'
import { createRoot } from '~stackable/util'
import { useSetting } from '@wordpress/block-editor'
import { useSettings } from '@wordpress/block-editor'
import domReady from '@wordpress/dom-ready'
import { useEffect } from '@wordpress/element'
import { useSelect } from '@wordpress/data'

export const ThemeBlockSize = () => {
const contentSize = useSetting( 'layout.contentSize' )
const wideSize = useSetting( 'layout.wideSize' )
const [ contentSize, wideSize ] = useSettings( 'layout.contentSize', 'layout.wideSize' )

const deviceType = useDeviceType()
const editorDom = useSelect( select => {
Expand Down
Loading