@wordpress/edit-site 4.8.0 → 4.11.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 +6 -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 +204 -0
- package/build/components/add-new-template/add-custom-template-modal.js.map +1 -0
- package/build/components/add-new-template/new-template.js +91 -33
- package/build/components/add-new-template/new-template.js.map +1 -1
- package/build/components/add-new-template/utils.js +532 -0
- package/build/components/add-new-template/utils.js.map +1 -0
- package/build/components/block-editor/index.js +1 -3
- package/build/components/block-editor/index.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/context-menu.js +6 -3
- package/build/components/global-styles/context-menu.js.map +1 -1
- package/build/components/global-styles/dimensions-panel.js +185 -19
- 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 +11 -2
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/palette.js +2 -1
- package/build/components/global-styles/palette.js.map +1 -1
- package/build/components/global-styles/screen-block-list.js +4 -1
- package/build/components/global-styles/screen-block-list.js.map +1 -1
- package/build/components/global-styles/screen-button-color.js +80 -0
- package/build/components/global-styles/screen-button-color.js.map +1 -0
- 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 +56 -8
- 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/screen-root.js +4 -2
- package/build/components/global-styles/screen-root.js.map +1 -1
- 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 +9 -1
- package/build/components/global-styles/screen-typography.js.map +1 -1
- 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 +282 -35
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/global-styles/utils.js +35 -2
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/header/index.js +29 -10
- package/build/components/header/index.js.map +1 -1
- package/build/components/header/more-menu/site-export.js +4 -1
- package/build/components/header/more-menu/site-export.js.map +1 -1
- package/build/components/header/undo-redo/redo.js +13 -4
- package/build/components/header/undo-redo/redo.js.map +1 -1
- package/build/components/header/undo-redo/undo.js +13 -4
- package/build/components/header/undo-redo/undo.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/config.js +17 -0
- package/build/components/keyboard-shortcut-help-modal/config.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/sidebar/template-card/index.js +19 -7
- package/build/components/sidebar/template-card/index.js.map +1 -1
- package/build/components/sidebar/template-card/template-actions.js +64 -0
- package/build/components/sidebar/template-card/template-actions.js.map +1 -0
- 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/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/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 +189 -0
- package/build-module/components/add-new-template/add-custom-template-modal.js.map +1 -0
- package/build-module/components/add-new-template/new-template.js +90 -34
- package/build-module/components/add-new-template/new-template.js.map +1 -1
- package/build-module/components/add-new-template/utils.js +503 -0
- package/build-module/components/add-new-template/utils.js.map +1 -0
- 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/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/context-menu.js +6 -3
- package/build-module/components/global-styles/context-menu.js.map +1 -1
- package/build-module/components/global-styles/dimensions-panel.js +185 -20
- 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 +11 -2
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/palette.js +2 -1
- package/build-module/components/global-styles/palette.js.map +1 -1
- package/build-module/components/global-styles/screen-block-list.js +4 -1
- package/build-module/components/global-styles/screen-block-list.js.map +1 -1
- package/build-module/components/global-styles/screen-button-color.js +67 -0
- package/build-module/components/global-styles/screen-button-color.js.map +1 -0
- 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 +57 -9
- 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/screen-root.js +4 -2
- package/build-module/components/global-styles/screen-root.js.map +1 -1
- 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 +10 -2
- package/build-module/components/global-styles/screen-typography.js.map +1 -1
- 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 +280 -42
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/global-styles/utils.js +34 -3
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/header/index.js +31 -11
- package/build-module/components/header/index.js.map +1 -1
- package/build-module/components/header/more-menu/site-export.js +4 -1
- package/build-module/components/header/more-menu/site-export.js.map +1 -1
- package/build-module/components/header/undo-redo/redo.js +9 -3
- package/build-module/components/header/undo-redo/redo.js.map +1 -1
- package/build-module/components/header/undo-redo/undo.js +9 -3
- package/build-module/components/header/undo-redo/undo.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/config.js +17 -0
- package/build-module/components/keyboard-shortcut-help-modal/config.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/sidebar/template-card/index.js +18 -7
- package/build-module/components/sidebar/template-card/index.js.map +1 -1
- package/build-module/components/sidebar/template-card/template-actions.js +49 -0
- package/build-module/components/sidebar/template-card/template-actions.js.map +1 -0
- 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/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/store/selectors.js +5 -2
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +198 -49
- package/build-style/style.css +198 -49
- 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 +247 -0
- package/src/components/add-new-template/new-template.js +158 -70
- package/src/components/add-new-template/style.scss +149 -0
- package/src/components/add-new-template/utils.js +538 -0
- package/src/components/block-editor/index.js +0 -2
- 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/context-menu.js +3 -0
- package/src/components/global-styles/dimensions-panel.js +209 -21
- package/src/components/global-styles/global-styles-provider.js +8 -9
- package/src/components/global-styles/hooks.js +18 -0
- package/src/components/global-styles/palette.js +4 -1
- package/src/components/global-styles/screen-block-list.js +10 -1
- package/src/components/global-styles/screen-button-color.js +102 -0
- package/src/components/global-styles/screen-color-palette.js +25 -27
- package/src/components/global-styles/screen-colors.js +58 -7
- package/src/components/global-styles/screen-link-color.js +65 -23
- package/src/components/global-styles/screen-root.js +8 -2
- package/src/components/global-styles/screen-typography-element.js +4 -0
- package/src/components/global-styles/screen-typography.js +17 -2
- package/src/components/global-styles/style.scss +14 -8
- package/src/components/global-styles/test/use-global-styles-output.js +313 -16
- package/src/components/global-styles/ui.js +13 -0
- package/src/components/global-styles/use-global-styles-output.js +344 -38
- package/src/components/global-styles/utils.js +36 -2
- package/src/components/header/index.js +42 -17
- package/src/components/header/more-menu/site-export.js +3 -0
- package/src/components/header/style.scss +58 -8
- package/src/components/header/undo-redo/redo.js +6 -1
- package/src/components/header/undo-redo/undo.js +6 -1
- package/src/components/keyboard-shortcut-help-modal/config.js +12 -0
- 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/sidebar/style.scss +4 -0
- package/src/components/sidebar/template-card/index.js +15 -6
- package/src/components/sidebar/template-card/style.scss +49 -35
- package/src/components/sidebar/template-card/template-actions.js +43 -0
- 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/hooks/index.js +1 -0
- package/src/hooks/template-part-edit.js +82 -0
- package/src/store/selectors.js +11 -5
- 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,6 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.getBlockSelectors = void 0;
|
|
7
|
+
exports.getLayoutStyles = getLayoutStyles;
|
|
6
8
|
exports.toStyles = exports.toCustomProperties = exports.getNodesWithStyles = exports.getNodesWithSettings = void 0;
|
|
7
9
|
exports.toSvgFilters = toSvgFilters;
|
|
8
10
|
exports.useGlobalStylesOutput = useGlobalStylesOutput;
|
|
@@ -34,6 +36,15 @@ var _hooks = require("./hooks");
|
|
|
34
36
|
/**
|
|
35
37
|
* Internal dependencies
|
|
36
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
|
+
|
|
37
48
|
function compileStyleValue(uncompiledValue) {
|
|
38
49
|
const VARIABLE_REFERENCE_PREFIX = 'var:';
|
|
39
50
|
const VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE = '|';
|
|
@@ -159,7 +170,11 @@ function flattenTree() {
|
|
|
159
170
|
/**
|
|
160
171
|
* Transform given style tree into a set of style declarations.
|
|
161
172
|
*
|
|
162
|
-
* @param {Object}
|
|
173
|
+
* @param {Object} blockStyles Block styles.
|
|
174
|
+
*
|
|
175
|
+
* @param {string} selector The selector these declarations should attach to.
|
|
176
|
+
*
|
|
177
|
+
* @param {boolean} useRootPaddingAlign Whether to use CSS custom properties in root selector.
|
|
163
178
|
*
|
|
164
179
|
* @return {Array} An array of style declarations.
|
|
165
180
|
*/
|
|
@@ -167,12 +182,21 @@ function flattenTree() {
|
|
|
167
182
|
|
|
168
183
|
function getStylesDeclarations() {
|
|
169
184
|
let blockStyles = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
185
|
+
let selector = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
186
|
+
let useRootPaddingAlign = arguments.length > 2 ? arguments[2] : undefined;
|
|
187
|
+
const isRoot = _utils.ROOT_BLOCK_SELECTOR === selector;
|
|
170
188
|
const output = (0, _lodash.reduce)(_blocks.__EXPERIMENTAL_STYLE_PROPERTY, (declarations, _ref5, key) => {
|
|
171
189
|
let {
|
|
172
190
|
value,
|
|
173
191
|
properties,
|
|
174
|
-
useEngine
|
|
192
|
+
useEngine,
|
|
193
|
+
rootOnly
|
|
175
194
|
} = _ref5;
|
|
195
|
+
|
|
196
|
+
if (rootOnly && !isRoot) {
|
|
197
|
+
return declarations;
|
|
198
|
+
}
|
|
199
|
+
|
|
176
200
|
const pathToValue = value;
|
|
177
201
|
|
|
178
202
|
if ((0, _lodash.first)(pathToValue) === 'elements' || useEngine) {
|
|
@@ -181,7 +205,7 @@ function getStylesDeclarations() {
|
|
|
181
205
|
|
|
182
206
|
const styleValue = (0, _lodash.get)(blockStyles, pathToValue);
|
|
183
207
|
|
|
184
|
-
if (!!properties &&
|
|
208
|
+
if (!!properties && typeof styleValue !== 'string') {
|
|
185
209
|
Object.entries(properties).forEach(entry => {
|
|
186
210
|
const [name, prop] = entry;
|
|
187
211
|
|
|
@@ -191,18 +215,27 @@ function getStylesDeclarations() {
|
|
|
191
215
|
return;
|
|
192
216
|
}
|
|
193
217
|
|
|
194
|
-
const cssProperty = (0, _lodash.kebabCase)(name);
|
|
218
|
+
const cssProperty = name.startsWith('--') ? name : (0, _lodash.kebabCase)(name);
|
|
195
219
|
declarations.push(`${cssProperty}: ${compileStyleValue((0, _lodash.get)(styleValue, [prop]))}`);
|
|
196
220
|
});
|
|
221
|
+
} else if (key === '--wp--style--root--padding' && typeof styleValue === 'string') {
|
|
222
|
+
// Root-level padding styles don't currently support strings with CSS shorthand values.
|
|
223
|
+
// This may change: https://github.com/WordPress/gutenberg/issues/40132.
|
|
224
|
+
return declarations;
|
|
197
225
|
} else if ((0, _lodash.get)(blockStyles, pathToValue, false)) {
|
|
198
226
|
const cssProperty = key.startsWith('--') ? key : (0, _lodash.kebabCase)(key);
|
|
199
227
|
declarations.push(`${cssProperty}: ${compileStyleValue((0, _lodash.get)(blockStyles, pathToValue))}`);
|
|
200
228
|
}
|
|
201
229
|
|
|
202
230
|
return declarations;
|
|
203
|
-
}, []);
|
|
231
|
+
}, []);
|
|
232
|
+
|
|
233
|
+
if (isRoot && useRootPaddingAlign) {
|
|
234
|
+
return output;
|
|
235
|
+
} // The goal is to move everything to server side generated engine styles
|
|
204
236
|
// This is temporary as we absorb more and more styles into the engine.
|
|
205
237
|
|
|
238
|
+
|
|
206
239
|
const extraRules = (0, _styleEngine.getCSSRules)(blockStyles);
|
|
207
240
|
extraRules.forEach(rule => {
|
|
208
241
|
const cssProperty = rule.key.startsWith('--') ? rule.key : (0, _lodash.kebabCase)(rule.key);
|
|
@@ -210,6 +243,117 @@ function getStylesDeclarations() {
|
|
|
210
243
|
});
|
|
211
244
|
return output;
|
|
212
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* Get generated CSS for layout styles by looking up layout definitions provided
|
|
248
|
+
* in theme.json, and outputting common layout styles, and specific blockGap values.
|
|
249
|
+
*
|
|
250
|
+
* @param {Object} props
|
|
251
|
+
* @param {Object} props.tree A theme.json tree containing layout definitions.
|
|
252
|
+
* @param {Object} props.style A style object containing spacing values.
|
|
253
|
+
* @param {string} props.selector Selector used to group together layout styling rules.
|
|
254
|
+
* @param {boolean} props.hasBlockGapSupport Whether or not the theme opts-in to blockGap support.
|
|
255
|
+
* @param {boolean} props.hasFallbackGapSupport Whether or not the theme allows fallback gap styles.
|
|
256
|
+
* @param {?string} props.fallbackGapValue An optional fallback gap value if no real gap value is available.
|
|
257
|
+
* @return {string} Generated CSS rules for the layout styles.
|
|
258
|
+
*/
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
function getLayoutStyles(_ref6) {
|
|
262
|
+
var _style$spacing, _tree$settings, _tree$settings$layout, _tree$settings2, _tree$settings2$layou;
|
|
263
|
+
|
|
264
|
+
let {
|
|
265
|
+
tree,
|
|
266
|
+
style,
|
|
267
|
+
selector,
|
|
268
|
+
hasBlockGapSupport,
|
|
269
|
+
hasFallbackGapSupport,
|
|
270
|
+
fallbackGapValue
|
|
271
|
+
} = _ref6;
|
|
272
|
+
let ruleset = '';
|
|
273
|
+
let gapValue = hasBlockGapSupport ? (0, _blockEditor.__experimentalGetGapCSSValue)(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,
|
|
274
|
+
// and use a fallback value if one is provided for the current block.
|
|
275
|
+
|
|
276
|
+
if (hasFallbackGapSupport) {
|
|
277
|
+
if (selector === _utils.ROOT_BLOCK_SELECTOR) {
|
|
278
|
+
gapValue = !gapValue ? '0.5em' : gapValue;
|
|
279
|
+
} else if (!hasBlockGapSupport && fallbackGapValue) {
|
|
280
|
+
gapValue = fallbackGapValue;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
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) {
|
|
285
|
+
Object.values(tree.settings.layout.definitions).forEach(_ref7 => {
|
|
286
|
+
let {
|
|
287
|
+
className,
|
|
288
|
+
name,
|
|
289
|
+
spacingStyles
|
|
290
|
+
} = _ref7;
|
|
291
|
+
|
|
292
|
+
// Allow skipping default layout for themes that opt-in to block styles, but opt-out of blockGap.
|
|
293
|
+
if (!hasBlockGapSupport && 'default' === name) {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (spacingStyles !== null && spacingStyles !== void 0 && spacingStyles.length) {
|
|
298
|
+
spacingStyles.forEach(spacingStyle => {
|
|
299
|
+
const declarations = [];
|
|
300
|
+
|
|
301
|
+
if (spacingStyle.rules) {
|
|
302
|
+
Object.entries(spacingStyle.rules).forEach(_ref8 => {
|
|
303
|
+
let [cssProperty, cssValue] = _ref8;
|
|
304
|
+
declarations.push(`${cssProperty}: ${cssValue ? cssValue : gapValue}`);
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (declarations.length) {
|
|
309
|
+
const combinedSelector = selector === _utils.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) || ''}`;
|
|
310
|
+
ruleset += `${combinedSelector} { ${declarations.join('; ')}; }`;
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
}); // For backwards compatibility, ensure the legacy block gap CSS variable is still available.
|
|
315
|
+
|
|
316
|
+
if (selector === _utils.ROOT_BLOCK_SELECTOR && hasBlockGapSupport) {
|
|
317
|
+
ruleset += `${selector} { --wp--style--block-gap: ${gapValue}; }`;
|
|
318
|
+
}
|
|
319
|
+
} // Output base styles
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
if (selector === _utils.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) {
|
|
323
|
+
const validDisplayModes = ['block', 'flex', 'grid'];
|
|
324
|
+
Object.values(tree.settings.layout.definitions).forEach(_ref9 => {
|
|
325
|
+
let {
|
|
326
|
+
className,
|
|
327
|
+
displayMode,
|
|
328
|
+
baseStyles
|
|
329
|
+
} = _ref9;
|
|
330
|
+
|
|
331
|
+
if (displayMode && validDisplayModes.includes(displayMode)) {
|
|
332
|
+
ruleset += `${selector} .${className} { display:${displayMode}; }`;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
if (baseStyles !== null && baseStyles !== void 0 && baseStyles.length) {
|
|
336
|
+
baseStyles.forEach(baseStyle => {
|
|
337
|
+
const declarations = [];
|
|
338
|
+
|
|
339
|
+
if (baseStyle.rules) {
|
|
340
|
+
Object.entries(baseStyle.rules).forEach(_ref10 => {
|
|
341
|
+
let [cssProperty, cssValue] = _ref10;
|
|
342
|
+
declarations.push(`${cssProperty}: ${cssValue}`);
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if (declarations.length) {
|
|
347
|
+
const combinedSelector = `${selector} .${className}${(baseStyle === null || baseStyle === void 0 ? void 0 : baseStyle.selector) || ''}`;
|
|
348
|
+
ruleset += `${combinedSelector} { ${declarations.join('; ')}; }`;
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return ruleset;
|
|
356
|
+
}
|
|
213
357
|
|
|
214
358
|
const getNodesWithStyles = (tree, blockSelectors) => {
|
|
215
359
|
var _tree$styles, _tree$styles2;
|
|
@@ -248,9 +392,12 @@ const getNodesWithStyles = (tree, blockSelectors) => {
|
|
|
248
392
|
|
|
249
393
|
if (!!blockStyles && !!(blockSelectors !== null && blockSelectors !== void 0 && (_blockSelectors$block = blockSelectors[blockName]) !== null && _blockSelectors$block !== void 0 && _blockSelectors$block.selector)) {
|
|
250
394
|
nodes.push({
|
|
251
|
-
|
|
395
|
+
duotoneSelector: blockSelectors[blockName].duotoneSelector,
|
|
396
|
+
fallbackGapValue: blockSelectors[blockName].fallbackGapValue,
|
|
397
|
+
hasLayoutSupport: blockSelectors[blockName].hasLayoutSupport,
|
|
252
398
|
selector: blockSelectors[blockName].selector,
|
|
253
|
-
|
|
399
|
+
styles: blockStyles,
|
|
400
|
+
featureSelectors: blockSelectors[blockName].featureSelectors
|
|
254
401
|
});
|
|
255
402
|
}
|
|
256
403
|
|
|
@@ -258,7 +405,11 @@ const getNodesWithStyles = (tree, blockSelectors) => {
|
|
|
258
405
|
if (!!value && !!(blockSelectors !== null && blockSelectors !== void 0 && blockSelectors[blockName]) && !!(_blocks.__EXPERIMENTAL_ELEMENTS !== null && _blocks.__EXPERIMENTAL_ELEMENTS !== void 0 && _blocks.__EXPERIMENTAL_ELEMENTS[elementName])) {
|
|
259
406
|
nodes.push({
|
|
260
407
|
styles: value,
|
|
261
|
-
selector: blockSelectors[blockName].selector.split(',').map(sel =>
|
|
408
|
+
selector: blockSelectors[blockName].selector.split(',').map(sel => {
|
|
409
|
+
const elementSelectors = _blocks.__EXPERIMENTAL_ELEMENTS[elementName].split(',');
|
|
410
|
+
|
|
411
|
+
return elementSelectors.map(elementSelector => sel + ' ' + elementSelector);
|
|
412
|
+
}).join(',')
|
|
262
413
|
});
|
|
263
414
|
}
|
|
264
415
|
});
|
|
@@ -269,7 +420,7 @@ const getNodesWithStyles = (tree, blockSelectors) => {
|
|
|
269
420
|
exports.getNodesWithStyles = getNodesWithStyles;
|
|
270
421
|
|
|
271
422
|
const getNodesWithSettings = (tree, blockSelectors) => {
|
|
272
|
-
var _tree$
|
|
423
|
+
var _tree$settings3, _tree$settings4;
|
|
273
424
|
|
|
274
425
|
const nodes = [];
|
|
275
426
|
|
|
@@ -280,10 +431,10 @@ const getNodesWithSettings = (tree, blockSelectors) => {
|
|
|
280
431
|
const pickPresets = treeToPickFrom => {
|
|
281
432
|
const presets = {};
|
|
282
433
|
|
|
283
|
-
_utils.PRESET_METADATA.forEach(
|
|
434
|
+
_utils.PRESET_METADATA.forEach(_ref11 => {
|
|
284
435
|
let {
|
|
285
436
|
path
|
|
286
|
-
} =
|
|
437
|
+
} = _ref11;
|
|
287
438
|
const value = (0, _lodash.get)(treeToPickFrom, path, false);
|
|
288
439
|
|
|
289
440
|
if (value !== false) {
|
|
@@ -296,7 +447,7 @@ const getNodesWithSettings = (tree, blockSelectors) => {
|
|
|
296
447
|
|
|
297
448
|
|
|
298
449
|
const presets = pickPresets(tree.settings);
|
|
299
|
-
const custom = (_tree$
|
|
450
|
+
const custom = (_tree$settings3 = tree.settings) === null || _tree$settings3 === void 0 ? void 0 : _tree$settings3.custom;
|
|
300
451
|
|
|
301
452
|
if (!(0, _lodash.isEmpty)(presets) || !!custom) {
|
|
302
453
|
nodes.push({
|
|
@@ -307,7 +458,7 @@ const getNodesWithSettings = (tree, blockSelectors) => {
|
|
|
307
458
|
} // Blocks.
|
|
308
459
|
|
|
309
460
|
|
|
310
|
-
(0, _lodash.forEach)((_tree$
|
|
461
|
+
(0, _lodash.forEach)((_tree$settings4 = tree.settings) === null || _tree$settings4 === void 0 ? void 0 : _tree$settings4.blocks, (node, blockName) => {
|
|
311
462
|
const blockPresets = pickPresets(node);
|
|
312
463
|
const blockCustom = node.custom;
|
|
313
464
|
|
|
@@ -327,12 +478,12 @@ exports.getNodesWithSettings = getNodesWithSettings;
|
|
|
327
478
|
const toCustomProperties = (tree, blockSelectors) => {
|
|
328
479
|
const settings = getNodesWithSettings(tree, blockSelectors);
|
|
329
480
|
let ruleset = '';
|
|
330
|
-
settings.forEach(
|
|
481
|
+
settings.forEach(_ref12 => {
|
|
331
482
|
let {
|
|
332
483
|
presets,
|
|
333
484
|
custom,
|
|
334
485
|
selector
|
|
335
|
-
} =
|
|
486
|
+
} = _ref12;
|
|
336
487
|
const declarations = getPresetsDeclarations(presets);
|
|
337
488
|
const customProps = flattenTree(custom, '--wp--custom--', '--');
|
|
338
489
|
|
|
@@ -349,9 +500,12 @@ const toCustomProperties = (tree, blockSelectors) => {
|
|
|
349
500
|
|
|
350
501
|
exports.toCustomProperties = toCustomProperties;
|
|
351
502
|
|
|
352
|
-
const toStyles = (tree, blockSelectors, hasBlockGapSupport) => {
|
|
503
|
+
const toStyles = (tree, blockSelectors, hasBlockGapSupport, hasFallbackGapSupport) => {
|
|
504
|
+
var _tree$settings5;
|
|
505
|
+
|
|
353
506
|
const nodesWithStyles = getNodesWithStyles(tree, blockSelectors);
|
|
354
507
|
const nodesWithSettings = getNodesWithSettings(tree, blockSelectors);
|
|
508
|
+
const useRootPaddingAlign = tree === null || tree === void 0 ? void 0 : (_tree$settings5 = tree.settings) === null || _tree$settings5 === void 0 ? void 0 : _tree$settings5.useRootPaddingAwareAlignments;
|
|
355
509
|
/*
|
|
356
510
|
* Reset default browser margin on the root body element.
|
|
357
511
|
* This is set on the root selector **before** generating the ruleset
|
|
@@ -362,12 +516,41 @@ const toStyles = (tree, blockSelectors, hasBlockGapSupport) => {
|
|
|
362
516
|
*/
|
|
363
517
|
|
|
364
518
|
let ruleset = 'body {margin: 0;}';
|
|
365
|
-
|
|
519
|
+
|
|
520
|
+
if (useRootPaddingAlign) {
|
|
521
|
+
ruleset = 'body { margin: 0; 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); }';
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
nodesWithStyles.forEach(_ref13 => {
|
|
366
525
|
let {
|
|
367
526
|
selector,
|
|
368
527
|
duotoneSelector,
|
|
369
|
-
styles
|
|
370
|
-
|
|
528
|
+
styles,
|
|
529
|
+
fallbackGapValue,
|
|
530
|
+
hasLayoutSupport,
|
|
531
|
+
featureSelectors
|
|
532
|
+
} = _ref13;
|
|
533
|
+
|
|
534
|
+
// Process styles for block support features with custom feature level
|
|
535
|
+
// CSS selectors set.
|
|
536
|
+
if (featureSelectors) {
|
|
537
|
+
Object.entries(featureSelectors).forEach(_ref14 => {
|
|
538
|
+
let [featureName, featureSelector] = _ref14;
|
|
539
|
+
|
|
540
|
+
if (styles !== null && styles !== void 0 && styles[featureName]) {
|
|
541
|
+
const featureStyles = {
|
|
542
|
+
[featureName]: styles[featureName]
|
|
543
|
+
};
|
|
544
|
+
const featureDeclarations = getStylesDeclarations(featureStyles);
|
|
545
|
+
delete styles[featureName];
|
|
546
|
+
|
|
547
|
+
if (!!featureDeclarations.length) {
|
|
548
|
+
ruleset = ruleset + `${featureSelector}{${featureDeclarations.join(';')} }`;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
|
|
371
554
|
const duotoneStyles = {};
|
|
372
555
|
|
|
373
556
|
if (styles !== null && styles !== void 0 && styles.filter) {
|
|
@@ -384,16 +567,55 @@ const toStyles = (tree, blockSelectors, hasBlockGapSupport) => {
|
|
|
384
567
|
}
|
|
385
568
|
|
|
386
569
|
ruleset = ruleset + `${duotoneSelector}{${duotoneDeclarations.join(';')};}`;
|
|
387
|
-
} // Process
|
|
570
|
+
} // Process blockGap and layout styles.
|
|
388
571
|
|
|
389
572
|
|
|
390
|
-
|
|
573
|
+
if (_utils.ROOT_BLOCK_SELECTOR === selector || hasLayoutSupport) {
|
|
574
|
+
ruleset += getLayoutStyles({
|
|
575
|
+
tree,
|
|
576
|
+
style: styles,
|
|
577
|
+
selector,
|
|
578
|
+
hasBlockGapSupport,
|
|
579
|
+
hasFallbackGapSupport,
|
|
580
|
+
fallbackGapValue
|
|
581
|
+
});
|
|
582
|
+
} // Process the remaining block styles (they use either normal block class or __experimentalSelector).
|
|
391
583
|
|
|
392
|
-
if (declarations.length === 0) {
|
|
393
|
-
return;
|
|
394
|
-
}
|
|
395
584
|
|
|
396
|
-
|
|
585
|
+
const declarations = getStylesDeclarations(styles, selector, useRootPaddingAlign);
|
|
586
|
+
|
|
587
|
+
if (declarations !== null && declarations !== void 0 && declarations.length) {
|
|
588
|
+
ruleset = ruleset + `${selector}{${declarations.join(';')};}`;
|
|
589
|
+
} // Check for pseudo selector in `styles` and handle separately.
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
const pseudoSelectorStyles = Object.entries(styles).filter(_ref15 => {
|
|
593
|
+
let [key] = _ref15;
|
|
594
|
+
return key.startsWith(':');
|
|
595
|
+
});
|
|
596
|
+
|
|
597
|
+
if (pseudoSelectorStyles !== null && pseudoSelectorStyles !== void 0 && pseudoSelectorStyles.length) {
|
|
598
|
+
pseudoSelectorStyles.forEach(_ref16 => {
|
|
599
|
+
let [pseudoKey, pseudoStyle] = _ref16;
|
|
600
|
+
const pseudoDeclarations = getStylesDeclarations(pseudoStyle);
|
|
601
|
+
|
|
602
|
+
if (!(pseudoDeclarations !== null && pseudoDeclarations !== void 0 && pseudoDeclarations.length)) {
|
|
603
|
+
return;
|
|
604
|
+
} // `selector` maybe provided in a form
|
|
605
|
+
// where block level selectors have sub element
|
|
606
|
+
// selectors appended to them as a comma separated
|
|
607
|
+
// string.
|
|
608
|
+
// e.g. `h1 a,h2 a,h3 a,h4 a,h5 a,h6 a`;
|
|
609
|
+
// Split and append pseudo selector to create
|
|
610
|
+
// the proper rules to target the elements.
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
const _selector = selector.split(',').map(sel => sel + pseudoKey).join(',');
|
|
614
|
+
|
|
615
|
+
const pseudoRule = `${_selector}{${pseudoDeclarations.join(';')};}`;
|
|
616
|
+
ruleset = ruleset + pseudoRule;
|
|
617
|
+
});
|
|
618
|
+
}
|
|
397
619
|
});
|
|
398
620
|
/* Add alignment / layout styles */
|
|
399
621
|
|
|
@@ -402,15 +624,19 @@ const toStyles = (tree, blockSelectors, hasBlockGapSupport) => {
|
|
|
402
624
|
ruleset = ruleset + '.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }';
|
|
403
625
|
|
|
404
626
|
if (hasBlockGapSupport) {
|
|
627
|
+
var _tree$styles3, _tree$styles3$spacing;
|
|
628
|
+
|
|
629
|
+
// Use fallback of `0.5em` just in case, however if there is blockGap support, there should nearly always be a real value.
|
|
630
|
+
const gapValue = (0, _blockEditor.__experimentalGetGapCSSValue)(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';
|
|
405
631
|
ruleset = ruleset + '.wp-site-blocks > * { margin-block-start: 0; margin-block-end: 0; }';
|
|
406
|
-
ruleset = ruleset +
|
|
632
|
+
ruleset = ruleset + `.wp-site-blocks > * + * { margin-block-start: ${gapValue}; }`;
|
|
407
633
|
}
|
|
408
634
|
|
|
409
|
-
nodesWithSettings.forEach(
|
|
635
|
+
nodesWithSettings.forEach(_ref17 => {
|
|
410
636
|
let {
|
|
411
637
|
selector,
|
|
412
638
|
presets
|
|
413
|
-
} =
|
|
639
|
+
} = _ref17;
|
|
414
640
|
|
|
415
641
|
if (_utils.ROOT_BLOCK_SELECTOR === selector) {
|
|
416
642
|
// Do not add extra specificity for top-level classes.
|
|
@@ -430,10 +656,10 @@ exports.toStyles = toStyles;
|
|
|
430
656
|
|
|
431
657
|
function toSvgFilters(tree, blockSelectors) {
|
|
432
658
|
const nodesWithSettings = getNodesWithSettings(tree, blockSelectors);
|
|
433
|
-
return nodesWithSettings.flatMap(
|
|
659
|
+
return nodesWithSettings.flatMap(_ref18 => {
|
|
434
660
|
let {
|
|
435
661
|
presets
|
|
436
|
-
} =
|
|
662
|
+
} = _ref18;
|
|
437
663
|
return getPresetsSvgFilters(presets);
|
|
438
664
|
});
|
|
439
665
|
}
|
|
@@ -441,20 +667,39 @@ function toSvgFilters(tree, blockSelectors) {
|
|
|
441
667
|
const getBlockSelectors = blockTypes => {
|
|
442
668
|
const result = {};
|
|
443
669
|
blockTypes.forEach(blockType => {
|
|
444
|
-
var _blockType$supports$_, _blockType$supports, _blockType$supports$c, _blockType$supports2, _blockType$supports2
|
|
670
|
+
var _blockType$supports$_, _blockType$supports, _blockType$supports$c, _blockType$supports2, _blockType$supports2$, _blockType$supports3, _blockType$supports4, _blockType$supports4$, _blockType$supports4$2;
|
|
445
671
|
|
|
446
672
|
const name = blockType.name;
|
|
447
673
|
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('/', '-');
|
|
448
674
|
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;
|
|
675
|
+
const hasLayoutSupport = !!(blockType !== null && blockType !== void 0 && (_blockType$supports3 = blockType.supports) !== null && _blockType$supports3 !== void 0 && _blockType$supports3.__experimentalLayout);
|
|
676
|
+
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.
|
|
677
|
+
|
|
678
|
+
const featureSelectors = {};
|
|
679
|
+
Object.entries(BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS).forEach(_ref19 => {
|
|
680
|
+
var _blockType$supports5, _blockType$supports5$;
|
|
681
|
+
|
|
682
|
+
let [featureKey, featureName] = _ref19;
|
|
683
|
+
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;
|
|
684
|
+
|
|
685
|
+
if (featureSelector) {
|
|
686
|
+
featureSelectors[featureName] = (0, _utils.scopeSelector)(selector, featureSelector);
|
|
687
|
+
}
|
|
688
|
+
});
|
|
449
689
|
result[name] = {
|
|
690
|
+
duotoneSelector,
|
|
691
|
+
fallbackGapValue,
|
|
692
|
+
featureSelectors: Object.keys(featureSelectors).length ? featureSelectors : undefined,
|
|
693
|
+
hasLayoutSupport,
|
|
450
694
|
name,
|
|
451
|
-
selector
|
|
452
|
-
duotoneSelector
|
|
695
|
+
selector
|
|
453
696
|
};
|
|
454
697
|
});
|
|
455
698
|
return result;
|
|
456
699
|
};
|
|
457
700
|
|
|
701
|
+
exports.getBlockSelectors = getBlockSelectors;
|
|
702
|
+
|
|
458
703
|
function useGlobalStylesOutput() {
|
|
459
704
|
const [stylesheets, setStylesheets] = (0, _element.useState)([]);
|
|
460
705
|
const [settings, setSettings] = (0, _element.useState)({});
|
|
@@ -464,6 +709,8 @@ function useGlobalStylesOutput() {
|
|
|
464
709
|
} = (0, _element.useContext)(_context.GlobalStylesContext);
|
|
465
710
|
const [blockGap] = (0, _hooks.useSetting)('spacing.blockGap');
|
|
466
711
|
const hasBlockGapSupport = blockGap !== null;
|
|
712
|
+
const hasFallbackGapSupport = !hasBlockGapSupport; // This setting isn't useful yet: it exists as a placeholder for a future explicit fallback styles support.
|
|
713
|
+
|
|
467
714
|
(0, _element.useEffect)(() => {
|
|
468
715
|
if (!(mergedConfig !== null && mergedConfig !== void 0 && mergedConfig.styles) || !(mergedConfig !== null && mergedConfig !== void 0 && mergedConfig.settings)) {
|
|
469
716
|
return;
|
|
@@ -471,7 +718,7 @@ function useGlobalStylesOutput() {
|
|
|
471
718
|
|
|
472
719
|
const blockSelectors = getBlockSelectors((0, _blocks.getBlockTypes)());
|
|
473
720
|
const customProperties = toCustomProperties(mergedConfig, blockSelectors);
|
|
474
|
-
const globalStyles = toStyles(mergedConfig, blockSelectors, hasBlockGapSupport);
|
|
721
|
+
const globalStyles = toStyles(mergedConfig, blockSelectors, hasBlockGapSupport, hasFallbackGapSupport);
|
|
475
722
|
const filters = toSvgFilters(mergedConfig, blockSelectors);
|
|
476
723
|
setStylesheets([{
|
|
477
724
|
css: customProperties,
|
|
@@ -482,7 +729,7 @@ function useGlobalStylesOutput() {
|
|
|
482
729
|
}]);
|
|
483
730
|
setSettings(mergedConfig.settings);
|
|
484
731
|
setSvgFilters(filters);
|
|
485
|
-
}, [mergedConfig]);
|
|
732
|
+
}, [hasBlockGapSupport, hasFallbackGapSupport, mergedConfig]);
|
|
486
733
|
return [stylesheets, settings, svgFilters, hasBlockGapSupport];
|
|
487
734
|
}
|
|
488
735
|
//# sourceMappingURL=use-global-styles-output.js.map
|