@wordpress/edit-site 4.9.0 → 4.10.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/add-new-template/add-custom-generic-template-modal.js +84 -0
- package/build/components/add-new-template/add-custom-generic-template-modal.js.map +1 -0
- package/build/components/add-new-template/add-custom-template-modal.js +92 -53
- package/build/components/add-new-template/add-custom-template-modal.js.map +1 -1
- package/build/components/add-new-template/new-template.js +77 -81
- package/build/components/add-new-template/new-template.js.map +1 -1
- package/build/components/add-new-template/utils.js +310 -44
- package/build/components/add-new-template/utils.js.map +1 -1
- package/build/components/code-editor/index.js +17 -4
- package/build/components/code-editor/index.js.map +1 -1
- package/build/components/editor/index.js +16 -0
- package/build/components/editor/index.js.map +1 -1
- package/build/components/error-boundary/index.js +6 -0
- package/build/components/error-boundary/index.js.map +1 -1
- package/build/components/global-styles/dimensions-panel.js +2 -6
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/global-styles/global-styles-provider.js +4 -2
- package/build/components/global-styles/global-styles-provider.js.map +1 -1
- package/build/components/global-styles/hooks.js +10 -1
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/screen-color-palette.js +13 -17
- package/build/components/global-styles/screen-color-palette.js.map +1 -1
- package/build/components/global-styles/screen-colors.js +9 -1
- package/build/components/global-styles/screen-colors.js.map +1 -1
- package/build/components/global-styles/screen-link-color.js +48 -14
- package/build/components/global-styles/screen-link-color.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +171 -33
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/global-styles/utils.js +1 -1
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/index.js +1 -3
- package/build/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build/components/template-details/edit-template-title.js +11 -3
- package/build/components/template-details/edit-template-title.js.map +1 -1
- package/build/components/template-details/index.js +1 -20
- package/build/components/template-details/index.js.map +1 -1
- package/build/store/selectors.js +4 -1
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/add-new-template/add-custom-generic-template-modal.js +77 -0
- package/build-module/components/add-new-template/add-custom-generic-template-modal.js.map +1 -0
- package/build-module/components/add-new-template/add-custom-template-modal.js +92 -53
- 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 +80 -83
- package/build-module/components/add-new-template/new-template.js.map +1 -1
- package/build-module/components/add-new-template/utils.js +286 -40
- package/build-module/components/add-new-template/utils.js.map +1 -1
- package/build-module/components/code-editor/index.js +18 -5
- package/build-module/components/code-editor/index.js.map +1 -1
- package/build-module/components/editor/index.js +16 -0
- package/build-module/components/editor/index.js.map +1 -1
- package/build-module/components/error-boundary/index.js +5 -0
- package/build-module/components/error-boundary/index.js.map +1 -1
- package/build-module/components/global-styles/dimensions-panel.js +2 -6
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/global-styles/global-styles-provider.js +4 -2
- package/build-module/components/global-styles/global-styles-provider.js.map +1 -1
- package/build-module/components/global-styles/hooks.js +10 -1
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/screen-color-palette.js +14 -19
- package/build-module/components/global-styles/screen-color-palette.js.map +1 -1
- package/build-module/components/global-styles/screen-colors.js +9 -1
- package/build-module/components/global-styles/screen-colors.js.map +1 -1
- package/build-module/components/global-styles/screen-link-color.js +47 -14
- package/build-module/components/global-styles/screen-link-color.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +171 -35
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/global-styles/utils.js +2 -2
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/index.js +1 -2
- package/build-module/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build-module/components/template-details/edit-template-title.js +12 -3
- package/build-module/components/template-details/edit-template-title.js.map +1 -1
- package/build-module/components/template-details/index.js +2 -21
- package/build-module/components/template-details/index.js.map +1 -1
- package/build-module/store/selectors.js +5 -2
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +21 -23
- package/build-style/style.css +21 -23
- package/package.json +29 -29
- package/src/components/add-new-template/add-custom-generic-template-modal.js +97 -0
- package/src/components/add-new-template/add-custom-template-modal.js +92 -58
- package/src/components/add-new-template/new-template.js +142 -94
- package/src/components/add-new-template/style.scss +21 -0
- package/src/components/add-new-template/utils.js +290 -46
- package/src/components/code-editor/index.js +15 -5
- package/src/components/editor/index.js +11 -0
- package/src/components/error-boundary/index.js +5 -0
- package/src/components/global-styles/dimensions-panel.js +2 -7
- package/src/components/global-styles/global-styles-provider.js +8 -9
- package/src/components/global-styles/hooks.js +15 -0
- package/src/components/global-styles/screen-color-palette.js +25 -27
- package/src/components/global-styles/screen-colors.js +9 -3
- package/src/components/global-styles/screen-link-color.js +65 -23
- package/src/components/global-styles/style.scss +7 -11
- package/src/components/global-styles/test/use-global-styles-output.js +168 -0
- package/src/components/global-styles/use-global-styles-output.js +234 -59
- package/src/components/global-styles/utils.js +2 -2
- package/src/components/keyboard-shortcut-help-modal/index.js +1 -2
- package/src/components/keyboard-shortcut-help-modal/style.scss +0 -5
- package/src/components/list/style.scss +0 -8
- package/src/components/template-details/edit-template-title.js +10 -2
- package/src/components/template-details/index.js +4 -21
- package/src/components/test/error-boundary.js +38 -0
- package/src/store/selectors.js +11 -5
|
@@ -5,6 +5,7 @@ import { createElement, Fragment } from "@wordpress/element";
|
|
|
5
5
|
*/
|
|
6
6
|
import { __ } from '@wordpress/i18n';
|
|
7
7
|
import { __experimentalColorGradientControl as ColorGradientControl } from '@wordpress/block-editor';
|
|
8
|
+
import { TabPanel } from '@wordpress/components';
|
|
8
9
|
/**
|
|
9
10
|
* Internal dependencies
|
|
10
11
|
*/
|
|
@@ -22,27 +23,59 @@ function ScreenLinkColor(_ref) {
|
|
|
22
23
|
const colorsPerOrigin = useColorsPerOrigin(name);
|
|
23
24
|
const [isLinkEnabled] = useSetting('color.link', name);
|
|
24
25
|
const hasLinkColor = supports.includes('linkColor') && isLinkEnabled && (solids.length > 0 || areCustomSolidsEnabled);
|
|
25
|
-
const
|
|
26
|
-
|
|
26
|
+
const pseudoStates = {
|
|
27
|
+
default: {
|
|
28
|
+
label: __('Default'),
|
|
29
|
+
value: useStyle('elements.link.color.text', name)[0],
|
|
30
|
+
handler: useStyle('elements.link.color.text', name)[1],
|
|
31
|
+
userValue: useStyle('elements.link.color.text', name, 'user')[0]
|
|
32
|
+
},
|
|
33
|
+
hover: {
|
|
34
|
+
label: __('Hover'),
|
|
35
|
+
value: useStyle('elements.link.:hover.color.text', name)[0],
|
|
36
|
+
handler: useStyle('elements.link.:hover.color.text', name)[1],
|
|
37
|
+
userValue: useStyle('elements.link.:hover.color.text', name, 'user')[0]
|
|
38
|
+
}
|
|
39
|
+
};
|
|
27
40
|
|
|
28
41
|
if (!hasLinkColor) {
|
|
29
42
|
return null;
|
|
30
43
|
}
|
|
31
44
|
|
|
45
|
+
const tabs = Object.entries(pseudoStates).map(_ref2 => {
|
|
46
|
+
let [selector, config] = _ref2;
|
|
47
|
+
return {
|
|
48
|
+
name: selector,
|
|
49
|
+
title: config.label,
|
|
50
|
+
className: `color-text-${selector}`
|
|
51
|
+
};
|
|
52
|
+
});
|
|
32
53
|
return createElement(Fragment, null, createElement(ScreenHeader, {
|
|
33
54
|
title: __('Links'),
|
|
34
|
-
description: __('Set the
|
|
35
|
-
}), createElement(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
55
|
+
description: __('Set the colors used for links across the site.')
|
|
56
|
+
}), createElement(TabPanel, {
|
|
57
|
+
tabs: tabs
|
|
58
|
+
}, tab => {
|
|
59
|
+
var _pseudoStates$tab$nam;
|
|
60
|
+
|
|
61
|
+
const pseudoSelectorConfig = (_pseudoStates$tab$nam = pseudoStates[tab.name]) !== null && _pseudoStates$tab$nam !== void 0 ? _pseudoStates$tab$nam : null;
|
|
62
|
+
|
|
63
|
+
if (!pseudoSelectorConfig) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return createElement(Fragment, null, createElement(ColorGradientControl, {
|
|
68
|
+
className: "edit-site-screen-link-color__control",
|
|
69
|
+
colors: colorsPerOrigin,
|
|
70
|
+
disableCustomColors: !areCustomSolidsEnabled,
|
|
71
|
+
__experimentalHasMultipleOrigins: true,
|
|
72
|
+
showTitle: false,
|
|
73
|
+
enableAlpha: true,
|
|
74
|
+
__experimentalIsRenderedInSidebar: true,
|
|
75
|
+
colorValue: pseudoSelectorConfig.value,
|
|
76
|
+
onColorChange: pseudoSelectorConfig.handler,
|
|
77
|
+
clearable: pseudoSelectorConfig.value === pseudoSelectorConfig.userValue
|
|
78
|
+
}));
|
|
46
79
|
}));
|
|
47
80
|
}
|
|
48
81
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/global-styles/screen-link-color.js"],"names":["__","__experimentalColorGradientControl","ColorGradientControl","ScreenHeader","getSupportedGlobalStylesPanels","useSetting","useStyle","useColorsPerOrigin","ScreenLinkColor","name","supports","solids","areCustomSolidsEnabled","colorsPerOrigin","isLinkEnabled","hasLinkColor","includes","length","
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/global-styles/screen-link-color.js"],"names":["__","__experimentalColorGradientControl","ColorGradientControl","TabPanel","ScreenHeader","getSupportedGlobalStylesPanels","useSetting","useStyle","useColorsPerOrigin","ScreenLinkColor","name","supports","solids","areCustomSolidsEnabled","colorsPerOrigin","isLinkEnabled","hasLinkColor","includes","length","pseudoStates","default","label","value","handler","userValue","hover","tabs","Object","entries","map","selector","config","title","className","tab","pseudoSelectorConfig"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,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AAA,UAAU,EAAGsB,oBAAoB,CAACb,KARnC;AASC,MAAA,aAAa,EAAGa,oBAAoB,CAACZ,OATtC;AAUC,MAAA,SAAS,EACRY,oBAAoB,CAACb,KAArB,KACAa,oBAAoB,CAACX;AAZvB,MADD,CADD;AAmBA,GA5BF,CARD,CADD;AAyCA;;AAED,eAAef,eAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { __experimentalColorGradientControl as ColorGradientControl } from '@wordpress/block-editor';\nimport { TabPanel } from '@wordpress/components';\n/**\n * Internal dependencies\n */\nimport ScreenHeader from './header';\nimport {\n\tgetSupportedGlobalStylesPanels,\n\tuseSetting,\n\tuseStyle,\n\tuseColorsPerOrigin,\n} from './hooks';\n\nfunction ScreenLinkColor( { name } ) {\n\tconst supports = getSupportedGlobalStylesPanels( name );\n\tconst [ solids ] = useSetting( 'color.palette', name );\n\tconst [ areCustomSolidsEnabled ] = useSetting( 'color.custom', name );\n\n\tconst colorsPerOrigin = useColorsPerOrigin( name );\n\n\tconst [ isLinkEnabled ] = useSetting( 'color.link', name );\n\n\tconst hasLinkColor =\n\t\tsupports.includes( 'linkColor' ) &&\n\t\tisLinkEnabled &&\n\t\t( solids.length > 0 || areCustomSolidsEnabled );\n\n\tconst pseudoStates = {\n\t\tdefault: {\n\t\t\tlabel: __( 'Default' ),\n\t\t\tvalue: useStyle( 'elements.link.color.text', name )[ 0 ],\n\t\t\thandler: useStyle( 'elements.link.color.text', name )[ 1 ],\n\t\t\tuserValue: useStyle(\n\t\t\t\t'elements.link.color.text',\n\t\t\t\tname,\n\t\t\t\t'user'\n\t\t\t)[ 0 ],\n\t\t},\n\t\thover: {\n\t\t\tlabel: __( 'Hover' ),\n\t\t\tvalue: useStyle( 'elements.link.:hover.color.text', name )[ 0 ],\n\t\t\thandler: useStyle( 'elements.link.:hover.color.text', name )[ 1 ],\n\t\t\tuserValue: useStyle(\n\t\t\t\t'elements.link.:hover.color.text',\n\t\t\t\tname,\n\t\t\t\t'user'\n\t\t\t)[ 0 ],\n\t\t},\n\t};\n\n\tif ( ! hasLinkColor ) {\n\t\treturn null;\n\t}\n\n\tconst tabs = Object.entries( pseudoStates ).map(\n\t\t( [ selector, config ] ) => {\n\t\t\treturn {\n\t\t\t\tname: selector,\n\t\t\t\ttitle: config.label,\n\t\t\t\tclassName: `color-text-${ selector }`,\n\t\t\t};\n\t\t}\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t<ScreenHeader\n\t\t\t\ttitle={ __( 'Links' ) }\n\t\t\t\tdescription={ __(\n\t\t\t\t\t'Set the colors used for links across the site.'\n\t\t\t\t) }\n\t\t\t/>\n\n\t\t\t<TabPanel tabs={ tabs }>\n\t\t\t\t{ ( tab ) => {\n\t\t\t\t\tconst pseudoSelectorConfig =\n\t\t\t\t\t\tpseudoStates[ tab.name ] ?? null;\n\n\t\t\t\t\tif ( ! pseudoSelectorConfig ) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<ColorGradientControl\n\t\t\t\t\t\t\t\tclassName=\"edit-site-screen-link-color__control\"\n\t\t\t\t\t\t\t\tcolors={ colorsPerOrigin }\n\t\t\t\t\t\t\t\tdisableCustomColors={ ! areCustomSolidsEnabled }\n\t\t\t\t\t\t\t\t__experimentalHasMultipleOrigins\n\t\t\t\t\t\t\t\tshowTitle={ false }\n\t\t\t\t\t\t\t\tenableAlpha\n\t\t\t\t\t\t\t\t__experimentalIsRenderedInSidebar\n\t\t\t\t\t\t\t\tcolorValue={ pseudoSelectorConfig.value }\n\t\t\t\t\t\t\t\tonColorChange={ pseudoSelectorConfig.handler }\n\t\t\t\t\t\t\t\tclearable={\n\t\t\t\t\t\t\t\t\tpseudoSelectorConfig.value ===\n\t\t\t\t\t\t\t\t\tpseudoSelectorConfig.userValue\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</>\n\t\t\t\t\t);\n\t\t\t\t} }\n\t\t\t</TabPanel>\n\t\t</>\n\t);\n}\n\nexport default ScreenLinkColor;\n"]}
|
|
@@ -3,7 +3,7 @@ import { createElement } from "@wordpress/element";
|
|
|
3
3
|
/**
|
|
4
4
|
* External dependencies
|
|
5
5
|
*/
|
|
6
|
-
import { first, forEach, get, isEmpty,
|
|
6
|
+
import { first, forEach, get, isEmpty, kebabCase, pickBy, reduce, set, startsWith } from 'lodash';
|
|
7
7
|
/**
|
|
8
8
|
* WordPress dependencies
|
|
9
9
|
*/
|
|
@@ -11,7 +11,7 @@ import { first, forEach, get, isEmpty, isString, kebabCase, pickBy, reduce, set,
|
|
|
11
11
|
import { __EXPERIMENTAL_STYLE_PROPERTY as STYLE_PROPERTY, __EXPERIMENTAL_ELEMENTS as ELEMENTS, getBlockTypes } from '@wordpress/blocks';
|
|
12
12
|
import { useEffect, useState, useContext } from '@wordpress/element';
|
|
13
13
|
import { getCSSRules } from '@wordpress/style-engine';
|
|
14
|
-
import { __unstablePresetDuotoneFilter as PresetDuotoneFilter } from '@wordpress/block-editor';
|
|
14
|
+
import { __unstablePresetDuotoneFilter as PresetDuotoneFilter, __experimentalGetGapCSSValue as getGapCSSValue } from '@wordpress/block-editor';
|
|
15
15
|
/**
|
|
16
16
|
* Internal dependencies
|
|
17
17
|
*/
|
|
@@ -167,7 +167,7 @@ function getStylesDeclarations() {
|
|
|
167
167
|
|
|
168
168
|
const styleValue = get(blockStyles, pathToValue);
|
|
169
169
|
|
|
170
|
-
if (!!properties &&
|
|
170
|
+
if (!!properties && typeof styleValue !== 'string') {
|
|
171
171
|
Object.entries(properties).forEach(entry => {
|
|
172
172
|
const [name, prop] = entry;
|
|
173
173
|
|
|
@@ -196,7 +196,117 @@ function getStylesDeclarations() {
|
|
|
196
196
|
});
|
|
197
197
|
return output;
|
|
198
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Get generated CSS for layout styles by looking up layout definitions provided
|
|
201
|
+
* in theme.json, and outputting common layout styles, and specific blockGap values.
|
|
202
|
+
*
|
|
203
|
+
* @param {Object} props
|
|
204
|
+
* @param {Object} props.tree A theme.json tree containing layout definitions.
|
|
205
|
+
* @param {Object} props.style A style object containing spacing values.
|
|
206
|
+
* @param {string} props.selector Selector used to group together layout styling rules.
|
|
207
|
+
* @param {boolean} props.hasBlockGapSupport Whether or not the theme opts-in to blockGap support.
|
|
208
|
+
* @param {boolean} props.hasFallbackGapSupport Whether or not the theme allows fallback gap styles.
|
|
209
|
+
* @param {?string} props.fallbackGapValue An optional fallback gap value if no real gap value is available.
|
|
210
|
+
* @return {string} Generated CSS rules for the layout styles.
|
|
211
|
+
*/
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
export function getLayoutStyles(_ref6) {
|
|
215
|
+
var _style$spacing, _tree$settings, _tree$settings$layout, _tree$settings2, _tree$settings2$layou;
|
|
216
|
+
|
|
217
|
+
let {
|
|
218
|
+
tree,
|
|
219
|
+
style,
|
|
220
|
+
selector,
|
|
221
|
+
hasBlockGapSupport,
|
|
222
|
+
hasFallbackGapSupport,
|
|
223
|
+
fallbackGapValue
|
|
224
|
+
} = _ref6;
|
|
225
|
+
let ruleset = '';
|
|
226
|
+
let gapValue = hasBlockGapSupport ? getGapCSSValue(style === null || style === void 0 ? void 0 : (_style$spacing = style.spacing) === null || _style$spacing === void 0 ? void 0 : _style$spacing.blockGap) : ''; // Ensure a fallback gap value for the root layout definitions,
|
|
227
|
+
// and use a fallback value if one is provided for the current block.
|
|
228
|
+
|
|
229
|
+
if (hasFallbackGapSupport) {
|
|
230
|
+
if (selector === ROOT_BLOCK_SELECTOR) {
|
|
231
|
+
gapValue = !gapValue ? '0.5em' : gapValue;
|
|
232
|
+
} else if (!hasBlockGapSupport && fallbackGapValue) {
|
|
233
|
+
gapValue = fallbackGapValue;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (gapValue && tree !== null && tree !== void 0 && (_tree$settings = tree.settings) !== null && _tree$settings !== void 0 && (_tree$settings$layout = _tree$settings.layout) !== null && _tree$settings$layout !== void 0 && _tree$settings$layout.definitions) {
|
|
238
|
+
Object.values(tree.settings.layout.definitions).forEach(_ref7 => {
|
|
239
|
+
let {
|
|
240
|
+
className,
|
|
241
|
+
name,
|
|
242
|
+
spacingStyles
|
|
243
|
+
} = _ref7;
|
|
244
|
+
|
|
245
|
+
// Allow skipping default layout for themes that opt-in to block styles, but opt-out of blockGap.
|
|
246
|
+
if (!hasBlockGapSupport && 'default' === name) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (spacingStyles !== null && spacingStyles !== void 0 && spacingStyles.length) {
|
|
251
|
+
spacingStyles.forEach(spacingStyle => {
|
|
252
|
+
const declarations = [];
|
|
253
|
+
|
|
254
|
+
if (spacingStyle.rules) {
|
|
255
|
+
Object.entries(spacingStyle.rules).forEach(_ref8 => {
|
|
256
|
+
let [cssProperty, cssValue] = _ref8;
|
|
257
|
+
declarations.push(`${cssProperty}: ${cssValue ? cssValue : gapValue}`);
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (declarations.length) {
|
|
262
|
+
const 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) || ''}`;
|
|
263
|
+
ruleset += `${combinedSelector} { ${declarations.join('; ')}; }`;
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}); // For backwards compatibility, ensure the legacy block gap CSS variable is still available.
|
|
268
|
+
|
|
269
|
+
if (selector === ROOT_BLOCK_SELECTOR && hasBlockGapSupport) {
|
|
270
|
+
ruleset += `${selector} { --wp--style--block-gap: ${gapValue}; }`;
|
|
271
|
+
}
|
|
272
|
+
} // Output base styles
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
if (selector === ROOT_BLOCK_SELECTOR && tree !== null && tree !== void 0 && (_tree$settings2 = tree.settings) !== null && _tree$settings2 !== void 0 && (_tree$settings2$layou = _tree$settings2.layout) !== null && _tree$settings2$layou !== void 0 && _tree$settings2$layou.definitions) {
|
|
276
|
+
const validDisplayModes = ['block', 'flex', 'grid'];
|
|
277
|
+
Object.values(tree.settings.layout.definitions).forEach(_ref9 => {
|
|
278
|
+
let {
|
|
279
|
+
className,
|
|
280
|
+
displayMode,
|
|
281
|
+
baseStyles
|
|
282
|
+
} = _ref9;
|
|
283
|
+
|
|
284
|
+
if (displayMode && validDisplayModes.includes(displayMode)) {
|
|
285
|
+
ruleset += `${selector} .${className} { display:${displayMode}; }`;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (baseStyles !== null && baseStyles !== void 0 && baseStyles.length) {
|
|
289
|
+
baseStyles.forEach(baseStyle => {
|
|
290
|
+
const declarations = [];
|
|
199
291
|
|
|
292
|
+
if (baseStyle.rules) {
|
|
293
|
+
Object.entries(baseStyle.rules).forEach(_ref10 => {
|
|
294
|
+
let [cssProperty, cssValue] = _ref10;
|
|
295
|
+
declarations.push(`${cssProperty}: ${cssValue}`);
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (declarations.length) {
|
|
300
|
+
const combinedSelector = `${selector} .${className}${(baseStyle === null || baseStyle === void 0 ? void 0 : baseStyle.selector) || ''}`;
|
|
301
|
+
ruleset += `${combinedSelector} { ${declarations.join('; ')}; }`;
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
return ruleset;
|
|
309
|
+
}
|
|
200
310
|
export const getNodesWithStyles = (tree, blockSelectors) => {
|
|
201
311
|
var _tree$styles, _tree$styles2;
|
|
202
312
|
|
|
@@ -234,9 +344,11 @@ export const getNodesWithStyles = (tree, blockSelectors) => {
|
|
|
234
344
|
|
|
235
345
|
if (!!blockStyles && !!(blockSelectors !== null && blockSelectors !== void 0 && (_blockSelectors$block = blockSelectors[blockName]) !== null && _blockSelectors$block !== void 0 && _blockSelectors$block.selector)) {
|
|
236
346
|
nodes.push({
|
|
237
|
-
|
|
347
|
+
duotoneSelector: blockSelectors[blockName].duotoneSelector,
|
|
348
|
+
fallbackGapValue: blockSelectors[blockName].fallbackGapValue,
|
|
349
|
+
hasLayoutSupport: blockSelectors[blockName].hasLayoutSupport,
|
|
238
350
|
selector: blockSelectors[blockName].selector,
|
|
239
|
-
|
|
351
|
+
styles: blockStyles
|
|
240
352
|
});
|
|
241
353
|
}
|
|
242
354
|
|
|
@@ -255,7 +367,7 @@ export const getNodesWithStyles = (tree, blockSelectors) => {
|
|
|
255
367
|
return nodes;
|
|
256
368
|
};
|
|
257
369
|
export const getNodesWithSettings = (tree, blockSelectors) => {
|
|
258
|
-
var _tree$
|
|
370
|
+
var _tree$settings3, _tree$settings4;
|
|
259
371
|
|
|
260
372
|
const nodes = [];
|
|
261
373
|
|
|
@@ -265,10 +377,10 @@ export const getNodesWithSettings = (tree, blockSelectors) => {
|
|
|
265
377
|
|
|
266
378
|
const pickPresets = treeToPickFrom => {
|
|
267
379
|
const presets = {};
|
|
268
|
-
PRESET_METADATA.forEach(
|
|
380
|
+
PRESET_METADATA.forEach(_ref11 => {
|
|
269
381
|
let {
|
|
270
382
|
path
|
|
271
|
-
} =
|
|
383
|
+
} = _ref11;
|
|
272
384
|
const value = get(treeToPickFrom, path, false);
|
|
273
385
|
|
|
274
386
|
if (value !== false) {
|
|
@@ -280,7 +392,7 @@ export const getNodesWithSettings = (tree, blockSelectors) => {
|
|
|
280
392
|
|
|
281
393
|
|
|
282
394
|
const presets = pickPresets(tree.settings);
|
|
283
|
-
const custom = (_tree$
|
|
395
|
+
const custom = (_tree$settings3 = tree.settings) === null || _tree$settings3 === void 0 ? void 0 : _tree$settings3.custom;
|
|
284
396
|
|
|
285
397
|
if (!isEmpty(presets) || !!custom) {
|
|
286
398
|
nodes.push({
|
|
@@ -291,7 +403,7 @@ export const getNodesWithSettings = (tree, blockSelectors) => {
|
|
|
291
403
|
} // Blocks.
|
|
292
404
|
|
|
293
405
|
|
|
294
|
-
forEach((_tree$
|
|
406
|
+
forEach((_tree$settings4 = tree.settings) === null || _tree$settings4 === void 0 ? void 0 : _tree$settings4.blocks, (node, blockName) => {
|
|
295
407
|
const blockPresets = pickPresets(node);
|
|
296
408
|
const blockCustom = node.custom;
|
|
297
409
|
|
|
@@ -308,12 +420,12 @@ export const getNodesWithSettings = (tree, blockSelectors) => {
|
|
|
308
420
|
export const toCustomProperties = (tree, blockSelectors) => {
|
|
309
421
|
const settings = getNodesWithSettings(tree, blockSelectors);
|
|
310
422
|
let ruleset = '';
|
|
311
|
-
settings.forEach(
|
|
423
|
+
settings.forEach(_ref12 => {
|
|
312
424
|
let {
|
|
313
425
|
presets,
|
|
314
426
|
custom,
|
|
315
427
|
selector
|
|
316
|
-
} =
|
|
428
|
+
} = _ref12;
|
|
317
429
|
const declarations = getPresetsDeclarations(presets);
|
|
318
430
|
const customProps = flattenTree(custom, '--wp--custom--', '--');
|
|
319
431
|
|
|
@@ -327,7 +439,7 @@ export const toCustomProperties = (tree, blockSelectors) => {
|
|
|
327
439
|
});
|
|
328
440
|
return ruleset;
|
|
329
441
|
};
|
|
330
|
-
export const toStyles = (tree, blockSelectors, hasBlockGapSupport) => {
|
|
442
|
+
export const toStyles = (tree, blockSelectors, hasBlockGapSupport, hasFallbackGapSupport) => {
|
|
331
443
|
const nodesWithStyles = getNodesWithStyles(tree, blockSelectors);
|
|
332
444
|
const nodesWithSettings = getNodesWithSettings(tree, blockSelectors);
|
|
333
445
|
/*
|
|
@@ -340,12 +452,14 @@ export const toStyles = (tree, blockSelectors, hasBlockGapSupport) => {
|
|
|
340
452
|
*/
|
|
341
453
|
|
|
342
454
|
let ruleset = 'body {margin: 0;}';
|
|
343
|
-
nodesWithStyles.forEach(
|
|
455
|
+
nodesWithStyles.forEach(_ref13 => {
|
|
344
456
|
let {
|
|
345
457
|
selector,
|
|
346
458
|
duotoneSelector,
|
|
347
|
-
styles
|
|
348
|
-
|
|
459
|
+
styles,
|
|
460
|
+
fallbackGapValue,
|
|
461
|
+
hasLayoutSupport
|
|
462
|
+
} = _ref13;
|
|
349
463
|
const duotoneStyles = {};
|
|
350
464
|
|
|
351
465
|
if (styles !== null && styles !== void 0 && styles.filter) {
|
|
@@ -362,7 +476,19 @@ export const toStyles = (tree, blockSelectors, hasBlockGapSupport) => {
|
|
|
362
476
|
}
|
|
363
477
|
|
|
364
478
|
ruleset = ruleset + `${duotoneSelector}{${duotoneDeclarations.join(';')};}`;
|
|
365
|
-
} // Process
|
|
479
|
+
} // Process blockGap and layout styles.
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
if (ROOT_BLOCK_SELECTOR === selector || hasLayoutSupport) {
|
|
483
|
+
ruleset += getLayoutStyles({
|
|
484
|
+
tree,
|
|
485
|
+
style: styles,
|
|
486
|
+
selector,
|
|
487
|
+
hasBlockGapSupport,
|
|
488
|
+
hasFallbackGapSupport,
|
|
489
|
+
fallbackGapValue
|
|
490
|
+
});
|
|
491
|
+
} // Process the remaining block styles (they use either normal block class or __experimentalSelector).
|
|
366
492
|
|
|
367
493
|
|
|
368
494
|
const declarations = getStylesDeclarations(styles);
|
|
@@ -372,15 +498,15 @@ export const toStyles = (tree, blockSelectors, hasBlockGapSupport) => {
|
|
|
372
498
|
} // Check for pseudo selector in `styles` and handle separately.
|
|
373
499
|
|
|
374
500
|
|
|
375
|
-
const
|
|
376
|
-
let [key] =
|
|
501
|
+
const pseudoSelectorStyles = Object.entries(styles).filter(_ref14 => {
|
|
502
|
+
let [key] = _ref14;
|
|
377
503
|
return key.startsWith(':');
|
|
378
504
|
});
|
|
379
505
|
|
|
380
|
-
if (
|
|
381
|
-
|
|
382
|
-
let [pseudoKey,
|
|
383
|
-
const pseudoDeclarations = getStylesDeclarations(
|
|
506
|
+
if (pseudoSelectorStyles !== null && pseudoSelectorStyles !== void 0 && pseudoSelectorStyles.length) {
|
|
507
|
+
pseudoSelectorStyles.forEach(_ref15 => {
|
|
508
|
+
let [pseudoKey, pseudoStyle] = _ref15;
|
|
509
|
+
const pseudoDeclarations = getStylesDeclarations(pseudoStyle);
|
|
384
510
|
|
|
385
511
|
if (!(pseudoDeclarations !== null && pseudoDeclarations !== void 0 && pseudoDeclarations.length)) {
|
|
386
512
|
return;
|
|
@@ -395,8 +521,8 @@ export const toStyles = (tree, blockSelectors, hasBlockGapSupport) => {
|
|
|
395
521
|
|
|
396
522
|
const _selector = selector.split(',').map(sel => sel + pseudoKey).join(',');
|
|
397
523
|
|
|
398
|
-
const
|
|
399
|
-
ruleset = ruleset +
|
|
524
|
+
const pseudoRule = `${_selector}{${pseudoDeclarations.join(';')};}`;
|
|
525
|
+
ruleset = ruleset + pseudoRule;
|
|
400
526
|
});
|
|
401
527
|
}
|
|
402
528
|
});
|
|
@@ -407,15 +533,19 @@ export const toStyles = (tree, blockSelectors, hasBlockGapSupport) => {
|
|
|
407
533
|
ruleset = ruleset + '.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }';
|
|
408
534
|
|
|
409
535
|
if (hasBlockGapSupport) {
|
|
536
|
+
var _tree$styles3, _tree$styles3$spacing;
|
|
537
|
+
|
|
538
|
+
// 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$styles3 = tree.styles) === null || _tree$styles3 === void 0 ? void 0 : (_tree$styles3$spacing = _tree$styles3.spacing) === null || _tree$styles3$spacing === void 0 ? void 0 : _tree$styles3$spacing.blockGap) || '0.5em';
|
|
410
540
|
ruleset = ruleset + '.wp-site-blocks > * { margin-block-start: 0; margin-block-end: 0; }';
|
|
411
|
-
ruleset = ruleset +
|
|
541
|
+
ruleset = ruleset + `.wp-site-blocks > * + * { margin-block-start: ${gapValue}; }`;
|
|
412
542
|
}
|
|
413
543
|
|
|
414
|
-
nodesWithSettings.forEach(
|
|
544
|
+
nodesWithSettings.forEach(_ref16 => {
|
|
415
545
|
let {
|
|
416
546
|
selector,
|
|
417
547
|
presets
|
|
418
|
-
} =
|
|
548
|
+
} = _ref16;
|
|
419
549
|
|
|
420
550
|
if (ROOT_BLOCK_SELECTOR === selector) {
|
|
421
551
|
// Do not add extra specificity for top-level classes.
|
|
@@ -432,10 +562,10 @@ export const toStyles = (tree, blockSelectors, hasBlockGapSupport) => {
|
|
|
432
562
|
};
|
|
433
563
|
export function toSvgFilters(tree, blockSelectors) {
|
|
434
564
|
const nodesWithSettings = getNodesWithSettings(tree, blockSelectors);
|
|
435
|
-
return nodesWithSettings.flatMap(
|
|
565
|
+
return nodesWithSettings.flatMap(_ref17 => {
|
|
436
566
|
let {
|
|
437
567
|
presets
|
|
438
|
-
} =
|
|
568
|
+
} = _ref17;
|
|
439
569
|
return getPresetsSvgFilters(presets);
|
|
440
570
|
});
|
|
441
571
|
}
|
|
@@ -443,15 +573,19 @@ export function toSvgFilters(tree, blockSelectors) {
|
|
|
443
573
|
const getBlockSelectors = blockTypes => {
|
|
444
574
|
const result = {};
|
|
445
575
|
blockTypes.forEach(blockType => {
|
|
446
|
-
var _blockType$supports$_, _blockType$supports, _blockType$supports$c, _blockType$supports2, _blockType$supports2
|
|
576
|
+
var _blockType$supports$_, _blockType$supports, _blockType$supports$c, _blockType$supports2, _blockType$supports2$, _blockType$supports3, _blockType$supports4, _blockType$supports4$, _blockType$supports4$2;
|
|
447
577
|
|
|
448
578
|
const name = blockType.name;
|
|
449
579
|
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('/', '-');
|
|
450
580
|
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
|
+
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;
|
|
451
583
|
result[name] = {
|
|
584
|
+
duotoneSelector,
|
|
585
|
+
fallbackGapValue,
|
|
586
|
+
hasLayoutSupport,
|
|
452
587
|
name,
|
|
453
|
-
selector
|
|
454
|
-
duotoneSelector
|
|
588
|
+
selector
|
|
455
589
|
};
|
|
456
590
|
});
|
|
457
591
|
return result;
|
|
@@ -466,6 +600,8 @@ export function useGlobalStylesOutput() {
|
|
|
466
600
|
} = useContext(GlobalStylesContext);
|
|
467
601
|
const [blockGap] = useSetting('spacing.blockGap');
|
|
468
602
|
const hasBlockGapSupport = blockGap !== null;
|
|
603
|
+
const hasFallbackGapSupport = !hasBlockGapSupport; // This setting isn't useful yet: it exists as a placeholder for a future explicit fallback styles support.
|
|
604
|
+
|
|
469
605
|
useEffect(() => {
|
|
470
606
|
if (!(mergedConfig !== null && mergedConfig !== void 0 && mergedConfig.styles) || !(mergedConfig !== null && mergedConfig !== void 0 && mergedConfig.settings)) {
|
|
471
607
|
return;
|
|
@@ -473,7 +609,7 @@ export function useGlobalStylesOutput() {
|
|
|
473
609
|
|
|
474
610
|
const blockSelectors = getBlockSelectors(getBlockTypes());
|
|
475
611
|
const customProperties = toCustomProperties(mergedConfig, blockSelectors);
|
|
476
|
-
const globalStyles = toStyles(mergedConfig, blockSelectors, hasBlockGapSupport);
|
|
612
|
+
const globalStyles = toStyles(mergedConfig, blockSelectors, hasBlockGapSupport, hasFallbackGapSupport);
|
|
477
613
|
const filters = toSvgFilters(mergedConfig, blockSelectors);
|
|
478
614
|
setStylesheets([{
|
|
479
615
|
css: customProperties,
|
|
@@ -484,7 +620,7 @@ export function useGlobalStylesOutput() {
|
|
|
484
620
|
}]);
|
|
485
621
|
setSettings(mergedConfig.settings);
|
|
486
622
|
setSvgFilters(filters);
|
|
487
|
-
}, [mergedConfig]);
|
|
623
|
+
}, [hasBlockGapSupport, hasFallbackGapSupport, mergedConfig]);
|
|
488
624
|
return [stylesheets, settings, svgFilters, hasBlockGapSupport];
|
|
489
625
|
}
|
|
490
626
|
//# sourceMappingURL=use-global-styles-output.js.map
|