@wordpress/block-editor 8.0.6 → 8.0.10
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/block-tools/block-selection-button.js +7 -1
- package/build/components/block-tools/block-selection-button.js.map +1 -1
- 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 +3 -0
- package/build/components/colors-gradients/control.js.map +1 -1
- package/build/components/colors-gradients/panel-color-gradient-settings.js +8 -69
- package/build/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
- package/build/components/colors-gradients/use-common-single-multiple-selects.js +21 -0
- package/build/components/colors-gradients/use-common-single-multiple-selects.js.map +1 -0
- package/build/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +98 -0
- package/build/components/colors-gradients/use-multiple-origin-colors-and-gradients.js.map +1 -0
- 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 +12 -12
- 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/utils/transform-styles/index.js +2 -3
- package/build/utils/transform-styles/index.js.map +1 -1
- package/build-module/components/block-tools/block-selection-button.js +7 -1
- package/build-module/components/block-tools/block-selection-button.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 +3 -0
- package/build-module/components/colors-gradients/control.js.map +1 -1
- package/build-module/components/colors-gradients/panel-color-gradient-settings.js +7 -71
- package/build-module/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
- package/build-module/components/colors-gradients/use-common-single-multiple-selects.js +11 -0
- package/build-module/components/colors-gradients/use-common-single-multiple-selects.js.map +1 -0
- package/build-module/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +85 -0
- package/build-module/components/colors-gradients/use-multiple-origin-colors-and-gradients.js.map +1 -0
- 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 +11 -12
- 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-module/utils/transform-styles/index.js +2 -3
- package/build-module/utils/transform-styles/index.js.map +1 -1
- package/build-style/style-rtl.css +7 -3
- package/build-style/style.css +7 -3
- package/package.json +3 -3
- package/src/components/block-tools/block-selection-button.js +5 -1
- package/src/components/border-style-control/style.scss +3 -2
- package/src/components/color-palette/test/__snapshots__/control.js.snap +1 -0
- package/src/components/colors/with-colors.js +10 -5
- package/src/components/colors-gradients/control.js +7 -0
- package/src/components/colors-gradients/panel-color-gradient-settings.js +6 -92
- package/src/components/colors-gradients/use-common-single-multiple-selects.js +11 -0
- package/src/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +107 -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 +15 -9
- 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/utils/transform-styles/index.js +13 -16
|
@@ -45,14 +45,19 @@ const withCustomColorPalette = ( colorsArray ) =>
|
|
|
45
45
|
const withEditorColorPalette = () =>
|
|
46
46
|
createHigherOrderComponent(
|
|
47
47
|
( WrappedComponent ) => ( props ) => {
|
|
48
|
-
|
|
48
|
+
// Some color settings have a special handling for deprecated flags in `useSetting`,
|
|
49
|
+
// so we can't unwrap them by doing const { ... } = useSetting('color')
|
|
50
|
+
// until https://github.com/WordPress/gutenberg/issues/37094 is fixed.
|
|
51
|
+
const userPalette = useSetting( 'color.palette.custom' );
|
|
52
|
+
const themePalette = useSetting( 'color.palette.theme' );
|
|
53
|
+
const defaultPalette = useSetting( 'color.palette.default' );
|
|
49
54
|
const allColors = useMemo(
|
|
50
55
|
() => [
|
|
51
|
-
...(
|
|
52
|
-
...(
|
|
53
|
-
...(
|
|
56
|
+
...( userPalette || [] ),
|
|
57
|
+
...( themePalette || [] ),
|
|
58
|
+
...( defaultPalette || [] ),
|
|
54
59
|
],
|
|
55
|
-
[
|
|
60
|
+
[ userPalette, themePalette, defaultPalette ]
|
|
56
61
|
);
|
|
57
62
|
return <WrappedComponent { ...props } colors={ allColors } />;
|
|
58
63
|
},
|
|
@@ -36,6 +36,7 @@ function ColorGradientControlInner( {
|
|
|
36
36
|
disableCustomColors,
|
|
37
37
|
disableCustomGradients,
|
|
38
38
|
__experimentalHasMultipleOrigins,
|
|
39
|
+
__experimentalIsRenderedInSidebar,
|
|
39
40
|
className,
|
|
40
41
|
label,
|
|
41
42
|
onColorChange,
|
|
@@ -109,6 +110,9 @@ function ColorGradientControlInner( {
|
|
|
109
110
|
__experimentalHasMultipleOrigins={
|
|
110
111
|
__experimentalHasMultipleOrigins
|
|
111
112
|
}
|
|
113
|
+
__experimentalIsRenderedInSidebar={
|
|
114
|
+
__experimentalIsRenderedInSidebar
|
|
115
|
+
}
|
|
112
116
|
clearable={ clearable }
|
|
113
117
|
enableAlpha={ enableAlpha }
|
|
114
118
|
/>
|
|
@@ -128,6 +132,9 @@ function ColorGradientControlInner( {
|
|
|
128
132
|
__experimentalHasMultipleOrigins={
|
|
129
133
|
__experimentalHasMultipleOrigins
|
|
130
134
|
}
|
|
135
|
+
__experimentalIsRenderedInSidebar={
|
|
136
|
+
__experimentalIsRenderedInSidebar
|
|
137
|
+
}
|
|
131
138
|
clearable={ clearable }
|
|
132
139
|
/>
|
|
133
140
|
) }
|
|
@@ -8,8 +8,7 @@ import { every, isEmpty } from 'lodash';
|
|
|
8
8
|
* WordPress dependencies
|
|
9
9
|
*/
|
|
10
10
|
import { PanelBody, ColorIndicator } from '@wordpress/components';
|
|
11
|
-
import { sprintf, __
|
|
12
|
-
import { useMemo } from '@wordpress/element';
|
|
11
|
+
import { sprintf, __ } from '@wordpress/i18n';
|
|
13
12
|
|
|
14
13
|
/**
|
|
15
14
|
* Internal dependencies
|
|
@@ -18,6 +17,8 @@ import ColorGradientControl from './control';
|
|
|
18
17
|
import { getColorObjectByColorValue } from '../colors';
|
|
19
18
|
import { __experimentalGetGradientObjectByGradientValue } from '../gradients';
|
|
20
19
|
import useSetting from '../use-setting';
|
|
20
|
+
import useCommonSingleMultipleSelects from './use-common-single-multiple-selects';
|
|
21
|
+
import useMultipleOriginColorsAndGradients from './use-multiple-origin-colors-and-gradients';
|
|
21
22
|
|
|
22
23
|
// translators: first %s: The type of color or gradient (e.g. background, overlay...), second %s: the color name or value (e.g. red or #ff0000)
|
|
23
24
|
const colorIndicatorAriaLabel = __( '(%s: color %s)' );
|
|
@@ -92,6 +93,7 @@ export const PanelColorGradientSettingsInner = ( {
|
|
|
92
93
|
title,
|
|
93
94
|
showTitle = true,
|
|
94
95
|
__experimentalHasMultipleOrigins,
|
|
96
|
+
__experimentalIsRenderedInSidebar,
|
|
95
97
|
enableAlpha,
|
|
96
98
|
...props
|
|
97
99
|
} ) => {
|
|
@@ -144,6 +146,7 @@ export const PanelColorGradientSettingsInner = ( {
|
|
|
144
146
|
disableCustomColors,
|
|
145
147
|
disableCustomGradients,
|
|
146
148
|
__experimentalHasMultipleOrigins,
|
|
149
|
+
__experimentalIsRenderedInSidebar,
|
|
147
150
|
enableAlpha,
|
|
148
151
|
...setting,
|
|
149
152
|
} }
|
|
@@ -154,13 +157,6 @@ export const PanelColorGradientSettingsInner = ( {
|
|
|
154
157
|
);
|
|
155
158
|
};
|
|
156
159
|
|
|
157
|
-
function useCommonSingleMultipleSelects() {
|
|
158
|
-
return {
|
|
159
|
-
disableCustomColors: ! useSetting( 'color.custom' ),
|
|
160
|
-
disableCustomGradients: ! useSetting( 'color.customGradient' ),
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
|
|
164
160
|
const PanelColorGradientSettingsSingleSelect = ( props ) => {
|
|
165
161
|
const colorGradientSettings = useCommonSingleMultipleSelects();
|
|
166
162
|
colorGradientSettings.colors = useSetting( 'color.palette' );
|
|
@@ -173,89 +169,7 @@ const PanelColorGradientSettingsSingleSelect = ( props ) => {
|
|
|
173
169
|
};
|
|
174
170
|
|
|
175
171
|
const PanelColorGradientSettingsMultipleSelect = ( props ) => {
|
|
176
|
-
const colorGradientSettings =
|
|
177
|
-
const customColors = useSetting( 'color.palette.custom' );
|
|
178
|
-
const themeColors = useSetting( 'color.palette.theme' );
|
|
179
|
-
const defaultColors = useSetting( 'color.palette.default' );
|
|
180
|
-
const shouldDisplayDefaultColors = useSetting( 'color.defaultPalette' );
|
|
181
|
-
|
|
182
|
-
colorGradientSettings.colors = useMemo( () => {
|
|
183
|
-
const result = [];
|
|
184
|
-
if ( themeColors && themeColors.length ) {
|
|
185
|
-
result.push( {
|
|
186
|
-
name: _x(
|
|
187
|
-
'Theme',
|
|
188
|
-
'Indicates this palette comes from the theme.'
|
|
189
|
-
),
|
|
190
|
-
colors: themeColors,
|
|
191
|
-
} );
|
|
192
|
-
}
|
|
193
|
-
if (
|
|
194
|
-
shouldDisplayDefaultColors &&
|
|
195
|
-
defaultColors &&
|
|
196
|
-
defaultColors.length
|
|
197
|
-
) {
|
|
198
|
-
result.push( {
|
|
199
|
-
name: _x(
|
|
200
|
-
'Default',
|
|
201
|
-
'Indicates this palette comes from WordPress.'
|
|
202
|
-
),
|
|
203
|
-
colors: defaultColors,
|
|
204
|
-
} );
|
|
205
|
-
}
|
|
206
|
-
if ( customColors && customColors.length ) {
|
|
207
|
-
result.push( {
|
|
208
|
-
name: _x(
|
|
209
|
-
'Custom',
|
|
210
|
-
'Indicates this palette comes from the theme.'
|
|
211
|
-
),
|
|
212
|
-
colors: customColors,
|
|
213
|
-
} );
|
|
214
|
-
}
|
|
215
|
-
return result;
|
|
216
|
-
}, [ defaultColors, themeColors, customColors ] );
|
|
217
|
-
|
|
218
|
-
const customGradients = useSetting( 'color.gradients.custom' );
|
|
219
|
-
const themeGradients = useSetting( 'color.gradients.theme' );
|
|
220
|
-
const defaultGradients = useSetting( 'color.gradients.default' );
|
|
221
|
-
const shouldDisplayDefaultGradients = useSetting(
|
|
222
|
-
'color.defaultGradients'
|
|
223
|
-
);
|
|
224
|
-
colorGradientSettings.gradients = useMemo( () => {
|
|
225
|
-
const result = [];
|
|
226
|
-
if ( themeGradients && themeGradients.length ) {
|
|
227
|
-
result.push( {
|
|
228
|
-
name: _x(
|
|
229
|
-
'Theme',
|
|
230
|
-
'Indicates this palette comes from the theme.'
|
|
231
|
-
),
|
|
232
|
-
gradients: themeGradients,
|
|
233
|
-
} );
|
|
234
|
-
}
|
|
235
|
-
if (
|
|
236
|
-
shouldDisplayDefaultGradients &&
|
|
237
|
-
defaultGradients &&
|
|
238
|
-
defaultGradients.length
|
|
239
|
-
) {
|
|
240
|
-
result.push( {
|
|
241
|
-
name: _x(
|
|
242
|
-
'Default',
|
|
243
|
-
'Indicates this palette comes from WordPress.'
|
|
244
|
-
),
|
|
245
|
-
gradients: defaultGradients,
|
|
246
|
-
} );
|
|
247
|
-
}
|
|
248
|
-
if ( customGradients && customGradients.length ) {
|
|
249
|
-
result.push( {
|
|
250
|
-
name: _x(
|
|
251
|
-
'Custom',
|
|
252
|
-
'Indicates this palette is created by the user.'
|
|
253
|
-
),
|
|
254
|
-
gradients: customGradients,
|
|
255
|
-
} );
|
|
256
|
-
}
|
|
257
|
-
return result;
|
|
258
|
-
}, [ customGradients, themeGradients, defaultGradients ] );
|
|
172
|
+
const colorGradientSettings = useMultipleOriginColorsAndGradients();
|
|
259
173
|
return (
|
|
260
174
|
<PanelColorGradientSettingsInner
|
|
261
175
|
{ ...{ ...colorGradientSettings, ...props } }
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import useSetting from '../use-setting';
|
|
5
|
+
|
|
6
|
+
export default function useCommonSingleMultipleSelects() {
|
|
7
|
+
return {
|
|
8
|
+
disableCustomColors: ! useSetting( 'color.custom' ),
|
|
9
|
+
disableCustomGradients: ! useSetting( 'color.customGradient' ),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useMemo } from '@wordpress/element';
|
|
5
|
+
import { _x } from '@wordpress/i18n';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import useSetting from '../use-setting';
|
|
11
|
+
import useCommonSingleMultipleSelects from './use-common-single-multiple-selects';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Retrieves color and gradient related settings.
|
|
15
|
+
*
|
|
16
|
+
* The arrays for colors and gradients are made up of color palettes from each
|
|
17
|
+
* origin i.e. "Core", "Theme", and "User".
|
|
18
|
+
*
|
|
19
|
+
* @return {Object} Color and gradient related settings.
|
|
20
|
+
*/
|
|
21
|
+
export default function useMultipleOriginColorsAndGradients() {
|
|
22
|
+
const colorGradientSettings = useCommonSingleMultipleSelects();
|
|
23
|
+
const customColors = useSetting( 'color.palette.custom' );
|
|
24
|
+
const themeColors = useSetting( 'color.palette.theme' );
|
|
25
|
+
const defaultColors = useSetting( 'color.palette.default' );
|
|
26
|
+
const shouldDisplayDefaultColors = useSetting( 'color.defaultPalette' );
|
|
27
|
+
|
|
28
|
+
colorGradientSettings.colors = useMemo( () => {
|
|
29
|
+
const result = [];
|
|
30
|
+
if ( themeColors && themeColors.length ) {
|
|
31
|
+
result.push( {
|
|
32
|
+
name: _x(
|
|
33
|
+
'Theme',
|
|
34
|
+
'Indicates this palette comes from the theme.'
|
|
35
|
+
),
|
|
36
|
+
colors: themeColors,
|
|
37
|
+
} );
|
|
38
|
+
}
|
|
39
|
+
if (
|
|
40
|
+
shouldDisplayDefaultColors &&
|
|
41
|
+
defaultColors &&
|
|
42
|
+
defaultColors.length
|
|
43
|
+
) {
|
|
44
|
+
result.push( {
|
|
45
|
+
name: _x(
|
|
46
|
+
'Default',
|
|
47
|
+
'Indicates this palette comes from WordPress.'
|
|
48
|
+
),
|
|
49
|
+
colors: defaultColors,
|
|
50
|
+
} );
|
|
51
|
+
}
|
|
52
|
+
if ( customColors && customColors.length ) {
|
|
53
|
+
result.push( {
|
|
54
|
+
name: _x(
|
|
55
|
+
'Custom',
|
|
56
|
+
'Indicates this palette comes from the theme.'
|
|
57
|
+
),
|
|
58
|
+
colors: customColors,
|
|
59
|
+
} );
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
}, [ defaultColors, themeColors, customColors ] );
|
|
63
|
+
|
|
64
|
+
const customGradients = useSetting( 'color.gradients.custom' );
|
|
65
|
+
const themeGradients = useSetting( 'color.gradients.theme' );
|
|
66
|
+
const defaultGradients = useSetting( 'color.gradients.default' );
|
|
67
|
+
const shouldDisplayDefaultGradients = useSetting(
|
|
68
|
+
'color.defaultGradients'
|
|
69
|
+
);
|
|
70
|
+
colorGradientSettings.gradients = useMemo( () => {
|
|
71
|
+
const result = [];
|
|
72
|
+
if ( themeGradients && themeGradients.length ) {
|
|
73
|
+
result.push( {
|
|
74
|
+
name: _x(
|
|
75
|
+
'Theme',
|
|
76
|
+
'Indicates this palette comes from the theme.'
|
|
77
|
+
),
|
|
78
|
+
gradients: themeGradients,
|
|
79
|
+
} );
|
|
80
|
+
}
|
|
81
|
+
if (
|
|
82
|
+
shouldDisplayDefaultGradients &&
|
|
83
|
+
defaultGradients &&
|
|
84
|
+
defaultGradients.length
|
|
85
|
+
) {
|
|
86
|
+
result.push( {
|
|
87
|
+
name: _x(
|
|
88
|
+
'Default',
|
|
89
|
+
'Indicates this palette comes from WordPress.'
|
|
90
|
+
),
|
|
91
|
+
gradients: defaultGradients,
|
|
92
|
+
} );
|
|
93
|
+
}
|
|
94
|
+
if ( customGradients && customGradients.length ) {
|
|
95
|
+
result.push( {
|
|
96
|
+
name: _x(
|
|
97
|
+
'Custom',
|
|
98
|
+
'Indicates this palette is created by the user.'
|
|
99
|
+
),
|
|
100
|
+
gradients: customGradients,
|
|
101
|
+
} );
|
|
102
|
+
}
|
|
103
|
+
return result;
|
|
104
|
+
}, [ customGradients, themeGradients, defaultGradients ] );
|
|
105
|
+
|
|
106
|
+
return colorGradientSettings;
|
|
107
|
+
}
|
|
@@ -59,13 +59,15 @@ export function getGradientSlugByValue( gradients, value ) {
|
|
|
59
59
|
return gradient && gradient.slug;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
const EMPTY_OBJECT = {};
|
|
63
|
+
|
|
62
64
|
export function __experimentalUseGradient( {
|
|
63
65
|
gradientAttribute = 'gradient',
|
|
64
66
|
customGradientAttribute = 'customGradient',
|
|
65
67
|
} = {} ) {
|
|
66
68
|
const { clientId } = useBlockEditContext();
|
|
67
69
|
|
|
68
|
-
const
|
|
70
|
+
const gradientsPerOrigin = useSetting( 'color.gradients' ) || EMPTY_OBJECT;
|
|
69
71
|
const allGradients = useMemo(
|
|
70
72
|
() => [
|
|
71
73
|
...( gradientsPerOrigin?.custom || [] ),
|
|
@@ -197,12 +197,16 @@ $preview-image-height: 140px;
|
|
|
197
197
|
// of text, particular those with no spaces.
|
|
198
198
|
// See: https://github.com/WordPress/gutenberg/issues/33586#issuecomment-888921188
|
|
199
199
|
white-space: pre-wrap;
|
|
200
|
-
|
|
200
|
+
overflow-wrap: break-word;
|
|
201
|
+
|
|
202
|
+
.block-editor-link-control__search-item-info {
|
|
203
|
+
word-break: break-all;
|
|
204
|
+
}
|
|
201
205
|
}
|
|
202
206
|
|
|
203
207
|
&.is-preview .block-editor-link-control__search-item-header {
|
|
204
208
|
display: flex;
|
|
205
|
-
flex: 1; //
|
|
209
|
+
flex: 1; // Fill available space.
|
|
206
210
|
}
|
|
207
211
|
|
|
208
212
|
&.is-error .block-editor-link-control__search-item-header {
|
|
@@ -15,6 +15,7 @@ import { useState } from '@wordpress/element';
|
|
|
15
15
|
* Internal dependencies
|
|
16
16
|
*/
|
|
17
17
|
import ColorGradientControl from '../components/colors-gradients/control';
|
|
18
|
+
import useMultipleOriginColorsAndGradients from '../components/colors-gradients/use-multiple-origin-colors-and-gradients';
|
|
18
19
|
import {
|
|
19
20
|
getColorClassName,
|
|
20
21
|
getColorObjectByColorValue,
|
|
@@ -46,13 +47,15 @@ export function BorderColorEdit( props ) {
|
|
|
46
47
|
attributes: { borderColor, style },
|
|
47
48
|
setAttributes,
|
|
48
49
|
} = props;
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
|
|
50
|
+
const colorGradientSettings = useMultipleOriginColorsAndGradients();
|
|
51
|
+
const availableColors = colorGradientSettings.colors.reduce(
|
|
52
|
+
( colors, origin ) => colors.concat( origin.colors ),
|
|
53
|
+
[]
|
|
54
|
+
);
|
|
52
55
|
const [ colorValue, setColorValue ] = useState(
|
|
53
56
|
() =>
|
|
54
57
|
getColorObjectByAttributeValues(
|
|
55
|
-
|
|
58
|
+
availableColors,
|
|
56
59
|
borderColor,
|
|
57
60
|
style?.border?.color
|
|
58
61
|
)?.color
|
|
@@ -61,7 +64,10 @@ export function BorderColorEdit( props ) {
|
|
|
61
64
|
const onChangeColor = ( value ) => {
|
|
62
65
|
setColorValue( value );
|
|
63
66
|
|
|
64
|
-
const colorObject = getColorObjectByColorValue(
|
|
67
|
+
const colorObject = getColorObjectByColorValue(
|
|
68
|
+
availableColors,
|
|
69
|
+
value
|
|
70
|
+
);
|
|
65
71
|
const newStyle = {
|
|
66
72
|
...style,
|
|
67
73
|
border: {
|
|
@@ -83,11 +89,11 @@ export function BorderColorEdit( props ) {
|
|
|
83
89
|
<ColorGradientControl
|
|
84
90
|
label={ __( 'Color' ) }
|
|
85
91
|
colorValue={ colorValue }
|
|
86
|
-
colors={ colors }
|
|
87
|
-
gradients={ undefined }
|
|
88
|
-
disableCustomColors={ disableCustomColors }
|
|
89
|
-
disableCustomGradients={ disableCustomGradients }
|
|
90
92
|
onColorChange={ onChangeColor }
|
|
93
|
+
clearable={ false }
|
|
94
|
+
__experimentalHasMultipleOrigins
|
|
95
|
+
__experimentalIsRenderedInSidebar
|
|
96
|
+
{ ...colorGradientSettings }
|
|
91
97
|
/>
|
|
92
98
|
);
|
|
93
99
|
}
|
package/src/hooks/color-panel.js
CHANGED
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
|
+
} );
|