@wordpress/block-editor 10.0.5 → 10.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.
Files changed (45) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +40 -0
  3. package/build/components/block-inspector/index.js +3 -2
  4. package/build/components/block-inspector/index.js.map +1 -1
  5. package/build/components/font-sizes/fluid-utils.js +208 -0
  6. package/build/components/font-sizes/fluid-utils.js.map +1 -0
  7. package/build/components/font-sizes/index.js +8 -0
  8. package/build/components/font-sizes/index.js.map +1 -1
  9. package/build/components/inner-blocks/use-inner-block-template-sync.js +3 -2
  10. package/build/components/inner-blocks/use-inner-block-template-sync.js.map +1 -1
  11. package/build/components/spacing-sizes-control/spacing-input-control.js +4 -2
  12. package/build/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
  13. package/build/hooks/font-size.js +60 -0
  14. package/build/hooks/font-size.js.map +1 -1
  15. package/build/hooks/use-typography-props.js +17 -3
  16. package/build/hooks/use-typography-props.js.map +1 -1
  17. package/build-module/components/block-inspector/index.js +3 -2
  18. package/build-module/components/block-inspector/index.js.map +1 -1
  19. package/build-module/components/font-sizes/fluid-utils.js +197 -0
  20. package/build-module/components/font-sizes/fluid-utils.js.map +1 -0
  21. package/build-module/components/font-sizes/index.js +1 -0
  22. package/build-module/components/font-sizes/index.js.map +1 -1
  23. package/build-module/components/inner-blocks/use-inner-block-template-sync.js +3 -2
  24. package/build-module/components/inner-blocks/use-inner-block-template-sync.js.map +1 -1
  25. package/build-module/components/spacing-sizes-control/spacing-input-control.js +4 -2
  26. package/build-module/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
  27. package/build-module/hooks/font-size.js +59 -1
  28. package/build-module/hooks/font-size.js.map +1 -1
  29. package/build-module/hooks/use-typography-props.js +17 -4
  30. package/build-module/hooks/use-typography-props.js.map +1 -1
  31. package/build-style/style-rtl.css +27 -21
  32. package/build-style/style.css +27 -21
  33. package/package.json +3 -3
  34. package/src/components/block-inspector/index.js +6 -3
  35. package/src/components/block-patterns-list/style.scss +5 -0
  36. package/src/components/button-block-appender/style.scss +3 -2
  37. package/src/components/font-sizes/fluid-utils.js +221 -0
  38. package/src/components/font-sizes/index.js +1 -0
  39. package/src/components/font-sizes/test/fluid-utils.js +168 -0
  40. package/src/components/inner-blocks/use-inner-block-template-sync.js +3 -2
  41. package/src/components/spacing-sizes-control/spacing-input-control.js +2 -0
  42. package/src/components/spacing-sizes-control/style.scss +26 -19
  43. package/src/hooks/font-size.js +75 -0
  44. package/src/hooks/test/use-typography-props.js +22 -0
  45. package/src/hooks/use-typography-props.js +18 -3
@@ -2,7 +2,7 @@
2
2
  display: grid;
3
3
  grid-template-columns: auto 1fr auto;
4
4
  align-items: center;
5
- grid-template-rows: 25px auto;
5
+ grid-template-rows: 16px auto;
6
6
  }
7
7
 
8
8
  .component-spacing-sizes-control {
@@ -27,7 +27,7 @@
27
27
  grid-column: 1 / 1;
28
28
  justify-content: left;
29
29
  height: $grid-unit-20;
30
- margin-top: $grid-unit-15;
30
+ margin-top: $grid-unit-20;
31
31
  }
32
32
 
33
33
  .components-spacing-sizes-control__side-label {
@@ -37,8 +37,9 @@
37
37
  }
38
38
 
39
39
  &.is-unlinked {
40
- .components-range-control.components-spacing-sizes-control__range-control {
41
- margin-top: $grid-unit-15;
40
+ .components-range-control.components-spacing-sizes-control__range-control,
41
+ .components-spacing-sizes-control__custom-value-input {
42
+ margin-top: $grid-unit-10;
42
43
  }
43
44
  }
44
45
 
@@ -60,12 +61,7 @@
60
61
  grid-column: 2 / 2;
61
62
  grid-row: 1 / 1;
62
63
  justify-self: end;
63
- padding: 0;
64
- &.is-small.has-icon {
65
- padding: 0;
66
- min-width: $icon-size;
67
- height: $grid-unit-20;
68
- }
64
+ margin-top: -4px;
69
65
  }
70
66
 
