@wordpress/block-editor 8.0.7 → 8.0.8
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/build/components/colors/with-colors.js +7 -4
- package/build/components/colors/with-colors.js.map +1 -1
- package/build/components/colors-gradients/control.js +2 -0
- package/build/components/colors-gradients/control.js.map +1 -1
- package/build/components/colors-gradients/panel-color-gradient-settings.js +2 -0
- package/build/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
- package/build/components/gradients/use-gradient.js +3 -3
- package/build/components/gradients/use-gradient.js.map +1 -1
- package/build/hooks/border-color.js +2 -1
- package/build/hooks/border-color.js.map +1 -1
- package/build/hooks/color-panel.js +2 -1
- package/build/hooks/color-panel.js.map +1 -1
- package/build/hooks/color.js +36 -22
- package/build/hooks/color.js.map +1 -1
- package/build/hooks/use-color-props.js +11 -7
- package/build/hooks/use-color-props.js.map +1 -1
- package/build-module/components/colors/with-colors.js +7 -4
- package/build-module/components/colors/with-colors.js.map +1 -1
- package/build-module/components/colors-gradients/control.js +2 -0
- package/build-module/components/colors-gradients/control.js.map +1 -1
- package/build-module/components/colors-gradients/panel-color-gradient-settings.js +2 -0
- package/build-module/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
- package/build-module/components/gradients/use-gradient.js +2 -3
- package/build-module/components/gradients/use-gradient.js.map +1 -1
- package/build-module/hooks/border-color.js +2 -1
- package/build-module/hooks/border-color.js.map +1 -1
- package/build-module/hooks/color-panel.js +2 -1
- package/build-module/hooks/color-panel.js.map +1 -1
- package/build-module/hooks/color.js +36 -22
- package/build-module/hooks/color.js.map +1 -1
- package/build-module/hooks/use-color-props.js +10 -6
- package/build-module/hooks/use-color-props.js.map +1 -1
- package/build-style/style-rtl.css +4 -1
- package/build-style/style.css +4 -1
- package/package.json +3 -3
- package/src/components/colors/with-colors.js +10 -5
- package/src/components/colors-gradients/control.js +4 -0
- package/src/components/colors-gradients/panel-color-gradient-settings.js +2 -0
- package/src/components/gradients/use-gradient.js +3 -1
- package/src/components/link-control/style.scss +6 -2
- package/src/hooks/border-color.js +1 -0
- package/src/hooks/color-panel.js +1 -0
- package/src/hooks/color.js +43 -35
- package/src/hooks/test/color.js +109 -0
- package/src/hooks/use-color-props.js +13 -6
package/src/hooks/color.js
CHANGED
|
@@ -32,6 +32,8 @@ import useSetting from '../components/use-setting';
|
|
|
32
32
|
|
|
33
33
|
export const COLOR_SUPPORT_KEY = 'color';
|
|
34
34
|
|
|
35
|
+
const EMPTY_OBJECT = {};
|
|
36
|
+
|
|
35
37
|
const hasColorSupport = ( blockType ) => {
|
|
36
38
|
const colorSupport = getBlockSupport( blockType, COLOR_SUPPORT_KEY );
|
|
37
39
|
return (
|
|
@@ -216,35 +218,35 @@ function immutableSet( object, path, value ) {
|
|
|
216
218
|
*/
|
|
217
219
|
export function ColorEdit( props ) {
|
|
218
220
|
const { name: blockName, attributes } = props;
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
221
|
+
// Some color settings have a special handling for deprecated flags in `useSetting`,
|
|
222
|
+
// so we can't unwrap them by doing const { ... } = useSetting('color')
|
|
223
|
+
// until https://github.com/WordPress/gutenberg/issues/37094 is fixed.
|
|
224
|
+
const userPalette = useSetting( 'color.palette.custom' );
|
|
225
|
+
const themePalette = useSetting( 'color.palette.theme' );
|
|
226
|
+
const defaultPalette = useSetting( 'color.palette.default' );
|
|
227
|
+
const allSolids = useMemo(
|
|
228
|
+
() => [
|
|
229
|
+
...( userPalette || [] ),
|
|
230
|
+
...( themePalette || [] ),
|
|
231
|
+
...( defaultPalette || [] ),
|
|
232
|
+
],
|
|
233
|
+
[ userPalette, themePalette, defaultPalette ]
|
|
234
|
+
);
|
|
235
|
+
const gradientsPerOrigin = useSetting( 'color.gradients' ) || EMPTY_OBJECT;
|
|
236
|
+
const areCustomSolidsEnabled = useSetting( 'color.custom' );
|
|
237
|
+
const areCustomGradientsEnabled = useSetting( 'color.customGradient' );
|
|
238
|
+
const isBackgroundEnabled = useSetting( 'color.background' );
|
|
239
|
+
const isLinkEnabled = useSetting( 'color.link' );
|
|
240
|
+
const isTextEnabled = useSetting( 'color.text' );
|
|
228
241
|
|
|
229
242
|
const solidsEnabled =
|
|
230
|
-
areCustomSolidsEnabled ||
|
|
231
|
-
! solidsPerOrigin?.theme ||
|
|
232
|
-
solidsPerOrigin?.theme?.length > 0;
|
|
243
|
+
areCustomSolidsEnabled || ! themePalette || themePalette?.length > 0;
|
|
233
244
|
|
|
234
245
|
const gradientsEnabled =
|
|
235
246
|
areCustomGradientsEnabled ||
|
|
236
247
|
! gradientsPerOrigin?.theme ||
|
|
237
248
|
gradientsPerOrigin?.theme?.length > 0;
|
|
238
249
|
|
|
239
|
-
const allSolids = useMemo(
|
|
240
|
-
() => [
|
|
241
|
-
...( solidsPerOrigin?.custom || [] ),
|
|
242
|
-
...( solidsPerOrigin?.theme || [] ),
|
|
243
|
-
...( solidsPerOrigin?.default || [] ),
|
|
244
|
-
],
|
|
245
|
-
[ solidsPerOrigin ]
|
|
246
|
-
);
|
|
247
|
-
|
|
248
250
|
const allGradients = useMemo(
|
|
249
251
|
() => [
|
|
250
252
|
...( gradientsPerOrigin?.custom || [] ),
|
|
@@ -441,28 +443,34 @@ export const withColorPaletteStyles = createHigherOrderComponent(
|
|
|
441
443
|
( BlockListBlock ) => ( props ) => {
|
|
442
444
|
const { name, attributes } = props;
|
|
443
445
|
const { backgroundColor, textColor } = attributes;
|
|
444
|
-
const
|
|
446
|
+
const userPalette = useSetting( 'color.palette.custom' ) || [];
|
|
447
|
+
const themePalette = useSetting( 'color.palette.theme' ) || [];
|
|
448
|
+
const defaultPalette = useSetting( 'color.palette.default' ) || [];
|
|
445
449
|
const colors = useMemo(
|
|
446
450
|
() => [
|
|
447
|
-
...(
|
|
448
|
-
...(
|
|
449
|
-
...(
|
|
451
|
+
...( userPalette || [] ),
|
|
452
|
+
...( themePalette || [] ),
|
|
453
|
+
...( defaultPalette || [] ),
|
|
450
454
|
],
|
|
451
|
-
[
|
|
455
|
+
[ userPalette, themePalette, defaultPalette ]
|
|
452
456
|
);
|
|
453
457
|
if ( ! hasColorSupport( name ) || shouldSkipSerialization( name ) ) {
|
|
454
458
|
return <BlockListBlock { ...props } />;
|
|
455
459
|
}
|
|
460
|
+
const extraStyles = {};
|
|
456
461
|
|
|
457
|
-
|
|
458
|
-
color
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
462
|
+
if ( textColor ) {
|
|
463
|
+
extraStyles.color = getColorObjectByAttributeValues(
|
|
464
|
+
colors,
|
|
465
|
+
textColor
|
|
466
|
+
)?.color;
|
|
467
|
+
}
|
|
468
|
+
if ( backgroundColor ) {
|
|
469
|
+
extraStyles.backgroundColor = getColorObjectByAttributeValues(
|
|
470
|
+
colors,
|
|
471
|
+
backgroundColor
|
|
472
|
+
)?.color;
|
|
473
|
+
}
|
|
466
474
|
|
|
467
475
|
let wrapperProps = props.wrapperProps;
|
|
468
476
|
wrapperProps = {
|
package/src/hooks/test/color.js
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { render } from '@testing-library/react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { registerBlockType, unregisterBlockType } from '@wordpress/blocks';
|
|
10
|
+
|
|
1
11
|
/**
|
|
2
12
|
* Internal dependencies
|
|
3
13
|
*/
|
|
14
|
+
import BlockEditorProvider from '../../components/provider';
|
|
4
15
|
import { cleanEmptyObject } from '../utils';
|
|
16
|
+
import { withColorPaletteStyles } from '../color';
|
|
5
17
|
|
|
6
18
|
describe( 'cleanEmptyObject', () => {
|
|
7
19
|
it( 'should remove nested keys', () => {
|
|
@@ -10,3 +22,100 @@ describe( 'cleanEmptyObject', () => {
|
|
|
10
22
|
);
|
|
11
23
|
} );
|
|
12
24
|
} );
|
|
25
|
+
|
|
26
|
+
describe( 'withColorPaletteStyles', () => {
|
|
27
|
+
const settings = {
|
|
28
|
+
__experimentalFeatures: {
|
|
29
|
+
color: {
|
|
30
|
+
palette: {
|
|
31
|
+
default: [
|
|
32
|
+
{
|
|
33
|
+
name: 'Pale pink',
|
|
34
|
+
slug: 'pale-pink',
|
|
35
|
+
color: '#f78da7',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: 'Vivid green cyan',
|
|
39
|
+
slug: 'vivid-green-cyan',
|
|
40
|
+
color: '#00d084',
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const EnhancedComponent = withColorPaletteStyles(
|
|
49
|
+
( { getStyleObj, wrapperProps } ) => (
|
|
50
|
+
<div>{ getStyleObj( wrapperProps.style ) }</div>
|
|
51
|
+
)
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
beforeAll( () => {
|
|
55
|
+
registerBlockType( 'core/test-block', {
|
|
56
|
+
save: () => undefined,
|
|
57
|
+
edit: () => undefined,
|
|
58
|
+
category: 'text',
|
|
59
|
+
title: 'test block',
|
|
60
|
+
supports: {
|
|
61
|
+
color: {
|
|
62
|
+
text: true,
|
|
63
|
+
background: true,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
} );
|
|
67
|
+
} );
|
|
68
|
+
|
|
69
|
+
afterAll( () => {
|
|
70
|
+
unregisterBlockType( 'core/test-block' );
|
|
71
|
+
} );
|
|
72
|
+
|
|
73
|
+
it( 'should add color styles from attributes', () => {
|
|
74
|
+
const getStyleObj = jest.fn();
|
|
75
|
+
|
|
76
|
+
render(
|
|
77
|
+
<BlockEditorProvider settings={ settings } value={ [] }>
|
|
78
|
+
<EnhancedComponent
|
|
79
|
+
attributes={ {
|
|
80
|
+
backgroundColor: 'vivid-green-cyan',
|
|
81
|
+
textColor: 'pale-pink',
|
|
82
|
+
} }
|
|
83
|
+
name="core/test-block"
|
|
84
|
+
getStyleObj={ getStyleObj }
|
|
85
|
+
/>
|
|
86
|
+
</BlockEditorProvider>
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
expect( getStyleObj ).toHaveBeenLastCalledWith( {
|
|
90
|
+
color: '#f78da7',
|
|
91
|
+
backgroundColor: '#00d084',
|
|
92
|
+
} );
|
|
93
|
+
} );
|
|
94
|
+
|
|
95
|
+
it( 'should not add undefined style values', () => {
|
|
96
|
+
// This test ensures that undefined `color` and `backgroundColor` styles
|
|
97
|
+
// are not added to the styles object. An undefined `backgroundColor`
|
|
98
|
+
// style causes a React warning when gradients are used, as the gradient
|
|
99
|
+
// style currently uses the `background` shorthand syntax.
|
|
100
|
+
// See: https://github.com/WordPress/gutenberg/issues/36899.
|
|
101
|
+
const getStyleObj = jest.fn();
|
|
102
|
+
|
|
103
|
+
render(
|
|
104
|
+
<BlockEditorProvider settings={ settings } value={ [] }>
|
|
105
|
+
<EnhancedComponent
|
|
106
|
+
attributes={ {
|
|
107
|
+
backgroundColor: undefined,
|
|
108
|
+
textColor: undefined,
|
|
109
|
+
} }
|
|
110
|
+
name="core/test-block"
|
|
111
|
+
getStyleObj={ getStyleObj }
|
|
112
|
+
/>
|
|
113
|
+
</BlockEditorProvider>
|
|
114
|
+
);
|
|
115
|
+
// Check explictly for the object used in the call, because
|
|
116
|
+
// `toHaveBeenCalledWith` does not check for empty keys.
|
|
117
|
+
expect(
|
|
118
|
+
getStyleObj.mock.calls[ getStyleObj.mock.calls.length - 1 ][ 0 ]
|
|
119
|
+
).toStrictEqual( {} );
|
|
120
|
+
} );
|
|
121
|
+
} );
|
|
@@ -73,6 +73,8 @@ export function getColorClassesAndStyles( attributes ) {
|
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
const EMPTY_OBJECT = {};
|
|
77
|
+
|
|
76
78
|
/**
|
|
77
79
|
* Determines the color related props for a block derived from its color block
|
|
78
80
|
* support attributes.
|
|
@@ -87,15 +89,20 @@ export function getColorClassesAndStyles( attributes ) {
|
|
|
87
89
|
export function useColorProps( attributes ) {
|
|
88
90
|
const { backgroundColor, textColor, gradient } = attributes;
|
|
89
91
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
// Some color settings have a special handling for deprecated flags in `useSetting`,
|
|
93
|
+
// so we can't unwrap them by doing const { ... } = useSetting('color')
|
|
94
|
+
// until https://github.com/WordPress/gutenberg/issues/37094 is fixed.
|
|
95
|
+
const userPalette = useSetting( 'color.palette.custom' ) || [];
|
|
96
|
+
const themePalette = useSetting( 'color.palette.theme' ) || [];
|
|
97
|
+
const defaultPalette = useSetting( 'color.palette.default' ) || [];
|
|
98
|
+
const gradientsPerOrigin = useSetting( 'color.gradients' ) || EMPTY_OBJECT;
|
|
92
99
|
const colors = useMemo(
|
|
93
100
|
() => [
|
|
94
|
-
...(
|
|
95
|
-
...(
|
|
96
|
-
...(
|
|
101
|
+
...( userPalette || [] ),
|
|
102
|
+
...( themePalette || [] ),
|
|
103
|
+
...( defaultPalette || [] ),
|
|
97
104
|
],
|
|
98
|
-
[
|
|
105
|
+
[ userPalette, themePalette, defaultPalette ]
|
|
99
106
|
);
|
|
100
107
|
const gradients = useMemo(
|
|
101
108
|
() => [
|