@wordpress/block-editor 8.5.7 → 9.1.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 (462) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +5 -2
  3. package/build/components/block-alignment-control/constants.js +48 -0
  4. package/build/components/block-alignment-control/constants.js.map +1 -0
  5. package/build/components/block-alignment-control/ui.js +9 -40
  6. package/build/components/block-alignment-control/ui.js.map +1 -1
  7. package/build/components/block-alignment-control/ui.native.js +92 -0
  8. package/build/components/block-alignment-control/ui.native.js.map +1 -0
  9. package/build/components/block-alignment-matrix-control/index.js +1 -6
  10. package/build/components/block-alignment-matrix-control/index.js.map +1 -1
  11. package/build/components/block-content-overlay/index.js +5 -74
  12. package/build/components/block-content-overlay/index.js.map +1 -1
  13. package/build/components/block-draggable/draggable-chip.native.js +64 -0
  14. package/build/components/block-draggable/draggable-chip.native.js.map +1 -0
  15. package/build/components/block-draggable/dropping-insertion-point.native.js +157 -0
  16. package/build/components/block-draggable/dropping-insertion-point.native.js.map +1 -0
  17. package/build/components/block-draggable/index.native.js +484 -0
  18. package/build/components/block-draggable/index.native.js.map +1 -0
  19. package/build/components/block-draggable/use-scroll-when-dragging.native.js +130 -0
  20. package/build/components/block-draggable/use-scroll-when-dragging.native.js.map +1 -0
  21. package/build/components/block-list/block-list-context.native.js +195 -0
  22. package/build/components/block-list/block-list-context.native.js.map +1 -0
  23. package/build/components/block-list/block-list-item-cell.native.js +67 -0
  24. package/build/components/block-list/block-list-item-cell.native.js.map +1 -0
  25. package/build/components/block-list/block-list-item.native.js +12 -9
  26. package/build/components/block-list/block-list-item.native.js.map +1 -1
  27. package/build/components/block-list/block.native.js +29 -6
  28. package/build/components/block-list/block.native.js.map +1 -1
  29. package/build/components/block-list/index.native.js +75 -23
  30. package/build/components/block-list/index.native.js.map +1 -1
  31. package/build/components/block-list/use-block-props/index.js +8 -4
  32. package/build/components/block-list/use-block-props/index.js.map +1 -1
  33. package/build/components/block-list/use-block-props/use-block-class-names.js +1 -7
  34. package/build/components/block-list/use-block-props/use-block-class-names.js.map +1 -1
  35. package/build/components/block-list/use-in-between-inserter.js +1 -1
  36. package/build/components/block-list/use-in-between-inserter.js.map +1 -1
  37. package/build/components/block-lock/modal.js +34 -4
  38. package/build/components/block-lock/modal.js.map +1 -1
  39. package/build/components/block-lock/toolbar.js +2 -1
  40. package/build/components/block-lock/toolbar.js.map +1 -1
  41. package/build/components/block-lock/use-block-lock.js +4 -1
  42. package/build/components/block-lock/use-block-lock.js.map +1 -1
  43. package/build/components/block-mobile-toolbar/index.native.js +9 -3
  44. package/build/components/block-mobile-toolbar/index.native.js.map +1 -1
  45. package/build/components/block-mover/button.js +4 -4
  46. package/build/components/block-mover/button.js.map +1 -1
  47. package/build/components/block-mover/index.js +39 -65
  48. package/build/components/block-mover/index.js.map +1 -1
  49. package/build/components/block-mover/index.native.js +17 -4
  50. package/build/components/block-mover/index.native.js.map +1 -1
  51. package/build/components/block-navigation/dropdown.js +11 -5
  52. package/build/components/block-navigation/dropdown.js.map +1 -1
  53. package/build/components/block-popover/inbetween.js +191 -0
  54. package/build/components/block-popover/inbetween.js.map +1 -0
  55. package/build/components/block-popover/index.js +85 -0
  56. package/build/components/block-popover/index.js.map +1 -0
  57. package/build/components/{block-tools → block-popover}/use-popover-scroll.js +4 -1
  58. package/build/components/block-popover/use-popover-scroll.js.map +1 -0
  59. package/build/components/block-preview/index.js +1 -1
  60. package/build/components/block-preview/index.js.map +1 -1
  61. package/build/components/block-styles/index.js +1 -10
  62. package/build/components/block-styles/index.js.map +1 -1
  63. package/build/components/block-tools/back-compat.js +2 -2
  64. package/build/components/block-tools/back-compat.js.map +1 -1
  65. package/build/components/block-tools/block-selection-button.js +4 -2
  66. package/build/components/block-tools/block-selection-button.js.map +1 -1
  67. package/build/components/block-tools/index.js +5 -5
  68. package/build/components/block-tools/index.js.map +1 -1
  69. package/build/components/block-tools/insertion-point.js +14 -121
  70. package/build/components/block-tools/insertion-point.js.map +1 -1
  71. package/build/components/block-tools/selected-block-popover.js +216 -0
  72. package/build/components/block-tools/selected-block-popover.js.map +1 -0
  73. package/build/components/border-radius-control/input-controls.js +10 -3
  74. package/build/components/border-radius-control/input-controls.js.map +1 -1
  75. package/build/components/color-style-selector/index.js +9 -0
  76. package/build/components/color-style-selector/index.js.map +1 -1
  77. package/build/components/colors-gradients/dropdown.js +149 -44
  78. package/build/components/colors-gradients/dropdown.js.map +1 -1
  79. package/build/components/duotone-control/index.js +5 -1
  80. package/build/components/duotone-control/index.js.map +1 -1
  81. package/build/components/image-editor/use-save-image.js +3 -1
  82. package/build/components/image-editor/use-save-image.js.map +1 -1
  83. package/build/components/index.js +5 -23
  84. package/build/components/index.js.map +1 -1
  85. package/build/components/inserter/index.native.js +31 -9
  86. package/build/components/inserter/index.native.js.map +1 -1
  87. package/build/components/link-control/constants.js +11 -1
  88. package/build/components/link-control/constants.js.map +1 -1
  89. package/build/components/link-control/search-results.js +4 -3
  90. package/build/components/link-control/search-results.js.map +1 -1
  91. package/build/components/link-control/use-search-handler.js +4 -4
  92. package/build/components/link-control/use-search-handler.js.map +1 -1
  93. package/build/components/list-view/block.js +15 -15
  94. package/build/components/list-view/block.js.map +1 -1
  95. package/build/components/list-view/branch.js +9 -13
  96. package/build/components/list-view/branch.js.map +1 -1
  97. package/build/components/list-view/context.js +1 -4
  98. package/build/components/list-view/context.js.map +1 -1
  99. package/build/components/list-view/drop-indicator.js +0 -1
  100. package/build/components/list-view/drop-indicator.js.map +1 -1
  101. package/build/components/list-view/index.js +15 -32
  102. package/build/components/list-view/index.js.map +1 -1
  103. package/build/components/navigable-toolbar/index.js +12 -2
  104. package/build/components/navigable-toolbar/index.js.map +1 -1
  105. package/build/components/rich-text/format-toolbar-container.js +0 -1
  106. package/build/components/rich-text/format-toolbar-container.js.map +1 -1
  107. package/build/components/rich-text/index.js +1 -6
  108. package/build/components/rich-text/index.js.map +1 -1
  109. package/build/components/rich-text/index.native.js +0 -4
  110. package/build/components/rich-text/index.native.js.map +1 -1
  111. package/build/components/url-input/index.js +11 -4
  112. package/build/components/url-input/index.js.map +1 -1
  113. package/build/components/use-block-display-information/index.js +3 -1
  114. package/build/components/use-block-display-information/index.js.map +1 -1
  115. package/build/components/use-block-drop-zone/index.native.js +167 -0
  116. package/build/components/use-block-drop-zone/index.native.js.map +1 -0
  117. package/build/components/use-on-block-drop/index.native.js +95 -0
  118. package/build/components/use-on-block-drop/index.native.js.map +1 -0
  119. package/build/components/use-setting/index.js +42 -18
  120. package/build/components/use-setting/index.js.map +1 -1
  121. package/build/hooks/anchor.js.map +1 -1
  122. package/build/hooks/border.js +463 -44
  123. package/build/hooks/border.js.map +1 -1
  124. package/build/hooks/color-panel.js +14 -7
  125. package/build/hooks/color-panel.js.map +1 -1
  126. package/build/hooks/dimensions.js +2 -2
  127. package/build/hooks/dimensions.js.map +1 -1
  128. package/build/hooks/index.js +3 -1
  129. package/build/hooks/index.js.map +1 -1
  130. package/build/hooks/margin.js +64 -12
  131. package/build/hooks/margin.js.map +1 -1
  132. package/build/hooks/padding.js +60 -12
  133. package/build/hooks/padding.js.map +1 -1
  134. package/build/hooks/settings.js +32 -0
  135. package/build/hooks/settings.js.map +1 -0
  136. package/build/hooks/style.js +14 -13
  137. package/build/hooks/style.js.map +1 -1
  138. package/build/hooks/typography.js +6 -2
  139. package/build/hooks/typography.js.map +1 -1
  140. package/build/hooks/use-border-props.js +22 -32
  141. package/build/hooks/use-border-props.js.map +1 -1
  142. package/build/store/actions.js +14 -2
  143. package/build/store/actions.js.map +1 -1
  144. package/build/store/defaults.js +0 -1
  145. package/build/store/defaults.js.map +1 -1
  146. package/build/store/reducer.js +0 -26
  147. package/build/store/reducer.js.map +1 -1
  148. package/build/store/selectors.js +47 -15
  149. package/build/store/selectors.js.map +1 -1
  150. package/build-module/components/block-alignment-control/constants.js +36 -0
  151. package/build-module/components/block-alignment-control/constants.js.map +1 -0
  152. package/build-module/components/block-alignment-control/ui.js +4 -35
  153. package/build-module/components/block-alignment-control/ui.js.map +1 -1
  154. package/build-module/components/block-alignment-control/ui.native.js +78 -0
  155. package/build-module/components/block-alignment-control/ui.native.js.map +1 -0
  156. package/build-module/components/block-alignment-matrix-control/index.js +1 -6
  157. package/build-module/components/block-alignment-matrix-control/index.js.map +1 -1
  158. package/build-module/components/block-content-overlay/index.js +4 -70
  159. package/build-module/components/block-content-overlay/index.js.map +1 -1
  160. package/build-module/components/block-draggable/draggable-chip.native.js +50 -0
  161. package/build-module/components/block-draggable/draggable-chip.native.js.map +1 -0
  162. package/build-module/components/block-draggable/dropping-insertion-point.native.js +137 -0
  163. package/build-module/components/block-draggable/dropping-insertion-point.native.js.map +1 -0
  164. package/build-module/components/block-draggable/index.native.js +449 -0
  165. package/build-module/components/block-draggable/index.native.js.map +1 -0
  166. package/build-module/components/block-draggable/use-scroll-when-dragging.native.js +120 -0
  167. package/build-module/components/block-draggable/use-scroll-when-dragging.native.js.map +1 -0
  168. package/build-module/components/block-list/block-list-context.native.js +179 -0
  169. package/build-module/components/block-list/block-list-context.native.js.map +1 -0
  170. package/build-module/components/block-list/block-list-item-cell.native.js +59 -0
  171. package/build-module/components/block-list/block-list-item-cell.native.js.map +1 -0
  172. package/build-module/components/block-list/block-list-item.native.js +12 -9
  173. package/build-module/components/block-list/block-list-item.native.js.map +1 -1
  174. package/build-module/components/block-list/block.native.js +28 -6
  175. package/build-module/components/block-list/block.native.js.map +1 -1
  176. package/build-module/components/block-list/index.native.js +72 -23
  177. package/build-module/components/block-list/index.native.js.map +1 -1
  178. package/build-module/components/block-list/use-block-props/index.js +9 -5
  179. package/build-module/components/block-list/use-block-props/index.js.map +1 -1
  180. package/build-module/components/block-list/use-block-props/use-block-class-names.js +1 -7
  181. package/build-module/components/block-list/use-block-props/use-block-class-names.js.map +1 -1
  182. package/build-module/components/block-list/use-in-between-inserter.js +1 -1
  183. package/build-module/components/block-list/use-in-between-inserter.js.map +1 -1
  184. package/build-module/components/block-lock/modal.js +34 -5
  185. package/build-module/components/block-lock/modal.js.map +1 -1
  186. package/build-module/components/block-lock/toolbar.js +2 -1
  187. package/build-module/components/block-lock/toolbar.js.map +1 -1
  188. package/build-module/components/block-lock/use-block-lock.js +4 -1
  189. package/build-module/components/block-lock/use-block-lock.js.map +1 -1
  190. package/build-module/components/block-mobile-toolbar/index.native.js +8 -3
  191. package/build-module/components/block-mobile-toolbar/index.native.js.map +1 -1
  192. package/build-module/components/block-mover/button.js +5 -5
  193. package/build-module/components/block-mover/button.js.map +1 -1
  194. package/build-module/components/block-mover/index.js +38 -63
  195. package/build-module/components/block-mover/index.js.map +1 -1
  196. package/build-module/components/block-mover/index.native.js +18 -5
  197. package/build-module/components/block-mover/index.native.js.map +1 -1
  198. package/build-module/components/block-navigation/dropdown.js +10 -5
  199. package/build-module/components/block-navigation/dropdown.js.map +1 -1
  200. package/build-module/components/block-popover/inbetween.js +173 -0
  201. package/build-module/components/block-popover/inbetween.js.map +1 -0
  202. package/build-module/components/block-popover/index.js +72 -0
  203. package/build-module/components/block-popover/index.js.map +1 -0
  204. package/build-module/components/{block-tools → block-popover}/use-popover-scroll.js +3 -1
  205. package/build-module/components/block-popover/use-popover-scroll.js.map +1 -0
  206. package/build-module/components/block-preview/index.js +1 -1
  207. package/build-module/components/block-preview/index.js.map +1 -1
  208. package/build-module/components/block-styles/index.js +1 -9
  209. package/build-module/components/block-styles/index.js.map +1 -1
  210. package/build-module/components/block-tools/back-compat.js +1 -1
  211. package/build-module/components/block-tools/back-compat.js.map +1 -1
  212. package/build-module/components/block-tools/block-selection-button.js +3 -2
  213. package/build-module/components/block-tools/block-selection-button.js.map +1 -1
  214. package/build-module/components/block-tools/index.js +3 -3
  215. package/build-module/components/block-tools/index.js.map +1 -1
  216. package/build-module/components/block-tools/insertion-point.js +16 -121
  217. package/build-module/components/block-tools/insertion-point.js.map +1 -1
  218. package/build-module/components/block-tools/selected-block-popover.js +199 -0
  219. package/build-module/components/block-tools/selected-block-popover.js.map +1 -0
  220. package/build-module/components/border-radius-control/input-controls.js +11 -4
  221. package/build-module/components/border-radius-control/input-controls.js.map +1 -1
  222. package/build-module/components/color-style-selector/index.js +6 -0
  223. package/build-module/components/color-style-selector/index.js.map +1 -1
  224. package/build-module/components/colors-gradients/dropdown.js +151 -46
  225. package/build-module/components/colors-gradients/dropdown.js.map +1 -1
  226. package/build-module/components/duotone-control/index.js +4 -1
  227. package/build-module/components/duotone-control/index.js.map +1 -1
  228. package/build-module/components/image-editor/use-save-image.js +2 -1
  229. package/build-module/components/image-editor/use-save-image.js.map +1 -1
  230. package/build-module/components/index.js +1 -3
  231. package/build-module/components/index.js.map +1 -1
  232. package/build-module/components/inserter/index.native.js +32 -11
  233. package/build-module/components/inserter/index.native.js.map +1 -1
  234. package/build-module/components/link-control/constants.js +5 -0
  235. package/build-module/components/link-control/constants.js.map +1 -1
  236. package/build-module/components/link-control/search-results.js +3 -4
  237. package/build-module/components/link-control/search-results.js.map +1 -1
  238. package/build-module/components/link-control/use-search-handler.js +5 -5
  239. package/build-module/components/link-control/use-search-handler.js.map +1 -1
  240. package/build-module/components/list-view/block.js +15 -16
  241. package/build-module/components/list-view/block.js.map +1 -1
  242. package/build-module/components/list-view/branch.js +9 -13
  243. package/build-module/components/list-view/branch.js.map +1 -1
  244. package/build-module/components/list-view/context.js +1 -4
  245. package/build-module/components/list-view/context.js.map +1 -1
  246. package/build-module/components/list-view/drop-indicator.js +0 -1
  247. package/build-module/components/list-view/drop-indicator.js.map +1 -1
  248. package/build-module/components/list-view/index.js +15 -31
  249. package/build-module/components/list-view/index.js.map +1 -1
  250. package/build-module/components/navigable-toolbar/index.js +12 -2
  251. package/build-module/components/navigable-toolbar/index.js.map +1 -1
  252. package/build-module/components/rich-text/format-toolbar-container.js +0 -1
  253. package/build-module/components/rich-text/format-toolbar-container.js.map +1 -1
  254. package/build-module/components/rich-text/index.js +1 -5
  255. package/build-module/components/rich-text/index.js.map +1 -1
  256. package/build-module/components/rich-text/index.native.js +0 -4
  257. package/build-module/components/rich-text/index.native.js.map +1 -1
  258. package/build-module/components/url-input/index.js +11 -4
  259. package/build-module/components/url-input/index.js.map +1 -1
  260. package/build-module/components/use-block-display-information/index.js +3 -1
  261. package/build-module/components/use-block-display-information/index.js.map +1 -1
  262. package/build-module/components/use-block-drop-zone/index.native.js +148 -0
  263. package/build-module/components/use-block-drop-zone/index.native.js.map +1 -0
  264. package/build-module/components/use-on-block-drop/index.native.js +83 -0
  265. package/build-module/components/use-on-block-drop/index.native.js.map +1 -0
  266. package/build-module/components/use-setting/index.js +43 -19
  267. package/build-module/components/use-setting/index.js.map +1 -1
  268. package/build-module/hooks/anchor.js.map +1 -1
  269. package/build-module/hooks/border.js +453 -44
  270. package/build-module/hooks/border.js.map +1 -1
  271. package/build-module/hooks/color-panel.js +11 -6
  272. package/build-module/hooks/color-panel.js.map +1 -1
  273. package/build-module/hooks/dimensions.js +5 -5
  274. package/build-module/hooks/dimensions.js.map +1 -1
  275. package/build-module/hooks/index.js +2 -1
  276. package/build-module/hooks/index.js.map +1 -1
  277. package/build-module/hooks/margin.js +61 -13
  278. package/build-module/hooks/margin.js.map +1 -1
  279. package/build-module/hooks/padding.js +57 -13
  280. package/build-module/hooks/padding.js.map +1 -1
  281. package/build-module/hooks/settings.js +29 -0
  282. package/build-module/hooks/settings.js.map +1 -0
  283. package/build-module/hooks/style.js +15 -14
  284. package/build-module/hooks/style.js.map +1 -1
  285. package/build-module/hooks/typography.js +6 -2
  286. package/build-module/hooks/typography.js.map +1 -1
  287. package/build-module/hooks/use-border-props.js +21 -30
  288. package/build-module/hooks/use-border-props.js.map +1 -1
  289. package/build-module/store/actions.js +14 -2
  290. package/build-module/store/actions.js.map +1 -1
  291. package/build-module/store/defaults.js +0 -1
  292. package/build-module/store/defaults.js.map +1 -1
  293. package/build-module/store/reducer.js +0 -24
  294. package/build-module/store/reducer.js.map +1 -1
  295. package/build-module/store/selectors.js +44 -15
  296. package/build-module/store/selectors.js.map +1 -1
  297. package/build-style/style-rtl.css +148 -410
  298. package/build-style/style.css +148 -410
  299. package/package.json +28 -28
  300. package/src/components/block-alignment-control/constants.js +45 -0
  301. package/src/components/block-alignment-control/ui.js +69 -109
  302. package/src/components/block-alignment-control/ui.native.js +86 -0
  303. package/src/components/block-alignment-matrix-control/index.js +1 -5
  304. package/src/components/block-content-overlay/index.js +9 -79
  305. package/src/components/block-content-overlay/style.scss +2 -11
  306. package/src/components/block-draggable/draggable-chip.native.js +49 -0
  307. package/src/components/block-draggable/dropping-insertion-point.native.js +181 -0
  308. package/src/components/block-draggable/dropping-insertion-point.native.scss +8 -0
  309. package/src/components/block-draggable/index.native.js +458 -0
  310. package/src/components/block-draggable/style.native.scss +19 -0
  311. package/src/components/block-draggable/use-scroll-when-dragging.native.js +135 -0
  312. package/src/components/block-list/block-list-context.native.js +175 -0
  313. package/src/components/block-list/block-list-item-cell.native.js +49 -0
  314. package/src/components/block-list/block-list-item.native.js +7 -11
  315. package/src/components/block-list/block.native.js +38 -8
  316. package/src/components/block-list/index.native.js +54 -13
  317. package/src/components/block-list/style.scss +7 -18
  318. package/src/components/block-list/test/block-list-context.native.js +253 -0
  319. package/src/components/block-list/test/fixtures/block-list-context.native.js +79 -0
  320. package/src/components/block-list/use-block-props/index.js +10 -5
  321. package/src/components/block-list/use-block-props/use-block-class-names.js +1 -11
  322. package/src/components/block-list/use-in-between-inserter.js +1 -1
  323. package/src/components/block-lock/modal.js +42 -3
  324. package/src/components/block-lock/toolbar.js +2 -2
  325. package/src/components/block-lock/use-block-lock.js +4 -1
  326. package/src/components/block-mobile-toolbar/index.native.js +8 -1
  327. package/src/components/block-mover/button.js +5 -7
  328. package/src/components/block-mover/index.js +37 -60
  329. package/src/components/block-mover/index.native.js +22 -6
  330. package/src/components/block-mover/stories/index.js +110 -0
  331. package/src/components/block-mover/style.scss +48 -138
  332. package/src/components/block-mover/test/__snapshots__/index.native.js.snap +6 -0
  333. package/src/components/block-navigation/dropdown.js +12 -8
  334. package/src/components/block-popover/README.md +41 -0
  335. package/src/components/block-popover/inbetween.js +188 -0
  336. package/src/components/block-popover/index.js +75 -0
  337. package/src/components/block-popover/style.scss +28 -0
  338. package/src/components/{block-tools → block-popover}/use-popover-scroll.js +3 -1
  339. package/src/components/block-preview/index.js +1 -4
  340. package/src/components/block-styles/index.js +1 -12
  341. package/src/components/block-switcher/style.scss +2 -43
  342. package/src/components/block-toolbar/style.scss +0 -12
  343. package/src/components/block-tools/back-compat.js +1 -1
  344. package/src/components/block-tools/block-selection-button.js +3 -1
  345. package/src/components/block-tools/index.js +6 -4
  346. package/src/components/block-tools/insertion-point.js +19 -152
  347. package/src/components/block-tools/{block-popover.js → selected-block-popover.js} +24 -151
  348. package/src/components/block-tools/style.scss +12 -135
  349. package/src/components/border-radius-control/input-controls.js +16 -8
  350. package/src/components/border-radius-control/style.scss +7 -3
  351. package/src/components/color-palette/test/__snapshots__/control.js.snap +1 -1
  352. package/src/components/color-style-selector/index.js +18 -9
  353. package/src/components/colors-gradients/dropdown.js +156 -62
  354. package/src/components/colors-gradients/style.scss +51 -23
  355. package/src/components/default-block-appender/style.scss +1 -2
  356. package/src/components/duotone-control/index.js +8 -1
  357. package/src/components/duotone-control/style.scss +1 -7
  358. package/src/components/gradients/README.md +29 -0
  359. package/src/components/image-editor/use-save-image.js +2 -1
  360. package/src/components/image-size-control/README.md +1 -1
  361. package/src/components/index.js +1 -3
  362. package/src/components/inserter/index.native.js +60 -25
  363. package/src/components/inserter/style.native.scss +25 -3
  364. package/src/components/inserter/style.scss +2 -1
  365. package/src/components/link-control/constants.js +11 -0
  366. package/src/components/link-control/search-results.js +4 -5
  367. package/src/components/link-control/use-search-handler.js +11 -5
  368. package/src/components/list-view/block.js +24 -34
  369. package/src/components/list-view/branch.js +10 -20
  370. package/src/components/list-view/context.js +1 -4
  371. package/src/components/list-view/drop-indicator.js +0 -1
  372. package/src/components/list-view/index.js +11 -41
  373. package/src/components/list-view/style.scss +2 -1
  374. package/src/components/navigable-toolbar/README.md +16 -0
  375. package/src/components/navigable-toolbar/index.js +12 -2
  376. package/src/components/preview-options/style.scss +0 -4
  377. package/src/components/rich-text/format-toolbar-container.js +0 -1
  378. package/src/components/rich-text/index.js +1 -3
  379. package/src/components/rich-text/index.native.js +0 -4
  380. package/src/components/rich-text/style.scss +2 -8
  381. package/src/components/url-input/index.js +9 -4
  382. package/src/components/use-block-display-information/index.js +2 -0
  383. package/src/components/use-block-drop-zone/index.native.js +173 -0
  384. package/src/components/use-on-block-drop/index.native.js +119 -0
  385. package/src/components/use-setting/index.js +57 -21
  386. package/src/hooks/anchor.js +1 -1
  387. package/src/hooks/border.js +429 -72
  388. package/src/hooks/color-panel.js +13 -9
  389. package/src/hooks/color.scss +0 -62
  390. package/src/hooks/dimensions.js +44 -38
  391. package/src/hooks/index.js +2 -1
  392. package/src/hooks/margin.js +64 -15
  393. package/src/hooks/padding.js +60 -15
  394. package/src/hooks/padding.scss +12 -0
  395. package/src/hooks/settings.js +32 -0
  396. package/src/hooks/style.js +25 -39
  397. package/src/hooks/test/settings.js +48 -0
  398. package/src/hooks/typography.js +2 -0
  399. package/src/hooks/use-border-props.js +15 -32
  400. package/src/store/actions.js +14 -2
  401. package/src/store/defaults.js +0 -1
  402. package/src/store/reducer.js +0 -21
  403. package/src/store/selectors.js +46 -15
  404. package/src/store/test/actions.js +0 -18
  405. package/src/store/test/reducer.js +0 -19
  406. package/src/store/test/selectors.js +17 -19
  407. package/src/style.scss +2 -3
  408. package/tsconfig.tsbuildinfo +1 -1
  409. package/build/components/block-mobile-toolbar/index.js +0 -42
  410. package/build/components/block-mobile-toolbar/index.js.map +0 -1
  411. package/build/components/block-tools/block-popover.js +0 -327
  412. package/build/components/block-tools/block-popover.js.map +0 -1
  413. package/build/components/block-tools/use-popover-scroll.js.map +0 -1
  414. package/build/components/border-style-control/index.js +0 -60
  415. package/build/components/border-style-control/index.js.map +0 -1
  416. package/build/components/colors-gradients/tools-panel-color-dropdown.js +0 -89
  417. package/build/components/colors-gradients/tools-panel-color-dropdown.js.map +0 -1
  418. package/build/components/list-view/appender.js +0 -93
  419. package/build/components/list-view/appender.js.map +0 -1
  420. package/build/components/list-view/list-item.js +0 -62
  421. package/build/components/list-view/list-item.js.map +0 -1
  422. package/build/components/rich-text/use-caret-in-format.js +0 -43
  423. package/build/components/rich-text/use-caret-in-format.js.map +0 -1
  424. package/build/hooks/border-color.js +0 -302
  425. package/build/hooks/border-color.js.map +0 -1
  426. package/build/hooks/border-style.js +0 -96
  427. package/build/hooks/border-style.js.map +0 -1
  428. package/build/hooks/border-width.js +0 -162
  429. package/build/hooks/border-width.js.map +0 -1
  430. package/build-module/components/block-mobile-toolbar/index.js +0 -31
  431. package/build-module/components/block-mobile-toolbar/index.js.map +0 -1
  432. package/build-module/components/block-tools/block-popover.js +0 -306
  433. package/build-module/components/block-tools/block-popover.js.map +0 -1
  434. package/build-module/components/block-tools/use-popover-scroll.js.map +0 -1
  435. package/build-module/components/border-style-control/index.js +0 -50
  436. package/build-module/components/border-style-control/index.js.map +0 -1
  437. package/build-module/components/colors-gradients/tools-panel-color-dropdown.js +0 -75
  438. package/build-module/components/colors-gradients/tools-panel-color-dropdown.js.map +0 -1
  439. package/build-module/components/list-view/appender.js +0 -76
  440. package/build-module/components/list-view/appender.js.map +0 -1
  441. package/build-module/components/list-view/list-item.js +0 -47
  442. package/build-module/components/list-view/list-item.js.map +0 -1
  443. package/build-module/components/rich-text/use-caret-in-format.js +0 -33
  444. package/build-module/components/rich-text/use-caret-in-format.js.map +0 -1
  445. package/build-module/hooks/border-color.js +0 -276
  446. package/build-module/hooks/border-color.js.map +0 -1
  447. package/build-module/hooks/border-style.js +0 -78
  448. package/build-module/hooks/border-style.js.map +0 -1
  449. package/build-module/hooks/border-width.js +0 -143
  450. package/build-module/hooks/border-width.js.map +0 -1
  451. package/src/components/block-alignment-matrix-control/style.scss +0 -10
  452. package/src/components/block-mobile-toolbar/index.js +0 -24
  453. package/src/components/block-mobile-toolbar/style.scss +0 -29
  454. package/src/components/border-style-control/index.js +0 -47
  455. package/src/components/border-style-control/style.scss +0 -18
  456. package/src/components/colors-gradients/tools-panel-color-dropdown.js +0 -85
  457. package/src/components/list-view/appender.js +0 -82
  458. package/src/components/list-view/list-item.js +0 -59
  459. package/src/components/rich-text/use-caret-in-format.js +0 -28
  460. package/src/hooks/border-color.js +0 -315
  461. package/src/hooks/border-style.js +0 -64
  462. package/src/hooks/border-width.js +0 -139
