22 * WordPress dependencies
33 */
44import { __ } from '@wordpress/i18n' ;
5- import { useState , useRef } from '@wordpress/element' ;
5+ import { useMemo , useState , useRef } from '@wordpress/element' ;
66import { useSelect } from '@wordpress/data' ;
7- import { BlockControls , transformStyles , useBlockProps } from '@wordpress/block-editor' ;
7+ import {
8+ BlockControls ,
9+ transformStyles ,
10+ useBlockProps ,
11+ store as blockEditorStore ,
12+ } from '@wordpress/block-editor' ;
813import {
914 ResizableBox ,
1015 ToolbarButton ,
@@ -45,6 +50,15 @@ const INDENT_TYPES = [
4550 } ,
4651] ;
4752
53+ const DEFAULT_STYLES = `
54+ html,body,:root {
55+ margin: 0 !important;
56+ padding: 0 !important;
57+ overflow: visible !important;
58+ min-height: auto !important;
59+ }
60+ ` ;
61+
4862export default function HTMLEdit ( { attributes, isSelected, setAttributes, toggleSelection } ) {
4963 const { content, height } = attributes ;
5064 const { editorSettings, editorOptions } = window . chbeObj ;
@@ -62,21 +76,18 @@ export default function HTMLEdit( { attributes, isSelected, setAttributes, toggl
6276
6377 const ref = useRef ( ) ;
6478
65- const styles = useSelect ( ( select ) => {
66- const defaultStyles = `
67- html,body,:root {
68- margin: 0 !important;
69- padding: 0 !important;
70- overflow: visible !important;
71- min-height: auto !important;
72- }
73- ` ;
79+ const settingStyles = useSelect (
80+ ( select ) => select ( blockEditorStore ) . getSettings ( ) . styles ,
81+ [ ]
82+ ) ;
7483
75- return [
76- defaultStyles ,
77- ...transformStyles ( select ( 'core/block-editor' ) . getSettings ( ) . styles ) ,
78- ] ;
79- } , [ ] ) ;
84+ const styles = useMemo (
85+ ( ) => [
86+ DEFAULT_STYLES ,
87+ ...transformStyles ( ( settingStyles ?? [ ] ) . filter ( ( style ) => style . css ) ) ,
88+ ] ,
89+ [ settingStyles ]
90+ ) ;
8091
8192 const onResizeStart = ( ) => {
8293 toggleSelection ( false ) ;
0 commit comments