@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
|
@@ -3,29 +3,40 @@ import { createElement } from "@wordpress/element";
|
|
|
3
3
|
/**
|
|
4
4
|
* External dependencies
|
|
5
5
|
*/
|
|
6
|
-
import { first, forEach, get, isEmpty, kebabCase, pickBy, reduce, set
|
|
6
|
+
import { first, forEach, get, isEmpty, kebabCase, pickBy, reduce, set } from 'lodash';
|
|
7
7
|
/**
|
|
8
8
|
* WordPress dependencies
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { __EXPERIMENTAL_STYLE_PROPERTY as STYLE_PROPERTY, __EXPERIMENTAL_ELEMENTS as ELEMENTS, getBlockTypes } from '@wordpress/blocks';
|
|
12
|
-
import {
|
|
12
|
+
import { useSelect } from '@wordpress/data';
|
|
13
|
+
import { useContext, useMemo } from '@wordpress/element';
|
|
13
14
|
import { getCSSRules } from '@wordpress/style-engine';
|
|
14
|
-
import { __unstablePresetDuotoneFilter as PresetDuotoneFilter, __experimentalGetGapCSSValue as getGapCSSValue } from '@wordpress/block-editor';
|
|
15
|
+
import { __unstablePresetDuotoneFilter as PresetDuotoneFilter, __experimentalGetGapCSSValue as getGapCSSValue, store as blockEditorStore } from '@wordpress/block-editor';
|
|
15
16
|
/**
|
|
16
17
|
* Internal dependencies
|
|
17
18
|
*/
|
|
18
19
|
|
|
19
|
-
import { PRESET_METADATA, ROOT_BLOCK_SELECTOR } from './utils';
|
|
20
|
+
import { PRESET_METADATA, ROOT_BLOCK_SELECTOR, scopeSelector } from './utils';
|
|
20
21
|
import { GlobalStylesContext } from './context';
|
|
21
|
-
import { useSetting } from './hooks';
|
|
22
|
+
import { useSetting } from './hooks'; // List of block support features that can have their related styles
|
|
23
|
+
// generated under their own feature level selector rather than the block's.
|
|
24
|
+
|
|
25
|
+
const BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS = {
|
|
26
|
+
__experimentalBorder: 'border',
|
|
27
|
+
color: 'color',
|
|
28
|
+
spacing: 'spacing',
|
|
29
|
+
typography: 'typography'
|
|
30
|
+
};
|
|
22
31
|
|
|
23
32
|
function compileStyleValue(uncompiledValue) {
|
|
33
|
+
var _uncompiledValue$star;
|
|
34
|
+
|
|
24
35
|
const VARIABLE_REFERENCE_PREFIX = 'var:';
|
|
25
36
|
const VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE = '|';
|
|
26
37
|
const VARIABLE_PATH_SEPARATOR_TOKEN_STYLE = '--';
|
|
27
38
|
|
|
28
|
-
if (startsWith(uncompiledValue, VARIABLE_REFERENCE_PREFIX)) {
|
|
39
|
+
if (uncompiledValue !== null && uncompiledValue !== void 0 && (_uncompiledValue$star = uncompiledValue.startsWith) !== null && _uncompiledValue$star !== void 0 && _uncompiledValue$star.call(uncompiledValue, VARIABLE_REFERENCE_PREFIX)) {
|
|
29
40
|
const variable = uncompiledValue.slice(VARIABLE_REFERENCE_PREFIX.length).split(VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE).join(VARIABLE_PATH_SEPARATOR_TOKEN_STYLE);
|
|
30
41
|
return `var(--wp--${variable})`;
|
|
31
42
|
}
|
|
@@ -36,13 +47,15 @@ function compileStyleValue(uncompiledValue) {
|
|
|
36
47
|
* Transform given preset tree into a set of style declarations.
|
|
37
48
|
*
|
|
38
49
|
* @param {Object} blockPresets
|
|
50
|
+
* @param {Object} mergedSettings Merged theme.json settings.
|
|
39
51
|
*
|
|
40
|
-
* @return {Array} An array of style declarations.
|
|
52
|
+
* @return {Array<Object>} An array of style declarations.
|
|
41
53
|
*/
|
|
42
54
|
|
|
43
55
|
|
|
44
56
|
function getPresetsDeclarations() {
|
|
45
57
|
let blockPresets = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
58
|
+
let mergedSettings = arguments.length > 1 ? arguments[1] : undefined;
|
|
46
59
|
return reduce(PRESET_METADATA, (declarations, _ref) => {
|
|
47
60
|
let {
|
|
48
61
|
path,
|
|
@@ -54,10 +67,10 @@ function getPresetsDeclarations() {
|
|
|
54
67
|
['default', 'theme', 'custom'].forEach(origin => {
|
|
55
68
|
if (presetByOrigin[origin]) {
|
|
56
69
|
presetByOrigin[origin].forEach(value => {
|
|
57
|
-
if (valueKey) {
|
|
70
|
+
if (valueKey && !valueFunc) {
|
|
58
71
|
declarations.push(`--wp--preset--${cssVarInfix}--${kebabCase(value.slug)}: ${value[valueKey]}`);
|
|
59
72
|
} else if (valueFunc && typeof valueFunc === 'function') {
|
|
60
|
-
declarations.push(`--wp--preset--${cssVarInfix}--${kebabCase(value.slug)}: ${valueFunc(value)}`);
|
|
73
|
+
declarations.push(`--wp--preset--${cssVarInfix}--${kebabCase(value.slug)}: ${valueFunc(value, mergedSettings)}`);
|
|
61
74
|
}
|
|
62
75
|
});
|
|
63
76
|
}
|
|
@@ -145,27 +158,48 @@ function flattenTree() {
|
|
|
145
158
|
/**
|
|
146
159
|
* Transform given style tree into a set of style declarations.
|
|
147
160
|
*
|
|
148
|
-
* @param {Object}
|
|
161
|
+
* @param {Object} blockStyles Block styles.
|
|
162
|
+
*
|
|
163
|
+
* @param {string} selector The selector these declarations should attach to.
|
|
164
|
+
*
|
|
165
|
+
* @param {boolean} useRootPaddingAlign Whether to use CSS custom properties in root selector.
|
|
166
|
+
*
|
|
167
|
+
* @param {Object} tree A theme.json tree containing layout definitions.
|
|
149
168
|
*
|
|
150
169
|
* @return {Array} An array of style declarations.
|
|
151
170
|
*/
|
|
152
171
|
|
|
153
172
|
|
|
154
|
-
function getStylesDeclarations() {
|
|
173
|
+
export function getStylesDeclarations() {
|
|
155
174
|
let blockStyles = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
175
|
+
let selector = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
176
|
+
let useRootPaddingAlign = arguments.length > 2 ? arguments[2] : undefined;
|
|
177
|
+
let tree = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
178
|
+
const isRoot = ROOT_BLOCK_SELECTOR === selector;
|
|
156
179
|
const output = reduce(STYLE_PROPERTY, (declarations, _ref5, key) => {
|
|
157
180
|
let {
|
|
158
181
|
value,
|
|
159
182
|
properties,
|
|
160
|
-
useEngine
|
|
183
|
+
useEngine,
|
|
184
|
+
rootOnly
|
|
161
185
|
} = _ref5;
|
|
186
|
+
|
|
187
|
+
if (rootOnly && !isRoot) {
|
|
188
|
+
return declarations;
|
|
189
|
+
}
|
|
190
|
+
|
|
162
191
|
const pathToValue = value;
|
|
163
192
|
|
|
164
193
|
if (first(pathToValue) === 'elements' || useEngine) {
|
|
165
194
|
return declarations;
|
|
166
195
|
}
|
|
167
196
|
|
|
168
|
-
const styleValue = get(blockStyles, pathToValue);
|
|
197
|
+
const styleValue = get(blockStyles, pathToValue); // Root-level padding styles don't currently support strings with CSS shorthand values.
|
|
198
|
+
// This may change: https://github.com/WordPress/gutenberg/issues/40132.
|
|
199
|
+
|
|
200
|
+
if (key === '--wp--style--root--padding' && (typeof styleValue === 'string' || !useRootPaddingAlign)) {
|
|
201
|
+
return declarations;
|
|
202
|
+
}
|
|
169
203
|
|
|
170
204
|
if (!!properties && typeof styleValue !== 'string') {
|
|
171
205
|
Object.entries(properties).forEach(entry => {
|
|
@@ -177,7 +211,7 @@ function getStylesDeclarations() {
|
|
|
177
211
|
return;
|
|
178
212
|
}
|
|
179
213
|
|
|
180
|
-
const cssProperty = kebabCase(name);
|
|
214
|
+
const cssProperty = name.startsWith('--') ? name : kebabCase(name);
|
|
181
215
|
declarations.push(`${cssProperty}: ${compileStyleValue(get(styleValue, [prop]))}`);
|
|
182
216
|
});
|
|
183
217
|
} else if (get(blockStyles, pathToValue, false)) {
|
|
@@ -191,8 +225,29 @@ function getStylesDeclarations() {
|
|
|
191
225
|
|
|
192
226
|
const extraRules = getCSSRules(blockStyles);
|
|
193
227
|
extraRules.forEach(rule => {
|
|
228
|
+
var _ruleValue;
|
|
229
|
+
|
|
230
|
+
// Don't output padding properties if padding variables are set.
|
|
231
|
+
if (isRoot && useRootPaddingAlign && rule.key.startsWith('padding')) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
|
|
194
235
|
const cssProperty = rule.key.startsWith('--') ? rule.key : kebabCase(rule.key);
|
|
195
|
-
|
|
236
|
+
let ruleValue = rule.value;
|
|
237
|
+
|
|
238
|
+
if (typeof ruleValue !== 'string' && (_ruleValue = ruleValue) !== null && _ruleValue !== void 0 && _ruleValue.ref) {
|
|
239
|
+
var _ruleValue2;
|
|
240
|
+
|
|
241
|
+
const refPath = ruleValue.ref.split('.');
|
|
242
|
+
ruleValue = get(tree, refPath); // Presence of another ref indicates a reference to another dynamic value.
|
|
243
|
+
// Pointing to another dynamic value is not supported.
|
|
244
|
+
|
|
245
|
+
if (!ruleValue || !!((_ruleValue2 = ruleValue) !== null && _ruleValue2 !== void 0 && _ruleValue2.ref)) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
output.push(`${cssProperty}: ${ruleValue}`);
|
|
196
251
|
});
|
|
197
252
|
return output;
|
|
198
253
|
}
|
|
@@ -210,7 +265,6 @@ function getStylesDeclarations() {
|
|
|
210
265
|
* @return {string} Generated CSS rules for the layout styles.
|
|
211
266
|
*/
|
|
212
267
|
|
|
213
|
-
|
|
214
268
|
export function getLayoutStyles(_ref6) {
|
|
215
269
|
var _style$spacing, _tree$settings, _tree$settings$layout, _tree$settings2, _tree$settings2$layou;
|
|
216
270
|
|
|
@@ -259,7 +313,15 @@ export function getLayoutStyles(_ref6) {
|
|
|
259
313
|
}
|
|
260
314
|
|
|
261
315
|
if (declarations.length) {
|
|
262
|
-
|
|
316
|
+
let combinedSelector = '';
|
|
317
|
+
|
|
318
|
+
if (!hasBlockGapSupport) {
|
|
319
|
+
// For fallback gap styles, use lower specificity, to ensure styles do not unintentionally override theme styles.
|
|
320
|
+
combinedSelector = selector === ROOT_BLOCK_SELECTOR ? `:where(.${className}${(spacingStyle === null || spacingStyle === void 0 ? void 0 : spacingStyle.selector) || ''})` : `:where(${selector}.${className}${(spacingStyle === null || spacingStyle === void 0 ? void 0 : spacingStyle.selector) || ''})`;
|
|
321
|
+
} else {
|
|
322
|
+
combinedSelector = selector === ROOT_BLOCK_SELECTOR ? `${selector} .${className}${(spacingStyle === null || spacingStyle === void 0 ? void 0 : spacingStyle.selector) || ''}` : `${selector}.${className}${(spacingStyle === null || spacingStyle === void 0 ? void 0 : spacingStyle.selector) || ''}`;
|
|
323
|
+
}
|
|
324
|
+
|
|
263
325
|
ruleset += `${combinedSelector} { ${declarations.join('; ')}; }`;
|
|
264
326
|
}
|
|
265
327
|
});
|
|
@@ -308,7 +370,7 @@ export function getLayoutStyles(_ref6) {
|
|
|
308
370
|
return ruleset;
|
|
309
371
|
}
|
|
310
372
|
export const getNodesWithStyles = (tree, blockSelectors) => {
|
|
311
|
-
var _tree$
|
|
373
|
+
var _tree$styles3;
|
|
312
374
|
|
|
313
375
|
const nodes = [];
|
|
314
376
|
|
|
@@ -328,16 +390,20 @@ export const getNodesWithStyles = (tree, blockSelectors) => {
|
|
|
328
390
|
});
|
|
329
391
|
}
|
|
330
392
|
|
|
331
|
-
forEach(
|
|
332
|
-
|
|
393
|
+
forEach(ELEMENTS, (selector, name) => {
|
|
394
|
+
var _tree$styles;
|
|
395
|
+
|
|
396
|
+
if (!!((_tree$styles = tree.styles) !== null && _tree$styles !== void 0 && _tree$styles.elements[name])) {
|
|
397
|
+
var _tree$styles2;
|
|
398
|
+
|
|
333
399
|
nodes.push({
|
|
334
|
-
styles:
|
|
335
|
-
selector
|
|
400
|
+
styles: (_tree$styles2 = tree.styles) === null || _tree$styles2 === void 0 ? void 0 : _tree$styles2.elements[name],
|
|
401
|
+
selector
|
|
336
402
|
});
|
|
337
403
|
}
|
|
338
404
|
}); // Iterate over blocks: they can have styles & elements.
|
|
339
405
|
|
|
340
|
-
forEach((_tree$
|
|
406
|
+
forEach((_tree$styles3 = tree.styles) === null || _tree$styles3 === void 0 ? void 0 : _tree$styles3.blocks, (node, blockName) => {
|
|
341
407
|
var _blockSelectors$block;
|
|
342
408
|
|
|
343
409
|
const blockStyles = pickStyleKeys(node);
|
|
@@ -348,7 +414,8 @@ export const getNodesWithStyles = (tree, blockSelectors) => {
|
|
|
348
414
|
fallbackGapValue: blockSelectors[blockName].fallbackGapValue,
|
|
349
415
|
hasLayoutSupport: blockSelectors[blockName].hasLayoutSupport,
|
|
350
416
|
selector: blockSelectors[blockName].selector,
|
|
351
|
-
styles: blockStyles
|
|
417
|
+
styles: blockStyles,
|
|
418
|
+
featureSelectors: blockSelectors[blockName].featureSelectors
|
|
352
419
|
});
|
|
353
420
|
}
|
|
354
421
|
|
|
@@ -426,7 +493,7 @@ export const toCustomProperties = (tree, blockSelectors) => {
|
|
|
426
493
|
custom,
|
|
427
494
|
selector
|
|
428
495
|
} = _ref12;
|
|
429
|
-
const declarations = getPresetsDeclarations(presets);
|
|
496
|
+
const declarations = getPresetsDeclarations(presets, tree === null || tree === void 0 ? void 0 : tree.settings);
|
|
430
497
|
const customProps = flattenTree(custom, '--wp--custom--', '--');
|
|
431
498
|
|
|
432
499
|
if (customProps.length > 0) {
|
|
@@ -439,9 +506,17 @@ export const toCustomProperties = (tree, blockSelectors) => {
|
|
|
439
506
|
});
|
|
440
507
|
return ruleset;
|
|
441
508
|
};
|
|
442
|
-
export const toStyles = (tree, blockSelectors, hasBlockGapSupport, hasFallbackGapSupport)
|
|
509
|
+
export const toStyles = function (tree, blockSelectors, hasBlockGapSupport, hasFallbackGapSupport) {
|
|
510
|
+
var _tree$settings5, _tree$settings6;
|
|
511
|
+
|
|
512
|
+
let disableLayoutStyles = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
443
513
|
const nodesWithStyles = getNodesWithStyles(tree, blockSelectors);
|
|
444
514
|
const nodesWithSettings = getNodesWithSettings(tree, blockSelectors);
|
|
515
|
+
const useRootPaddingAlign = tree === null || tree === void 0 ? void 0 : (_tree$settings5 = tree.settings) === null || _tree$settings5 === void 0 ? void 0 : _tree$settings5.useRootPaddingAwareAlignments;
|
|
516
|
+
const {
|
|
517
|
+
contentSize,
|
|
518
|
+
wideSize
|
|
519
|
+
} = (tree === null || tree === void 0 ? void 0 : (_tree$settings6 = tree.settings) === null || _tree$settings6 === void 0 ? void 0 : _tree$settings6.layout) || {};
|
|
445
520
|
/*
|
|
446
521
|
* Reset default browser margin on the root body element.
|
|
447
522
|
* This is set on the root selector **before** generating the ruleset
|
|
@@ -451,15 +526,51 @@ export const toStyles = (tree, blockSelectors, hasBlockGapSupport, hasFallbackGa
|
|
|
451
526
|
* @link https://github.com/WordPress/gutenberg/issues/36147.
|
|
452
527
|
*/
|
|
453
528
|
|
|
454
|
-
let ruleset = 'body {margin: 0;
|
|
529
|
+
let ruleset = 'body {margin: 0;';
|
|
530
|
+
|
|
531
|
+
if (contentSize) {
|
|
532
|
+
ruleset += ` --wp--style--global--content-size: ${contentSize};`;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
if (wideSize) {
|
|
536
|
+
ruleset += ` --wp--style--global--wide-size: ${wideSize};`;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
if (useRootPaddingAlign) {
|
|
540
|
+
ruleset += '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);';
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
ruleset += '}';
|
|
455
544
|
nodesWithStyles.forEach(_ref13 => {
|
|
456
545
|
let {
|
|
457
546
|
selector,
|
|
458
547
|
duotoneSelector,
|
|
459
548
|
styles,
|
|
460
549
|
fallbackGapValue,
|
|
461
|
-
hasLayoutSupport
|
|
550
|
+
hasLayoutSupport,
|
|
551
|
+
featureSelectors
|
|
462
552
|
} = _ref13;
|
|
553
|
+
|
|
554
|
+
// Process styles for block support features with custom feature level
|
|
555
|
+
// CSS selectors set.
|
|
556
|
+
if (featureSelectors) {
|
|
557
|
+
Object.entries(featureSelectors).forEach(_ref14 => {
|
|
558
|
+
let [featureName, featureSelector] = _ref14;
|
|
559
|
+
|
|
560
|
+
if (styles !== null && styles !== void 0 && styles[featureName]) {
|
|
561
|
+
const featureStyles = {
|
|
562
|
+
[featureName]: styles[featureName]
|
|
563
|
+
};
|
|
564
|
+
const featureDeclarations = getStylesDeclarations(featureStyles);
|
|
565
|
+
delete styles[featureName];
|
|
566
|
+
|
|
567
|
+
if (!!featureDeclarations.length) {
|
|
568
|
+
ruleset = ruleset + `${featureSelector}{${featureDeclarations.join(';')} }`;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
|
|
463
574
|
const duotoneStyles = {};
|
|
464
575
|
|
|
465
576
|
if (styles !== null && styles !== void 0 && styles.filter) {
|
|
@@ -471,15 +582,13 @@ export const toStyles = (tree, blockSelectors, hasBlockGapSupport, hasFallbackGa
|
|
|
471
582
|
if (duotoneSelector) {
|
|
472
583
|
const duotoneDeclarations = getStylesDeclarations(duotoneStyles);
|
|
473
584
|
|
|
474
|
-
if (duotoneDeclarations.length
|
|
475
|
-
|
|
585
|
+
if (duotoneDeclarations.length > 0) {
|
|
586
|
+
ruleset = ruleset + `${duotoneSelector}{${duotoneDeclarations.join(';')};}`;
|
|
476
587
|
}
|
|
477
|
-
|
|
478
|
-
ruleset = ruleset + `${duotoneSelector}{${duotoneDeclarations.join(';')};}`;
|
|
479
588
|
} // Process blockGap and layout styles.
|
|
480
589
|
|
|
481
590
|
|
|
482
|
-
if (ROOT_BLOCK_SELECTOR === selector || hasLayoutSupport) {
|
|
591
|
+
if (!disableLayoutStyles && (ROOT_BLOCK_SELECTOR === selector || hasLayoutSupport)) {
|
|
483
592
|
ruleset += getLayoutStyles({
|
|
484
593
|
tree,
|
|
485
594
|
style: styles,
|
|
@@ -491,28 +600,28 @@ export const toStyles = (tree, blockSelectors, hasBlockGapSupport, hasFallbackGa
|
|
|
491
600
|
} // Process the remaining block styles (they use either normal block class or __experimentalSelector).
|
|
492
601
|
|
|
493
602
|
|
|
494
|
-
const declarations = getStylesDeclarations(styles);
|
|
603
|
+
const declarations = getStylesDeclarations(styles, selector, useRootPaddingAlign, tree);
|
|
495
604
|
|
|
496
605
|
if (declarations !== null && declarations !== void 0 && declarations.length) {
|
|
497
606
|
ruleset = ruleset + `${selector}{${declarations.join(';')};}`;
|
|
498
607
|
} // Check for pseudo selector in `styles` and handle separately.
|
|
499
608
|
|
|
500
609
|
|
|
501
|
-
const pseudoSelectorStyles = Object.entries(styles).filter(
|
|
502
|
-
let [key] =
|
|
610
|
+
const pseudoSelectorStyles = Object.entries(styles).filter(_ref15 => {
|
|
611
|
+
let [key] = _ref15;
|
|
503
612
|
return key.startsWith(':');
|
|
504
613
|
});
|
|
505
614
|
|
|
506
615
|
if (pseudoSelectorStyles !== null && pseudoSelectorStyles !== void 0 && pseudoSelectorStyles.length) {
|
|
507
|
-
pseudoSelectorStyles.forEach(
|
|
508
|
-
let [pseudoKey, pseudoStyle] =
|
|
616
|
+
pseudoSelectorStyles.forEach(_ref16 => {
|
|
617
|
+
let [pseudoKey, pseudoStyle] = _ref16;
|
|
509
618
|
const pseudoDeclarations = getStylesDeclarations(pseudoStyle);
|
|
510
619
|
|
|
511
620
|
if (!(pseudoDeclarations !== null && pseudoDeclarations !== void 0 && pseudoDeclarations.length)) {
|
|
512
621
|
return;
|
|
513
622
|
} // `selector` maybe provided in a form
|
|
514
623
|
// where block level selectors have sub element
|
|
515
|
-
// selectors appended to them as a comma
|
|
624
|
+
// selectors appended to them as a comma separated
|
|
516
625
|
// string.
|
|
517
626
|
// e.g. `h1 a,h2 a,h3 a,h4 a,h5 a,h6 a`;
|
|
518
627
|
// Split and append pseudo selector to create
|
|
@@ -533,19 +642,19 @@ export const toStyles = (tree, blockSelectors, hasBlockGapSupport, hasFallbackGa
|
|
|
533
642
|
ruleset = ruleset + '.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }';
|
|
534
643
|
|
|
535
644
|
if (hasBlockGapSupport) {
|
|
536
|
-
var _tree$
|
|
645
|
+
var _tree$styles4, _tree$styles4$spacing;
|
|
537
646
|
|
|
538
647
|
// Use fallback of `0.5em` just in case, however if there is blockGap support, there should nearly always be a real value.
|
|
539
|
-
const gapValue = getGapCSSValue(tree === null || tree === void 0 ? void 0 : (_tree$
|
|
648
|
+
const gapValue = getGapCSSValue(tree === null || tree === void 0 ? void 0 : (_tree$styles4 = tree.styles) === null || _tree$styles4 === void 0 ? void 0 : (_tree$styles4$spacing = _tree$styles4.spacing) === null || _tree$styles4$spacing === void 0 ? void 0 : _tree$styles4$spacing.blockGap) || '0.5em';
|
|
540
649
|
ruleset = ruleset + '.wp-site-blocks > * { margin-block-start: 0; margin-block-end: 0; }';
|
|
541
650
|
ruleset = ruleset + `.wp-site-blocks > * + * { margin-block-start: ${gapValue}; }`;
|
|
542
651
|
}
|
|
543
652
|
|
|
544
|
-
nodesWithSettings.forEach(
|
|
653
|
+
nodesWithSettings.forEach(_ref17 => {
|
|
545
654
|
let {
|
|
546
655
|
selector,
|
|
547
656
|
presets
|
|
548
|
-
} =
|
|
657
|
+
} = _ref17;
|
|
549
658
|
|
|
550
659
|
if (ROOT_BLOCK_SELECTOR === selector) {
|
|
551
660
|
// Do not add extra specificity for top-level classes.
|
|
@@ -562,15 +671,14 @@ export const toStyles = (tree, blockSelectors, hasBlockGapSupport, hasFallbackGa
|
|
|
562
671
|
};
|
|
563
672
|
export function toSvgFilters(tree, blockSelectors) {
|
|
564
673
|
const nodesWithSettings = getNodesWithSettings(tree, blockSelectors);
|
|
565
|
-
return nodesWithSettings.flatMap(
|
|
674
|
+
return nodesWithSettings.flatMap(_ref18 => {
|
|
566
675
|
let {
|
|
567
676
|
presets
|
|
568
|
-
} =
|
|
677
|
+
} = _ref18;
|
|
569
678
|
return getPresetsSvgFilters(presets);
|
|
570
679
|
});
|
|
571
680
|
}
|
|
572
|
-
|
|
573
|
-
const getBlockSelectors = blockTypes => {
|
|
681
|
+
export const getBlockSelectors = blockTypes => {
|
|
574
682
|
const result = {};
|
|
575
683
|
blockTypes.forEach(blockType => {
|
|
576
684
|
var _blockType$supports$_, _blockType$supports, _blockType$supports$c, _blockType$supports2, _blockType$supports2$, _blockType$supports3, _blockType$supports4, _blockType$supports4$, _blockType$supports4$2;
|
|
@@ -579,10 +687,23 @@ const getBlockSelectors = blockTypes => {
|
|
|
579
687
|
const selector = (_blockType$supports$_ = blockType === null || blockType === void 0 ? void 0 : (_blockType$supports = blockType.supports) === null || _blockType$supports === void 0 ? void 0 : _blockType$supports.__experimentalSelector) !== null && _blockType$supports$_ !== void 0 ? _blockType$supports$_ : '.wp-block-' + name.replace('core/', '').replace('/', '-');
|
|
580
688
|
const duotoneSelector = (_blockType$supports$c = blockType === null || blockType === void 0 ? void 0 : (_blockType$supports2 = blockType.supports) === null || _blockType$supports2 === void 0 ? void 0 : (_blockType$supports2$ = _blockType$supports2.color) === null || _blockType$supports2$ === void 0 ? void 0 : _blockType$supports2$.__experimentalDuotone) !== null && _blockType$supports$c !== void 0 ? _blockType$supports$c : null;
|
|
581
689
|
const hasLayoutSupport = !!(blockType !== null && blockType !== void 0 && (_blockType$supports3 = blockType.supports) !== null && _blockType$supports3 !== void 0 && _blockType$supports3.__experimentalLayout);
|
|
582
|
-
const fallbackGapValue = blockType === null || blockType === void 0 ? void 0 : (_blockType$supports4 = blockType.supports) === null || _blockType$supports4 === void 0 ? void 0 : (_blockType$supports4$ = _blockType$supports4.spacing) === null || _blockType$supports4$ === void 0 ? void 0 : (_blockType$supports4$2 = _blockType$supports4$.blockGap) === null || _blockType$supports4$2 === void 0 ? void 0 : _blockType$supports4$2.__experimentalDefault;
|
|
690
|
+
const fallbackGapValue = blockType === null || blockType === void 0 ? void 0 : (_blockType$supports4 = blockType.supports) === null || _blockType$supports4 === void 0 ? void 0 : (_blockType$supports4$ = _blockType$supports4.spacing) === null || _blockType$supports4$ === void 0 ? void 0 : (_blockType$supports4$2 = _blockType$supports4$.blockGap) === null || _blockType$supports4$2 === void 0 ? void 0 : _blockType$supports4$2.__experimentalDefault; // For each block support feature add any custom selectors.
|
|
691
|
+
|
|
692
|
+
const featureSelectors = {};
|
|
693
|
+
Object.entries(BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS).forEach(_ref19 => {
|
|
694
|
+
var _blockType$supports5, _blockType$supports5$;
|
|
695
|
+
|
|
696
|
+
let [featureKey, featureName] = _ref19;
|
|
697
|
+
const featureSelector = blockType === null || blockType === void 0 ? void 0 : (_blockType$supports5 = blockType.supports) === null || _blockType$supports5 === void 0 ? void 0 : (_blockType$supports5$ = _blockType$supports5[featureKey]) === null || _blockType$supports5$ === void 0 ? void 0 : _blockType$supports5$.__experimentalSelector;
|
|
698
|
+
|
|
699
|
+
if (featureSelector) {
|
|
700
|
+
featureSelectors[featureName] = scopeSelector(selector, featureSelector);
|
|
701
|
+
}
|
|
702
|
+
});
|
|
583
703
|
result[name] = {
|
|
584
704
|
duotoneSelector,
|
|
585
705
|
fallbackGapValue,
|
|
706
|
+
featureSelectors: Object.keys(featureSelectors).length ? featureSelectors : undefined,
|
|
586
707
|
hasLayoutSupport,
|
|
587
708
|
name,
|
|
588
709
|
selector
|
|
@@ -590,11 +711,7 @@ const getBlockSelectors = blockTypes => {
|
|
|
590
711
|
});
|
|
591
712
|
return result;
|
|
592
713
|
};
|
|
593
|
-
|
|
594
714
|
export function useGlobalStylesOutput() {
|
|
595
|
-
const [stylesheets, setStylesheets] = useState([]);
|
|
596
|
-
const [settings, setSettings] = useState({});
|
|
597
|
-
const [svgFilters, setSvgFilters] = useState({});
|
|
598
715
|
const {
|
|
599
716
|
merged: mergedConfig
|
|
600
717
|
} = useContext(GlobalStylesContext);
|
|
@@ -602,25 +719,29 @@ export function useGlobalStylesOutput() {
|
|
|
602
719
|
const hasBlockGapSupport = blockGap !== null;
|
|
603
720
|
const hasFallbackGapSupport = !hasBlockGapSupport; // This setting isn't useful yet: it exists as a placeholder for a future explicit fallback styles support.
|
|
604
721
|
|
|
605
|
-
|
|
722
|
+
const disableLayoutStyles = useSelect(select => {
|
|
723
|
+
const {
|
|
724
|
+
getSettings
|
|
725
|
+
} = select(blockEditorStore);
|
|
726
|
+
return !!getSettings().disableLayoutStyles;
|
|
727
|
+
});
|
|
728
|
+
return useMemo(() => {
|
|
606
729
|
if (!(mergedConfig !== null && mergedConfig !== void 0 && mergedConfig.styles) || !(mergedConfig !== null && mergedConfig !== void 0 && mergedConfig.settings)) {
|
|
607
|
-
return;
|
|
730
|
+
return [];
|
|
608
731
|
}
|
|
609
732
|
|
|
610
733
|
const blockSelectors = getBlockSelectors(getBlockTypes());
|
|
611
734
|
const customProperties = toCustomProperties(mergedConfig, blockSelectors);
|
|
612
|
-
const globalStyles = toStyles(mergedConfig, blockSelectors, hasBlockGapSupport, hasFallbackGapSupport);
|
|
735
|
+
const globalStyles = toStyles(mergedConfig, blockSelectors, hasBlockGapSupport, hasFallbackGapSupport, disableLayoutStyles);
|
|
613
736
|
const filters = toSvgFilters(mergedConfig, blockSelectors);
|
|
614
|
-
|
|
737
|
+
const stylesheets = [{
|
|
615
738
|
css: customProperties,
|
|
616
739
|
isGlobalStyles: true
|
|
617
740
|
}, {
|
|
618
741
|
css: globalStyles,
|
|
619
742
|
isGlobalStyles: true
|
|
620
|
-
}]
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
}, [hasBlockGapSupport, hasFallbackGapSupport, mergedConfig]);
|
|
624
|
-
return [stylesheets, settings, svgFilters, hasBlockGapSupport];
|
|
743
|
+
}];
|
|
744
|
+
return [stylesheets, mergedConfig.settings, filters];
|
|
745
|
+
}, [hasBlockGapSupport, hasFallbackGapSupport, mergedConfig, disableLayoutStyles]);
|
|
625
746
|
}
|
|
626
747
|
//# sourceMappingURL=use-global-styles-output.js.map
|