-
Notifications
You must be signed in to change notification settings - Fork 1
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
4d6de33
commit d26e80e
Showing
12 changed files
with
165 additions
and
129 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
2 changes: 1 addition & 1 deletion
2
...mattic/jetpack-mu-wpcom/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'); |
4 changes: 2 additions & 2 deletions
4
...or/automattic/jetpack-mu-wpcom/src/build/wpcom-block-editor-nux/wpcom-block-editor-nux.js
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'; |
20 changes: 20 additions & 0 deletions
20
vendor/automattic/jetpack-mu-wpcom/src/common/hooks/use-canvas-mode.ts
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; |
15 changes: 15 additions & 0 deletions
15
vendor/automattic/jetpack-mu-wpcom/src/common/hooks/use-location.ts
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; | ||
} | ||
}; |
Oops, something went wrong.