@wordpress/block-editor 15.22.1-next.v.202606191442.0 → 15.22.1

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 (352) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +2 -2
  3. package/build/components/block-editing-mode/index.cjs +13 -7
  4. package/build/components/block-editing-mode/index.cjs.map +2 -2
  5. package/build/components/block-inspector/index.cjs +32 -16
  6. package/build/components/block-inspector/index.cjs.map +2 -2
  7. package/build/components/block-rename/modal.cjs +0 -1
  8. package/build/components/block-rename/modal.cjs.map +2 -2
  9. package/build/components/block-toolbar/block-toolbar-icon.cjs +14 -6
  10. package/build/components/block-toolbar/block-toolbar-icon.cjs.map +2 -2
  11. package/build/components/colors-gradients/control.cjs +25 -14
  12. package/build/components/colors-gradients/control.cjs.map +2 -2
  13. package/build/components/colors-gradients/dropdown.cjs +4 -1
  14. package/build/components/colors-gradients/dropdown.cjs.map +3 -3
  15. package/build/components/contrast-checker/index.cjs +22 -4
  16. package/build/components/contrast-checker/index.cjs.map +2 -2
  17. package/build/components/date-format-picker/index.cjs +0 -1
  18. package/build/components/date-format-picker/index.cjs.map +2 -2
  19. package/build/components/global-styles/background-panel.cjs +153 -25
  20. package/build/components/global-styles/background-panel.cjs.map +3 -3
  21. package/build/components/global-styles/color-gradient-dropdown-item.cjs +227 -0
  22. package/build/components/global-styles/color-gradient-dropdown-item.cjs.map +7 -0
  23. package/build/components/global-styles/color-panel.cjs +98 -375
  24. package/build/components/global-styles/color-panel.cjs.map +3 -3
  25. package/build/components/global-styles/dimensions-panel.cjs +0 -3
  26. package/build/components/global-styles/dimensions-panel.cjs.map +2 -2
  27. package/build/components/global-styles/hooks.cjs +34 -0
  28. package/build/components/global-styles/hooks.cjs.map +2 -2
  29. package/build/components/global-styles/typography-panel.cjs +82 -10
  30. package/build/components/global-styles/typography-panel.cjs.map +3 -3
  31. package/build/components/inspector-controls/groups.cjs +2 -0
  32. package/build/components/inspector-controls/groups.cjs.map +2 -2
  33. package/build/components/inspector-controls-tabs/styles-tab.cjs +75 -31
  34. package/build/components/inspector-controls-tabs/styles-tab.cjs.map +2 -2
  35. package/build/components/link-control/index.cjs +1 -2
  36. package/build/components/link-control/index.cjs.map +2 -2
  37. package/build/components/list-view/block-select-button.cjs +1 -10
  38. package/build/components/list-view/block-select-button.cjs.map +3 -3
  39. package/build/components/provider/use-block-sync.cjs +3 -1
  40. package/build/components/provider/use-block-sync.cjs.map +2 -2
  41. package/build/components/url-popover/image-url-input-ui.cjs +0 -2
  42. package/build/components/url-popover/image-url-input-ui.cjs.map +2 -2
  43. package/build/components/use-block-display-information/index.cjs +10 -3
  44. package/build/components/use-block-display-information/index.cjs.map +2 -2
  45. package/build/hooks/anchor.cjs +0 -1
  46. package/build/hooks/anchor.cjs.map +2 -2
  47. package/build/hooks/background.cjs +124 -75
  48. package/build/hooks/background.cjs.map +3 -3
  49. package/build/hooks/color.cjs +0 -162
  50. package/build/hooks/color.cjs.map +3 -3
  51. package/build/hooks/contrast-checker.cjs +31 -28
  52. package/build/hooks/contrast-checker.cjs.map +3 -3
  53. package/build/hooks/custom-class-name.cjs +0 -1
  54. package/build/hooks/custom-class-name.cjs.map +2 -2
  55. package/build/hooks/elements.cjs +142 -0
  56. package/build/hooks/elements.cjs.map +7 -0
  57. package/build/hooks/grid-visualizer.cjs +21 -11
  58. package/build/hooks/grid-visualizer.cjs.map +2 -2
  59. package/build/hooks/layout-child.cjs +38 -8
  60. package/build/hooks/layout-child.cjs.map +2 -2
  61. package/build/hooks/layout.cjs +6 -3
  62. package/build/hooks/layout.cjs.map +2 -2
  63. package/build/hooks/states.cjs +2 -2
  64. package/build/hooks/states.cjs.map +2 -2
  65. package/build/hooks/style.cjs +8 -4
  66. package/build/hooks/style.cjs.map +2 -2
  67. package/build/hooks/typography.cjs +62 -10
  68. package/build/hooks/typography.cjs.map +3 -3
  69. package/build/layouts/flex.cjs +99 -6
  70. package/build/layouts/flex.cjs.map +2 -2
  71. package/build/utils/block-bindings.cjs +9 -9
  72. package/build/utils/block-bindings.cjs.map +3 -3
  73. package/build/utils/color-values.cjs +10 -1
  74. package/build/utils/color-values.cjs.map +3 -3
  75. package/build/utils/dom.cjs +2 -5
  76. package/build/utils/dom.cjs.map +3 -3
  77. package/build/utils/fit-text-frontend.cjs +6 -2
  78. package/build/utils/fit-text-frontend.cjs.map +3 -3
  79. package/build/utils/fit-text-utils.cjs +1 -1
  80. package/build/utils/fit-text-utils.cjs.map +3 -3
  81. package/build/utils/format-font-style.cjs +1 -1
  82. package/build/utils/format-font-style.cjs.map +3 -3
  83. package/build/utils/format-font-weight.cjs +1 -1
  84. package/build/utils/format-font-weight.cjs.map +3 -3
  85. package/build/utils/get-editor-region.cjs +4 -2
  86. package/build/utils/get-editor-region.cjs.map +3 -3
  87. package/build/utils/get-font-styles-and-weights.cjs +8 -12
  88. package/build/utils/get-font-styles-and-weights.cjs.map +3 -3
  89. package/build/utils/get-px-from-css-unit.cjs +1 -1
  90. package/build/utils/get-px-from-css-unit.cjs.map +1 -1
  91. package/build/utils/index.cjs +1 -1
  92. package/build/utils/index.cjs.map +1 -1
  93. package/build/utils/math.cjs +1 -1
  94. package/build/utils/math.cjs.map +3 -3
  95. package/build/utils/object.cjs +8 -8
  96. package/build/utils/object.cjs.map +3 -3
  97. package/build/utils/order-inserter-block-items.cjs +1 -1
  98. package/build/utils/order-inserter-block-items.cjs.map +3 -3
  99. package/build/utils/pasting.cjs +4 -2
  100. package/build/utils/pasting.cjs.map +3 -3
  101. package/build/utils/selection.cjs +2 -1
  102. package/build/utils/selection.cjs.map +3 -3
  103. package/build/utils/sorting.cjs +9 -3
  104. package/build/utils/sorting.cjs.map +3 -3
  105. package/build/utils/transform-styles/index.cjs +3 -2
  106. package/build/utils/transform-styles/index.cjs.map +3 -3
  107. package/build/utils/transform-styles/postcss-urlrebase.d.cjs +2 -0
  108. package/build/utils/transform-styles/postcss-urlrebase.d.cjs.map +7 -0
  109. package/build/utils/transform-styles/types.cjs +19 -0
  110. package/build/utils/transform-styles/types.cjs.map +7 -0
  111. package/build/utils/types.cjs +19 -0
  112. package/build/utils/types.cjs.map +7 -0
  113. package/build-module/components/block-editing-mode/index.mjs +14 -8
  114. package/build-module/components/block-editing-mode/index.mjs.map +2 -2
  115. package/build-module/components/block-inspector/index.mjs +32 -16
  116. package/build-module/components/block-inspector/index.mjs.map +2 -2
  117. package/build-module/components/block-rename/modal.mjs +0 -1
  118. package/build-module/components/block-rename/modal.mjs.map +2 -2
  119. package/build-module/components/block-toolbar/block-toolbar-icon.mjs +14 -6
  120. package/build-module/components/block-toolbar/block-toolbar-icon.mjs.map +2 -2
  121. package/build-module/components/colors-gradients/control.mjs +27 -15
  122. package/build-module/components/colors-gradients/control.mjs.map +2 -2
  123. package/build-module/components/colors-gradients/dropdown.mjs +4 -1
  124. package/build-module/components/colors-gradients/dropdown.mjs.map +2 -2
  125. package/build-module/components/contrast-checker/index.mjs +18 -4
  126. package/build-module/components/contrast-checker/index.mjs.map +2 -2
  127. package/build-module/components/date-format-picker/index.mjs +0 -1
  128. package/build-module/components/date-format-picker/index.mjs.map +2 -2
  129. package/build-module/components/global-styles/background-panel.mjs +155 -27
  130. package/build-module/components/global-styles/background-panel.mjs.map +2 -2
  131. package/build-module/components/global-styles/color-gradient-dropdown-item.mjs +207 -0
  132. package/build-module/components/global-styles/color-gradient-dropdown-item.mjs.map +7 -0
  133. package/build-module/components/global-styles/color-panel.mjs +106 -387
  134. package/build-module/components/global-styles/color-panel.mjs.map +3 -3
  135. package/build-module/components/global-styles/dimensions-panel.mjs +0 -3
  136. package/build-module/components/global-styles/dimensions-panel.mjs.map +2 -2
  137. package/build-module/components/global-styles/hooks.mjs +33 -0
  138. package/build-module/components/global-styles/hooks.mjs.map +2 -2
  139. package/build-module/components/global-styles/typography-panel.mjs +84 -10
  140. package/build-module/components/global-styles/typography-panel.mjs.map +2 -2
  141. package/build-module/components/inspector-controls/groups.mjs +2 -0
  142. package/build-module/components/inspector-controls/groups.mjs.map +2 -2
  143. package/build-module/components/inspector-controls-tabs/styles-tab.mjs +75 -31
  144. package/build-module/components/inspector-controls-tabs/styles-tab.mjs.map +2 -2
  145. package/build-module/components/link-control/index.mjs +1 -2
  146. package/build-module/components/link-control/index.mjs.map +2 -2
  147. package/build-module/components/list-view/block-select-button.mjs +2 -17
  148. package/build-module/components/list-view/block-select-button.mjs.map +2 -2
  149. package/build-module/components/provider/use-block-sync.mjs +3 -1
  150. package/build-module/components/provider/use-block-sync.mjs.map +2 -2
  151. package/build-module/components/url-popover/image-url-input-ui.mjs +0 -2
  152. package/build-module/components/url-popover/image-url-input-ui.mjs.map +2 -2
  153. package/build-module/components/use-block-display-information/index.mjs +10 -3
  154. package/build-module/components/use-block-display-information/index.mjs.map +2 -2
  155. package/build-module/hooks/anchor.mjs +0 -1
  156. package/build-module/hooks/anchor.mjs.map +2 -2
  157. package/build-module/hooks/background.mjs +123 -75
  158. package/build-module/hooks/background.mjs.map +2 -2
  159. package/build-module/hooks/color.mjs +2 -175
  160. package/build-module/hooks/color.mjs.map +2 -2
  161. package/build-module/hooks/contrast-checker.mjs +32 -19
  162. package/build-module/hooks/contrast-checker.mjs.map +2 -2
  163. package/build-module/hooks/custom-class-name.mjs +0 -1
  164. package/build-module/hooks/custom-class-name.mjs.map +2 -2
  165. package/build-module/hooks/elements.mjs +115 -0
  166. package/build-module/hooks/elements.mjs.map +7 -0
  167. package/build-module/hooks/grid-visualizer.mjs +21 -11
  168. package/build-module/hooks/grid-visualizer.mjs.map +2 -2
  169. package/build-module/hooks/layout-child.mjs +41 -8
  170. package/build-module/hooks/layout-child.mjs.map +2 -2
  171. package/build-module/hooks/layout.mjs +6 -3
  172. package/build-module/hooks/layout.mjs.map +2 -2
  173. package/build-module/hooks/states.mjs +2 -2
  174. package/build-module/hooks/states.mjs.map +2 -2
  175. package/build-module/hooks/style.mjs +9 -5
  176. package/build-module/hooks/style.mjs.map +2 -2
  177. package/build-module/hooks/typography.mjs +62 -10
  178. package/build-module/hooks/typography.mjs.map +2 -2
  179. package/build-module/layouts/flex.mjs +105 -7
  180. package/build-module/layouts/flex.mjs.map +2 -2
  181. package/build-module/utils/block-bindings.mjs +9 -9
  182. package/build-module/utils/block-bindings.mjs.map +3 -3
  183. package/build-module/utils/color-values.mjs +9 -1
  184. package/build-module/utils/color-values.mjs.map +3 -3
  185. package/build-module/utils/dom.mjs +2 -5
  186. package/build-module/utils/dom.mjs.map +3 -3
  187. package/build-module/utils/fit-text-frontend.mjs +6 -2
  188. package/build-module/utils/fit-text-frontend.mjs.map +3 -3
  189. package/build-module/utils/fit-text-utils.mjs +1 -1
  190. package/build-module/utils/fit-text-utils.mjs.map +3 -3
  191. package/build-module/utils/format-font-style.mjs +1 -1
  192. package/build-module/utils/format-font-style.mjs.map +3 -3
  193. package/build-module/utils/format-font-weight.mjs +1 -1
  194. package/build-module/utils/format-font-weight.mjs.map +3 -3
  195. package/build-module/utils/get-editor-region.mjs +4 -2
  196. package/build-module/utils/get-editor-region.mjs.map +3 -3
  197. package/build-module/utils/get-font-styles-and-weights.mjs +8 -12
  198. package/build-module/utils/get-font-styles-and-weights.mjs.map +3 -3
  199. package/build-module/utils/get-px-from-css-unit.mjs +1 -1
  200. package/build-module/utils/get-px-from-css-unit.mjs.map +1 -1
  201. package/build-module/utils/index.mjs +1 -1
  202. package/build-module/utils/index.mjs.map +1 -1
  203. package/build-module/utils/math.mjs +1 -1
  204. package/build-module/utils/math.mjs.map +3 -3
  205. package/build-module/utils/object.mjs +8 -8
  206. package/build-module/utils/object.mjs.map +3 -3
  207. package/build-module/utils/order-inserter-block-items.mjs +1 -1
  208. package/build-module/utils/order-inserter-block-items.mjs.map +3 -3
  209. package/build-module/utils/pasting.mjs +4 -2
  210. package/build-module/utils/pasting.mjs.map +3 -3
  211. package/build-module/utils/selection.mjs +2 -1
  212. package/build-module/utils/selection.mjs.map +3 -3
  213. package/build-module/utils/sorting.mjs +9 -3
  214. package/build-module/utils/sorting.mjs.map +3 -3
  215. package/build-module/utils/transform-styles/index.mjs +3 -2
  216. package/build-module/utils/transform-styles/index.mjs.map +3 -3
  217. package/build-module/utils/transform-styles/postcss-urlrebase.d.mjs +1 -0
  218. package/build-module/utils/transform-styles/postcss-urlrebase.d.mjs.map +7 -0
  219. package/build-module/utils/transform-styles/types.mjs +1 -0
  220. package/build-module/utils/transform-styles/types.mjs.map +7 -0
  221. package/build-module/utils/types.mjs +1 -0
  222. package/build-module/utils/types.mjs.map +7 -0
  223. package/build-style/content-rtl.css +2 -0
  224. package/build-style/content.css +2 -0
  225. package/build-style/style-rtl.css +34 -41
  226. package/build-style/style.css +34 -41
  227. package/build-types/utils/block-bindings.d.ts +27 -0
  228. package/build-types/utils/block-bindings.d.ts.map +1 -0
  229. package/build-types/utils/color-values.d.ts +40 -0
  230. package/build-types/utils/color-values.d.ts.map +1 -0
  231. package/build-types/utils/dom.d.ts +19 -19
  232. package/build-types/utils/dom.d.ts.map +1 -1
  233. package/build-types/utils/fit-text-frontend.d.ts +7 -0
  234. package/build-types/utils/fit-text-frontend.d.ts.map +1 -0
  235. package/build-types/utils/fit-text-utils.d.ts +15 -0
  236. package/build-types/utils/fit-text-utils.d.ts.map +1 -0
  237. package/build-types/utils/format-font-style.d.ts +12 -0
  238. package/build-types/utils/format-font-style.d.ts.map +1 -0
  239. package/build-types/utils/format-font-weight.d.ts +12 -0
  240. package/build-types/utils/format-font-weight.d.ts.map +1 -0
  241. package/build-types/utils/get-editor-region.d.ts +9 -0
  242. package/build-types/utils/get-editor-region.d.ts.map +1 -0
  243. package/build-types/utils/get-font-styles-and-weights.d.ts +16 -0
  244. package/build-types/utils/get-font-styles-and-weights.d.ts.map +1 -0
  245. package/build-types/utils/get-px-from-css-unit.d.ts +10 -0
  246. package/build-types/utils/get-px-from-css-unit.d.ts.map +1 -0
  247. package/build-types/utils/index.d.ts +3 -0
  248. package/build-types/utils/index.d.ts.map +1 -0
  249. package/build-types/utils/math.d.ts +61 -0
  250. package/build-types/utils/math.d.ts.map +1 -0
  251. package/build-types/utils/object.d.ts +39 -0
  252. package/build-types/utils/object.d.ts.map +1 -0
  253. package/build-types/utils/order-inserter-block-items.d.ts +13 -0
  254. package/build-types/utils/order-inserter-block-items.d.ts.map +1 -0
  255. package/build-types/utils/pasting.d.ts +28 -0
  256. package/build-types/utils/pasting.d.ts.map +1 -0
  257. package/build-types/utils/selection.d.ts +21 -0
  258. package/build-types/utils/selection.d.ts.map +1 -0
  259. package/build-types/utils/sorting.d.ts +17 -0
  260. package/build-types/utils/sorting.d.ts.map +1 -0
  261. package/build-types/utils/transform-styles/index.d.ts +15 -0
  262. package/build-types/utils/transform-styles/index.d.ts.map +1 -0
  263. package/build-types/utils/transform-styles/types.d.ts +13 -0
  264. package/build-types/utils/transform-styles/types.d.ts.map +1 -0
  265. package/build-types/utils/types.d.ts +28 -0
  266. package/build-types/utils/types.d.ts.map +1 -0
  267. package/package.json +40 -39
  268. package/src/components/alignment-control/test/__snapshots__/index.js.snap +6 -0
  269. package/src/components/block-alignment-control/test/__snapshots__/index.js.snap +5 -0
  270. package/src/components/block-editing-mode/index.js +17 -9
  271. package/src/components/block-icon/test/__snapshots__/index.js.snap +1 -0
  272. package/src/components/block-inspector/index.js +20 -10
  273. package/src/components/block-rename/modal.js +0 -1
  274. package/src/components/block-toolbar/block-toolbar-icon.js +22 -6
  275. package/src/components/block-toolbar/test/block-toolbar-icon.js +99 -0
  276. package/src/components/block-vertical-alignment-control/test/__snapshots__/index.js.snap +4 -0
  277. package/src/components/colors-gradients/control.js +29 -12
  278. package/src/components/colors-gradients/dropdown.js +4 -1
  279. package/src/components/colors-gradients/style.scss +39 -2
  280. package/src/components/contrast-checker/README.md +9 -0
  281. package/src/components/contrast-checker/index.js +42 -3
  282. package/src/components/date-format-picker/index.js +0 -1
  283. package/src/components/default-block-appender/content.scss +3 -0
  284. package/src/components/global-styles/background-panel.js +201 -34
  285. package/src/components/global-styles/color-gradient-dropdown-item.js +258 -0
  286. package/src/components/global-styles/color-panel.js +125 -487
  287. package/src/components/global-styles/dimensions-panel.js +0 -3
  288. package/src/components/global-styles/hooks.js +45 -0
  289. package/src/components/global-styles/test/background-panel.js +56 -0
  290. package/src/components/global-styles/test/color-panel.js +172 -118
  291. package/src/components/global-styles/test/typography-panel.js +167 -0
  292. package/src/components/global-styles/typography-panel.js +100 -11
  293. package/src/components/inspector-controls/README.md +0 -2
  294. package/src/components/inspector-controls/groups.js +2 -0
  295. package/src/components/inspector-controls-tabs/styles-tab.js +74 -28
  296. package/src/components/link-control/index.js +0 -1
  297. package/src/components/link-control/test/index.js +2 -3
  298. package/src/components/list-view/block-select-button.js +2 -17
  299. package/src/components/provider/use-block-sync.js +3 -1
  300. package/src/components/rich-text/content.scss +2 -0
  301. package/src/components/url-popover/image-url-input-ui.js +0 -2
  302. package/src/components/use-block-display-information/index.js +15 -2
  303. package/src/components/use-block-display-information/test/index.js +140 -0
  304. package/src/hooks/anchor.js +0 -1
  305. package/src/hooks/background.js +210 -133
  306. package/src/hooks/background.scss +0 -35
  307. package/src/hooks/color.js +2 -205
  308. package/src/hooks/color.scss +3 -9
  309. package/src/hooks/contrast-checker.js +60 -17
  310. package/src/hooks/custom-class-name.js +0 -1
  311. package/src/hooks/elements.js +140 -0
  312. package/src/hooks/elements.scss +8 -0
  313. package/src/hooks/grid-visualizer.js +59 -45
  314. package/src/hooks/layout-child.js +51 -12
  315. package/src/hooks/layout.js +6 -3
  316. package/src/hooks/states.js +2 -2
  317. package/src/hooks/style.js +11 -7
  318. package/src/hooks/test/background.js +59 -0
  319. package/src/hooks/test/block-style-state.js +14 -14
  320. package/src/hooks/test/layout.js +6 -6
  321. package/src/hooks/test/style.js +8 -8
  322. package/src/hooks/typography.js +70 -6
  323. package/src/layouts/flex.js +118 -15
  324. package/src/store/test/private-selectors.js +28 -7
  325. package/src/store/test/reducer.js +61 -10
  326. package/src/style.scss +1 -0
  327. package/src/utils/block-bindings.ts +51 -0
  328. package/src/utils/color-values.ts +63 -0
  329. package/src/utils/{dom.js → dom.ts} +27 -27
  330. package/src/utils/{fit-text-frontend.js → fit-text-frontend.ts} +12 -4
  331. package/src/utils/{fit-text-utils.js → fit-text-utils.ts} +15 -7
  332. package/src/utils/{format-font-style.js → format-font-style.ts} +10 -3
  333. package/src/utils/{format-font-weight.js → format-font-weight.ts} +10 -3
  334. package/src/utils/{get-editor-region.js → get-editor-region.ts} +10 -6
  335. package/src/utils/{get-font-styles-and-weights.js → get-font-styles-and-weights.ts} +21 -17
  336. package/src/utils/{math.js → math.ts} +37 -30
  337. package/src/utils/object.ts +89 -0
  338. package/src/utils/{order-inserter-block-items.js → order-inserter-block-items.ts} +8 -5
  339. package/src/utils/{pasting.js → pasting.ts} +18 -11
  340. package/src/utils/{selection.js → selection.ts} +11 -4
  341. package/src/utils/sorting.ts +81 -0
  342. package/src/utils/test/color-values.js +44 -1
  343. package/src/utils/transform-styles/{index.js → index.ts} +25 -25
  344. package/src/utils/transform-styles/postcss-urlrebase.d.ts +15 -0
  345. package/src/utils/transform-styles/types.ts +13 -0
  346. package/src/utils/types.ts +29 -0
  347. package/src/utils/block-bindings.js +0 -46
  348. package/src/utils/color-values.js +0 -28
  349. package/src/utils/object.js +0 -67
  350. package/src/utils/sorting.js +0 -54
  351. /package/src/utils/{get-px-from-css-unit.js → get-px-from-css-unit.ts} +0 -0
  352. /package/src/utils/{index.js → index.ts} +0 -0
