-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Help Center: use URL params for determining editor canvas state (#95964)
* Help Center: Use router params for canvas mode * Add wordpress router dep * Dedupe wordpress router * Only return canvas mode value in the site editor * Match wordpress router version of wpcom-block-editor * Reset yarn.lock from trunk
- Loading branch information
Showing
8 changed files
with
60 additions
and
29 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
This file was deleted.
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,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 { 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,13 @@ | ||
import { privateApis as routerPrivateApis } from '@wordpress/router'; | ||
import { getUnlock } from '../utils'; | ||
|
||
const unlock = getUnlock(); | ||
|
||
let useLocation; | ||
|
||
// The routerPrivateApis may be unavailable. | ||
if ( unlock && routerPrivateApis && unlock( routerPrivateApis ) ) { | ||
useLocation = unlock( routerPrivateApis ).useLocation; | ||
} | ||
|
||
export { 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
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,23 @@ | ||
import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis'; | ||
|
||
/** | ||
* Get unlock API from Gutenberg. | ||
* Sometimes Gutenberg doesn't allow you to re-register the module and throws an error. | ||
*/ | ||
export const getUnlock = () => { | ||
/** | ||
* Sometimes Gutenberg doesn't allow you to re-register the module and throws an error. | ||
*/ | ||
let unlock; | ||
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