@wordpress/block-editor 8.0.8 → 8.0.12-next.33ec3857e2.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 (294) hide show
  1. package/README.md +4 -0
  2. package/build/components/block-caption/index.native.js +14 -3
  3. package/build/components/block-caption/index.native.js.map +1 -1
  4. package/build/components/block-inspector/index.js +12 -23
  5. package/build/components/block-inspector/index.js.map +1 -1
  6. package/build/components/block-list-appender/index.js +3 -11
  7. package/build/components/block-list-appender/index.js.map +1 -1
  8. package/build/components/block-preview/auto.js +10 -2
  9. package/build/components/block-preview/auto.js.map +1 -1
  10. package/build/components/block-preview/index.js +51 -0
  11. package/build/components/block-preview/index.js.map +1 -1
  12. package/build/components/block-settings/container.native.js +2 -1
  13. package/build/components/block-settings/container.native.js.map +1 -1
  14. package/build/components/block-styles/index.js +110 -134
  15. package/build/components/block-styles/index.js.map +1 -1
  16. package/build/components/block-styles/menu-items.js +63 -0
  17. package/build/components/block-styles/menu-items.js.map +1 -0
  18. package/build/components/block-styles/preview-panel.js +45 -0
  19. package/build/components/block-styles/preview-panel.js.map +1 -0
  20. package/build/components/block-styles/use-styles-for-block.js +119 -0
  21. package/build/components/block-styles/use-styles-for-block.js.map +1 -0
  22. package/build/components/block-styles/utils.js +39 -0
  23. package/build/components/block-styles/utils.js.map +1 -1
  24. package/build/components/block-switcher/block-styles-menu.js +3 -23
  25. package/build/components/block-switcher/block-styles-menu.js.map +1 -1
  26. package/build/components/block-tools/back-compat.js +2 -1
  27. package/build/components/block-tools/back-compat.js.map +1 -1
  28. package/build/components/block-tools/insertion-point.js +11 -1
  29. package/build/components/block-tools/insertion-point.js.map +1 -1
  30. package/build/components/button-block-appender/index.js +2 -1
  31. package/build/components/button-block-appender/index.js.map +1 -1
  32. package/build/components/colors-gradients/control.js +1 -0
  33. package/build/components/colors-gradients/control.js.map +1 -1
  34. package/build/components/colors-gradients/panel-color-gradient-settings.js +51 -10
  35. package/build/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
  36. package/build/components/default-block-appender/index.js +16 -19
  37. package/build/components/default-block-appender/index.js.map +1 -1
  38. package/build/components/default-style-picker/index.js +18 -3
  39. package/build/components/default-style-picker/index.js.map +1 -1
  40. package/build/components/iframe/index.js +3 -4
  41. package/build/components/iframe/index.js.map +1 -1
  42. package/build/components/index.js +17 -10
  43. package/build/components/index.js.map +1 -1
  44. package/build/components/inner-blocks/default-block-appender.js +2 -4
  45. package/build/components/inner-blocks/default-block-appender.js.map +1 -1
  46. package/build/components/inserter/index.native.js +1 -1
  47. package/build/components/inserter/index.native.js.map +1 -1
  48. package/build/components/inserter/tabs.native.js +7 -4
  49. package/build/components/inserter/tabs.native.js.map +1 -1
  50. package/build/components/inspector-controls/block-support-slot-container.js +2 -1
  51. package/build/components/inspector-controls/block-support-slot-container.js.map +1 -1
  52. package/build/components/inspector-controls/fill.native.js +3 -5
  53. package/build/components/inspector-controls/fill.native.js.map +1 -1
  54. package/build/components/inspector-controls/groups.js +2 -0
  55. package/build/components/inspector-controls/groups.js.map +1 -1
  56. package/build/components/inspector-controls/slot.js +1 -3
  57. package/build/components/inspector-controls/slot.js.map +1 -1
  58. package/build/components/letter-spacing-control/index.js +6 -6
  59. package/build/components/letter-spacing-control/index.js.map +1 -1
  60. package/build/components/list-view/block-select-button.js +23 -3
  61. package/build/components/list-view/block-select-button.js.map +1 -1
  62. package/build/components/media-placeholder/index.js +2 -0
  63. package/build/components/media-placeholder/index.js.map +1 -1
  64. package/build/components/media-replace-flow/index.js +2 -0
  65. package/build/components/media-replace-flow/index.js.map +1 -1
  66. package/build/components/rich-text/file-paste-handler.js +1 -1
  67. package/build/components/rich-text/file-paste-handler.js.map +1 -1
  68. package/build/components/rich-text/prevent-event-discovery.js +33 -0
  69. package/build/components/rich-text/prevent-event-discovery.js.map +1 -0
  70. package/build/components/rich-text/use-input-rules.js +3 -1
  71. package/build/components/rich-text/use-input-rules.js.map +1 -1
  72. package/build/components/selection-scroll-into-view/index.js +2 -1
  73. package/build/components/selection-scroll-into-view/index.js.map +1 -1
  74. package/build/components/use-display-block-controls/index.native.js +45 -0
  75. package/build/components/use-display-block-controls/index.native.js.map +1 -0
  76. package/build/components/use-on-block-drop/index.js +7 -3
  77. package/build/components/use-on-block-drop/index.js.map +1 -1
  78. package/build/components/writing-flow/use-multi-selection.js +3 -1
  79. package/build/components/writing-flow/use-multi-selection.js.map +1 -1
  80. package/build/hooks/border-color.js +63 -5
  81. package/build/hooks/border-color.js.map +1 -1
  82. package/build/hooks/border-radius.js +47 -0
  83. package/build/hooks/border-radius.js.map +1 -1
  84. package/build/hooks/border-style.js +41 -0
  85. package/build/hooks/border-style.js.map +1 -1
  86. package/build/hooks/border-width.js +70 -31
  87. package/build/hooks/border-width.js.map +1 -1
  88. package/build/hooks/border.js +81 -11
  89. package/build/hooks/border.js.map +1 -1
  90. package/build/hooks/letter-spacing.js +1 -1
  91. package/build/hooks/letter-spacing.js.map +1 -1
  92. package/build/hooks/typography.js +1 -1
  93. package/build/hooks/typography.js.map +1 -1
  94. package/build/store/actions.js +1 -2
  95. package/build/store/actions.js.map +1 -1
  96. package/build/store/defaults.js +5 -1
  97. package/build/store/defaults.js.map +1 -1
  98. package/build/store/reducer.js +10 -82
  99. package/build/store/reducer.js.map +1 -1
  100. package/build/store/selectors.js +25 -7
  101. package/build/store/selectors.js.map +1 -1
  102. package/build/utils/get-paste-event-data.js +1 -1
  103. package/build/utils/get-paste-event-data.js.map +1 -1
  104. package/build/utils/parse-css-unit-to-px.js +1 -1
  105. package/build/utils/parse-css-unit-to-px.js.map +1 -1
  106. package/build/utils/transform-styles/index.js +2 -3
  107. package/build/utils/transform-styles/index.js.map +1 -1
  108. package/build-module/components/block-caption/index.native.js +13 -3
  109. package/build-module/components/block-caption/index.native.js.map +1 -1
  110. package/build-module/components/block-inspector/index.js +12 -23
  111. package/build-module/components/block-inspector/index.js.map +1 -1
  112. package/build-module/components/block-list-appender/index.js +3 -10
  113. package/build-module/components/block-list-appender/index.js.map +1 -1
  114. package/build-module/components/block-preview/auto.js +10 -2
  115. package/build-module/components/block-preview/auto.js.map +1 -1
  116. package/build-module/components/block-preview/index.js +46 -0
  117. package/build-module/components/block-preview/index.js.map +1 -1
  118. package/build-module/components/block-settings/container.native.js +2 -1
  119. package/build-module/components/block-settings/container.native.js.map +1 -1
  120. package/build-module/components/block-styles/index.js +112 -133
  121. package/build-module/components/block-styles/index.js.map +1 -1
  122. package/build-module/components/block-styles/menu-items.js +50 -0
  123. package/build-module/components/block-styles/menu-items.js.map +1 -0
  124. package/build-module/components/block-styles/preview-panel.js +35 -0
  125. package/build-module/components/block-styles/preview-panel.js.map +1 -0
  126. package/build-module/components/block-styles/use-styles-for-block.js +107 -0
  127. package/build-module/components/block-styles/use-styles-for-block.js.map +1 -0
  128. package/build-module/components/block-styles/utils.js +34 -0
  129. package/build-module/components/block-styles/utils.js.map +1 -1
  130. package/build-module/components/block-switcher/block-styles-menu.js +3 -21
  131. package/build-module/components/block-switcher/block-styles-menu.js.map +1 -1
  132. package/build-module/components/block-tools/back-compat.js +2 -1
  133. package/build-module/components/block-tools/back-compat.js.map +1 -1
  134. package/build-module/components/block-tools/insertion-point.js +11 -1
  135. package/build-module/components/block-tools/insertion-point.js.map +1 -1
  136. package/build-module/components/button-block-appender/index.js +2 -1
  137. package/build-module/components/button-block-appender/index.js.map +1 -1
  138. package/build-module/components/colors-gradients/control.js +1 -0
  139. package/build-module/components/colors-gradients/control.js.map +1 -1
  140. package/build-module/components/colors-gradients/panel-color-gradient-settings.js +54 -13
  141. package/build-module/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
  142. package/build-module/components/default-block-appender/index.js +15 -18
  143. package/build-module/components/default-block-appender/index.js.map +1 -1
  144. package/build-module/components/default-style-picker/index.js +17 -3
  145. package/build-module/components/default-style-picker/index.js.map +1 -1
  146. package/build-module/components/iframe/index.js +3 -4
  147. package/build-module/components/iframe/index.js.map +1 -1
  148. package/build-module/components/index.js +2 -2
  149. package/build-module/components/index.js.map +1 -1
  150. package/build-module/components/inner-blocks/default-block-appender.js +2 -4
  151. package/build-module/components/inner-blocks/default-block-appender.js.map +1 -1
  152. package/build-module/components/inserter/index.native.js +2 -2
  153. package/build-module/components/inserter/index.native.js.map +1 -1
  154. package/build-module/components/inserter/tabs.native.js +7 -4
  155. package/build-module/components/inserter/tabs.native.js.map +1 -1
  156. package/build-module/components/inspector-controls/block-support-slot-container.js +2 -1
  157. package/build-module/components/inspector-controls/block-support-slot-container.js.map +1 -1
  158. package/build-module/components/inspector-controls/fill.native.js +3 -5
  159. package/build-module/components/inspector-controls/fill.native.js.map +1 -1
  160. package/build-module/components/inspector-controls/groups.js +2 -0
  161. package/build-module/components/inspector-controls/groups.js.map +1 -1
  162. package/build-module/components/inspector-controls/slot.js +1 -3
  163. package/build-module/components/inspector-controls/slot.js.map +1 -1
  164. package/build-module/components/letter-spacing-control/index.js +6 -6
  165. package/build-module/components/letter-spacing-control/index.js.map +1 -1
  166. package/build-module/components/list-view/block-select-button.js +22 -3
  167. package/build-module/components/list-view/block-select-button.js.map +1 -1
  168. package/build-module/components/media-placeholder/index.js +2 -0
  169. package/build-module/components/media-placeholder/index.js.map +1 -1
  170. package/build-module/components/media-replace-flow/index.js +2 -0
  171. package/build-module/components/media-replace-flow/index.js.map +1 -1
  172. package/build-module/components/rich-text/file-paste-handler.js +1 -1
  173. package/build-module/components/rich-text/file-paste-handler.js.map +1 -1
  174. package/build-module/components/rich-text/prevent-event-discovery.js +25 -0
  175. package/build-module/components/rich-text/prevent-event-discovery.js.map +1 -0
  176. package/build-module/components/rich-text/use-input-rules.js +2 -1
  177. package/build-module/components/rich-text/use-input-rules.js.map +1 -1
  178. package/build-module/components/selection-scroll-into-view/index.js +2 -1
  179. package/build-module/components/selection-scroll-into-view/index.js.map +1 -1
  180. package/build-module/components/use-display-block-controls/index.native.js +34 -0
  181. package/build-module/components/use-display-block-controls/index.native.js.map +1 -0
  182. package/build-module/components/use-on-block-drop/index.js +7 -3
  183. package/build-module/components/use-on-block-drop/index.js.map +1 -1
  184. package/build-module/components/writing-flow/use-multi-selection.js +3 -4
  185. package/build-module/components/writing-flow/use-multi-selection.js.map +1 -1
  186. package/build-module/hooks/border-color.js +61 -7
  187. package/build-module/hooks/border-color.js.map +1 -1
  188. package/build-module/hooks/border-radius.js +42 -0
  189. package/build-module/hooks/border-radius.js.map +1 -1
  190. package/build-module/hooks/border-style.js +36 -0
  191. package/build-module/hooks/border-style.js.map +1 -1
  192. package/build-module/hooks/border-width.js +66 -32
  193. package/build-module/hooks/border-width.js.map +1 -1
  194. package/build-module/hooks/border.js +80 -12
  195. package/build-module/hooks/border.js.map +1 -1
  196. package/build-module/hooks/letter-spacing.js +1 -1
  197. package/build-module/hooks/letter-spacing.js.map +1 -1
  198. package/build-module/hooks/typography.js +1 -1
  199. package/build-module/hooks/typography.js.map +1 -1
  200. package/build-module/store/actions.js +1 -2
  201. package/build-module/store/actions.js.map +1 -1
  202. package/build-module/store/defaults.js +5 -1
  203. package/build-module/store/defaults.js.map +1 -1
  204. package/build-module/store/reducer.js +11 -83
  205. package/build-module/store/reducer.js.map +1 -1
  206. package/build-module/store/selectors.js +24 -7
  207. package/build-module/store/selectors.js.map +1 -1
  208. package/build-module/utils/get-paste-event-data.js +1 -1
  209. package/build-module/utils/get-paste-event-data.js.map +1 -1
  210. package/build-module/utils/parse-css-unit-to-px.js +1 -1
  211. package/build-module/utils/parse-css-unit-to-px.js.map +1 -1
  212. package/build-module/utils/transform-styles/index.js +2 -3
  213. package/build-module/utils/transform-styles/index.js.map +1 -1
  214. package/build-style/style-rtl.css +229 -182
  215. package/build-style/style.css +229 -182
  216. package/package.json +27 -27
  217. package/src/components/block-caption/index.native.js +22 -4
  218. package/src/components/block-inspector/index.js +14 -17
  219. package/src/components/block-list-appender/index.js +5 -21
  220. package/src/components/block-preview/auto.js +7 -2
  221. package/src/components/block-preview/index.js +60 -0
  222. package/src/components/block-preview/style.scss +23 -0
  223. package/src/components/block-preview/test/index.js +114 -0
  224. package/src/components/block-settings/container.native.js +1 -0
  225. package/src/components/block-styles/index.js +125 -145
  226. package/src/components/block-styles/menu-items.js +49 -0
  227. package/src/components/block-styles/preview-panel.js +36 -0
  228. package/src/components/block-styles/style.scss +59 -51
  229. package/src/components/block-styles/test/{index.js → utils.js} +60 -1
  230. package/src/components/block-styles/use-styles-for-block.js +99 -0
  231. package/src/components/block-styles/utils.js +39 -0
  232. package/src/components/block-switcher/block-styles-menu.js +3 -38
  233. package/src/components/block-tools/back-compat.js +1 -0
  234. package/src/components/block-tools/insertion-point.js +10 -1
  235. package/src/components/border-style-control/style.scss +3 -3
  236. package/src/components/button-block-appender/index.js +1 -0
  237. package/src/components/color-palette/test/__snapshots__/control.js.snap +1 -0
  238. package/src/components/colors-gradients/control.js +3 -0
  239. package/src/components/colors-gradients/panel-color-gradient-settings.js +75 -19
  240. package/src/components/colors-gradients/style.scss +42 -5
  241. package/src/components/default-block-appender/index.js +17 -24
  242. package/src/components/default-block-appender/style.scss +4 -0
  243. package/src/components/default-block-appender/test/__snapshots__/index.js.snap +12 -24
  244. package/src/components/default-block-appender/test/index.js +4 -14
  245. package/src/components/default-style-picker/index.js +18 -6
  246. package/src/components/iframe/index.js +6 -3
  247. package/src/components/index.js +5 -2
  248. package/src/components/inner-blocks/README.md +2 -0
  249. package/src/components/inner-blocks/default-block-appender.js +2 -7
  250. package/src/components/inserter/index.native.js +2 -2
  251. package/src/components/inserter/tabs.native.js +5 -4
  252. package/src/components/inspector-controls/block-support-slot-container.js +3 -1
  253. package/src/components/inspector-controls/fill.native.js +4 -3
  254. package/src/components/inspector-controls/groups.js +2 -0
  255. package/src/components/inspector-controls/slot.js +2 -7
  256. package/src/components/letter-spacing-control/index.js +6 -6
  257. package/src/components/link-control/README.md +1 -1
  258. package/src/components/link-control/test/index.js +2 -0
  259. package/src/components/list-view/block-select-button.js +20 -1
  260. package/src/components/media-placeholder/index.js +2 -0
  261. package/src/components/media-replace-flow/index.js +2 -0
  262. package/src/components/rich-text/file-paste-handler.js +3 -1
  263. package/src/components/rich-text/prevent-event-discovery.js +23 -0
  264. package/src/components/rich-text/use-input-rules.js +2 -1
  265. package/src/components/selection-scroll-into-view/index.js +1 -0
  266. package/src/components/url-input/README.md +5 -0
  267. package/src/components/use-display-block-controls/index.native.js +38 -0
  268. package/src/components/use-on-block-drop/index.js +7 -3
  269. package/src/components/writing-flow/test/use-multi-selection.js +36 -0
  270. package/src/components/writing-flow/use-multi-selection.js +12 -9
  271. package/src/hooks/border-color.js +55 -3
  272. package/src/hooks/border-radius.js +32 -0
  273. package/src/hooks/border-style.js +26 -0
  274. package/src/hooks/border-width.js +56 -32
  275. package/src/hooks/border.js +115 -20
  276. package/src/hooks/border.scss +3 -17
  277. package/src/hooks/dimensions.scss +5 -0
  278. package/src/hooks/letter-spacing.js +1 -1
  279. package/src/hooks/typography.js +1 -1
  280. package/src/store/actions.js +1 -2
  281. package/src/store/defaults.js +2 -0
  282. package/src/store/reducer.js +13 -104
  283. package/src/store/selectors.js +37 -7
  284. package/src/style.scss +4 -3
  285. package/src/utils/get-paste-event-data.js +1 -1
  286. package/src/utils/parse-css-unit-to-px.js +1 -1
  287. package/src/utils/test/parse-css-unit-to-px.js +1 -0
  288. package/src/utils/transform-styles/index.js +13 -16
  289. package/tsconfig.tsbuildinfo +1 -1
  290. package/build/components/use-canvas-click-redirect/index.js +0 -66
  291. package/build/components/use-canvas-click-redirect/index.js.map +0 -1
  292. package/build-module/components/use-canvas-click-redirect/index.js +0 -54
  293. package/build-module/components/use-canvas-click-redirect/index.js.map +0 -1
  294. package/src/components/use-canvas-click-redirect/index.js +0 -57
