-
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.
Apply the editor styles to the Site Editor page (#20982)
Co-Authored-By: Andrés <[email protected]>
- Loading branch information
1 parent
516f022
commit a061e7f
Showing
6 changed files
with
118 additions
and
37 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
38 changes: 38 additions & 0 deletions
38
packages/block-editor/src/components/editor-styles/index.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,38 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { compact, map } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useEffect } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import transformStyles from '../../utils/transform-styles'; | ||
|
||
function EditorStyles( { styles } ) { | ||
useEffect( () => { | ||
const updatedStyles = transformStyles( | ||
styles, | ||
'.editor-styles-wrapper' | ||
); | ||
|
||
const nodes = map( compact( updatedStyles ), ( updatedCSS ) => { | ||
const node = document.createElement( 'style' ); | ||
node.innerHTML = updatedCSS; | ||
document.body.appendChild( node ); | ||
|
||
return node; | ||
} ); | ||
|
||
return () => | ||
nodes.forEach( ( node ) => document.body.removeChild( node ) ); | ||
}, [ styles ] ); | ||
|
||
return null; | ||
} | ||
|
||
export default EditorStyles; |
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