-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Zoom Out: Bundle behavior in block-editor and add story (#66240)
Co-authored-by: youknowriad <youknowriad@git.wordpress.org> Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org> Co-authored-by: ellatrix <ellatrix@git.wordpress.org>
- Loading branch information
1 parent
91272a2
commit 9b0f6aa
Showing
8 changed files
with
193 additions
and
18 deletions.
There are no files selected for viewing
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
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 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 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,68 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useEffect, useState } from '@wordpress/element'; | ||
import { registerCoreBlocks } from '@wordpress/block-library'; | ||
import { useDispatch } from '@wordpress/data'; | ||
import { | ||
BlockEditorProvider, | ||
BlockCanvas, | ||
store as blockEditorStore, | ||
BlockList, | ||
} from '@wordpress/block-editor'; | ||
import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis'; | ||
import { parse } from '@wordpress/blocks'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import editorStyles from '../editor-styles'; | ||
// eslint-disable-next-line @wordpress/dependency-group | ||
import contentCss from '!!raw-loader!../../../../packages/block-editor/build-style/content.css'; | ||
import { pattern } from './pattern'; | ||
|
||
// Temporary hack to access private APIs before stabilizing zoom level. | ||
const { 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' | ||
); | ||
|
||
function EnableZoomOut() { | ||
const { setZoomLevel } = unlock( useDispatch( blockEditorStore ) ); | ||
|
||
useEffect( () => { | ||
setZoomLevel( 50 ); | ||
}, [ setZoomLevel ] ); | ||
|
||
return null; | ||
} | ||
|
||
export default function EditorZoomOut() { | ||
const [ blocks, updateBlocks ] = useState( [] ); | ||
|
||
useEffect( () => { | ||
registerCoreBlocks(); | ||
updateBlocks( parse( pattern ) ); | ||
}, [] ); | ||
|
||
return ( | ||
// eslint-disable-next-line jsx-a11y/no-static-element-interactions | ||
<div | ||
className="editor-zoom-out" | ||
onKeyDown={ ( event ) => event.stopPropagation() } | ||
style={ { background: '#ddd', border: '1px solid gray' } } | ||
> | ||
<BlockEditorProvider | ||
value={ blocks } | ||
onInput={ updateBlocks } | ||
onChange={ updateBlocks } | ||
> | ||
<EnableZoomOut /> | ||
<BlockCanvas height="500px" styles={ editorStyles }> | ||
<style>{ contentCss }</style> | ||
<BlockList /> | ||
</BlockCanvas> | ||
</BlockEditorProvider> | ||
</div> | ||
); | ||
} |
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,39 @@ | ||
export const pattern = `<!-- wp:cover {"customOverlayColor":"#eb4c77","contentPosition":"center center","isDark":false,"align":"full","style":{"spacing":{"padding":{"top":"6vw","right":"6vw","bottom":"6vw","left":"6vw"},"margin":{"top":"0"}}}} --> | ||
<div class="wp-block-cover alignfull is-light" style="margin-top:0;padding-top:6vw;padding-right:6vw;padding-bottom:6vw;padding-left:6vw"><span aria-hidden="true" class="wp-block-cover__background has-background-dim-100 has-background-dim" style="background-color:#eb4c77"></span><div class="wp-block-cover__inner-container"><!-- wp:group {"style":{"spacing":{"blockGap":"0vw"}},"layout":{"type":"flex","flexWrap":"wrap","justifyContent":"center","verticalAlignment":"top"}} --> | ||
<div class="wp-block-group"><!-- wp:group {"align":"wide","style":{"spacing":{"blockGap":"0px"},"layout":{"selfStretch":"fill"}},"layout":{"type":"constrained","justifyContent":"left","contentSize":"600px"}} --> | ||
<div class="wp-block-group alignwide"><!-- wp:heading {"textAlign":"left","align":"wide","style":{"typography":{"fontSize":"100px","textTransform":"none","fontStyle":"normal","fontWeight":"500","lineHeight":"0.9"}},"textColor":"contrast"} --> | ||
<h2 class="wp-block-heading alignwide has-text-align-left has-contrast-color has-text-color" style="font-size:100px;font-style:normal;font-weight:500;line-height:0.9;text-transform:none">Time for an adventure</h2> | ||
<!-- /wp:heading --> | ||
<!-- wp:spacer {"height":"24px"} --> | ||
<div style="height:24px" aria-hidden="true" class="wp-block-spacer"></div> | ||
<!-- /wp:spacer --> | ||
<!-- wp:paragraph {"align":"left","textColor":"contrast"} --> | ||
<p class="has-text-align-left has-contrast-color has-text-color">Explore our network of trails that lead through a variety of woodland habitats and observe the diverse flora that call this area home. </p> | ||
<!-- /wp:paragraph --> | ||
<!-- wp:spacer {"height":"60px"} --> | ||
<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div> | ||
<!-- /wp:spacer --> | ||
<!-- wp:buttons {"layout":{"type":"flex","justifyContent":"left","flexWrap":"nowrap"}} --> | ||
<div class="wp-block-buttons"><!-- wp:button {"backgroundColor":"contrast","textColor":"base","style":{"spacing":{"padding":{"top":"24px","right":"48px","bottom":"24px","left":"48px"}},"typography":{"fontSize":"16px","fontStyle":"normal","fontWeight":"500","textTransform":"uppercase","letterSpacing":"0px"},"border":{"radius":"0px"}},"className":"is-style-fill"} --> | ||
<div class="wp-block-button has-custom-font-size is-style-fill" style="font-size:16px;font-style:normal;font-weight:500;letter-spacing:0px;text-transform:uppercase"><a class="wp-block-button__link has-base-color has-contrast-background-color has-text-color has-background wp-element-button" style="border-radius:0px;padding-top:24px;padding-right:48px;padding-bottom:24px;padding-left:48px">Sign up</a></div> | ||
<!-- /wp:button --></div> | ||
<!-- /wp:buttons --></div> | ||
<!-- /wp:group --> | ||
<!-- wp:group {"style":{"layout":{"selfStretch":"fit","flexSize":null},"spacing":{"blockGap":"24px"}},"layout":{"type":"flex","flexWrap":"nowrap","verticalAlignment":"top","justifyContent":"right"}} --> | ||
<div class="wp-block-group"><!-- wp:group {"style":{"layout":{"selfStretch":"fixed","flexSize":"50%"}},"layout":{"type":"default"}} --> | ||
<div class="wp-block-group"><!-- wp:spacer {"height":"8vw"} --> | ||
<div style="height:8vw" aria-hidden="true" class="wp-block-spacer"></div> | ||
<!-- /wp:spacer --> | ||
</div> | ||
<!-- /wp:group --> | ||
</div> | ||
<!-- /wp:group --></div> | ||
<!-- /wp:group --></div></div> | ||
<!-- /wp:cover -->`; |