@wordpress/editor 14.33.3 → 14.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/components/collab-sidebar/comment-author-info.js +26 -14
- package/build/components/collab-sidebar/comment-author-info.js.map +2 -2
- package/build/components/document-bar/index.js +16 -3
- package/build/components/document-bar/index.js.map +2 -2
- package/build/components/editor/index.js +23 -4
- package/build/components/editor/index.js.map +3 -3
- package/build/components/editor-interface/index.js +15 -10
- package/build/components/editor-interface/index.js.map +3 -3
- package/build/components/entities-saved-states/entity-type-list.js +19 -15
- package/build/components/entities-saved-states/entity-type-list.js.map +3 -3
- package/build/components/global-styles/block-link.js +70 -0
- package/build/components/global-styles/block-link.js.map +7 -0
- package/build/components/global-styles/header.js +54 -0
- package/build/components/global-styles/header.js.map +7 -0
- package/build/components/global-styles/hooks.js +176 -0
- package/build/components/global-styles/hooks.js.map +7 -0
- package/build/components/global-styles/index.js +138 -0
- package/build/components/global-styles/index.js.map +7 -0
- package/build/components/global-styles/menu.js +95 -0
- package/build/components/global-styles/menu.js.map +7 -0
- package/build/components/global-styles-provider/index.js +3 -49
- package/build/components/global-styles-provider/index.js.map +3 -3
- package/build/components/global-styles-renderer/index.js +55 -0
- package/build/components/global-styles-renderer/index.js.map +7 -0
- package/build/components/global-styles-sidebar/default-sidebar.js +66 -0
- package/build/components/global-styles-sidebar/default-sidebar.js.map +7 -0
- package/build/components/global-styles-sidebar/index.js +182 -0
- package/build/components/global-styles-sidebar/index.js.map +7 -0
- package/build/components/global-styles-sidebar/welcome-guide-image.js +37 -0
- package/build/components/global-styles-sidebar/welcome-guide-image.js.map +7 -0
- package/build/components/global-styles-sidebar/welcome-guide.js +143 -0
- package/build/components/global-styles-sidebar/welcome-guide.js.map +7 -0
- package/build/components/header/index.js +12 -9
- package/build/components/header/index.js.map +2 -2
- package/build/components/post-featured-image/index.js +32 -1
- package/build/components/post-featured-image/index.js.map +3 -3
- package/build/components/provider/index.js +0 -2
- package/build/components/provider/index.js.map +3 -3
- package/build/components/style-book/categories.js +86 -0
- package/build/components/style-book/categories.js.map +7 -0
- package/build/components/style-book/color-examples.js +64 -0
- package/build/components/style-book/color-examples.js.map +7 -0
- package/build/components/style-book/constants.js +319 -0
- package/build/components/style-book/constants.js.map +7 -0
- package/build/components/style-book/duotone-examples.js +68 -0
- package/build/components/style-book/duotone-examples.js.map +7 -0
- package/build/components/style-book/examples.js +237 -0
- package/build/components/style-book/examples.js.map +7 -0
- package/build/components/style-book/index.js +627 -0
- package/build/components/style-book/index.js.map +7 -0
- package/build/components/style-book/types.js +17 -0
- package/build/components/style-book/types.js.map +7 -0
- package/build/components/styles-canvas/index.js +138 -0
- package/build/components/styles-canvas/index.js.map +7 -0
- package/build/components/styles-canvas/revisions.js +121 -0
- package/build/components/styles-canvas/revisions.js.map +7 -0
- package/build/components/styles-canvas/style-book.js +68 -0
- package/build/components/styles-canvas/style-book.js.map +7 -0
- package/build/components/visual-editor/index.js +4 -3
- package/build/components/visual-editor/index.js.map +2 -2
- package/build/dataviews/fields/content-preview/content-preview-view.js.map +2 -2
- package/build/hooks/index.js +1 -0
- package/build/hooks/index.js.map +2 -2
- package/build/hooks/media-upload.js +15 -4
- package/build/hooks/media-upload.js.map +3 -3
- package/build/hooks/push-changes-to-global-styles/index.js +322 -0
- package/build/hooks/push-changes-to-global-styles/index.js.map +7 -0
- package/build/hooks/use-global-styles-output.js +74 -0
- package/build/hooks/use-global-styles-output.js.map +7 -0
- package/build/private-apis.js +10 -5
- package/build/private-apis.js.map +3 -3
- package/build/store/private-actions.js +23 -0
- package/build/store/private-actions.js.map +2 -2
- package/build/store/private-selectors.js +10 -0
- package/build/store/private-selectors.js.map +2 -2
- package/build/store/reducer.js +24 -0
- package/build/store/reducer.js.map +2 -2
- package/build/{components/editor-interface/content-slot-fill.js → utils/set-nested-value.js} +24 -10
- package/build/utils/set-nested-value.js.map +7 -0
- package/build-module/components/collab-sidebar/comment-author-info.js +26 -14
- package/build-module/components/collab-sidebar/comment-author-info.js.map +2 -2
- package/build-module/components/document-bar/index.js +16 -3
- package/build-module/components/document-bar/index.js.map +2 -2
- package/build-module/components/editor/index.js +23 -4
- package/build-module/components/editor/index.js.map +2 -2
- package/build-module/components/editor-interface/index.js +15 -10
- package/build-module/components/editor-interface/index.js.map +2 -2
- package/build-module/components/entities-saved-states/entity-type-list.js +18 -14
- package/build-module/components/entities-saved-states/entity-type-list.js.map +2 -2
- package/build-module/components/global-styles/block-link.js +46 -0
- package/build-module/components/global-styles/block-link.js.map +7 -0
- package/build-module/components/global-styles/header.js +41 -0
- package/build-module/components/global-styles/header.js.map +7 -0
- package/build-module/components/global-styles/hooks.js +154 -0
- package/build-module/components/global-styles/hooks.js.map +7 -0
- package/build-module/components/global-styles/index.js +112 -0
- package/build-module/components/global-styles/index.js.map +7 -0
- package/build-module/components/global-styles/menu.js +71 -0
- package/build-module/components/global-styles/menu.js.map +7 -0
- package/build-module/components/global-styles-provider/index.js +3 -37
- package/build-module/components/global-styles-provider/index.js.map +2 -2
- package/build-module/components/global-styles-renderer/index.js +31 -0
- package/build-module/components/global-styles-renderer/index.js.map +7 -0
- package/build-module/components/global-styles-sidebar/default-sidebar.js +49 -0
- package/build-module/components/global-styles-sidebar/default-sidebar.js.map +7 -0
- package/build-module/components/global-styles-sidebar/index.js +152 -0
- package/build-module/components/global-styles-sidebar/index.js.map +7 -0
- package/build-module/components/global-styles-sidebar/welcome-guide-image.js +17 -0
- package/build-module/components/global-styles-sidebar/welcome-guide-image.js.map +7 -0
- package/build-module/components/global-styles-sidebar/welcome-guide.js +113 -0
- package/build-module/components/global-styles-sidebar/welcome-guide.js.map +7 -0
- package/build-module/components/header/index.js +12 -9
- package/build-module/components/header/index.js.map +2 -2
- package/build-module/components/post-featured-image/index.js +35 -3
- package/build-module/components/post-featured-image/index.js.map +2 -2
- package/build-module/components/provider/index.js +0 -2
- package/build-module/components/provider/index.js.map +2 -2
- package/build-module/components/style-book/categories.js +64 -0
- package/build-module/components/style-book/categories.js.map +7 -0
- package/build-module/components/style-book/color-examples.js +37 -0
- package/build-module/components/style-book/color-examples.js.map +7 -0
- package/build-module/components/style-book/constants.js +290 -0
- package/build-module/components/style-book/constants.js.map +7 -0
- package/build-module/components/style-book/duotone-examples.js +48 -0
- package/build-module/components/style-book/duotone-examples.js.map +7 -0
- package/build-module/components/style-book/examples.js +208 -0
- package/build-module/components/style-book/examples.js.map +7 -0
- package/build-module/components/style-book/index.js +618 -0
- package/build-module/components/style-book/index.js.map +7 -0
- package/build-module/components/style-book/types.js +1 -0
- package/build-module/components/style-book/types.js.map +7 -0
- package/build-module/components/styles-canvas/index.js +104 -0
- package/build-module/components/styles-canvas/index.js.map +7 -0
- package/build-module/components/styles-canvas/revisions.js +107 -0
- package/build-module/components/styles-canvas/revisions.js.map +7 -0
- package/build-module/components/styles-canvas/style-book.js +38 -0
- package/build-module/components/styles-canvas/style-book.js.map +7 -0
- package/build-module/components/visual-editor/index.js +4 -3
- package/build-module/components/visual-editor/index.js.map +2 -2
- package/build-module/dataviews/fields/content-preview/content-preview-view.js.map +2 -2
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +2 -2
- package/build-module/hooks/media-upload.js +19 -5
- package/build-module/hooks/media-upload.js.map +2 -2
- package/build-module/hooks/push-changes-to-global-styles/index.js +309 -0
- package/build-module/hooks/push-changes-to-global-styles/index.js.map +7 -0
- package/build-module/hooks/use-global-styles-output.js +49 -0
- package/build-module/hooks/use-global-styles-output.js.map +7 -0
- package/build-module/private-apis.js +10 -8
- package/build-module/private-apis.js.map +2 -2
- package/build-module/store/private-actions.js +20 -0
- package/build-module/store/private-actions.js.map +2 -2
- package/build-module/store/private-selectors.js +8 -0
- package/build-module/store/private-selectors.js.map +2 -2
- package/build-module/store/reducer.js +22 -0
- package/build-module/store/reducer.js.map +2 -2
- package/build-module/utils/set-nested-value.js +23 -0
- package/build-module/utils/set-nested-value.js.map +7 -0
- package/build-style/style-rtl.css +3017 -11
- package/build-style/style.css +3018 -11
- package/build-types/components/collab-sidebar/comment-author-info.d.ts +5 -16
- package/build-types/components/collab-sidebar/comment-author-info.d.ts.map +1 -1
- package/build-types/components/document-bar/index.d.ts +2 -2
- package/build-types/components/document-bar/index.d.ts.map +1 -1
- package/build-types/components/editor/index.d.ts.map +1 -1
- package/build-types/components/editor-interface/index.d.ts +1 -3
- package/build-types/components/editor-interface/index.d.ts.map +1 -1
- package/build-types/components/entities-saved-states/entity-type-list.d.ts.map +1 -1
- package/build-types/components/global-styles/block-link.d.ts +12 -0
- package/build-types/components/global-styles/block-link.d.ts.map +1 -0
- package/build-types/components/global-styles/header.d.ts +7 -0
- package/build-types/components/global-styles/header.d.ts.map +1 -0
- package/build-types/components/global-styles/hooks.d.ts +24 -0
- package/build-types/components/global-styles/hooks.d.ts.map +1 -0
- package/build-types/components/global-styles/index.d.ts +6 -0
- package/build-types/components/global-styles/index.d.ts.map +1 -0
- package/build-types/components/global-styles/menu.d.ts +13 -0
- package/build-types/components/global-styles/menu.d.ts.map +1 -0
- package/build-types/components/global-styles-provider/index.d.ts +1 -5
- package/build-types/components/global-styles-provider/index.d.ts.map +1 -1
- package/build-types/components/global-styles-renderer/index.d.ts +4 -0
- package/build-types/components/global-styles-renderer/index.d.ts.map +1 -0
- package/build-types/components/global-styles-sidebar/default-sidebar.d.ts +13 -0
- package/build-types/components/global-styles-sidebar/default-sidebar.d.ts.map +1 -0
- package/build-types/components/global-styles-sidebar/index.d.ts +2 -0
- package/build-types/components/global-styles-sidebar/index.d.ts.map +1 -0
- package/build-types/components/global-styles-sidebar/welcome-guide-image.d.ts +5 -0
- package/build-types/components/global-styles-sidebar/welcome-guide-image.d.ts.map +1 -0
- package/build-types/components/global-styles-sidebar/welcome-guide.d.ts +2 -0
- package/build-types/components/global-styles-sidebar/welcome-guide.d.ts.map +1 -0
- package/build-types/components/header/index.d.ts +1 -3
- package/build-types/components/header/index.d.ts.map +1 -1
- package/build-types/components/provider/index.d.ts.map +1 -1
- package/build-types/components/style-book/categories.d.ts +18 -0
- package/build-types/components/style-book/categories.d.ts.map +1 -0
- package/build-types/components/style-book/color-examples.d.ts +7 -0
- package/build-types/components/style-book/color-examples.d.ts.map +1 -0
- package/build-types/components/style-book/constants.d.ts +11 -0
- package/build-types/components/style-book/constants.d.ts.map +1 -0
- package/build-types/components/style-book/duotone-examples.d.ts +9 -0
- package/build-types/components/style-book/duotone-examples.d.ts.map +1 -0
- package/build-types/components/style-book/examples.d.ts +12 -0
- package/build-types/components/style-book/examples.d.ts.map +1 -0
- package/build-types/components/style-book/index.d.ts +31 -0
- package/build-types/components/style-book/index.d.ts.map +1 -0
- package/build-types/components/style-book/types.d.ts +72 -0
- package/build-types/components/style-book/types.d.ts.map +1 -0
- package/build-types/components/styles-canvas/index.d.ts +16 -0
- package/build-types/components/styles-canvas/index.d.ts.map +1 -0
- package/build-types/components/styles-canvas/revisions.d.ts +5 -0
- package/build-types/components/styles-canvas/revisions.d.ts.map +1 -0
- package/build-types/components/styles-canvas/style-book.d.ts +6 -0
- package/build-types/components/styles-canvas/style-book.d.ts.map +1 -0
- package/build-types/components/visual-editor/index.d.ts +1 -2
- package/build-types/components/visual-editor/index.d.ts.map +1 -1
- package/build-types/dataviews/fields/content-preview/content-preview-view.d.ts.map +1 -1
- package/build-types/hooks/push-changes-to-global-styles/index.d.ts +2 -0
- package/build-types/hooks/push-changes-to-global-styles/index.d.ts.map +1 -0
- package/build-types/hooks/use-global-styles-output.d.ts +18 -0
- package/build-types/hooks/use-global-styles-output.d.ts.map +1 -0
- package/build-types/private-apis.d.ts.map +1 -1
- package/build-types/store/private-actions.d.ts +20 -0
- package/build-types/store/private-actions.d.ts.map +1 -1
- package/build-types/store/private-selectors.d.ts +14 -0
- package/build-types/store/private-selectors.d.ts.map +1 -1
- package/build-types/store/reducer.d.ts +20 -0
- package/build-types/store/reducer.d.ts.map +1 -1
- package/build-types/utils/set-nested-value.d.ts +20 -0
- package/build-types/utils/set-nested-value.d.ts.map +1 -0
- package/package.json +40 -40
- package/src/components/collab-sidebar/comment-author-info.js +32 -25
- package/src/components/collab-sidebar/style.scss +1 -1
- package/src/components/document-bar/index.js +18 -3
- package/src/components/editor/index.js +25 -1
- package/src/components/editor-help/style.scss +1 -1
- package/src/components/editor-interface/index.js +40 -39
- package/src/components/entities-saved-states/entity-type-list.js +19 -17
- package/src/components/global-styles/block-link.js +65 -0
- package/src/components/global-styles/header.js +48 -0
- package/src/components/global-styles/hooks.js +216 -0
- package/src/components/global-styles/index.js +125 -0
- package/src/components/global-styles/menu.js +101 -0
- package/src/components/global-styles/style.scss +11 -0
- package/src/components/global-styles-provider/index.js +3 -45
- package/src/components/global-styles-renderer/index.js +39 -0
- package/src/components/global-styles-sidebar/default-sidebar.js +46 -0
- package/src/components/global-styles-sidebar/index.js +177 -0
- package/src/components/global-styles-sidebar/style.scss +119 -0
- package/src/components/global-styles-sidebar/welcome-guide-image.js +11 -0
- package/src/components/global-styles-sidebar/welcome-guide.js +136 -0
- package/src/components/header/index.js +11 -6
- package/src/components/post-featured-image/index.js +44 -1
- package/src/components/post-last-revision/style.scss +1 -1
- package/src/components/post-panel-row/style.scss +1 -0
- package/src/components/post-publish-panel/style.scss +1 -1
- package/src/components/post-publish-panel/test/__snapshots__/index.js.snap +2 -2
- package/src/components/provider/index.js +0 -2
- package/src/components/style-book/categories.ts +97 -0
- package/src/components/style-book/color-examples.tsx +56 -0
- package/src/components/style-book/constants.ts +308 -0
- package/src/components/style-book/duotone-examples.tsx +56 -0
- package/src/components/style-book/examples.tsx +273 -0
- package/src/components/style-book/index.js +794 -0
- package/src/components/style-book/style.scss +44 -0
- package/src/components/style-book/test/categories.js +166 -0
- package/src/components/style-book/types.ts +80 -0
- package/src/components/styles-canvas/index.js +126 -0
- package/src/components/styles-canvas/revisions.js +144 -0
- package/src/components/styles-canvas/style-book.js +57 -0
- package/src/components/styles-canvas/style.scss +40 -0
- package/src/components/visual-editor/index.js +2 -1
- package/src/dataviews/fields/content-preview/content-preview-view.tsx +2 -0
- package/src/hooks/index.js +1 -0
- package/src/hooks/media-upload.js +25 -5
- package/src/hooks/push-changes-to-global-styles/index.js +391 -0
- package/src/hooks/push-changes-to-global-styles/style.scss +4 -0
- package/src/hooks/use-global-styles-output.js +76 -0
- package/src/private-apis.js +10 -8
- package/src/store/private-actions.js +37 -0
- package/src/store/private-selectors.js +20 -0
- package/src/store/reducer.js +36 -0
- package/src/style.scss +7 -1
- package/src/utils/set-nested-value.js +39 -0
- package/tsconfig.json +3 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/block-settings-menu/content-only-settings-menu.js +0 -186
- package/build/components/block-settings-menu/content-only-settings-menu.js.map +0 -7
- package/build/components/editor-interface/content-slot-fill.js.map +0 -7
- package/build-module/components/block-settings-menu/content-only-settings-menu.js +0 -161
- package/build-module/components/block-settings-menu/content-only-settings-menu.js.map +0 -7
- package/build-module/components/editor-interface/content-slot-fill.js +0 -9
- package/build-module/components/editor-interface/content-slot-fill.js.map +0 -7
- package/build-types/components/block-settings-menu/content-only-settings-menu.d.ts +0 -2
- package/build-types/components/block-settings-menu/content-only-settings-menu.d.ts.map +0 -1
- package/build-types/components/editor-interface/content-slot-fill.d.ts +0 -14
- package/build-types/components/editor-interface/content-slot-fill.d.ts.map +0 -1
- package/src/components/block-settings-menu/content-only-settings-menu.js +0 -185
- package/src/components/block-settings-menu/content-only-settings-menu.native.js +0 -4
- package/src/components/block-settings-menu/style.scss +0 -6
- package/src/components/editor-interface/content-slot-fill.js +0 -10
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useSelect } from '@wordpress/data';
|
|
5
|
+
import { useEffect } from '@wordpress/element';
|
|
6
|
+
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
7
|
+
import { usePrevious } from '@wordpress/compose';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Auto-navigate to block styles when a block is selected in the canvas.
|
|
11
|
+
*
|
|
12
|
+
* @param {Object} props
|
|
13
|
+
* @param {string} props.path Current navigation path.
|
|
14
|
+
* @param {Function} props.onPathChange Callback to change the navigation path.
|
|
15
|
+
*/
|
|
16
|
+
export function GlobalStylesBlockLink( { path, onPathChange } ) {
|
|
17
|
+
const { selectedBlockName, selectedBlockClientId } = useSelect(
|
|
18
|
+
( select ) => {
|
|
19
|
+
const { getSelectedBlockClientId, getBlockName } =
|
|
20
|
+
select( blockEditorStore );
|
|
21
|
+
const clientId = getSelectedBlockClientId();
|
|
22
|
+
return {
|
|
23
|
+
selectedBlockName: getBlockName( clientId ),
|
|
24
|
+
selectedBlockClientId: clientId,
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
[]
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
// const blockHasGlobalStyles = useBlockHasGlobalStyles( selectedBlockName );
|
|
31
|
+
const blockHasGlobalStyles = true;
|
|
32
|
+
const previousBlockClientId = usePrevious( selectedBlockClientId );
|
|
33
|
+
|
|
34
|
+
// When we're in the `Blocks` screen enable deep linking to the selected block.
|
|
35
|
+
useEffect( () => {
|
|
36
|
+
// Only navigate when block selection changes, not when path changes
|
|
37
|
+
if ( selectedBlockClientId === previousBlockClientId ) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if ( ! selectedBlockClientId || ! blockHasGlobalStyles ) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (
|
|
44
|
+
! path ||
|
|
45
|
+
( path !== '/blocks' && ! path.startsWith( '/blocks/' ) )
|
|
46
|
+
) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const newPath = '/blocks/' + encodeURIComponent( selectedBlockName );
|
|
50
|
+
// Avoid navigating to the same path. This can happen when selecting
|
|
51
|
+
// a new block of the same type.
|
|
52
|
+
if ( newPath !== path ) {
|
|
53
|
+
onPathChange?.( newPath );
|
|
54
|
+
}
|
|
55
|
+
}, [
|
|
56
|
+
selectedBlockClientId,
|
|
57
|
+
previousBlockClientId,
|
|
58
|
+
selectedBlockName,
|
|
59
|
+
blockHasGlobalStyles,
|
|
60
|
+
path,
|
|
61
|
+
onPathChange,
|
|
62
|
+
] );
|
|
63
|
+
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import {
|
|
5
|
+
__experimentalHStack as HStack,
|
|
6
|
+
__experimentalVStack as VStack,
|
|
7
|
+
__experimentalSpacer as Spacer,
|
|
8
|
+
__experimentalHeading as Heading,
|
|
9
|
+
__experimentalView as View,
|
|
10
|
+
Navigator,
|
|
11
|
+
} from '@wordpress/components';
|
|
12
|
+
import { isRTL, __ } from '@wordpress/i18n';
|
|
13
|
+
import { chevronRight, chevronLeft } from '@wordpress/icons';
|
|
14
|
+
|
|
15
|
+
function ScreenHeader( { title, description, onBack } ) {
|
|
16
|
+
return (
|
|
17
|
+
<VStack spacing={ 0 }>
|
|
18
|
+
<View>
|
|
19
|
+
<Spacer marginBottom={ 0 } paddingX={ 4 } paddingY={ 3 }>
|
|
20
|
+
<HStack spacing={ 2 }>
|
|
21
|
+
<Navigator.BackButton
|
|
22
|
+
icon={ isRTL() ? chevronRight : chevronLeft }
|
|
23
|
+
size="small"
|
|
24
|
+
label={ __( 'Back' ) }
|
|
25
|
+
onClick={ onBack }
|
|
26
|
+
/>
|
|
27
|
+
<Spacer>
|
|
28
|
+
<Heading
|
|
29
|
+
className="editor-global-styles-header"
|
|
30
|
+
level={ 2 }
|
|
31
|
+
size={ 13 }
|
|
32
|
+
>
|
|
33
|
+
{ title }
|
|
34
|
+
</Heading>
|
|
35
|
+
</Spacer>
|
|
36
|
+
</HStack>
|
|
37
|
+
</Spacer>
|
|
38
|
+
</View>
|
|
39
|
+
{ description && (
|
|
40
|
+
<p className="editor-global-styles-header__description">
|
|
41
|
+
{ description }
|
|
42
|
+
</p>
|
|
43
|
+
) }
|
|
44
|
+
</VStack>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default ScreenHeader;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useMemo, useCallback } from '@wordpress/element';
|
|
5
|
+
import {
|
|
6
|
+
mergeGlobalStyles,
|
|
7
|
+
getStyle,
|
|
8
|
+
getSetting,
|
|
9
|
+
} from '@wordpress/global-styles-engine';
|
|
10
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
11
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
12
|
+
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Internal dependencies
|
|
16
|
+
*/
|
|
17
|
+
import { unlock } from '../../lock-unlock';
|
|
18
|
+
|
|
19
|
+
const { cleanEmptyObject } = unlock( blockEditorPrivateApis );
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Hook to fetch and manage user global styles config
|
|
23
|
+
*/
|
|
24
|
+
function useGlobalStylesUserConfig() {
|
|
25
|
+
const { globalStylesId, isReady, settings, styles, _links } = useSelect(
|
|
26
|
+
( select ) => {
|
|
27
|
+
const {
|
|
28
|
+
getEntityRecord,
|
|
29
|
+
getEditedEntityRecord,
|
|
30
|
+
hasFinishedResolution,
|
|
31
|
+
canUser,
|
|
32
|
+
} = select( coreStore );
|
|
33
|
+
const _globalStylesId =
|
|
34
|
+
select( coreStore ).__experimentalGetCurrentGlobalStylesId();
|
|
35
|
+
|
|
36
|
+
let record;
|
|
37
|
+
|
|
38
|
+
const userCanEditGlobalStyles = _globalStylesId
|
|
39
|
+
? canUser( 'update', {
|
|
40
|
+
kind: 'root',
|
|
41
|
+
name: 'globalStyles',
|
|
42
|
+
id: _globalStylesId,
|
|
43
|
+
} )
|
|
44
|
+
: null;
|
|
45
|
+
|
|
46
|
+
if (
|
|
47
|
+
_globalStylesId &&
|
|
48
|
+
typeof userCanEditGlobalStyles === 'boolean'
|
|
49
|
+
) {
|
|
50
|
+
if ( userCanEditGlobalStyles ) {
|
|
51
|
+
record = getEditedEntityRecord(
|
|
52
|
+
'root',
|
|
53
|
+
'globalStyles',
|
|
54
|
+
_globalStylesId
|
|
55
|
+
);
|
|
56
|
+
} else {
|
|
57
|
+
record = getEntityRecord(
|
|
58
|
+
'root',
|
|
59
|
+
'globalStyles',
|
|
60
|
+
_globalStylesId,
|
|
61
|
+
{ context: 'view' }
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let hasResolved = false;
|
|
67
|
+
if (
|
|
68
|
+
hasFinishedResolution(
|
|
69
|
+
'__experimentalGetCurrentGlobalStylesId'
|
|
70
|
+
)
|
|
71
|
+
) {
|
|
72
|
+
if ( _globalStylesId ) {
|
|
73
|
+
hasResolved = userCanEditGlobalStyles
|
|
74
|
+
? hasFinishedResolution( 'getEditedEntityRecord', [
|
|
75
|
+
'root',
|
|
76
|
+
'globalStyles',
|
|
77
|
+
_globalStylesId,
|
|
78
|
+
] )
|
|
79
|
+
: hasFinishedResolution( 'getEntityRecord', [
|
|
80
|
+
'root',
|
|
81
|
+
'globalStyles',
|
|
82
|
+
_globalStylesId,
|
|
83
|
+
{ context: 'view' },
|
|
84
|
+
] );
|
|
85
|
+
} else {
|
|
86
|
+
hasResolved = true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
globalStylesId: _globalStylesId,
|
|
92
|
+
isReady: hasResolved,
|
|
93
|
+
settings: record?.settings,
|
|
94
|
+
styles: record?.styles,
|
|
95
|
+
_links: record?._links,
|
|
96
|
+
};
|
|
97
|
+
},
|
|
98
|
+
[]
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
const { getEditedEntityRecord } = useSelect( coreStore );
|
|
102
|
+
const { editEntityRecord } = useDispatch( coreStore );
|
|
103
|
+
|
|
104
|
+
const config = useMemo( () => {
|
|
105
|
+
return {
|
|
106
|
+
settings: settings ?? {},
|
|
107
|
+
styles: styles ?? {},
|
|
108
|
+
_links: _links ?? {},
|
|
109
|
+
};
|
|
110
|
+
}, [ settings, styles, _links ] );
|
|
111
|
+
|
|
112
|
+
const setConfig = useCallback(
|
|
113
|
+
( callbackOrObject, options = {} ) => {
|
|
114
|
+
const record = getEditedEntityRecord(
|
|
115
|
+
'root',
|
|
116
|
+
'globalStyles',
|
|
117
|
+
globalStylesId
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
const currentConfig = {
|
|
121
|
+
styles: record?.styles ?? {},
|
|
122
|
+
settings: record?.settings ?? {},
|
|
123
|
+
_links: record?._links ?? {},
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const updatedConfig =
|
|
127
|
+
typeof callbackOrObject === 'function'
|
|
128
|
+
? callbackOrObject( currentConfig )
|
|
129
|
+
: callbackOrObject;
|
|
130
|
+
|
|
131
|
+
editEntityRecord(
|
|
132
|
+
'root',
|
|
133
|
+
'globalStyles',
|
|
134
|
+
globalStylesId,
|
|
135
|
+
{
|
|
136
|
+
styles: cleanEmptyObject( updatedConfig.styles ) || {},
|
|
137
|
+
settings: cleanEmptyObject( updatedConfig.settings ) || {},
|
|
138
|
+
_links: cleanEmptyObject( updatedConfig._links ) || {},
|
|
139
|
+
},
|
|
140
|
+
options
|
|
141
|
+
);
|
|
142
|
+
},
|
|
143
|
+
[ globalStylesId, editEntityRecord, getEditedEntityRecord ]
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
return [ isReady, config, setConfig ];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Hook to fetch base/theme global styles config
|
|
151
|
+
*/
|
|
152
|
+
function useGlobalStylesBaseConfig() {
|
|
153
|
+
const baseConfig = useSelect(
|
|
154
|
+
( select ) =>
|
|
155
|
+
select( coreStore ).__experimentalGetCurrentThemeBaseGlobalStyles(),
|
|
156
|
+
[]
|
|
157
|
+
);
|
|
158
|
+
return [ !! baseConfig, baseConfig ];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Hook to get merged global styles configuration
|
|
163
|
+
*
|
|
164
|
+
* @return {Object} Object containing merged, base, user configs and setUser function
|
|
165
|
+
* { merged, base, user, setUser }
|
|
166
|
+
*/
|
|
167
|
+
export function useGlobalStyles() {
|
|
168
|
+
const [ isUserConfigReady, userConfig, setUserConfig ] =
|
|
169
|
+
useGlobalStylesUserConfig();
|
|
170
|
+
const [ isBaseConfigReady, baseConfig ] = useGlobalStylesBaseConfig();
|
|
171
|
+
|
|
172
|
+
const merged = useMemo( () => {
|
|
173
|
+
if ( ! isUserConfigReady || ! isBaseConfigReady ) {
|
|
174
|
+
return {};
|
|
175
|
+
}
|
|
176
|
+
return mergeGlobalStyles( baseConfig || {}, userConfig );
|
|
177
|
+
}, [ isUserConfigReady, isBaseConfigReady, baseConfig, userConfig ] );
|
|
178
|
+
|
|
179
|
+
return {
|
|
180
|
+
merged,
|
|
181
|
+
base: baseConfig || {},
|
|
182
|
+
user: userConfig,
|
|
183
|
+
setUser: setUserConfig,
|
|
184
|
+
isReady: isUserConfigReady && isBaseConfigReady,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Hook to get a style value from global styles
|
|
190
|
+
*
|
|
191
|
+
* @param {string} path Style path (e.g., 'color.background')
|
|
192
|
+
* @param {string} blockName Optional block name
|
|
193
|
+
* @return {*} Style value
|
|
194
|
+
*/
|
|
195
|
+
export function useStyle( path, blockName ) {
|
|
196
|
+
const { merged } = useGlobalStyles();
|
|
197
|
+
return useMemo(
|
|
198
|
+
() => getStyle( merged, path, blockName ),
|
|
199
|
+
[ merged, path, blockName ]
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Hook to get a setting value from global styles
|
|
205
|
+
*
|
|
206
|
+
* @param {string} path Setting path (e.g., 'spacing.blockGap')
|
|
207
|
+
* @param {string} blockName Optional block name
|
|
208
|
+
* @return {*} Setting value
|
|
209
|
+
*/
|
|
210
|
+
export function useSetting( path, blockName ) {
|
|
211
|
+
const { merged } = useGlobalStyles();
|
|
212
|
+
return useMemo(
|
|
213
|
+
() => getSetting( merged, path, blockName ),
|
|
214
|
+
[ merged, path, blockName ]
|
|
215
|
+
);
|
|
216
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
5
|
+
import { useSelect } from '@wordpress/data';
|
|
6
|
+
import { useMemo } from '@wordpress/element';
|
|
7
|
+
import { GlobalStylesUI } from '@wordpress/global-styles-ui';
|
|
8
|
+
import { uploadMedia } from '@wordpress/media-utils';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Internal dependencies
|
|
12
|
+
*/
|
|
13
|
+
import { store as editorStore } from '../../store';
|
|
14
|
+
import { GlobalStylesBlockLink } from './block-link';
|
|
15
|
+
import { useGlobalStyles } from './hooks';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Hook to fetch server CSS and settings for BlockEditorProvider that are not Global Styles.
|
|
19
|
+
*/
|
|
20
|
+
function useServerData() {
|
|
21
|
+
const {
|
|
22
|
+
styles,
|
|
23
|
+
__unstableResolvedAssets,
|
|
24
|
+
colors,
|
|
25
|
+
gradients,
|
|
26
|
+
__experimentalDiscussionSettings,
|
|
27
|
+
mediaUploadHandler,
|
|
28
|
+
fontLibraryEnabled,
|
|
29
|
+
} = useSelect( ( select ) => {
|
|
30
|
+
const { getEditorSettings } = select( editorStore );
|
|
31
|
+
const { canUser } = select( coreStore );
|
|
32
|
+
const editorSettings = getEditorSettings();
|
|
33
|
+
|
|
34
|
+
const canUserUploadMedia = canUser( 'create', {
|
|
35
|
+
kind: 'root',
|
|
36
|
+
name: 'media',
|
|
37
|
+
} );
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
styles: editorSettings?.styles || [],
|
|
41
|
+
__unstableResolvedAssets:
|
|
42
|
+
editorSettings?.__unstableResolvedAssets || {},
|
|
43
|
+
colors: editorSettings?.colors || [],
|
|
44
|
+
gradients: editorSettings?.gradients || [],
|
|
45
|
+
__experimentalDiscussionSettings:
|
|
46
|
+
editorSettings?.__experimentalDiscussionSettings,
|
|
47
|
+
mediaUploadHandler: canUserUploadMedia ? uploadMedia : undefined,
|
|
48
|
+
fontLibraryEnabled: editorSettings?.fontLibraryEnabled ?? true,
|
|
49
|
+
};
|
|
50
|
+
}, [] );
|
|
51
|
+
|
|
52
|
+
// Filter out global styles to get only server-provided styles
|
|
53
|
+
const serverCSS = useMemo( () => {
|
|
54
|
+
if ( ! styles ) {
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
return styles.filter( ( style ) => ! style.isGlobalStyles );
|
|
58
|
+
}, [ styles ] );
|
|
59
|
+
|
|
60
|
+
// Create server settings object
|
|
61
|
+
const serverSettings = useMemo( () => {
|
|
62
|
+
return {
|
|
63
|
+
__unstableResolvedAssets,
|
|
64
|
+
settings: {
|
|
65
|
+
color: {
|
|
66
|
+
palette: {
|
|
67
|
+
theme: colors,
|
|
68
|
+
},
|
|
69
|
+
gradients: {
|
|
70
|
+
theme: gradients,
|
|
71
|
+
},
|
|
72
|
+
duotone: {
|
|
73
|
+
theme: [],
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
__experimentalDiscussionSettings,
|
|
78
|
+
mediaUpload: mediaUploadHandler,
|
|
79
|
+
};
|
|
80
|
+
}, [
|
|
81
|
+
__unstableResolvedAssets,
|
|
82
|
+
colors,
|
|
83
|
+
gradients,
|
|
84
|
+
__experimentalDiscussionSettings,
|
|
85
|
+
mediaUploadHandler,
|
|
86
|
+
] );
|
|
87
|
+
|
|
88
|
+
return { serverCSS, serverSettings, fontLibraryEnabled };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export default function GlobalStylesUIWrapper( { path, onPathChange } ) {
|
|
92
|
+
const {
|
|
93
|
+
user: userConfig,
|
|
94
|
+
base: baseConfig,
|
|
95
|
+
setUser: setUserConfig,
|
|
96
|
+
isReady,
|
|
97
|
+
} = useGlobalStyles();
|
|
98
|
+
const { serverCSS, serverSettings, fontLibraryEnabled } = useServerData();
|
|
99
|
+
|
|
100
|
+
// Show loading state while data is being fetched
|
|
101
|
+
if ( ! isReady ) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<>
|
|
107
|
+
<GlobalStylesUI
|
|
108
|
+
value={ userConfig }
|
|
109
|
+
baseValue={ baseConfig || {} }
|
|
110
|
+
onChange={ setUserConfig }
|
|
111
|
+
path={ path }
|
|
112
|
+
onPathChange={ onPathChange }
|
|
113
|
+
fontLibraryEnabled={ fontLibraryEnabled }
|
|
114
|
+
serverCSS={ serverCSS }
|
|
115
|
+
serverSettings={ serverSettings }
|
|
116
|
+
/>
|
|
117
|
+
<GlobalStylesBlockLink
|
|
118
|
+
path={ path }
|
|
119
|
+
onPathChange={ onPathChange }
|
|
120
|
+
/>
|
|
121
|
+
</>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export { useGlobalStyles, useStyle, useSetting } from './hooks';
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components';
|
|
5
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
6
|
+
import { __ } from '@wordpress/i18n';
|
|
7
|
+
import { store as preferencesStore } from '@wordpress/preferences';
|
|
8
|
+
import { moreVertical } from '@wordpress/icons';
|
|
9
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
import { useGlobalStyles } from './hooks';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Action menu with Reset, Welcome Guide, and Additional CSS.
|
|
18
|
+
*
|
|
19
|
+
* @param {Object} props Component props.
|
|
20
|
+
* @param {boolean} props.hideWelcomeGuide Whether to hide the Welcome Guide option.
|
|
21
|
+
* @param {Function} props.onChangePath Callback for navigation to different paths (e.g., '/css').
|
|
22
|
+
* @return {JSX.Element} The Global Styles Action Menu component.
|
|
23
|
+
*/
|
|
24
|
+
export function GlobalStylesActionMenu( {
|
|
25
|
+
hideWelcomeGuide = false,
|
|
26
|
+
onChangePath,
|
|
27
|
+
} ) {
|
|
28
|
+
const { user, setUser } = useGlobalStyles();
|
|
29
|
+
|
|
30
|
+
// Check if there are user customizations that can be reset
|
|
31
|
+
const canReset =
|
|
32
|
+
!! user &&
|
|
33
|
+
( Object.keys( user?.styles ?? {} ).length > 0 ||
|
|
34
|
+
Object.keys( user?.settings ?? {} ).length > 0 );
|
|
35
|
+
|
|
36
|
+
// Reset function to clear all user customizations
|
|
37
|
+
const onReset = () => {
|
|
38
|
+
setUser( { styles: {}, settings: {} } );
|
|
39
|
+
};
|
|
40
|
+
const { toggle } = useDispatch( preferencesStore );
|
|
41
|
+
const { canEditCSS } = useSelect( ( select ) => {
|
|
42
|
+
const { getEntityRecord, __experimentalGetCurrentGlobalStylesId } =
|
|
43
|
+
select( coreStore );
|
|
44
|
+
|
|
45
|
+
const globalStylesId = __experimentalGetCurrentGlobalStylesId();
|
|
46
|
+
const globalStyles = globalStylesId
|
|
47
|
+
? getEntityRecord( 'root', 'globalStyles', globalStylesId )
|
|
48
|
+
: undefined;
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
canEditCSS: !! globalStyles?._links?.[ 'wp:action-edit-css' ],
|
|
52
|
+
};
|
|
53
|
+
}, [] );
|
|
54
|
+
const loadCustomCSS = () => {
|
|
55
|
+
onChangePath( '/css' );
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<DropdownMenu
|
|
60
|
+
icon={ moreVertical }
|
|
61
|
+
label={ __( 'More' ) }
|
|
62
|
+
toggleProps={ { size: 'compact' } }
|
|
63
|
+
>
|
|
64
|
+
{ ( { onClose } ) => (
|
|
65
|
+
<>
|
|
66
|
+
<MenuGroup>
|
|
67
|
+
{ canEditCSS && (
|
|
68
|
+
<MenuItem onClick={ loadCustomCSS }>
|
|
69
|
+
{ __( 'Additional CSS' ) }
|
|
70
|
+
</MenuItem>
|
|
71
|
+
) }
|
|
72
|
+
{ ! hideWelcomeGuide && (
|
|
73
|
+
<MenuItem
|
|
74
|
+
onClick={ () => {
|
|
75
|
+
toggle(
|
|
76
|
+
'core/edit-site',
|
|
77
|
+
'welcomeGuideStyles'
|
|
78
|
+
);
|
|
79
|
+
onClose();
|
|
80
|
+
} }
|
|
81
|
+
>
|
|
82
|
+
{ __( 'Welcome Guide' ) }
|
|
83
|
+
</MenuItem>
|
|
84
|
+
) }
|
|
85
|
+
</MenuGroup>
|
|
86
|
+
<MenuGroup>
|
|
87
|
+
<MenuItem
|
|
88
|
+
onClick={ () => {
|
|
89
|
+
onReset();
|
|
90
|
+
onClose();
|
|
91
|
+
} }
|
|
92
|
+
disabled={ ! canReset }
|
|
93
|
+
>
|
|
94
|
+
{ __( 'Reset styles' ) }
|
|
95
|
+
</MenuItem>
|
|
96
|
+
</MenuGroup>
|
|
97
|
+
</>
|
|
98
|
+
) }
|
|
99
|
+
</DropdownMenu>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
@use "@wordpress/base-styles/colors" as *;
|
|
2
|
+
@use "@wordpress/base-styles/variables" as *;
|
|
3
|
+
|
|
4
|
+
.editor-global-styles-header__description {
|
|
5
|
+
padding: 0 $grid-unit-20;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.editor-global-styles-header {
|
|
9
|
+
// Need to override the too specific bottom margin for complementary areas.
|
|
10
|
+
margin-bottom: 0 !important;
|
|
11
|
+
}
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import deepmerge from 'deepmerge';
|
|
5
|
-
import { isPlainObject } from 'is-plain-object';
|
|
6
|
-
|
|
7
1
|
/**
|
|
8
2
|
* WordPress dependencies
|
|
9
3
|
*/
|
|
@@ -11,37 +5,14 @@ import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
|
|
|
11
5
|
import { store as coreStore } from '@wordpress/core-data';
|
|
12
6
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
13
7
|
import { useMemo, useCallback } from '@wordpress/element';
|
|
8
|
+
import { mergeGlobalStyles } from '@wordpress/global-styles-engine';
|
|
14
9
|
|
|
15
10
|
/**
|
|
16
11
|
* Internal dependencies
|
|
17
12
|
*/
|
|
18
13
|
import { unlock } from '../../lock-unlock';
|
|
19
14
|
|
|
20
|
-
const {
|
|
21
|
-
blockEditorPrivateApis
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
export function mergeBaseAndUserConfigs( base, user ) {
|
|
25
|
-
return deepmerge( base, user, {
|
|
26
|
-
/*
|
|
27
|
-
* We only pass as arrays the presets,
|
|
28
|
-
* in which case we want the new array of values
|
|
29
|
-
* to override the old array (no merging).
|
|
30
|
-
*/
|
|
31
|
-
isMergeableObject: isPlainObject,
|
|
32
|
-
/*
|
|
33
|
-
* Exceptions to the above rule.
|
|
34
|
-
* Background images should be replaced, not merged,
|
|
35
|
-
* as they themselves are specific object definitions for the style.
|
|
36
|
-
*/
|
|
37
|
-
customMerge: ( key ) => {
|
|
38
|
-
if ( key === 'backgroundImage' ) {
|
|
39
|
-
return ( baseConfig, userConfig ) => userConfig;
|
|
40
|
-
}
|
|
41
|
-
return undefined;
|
|
42
|
-
},
|
|
43
|
-
} );
|
|
44
|
-
}
|
|
15
|
+
const { cleanEmptyObject } = unlock( blockEditorPrivateApis );
|
|
45
16
|
|
|
46
17
|
function useGlobalStylesUserConfig() {
|
|
47
18
|
const { globalStylesId, isReady, settings, styles, _links } = useSelect(
|
|
@@ -212,7 +183,7 @@ export function useGlobalStylesContext() {
|
|
|
212
183
|
return {};
|
|
213
184
|
}
|
|
214
185
|
|
|
215
|
-
return
|
|
186
|
+
return mergeGlobalStyles( baseConfig, userConfig );
|
|
216
187
|
}, [ userConfig, baseConfig ] );
|
|
217
188
|
|
|
218
189
|
const context = useMemo( () => {
|
|
@@ -234,16 +205,3 @@ export function useGlobalStylesContext() {
|
|
|
234
205
|
|
|
235
206
|
return context;
|
|
236
207
|
}
|
|
237
|
-
|
|
238
|
-
export function GlobalStylesProvider( { children } ) {
|
|
239
|
-
const context = useGlobalStylesContext();
|
|
240
|
-
if ( ! context.isReady ) {
|
|
241
|
-
return null;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
return (
|
|
245
|
-
<GlobalStylesContext.Provider value={ context }>
|
|
246
|
-
{ children }
|
|
247
|
-
</GlobalStylesContext.Provider>
|
|
248
|
-
);
|
|
249
|
-
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useEffect } from '@wordpress/element';
|
|
5
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { store as editorStore } from '../../store';
|
|
11
|
+
import { useGlobalStylesOutput } from '../../hooks/use-global-styles-output';
|
|
12
|
+
|
|
13
|
+
function useGlobalStylesRenderer( disableRootPadding ) {
|
|
14
|
+
const [ styles, settings ] = useGlobalStylesOutput( disableRootPadding );
|
|
15
|
+
const { getEditorSettings } = useSelect( editorStore );
|
|
16
|
+
const { updateEditorSettings } = useDispatch( editorStore );
|
|
17
|
+
|
|
18
|
+
useEffect( () => {
|
|
19
|
+
if ( ! styles || ! settings ) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const currentStoreSettings = getEditorSettings();
|
|
24
|
+
const nonGlobalStyles = Object.values(
|
|
25
|
+
currentStoreSettings.styles ?? []
|
|
26
|
+
).filter( ( style ) => ! style.isGlobalStyles );
|
|
27
|
+
updateEditorSettings( {
|
|
28
|
+
...currentStoreSettings,
|
|
29
|
+
styles: [ ...nonGlobalStyles, ...styles ],
|
|
30
|
+
__experimentalFeatures: settings,
|
|
31
|
+
} );
|
|
32
|
+
}, [ styles, settings, updateEditorSettings, getEditorSettings ] );
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function GlobalStylesRenderer( { disableRootPadding } ) {
|
|
36
|
+
useGlobalStylesRenderer( disableRootPadding );
|
|
37
|
+
|
|
38
|
+
return null;
|
|
39
|
+
}
|