@@ -5,13 +5,14 @@ import {
5
5
  __experimentalUnitControl as UnitControl,
6
6
  __experimentalUseCustomUnits as useCustomUnits,
7
7
  } from '@wordpress/components';
8
- import { useEffect, useState } from '@wordpress/element';
8
+ import { useState } from '@wordpress/element';
9
9
  import { __ } from '@wordpress/i18n';
10
10
 
11
11
  /**
12
12
  * Internal dependencies
13
13
  */
14
14
  import { cleanEmptyObject } from './utils';
15
+ import { removeBorderAttribute } from './border';
15
16
  import useSetting from '../components/use-setting';
16
17
 
17
18
  const MIN_BORDER_WIDTH = 0;
@@ -31,25 +32,12 @@ export const BorderWidthEdit = ( props ) => {
31
32
 
32
33
  const { width, color: customBorderColor, style: borderStyle } =
33
34
  style?.border || {};
35
+
36
+ // Used to temporarily track previous border color & style selections to be
37
+ // able to restore them when border width changes from zero value.
34
38
  const [ styleSelection, setStyleSelection ] = useState();
35
39
  const [ colorSelection, setColorSelection ] = useState();
36
-
37
- // Temporarily track previous border color & style selections to be able to
38
- // restore them when border width changes from zero value.
39
- useEffect( () => {
40
- if ( borderStyle !== 'none' ) {
41
- setStyleSelection( borderStyle );
42
- }
43
- }, [ borderStyle ] );
44
-
45
- useEffect( () => {
46
- if ( borderColor || customBorderColor ) {
47
- setColorSelection( {
48
- name: !! borderColor ? borderColor : undefined,
49
- color: !! customBorderColor ? customBorderColor : undefined,
50
- } );
51
- }
52
- }, [ borderColor, customBorderColor ] );
40
+ const [ customColorSelection, setCustomColorSelection ] = useState();
53
41
 
54
42
  const onChange = ( newWidth ) => {
55
43
  let newStyle = {
@@ -64,28 +52,39 @@ export const BorderWidthEdit = ( props ) => {
64
52
  let borderPaletteColor = borderColor;
65
53
 
66
54
  const hasZeroWidth = parseFloat( newWidth ) === 0;
55
+ const hadPreviousZeroWidth = parseFloat( width ) === 0;
67
56
 
68
57
  // Setting the border width explicitly to zero will also set the
69
58
  // border style to `none` and clear border color attributes.
70
- if ( hasZeroWidth ) {
59
+ if ( hasZeroWidth && ! hadPreviousZeroWidth ) {
60
+ // Before clearing color and style selections, keep track of
61
+ // the current selections so they can be restored when the width
62
+ // changes to a non-zero value.
63
+ setColorSelection( borderColor );
64
+ setCustomColorSelection( customBorderColor );
65
+ setStyleSelection( borderStyle );
66
+
67
+ // Clear style and color attributes.
71
68
  borderPaletteColor = undefined;
72
69
  newStyle.border.color = undefined;
73
70
  newStyle.border.style = 'none';
74
71
  }
75
72
 
76
- // Restore previous border style selection if width is now not zero and
77
- // border style was 'none'. This is to support changes to the UI which
78
- // change the border style UI to a segmented control without a "none"
79
- // option.
80
- if ( ! hasZeroWidth && borderStyle === 'none' ) {
81
- newStyle.border.style = styleSelection;
82
- }
83
-
84
- // Restore previous border color selection if width is no longer zero
85
- // and current border color is undefined.
86
- if ( ! hasZeroWidth && borderColor === undefined ) {
87
- borderPaletteColor = colorSelection?.name;
88
- newStyle.border.color = colorSelection?.color;
73
+ if ( ! hasZeroWidth && hadPreviousZeroWidth ) {
74
+ // Restore previous border style selection if width is now not zero and
75
+ // border style was 'none'. This is to support changes to the UI which
76
+ // change the border style UI to a segmented control without a "none"
77
+ // option.
78
+ if ( borderStyle === 'none' ) {
79
+ newStyle.border.style = styleSelection;
80
+ }
81
+
82
+ // Restore previous border color selection if width is no longer zero
83
+ // and current border color is undefined.
84
+ if ( borderColor === undefined ) {
85
+ borderPaletteColor = colorSelection;
86
+ newStyle.border.color = customColorSelection;
87
+ }
89
88
  }
90
89
 
91
90
  // If width was reset, clean out undefined styles.
@@ -113,3 +112,28 @@ export const BorderWidthEdit = ( props ) => {
113
112
  />
114
113
  );
115
114
  };
115
+
116
+ /**
117
+ * Checks if there is a current value in the border width block support
118
+ * attributes.
119
+ *
120
+ * @param {Object} props Block props.
121
+ * @return {boolean} Whether or not the block has a border width value set.
122
+ */
123
+ export function hasBorderWidthValue( props ) {
124
+ return !! props.attributes.style?.border?.width;
125
+ }
126
+
127
+ /**
128
+ * Resets the border width block support attribute. This can be used when
129
+ * disabling the border width support control for a block via a progressive
130
+ * discovery panel.
131
+ *
132
+ * @param {Object} props Block props.
133
+ * @param {Object} props.attributes Block's attributes.
134
+ * @param {Object} props.setAttributes Function to set block's attributes.
135
+ */
136
+ export function resetBorderWidth( { attributes = {}, setAttributes } ) {
137
+ const { style } = attributes;
138
+ setAttributes( { style: removeBorderAttribute( style, 'width' ) } );
139
+ }
@@ -2,23 +2,41 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { getBlockSupport } from '@wordpress/blocks';
5
- import { PanelBody } from '@wordpress/components';
5
+ import { __experimentalToolsPanelItem as ToolsPanelItem } from '@wordpress/components';
6
6
  import { Platform } from '@wordpress/element';
7
7
  import { __ } from '@wordpress/i18n';
8
8
 
9
9
  /**
10
10
  * Internal dependencies
11
11
  */
12
+ import {
13
+ BorderColorEdit,
14
+ hasBorderColorValue,
15
+ resetBorderColor,
16
+ } from './border-color';
17
+ import {
18
+ BorderRadiusEdit,
19
+ hasBorderRadiusValue,
20
+ resetBorderRadius,
21
+ } from './border-radius';
22
+ import {
23
+ BorderStyleEdit,
24
+ hasBorderStyleValue,
25
+ resetBorderStyle,
26
+ } from './border-style';
27
+ import {
28
+ BorderWidthEdit,
29
+ hasBorderWidthValue,
30
+ resetBorderWidth,
31
+ } from './border-width';
12
32
  import InspectorControls from '../components/inspector-controls';
13
33
  import useSetting from '../components/use-setting';
14
- import { BorderColorEdit } from './border-color';
15
- import { BorderRadiusEdit } from './border-radius';
16
- import { BorderStyleEdit } from './border-style';
17
- import { BorderWidthEdit } from './border-width';
34
+ import { cleanEmptyObject } from './utils';
18
35
 
19
36
  export const BORDER_SUPPORT_KEY = '__experimentalBorder';
20
37
 
21
38
  export function BorderPanel( props ) {
39
+ const { clientId } = props;
22
40
  const isDisabled = useIsBorderDisabled( props );
23
41
  const isSupported = hasBorderSupport( props.name );
24
42
 
@@ -39,22 +57,80 @@ export function BorderPanel( props ) {
39
57
  return null;
40
58
  }
41
59
 
60
+ const defaultBorderControls = getBlockSupport( props.name, [
61
+ BORDER_SUPPORT_KEY,
62
+ '__experimentalDefaultControls',
63
+ ] );
64
+
65
+ const createResetAllFilter = (
66
+ borderAttribute,
67
+ topLevelAttributes = {}
68
+ ) => ( newAttributes ) => ( {
69
+ ...newAttributes,
70
+ ...topLevelAttributes,
71
+ style: {
72
+ ...newAttributes.style,
73
+ border: {
74
+ ...newAttributes.style?.border,
75
+ [ borderAttribute ]: undefined,
76
+ },
77
+ },
78
+ } );
79
+
42
80
  return (
43
- <InspectorControls>
44
- <PanelBody
45
- className="block-editor-hooks__border-controls"
46
- title={ __( 'Border' ) }
47
- initialOpen={ false }
48
- >
49
- { ( isWidthSupported || isStyleSupported ) && (
50
- <div className="block-editor-hooks__border-controls-row">
51
- { isWidthSupported && <BorderWidthEdit { ...props } /> }
52
- { isStyleSupported && <BorderStyleEdit { ...props } /> }
53
- </div>
54
- ) }
55
- { isColorSupported && <BorderColorEdit { ...props } /> }
56
- { isRadiusSupported && <BorderRadiusEdit { ...props } /> }
57
- </PanelBody>
81
+ <InspectorControls __experimentalGroup="border">
82
+ { isWidthSupported && (
83
+ <ToolsPanelItem
84
+ className="single-column"
85
+ hasValue={ () => hasBorderWidthValue( props ) }
86
+ label={ __( 'Width' ) }
87
+ onDeselect={ () => resetBorderWidth( props ) }
88
+ isShownByDefault={ defaultBorderControls?.width }
89
+ resetAllFilter={ createResetAllFilter( 'width' ) }
90
+ panelId={ clientId }
91
+ >
92
+ <BorderWidthEdit { ...props } />
93
+ </ToolsPanelItem>
94
+ ) }
95
+ { isStyleSupported && (
96
+ <ToolsPanelItem
97
+ className="single-column"
98
+ hasValue={ () => hasBorderStyleValue( props ) }
99
+ label={ __( 'Style' ) }
100
+ onDeselect={ () => resetBorderStyle( props ) }
101
+ isShownByDefault={ defaultBorderControls?.style }
102
+ resetAllFilter={ createResetAllFilter( 'style' ) }
103
+ panelId={ clientId }
104
+ >
105
+ <BorderStyleEdit { ...props } />
106
+ </ToolsPanelItem>
107
+ ) }
108
+ { isColorSupported && (
109
+ <ToolsPanelItem
110
+ hasValue={ () => hasBorderColorValue( props ) }
111
+ label={ __( 'Color' ) }
112
+ onDeselect={ () => resetBorderColor( props ) }
113
+ isShownByDefault={ defaultBorderControls?.color }
114
+ resetAllFilter={ createResetAllFilter( 'color', {
115
+ borderColor: undefined,
116
+ } ) }
117
+ panelId={ clientId }
118
+ >
119
+ <BorderColorEdit { ...props } />
120
+ </ToolsPanelItem>
121
+ ) }
122
+ { isRadiusSupported && (
123
+ <ToolsPanelItem
124
+ hasValue={ () => hasBorderRadiusValue( props ) }
125
+ label={ __( 'Radius' ) }
126
+ onDeselect={ () => resetBorderRadius( props ) }
127
+ isShownByDefault={ defaultBorderControls?.radius }
128
+ resetAllFilter={ createResetAllFilter( 'radius' ) }
129
+ panelId={ clientId }
130
+ >
131
+ <BorderRadiusEdit { ...props } />
132
+ </ToolsPanelItem>
133
+ ) }
58
134
  </InspectorControls>
59
135
  );
60
136
  }
@@ -118,3 +194,22 @@ const useIsBorderDisabled = () => {
118
194
 
119
195
  return configs.every( Boolean );
120
196
  };
197
+
198
+ /**
199
+ * Returns a new style object where the specified border attribute has been
200
+ * removed.
201
+ *
202
+ * @param {Object} style Styles from block attributes.
203
+ * @param {string} attribute The border style attribute to clear.
204
+ *
205
+ * @return {Object} Style object with the specified attribute removed.
206
+ */
207
+ export function removeBorderAttribute( style, attribute ) {
208
+ return cleanEmptyObject( {
209
+ ...style,
210
+ border: {
211
+ ...style?.border,
212
+ [ attribute ]: undefined,
213
+ },
214
+ } );
215
+ }
@@ -1,19 +1,5 @@
1
- .block-editor-hooks__border-controls {
2
- .block-editor-hooks__border-controls-row {
3
- display: flex;
4
- justify-content: space-between;
5
-
6
- > * {
7
- width: calc(50% - #{ $grid-unit-10 });
8
- }
9
- }
10
-
11
- .components-unit-control-wrapper {
12
- margin-bottom: $grid-unit-30;
13
-
14
- &:last-child {
15
- margin-bottom: $grid-unit-10;
16
- }
1
+ .border-block-support-panel {
2
+ .single-column {
3
+ grid-column: span 1;
17
4
  }
18
5
  }
19
-
@@ -0,0 +1,5 @@
1
+ .dimensions-block-support-panel {
2
+ .single-column {
3
+ grid-column: span 1;
4
+ }
5
+ }
@@ -45,7 +45,7 @@ export function LetterSpacingEdit( props ) {
45
45
  <LetterSpacingControl
46
46
  value={ style?.typography?.letterSpacing }
47
47
  onChange={ onChange }
48
- __unstableInputWidth={ false }
48
+ __unstableInputWidth={ '100%' }
49
49
  />
50
50
  );
51
51
  }
@@ -218,7 +218,7 @@ export function TypographyPanel( props ) {
218
218
  <ToolsPanelItem
219
219
  className="single-column"
220
220
  hasValue={ () => hasLetterSpacingValue( props ) }
221
- label={ __( 'Letter-spacing' ) }
221
+ label={ __( 'Letter spacing' ) }
222
222
  onDeselect={ () => resetLetterSpacing( props ) }
223
223
  isShownByDefault={ defaultControls?.letterSpacing }
224
224
  resetAllFilter={ createResetAllFilter( 'letterSpacing' ) }
@@ -555,8 +555,7 @@ export const insertBlocks = (
555
555
  meta = initialPosition;
556
556
  initialPosition = 0;
557
557
  deprecated( "meta argument in wp.data.dispatch('core/block-editor')", {
558
- since: '10.1',
559
- plugin: 'Gutenberg',
558
+ since: '5.8',
560
559
  hint: 'The meta argument is now the 6th argument of the function',
561
560
  } );
562
561
  }
@@ -234,4 +234,6 @@ export const SETTINGS_DEFAULTS = {
234
234
  slug: 'midnight',
235
235
  },
236
236
  ],
237
+
238
+ __unstableResolvedAssets: { styles: [], scripts: [] },
237
239
  };
@@ -14,7 +14,6 @@ import {
14
14
  isEmpty,
15
15
  identity,
16
16
  omitBy,
17
- pickBy,
18
17
  } from 'lodash';
19
18
 
20
19
  /**
@@ -122,48 +121,6 @@ function getFlattenedBlockAttributes( blocks ) {
122
121
  return flattenBlocks( blocks, ( block ) => block.attributes );
123
122
  }
124
123
 
125
- /**
126
- * Given a block order map object, returns *all* of the block client IDs that are
127
- * a descendant of the given root client ID.
128
- *
129
- * Calling this with `rootClientId` set to `''` results in a list of client IDs
130
- * that are in the post. That is, it excludes blocks like fetched reusable
131
- * blocks which are stored into state but not visible. It also excludes
132
- * InnerBlocks controllers, like template parts.
133
- *
134
- * It is important to exclude the full inner block controller and not just the
135
- * inner blocks because in many cases, we need to persist the previous value of
136
- * an inner block controller. To do so, it must be excluded from the list of
137
- * client IDs which are considered to be part of the top-level entity.
138
- *
139
- * @param {Object} blocksOrder Object that maps block client IDs to a list of
140
- * nested block client IDs.
141
- * @param {?string} rootClientId The root client ID to search. Defaults to ''.
142
- * @param {?Object} controlledInnerBlocks The InnerBlocks controller state.
143
- *
144
- * @return {Array} List of descendant client IDs.
145
- */
146
- function getNestedBlockClientIds(
147
- blocksOrder,
148
- rootClientId = '',
149
- controlledInnerBlocks = {}
150
- ) {
151
- return reduce(
152
- blocksOrder[ rootClientId ],
153
- ( result, clientId ) => {
154
- if ( !! controlledInnerBlocks[ clientId ] ) {
155
- return result;
156
- }
157
- return [
158
- ...result,
159
- clientId,
160
- ...getNestedBlockClientIds( blocksOrder, clientId ),
161
- ];
162
- },
163
- []
164
- );
165
- }
166
-
167
124
  /**
168
125
  * Returns an object against which it is safe to perform mutating operations,
169
126
  * given the original object and its current working copy.
@@ -369,9 +326,14 @@ const withBlockTree = ( reducer ) => ( state = {}, action ) => {
369
326
  ...omit(
370
327
  newState.tree,
371
328
  action.replacedClientIds.concat(
372
- action.replacedClientIds.map(
373
- ( clientId ) => 'controlled||' + clientId
374
- )
329
+ // Controlled inner blocks are only removed
330
+ // if the block doesn't move to another position
331
+ // otherwise their content will be lost.
332
+ action.replacedClientIds
333
+ .filter( ( clientId ) => ! subTree[ clientId ] )
334
+ .map(
335
+ ( clientId ) => 'controlled||' + clientId
336
+ )
375
337
  )
376
338
  ),
377
339
  ...subTree,
@@ -637,70 +599,17 @@ const withInnerBlocksRemoveCascade = ( reducer ) => ( state, action ) => {
637
599
  */
638
600
  const withBlockReset = ( reducer ) => ( state, action ) => {
639
601
  if ( action.type === 'RESET_BLOCKS' ) {
640
- /**
641
- * A list of client IDs associated with the top level entity (like a
642
- * post or template). It excludes the client IDs of blocks associated
643
- * with other entities, like inner block controllers or reusable blocks.
644
- */
645
- const visibleClientIds = getNestedBlockClientIds(
646
- state?.order ?? {},
647
- '',
648
- state?.controlledInnerBlocks ?? {}
649
- );
650
-
651
- // pickBy returns only the truthy values from controlledInnerBlocks
652
- const controlledInnerBlocks = Object.keys(
653
- pickBy( state?.controlledInnerBlocks ?? {} )
654
- );
655
-
656
- /**
657
- * Each update operation consists of a few parts:
658
- * 1. First, the client IDs associated with the top level entity are
659
- * removed from the existing state key, leaving in place controlled
660
- * blocks (like reusable blocks and inner block controllers).
661
- * 2. Second, the blocks from the reset action are used to calculate the
662
- * individual state keys. This will re-populate the clientIDs which
663
- * were removed in step 1.
664
- * 3. In some cases, we remove the recalculated inner block controllers,
665
- * letting their old values persist. We need to do this because the
666
- * reset block action from a top-level entity is not aware of any
667
- * inner blocks inside InnerBlock controllers. So if the new values
668
- * were used, it would not take into account the existing InnerBlocks
669
- * which already exist in the state for inner block controllers. For
670
- * example, `attributes` uses the newly computed value for controllers
671
- * since attributes are stored in the top-level entity. But `order`
672
- * uses the previous value for the controllers since the new value
673
- * does not include the order of controlled inner blocks. So if the
674
- * new value was used, template parts would disappear from the editor
675
- * whenever you try to undo a change in the top level entity.
676
- */
677
602
  const newState = {
678
603
  ...state,
679
- byClientId: {
680
- ...omit( state?.byClientId, visibleClientIds ),
681
- ...getFlattenedBlocksWithoutAttributes( action.blocks ),
682
- },
683
- attributes: {
684
- ...omit( state?.attributes, visibleClientIds ),
685
- ...getFlattenedBlockAttributes( action.blocks ),
686
- },
687
- order: {
688
- ...omit( state?.order, visibleClientIds ),
689
- ...omit(
690
- mapBlockOrder( action.blocks ),
691
- controlledInnerBlocks
692
- ),
693
- },
694
- parents: {
695
- ...omit( state?.parents, visibleClientIds ),
696
- ...mapBlockParents( action.blocks ),
697
- },
698
- controlledInnerBlocks: state?.controlledInnerBlocks || {},
604
+ byClientId: getFlattenedBlocksWithoutAttributes( action.blocks ),
605
+ attributes: getFlattenedBlockAttributes( action.blocks ),
606
+ order: mapBlockOrder( action.blocks ),
607
+ parents: mapBlockParents( action.blocks ),
608
+ controlledInnerBlocks: {},
699
609
  };
700
610
 
701
611
  const subTree = buildBlockTree( newState, action.blocks );
702
612
  newState.tree = {
703
- ...omit( state?.tree, visibleClientIds ),
704
613
  ...subTree,
705
614
  // Root
706
615
  '': {
@@ -30,6 +30,7 @@ import {
30
30
  parse,
31
31
  } from '@wordpress/blocks';
32
32
  import { Platform } from '@wordpress/element';
33
+ import { applyFilters } from '@wordpress/hooks';
33
34
  import { symbol } from '@wordpress/icons';
34
35
 
35
36
  /**
@@ -826,6 +827,7 @@ export const isAncestorMultiSelected = createSelector(
826
827
  state.selection.selectionEnd.clientId,
827
828
  ]
828
829
  );
830
+
829
831
  /**
830
832
  * Returns the client ID of the block which begins the multi-selection set, or
831
833
  * null if there is no multi-selection.
@@ -1259,15 +1261,43 @@ const canInsertBlockTypeUnmemoized = (
1259
1261
  parentName
1260
1262
  );
1261
1263
 
1262
- if ( hasParentAllowedBlock !== null && hasBlockAllowedParent !== null ) {
1263
- return hasParentAllowedBlock || hasBlockAllowedParent;
1264
- } else if ( hasParentAllowedBlock !== null ) {
1265
- return hasParentAllowedBlock;
1266
- } else if ( hasBlockAllowedParent !== null ) {
1267
- return hasBlockAllowedParent;
1264
+ const canInsert =
1265
+ ( hasParentAllowedBlock === null && hasBlockAllowedParent === null ) ||
1266
+ hasParentAllowedBlock === true ||
1267
+ hasBlockAllowedParent === true;
1268
+
1269
+ if ( ! canInsert ) {
1270
+ return canInsert;
1268
1271
  }
1269
1272
 
1270
- return true;
1273
+ /**
1274
+ * This filter is an ad-hoc solution to prevent adding template parts inside post content.
1275
+ * Conceptually, having a filter inside a selector is bad pattern so this code will be
1276
+ * replaced by a declarative API that doesn't the following drawbacks:
1277
+ *
1278
+ * Filters are not reactive: Upon switching between "template mode" and non "template mode",
1279
+ * the filter and selector won't necessarily be executed again. For now, it doesn't matter much
1280
+ * because you can't switch between the two modes while the inserter stays open.
1281
+ *
1282
+ * Filters are global: Once they're defined, they will affect all editor instances and all registries.
1283
+ * An ideal API would only affect specific editor instances.
1284
+ */
1285
+ return applyFilters(
1286
+ 'blockEditor.__unstableCanInsertBlockType',
1287
+ canInsert,
1288
+ blockType,
1289
+ rootClientId,
1290
+ {
1291
+ // Pass bound selectors of the current registry. If we're in a nested
1292
+ // context, the data will differ from the one selected from the root
1293
+ // registry.
1294
+ getBlock: getBlock.bind( null, state ),
1295
+ getBlockParentsByBlockName: getBlockParentsByBlockName.bind(
1296
+ null,
1297
+ state
1298
+ ),
1299
+ }
1300
+ );
1271
1301
  };
1272
1302
 
1273
1303
  /**
package/src/style.scss CHANGED
@@ -32,12 +32,12 @@
32
32
  @import "./components/default-block-appender/style.scss";
33
33
  @import "./components/duotone-control/style.scss";
34
34
  @import "./components/font-appearance-control/style.scss";
35
- @import "./components/justify-content-control/style.scss";
36
- @import "./components/link-control/style.scss";
37
- @import "./components/line-height-control/style.scss";
38
35
  @import "./components/image-size-control/style.scss";
39
36
  @import "./components/inner-blocks/style.scss";
40
37
  @import "./components/inserter-list-item/style.scss";
38
+ @import "./components/justify-content-control/style.scss";
39
+ @import "./components/line-height-control/style.scss";
40
+ @import "./components/link-control/style.scss";
41
41
  @import "./components/list-view/style.scss";
42
42
  @import "./components/media-replace-flow/style.scss";
43
43
  @import "./components/media-placeholder/style.scss";
@@ -55,6 +55,7 @@
55
55
  @import "./hooks/anchor.scss";
56
56
  @import "./hooks/layout.scss";
57
57
  @import "./hooks/border.scss";
58
+ @import "./hooks/dimensions.scss";
58
59
  @import "./hooks/typography.scss";
59
60
 
60
61
  @import "./components/block-toolbar/style.scss";
@@ -27,7 +27,7 @@ export function getPasteEventData( { clipboardData } ) {
27
27
 
28
28
  const files = getFilesFromDataTransfer(
29
29
  clipboardData
30
- ).filter( ( { type } ) => /^image\/(?:jpe?g|png|gif)$/.test( type ) );
30
+ ).filter( ( { type } ) => /^image\/(?:jpe?g|png|gif|webp)$/.test( type ) );
31
31
 
32
32
  // Only process files if no HTML is present.
33
33
  // A pasted file may have the URL as plain text.
@@ -8,7 +8,7 @@ function parseUnit( cssUnit ) {
8
8
  const match = cssUnit
9
9
  ?.trim()
10
10
  .match(
11
- /^(0?[-.]?\d+)(r?e[m|x]|v[h|w|min|max]+|p[x|t|c]|[c|m]m|%|in|ch|Q|lh)$/
11
+ /^(0?[-.]?\d*\.?\d+)(r?e[m|x]|v[h|w|min|max]+|p[x|t|c]|[c|m]m|%|in|ch|Q|lh)$/
12
12
  );
13
13
  if ( ! isNaN( cssUnit ) && ! isNaN( parseFloat( cssUnit ) ) ) {
14
14
  return { value: parseFloat( cssUnit ), unit: 'px' };
@@ -52,6 +52,7 @@ describe( 'getPxFromCssUnit', () => {
52
52
  const testData = [
53
53
  [ '2em', '20px' ],
54
54
  [ '2rem', '20px' ],
55
+ [ '1.125rem', '11px' ],
55
56
  [ '20vw', '20px' ],
56
57
  [ '20vh', '40px' ],
57
58
  [ '20vmin', '20px' ],
@@ -23,23 +23,20 @@ import wrap from './transforms/wrap';
23
23
  * @return {Array} converted rules.
24
24
  */
25
25
  const transformStyles = ( styles, wrapperClassName = '' ) => {
26
- return map(
27
- styles,
28
- ( { css, baseURL, __experimentalNoWrapper = false } ) => {
29
- const transforms = [];
30
- if ( wrapperClassName && ! __experimentalNoWrapper ) {
31
- transforms.push( wrap( wrapperClassName ) );
32
- }
33
- if ( baseURL ) {
34
- transforms.push( urlRewrite( baseURL ) );
35
- }
36
- if ( transforms.length ) {
37
- return traverse( css, compose( transforms ) );
38
- }
39
-
40
- return css;
26
+ return map( styles, ( { css, baseURL } ) => {
27
+ const transforms = [];
28
+ if ( wrapperClassName ) {
29
+ transforms.push( wrap( wrapperClassName ) );
30
+ }
31
+ if ( baseURL ) {
32
+ transforms.push( urlRewrite( baseURL ) );
41
33
  }
42
- );
34
+ if ( transforms.length ) {
35
+ return traverse( css, compose( transforms ) );
36
+ }
37
+
38
+ return css;
39
+ } );
43
40
  };
44
41
 
45
42
  export default transformStyles;