@wordpress/block-editor 13.4.0 → 14.0.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 (331) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +11 -1
  3. package/build/components/block-breadcrumb/index.js +3 -1
  4. package/build/components/block-breadcrumb/index.js.map +1 -1
  5. package/build/components/block-draggable/index.js +2 -2
  6. package/build/components/block-draggable/index.js.map +1 -1
  7. package/build/components/block-list/use-block-props/use-block-refs.js +24 -32
  8. package/build/components/block-list/use-block-props/use-block-refs.js.map +1 -1
  9. package/build/components/block-mover/index.js +1 -2
  10. package/build/components/block-mover/index.js.map +1 -1
  11. package/build/components/block-popover/cover.js +1 -1
  12. package/build/components/block-popover/cover.js.map +1 -1
  13. package/build/components/block-popover/inbetween.js +2 -2
  14. package/build/components/block-popover/inbetween.js.map +1 -1
  15. package/build/components/block-popover/index.js +2 -2
  16. package/build/components/block-popover/index.js.map +1 -1
  17. package/build/components/block-tools/block-selection-button.js +1 -2
  18. package/build/components/block-tools/block-selection-button.js.map +1 -1
  19. package/build/components/block-tools/index.js +1 -1
  20. package/build/components/block-tools/index.js.map +1 -1
  21. package/build/components/block-tools/use-block-toolbar-popover-props.js +1 -1
  22. package/build/components/block-tools/use-block-toolbar-popover-props.js.map +1 -1
  23. package/build/components/block-tools/zoom-out-mode-inserters.js +15 -16
  24. package/build/components/block-tools/zoom-out-mode-inserters.js.map +1 -1
  25. package/build/components/block-tools/zoom-out-toolbar.js +0 -1
  26. package/build/components/block-tools/zoom-out-toolbar.js.map +1 -1
  27. package/build/components/child-layout-control/index.js +3 -1
  28. package/build/components/child-layout-control/index.js.map +1 -1
  29. package/build/components/dimensions-tool/scale-tool.js +1 -0
  30. package/build/components/dimensions-tool/scale-tool.js.map +1 -1
  31. package/build/components/font-family/index.js +12 -0
  32. package/build/components/font-family/index.js.map +1 -1
  33. package/build/components/global-styles/background-panel.js +55 -51
  34. package/build/components/global-styles/background-panel.js.map +1 -1
  35. package/build/components/global-styles/image-settings-panel.js +1 -0
  36. package/build/components/global-styles/image-settings-panel.js.map +1 -1
  37. package/build/components/global-styles/theme-file-uri-utils.js +0 -59
  38. package/build/components/global-styles/theme-file-uri-utils.js.map +1 -1
  39. package/build/components/global-styles/typography-panel.js +0 -1
  40. package/build/components/global-styles/typography-panel.js.map +1 -1
  41. package/build/components/global-styles/use-global-styles-output.js +58 -39
  42. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  43. package/build/components/global-styles/utils.js +96 -0
  44. package/build/components/global-styles/utils.js.map +1 -1
  45. package/build/components/grid/grid-item-movers.js +30 -26
  46. package/build/components/grid/grid-item-movers.js.map +1 -1
  47. package/build/components/grid/grid-item-resizer.js +14 -15
  48. package/build/components/grid/grid-item-resizer.js.map +1 -1
  49. package/build/components/grid/grid-visualizer.js +1 -1
  50. package/build/components/grid/grid-visualizer.js.map +1 -1
  51. package/build/components/grid/use-grid-layout-sync.js +56 -20
  52. package/build/components/grid/use-grid-layout-sync.js.map +1 -1
  53. package/build/components/iframe/index.js +4 -8
  54. package/build/components/iframe/index.js.map +1 -1
  55. package/build/components/inserter/category-tabs/index.js +29 -2
  56. package/build/components/inserter/category-tabs/index.js.map +1 -1
  57. package/build/components/inserter/menu.js +2 -2
  58. package/build/components/inserter/menu.js.map +1 -1
  59. package/build/components/line-height-control/index.js +0 -15
  60. package/build/components/line-height-control/index.js.map +1 -1
  61. package/build/components/link-control/search-input.js +0 -1
  62. package/build/components/link-control/search-input.js.map +1 -1
  63. package/build/components/media-replace-flow/index.js +3 -1
  64. package/build/components/media-replace-flow/index.js.map +1 -1
  65. package/build/components/resolution-tool/index.js +1 -0
  66. package/build/components/resolution-tool/index.js.map +1 -1
  67. package/build/components/skip-to-selected-block/index.js +4 -2
  68. package/build/components/skip-to-selected-block/index.js.map +1 -1
  69. package/build/components/spacing-sizes-control/input-controls/spacing-input-control.js +4 -6
  70. package/build/components/spacing-sizes-control/input-controls/spacing-input-control.js.map +1 -1
  71. package/build/components/url-input/button.js +0 -1
  72. package/build/components/url-input/button.js.map +1 -1
  73. package/build/components/url-input/index.js +1 -11
  74. package/build/components/url-input/index.js.map +1 -1
  75. package/build/components/url-popover/link-editor.js +0 -1
  76. package/build/components/url-popover/link-editor.js.map +1 -1
  77. package/build/components/use-block-drop-zone/index.js +30 -4
  78. package/build/components/use-block-drop-zone/index.js.map +1 -1
  79. package/build/components/use-on-block-drop/index.js +3 -6
  80. package/build/components/use-on-block-drop/index.js.map +1 -1
  81. package/build/components/use-resize-canvas/index.js +1 -3
  82. package/build/components/use-resize-canvas/index.js.map +1 -1
  83. package/build/components/use-settings/index.js +2 -1
  84. package/build/components/use-settings/index.js.map +1 -1
  85. package/build/hooks/block-bindings.js +248 -36
  86. package/build/hooks/block-bindings.js.map +1 -1
  87. package/build/hooks/block-hooks.js +1 -0
  88. package/build/hooks/block-hooks.js.map +1 -1
  89. package/build/hooks/block-style-variation.js +2 -2
  90. package/build/hooks/block-style-variation.js.map +1 -1
  91. package/build/hooks/contrast-checker.js +6 -6
  92. package/build/hooks/contrast-checker.js.map +1 -1
  93. package/build/hooks/duotone.js +3 -3
  94. package/build/hooks/duotone.js.map +1 -1
  95. package/build/hooks/index.js +7 -1
  96. package/build/hooks/index.js.map +1 -1
  97. package/build/hooks/line-height.js +0 -1
  98. package/build/hooks/line-height.js.map +1 -1
  99. package/build/hooks/spacing-visualizer.js +1 -1
  100. package/build/hooks/spacing-visualizer.js.map +1 -1
  101. package/build/hooks/use-bindings-attributes.js +4 -0
  102. package/build/hooks/use-bindings-attributes.js.map +1 -1
  103. package/build/hooks/use-zoom-out.js +1 -1
  104. package/build/hooks/use-zoom-out.js.map +1 -1
  105. package/build/hooks/utils.js +20 -0
  106. package/build/hooks/utils.js.map +1 -1
  107. package/build/index.js +7 -0
  108. package/build/index.js.map +1 -1
  109. package/build/private-apis.js +0 -1
  110. package/build/private-apis.js.map +1 -1
  111. package/build/store/actions.js +9 -1
  112. package/build/store/actions.js.map +1 -1
  113. package/build/store/selectors.js +4 -4
  114. package/build/store/selectors.js.map +1 -1
  115. package/build/utils/get-editor-region.js +1 -1
  116. package/build/utils/get-editor-region.js.map +1 -1
  117. package/build/utils/get-px-from-css-unit.js +1 -1
  118. package/build/utils/get-px-from-css-unit.js.map +1 -1
  119. package/build-module/components/block-breadcrumb/index.js +4 -2
  120. package/build-module/components/block-breadcrumb/index.js.map +1 -1
  121. package/build-module/components/block-draggable/index.js +3 -3
  122. package/build-module/components/block-draggable/index.js.map +1 -1
  123. package/build-module/components/block-list/use-block-props/use-block-refs.js +24 -34
  124. package/build-module/components/block-list/use-block-props/use-block-refs.js.map +1 -1
  125. package/build-module/components/block-mover/index.js +1 -2
  126. package/build-module/components/block-mover/index.js.map +1 -1
  127. package/build-module/components/block-popover/cover.js +1 -1
  128. package/build-module/components/block-popover/cover.js.map +1 -1
  129. package/build-module/components/block-popover/inbetween.js +1 -1
  130. package/build-module/components/block-popover/inbetween.js.map +1 -1
  131. package/build-module/components/block-popover/index.js +1 -1
  132. package/build-module/components/block-popover/index.js.map +1 -1
  133. package/build-module/components/block-tools/block-selection-button.js +1 -2
  134. package/build-module/components/block-tools/block-selection-button.js.map +1 -1
  135. package/build-module/components/block-tools/index.js +1 -1
  136. package/build-module/components/block-tools/index.js.map +1 -1
  137. package/build-module/components/block-tools/use-block-toolbar-popover-props.js +1 -1
  138. package/build-module/components/block-tools/use-block-toolbar-popover-props.js.map +1 -1
  139. package/build-module/components/block-tools/zoom-out-mode-inserters.js +16 -17
  140. package/build-module/components/block-tools/zoom-out-mode-inserters.js.map +1 -1
  141. package/build-module/components/block-tools/zoom-out-toolbar.js +0 -1
  142. package/build-module/components/block-tools/zoom-out-toolbar.js.map +1 -1
  143. package/build-module/components/child-layout-control/index.js +3 -1
  144. package/build-module/components/child-layout-control/index.js.map +1 -1
  145. package/build-module/components/dimensions-tool/scale-tool.js +1 -0
  146. package/build-module/components/dimensions-tool/scale-tool.js.map +1 -1
  147. package/build-module/components/font-family/index.js +11 -0
  148. package/build-module/components/font-family/index.js.map +1 -1
  149. package/build-module/components/global-styles/background-panel.js +55 -51
  150. package/build-module/components/global-styles/background-panel.js.map +1 -1
  151. package/build-module/components/global-styles/image-settings-panel.js +1 -0
  152. package/build-module/components/global-styles/image-settings-panel.js.map +1 -1
  153. package/build-module/components/global-styles/theme-file-uri-utils.js +0 -58
  154. package/build-module/components/global-styles/theme-file-uri-utils.js.map +1 -1
  155. package/build-module/components/global-styles/typography-panel.js +0 -1
  156. package/build-module/components/global-styles/typography-panel.js.map +1 -1
  157. package/build-module/components/global-styles/use-global-styles-output.js +57 -38
  158. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  159. package/build-module/components/global-styles/utils.js +92 -0
  160. package/build-module/components/global-styles/utils.js.map +1 -1
  161. package/build-module/components/grid/grid-item-movers.js +30 -26
  162. package/build-module/components/grid/grid-item-movers.js.map +1 -1
  163. package/build-module/components/grid/grid-item-resizer.js +14 -15
  164. package/build-module/components/grid/grid-item-resizer.js.map +1 -1
  165. package/build-module/components/grid/grid-visualizer.js +1 -1
  166. package/build-module/components/grid/grid-visualizer.js.map +1 -1
  167. package/build-module/components/grid/use-grid-layout-sync.js +56 -20
  168. package/build-module/components/grid/use-grid-layout-sync.js.map +1 -1
  169. package/build-module/components/iframe/index.js +4 -8
  170. package/build-module/components/iframe/index.js.map +1 -1
  171. package/build-module/components/inserter/category-tabs/index.js +30 -3
  172. package/build-module/components/inserter/category-tabs/index.js.map +1 -1
  173. package/build-module/components/inserter/menu.js +2 -2
  174. package/build-module/components/inserter/menu.js.map +1 -1
  175. package/build-module/components/line-height-control/index.js +0 -14
  176. package/build-module/components/line-height-control/index.js.map +1 -1
  177. package/build-module/components/link-control/search-input.js +0 -1
  178. package/build-module/components/link-control/search-input.js.map +1 -1
  179. package/build-module/components/media-replace-flow/index.js +3 -1
  180. package/build-module/components/media-replace-flow/index.js.map +1 -1
  181. package/build-module/components/resolution-tool/index.js +1 -0
  182. package/build-module/components/resolution-tool/index.js.map +1 -1
  183. package/build-module/components/skip-to-selected-block/index.js +5 -3
  184. package/build-module/components/skip-to-selected-block/index.js.map +1 -1
  185. package/build-module/components/spacing-sizes-control/input-controls/spacing-input-control.js +4 -6
  186. package/build-module/components/spacing-sizes-control/input-controls/spacing-input-control.js.map +1 -1
  187. package/build-module/components/url-input/button.js +0 -1
  188. package/build-module/components/url-input/button.js.map +1 -1
  189. package/build-module/components/url-input/index.js +1 -11
  190. package/build-module/components/url-input/index.js.map +1 -1
  191. package/build-module/components/url-popover/link-editor.js +0 -1
  192. package/build-module/components/url-popover/link-editor.js.map +1 -1
  193. package/build-module/components/use-block-drop-zone/index.js +30 -4
  194. package/build-module/components/use-block-drop-zone/index.js.map +1 -1
  195. package/build-module/components/use-on-block-drop/index.js +3 -6
  196. package/build-module/components/use-on-block-drop/index.js.map +1 -1
  197. package/build-module/components/use-resize-canvas/index.js +1 -3
  198. package/build-module/components/use-resize-canvas/index.js.map +1 -1
  199. package/build-module/components/use-settings/index.js +2 -1
  200. package/build-module/components/use-settings/index.js.map +1 -1
  201. package/build-module/hooks/block-bindings.js +253 -40
  202. package/build-module/hooks/block-bindings.js.map +1 -1
  203. package/build-module/hooks/block-hooks.js +1 -0
  204. package/build-module/hooks/block-hooks.js.map +1 -1
  205. package/build-module/hooks/block-style-variation.js +3 -3
  206. package/build-module/hooks/block-style-variation.js.map +1 -1
  207. package/build-module/hooks/contrast-checker.js +7 -7
  208. package/build-module/hooks/contrast-checker.js.map +1 -1
  209. package/build-module/hooks/duotone.js +4 -4
  210. package/build-module/hooks/duotone.js.map +1 -1
  211. package/build-module/hooks/index.js +2 -1
  212. package/build-module/hooks/index.js.map +1 -1
  213. package/build-module/hooks/line-height.js +0 -1
  214. package/build-module/hooks/line-height.js.map +1 -1
  215. package/build-module/hooks/spacing-visualizer.js +1 -1
  216. package/build-module/hooks/spacing-visualizer.js.map +1 -1
  217. package/build-module/hooks/use-bindings-attributes.js +3 -0
  218. package/build-module/hooks/use-bindings-attributes.js.map +1 -1
  219. package/build-module/hooks/use-zoom-out.js +1 -1
  220. package/build-module/hooks/use-zoom-out.js.map +1 -1
  221. package/build-module/hooks/utils.js +19 -0
  222. package/build-module/hooks/utils.js.map +1 -1
  223. package/build-module/index.js +1 -1
  224. package/build-module/index.js.map +1 -1
  225. package/build-module/private-apis.js +1 -2
  226. package/build-module/private-apis.js.map +1 -1
  227. package/build-module/store/actions.js +9 -1
  228. package/build-module/store/actions.js.map +1 -1
  229. package/build-module/store/selectors.js +4 -4
  230. package/build-module/store/selectors.js.map +1 -1
  231. package/build-module/utils/get-editor-region.js +1 -1
  232. package/build-module/utils/get-editor-region.js.map +1 -1
  233. package/build-module/utils/get-px-from-css-unit.js +1 -1
  234. package/build-module/utils/get-px-from-css-unit.js.map +1 -1
  235. package/build-style/content-rtl.css +5 -12
  236. package/build-style/content.css +5 -12
  237. package/build-style/default-editor-styles-rtl.css +3 -0
  238. package/build-style/default-editor-styles.css +3 -0
  239. package/build-style/style-rtl.css +88 -46
  240. package/build-style/style.css +88 -46
  241. package/package.json +31 -31
  242. package/src/autocompleters/style.scss +4 -0
  243. package/src/components/block-breadcrumb/index.js +4 -2
  244. package/src/components/block-canvas/style.scss +1 -0
  245. package/src/components/block-draggable/index.js +3 -3
  246. package/src/components/block-list/use-block-props/use-block-refs.js +27 -43
  247. package/src/components/block-mover/index.js +5 -2
  248. package/src/components/block-popover/cover.js +1 -1
  249. package/src/components/block-popover/inbetween.js +1 -1
  250. package/src/components/block-popover/index.js +1 -1
  251. package/src/components/block-tools/block-selection-button.js +1 -2
  252. package/src/components/block-tools/index.js +5 -6
  253. package/src/components/block-tools/use-block-toolbar-popover-props.js +1 -1
  254. package/src/components/block-tools/zoom-out-mode-inserters.js +14 -18
  255. package/src/components/block-tools/zoom-out-toolbar.js +0 -1
  256. package/src/components/button-block-appender/content.scss +1 -1
  257. package/src/components/child-layout-control/index.js +2 -0
  258. package/src/components/color-palette/test/__snapshots__/control.js.snap +2 -2
  259. package/src/components/colors-gradients/test/control.js +3 -2
  260. package/src/components/dimensions-tool/scale-tool.js +1 -0
  261. package/src/components/font-family/README.md +8 -0
  262. package/src/components/font-family/index.js +16 -0
  263. package/src/components/font-family/stories/index.story.js +54 -0
  264. package/src/components/global-styles/background-panel.js +69 -61
  265. package/src/components/global-styles/image-settings-panel.js +1 -0
  266. package/src/components/global-styles/style.scss +0 -10
  267. package/src/components/global-styles/test/theme-file-uri-utils.js +1 -26
  268. package/src/components/global-styles/test/use-global-styles-output.js +49 -4
  269. package/src/components/global-styles/test/utils.js +120 -0
  270. package/src/components/global-styles/theme-file-uri-utils.js +0 -59
  271. package/src/components/global-styles/typography-panel.js +0 -1
  272. package/src/components/global-styles/use-global-styles-output.js +67 -48
  273. package/src/components/global-styles/utils.js +112 -0
  274. package/src/components/grid/grid-item-movers.js +46 -44
  275. package/src/components/grid/grid-item-resizer.js +11 -17
  276. package/src/components/grid/grid-visualizer.js +1 -1
  277. package/src/components/grid/style.scss +60 -10
  278. package/src/components/grid/use-grid-layout-sync.js +68 -14
  279. package/src/components/iframe/content.scss +2 -2
  280. package/src/components/iframe/index.js +3 -7
  281. package/src/components/inserter/category-tabs/index.js +35 -2
  282. package/src/components/inserter/menu.js +2 -2
  283. package/src/components/inserter/style.scss +16 -11
  284. package/src/components/inspector-controls/README.md +5 -0
  285. package/src/components/line-height-control/README.md +0 -8
  286. package/src/components/line-height-control/index.js +1 -21
  287. package/src/components/line-height-control/stories/index.story.js +0 -1
  288. package/src/components/line-height-control/test/index.js +1 -7
  289. package/src/components/link-control/search-input.js +0 -1
  290. package/src/components/media-replace-flow/README.md +7 -0
  291. package/src/components/media-replace-flow/index.js +3 -1
  292. package/src/components/resolution-tool/index.js +1 -0
  293. package/src/components/responsive-block-control/test/index.js +5 -1
  294. package/src/components/skip-to-selected-block/index.js +5 -3
  295. package/src/components/spacing-sizes-control/input-controls/spacing-input-control.js +3 -6
  296. package/src/components/tabbed-sidebar/style.scss +1 -19
  297. package/src/components/url-input/README.md +0 -5
  298. package/src/components/url-input/button.js +0 -1
  299. package/src/components/url-input/index.js +1 -15
  300. package/src/components/url-popover/link-editor.js +0 -1
  301. package/src/components/use-block-drop-zone/index.js +66 -14
  302. package/src/components/use-on-block-drop/index.js +1 -9
  303. package/src/components/use-resize-canvas/index.js +1 -3
  304. package/src/components/use-settings/index.js +2 -1
  305. package/src/hooks/block-bindings.js +303 -52
  306. package/src/hooks/block-bindings.scss +13 -2
  307. package/src/hooks/block-hooks.js +1 -0
  308. package/src/hooks/block-hooks.scss +1 -0
  309. package/src/hooks/block-style-variation.js +3 -3
  310. package/src/hooks/contrast-checker.js +7 -7
  311. package/src/hooks/duotone.js +4 -4
  312. package/src/hooks/index.js +2 -1
  313. package/src/hooks/line-height.js +0 -1
  314. package/src/hooks/spacing-visualizer.js +1 -1
  315. package/src/hooks/use-bindings-attributes.js +4 -0
  316. package/src/hooks/use-editor-wrapper-styles.native.scss +1 -0
  317. package/src/hooks/use-zoom-out.js +1 -1
  318. package/src/hooks/utils.js +14 -1
  319. package/src/index.js +1 -0
  320. package/src/private-apis.js +1 -2
  321. package/src/store/actions.js +13 -5
  322. package/src/store/selectors.js +4 -4
  323. package/src/style.scss +1 -1
  324. package/src/utils/get-editor-region.js +1 -1
  325. package/src/utils/get-px-from-css-unit.js +1 -1
  326. package/tsconfig.tsbuildinfo +1 -1
  327. package/build/components/inserter/block-patterns-tab/pattern-category-preview-panel.js +0 -30
  328. package/build/components/inserter/block-patterns-tab/pattern-category-preview-panel.js.map +0 -1
  329. package/build-module/components/inserter/block-patterns-tab/pattern-category-preview-panel.js +0 -23
  330. package/build-module/components/inserter/block-patterns-tab/pattern-category-preview-panel.js.map +0 -1
  331. package/src/components/inserter/block-patterns-tab/pattern-category-preview-panel.js +0 -25
