@wordpress/block-editor 11.7.0 → 12.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 (357) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +56 -57
  3. package/build/components/block-info-slot-fill/index.js +47 -0
  4. package/build/components/block-info-slot-fill/index.js.map +1 -0
  5. package/build/components/block-inspector/index.js +4 -2
  6. package/build/components/block-inspector/index.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-settings-menu/block-settings-dropdown.js +1 -10
  14. package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  15. package/build/components/block-toolbar/index.js +2 -1
  16. package/build/components/block-toolbar/index.js.map +1 -1
  17. package/build/components/block-tools/block-contextual-toolbar.js +83 -9
  18. package/build/components/block-tools/block-contextual-toolbar.js.map +1 -1
  19. package/build/components/block-tools/selected-block-popover.js +11 -28
  20. package/build/components/block-tools/selected-block-popover.js.map +1 -1
  21. package/build/components/caption/index.native.js +0 -1
  22. package/build/components/caption/index.native.js.map +1 -1
  23. package/build/components/date-format-picker/index.js +1 -1
  24. package/build/components/date-format-picker/index.js.map +1 -1
  25. package/build/components/editor-styles/index.js +4 -3
  26. package/build/components/editor-styles/index.js.map +1 -1
  27. package/build/components/font-sizes/fluid-utils.js +21 -14
  28. package/build/components/font-sizes/fluid-utils.js.map +1 -1
  29. package/build/components/global-styles/border-panel.js +15 -59
  30. package/build/components/global-styles/border-panel.js.map +1 -1
  31. package/build/components/global-styles/color-panel.js +12 -12
  32. package/build/components/global-styles/color-panel.js.map +1 -1
  33. package/build/components/global-styles/color-panel.native.js +174 -0
  34. package/build/components/global-styles/color-panel.native.js.map +1 -0
  35. package/build/components/global-styles/dimensions-panel.js +21 -20
  36. package/build/components/global-styles/dimensions-panel.js.map +1 -1
  37. package/build/components/global-styles/effects-panel.js +244 -0
  38. package/build/components/global-styles/effects-panel.js.map +1 -0
  39. package/build/components/global-styles/filters-panel.js +215 -0
  40. package/build/components/global-styles/filters-panel.js.map +1 -0
  41. package/build/components/global-styles/get-block-css-selector.js +1 -12
  42. package/build/components/global-styles/get-block-css-selector.js.map +1 -1
  43. package/build/components/global-styles/hooks.js +7 -0
  44. package/build/components/global-styles/hooks.js.map +1 -1
  45. package/build/components/global-styles/index.js +28 -0
  46. package/build/components/global-styles/index.js.map +1 -1
  47. package/build/components/global-styles/typography-panel.js +9 -9
  48. package/build/components/global-styles/typography-panel.js.map +1 -1
  49. package/build/components/global-styles/use-global-styles-output.js +100 -82
  50. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  51. package/build/components/iframe/index.js +1 -1
  52. package/build/components/iframe/index.js.map +1 -1
  53. package/build/components/image-size-control/use-dimension-handler.js +5 -3
  54. package/build/components/image-size-control/use-dimension-handler.js.map +1 -1
  55. package/build/components/index.js +23 -0
  56. package/build/components/index.js.map +1 -1
  57. package/build/components/inserter/block-patterns-tab.js +4 -2
  58. package/build/components/inserter/block-patterns-tab.js.map +1 -1
  59. package/build/components/inserter/block-types-tab.js +12 -7
  60. package/build/components/inserter/block-types-tab.js.map +1 -1
  61. package/build/components/inserter/index.js +2 -1
  62. package/build/components/inserter/index.js.map +1 -1
  63. package/build/components/inspector-controls/groups.js +2 -0
  64. package/build/components/inspector-controls/groups.js.map +1 -1
  65. package/build/components/inspector-controls-tabs/styles-tab.js +2 -0
  66. package/build/components/inspector-controls-tabs/styles-tab.js.map +1 -1
  67. package/build/components/inspector-controls-tabs/utils.js +5 -3
  68. package/build/components/inspector-controls-tabs/utils.js.map +1 -1
  69. package/build/components/list-view/block-select-button.js +7 -2
  70. package/build/components/list-view/block-select-button.js.map +1 -1
  71. package/build/components/list-view/block.js +13 -21
  72. package/build/components/list-view/block.js.map +1 -1
  73. package/build/components/list-view/drop-indicator.js +37 -10
  74. package/build/components/list-view/drop-indicator.js.map +1 -1
  75. package/build/components/list-view/index.js +31 -7
  76. package/build/components/list-view/index.js.map +1 -1
  77. package/build/components/list-view/leaf.js +2 -1
  78. package/build/components/list-view/leaf.js.map +1 -1
  79. package/build/components/list-view/use-block-selection.js +1 -1
  80. package/build/components/list-view/use-block-selection.js.map +1 -1
  81. package/build/components/list-view/use-list-view-client-ids.js +7 -3
  82. package/build/components/list-view/use-list-view-client-ids.js.map +1 -1
  83. package/build/components/list-view/use-list-view-drop-zone.js +8 -2
  84. package/build/components/list-view/use-list-view-drop-zone.js.map +1 -1
  85. package/build/components/media-replace-flow/index.js +5 -5
  86. package/build/components/media-replace-flow/index.js.map +1 -1
  87. package/build/components/navigable-toolbar/index.js +12 -4
  88. package/build/components/navigable-toolbar/index.js.map +1 -1
  89. package/build/components/off-canvas-editor/appender.js +2 -7
  90. package/build/components/off-canvas-editor/appender.js.map +1 -1
  91. package/build/components/off-canvas-editor/block-contents.js +6 -1
  92. package/build/components/off-canvas-editor/block-contents.js.map +1 -1
  93. package/build/components/off-canvas-editor/index.js +17 -14
  94. package/build/components/off-canvas-editor/index.js.map +1 -1
  95. package/build/components/resizable-box-popover/index.js +38 -0
  96. package/build/components/resizable-box-popover/index.js.map +1 -0
  97. package/build/components/rich-text/index.js +0 -1
  98. package/build/components/rich-text/index.js.map +1 -1
  99. package/build/components/rich-text/index.native.js +7 -11
  100. package/build/components/rich-text/index.native.js.map +1 -1
  101. package/build/components/spacing-sizes-control/spacing-input-control.js +8 -0
  102. package/build/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
  103. package/build/hooks/anchor.js +1 -1
  104. package/build/hooks/anchor.js.map +1 -1
  105. package/build/hooks/border.js +1 -1
  106. package/build/hooks/border.js.map +1 -1
  107. package/build/hooks/duotone.js +121 -70
  108. package/build/hooks/duotone.js.map +1 -1
  109. package/build/hooks/margin.js +27 -17
  110. package/build/hooks/margin.js.map +1 -1
  111. package/build/hooks/padding.js +19 -9
  112. package/build/hooks/padding.js.map +1 -1
  113. package/build/hooks/utils.js +22 -7
  114. package/build/hooks/utils.js.map +1 -1
  115. package/build/layouts/utils.js +3 -2
  116. package/build/layouts/utils.js.map +1 -1
  117. package/build/private-apis.js +13 -1
  118. package/build/private-apis.js.map +1 -1
  119. package/build/store/actions.js +8 -1
  120. package/build/store/actions.js.map +1 -1
  121. package/build/utils/object.js +6 -6
  122. package/build/utils/object.js.map +1 -1
  123. package/build/utils/transform-styles/index.js +2 -2
  124. package/build/utils/transform-styles/index.js.map +1 -1
  125. package/build/utils/use-should-contextual-toolbar-show.js +68 -0
  126. package/build/utils/use-should-contextual-toolbar-show.js.map +1 -0
  127. package/build-module/components/block-info-slot-fill/index.js +34 -0
  128. package/build-module/components/block-info-slot-fill/index.js.map +1 -0
  129. package/build-module/components/block-inspector/index.js +3 -2
  130. package/build-module/components/block-inspector/index.js.map +1 -1
  131. package/build-module/components/block-list/index.native.js +11 -19
  132. package/build-module/components/block-list/index.native.js.map +1 -1
  133. package/build-module/components/block-list/use-in-between-inserter.js +2 -1
  134. package/build-module/components/block-list/use-in-between-inserter.js.map +1 -1
  135. package/build-module/components/block-popover/inbetween.js +2 -9
  136. package/build-module/components/block-popover/inbetween.js.map +1 -1
  137. package/build-module/components/block-settings-menu/block-settings-dropdown.js +1 -9
  138. package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  139. package/build-module/components/block-toolbar/index.js +2 -1
  140. package/build-module/components/block-toolbar/index.js.map +1 -1
  141. package/build-module/components/block-tools/block-contextual-toolbar.js +79 -9
  142. package/build-module/components/block-tools/block-contextual-toolbar.js.map +1 -1
  143. package/build-module/components/block-tools/selected-block-popover.js +10 -27
  144. package/build-module/components/block-tools/selected-block-popover.js.map +1 -1
  145. package/build-module/components/caption/index.native.js +0 -1
  146. package/build-module/components/caption/index.native.js.map +1 -1
  147. package/build-module/components/date-format-picker/index.js +1 -1
  148. package/build-module/components/date-format-picker/index.js.map +1 -1
  149. package/build-module/components/editor-styles/index.js +4 -3
  150. package/build-module/components/editor-styles/index.js.map +1 -1
  151. package/build-module/components/font-sizes/fluid-utils.js +21 -14
  152. package/build-module/components/font-sizes/fluid-utils.js.map +1 -1
  153. package/build-module/components/global-styles/border-panel.js +15 -59
  154. package/build-module/components/global-styles/border-panel.js.map +1 -1
  155. package/build-module/components/global-styles/color-panel.js +13 -13
  156. package/build-module/components/global-styles/color-panel.js.map +1 -1
  157. package/build-module/components/global-styles/color-panel.native.js +150 -0
  158. package/build-module/components/global-styles/color-panel.native.js.map +1 -0
  159. package/build-module/components/global-styles/dimensions-panel.js +22 -21
  160. package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
  161. package/build-module/components/global-styles/effects-panel.js +228 -0
  162. package/build-module/components/global-styles/effects-panel.js.map +1 -0
  163. package/build-module/components/global-styles/filters-panel.js +201 -0
  164. package/build-module/components/global-styles/filters-panel.js.map +1 -0
  165. package/build-module/components/global-styles/get-block-css-selector.js +1 -12
  166. package/build-module/components/global-styles/get-block-css-selector.js.map +1 -1
  167. package/build-module/components/global-styles/hooks.js +7 -0
  168. package/build-module/components/global-styles/hooks.js.map +1 -1
  169. package/build-module/components/global-styles/index.js +2 -0
  170. package/build-module/components/global-styles/index.js.map +1 -1
  171. package/build-module/components/global-styles/typography-panel.js +10 -10
  172. package/build-module/components/global-styles/typography-panel.js.map +1 -1
  173. package/build-module/components/global-styles/use-global-styles-output.js +101 -83
  174. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  175. package/build-module/components/iframe/index.js +1 -1
  176. package/build-module/components/iframe/index.js.map +1 -1
  177. package/build-module/components/image-size-control/use-dimension-handler.js +5 -3
  178. package/build-module/components/image-size-control/use-dimension-handler.js.map +1 -1
  179. package/build-module/components/index.js +1 -0
  180. package/build-module/components/index.js.map +1 -1
  181. package/build-module/components/inserter/block-patterns-tab.js +5 -2
  182. package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
  183. package/build-module/components/inserter/block-types-tab.js +12 -6
  184. package/build-module/components/inserter/block-types-tab.js.map +1 -1
  185. package/build-module/components/inserter/index.js +2 -1
  186. package/build-module/components/inserter/index.js.map +1 -1
  187. package/build-module/components/inspector-controls/groups.js +2 -0
  188. package/build-module/components/inspector-controls/groups.js.map +1 -1
  189. package/build-module/components/inspector-controls-tabs/styles-tab.js +2 -0
  190. package/build-module/components/inspector-controls-tabs/styles-tab.js.map +1 -1
  191. package/build-module/components/inspector-controls-tabs/utils.js +4 -3
  192. package/build-module/components/inspector-controls-tabs/utils.js.map +1 -1
  193. package/build-module/components/list-view/block-select-button.js +7 -2
  194. package/build-module/components/list-view/block-select-button.js.map +1 -1
  195. package/build-module/components/list-view/block.js +15 -22
  196. package/build-module/components/list-view/block.js.map +1 -1
  197. package/build-module/components/list-view/drop-indicator.js +36 -10
  198. package/build-module/components/list-view/drop-indicator.js.map +1 -1
  199. package/build-module/components/list-view/index.js +31 -8
  200. package/build-module/components/list-view/index.js.map +1 -1
  201. package/build-module/components/list-view/leaf.js +2 -1
  202. package/build-module/components/list-view/leaf.js.map +1 -1
  203. package/build-module/components/list-view/use-block-selection.js +1 -1
  204. package/build-module/components/list-view/use-block-selection.js.map +1 -1
  205. package/build-module/components/list-view/use-list-view-client-ids.js +7 -3
  206. package/build-module/components/list-view/use-list-view-client-ids.js.map +1 -1
  207. package/build-module/components/list-view/use-list-view-drop-zone.js +8 -4
  208. package/build-module/components/list-view/use-list-view-drop-zone.js.map +1 -1
  209. package/build-module/components/media-replace-flow/index.js +5 -5
  210. package/build-module/components/media-replace-flow/index.js.map +1 -1
  211. package/build-module/components/navigable-toolbar/index.js +12 -4
  212. package/build-module/components/navigable-toolbar/index.js.map +1 -1
  213. package/build-module/components/off-canvas-editor/appender.js +1 -5
  214. package/build-module/components/off-canvas-editor/appender.js.map +1 -1
  215. package/build-module/components/off-canvas-editor/block-contents.js +5 -1
  216. package/build-module/components/off-canvas-editor/block-contents.js.map +1 -1
  217. package/build-module/components/off-canvas-editor/index.js +17 -14
  218. package/build-module/components/off-canvas-editor/index.js.map +1 -1
  219. package/build-module/components/resizable-box-popover/index.js +26 -0
  220. package/build-module/components/resizable-box-popover/index.js.map +1 -0
  221. package/build-module/components/rich-text/index.js +0 -1
  222. package/build-module/components/rich-text/index.js.map +1 -1
  223. package/build-module/components/rich-text/index.native.js +7 -10
  224. package/build-module/components/rich-text/index.native.js.map +1 -1
  225. package/build-module/components/spacing-sizes-control/spacing-input-control.js +7 -0
  226. package/build-module/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
  227. package/build-module/hooks/anchor.js +1 -1
  228. package/build-module/hooks/anchor.js.map +1 -1
  229. package/build-module/hooks/border.js +1 -1
  230. package/build-module/hooks/border.js.map +1 -1
  231. package/build-module/hooks/duotone.js +118 -71
  232. package/build-module/hooks/duotone.js.map +1 -1
  233. package/build-module/hooks/margin.js +29 -18
  234. package/build-module/hooks/margin.js.map +1 -1
  235. package/build-module/hooks/padding.js +21 -10
  236. package/build-module/hooks/padding.js.map +1 -1
  237. package/build-module/hooks/utils.js +24 -9
  238. package/build-module/hooks/utils.js.map +1 -1
  239. package/build-module/layouts/utils.js +3 -2
  240. package/build-module/layouts/utils.js.map +1 -1
  241. package/build-module/private-apis.js +9 -1
  242. package/build-module/private-apis.js.map +1 -1
  243. package/build-module/store/actions.js +8 -1
  244. package/build-module/store/actions.js.map +1 -1
  245. package/build-module/utils/object.js +5 -5
  246. package/build-module/utils/object.js.map +1 -1
  247. package/build-module/utils/transform-styles/index.js +2 -2
  248. package/build-module/utils/transform-styles/index.js.map +1 -1
  249. package/build-module/utils/use-should-contextual-toolbar-show.js +56 -0
  250. package/build-module/utils/use-should-contextual-toolbar-show.js.map +1 -0
  251. package/build-style/content-rtl.css +9 -6
  252. package/build-style/content.css +9 -6
  253. package/build-style/style-rtl.css +272 -54
  254. package/build-style/style.css +272 -54
  255. package/package.json +32 -32
  256. package/src/components/block-info-slot-fill/index.js +24 -0
  257. package/src/components/block-inspector/index.js +3 -0
  258. package/src/components/block-inspector/style.scss +6 -4
  259. package/src/components/block-list/content.scss +16 -15
  260. package/src/components/block-list/index.native.js +19 -38
  261. package/src/components/block-list/use-in-between-inserter.js +4 -1
  262. package/src/components/block-mobile-toolbar/test/block-actions-menu.native.js +9 -9
  263. package/src/components/block-mover/style.scss +10 -4
  264. package/src/components/block-mover/test/index.native.js +4 -4
  265. package/src/components/block-popover/inbetween.js +2 -13
  266. package/src/components/block-settings-menu/block-settings-dropdown.js +2 -12
  267. package/src/components/block-toolbar/index.js +4 -3
  268. package/src/components/block-toolbar/style.scss +56 -33
  269. package/src/components/block-tools/block-contextual-toolbar.js +94 -11
  270. package/src/components/block-tools/selected-block-popover.js +11 -44
  271. package/src/components/block-tools/style.scss +157 -3
  272. package/src/components/caption/index.native.js +0 -1
  273. package/src/components/date-format-picker/index.js +1 -1
  274. package/src/components/editor-styles/index.js +9 -5
  275. package/src/components/font-sizes/fluid-utils.js +31 -14
  276. package/src/components/font-sizes/test/fluid-utils.js +5 -16
  277. package/src/components/global-styles/README.md +129 -16
  278. package/src/components/global-styles/border-panel.js +13 -61
  279. package/src/components/global-styles/color-panel.js +13 -13
  280. package/src/components/global-styles/color-panel.native.js +207 -0
  281. package/src/components/global-styles/dimensions-panel.js +47 -20
  282. package/src/components/global-styles/effects-panel.js +228 -0
  283. package/src/components/global-styles/filters-panel.js +230 -0
  284. package/src/components/global-styles/get-block-css-selector.js +0 -11
  285. package/src/components/global-styles/hooks.js +10 -0
  286. package/src/components/global-styles/index.js +2 -0
  287. package/src/components/global-styles/style.scss +43 -0
  288. package/src/components/global-styles/test/typography-utils.js +63 -22
  289. package/src/components/global-styles/test/use-global-styles-output.js +130 -8
  290. package/src/components/global-styles/typography-panel.js +37 -11
  291. package/src/components/global-styles/use-global-styles-output.js +88 -72
  292. package/src/components/iframe/index.js +1 -1
  293. package/src/components/image-size-control/use-dimension-handler.js +4 -3
  294. package/src/components/index.js +5 -1
  295. package/src/components/inserter/block-patterns-tab.js +3 -1
  296. package/src/components/inserter/block-types-tab.js +9 -6
  297. package/src/components/inserter/index.js +1 -1
  298. package/src/components/inspector-controls/groups.js +2 -0
  299. package/src/components/inspector-controls-tabs/styles-tab.js +1 -0
  300. package/src/components/inspector-controls-tabs/utils.js +4 -3
  301. package/src/components/list-view/README.md +2 -0
  302. package/src/components/list-view/block-select-button.js +6 -1
  303. package/src/components/list-view/block.js +24 -31
  304. package/src/components/list-view/drop-indicator.js +67 -22
  305. package/src/components/list-view/index.js +26 -3
  306. package/src/components/list-view/leaf.js +1 -0
  307. package/src/components/list-view/style.scss +18 -4
  308. package/src/components/list-view/test/use-list-view-drop-zone.js +188 -0
  309. package/src/components/list-view/use-block-selection.js +1 -1
  310. package/src/components/list-view/use-list-view-client-ids.js +5 -3
  311. package/src/components/list-view/use-list-view-drop-zone.js +9 -3
  312. package/src/components/media-replace-flow/README.md +3 -2
  313. package/src/components/media-replace-flow/index.js +4 -5
  314. package/src/components/navigable-toolbar/index.js +12 -3
  315. package/src/components/off-canvas-editor/appender.js +1 -4
  316. package/src/components/off-canvas-editor/block-contents.js +4 -0
  317. package/src/components/off-canvas-editor/index.js +15 -11
  318. package/src/components/resizable-box-popover/index.js +27 -0
  319. package/src/components/rich-text/index.js +0 -1
  320. package/src/components/rich-text/index.native.js +2 -5
  321. package/src/components/spacing-sizes-control/spacing-input-control.js +10 -0
  322. package/src/components/spacing-sizes-control/style.scss +7 -7
  323. package/src/components/url-popover/test/__snapshots__/index.js.snap +3 -3
  324. package/src/hooks/anchor.js +1 -1
  325. package/src/hooks/border.js +1 -1
  326. package/src/hooks/duotone.js +162 -99
  327. package/src/hooks/margin.js +31 -26
  328. package/src/hooks/padding.js +24 -18
  329. package/src/hooks/test/anchor.js +113 -0
  330. package/src/hooks/test/color.js +0 -9
  331. package/src/hooks/test/use-typography-props.js +2 -2
  332. package/src/hooks/test/utils.js +20 -101
  333. package/src/hooks/utils.js +23 -6
  334. package/src/layouts/utils.js +2 -2
  335. package/src/private-apis.js +8 -0
  336. package/src/store/actions.js +8 -1
  337. package/src/style.scss +1 -0
  338. package/src/utils/object.js +5 -5
  339. package/src/utils/test/object.js +53 -15
  340. package/src/utils/transform-styles/index.js +2 -2
  341. package/src/utils/use-should-contextual-toolbar-show.js +75 -0
  342. package/tsconfig.json +1 -0
  343. package/build/components/rich-text/use-native-props.js +0 -11
  344. package/build/components/rich-text/use-native-props.js.map +0 -1
  345. package/build/components/rich-text/use-native-props.native.js +0 -24
  346. package/build/components/rich-text/use-native-props.native.js.map +0 -1
  347. package/build/hooks/color-panel.native.js +0 -77
  348. package/build/hooks/color-panel.native.js.map +0 -1
  349. package/build-module/components/rich-text/use-native-props.js +0 -4
  350. package/build-module/components/rich-text/use-native-props.js.map +0 -1
  351. package/build-module/components/rich-text/use-native-props.native.js +0 -15
  352. package/build-module/components/rich-text/use-native-props.native.js.map +0 -1
  353. package/build-module/hooks/color-panel.native.js +0 -62
  354. package/build-module/hooks/color-panel.native.js.map +0 -1
  355. package/src/components/rich-text/use-native-props.js +0 -3
  356. package/src/components/rich-text/use-native-props.native.js +0 -17
  357. package/src/hooks/color-panel.native.js +0 -63
