@wordpress/block-editor 11.6.0 → 11.8.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 (350) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +46 -55
  3. package/build/components/block-list/block-html.js +1 -3
  4. package/build/components/block-list/block-html.js.map +1 -1
  5. package/build/components/block-list/block.native.js +4 -3
  6. package/build/components/block-list/block.native.js.map +1 -1
  7. package/build/components/block-list/index.native.js +11 -21
  8. package/build/components/block-list/index.native.js.map +1 -1
  9. package/build/components/block-list/use-in-between-inserter.js +3 -1
  10. package/build/components/block-list/use-in-between-inserter.js.map +1 -1
  11. package/build/components/block-popover/inbetween.js +2 -9
  12. package/build/components/block-popover/inbetween.js.map +1 -1
  13. package/build/components/block-preview/auto.js +6 -23
  14. package/build/components/block-preview/auto.js.map +1 -1
  15. package/build/components/block-settings-menu/block-settings-dropdown.js +1 -10
  16. package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  17. package/build/components/caption/index.native.js +0 -1
  18. package/build/components/caption/index.native.js.map +1 -1
  19. package/build/components/date-format-picker/index.js +1 -1
  20. package/build/components/date-format-picker/index.js.map +1 -1
  21. package/build/components/editor-styles/index.js +20 -2
  22. package/build/components/editor-styles/index.js.map +1 -1
  23. package/build/components/global-styles/border-panel.js +15 -29
  24. package/build/components/global-styles/border-panel.js.map +1 -1
  25. package/build/components/global-styles/color-panel.js +583 -0
  26. package/build/components/global-styles/color-panel.js.map +1 -0
  27. package/build/components/global-styles/dimensions-panel.js +23 -44
  28. package/build/components/global-styles/dimensions-panel.js.map +1 -1
  29. package/build/components/global-styles/effects-panel.js +244 -0
  30. package/build/components/global-styles/effects-panel.js.map +1 -0
  31. package/build/components/global-styles/filters-panel.js +151 -0
  32. package/build/components/global-styles/filters-panel.js.map +1 -0
  33. package/build/components/global-styles/get-block-css-selector.js +118 -0
  34. package/build/components/global-styles/get-block-css-selector.js.map +1 -0
  35. package/build/components/global-styles/hooks.js +60 -1
  36. package/build/components/global-styles/hooks.js.map +1 -1
  37. package/build/components/global-styles/index.js +46 -2
  38. package/build/components/global-styles/index.js.map +1 -1
  39. package/build/components/global-styles/typography-panel.js +9 -35
  40. package/build/components/global-styles/typography-panel.js.map +1 -1
  41. package/build/components/global-styles/use-global-styles-output.js +173 -91
  42. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  43. package/build/components/global-styles/utils.js +2 -1
  44. package/build/components/global-styles/utils.js.map +1 -1
  45. package/build/components/iframe/index.js +1 -1
  46. package/build/components/iframe/index.js.map +1 -1
  47. package/build/components/image-size-control/index.js +8 -5
  48. package/build/components/image-size-control/index.js.map +1 -1
  49. package/build/components/image-size-control/use-dimension-handler.js +5 -3
  50. package/build/components/image-size-control/use-dimension-handler.js.map +1 -1
  51. package/build/components/index.js +16 -0
  52. package/build/components/index.js.map +1 -1
  53. package/build/components/inserter/block-patterns-tab.js +4 -2
  54. package/build/components/inserter/block-patterns-tab.js.map +1 -1
  55. package/build/components/inspector-controls-tabs/position-controls-panel.js +43 -7
  56. package/build/components/inspector-controls-tabs/position-controls-panel.js.map +1 -1
  57. package/build/components/inspector-controls-tabs/utils.js +5 -3
  58. package/build/components/inspector-controls-tabs/utils.js.map +1 -1
  59. package/build/components/line-height-control/index.js +15 -1
  60. package/build/components/line-height-control/index.js.map +1 -1
  61. package/build/components/list-view/appender.js +105 -0
  62. package/build/components/list-view/appender.js.map +1 -0
  63. package/build/components/list-view/block.js +6 -5
  64. package/build/components/list-view/block.js.map +1 -1
  65. package/build/components/list-view/branch.js +25 -5
  66. package/build/components/list-view/branch.js.map +1 -1
  67. package/build/components/list-view/index.js +56 -14
  68. package/build/components/list-view/index.js.map +1 -1
  69. package/build/components/list-view/use-list-view-client-ids.js +7 -3
  70. package/build/components/list-view/use-list-view-client-ids.js.map +1 -1
  71. package/build/components/list-view/use-list-view-drop-zone.js +8 -2
  72. package/build/components/list-view/use-list-view-drop-zone.js.map +1 -1
  73. package/build/components/media-replace-flow/index.js +13 -4
  74. package/build/components/media-replace-flow/index.js.map +1 -1
  75. package/build/components/off-canvas-editor/block-contents.js +6 -1
  76. package/build/components/off-canvas-editor/block-contents.js.map +1 -1
  77. package/build/components/off-canvas-editor/index.js +17 -14
  78. package/build/components/off-canvas-editor/index.js.map +1 -1
  79. package/build/components/resizable-box-popover/index.js +38 -0
  80. package/build/components/resizable-box-popover/index.js.map +1 -0
  81. package/build/components/rich-text/format-edit.js +2 -30
  82. package/build/components/rich-text/format-edit.js.map +1 -1
  83. package/build/components/rich-text/index.js +0 -1
  84. package/build/components/rich-text/index.js.map +1 -1
  85. package/build/components/rich-text/index.native.js +7 -11
  86. package/build/components/rich-text/index.native.js.map +1 -1
  87. package/build/components/spacing-sizes-control/spacing-input-control.js +8 -0
  88. package/build/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
  89. package/build/components/writing-flow/use-input.js +4 -8
  90. package/build/components/writing-flow/use-input.js.map +1 -1
  91. package/build/hooks/anchor.js +1 -1
  92. package/build/hooks/anchor.js.map +1 -1
  93. package/build/hooks/border.js +1 -2
  94. package/build/hooks/border.js.map +1 -1
  95. package/build/hooks/color.js +92 -229
  96. package/build/hooks/color.js.map +1 -1
  97. package/build/hooks/content-lock-ui.js +4 -2
  98. package/build/hooks/content-lock-ui.js.map +1 -1
  99. package/build/hooks/{color-panel.js → contrast-checker.js} +11 -49
  100. package/build/hooks/contrast-checker.js.map +1 -0
  101. package/build/hooks/dimensions.js +0 -1
  102. package/build/hooks/dimensions.js.map +1 -1
  103. package/build/hooks/duotone.js +92 -64
  104. package/build/hooks/duotone.js.map +1 -1
  105. package/build/hooks/margin.js +27 -17
  106. package/build/hooks/margin.js.map +1 -1
  107. package/build/hooks/padding.js +19 -9
  108. package/build/hooks/padding.js.map +1 -1
  109. package/build/hooks/position.js +2 -2
  110. package/build/hooks/position.js.map +1 -1
  111. package/build/hooks/style.js +23 -26
  112. package/build/hooks/style.js.map +1 -1
  113. package/build/hooks/typography.js +0 -1
  114. package/build/hooks/typography.js.map +1 -1
  115. package/build/hooks/utils.js +28 -76
  116. package/build/hooks/utils.js.map +1 -1
  117. package/build/layouts/grid.js +165 -0
  118. package/build/layouts/grid.js.map +1 -0
  119. package/build/layouts/index.js +3 -1
  120. package/build/layouts/index.js.map +1 -1
  121. package/build/layouts/utils.js +3 -2
  122. package/build/layouts/utils.js.map +1 -1
  123. package/build/private-apis.js +7 -1
  124. package/build/private-apis.js.map +1 -1
  125. package/build/store/actions.js +1 -1
  126. package/build/store/actions.js.map +1 -1
  127. package/build/utils/object.js +76 -0
  128. package/build/utils/object.js.map +1 -0
  129. package/build-module/components/block-list/block-html.js +1 -3
  130. package/build-module/components/block-list/block-html.js.map +1 -1
  131. package/build-module/components/block-list/block.native.js +4 -3
  132. package/build-module/components/block-list/block.native.js.map +1 -1
  133. package/build-module/components/block-list/index.native.js +11 -19
  134. package/build-module/components/block-list/index.native.js.map +1 -1
  135. package/build-module/components/block-list/use-in-between-inserter.js +2 -1
  136. package/build-module/components/block-list/use-in-between-inserter.js.map +1 -1
  137. package/build-module/components/block-popover/inbetween.js +2 -9
  138. package/build-module/components/block-popover/inbetween.js.map +1 -1
  139. package/build-module/components/block-preview/auto.js +6 -22
  140. package/build-module/components/block-preview/auto.js.map +1 -1
  141. package/build-module/components/block-settings-menu/block-settings-dropdown.js +1 -9
  142. package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  143. package/build-module/components/caption/index.native.js +0 -1
  144. package/build-module/components/caption/index.native.js.map +1 -1
  145. package/build-module/components/date-format-picker/index.js +1 -1
  146. package/build-module/components/date-format-picker/index.js.map +1 -1
  147. package/build-module/components/editor-styles/index.js +19 -2
  148. package/build-module/components/editor-styles/index.js.map +1 -1
  149. package/build-module/components/global-styles/border-panel.js +15 -29
  150. package/build-module/components/global-styles/border-panel.js.map +1 -1
  151. package/build-module/components/global-styles/color-panel.js +554 -0
  152. package/build-module/components/global-styles/color-panel.js.map +1 -0
  153. package/build-module/components/global-styles/dimensions-panel.js +22 -44
  154. package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
  155. package/build-module/components/global-styles/effects-panel.js +228 -0
  156. package/build-module/components/global-styles/effects-panel.js.map +1 -0
  157. package/build-module/components/global-styles/filters-panel.js +139 -0
  158. package/build-module/components/global-styles/filters-panel.js.map +1 -0
  159. package/build-module/components/global-styles/get-block-css-selector.js +109 -0
  160. package/build-module/components/global-styles/get-block-css-selector.js.map +1 -0
  161. package/build-module/components/global-styles/hooks.js +58 -1
  162. package/build-module/components/global-styles/hooks.js.map +1 -1
  163. package/build-module/components/global-styles/index.js +5 -1
  164. package/build-module/components/global-styles/index.js.map +1 -1
  165. package/build-module/components/global-styles/typography-panel.js +8 -35
  166. package/build-module/components/global-styles/typography-panel.js.map +1 -1
  167. package/build-module/components/global-styles/use-global-styles-output.js +175 -93
  168. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  169. package/build-module/components/global-styles/utils.js +2 -1
  170. package/build-module/components/global-styles/utils.js.map +1 -1
  171. package/build-module/components/iframe/index.js +1 -1
  172. package/build-module/components/iframe/index.js.map +1 -1
  173. package/build-module/components/image-size-control/index.js +8 -5
  174. package/build-module/components/image-size-control/index.js.map +1 -1
  175. package/build-module/components/image-size-control/use-dimension-handler.js +5 -3
  176. package/build-module/components/image-size-control/use-dimension-handler.js.map +1 -1
  177. package/build-module/components/index.js +1 -0
  178. package/build-module/components/index.js.map +1 -1
  179. package/build-module/components/inserter/block-patterns-tab.js +5 -2
  180. package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
  181. package/build-module/components/inspector-controls-tabs/position-controls-panel.js +42 -7
  182. package/build-module/components/inspector-controls-tabs/position-controls-panel.js.map +1 -1
  183. package/build-module/components/inspector-controls-tabs/utils.js +4 -3
  184. package/build-module/components/inspector-controls-tabs/utils.js.map +1 -1
  185. package/build-module/components/line-height-control/index.js +15 -1
  186. package/build-module/components/line-height-control/index.js.map +1 -1
  187. package/build-module/components/list-view/appender.js +88 -0
  188. package/build-module/components/list-view/appender.js.map +1 -0
  189. package/build-module/components/list-view/block.js +6 -4
  190. package/build-module/components/list-view/block.js.map +1 -1
  191. package/build-module/components/list-view/branch.js +22 -5
  192. package/build-module/components/list-view/branch.js.map +1 -1
  193. package/build-module/components/list-view/index.js +50 -13
  194. package/build-module/components/list-view/index.js.map +1 -1
  195. package/build-module/components/list-view/use-list-view-client-ids.js +7 -3
  196. package/build-module/components/list-view/use-list-view-client-ids.js.map +1 -1
  197. package/build-module/components/list-view/use-list-view-drop-zone.js +8 -4
  198. package/build-module/components/list-view/use-list-view-drop-zone.js.map +1 -1
  199. package/build-module/components/media-replace-flow/index.js +12 -4
  200. package/build-module/components/media-replace-flow/index.js.map +1 -1
  201. package/build-module/components/off-canvas-editor/block-contents.js +5 -1
  202. package/build-module/components/off-canvas-editor/block-contents.js.map +1 -1
  203. package/build-module/components/off-canvas-editor/index.js +17 -14
  204. package/build-module/components/off-canvas-editor/index.js.map +1 -1
  205. package/build-module/components/resizable-box-popover/index.js +26 -0
  206. package/build-module/components/resizable-box-popover/index.js.map +1 -0
  207. package/build-module/components/rich-text/format-edit.js +3 -31
  208. package/build-module/components/rich-text/format-edit.js.map +1 -1
  209. package/build-module/components/rich-text/index.js +0 -1
  210. package/build-module/components/rich-text/index.js.map +1 -1
  211. package/build-module/components/rich-text/index.native.js +7 -10
  212. package/build-module/components/rich-text/index.native.js.map +1 -1
  213. package/build-module/components/spacing-sizes-control/spacing-input-control.js +7 -0
  214. package/build-module/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
  215. package/build-module/components/writing-flow/use-input.js +4 -8
  216. package/build-module/components/writing-flow/use-input.js.map +1 -1
  217. package/build-module/hooks/anchor.js +1 -1
  218. package/build-module/hooks/anchor.js.map +1 -1
  219. package/build-module/hooks/border.js +1 -2
  220. package/build-module/hooks/border.js.map +1 -1
  221. package/build-module/hooks/color.js +90 -232
  222. package/build-module/hooks/color.js.map +1 -1
  223. package/build-module/hooks/content-lock-ui.js +4 -2
  224. package/build-module/hooks/content-lock-ui.js.map +1 -1
  225. package/build-module/hooks/{color-panel.js → contrast-checker.js} +10 -44
  226. package/build-module/hooks/contrast-checker.js.map +1 -0
  227. package/build-module/hooks/dimensions.js +0 -1
  228. package/build-module/hooks/dimensions.js.map +1 -1
  229. package/build-module/hooks/duotone.js +91 -65
  230. package/build-module/hooks/duotone.js.map +1 -1
  231. package/build-module/hooks/margin.js +29 -18
  232. package/build-module/hooks/margin.js.map +1 -1
  233. package/build-module/hooks/padding.js +21 -10
  234. package/build-module/hooks/padding.js.map +1 -1
  235. package/build-module/hooks/position.js +3 -3
  236. package/build-module/hooks/position.js.map +1 -1
  237. package/build-module/hooks/style.js +23 -26
  238. package/build-module/hooks/style.js.map +1 -1
  239. package/build-module/hooks/typography.js +0 -1
  240. package/build-module/hooks/typography.js.map +1 -1
  241. package/build-module/hooks/utils.js +27 -74
  242. package/build-module/hooks/utils.js.map +1 -1
  243. package/build-module/layouts/grid.js +151 -0
  244. package/build-module/layouts/grid.js.map +1 -0
  245. package/build-module/layouts/index.js +2 -1
  246. package/build-module/layouts/index.js.map +1 -1
  247. package/build-module/layouts/utils.js +3 -2
  248. package/build-module/layouts/utils.js.map +1 -1
  249. package/build-module/private-apis.js +5 -1
  250. package/build-module/private-apis.js.map +1 -1
  251. package/build-module/store/actions.js +1 -1
  252. package/build-module/store/actions.js.map +1 -1
  253. package/build-module/utils/object.js +69 -0
  254. package/build-module/utils/object.js.map +1 -0
  255. package/build-style/style-rtl.css +77 -16
  256. package/build-style/style.css +77 -16
  257. package/package.json +31 -31
  258. package/src/components/block-draggable/content.scss +1 -1
  259. package/src/components/block-inspector/style.scss +6 -4
  260. package/src/components/block-list/block-html.js +1 -1
  261. package/src/components/block-list/block.native.js +3 -2
  262. package/src/components/block-list/index.native.js +19 -38
  263. package/src/components/block-list/use-in-between-inserter.js +4 -1
  264. package/src/components/block-popover/inbetween.js +2 -13
  265. package/src/components/block-preview/auto.js +2 -17
  266. package/src/components/block-settings-menu/block-settings-dropdown.js +2 -12
  267. package/src/components/caption/index.native.js +0 -1
  268. package/src/components/colors-gradients/style.scss +8 -8
  269. package/src/components/date-format-picker/index.js +1 -1
  270. package/src/components/editor-styles/index.js +29 -1
  271. package/src/components/global-styles/README.md +129 -16
  272. package/src/components/global-styles/border-panel.js +13 -32
  273. package/src/components/global-styles/color-panel.js +706 -0
  274. package/src/components/global-styles/dimensions-panel.js +43 -55
  275. package/src/components/global-styles/effects-panel.js +228 -0
  276. package/src/components/global-styles/filters-panel.js +157 -0
  277. package/src/components/global-styles/get-block-css-selector.js +118 -0
  278. package/src/components/global-styles/hooks.js +90 -0
  279. package/src/components/global-styles/index.js +4 -1
  280. package/src/components/global-styles/style.scss +42 -0
  281. package/src/components/global-styles/test/use-global-styles-output.js +34 -5
  282. package/src/components/global-styles/typography-panel.js +26 -51
  283. package/src/components/global-styles/use-global-styles-output.js +188 -89
  284. package/src/components/global-styles/utils.js +3 -0
  285. package/src/components/iframe/index.js +1 -1
  286. package/src/components/image-size-control/index.js +4 -3
  287. package/src/components/image-size-control/test/index.js +2 -2
  288. package/src/components/image-size-control/use-dimension-handler.js +4 -3
  289. package/src/components/index.js +4 -1
  290. package/src/components/inner-blocks/README.md +1 -1
  291. package/src/components/inserter/block-patterns-tab.js +3 -1
  292. package/src/components/inspector-controls-tabs/position-controls-panel.js +40 -9
  293. package/src/components/inspector-controls-tabs/utils.js +4 -3
  294. package/src/components/line-height-control/index.js +10 -1
  295. package/src/components/list-view/README.md +2 -0
  296. package/src/components/list-view/appender.js +101 -0
  297. package/src/components/list-view/block.js +6 -4
  298. package/src/components/list-view/branch.js +30 -1
  299. package/src/components/list-view/index.js +60 -11
  300. package/src/components/list-view/style.scss +22 -1
  301. package/src/components/list-view/test/use-list-view-drop-zone.js +188 -0
  302. package/src/components/list-view/use-list-view-client-ids.js +5 -3
  303. package/src/components/list-view/use-list-view-drop-zone.js +9 -3
  304. package/src/components/media-replace-flow/index.js +36 -24
  305. package/src/components/media-replace-flow/style.scss +5 -2
  306. package/src/components/off-canvas-editor/block-contents.js +4 -0
  307. package/src/components/off-canvas-editor/index.js +15 -11
  308. package/src/components/resizable-box-popover/index.js +27 -0
  309. package/src/components/rich-text/format-edit.js +2 -32
  310. package/src/components/rich-text/index.js +0 -1
  311. package/src/components/rich-text/index.native.js +2 -5
  312. package/src/components/spacing-sizes-control/spacing-input-control.js +10 -0
  313. package/src/components/spacing-sizes-control/style.scss +7 -7
  314. package/src/components/writing-flow/use-input.js +4 -5
  315. package/src/hooks/anchor.js +1 -1
  316. package/src/hooks/border.js +1 -2
  317. package/src/hooks/color.js +120 -296
  318. package/src/hooks/content-lock-ui.js +6 -2
  319. package/src/hooks/{color-panel.js → contrast-checker.js} +10 -46
  320. package/src/hooks/dimensions.js +0 -1
  321. package/src/hooks/duotone.js +121 -76
  322. package/src/hooks/margin.js +31 -26
  323. package/src/hooks/padding.js +24 -18
  324. package/src/hooks/position.js +3 -3
  325. package/src/hooks/style.js +29 -28
  326. package/src/hooks/test/utils.js +0 -104
  327. package/src/hooks/typography.js +0 -1
  328. package/src/hooks/utils.js +31 -74
  329. package/src/layouts/grid.js +172 -0
  330. package/src/layouts/index.js +2 -1
  331. package/src/layouts/test/grid.js +21 -0
  332. package/src/layouts/utils.js +2 -2
  333. package/src/private-apis.js +4 -0
  334. package/src/store/actions.js +1 -1
  335. package/src/style.scss +1 -0
  336. package/src/utils/object.js +69 -0
  337. package/src/utils/test/object.js +145 -0
  338. package/tsconfig.tsbuildinfo +1 -1
  339. package/build/components/rich-text/use-native-props.js +0 -11
  340. package/build/components/rich-text/use-native-props.js.map +0 -1
  341. package/build/components/rich-text/use-native-props.native.js +0 -24
  342. package/build/components/rich-text/use-native-props.native.js.map +0 -1
  343. package/build/hooks/color-panel.js.map +0 -1
  344. package/build-module/components/rich-text/use-native-props.js +0 -4
  345. package/build-module/components/rich-text/use-native-props.js.map +0 -1
  346. package/build-module/components/rich-text/use-native-props.native.js +0 -15
  347. package/build-module/components/rich-text/use-native-props.native.js.map +0 -1
  348. package/build-module/hooks/color-panel.js.map +0 -1
  349. package/src/components/rich-text/use-native-props.js +0 -3
  350. package/src/components/rich-text/use-native-props.native.js +0 -17
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { isEmpty, mapValues, get } from 'lodash';
4
+ import { isEmpty, get } from 'lodash';
5
5
 