@@ -1,55 +1,39 @@
1
- /**
2
- * External dependencies
3
- */
4
- import clsx from 'clsx';
5
-
6
1
  /**
7
2
  * WordPress dependencies
8
3
  */
9
- import {
10
- __experimentalToolsPanel as ToolsPanel,
11
- __experimentalToolsPanelItem as ToolsPanelItem,
12
- __experimentalHStack as HStack,
13
- __experimentalZStack as ZStack,
14
- __experimentalDropdownContentWrapper as DropdownContentWrapper,
15
- ColorIndicator,
16
- Flex,
17
- FlexItem,
18
- Dropdown,
19
- Button,
20
- privateApis as componentsPrivateApis,
21
- } from '@wordpress/components';
22
- import { useMemo, useRef } from '@wordpress/element';
4
+ import { __experimentalToolsPanel as ToolsPanel } from '@wordpress/components';
5
+ import { useCallback, useMemo } from '@wordpress/element';
23
6
  import { __ } from '@wordpress/i18n';
24
- import { getValueFromVariable } from '@wordpress/global-styles-engine';
25
- import { reset as resetIcon } from '@wordpress/icons';
26
7
 
27
8
  /**
28
9
  * Internal dependencies
29
10
  */
30
- import ColorGradientControl from '../colors-gradients/control';
31
- import { useColorsPerOrigin, useGradientsPerOrigin } from './hooks';
11
+ import ColorGradientDropdownItem from './color-gradient-dropdown-item';
12
+ import {
13
+ useColorsPerOrigin,
14
+ useGradientsPerOrigin,
15
+ useColorGradientSettings,
16
+ } from './hooks';
32
17
  import { useToolsPanelDropdownMenuProps } from './utils';