@@ -14,9 +14,7 @@ import { useGlobalStylesReset } from '@wordpress/block-editor';
14
14
  function MyComponent() {
15
15
  const [ canReset, reset ] = useGlobalStylesReset();
16
16
 
17
- return canReset
18
- ? <Button onClick={ () => reset() }>Reset</Button>
19
- : null;
17
+ return canReset ? <Button onClick={ () => reset() }>Reset</Button> : null;
20
18
  }
21
19
  ```
22
20
 
@@ -25,17 +23,25 @@ function MyComponent() {
25
23
  A React hook used to retrieve the styles array and settings to provide for block editor instances based on the current global styles.
26
24
 
27
25
  ```js
28
- import { useGlobalStylesOutput, BlockEditorProvider, BlockList } from '@wordpress/block-editor';
26
+ import {
27
+ useGlobalStylesOutput,
28
+ BlockEditorProvider,
29
+ BlockList,
30
+ } from '@wordpress/block-editor';
29
31
 
30
32
  function MyComponent() {
31
33
  const [ styles, settings ] = useGlobalStylesOutput();
32
34
 
33
- return <BlockEditorProvider settings={{
34
- styles,
35
- __experimentalFeatures: settings
36
- }}>
37
- <BlockList />
38
- </BlockEditorProvider>
35
+ return (
36
+ <BlockEditorProvider
37
+ settings={ {
38
+ styles,
39
+ __experimentalFeatures: settings,
40
+ } }
41
+ >
42
+ <BlockList />
43
+ </BlockEditorProvider>
44
+ );
39
45
  }