6
6
  /**
7
7
  * WordPress dependencies
@@ -14,6 +14,7 @@ import { useMemo } from '@wordpress/element';
14
14
  */
15
15
  import { useSetting } from '../components';
16
16
  import { useSettingsForBlockElement } from '../components/global-styles/hooks';
17
+ import { immutableSet } from '../utils/object';
17
18
 
18
19
  /**
19
20
  * Removed falsy values from nested object.
@@ -30,83 +31,13 @@ export const cleanEmptyObject = ( object ) => {
30
31
  return object;
31
32
  }
32
33
  const cleanedNestedObjects = Object.fromEntries(
33
- Object.entries( mapValues( object, cleanEmptyObject ) ).filter(
34
- ( [ , value ] ) => Boolean( value )
35
- )
34
+ Object.entries( object )
35
+ .map( ( [ key, value ] ) => [ key, cleanEmptyObject( value ) ] )
36
+ .filter( ( [ , value ] ) => Boolean( value ) )
36
37
  );
37
38
  return isEmpty( cleanedNestedObjects ) ? undefined : cleanedNestedObjects;
38
39
  };
39
40
 
40
- /**
41
- * Converts a path to an array of its fragments.
42
- * Supports strings, numbers and arrays:
43
- *
44
- * 'foo' => [ 'foo' ]
45
- * 2 => [ '2' ]
46
- * [ 'foo', 'bar' ] => [ 'foo', 'bar' ]
47
- *
48
- * @param {string|number|Array} path Path
49
- * @return {Array} Normalized path.
50
- */
51
- function normalizePath( path ) {
52
- if ( Array.isArray( path ) ) {
53
- return path;
54
- } else if ( typeof path === 'number' ) {
55
- return [ path.toString() ];
56
- }
57
-
58
- return [ path ];
59
- }
60
-
61
- /**
62
- * Clones an object.
63
- * Non-object values are returned unchanged.
64
- *
65
- * @param {*} object Object to clone.
66
- * @return {*} Cloned object, or original literal non-object value.
67
- */
68
- function cloneObject( object ) {
69
- if ( typeof object === 'object' ) {
70
- return {
71
- ...Object.fromEntries(
72
- Object.entries( object ).map( ( [ key, value ] ) => [
73
- key,
74
- cloneObject( value ),
75
- ] )
76
- ),
77
- };
78
- }
79
-
80
- return object;
81
- }
82
-
83
- /**
84
- * Perform an immutable set.
85
- * Handles nullish initial values.
86
- * Clones all nested objects in the specified object.
87
- *
88
- * @param {Object} object Object to set a value in.
89
- * @param {number|string|Array} path Path in the object to modify.
90
- * @param {*} value New value to set.
91
- * @return {Object} Cloned object with the new value set.
92
- */
93
- export function immutableSet( object, path, value ) {
94
- const normalizedPath = normalizePath( path );
95
- const newObject = object ? cloneObject( object ) : {};
96
-
97
- normalizedPath.reduce( ( acc, key, i ) => {
98
- if ( acc[ key ] === undefined ) {
99
- acc[ key ] = {};
100
- }
101
- if ( i === normalizedPath.length - 1 ) {
102
- acc[ key ] = value;
103
- }
104
- return acc[ key ];
105
- }, newObject );
106
-
107
- return newObject;
108
- }
109
-
110
41
  export function transformStyles(
111
42
  activeSupports,
112
43
  migrationPaths,
@@ -222,6 +153,14 @@ export function useBlockSettings( name, parentLayout ) {
222
153
  const themeColors = useSetting( 'color.palette.theme' );
223
154
  const defaultColors = useSetting( 'color.palette.default' );
224
155
  const defaultPalette = useSetting( 'color.defaultPalette' );
156
+ const userGradientPalette = useSetting( 'color.gradients.custom' );
157
+ const themeGradientPalette = useSetting( 'color.gradients.theme' );
158
+ const defaultGradientPalette = useSetting( 'color.gradients.default' );
159
+ const defaultGradients = useSetting( 'color.defaultGradients' );
160
+ const areCustomGradientsEnabled = useSetting( 'color.customGradient' );
161
+ const isBackgroundEnabled = useSetting( 'color.background' );
162
+ const isLinkEnabled = useSetting( 'color.link' );
163
+ const isTextEnabled = useSetting( 'color.text' );
225
164
 
226
165
  const rawSettings = useMemo( () => {
227
166
  return {
@@ -231,8 +170,18 @@ export function useBlockSettings( name, parentLayout ) {
231
170
  theme: themeColors,
232
171
  default: defaultColors,
233
172
  },
173
+ gradients: {
174
+ custom: userGradientPalette,
175
+ theme: themeGradientPalette,
176
+ default: defaultGradientPalette,
177
+ },
178
+ defaultGradients,
234
179
  defaultPalette,
235
180
  custom: customColorsEnabled,
181
+ customGradient: areCustomGradientsEnabled,
182
+ background: isBackgroundEnabled,
183
+ link: isLinkEnabled,
184
+ text: isTextEnabled,
236
185
  },
237
186
  typography: {
238
187
  fontFamilies: {
@@ -299,6 +248,14 @@ export function useBlockSettings( name, parentLayout ) {
299
248
  themeColors,
300
249
  defaultColors,
301
250
  defaultPalette,
251
+ userGradientPalette,
252
+ themeGradientPalette,
253
+ defaultGradientPalette,
254
+ defaultGradients,
255
+ areCustomGradientsEnabled,
256
+ isBackgroundEnabled,
257
+ isLinkEnabled,
258
+ isTextEnabled,
302
259
  ] );
303
260
 
304
261
  return useSettingsForBlockElement( rawSettings, name );
@@ -0,0 +1,172 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { __ } from '@wordpress/i18n';
5
+
6
+ import {
7
+ BaseControl,
8
+ Flex,
9
+ FlexItem,
10
+ RangeControl,
11
+ __experimentalUnitControl as UnitControl,
12
+ __experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue,
13
+ } from '@wordpress/components';
14
+
15
+ /**
16
+ * Internal dependencies
17
+ */
18
+ import { appendSelectors, getBlockGapCSS } from './utils';
19
+ import { getGapCSSValue } from '../hooks/gap';
20
+ import { shouldSkipSerialization } from '../hooks/utils';
21
+
22
+ const RANGE_CONTROL_MAX_VALUES = {
23
+ px: 600,
24
+ '%': 100,
25
+ vw: 100,
26
+ vh: 100,
27
+ em: 38,
28
+ rem: 38,
29
+ };
30
+
31
+ export default {
32
+ name: 'grid',
33
+ label: __( 'Grid' ),
34
+ inspectorControls: function GridLayoutInspectorControls( {
35
+ layout = {},
36
+ onChange,
37
+ } ) {
38
+ return (
39
+ <GridLayoutMinimumWidthControl
40
+ layout={ layout }
41
+ onChange={ onChange }
42
+ />
43
+ );
44
+ },
45
+ toolBarControls: function DefaultLayoutToolbarControls() {
46
+ return null;
47
+ },
48
+ getLayoutStyle: function getLayoutStyle( {
49
+ selector,
50
+ layout,
51
+ style,
52
+ blockName,
53
+ hasBlockGapSupport,
54
+ layoutDefinitions,
55
+ } ) {
56
+ const { minimumColumnWidth = '12rem' } = layout;
57
+
58
+ // If a block's block.json skips serialization for spacing or spacing.blockGap,
59
+ // don't apply the user-defined value to the styles.
60
+ const blockGapValue =
61
+ style?.spacing?.blockGap &&
62
+ ! shouldSkipSerialization( blockName, 'spacing', 'blockGap' )
63
+ ? getGapCSSValue( style?.spacing?.blockGap, '0.5em' )
64
+ : undefined;
65
+
66
+ let output = '';
67
+ const rules = [];
68
+
69
+ if ( minimumColumnWidth ) {
70
+ rules.push(
71
+ `grid-template-columns: repeat(auto-fill, minmax(min(${ minimumColumnWidth }, 100%), 1fr))`
72
+ );
73
+ }
74
+
75
+ if ( rules.length ) {
76
+ // Reason to disable: the extra line breaks added by prettier mess with the unit tests.
77
+ // eslint-disable-next-line prettier/prettier
78
+ output = `${ appendSelectors( selector ) } { ${ rules.join(
79
+ '; '
80
+ ) }; }`;
81
+ }
82
+
83
+ // Output blockGap styles based on rules contained in layout definitions in theme.json.
84
+ if ( hasBlockGapSupport && blockGapValue ) {
85
+ output += getBlockGapCSS(
86
+ selector,
87
+ layoutDefinitions,
88
+ 'grid',
89
+ blockGapValue
90
+ );
91
+ }
92
+ return output;
93
+ },
94
+ getOrientation() {
95
+ return 'horizontal';
96
+ },
97
+ getAlignments() {
98
+ return [];
99
+ },
100
+ };
101
+
102
+ // Enables setting minimum width of grid items.
103
+ function GridLayoutMinimumWidthControl( { layout, onChange } ) {
104
+ const { minimumColumnWidth: value = '12rem' } = layout;
105
+ const [ quantity, unit ] = parseQuantityAndUnitFromRawValue( value );
106
+
107
+ const handleSliderChange = ( next ) => {
108
+ onChange( {
109
+ ...layout,
110
+ minimumColumnWidth: [ next, unit ].join( '' ),
111
+ } );
112
+ };
113
+
114
+ // Mostly copied from HeightControl.
115
+ const handleUnitChange = ( newUnit ) => {
116
+ // Attempt to smooth over differences between currentUnit and newUnit.
117
+ // This should slightly improve the experience of switching between unit types.
118
+ let newValue;
119
+
120
+ if ( [ 'em', 'rem' ].includes( newUnit ) && unit === 'px' ) {
121
+ // Convert pixel value to an approximate of the new unit, assuming a root size of 16px.
122
+ newValue = ( quantity / 16 ).toFixed( 2 ) + newUnit;
123
+ } else if ( [ 'em', 'rem' ].includes( unit ) && newUnit === 'px' ) {
124
+ // Convert to pixel value assuming a root size of 16px.
125
+ newValue = Math.round( quantity * 16 ) + newUnit;
126
+ } else if (
127
+ [ 'vh', 'vw', '%' ].includes( newUnit ) &&
128
+ quantity > 100
129
+ ) {
130
+ // When converting to `vh`, `vw`, or `%` units, cap the new value at 100.
131
+ newValue = 100 + newUnit;
132
+ }
133
+
134
+ onChange( {
135
+ ...layout,
136
+ minimumColumnWidth: newValue,
137
+ } );
138
+ };
139
+
140
+ return (
141
+ <fieldset>
142
+ <BaseControl.VisualLabel as="legend">
143
+ { __( 'Minimum column width' ) }
144
+ </BaseControl.VisualLabel>
145
+ <Flex gap={ 4 }>
146
+ <FlexItem isBlock>
147
+ <UnitControl
148
+ size={ '__unstable-large' }
149
+ onChange={ ( newValue ) => {
150
+ onChange( {
151
+ ...layout,
152
+ minimumColumnWidth: newValue,
153
+ } );
154
+ } }
155
+ onUnitChange={ handleUnitChange }
156
+ value={ value }
157
+ min={ 0 }
158
+ />
159
+ </FlexItem>
160
+ <FlexItem isBlock>
161
+ <RangeControl
162
+ onChange={ handleSliderChange }
163
+ value={ quantity }
164
+ min={ 0 }
165
+ max={ RANGE_CONTROL_MAX_VALUES[ unit ] || 600 }
166
+ withInputField={ false }
167
+ />
168
+ </FlexItem>
169
+ </Flex>
170
+ </fieldset>
171
+ );
172
+ }
@@ -4,8 +4,9 @@
4
4
  import flex from './flex';
5
5
  import flow from './flow';
6
6
  import constrained from './constrained';
7
+ import grid from './grid';
7
8
 
8
- const layoutTypes = [ flow, flex, constrained ];
9
+ const layoutTypes = [ flow, flex, constrained, grid ];
9
10
 
10
11
  /**
11
12
  * Retrieves a layout type by name.
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import grid from '../grid';
5
+
6
+ describe( 'getLayoutStyle', () => {
7
+ it( 'should return a single `grid-template-columns` property if no non-default params are provided', () => {
8
+ const expected = `.editor-styles-wrapper .my-container { grid-template-columns: repeat(auto-fill, minmax(min(12rem, 100%), 1fr)); }`;
9
+
10
+ const result = grid.getLayoutStyle( {
11
+ selector: '.my-container',
12
+ layout: {},
13
+ style: {},
14
+ blockName: 'test-block',
15
+ hasBlockGapSupport: false,
16
+ layoutDefinitions: undefined,
17
+ } );
18
+
19
+ expect( result ).toBe( expected );
20
+ } );
21
+ } );
@@ -83,10 +83,10 @@ export function getBlockGapCSS(
83
83
  * @return {Object} An object with contextual info per alignment.
84
84
  */
85
85
  export function getAlignmentsInfo( layout ) {
86
- const { contentSize, wideSize } = layout;
86
+ const { contentSize, wideSize, type = 'default' } = layout;
87
87
  const alignmentInfo = {};
88
88
  const sizeRegex = /^(?!0)\d+(px|em|rem|vw|vh|%)?$/i;
89
- if ( sizeRegex.test( contentSize ) ) {
89
+ if ( sizeRegex.test( contentSize ) && type === 'constrained' ) {
90
90
  // translators: %s: container size (i.e. 600px etc)
91
91
  alignmentInfo.none = sprintf( __( 'Max %s wide' ), contentSize );
92
92
  }
@@ -6,7 +6,9 @@ import { ExperimentalBlockEditorProvider } from './components/provider';
6
6
  import { lock } from './lock-unlock';
7
7
  import OffCanvasEditor from './components/off-canvas-editor';
8
8
  import LeafMoreMenu from './components/off-canvas-editor/leaf-more-menu';
9
+ import ResizableBoxPopover from './components/resizable-box-popover';
9
10
  import { ComposedPrivateInserter as PrivateInserter } from './components/inserter';
11
+ import { PrivateListView } from './components/list-view';
10
12
 
11
13
  /**
12
14
  * Private @wordpress/block-editor APIs.
@@ -18,4 +20,6 @@ lock( privateApis, {
18
20
  LeafMoreMenu,
19
21
  OffCanvasEditor,
20
22
  PrivateInserter,
23
+ PrivateListView,
24
+ ResizableBoxPopover,
21
25
  } );
@@ -75,7 +75,7 @@ export const resetBlocks =
75
75
  /**
76
76
  * Block validity is a function of blocks state (at the point of a
77
77
  * reset) and the template setting. As a compromise to its placement
78
- * across distinct parts of state, it is implemented here as a side-
78
+ * across distinct parts of state, it is implemented here as a side
79
79
  * effect of the block reset action.
80
80
  *
81
81
  * @param {Array} blocks Array of blocks.
package/src/style.scss CHANGED
@@ -26,6 +26,7 @@
26
26
  @import "./components/date-format-picker/style.scss";
27
27
  @import "./components/duotone-control/style.scss";
28
28
  @import "./components/font-appearance-control/style.scss";
29
+ @import "./components/global-styles/style.scss";
29
30
  @import "./components/height-control/style.scss";
30
31
  @import "./components/image-size-control/style.scss";
31
32
  @import "./components/inserter-list-item/style.scss";
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Converts a path to an array of its fragments.
3
+ * Supports strings, numbers and arrays:
4
+ *
5
+ * 'foo' => [ 'foo' ]
6
+ * 2 => [ '2' ]
7
+ * [ 'foo', 'bar' ] => [ 'foo', 'bar' ]
8
+ *
9
+ * @param {string|number|Array} path Path
10
+ * @return {Array} Normalized path.
11
+ */
12
+ function normalizePath( path ) {
13
+ if ( Array.isArray( path ) ) {
14
+ return path;
15
+ } else if ( typeof path === 'number' ) {
16
+ return [ path.toString() ];
17
+ }
18
+
19
+ return [ path ];
20
+ }
21
+
22
+ /**
23
+ * Clones an object.
24
+ * Non-object values are returned unchanged.
25
+ *
26
+ * @param {*} object Object to clone.
27
+ * @return {*} Cloned object, or original literal non-object value.
28
+ */
29
+ function cloneObject( object ) {
30
+ if ( object && typeof object === 'object' ) {
31
+ return {
32
+ ...Object.fromEntries(
33
+ Object.entries( object ).map( ( [ key, value ] ) => [
34
+ key,
35
+ cloneObject( value ),
36
+ ] )
37
+ ),
38
+ };
39
+ }
40
+
41
+ return object;
42
+ }
43
+
44
+ /**
45
+ * Perform an immutable set.
46
+ * Handles nullish initial values.
47
+ * Clones all nested objects in the specified object.
48
+ *
49
+ * @param {Object} object Object to set a value in.
50
+ * @param {number|string|Array} path Path in the object to modify.
51
+ * @param {*} value New value to set.
52
+ * @return {Object} Cloned object with the new value set.
53
+ */
54
+ export function immutableSet( object, path, value ) {
55
+ const normalizedPath = normalizePath( path );
56
+ const newObject = object ? cloneObject( object ) : {};
57
+
58
+ normalizedPath.reduce( ( acc, key, i ) => {
59
+ if ( acc[ key ] === undefined ) {
60
+ acc[ key ] = {};
61
+ }
62
+ if ( i === normalizedPath.length - 1 ) {
63
+ acc[ key ] = value;
64
+ }
65
+ return acc[ key ];
66
+ }, newObject );
67
+
68
+ return newObject;
69
+ }
@@ -0,0 +1,145 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import { immutableSet } from '../object';
5
+
6
+ describe( 'immutableSet', () => {
7
+ describe( 'handling falsy values properly', () => {
8
+ it( 'should create a new object if `undefined` is passed', () => {
9
+ const result = immutableSet( undefined, 'test', 1 );
10
+
11
+ expect( result ).toEqual( { test: 1 } );
12
+ } );
13
+
14
+ it( 'should create a new object if `null` is passed', () => {
15
+ const result = immutableSet( null, 'test', 1 );
16
+
17
+ expect( result ).toEqual( { test: 1 } );
18
+ } );
19
+
20
+ it( 'should create a new object if `false` is passed', () => {
21
+ const result = immutableSet( false, 'test', 1 );
22
+
23
+ expect( result ).toEqual( { test: 1 } );
24
+ } );
25
+
26
+ it( 'should create a new object if `0` is passed', () => {
27
+ const result = immutableSet( 0, 'test', 1 );
28
+
29
+ expect( result ).toEqual( { test: 1 } );
30
+ } );
31
+
32
+ it( 'should create a new object if an empty string is passed', () => {
33
+ const result = immutableSet( '', 'test', 1 );
34
+
35
+ expect( result ).toEqual( { test: 1 } );
36
+ } );
37
+
38
+ it( 'should create a new object if a NaN is passed', () => {
39
+ const result = immutableSet( NaN, 'test', 1 );
40
+
41
+ expect( result ).toEqual( { test: 1 } );
42
+ } );
43
+ } );
44
+
45
+ describe( 'manages data assignment properly', () => {
46
+ it( 'assigns value properly when it does not exist', () => {
47
+ const result = immutableSet( {}, 'test', 1 );
48
+
49
+ expect( result ).toEqual( { test: 1 } );
50
+ } );
51
+
52
+ it( 'overrides existing values', () => {
53
+ const result = immutableSet( { test: 1 }, 'test', 2 );
54
+
55
+ expect( result ).toEqual( { test: 2 } );
56
+ } );
57
+
58
+ describe( 'with array notation access', () => {
59
+ it( 'assigns values at deeper levels', () => {
60
+ const result = immutableSet( {}, [ 'foo', 'bar', 'baz' ], 5 );
61
+
62
+ expect( result ).toEqual( { foo: { bar: { baz: 5 } } } );
63
+ } );
64
+
65
+ it( 'overrides existing values at deeper levels', () => {
66
+ const result = immutableSet(
67
+ { foo: { bar: { baz: 1 } } },
68
+ [ 'foo', 'bar', 'baz' ],
69
+ 5
70
+ );
71
+
72
+ expect( result ).toEqual( { foo: { bar: { baz: 5 } } } );
73
+ } );
74
+
75
+ it( 'keeps other properties intact', () => {
76
+ const result = immutableSet(
77
+ { foo: { bar: { baz: 1 } } },
78
+ [ 'foo', 'bar', 'test' ],
79
+ 5
80
+ );
81
+
82
+ expect( result ).toEqual( {
83
+ foo: { bar: { baz: 1, test: 5 } },
84
+ } );
85
+ } );
86
+ } );
87
+
88
+ describe( 'for nested falsey values', () => {
89
+ it( 'overwrites undefined values', () => {
90
+ const result = immutableSet( { test: undefined }, 'test', 1 );
91
+
92
+ expect( result ).toEqual( { test: 1 } );
93
+ } );
94
+
95
+ it( 'overwrites null values', () => {
96
+ const result = immutableSet( { test: null }, 'test', 1 );
97
+
98
+ expect( result ).toEqual( { test: 1 } );
99
+ } );
100
+
101
+ it( 'overwrites false values', () => {
102
+ const result = immutableSet( { test: false }, 'test', 1 );
103
+
104
+ expect( result ).toEqual( { test: 1 } );
105
+ } );
106
+
107
+ it( 'overwrites `0` values', () => {
108
+ const result = immutableSet( { test: 0 }, 'test', 1 );
109
+
110
+ expect( result ).toEqual( { test: 1 } );
111
+ } );
112
+
113
+ it( 'overwrites empty string values', () => {
114
+ const result = immutableSet( { test: '' }, 'test', 1 );
115
+
116
+ expect( result ).toEqual( { test: 1 } );
117
+ } );
118
+
119
+ it( 'overwrites NaN values', () => {
120
+ const result = immutableSet( { test: NaN }, 'test', 1 );
121
+
122
+ expect( result ).toEqual( { test: 1 } );
123
+ } );
124
+ } );
125
+ } );
126
+
127
+ describe( 'does not mutate the original object', () => {
128
+ it( 'clones the object at the first level', () => {
129
+ const input = {};
130
+ const result = immutableSet( input, 'test', 1 );
131
+
132
+ expect( result ).not.toBe( input );
133
+ } );
134
+
135
+ it( 'clones the object at deeper levels', () => {
136
+ const input = { foo: { bar: { baz: 1 } } };
137
+ const result = immutableSet( input, [ 'foo', 'bar', 'baz' ], 2 );
138
+
139
+ expect( result ).not.toBe( input );
140
+ expect( result.foo ).not.toBe( input.foo );
141
+ expect( result.foo.bar ).not.toBe( input.foo.bar );
142
+ expect( result.foo.bar.baz ).not.toBe( input.foo.bar.baz );
143
+ } );
144
+ } );
145
+ } );