@wordpress/block-editor 8.0.3 → 8.0.7
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-preview/auto.js +1 -0
- package/build/components/block-preview/auto.js.map +1 -1
- 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 +6 -4
- package/build/components/colors/with-colors.js.map +1 -1
- package/build/components/colors-gradients/control.js +4 -2
- package/build/components/colors-gradients/control.js.map +1 -1
- package/build/components/colors-gradients/panel-color-gradient-settings.js +9 -68
- 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 +7 -6
- package/build/components/gradients/use-gradient.js.map +1 -1
- package/build/components/use-setting/index.js +1 -1
- package/build/components/use-setting/index.js.map +1 -1
- package/build/hooks/border-color.js +11 -12
- package/build/hooks/border-color.js.map +1 -1
- package/build/hooks/color.js +29 -21
- package/build/hooks/color.js.map +1 -1
- package/build/hooks/typography.js +3 -0
- package/build/hooks/typography.js.map +1 -1
- package/build/hooks/use-color-props.js +13 -4
- package/build/hooks/use-color-props.js.map +1 -1
- package/build/store/selectors.js +37 -43
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/block-preview/auto.js +1 -0
- package/build-module/components/block-preview/auto.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 +6 -4
- package/build-module/components/colors/with-colors.js.map +1 -1
- package/build-module/components/colors-gradients/control.js +4 -2
- package/build-module/components/colors-gradients/control.js.map +1 -1
- package/build-module/components/colors-gradients/panel-color-gradient-settings.js +7 -69
- 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 +8 -6
- package/build-module/components/gradients/use-gradient.js.map +1 -1
- package/build-module/components/use-setting/index.js +1 -1
- package/build-module/components/use-setting/index.js.map +1 -1
- package/build-module/hooks/border-color.js +10 -12
- package/build-module/hooks/border-color.js.map +1 -1
- package/build-module/hooks/color.js +30 -22
- package/build-module/hooks/color.js.map +1 -1
- package/build-module/hooks/typography.js +1 -2
- package/build-module/hooks/typography.js.map +1 -1
- package/build-module/hooks/use-color-props.js +11 -3
- package/build-module/hooks/use-color-props.js.map +1 -1
- package/build-module/store/selectors.js +37 -43
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +72 -68
- package/build-style/style.css +72 -68
- package/package.json +3 -3
- package/src/components/block-list-appender/style.scss +0 -42
- package/src/components/block-preview/auto.js +3 -0
- package/src/components/block-preview/style.scss +5 -0
- package/src/components/block-tools/block-selection-button.js +5 -1
- package/src/components/button-block-appender/style.scss +0 -17
- package/src/components/colors/with-colors.js +11 -5
- package/src/components/colors-gradients/control.js +2 -0
- package/src/components/colors-gradients/panel-color-gradient-settings.js +5 -60
- 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/default-block-appender/style.scss +90 -16
- package/src/components/gradients/use-gradient.js +16 -7
- package/src/components/inner-blocks/style.scss +4 -10
- package/src/components/use-setting/index.js +2 -2
- package/src/hooks/border-color.js +14 -9
- package/src/hooks/color.js +58 -26
- package/src/hooks/typography.js +1 -1
- package/src/hooks/use-color-props.js +23 -4
- package/src/store/selectors.js +14 -26
|
@@ -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
|
+
}
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default block appender.
|
|
3
|
+
*
|
|
4
|
+
* This component shows up in 3 places:
|
|
5
|
+
* - the black plus that sits at the end of the canvas, if the last block isn't a paragraph
|
|
6
|
+
* - on the right, inside empty paragraphs
|
|
7
|
+
* - absolute positioned and blue inside nesting containers
|
|
8
|
+
*/
|
|
9
|
+
|
|
1
10
|
.block-editor-default-block-appender {
|
|
2
11
|
clear: both; // The appender doesn't scale well to sit next to floats, so clear them.
|
|
3
12
|
|
|
@@ -23,32 +32,97 @@
|
|
|
23
32
|
}
|
|
24
33
|
}
|
|
25
34
|
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
.block-editor-default-block-appender .block-editor-inserter
|
|
35
|
+
// The black plus that shows up on the right side of an empty paragraph block, or the initial appender
|
|
36
|
+
// that exists only on empty documents.
|
|
37
|
+
.block-editor-default-block-appender .block-editor-inserter,
|
|
38
|
+
.block-editor-block-list__empty-block-inserter.block-editor-block-list__empty-block-inserter { // This needs specificity to override inherited popover styles.
|
|
29
39
|
position: absolute;
|
|
30
40
|
top: 0;
|
|
31
|
-
|
|
41
|
+
right: 0;
|
|
42
|
+
line-height: 0;
|
|
32
43
|
|
|
33
|
-
|
|
34
|
-
|
|
44
|
+
&:disabled {
|
|
45
|
+
display: none;
|
|
35
46
|
}
|
|
36
47
|
}
|
|
37
48
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Fixed position appender.
|
|
52
|
+
* These styles apply to all in-canvas inserters that exist inside nesting containers.
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
.block-editor-block-list__block .block-list-appender {
|
|
56
|
+
position: absolute;
|
|
57
|
+
list-style: none;
|
|
58
|
+
padding: 0;
|
|
59
|
+
z-index: z-index(".block-editor-block-list__block .block-list-appender");
|
|
60
|
+
bottom: 0;
|
|
61
|
+
right: 0;
|
|
62
|
+
|
|
63
|
+
// These rules needs extra specificity as it's affected by DOM rules.
|
|
64
|
+
&.block-list-appender {
|
|
65
|
+
margin: 0;
|
|
66
|
+
line-height: 0;
|
|
44
67
|
}
|
|
45
68
|
|
|
46
|
-
|
|
69
|
+
.block-editor-default-block-appender {
|
|
70
|
+
height: $button-size-small;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// @todo: these are currently two separate components. Since we're now
|
|
74
|
+
// treating them the same, one or both can be retired.
|
|
75
|
+
.block-editor-inserter__toggle.components-button.has-icon,
|
|
76
|
+
.block-list-appender__toggle {
|
|
77
|
+
flex-direction: row;
|
|
78
|
+
box-shadow: none;
|
|
79
|
+
height: $button-size-small;
|
|
80
|
+
width: $button-size-small;
|
|
81
|
+
|
|
82
|
+
// Hide by default, then we unhide it when the selected block is a direct ancestor.
|
|
83
|
+
display: none;
|
|
84
|
+
|
|
85
|
+
// Important to override styles form Button component.
|
|
86
|
+
padding: 0 !important;
|
|
87
|
+
|
|
88
|
+
// Basic look
|
|
89
|
+
background: $gray-900;
|
|
90
|
+
color: $white;
|
|
91
|
+
|
|
92
|
+
&:hover {
|
|
93
|
+
color: $white;
|
|
94
|
+
background: var(--wp-admin-theme-color);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// This content only shows up inside the empty appender.
|
|
99
|
+
.block-editor-default-block-appender__content {
|
|
47
100
|
display: none;
|
|
48
101
|
}
|
|
102
|
+
|
|
103
|
+
// These could be avoided by employing a :not(:only-child) on the parent,
|
|
104
|
+
// but this should be more performant.
|
|
105
|
+
// @todo: These styles can almost certainly be refactored away we refactor
|
|
106
|
+
// the markup and classes of the component itself. The rules provide some
|
|
107
|
+
// baseline styles for when the block is the only one inside.
|
|
108
|
+
&:only-child {
|
|
109
|
+
position: relative;
|
|
110
|
+
right: auto;
|
|
111
|
+
align-self: center;
|
|
112
|
+
list-style: none;
|
|
113
|
+
line-height: inherit;
|
|
114
|
+
|
|
115
|
+
.block-editor-default-block-appender__content {
|
|
116
|
+
display: block;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
49
119
|
}
|
|
50
120
|
|
|
51
|
-
|
|
52
|
-
.block-editor-block-
|
|
53
|
-
|
|
121
|
+
// Unhide the inserter when you're in the exact container.
|
|
122
|
+
.block-editor-block-list__block.is-selected .block-editor-block-list__layout > .block-list-appender,
|
|
123
|
+
.block-editor-block-list__block.is-selected > .block-list-appender {
|
|
124
|
+
.block-editor-inserter__toggle.components-button.has-icon,
|
|
125
|
+
.block-list-appender__toggle {
|
|
126
|
+
display: flex;
|
|
127
|
+
}
|
|
54
128
|
}
|
|
@@ -6,7 +6,7 @@ import { find } from 'lodash';
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
8
8
|
*/
|
|
9
|
-
import { useCallback } from '@wordpress/element';
|
|
9
|
+
import { useCallback, useMemo } from '@wordpress/element';
|
|
10
10
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -16,8 +16,6 @@ import { useBlockEditContext } from '../block-edit';
|
|
|
16
16
|
import useSetting from '../use-setting';
|
|
17
17
|
import { store as blockEditorStore } from '../../store';
|
|
18
18
|
|
|
19
|
-
const EMPTY_ARRAY = [];
|
|
20
|
-
|
|
21
19
|
export function __experimentalGetGradientClass( gradientSlug ) {
|
|
22
20
|
if ( ! gradientSlug ) {
|
|
23
21
|
return undefined;
|
|
@@ -67,7 +65,15 @@ export function __experimentalUseGradient( {
|
|
|
67
65
|
} = {} ) {
|
|
68
66
|
const { clientId } = useBlockEditContext();
|
|
69
67
|
|
|
70
|
-
const gradients = useSetting( 'color
|
|
68
|
+
const { gradients: gradientsPerOrigin } = useSetting( 'color' ) || {};
|
|
69
|
+
const allGradients = useMemo(
|
|
70
|
+
() => [
|
|
71
|
+
...( gradientsPerOrigin?.custom || [] ),
|
|
72
|
+
...( gradientsPerOrigin?.theme || [] ),
|
|
73
|
+
...( gradientsPerOrigin?.default || [] ),
|
|
74
|
+
],
|
|
75
|
+
[ gradientsPerOrigin ]
|
|
76
|
+
);
|
|
71
77
|
const { gradient, customGradient } = useSelect(
|
|
72
78
|
( select ) => {
|
|
73
79
|
const { getBlockAttributes } = select( blockEditorStore );
|
|
@@ -83,7 +89,10 @@ export function __experimentalUseGradient( {
|
|
|
83
89
|
const { updateBlockAttributes } = useDispatch( blockEditorStore );
|
|
84
90
|
const setGradient = useCallback(
|
|
85
91
|
( newGradientValue ) => {
|
|
86
|
-
const slug = getGradientSlugByValue(
|
|
92
|
+
const slug = getGradientSlugByValue(
|
|
93
|
+
allGradients,
|
|
94
|
+
newGradientValue
|
|
95
|
+
);
|
|
87
96
|
if ( slug ) {
|
|
88
97
|
updateBlockAttributes( clientId, {
|
|
89
98
|
[ gradientAttribute ]: slug,
|
|
@@ -96,13 +105,13 @@ export function __experimentalUseGradient( {
|
|
|
96
105
|
[ customGradientAttribute ]: newGradientValue,
|
|
97
106
|
} );
|
|
98
107
|
},
|
|
99
|
-
[
|
|
108
|
+
[ allGradients, clientId, updateBlockAttributes ]
|
|
100
109
|
);
|
|
101
110
|
|
|
102
111
|
const gradientClass = __experimentalGetGradientClass( gradient );
|
|
103
112
|
let gradientValue;
|
|
104
113
|
if ( gradient ) {
|
|
105
|
-
gradientValue = getGradientValueBySlug(
|
|
114
|
+
gradientValue = getGradientValueBySlug( allGradients, gradient );
|
|
106
115
|
} else {
|
|
107
116
|
gradientValue = customGradient;
|
|
108
117
|
}
|
|
@@ -4,16 +4,10 @@
|
|
|
4
4
|
&::after {
|
|
5
5
|
content: "";
|
|
6
6
|
position: absolute;
|
|
7
|
-
top:
|
|
8
|
-
right:
|
|
9
|
-
bottom:
|
|
10
|
-
left:
|
|
7
|
+
top: 0;
|
|
8
|
+
right: 0;
|
|
9
|
+
bottom: 0;
|
|
10
|
+
left: 0;
|
|
11
11
|
z-index: z-index(".block-editor-block-list__layout.has-overlay::after");
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
// On fullwide blocks, don't go beyond the canvas.
|
|
16
|
-
[data-align="full"] .has-overlay::after {
|
|
17
|
-
right: 0;
|
|
18
|
-
left: 0;
|
|
19
|
-
}
|
|
@@ -117,9 +117,9 @@ export default function useSetting( path ) {
|
|
|
117
117
|
if ( experimentalFeaturesResult !== undefined ) {
|
|
118
118
|
if ( PATHS_WITH_MERGE[ normalizedPath ] ) {
|
|
119
119
|
return (
|
|
120
|
-
experimentalFeaturesResult.
|
|
120
|
+
experimentalFeaturesResult.custom ??
|
|
121
121
|
experimentalFeaturesResult.theme ??
|
|
122
|
-
experimentalFeaturesResult.
|
|
122
|
+
experimentalFeaturesResult.default
|
|
123
123
|
);
|
|
124
124
|
}
|
|
125
125
|
return experimentalFeaturesResult;
|
|
@@ -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,10 @@ 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
|
+
{ ...colorGradientSettings }
|
|
91
96
|
/>
|
|
92
97
|
);
|
|
93
98
|
}
|
package/src/hooks/color.js
CHANGED
|
@@ -10,7 +10,7 @@ import { isObject, setWith, clone } from 'lodash';
|
|
|
10
10
|
import { addFilter } from '@wordpress/hooks';
|
|
11
11
|
import { getBlockSupport } from '@wordpress/blocks';
|
|
12
12
|
import { __ } from '@wordpress/i18n';
|
|
13
|
-
import { useRef, useEffect, Platform } from '@wordpress/element';
|
|
13
|
+
import { useRef, useEffect, useMemo, Platform } from '@wordpress/element';
|
|
14
14
|
import { createHigherOrderComponent } from '@wordpress/compose';
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -31,7 +31,6 @@ import ColorPanel from './color-panel';
|
|
|
31
31
|
import useSetting from '../components/use-setting';
|
|
32
32
|
|
|
33
33
|
export const COLOR_SUPPORT_KEY = 'color';
|
|
34
|
-
const EMPTY_ARRAY = [];
|
|
35
34
|
|
|
36
35
|
const hasColorSupport = ( blockType ) => {
|
|
37
36
|
const colorSupport = getBlockSupport( blockType, COLOR_SUPPORT_KEY );
|
|
@@ -217,13 +216,43 @@ function immutableSet( object, path, value ) {
|
|
|
217
216
|
*/
|
|
218
217
|
export function ColorEdit( props ) {
|
|
219
218
|
const { name: blockName, attributes } = props;
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
219
|
+
const {
|
|
220
|
+
palette: solidsPerOrigin,
|
|
221
|
+
gradients: gradientsPerOrigin,
|
|
222
|
+
customGradient: areCustomGradientsEnabled,
|
|
223
|
+
custom: areCustomSolidsEnabled,
|
|
224
|
+
text: isTextEnabled,
|
|
225
|
+
background: isBackgroundEnabled,
|
|
226
|
+
link: isLinkEnabled,
|
|
227
|
+
} = useSetting( 'color' ) || {};
|
|
228
|
+
|
|
229
|
+
const solidsEnabled =
|
|
230
|
+
areCustomSolidsEnabled ||
|
|
231
|
+
! solidsPerOrigin?.theme ||
|
|
232
|
+
solidsPerOrigin?.theme?.length > 0;
|
|
233
|
+
|
|
234
|
+
const gradientsEnabled =
|
|
235
|
+
areCustomGradientsEnabled ||
|
|
236
|
+
! gradientsPerOrigin?.theme ||
|
|
237
|
+
gradientsPerOrigin?.theme?.length > 0;
|
|
238
|
+
|
|
239
|
+
const allSolids = useMemo(
|
|
240
|
+
() => [
|
|
241
|
+
...( solidsPerOrigin?.custom || [] ),
|
|
242
|
+
...( solidsPerOrigin?.theme || [] ),
|
|
243
|
+
...( solidsPerOrigin?.default || [] ),
|
|
244
|
+
],
|
|
245
|
+
[ solidsPerOrigin ]
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
const allGradients = useMemo(
|
|
249
|
+
() => [
|
|
250
|
+
...( gradientsPerOrigin?.custom || [] ),
|
|
251
|
+
...( gradientsPerOrigin?.theme || [] ),
|
|
252
|
+
...( gradientsPerOrigin?.default || [] ),
|
|
253
|
+
],
|
|
254
|
+
[ gradientsPerOrigin ]
|
|
255
|
+
);
|
|
227
256
|
|
|
228
257
|
// Shouldn't be needed but right now the ColorGradientsPanel
|
|
229
258
|
// can trigger both onChangeColor and onChangeBackground
|
|
@@ -239,20 +268,15 @@ export function ColorEdit( props ) {
|
|
|
239
268
|
}
|
|
240
269
|
|
|
241
270
|
const hasLinkColor =
|
|
242
|
-
hasLinkColorSupport( blockName ) &&
|
|
243
|
-
isLinkEnabled &&
|
|
244
|
-
( solids.length > 0 || areCustomSolidsEnabled );
|
|
271
|
+
hasLinkColorSupport( blockName ) && isLinkEnabled && solidsEnabled;
|
|
245
272
|
const hasTextColor =
|
|
246
|
-
hasTextColorSupport( blockName ) &&
|
|
247
|
-
isTextEnabled &&
|
|
248
|
-
( solids.length > 0 || areCustomSolidsEnabled );
|
|
273
|
+
hasTextColorSupport( blockName ) && isTextEnabled && solidsEnabled;
|
|
249
274
|
const hasBackgroundColor =
|
|
250
275
|
hasBackgroundColorSupport( blockName ) &&
|
|
251
276
|
isBackgroundEnabled &&
|
|
252
|
-
|
|
277
|
+
solidsEnabled;
|
|
253
278
|
const hasGradientColor =
|
|
254
|
-
hasGradientSupport( blockName ) &&
|
|
255
|
-
( gradients.length > 0 || areCustomGradientsEnabled );
|
|
279
|
+
hasGradientSupport( blockName ) && gradientsEnabled;
|
|
256
280
|
|
|
257
281
|
if (
|
|
258
282
|
! hasLinkColor &&
|
|
@@ -266,13 +290,13 @@ export function ColorEdit( props ) {
|
|
|
266
290
|
const { style, textColor, backgroundColor, gradient } = attributes;
|
|
267
291
|
let gradientValue;
|
|
268
292
|
if ( hasGradientColor && gradient ) {
|
|
269
|
-
gradientValue = getGradientValueBySlug(
|
|
293
|
+
gradientValue = getGradientValueBySlug( allGradients, gradient );
|
|
270
294
|
} else if ( hasGradientColor ) {
|
|
271
295
|
gradientValue = style?.color?.gradient;
|
|
272
296
|
}
|
|
273
297
|
|
|
274
298
|
const onChangeColor = ( name ) => ( value ) => {
|
|
275
|
-
const colorObject = getColorObjectByColorValue(
|
|
299
|
+
const colorObject = getColorObjectByColorValue( allSolids, value );
|
|
276
300
|
const attributeName = name + 'Color';
|
|
277
301
|
const newStyle = {
|
|
278
302
|
...localAttributes.current.style,
|
|
@@ -296,7 +320,7 @@ export function ColorEdit( props ) {
|
|
|
296
320
|
};
|
|
297
321
|
|
|
298
322
|
const onChangeGradient = ( value ) => {
|
|
299
|
-
const slug = getGradientSlugByValue(
|
|
323
|
+
const slug = getGradientSlugByValue( allGradients, value );
|
|
300
324
|
let newAttributes;
|
|
301
325
|
if ( slug ) {
|
|
302
326
|
const newStyle = {
|
|
@@ -331,7 +355,7 @@ export function ColorEdit( props ) {
|
|
|
331
355
|
};
|
|
332
356
|
|
|
333
357
|
const onChangeLinkColor = ( value ) => {
|
|
334
|
-
const colorObject = getColorObjectByColorValue(
|
|
358
|
+
const colorObject = getColorObjectByColorValue( allSolids, value );
|
|
335
359
|
const newLinkColorValue = colorObject?.slug
|
|
336
360
|
? `var:preset|color|${ colorObject.slug }`
|
|
337
361
|
: value;
|
|
@@ -360,7 +384,7 @@ export function ColorEdit( props ) {
|
|
|
360
384
|
label: __( 'Text color' ),
|
|
361
385
|
onColorChange: onChangeColor( 'text' ),
|
|
362
386
|
colorValue: getColorObjectByAttributeValues(
|
|
363
|
-
|
|
387
|
+
allSolids,
|
|
364
388
|
textColor,
|
|
365
389
|
style?.color?.text
|
|
366
390
|
).color,
|
|
@@ -375,7 +399,7 @@ export function ColorEdit( props ) {
|
|
|
375
399
|
? onChangeColor( 'background' )
|
|
376
400
|
: undefined,
|
|
377
401
|
colorValue: getColorObjectByAttributeValues(
|
|
378
|
-
|
|
402
|
+
allSolids,
|
|
379
403
|
backgroundColor,
|
|
380
404
|
style?.color?.background
|
|
381
405
|
).color,
|
|
@@ -392,7 +416,7 @@ export function ColorEdit( props ) {
|
|
|
392
416
|
label: __( 'Link Color' ),
|
|
393
417
|
onColorChange: onChangeLinkColor,
|
|
394
418
|
colorValue: getLinkColorFromAttributeValue(
|
|
395
|
-
|
|
419
|
+
allSolids,
|
|
396
420
|
style?.elements?.link?.color?.text
|
|
397
421
|
),
|
|
398
422
|
clearable: !! style?.elements?.link?.color
|
|
@@ -417,7 +441,15 @@ export const withColorPaletteStyles = createHigherOrderComponent(
|
|
|
417
441
|
( BlockListBlock ) => ( props ) => {
|
|
418
442
|
const { name, attributes } = props;
|
|
419
443
|
const { backgroundColor, textColor } = attributes;
|
|
420
|
-
const
|
|
444
|
+
const { palette: solidsPerOrigin } = useSetting( 'color' ) || {};
|
|
445
|
+
const colors = useMemo(
|
|
446
|
+
() => [
|
|
447
|
+
...( solidsPerOrigin?.custom || [] ),
|
|
448
|
+
...( solidsPerOrigin?.theme || [] ),
|
|
449
|
+
...( solidsPerOrigin?.default || [] ),
|
|
450
|
+
],
|
|
451
|
+
[ solidsPerOrigin ]
|
|
452
|
+
);
|
|
421
453
|
if ( ! hasColorSupport( name ) || shouldSkipSerialization( name ) ) {
|
|
422
454
|
return <BlockListBlock { ...props } />;
|
|
423
455
|
}
|
package/src/hooks/typography.js
CHANGED
|
@@ -231,7 +231,7 @@ export function TypographyPanel( props ) {
|
|
|
231
231
|
);
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
-
const hasTypographySupport = ( blockName ) => {
|
|
234
|
+
export const hasTypographySupport = ( blockName ) => {
|
|
235
235
|
return TYPOGRAPHY_SUPPORT_KEYS.some( ( key ) =>
|
|
236
236
|
hasBlockSupport( blockName, key )
|
|
237
237
|
);
|
|
@@ -3,6 +3,11 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import classnames from 'classnames';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { useMemo } from '@wordpress/element';
|
|
10
|
+
|
|
6
11
|
/**
|
|
7
12
|
* Internal dependencies
|
|
8
13
|
*/
|
|
@@ -24,8 +29,6 @@ import useSetting from '../components/use-setting';
|
|
|
24
29
|
// block support is being skipped for a block but the color related CSS classes
|
|
25
30
|
// & styles still need to be generated so they can be applied to inner elements.
|
|
26
31
|
|
|
27
|
-
const EMPTY_ARRAY = [];
|
|
28
|
-
|
|
29
32
|
/**
|
|
30
33
|
* Provides the CSS class names and inline styles for a block's color support
|
|
31
34
|
* attributes.
|
|
@@ -84,8 +87,24 @@ export function getColorClassesAndStyles( attributes ) {
|
|
|
84
87
|
export function useColorProps( attributes ) {
|
|
85
88
|
const { backgroundColor, textColor, gradient } = attributes;
|
|
86
89
|
|
|
87
|
-
const
|
|
88
|
-
|
|
90
|
+
const { palette: solidsPerOrigin, gradients: gradientsPerOrigin } =
|
|
91
|
+
useSetting( 'color' ) || {};
|
|
92
|
+
const colors = useMemo(
|
|
93
|
+
() => [
|
|
94
|
+
...( solidsPerOrigin?.custom || [] ),
|
|
95
|
+
...( solidsPerOrigin?.theme || [] ),
|
|
96
|
+
...( solidsPerOrigin?.default || [] ),
|
|
97
|
+
],
|
|
98
|
+
[ solidsPerOrigin ]
|
|
99
|
+
);
|
|
100
|
+
const gradients = useMemo(
|
|
101
|
+
() => [
|
|
102
|
+
...( gradientsPerOrigin?.custom || [] ),
|
|
103
|
+
...( gradientsPerOrigin?.theme || [] ),
|
|
104
|
+
...( gradientsPerOrigin?.default || [] ),
|
|
105
|
+
],
|
|
106
|
+
[ gradientsPerOrigin ]
|
|
107
|
+
);
|
|
89
108
|
|
|
90
109
|
const colorProps = getColorClassesAndStyles( attributes );
|
|
91
110
|
|
package/src/store/selectors.js
CHANGED
|
@@ -1643,22 +1643,19 @@ export const getInserterItems = createSelector(
|
|
|
1643
1643
|
? getReusableBlocks( state ).map( buildReusableBlockInserterItem )
|
|
1644
1644
|
: [];
|
|
1645
1645
|
|
|
1646
|
-
|
|
1647
|
-
// variation.
|
|
1648
|
-
const visibleBlockTypeInserterItems = blockTypeInserterItems.filter(
|
|
1649
|
-
( { variations = [] } ) =>
|
|
1650
|
-
! variations.some( ( { isDefault } ) => isDefault )
|
|
1651
|
-
);
|
|
1652
|
-
|
|
1653
|
-
const blockVariations = [];
|
|
1654
|
-
// Show all available blocks with variations
|
|
1655
|
-
for ( const item of blockTypeInserterItems ) {
|
|
1646
|
+
const items = blockTypeInserterItems.reduce( ( accumulator, item ) => {
|
|
1656
1647
|
const { variations = [] } = item;
|
|
1648
|
+
// Exclude any block type item that is to be replaced by a default variation
|
|
1649
|
+
if ( ! variations.some( ( { isDefault } ) => isDefault ) ) {
|
|
1650
|
+
accumulator.push( item );
|
|
1651
|
+
}
|
|
1657
1652
|
if ( variations.length ) {
|
|
1658
1653
|
const variationMapper = getItemFromVariation( state, item );
|
|
1659
|
-
|
|
1654
|
+
accumulator.push( ...variations.map( variationMapper ) );
|
|
1660
1655
|
}
|
|
1661
|
-
|
|
1656
|
+
return accumulator;
|
|
1657
|
+
}, [] );
|
|
1658
|
+
|
|
1662
1659
|
// Ensure core blocks are prioritized in the returned results,
|
|
1663
1660
|
// because third party blocks can be registered earlier than
|
|
1664
1661
|
// the core blocks (usually by using the `init` action),
|
|
@@ -1671,20 +1668,11 @@ export const getInserterItems = createSelector(
|
|
|
1671
1668
|
type.push( block );
|
|
1672
1669
|
return blocks;
|
|
1673
1670
|
};
|
|
1674
|
-
const
|
|
1675
|
-
core:
|
|
1676
|
-
noncore:
|
|
1677
|
-
} );
|
|
1678
|
-
const
|
|
1679
|
-
core: [],
|
|
1680
|
-
noncore: [],
|
|
1681
|
-
} );
|
|
1682
|
-
const sortedBlockTypes = [
|
|
1683
|
-
...items.core,
|
|
1684
|
-
...variations.core,
|
|
1685
|
-
...items.noncore,
|
|
1686
|
-
...variations.noncore,
|
|
1687
|
-
];
|
|
1671
|
+
const {
|
|
1672
|
+
core: coreItems,
|
|
1673
|
+
noncore: nonCoreItems,
|
|
1674
|
+
} = items.reduce( groupByType, { core: [], noncore: [] } );
|
|
1675
|
+
const sortedBlockTypes = [ ...coreItems, ...nonCoreItems ];
|
|
1688
1676
|
return [ ...sortedBlockTypes, ...reusableBlockInserterItems ];
|
|
1689
1677
|
},
|
|
1690
1678
|
( state, rootClientId ) => [
|