@@ -7,7 +7,10 @@ import { get } from 'lodash';
7
7
  * WordPress dependencies
8
8
  */
9
9
  import { useSelect } from '@wordpress/data';
10
- import { __EXPERIMENTAL_PATHS_WITH_MERGE as PATHS_WITH_MERGE } from '@wordpress/blocks';
10
+ import {
11
+ __EXPERIMENTAL_PATHS_WITH_MERGE as PATHS_WITH_MERGE,
12
+ hasBlockSupport,
13
+ } from '@wordpress/blocks';
11
14
 
12
15
  /**
13
16
  * Internal dependencies
@@ -91,8 +94,10 @@ const removeCustomPrefixes = ( path ) => {
91
94
  };
92
95
 
93
96
  /**
94
- * Hook that retrieves the editor setting.
95
- * It works with nested objects using by finding the value at path.
97
+ * Hook that retrieves the given setting for the block instance in use.
98
+ *
99
+ * It looks up the settings first in the block instance hierarchy.
100
+ * If none is found, it'll look it up in the block editor store.
96
101
  *
97
102
  * @param {string} path The path to the setting.
98
103
  * @return {any} Returns the value defined for the setting.
@@ -102,7 +107,7 @@ const removeCustomPrefixes = ( path ) => {
102
107
  * ```
103
108
  */
