-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f523187
commit a26d321
Showing
12 changed files
with
482 additions
and
132 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
69 changes: 69 additions & 0 deletions
69
packages/edit-site/src/components/block-editor/editor-canvas.js
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,69 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
__experimentalUseResizeCanvas as useResizeCanvas, | ||
__unstableEditorStyles as EditorStyles, | ||
__unstableIframe as Iframe, | ||
__unstableUseMouseMoveTypingReset as useMouseMoveTypingReset, | ||
store as blockEditorStore, | ||
} from '@wordpress/block-editor'; | ||
import { useSelect } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as editSiteStore } from '../../store'; | ||
|
||
function EditorCanvas( { enableResizing, settings, children, ...props } ) { | ||
const { deviceType, isZoomOutMode } = useSelect( | ||
( select ) => ( { | ||
deviceType: | ||
select( editSiteStore ).__experimentalGetPreviewDeviceType(), | ||
isZoomOutMode: | ||
select( blockEditorStore ).__unstableGetEditorMode() === | ||
'zoom-out', | ||
} ), | ||
[] | ||
); | ||
const deviceStyles = useResizeCanvas( deviceType ); | ||
const mouseMoveTypingRef = useMouseMoveTypingReset(); | ||
return ( | ||
<Iframe | ||
scale={ ( isZoomOutMode && 0.45 ) || undefined } | ||
frameSize={ isZoomOutMode ? 100 : undefined } | ||
style={ enableResizing ? {} : deviceStyles } | ||
head={ | ||
<> | ||
<EditorStyles styles={ settings.styles } /> | ||
<style>{ | ||
// Forming a "block formatting context" to prevent margin collapsing. | ||
// @see https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Block_formatting_context | ||
`.is-root-container { display: flow-root; } | ||
body { position: relative; }` | ||
}</style> | ||
{ enableResizing && ( | ||
<style> | ||
{ | ||
// Some themes will have `min-height: 100vh` for the root container, | ||
// which isn't a requirement in auto resize mode. | ||
`.is-root-container { min-height: 0 !important; }` | ||
} | ||
</style> | ||
) } | ||
</> | ||
} | ||
assets={ settings.__unstableResolvedAssets } | ||
ref={ mouseMoveTypingRef } | ||
name="editor-canvas" | ||
className="edit-site-visual-editor__editor-canvas" | ||
{ ...props } | ||
> | ||
{ /* Filters need to be rendered before children to avoid Safari rendering issues. */ } | ||
{ settings.svgFilters } | ||
{ children } | ||
</Iframe> | ||
); | ||
} | ||
|
||
export default EditorCanvas; |
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
Oops, something went wrong.