40
46
  ```
41
47
 
@@ -48,12 +54,16 @@ import { useGlobalStyle } from '@wordpress/block-editor';
48
54
 
49
55
  function MyComponent() {
50
56
  // Text color for the site root.
51
- const [ color, setColor ] = useGlobalStyle( 'color.text' );
57
+ const [ color, setColor ] = useGlobalStyle( 'color.text' );
52
58
 
53
59
  // The user modified color for the core paragraph block.
54
- const [ pColor, setPColor ] = useGlobalStyle( 'color.text', 'core/paragraph', 'user' );
60
+ const [ pColor, setPColor ] = useGlobalStyle(
61
+ 'color.text',
62
+ 'core/paragraph',
63
+ 'user'
64
+ );
55
65
 
56
- return "Something";
66
+ return 'Something';
57
67
  }
58
68
  ```
59
69
 
@@ -66,12 +76,115 @@ import { useGlobalSetting } from '@wordpress/block-editor';
66
76
 
67
77
  function MyComponent() {
68
78
  // The theme color palette.
69
- const [ colorPalette, setColorPalette ] = useGlobalSetting( 'color.palette.theme' );
79
+ const [ colorPalette, setColorPalette ] = useGlobalSetting(
80
+ 'color.palette.theme'
81
+ );
70
82
 
71
83
  // The theme color palette for the paragraph block, ignoring user changes.
72
84
  // If the palette is not defined for the paragraph block, the root one is returned.
73
- const [ pColor, setPColor ] = useGlobalSetting( 'color.palette.theme', 'core/paragraph', 'base' );
85
+ const [ pColor, setPColor ] = useGlobalSetting(
86
+ 'color.palette.theme',
87
+ 'core/paragraph',
88
+ 'base'
89
+ );
74
90
 
75
- return "Something";
91
+ return 'Something';
76
92
  }
