@wordpress/block-editor 10.0.8 → 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.
@@ -9,7 +9,6 @@ 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 DEFAULT_MAXIMUM_FONT_SIZE_FACTOR = 1.5;
13
12
  const DEFAULT_MINIMUM_FONT_SIZE_LIMIT = '14px';
14
13
 
15
14
  /**
@@ -41,7 +40,6 @@ const DEFAULT_MINIMUM_FONT_SIZE_LIMIT = '14px';
41
40
  * @param {?string} args.minimumFontSize Minimum font size for any clamp() calculation. Optional.
42
41
  * @param {?number} args.scaleFactor A scale factor to determine how fast a font scales within boundaries. Optional.
43
42
  * @param {?number} args.minimumFontSizeFactor How much to scale defaultFontSize by to derive minimumFontSize. Optional.
44
- * @param {?number} args.maximumFontSizeFactor How much to scale defaultFontSize by to derive maximumFontSize. Optional.
45
43
  *
46
44
  * @return {string|null} A font-size value using clamp().
47
45
  */
@@ -53,15 +51,8 @@ export function getComputedFluidTypographyValue( {
53
51
  maximumViewPortWidth = DEFAULT_MAXIMUM_VIEWPORT_WIDTH,
54
52
  scaleFactor = DEFAULT_SCALE_FACTOR,
55
53
  minimumFontSizeFactor = DEFAULT_MINIMUM_FONT_SIZE_FACTOR,
56
- maximumFontSizeFactor = DEFAULT_MAXIMUM_FONT_SIZE_FACTOR,
57
54
  minimumFontSizeLimit = DEFAULT_MINIMUM_FONT_SIZE_LIMIT,
58
55
  } ) {
59
- /*
60
- * Caches minimumFontSize in minimumFontSizeValue
61
- * so we can check if minimumFontSize exists later.
62
- */
63
- let minimumFontSizeValue = minimumFontSize;
64
-
65
56
  /*
66
57
  * Calculates missing minimumFontSize and maximumFontSize from
67
58
  * defaultFontSize if provided.
@@ -75,15 +66,6 @@ export function getComputedFluidTypographyValue( {
75
66
  return null;
76
67
  }
77
68
 
78
- // If no minimumFontSize is provided, derive using min scale factor.
79
- if ( ! minimumFontSizeValue ) {
80
- minimumFontSizeValue =
81
- roundToPrecision(
82
- fontSizeParsed.value * minimumFontSizeFactor,
83
- 3
84
- ) + fontSizeParsed.unit;
85
- }
86
-
87
69
  // Parses the minimum font size limit, so we can perform checks using it.
88
70
  const minimumFontSizeLimitParsed = getTypographyValueAndUnit(
89
71
  minimumFontSizeLimit,
@@ -92,57 +74,51 @@ export function getComputedFluidTypographyValue( {
92
74
  }
93
75
  );
94
76
 
95
- if ( !! minimumFontSizeLimitParsed?.value ) {
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
+ ) {
96
83
  /*
97
84
  * If a minimum size was not passed to this function
98
- * and the user-defined font size is lower than `minimumFontSizeLimit`,
99
- * then uses the user-defined font size as the minimum font-size.
85
+ * and the user-defined font size is lower than $minimum_font_size_limit,
86
+ * do not calculate a fluid value.
100
87
  */
101
- if (
102
- ! minimumFontSize &&
103
- fontSizeParsed?.value < minimumFontSizeLimitParsed?.value
104
- ) {
105
- minimumFontSizeValue = `${ fontSizeParsed.value }${ fontSizeParsed.unit }`;
106
- } else {
107
- const minimumFontSizeParsed = getTypographyValueAndUnit(
108
- minimumFontSizeValue,
109
- {
110
- coerceTo: fontSizeParsed.unit,
111
- }
112
- );
113
-
114
- /*
115
- * Otherwise, if the passed or calculated minimum font size is lower than `minimumFontSizeLimit`
116
- * use `minimumFontSizeLimit` instead.
117
- */
118
- if (
119
- !! minimumFontSizeParsed?.value &&
120
- minimumFontSizeParsed.value <
121
- minimumFontSizeLimitParsed.value
122
- ) {
123
- minimumFontSizeValue = `${ minimumFontSizeLimitParsed.value }${ minimumFontSizeLimitParsed.unit }`;
124
- }
88
+ if ( fontSizeParsed?.value <= minimumFontSizeLimitParsed?.value ) {
89
+ return null;
125
90
  }
126
91
  }
127
92
 
128
- // If no maximumFontSize is provided, derive using max scale factor.
93
+ // If no fluid max font size is available use the incoming value.
129
94
  if ( ! maximumFontSize ) {
130
- maximumFontSize =
131
- roundToPrecision(
132
- fontSizeParsed.value * maximumFontSizeFactor,
133
- 3
134
- ) + fontSizeParsed.unit;
95
+ maximumFontSize = `${ fontSizeParsed.value }${ fontSizeParsed.unit }`;
135
96
  }
136
- }
137
97
 
