@wordpress/block-editor 11.6.0 → 11.7.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/README.md +4 -0
- package/build/components/block-list/block-html.js +1 -3
- package/build/components/block-list/block-html.js.map +1 -1
- package/build/components/block-preview/auto.js +6 -23
- package/build/components/block-preview/auto.js.map +1 -1
- package/build/components/editor-styles/index.js +20 -2
- package/build/components/editor-styles/index.js.map +1 -1
- package/build/components/global-styles/color-panel.js +583 -0
- package/build/components/global-styles/color-panel.js.map +1 -0
- package/build/components/global-styles/dimensions-panel.js +8 -30
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/global-styles/get-block-css-selector.js +129 -0
- package/build/components/global-styles/get-block-css-selector.js.map +1 -0
- package/build/components/global-styles/hooks.js +53 -1
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/index.js +18 -2
- package/build/components/global-styles/index.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +9 -35
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +160 -86
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/global-styles/utils.js +2 -1
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/image-size-control/index.js +8 -5
- package/build/components/image-size-control/index.js.map +1 -1
- package/build/components/inspector-controls-tabs/position-controls-panel.js +43 -7
- package/build/components/inspector-controls-tabs/position-controls-panel.js.map +1 -1
- package/build/components/line-height-control/index.js +15 -1
- package/build/components/line-height-control/index.js.map +1 -1
- package/build/components/list-view/appender.js +105 -0
- package/build/components/list-view/appender.js.map +1 -0
- package/build/components/list-view/block.js +5 -5
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/list-view/branch.js +25 -5
- package/build/components/list-view/branch.js.map +1 -1
- package/build/components/list-view/index.js +37 -13
- package/build/components/list-view/index.js.map +1 -1
- package/build/components/media-replace-flow/index.js +13 -4
- package/build/components/media-replace-flow/index.js.map +1 -1
- package/build/components/rich-text/format-edit.js +2 -30
- package/build/components/rich-text/format-edit.js.map +1 -1
- package/build/components/writing-flow/use-input.js +4 -8
- package/build/components/writing-flow/use-input.js.map +1 -1
- package/build/hooks/border.js +0 -1
- package/build/hooks/border.js.map +1 -1
- package/build/hooks/color.js +92 -229
- package/build/hooks/color.js.map +1 -1
- package/build/hooks/content-lock-ui.js +4 -2
- package/build/hooks/content-lock-ui.js.map +1 -1
- package/build/hooks/{color-panel.js → contrast-checker.js} +11 -49
- package/build/hooks/contrast-checker.js.map +1 -0
- package/build/hooks/dimensions.js +0 -1
- package/build/hooks/dimensions.js.map +1 -1
- package/build/hooks/duotone.js +3 -1
- package/build/hooks/duotone.js.map +1 -1
- package/build/hooks/position.js +2 -2
- package/build/hooks/position.js.map +1 -1
- package/build/hooks/style.js +23 -26
- package/build/hooks/style.js.map +1 -1
- package/build/hooks/typography.js +0 -1
- package/build/hooks/typography.js.map +1 -1
- package/build/hooks/utils.js +25 -76
- package/build/hooks/utils.js.map +1 -1
- package/build/layouts/grid.js +165 -0
- package/build/layouts/grid.js.map +1 -0
- package/build/layouts/index.js +3 -1
- package/build/layouts/index.js.map +1 -1
- package/build/private-apis.js +4 -1
- package/build/private-apis.js.map +1 -1
- package/build/utils/object.js +76 -0
- package/build/utils/object.js.map +1 -0
- package/build-module/components/block-list/block-html.js +1 -3
- package/build-module/components/block-list/block-html.js.map +1 -1
- package/build-module/components/block-preview/auto.js +6 -22
- package/build-module/components/block-preview/auto.js.map +1 -1
- package/build-module/components/editor-styles/index.js +19 -2
- package/build-module/components/editor-styles/index.js.map +1 -1
- package/build-module/components/global-styles/color-panel.js +554 -0
- package/build-module/components/global-styles/color-panel.js.map +1 -0
- package/build-module/components/global-styles/dimensions-panel.js +7 -30
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/global-styles/get-block-css-selector.js +120 -0
- package/build-module/components/global-styles/get-block-css-selector.js.map +1 -0
- package/build-module/components/global-styles/hooks.js +51 -1
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/index.js +3 -1
- package/build-module/components/global-styles/index.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +8 -35
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +161 -87
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/global-styles/utils.js +2 -1
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/image-size-control/index.js +8 -5
- package/build-module/components/image-size-control/index.js.map +1 -1
- package/build-module/components/inspector-controls-tabs/position-controls-panel.js +42 -7
- package/build-module/components/inspector-controls-tabs/position-controls-panel.js.map +1 -1
- package/build-module/components/line-height-control/index.js +15 -1
- package/build-module/components/line-height-control/index.js.map +1 -1
- package/build-module/components/list-view/appender.js +88 -0
- package/build-module/components/list-view/appender.js.map +1 -0
- package/build-module/components/list-view/block.js +5 -4
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/list-view/branch.js +22 -5
- package/build-module/components/list-view/branch.js.map +1 -1
- package/build-module/components/list-view/index.js +32 -12
- package/build-module/components/list-view/index.js.map +1 -1
- package/build-module/components/media-replace-flow/index.js +12 -4
- package/build-module/components/media-replace-flow/index.js.map +1 -1
- package/build-module/components/rich-text/format-edit.js +3 -31
- package/build-module/components/rich-text/format-edit.js.map +1 -1
- package/build-module/components/writing-flow/use-input.js +4 -8
- package/build-module/components/writing-flow/use-input.js.map +1 -1
- package/build-module/hooks/border.js +0 -1
- package/build-module/hooks/border.js.map +1 -1
- package/build-module/hooks/color.js +90 -232
- package/build-module/hooks/color.js.map +1 -1
- package/build-module/hooks/content-lock-ui.js +4 -2
- package/build-module/hooks/content-lock-ui.js.map +1 -1
- package/build-module/hooks/{color-panel.js → contrast-checker.js} +10 -44
- package/build-module/hooks/contrast-checker.js.map +1 -0
- package/build-module/hooks/dimensions.js +0 -1
- package/build-module/hooks/dimensions.js.map +1 -1
- package/build-module/hooks/duotone.js +4 -2
- package/build-module/hooks/duotone.js.map +1 -1
- package/build-module/hooks/position.js +3 -3
- package/build-module/hooks/position.js.map +1 -1
- package/build-module/hooks/style.js +23 -26
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/hooks/typography.js +0 -1
- package/build-module/hooks/typography.js.map +1 -1
- package/build-module/hooks/utils.js +23 -73
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/layouts/grid.js +151 -0
- package/build-module/layouts/grid.js.map +1 -0
- package/build-module/layouts/index.js +2 -1
- package/build-module/layouts/index.js.map +1 -1
- package/build-module/private-apis.js +3 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/utils/object.js +69 -0
- package/build-module/utils/object.js.map +1 -0
- package/build-style/style-rtl.css +26 -6
- package/build-style/style.css +26 -6
- package/package.json +31 -31
- package/src/components/block-draggable/content.scss +1 -1
- package/src/components/block-list/block-html.js +1 -1
- package/src/components/block-preview/auto.js +2 -17
- package/src/components/colors-gradients/style.scss +8 -8
- package/src/components/editor-styles/index.js +29 -1
- package/src/components/global-styles/color-panel.js +706 -0
- package/src/components/global-styles/dimensions-panel.js +13 -42
- package/src/components/global-styles/get-block-css-selector.js +129 -0
- package/src/components/global-styles/hooks.js +80 -0
- package/src/components/global-styles/index.js +2 -1
- package/src/components/global-styles/test/use-global-styles-output.js +30 -1
- package/src/components/global-styles/typography-panel.js +26 -51
- package/src/components/global-styles/use-global-styles-output.js +163 -80
- package/src/components/global-styles/utils.js +3 -0
- package/src/components/image-size-control/index.js +4 -3
- package/src/components/image-size-control/test/index.js +2 -2
- package/src/components/inner-blocks/README.md +1 -1
- package/src/components/inspector-controls-tabs/position-controls-panel.js +40 -9
- package/src/components/line-height-control/index.js +10 -1
- package/src/components/list-view/appender.js +101 -0
- package/src/components/list-view/block.js +5 -4
- package/src/components/list-view/branch.js +30 -1
- package/src/components/list-view/index.js +43 -10
- package/src/components/list-view/style.scss +19 -0
- package/src/components/media-replace-flow/index.js +36 -24
- package/src/components/media-replace-flow/style.scss +5 -2
- package/src/components/rich-text/format-edit.js +2 -32
- package/src/components/writing-flow/use-input.js +4 -5
- package/src/hooks/border.js +0 -1
- package/src/hooks/color.js +120 -296
- package/src/hooks/content-lock-ui.js +6 -2
- package/src/hooks/{color-panel.js → contrast-checker.js} +10 -46
- package/src/hooks/dimensions.js +0 -1
- package/src/hooks/duotone.js +8 -5
- package/src/hooks/position.js +3 -3
- package/src/hooks/style.js +29 -28
- package/src/hooks/test/utils.js +0 -104
- package/src/hooks/typography.js +0 -1
- package/src/hooks/utils.js +27 -70
- package/src/layouts/grid.js +172 -0
- package/src/layouts/index.js +2 -1
- package/src/layouts/test/grid.js +21 -0
- package/src/private-apis.js +2 -0
- package/src/utils/object.js +69 -0
- package/src/utils/test/object.js +107 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build/hooks/color-panel.js.map +0 -1
- package/build-module/hooks/color-panel.js.map +0 -1
|
@@ -28,6 +28,7 @@ import SpacingSizesControl from '../spacing-sizes-control';
|
|
|
28
28
|
import HeightControl from '../height-control';
|
|
29
29
|
import ChildLayoutControl from '../child-layout-control';
|
|
30
30
|
import { cleanEmptyObject } from '../../hooks/utils';
|
|
31
|
+
import { immutableSet } from '../../utils/object';
|
|
31
32
|
|
|
32
33
|
const AXIAL_SIDES = [ 'horizontal', 'vertical' ];
|
|
33
34
|
|
|
@@ -223,13 +224,9 @@ export default function DimensionsPanel( {
|
|
|
223
224
|
useHasContentSize( settings ) && includeLayoutControls;
|
|
224
225
|
const contentSizeValue = decodeValue( inheritedValue?.layout?.contentSize );
|
|
225
226
|
const setContentSizeValue = ( newValue ) => {
|
|
226
|
-
onChange(
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
...value?.layout,
|
|
230
|
-
contentSize: newValue,
|
|
231
|
-
},
|
|
232
|
-
} );
|
|
227
|
+
onChange(
|
|
228
|
+
immutableSet( value, [ 'layout', 'contentSize' ], newValue )
|
|
229
|
+
);
|
|
233
230
|
};
|
|
234
231
|
const hasUserSetContentSizeValue = () => !! value?.layout?.contentSize;
|
|
235
232
|
const resetContentSizeValue = () => setContentSizeValue( undefined );
|
|
@@ -239,13 +236,7 @@ export default function DimensionsPanel( {
|
|
|
239
236
|
useHasWideSize( settings ) && includeLayoutControls;
|
|
240
237
|
const wideSizeValue = decodeValue( inheritedValue?.layout?.wideSize );
|
|
241
238
|
const setWideSizeValue = ( newValue ) => {
|
|
242
|
-
onChange(
|
|
243
|
-
...value,
|
|
244
|
-
layout: {
|
|
245
|
-
...value?.layout,
|
|
246
|
-
wideSize: newValue,
|
|
247
|
-
},
|
|
248
|
-
} );
|
|
239
|
+
onChange( immutableSet( value, [ 'layout', 'wideSize' ], newValue ) );
|
|
249
240
|
};
|
|
250
241
|
const hasUserSetWideSizeValue = () => !! value?.layout?.wideSize;
|
|
251
242
|
const resetWideSizeValue = () => setWideSizeValue( undefined );
|
|
@@ -262,13 +253,7 @@ export default function DimensionsPanel( {
|
|
|
262
253
|
paddingSides.some( ( side ) => AXIAL_SIDES.includes( side ) );
|
|
263
254
|
const setPaddingValues = ( newPaddingValues ) => {
|
|
264
255
|
const padding = filterValuesBySides( newPaddingValues, paddingSides );
|
|
265
|
-
onChange(
|
|
266
|
-
...value,
|
|
267
|
-
spacing: {
|
|
268
|
-
...value?.spacing,
|
|
269
|
-
padding,
|
|
270
|
-
},
|
|
271
|
-
} );
|
|
256
|
+
onChange( immutableSet( value, [ 'spacing', 'padding' ], padding ) );
|
|
272
257
|
};
|
|
273
258
|
const hasPaddingValue = () =>
|
|
274
259
|
!! value?.spacing?.padding &&
|
|
@@ -288,13 +273,7 @@ export default function DimensionsPanel( {
|
|
|
288
273
|
marginSides.some( ( side ) => AXIAL_SIDES.includes( side ) );
|
|
289
274
|
const setMarginValues = ( newMarginValues ) => {
|
|
290
275
|
const margin = filterValuesBySides( newMarginValues, marginSides );
|
|
291
|
-
onChange(
|
|
292
|
-
...value,
|
|
293
|
-
spacing: {
|
|
294
|
-
...value?.spacing,
|
|
295
|
-
margin,
|
|
296
|
-
},
|
|
297
|
-
} );
|
|
276
|
+
onChange( immutableSet( value, [ 'spacing', 'margin' ], margin ) );
|
|
298
277
|
};
|
|
299
278
|
const hasMarginValue = () =>
|
|
300
279
|
!! value?.spacing?.margin &&
|
|
@@ -312,13 +291,9 @@ export default function DimensionsPanel( {
|
|
|
312
291
|
const isAxialGap =
|
|
313
292
|
gapSides && gapSides.some( ( side ) => AXIAL_SIDES.includes( side ) );
|
|
314
293
|
const setGapValue = ( newGapValue ) => {
|
|
315
|
-
onChange(
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
...value?.spacing,
|
|
319
|
-
blockGap: newGapValue,
|
|
320
|
-
},
|
|
321
|
-
} );
|
|
294
|
+
onChange(
|
|
295
|
+
immutableSet( value, [ 'spacing', 'blockGap' ], newGapValue )
|
|
296
|
+
);
|
|
322
297
|
};
|
|
323
298
|
const setGapValues = ( nextBoxGapValue ) => {
|
|
324
299
|
if ( ! nextBoxGapValue ) {
|
|
@@ -341,13 +316,9 @@ export default function DimensionsPanel( {
|
|
|
341
316
|
const showMinHeightControl = useHasMinHeight( settings );
|
|
342
317
|
const minHeightValue = decodeValue( inheritedValue?.dimensions?.minHeight );
|
|
343
318
|
const setMinHeightValue = ( newValue ) => {
|
|
344
|
-
onChange(
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
...value?.dimensions,
|
|
348
|
-
minHeight: newValue,
|
|
349
|
-
},
|
|
350
|
-
} );
|
|
319
|
+
onChange(
|
|
320
|
+
immutableSet( value, [ 'dimensions', 'minHeight' ], newValue )
|
|
321
|
+
);
|
|
351
322
|
};
|
|
352
323
|
const resetMinHeightValue = () => {
|
|
353
324
|
setMinHeightValue( undefined );
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { get, isEmpty } from 'lodash';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { scopeSelector } from './utils';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Determine the CSS selector for the block type and target provided, returning
|
|
13
|
+
* it if available.
|
|
14
|
+
*
|
|
15
|
+
* @param {import('@wordpress/blocks').Block} blockType The block's type.
|
|
16
|
+
* @param {string|string[]} target The desired selector's target e.g. `root`, delimited string, or array path.
|
|
17
|
+
* @param {Object} options Options object.
|
|
18
|
+
* @param {boolean} options.fallback Whether or not to fallback to broader selector.
|
|
19
|
+
*
|
|
20
|
+
* @return {?string} The CSS selector or `null` if no selector available.
|
|
21
|
+
*/
|
|
22
|
+
export function getBlockCSSSelector(
|
|
23
|
+
blockType,
|
|
24
|
+
target = 'root',
|
|
25
|
+
options = {}
|
|
26
|
+
) {
|
|
27
|
+
if ( ! target ) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const { fallback = false } = options;
|
|
32
|
+
const { name, selectors, supports } = blockType;
|
|
33
|
+
|
|
34
|
+
const hasSelectors = ! isEmpty( selectors );
|
|
35
|
+
const path = Array.isArray( target ) ? target.join( '.' ) : target;
|
|
36
|
+
|
|
37
|
+
// Duotone ( no fallback selectors for Duotone ).
|
|
38
|
+
if ( path === 'filter.duotone' ) {
|
|
39
|
+
// If selectors API in use, only use its value or null.
|
|
40
|
+
if ( hasSelectors ) {
|
|
41
|
+
return get( selectors, path, null );
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Selectors API, not available, check for old experimental selector.
|
|
45
|
+
return get( supports, 'color.__experimentalDuotone', null );
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Root selector.
|
|
49
|
+
|
|
50
|
+
// Calculated before returning as it can be used as a fallback for feature
|
|
51
|
+
// selectors later on.
|
|
52
|
+
let rootSelector = null;
|
|
53
|
+
|
|
54
|
+
if ( hasSelectors && selectors.root ) {
|
|
55
|
+
// Use the selectors API if available.
|
|
56
|
+
rootSelector = selectors?.root;
|
|
57
|
+
} else if ( supports?.__experimentalSelector ) {
|
|
58
|
+
// Use the old experimental selector supports property if set.
|
|
59
|
+
rootSelector = supports.__experimentalSelector;
|
|
60
|
+
} else {
|
|
61
|
+
// If no root selector found, generate default block class selector.
|
|
62
|
+
rootSelector =
|
|
63
|
+
'.wp-block-' + name.replace( 'core/', '' ).replace( '/', '-' );
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Return selector if it's the root target we are looking for.
|
|
67
|
+
if ( path === 'root' ) {
|
|
68
|
+
return rootSelector;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// If target is not `root` or `duotone` we have a feature or subfeature
|
|
72
|
+
// as the target. If the target is a string convert to an array.
|
|
73
|
+
const pathArray = Array.isArray( target ) ? target : target.split( '.' );
|
|
74
|
+
|
|
75
|
+
// Feature selectors ( may fallback to root selector );
|
|
76
|
+
if ( pathArray.length === 1 ) {
|
|
77
|
+
const fallbackSelector = fallback ? rootSelector : null;
|
|
78
|
+
|
|
79
|
+
// Prefer the selectors API if available.
|
|
80
|
+
if ( hasSelectors ) {
|
|
81
|
+
// Get selector from either `feature.root` or shorthand path.
|
|
82
|
+
const featureSelector =
|
|
83
|
+
get( selectors, `${ path }.root`, null ) ||
|
|
84
|
+
get( selectors, path, null );
|
|
85
|
+
|
|
86
|
+
// Return feature selector if found or any available fallback.
|
|
87
|
+
return featureSelector || fallbackSelector;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Try getting old experimental supports selector value.
|
|
91
|
+
const featureSelector = get(
|
|
92
|
+
supports,
|
|
93
|
+
`${ path }.__experimentalSelector`,
|
|
94
|
+
null
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
// If nothing to work with, provide fallback selector if available.
|
|
98
|
+
if ( ! featureSelector ) {
|
|
99
|
+
return fallbackSelector;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Scope the feature selector by the block's root selector.
|
|
103
|
+
return scopeSelector( rootSelector, featureSelector );
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Subfeature selector.
|
|
107
|
+
// This may fallback either to parent feature or root selector.
|
|
108
|
+
let subfeatureSelector;
|
|
109
|
+
|
|
110
|
+
// Use selectors API if available.
|
|
111
|
+
if ( hasSelectors ) {
|
|
112
|
+
subfeatureSelector = get( selectors, path, null );
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Only return if we have a subfeature selector.
|
|
116
|
+
if ( subfeatureSelector ) {
|
|
117
|
+
return subfeatureSelector;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// To this point we don't have a subfeature selector. If a fallback has been
|
|
121
|
+
// requested, remove subfeature from target path and return results of a
|
|
122
|
+
// call for the parent feature's selector.
|
|
123
|
+
if ( fallback ) {
|
|
124
|
+
return getBlockCSSSelector( blockType, pathArray[ 0 ], options );
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// We tried.
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
@@ -31,6 +31,8 @@ const VALID_SETTINGS = [
|
|
|
31
31
|
'shadow.presets',
|
|
32
32
|
'shadow.defaultPresets',
|
|
33
33
|
'color.background',
|
|
34
|
+
'color.button',
|
|
35
|
+
'color.caption',
|
|
34
36
|
'color.custom',
|
|
35
37
|
'color.customDuotone',
|
|
36
38
|
'color.customGradient',
|
|
@@ -39,6 +41,7 @@ const VALID_SETTINGS = [
|
|
|
39
41
|
'color.defaultPalette',
|
|
40
42
|
'color.duotone',
|
|
41
43
|
'color.gradients',
|
|
44
|
+
'color.heading',
|
|
42
45
|
'color.link',
|
|
43
46
|
'color.palette',
|
|
44
47
|
'color.text',
|
|
@@ -251,6 +254,35 @@ export function useSettingsForBlockElement(
|
|
|
251
254
|
};
|
|
252
255
|
}
|
|
253
256
|
|
|
257
|
+
updatedSettings.color = {
|
|
258
|
+
...updatedSettings.color,
|
|
259
|
+
text:
|
|
260
|
+
updatedSettings.color?.text &&
|
|
261
|
+
supportedStyles.includes( 'color' ),
|
|
262
|
+
background:
|
|
263
|
+
updatedSettings.color?.background &&
|
|
264
|
+
( supportedStyles.includes( 'background' ) ||
|
|
265
|
+
supportedStyles.includes( 'backgroundColor' ) ),
|
|
266
|
+
button:
|
|
267
|
+
updatedSettings.color?.button &&
|
|
268
|
+
supportedStyles.includes( 'buttonColor' ),
|
|
269
|
+
heading:
|
|
270
|
+
updatedSettings.color?.heading &&
|
|
271
|
+
supportedStyles.includes( 'headingColor' ),
|
|
272
|
+
link:
|
|
273
|
+
updatedSettings.color?.link &&
|
|
274
|
+
supportedStyles.includes( 'linkColor' ),
|
|
275
|
+
caption:
|
|
276
|
+
updatedSettings.color?.caption &&
|
|
277
|
+
supportedStyles.includes( 'captionColor' ),
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
// Some blocks can enable background colors but disable gradients.
|
|
281
|
+
if ( ! supportedStyles.includes( 'background' ) ) {
|
|
282
|
+
updatedSettings.color.gradients = [];
|
|
283
|
+
updatedSettings.color.customGradient = false;
|
|
284
|
+
}
|
|
285
|
+
|
|
254
286
|
[
|
|
255
287
|
'lineHeight',
|
|
256
288
|
'fontStyle',
|
|
@@ -379,3 +411,51 @@ export function useColorsPerOrigin( settings ) {
|
|
|
379
411
|
shouldDisplayDefaultColors,
|
|
380
412
|
] );
|
|
381
413
|
}
|
|
414
|
+
|
|
415
|
+
export function useGradientsPerOrigin( settings ) {
|
|
416
|
+
const customGradients = settings?.color?.gradients?.custom;
|
|
417
|
+
const themeGradients = settings?.color?.gradients?.theme;
|
|
418
|
+
const defaultGradients = settings?.color?.gradients?.default;
|
|
419
|
+
const shouldDisplayDefaultGradients = settings?.color?.defaultGradients;
|
|
420
|
+
|
|
421
|
+
return useMemo( () => {
|
|
422
|
+
const result = [];
|
|
423
|
+
if ( themeGradients && themeGradients.length ) {
|
|
424
|
+
result.push( {
|
|
425
|
+
name: _x(
|
|
426
|
+
'Theme',
|
|
427
|
+
'Indicates this palette comes from the theme.'
|
|
428
|
+
),
|
|
429
|
+
gradients: themeGradients,
|
|
430
|
+
} );
|
|
431
|
+
}
|
|
432
|
+
if (
|
|
433
|
+
shouldDisplayDefaultGradients &&
|
|
434
|
+
defaultGradients &&
|
|
435
|
+
defaultGradients.length
|
|
436
|
+
) {
|
|
437
|
+
result.push( {
|
|
438
|
+
name: _x(
|
|
439
|
+
'Default',
|
|
440
|
+
'Indicates this palette comes from WordPress.'
|
|
441
|
+
),
|
|
442
|
+
gradients: defaultGradients,
|
|
443
|
+
} );
|
|
444
|
+
}
|
|
445
|
+
if ( customGradients && customGradients.length ) {
|
|
446
|
+
result.push( {
|
|
447
|
+
name: _x(
|
|
448
|
+
'Custom',
|
|
449
|
+
'Indicates this palette is created by the user.'
|
|
450
|
+
),
|
|
451
|
+
gradients: customGradients,
|
|
452
|
+
} );
|
|
453
|
+
}
|
|
454
|
+
return result;
|
|
455
|
+
}, [
|
|
456
|
+
customGradients,
|
|
457
|
+
themeGradients,
|
|
458
|
+
defaultGradients,
|
|
459
|
+
shouldDisplayDefaultGradients,
|
|
460
|
+
] );
|
|
461
|
+
}
|
|
@@ -3,8 +3,8 @@ export {
|
|
|
3
3
|
useGlobalSetting,
|
|
4
4
|
useGlobalStyle,
|
|
5
5
|
useSettingsForBlockElement,
|
|
6
|
-
useColorsPerOrigin,
|
|
7
6
|
} from './hooks';
|
|
7
|
+
export { getBlockCSSSelector } from './get-block-css-selector';
|
|
8
8
|
export { useGlobalStylesOutput } from './use-global-styles-output';
|
|
9
9
|
export { GlobalStylesContext } from './context';
|
|
10
10
|
export {
|
|
@@ -16,3 +16,4 @@ export {
|
|
|
16
16
|
useHasDimensionsPanel,
|
|
17
17
|
} from './dimensions-panel';
|
|
18
18
|
export { default as BorderPanel, useHasBorderPanel } from './border-panel';
|
|
19
|
+
export { default as ColorPanel, useHasColorPanel } from './color-panel';
|
|
@@ -480,7 +480,7 @@ describe( 'global styles renderer', () => {
|
|
|
480
480
|
expect( toStyles( tree, blockSelectors ) ).toEqual(
|
|
481
481
|
'body {margin: 0;}' +
|
|
482
482
|
'body{background-color: red;margin: 10px;padding: 10px;}a{color: blue;}a:hover{color: orange;}a:focus{color: orange;}h1{font-size: 42px;}.wp-block-group{margin-top: 10px;margin-right: 20px;margin-bottom: 30px;margin-left: 40px;padding-top: 11px;padding-right: 22px;padding-bottom: 33px;padding-left: 44px;}h1,h2,h3,h4,h5,h6{color: orange;}h1 a,h2 a,h3 a,h4 a,h5 a,h6 a{color: hotpink;}h1 a:hover,h2 a:hover,h3 a:hover,h4 a:hover,h5 a:hover,h6 a:hover{color: red;}h1 a:focus,h2 a:focus,h3 a:focus,h4 a:focus,h5 a:focus,h6 a:focus{color: red;}' +
|
|
483
|
-
'.wp-block-image img, .wp-block-image .wp-crop-area{border-radius: 9999px
|
|
483
|
+
'.wp-block-image img, .wp-block-image .wp-crop-area{border-radius: 9999px}.wp-block-image{color: red;}.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }' +
|
|
484
484
|
'.has-white-color{color: var(--wp--preset--color--white) !important;}.has-white-background-color{background-color: var(--wp--preset--color--white) !important;}.has-white-border-color{border-color: var(--wp--preset--color--white) !important;}.has-black-color{color: var(--wp--preset--color--black) !important;}.has-black-background-color{background-color: var(--wp--preset--color--black) !important;}.has-black-border-color{border-color: var(--wp--preset--color--black) !important;}h1.has-blue-color,h2.has-blue-color,h3.has-blue-color,h4.has-blue-color,h5.has-blue-color,h6.has-blue-color{color: var(--wp--preset--color--blue) !important;}h1.has-blue-background-color,h2.has-blue-background-color,h3.has-blue-background-color,h4.has-blue-background-color,h5.has-blue-background-color,h6.has-blue-background-color{background-color: var(--wp--preset--color--blue) !important;}h1.has-blue-border-color,h2.has-blue-border-color,h3.has-blue-border-color,h4.has-blue-border-color,h5.has-blue-border-color,h6.has-blue-border-color{border-color: var(--wp--preset--color--blue) !important;}'
|
|
485
485
|
);
|
|
486
486
|
} );
|
|
@@ -668,6 +668,34 @@ describe( 'global styles renderer', () => {
|
|
|
668
668
|
|
|
669
669
|
describe( 'getBlockSelectors', () => {
|
|
670
670
|
it( 'should return block selectors data', () => {
|
|
671
|
+
const imageSelectors = {
|
|
672
|
+
root: '.my-image',
|
|
673
|
+
border: '.my-image img, .my-image .crop-area',
|
|
674
|
+
filter: { duotone: 'img' },
|
|
675
|
+
};
|
|
676
|
+
const imageBlock = {
|
|
677
|
+
name: 'core/image',
|
|
678
|
+
selectors: imageSelectors,
|
|
679
|
+
};
|
|
680
|
+
const blockTypes = [ imageBlock ];
|
|
681
|
+
|
|
682
|
+
expect( getBlockSelectors( blockTypes, () => {} ) ).toEqual( {
|
|
683
|
+
'core/image': {
|
|
684
|
+
name: imageBlock.name,
|
|
685
|
+
selector: imageSelectors.root,
|
|
686
|
+
duotoneSelector: imageSelectors.filter.duotone,
|
|
687
|
+
fallbackGapValue: undefined,
|
|
688
|
+
featureSelectors: {
|
|
689
|
+
root: '.my-image',
|
|
690
|
+
border: '.my-image img, .my-image .crop-area',
|
|
691
|
+
filter: { duotone: 'img' },
|
|
692
|
+
},
|
|
693
|
+
hasLayoutSupport: false,
|
|
694
|
+
},
|
|
695
|
+
} );
|
|
696
|
+
} );
|
|
697
|
+
|
|
698
|
+
it( 'should return block selectors data with old experimental selectors', () => {
|
|
671
699
|
const imageSupports = {
|
|
672
700
|
__experimentalBorder: {
|
|
673
701
|
radius: true,
|
|
@@ -688,6 +716,7 @@ describe( 'global styles renderer', () => {
|
|
|
688
716
|
duotoneSelector: imageSupports.color.__experimentalDuotone,
|
|
689
717
|
fallbackGapValue: undefined,
|
|
690
718
|
featureSelectors: {
|
|
719
|
+
root: '.my-image',
|
|
691
720
|
border: '.my-image img, .my-image .crop-area',
|
|
692
721
|
},
|
|
693
722
|
hasLayoutSupport: false,
|
|
@@ -20,6 +20,7 @@ import LetterSpacingControl from '../letter-spacing-control';
|
|
|
20
20
|
import TextTransformControl from '../text-transform-control';
|
|
21
21
|
import TextDecorationControl from '../text-decoration-control';
|
|
22
22
|
import { getValueFromVariable } from './utils';
|
|
23
|
+
import { immutableSet } from '../../utils/object';
|
|
23
24
|
|
|
24
25
|
const MIN_TEXT_COLUMNS = 1;
|
|
25
26
|
const MAX_TEXT_COLUMNS = 6;
|
|
@@ -161,15 +162,13 @@ export default function TypographyPanel( {
|
|
|
161
162
|
const slug = fontFamilies?.find(
|
|
162
163
|
( { fontFamily: f } ) => f === newValue
|
|
163
164
|
)?.slug;
|
|
164
|
-
onChange(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
},
|
|
172
|
-
} );
|
|
165
|
+
onChange(
|
|
166
|
+
immutableSet(
|
|
167
|
+
value,
|
|
168
|
+
[ 'typography', 'fontFamily' ],
|
|
169
|
+
slug ? `var:preset|font-family|${ slug }` : newValue
|
|
170
|
+
)
|
|
171
|
+
);
|
|
173
172
|
};
|
|
174
173
|
const hasFontFamily = () => !! value?.typography?.fontFamily;
|
|
175
174
|
const resetFontFamily = () => setFontFamily( undefined );
|
|
@@ -188,13 +187,9 @@ export default function TypographyPanel( {
|
|
|
188
187
|
? `var:preset|font-size|${ metadata?.slug }`
|
|
189
188
|
: newValue;
|
|
190
189
|
|
|
191
|
-
onChange(
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
...value?.typography,
|
|
195
|
-
fontSize: actualValue,
|
|
196
|
-
},
|
|
197
|
-
} );
|
|
190
|
+
onChange(
|
|
191
|
+
immutableSet( value, [ 'typography', 'fontSize' ], actualValue )
|
|
192
|
+
);
|
|
198
193
|
};
|
|
199
194
|
const hasFontSize = () => !! value?.typography?.fontSize;
|
|
200
195
|
const resetFontSize = () => setFontSize( undefined );
|
|
@@ -229,13 +224,9 @@ export default function TypographyPanel( {
|
|
|
229
224
|
const hasLineHeightEnabled = useHasLineHeightControl( settings );
|
|
230
225
|
const lineHeight = decodeValue( inheritedValue?.typography?.lineHeight );
|
|
231
226
|
const setLineHeight = ( newValue ) => {
|
|
232
|
-
onChange(
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
...value?.typography,
|
|
236
|
-
lineHeight: newValue,
|
|
237
|
-
},
|
|
238
|
-
} );
|
|
227
|
+
onChange(
|
|
228
|
+
immutableSet( value, [ 'typography', 'lineHeight' ], newValue )
|
|
229
|
+
);
|
|
239
230
|
};
|
|
240
231
|
const hasLineHeight = () => !! value?.typography?.lineHeight;
|
|
241
232
|
const resetLineHeight = () => setLineHeight( undefined );
|
|
@@ -246,13 +237,9 @@ export default function TypographyPanel( {
|
|
|
246
237
|
inheritedValue?.typography?.letterSpacing
|
|
247
238
|
);
|
|
248
239
|
const setLetterSpacing = ( newValue ) => {
|
|
249
|
-
onChange(
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
...value?.typography,
|
|
253
|
-
letterSpacing: newValue,
|
|
254
|
-
},
|
|
255
|
-
} );
|
|
240
|
+
onChange(
|
|
241
|
+
immutableSet( value, [ 'typography', 'letterSpacing' ], newValue )
|
|
242
|
+
);
|
|
256
243
|
};
|
|
257
244
|
const hasLetterSpacing = () => !! value?.typography?.letterSpacing;
|
|
258
245
|
const resetLetterSpacing = () => setLetterSpacing( undefined );
|
|
@@ -261,13 +248,9 @@ export default function TypographyPanel( {
|
|
|
261
248
|
const hasTextColumnsControl = useHasTextColumnsControl( settings );
|
|
262
249
|
const textColumns = decodeValue( inheritedValue?.typography?.textColumns );
|
|
263
250
|
const setTextColumns = ( newValue ) => {
|
|
264
|
-
onChange(
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
...value?.typography,
|
|
268
|
-
textColumns: newValue,
|
|
269
|
-
},
|
|
270
|
-
} );
|
|
251
|
+
onChange(
|
|
252
|
+
immutableSet( value, [ 'typography', 'textColumns' ], newValue )
|
|
253
|
+
);
|
|
271
254
|
};
|
|
272
255
|
const hasTextColumns = () => !! value?.typography?.textColumns;
|
|
273
256
|
const resetTextColumns = () => setTextColumns( undefined );
|
|
@@ -278,13 +261,9 @@ export default function TypographyPanel( {
|
|
|
278
261
|
inheritedValue?.typography?.textTransform
|
|
279
262
|
);
|
|
280
263
|
const setTextTransform = ( newValue ) => {
|
|
281
|
-
onChange(
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
...value?.typography,
|
|
285
|
-
textTransform: newValue,
|
|
286
|
-
},
|
|
287
|
-
} );
|
|
264
|
+
onChange(
|
|
265
|
+
immutableSet( value, [ 'typography', 'textTransform' ], newValue )
|
|
266
|
+
);
|
|
288
267
|
};
|
|
289
268
|
const hasTextTransform = () => !! value?.typography?.textTransform;
|
|
290
269
|
const resetTextTransform = () => setTextTransform( undefined );
|
|
@@ -295,13 +274,9 @@ export default function TypographyPanel( {
|
|
|
295
274
|
inheritedValue?.typography?.textDecoration
|
|
296
275
|
);
|
|
297
276
|
const setTextDecoration = ( newValue ) => {
|
|
298
|
-
onChange(
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
...value?.typography,
|
|
302
|
-
textDecoration: newValue,
|
|
303
|
-
},
|
|
304
|
-
} );
|
|
277
|
+
onChange(
|
|
278
|
+
immutableSet( value, [ 'typography', 'textDecoration' ], newValue )
|
|
279
|
+
);
|
|
305
280
|
};
|
|
306
281
|
const hasTextDecoration = () => !! value?.typography?.textDecoration;
|
|
307
282
|
const resetTextDecoration = () => setTextDecoration( undefined );
|