-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'trunk' into try/export-patterns
# Conflicts: # includes/class-create-block-theme-api.php
- Loading branch information
Showing
4 changed files
with
96 additions
and
2 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 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,72 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import CodeMirror from '@uiw/react-codemirror'; | ||
import { json } from '@codemirror/lang-json'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
import { Modal } from '@wordpress/components'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
|
||
const GlobalStylesJsonEditorModal = ( { onRequestClose } ) => { | ||
const themeName = useSelect( ( select ) => | ||
select( 'core' ).getCurrentTheme() | ||
)?.name?.raw; | ||
|
||
const { record: globalStylesRecord } = useSelect( ( select ) => { | ||
const { | ||
__experimentalGetCurrentGlobalStylesId, | ||
getEditedEntityRecord, | ||
} = select( coreStore ); | ||
const globalStylesId = __experimentalGetCurrentGlobalStylesId(); | ||
const record = getEditedEntityRecord( | ||
'root', | ||
'globalStyles', | ||
globalStylesId | ||
); | ||
return { | ||
record, | ||
}; | ||
} ); | ||
|
||
const globalStyles = { | ||
...( globalStylesRecord?.styles && { | ||
styles: globalStylesRecord.styles, | ||
} ), | ||
...( globalStylesRecord?.settings && { | ||
settings: globalStylesRecord.settings, | ||
} ), | ||
}; | ||
|
||
const globalStylesAsString = globalStyles | ||
? JSON.stringify( globalStyles, null, 4 ) | ||
: ''; | ||
|
||
const handleSave = () => {}; | ||
|
||
return ( | ||
<Modal | ||
size="large" | ||
title={ sprintf( | ||
// translators: %s: theme name. | ||
__( 'Custom Styles for %s', 'create-block-theme' ), | ||
themeName | ||
) } | ||
onRequestClose={ onRequestClose } | ||
className="create-block-theme__theme-json-modal" | ||
> | ||
<CodeMirror | ||
extensions={ [ json() ] } | ||
value={ globalStylesAsString } | ||
onChange={ handleSave } | ||
readOnly | ||
/> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default GlobalStylesJsonEditorModal; |
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