@@ -318,8 +318,12 @@ function BackgroundImageControls( {
318
318
  return;
319
319
  }
320
320
 
321
- const sizeValue = style?.background?.backgroundSize;
322
- const positionValue = style?.background?.backgroundPosition;
321
+ const sizeValue =
322
+ style?.background?.backgroundSize ||
323
+ inheritedValue?.background?.backgroundSize;
324
+ const positionValue =
325
+ style?.background?.backgroundPosition ||
326
+ inheritedValue?.background?.backgroundPosition;
323
327
 
324
328
  onChange(
325
329
  setImmutably( style, [ 'background' ], {
@@ -334,6 +338,7 @@ function BackgroundImageControls( {
334
338
  ! positionValue && ( 'auto' === sizeValue || ! sizeValue )
335
339
  ? '50% 0'
336
340
  : positionValue,
341
+ backgroundSize: sizeValue,
337
342
  } )
338
343
  );
339
344
  };
@@ -448,6 +453,9 @@ function BackgroundSizeControls( {
448
453
  const imageValue =
449
454
  style?.background?.backgroundImage?.url ||
450
455
  inheritedValue?.background?.backgroundImage?.url;
456
+ const isUploadedImage =
457
+ style?.background?.backgroundImage?.id ||
458
+ inheritedValue?.background?.backgroundImage?.id;
451
459
  const positionValue =
452
460
  style?.background?.backgroundPosition ||
453
461
  inheritedValue?.background?.backgroundPosition;
@@ -456,19 +464,15 @@ function BackgroundSizeControls( {
456
464
  inheritedValue?.background?.backgroundAttachment;
457
465
 
458
466
  /*
459
- * An `undefined` value is replaced with any supplied
460
- * default control value for the toggle group control.
461
- * An empty string is treated as `auto` - this allows a user
462
- * to select "Size" and then enter a custom value, with an
463
- * empty value being treated as `auto`.
467
+ * Set default values for uploaded images.
468
+ * The default values are passed by the consumer.
469
+ * Block-level controls may have different defaults to root-level controls.
470
+ * A falsy value is treated by default as `auto` (Tile).
464
471
  */
465
472
  const currentValueForToggle =
466
- ( sizeValue !== undefined &&
467
- sizeValue !== 'cover' &&
468
- sizeValue !== 'contain' ) ||
469
- sizeValue === ''
470
- ? 'auto'
471
- : sizeValue || defaultValues?.backgroundSize;
473
+ ! sizeValue && isUploadedImage
474
+ ? defaultValues?.backgroundSize
475
+ : sizeValue || 'auto';
472
476
 
473
477
  /*
474
478
  * If the current value is `cover` and the repeat value is `undefined`, then
@@ -569,6 +573,7 @@ function BackgroundSizeControls( {
569
573
  onChange={ updateBackgroundPosition }
570
574
  />
571
575
  <ToggleControl
576
+ __nextHasNoMarginBottom
572
577
  label={ __( 'Fixed background' ) }
573
578
  checked={ attachmentValue === 'fixed' }
574
579
  onChange={ toggleScrollWithPage }
@@ -577,6 +582,7 @@ function BackgroundSizeControls( {
577
582
  ) }
578
583
  />
579
584
  <ToggleGroupControl
585
+ __nextHasNoMarginBottom
580
586
  size="__unstable-large"
581
587
  label={ __( 'Size' ) }
582
588
  value={ currentValueForToggle }
@@ -626,6 +632,7 @@ function BackgroundSizeControls( {
626
632
  }
627
633
  />
628
634
  <ToggleControl
635
+ __nextHasNoMarginBottom
629
636
  label={ __( 'Repeat' ) }
630
637
  checked={ repeatCheckedValue }
631
638
  onChange={ toggleIsRepeated }
@@ -717,55 +724,56 @@ export default function BackgroundPanel( {
717
724
  }
718
725
  ) }
719
726
  >
720
- { shouldShowBackgroundImageControls ? (
721
- <BackgroundControlsPanel
722
- label={ title }
723
- filename={ title }
724
- url={ getResolvedThemeFilePath( url, themeFileURIs ) }
725
- onToggle={ setIsDropDownOpen }
726
- hasImageValue={ hasImageValue }
727
- >
728
- <VStack spacing={ 3 } className="single-column">
729
- <BackgroundImageControls
730
- onChange={ onChange }
731
- style={ value }
732
- inheritedValue={ inheritedValue }
733
- themeFileURIs={ themeFileURIs }
734
- displayInPanel
735
- onRemoveImage={ () => {
736
- setIsDropDownOpen( false );
737
- resetBackground();
738
- } }
739
- />
740
- <BackgroundSizeControls
741
- onChange={ onChange }
742
- panelId={ panelId }
743
- style={ value }
744
- defaultValues={ defaultValues }
745
- inheritedValue={ inheritedValue }
746
- themeFileURIs={ themeFileURIs }
747
- />
748
- </VStack>
749
- </BackgroundControlsPanel>
750
- ) : (
751
- <BackgroundImageControls
752
- onChange={ onChange }
753
- style={ value }
754
- inheritedValue={ inheritedValue }
755
- themeFileURIs={ themeFileURIs }
756
- />
757
- ) }
727
+ <ToolsPanelItem
728
+ hasValue={ () => hasImageValue }
729
+ label={ __( 'Image' ) }
730
+ onDeselect={ resetBackground }
731
+ isShownByDefault={ defaultControls.backgroundImage }
732
+ panelId={ panelId }
733
+ >
734
+ { shouldShowBackgroundImageControls ? (
735
+ <BackgroundControlsPanel
736
+ label={ title }
737
+ filename={ title }
738
+ url={ getResolvedThemeFilePath(
739
+ url,
740
+ themeFileURIs
741
+ ) }
742
+ onToggle={ setIsDropDownOpen }
743
+ hasImageValue={ hasImageValue }
744
+ >
745
+ <VStack spacing={ 3 } className="single-column">
746
+ <BackgroundImageControls
747
+ onChange={ onChange }
748
+ style={ value }
749
+ inheritedValue={ inheritedValue }
750
+ themeFileURIs={ themeFileURIs }
751
+ displayInPanel
752
+ onRemoveImage={ () => {
753
+ setIsDropDownOpen( false );
754
+ resetBackground();
755
+ } }
756
+ />
757
+ <BackgroundSizeControls
758
+ onChange={ onChange }
759
+ panelId={ panelId }
760
+ style={ value }
761
+ defaultValues={ defaultValues }
762
+ inheritedValue={ inheritedValue }
763
+ themeFileURIs={ themeFileURIs }
764
+ />
765
+ </VStack>
766
+ </BackgroundControlsPanel>
767
+ ) : (
768
+ <BackgroundImageControls
769
+ onChange={ onChange }
770
+ style={ value }
771
+ inheritedValue={ inheritedValue }
772
+ themeFileURIs={ themeFileURIs }
773
+ />
774
+ ) }
775
+ </ToolsPanelItem>
758
776
  </div>
759
-
760
- { /* Dummy ToolsPanel items, so we can control what's in the dropdown popover */ }
761
- <ToolsPanelItem
762
- hasValue={ () => hasImageValue }
763
- label={ __( 'Image' ) }
764
- onDeselect={ resetBackground }
765
- isShownByDefault={ defaultControls.backgroundImage }
766
- panelId={ panelId }
767
- className="block-editor-global-styles-background-panel__hidden-tools-panel-item"
768
- />
769
777
  </Wrapper>
770
778
  );
771
779
  }
@@ -67,6 +67,7 @@ export default function ImageSettingsPanel( {
67
67
  panelId={ panelId }
68
68
  >
69
69
  <ToggleControl
70
+ __nextHasNoMarginBottom
70
71
  label={ __( 'Expand on click' ) }
71
72
  checked={ lightboxChecked }
72
73
  onChange={ onChangeLightbox }
@@ -193,10 +193,6 @@
193
193
  .block-editor-global-styles-background-panel__dropdown-content-wrapper {
194
194
  min-width: 260px;
195
195
  overflow-x: hidden;
196
- .components-base-control__help,
197
- .components-toggle-control {
198
- margin-bottom: 0;
199
- }
200
196
 
201
197
  .components-focal-point-picker-wrapper {
202
198
  background-color: $gray-100;
@@ -215,12 +211,6 @@
215
211
  }
216
212
  }
217
213
 
218
- .block-editor-global-styles-background-panel__hidden-tools-panel-item {
219
- height: 0;
220
- width: 0;
221
- position: absolute;
222
- }
223
-
224
214
  // Push control panel into the background when the media modal is open.
225
215
  .modal-open .block-editor-global-styles-background-panel__popover {
226
216
  z-index: z-index(".block-editor-global-styles-background-panel__popover");
@@ -1,10 +1,7 @@
1
1
  /**
2
2
  * Internal dependencies
3
3
  */
4
- import {
5
- setThemeFileUris,
6
- getResolvedThemeFilePath,
7
- } from '../theme-file-uri-utils';
4
+ import { getResolvedThemeFilePath } from '../theme-file-uri-utils';
8
5
 
9
6
  const themeFileURIs = [
10
7
  {
@@ -19,28 +16,6 @@ const themeFileURIs = [
19
16
  },
20
17
  ];
21
18
 
22
- describe( 'setThemeFileUris()', () => {
23
- const themeJson = {
24
- styles: {
25
- background: {
26
- backgroundImage: {
27
- url: 'file:./assets/image.jpg',
28
- },
29
- },
30
- },
31
- };
32
-
33
- it( 'should replace relative paths with resolved URIs if found in themeFileURIs', () => {
34
- const newThemeJson = setThemeFileUris( themeJson, themeFileURIs );
35
- expect(
36
- newThemeJson.styles.background.backgroundImage.url ===
37
- 'https://wordpress.org/assets/image.jpg'
38
- ).toBe( true );
39
- // Object reference should be the same as the function is mutating the object.
40
- expect( newThemeJson ).toEqual( themeJson );
41
- } );
42
- } );
43
-
44
19
  describe( 'getResolvedThemeFilePath()', () => {
45
20
  it.each( [
46
21
  [
@@ -1028,14 +1028,59 @@ describe( 'global styles renderer', () => {
1028
1028
  'letter-spacing: 2px',
1029
1029
  ] );
1030
1030
  } );
1031
+ it( 'should set default values for block background styles', () => {
1032
+ const backgroundStyles = {
1033
+ background: {
1034
+ backgroundImage: {
1035
+ url: 'https://wordpress.org/assets/image.jpg',
1036
+ id: 123,
1037
+ },
1038
+ },
1039
+ };
1040
+ expect(
1041
+ getStylesDeclarations( backgroundStyles, '.wp-block-group' )
1042
+ ).toEqual( [
1043
+ "background-image: url( 'https://wordpress.org/assets/image.jpg' )",
1044
+ 'background-size: cover',
1045
+ ] );
1046
+ // Test with root-level styles.
1047
+ expect(
1048
+ getStylesDeclarations( backgroundStyles, ROOT_BLOCK_SELECTOR )
1049
+ ).toEqual( [
1050
+ "background-image: url( 'https://wordpress.org/assets/image.jpg' )",
1051
+ ] );
1052
+ expect(
1053
+ getStylesDeclarations(
1054
+ {
1055
+ background: {
1056
+ ...backgroundStyles.background,
1057
+ backgroundSize: 'contain',
1058
+ },
1059
+ },
1060
+ '.wp-block-group'
1061
+ )
1062
+ ).toEqual( [
1063
+ "background-image: url( 'https://wordpress.org/assets/image.jpg' )",
1064
+ 'background-position: center',
1065
+ 'background-size: contain',
1066
+ ] );
1067
+ } );
1031
1068
  } );
1032
1069
 
1033
1070
  describe( 'processCSSNesting', () => {
1071
+ it( 'should return empty string when supplied css is empty', () => {
1072
+ expect( processCSSNesting( '', '.foo' ) ).toEqual( '' );
1073
+ } );
1034
1074
  it( 'should return processed CSS without any nested selectors', () => {
1035
1075
  expect(
1036
1076
  processCSSNesting( 'color: red; margin: auto;', '.foo' )
1037
1077
  ).toEqual( ':root :where(.foo){color: red; margin: auto;}' );
1038
1078
  } );
1079
+ it( 'should return processed CSS when there are no root selectors', () => {
1080
+ expect(
1081
+ processCSSNesting( '&::before{color: red;}', '.foo' )
1082
+ ).toEqual( ':root :where(.foo)::before{color: red;}' );
1083
+ } );
1039
1084
  it( 'should return processed CSS with nested selectors', () => {
1040
1085
  expect(
1041
1086
  processCSSNesting(
@@ -1049,21 +1094,21 @@ describe( 'global styles renderer', () => {
1049
1094
  it( 'should return processed CSS with pseudo elements', () => {
1050
1095
  expect(
1051
1096
  processCSSNesting(
1052
- 'color: red; margin: auto; &::before{color: blue;} & ::before{color: green;} &.one::before{color: yellow;} & .two::before{color: purple;}',
1097
+ 'color: red; margin: auto; &::before{color: blue;} & ::before{color: green;} &.one::before{color: yellow;} & .two::before{color: purple;} & > ::before{color: darkseagreen;}',
1053
1098
  '.foo'
1054
1099
  )
1055
1100
  ).toEqual(
1056
- ':root :where(.foo){color: red; margin: auto;}:root :where(.foo::before){color: blue;}:root :where(.foo ::before){color: green;}:root :where(.foo.one::before){color: yellow;}:root :where(.foo .two::before){color: purple;}'
1101
+ ':root :where(.foo){color: red; margin: auto;}:root :where(.foo)::before{color: blue;}:root :where(.foo) ::before{color: green;}:root :where(.foo.one)::before{color: yellow;}:root :where(.foo .two)::before{color: purple;}:root :where(.foo) > ::before{color: darkseagreen;}'
1057
1102
  );
1058
1103
  } );
1059
1104
  it( 'should return processed CSS with multiple root selectors', () => {
1060
1105
  expect(
1061
1106
  processCSSNesting(
1062
- 'color: red; margin: auto; &.one{color: blue;} & .two{color: green;} &::before{color: yellow;} & ::before{color: purple;} &.three::before{color: orange;} & .four::before{color: skyblue;}',
1107
+ 'color: red; margin: auto; &.one{color: blue;} & .two{color: green;} &::before{color: yellow;} & ::before{color: purple;} &.three::before{color: orange;} & .four::before{color: skyblue;} & > ::before{color: darkseagreen;}',
1063
1108
  '.foo, .bar'
1064
1109
  )
1065
1110
  ).toEqual(
1066
- ':root :where(.foo, .bar){color: red; margin: auto;}:root :where(.foo.one, .bar.one){color: blue;}:root :where(.foo .two, .bar .two){color: green;}:root :where(.foo::before, .bar::before){color: yellow;}:root :where(.foo ::before, .bar ::before){color: purple;}:root :where(.foo.three::before, .bar.three::before){color: orange;}:root :where(.foo .four::before, .bar .four::before){color: skyblue;}'
1111
+ ':root :where(.foo, .bar){color: red; margin: auto;}:root :where(.foo.one, .bar.one){color: blue;}:root :where(.foo .two, .bar .two){color: green;}:root :where(.foo, .bar)::before{color: yellow;}:root :where(.foo, .bar) ::before{color: purple;}:root :where(.foo.three, .bar.three)::before{color: orange;}:root :where(.foo .four, .bar .four)::before{color: skyblue;}:root :where(.foo, .bar) > ::before{color: darkseagreen;}'
1067
1112
  );
1068
1113
  } );
1069
1114
  } );
@@ -7,6 +7,9 @@ import {
7
7
  getPresetVariableFromValue,
8
8
  getValueFromVariable,
9
9
  scopeFeatureSelectors,
10
+ getResolvedThemeFilePath,
11
+ getResolvedRefValue,
12
+ getResolvedValue,
10
13
  } from '../utils';
11
14
 
12
15
  describe( 'editor utils', () => {
@@ -52,6 +55,41 @@ describe( 'editor utils', () => {
52
55
  },
53
56
  },
54
57
  },
58
+ styles: {
59
+ background: {
60
+ backgroundImage: {
61
+ url: 'file:./assets/image.jpg',
62
+ },
63
+ backgroundAttachment: 'fixed',
64
+ backgroundPosition: 'top left',
65
+ },
66
+ blocks: {
67
+ 'core/group': {
68
+ background: {
69
+ backgroundImage: {
70
+ ref: 'styles.background.backgroundImage',
71
+ },
72
+ },
73
+ dimensions: {
74
+ minHeight: '100px',
75
+ },
76
+ },
77
+ },
78
+ },
79
+ _links: {
80
+ 'wp:theme-file': [
81
+ {
82
+ name: 'file:./assets/image.jpg',
83
+ href: 'https://wordpress.org/assets/image.jpg',
84
+ target: 'styles.background.backgroundImage.url',
85
+ },
86
+ {
87
+ name: 'file:./assets/other/image.jpg',
88
+ href: 'https://wordpress.org/assets/other/image.jpg',
89
+ target: "styles.blocks.['core/group'].background.backgroundImage.url",
90
+ },
91
+ ],
92
+ },
55
93
  isGlobalStylesUserThemeJSON: true,
56
94
  };
57
95
 
@@ -366,4 +404,86 @@ describe( 'editor utils', () => {
366
404
  } );
367
405
  } );
368
406
  } );
407
+
408
+ describe( 'getResolvedThemeFilePath()', () => {
409
+ it.each( [
410
+ [
411
+ 'file:./assets/image.jpg',
412
+ 'https://wordpress.org/assets/image.jpg',
413
+ 'Should return absolute URL if found in themeFileURIs',
414
+ ],
415
+ [
416
+ 'file:./misc/image.jpg',
417
+ 'file:./misc/image.jpg',
418
+ 'Should return value if not found in themeFileURIs',
419
+ ],
420
+ [
421
+ 'https://wordpress.org/assets/image.jpg',
422
+ 'https://wordpress.org/assets/image.jpg',
423
+ 'Should not match absolute URLs',
424
+ ],
425
+ ] )(
426
+ 'Given file %s and return value %s: %s',
427
+ ( file, returnedValue ) => {
428
+ expect(
429
+ getResolvedThemeFilePath(
430
+ file,
431
+ themeJson._links[ 'wp:theme-file' ]
432
+ ) === returnedValue
433
+ ).toBe( true );
434
+ }
435
+ );
436
+ } );
437
+
438
+ describe( 'getResolvedRefValue()', () => {
439
+ it.each( [
440
+ [ 'blue', 'blue', null ],
441
+ [ 0, 0, themeJson ],
442
+ [
443
+ { ref: 'styles.background.backgroundImage' },
444
+ { url: 'file:./assets/image.jpg' },
445
+ themeJson,
446
+ ],
447
+ [
448
+ {
449
+ ref: 'styles.blocks.core/group.background.backgroundImage',
450
+ },
451
+ undefined,
452
+ themeJson,
453
+ ],
454
+ ] )(
455
+ 'Given ruleValue %s return expected value of %s',
456
+ ( ruleValue, returnedValue, tree ) => {
457
+ expect( getResolvedRefValue( ruleValue, tree ) ).toEqual(
458
+ returnedValue
459
+ );
460
+ }
461
+ );
462
+ } );
463
+
464
+ describe( 'getResolvedValue()', () => {
465
+ it.each( [
466
+ [ 'blue', 'blue', null ],
467
+ [ 0, 0, themeJson ],
468
+ [
469
+ { ref: 'styles.background.backgroundImage' },
470
+ { url: 'https://wordpress.org/assets/image.jpg' },
471
+ themeJson,
472
+ ],
473
+ [
474
+ {
475
+ ref: 'styles.blocks.core/group.background.backgroundImage',
476
+ },
477
+ undefined,
478
+ themeJson,
479
+ ],
480
+ ] )(
481
+ 'Given ruleValue %s return expected value of %s',
482
+ ( ruleValue, returnedValue, tree ) => {
483
+ expect( getResolvedValue( ruleValue, tree ) ).toEqual(
484
+ returnedValue
485
+ );
486
+ }
487
+ );
488
+ } );
369
489
  } );
@@ -1,8 +1,3 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import { getValueFromObjectPath } from '../../utils/object';
5
-
6
1
  /**
7
2
  * Looks up a theme file URI based on a relative path.
8
3
  *
@@ -21,57 +16,3 @@ export function getResolvedThemeFilePath( file, themeFileURIs = [] ) {
21
16
 
22
17
  return uri?.href;
23
18
  }
24
-
25
- /**
26
- * Mutates an object by settings a value at the provided path.
27
- *
28
- * @param {Object} object Object to set a value in.
29
- * @param {number|string|Array} path Path in the object to modify.
30
- * @param {*} value New value to set.
31
- * @return {Object} Object with the new value set.
32
- */
33
- function setMutably( object, path, value ) {
34
- path = path.split( '.' );
35
- const finalValueKey = path.pop();
36
- let prev = object;
37
-
38
- for ( const key of path ) {
39
- const current = prev[ key ];
40
- prev = current;
41
- }
42
-
43
- prev[ finalValueKey ] = value;
44
-
45
- return object;
46
- }
47
-
48
- /**
49
- * Resolves any relative paths if a corresponding theme file URI is available.
50
- * Note: this function mutates the object and is specifically to be used in
51
- * an async styles build context in useGlobalStylesOutput
52
- *
53
- * @param {Object} themeJson Theme.json/Global styles tree.
54
- * @param {Array<Object>} themeFileURIs A collection of absolute theme file URIs and their corresponding file paths.
55
- * @return {Object} Returns mutated object.
56
- */
57
- export function setThemeFileUris( themeJson, themeFileURIs ) {
58
- if ( ! themeJson?.styles || ! themeFileURIs ) {
59
- return themeJson;
60
- }
61
-
62
- themeFileURIs.forEach( ( { name, href, target } ) => {
63
- const value = getValueFromObjectPath( themeJson, target );
64
- if ( value === name ) {
65
- /*
66
- * The object must not be updated immutably here because the
67
- * themeJson is a reference to the global styles tree used as a dependency in the
68
- * useGlobalStylesOutputWithConfig() hook. If we don't mutate the object,
69
- * the hook will detect the change and re-render the component, resulting
70
- * in a maximum depth exceeded error.
71
- */
72
- themeJson = setMutably( themeJson, target, href );
73
- }
74
- } );
75
-
76
- return themeJson;
77
- }
@@ -474,7 +474,6 @@ export default function TypographyPanel( {
474
474
  panelId={ panelId }
475
475
  >
476
476
  <LineHeightControl
477
- __nextHasNoMarginBottom
478
477
  __unstableInputWidth="auto"
479
478
  value={ lineHeight }
480
479
  onChange={ setLineHeight }