Skip to content

Commit

Permalink
fixed compatibility with older versions
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Nov 5, 2024
1 parent 30c368a commit 3048918
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/hooks/use-device-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export const useDeviceType = () => {
const { deviceType } = useSelect( select => {
let deviceType = 'Desktop'

deviceType = select( 'core/editor' ).getDeviceType() ||
deviceType = select( 'core/editor' )?.getDeviceType?.() ||
select( 'core/edit-site' )?.__experimentalGetPreviewDeviceType?.() ||
select( 'core/edit-post' )?.__experimentalGetPreviewDeviceType?.() ||
select( 'stackable/device-type' ).getDeviceType()

return { deviceType }
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/global-settings/typography/editor-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ export const GlobalTypographyStyles = () => {

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

// This is a custom hook for the deprecated useSetting since WP 6.3 & 6.4 doesn't have useSettings yet.
const useSettings = _useSettings || ( () => {
const contentSize = deprecatedUseSetting( 'layout.contentSize' )
const wideSize = deprecatedUseSetting( 'layout.wideSize' )
return [ contentSize, wideSize ]
} )

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

Expand Down

0 comments on commit 3048918

Please sign in to comment.