-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wpcom-block-editor-nux: Support getting the canvas mode from the quer…
…y string after GB 19.6 (#40045) * Introduce @wordpress/router * Get canvas mode from the URL search parameter * changelog Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/11677336292 Upstream-Ref: Automattic/jetpack@e8c0297
- Loading branch information
1 parent
e67c752
commit 7c409d8
Showing
9 changed files
with
80 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/build/wpcom-block-editor-nux/wpcom-block-editor-nux.asset.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<?php return array('dependencies' => array('jetpack-connection', 'lodash', 'moment', 'react', 'react-dom', 'react-jsx-runtime', 'wp-api-fetch', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-data-controls', 'wp-dom', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-notices', 'wp-nux', 'wp-plugins', 'wp-polyfill', 'wp-primitives', 'wp-private-apis', 'wp-url'), 'version' => '84c0373645699d975b72'); | ||
<?php return array('dependencies' => array('jetpack-connection', 'lodash', 'moment', 'react', 'react-dom', 'react-jsx-runtime', 'wp-api-fetch', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-data-controls', 'wp-dom', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-notices', 'wp-nux', 'wp-plugins', 'wp-polyfill', 'wp-primitives', 'wp-private-apis', 'wp-router', 'wp-url'), 'version' => 'acd9efa73a7249ceeaef'); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as useCanvasMode } from './use-canvas-mode'; | ||
export { default as useLocation } from './use-location'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { useSelect } from '@wordpress/data'; | ||
import useLocation from './use-location'; | ||
|
||
const useCanvasMode = () => { | ||
const location = useLocation(); | ||
|
||
return useSelect( | ||
select => { | ||
// The canvas mode is limited to the site editor. | ||
if ( ! select( 'core/edit-site' ) ) { | ||
return null; | ||
} | ||
|
||
return new URLSearchParams( location?.search ).get( 'canvas' ) || 'view'; | ||
}, | ||
[ location?.search ] | ||
); | ||
}; | ||
|
||
export default useCanvasMode; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import * as router from '@wordpress/router'; | ||
import { getUnlock } from '../utils'; | ||
|
||
const unlock = getUnlock(); | ||
|
||
const routerPrivateApis = router?.privateApis; | ||
|
||
let useLocation: () => Location | null = () => null; | ||
|
||
// The routerPrivateApis may be unavailable. | ||
if ( unlock && routerPrivateApis && unlock( routerPrivateApis ) ) { | ||
useLocation = unlock( routerPrivateApis ).useLocation; | ||
} | ||
|
||
export default useLocation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis'; | ||
|
||
export const getUnlock = () => { | ||
/** | ||
* Sometimes Gutenberg doesn't allow you to re-register the module and throws an error. | ||
* FIXME: The new version allow it by default, but we might need to ensure that all the site has the new version. | ||
* @see https://github.com/Automattic/wp-calypso/pull/79663 | ||
*/ | ||
let unlock: ( object: any ) => any | undefined; // eslint-disable-line @typescript-eslint/no-explicit-any | ||
try { | ||
unlock = __dangerousOptInToUnstableAPIsOnlyForCoreModules( | ||
'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', | ||
'@wordpress/edit-site' | ||
).unlock; | ||
return unlock; | ||
} catch ( error ) { | ||
// eslint-disable-next-line no-console | ||
console.error( 'Error: Unable to get the unlock api. Reason: %s', error ); | ||
return undefined; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters