@wordpress/block-library 7.1.1 → 7.2.0

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 (304) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/build/avatar/edit.js +205 -0
  3. package/build/avatar/edit.js.map +1 -0
  4. package/build/avatar/hooks.js +111 -0
  5. package/build/avatar/hooks.js.map +1 -0
  6. package/build/avatar/index.js +83 -0
  7. package/build/avatar/index.js.map +1 -0
  8. package/build/avatar/user-control.js +63 -0
  9. package/build/avatar/user-control.js.map +1 -0
  10. package/build/column/index.js +2 -1
  11. package/build/column/index.js.map +1 -1
  12. package/build/comment-author-avatar/index.js +1 -0
  13. package/build/comment-author-avatar/index.js.map +1 -1
  14. package/build/comment-date/edit.js +10 -25
  15. package/build/comment-date/edit.js.map +1 -1
  16. package/build/comment-template/edit.js +79 -52
  17. package/build/comment-template/edit.js.map +1 -1
  18. package/build/cover/edit.js +23 -33
  19. package/build/cover/edit.js.map +1 -1
  20. package/build/embed/variations.js +2 -2
  21. package/build/embed/variations.js.map +1 -1
  22. package/build/gallery/edit.js +18 -5
  23. package/build/gallery/edit.js.map +1 -1
  24. package/build/gallery/gallery.js +1 -1
  25. package/build/gallery/gallery.js.map +1 -1
  26. package/build/gallery/gap-styles.js +29 -0
  27. package/build/gallery/gap-styles.js.map +1 -0
  28. package/build/gallery/index.js +17 -1
  29. package/build/gallery/index.js.map +1 -1
  30. package/build/group/index.js +3 -1
  31. package/build/group/index.js.map +1 -1
  32. package/build/group/variations.js +1 -2
  33. package/build/group/variations.js.map +1 -1
  34. package/build/image/image.js +3 -1
  35. package/build/image/image.js.map +1 -1
  36. package/build/index.js +8 -2
  37. package/build/index.js.map +1 -1
  38. package/build/list/index.js +5 -7
  39. package/build/list/index.js.map +1 -1
  40. package/build/list/v2/edit.js +85 -0
  41. package/build/list/v2/edit.js.map +1 -0
  42. package/build/list/v2/index.js +33 -0
  43. package/build/list/v2/index.js.map +1 -0
  44. package/build/list/v2/save.js +34 -0
  45. package/build/list/v2/save.js.map +1 -0
  46. package/build/list/v2/transforms.js +121 -0
  47. package/build/list/v2/transforms.js.map +1 -0
  48. package/build/list-item/edit.js +47 -0
  49. package/build/list-item/edit.js.map +1 -0
  50. package/build/list-item/index.js +67 -0
  51. package/build/list-item/index.js.map +1 -0
  52. package/build/list-item/save.js +23 -0
  53. package/build/list-item/save.js.map +1 -0
  54. package/build/media-text/edit.js +3 -1
  55. package/build/media-text/edit.js.map +1 -1
  56. package/build/navigation/use-navigation-entities.js +26 -54
  57. package/build/navigation/use-navigation-entities.js.map +1 -1
  58. package/build/navigation-link/edit.js +88 -34
  59. package/build/navigation-link/edit.js.map +1 -1
  60. package/build/post-date/edit.js +31 -37
  61. package/build/post-date/edit.js.map +1 -1
  62. package/build/post-featured-image/edit.js +2 -1
  63. package/build/post-featured-image/edit.js.map +1 -1
  64. package/build/pullquote/edit.js +5 -3
  65. package/build/pullquote/edit.js.map +1 -1
  66. package/build/query/variations.js +4 -4
  67. package/build/query/variations.js.map +1 -1
  68. package/build/query-no-results/edit.js +28 -0
  69. package/build/query-no-results/edit.js.map +1 -0
  70. package/build/query-no-results/index.js +54 -0
  71. package/build/query-no-results/index.js.map +1 -0
  72. package/build/query-no-results/save.js +18 -0
  73. package/build/query-no-results/save.js.map +1 -0
  74. package/build/search/edit.js +2 -3
  75. package/build/search/edit.js.map +1 -1
  76. package/build/separator/deprecated.js +83 -0
  77. package/build/separator/deprecated.js.map +1 -0
  78. package/build/separator/edit.js +31 -23
  79. package/build/separator/edit.js.map +1 -1
  80. package/build/separator/index.js +17 -7
  81. package/build/separator/index.js.map +1 -1
  82. package/build/separator/save.js +18 -13
  83. package/build/separator/save.js.map +1 -1
  84. package/build/separator/use-deprecated-opacity.js +39 -0
  85. package/build/separator/use-deprecated-opacity.js.map +1 -0
  86. package/build/social-links/edit.js +14 -3
  87. package/build/social-links/edit.js.map +1 -1
  88. package/build/social-links/index.js +1 -1
  89. package/build/spacer/controls.js +6 -16
  90. package/build/spacer/controls.js.map +1 -1
  91. package/build/spacer/controls.native.js +3 -1
  92. package/build/spacer/controls.native.js.map +1 -1
  93. package/build/spacer/edit.js +4 -5
  94. package/build/spacer/edit.js.map +1 -1
  95. package/build/table/deprecated.js +1 -1
  96. package/build/table/deprecated.js.map +1 -1
  97. package/build/tag-cloud/edit.js +58 -2
  98. package/build/tag-cloud/edit.js.map +1 -1
  99. package/build/tag-cloud/index.js +8 -0
  100. package/build/tag-cloud/index.js.map +1 -1
  101. package/build-module/avatar/edit.js +190 -0
  102. package/build-module/avatar/edit.js.map +1 -0
  103. package/build-module/avatar/hooks.js +99 -0
  104. package/build-module/avatar/hooks.js.map +1 -0
  105. package/build-module/avatar/index.js +70 -0
  106. package/build-module/avatar/index.js.map +1 -0
  107. package/build-module/avatar/user-control.js +52 -0
  108. package/build-module/avatar/user-control.js.map +1 -0
  109. package/build-module/column/index.js +2 -1
  110. package/build-module/column/index.js.map +1 -1
  111. package/build-module/comment-author-avatar/index.js +1 -0
  112. package/build-module/comment-author-avatar/index.js.map +1 -1
  113. package/build-module/comment-date/edit.js +13 -30
  114. package/build-module/comment-date/edit.js.map +1 -1
  115. package/build-module/comment-template/edit.js +79 -52
  116. package/build-module/comment-template/edit.js.map +1 -1
  117. package/build-module/cover/edit.js +23 -34
  118. package/build-module/cover/edit.js.map +1 -1
  119. package/build-module/embed/variations.js +2 -2
  120. package/build-module/embed/variations.js.map +1 -1
  121. package/build-module/gallery/edit.js +17 -5
  122. package/build-module/gallery/edit.js.map +1 -1
  123. package/build-module/gallery/gallery.js +1 -1
  124. package/build-module/gallery/gallery.js.map +1 -1
  125. package/build-module/gallery/gap-styles.js +22 -0
  126. package/build-module/gallery/gap-styles.js.map +1 -0
  127. package/build-module/gallery/index.js +17 -1
  128. package/build-module/gallery/index.js.map +1 -1
  129. package/build-module/group/index.js +3 -1
  130. package/build-module/group/index.js.map +1 -1
  131. package/build-module/group/variations.js +1 -2
  132. package/build-module/group/variations.js.map +1 -1
  133. package/build-module/image/image.js +3 -1
  134. package/build-module/image/image.js.map +1 -1
  135. package/build-module/index.js +5 -2
  136. package/build-module/index.js.map +1 -1
  137. package/build-module/list/index.js +5 -1
  138. package/build-module/list/index.js.map +1 -1
  139. package/build-module/list/v2/edit.js +69 -0
  140. package/build-module/list/v2/edit.js.map +1 -0
  141. package/build-module/list/v2/index.js +19 -0
  142. package/build-module/list/v2/index.js.map +1 -0
  143. package/build-module/list/v2/save.js +23 -0
  144. package/build-module/list/v2/save.js.map +1 -0
  145. package/build-module/list/v2/transforms.js +111 -0
  146. package/build-module/list/v2/transforms.js.map +1 -0
  147. package/build-module/list-item/edit.js +37 -0
  148. package/build-module/list-item/edit.js.map +1 -0
  149. package/build-module/list-item/index.js +53 -0
  150. package/build-module/list-item/index.js.map +1 -0
  151. package/build-module/list-item/save.js +15 -0
  152. package/build-module/list-item/save.js.map +1 -0
  153. package/build-module/media-text/edit.js +3 -1
  154. package/build-module/media-text/edit.js.map +1 -1
  155. package/build-module/navigation/use-navigation-entities.js +27 -54
  156. package/build-module/navigation/use-navigation-entities.js.map +1 -1
  157. package/build-module/navigation-link/edit.js +88 -33
  158. package/build-module/navigation-link/edit.js.map +1 -1
  159. package/build-module/post-date/edit.js +32 -43
  160. package/build-module/post-date/edit.js.map +1 -1
  161. package/build-module/post-featured-image/edit.js +2 -1
  162. package/build-module/post-featured-image/edit.js.map +1 -1
  163. package/build-module/pullquote/edit.js +6 -3
  164. package/build-module/pullquote/edit.js.map +1 -1
  165. package/build-module/query/variations.js +4 -4
  166. package/build-module/query/variations.js.map +1 -1
  167. package/build-module/query-no-results/edit.js +18 -0
  168. package/build-module/query-no-results/edit.js.map +1 -0
  169. package/build-module/query-no-results/index.js +40 -0
  170. package/build-module/query-no-results/index.js.map +1 -0
  171. package/build-module/query-no-results/save.js +10 -0
  172. package/build-module/query-no-results/save.js.map +1 -0
  173. package/build-module/search/edit.js +2 -3
  174. package/build-module/search/edit.js.map +1 -1
  175. package/build-module/separator/deprecated.js +70 -0
  176. package/build-module/separator/deprecated.js.map +1 -0
  177. package/build-module/separator/edit.js +31 -22
  178. package/build-module/separator/edit.js.map +1 -1
  179. package/build-module/separator/index.js +16 -7
  180. package/build-module/separator/index.js.map +1 -1
  181. package/build-module/separator/save.js +19 -14
  182. package/build-module/separator/save.js.map +1 -1
  183. package/build-module/separator/use-deprecated-opacity.js +30 -0
  184. package/build-module/separator/use-deprecated-opacity.js.map +1 -0
  185. package/build-module/social-links/edit.js +15 -4
  186. package/build-module/social-links/edit.js.map +1 -1
  187. package/build-module/social-links/index.js +1 -1
  188. package/build-module/spacer/controls.js +8 -19
  189. package/build-module/spacer/controls.js.map +1 -1
  190. package/build-module/spacer/controls.native.js +2 -1
  191. package/build-module/spacer/controls.native.js.map +1 -1
  192. package/build-module/spacer/edit.js +3 -3
  193. package/build-module/spacer/edit.js.map +1 -1
  194. package/build-module/table/deprecated.js +1 -1
  195. package/build-module/table/deprecated.js.map +1 -1
  196. package/build-module/tag-cloud/edit.js +60 -4
  197. package/build-module/tag-cloud/edit.js.map +1 -1
  198. package/build-module/tag-cloud/index.js +8 -0
  199. package/build-module/tag-cloud/index.js.map +1 -1
  200. package/build-style/avatar/editor-rtl.css +79 -0
  201. package/build-style/avatar/editor.css +79 -0
  202. package/build-style/editor-rtl.css +23 -2
  203. package/build-style/editor.css +23 -2
  204. package/build-style/gallery/editor-rtl.css +0 -1
  205. package/build-style/gallery/editor.css +0 -1
  206. package/build-style/gallery/style-rtl.css +102 -169
  207. package/build-style/gallery/style.css +102 -169
  208. package/build-style/image/style-rtl.css +2 -0
  209. package/build-style/image/style.css +2 -0
  210. package/build-style/navigation-link/editor-rtl.css +13 -0
  211. package/build-style/navigation-link/editor.css +13 -0
  212. package/build-style/pullquote/style-rtl.css +0 -4
  213. package/build-style/pullquote/style.css +0 -4
  214. package/build-style/separator/editor-rtl.css +3 -0
  215. package/build-style/separator/editor.css +3 -0
  216. package/build-style/separator/theme-rtl.css +7 -1
  217. package/build-style/separator/theme.css +7 -1
  218. package/build-style/site-logo/editor-rtl.css +3 -1
  219. package/build-style/site-logo/editor.css +3 -1
  220. package/build-style/style-rtl.css +104 -173
  221. package/build-style/style.css +104 -173
  222. package/build-style/theme-rtl.css +7 -1
  223. package/build-style/theme.css +7 -1
  224. package/package.json +28 -28
  225. package/src/avatar/block.json +53 -0
  226. package/src/avatar/edit.js +222 -0
  227. package/src/avatar/editor.scss +3 -0
  228. package/src/avatar/hooks.js +96 -0
  229. package/src/avatar/index.js +18 -0
  230. package/src/avatar/index.php +146 -0
  231. package/src/avatar/user-control.js +56 -0
  232. package/src/column/block.json +2 -1
  233. package/src/comment-author-avatar/block.json +1 -0
  234. package/src/comment-date/edit.js +20 -30
  235. package/src/comment-template/edit.js +65 -44
  236. package/src/cover/edit.js +26 -31
  237. package/src/editor.scss +1 -0
  238. package/src/embed/variations.js +2 -2
  239. package/src/gallery/block.json +17 -1
  240. package/src/gallery/deprecated.scss +2 -2
  241. package/src/gallery/edit.js +15 -8
  242. package/src/gallery/editor.scss +0 -1
  243. package/src/gallery/gallery.js +8 -7
  244. package/src/gallery/gap-styles.js +21 -0
  245. package/src/gallery/index.php +42 -1
  246. package/src/gallery/style.scss +11 -44
  247. package/src/group/block.json +3 -1
  248. package/src/group/variations.js +1 -1
  249. package/src/image/image.js +4 -1
  250. package/src/image/style.scss +3 -0
  251. package/src/index.js +6 -1
  252. package/src/list/index.js +6 -1
  253. package/src/list/v2/edit.js +77 -0
  254. package/src/list/v2/index.js +20 -0
  255. package/src/list/v2/save.js +18 -0
  256. package/src/list/v2/transforms.js +116 -0
  257. package/src/list-item/block.json +26 -0
  258. package/src/list-item/edit.js +47 -0
  259. package/src/list-item/index.js +27 -0
  260. package/src/list-item/save.js +13 -0
  261. package/src/media-text/edit.js +1 -1
  262. package/src/navigation/index.php +22 -2
  263. package/src/navigation/use-navigation-entities.js +37 -73
  264. package/src/navigation-link/edit.js +145 -61
  265. package/src/navigation-link/editor.scss +11 -0
  266. package/src/post-date/edit.js +63 -52
  267. package/src/post-date/index.php +1 -1
  268. package/src/post-date/test/edit.js +17 -0
  269. package/src/post-featured-image/edit.js +9 -1
  270. package/src/post-featured-image/index.php +2 -1
  271. package/src/pullquote/edit.js +4 -3
  272. package/src/pullquote/style.scss +0 -5
  273. package/src/query/variations.js +4 -0
  274. package/src/query-no-results/block.json +20 -0
  275. package/src/query-no-results/edit.js +28 -0
  276. package/src/query-no-results/index.js +20 -0
  277. package/src/query-no-results/index.php +59 -0
  278. package/src/query-no-results/save.js +8 -0
  279. package/src/search/edit.js +1 -2
  280. package/src/separator/block.json +13 -6
  281. package/src/separator/deprecated.js +57 -0
  282. package/src/separator/deprecated.scss +6 -0
  283. package/src/separator/edit.js +36 -14
  284. package/src/separator/editor.scss +6 -0
  285. package/src/separator/index.js +2 -0
  286. package/src/separator/save.js +22 -14
  287. package/src/separator/test/edit.js +113 -0
  288. package/src/separator/theme.scss +7 -1
  289. package/src/separator/use-deprecated-opacity.js +41 -0
  290. package/src/site-logo/editor.scss +3 -1
  291. package/src/social-links/block.json +1 -1
  292. package/src/social-links/edit.js +15 -5
  293. package/src/spacer/controls.js +12 -18
  294. package/src/spacer/controls.native.js +2 -1
  295. package/src/spacer/edit.js +3 -6
  296. package/src/table/deprecated.js +5 -1
  297. package/src/tag-cloud/block.json +8 -0
  298. package/src/tag-cloud/edit.js +82 -2
  299. package/src/tag-cloud/index.php +6 -0
  300. package/build/separator/separator-settings.js +0 -36
  301. package/build/separator/separator-settings.js.map +0 -1
  302. package/build-module/separator/separator-settings.js +0 -27
  303. package/build-module/separator/separator-settings.js.map +0 -1
  304. package/src/separator/separator-settings.js +0 -24