33
18
  import { setImmutably } from '../../utils/object';
34
- import { extractPresetSlug } from '../../utils/color-values';
35
- import { unlock } from '../../lock-unlock';
36
-
19
+ import {
20
+ extractPresetSlug,
21
+ encodeColorValueWithPalette,
22
+ } from '../../utils/color-values';
23
+
24
+ // Despite the "ColorPanel" name, this gates only the element-level color
25
+ // controls (link, heading, button, caption, h1–h6) — surfaced as the
26
+ // "Elements" panel in the block inspector and the "Colors" screen in
27
+ // Global Styles. Top-level text and background color moved to the
28
+ // Typography and Background panels, so this returns false for blocks
29
+ // whose only color support is text and/or background.
37
30
  export function useHasColorPanel( settings ) {
38
- const hasTextPanel = useHasTextPanel( settings );
39
- const hasBackgroundPanel = useHasBackgroundColorPanel( settings );
40
31
  const hasLinkPanel = useHasLinkPanel( settings );
41
32
  const hasHeadingPanel = useHasHeadingPanel( settings );
42
33
  const hasButtonPanel = useHasButtonPanel( settings );
43
34
  const hasCaptionPanel = useHasCaptionPanel( settings );
44
35
 
45
- return (
46
- hasTextPanel ||
47
- hasBackgroundPanel ||
48
- hasLinkPanel ||
49
- hasHeadingPanel ||
50
- hasButtonPanel ||
51
- hasCaptionPanel
52
- );
36
+ return hasLinkPanel || hasHeadingPanel || hasButtonPanel || hasCaptionPanel;
53
37
  }
