@wordpress/block-editor 8.0.7 → 8.0.11
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 +3 -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/store/reducer.js +10 -82
- package/build/store/reducer.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/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 +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-module/store/reducer.js +11 -83
- package/build-module/store/reducer.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/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 +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/store/reducer.js +13 -104
- package/src/utils/transform-styles/index.js +13 -16
|
@@ -27,12 +27,11 @@ const transformStyles = function (styles) {
|
|
|
27
27
|
return map(styles, _ref => {
|
|
28
28
|
let {
|
|
29
29
|
css,
|
|
30
|
-
baseURL
|
|
31
|
-
__experimentalNoWrapper = false
|
|
30
|
+
baseURL
|
|
32
31
|
} = _ref;
|
|
33
32
|
const transforms = [];
|
|
34
33
|
|
|
35
|
-
if (wrapperClassName
|
|
34
|
+
if (wrapperClassName) {
|
|
36
35
|
transforms.push(wrap(wrapperClassName));
|
|
37
36
|
}
|
|
38
37
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/utils/transform-styles/index.js"],"names":["map","compose","traverse","urlRewrite","wrap","transformStyles","styles","wrapperClassName","css","baseURL","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/utils/transform-styles/index.js"],"names":["map","compose","traverse","urlRewrite","wrap","transformStyles","styles","wrapperClassName","css","baseURL","transforms","push","length"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,GAAT,QAAoB,QAApB;AAEA;AACA;AACA;;AACA,SAASC,OAAT,QAAwB,oBAAxB;AAEA;AACA;AACA;;AACA,OAAOC,QAAP,MAAqB,YAArB;AACA,OAAOC,UAAP,MAAuB,0BAAvB;AACA,OAAOC,IAAP,MAAiB,mBAAjB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,eAAe,GAAG,UAAEC,MAAF,EAAqC;AAAA,MAA3BC,gBAA2B,uEAAR,EAAQ;AAC5D,SAAOP,GAAG,CAAEM,MAAF,EAAU,QAAwB;AAAA,QAAtB;AAAEE,MAAAA,GAAF;AAAOC,MAAAA;AAAP,KAAsB;AAC3C,UAAMC,UAAU,GAAG,EAAnB;;AACA,QAAKH,gBAAL,EAAwB;AACvBG,MAAAA,UAAU,CAACC,IAAX,CAAiBP,IAAI,CAAEG,gBAAF,CAArB;AACA;;AACD,QAAKE,OAAL,EAAe;AACdC,MAAAA,UAAU,CAACC,IAAX,CAAiBR,UAAU,CAAEM,OAAF,CAA3B;AACA;;AACD,QAAKC,UAAU,CAACE,MAAhB,EAAyB;AACxB,aAAOV,QAAQ,CAAEM,GAAF,EAAOP,OAAO,CAAES,UAAF,CAAd,CAAf;AACA;;AAED,WAAOF,GAAP;AACA,GAbS,CAAV;AAcA,CAfD;;AAiBA,eAAeH,eAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { map } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { compose } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport traverse from './traverse';\nimport urlRewrite from './transforms/url-rewrite';\nimport wrap from './transforms/wrap';\n\n/**\n * Applies a series of CSS rule transforms to wrap selectors inside a given class and/or rewrite URLs depending on the parameters passed.\n *\n * @param {Array} styles CSS rules.\n * @param {string} wrapperClassName Wrapper Class Name.\n * @return {Array} converted rules.\n */\nconst transformStyles = ( styles, wrapperClassName = '' ) => {\n\treturn map( styles, ( { css, baseURL } ) => {\n\t\tconst transforms = [];\n\t\tif ( wrapperClassName ) {\n\t\t\ttransforms.push( wrap( wrapperClassName ) );\n\t\t}\n\t\tif ( baseURL ) {\n\t\t\ttransforms.push( urlRewrite( baseURL ) );\n\t\t}\n\t\tif ( transforms.length ) {\n\t\t\treturn traverse( css, compose( transforms ) );\n\t\t}\n\n\t\treturn css;\n\t} );\n};\n\nexport default transformStyles;\n"]}
|
|
@@ -1698,8 +1698,9 @@
|
|
|
1698
1698
|
}
|
|
1699
1699
|
|
|
1700
1700
|
.components-border-style-control legend {
|
|
1701
|
-
line-height: 1.
|
|
1702
|
-
|
|
1701
|
+
line-height: 1.4;
|
|
1702
|
+
margin-bottom: 8px;
|
|
1703
|
+
padding: 0;
|
|
1703
1704
|
}
|
|
1704
1705
|
.components-border-style-control .components-border-style-control__buttons {
|
|
1705
1706
|
display: inline-flex;
|
|
@@ -2110,7 +2111,10 @@
|
|
|
2110
2111
|
align-items: flex-start;
|
|
2111
2112
|
margin-left: 8px;
|
|
2112
2113
|
white-space: pre-wrap;
|
|
2113
|
-
|
|
2114
|
+
overflow-wrap: break-word;
|
|
2115
|
+
}
|
|
2116
|
+
.block-editor-link-control__search-item .block-editor-link-control__search-item-header .block-editor-link-control__search-item-info {
|
|
2117
|
+
word-break: break-all;
|
|
2114
2118
|
}
|
|
2115
2119
|
.block-editor-link-control__search-item.is-preview .block-editor-link-control__search-item-header {
|
|
2116
2120
|
display: flex;
|
package/build-style/style.css
CHANGED
|
@@ -1698,8 +1698,9 @@
|
|
|
1698
1698
|
}
|
|
1699
1699
|
|
|
1700
1700
|
.components-border-style-control legend {
|
|
1701
|
-
line-height: 1.
|
|
1702
|
-
|
|
1701
|
+
line-height: 1.4;
|
|
1702
|
+
margin-bottom: 8px;
|
|
1703
|
+
padding: 0;
|
|
1703
1704
|
}
|
|
1704
1705
|
.components-border-style-control .components-border-style-control__buttons {
|
|
1705
1706
|
display: inline-flex;
|
|
@@ -2110,7 +2111,10 @@
|
|
|
2110
2111
|
align-items: flex-start;
|
|
2111
2112
|
margin-right: 8px;
|
|
2112
2113
|
white-space: pre-wrap;
|
|
2113
|
-
|
|
2114
|
+
overflow-wrap: break-word;
|
|
2115
|
+
}
|
|
2116
|
+
.block-editor-link-control__search-item .block-editor-link-control__search-item-header .block-editor-link-control__search-item-info {
|
|
2117
|
+
word-break: break-all;
|
|
2114
2118
|
}
|
|
2115
2119
|
.block-editor-link-control__search-item.is-preview .block-editor-link-control__search-item-header {
|
|
2116
2120
|
display: flex;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/block-editor",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.11",
|
|
4
4
|
"description": "Generic block editor.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@wordpress/blob": "^3.2.2",
|
|
39
39
|
"@wordpress/block-serialization-default-parser": "^4.2.3",
|
|
40
40
|
"@wordpress/blocks": "^11.1.4",
|
|
41
|
-
"@wordpress/components": "^19.1.
|
|
41
|
+
"@wordpress/components": "^19.1.5",
|
|
42
42
|
"@wordpress/compose": "^5.0.6",
|
|
43
43
|
"@wordpress/data": "^6.1.4",
|
|
44
44
|
"@wordpress/deprecated": "^3.2.3",
|
|
@@ -75,5 +75,5 @@
|
|
|
75
75
|
"publishConfig": {
|
|
76
76
|
"access": "public"
|
|
77
77
|
},
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "3665e3e1b121046300d8b2fa35074d748f16dbc2"
|
|
79
79
|
}
|
|
@@ -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
|
) }
|
|
@@ -93,6 +93,7 @@ export const PanelColorGradientSettingsInner = ( {
|
|
|
93
93
|
title,
|
|
94
94
|
showTitle = true,
|
|
95
95
|
__experimentalHasMultipleOrigins,
|
|
96
|
+
__experimentalIsRenderedInSidebar,
|
|
96
97
|
enableAlpha,
|
|
97
98
|
...props
|
|
98
99
|
} ) => {
|
|
@@ -145,6 +146,7 @@ export const PanelColorGradientSettingsInner = ( {
|
|
|
145
146
|
disableCustomColors,
|
|
146
147
|
disableCustomGradients,
|
|
147
148
|
__experimentalHasMultipleOrigins,
|
|
149
|
+
__experimentalIsRenderedInSidebar,
|
|
148
150
|
enableAlpha,
|
|
149
151
|
...setting,
|
|
150
152
|
} }
|
|
@@ -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 {
|
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
|
+
} );
|
|
@@ -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
|
() => [
|
package/src/store/reducer.js
CHANGED
|
@@ -14,7 +14,6 @@ import {
|
|
|
14
14
|
isEmpty,
|
|
15
15
|
identity,
|
|
16
16
|
omitBy,
|
|
17
|
-
pickBy,
|
|
18
17
|
} from 'lodash';
|
|
19
18
|
|
|
20
19
|
/**
|
|
@@ -122,48 +121,6 @@ function getFlattenedBlockAttributes( blocks ) {
|
|
|
122
121
|
return flattenBlocks( blocks, ( block ) => block.attributes );
|
|
123
122
|
}
|
|
124
123
|
|
|
125
|
-
/**
|
|
126
|
-
* Given a block order map object, returns *all* of the block client IDs that are
|
|
127
|
-
* a descendant of the given root client ID.
|
|
128
|
-
*
|
|
129
|
-
* Calling this with `rootClientId` set to `''` results in a list of client IDs
|
|
130
|
-
* that are in the post. That is, it excludes blocks like fetched reusable
|
|
131
|
-
* blocks which are stored into state but not visible. It also excludes
|
|
132
|
-
* InnerBlocks controllers, like template parts.
|
|
133
|
-
*
|
|
134
|
-
* It is important to exclude the full inner block controller and not just the
|
|
135
|
-
* inner blocks because in many cases, we need to persist the previous value of
|
|
136
|
-
* an inner block controller. To do so, it must be excluded from the list of
|
|
137
|
-
* client IDs which are considered to be part of the top-level entity.
|
|
138
|
-
*
|
|
139
|
-
* @param {Object} blocksOrder Object that maps block client IDs to a list of
|
|
140
|
-
* nested block client IDs.
|
|
141
|
-
* @param {?string} rootClientId The root client ID to search. Defaults to ''.
|
|
142
|
-
* @param {?Object} controlledInnerBlocks The InnerBlocks controller state.
|
|
143
|
-
*
|
|
144
|
-
* @return {Array} List of descendant client IDs.
|
|
145
|
-
*/
|
|
146
|
-
function getNestedBlockClientIds(
|
|
147
|
-
blocksOrder,
|
|
148
|
-
rootClientId = '',
|
|
149
|
-
controlledInnerBlocks = {}
|
|
150
|
-
) {
|
|
151
|
-
return reduce(
|
|
152
|
-
blocksOrder[ rootClientId ],
|
|
153
|
-
( result, clientId ) => {
|
|
154
|
-
if ( !! controlledInnerBlocks[ clientId ] ) {
|
|
155
|
-
return result;
|
|
156
|
-
}
|
|
157
|
-
return [
|
|
158
|
-
...result,
|
|
159
|
-
clientId,
|
|
160
|
-
...getNestedBlockClientIds( blocksOrder, clientId ),
|
|
161
|
-
];
|
|
162
|
-
},
|
|
163
|
-
[]
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
124
|
/**
|
|
168
125
|
* Returns an object against which it is safe to perform mutating operations,
|
|
169
126
|
* given the original object and its current working copy.
|
|
@@ -369,9 +326,14 @@ const withBlockTree = ( reducer ) => ( state = {}, action ) => {
|
|
|
369
326
|
...omit(
|
|
370
327
|
newState.tree,
|
|
371
328
|
action.replacedClientIds.concat(
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
329
|
+
// Controlled inner blocks are only removed
|
|
330
|
+
// if the block doesn't move to another position
|
|
331
|
+
// otherwise their content will be lost.
|
|
332
|
+
action.replacedClientIds
|
|
333
|
+
.filter( ( clientId ) => ! subTree[ clientId ] )
|
|
334
|
+
.map(
|
|
335
|
+
( clientId ) => 'controlled||' + clientId
|
|
336
|
+
)
|
|
375
337
|
)
|
|
376
338
|
),
|
|
377
339
|
...subTree,
|
|
@@ -637,70 +599,17 @@ const withInnerBlocksRemoveCascade = ( reducer ) => ( state, action ) => {
|
|
|
637
599
|
*/
|
|
638
600
|
const withBlockReset = ( reducer ) => ( state, action ) => {
|
|
639
601
|
if ( action.type === 'RESET_BLOCKS' ) {
|
|
640
|
-
/**
|
|
641
|
-
* A list of client IDs associated with the top level entity (like a
|
|
642
|
-
* post or template). It excludes the client IDs of blocks associated
|
|
643
|
-
* with other entities, like inner block controllers or reusable blocks.
|
|
644
|
-
*/
|
|
645
|
-
const visibleClientIds = getNestedBlockClientIds(
|
|
646
|
-
state?.order ?? {},
|
|
647
|
-
'',
|
|
648
|
-
state?.controlledInnerBlocks ?? {}
|
|
649
|
-
);
|
|
650
|
-
|
|
651
|
-
// pickBy returns only the truthy values from controlledInnerBlocks
|
|
652
|
-
const controlledInnerBlocks = Object.keys(
|
|
653
|
-
pickBy( state?.controlledInnerBlocks ?? {} )
|
|
654
|
-
);
|
|
655
|
-
|
|
656
|
-
/**
|
|
657
|
-
* Each update operation consists of a few parts:
|
|
658
|
-
* 1. First, the client IDs associated with the top level entity are
|
|
659
|
-
* removed from the existing state key, leaving in place controlled
|
|
660
|
-
* blocks (like reusable blocks and inner block controllers).
|
|
661
|
-
* 2. Second, the blocks from the reset action are used to calculate the
|
|
662
|
-
* individual state keys. This will re-populate the clientIDs which
|
|
663
|
-
* were removed in step 1.
|
|
664
|
-
* 3. In some cases, we remove the recalculated inner block controllers,
|
|
665
|
-
* letting their old values persist. We need to do this because the
|
|
666
|
-
* reset block action from a top-level entity is not aware of any
|
|
667
|
-
* inner blocks inside InnerBlock controllers. So if the new values
|
|
668
|
-
* were used, it would not take into account the existing InnerBlocks
|
|
669
|
-
* which already exist in the state for inner block controllers. For
|
|
670
|
-
* example, `attributes` uses the newly computed value for controllers
|
|
671
|
-
* since attributes are stored in the top-level entity. But `order`
|
|
672
|
-
* uses the previous value for the controllers since the new value
|
|
673
|
-
* does not include the order of controlled inner blocks. So if the
|
|
674
|
-
* new value was used, template parts would disappear from the editor
|
|
675
|
-
* whenever you try to undo a change in the top level entity.
|
|
676
|
-
*/
|
|
677
602
|
const newState = {
|
|
678
603
|
...state,
|
|
679
|
-
byClientId:
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
...omit( state?.attributes, visibleClientIds ),
|
|
685
|
-
...getFlattenedBlockAttributes( action.blocks ),
|
|
686
|
-
},
|
|
687
|
-
order: {
|
|
688
|
-
...omit( state?.order, visibleClientIds ),
|
|
689
|
-
...omit(
|
|
690
|
-
mapBlockOrder( action.blocks ),
|
|
691
|
-
controlledInnerBlocks
|
|
692
|
-
),
|
|
693
|
-
},
|
|
694
|
-
parents: {
|
|
695
|
-
...omit( state?.parents, visibleClientIds ),
|
|
696
|
-
...mapBlockParents( action.blocks ),
|
|
697
|
-
},
|
|
698
|
-
controlledInnerBlocks: state?.controlledInnerBlocks || {},
|
|
604
|
+
byClientId: getFlattenedBlocksWithoutAttributes( action.blocks ),
|
|
605
|
+
attributes: getFlattenedBlockAttributes( action.blocks ),
|
|
606
|
+
order: mapBlockOrder( action.blocks ),
|
|
607
|
+
parents: mapBlockParents( action.blocks ),
|
|
608
|
+
controlledInnerBlocks: {},
|
|
699
609
|
};
|
|
700
610
|
|
|
701
611
|
const subTree = buildBlockTree( newState, action.blocks );
|
|
702
612
|
newState.tree = {
|
|
703
|
-
...omit( state?.tree, visibleClientIds ),
|
|
704
613
|
...subTree,
|
|
705
614
|
// Root
|
|
706
615
|
'': {
|