@@ -7,7 +7,7 @@ import classNames from 'classnames';
7
7
  * WordPress dependencies
8
8
  */
9
9
  import { getBlockSupport } from '@wordpress/blocks';
10
- import { Fragment, useEffect } from '@wordpress/element';
10
+ import { Fragment, useEffect, useRef } from '@wordpress/element';
11
11
  import {
12
12
  BlockControls,
13
13
  useInnerBlocksProps,
@@ -58,6 +58,7 @@ export function SocialLinksEdit( props ) {
58
58
 
59
59
  const {
60
60
  iconBackgroundColorValue,
61
+ customIconBackgroundColor,
61
62
  iconColorValue,
62
63
  openInNewTab,
63
64
  showLabels,
@@ -66,18 +67,27 @@ export function SocialLinksEdit( props ) {
66
67
  } = attributes;
67
68
  const usedLayout = layout || getDefaultBlockLayout( name );
68
69
 
69
- // Remove icon background color if logos only style selected.
70
- const logosOnly =
71
- attributes.className?.indexOf( 'is-style-logos-only' ) >= 0;
70
+ const logosOnly = attributes.className?.includes( 'is-style-logos-only' );
71
+
72
+ // Remove icon background color when logos only style is selected or
73
+ // restore it when any other style is selected.
74
+ const backgroundBackup = useRef( {} );
72
75
  useEffect( () => {
73
76
  if ( logosOnly ) {
77
+ backgroundBackup.current = {
78
+ iconBackgroundColor,
79
+ iconBackgroundColorValue,
80
+ customIconBackgroundColor,
81
+ };
74
82
  setAttributes( {
75
83
  iconBackgroundColor: undefined,
76
84
  customIconBackgroundColor: undefined,
77
85
  iconBackgroundColorValue: undefined,
78
86
  } );
87
+ } else {
88
+ setAttributes( { ...backgroundBackup.current } );
79
89
  }
80
- }, [ logosOnly, setAttributes ] );
90
+ }, [ logosOnly ] );
81
91
 
82
92
  const SocialPlaceholder = (
83
93
  <li className="wp-block-social-links__social-placeholder">
@@ -8,18 +8,16 @@ import {
8
8
  PanelBody,
9
9
  __experimentalUseCustomUnits as useCustomUnits,
10
10
  __experimentalUnitControl as UnitControl,
11
+ __experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue,
11
12
  } from '@wordpress/components';
12
13
  import { useInstanceId } from '@wordpress/compose';
13
- import { useState } from '@wordpress/element';
14
14
 
15
15
  /**
16
16
  * Internal dependencies
17
17
  */
18
- import { MAX_SPACER_SIZE } from './edit';
18
+ import { MIN_SPACER_SIZE } from './edit';
19
19
 
20
20
  function DimensionInput( { label, onChange, isResizing, value = '' } ) {
21
- const [ temporaryInput, setTemporaryInput ] = useState( null );
22
-
23
21
  const inputId = useInstanceId( UnitControl, 'block-spacer-height-input' );
24
22
 
25
23
  // In most contexts the spacer size cannot meaningfully be set to a
@@ -41,32 +39,28 @@ function DimensionInput( { label, onChange, isResizing, value = '' } ) {
41
39
  } );
42
40
 
43
41
  const handleOnChange = ( unprocessedValue ) => {
44
- setTemporaryInput( null );
45
42
  onChange( unprocessedValue );
46
43
  };
47
44
 
48
- const handleOnBlur = () => {
49
- if ( temporaryInput !== null ) {
50
- setTemporaryInput( null );
51
- }
52
- };
53
-
54
- const inputValue = temporaryInput !== null ? temporaryInput : value;
45
+ // Force the unit to update to `px` when the Spacer is being resized.
46
+ const [ parsedQuantity, parsedUnit ] = parseQuantityAndUnitFromRawValue(
47
+ value
48
+ );
49
+ const computedValue = [
50
+ parsedQuantity,
51
+ isResizing ? 'px' : parsedUnit,
52
+ ].join( '' );
55
53
 
56
54
  return (
57
55
  <BaseControl label={ label } id={ inputId }>
58
56
  <UnitControl
59
57
  id={ inputId }
60
58
  isResetValueOnUnitChange
61
- min={ 0 }
62
- max={ MAX_SPACER_SIZE }
63
- onBlur={ handleOnBlur }
59
+ min={ MIN_SPACER_SIZE }
64
60
  onChange={ handleOnChange }
65
61
  style={ { maxWidth: 80 } }
66
- value={ inputValue }
62
+ value={ computedValue }
67
63
  units={ units }
68
- // Force the unit to update to `px` when the Spacer is being resized.
69
- unit={ isResizing ? 'px' : undefined }
70
64
  />
71
65
  </BaseControl>
72
66
  );
@@ -14,6 +14,7 @@ import { __ } from '@wordpress/i18n';
14
14
  /**
15
15
  * Internal dependencies
16
16
  */
17
+ import { MIN_SPACER_SIZE } from './edit';
17
18
  import styles from './style.scss';
18
19
 
19
20
  const DEFAULT_VALUES = { px: 100, em: 10, rem: 10, vw: 10, vh: 25 };
@@ -66,7 +67,7 @@ function Controls( { attributes, context, setAttributes } ) {
66
67
  <PanelBody title={ __( 'Dimensions' ) }>
67
68
  <UnitControl
68
69
  label={ label }
69
- min={ 1 }
70
+ min={ MIN_SPACER_SIZE }
70
71
  value={ value }
71
72
  onChange={ handleChange }
72
73
  onUnitChange={ handleUnitChange }
@@ -16,8 +16,7 @@ import { View } from '@wordpress/primitives';
16
16
  */
17
17
  import SpacerControls from './controls';
18
18
 
19
- export const MIN_SPACER_SIZE = 1;
20
- export const MAX_SPACER_SIZE = 500;
19
+ export const MIN_SPACER_SIZE = 0;
21
20
 
22
21
  const ResizableSpacer = ( {
23
22
  orientation,
@@ -58,10 +57,7 @@ const ResizableSpacer = ( {
58
57
  }
59
58
  } }
60
59
  onResizeStop={ ( _event, _direction, elt ) => {
61
- const nextVal = Math.min(
62
- MAX_SPACER_SIZE,
63
- getCurrentSize( elt )
64
- );
60
+ const nextVal = getCurrentSize( elt );
65
61
  onResizeStop( `${ nextVal }px` );
66
62
  setIsResizing( false );
67
63
  } }
@@ -147,6 +143,7 @@ const SpacerEdit = ( {
147
143
  return (
148
144
  <>
149
145
  <ResizableSpacer
146
+ minHeight={ MIN_SPACER_SIZE }
150
147
  enable={ {
151
148
  top: false,
152
149
  right: false,
@@ -244,7 +244,11 @@ const deprecated = [
244
244
  );
245
245
  },
246
246
  isEligible: ( attributes ) => {
247
- return attributes.backgroundColor && ! attributes.style;
247
+ return (
248
+ attributes.backgroundColor &&
249
+ attributes.backgroundColor in oldColors &&
250
+ ! attributes.style
251
+ );
248
252
  },
249
253
 
250
254
  // This version is the first to introduce the style attribute to the
@@ -20,6 +20,14 @@
20
20
  "showTagCounts": {
21
21
  "type": "boolean",
22
22
  "default": false
23
+ },
24
+ "smallestFontSize": {
25
+ "type": "string",
26
+ "default": "8pt"
27
+ },
28
+ "largestFontSize": {
29
+ "type": "string",
30
+ "default": "22pt"
23
31
  }
24
32
  },
25
33
  "styles": [
@@ -7,14 +7,23 @@ import { map, filter } from 'lodash';
7
7
  * WordPress dependencies
8
8
  */
9
9
  import {
10
+ Flex,
11
+ FlexItem,
10
12
  PanelBody,
11
13
  ToggleControl,
12
14
  SelectControl,
13
15
  RangeControl,
16
+ __experimentalUnitControl as UnitControl,
17
+ __experimentalUseCustomUnits as useCustomUnits,
18
+ __experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue,
14
19
  } from '@wordpress/components';
15
20
  import { withSelect } from '@wordpress/data';
16
21
  import { __ } from '@wordpress/i18n';
17
- import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
22
+ import {
23
+ InspectorControls,
24
+ useBlockProps,
25
+ useSetting,
26
+ } from '@wordpress/block-editor';
18
27
  import ServerSideRender from '@wordpress/server-side-render';
19
28
  import { store as coreStore } from '@wordpress/core-data';
20
29
 
@@ -32,8 +41,26 @@ const MIN_TAGS = 1;
32
41
  */
33
42
  const MAX_TAGS = 100;
34
43
 
44
+ const MIN_FONT_SIZE = 0.1;
45
+ const MAX_FONT_SIZE = 100;
46
+
35
47
  function TagCloudEdit( { attributes, setAttributes, taxonomies } ) {
36
- const { taxonomy, showTagCounts, numberOfTags } = attributes;
48
+ const {
49
+ taxonomy,
50
+ showTagCounts,
51
+ numberOfTags,
52
+ smallestFontSize,
53
+ largestFontSize,
54
+ } = attributes;
55
+
56
+ const units = useCustomUnits( {
57
+ availableUnits: useSetting( 'spacing.units' ) || [
58
+ '%',
59
+ 'px',
60
+ 'em',
61
+ 'rem',
62
+ ],
63
+ } );
37
64
 
38
65
  const getTaxonomyOptions = () => {
39
66
  const selectOption = {
@@ -54,6 +81,33 @@ function TagCloudEdit( { attributes, setAttributes, taxonomies } ) {
54
81
  return [ selectOption, ...taxonomyOptions ];
55
82
  };
56
83
 
84
+ const onFontSizeChange = ( fontSizeLabel, newValue ) => {
85
+ // eslint-disable-next-line @wordpress/no-unused-vars-before-return
86
+ const [ quantity, newUnit ] = parseQuantityAndUnitFromRawValue(
87
+ newValue
88
+ );
89
+ if ( ! Number.isFinite( quantity ) ) {
90
+ return;
91
+ }
92
+ const updateObj = { [ fontSizeLabel ]: newValue };
93
+ // We need to keep in sync the `unit` changes to both `smallestFontSize`
94
+ // and `largestFontSize` attributes.
95
+ Object.entries( {
96
+ smallestFontSize,
97
+ largestFontSize,
98
+ } ).forEach( ( [ attribute, currentValue ] ) => {
99
+ const [
100
+ currentQuantity,
101
+ currentUnit,
102
+ ] = parseQuantityAndUnitFromRawValue( currentValue );
103
+ // Only add an update if the other font size attribute has a different unit.
104
+ if ( attribute !== fontSizeLabel && currentUnit !== newUnit ) {
105
+ updateObj[ attribute ] = `${ currentQuantity }${ newUnit }`;
106
+ }
107
+ } );
108
+ setAttributes( updateObj );
109
+ };
110
+
57
111
  const inspectorControls = (
58
112
  <InspectorControls>
59
113
  <PanelBody title={ __( 'Tag Cloud settings' ) }>
@@ -82,6 +136,32 @@ function TagCloudEdit( { attributes, setAttributes, taxonomies } ) {
82
136
  max={ MAX_TAGS }
83
137
  required
84
138
  />
139
+ <Flex>
140
+ <FlexItem isBlock>
141
+ <UnitControl
142
+ label={ __( 'Smallest size' ) }
143
+ value={ smallestFontSize }
144
+ onChange={ ( value ) => {
145
+ onFontSizeChange( 'smallestFontSize', value );
146
+ } }
147
+ units={ units }
148
+ min={ MIN_FONT_SIZE }
149
+ max={ MAX_FONT_SIZE }
150
+ />
151
+ </FlexItem>
152
+ <FlexItem isBlock>
153
+ <UnitControl
154
+ label={ __( 'Largest size' ) }
155
+ value={ largestFontSize }
156
+ onChange={ ( value ) => {
157
+ onFontSizeChange( 'largestFontSize', value );
158
+ } }
159
+ units={ units }
160
+ min={ MIN_FONT_SIZE }
161
+ max={ MAX_FONT_SIZE }
162
+ />
163
+ </FlexItem>
164
+ </Flex>
85
165
  </PanelBody>
86
166
  </InspectorControls>
87
167
  );
@@ -13,11 +13,17 @@
13
13
  * @return string Returns the tag cloud for selected taxonomy.
14
14
  */
15
15
  function render_block_core_tag_cloud( $attributes ) {
16
+ $smallest_font_size = $attributes['smallestFontSize'];
17
+ $unit = ( preg_match( '/^[0-9.]+(?P<unit>[a-z%]+)$/i', $smallest_font_size, $m ) ? $m['unit'] : 'pt' );
18
+
16
19
  $args = array(
17
20
  'echo' => false,
21
+ 'unit' => $unit,
18
22
  'taxonomy' => $attributes['taxonomy'],
19
23
  'show_count' => $attributes['showTagCounts'],
20
24
  'number' => $attributes['numberOfTags'],
25
+ 'smallest' => floatVal( $attributes['smallestFontSize'] ),
26
+ 'largest' => floatVal( $attributes['largestFontSize'] ),
21
27
  );
22
28
  $tag_cloud = wp_tag_cloud( $args );
23
29
 
@@ -1,36 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _element = require("@wordpress/element");
9
-
10
- var _i18n = require("@wordpress/i18n");
11
-
12
- var _blockEditor = require("@wordpress/block-editor");
13
-
14
- /**
15
- * WordPress dependencies
16
- */
17
- const SeparatorSettings = _ref => {
18
- let {
19
- color,
20
- setColor
21
- } = _ref;
22
- return (0, _element.createElement)(_blockEditor.InspectorControls, null, (0, _element.createElement)(_blockEditor.PanelColorSettings, {
23
- __experimentalHasMultipleOrigins: true,
24
- __experimentalIsRenderedInSidebar: true,
25
- title: (0, _i18n.__)('Color'),
26
- colorSettings: [{
27
- value: color.color,
28
- onChange: setColor,
29
- label: (0, _i18n.__)('Color')
30
- }]
31
- }));
32
- };
33
-
34
- var _default = SeparatorSettings;
35
- exports.default = _default;
36
- //# sourceMappingURL=separator-settings.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/block-library/src/separator/separator-settings.js"],"names":["SeparatorSettings","color","setColor","value","onChange","label"],"mappings":";;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;AAIA,MAAMA,iBAAiB,GAAG;AAAA,MAAE;AAAEC,IAAAA,KAAF;AAASC,IAAAA;AAAT,GAAF;AAAA,SACzB,4BAAC,8BAAD,QACC,4BAAC,+BAAD;AACC,IAAA,gCAAgC,MADjC;AAEC,IAAA,iCAAiC,MAFlC;AAGC,IAAA,KAAK,EAAG,cAAI,OAAJ,CAHT;AAIC,IAAA,aAAa,EAAG,CACf;AACCC,MAAAA,KAAK,EAAEF,KAAK,CAACA,KADd;AAECG,MAAAA,QAAQ,EAAEF,QAFX;AAGCG,MAAAA,KAAK,EAAE,cAAI,OAAJ;AAHR,KADe;AAJjB,IADD,CADyB;AAAA,CAA1B;;eAiBeL,iB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { InspectorControls, PanelColorSettings } from '@wordpress/block-editor';\n\nconst SeparatorSettings = ( { color, setColor } ) => (\n\t<InspectorControls>\n\t\t<PanelColorSettings\n\t\t\t__experimentalHasMultipleOrigins\n\t\t\t__experimentalIsRenderedInSidebar\n\t\t\ttitle={ __( 'Color' ) }\n\t\t\tcolorSettings={ [\n\t\t\t\t{\n\t\t\t\t\tvalue: color.color,\n\t\t\t\t\tonChange: setColor,\n\t\t\t\t\tlabel: __( 'Color' ),\n\t\t\t\t},\n\t\t\t] }\n\t\t></PanelColorSettings>\n\t</InspectorControls>\n);\n\nexport default SeparatorSettings;\n"]}
@@ -1,27 +0,0 @@
1
- import { createElement } from "@wordpress/element";
2
-
3
- /**
4
- * WordPress dependencies
5
- */
6
- import { __ } from '@wordpress/i18n';
7
- import { InspectorControls, PanelColorSettings } from '@wordpress/block-editor';
8
-
9
- const SeparatorSettings = _ref => {
10
- let {
11
- color,
12
- setColor
13
- } = _ref;
14
- return createElement(InspectorControls, null, createElement(PanelColorSettings, {
15
- __experimentalHasMultipleOrigins: true,
16
- __experimentalIsRenderedInSidebar: true,
17
- title: __('Color'),
18
- colorSettings: [{
19
- value: color.color,
20
- onChange: setColor,
21
- label: __('Color')
22
- }]
23
- }));
24
- };
25
-
26
- export default SeparatorSettings;
27
- //# sourceMappingURL=separator-settings.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/block-library/src/separator/separator-settings.js"],"names":["__","InspectorControls","PanelColorSettings","SeparatorSettings","color","setColor","value","onChange","label"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,iBAAT,EAA4BC,kBAA5B,QAAsD,yBAAtD;;AAEA,MAAMC,iBAAiB,GAAG;AAAA,MAAE;AAAEC,IAAAA,KAAF;AAASC,IAAAA;AAAT,GAAF;AAAA,SACzB,cAAC,iBAAD,QACC,cAAC,kBAAD;AACC,IAAA,gCAAgC,MADjC;AAEC,IAAA,iCAAiC,MAFlC;AAGC,IAAA,KAAK,EAAGL,EAAE,CAAE,OAAF,CAHX;AAIC,IAAA,aAAa,EAAG,CACf;AACCM,MAAAA,KAAK,EAAEF,KAAK,CAACA,KADd;AAECG,MAAAA,QAAQ,EAAEF,QAFX;AAGCG,MAAAA,KAAK,EAAER,EAAE,CAAE,OAAF;AAHV,KADe;AAJjB,IADD,CADyB;AAAA,CAA1B;;AAiBA,eAAeG,iBAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { InspectorControls, PanelColorSettings } from '@wordpress/block-editor';\n\nconst SeparatorSettings = ( { color, setColor } ) => (\n\t<InspectorControls>\n\t\t<PanelColorSettings\n\t\t\t__experimentalHasMultipleOrigins\n\t\t\t__experimentalIsRenderedInSidebar\n\t\t\ttitle={ __( 'Color' ) }\n\t\t\tcolorSettings={ [\n\t\t\t\t{\n\t\t\t\t\tvalue: color.color,\n\t\t\t\t\tonChange: setColor,\n\t\t\t\t\tlabel: __( 'Color' ),\n\t\t\t\t},\n\t\t\t] }\n\t\t></PanelColorSettings>\n\t</InspectorControls>\n);\n\nexport default SeparatorSettings;\n"]}
@@ -1,24 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { __ } from '@wordpress/i18n';
5
- import { InspectorControls, PanelColorSettings } from '@wordpress/block-editor';
6
-
7
- const SeparatorSettings = ( { color, setColor } ) => (
8
- <InspectorControls>
9
- <PanelColorSettings
10
- __experimentalHasMultipleOrigins
11
- __experimentalIsRenderedInSidebar
12
- title={ __( 'Color' ) }
13
- colorSettings={ [
14
- {
15
- value: color.color,
16
- onChange: setColor,
17
- label: __( 'Color' ),
18
- },
19
- ] }
20
- ></PanelColorSettings>
21
- </InspectorControls>
22
- );
23
-
24
- export default SeparatorSettings;