77
93
  ```
94
+
95
+ ## UI Components
96
+
97
+ The global styles folder also offers a set of reusable UI components. These components follow a strict set of guidelines:
98
+
99
+ - They are independent of any context or any store dependency. They only rely on the props passed to them.
100
+ - They receive a similar set of props:
101
+
102
+ - `value`: The value is a style object that maps closely the format used in `theme.json` and is also very close to the format of the `style` attributes for blocks. There are some differences with the block attributes due to the iteration process and the fact that we need to maintain compatibility with the existing blocks even if they predate the introduction of Global Styles and these UI components. An example value for a style object is:
103
+
104
+ ```js
105
+ {
106
+ color: {
107
+ text: 'var:preset|color|blue',
108
+ background: '#FF0000',
109
+ },
110
+ typography: {
111
+ fontFamily: 'var:preset|font-family|base',
112
+ fontSize: '10px',
113
+ lineHeight: 1.5,
114
+ },
115
+ spacing: {
116
+ padding: 'var:preset|spacing|medium',
117
+ },
118
+ elements: {
119
+ link: {
120
+ color: {
121
+ text: 'var:preset|color|green',
122
+ },
123
+ },
124
+ },
125
+ }
126
+ ```
127
+
128
+ - `onChange`: A callback that receives the new value and is called when the user changes the value of the UI component.
129
+ - `inheritedValue`: The inherited value is a style object that represents the combined value of the style inherited from the parent context in addition to the style applied to the current context. The format is the same as the `value` prop.
130
+ - `settings`: The settings are the theme.json settings. They are used to provide the UI components with the necessary information to render the UI. An example value for the settings is:
131
+
132
+ ```js
133
+ {
134
+ color: {
135
+ palette: {
136
+ custom: [
137
+ {
138
+ slug: 'black',
139
+ color: '#000000',
140
+ },
141
+ {
142
+ slug: 'white',
143
+ color: '#FFFFFF',
144
+ },
145
+ {
146
+ slug: 'blue',
147
+ color: '#0000FF',
148
+ },
149
+ ]
150
+ },
151
+ gradients: {
152
+ custom: [
153
+ {
154
+ slug: 'gradient-1',
155
+ gradient: 'linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)',
156
+ },
157
+ {
158
+ slug: 'gradient-2',
159
+ gradient: 'linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)',
160
+ },
161
+ ]
162
+ },
163
+ },
164
+ typography: {
165
+ fontSizes: [
166
+ {
167
+ slug: 'small',
168
+ size: '12px',
169
+ },
170
+ {
171
+ slug: 'medium',
172
+ size: '16px',
173
+ },
174
+ {
175
+ slug: 'large',
176
+ size: '24px',
177
+ },
178
+ ],
179
+ }
180
+ }
181
+ ```
182
+ - `defaultControls`: The default controls are the controls that are used by default to render the UI. They are used to provide the UI components with the necessary information to render the UI. An example value for the default controls for the `ColorPanel` component is:
183
+
184
+ ```js
185
+ {
186
+ background: true,
187
+ text: true,
188
+ link: true,
189
+ },
190
+ ```
@@ -45,35 +45,6 @@ function useHasBorderWidthControl( settings ) {
45
45
  return settings?.border?.width;
46
46
  }
47
47
 
48
- function applyFallbackStyle( border ) {
49
- if ( ! border ) {
50
- return border;
51
- }
52
-
53
- if ( ! border.style && ( border.color || border.width ) ) {
54
- return { ...border, style: 'solid' };
55
- }
56
-
57
- return border;
58
- }
59
-
60
- function applyAllFallbackStyles( border ) {
61
- if ( ! border ) {
62
- return border;
63
- }
64
-
65
- if ( hasSplitBorders( border ) ) {
66
- return {
67
- top: applyFallbackStyle( border.top ),
68
- right: applyFallbackStyle( border.right ),
69
- bottom: applyFallbackStyle( border.bottom ),
70
- left: applyFallbackStyle( border.left ),
71
- };
72
- }
73
-
74
- return applyFallbackStyle( border );
75
- }
76
-
77
48
  function BorderToolsPanel( {
78
49
  resetAllFilter,
79
50
  onChange,
@@ -186,39 +157,20 @@ export default function BorderPanel( {
186
157
  const onBorderChange = ( newBorder ) => {
187
158
  // Ensure we have a visible border style when a border width or
188
159
  // color is being selected.
189
- const newBorderWithStyle = applyAllFallbackStyles( newBorder );
190
-
191
- // As we can't conditionally generate styles based on if other
192
- // style properties have been set we need to force split border
193
- // definitions for user set border styles. Border radius is derived
194
- // from the same property i.e. `border.radius` if it is a string
195
- // that is used. The longhand border radii styles are only generated
196
- // if that property is an object.
197
- //
198
- // For borders (color, style, and width) those are all properties on
199
- // the `border` style property. This means if the theme.json defined
200
- // split borders and the user condenses them into a flat border or
201
- // vice-versa we'd get both sets of styles which would conflict.
202
- const updatedBorder = ! hasSplitBorders( newBorderWithStyle )
203
- ? {
204
- top: newBorderWithStyle,
205
- right: newBorderWithStyle,
206
- bottom: newBorderWithStyle,
207
- left: newBorderWithStyle,
208
- }
209
- : {
210
- color: null,
211
- style: null,
212
- width: null,
213
- ...newBorderWithStyle,
214
- };
160
+ const updatedBorder = { ...newBorder };
215
161
 
216
- [ 'top', 'right', 'bottom', 'left' ].forEach( ( side ) => {
217
- updatedBorder[ side ] = {
218
- ...updatedBorder[ side ],
219
- color: encodeColorValue( updatedBorder[ side ]?.color ),
220
- };
221
- } );
162
+ if ( hasSplitBorders( updatedBorder ) ) {
163
+ [ 'top', 'right', 'bottom', 'left' ].forEach( ( side ) => {
164
+ if ( updatedBorder[ side ] ) {
165
+ updatedBorder[ side ] = {
166
+ ...updatedBorder[ side ],
167
+ color: encodeColorValue( updatedBorder[ side ]?.color ),
168
+ };
169
+ }
170
+ } );
171
+ } else if ( updatedBorder ) {
172
+ updatedBorder.color = encodeColorValue( updatedBorder.color );
173
+ }
222
174
 
223
175
  // As radius is maintained separately to color, style, and width
224
176
  // maintain its value. Undefined values here will be cleaned when
@@ -28,7 +28,7 @@ import { __ } from '@wordpress/i18n';
28
28
  import ColorGradientControl from '../colors-gradients/control';
29
29
  import { useColorsPerOrigin, useGradientsPerOrigin } from './hooks';
30
30
  import { getValueFromVariable } from './utils';
31
- import { immutableSet } from '../../utils/object';
31
+ import { setImmutably } from '../../utils/object';
32
32
 
33
33
  export function useHasColorPanel( settings ) {
34
34
  const hasTextPanel = useHasTextPanel( settings );
@@ -330,7 +330,7 @@ export default function ColorPanel( {
330
330
  const hasTextColor = () => !! userTextColor;
331
331
  const setTextColor = ( newColor ) => {
332
332
  onChange(
333
- immutableSet(
333
+ setImmutably(
334
334
  value,
335
335
  [ 'color', 'text' ],
336
336
  encodeColorValue( newColor )
@@ -347,7 +347,7 @@ export default function ColorPanel( {
347
347
  const userGradient = decodeValue( value?.color?.gradient );
348
348
  const hasBackground = () => !! userBackgroundColor || !! userGradient;
349
349
  const setBackgroundColor = ( newColor ) => {
350
- const newValue = immutableSet(
350
+ const newValue = setImmutably(
351
351
  value,
352
352
  [ 'color', 'background' ],
353
353
  encodeColorValue( newColor )
@@ -356,7 +356,7 @@ export default function ColorPanel( {
356
356
  onChange( newValue );
357
357
  };
358
358
  const setGradient = ( newGradient ) => {
359
- const newValue = immutableSet(
359
+ const newValue = setImmutably(
360
360
  value,
361
361
  [ 'color', 'gradient' ],
362
362
  encodeGradientValue( newGradient )
@@ -365,7 +365,7 @@ export default function ColorPanel( {
365
365
  onChange( newValue );
366
366
  };
367
367
  const resetBackground = () => {
368
- const newValue = immutableSet(
368
+ const newValue = setImmutably(
369
369
  value,
370
370
  [ 'color', 'background' ],
371
371
  undefined
@@ -382,7 +382,7 @@ export default function ColorPanel( {
382
382
  const userLinkColor = decodeValue( value?.elements?.link?.color?.text );
383
383
  const setLinkColor = ( newColor ) => {
384
384
  onChange(
385
- immutableSet(
385
+ setImmutably(
386
386
  value,
387
387
  [ 'elements', 'link', 'color', 'text' ],
388
388
  encodeColorValue( newColor )
@@ -397,7 +397,7 @@ export default function ColorPanel( {
397
397
  );
398
398
  const setHoverLinkColor = ( newColor ) => {
399
399
  onChange(
400
- immutableSet(
400
+ setImmutably(
401
401
  value,
402
402
  [ 'elements', 'link', ':hover', 'color', 'text' ],
403
403
  encodeColorValue( newColor )
@@ -406,12 +406,12 @@ export default function ColorPanel( {
406
406
  };
407
407
  const hasLink = () => !! userLinkColor || !! userHoverLinkColor;
408
408
  const resetLink = () => {
409
- let newValue = immutableSet(
409
+ let newValue = setImmutably(
410
410
  value,
411
411
  [ 'elements', 'link', ':hover', 'color', 'text' ],
412
412
  undefined
413
413
  );
414
- newValue = immutableSet(
414
+ newValue = setImmutably(
415
415
  newValue,
416
416
  [ 'elements', 'link', 'color', 'text' ],
417
417
  undefined
@@ -591,7 +591,7 @@ export default function ColorPanel( {
591
591
  elementGradientUserColor
592
592
  );
593
593
  const resetElement = () => {
594
- const newValue = immutableSet(
594
+ const newValue = setImmutably(
595
595
  value,
596
596
  [ 'elements', name, 'color', 'background' ],
597
597
  undefined
@@ -603,7 +603,7 @@ export default function ColorPanel( {
603
603
 
604
604
  const setElementTextColor = ( newTextColor ) => {
605
605
  onChange(
606
- immutableSet(
606
+ setImmutably(
607
607
  value,
608
608
  [ 'elements', name, 'color', 'text' ],
609
609
  encodeColorValue( newTextColor )
@@ -611,7 +611,7 @@ export default function ColorPanel( {
611
611
  );
612
612
  };
613
613
  const setElementBackgroundColor = ( newBackgroundColor ) => {
614
- const newValue = immutableSet(
614
+ const newValue = setImmutably(
615
615
  value,
616
616
  [ 'elements', name, 'color', 'background' ],
617
617
  encodeColorValue( newBackgroundColor )
@@ -620,7 +620,7 @@ export default function ColorPanel( {
620
620
  onChange( newValue );
621
621
  };
622
622
  const setElementGradient = ( newGradient ) => {
623
- const newValue = immutableSet(
623
+ const newValue = setImmutably(
624
624
  value,
625
625
  [ 'elements', name, 'color', 'gradient' ],
626
626
  encodeGradientValue( newGradient )
@@ -0,0 +1,207 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useSelect } from '@wordpress/data';
5
+ import { useEffect, useState, useMemo, useCallback } from '@wordpress/element';
6
+ import { __ } from '@wordpress/i18n';
7
+ import { useGlobalStyles } from '@wordpress/components';
8
+ import { store as blockEditorStore } from '@wordpress/block-editor';
9
+
10
+ /**
11
+ * Internal dependencies
12
+ */
13
+ import PanelColorGradientSettings from '../colors-gradients/panel-color-gradient-settings';
14
+ import { useColorsPerOrigin, useGradientsPerOrigin } from './hooks';
15
+ import { getValueFromVariable } from './utils';
16
+ import { setImmutably } from '../../utils/object';
17
+ import ContrastChecker from '../contrast-checker';
18
+ import InspectorControls from '../inspector-controls';
19
+ import {
20
+ useHasColorPanel,
21
+ useHasTextPanel,
22
+ useHasBackgroundPanel,
23
+ } from './color-panel.js';
24
+
25
+ const ColorPanel = ( {
26
+ value,
27
+ inheritedValue = value,
28
+ onChange,
29
+ settings,
30
+ } ) => {
31
+ const colors = useColorsPerOrigin( settings );
32
+ const gradients = useGradientsPerOrigin( settings );
33
+ const globalStyles = useGlobalStyles();
34
+
35
+ const [ detectedBackgroundColor, setDetectedBackgroundColor ] = useState();
36
+ const [ detectedTextColor, setDetectedTextColor ] = useState();
37
+
38
+ const { baseGlobalStyles } = useSelect( ( select ) => {
39
+ const { getSettings } = select( blockEditorStore );
40
+ return {
41
+ baseGlobalStyles:
42
+ getSettings()?.__experimentalGlobalStylesBaseStyles?.color,
43
+ };
44
+ } );
45
+
46
+ const decodeValue = ( rawValue ) =>
47
+ getValueFromVariable( { settings }, '', rawValue );
48
+ const encodeColorValue = useCallback(
49
+ ( colorValue ) => {
50
+ const allColors = colors.flatMap(
51
+ ( { colors: originColors } ) => originColors
52
+ );
53
+ const colorObject = allColors.find(
54
+ ( { color } ) => color === colorValue
55
+ );
56
+ return colorObject
57
+ ? 'var:preset|color|' + colorObject.slug
58
+ : colorValue;
59
+ },
60
+ [ colors ]
61
+ );
62
+ const encodeGradientValue = useCallback(
63
+ ( gradientValue ) => {
64
+ const allGradients = gradients.flatMap(
65
+ ( { gradients: originGradients } ) => originGradients
66
+ );
67
+ const gradientObject = allGradients.find(
68
+ ( { gradient } ) => gradient === gradientValue
69
+ );
70
+ return gradientObject
71
+ ? 'var:preset|gradient|' + gradientObject.slug
72
+ : gradientValue;
73
+ },
74
+ [ gradients ]
75
+ );
76
+
77
+ // Text Color
78
+ const showTextPanel = useHasTextPanel( settings );
79
+ const textColor = decodeValue( inheritedValue?.color?.text );
80
+ const setTextColor = useCallback(
81
+ ( newColor ) => {
82
+ onChange(
83
+ setImmutably(
84
+ value,
85
+ [ 'color', 'text' ],
86
+ encodeColorValue( newColor )
87
+ )
88
+ );
89
+ },
90
+ [ encodeColorValue, onChange, value ]
91
+ );
92
+ const resetTextColor = useCallback(
93
+ () => setTextColor( undefined ),
94
+ [ setTextColor ]
95
+ );
96
+
97
+ // BackgroundColor
98
+ const showBackgroundPanel = useHasBackgroundPanel( settings );
99
+ const backgroundColor = decodeValue( inheritedValue?.color?.background );
100
+ const gradient = decodeValue( inheritedValue?.color?.gradient );
101
+ const setBackgroundColor = useCallback(
102
+ ( newColor ) => {
103
+ const newValue = setImmutably(
104
+ value,
105
+ [ 'color', 'background' ],
106
+ encodeColorValue( newColor )
107
+ );
108
+ newValue.color.gradient = undefined;
109
+ onChange( newValue );
110
+ },
111
+ [ encodeColorValue, onChange, value ]
112
+ );
113
+ const setGradient = useCallback(
114
+ ( newGradient ) => {
115
+ const newValue = setImmutably(
116
+ value,
117
+ [ 'color', 'gradient' ],
118
+ encodeGradientValue( newGradient )
119
+ );
120
+ newValue.color.background = undefined;
121
+ onChange( newValue );
122
+ },
123
+ [ encodeGradientValue, onChange, value ]
124
+ );
125
+ const resetBackground = useCallback( () => {
126
+ const newValue = setImmutably(
127
+ value,
128
+ [ 'color', 'background' ],
129
+ undefined
130
+ );
131
+ newValue.color.gradient = undefined;
132
+ onChange( newValue );
133
+ }, [ onChange, value ] );
134
+ const currentGradients = settings?.color?.gradients;
135
+ const withoutGradientsSupport =
136
+ Array.isArray( currentGradients ) && currentGradients.length === 0;
137
+
138
+ const items = useMemo(
139
+ () =>
140
+ [
141
+ showTextPanel && {
142
+ label: __( 'Text' ),
143
+ colorValue: textColor,
144
+ onColorChange: setTextColor,
145
+ onColorCleared: resetTextColor,
146
+ },
147
+ showBackgroundPanel && {
148
+ label: __( 'Background' ),
149
+ colorValue: backgroundColor,
150
+ onColorChange: setBackgroundColor,
151
+ onColorCleared: resetBackground,
152
+ onGradientChange: ! withoutGradientsSupport
153
+ ? setGradient
154
+ : undefined,
155
+ gradientValue: gradient,
156
+ },
157
+ ].filter( Boolean ),
158
+ [
159
+ backgroundColor,
160
+ gradient,
161
+ resetBackground,
162
+ resetTextColor,
163
+ setBackgroundColor,
164
+ setGradient,
165
+ setTextColor,
166
+ showBackgroundPanel,
167
+ showTextPanel,
168
+ textColor,
169
+ withoutGradientsSupport,
170
+ ]
171
+ );
172
+
173
+ useEffect( () => {
174
+ // The following logic is used to determine current text/background colors:
175
+ // 1. The globalStyles object is queried to determine whether a color has been
176
+ // set via a block's settings.
177
+ // 2. If a block-based theme is in use and no globalStyles exist, the theme's
178
+ // default/base colors are used.
179
+ // 3. If no globalStyles exist and a theme isn't block-based, there is no way
180
+ // to determine the default text/background color and the checker won't run.
181
+ const currentDetectedTextColor =
182
+ globalStyles?.color || baseGlobalStyles?.text;
183
+ const currentDetectedBackgroundColor =
184
+ globalStyles?.backgroundColor || baseGlobalStyles?.background;
185
+
186
+ setDetectedTextColor( currentDetectedTextColor );
187
+ setDetectedBackgroundColor( currentDetectedBackgroundColor );
188
+ }, [ globalStyles, baseGlobalStyles ] );
189
+
190
+ return (
191
+ <InspectorControls>
192
+ <PanelColorGradientSettings
193
+ title={ __( 'Color' ) }
194
+ initialOpen={ false }
195
+ settings={ items }
196
+ >
197
+ <ContrastChecker
198
+ backgroundColor={ detectedBackgroundColor }
199
+ textColor={ detectedTextColor }
200
+ />
201
+ </PanelColorGradientSettings>
202
+ </InspectorControls>
203
+ );
204
+ };
205
+
206
+ export { useHasColorPanel };
207
+ export default ColorPanel;