@wordpress/block-editor 10.0.9 → 10.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/CHANGELOG.md +4 -0
- package/README.md +0 -1
- package/build/components/block-tools/selected-block-popover.js +23 -3
- package/build/components/block-tools/selected-block-popover.js.map +1 -1
- package/build/components/font-sizes/fluid-utils.js +56 -24
- package/build/components/font-sizes/fluid-utils.js.map +1 -1
- package/build/components/inner-blocks/index.js +6 -2
- package/build/components/inner-blocks/index.js.map +1 -1
- package/build-module/components/block-tools/selected-block-popover.js +23 -4
- package/build-module/components/block-tools/selected-block-popover.js.map +1 -1
- package/build-module/components/font-sizes/fluid-utils.js +56 -24
- package/build-module/components/font-sizes/fluid-utils.js.map +1 -1
- package/build-module/components/inner-blocks/index.js +6 -2
- package/build-module/components/inner-blocks/index.js.map +1 -1
- package/build-style/style-rtl.css +12 -1
- package/build-style/style.css +12 -1
- package/package.json +3 -3
- package/src/components/block-popover/style.scss +1 -1
- package/src/components/block-tools/selected-block-popover.js +74 -33
- package/src/components/block-tools/style.scss +9 -0
- package/src/components/default-block-appender/style.scss +1 -0
- package/src/components/font-sizes/fluid-utils.js +77 -29
- package/src/components/font-sizes/test/fluid-utils.js +5 -5
- package/src/components/inner-blocks/index.js +6 -3
- package/src/hooks/test/use-typography-props.js +1 -1
|
@@ -9,7 +9,7 @@ const DEFAULT_MAXIMUM_VIEWPORT_WIDTH = '1600px';
|
|
|
9
9
|
const DEFAULT_MINIMUM_VIEWPORT_WIDTH = '768px';
|
|
10
10
|
const DEFAULT_SCALE_FACTOR = 1;
|
|
11
11
|
const DEFAULT_MINIMUM_FONT_SIZE_FACTOR = 0.75;
|
|
12
|
-
const
|
|
12
|
+
const DEFAULT_MINIMUM_FONT_SIZE_LIMIT = '14px';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Computes a fluid font-size value that uses clamp(). A minimum and maxinmum
|
|
@@ -40,7 +40,6 @@ const DEFAULT_MAXIMUM_FONT_SIZE_FACTOR = 1.5;
|
|
|
40
40
|
* @param {?string} args.minimumFontSize Minimum font size for any clamp() calculation. Optional.
|
|
41
41
|
* @param {?number} args.scaleFactor A scale factor to determine how fast a font scales within boundaries. Optional.
|
|
42
42
|
* @param {?number} args.minimumFontSizeFactor How much to scale defaultFontSize by to derive minimumFontSize. Optional.
|
|
43
|
-
* @param {?number} args.maximumFontSizeFactor How much to scale defaultFontSize by to derive maximumFontSize. Optional.
|
|
44
43
|
*
|
|
45
44
|
* @return {string|null} A font-size value using clamp().
|
|
46
45
|
*/
|
|
@@ -52,12 +51,14 @@ export function getComputedFluidTypographyValue( {
|
|
|
52
51
|
maximumViewPortWidth = DEFAULT_MAXIMUM_VIEWPORT_WIDTH,
|
|
53
52
|
scaleFactor = DEFAULT_SCALE_FACTOR,
|
|
54
53
|
minimumFontSizeFactor = DEFAULT_MINIMUM_FONT_SIZE_FACTOR,
|
|
55
|
-
|
|
54
|
+
minimumFontSizeLimit = DEFAULT_MINIMUM_FONT_SIZE_LIMIT,
|
|
56
55
|
} ) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
/*
|
|
57
|
+
* Calculates missing minimumFontSize and maximumFontSize from
|
|
58
|
+
* defaultFontSize if provided.
|
|
59
|
+
*/
|
|
60
|
+
if ( fontSize ) {
|
|
61
|
+
// Parses default font size.
|
|
61
62
|
const fontSizeParsed = getTypographyValueAndUnit( fontSize );
|
|
62
63
|
|
|
63
64
|
// Protect against invalid units.
|
|
@@ -65,24 +66,55 @@ export function getComputedFluidTypographyValue( {
|
|
|
65
66
|
return null;
|
|
66
67
|
}
|
|
67
68
|
|
|
68
|
-
//
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
fontSizeParsed.unit
|
|
69
|
+
// Parses the minimum font size limit, so we can perform checks using it.
|
|
70
|
+
const minimumFontSizeLimitParsed = getTypographyValueAndUnit(
|
|
71
|
+
minimumFontSizeLimit,
|
|
72
|
+
{
|
|
73
|
+
coerceTo: fontSizeParsed.unit,
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
// Don't enforce minimum font size if a font size has explicitly set a min and max value.
|
|
78
|
+
if (
|
|
79
|
+
!! minimumFontSizeLimitParsed?.value &&
|
|
80
|
+
! minimumFontSize &&
|
|
81
|
+
! maximumFontSize
|
|
82
|
+
) {
|
|
83
|
+
/*
|
|
84
|
+
* If a minimum size was not passed to this function
|
|
85
|
+
* and the user-defined font size is lower than $minimum_font_size_limit,
|
|
86
|
+
* do not calculate a fluid value.
|
|
87
|
+
*/
|
|
88
|
+
if ( fontSizeParsed?.value <= minimumFontSizeLimitParsed?.value ) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
73
91
|
}
|
|
74
92
|
|
|
75
|
-
// If no
|
|
93
|
+
// If no fluid max font size is available use the incoming value.
|
|
76
94
|
if ( ! maximumFontSize ) {
|
|
77
|
-
maximumFontSize =
|
|
78
|
-
fontSizeParsed.value * maximumFontSizeFactor +
|
|
79
|
-
fontSizeParsed.unit;
|
|
95
|
+
maximumFontSize = `${ fontSizeParsed.value }${ fontSizeParsed.unit }`;
|
|
80
96
|
}
|
|
81
|
-
}
|
|
82
97
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
98
|
+
/*
|
|
99
|
+
* If no minimumFontSize is provided, create one using
|
|
100
|
+
* the given font size multiplied by the min font size scale factor.
|
|
101
|
+
*/
|
|
102
|
+
if ( ! minimumFontSize ) {
|
|
103
|
+
const calculatedMinimumFontSize = roundToPrecision(
|
|
104
|
+
fontSizeParsed.value * minimumFontSizeFactor,
|
|
105
|
+
3
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
// Only use calculated min font size if it's > $minimum_font_size_limit value.
|
|
109
|
+
if (
|
|
110
|
+
!! minimumFontSizeLimitParsed?.value &&
|
|
111
|
+
calculatedMinimumFontSize < minimumFontSizeLimitParsed?.value
|
|
112
|
+
) {
|
|
113
|
+
minimumFontSize = `${ minimumFontSizeLimitParsed.value }${ minimumFontSizeLimitParsed.unit }`;
|
|
114
|
+
} else {
|
|
115
|
+
minimumFontSize = `${ calculatedMinimumFontSize }${ fontSizeParsed.unit }`;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
86
118
|
}
|
|
87
119
|
|
|
88
120
|
// Grab the minimum font size and normalize it in order to use the value for calculations.
|
|
@@ -92,17 +124,17 @@ export function getComputedFluidTypographyValue( {
|
|
|
92
124
|
// otherwise the result will not be accurate.
|
|
93
125
|
const fontSizeUnit = minimumFontSizeParsed?.unit || 'rem';
|
|
94
126
|
|
|
95
|
-
//
|
|
127
|
+
// Grabs the maximum font size and normalize it in order to use the value for calculations.
|
|
96
128
|
const maximumFontSizeParsed = getTypographyValueAndUnit( maximumFontSize, {
|
|
97
129
|
coerceTo: fontSizeUnit,
|
|
98
130
|
} );
|
|
99
131
|
|
|
100
|
-
//
|
|
132
|
+
// Checks for mandatory min and max sizes, and protects against unsupported units.
|
|
101
133
|
if ( ! minimumFontSizeParsed || ! maximumFontSizeParsed ) {
|
|
102
134
|
return null;
|
|
103
135
|
}
|
|
104
136
|
|
|
105
|
-
//
|
|
137
|
+
// Uses rem for accessible fluid target font scaling.
|
|
106
138
|
const minimumFontSizeRem = getTypographyValueAndUnit( minimumFontSize, {
|
|
107
139
|
coerceTo: 'rem',
|
|
108
140
|
} );
|
|
@@ -133,14 +165,17 @@ export function getComputedFluidTypographyValue( {
|
|
|
133
165
|
3
|
|
134
166
|
);
|
|
135
167
|
|
|
136
|
-
const viewPortWidthOffset =
|
|
137
|
-
|
|
168
|
+
const viewPortWidthOffset =
|
|
169
|
+
roundToPrecision( minViewPortWidthOffsetValue, 3 ) + fontSizeUnit;
|
|
170
|
+
const linearFactor =
|
|
138
171
|
100 *
|
|
139
172
|
( ( maximumFontSizeParsed.value - minimumFontSizeParsed.value ) /
|
|
140
173
|
( maximumViewPortWidthParsed.value -
|
|
141
174
|
minumumViewPortWidthParsed.value ) );
|
|
142
|
-
|
|
143
|
-
|
|
175
|
+
const linearFactorScaled = roundToPrecision(
|
|
176
|
+
( linearFactor || 1 ) * scaleFactor,
|
|
177
|
+
3
|
|
178
|
+
);
|
|
144
179
|
const fluidTargetFontSize = `${ minimumFontSizeRem.value }${ minimumFontSizeRem.unit } + ((1vw - ${ viewPortWidthOffset }) * ${ linearFactorScaled })`;
|
|
145
180
|
|
|
146
181
|
return `clamp(${ minimumFontSize }, ${ fluidTargetFontSize }, ${ maximumFontSize })`;
|
|
@@ -199,8 +234,20 @@ export function getTypographyValueAndUnit( rawValue, options = {} ) {
|
|
|
199
234
|
unit = coerceTo;
|
|
200
235
|
}
|
|
201
236
|
|
|
237
|
+
/*
|
|
238
|
+
* No calculation is required if swapping between em and rem yet,
|
|
239
|
+
* since we assume a root size value. Later we might like to differentiate between
|
|
240
|
+
* :root font size (rem) and parent element font size (em) relativity.
|
|
241
|
+
*/
|
|
242
|
+
if (
|
|
243
|
+
( 'em' === coerceTo || 'rem' === coerceTo ) &&
|
|
244
|
+
( 'em' === unit || 'rem' === unit )
|
|
245
|
+
) {
|
|
246
|
+
unit = coerceTo;
|
|
247
|
+
}
|
|
248
|
+
|
|
202
249
|
return {
|
|
203
|
-
value: returnValue,
|
|
250
|
+
value: roundToPrecision( returnValue, 3 ),
|
|
204
251
|
unit,
|
|
205
252
|
};
|
|
206
253
|
}
|
|
@@ -215,7 +262,8 @@ export function getTypographyValueAndUnit( rawValue, options = {} ) {
|
|
|
215
262
|
* @return {number|undefined} Value rounded to standard precision.
|
|
216
263
|
*/
|
|
217
264
|
export function roundToPrecision( value, digits = 3 ) {
|
|
265
|
+
const base = Math.pow( 10, digits );
|
|
218
266
|
return Number.isFinite( value )
|
|
219
|
-
? parseFloat(
|
|
267
|
+
? parseFloat( Math.round( value * base ) / base )
|
|
220
268
|
: undefined;
|
|
221
269
|
}
|
|
@@ -33,7 +33,7 @@ describe( 'getComputedFluidTypographyValue()', () => {
|
|
|
33
33
|
fontSize: '30px',
|
|
34
34
|
} );
|
|
35
35
|
expect( fluidTypographyValues ).toBe(
|
|
36
|
-
'clamp(22.5px, 1.
|
|
36
|
+
'clamp(22.5px, 1.406rem + ((1vw - 7.68px) * 0.901), 30px)'
|
|
37
37
|
);
|
|
38
38
|
} );
|
|
39
39
|
|
|
@@ -42,7 +42,7 @@ describe( 'getComputedFluidTypographyValue()', () => {
|
|
|
42
42
|
fontSize: '30px',
|
|
43
43
|
} );
|
|
44
44
|
expect( fluidTypographyValues ).toBe(
|
|
45
|
-
'clamp(22.5px, 1.
|
|
45
|
+
'clamp(22.5px, 1.406rem + ((1vw - 7.68px) * 0.901), 30px)'
|
|
46
46
|
);
|
|
47
47
|
} );
|
|
48
48
|
|
|
@@ -53,7 +53,7 @@ describe( 'getComputedFluidTypographyValue()', () => {
|
|
|
53
53
|
maximumViewPortWidth: '1000px',
|
|
54
54
|
} );
|
|
55
55
|
expect( fluidTypographyValues ).toBe(
|
|
56
|
-
'clamp(22.5px, 1.
|
|
56
|
+
'clamp(22.5px, 1.406rem + ((1vw - 5px) * 1.5), 30px)'
|
|
57
57
|
);
|
|
58
58
|
} );
|
|
59
59
|
|
|
@@ -63,7 +63,7 @@ describe( 'getComputedFluidTypographyValue()', () => {
|
|
|
63
63
|
scaleFactor: '2',
|
|
64
64
|
} );
|
|
65
65
|
expect( fluidTypographyValues ).toBe(
|
|
66
|
-
'clamp(22.5px, 1.
|
|
66
|
+
'clamp(22.5px, 1.406rem + ((1vw - 7.68px) * 1.803), 30px)'
|
|
67
67
|
);
|
|
68
68
|
} );
|
|
69
69
|
|
|
@@ -74,7 +74,7 @@ describe( 'getComputedFluidTypographyValue()', () => {
|
|
|
74
74
|
maximumFontSizeFactor: '2',
|
|
75
75
|
} );
|
|
76
76
|
expect( fluidTypographyValues ).toBe(
|
|
77
|
-
'clamp(15px, 0.
|
|
77
|
+
'clamp(15px, 0.938rem + ((1vw - 7.68px) * 1.803), 30px)'
|
|
78
78
|
);
|
|
79
79
|
} );
|
|
80
80
|
|
|
@@ -150,6 +150,7 @@ const ForwardedInnerBlocks = forwardRef( ( props, ref ) => {
|
|
|
150
150
|
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/inner-blocks/README.md
|
|
151
151
|
*/
|
|
152
152
|
export function useInnerBlocksProps( props = {}, options = {} ) {
|
|
153
|
+
const { __unstableDisableDropZone } = options;
|
|
153
154
|
const { clientId } = useBlockEditContext();
|
|
154
155
|
const isSmallScreen = useViewportMatch( 'medium', '<' );
|
|
155
156
|
const { __experimentalCaptureToolbars, hasOverlay } = useSelect(
|
|
@@ -185,11 +186,13 @@ export function useInnerBlocksProps( props = {}, options = {} ) {
|
|
|
185
186
|
[ clientId, isSmallScreen ]
|
|
186
187
|
);
|
|
187
188
|
|
|
189
|
+
const blockDropZoneRef = useBlockDropZone( {
|
|
190
|
+
rootClientId: clientId,
|
|
191
|
+
} );
|
|
192
|
+
|
|
188
193
|
const ref = useMergeRefs( [
|
|
189
194
|
props.ref,
|
|
190
|
-
|
|
191
|
-
rootClientId: clientId,
|
|
192
|
-
} ),
|
|
195
|
+
__unstableDisableDropZone ? null : blockDropZoneRef,
|
|
193
196
|
] );
|
|
194
197
|
|
|
195
198
|
const innerBlocksProps = {
|
|
@@ -42,7 +42,7 @@ describe( 'getTypographyClassesAndStyles', () => {
|
|
|
42
42
|
style: {
|
|
43
43
|
letterSpacing: '22px',
|
|
44
44
|
fontSize:
|
|
45
|
-
'clamp(1.5rem, 1.5rem + ((1vw - 0.48rem) *
|
|
45
|
+
'clamp(1.5rem, 1.5rem + ((1vw - 0.48rem) * 0.962), 2rem)',
|
|
46
46
|
textTransform: 'uppercase',
|
|
47
47
|
},
|
|
48
48
|
} );
|