104
109
  export default function useSetting( path ) {
105
- const { name: blockName } = useBlockEditContext();
110
+ const { name: blockName, clientId } = useBlockEditContext();
106
111
 
107
112
  const setting = useSelect(
108
113
  ( select ) => {
@@ -113,28 +118,59 @@ export default function useSetting( path ) {
113
118
  );
114
119
  return undefined;
115
120
  }
116
- const settings = select( blockEditorStore ).getSettings();
117
121
 
118
- // 1 - Use __experimental features, if available.
119
- // We cascade to the all value if the block one is not available.
122
+ let result;
120
123
  const normalizedPath = removeCustomPrefixes( path );
121
- const defaultsPath = `__experimentalFeatures.${ normalizedPath }`;
122
- const blockPath = `__experimentalFeatures.blocks.${ blockName }.${ normalizedPath }`;
123
- const experimentalFeaturesResult =
124
- get( settings, blockPath ) ?? get( settings, defaultsPath );
125
124
 
126
- if ( experimentalFeaturesResult !== undefined ) {
125
+ // 1. Take settings from the block instance or its ancestors.
126
+ const candidates = [
127
+ ...select( blockEditorStore ).getBlockParents( clientId ),
128
+ clientId, // The current block is added last, so it overwrites any ancestor.
129
+ ];
130
+ candidates.forEach( ( candidateClientId ) => {
131
+ const candidateBlockName = select(
132
+ blockEditorStore
133
+ ).getBlockName( candidateClientId );
134
+ if (
135
+ hasBlockSupport(
136
+ candidateBlockName,
137
+ '__experimentalSettings',
138
+ false
139
+ )
140
+ ) {
141
+ const candidateAtts = select(
142
+ blockEditorStore
143
+ ).getBlockAttributes( candidateClientId );
144
+ const candidateResult =
145
+ get(
146
+ candidateAtts,
147
+ `settings.blocks.${ blockName }.${ normalizedPath }`
148
+ ) ??
149
+ get( candidateAtts, `settings.${ normalizedPath }` );
150
+ if ( candidateResult !== undefined ) {
151
+ result = candidateResult;
152
+ }
153
+ }
154
+ } );
155
+
156
+ // 2. Fall back to the settings from the block editor store (__experimentalFeatures).
157
+ const settings = select( blockEditorStore ).getSettings();
158
+ if ( result === undefined ) {
159
+ const defaultsPath = `__experimentalFeatures.${ normalizedPath }`;
160
+ const blockPath = `__experimentalFeatures.blocks.${ blockName }.${ normalizedPath }`;
161
+ result =
162
+ get( settings, blockPath ) ?? get( settings, defaultsPath );
163
+ }
164
+
165
+ // Return if the setting was found in either the block instance or the store.
166
+ if ( result !== undefined ) {
127
167
  if ( PATHS_WITH_MERGE[ normalizedPath ] ) {
128
- return (
129
- experimentalFeaturesResult.custom ??
130
- experimentalFeaturesResult.theme ??
131
- experimentalFeaturesResult.default
132
- );
168
+ return result.custom ?? result.theme ?? result.default;
133
169
  }
134
- return experimentalFeaturesResult;
170
+ return result;
135
171
  }
136
172
 
137
- // 2 - Use deprecated settings, otherwise.
173
+ // 3. Otherwise, use deprecated settings.
138
174
  const deprecatedSettingsValue = deprecatedFlags[ normalizedPath ]
139
175
  ? deprecatedFlags[ normalizedPath ]( settings )
140
176
  : undefined;
@@ -142,13 +178,13 @@ export default function useSetting( path ) {
142
178
  return deprecatedSettingsValue;
143
179
  }
144
180
 
145
- // 3 - Fall back for typography.dropCap:
181
+ // 4. Fallback for typography.dropCap:
146
182
  // This is only necessary to support typography.dropCap.
147
183
  // when __experimentalFeatures are not present (core without plugin).
148
184
  // To remove when __experimentalFeatures are ported to core.
149
185
  return normalizedPath === 'typography.dropCap' ? true : undefined;
150
186
  },
151
- [ blockName, path ]
187
+ [ blockName, clientId, path ]
152
188
  );
153
189
 
154
190
  return setting;
@@ -117,7 +117,7 @@ export const withInspectorControl = createHigherOrderComponent(
117
117
  * We plan to remove scoping anchors to 'core/heading' to support
118
118
  * anchors for all eligble blocks. Additionally we plan to explore
119
119
  * leveraging InspectorAdvancedControls instead of a custom
120
- * PanelBody title. https://git.io/Jtcov
120
+ * PanelBody title. https://github.com/WordPress/gutenberg/issues/28363
121
121
  */ }
122
122
  { ! isWeb && props.name === 'core/heading' && (
123
123
  <InspectorControls>
@@ -1,53 +1,174 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import classnames from 'classnames';
5
+
1
6
  /**
2
7
  * WordPress dependencies
3
8
  */
4
9
  import { getBlockSupport } from '@wordpress/blocks';
5
- import { __experimentalToolsPanelItem as ToolsPanelItem } from '@wordpress/components';
10
+ import {
11
+ __experimentalBorderBoxControl as BorderBoxControl,
12
+ __experimentalHasSplitBorders as hasSplitBorders,
13
+ __experimentalIsDefinedBorder as isDefinedBorder,
14
+ __experimentalToolsPanelItem as ToolsPanelItem,
15
+ } from '@wordpress/components';
16
+ import { createHigherOrderComponent } from '@wordpress/compose';
6
17
  import { Platform } from '@wordpress/element';
18
+ import { addFilter } from '@wordpress/hooks';
7
19
  import { __ } from '@wordpress/i18n';
8
20
 
9
21
  /**
10
22
  * Internal dependencies
11
23
  */
12
- import {
13
- BorderColorEdit,
14
- hasBorderColorValue,
15
- resetBorderColor,
16
- } from './border-color';
17
24
  import {
18
25
  BorderRadiusEdit,
19
26
  hasBorderRadiusValue,
20
27
  resetBorderRadius,
21
28
  } from './border-radius';
22
- import {
23
- BorderStyleEdit,
24
- hasBorderStyleValue,
25
- resetBorderStyle,
26
- } from './border-style';
27
- import {
28
- BorderWidthEdit,
29
- hasBorderWidthValue,
30
- resetBorderWidth,
31
- } from './border-width';
29
+ import { getColorClassName } from '../components/colors';
32
30
  import InspectorControls from '../components/inspector-controls';
31
+ import useMultipleOriginColorsAndGradients from '../components/colors-gradients/use-multiple-origin-colors-and-gradients';
33
32
  import useSetting from '../components/use-setting';
34
- import { cleanEmptyObject } from './utils';
33
+ import { cleanEmptyObject, shouldSkipSerialization } from './utils';
35
34
 
36
35
  export const BORDER_SUPPORT_KEY = '__experimentalBorder';
37
36
 
37
+ const borderSides = [ 'top', 'right', 'bottom', 'left' ];
38
+
39
+ const hasBorderValue = ( props ) => {
40
+ const { borderColor, style } = props.attributes;
41
+ return isDefinedBorder( style?.border ) || !! borderColor;
42
+ };
43
+
44
+ // The border color, style, and width are omitted so they get undefined. The
45
+ // border radius is separate and must retain its selection.
46
+ const resetBorder = ( { attributes = {}, setAttributes } ) => {
47
+ const { style } = attributes;
48
+ setAttributes( {
49
+ borderColor: undefined,
50
+ style: {
51
+ ...style,
52
+ border: cleanEmptyObject( {
53
+ radius: style?.border?.radius,
54
+ } ),
55
+ },
56
+ } );
57
+ };
58
+
59
+ const resetBorderFilter = ( newAttributes ) => ( {
60
+ ...newAttributes,
61
+ borderColor: undefined,
62
+ style: {
63
+ ...newAttributes.style,
64
+ border: {
65
+ radius: newAttributes.style?.border?.radius,
66
+ },
67
+ },
68
+ } );
69
+
70
+ const getColorByProperty = ( colors, property, value ) => {
71
+ let matchedColor;
72
+
73
+ colors.some( ( origin ) =>
74
+ origin.colors.some( ( color ) => {
75
+ if ( color[ property ] === value ) {
76
+ matchedColor = color;
77
+ return true;
78
+ }
79
+
80
+ return false;
81
+ } )
82
+ );
83
+
84
+ return matchedColor;
85
+ };
86
+
87
+ export const getMultiOriginColor = ( { colors, namedColor, customColor } ) => {
88
+ // Search each origin (default, theme, or user) for matching color by name.
89
+ if ( namedColor ) {
90
+ const colorObject = getColorByProperty( colors, 'slug', namedColor );
91
+ if ( colorObject ) {
92
+ return colorObject;
93
+ }
94
+ }
95
+
96
+ // Skip if no custom color or matching named color.
97
+ if ( ! customColor ) {
98
+ return { color: undefined };
99
+ }
100
+
101
+ // Attempt to find color via custom color value or build new object.
102
+ const colorObject = getColorByProperty( colors, 'color', customColor );
103
+ return colorObject ? colorObject : { color: customColor };
104
+ };
105
+
106
+ const getBorderObject = ( attributes, colors ) => {
107
+ const { borderColor, style } = attributes;
108
+ const { border: borderStyles } = style || {};
109
+
110
+ // If we have a named color for a flat border. Fetch that color object and
111
+ // apply that color's value to the color property within the style object.
112
+ if ( borderColor ) {
113
+ const { color } = getMultiOriginColor( {
114
+ colors,
115
+ namedColor: borderColor,
116
+ } );
117
+
118
+ return color ? { ...borderStyles, color } : borderStyles;
119
+ }
120
+
121
+ // Individual side border color slugs are stored within the border style
122
+ // object. If we don't have a border styles object we have nothing further
123
+ // to hydrate.
124
+ if ( ! borderStyles ) {
125
+ return borderStyles;
126
+ }
127
+
128
+ // If we have named colors for the individual side borders, retrieve their
129
+ // related color objects and apply the real color values to the split
130
+ // border objects.
131
+ const hydratedBorderStyles = { ...borderStyles };
132
+ borderSides.forEach( ( side ) => {
133
+ const colorSlug = getColorSlugFromVariable(
134
+ hydratedBorderStyles[ side ]?.color
135
+ );
136
+ if ( colorSlug ) {
137
+ const { color } = getMultiOriginColor( {
138
+ colors,
139
+ namedColor: colorSlug,
140
+ } );
141
+ hydratedBorderStyles[ side ] = {
142
+ ...hydratedBorderStyles[ side ],
143
+ color,
144
+ };
145
+ }
146
+ } );
147
+
148
+ return hydratedBorderStyles;
149
+ };
150
+
151
+ function getColorSlugFromVariable( value ) {
152
+ const namedColor = /var:preset\|color\|(.+)/.exec( value );
153
+ if ( namedColor && namedColor[ 1 ] ) {
154
+ return namedColor[ 1 ];
155
+ }
156
+ return null;
157
+ }
158
+
38
159
  export function BorderPanel( props ) {
39
- const { clientId } = props;
160
+ const { attributes, clientId, setAttributes } = props;
161
+ const { style } = attributes;
162
+ const { colors } = useMultipleOriginColorsAndGradients();
40
163
 
164
+ const isSupported = hasBorderSupport( props.name );
41
165
  const isColorSupported =
42
166
  useSetting( 'border.color' ) && hasBorderSupport( props.name, 'color' );
43
-
44
167
  const isRadiusSupported =
45
168
  useSetting( 'border.radius' ) &&
46
169
  hasBorderSupport( props.name, 'radius' );
47
-
48
170
  const isStyleSupported =
49
171
  useSetting( 'border.style' ) && hasBorderSupport( props.name, 'style' );
50
-
51
172
  const isWidthSupported =
52
173
  useSetting( 'border.width' ) && hasBorderSupport( props.name, 'width' );
53
174
 
@@ -58,7 +179,7 @@ export function BorderPanel( props ) {
58
179
  ! isWidthSupported,
59
180
  ].every( Boolean );
60
181
 
61
- if ( isDisabled ) {
182
+ if ( isDisabled || ! isSupported ) {
62
183
  return null;
63
184
  }
64
185
 
@@ -67,61 +188,94 @@ export function BorderPanel( props ) {
67
188
  '__experimentalDefaultControls',
68
189
  ] );
69
190
 
70
- const createResetAllFilter = (
71
- borderAttribute,
72
- topLevelAttributes = {}
73
- ) => ( newAttributes ) => ( {
74
- ...newAttributes,
75
- ...topLevelAttributes,
76
- style: {
77
- ...newAttributes.style,
78
- border: {
79
- ...newAttributes.style?.border,
80
- [ borderAttribute ]: undefined,
81
- },
82
- },
83
- } );
191
+ const showBorderByDefault =
192
+ defaultBorderControls?.color || defaultBorderControls?.width;
193
+
194
+ const onBorderChange = ( newBorder ) => {
195
+ // Filter out named colors and apply them to appropriate block
196
+ // attributes so that CSS classes can be used to apply those colors.
197
+ // e.g. has-primary-border-top-color.
198
+
199
+ let newBorderStyles = { ...newBorder };
200
+ let newBorderColor;
201
+
202
+ if ( hasSplitBorders( newBorder ) ) {
203
+ // For each side check if the side has a color value set
204
+ // If so, determine if it belongs to a named color, in which case
205
+ // we update the color property.
206
+ //
207
+ // This deliberately overwrites `newBorderStyles` to avoid mutating
208
+ // the passed object which causes problems otherwise.
209
+ newBorderStyles = {
210
+ top: { ...newBorder.top },
211
+ right: { ...newBorder.right },
212
+ bottom: { ...newBorder.bottom },
213
+ left: { ...newBorder.left },
214
+ };
215
+
216
+ borderSides.forEach( ( side ) => {
217
+ if ( newBorder[ side ]?.color ) {
218
+ const colorObject = getMultiOriginColor( {
219
+ colors,
220
+ customColor: newBorder[ side ]?.color,
221
+ } );
222
+
223
+ if ( colorObject.slug ) {
224
+ newBorderStyles[
225
+ side
226
+ ].color = `var:preset|color|${ colorObject.slug }`;
227
+ }
228
+ }
229
+ } );
230
+ } else if ( newBorder?.color ) {
231
+ // We have a flat border configuration. Apply named color slug to
232
+ // `borderColor` attribute and clear color style property if found.
233
+ const customColor = newBorder?.color;
234
+ const colorObject = getMultiOriginColor( { colors, customColor } );
235
+
236
+ if ( colorObject.slug ) {
237
+ newBorderColor = colorObject.slug;
238
+ newBorderStyles.color = undefined;
239
+ }
240
+ }
241
+
242
+ // Ensure previous border radius styles are maintained and clean
243
+ // overall result for empty objects or properties.
244
+ const newStyle = cleanEmptyObject( {
245
+ ...style,
246
+ border: { radius: style?.border?.radius, ...newBorderStyles },
247
+ } );
248
+
249
+ setAttributes( {
250
+ style: newStyle,
251
+ borderColor: newBorderColor,
252
+ } );
253
+ };
254
+
255
+ const hydratedBorder = getBorderObject( attributes, colors );
84
256
 
85
257
  return (
86
258
  <InspectorControls __experimentalGroup="border">
87
- { isWidthSupported && (
259
+ { ( isWidthSupported || isColorSupported ) && (
88
260
  <ToolsPanelItem
89
- className="single-column"
90
- hasValue={ () => hasBorderWidthValue( props ) }
91
- label={ __( 'Width' ) }
92
- onDeselect={ () => resetBorderWidth( props ) }
93
- isShownByDefault={ defaultBorderControls?.width }
94
- resetAllFilter={ createResetAllFilter( 'width' ) }
261
+ hasValue={ () => hasBorderValue( props ) }
262
+ label={ __( 'Border' ) }
263
+ onDeselect={ () => resetBorder( props ) }
264
+ isShownByDefault={ showBorderByDefault }
265
+ resetAllFilter={ resetBorderFilter }
95
266
  panelId={ clientId }
96
267
  >
97
- <BorderWidthEdit { ...props } />
98
- </ToolsPanelItem>
99
- ) }
100
- { isStyleSupported && (
101
- <ToolsPanelItem
102
- className="single-column"
103
- hasValue={ () => hasBorderStyleValue( props ) }
104
- label={ __( 'Style' ) }
105
- onDeselect={ () => resetBorderStyle( props ) }
106
- isShownByDefault={ defaultBorderControls?.style }
107
- resetAllFilter={ createResetAllFilter( 'style' ) }
108
- panelId={ clientId }
109
- >
110
- <BorderStyleEdit { ...props } />
111
- </ToolsPanelItem>
112
- ) }
113
- { isColorSupported && (
114
- <ToolsPanelItem
115
- hasValue={ () => hasBorderColorValue( props ) }
116
- label={ __( 'Color' ) }
117
- onDeselect={ () => resetBorderColor( props ) }
118
- isShownByDefault={ defaultBorderControls?.color }
119
- resetAllFilter={ createResetAllFilter( 'color', {
120
- borderColor: undefined,
121
- } ) }
122
- panelId={ clientId }
123
- >
124
- <BorderColorEdit { ...props } />
268
+ <BorderBoxControl
269
+ colors={ colors }
270
+ enableAlpha={ true }
271
+ onChange={ onBorderChange }
272
+ popoverPlacement="left-start"
273
+ popoverOffset={ 40 }
274
+ showStyle={ isStyleSupported }
275
+ value={ hydratedBorder }
276
+ __experimentalHasMultipleOrigins={ true }
277
+ __experimentalIsRenderedInSidebar={ true }
278
+ />
125
279
  </ToolsPanelItem>
126
280
  ) }
127
281
  { isRadiusSupported && (
@@ -130,7 +284,16 @@ export function BorderPanel( props ) {
130
284
  label={ __( 'Radius' ) }
131
285
  onDeselect={ () => resetBorderRadius( props ) }
132
286
  isShownByDefault={ defaultBorderControls?.radius }
133
- resetAllFilter={ createResetAllFilter( 'radius' ) }
287
+ resetAllFilter={ ( newAttributes ) => ( {
288
+ ...newAttributes,
289
+ style: {
290
+ ...newAttributes.style,
291
+ border: {
292
+ ...newAttributes.style?.border,
293
+ radius: undefined,
294
+ },
295
+ },
296
+ } ) }
134
297
  panelId={ clientId }
135
298
  >
136
299
  <BorderRadiusEdit { ...props } />
@@ -189,3 +352,197 @@ export function removeBorderAttribute( style, attribute ) {
189
352
  },
190
353
  } );
191
354
  }
355
+
356
+ /**
357
+ * Filters registered block settings, extending attributes to include
358
+ * `borderColor` if needed.
359
+ *
360
+ * @param {Object} settings Original block settings.
361
+ *
362
+ * @return {Object} Updated block settings.
363
+ */
364
+ function addAttributes( settings ) {
365
+ if ( ! hasBorderSupport( settings, 'color' ) ) {
366
+ return settings;
367
+ }
368
+
369
+ // Allow blocks to specify default value if needed.
370
+ if ( settings.attributes.borderColor ) {
371
+ return settings;
372
+ }
373
+
374
+ // Add new borderColor attribute to block settings.
375
+ return {
376
+ ...settings,
377
+ attributes: {
378
+ ...settings.attributes,
379
+ borderColor: {
380
+ type: 'string',
381
+ },
382
+ },
383
+ };
384
+ }
385
+
386
+ /**
387
+ * Override props assigned to save component to inject border color.
388
+ *
389
+ * @param {Object} props Additional props applied to save element.
390
+ * @param {Object} blockType Block type definition.
391
+ * @param {Object} attributes Block's attributes.
392
+ *
393
+ * @return {Object} Filtered props to apply to save element.
394
+ */
395
+ function addSaveProps( props, blockType, attributes ) {
396
+ if (
397
+ ! hasBorderSupport( blockType, 'color' ) ||
398
+ shouldSkipSerialization( blockType, BORDER_SUPPORT_KEY, 'color' )
399
+ ) {
400
+ return props;
401
+ }
402
+
403
+ const borderClasses = getBorderClasses( attributes );
404
+ const newClassName = classnames( props.className, borderClasses );
405
+
406
+ // If we are clearing the last of the previous classes in `className`
407
+ // set it to `undefined` to avoid rendering empty DOM attributes.
408
+ props.className = newClassName ? newClassName : undefined;
409
+
410
+ return props;
411
+ }
412
+
413
+ /**
414
+ * Generates a CSS class name consisting of all the applicable border color
415
+ * classes given the current block attributes.
416
+ *
417
+ * @param {Object} attributes Block's attributes.
418
+ *
419
+ * @return {string} CSS class name.
420
+ */
421
+ export function getBorderClasses( attributes ) {
422
+ const { borderColor, style } = attributes;
423
+ const borderColorClass = getColorClassName( 'border-color', borderColor );
424
+
425
+ return classnames( {
426
+ 'has-border-color': borderColor || style?.border?.color,
427
+ [ borderColorClass ]: !! borderColorClass,
428
+ } );
429
+ }
430
+
431
+ /**
432
+ * Filters the registered block settings to apply border color styles and
433
+ * classnames to the block edit wrapper.
434
+ *
435
+ * @param {Object} settings Original block settings.
436
+ *
437
+ * @return {Object} Filtered block settings.
438
+ */
439
+ function addEditProps( settings ) {
440
+ if (
441
+ ! hasBorderSupport( settings, 'color' ) ||
442
+ shouldSkipSerialization( settings, BORDER_SUPPORT_KEY, 'color' )
443
+ ) {
444
+ return settings;
445
+ }
446
+
447
+ const existingGetEditWrapperProps = settings.getEditWrapperProps;
448
+ settings.getEditWrapperProps = ( attributes ) => {
449
+ let props = {};
450
+
451
+ if ( existingGetEditWrapperProps ) {
452
+ props = existingGetEditWrapperProps( attributes );
453
+ }
454
+
455
+ return addSaveProps( props, settings, attributes );
456
+ };
457
+
458
+ return settings;
459
+ }
460
+
461
+ /**
462
+ * This adds inline styles for color palette colors.
463
+ * Ideally, this is not needed and themes should load their palettes on the editor.
464
+ *
465
+ * @param {Function} BlockListBlock Original component.
466
+ *
467
+ * @return {Function} Wrapped component.
468
+ */
469
+ export const withBorderColorPaletteStyles = createHigherOrderComponent(
470
+ ( BlockListBlock ) => ( props ) => {
471
+ const { name, attributes } = props;
472
+ const { borderColor, style } = attributes;
473
+ const { colors } = useMultipleOriginColorsAndGradients();
474
+
475
+ if (
476
+ ! hasBorderSupport( name, 'color' ) ||
477
+ shouldSkipSerialization( name, BORDER_SUPPORT_KEY, 'color' )
478
+ ) {
479
+ return <BlockListBlock { ...props } />;
480
+ }
481
+
482
+ const { color: borderColorValue } = getMultiOriginColor( {
483
+ colors,
484
+ namedColor: borderColor,
485
+ } );
486
+ const { color: borderTopColor } = getMultiOriginColor( {
487
+ colors,
488
+ namedColor: getColorSlugFromVariable( style?.border?.top?.color ),
489
+ } );
490
+ const { color: borderRightColor } = getMultiOriginColor( {
491
+ colors,
492
+ namedColor: getColorSlugFromVariable( style?.border?.right?.color ),
493
+ } );
494
+
495
+ const { color: borderBottomColor } = getMultiOriginColor( {
496
+ colors,
497
+ namedColor: getColorSlugFromVariable(
498
+ style?.border?.bottom?.color
499
+ ),
500
+ } );
501
+ const { color: borderLeftColor } = getMultiOriginColor( {
502
+ colors,
503
+ namedColor: getColorSlugFromVariable( style?.border?.left?.color ),
504
+ } );
505
+
506
+ const extraStyles = {
507
+ borderTopColor: borderTopColor || borderColorValue,
508
+ borderRightColor: borderRightColor || borderColorValue,
509
+ borderBottomColor: borderBottomColor || borderColorValue,
510
+ borderLeftColor: borderLeftColor || borderColorValue,
511
+ };
512
+
513
+ let wrapperProps = props.wrapperProps;
514
+ wrapperProps = {
515
+ ...props.wrapperProps,
516
+ style: {
517
+ ...props.wrapperProps?.style,
518
+ ...extraStyles,
519
+ },
520
+ };
521
+
522
+ return <BlockListBlock { ...props } wrapperProps={ wrapperProps } />;
523
+ }
524
+ );
525
+
526
+ addFilter(
527
+ 'blocks.registerBlockType',
528
+ 'core/border/addAttributes',
529
+ addAttributes
530
+ );
531
+
532
+ addFilter(
533
+ 'blocks.getSaveContent.extraProps',
534
+ 'core/border/addSaveProps',
535
+ addSaveProps
536
+ );
537
+
538
+ addFilter(
539
+ 'blocks.registerBlockType',
540
+ 'core/border/addEditProps',
541
+ addEditProps
542
+ );
543
+
544
+ addFilter(
545
+ 'editor.BlockListBlock',
546
+ 'core/border/with-border-color-palette-styles',
547
+ withBorderColorPaletteStyles
548
+ );