71
67
  .component-spacing-sizes-control__linked-button ~ .components-spacing-sizes-control__custom-toggle-all {
@@ -75,33 +71,43 @@
75
71
  .components-spacing-sizes-control__custom-toggle-single {
76
72
  grid-column: 3 / 3;
77
73
  justify-self: end;
78
- &.is-small.has-icon {
79
- padding: 0;
80
- min-width: $icon-size;
81
- height: $grid-unit-20;
82
- margin-top: $grid-unit-15;
83
- }
74
+ margin-top: $grid-unit-15;
84
75
  }
85
76
 
86
77
  .component-spacing-sizes-control__linked-button {
87
78
  grid-column: 3 / 3;
88
79
  grid-row: 1 / 1;
89
80
  justify-self: end;
81
+ line-height: 0;
82
+ margin-top: -4px;
90
83
  }
91
84
 
92
85
  .components-spacing-sizes-control__custom-value-range {
93
86
  grid-column: span 2;
94
- margin-left: $grid-unit-10;
95
- height: 30px;
87
+ margin-left: $grid-unit-20;
88
+ margin-top: 8px;
96
89
  }
97
90
 
98
91
  .components-spacing-sizes-control__custom-value-input {
99
92
  width: 124px;
93
+ margin-top: 8px;
94
+ }
95
+
96
+ .components-range-control {
97
+ height: 40px;
98
+ /* Vertically center the RangeControl until it has true 40px height. */
99
+ display: flex;
100
+ align-items: center;
101
+
102
+ > .components-base-control__field {
103
+ /* Fixes RangeControl contents when the outer wrapper is flex */
104
+ flex: 1;
105
+ }
100
106
  }
101
107
 
102
108
  .components-spacing-sizes-control__range-control {
103
109
  grid-column: span 3;
104
- height: 40px;
110
+ margin-top: 8px;
105
111
  }
106
112
 
107
113
  .components-range-control__mark {
@@ -125,5 +131,6 @@
125
131
 
126
132
  .components-spacing-sizes-control__custom-select-control {
127
133
  grid-column: span 3;
134
+ margin-top: $grid-unit-10;
128
135
  }
129
136
  }
@@ -5,6 +5,7 @@ import { addFilter } from '@wordpress/hooks';
5
5
  import { hasBlockSupport } from '@wordpress/blocks';
6
6
  import TokenList from '@wordpress/token-list';
7
7
  import { createHigherOrderComponent } from '@wordpress/compose';
8
+ import { select } from '@wordpress/data';
8
9
 
9
10
  /**
10
11
  * Internal dependencies
@@ -14,6 +15,7 @@ import {
14
15
  getFontSizeClass,
15
16
  getFontSizeObjectByValue,
16
17
  FontSizePicker,
18
+ getComputedFluidTypographyValue,
17
19
  } from '../components/font-sizes';
18
20
  import { TYPOGRAPHY_SUPPORT_KEY } from './typography';
19
21
  import {
@@ -22,6 +24,7 @@ import {
22
24
  shouldSkipSerialization,
23
25
  } from './utils';
24
26
  import useSetting from '../components/use-setting';
27
+ import { store as blockEditorStore } from '../store';
25
28
 
26
29
  export const FONT_SIZE_SUPPORT_KEY = 'typography.fontSize';
27
30
 
@@ -282,6 +285,69 @@ export function addTransforms( result, source, index, results ) {
282
285
  );
283
286
  }
284
287
 
288
+ /**
289
+ * Allow custom font sizes to appear fluid when fluid typography is enabled at
290
+ * the theme level.
291
+ *
292
+ * Adds a custom getEditWrapperProps() callback to all block types that support
293
+ * font sizes. Then, if fluid typography is enabled, this callback will swap any
294
+ * custom font size in style.fontSize with a fluid font size (i.e. one that uses
295
+ * clamp()).
296
+ *
297
+ * It's important that this hook runs after 'core/style/addEditProps' sets
298
+ * style.fontSize as otherwise fontSize will be overwritten.
299
+ *
300
+ * @param {Object} blockType Block settings object.
301
+ */
302
+ function addEditPropsForFluidCustomFontSizes( blockType ) {
303
+ if (
304
+ ! hasBlockSupport( blockType, FONT_SIZE_SUPPORT_KEY ) ||
305
+ shouldSkipSerialization( blockType, TYPOGRAPHY_SUPPORT_KEY, 'fontSize' )
306
+ ) {
307
+ return blockType;
308
+ }
309
+
310
+ const existingGetEditWrapperProps = blockType.getEditWrapperProps;
311
+
312
+ blockType.getEditWrapperProps = ( attributes ) => {
313
+ const wrapperProps = existingGetEditWrapperProps
314
+ ? existingGetEditWrapperProps( attributes )
315
+ : {};
316
+
317
+ const fontSize = wrapperProps?.style?.fontSize;
318
+
319
+ // TODO: This sucks! We should be using useSetting( 'typography.fluid' )
320
+ // or even useSelect( blockEditorStore ). We can't do either here
321
+ // because getEditWrapperProps is a plain JavaScript function called by
322
+ // BlockListBlock and not a React component rendered within
323
+ // BlockListContext.Provider. If we set fontSize using editor.
324
+ // BlockListBlock instead of using getEditWrapperProps then the value is
325
+ // clobbered when the core/style/addEditProps filter runs.
326
+ const isFluidTypographyEnabled =
327
+ !! select( blockEditorStore ).getSettings().__experimentalFeatures
328
+ ?.typography?.fluid;
329
+
330
+ const newFontSize =
331
+ fontSize && isFluidTypographyEnabled
332
+ ? getComputedFluidTypographyValue( { fontSize } )
333
+ : null;
334
+
335
+ if ( newFontSize === null ) {
336
+ return wrapperProps;
337
+ }
338
+
339
+ return {
340
+ ...wrapperProps,
341
+ style: {
342
+ ...wrapperProps?.style,
343
+ fontSize: newFontSize,
344
+ },
345
+ };
346
+ };
347
+
348
+ return blockType;
349
+ }
350
+
285
351
  addFilter(
286
352
  'blocks.registerBlockType',
287
353
  'core/font/addAttribute',
@@ -307,3 +373,12 @@ addFilter(
307
373
  'core/font-size/addTransforms',
308
374
  addTransforms
309
375
  );
376
+
377
+ addFilter(
378
+ 'blocks.registerBlockType',
379
+ 'core/font-size/addEditPropsForFluidCustomFontSizes',
380
+ addEditPropsForFluidCustomFontSizes,
381
+ // Run after 'core/style/addEditProps' so that the style object has already
382
+ // been translated into inline CSS.
383
+ 11
384
+ );
@@ -25,4 +25,26 @@ describe( 'getTypographyClassesAndStyles', () => {
25
25
  },
26
26
  } );
27
27
  } );