54
38
 
55
39
  export function useHasTextPanel( settings ) {
@@ -145,205 +129,13 @@ export function ColorToolsPanel( {
145
129
  );
146
130
  }
147
131
 
148
- /**
149
- * Encodes a color value for storage in the style object.
150
- *
151
- * When a `slug` is provided it is used directly (slug-based selection path).
152
- * Otherwise the function falls back to looking up the hex value in the
153
- * palette; if found it encodes the slug, otherwise it stores the raw hex.
154
- *
155
- * Extracted to module scope so it is not re-created on every render.
156
- * Callers pass the flattened palette (`allColors`), computed once in `ColorPanel` from the per-origin `colors` array.
157
- *
158
- * @param {Array} allColors Flat array of `{ color, slug }` objects.
159
- * @param {string|void} colorValue Hex or CSS color string.
160
- * @param {string|void} slug Optional palette slug from slug-aware selection.
161
- * @return {string|void} Encoded value suitable for the style object.
162
- */
163
- function encodeColorValueWithPalette( allColors, colorValue, slug ) {
164
- if ( slug ) {
165
- return 'var:preset|color|' + slug;
166
- }
167
- const colorObject = allColors.find( ( { color } ) => color === colorValue );
168
- return colorObject ? 'var:preset|color|' + colorObject.slug : colorValue;
169
- }
170
-
171
132
  const DEFAULT_CONTROLS = {
172
- text: true,
173
- background: true,
174
133
  link: true,
175
134
  heading: true,
176
135
  button: true,
177
136
  caption: true,
178
137
  };
179
138
 
180
- const popoverProps = {
181
- placement: 'left-start',
182
- offset: 36,
183
- shift: true,
184
- };
185
-
186
- const { Tabs } = unlock( componentsPrivateApis );
187
-
188
- const LabeledColorIndicators = ( { indicators, label } ) => (
189
- <HStack justify="flex-start">
190
- <ZStack isLayered={ false } offset={ -8 }>
191
- { indicators.map( ( indicator, index ) => (
192
- <Flex key={ index } expanded={ false }>
193
- <ColorIndicator colorValue={ indicator } />
194
- </Flex>
195
- ) ) }
196
- </ZStack>
197
- <FlexItem className="block-editor-panel-color-gradient-settings__color-name">
198
- { label }
199
- </FlexItem>
200
- </HStack>
201
- );
202
-
203
- function ColorPanelTab( {
204
- isGradient,
205
- inheritedValue,
206
- inheritedSlug,
207
- userValue,
208
- setValue,
209
- colorGradientControlSettings,
210
- } ) {
211
- return (
212
- <ColorGradientControl
213
- { ...colorGradientControlSettings }
214
- showTitle={ false }
215
- enableAlpha
216
- __experimentalIsRenderedInSidebar
217
- colorValue={ isGradient ? undefined : inheritedValue }
218
- colorSlug={ isGradient ? undefined : inheritedSlug }
219
- gradientValue={ isGradient ? inheritedValue : undefined }
220
- onColorChange={ isGradient ? undefined : setValue }
221
- onGradientChange={ isGradient ? setValue : undefined }
222
- clearable={ inheritedValue === userValue }
223
- headingLevel={ 3 }
224
- />
225
- );
226
- }
227
-
228
- export function ColorPanelDropdown( {
229
- label,
230
- hasValue,
231
- resetValue,
232
- isShownByDefault,
233
- indicators,
234
- tabs,
235
- colorGradientControlSettings,
236
- panelId,
237
- className = 'block-editor-tools-panel-color-gradient-settings__item',
238
- } ) {
239
- const currentTab = tabs.find( ( tab ) => tab.userValue !== undefined );
240
- const { key: firstTabKey, ...firstTab } = tabs[ 0 ] ?? {};
241
- const colorGradientDropdownButtonRef = useRef( undefined );
242
- return (
243
- <ToolsPanelItem
244
- className={ className }
245
- hasValue={ hasValue }
246
- label={ label }
247
- onDeselect={ resetValue }
248
- isShownByDefault={ isShownByDefault }
249
- panelId={ panelId }
250
- >
251
- <Dropdown
252
- popoverProps={ popoverProps }
253
- className="block-editor-tools-panel-color-gradient-settings__dropdown"
254
- renderToggle={ ( { onToggle, isOpen } ) => {
255
- const toggleProps = {
256
- onClick: onToggle,
257
- className: clsx(
258
- 'block-editor-panel-color-gradient-settings__dropdown',
259
- { 'is-open': isOpen }
260
- ),
261
- 'aria-expanded': isOpen,
262
- ref: colorGradientDropdownButtonRef,
263
- };
264
-
265
- return (
266
- <>
267
- <Button { ...toggleProps } __next40pxDefaultSize>
268
- <LabeledColorIndicators
269
- indicators={ indicators }
270
- label={ label }
271
- />
272
- </Button>
273
- { hasValue() && (
274
- <Button
275
- __next40pxDefaultSize
276
- label={ __( 'Reset' ) }
277
- className="block-editor-panel-color-gradient-settings__reset"
278
- size="small"
279
- icon={ resetIcon }
280
- onClick={ () => {
281
- resetValue();
282
- if ( isOpen ) {
283
- onToggle();
284
- }
285
- // Return focus to parent button
286
- colorGradientDropdownButtonRef.current?.focus();
287
- } }
288
- />
289
- ) }
290
- </>
291
- );
292
- } }
293
- renderContent={ () => (
294
- <DropdownContentWrapper paddingSize="none">
295
- <div className="block-editor-panel-color-gradient-settings__dropdown-content">
296
- { tabs.length === 1 && (
297
- <ColorPanelTab
298
- key={ firstTabKey }
299
- { ...firstTab }
300
- colorGradientControlSettings={
301
- colorGradientControlSettings
302
- }
303
- />
304
- ) }
305
- { tabs.length > 1 && (
306
- <Tabs defaultTabId={ currentTab?.key }>
307
- <Tabs.TabList>
308
- { tabs.map( ( tab ) => (
309
- <Tabs.Tab
310
- key={ tab.key }
311
- tabId={ tab.key }
312
- >
313
- { tab.label }
314
- </Tabs.Tab>
315
- ) ) }
316
- </Tabs.TabList>
317
-
318
- { tabs.map( ( tab ) => {
319
- const { key: tabKey, ...restTabProps } =
320
- tab;
321
- return (
322
- <Tabs.TabPanel
323
- key={ tabKey }
324
- tabId={ tabKey }
325
- focusable={ false }
326
- >
327
- <ColorPanelTab
328
- key={ tabKey }
329
- { ...restTabProps }
330
- colorGradientControlSettings={
331
- colorGradientControlSettings
332
- }
333
- />
334
- </Tabs.TabPanel>
335
- );
336
- } ) }
337
- </Tabs>
338
- ) }
339
- </div>
340
- </DropdownContentWrapper>
341
- ) }
342
- />
343
- </ToolsPanelItem>
344
- );
345
- }
346
-
347
139
  export default function ColorPanel( {
348
140
  as: Wrapper = ColorToolsPanel,
349
141
  value,
@@ -354,80 +146,19 @@ export default function ColorPanel( {
354
146
  defaultControls = DEFAULT_CONTROLS,
355
147
  label,
356
148
  children,
149
+ contrastWarning,
357
150
  } ) {
358
- const colors = useColorsPerOrigin( settings );
359
- const gradients = useGradientsPerOrigin( settings );
360
- const areCustomSolidsEnabled = settings?.color?.custom;
361
- const areCustomGradientsEnabled = settings?.color?.customGradient;
362
- const hasSolidColors = colors.length > 0 || areCustomSolidsEnabled;
363
- const hasGradientColors = gradients.length > 0 || areCustomGradientsEnabled;
364
- // When a block opts into background.gradient support, the gradient
365
- // picker moves to the Background panel. Hide it here to avoid
366
- // showing duplicate gradient controls.
367
- const hasBackgroundGradientSupport = !! settings?.background?.gradient;
368
- const showGradientColors =
369
- hasGradientColors && ! hasBackgroundGradientSupport;
370
-
371
- const decodeValue = ( rawValue ) =>
372
- getValueFromVariable( { settings }, '', rawValue );
373
-
374
- const allColors = useMemo(
375
- () => colors.flatMap( ( { colors: originColors } ) => originColors ),
376
- [ colors ]
377
- );
378
-
379
- const encodeGradientValue = ( gradientValue ) => {
380
- const allGradients = gradients.flatMap(
381
- ( { gradients: originGradients } ) => originGradients
382
- );
383
- const gradientObject = allGradients.find(
384
- ( { gradient } ) => gradient === gradientValue
385
- );
386
- return gradientObject
387
- ? 'var:preset|gradient|' + gradientObject.slug
388
- : gradientValue;
389
- };
390
-
391
- // BackgroundColor
392
- const showBackgroundPanel = useHasBackgroundColorPanel( settings );
393
- const backgroundColor = decodeValue( inheritedValue?.color?.background );
394
- const userBackgroundColor = decodeValue( value?.color?.background );
395
- const gradient = decodeValue( inheritedValue?.color?.gradient );
396
- const userGradient = decodeValue( value?.color?.gradient );
397
- const hasBackground = () =>
398
- !! userBackgroundColor ||
399
- ( ! hasBackgroundGradientSupport && !! userGradient );
400
- const setBackgroundColor = ( newColor, newSlug ) => {
401
- const newValue = setImmutably(
402
- value,
403
- [ 'color', 'background' ],
404
- encodeColorValueWithPalette( allColors, newColor, newSlug )
405
- );
406
- if ( ! hasBackgroundGradientSupport ) {
407
- newValue.color.gradient = undefined;
408
- }
409
- onChange( newValue );
410
- };
411
- const setGradient = ( newGradient ) => {
412
- const newValue = setImmutably(
413
- value,
414
- [ 'color', 'gradient' ],
415
- encodeGradientValue( newGradient )
416
- );
417
- newValue.color.background = undefined;
418
- onChange( newValue );
419
- };
420
- const resetBackground = () => {
421
- const newValue = setImmutably(
422
- value,
423
- [ 'color', 'background' ],
424
- undefined
425
- );
426
- if ( ! hasBackgroundGradientSupport ) {
427
- newValue.color.gradient = undefined;
428
- }
429
- onChange( newValue );
430
- };
151
+ const {
152
+ colors,
153
+ gradients,
154
+ areCustomSolidsEnabled,
155
+ areCustomGradientsEnabled,
156
+ hasSolidColors,
157
+ hasGradientColors,
158
+ allColors,
159
+ decodeValue,
160
+ encodeGradientValue,
161
+ } = useColorGradientSettings( settings );
431
162
 
432
163
  // Links
433
164
  const showLinkPanel = useHasLinkPanel( settings );
@@ -474,178 +205,91 @@ export default function ColorPanel( {
474
205
  onChange( newValue );
475
206
  };
476
207
 
477
- // Text Color
478
- const showTextPanel = useHasTextPanel( settings );
479
208
  const showCaptionPanel = useHasCaptionPanel( settings );
480
209
  const showButtonPanel = useHasButtonPanel( settings );
481
210
  const showHeadingPanel = useHasHeadingPanel( settings );
482
- const textColor = decodeValue( inheritedValue?.color?.text );
483
- const userTextColor = decodeValue( value?.color?.text );
484
- const hasTextColor = () => !! userTextColor;
485
- const setTextColor = ( newColor, newSlug ) => {
486
- let changedObject = setImmutably(
487
- value,
488
- [ 'color', 'text' ],
489
- encodeColorValueWithPalette( allColors, newColor, newSlug )
490
- );
491
- // Compare raw encoded references (e.g. `var:preset|color|slug`), not
492
- // decoded hex values. Two palette entries can share the same hex but
493
- // carry different slugs (e.g. `var:preset|color|dark-background` and
494
- // `var:preset|color|dark-text` both resolving to `#000`); comparing decoded
495
- // values would conflate them and incorrectly force the link color to
496
- // follow the text color even when the user deliberately chose a
497
- // different palette slot.
498
- //
499
- // Note: this is stricter than the previous decoded comparison.
500
- // If text and link were stored in different formats that resolved to
501
- // the same hex (e.g. one as `var:preset|color|x` and the other as
502
- // `var(--wp--preset--color--x)`), the old check would sync them
503
- // and this one will not. In practice this should not arise because
504
- // both values are written through the same encoding path.
505
- if (
506
- inheritedValue?.color?.text ===
507
- inheritedValue?.elements?.link?.color?.text
508
- ) {
509
- changedObject = setImmutably(
510
- changedObject,
511
- [ 'elements', 'link', 'color', 'text' ],
512
- encodeColorValueWithPalette( allColors, newColor, newSlug )
513
- );
514
- }
515
-
516
- onChange( changedObject );
517
- };
518
- const resetTextColor = () => setTextColor( undefined );
519
211
 
520
212
  // Elements
521
- const elements = [
522
- {
523
- name: 'caption',
524
- label: __( 'Captions' ),
525
- showPanel: showCaptionPanel,
526
- },
527
- {
528
- name: 'button',
529
- label: __( 'Button' ),
530
- showPanel: showButtonPanel,
531
- },
532
- {
533
- name: 'heading',
534
- label: __( 'Heading' ),
535
- showPanel: showHeadingPanel,
536
- },
537
- {
538
- name: 'h1',
539
- label: __( 'H1' ),
540
- showPanel: showHeadingPanel,
541
- },
542
- {
543
- name: 'h2',
544
- label: __( 'H2' ),
545
- showPanel: showHeadingPanel,
546
- },
547
- {
548
- name: 'h3',
549
- label: __( 'H3' ),
550
- showPanel: showHeadingPanel,
551
- },
552
- {
553
- name: 'h4',
554
- label: __( 'H4' ),
555
- showPanel: showHeadingPanel,
556
- },
557
- {
558
- name: 'h5',
559
- label: __( 'H5' ),
560
- showPanel: showHeadingPanel,
561
- },
562
- {
563
- name: 'h6',
564
- label: __( 'H6' ),
565
- showPanel: showHeadingPanel,
566
- },
567
- ];
213
+ const elements = useMemo(
214
+ () => [
215
+ {
216
+ name: 'caption',
217
+ label: __( 'Captions' ),
218
+ showPanel: showCaptionPanel,
219
+ },
220
+ {
221
+ name: 'button',
222
+ label: __( 'Button' ),
223
+ showPanel: showButtonPanel,
224
+ },
225
+ {
226
+ name: 'heading',
227
+ label: __( 'Heading' ),
228
+ showPanel: showHeadingPanel,
229
+ },
230
+ {
231
+ name: 'h1',
232
+ label: __( 'H1' ),
233
+ showPanel: showHeadingPanel,
234
+ },
235
+ {
236
+ name: 'h2',
237
+ label: __( 'H2' ),
238
+ showPanel: showHeadingPanel,
239
+ },
240
+ {
241
+ name: 'h3',
242
+ label: __( 'H3' ),
243
+ showPanel: showHeadingPanel,
244
+ },
245
+ {
246
+ name: 'h4',
247
+ label: __( 'H4' ),
248
+ showPanel: showHeadingPanel,
249
+ },
250
+ {
251
+ name: 'h5',
252
+ label: __( 'H5' ),
253
+ showPanel: showHeadingPanel,
254
+ },
255
+ {
256
+ name: 'h6',
257
+ label: __( 'H6' ),
258
+ showPanel: showHeadingPanel,
259
+ },
260
+ ],
261
+ [ showCaptionPanel, showButtonPanel, showHeadingPanel ]
262
+ );
568
263
 
569
- const resetAllFilter = ( previousValue ) => {
570
- return {
571
- ...previousValue,
572
- color: undefined,
573
- elements: {
574
- ...previousValue?.elements,
575
- link: {
576
- ...previousValue?.elements?.link,
577
- color: undefined,
578
- ':hover': {
264
+ const resetAllFilter = useCallback(
265
+ ( previousValue ) => {
266
+ return {
267
+ ...previousValue,
268
+ elements: {
269
+ ...previousValue?.elements,
270
+ link: {
271
+ ...previousValue?.elements?.link,
579
272
  color: undefined,
580
- },
581
- },
582
- ...elements.reduce( ( acc, element ) => {
583
- return {
584
- ...acc,
585
- [ element.name ]: {
586
- ...previousValue?.elements?.[ element.name ],
273
+ ':hover': {
587
274
  color: undefined,
588
275
  },
589
- };
590
- }, {} ),
591
- },
592
- };
593
- };
594
-
595
- const items = [
596
- showTextPanel && {
597
- key: 'text',
598
- label: __( 'Text' ),
599
- hasValue: hasTextColor,
600
- resetValue: resetTextColor,
601
- isShownByDefault: defaultControls.text,
602
- indicators: [ textColor ],
603
- tabs: [
604
- {
605
- key: 'text',
606
- label: __( 'Text' ),
607
- inheritedValue: textColor,
608
- inheritedSlug: extractPresetSlug(
609
- inheritedValue?.color?.text,
610
- 'color'
611
- ),
612
- setValue: setTextColor,
613
- userValue: userTextColor,
614
- },
615
- ],
616
- },
617
- showBackgroundPanel && {
618
- key: 'background',
619
- label: __( 'Background' ),
620
- hasValue: hasBackground,
621
- resetValue: resetBackground,
622
- isShownByDefault: defaultControls.background,
623
- indicators: [
624
- ( showGradientColors ? gradient : undefined ) ??
625
- backgroundColor,
626
- ],
627
- tabs: [
628
- hasSolidColors && {
629
- key: 'background',
630
- label: __( 'Color' ),
631
- inheritedValue: backgroundColor,
632
- inheritedSlug: extractPresetSlug(
633
- inheritedValue?.color?.background,
634
- 'color'
635
- ),
636
- setValue: setBackgroundColor,
637
- userValue: userBackgroundColor,
638
- },
639
- showGradientColors && {
640
- key: 'gradient',
641
- label: __( 'Gradient' ),
642
- inheritedValue: gradient,
643
- setValue: setGradient,
644
- userValue: userGradient,
645
- isGradient: true,
276
+ },
277
+ ...elements.reduce( ( acc, element ) => {
278
+ return {
279
+ ...acc,
280
+ [ element.name ]: {
281
+ ...previousValue?.elements?.[ element.name ],
282
+ color: undefined,
283
+ },
284
+ };
285
+ }, {} ),
646
286
  },
647
- ].filter( Boolean ),
287
+ };
648
288
  },
289
+ [ elements ]
290
+ );
291
+
292
+ const items = [
649
293
  showLinkPanel && {
650
294
  key: 'link',
651
295
  label: __( 'Link' ),
@@ -653,6 +297,7 @@ export default function ColorPanel( {
653
297
  resetValue: resetLink,
654
298
  isShownByDefault: defaultControls.link,
655
299
  indicators: [ linkColor, hoverLinkColor ],
300
+ contrastWarning,
656
301
  tabs: [
657
302
  {
658
303
  key: 'link',
@@ -756,7 +401,6 @@ export default function ColorPanel( {
756
401
  newValue.elements[ name ].color.background = undefined;
757
402
  onChange( newValue );
758
403
  };
759
- const supportsTextColor = true;
760
404
  // Background color is not supported for `caption`
761
405
  // as there isn't yet a way to set padding for the element.
762
406
  const supportsBackground = name !== 'caption';
@@ -767,30 +411,24 @@ export default function ColorPanel( {
767
411
  hasValue: hasElement,
768
412
  resetValue: resetElement,
769
413
  isShownByDefault: defaultControls[ name ],
770
- indicators:
771
- supportsTextColor && supportsBackground
772
- ? [
773
- elementTextColor,
774
- elementGradient ?? elementBackgroundColor,
775
- ]
776
- : [
777
- supportsTextColor
778
- ? elementTextColor
779
- : elementGradient ?? elementBackgroundColor,
780
- ],
414
+ indicators: supportsBackground
415
+ ? [
416
+ elementTextColor,
417
+ elementGradient ?? elementBackgroundColor,
418
+ ]
419
+ : [ elementTextColor ],
781
420
  tabs: [
782
- hasSolidColors &&
783
- supportsTextColor && {
784
- key: 'text',
785
- label: __( 'Text' ),
786
- inheritedValue: elementTextColor,
787
- inheritedSlug: extractPresetSlug(
788
- inheritedValue?.elements?.[ name ]?.color?.text,
789
- 'color'
790
- ),
791
- setValue: setElementTextColor,
792
- userValue: elementTextUserColor,
793
- },
421
+ hasSolidColors && {
422
+ key: 'text',
423
+ label: __( 'Text' ),
424
+ inheritedValue: elementTextColor,
425
+ inheritedSlug: extractPresetSlug(
426
+ inheritedValue?.elements?.[ name ]?.color?.text,
427
+ 'color'
428
+ ),
429
+ setValue: setElementTextColor,
430
+ userValue: elementTextUserColor,
431
+ },
794
432
  hasSolidColors &&
795
433
  supportsBackground && {
796
434
  key: 'background',
@@ -828,7 +466,7 @@ export default function ColorPanel( {
828
466
  { items.map( ( item ) => {
829
467
  const { key, ...restItem } = item;
830
468
  return (
831
- <ColorPanelDropdown
469
+ <ColorGradientDropdownItem
832
470
  key={ key }
833
471
  { ...restItem }
834
472
  colorGradientControlSettings={ {