Skip to content

Commit

Permalink
Merge branch 'trunk' into try/export-patterns
Browse files Browse the repository at this point in the history
# Conflicts:
#	includes/class-create-block-theme-api.php
  • Loading branch information
mikachan committed Aug 14, 2024
2 parents 2b812e2 + 36310c3 commit b3e8b78
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 2 deletions.
2 changes: 1 addition & 1 deletion includes/class-create-block-theme-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ function rest_save_theme( $request ) {
// clear pattern customisations?
}

wp_cache_flush();
wp_get_theme()->cache_delete();

return new WP_REST_Response(
array(
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Contributors: wordpressdotorg, mikachan, onemaggie, pbking, scruffian, mmaattiiaass, jffng, madhudollu, egregor, vcanales, jeffikus, cwhitmore
Tags: themes, theme, block-theme
Requires at least: 6.5
Tested up to: 6.5
Tested up to: 6.6
Stable tag: 2.3.0
Requires PHP: 7.4
License: GPLv2 or later
Expand Down
72 changes: 72 additions & 0 deletions src/editor-sidebar/global-styles-json-editor-modal.js
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;
22 changes: 22 additions & 0 deletions src/plugin-sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
*/
import { CreateThemePanel } from './editor-sidebar/create-panel';
import ThemeJsonEditorModal from './editor-sidebar/json-editor-modal';
import GlobalStylesJsonEditorModal from './editor-sidebar/global-styles-json-editor-modal';
import { SaveThemePanel } from './editor-sidebar/save-panel';
import { CreateVariationPanel } from './editor-sidebar/create-variation-panel';
import { ThemeMetadataEditorModal } from './editor-sidebar/metadata-editor-modal';
Expand All @@ -59,6 +60,8 @@ import './plugin-styles.scss';

const CreateBlockThemePlugin = () => {
const [ isEditorOpen, setIsEditorOpen ] = useState( false );
const [ isGlobalStylesEditorOpen, setIsGlobalStylesEditorOpen ] =
useState( false );

const [ isMetadataEditorOpen, setIsMetadataEditorOpen ] = useState( false );

Expand Down Expand Up @@ -155,6 +158,17 @@ const CreateBlockThemePlugin = () => {
'create-block-theme'
) }
</Button>
<Button
icon={ code }
onClick={ () =>
setIsGlobalStylesEditorOpen( true )
}
>
{ __(
'View Custom Styles',
'create-block-theme'
) }
</Button>
<Button
icon={ download }
onClick={ () => handleExportClick() }
Expand Down Expand Up @@ -329,6 +343,14 @@ const CreateBlockThemePlugin = () => {
/>
) }

{ isGlobalStylesEditorOpen && (
<GlobalStylesJsonEditorModal
onRequestClose={ () =>
setIsGlobalStylesEditorOpen( false )
}
/>
) }

{ isMetadataEditorOpen && (
<ThemeMetadataEditorModal
onRequestClose={ () => setIsMetadataEditorOpen( false ) }
Expand Down

0 comments on commit b3e8b78

Please sign in to comment.