138
- // Return early if one of the provided inputs is not provided.
139
- if ( ! minimumFontSizeValue || ! maximumFontSize ) {
140
- return null;
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
+ }
141
118
  }
142
119
 
143
120
  // Grab the minimum font size and normalize it in order to use the value for calculations.
144
- const minimumFontSizeParsed =
145
- getTypographyValueAndUnit( minimumFontSizeValue );
121
+ const minimumFontSizeParsed = getTypographyValueAndUnit( minimumFontSize );
146
122
 
147
123
  // We get a 'preferred' unit to keep units consistent when calculating,
148
124
  // otherwise the result will not be accurate.
@@ -159,12 +135,9 @@ export function getComputedFluidTypographyValue( {
159
135
  }
160
136
 
161
137
  // Uses rem for accessible fluid target font scaling.
162
- const minimumFontSizeRem = getTypographyValueAndUnit(
163
- minimumFontSizeValue,
164
- {
165
- coerceTo: 'rem',
166
- }
167
- );
138
+ const minimumFontSizeRem = getTypographyValueAndUnit( minimumFontSize, {
139
+ coerceTo: 'rem',
140
+ } );
168
141
 
169
142
  // Viewport widths defined for fluid typography. Normalize units
170
143
  const maximumViewPortWidthParsed = getTypographyValueAndUnit(
@@ -205,7 +178,7 @@ export function getComputedFluidTypographyValue( {
205
178
  );
206
179
  const fluidTargetFontSize = `${ minimumFontSizeRem.value }${ minimumFontSizeRem.unit } + ((1vw - ${ viewPortWidthOffset }) * ${ linearFactorScaled })`;
207
180
 
208
- return `clamp(${ minimumFontSizeValue }, ${ fluidTargetFontSize }, ${ maximumFontSize })`;
181
+ return `clamp(${ minimumFontSize }, ${ fluidTargetFontSize }, ${ maximumFontSize })`;
209
182
  }
210
183
 
211
184
  /**
@@ -33,7 +33,7 @@ describe( 'getComputedFluidTypographyValue()', () => {
33
33
  fontSize: '30px',
34
34
  } );
35
35
  expect( fluidTypographyValues ).toBe(
36
- 'clamp(22.5px, 1.406rem + ((1vw - 7.68px) * 2.704), 45px)'
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.406rem + ((1vw - 7.68px) * 2.704), 45px)'
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.406rem + ((1vw - 5px) * 4.5), 45px)'
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.406rem + ((1vw - 7.68px) * 5.409), 45px)'
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.938rem + ((1vw - 7.68px) * 5.409), 60px)'
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
- useBlockDropZone( {
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) * 2.885), 3rem)',
45
+ 'clamp(1.5rem, 1.5rem + ((1vw - 0.48rem) * 0.962), 2rem)',
46
46
  textTransform: 'uppercase',
47
47
  },
48
48
  } );