28
+
29
+ it( 'should return fluid font size styles', () => {
30
+ const attributes = {
31
+ fontFamily: 'tofu',
32
+ style: {
33
+ typography: {
34
+ letterSpacing: '22px',
35
+ fontSize: '2rem',
36
+ textTransform: 'uppercase',
37
+ },
38
+ },
39
+ };
40
+ expect( getTypographyClassesAndStyles( attributes, true ) ).toEqual( {
41
+ className: 'has-tofu-font-family',
42
+ style: {
43
+ letterSpacing: '22px',
44
+ fontSize:
45
+ 'clamp(1.5rem, 1.5rem + ((1vw - 0.48rem) * 2.885), 3rem)',
46
+ textTransform: 'uppercase',
47
+ },
48
+ } );
49
+ } );
28
50
  } );
@@ -9,6 +9,7 @@ import classnames from 'classnames';
9
9
  */
10
10
  import { getInlineStyles } from './style';
11
11
  import { getFontSizeClass } from '../components/font-sizes';
12
+ import { getComputedFluidTypographyValue } from '../components/font-sizes/fluid-utils';
12
13
 
13
14
  // This utility is intended to assist where the serialization of the typography
14
15
  // block support is being skipped for a block but the typography related CSS
@@ -18,12 +19,26 @@ import { getFontSizeClass } from '../components/font-sizes';
18
19
  * Provides the CSS class names and inline styles for a block's typography support
19
20
  * attributes.
20
21
  *
21
- * @param {Object} attributes Block attributes.
22
+ * @param {Object} attributes Block attributes.
23
+ * @param {boolean} isFluidFontSizeActive Whether the function should try to convert font sizes to fluid values.
22
24
  *
23
25
  * @return {Object} Typography block support derived CSS classes & styles.
24
26
  */
25
- export function getTypographyClassesAndStyles( attributes ) {
26
- const typographyStyles = attributes?.style?.typography || {};
27
+ export function getTypographyClassesAndStyles(
28
+ attributes,
29
+ isFluidFontSizeActive
30
+ ) {
31
+ let typographyStyles = attributes?.style?.typography || {};
32
+
33
+ if ( isFluidFontSizeActive ) {
34
+ typographyStyles = {
35
+ ...typographyStyles,
36
+ fontSize: getComputedFluidTypographyValue( {
37
+ fontSize: attributes?.style?.typography?.fontSize,
38
+ } ),
39
+ };
40
+ }
41
+
27
42
  const style = getInlineStyles( { typography: typographyStyles } );
28
43
  const fontFamilyClassName = !! attributes?.fontFamily
29
44
  ? `has-${ kebabCase( attributes.fontFamily ) }-font-family`