@wordpress/edit-site 4.10.0 → 4.12.1-next.d6164808d3.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 +4 -0
- package/build/components/add-new-template/add-custom-template-modal.js +26 -44
- package/build/components/add-new-template/add-custom-template-modal.js.map +1 -1
- package/build/components/add-new-template/new-template.js +45 -23
- package/build/components/add-new-template/new-template.js.map +1 -1
- package/build/components/add-new-template/utils.js +493 -242
- package/build/components/add-new-template/utils.js.map +1 -1
- package/build/components/block-editor/index.js +1 -3
- package/build/components/block-editor/index.js.map +1 -1
- package/build/components/block-editor/resizable-editor.js +26 -12
- package/build/components/block-editor/resizable-editor.js.map +1 -1
- package/build/components/global-styles/border-panel.js +3 -3
- package/build/components/global-styles/border-panel.js.map +1 -1
- package/build/components/global-styles/dimensions-panel.js +280 -20
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/global-styles/hooks.js +4 -4
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/screen-color-palette.js +1 -1
- package/build/components/global-styles/screen-color-palette.js.map +1 -1
- package/build/components/global-styles/screen-colors.js +51 -7
- package/build/components/global-styles/screen-colors.js.map +1 -1
- package/build/components/global-styles/screen-heading-color.js +157 -0
- package/build/components/global-styles/screen-heading-color.js.map +1 -0
- package/build/components/global-styles/screen-typography-element.js +4 -0
- package/build/components/global-styles/screen-typography-element.js.map +1 -1
- package/build/components/global-styles/screen-typography.js +5 -0
- package/build/components/global-styles/screen-typography.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +82 -14
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/global-styles/typography-utils.js +217 -0
- package/build/components/global-styles/typography-utils.js.map +1 -0
- package/build/components/global-styles/ui.js +11 -0
- package/build/components/global-styles/ui.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +183 -52
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/global-styles/utils.js +85 -5
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/header/document-actions/index.js +1 -0
- package/build/components/header/document-actions/index.js.map +1 -1
- package/build/components/header/index.js +27 -12
- package/build/components/header/index.js.map +1 -1
- package/build/components/header/mode-switcher/index.js +0 -4
- package/build/components/header/mode-switcher/index.js.map +1 -1
- package/build/components/header/more-menu/index.js +13 -3
- package/build/components/header/more-menu/index.js.map +1 -1
- package/build/components/header/undo-redo/redo.js +2 -1
- package/build/components/header/undo-redo/redo.js.map +1 -1
- package/build/components/list/actions/index.js +1 -1
- package/build/components/list/actions/index.js.map +1 -1
- package/build/components/save-button/index.js +2 -3
- package/build/components/save-button/index.js.map +1 -1
- package/build/components/sidebar/default-sidebar.js +11 -1
- package/build/components/sidebar/default-sidebar.js.map +1 -1
- package/build/components/sidebar/navigation-menu-sidebar/navigation-menu.js +2 -2
- package/build/components/sidebar/navigation-menu-sidebar/navigation-menu.js.map +1 -1
- package/build/components/sidebar/plugin-sidebar/index.js +11 -1
- package/build/components/sidebar/plugin-sidebar/index.js.map +1 -1
- package/build/components/sidebar/template-card/template-actions.js +1 -1
- package/build/components/sidebar/template-card/template-actions.js.map +1 -1
- package/build/components/template-details/edit-template-title.js +1 -1
- package/build/components/template-details/edit-template-title.js.map +1 -1
- package/build/components/template-details/index.js +19 -9
- package/build/components/template-details/index.js.map +1 -1
- package/build/components/template-details/template-areas.js +1 -1
- package/build/components/template-details/template-areas.js.map +1 -1
- package/build/components/template-details/template-part-area-selector.js +47 -0
- package/build/components/template-details/template-part-area-selector.js.map +1 -0
- package/build/components/template-part-converter/convert-to-template-part.js +4 -1
- package/build/components/template-part-converter/convert-to-template-part.js.map +1 -1
- package/build/hooks/index.js +2 -0
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/template-part-edit.js +86 -0
- package/build/hooks/template-part-edit.js.map +1 -0
- package/build/index.js +1 -1
- package/build/index.js.map +1 -1
- package/build-module/components/add-new-template/add-custom-template-modal.js +27 -45
- package/build-module/components/add-new-template/add-custom-template-modal.js.map +1 -1
- package/build-module/components/add-new-template/new-template.js +45 -25
- package/build-module/components/add-new-template/new-template.js.map +1 -1
- package/build-module/components/add-new-template/utils.js +489 -230
- package/build-module/components/add-new-template/utils.js.map +1 -1
- package/build-module/components/block-editor/index.js +1 -2
- package/build-module/components/block-editor/index.js.map +1 -1
- package/build-module/components/block-editor/resizable-editor.js +26 -12
- package/build-module/components/block-editor/resizable-editor.js.map +1 -1
- package/build-module/components/global-styles/border-panel.js +3 -3
- package/build-module/components/global-styles/border-panel.js.map +1 -1
- package/build-module/components/global-styles/dimensions-panel.js +278 -22
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/global-styles/hooks.js +4 -4
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/screen-color-palette.js +1 -1
- package/build-module/components/global-styles/screen-color-palette.js.map +1 -1
- package/build-module/components/global-styles/screen-colors.js +51 -7
- package/build-module/components/global-styles/screen-colors.js.map +1 -1
- package/build-module/components/global-styles/screen-heading-color.js +143 -0
- package/build-module/components/global-styles/screen-heading-color.js.map +1 -0
- package/build-module/components/global-styles/screen-typography-element.js +4 -0
- package/build-module/components/global-styles/screen-typography-element.js.map +1 -1
- package/build-module/components/global-styles/screen-typography.js +5 -0
- package/build-module/components/global-styles/screen-typography.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +83 -15
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/global-styles/typography-utils.js +204 -0
- package/build-module/components/global-styles/typography-utils.js.map +1 -0
- package/build-module/components/global-styles/ui.js +10 -0
- package/build-module/components/global-styles/ui.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +182 -61
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/global-styles/utils.js +82 -5
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/header/document-actions/index.js +1 -0
- package/build-module/components/header/document-actions/index.js.map +1 -1
- package/build-module/components/header/index.js +30 -14
- package/build-module/components/header/index.js.map +1 -1
- package/build-module/components/header/mode-switcher/index.js +0 -4
- package/build-module/components/header/mode-switcher/index.js.map +1 -1
- package/build-module/components/header/more-menu/index.js +13 -3
- package/build-module/components/header/more-menu/index.js.map +1 -1
- package/build-module/components/header/undo-redo/redo.js +3 -2
- package/build-module/components/header/undo-redo/redo.js.map +1 -1
- package/build-module/components/list/actions/index.js +1 -1
- package/build-module/components/list/actions/index.js.map +1 -1
- package/build-module/components/save-button/index.js +3 -4
- package/build-module/components/save-button/index.js.map +1 -1
- package/build-module/components/sidebar/default-sidebar.js +9 -1
- package/build-module/components/sidebar/default-sidebar.js.map +1 -1
- package/build-module/components/sidebar/navigation-menu-sidebar/navigation-menu.js +3 -3
- package/build-module/components/sidebar/navigation-menu-sidebar/navigation-menu.js.map +1 -1
- package/build-module/components/sidebar/plugin-sidebar/index.js +9 -1
- package/build-module/components/sidebar/plugin-sidebar/index.js.map +1 -1
- package/build-module/components/sidebar/template-card/template-actions.js +1 -1
- package/build-module/components/sidebar/template-card/template-actions.js.map +1 -1
- package/build-module/components/template-details/edit-template-title.js +1 -1
- package/build-module/components/template-details/edit-template-title.js.map +1 -1
- package/build-module/components/template-details/index.js +19 -10
- package/build-module/components/template-details/index.js.map +1 -1
- package/build-module/components/template-details/template-areas.js +1 -1
- package/build-module/components/template-details/template-areas.js.map +1 -1
- package/build-module/components/template-details/template-part-area-selector.js +35 -0
- package/build-module/components/template-details/template-part-area-selector.js.map +1 -0
- package/build-module/components/template-part-converter/convert-to-template-part.js +3 -1
- package/build-module/components/template-part-converter/convert-to-template-part.js.map +1 -1
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/template-part-edit.js +67 -0
- package/build-module/hooks/template-part-edit.js.map +1 -0
- package/build-module/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-style/style-rtl.css +40 -33
- package/build-style/style.css +40 -33
- package/package.json +29 -29
- package/src/components/add-new-template/add-custom-template-modal.js +39 -48
- package/src/components/add-new-template/new-template.js +50 -58
- package/src/components/add-new-template/style.scss +20 -8
- package/src/components/add-new-template/utils.js +529 -231
- package/src/components/block-editor/index.js +0 -2
- package/src/components/block-editor/resizable-editor.js +28 -18
- package/src/components/editor/style.scss +1 -0
- package/src/components/global-styles/border-panel.js +3 -3
- package/src/components/global-styles/dimensions-panel.js +344 -45
- package/src/components/global-styles/hooks.js +6 -3
- package/src/components/global-styles/screen-color-palette.js +1 -1
- package/src/components/global-styles/screen-colors.js +46 -4
- package/src/components/global-styles/screen-heading-color.js +201 -0
- package/src/components/global-styles/screen-typography-element.js +4 -0
- package/src/components/global-styles/screen-typography.js +6 -0
- package/src/components/global-styles/style.scss +14 -6
- package/src/components/global-styles/test/typography-utils.js +130 -0
- package/src/components/global-styles/test/use-global-styles-output.js +143 -4
- package/src/components/global-styles/test/utils.js +68 -8
- package/src/components/global-styles/typography-panel.js +119 -48
- package/src/components/global-styles/typography-utils.js +228 -0
- package/src/components/global-styles/ui.js +13 -0
- package/src/components/global-styles/use-global-styles-output.js +203 -53
- package/src/components/global-styles/utils.js +70 -4
- package/src/components/header/document-actions/index.js +3 -0
- package/src/components/header/index.js +41 -14
- package/src/components/header/mode-switcher/index.js +0 -3
- package/src/components/header/more-menu/index.js +7 -2
- package/src/components/header/style.scss +5 -3
- package/src/components/header/undo-redo/redo.js +6 -2
- package/src/components/list/actions/index.js +3 -1
- package/src/components/save-button/index.js +10 -13
- package/src/components/sidebar/default-sidebar.js +12 -0
- package/src/components/sidebar/navigation-menu-sidebar/navigation-menu.js +1 -5
- package/src/components/sidebar/plugin-sidebar/index.js +12 -0
- package/src/components/sidebar/style.scss +4 -0
- package/src/components/sidebar/template-card/template-actions.js +3 -1
- package/src/components/template-details/edit-template-title.js +7 -3
- package/src/components/template-details/index.js +23 -8
- package/src/components/template-details/style.scss +0 -5
- package/src/components/template-details/template-areas.js +3 -1
- package/src/components/template-details/template-part-area-selector.js +38 -0
- package/src/components/template-part-converter/convert-to-template-part.js +3 -1
- package/src/hooks/index.js +1 -0
- package/src/hooks/template-part-edit.js +82 -0
- package/src/index.js +1 -1
- package/src/style.scss +0 -1
- package/build/components/edit-template-part-menu-button/index.js +0 -90
- package/build/components/edit-template-part-menu-button/index.js.map +0 -1
- package/build-module/components/edit-template-part-menu-button/index.js +0 -72
- package/build-module/components/edit-template-part-menu-button/index.js.map +0 -1
- package/src/components/edit-template-part-menu-button/index.js +0 -82
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
pickBy,
|
|
11
11
|
reduce,
|
|
12
12
|
set,
|
|
13
|
-
startsWith,
|
|
14
13
|
} from 'lodash';
|
|
15
14
|
|
|
16
15
|
/**
|
|
@@ -21,25 +20,37 @@ import {
|
|
|
21
20
|
__EXPERIMENTAL_ELEMENTS as ELEMENTS,
|
|
22
21
|
getBlockTypes,
|
|
23
22
|
} from '@wordpress/blocks';
|
|
24
|
-
import {
|
|
23
|
+
import { useSelect } from '@wordpress/data';
|
|
24
|
+
import { useContext, useMemo } from '@wordpress/element';
|
|
25
25
|
import { getCSSRules } from '@wordpress/style-engine';
|
|
26
26
|
import {
|
|
27
27
|
__unstablePresetDuotoneFilter as PresetDuotoneFilter,
|
|
28
28
|
__experimentalGetGapCSSValue as getGapCSSValue,
|
|
29
|
+
store as blockEditorStore,
|
|
29
30
|
} from '@wordpress/block-editor';
|
|
30
31
|
|
|
31
32
|
/**
|
|
32
33
|
* Internal dependencies
|
|
33
34
|
*/
|
|
34
|
-
import { PRESET_METADATA, ROOT_BLOCK_SELECTOR } from './utils';
|
|
35
|
+
import { PRESET_METADATA, ROOT_BLOCK_SELECTOR, scopeSelector } from './utils';
|
|
35
36
|
import { GlobalStylesContext } from './context';
|
|
36
37
|
import { useSetting } from './hooks';
|
|
37
38
|
|
|
39
|
+
// List of block support features that can have their related styles
|
|
40
|
+
// generated under their own feature level selector rather than the block's.
|
|
41
|
+
const BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS = {
|
|
42
|
+
__experimentalBorder: 'border',
|
|
43
|
+
color: 'color',
|
|
44
|
+
spacing: 'spacing',
|
|
45
|
+
typography: 'typography',
|
|
46
|
+
};
|
|
47
|
+
|
|
38
48
|
function compileStyleValue( uncompiledValue ) {
|
|
39
49
|
const VARIABLE_REFERENCE_PREFIX = 'var:';
|
|
40
50
|
const VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE = '|';
|
|
41
51
|
const VARIABLE_PATH_SEPARATOR_TOKEN_STYLE = '--';
|
|
42
|
-
|
|
52
|
+
|
|
53
|
+
if ( uncompiledValue?.startsWith?.( VARIABLE_REFERENCE_PREFIX ) ) {
|
|
43
54
|
const variable = uncompiledValue
|
|
44
55
|
.slice( VARIABLE_REFERENCE_PREFIX.length )
|
|
45
56
|
.split( VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE )
|
|
@@ -53,10 +64,11 @@ function compileStyleValue( uncompiledValue ) {
|
|
|
53
64
|
* Transform given preset tree into a set of style declarations.
|
|
54
65
|
*
|
|
55
66
|
* @param {Object} blockPresets
|
|
67
|
+
* @param {Object} mergedSettings Merged theme.json settings.
|
|
56
68
|
*
|
|
57
|
-
* @return {Array} An array of style declarations.
|
|
69
|
+
* @return {Array<Object>} An array of style declarations.
|
|
58
70
|
*/
|
|
59
|
-
function getPresetsDeclarations( blockPresets = {} ) {
|
|
71
|
+
function getPresetsDeclarations( blockPresets = {}, mergedSettings ) {
|
|
60
72
|
return reduce(
|
|
61
73
|
PRESET_METADATA,
|
|
62
74
|
( declarations, { path, valueKey, valueFunc, cssVarInfix } ) => {
|
|
@@ -64,7 +76,7 @@ function getPresetsDeclarations( blockPresets = {} ) {
|
|
|
64
76
|
[ 'default', 'theme', 'custom' ].forEach( ( origin ) => {
|
|
65
77
|
if ( presetByOrigin[ origin ] ) {
|
|
66
78
|
presetByOrigin[ origin ].forEach( ( value ) => {
|
|
67
|
-
if ( valueKey ) {
|
|
79
|
+
if ( valueKey && ! valueFunc ) {
|
|
68
80
|
declarations.push(
|
|
69
81
|
`--wp--preset--${ cssVarInfix }--${ kebabCase(
|
|
70
82
|
value.slug
|
|
@@ -77,7 +89,7 @@ function getPresetsDeclarations( blockPresets = {} ) {
|
|
|
77
89
|
declarations.push(
|
|
78
90
|
`--wp--preset--${ cssVarInfix }--${ kebabCase(
|
|
79
91
|
value.slug
|
|
80
|
-
) }: ${ valueFunc( value ) }`
|
|
92
|
+
) }: ${ valueFunc( value, mergedSettings ) }`
|
|
81
93
|
);
|
|
82
94
|
}
|
|
83
95
|
} );
|
|
@@ -172,14 +184,29 @@ function flattenTree( input = {}, prefix, token ) {
|
|
|
172
184
|
/**
|
|
173
185
|
* Transform given style tree into a set of style declarations.
|
|
174
186
|
*
|
|
175
|
-
* @param {Object}
|
|
187
|
+
* @param {Object} blockStyles Block styles.
|
|
188
|
+
*
|
|
189
|
+
* @param {string} selector The selector these declarations should attach to.
|
|
190
|
+
*
|
|
191
|
+
* @param {boolean} useRootPaddingAlign Whether to use CSS custom properties in root selector.
|
|
192
|
+
*
|
|
193
|
+
* @param {Object} tree A theme.json tree containing layout definitions.
|
|
176
194
|
*
|
|
177
195
|
* @return {Array} An array of style declarations.
|
|
178
196
|
*/
|
|
179
|
-
function getStylesDeclarations(
|
|
197
|
+
export function getStylesDeclarations(
|
|
198
|
+
blockStyles = {},
|
|
199
|
+
selector = '',
|
|
200
|
+
useRootPaddingAlign,
|
|
201
|
+
tree = {}
|
|
202
|
+
) {
|
|
203
|
+
const isRoot = ROOT_BLOCK_SELECTOR === selector;
|
|
180
204
|
const output = reduce(
|
|
181
205
|
STYLE_PROPERTY,
|
|
182
|
-
( declarations, { value, properties, useEngine }, key ) => {
|
|
206
|
+
( declarations, { value, properties, useEngine, rootOnly }, key ) => {
|
|
207
|
+
if ( rootOnly && ! isRoot ) {
|
|
208
|
+
return declarations;
|
|
209
|
+
}
|
|
183
210
|
const pathToValue = value;
|
|
184
211
|
if ( first( pathToValue ) === 'elements' || useEngine ) {
|
|
185
212
|
return declarations;
|
|
@@ -187,6 +214,15 @@ function getStylesDeclarations( blockStyles = {} ) {
|
|
|
187
214
|
|
|
188
215
|
const styleValue = get( blockStyles, pathToValue );
|
|
189
216
|
|
|
217
|
+
// Root-level padding styles don't currently support strings with CSS shorthand values.
|
|
218
|
+
// This may change: https://github.com/WordPress/gutenberg/issues/40132.
|
|
219
|
+
if (
|
|
220
|
+
key === '--wp--style--root--padding' &&
|
|
221
|
+
( typeof styleValue === 'string' || ! useRootPaddingAlign )
|
|
222
|
+
) {
|
|
223
|
+
return declarations;
|
|
224
|
+
}
|
|
225
|
+
|
|
190
226
|
if ( !! properties && typeof styleValue !== 'string' ) {
|
|
191
227
|
Object.entries( properties ).forEach( ( entry ) => {
|
|
192
228
|
const [ name, prop ] = entry;
|
|
@@ -197,7 +233,9 @@ function getStylesDeclarations( blockStyles = {} ) {
|
|
|
197
233
|
return;
|
|
198
234
|
}
|
|
199
235
|
|
|
200
|
-
const cssProperty =
|
|
236
|
+
const cssProperty = name.startsWith( '--' )
|
|
237
|
+
? name
|
|
238
|
+
: kebabCase( name );
|
|
201
239
|
declarations.push(
|
|
202
240
|
`${ cssProperty }: ${ compileStyleValue(
|
|
203
241
|
get( styleValue, [ prop ] )
|
|
@@ -224,10 +262,30 @@ function getStylesDeclarations( blockStyles = {} ) {
|
|
|
224
262
|
// This is temporary as we absorb more and more styles into the engine.
|
|
225
263
|
const extraRules = getCSSRules( blockStyles );
|
|
226
264
|
extraRules.forEach( ( rule ) => {
|
|
265
|
+
// Don't output padding properties if padding variables are set.
|
|
266
|
+
if (
|
|
267
|
+
isRoot &&
|
|
268
|
+
useRootPaddingAlign &&
|
|
269
|
+
rule.key.startsWith( 'padding' )
|
|
270
|
+
) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
227
273
|
const cssProperty = rule.key.startsWith( '--' )
|
|
228
274
|
? rule.key
|
|
229
275
|
: kebabCase( rule.key );
|
|
230
|
-
|
|
276
|
+
|
|
277
|
+
let ruleValue = rule.value;
|
|
278
|
+
if ( typeof ruleValue !== 'string' && ruleValue?.ref ) {
|
|
279
|
+
const refPath = ruleValue.ref.split( '.' );
|
|
280
|
+
ruleValue = get( tree, refPath );
|
|
281
|
+
// Presence of another ref indicates a reference to another dynamic value.
|
|
282
|
+
// Pointing to another dynamic value is not supported.
|
|
283
|
+
if ( ! ruleValue || !! ruleValue?.ref ) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
output.push( `${ cssProperty }: ${ ruleValue }` );
|
|
231
289
|
} );
|
|
232
290
|
|
|
233
291
|
return output;
|
|
@@ -294,14 +352,28 @@ export function getLayoutStyles( {
|
|
|
294
352
|
}
|
|
295
353
|
|
|
296
354
|
if ( declarations.length ) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
355
|
+
let combinedSelector = '';
|
|
356
|
+
|
|
357
|
+
if ( ! hasBlockGapSupport ) {
|
|
358
|
+
// For fallback gap styles, use lower specificity, to ensure styles do not unintentionally override theme styles.
|
|
359
|
+
combinedSelector =
|
|
360
|
+
selector === ROOT_BLOCK_SELECTOR
|
|
361
|
+
? `:where(.${ className }${
|
|
362
|
+
spacingStyle?.selector || ''
|
|
363
|
+
})`
|
|
364
|
+
: `:where(${ selector }.${ className }${
|
|
365
|
+
spacingStyle?.selector || ''
|
|
366
|
+
})`;
|
|
367
|
+
} else {
|
|
368
|
+
combinedSelector =
|
|
369
|
+
selector === ROOT_BLOCK_SELECTOR
|
|
370
|
+
? `${ selector } .${ className }${
|
|
371
|
+
spacingStyle?.selector || ''
|
|
372
|
+
}`
|
|
373
|
+
: `${ selector }.${ className }${
|
|
374
|
+
spacingStyle?.selector || ''
|
|
375
|
+
}`;
|
|
376
|
+
}
|
|
305
377
|
ruleset += `${ combinedSelector } { ${ declarations.join(
|
|
306
378
|
'; '
|
|
307
379
|
) }; }`;
|
|
@@ -384,11 +456,12 @@ export const getNodesWithStyles = ( tree, blockSelectors ) => {
|
|
|
384
456
|
selector: ROOT_BLOCK_SELECTOR,
|
|
385
457
|
} );
|
|
386
458
|
}
|
|
387
|
-
|
|
388
|
-
|
|
459
|
+
|
|
460
|
+
forEach( ELEMENTS, ( selector, name ) => {
|
|
461
|
+
if ( !! tree.styles?.elements[ name ] ) {
|
|
389
462
|
nodes.push( {
|
|
390
|
-
styles:
|
|
391
|
-
selector
|
|
463
|
+
styles: tree.styles?.elements[ name ],
|
|
464
|
+
selector,
|
|
392
465
|
} );
|
|
393
466
|
}
|
|
394
467
|
} );
|
|
@@ -403,6 +476,7 @@ export const getNodesWithStyles = ( tree, blockSelectors ) => {
|
|
|
403
476
|
hasLayoutSupport: blockSelectors[ blockName ].hasLayoutSupport,
|
|
404
477
|
selector: blockSelectors[ blockName ].selector,
|
|
405
478
|
styles: blockStyles,
|
|
479
|
+
featureSelectors: blockSelectors[ blockName ].featureSelectors,
|
|
406
480
|
} );
|
|
407
481
|
}
|
|
408
482
|
|
|
@@ -480,10 +554,9 @@ export const getNodesWithSettings = ( tree, blockSelectors ) => {
|
|
|
480
554
|
|
|
481
555
|
export const toCustomProperties = ( tree, blockSelectors ) => {
|
|
482
556
|
const settings = getNodesWithSettings( tree, blockSelectors );
|
|
483
|
-
|
|
484
557
|
let ruleset = '';
|
|
485
558
|
settings.forEach( ( { presets, custom, selector } ) => {
|
|
486
|
-
const declarations = getPresetsDeclarations( presets );
|
|
559
|
+
const declarations = getPresetsDeclarations( presets, tree?.settings );
|
|
487
560
|
const customProps = flattenTree( custom, '--wp--custom--', '--' );
|
|
488
561
|
if ( customProps.length > 0 ) {
|
|
489
562
|
declarations.push( ...customProps );
|
|
@@ -501,10 +574,13 @@ export const toStyles = (
|
|
|
501
574
|
tree,
|
|
502
575
|
blockSelectors,
|
|
503
576
|
hasBlockGapSupport,
|
|
504
|
-
hasFallbackGapSupport
|
|
577
|
+
hasFallbackGapSupport,
|
|
578
|
+
disableLayoutStyles = false
|
|
505
579
|
) => {
|
|
506
580
|
const nodesWithStyles = getNodesWithStyles( tree, blockSelectors );
|
|
507
581
|
const nodesWithSettings = getNodesWithSettings( tree, blockSelectors );
|
|
582
|
+
const useRootPaddingAlign = tree?.settings?.useRootPaddingAwareAlignments;
|
|
583
|
+
const { contentSize, wideSize } = tree?.settings?.layout || {};
|
|
508
584
|
|
|
509
585
|
/*
|
|
510
586
|
* Reset default browser margin on the root body element.
|
|
@@ -514,7 +590,23 @@ export const toStyles = (
|
|
|
514
590
|
* user-generated values take precedence in the CSS cascade.
|
|
515
591
|
* @link https://github.com/WordPress/gutenberg/issues/36147.
|
|
516
592
|
*/
|
|
517
|
-
let ruleset = 'body {margin: 0;
|
|
593
|
+
let ruleset = 'body {margin: 0;';
|
|
594
|
+
|
|
595
|
+
if ( contentSize ) {
|
|
596
|
+
ruleset += ` --wp--style--global--content-size: ${ contentSize };`;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
if ( wideSize ) {
|
|
600
|
+
ruleset += ` --wp--style--global--wide-size: ${ wideSize };`;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
if ( useRootPaddingAlign ) {
|
|
604
|
+
ruleset +=
|
|
605
|
+
'padding-right: 0; padding-left: 0; padding-top: var(--wp--style--root--padding-top); padding-bottom: var(--wp--style--root--padding-bottom) } .has-global-padding { padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left); } .has-global-padding > .alignfull { margin-right: calc(var(--wp--style--root--padding-right) * -1); margin-left: calc(var(--wp--style--root--padding-left) * -1); } .has-global-padding > .alignfull > :where([class*="wp-block-"]:not(.alignfull):not([class*="__"]),p,h1,h2,h3,h4,h5,h6,ul,ol) { padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left);';
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
ruleset += '}';
|
|
609
|
+
|
|
518
610
|
nodesWithStyles.forEach(
|
|
519
611
|
( {
|
|
520
612
|
selector,
|
|
@@ -522,7 +614,33 @@ export const toStyles = (
|
|
|
522
614
|
styles,
|
|
523
615
|
fallbackGapValue,
|
|
524
616
|
hasLayoutSupport,
|
|
617
|
+
featureSelectors,
|
|
525
618
|
} ) => {
|
|
619
|
+
// Process styles for block support features with custom feature level
|
|
620
|
+
// CSS selectors set.
|
|
621
|
+
if ( featureSelectors ) {
|
|
622
|
+
Object.entries( featureSelectors ).forEach(
|
|
623
|
+
( [ featureName, featureSelector ] ) => {
|
|
624
|
+
if ( styles?.[ featureName ] ) {
|
|
625
|
+
const featureStyles = {
|
|
626
|
+
[ featureName ]: styles[ featureName ],
|
|
627
|
+
};
|
|
628
|
+
const featureDeclarations =
|
|
629
|
+
getStylesDeclarations( featureStyles );
|
|
630
|
+
delete styles[ featureName ];
|
|
631
|
+
|
|
632
|
+
if ( !! featureDeclarations.length ) {
|
|
633
|
+
ruleset =
|
|
634
|
+
ruleset +
|
|
635
|
+
`${ featureSelector }{${ featureDeclarations.join(
|
|
636
|
+
';'
|
|
637
|
+
) } }`;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
);
|
|
642
|
+
}
|
|
643
|
+
|
|
526
644
|
const duotoneStyles = {};
|
|
527
645
|
if ( styles?.filter ) {
|
|
528
646
|
duotoneStyles.filter = styles.filter;
|
|
@@ -533,18 +651,20 @@ export const toStyles = (
|
|
|
533
651
|
if ( duotoneSelector ) {
|
|
534
652
|
const duotoneDeclarations =
|
|
535
653
|
getStylesDeclarations( duotoneStyles );
|
|
536
|
-
if ( duotoneDeclarations.length
|
|
537
|
-
|
|
654
|
+
if ( duotoneDeclarations.length > 0 ) {
|
|
655
|
+
ruleset =
|
|
656
|
+
ruleset +
|
|
657
|
+
`${ duotoneSelector }{${ duotoneDeclarations.join(
|
|
658
|
+
';'
|
|
659
|
+
) };}`;
|
|
538
660
|
}
|
|
539
|
-
ruleset =
|
|
540
|
-
ruleset +
|
|
541
|
-
`${ duotoneSelector }{${ duotoneDeclarations.join(
|
|
542
|
-
';'
|
|
543
|
-
) };}`;
|
|
544
661
|
}
|
|
545
662
|
|
|
546
663
|
// Process blockGap and layout styles.
|
|
547
|
-
if (
|
|
664
|
+
if (
|
|
665
|
+
! disableLayoutStyles &&
|
|
666
|
+
( ROOT_BLOCK_SELECTOR === selector || hasLayoutSupport )
|
|
667
|
+
) {
|
|
548
668
|
ruleset += getLayoutStyles( {
|
|
549
669
|
tree,
|
|
550
670
|
style: styles,
|
|
@@ -556,7 +676,12 @@ export const toStyles = (
|
|
|
556
676
|
}
|
|
557
677
|
|
|
558
678
|
// Process the remaining block styles (they use either normal block class or __experimentalSelector).
|
|
559
|
-
const declarations = getStylesDeclarations(
|
|
679
|
+
const declarations = getStylesDeclarations(
|
|
680
|
+
styles,
|
|
681
|
+
selector,
|
|
682
|
+
useRootPaddingAlign,
|
|
683
|
+
tree
|
|
684
|
+
);
|
|
560
685
|
if ( declarations?.length ) {
|
|
561
686
|
ruleset =
|
|
562
687
|
ruleset + `${ selector }{${ declarations.join( ';' ) };}`;
|
|
@@ -579,7 +704,7 @@ export const toStyles = (
|
|
|
579
704
|
|
|
580
705
|
// `selector` maybe provided in a form
|
|
581
706
|
// where block level selectors have sub element
|
|
582
|
-
// selectors appended to them as a comma
|
|
707
|
+
// selectors appended to them as a comma separated
|
|
583
708
|
// string.
|
|
584
709
|
// e.g. `h1 a,h2 a,h3 a,h4 a,h5 a,h6 a`;
|
|
585
710
|
// Split and append pseudo selector to create
|
|
@@ -645,7 +770,7 @@ export function toSvgFilters( tree, blockSelectors ) {
|
|
|
645
770
|
} );
|
|
646
771
|
}
|
|
647
772
|
|
|
648
|
-
const getBlockSelectors = ( blockTypes ) => {
|
|
773
|
+
export const getBlockSelectors = ( blockTypes ) => {
|
|
649
774
|
const result = {};
|
|
650
775
|
blockTypes.forEach( ( blockType ) => {
|
|
651
776
|
const name = blockType.name;
|
|
@@ -657,9 +782,29 @@ const getBlockSelectors = ( blockTypes ) => {
|
|
|
657
782
|
const hasLayoutSupport = !! blockType?.supports?.__experimentalLayout;
|
|
658
783
|
const fallbackGapValue =
|
|
659
784
|
blockType?.supports?.spacing?.blockGap?.__experimentalDefault;
|
|
785
|
+
|
|
786
|
+
// For each block support feature add any custom selectors.
|
|
787
|
+
const featureSelectors = {};
|
|
788
|
+
Object.entries( BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS ).forEach(
|
|
789
|
+
( [ featureKey, featureName ] ) => {
|
|
790
|
+
const featureSelector =
|
|
791
|
+
blockType?.supports?.[ featureKey ]?.__experimentalSelector;
|
|
792
|
+
|
|
793
|
+
if ( featureSelector ) {
|
|
794
|
+
featureSelectors[ featureName ] = scopeSelector(
|
|
795
|
+
selector,
|
|
796
|
+
featureSelector
|
|
797
|
+
);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
);
|
|
801
|
+
|
|
660
802
|
result[ name ] = {
|
|
661
803
|
duotoneSelector,
|
|
662
804
|
fallbackGapValue,
|
|
805
|
+
featureSelectors: Object.keys( featureSelectors ).length
|
|
806
|
+
? featureSelectors
|
|
807
|
+
: undefined,
|
|
663
808
|
hasLayoutSupport,
|
|
664
809
|
name,
|
|
665
810
|
selector,
|
|
@@ -670,17 +815,18 @@ const getBlockSelectors = ( blockTypes ) => {
|
|
|
670
815
|
};
|
|
671
816
|
|
|
672
817
|
export function useGlobalStylesOutput() {
|
|
673
|
-
const [ stylesheets, setStylesheets ] = useState( [] );
|
|
674
|
-
const [ settings, setSettings ] = useState( {} );
|
|
675
|
-
const [ svgFilters, setSvgFilters ] = useState( {} );
|
|
676
818
|
const { merged: mergedConfig } = useContext( GlobalStylesContext );
|
|
677
819
|
const [ blockGap ] = useSetting( 'spacing.blockGap' );
|
|
678
820
|
const hasBlockGapSupport = blockGap !== null;
|
|
679
821
|
const hasFallbackGapSupport = ! hasBlockGapSupport; // This setting isn't useful yet: it exists as a placeholder for a future explicit fallback styles support.
|
|
822
|
+
const disableLayoutStyles = useSelect( ( select ) => {
|
|
823
|
+
const { getSettings } = select( blockEditorStore );
|
|
824
|
+
return !! getSettings().disableLayoutStyles;
|
|
825
|
+
} );
|
|
680
826
|
|
|
681
|
-
|
|
827
|
+
return useMemo( () => {
|
|
682
828
|
if ( ! mergedConfig?.styles || ! mergedConfig?.settings ) {
|
|
683
|
-
return;
|
|
829
|
+
return [];
|
|
684
830
|
}
|
|
685
831
|
|
|
686
832
|
const blockSelectors = getBlockSelectors( getBlockTypes() );
|
|
@@ -692,10 +838,11 @@ export function useGlobalStylesOutput() {
|
|
|
692
838
|
mergedConfig,
|
|
693
839
|
blockSelectors,
|
|
694
840
|
hasBlockGapSupport,
|
|
695
|
-
hasFallbackGapSupport
|
|
841
|
+
hasFallbackGapSupport,
|
|
842
|
+
disableLayoutStyles
|
|
696
843
|
);
|
|
697
844
|
const filters = toSvgFilters( mergedConfig, blockSelectors );
|
|
698
|
-
|
|
845
|
+
const stylesheets = [
|
|
699
846
|
{
|
|
700
847
|
css: customProperties,
|
|
701
848
|
isGlobalStyles: true,
|
|
@@ -704,10 +851,13 @@ export function useGlobalStylesOutput() {
|
|
|
704
851
|
css: globalStyles,
|
|
705
852
|
isGlobalStyles: true,
|
|
706
853
|
},
|
|
707
|
-
]
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
}, [
|
|
711
|
-
|
|
712
|
-
|
|
854
|
+
];
|
|
855
|
+
|
|
856
|
+
return [ stylesheets, mergedConfig.settings, filters ];
|
|
857
|
+
}, [
|
|
858
|
+
hasBlockGapSupport,
|
|
859
|
+
hasFallbackGapSupport,
|
|
860
|
+
mergedConfig,
|
|
861
|
+
disableLayoutStyles,
|
|
862
|
+
] );
|
|
713
863
|
}
|
|
@@ -3,6 +3,11 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { get, find } from 'lodash';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { getTypographyFontSizeValue } from './typography-utils';
|
|
10
|
+
|
|
6
11
|
/* Supporting data. */
|
|
7
12
|
export const ROOT_BLOCK_NAME = 'root';
|
|
8
13
|
export const ROOT_BLOCK_SELECTOR = 'body';
|
|
@@ -58,6 +63,8 @@ export const PRESET_METADATA = [
|
|
|
58
63
|
},
|
|
59
64
|
{
|
|
60
65
|
path: [ 'typography', 'fontSizes' ],
|
|
66
|
+
valueFunc: ( preset, { typography: typographySettings } ) =>
|
|
67
|
+
getTypographyFontSizeValue( preset, typographySettings ),
|
|
61
68
|
valueKey: 'size',
|
|
62
69
|
cssVarInfix: 'font-size',
|
|
63
70
|
classes: [ { classSuffix: 'font-size', propertyName: 'font-size' } ],
|
|
@@ -70,6 +77,13 @@ export const PRESET_METADATA = [
|
|
|
70
77
|
{ classSuffix: 'font-family', propertyName: 'font-family' },
|
|
71
78
|
],
|
|
72
79
|
},
|
|
80
|
+
{
|
|
81
|
+
path: [ 'spacing', 'spacingSizes' ],
|
|
82
|
+
valueKey: 'spacingSizes',
|
|
83
|
+
cssVarInfix: 'spacing',
|
|
84
|
+
valueFunc: ( { size } ) => size,
|
|
85
|
+
classes: [],
|
|
86
|
+
},
|
|
73
87
|
];
|
|
74
88
|
|
|
75
89
|
const STYLE_PATH_TO_CSS_VAR_INFIX = {
|
|
@@ -78,6 +92,9 @@ const STYLE_PATH_TO_CSS_VAR_INFIX = {
|
|
|
78
92
|
'elements.link.color.text': 'color',
|
|
79
93
|
'elements.button.color.text': 'color',
|
|
80
94
|
'elements.button.backgroundColor': 'background-color',
|
|
95
|
+
'elements.heading.color': 'color',
|
|
96
|
+
'elements.heading.backgroundColor': 'background-color',
|
|
97
|
+
'elements.heading.gradient': 'gradient',
|
|
81
98
|
'color.gradient': 'gradient',
|
|
82
99
|
'typography.fontSize': 'font-size',
|
|
83
100
|
'typography.fontFamily': 'font-family',
|
|
@@ -185,7 +202,7 @@ function getValueFromPresetVariable(
|
|
|
185
202
|
}
|
|
186
203
|
|
|
187
204
|
const presetObject = findInPresetsBy(
|
|
188
|
-
features,
|
|
205
|
+
features.settings,
|
|
189
206
|
blockName,
|
|
190
207
|
metadata.path,
|
|
191
208
|
'slug',
|
|
@@ -203,8 +220,8 @@ function getValueFromPresetVariable(
|
|
|
203
220
|
|
|
204
221
|
function getValueFromCustomVariable( features, blockName, variable, path ) {
|
|
205
222
|
const result =
|
|
206
|
-
get( features, [ 'blocks', blockName, 'custom', ...path ] ) ??
|
|
207
|
-
get( features, [ 'custom', ...path ] );
|
|
223
|
+
get( features.settings, [ 'blocks', blockName, 'custom', ...path ] ) ??
|
|
224
|
+
get( features.settings, [ 'custom', ...path ] );
|
|
208
225
|
if ( ! result ) {
|
|
209
226
|
return variable;
|
|
210
227
|
}
|
|
@@ -212,9 +229,27 @@ function getValueFromCustomVariable( features, blockName, variable, path ) {
|
|
|
212
229
|
return getValueFromVariable( features, blockName, result );
|
|
213
230
|
}
|
|
214
231
|
|
|
232
|
+
/**
|
|
233
|
+
* Attempts to fetch the value of a theme.json CSS variable.
|
|
234
|
+
*
|
|
235
|
+
* @param {Object} features GlobalStylesContext config, e.g., user, base or merged. Represents the theme.json tree.
|
|
236
|
+
* @param {string} blockName The name of a block as represented in the styles property. E.g., 'root' for root-level, and 'core/${blockName}' for blocks.
|
|
237
|
+
* @param {string|*} variable An incoming style value. A CSS var value is expected, but it could be any value.
|
|
238
|
+
* @return {string|*|{ref}} The value of the CSS var, if found. If not found, the passed variable argument.
|
|
239
|
+
*/
|
|
215
240
|
export function getValueFromVariable( features, blockName, variable ) {
|
|
216
241
|
if ( ! variable || typeof variable !== 'string' ) {
|
|
217
|
-
|
|
242
|
+
if ( variable?.ref && typeof variable?.ref === 'string' ) {
|
|
243
|
+
const refPath = variable.ref.split( '.' );
|
|
244
|
+
variable = get( features, refPath );
|
|
245
|
+
// Presence of another ref indicates a reference to another dynamic value.
|
|
246
|
+
// Pointing to another dynamic value is not supported.
|
|
247
|
+
if ( ! variable || !! variable?.ref ) {
|
|
248
|
+
return variable;
|
|
249
|
+
}
|
|
250
|
+
} else {
|
|
251
|
+
return variable;
|
|
252
|
+
}
|
|
218
253
|
}
|
|
219
254
|
const USER_VALUE_PREFIX = 'var:';
|
|
220
255
|
const THEME_VALUE_PREFIX = 'var(--wp--';
|
|
@@ -255,3 +290,34 @@ export function getValueFromVariable( features, blockName, variable ) {
|
|
|
255
290
|
}
|
|
256
291
|
return variable;
|
|
257
292
|
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Function that scopes a selector with another one. This works a bit like
|
|
296
|
+
* SCSS nesting except the `&` operator isn't supported.
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* ```js
|
|
300
|
+
* const scope = '.a, .b .c';
|
|
301
|
+
* const selector = '> .x, .y';
|
|
302
|
+
* const merged = scopeSelector( scope, selector );
|
|
303
|
+
* // merged is '.a > .x, .a .y, .b .c > .x, .b .c .y'
|
|
304
|
+
* ```
|
|
305
|
+
*
|
|
306
|
+
* @param {string} scope Selector to scope to.
|
|
307
|
+
* @param {string} selector Original selector.
|
|
308
|
+
*
|
|
309
|
+
* @return {string} Scoped selector.
|
|
310
|
+
*/
|
|
311
|
+
export function scopeSelector( scope, selector ) {
|
|
312
|
+
const scopes = scope.split( ',' );
|
|
313
|
+
const selectors = selector.split( ',' );
|
|
314
|
+
|
|
315
|
+
const selectorsScoped = [];
|
|
316
|
+
scopes.forEach( ( outer ) => {
|
|
317
|
+
selectors.forEach( ( inner ) => {
|
|
318
|
+
selectorsScoped.push( `${ outer.trim() } ${ inner.trim() }` );
|
|
319
|
+
} );
|
|
320
|
+
} );
|
|
321
|
+
|
|
322
|
+
return selectorsScoped.join( ', ' );
|
|
323
|
+
}
|
|
@@ -141,6 +141,9 @@ export default function DocumentActions( {
|
|
|
141
141
|
aria-expanded={ isOpen }
|
|
142
142
|
aria-haspopup="true"
|
|
143
143
|
onClick={ onToggle }
|
|
144
|
+
variant={
|
|
145
|
+
showIconLabels ? 'tertiary' : undefined
|
|
146
|
+
}
|
|
144
147
|
label={ sprintf(
|
|
145
148
|
/* translators: %s: the entity to see details about, like "template"*/
|
|
146
149
|
__( 'Show %s details' ),
|