@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
@@ -2,35 +2,15 @@
2
2
  import clsx from "clsx";
3
3
  import { addFilter } from "@wordpress/hooks";
4
4
  import { getBlockSupport } from "@wordpress/blocks";
5
- import { useMemo, useCallback } from "@wordpress/element";
6
- import { useSelect } from "@wordpress/data";
5
+ import { useMemo } from "@wordpress/element";
7
6
  import {
8
7
  getColorClassName,
9
8
  getColorObjectByAttributeValues
10
9
  } from "../components/colors/index.mjs";
11
10
  import { __experimentalGetGradientClass } from "../components/gradients/index.mjs";
12
- import {
13
- cleanEmptyObject,
14
- transformStyles,
15
- shouldSkipSerialization
16
- } from "./utils.mjs";
11
+ import { transformStyles, shouldSkipSerialization } from "./utils.mjs";
17
12
  import { getBackgroundImageClasses } from "./background.mjs";
18
13
  import { useSettings } from "../components/use-settings/index.mjs";
19
- import InspectorControls from "../components/inspector-controls/index.mjs";
20
- import {
21
- useHasColorPanel,
22
- default as StylesColorPanel
23
- } from "../components/global-styles/color-panel.mjs";
24
- import { extractPresetSlug } from "../utils/color-values.mjs";
25
- import BlockColorContrastChecker from "./contrast-checker.mjs";
26
- import { store as blockEditorStore } from "../store/index.mjs";
27
- import {
28
- getStyleForState,
29
- isDefaultBlockStyleState,
30
- setStyleForState,
31
- useBlockStyleState
32
- } from "./block-style-state.mjs";
33
- import { jsx } from "react/jsx-runtime";
34
14
  var COLOR_SUPPORT_KEY = "color";
35
15
  var hasColorSupport = (blockNameOrType) => {
36
16
  const colorSupport = getBlockSupport(blockNameOrType, COLOR_SUPPORT_KEY);
@@ -105,158 +85,6 @@ function addSaveProps(props, blockNameOrType, attributes) {
105
85
  props.className = newClassName ? newClassName : void 0;
106
86
  return props;
107
87
  }
108
- function styleToAttributes(style) {
109
- const textColorValue = style?.color?.text;
110
- const textColorSlug = extractPresetSlug(textColorValue, "color");
111
- const backgroundColorValue = style?.color?.background;
112
- const backgroundColorSlug = extractPresetSlug(
113
- backgroundColorValue,
114
- "color"
115
- );
116
- const gradientValue = style?.color?.gradient;
117
- const gradientSlug = extractPresetSlug(gradientValue, "gradient");
118
- const updatedStyle = { ...style };
119
- updatedStyle.color = {
120
- ...updatedStyle.color,
121
- text: textColorSlug ? void 0 : textColorValue,
122
- background: backgroundColorSlug ? void 0 : backgroundColorValue,
123
- gradient: gradientSlug ? void 0 : gradientValue
124
- };
125
- return {
126
- style: cleanEmptyObject(updatedStyle),
127
- textColor: textColorSlug,
128
- backgroundColor: backgroundColorSlug,
129
- gradient: gradientSlug
130
- };
131
- }
132
- function attributesToStyle(attributes) {
133
- return {
134
- ...attributes.style,
135
- color: {
136
- ...attributes.style?.color,
137
- text: attributes.textColor ? "var:preset|color|" + attributes.textColor : attributes.style?.color?.text,
138
- background: attributes.backgroundColor ? "var:preset|color|" + attributes.backgroundColor : attributes.style?.color?.background,
139
- gradient: attributes.gradient ? "var:preset|gradient|" + attributes.gradient : attributes.style?.color?.gradient
140
- }
141
- };
142
- }
143
- function ColorInspectorControl({ children, resetAllFilter }) {
144
- const attributesResetAllFilter = useCallback(
145
- (attributes) => {
146
- const existingStyle = attributesToStyle(attributes);
147
- const updatedStyle = resetAllFilter(existingStyle);
148
- return {
149
- ...attributes,
150
- ...styleToAttributes(updatedStyle)
151
- };
152
- },
153
- [resetAllFilter]
154
- );
155
- return /* @__PURE__ */ jsx(
156
- InspectorControls,
157
- {
158
- group: "color",
159
- resetAllFilter: attributesResetAllFilter,
160
- children
161
- }
162
- );
163
- }
164
- function ColorEdit({
165
- clientId,
166
- name,
167
- setAttributes,
168
- settings,
169
- asWrapper,
170
- label,
171
- defaultControls
172
- }) {
173
- const selectedState = useBlockStyleState();
174
- const isEnabled = useHasColorPanel(settings);
175
- const { style, textColor, backgroundColor, gradient } = useSelect(
176
- (select) => {
177
- if (!isEnabled) {
178
- return {};
179
- }
180
- const {
181
- style: _style,
182
- textColor: _textColor,
183
- backgroundColor: _backgroundColor,
184
- gradient: _gradient
185
- } = select(blockEditorStore).getBlockAttributes(clientId) || {};
186
- return {
187
- style: _style,
188
- textColor: _textColor,
189
- backgroundColor: _backgroundColor,
190
- gradient: _gradient
191
- };
192
- },
193
- [clientId, isEnabled]
194
- );
195
- const isStateSelected = !isDefaultBlockStyleState(selectedState);
196
- const value = useMemo(() => {
197
- if (isStateSelected) {
198
- return getStyleForState(style, selectedState);
199
- }
200
- return attributesToStyle({
201
- style,
202
- textColor,
203
- backgroundColor,
204
- gradient
205
- });
206
- }, [
207
- isStateSelected,
208
- selectedState,
209
- style,
210
- textColor,
211
- backgroundColor,
212
- gradient
213
- ]);
214
- const onChange = isStateSelected ? (newStyle) => {
215
- setAttributes({
216
- style: setStyleForState(style, selectedState, newStyle)
217
- });
218
- } : (newStyle) => {
219
- setAttributes(styleToAttributes(newStyle));
220
- };
221
- const Wrapper = asWrapper || ColorInspectorControl;
222
- if (!isEnabled) {
223
- return null;
224
- }
225
- defaultControls = defaultControls ? defaultControls : getBlockSupport(name, [
226
- COLOR_SUPPORT_KEY,
227
- "__experimentalDefaultControls"
228
- ]);
229
- const enableContrastChecking = !isStateSelected && !value?.color?.gradient && (settings?.color?.text || settings?.color?.link) && // Contrast checking is enabled by default.
230
- // Deactivating it requires `enableContrastChecker` to have
231
- // an explicit value of `false`.
232
- false !== getBlockSupport(name, [
233
- COLOR_SUPPORT_KEY,
234
- "enableContrastChecker"
235
- ]);
236
- return /* @__PURE__ */ jsx(
237
- StylesColorPanel,
238
- {
239
- as: Wrapper,
240
- panelId: clientId,
241
- settings,
242
- value,
243
- onChange,
244
- defaultControls,
245
- label,
246
- enableContrastChecker: false !== getBlockSupport(name, [
247
- COLOR_SUPPORT_KEY,
248
- "enableContrastChecker"
249
- ]),
250
- children: enableContrastChecking && /* @__PURE__ */ jsx(
251
- BlockColorContrastChecker,
252
- {
253
- clientId,
254
- name
255
- }
256
- )
257
- }
258
- );
259
- }
260
88
  function useBlockProps({
261
89
  name,
262
90
  backgroundColor,
@@ -353,7 +181,6 @@ addFilter(
353
181
  );
354
182
  export {
355
183
  COLOR_SUPPORT_KEY,
356
- ColorEdit,
357
184
  addSaveProps,
358
185
  addTransforms,
359
186
  color_default as default
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/hooks/color.js"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { getBlockSupport } from '@wordpress/blocks';\nimport { useMemo, useCallback } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetColorClassName,\n\tgetColorObjectByAttributeValues,\n} from '../components/colors';\nimport { __experimentalGetGradientClass } from '../components/gradients';\nimport {\n\tcleanEmptyObject,\n\ttransformStyles,\n\tshouldSkipSerialization,\n} from './utils';\nimport { getBackgroundImageClasses } from './background';\nimport { useSettings } from '../components/use-settings';\nimport InspectorControls from '../components/inspector-controls';\nimport {\n\tuseHasColorPanel,\n\tdefault as StylesColorPanel,\n} from '../components/global-styles/color-panel';\nimport { extractPresetSlug } from '../utils/color-values';\nimport BlockColorContrastChecker from './contrast-checker';\nimport { store as blockEditorStore } from '../store';\nimport {\n\tgetStyleForState,\n\tisDefaultBlockStyleState,\n\tsetStyleForState,\n\tuseBlockStyleState,\n} from './block-style-state';\n\nexport const COLOR_SUPPORT_KEY = 'color';\n\nconst hasColorSupport = ( blockNameOrType ) => {\n\tconst colorSupport = getBlockSupport( blockNameOrType, COLOR_SUPPORT_KEY );\n\treturn (\n\t\tcolorSupport &&\n\t\t( colorSupport.link === true ||\n\t\t\tcolorSupport.gradient === true ||\n\t\t\tcolorSupport.background !== false ||\n\t\t\tcolorSupport.text !== false )\n\t);\n};\n\nconst hasLinkColorSupport = ( blockType ) => {\n\tconst colorSupport = getBlockSupport( blockType, COLOR_SUPPORT_KEY );\n\n\treturn (\n\t\tcolorSupport !== null &&\n\t\ttypeof colorSupport === 'object' &&\n\t\t!! colorSupport.link\n\t);\n};\n\nconst hasGradientSupport = ( blockNameOrType ) => {\n\tconst colorSupport = getBlockSupport( blockNameOrType, COLOR_SUPPORT_KEY );\n\n\treturn (\n\t\tcolorSupport !== null &&\n\t\ttypeof colorSupport === 'object' &&\n\t\t!! colorSupport.gradients\n\t);\n};\n\nconst hasBackgroundColorSupport = ( blockType ) => {\n\tconst colorSupport = getBlockSupport( blockType, COLOR_SUPPORT_KEY );\n\n\treturn colorSupport && colorSupport.background !== false;\n};\n\nconst hasTextColorSupport = ( blockType ) => {\n\tconst colorSupport = getBlockSupport( blockType, COLOR_SUPPORT_KEY );\n\n\treturn colorSupport && colorSupport.text !== false;\n};\n\n/**\n * Filters registered block settings, extending attributes to include\n * `backgroundColor` and `textColor` attribute.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nfunction addAttributes( settings ) {\n\tif ( ! hasColorSupport( settings ) ) {\n\t\treturn settings;\n\t}\n\n\t// Allow blocks to specify their own attribute definition with default values if needed.\n\tif ( ! settings.attributes.backgroundColor ) {\n\t\tObject.assign( settings.attributes, {\n\t\t\tbackgroundColor: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t} );\n\t}\n\tif ( ! settings.attributes.textColor ) {\n\t\tObject.assign( settings.attributes, {\n\t\t\ttextColor: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t} );\n\t}\n\n\tif ( hasGradientSupport( settings ) && ! settings.attributes.gradient ) {\n\t\tObject.assign( settings.attributes, {\n\t\t\tgradient: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t} );\n\t}\n\n\treturn settings;\n}\n\n/**\n * Override props assigned to save component to inject colors classnames.\n *\n * @param {Object} props Additional props applied to save element.\n * @param {Object|string} blockNameOrType Block type.\n * @param {Object} attributes Block attributes.\n *\n * @return {Object} Filtered props applied to save element.\n */\nexport function addSaveProps( props, blockNameOrType, attributes ) {\n\tif (\n\t\t! hasColorSupport( blockNameOrType ) ||\n\t\tshouldSkipSerialization( blockNameOrType, COLOR_SUPPORT_KEY )\n\t) {\n\t\treturn props;\n\t}\n\n\tconst hasGradient = hasGradientSupport( blockNameOrType );\n\n\t// I'd have preferred to avoid the \"style\" attribute usage here\n\tconst { backgroundColor, textColor, gradient, style } = attributes;\n\n\tconst shouldSerialize = ( feature ) =>\n\t\t! shouldSkipSerialization(\n\t\t\tblockNameOrType,\n\t\t\tCOLOR_SUPPORT_KEY,\n\t\t\tfeature\n\t\t);\n\n\t// Primary color classes must come before the `has-text-color`,\n\t// `has-background` and `has-link-color` classes to maintain backwards\n\t// compatibility and avoid block invalidations.\n\tconst textClass = shouldSerialize( 'text' )\n\t\t? getColorClassName( 'color', textColor )\n\t\t: undefined;\n\n\tconst gradientClass = shouldSerialize( 'gradients' )\n\t\t? __experimentalGetGradientClass( gradient )\n\t\t: undefined;\n\n\tconst backgroundClass = shouldSerialize( 'background' )\n\t\t? getColorClassName( 'background-color', backgroundColor )\n\t\t: undefined;\n\n\tconst serializeHasBackground =\n\t\tshouldSerialize( 'background' ) || shouldSerialize( 'gradients' );\n\tconst hasBackground =\n\t\tbackgroundColor ||\n\t\tstyle?.color?.background ||\n\t\t( hasGradient && ( gradient || style?.color?.gradient ) );\n\n\tconst newClassName = clsx( props.className, textClass, gradientClass, {\n\t\t// Don't apply the background class if there's a custom gradient.\n\t\t[ backgroundClass ]:\n\t\t\t( ! hasGradient || ! style?.color?.gradient ) && !! backgroundClass,\n\t\t'has-text-color':\n\t\t\tshouldSerialize( 'text' ) && ( textColor || style?.color?.text ),\n\t\t'has-background': serializeHasBackground && hasBackground,\n\t\t'has-link-color':\n\t\t\tshouldSerialize( 'link' ) && style?.elements?.link?.color,\n\t} );\n\tprops.className = newClassName ? newClassName : undefined;\n\n\treturn props;\n}\n\nfunction styleToAttributes( style ) {\n\tconst textColorValue = style?.color?.text;\n\tconst textColorSlug = extractPresetSlug( textColorValue, 'color' );\n\tconst backgroundColorValue = style?.color?.background;\n\tconst backgroundColorSlug = extractPresetSlug(\n\t\tbackgroundColorValue,\n\t\t'color'\n\t);\n\tconst gradientValue = style?.color?.gradient;\n\tconst gradientSlug = extractPresetSlug( gradientValue, 'gradient' );\n\tconst updatedStyle = { ...style };\n\tupdatedStyle.color = {\n\t\t...updatedStyle.color,\n\t\ttext: textColorSlug ? undefined : textColorValue,\n\t\tbackground: backgroundColorSlug ? undefined : backgroundColorValue,\n\t\tgradient: gradientSlug ? undefined : gradientValue,\n\t};\n\treturn {\n\t\tstyle: cleanEmptyObject( updatedStyle ),\n\t\ttextColor: textColorSlug,\n\t\tbackgroundColor: backgroundColorSlug,\n\t\tgradient: gradientSlug,\n\t};\n}\n\nfunction attributesToStyle( attributes ) {\n\treturn {\n\t\t...attributes.style,\n\t\tcolor: {\n\t\t\t...attributes.style?.color,\n\t\t\ttext: attributes.textColor\n\t\t\t\t? 'var:preset|color|' + attributes.textColor\n\t\t\t\t: attributes.style?.color?.text,\n\t\t\tbackground: attributes.backgroundColor\n\t\t\t\t? 'var:preset|color|' + attributes.backgroundColor\n\t\t\t\t: attributes.style?.color?.background,\n\t\t\tgradient: attributes.gradient\n\t\t\t\t? 'var:preset|gradient|' + attributes.gradient\n\t\t\t\t: attributes.style?.color?.gradient,\n\t\t},\n\t};\n}\n\nfunction ColorInspectorControl( { children, resetAllFilter } ) {\n\tconst attributesResetAllFilter = useCallback(\n\t\t( attributes ) => {\n\t\t\tconst existingStyle = attributesToStyle( attributes );\n\t\t\tconst updatedStyle = resetAllFilter( existingStyle );\n\t\t\treturn {\n\t\t\t\t...attributes,\n\t\t\t\t...styleToAttributes( updatedStyle ),\n\t\t\t};\n\t\t},\n\t\t[ resetAllFilter ]\n\t);\n\n\treturn (\n\t\t<InspectorControls\n\t\t\tgroup=\"color\"\n\t\t\tresetAllFilter={ attributesResetAllFilter }\n\t\t>\n\t\t\t{ children }\n\t\t</InspectorControls>\n\t);\n}\n\nexport function ColorEdit( {\n\tclientId,\n\tname,\n\tsetAttributes,\n\tsettings,\n\tasWrapper,\n\tlabel,\n\tdefaultControls,\n} ) {\n\tconst selectedState = useBlockStyleState();\n\tconst isEnabled = useHasColorPanel( settings );\n\n\tconst { style, textColor, backgroundColor, gradient } = useSelect(\n\t\t( select ) => {\n\t\t\t// Early return to avoid subscription when disabled\n\t\t\tif ( ! isEnabled ) {\n\t\t\t\treturn {};\n\t\t\t}\n\t\t\tconst {\n\t\t\t\tstyle: _style,\n\t\t\t\ttextColor: _textColor,\n\t\t\t\tbackgroundColor: _backgroundColor,\n\t\t\t\tgradient: _gradient,\n\t\t\t} = select( blockEditorStore ).getBlockAttributes( clientId ) || {};\n\t\t\treturn {\n\t\t\t\tstyle: _style,\n\t\t\t\ttextColor: _textColor,\n\t\t\t\tbackgroundColor: _backgroundColor,\n\t\t\t\tgradient: _gradient,\n\t\t\t};\n\t\t},\n\t\t[ clientId, isEnabled ]\n\t);\n\n\tconst isStateSelected = ! isDefaultBlockStyleState( selectedState );\n\n\tconst value = useMemo( () => {\n\t\tif ( isStateSelected ) {\n\t\t\treturn getStyleForState( style, selectedState );\n\t\t}\n\t\treturn attributesToStyle( {\n\t\t\tstyle,\n\t\t\ttextColor,\n\t\t\tbackgroundColor,\n\t\t\tgradient,\n\t\t} );\n\t}, [\n\t\tisStateSelected,\n\t\tselectedState,\n\t\tstyle,\n\t\ttextColor,\n\t\tbackgroundColor,\n\t\tgradient,\n\t] );\n\n\tconst onChange = isStateSelected\n\t\t? ( newStyle ) => {\n\t\t\t\tsetAttributes( {\n\t\t\t\t\tstyle: setStyleForState( style, selectedState, newStyle ),\n\t\t\t\t} );\n\t\t }\n\t\t: ( newStyle ) => {\n\t\t\t\tsetAttributes( styleToAttributes( newStyle ) );\n\t\t };\n\n\tconst Wrapper = asWrapper || ColorInspectorControl;\n\n\tif ( ! isEnabled ) {\n\t\treturn null;\n\t}\n\n\tdefaultControls = defaultControls\n\t\t? defaultControls\n\t\t: getBlockSupport( name, [\n\t\t\t\tCOLOR_SUPPORT_KEY,\n\t\t\t\t'__experimentalDefaultControls',\n\t\t ] );\n\n\tconst enableContrastChecking =\n\t\t! isStateSelected &&\n\t\t! value?.color?.gradient &&\n\t\t( settings?.color?.text || settings?.color?.link ) &&\n\t\t// Contrast checking is enabled by default.\n\t\t// Deactivating it requires `enableContrastChecker` to have\n\t\t// an explicit value of `false`.\n\t\tfalse !==\n\t\t\tgetBlockSupport( name, [\n\t\t\t\tCOLOR_SUPPORT_KEY,\n\t\t\t\t'enableContrastChecker',\n\t\t\t] );\n\n\treturn (\n\t\t<StylesColorPanel\n\t\t\tas={ Wrapper }\n\t\t\tpanelId={ clientId }\n\t\t\tsettings={ settings }\n\t\t\tvalue={ value }\n\t\t\tonChange={ onChange }\n\t\t\tdefaultControls={ defaultControls }\n\t\t\tlabel={ label }\n\t\t\tenableContrastChecker={\n\t\t\t\tfalse !==\n\t\t\t\tgetBlockSupport( name, [\n\t\t\t\t\tCOLOR_SUPPORT_KEY,\n\t\t\t\t\t'enableContrastChecker',\n\t\t\t\t] )\n\t\t\t}\n\t\t>\n\t\t\t{ enableContrastChecking && (\n\t\t\t\t<BlockColorContrastChecker\n\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\tname={ name }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</StylesColorPanel>\n\t);\n}\n\nfunction useBlockProps( {\n\tname,\n\tbackgroundColor,\n\ttextColor,\n\tgradient,\n\tstyle,\n} ) {\n\tconst [ userPalette, themePalette, defaultPalette ] = useSettings(\n\t\t'color.palette.custom',\n\t\t'color.palette.theme',\n\t\t'color.palette.default'\n\t);\n\n\tconst colors = useMemo(\n\t\t() => [\n\t\t\t...( userPalette || [] ),\n\t\t\t...( themePalette || [] ),\n\t\t\t...( defaultPalette || [] ),\n\t\t],\n\t\t[ userPalette, themePalette, defaultPalette ]\n\t);\n\tif (\n\t\t! hasColorSupport( name ) ||\n\t\tshouldSkipSerialization( name, COLOR_SUPPORT_KEY )\n\t) {\n\t\treturn {};\n\t}\n\tconst extraStyles = {};\n\n\tif (\n\t\ttextColor &&\n\t\t! shouldSkipSerialization( name, COLOR_SUPPORT_KEY, 'text' )\n\t) {\n\t\textraStyles.color = getColorObjectByAttributeValues(\n\t\t\tcolors,\n\t\t\ttextColor\n\t\t)?.color;\n\t}\n\tif (\n\t\tbackgroundColor &&\n\t\t! shouldSkipSerialization( name, COLOR_SUPPORT_KEY, 'background' )\n\t) {\n\t\textraStyles.backgroundColor = getColorObjectByAttributeValues(\n\t\t\tcolors,\n\t\t\tbackgroundColor\n\t\t)?.color;\n\t}\n\n\tconst saveProps = addSaveProps( { style: extraStyles }, name, {\n\t\ttextColor,\n\t\tbackgroundColor,\n\t\tgradient,\n\t\tstyle,\n\t} );\n\n\tconst hasBackgroundValue =\n\t\tbackgroundColor ||\n\t\tstyle?.color?.background ||\n\t\tgradient ||\n\t\tstyle?.color?.gradient;\n\n\treturn {\n\t\t...saveProps,\n\t\tclassName: clsx(\n\t\t\tsaveProps.className,\n\t\t\t// Add background image classes in the editor, if not already handled by background color values.\n\t\t\t! hasBackgroundValue && getBackgroundImageClasses( style )\n\t\t),\n\t};\n}\n\nexport default {\n\tuseBlockProps,\n\taddSaveProps,\n\tattributeKeys: [ 'backgroundColor', 'textColor', 'gradient', 'style' ],\n\thasSupport: hasColorSupport,\n};\n\nconst MIGRATION_PATHS = {\n\tlinkColor: [ [ 'style', 'elements', 'link', 'color', 'text' ] ],\n\ttextColor: [ [ 'textColor' ], [ 'style', 'color', 'text' ] ],\n\tbackgroundColor: [\n\t\t[ 'backgroundColor' ],\n\t\t[ 'style', 'color', 'background' ],\n\t],\n\tgradient: [ [ 'gradient' ], [ 'style', 'color', 'gradient' ] ],\n};\n\nexport function addTransforms( result, source, index, results ) {\n\tconst destinationBlockType = result.name;\n\tconst activeSupports = {\n\t\tlinkColor: hasLinkColorSupport( destinationBlockType ),\n\t\ttextColor: hasTextColorSupport( destinationBlockType ),\n\t\tbackgroundColor: hasBackgroundColorSupport( destinationBlockType ),\n\t\tgradient: hasGradientSupport( destinationBlockType ),\n\t};\n\treturn transformStyles(\n\t\tactiveSupports,\n\t\tMIGRATION_PATHS,\n\t\tresult,\n\t\tsource,\n\t\tindex,\n\t\tresults\n\t);\n}\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/color/addAttribute',\n\taddAttributes\n);\n\naddFilter(\n\t'blocks.switchToBlockType.transformedBlock',\n\t'core/color/addTransforms',\n\taddTransforms\n);\n"],
5
- "mappings": ";AAGA,OAAO,UAAU;AAKjB,SAAS,iBAAiB;AAC1B,SAAS,uBAAuB;AAChC,SAAS,SAAS,mBAAmB;AACrC,SAAS,iBAAiB;AAK1B;AAAA,EACC;AAAA,EACA;AA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;AAAA,EACA;AAAA,EACA;AACD;AAEA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AACD;",
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { getBlockSupport } from '@wordpress/blocks';\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetColorClassName,\n\tgetColorObjectByAttributeValues,\n} from '../components/colors';\nimport { __experimentalGetGradientClass } from '../components/gradients';\nimport { transformStyles, shouldSkipSerialization } from './utils';\nimport { getBackgroundImageClasses } from './background';\nimport { useSettings } from '../components/use-settings';\n\nexport const COLOR_SUPPORT_KEY = 'color';\n\nconst hasColorSupport = ( blockNameOrType ) => {\n\tconst colorSupport = getBlockSupport( blockNameOrType, COLOR_SUPPORT_KEY );\n\treturn (\n\t\tcolorSupport &&\n\t\t( colorSupport.link === true ||\n\t\t\tcolorSupport.gradient === true ||\n\t\t\tcolorSupport.background !== false ||\n\t\t\tcolorSupport.text !== false )\n\t);\n};\n\nconst hasLinkColorSupport = ( blockType ) => {\n\tconst colorSupport = getBlockSupport( blockType, COLOR_SUPPORT_KEY );\n\n\treturn (\n\t\tcolorSupport !== null &&\n\t\ttypeof colorSupport === 'object' &&\n\t\t!! colorSupport.link\n\t);\n};\n\nconst hasGradientSupport = ( blockNameOrType ) => {\n\tconst colorSupport = getBlockSupport( blockNameOrType, COLOR_SUPPORT_KEY );\n\n\treturn (\n\t\tcolorSupport !== null &&\n\t\ttypeof colorSupport === 'object' &&\n\t\t!! colorSupport.gradients\n\t);\n};\n\nconst hasBackgroundColorSupport = ( blockType ) => {\n\tconst colorSupport = getBlockSupport( blockType, COLOR_SUPPORT_KEY );\n\n\treturn colorSupport && colorSupport.background !== false;\n};\n\nconst hasTextColorSupport = ( blockType ) => {\n\tconst colorSupport = getBlockSupport( blockType, COLOR_SUPPORT_KEY );\n\n\treturn colorSupport && colorSupport.text !== false;\n};\n\n/**\n * Filters registered block settings, extending attributes to include\n * `backgroundColor` and `textColor` attribute.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nfunction addAttributes( settings ) {\n\tif ( ! hasColorSupport( settings ) ) {\n\t\treturn settings;\n\t}\n\n\t// Allow blocks to specify their own attribute definition with default values if needed.\n\tif ( ! settings.attributes.backgroundColor ) {\n\t\tObject.assign( settings.attributes, {\n\t\t\tbackgroundColor: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t} );\n\t}\n\tif ( ! settings.attributes.textColor ) {\n\t\tObject.assign( settings.attributes, {\n\t\t\ttextColor: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t} );\n\t}\n\n\tif ( hasGradientSupport( settings ) && ! settings.attributes.gradient ) {\n\t\tObject.assign( settings.attributes, {\n\t\t\tgradient: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t} );\n\t}\n\n\treturn settings;\n}\n\n/**\n * Override props assigned to save component to inject colors classnames.\n *\n * @param {Object} props Additional props applied to save element.\n * @param {Object|string} blockNameOrType Block type.\n * @param {Object} attributes Block attributes.\n *\n * @return {Object} Filtered props applied to save element.\n */\nexport function addSaveProps( props, blockNameOrType, attributes ) {\n\tif (\n\t\t! hasColorSupport( blockNameOrType ) ||\n\t\tshouldSkipSerialization( blockNameOrType, COLOR_SUPPORT_KEY )\n\t) {\n\t\treturn props;\n\t}\n\n\tconst hasGradient = hasGradientSupport( blockNameOrType );\n\n\t// I'd have preferred to avoid the \"style\" attribute usage here\n\tconst { backgroundColor, textColor, gradient, style } = attributes;\n\n\tconst shouldSerialize = ( feature ) =>\n\t\t! shouldSkipSerialization(\n\t\t\tblockNameOrType,\n\t\t\tCOLOR_SUPPORT_KEY,\n\t\t\tfeature\n\t\t);\n\n\t// Primary color classes must come before the `has-text-color`,\n\t// `has-background` and `has-link-color` classes to maintain backwards\n\t// compatibility and avoid block invalidations.\n\tconst textClass = shouldSerialize( 'text' )\n\t\t? getColorClassName( 'color', textColor )\n\t\t: undefined;\n\n\tconst gradientClass = shouldSerialize( 'gradients' )\n\t\t? __experimentalGetGradientClass( gradient )\n\t\t: undefined;\n\n\tconst backgroundClass = shouldSerialize( 'background' )\n\t\t? getColorClassName( 'background-color', backgroundColor )\n\t\t: undefined;\n\n\tconst serializeHasBackground =\n\t\tshouldSerialize( 'background' ) || shouldSerialize( 'gradients' );\n\tconst hasBackground =\n\t\tbackgroundColor ||\n\t\tstyle?.color?.background ||\n\t\t( hasGradient && ( gradient || style?.color?.gradient ) );\n\n\tconst newClassName = clsx( props.className, textClass, gradientClass, {\n\t\t// Don't apply the background class if there's a custom gradient.\n\t\t[ backgroundClass ]:\n\t\t\t( ! hasGradient || ! style?.color?.gradient ) && !! backgroundClass,\n\t\t'has-text-color':\n\t\t\tshouldSerialize( 'text' ) && ( textColor || style?.color?.text ),\n\t\t'has-background': serializeHasBackground && hasBackground,\n\t\t'has-link-color':\n\t\t\tshouldSerialize( 'link' ) && style?.elements?.link?.color,\n\t} );\n\tprops.className = newClassName ? newClassName : undefined;\n\n\treturn props;\n}\n\nfunction useBlockProps( {\n\tname,\n\tbackgroundColor,\n\ttextColor,\n\tgradient,\n\tstyle,\n} ) {\n\tconst [ userPalette, themePalette, defaultPalette ] = useSettings(\n\t\t'color.palette.custom',\n\t\t'color.palette.theme',\n\t\t'color.palette.default'\n\t);\n\n\tconst colors = useMemo(\n\t\t() => [\n\t\t\t...( userPalette || [] ),\n\t\t\t...( themePalette || [] ),\n\t\t\t...( defaultPalette || [] ),\n\t\t],\n\t\t[ userPalette, themePalette, defaultPalette ]\n\t);\n\tif (\n\t\t! hasColorSupport( name ) ||\n\t\tshouldSkipSerialization( name, COLOR_SUPPORT_KEY )\n\t) {\n\t\treturn {};\n\t}\n\tconst extraStyles = {};\n\n\tif (\n\t\ttextColor &&\n\t\t! shouldSkipSerialization( name, COLOR_SUPPORT_KEY, 'text' )\n\t) {\n\t\textraStyles.color = getColorObjectByAttributeValues(\n\t\t\tcolors,\n\t\t\ttextColor\n\t\t)?.color;\n\t}\n\tif (\n\t\tbackgroundColor &&\n\t\t! shouldSkipSerialization( name, COLOR_SUPPORT_KEY, 'background' )\n\t) {\n\t\textraStyles.backgroundColor = getColorObjectByAttributeValues(\n\t\t\tcolors,\n\t\t\tbackgroundColor\n\t\t)?.color;\n\t}\n\n\tconst saveProps = addSaveProps( { style: extraStyles }, name, {\n\t\ttextColor,\n\t\tbackgroundColor,\n\t\tgradient,\n\t\tstyle,\n\t} );\n\n\tconst hasBackgroundValue =\n\t\tbackgroundColor ||\n\t\tstyle?.color?.background ||\n\t\tgradient ||\n\t\tstyle?.color?.gradient;\n\n\treturn {\n\t\t...saveProps,\n\t\tclassName: clsx(\n\t\t\tsaveProps.className,\n\t\t\t// Add background image classes in the editor, if not already handled by background color values.\n\t\t\t! hasBackgroundValue && getBackgroundImageClasses( style )\n\t\t),\n\t};\n}\n\nexport default {\n\tuseBlockProps,\n\taddSaveProps,\n\tattributeKeys: [ 'backgroundColor', 'textColor', 'gradient', 'style' ],\n\thasSupport: hasColorSupport,\n};\n\nconst MIGRATION_PATHS = {\n\tlinkColor: [ [ 'style', 'elements', 'link', 'color', 'text' ] ],\n\ttextColor: [ [ 'textColor' ], [ 'style', 'color', 'text' ] ],\n\tbackgroundColor: [\n\t\t[ 'backgroundColor' ],\n\t\t[ 'style', 'color', 'background' ],\n\t],\n\tgradient: [ [ 'gradient' ], [ 'style', 'color', 'gradient' ] ],\n};\n\nexport function addTransforms( result, source, index, results ) {\n\tconst destinationBlockType = result.name;\n\tconst activeSupports = {\n\t\tlinkColor: hasLinkColorSupport( destinationBlockType ),\n\t\ttextColor: hasTextColorSupport( destinationBlockType ),\n\t\tbackgroundColor: hasBackgroundColorSupport( destinationBlockType ),\n\t\tgradient: hasGradientSupport( destinationBlockType ),\n\t};\n\treturn transformStyles(\n\t\tactiveSupports,\n\t\tMIGRATION_PATHS,\n\t\tresult,\n\t\tsource,\n\t\tindex,\n\t\tresults\n\t);\n}\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/color/addAttribute',\n\taddAttributes\n);\n\naddFilter(\n\t'blocks.switchToBlockType.transformedBlock',\n\t'core/color/addTransforms',\n\taddTransforms\n);\n"],
5
+ "mappings": ";AAGA,OAAO,UAAU;AAKjB,SAAS,iBAAiB;AAC1B,SAAS,uBAAuB;AAChC,SAAS,eAAe;AAKxB;AAAA,EACC;AAAA,EACA;AAAA,OACM;AACP,SAAS,sCAAsC;AAC/C,SAAS,iBAAiB,+BAA+B;AACzD,SAAS,iCAAiC;AAC1C,SAAS,mBAAmB;AAErB,IAAM,oBAAoB;AAEjC,IAAM,kBAAkB,CAAE,oBAAqB;AAC9C,QAAM,eAAe,gBAAiB,iBAAiB,iBAAkB;AACzE,SACC,iBACE,aAAa,SAAS,QACvB,aAAa,aAAa,QAC1B,aAAa,eAAe,SAC5B,aAAa,SAAS;AAEzB;AAEA,IAAM,sBAAsB,CAAE,cAAe;AAC5C,QAAM,eAAe,gBAAiB,WAAW,iBAAkB;AAEnE,SACC,iBAAiB,QACjB,OAAO,iBAAiB,YACxB,CAAC,CAAE,aAAa;AAElB;AAEA,IAAM,qBAAqB,CAAE,oBAAqB;AACjD,QAAM,eAAe,gBAAiB,iBAAiB,iBAAkB;AAEzE,SACC,iBAAiB,QACjB,OAAO,iBAAiB,YACxB,CAAC,CAAE,aAAa;AAElB;AAEA,IAAM,4BAA4B,CAAE,cAAe;AAClD,QAAM,eAAe,gBAAiB,WAAW,iBAAkB;AAEnE,SAAO,gBAAgB,aAAa,eAAe;AACpD;AAEA,IAAM,sBAAsB,CAAE,cAAe;AAC5C,QAAM,eAAe,gBAAiB,WAAW,iBAAkB;AAEnE,SAAO,gBAAgB,aAAa,SAAS;AAC9C;AAUA,SAAS,cAAe,UAAW;AAClC,MAAK,CAAE,gBAAiB,QAAS,GAAI;AACpC,WAAO;AAAA,EACR;AAGA,MAAK,CAAE,SAAS,WAAW,iBAAkB;AAC5C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EACA;AAAA,EACA,eAAe,CAAE,mBAAmB,aAAa,YAAY,OAAQ;AAAA,EACrE,YAAY;AACb;AAEA,IAAM,kBAAkB;AAAA,EACvB,WAAW,CAAE,CAAE,SAAS,YAAY,QAAQ,SAAS,MAAO,CAAE;AAAA,EAC9D,WAAW,CAAE,CAAE,WAAY,GAAG,CAAE,SAAS,SAAS,MAAO,CAAE;AAAA,EAC3D,iBAAiB;AAAA,IAChB,CAAE,iBAAkB;AAAA,IACpB,CAAE,SAAS,SAAS,YAAa;AAAA,EAClC;AAAA,EACA,UAAU,CAAE,CAAE,UAAW,GAAG,CAAE,SAAS,SAAS,UAAW,CAAE;AAC9D;AAEO,SAAS,cAAe,QAAQ,QAAQ,OAAO,SAAU;AAC/D,QAAM,uBAAuB,OAAO;AACpC,QAAM,iBAAiB;AAAA,IACtB,WAAW,oBAAqB,oBAAqB;AAAA,IACrD,WAAW,oBAAqB,oBAAqB;AAAA,IACrD,iBAAiB,0BAA2B,oBAAqB;AAAA,IACjE,UAAU,mBAAoB,oBAAqB;AAAA,EACpD;AACA,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAEA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AACD;AAEA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AACD;",
6
6
  "names": []
7
7
  }
@@ -1,11 +1,11 @@
1
1
  // packages/block-editor/src/hooks/contrast-checker.js
2
- import { useLayoutEffect, useReducer } from "@wordpress/element";
2
+ import { useEffect, useLayoutEffect, useReducer } from "@wordpress/element";
3
3
  import { useSelect } from "@wordpress/data";
4
4
  import { store as blocksStore } from "@wordpress/blocks";
5
5
  import { getBlockSelector } from "@wordpress/global-styles-engine";
6
- import ContrastChecker from "../components/contrast-checker/index.mjs";
6
+ import { speak } from "@wordpress/a11y";
7
+ import { getContrastWarning } from "../components/contrast-checker/index.mjs";
7
8
  import { useBlockElement } from "../components/block-list/use-block-props/use-block-refs.mjs";
8
- import { jsx } from "react/jsx-runtime";
9
9
  function getComputedValue(node, property) {
10
10
  return node.ownerDocument.defaultView.getComputedStyle(node).getPropertyValue(property);
11
11
  }
@@ -50,17 +50,24 @@ function reducer(prevColors, newColors) {
50
50
  );
51
51
  return hasChanged ? newColors : prevColors;
52
52
  }
53
- function BlockColorContrastChecker({ clientId, name }) {
53
+ function useBlockColorContrastWarning({
54
+ clientId,
55
+ name,
56
+ enabled = true,
57
+ checkTextColor = true,
58
+ checkLinkColor = true,
59
+ messageOverride
60
+ }) {
54
61
  const blockEl = useBlockElement(clientId);
55
62
  const [colors, setColors] = useReducer(reducer, {});
56
63
  const blockType = useSelect(
57
64
  (select) => {
58
- return name ? select(blocksStore).getBlockType(name) : void 0;
65
+ return name && enabled ? select(blocksStore).getBlockType(name) : void 0;
59
66
  },
60
- [name]
67
+ [name, enabled]
61
68
  );
62
69
  useLayoutEffect(() => {
63
- if (!blockEl || !blockType) {
70
+ if (!enabled || !blockEl || !blockType) {
64
71
  return;
65
72
  }
66
73
  window.requestAnimationFrame(
@@ -70,7 +77,7 @@ function BlockColorContrastChecker({ clientId, name }) {
70
77
  );
71
78
  });
72
79
  useLayoutEffect(() => {
73
- if (!blockEl || !blockType) {
80
+ if (!enabled || !blockEl || !blockType) {
74
81
  return;
75
82
  }
76
83
  const observer = new window.MutationObserver(() => {
@@ -78,23 +85,29 @@ function BlockColorContrastChecker({ clientId, name }) {
78
85
  });
79
86
  observer.observe(blockEl, {
80
87
  attributes: true,
81
- attributeFilter: ["class", "style"]
88
+ attributeFilter: ["class", "style"],
89
+ subtree: true
82
90
  });
83
91
  return () => {
84
92
  observer.disconnect();
85
93
  };
86
- }, [blockEl, blockType]);
87
- return /* @__PURE__ */ jsx(
88
- ContrastChecker,
89
- {
90
- backgroundColor: colors.backgroundColor,
91
- textColor: colors.textColor,
92
- linkColor: colors.linkColor,
93
- enableAlphaChecker: true
94
+ }, [enabled, blockEl, blockType]);
95
+ const warning = enabled ? getContrastWarning({
96
+ backgroundColor: colors.backgroundColor,
97
+ textColor: checkTextColor ? colors.textColor : void 0,
98
+ linkColor: checkLinkColor ? colors.linkColor : void 0,
99
+ messageOverride,
100
+ enableAlphaChecker: true
101
+ }) : null;
102
+ const speakMessage = warning?.speakMessage;
103
+ useEffect(() => {
104
+ if (speakMessage) {
105
+ speak(speakMessage);
94
106
  }
95
- );
107
+ }, [speakMessage]);
108
+ return warning?.message;
96
109
  }
97
110
  export {
98
- BlockColorContrastChecker as default
111
+ useBlockColorContrastWarning as default
99
112
  };
100
113
  //# sourceMappingURL=contrast-checker.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/hooks/contrast-checker.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useLayoutEffect, useReducer } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { store as blocksStore } from '@wordpress/blocks';\nimport { getBlockSelector } from '@wordpress/global-styles-engine';\n\n/**\n * Internal dependencies\n */\nimport ContrastChecker from '../components/contrast-checker';\nimport { useBlockElement } from '../components/block-list/use-block-props/use-block-refs';\n\nfunction getComputedValue( node, property ) {\n\treturn node.ownerDocument.defaultView\n\t\t.getComputedStyle( node )\n\t\t.getPropertyValue( property );\n}\n\nfunction getBlockElementColors( blockEl, blockType ) {\n\tif ( ! blockEl || ! blockType ) {\n\t\treturn {};\n\t}\n\n\t// Get color-specific selectors.\n\tconst textSelector = getBlockSelector( blockType, 'color.text', {\n\t\tfallback: true,\n\t} );\n\tconst backgroundSelector = getBlockSelector(\n\t\tblockType,\n\t\t'color.background',\n\t\t{ fallback: true }\n\t);\n\n\t// Find target elements - querySelector handles all the complexity\n\tconst textElement = blockEl.querySelector( textSelector ) || blockEl;\n\tconst backgroundElement =\n\t\tblockEl.querySelector( backgroundSelector ) || blockEl;\n\tconst linkElement = blockEl.querySelector( 'a' );\n\n\t// Get computed colors from the appropriate elements\n\tconst textColor = getComputedValue( textElement, 'color' );\n\tconst linkColor =\n\t\tlinkElement && linkElement.textContent\n\t\t\t? getComputedValue( linkElement, 'color' )\n\t\t\t: undefined;\n\n\tlet backgroundColorNode = backgroundElement;\n\tlet backgroundColor = getComputedValue(\n\t\tbackgroundColorNode,\n\t\t'background-color'\n\t);\n\twhile (\n\t\tbackgroundColor === 'rgba(0, 0, 0, 0)' &&\n\t\tbackgroundColorNode.parentNode &&\n\t\tbackgroundColorNode.parentNode.nodeType ===\n\t\t\tbackgroundColorNode.parentNode.ELEMENT_NODE\n\t) {\n\t\tbackgroundColorNode = backgroundColorNode.parentNode;\n\t\tbackgroundColor = getComputedValue(\n\t\t\tbackgroundColorNode,\n\t\t\t'background-color'\n\t\t);\n\t}\n\n\treturn {\n\t\ttextColor,\n\t\tbackgroundColor,\n\t\tlinkColor,\n\t};\n}\n\nfunction reducer( prevColors, newColors ) {\n\tconst hasChanged = Object.keys( newColors ).some(\n\t\t( key ) => prevColors[ key ] !== newColors[ key ]\n\t);\n\n\t// Do not re-render if the colors have not changed.\n\treturn hasChanged ? newColors : prevColors;\n}\n\nexport default function BlockColorContrastChecker( { clientId, name } ) {\n\tconst blockEl = useBlockElement( clientId );\n\tconst [ colors, setColors ] = useReducer( reducer, {} );\n\n\tconst blockType = useSelect(\n\t\t( select ) => {\n\t\t\treturn name\n\t\t\t\t? select( blocksStore ).getBlockType( name )\n\t\t\t\t: undefined;\n\t\t},\n\t\t[ name ]\n\t);\n\n\t// There are so many things that can change the color of a block\n\t// So we perform this check on every render.\n\tuseLayoutEffect( () => {\n\t\tif ( ! blockEl || ! blockType ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Combine `useLayoutEffect` and two rAF calls to ensure that values are read\n\t\t// after the current paint but before the next paint.\n\t\twindow.requestAnimationFrame( () =>\n\t\t\twindow.requestAnimationFrame( () =>\n\t\t\t\tsetColors( getBlockElementColors( blockEl, blockType ) )\n\t\t\t)\n\t\t);\n\t} );\n\n\t// Runs in its own effect with dependencies so the observer is only\n\t// recreated when the block element or block type changes.\n\tuseLayoutEffect( () => {\n\t\tif ( ! blockEl || ! blockType ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst observer = new window.MutationObserver( () => {\n\t\t\tsetColors( getBlockElementColors( blockEl, blockType ) );\n\t\t} );\n\n\t\tobserver.observe( blockEl, {\n\t\t\tattributes: true,\n\t\t\tattributeFilter: [ 'class', 'style' ],\n\t\t} );\n\n\t\treturn () => {\n\t\t\tobserver.disconnect();\n\t\t};\n\t}, [ blockEl, blockType ] );\n\n\treturn (\n\t\t<ContrastChecker\n\t\t\tbackgroundColor={ colors.backgroundColor }\n\t\t\ttextColor={ colors.textColor }\n\t\t\tlinkColor={ colors.linkColor }\n\t\t\tenableAlphaChecker\n\t\t/>\n\t);\n}\n"],
5
- "mappings": ";AAGA,SAAS,iBAAiB,kBAAkB;AAC5C,SAAS,iBAAiB;AAC1B,SAAS,SAAS,mBAAmB;AACrC,SAAS,wBAAwB;AAKjC,OAAO,qBAAqB;AAC5B,SAAS,uBAAuB;AAyH9B;AAvHF,SAAS,iBAAkB,MAAM,UAAW;AAC3C,SAAO,KAAK,cAAc,YACxB,iBAAkB,IAAK,EACvB,iBAAkB,QAAS;AAC9B;AAEA,SAAS,sBAAuB,SAAS,WAAY;AACpD,MAAK,CAAE,WAAW,CAAE,WAAY;AAC/B,WAAO,CAAC;AAAA,EACT;AAGA,QAAM,eAAe,iBAAkB,WAAW,cAAc;AAAA,IAC/D,UAAU;AAAA,EACX,CAAE;AACF,QAAM,qBAAqB;AAAA,IAC1B;AAAA,IACA;AAAA,IACA,EAAE,UAAU,KAAK;AAAA,EAClB;AAGA,QAAM,cAAc,QAAQ,cAAe,YAAa,KAAK;AAC7D,QAAM,oBACL,QAAQ,cAAe,kBAAmB,KAAK;AAChD,QAAM,cAAc,QAAQ,cAAe,GAAI;AAG/C,QAAM,YAAY,iBAAkB,aAAa,OAAQ;AACzD,QAAM,YACL,eAAe,YAAY,cACxB,iBAAkB,aAAa,OA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AAA,IACrC,CAAE;AAEF,WAAO,MAAM;AACZ,eAAS,WAAW;AAAA,IACrB;AAAA,EACD,GAAG,CAAE,SAAS,SAAU,CAAE;AAE1B,SACC;AAAA,IAAC;AAAA;AAAA,MACA,iBAAkB,OAAO;AAAA,MACzB,WAAY,OAAO;AAAA,MACnB,WAAY,OAAO;AAAA,MACnB,oBAAkB;AAAA;AAAA,EACnB;AAEF;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useEffect, useLayoutEffect, useReducer } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { store as blocksStore } from '@wordpress/blocks';\nimport { getBlockSelector } from '@wordpress/global-styles-engine';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport { getContrastWarning } from '../components/contrast-checker';\n\nimport { useBlockElement } from '../components/block-list/use-block-props/use-block-refs';\n\nfunction getComputedValue( node, property ) {\n\treturn node.ownerDocument.defaultView\n\t\t.getComputedStyle( node )\n\t\t.getPropertyValue( property );\n}\n\nfunction getBlockElementColors( blockEl, blockType ) {\n\tif ( ! blockEl || ! blockType ) {\n\t\treturn {};\n\t}\n\n\t// Get color-specific selectors.\n\tconst textSelector = getBlockSelector( blockType, 'color.text', {\n\t\tfallback: true,\n\t} );\n\tconst backgroundSelector = getBlockSelector(\n\t\tblockType,\n\t\t'color.background',\n\t\t{ fallback: true }\n\t);\n\n\t// Find target elements - querySelector handles all the complexity\n\tconst textElement = blockEl.querySelector( textSelector ) || blockEl;\n\tconst backgroundElement =\n\t\tblockEl.querySelector( backgroundSelector ) || blockEl;\n\tconst linkElement = blockEl.querySelector( 'a' );\n\n\t// Get computed colors from the appropriate elements\n\tconst textColor = getComputedValue( textElement, 'color' );\n\tconst linkColor =\n\t\tlinkElement && linkElement.textContent\n\t\t\t? getComputedValue( linkElement, 'color' )\n\t\t\t: undefined;\n\n\tlet backgroundColorNode = backgroundElement;\n\tlet backgroundColor = getComputedValue(\n\t\tbackgroundColorNode,\n\t\t'background-color'\n\t);\n\twhile (\n\t\tbackgroundColor === 'rgba(0, 0, 0, 0)' &&\n\t\tbackgroundColorNode.parentNode &&\n\t\tbackgroundColorNode.parentNode.nodeType ===\n\t\t\tbackgroundColorNode.parentNode.ELEMENT_NODE\n\t) {\n\t\tbackgroundColorNode = backgroundColorNode.parentNode;\n\t\tbackgroundColor = getComputedValue(\n\t\t\tbackgroundColorNode,\n\t\t\t'background-color'\n\t\t);\n\t}\n\n\treturn {\n\t\ttextColor,\n\t\tbackgroundColor,\n\t\tlinkColor,\n\t};\n}\n\nfunction reducer( prevColors, newColors ) {\n\tconst hasChanged = Object.keys( newColors ).some(\n\t\t( key ) => prevColors[ key ] !== newColors[ key ]\n\t);\n\n\t// Do not re-render if the colors have not changed.\n\treturn hasChanged ? newColors : prevColors;\n}\n\n/**\n * Returns a contrast warning message for a block's computed colors, or\n * `undefined` when contrast is sufficient or checking is disabled.\n *\n * Colors are read from the rendered block element so that inherited values\n * (e.g. from Global Styles or ancestor blocks) are taken into account.\n *\n * @param {Object} props\n * @param {string} props.clientId Block client ID.\n * @param {string} props.name Block name.\n * @param {boolean} [props.enabled] Whether contrast checking is active.\n * @param {boolean} [props.checkTextColor] Whether to evaluate the text/background pair.\n * @param {boolean} [props.checkLinkColor] Whether to evaluate the link/background pair.\n * @param {string} [props.messageOverride] Caller-provided copy used in place of the generic guidance.\n *\n * @return {?string} The warning message, if any.\n */\nexport default function useBlockColorContrastWarning( {\n\tclientId,\n\tname,\n\tenabled = true,\n\tcheckTextColor = true,\n\tcheckLinkColor = true,\n\tmessageOverride,\n} ) {\n\tconst blockEl = useBlockElement( clientId );\n\tconst [ colors, setColors ] = useReducer( reducer, {} );\n\n\tconst blockType = useSelect(\n\t\t( select ) => {\n\t\t\treturn name && enabled\n\t\t\t\t? select( blocksStore ).getBlockType( name )\n\t\t\t\t: undefined;\n\t\t},\n\t\t[ name, enabled ]\n\t);\n\n\t// There are so many things that can change the color of a block\n\t// So we perform this check on every render.\n\tuseLayoutEffect( () => {\n\t\tif ( ! enabled || ! blockEl || ! blockType ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Combine `useLayoutEffect` and two rAF calls to ensure that values are read\n\t\t// after the current paint but before the next paint.\n\t\twindow.requestAnimationFrame( () =>\n\t\t\twindow.requestAnimationFrame( () =>\n\t\t\t\tsetColors( getBlockElementColors( blockEl, blockType ) )\n\t\t\t)\n\t\t);\n\t} );\n\n\t// Runs in its own effect with dependencies so the observer is only\n\t// recreated when the block element or block type changes.\n\tuseLayoutEffect( () => {\n\t\tif ( ! enabled || ! blockEl || ! blockType ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst observer = new window.MutationObserver( () => {\n\t\t\tsetColors( getBlockElementColors( blockEl, blockType ) );\n\t\t} );\n\n\t\tobserver.observe( blockEl, {\n\t\t\tattributes: true,\n\t\t\tattributeFilter: [ 'class', 'style' ],\n\t\t\tsubtree: true,\n\t\t} );\n\n\t\treturn () => {\n\t\t\tobserver.disconnect();\n\t\t};\n\t}, [ enabled, blockEl, blockType ] );\n\n\tconst warning = enabled\n\t\t? getContrastWarning( {\n\t\t\t\tbackgroundColor: colors.backgroundColor,\n\t\t\t\ttextColor: checkTextColor ? colors.textColor : undefined,\n\t\t\t\tlinkColor: checkLinkColor ? colors.linkColor : undefined,\n\t\t\t\tmessageOverride,\n\t\t\t\tenableAlphaChecker: true,\n\t\t } )\n\t\t: null;\n\n\t// The popover Notice that displays this warning is muted\n\t// (`spokenMessage={ null }`), so this hook is the single source of the\n\t// spoken announcement. Announce only when the warning message itself\n\t// appears or changes; keying off `speakMessage` rather than the raw\n\t// computed `colors` avoids re-announcing the same warning when colors\n\t// recompute without changing the outcome.\n\tconst speakMessage = warning?.speakMessage;\n\tuseEffect( () => {\n\t\tif ( speakMessage ) {\n\t\t\tspeak( speakMessage );\n\t\t}\n\t}, [ speakMessage ] );\n\n\treturn warning?.message;\n}\n"],
5
+ "mappings": ";AAGA,SAAS,WAAW,iBAAiB,kBAAkB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a;AAAA,IACrB;AAAA,EACD,GAAG,CAAE,YAAa,CAAE;AAEpB,SAAO,SAAS;AACjB;",
6
6
  "names": []
7
7
  }
@@ -26,7 +26,6 @@ function CustomClassNameControlsPure({ className, setAttributes }) {
26
26
  return /* @__PURE__ */ jsx(InspectorControls, { group: "advanced", children: /* @__PURE__ */ jsx(
27
27
  TextControl,
28
28
  {
29
- __next40pxDefaultSize: true,
30
29
  autoComplete: "off",
31
30
  label: __("Additional CSS class(es)"),
32
31
  value: className || "",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/hooks/custom-class-name.js"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { TextControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { hasBlockSupport } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { InspectorControls } from '../components';\nimport { useBlockEditingMode } from '../components/block-editing-mode';\n\n/**\n * Filters registered block settings, extending attributes to include `className`.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nexport function addAttribute( settings ) {\n\tif ( hasBlockSupport( settings, 'customClassName', true ) ) {\n\t\t// Gracefully handle if settings.attributes is undefined.\n\t\tsettings.attributes = {\n\t\t\t...settings.attributes,\n\t\t\tclassName: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t};\n\t}\n\n\treturn settings;\n}\n\nfunction CustomClassNameControlsPure( { className, setAttributes } ) {\n\tconst blockEditingMode = useBlockEditingMode();\n\tif ( blockEditingMode !== 'default' ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<InspectorControls group=\"advanced\">\n\t\t\t<TextControl\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\tautoComplete=\"off\"\n\t\t\t\tlabel={ __( 'Additional CSS class(es)' ) }\n\t\t\t\tvalue={ className || '' }\n\t\t\t\tonChange={ ( nextValue ) => {\n\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\tclassName: nextValue !== '' ? nextValue : undefined,\n\t\t\t\t\t} );\n\t\t\t\t} }\n\t\t\t\thelp={ __( 'Separate multiple classes with spaces.' ) }\n\t\t\t/>\n\t\t</InspectorControls>\n\t);\n}\n\nexport default {\n\tedit: CustomClassNameControlsPure,\n\taddSaveProps,\n\tattributeKeys: [ 'className' ],\n\thasSupport( name ) {\n\t\treturn hasBlockSupport( name, 'customClassName', true );\n\t},\n};\n\n/**\n * Override props assigned to save component to inject the className, if block\n * supports customClassName. This is only applied if the block's save result is an\n * element and not a markup string.\n *\n * @param {Object} extraProps Additional props applied to save element.\n * @param {Object} blockType Block type.\n * @param {Object} attributes Current block attributes.\n *\n * @return {Object} Filtered props applied to save element.\n */\nexport function addSaveProps( extraProps, blockType, attributes ) {\n\tif (\n\t\thasBlockSupport( blockType, 'customClassName', true ) &&\n\t\tattributes.className\n\t) {\n\t\textraProps.className = clsx(\n\t\t\textraProps.className,\n\t\t\tattributes.className\n\t\t);\n\t}\n\n\treturn extraProps;\n}\n\nexport function addTransforms( result, source, index, results ) {\n\tif ( ! hasBlockSupport( result.name, 'customClassName', true ) ) {\n\t\treturn result;\n\t}\n\n\t// If the condition verifies we are probably in the presence of a wrapping transform\n\t// e.g: nesting paragraphs in a group or columns and in that case the class should not be kept.\n\tif ( results.length === 1 && result.innerBlocks.length === source.length ) {\n\t\treturn result;\n\t}\n\n\t// If we are transforming one block to multiple blocks or multiple blocks to one block,\n\t// we ignore the class during the transform.\n\tif (\n\t\t( results.length === 1 && source.length > 1 ) ||\n\t\t( results.length > 1 && source.length === 1 )\n\t) {\n\t\treturn result;\n\t}\n\n\t// If we are in presence of transform between one or more block in the source\n\t// that have one or more blocks in the result\n\t// we apply the class on source N to the result N,\n\t// if source N does not exists we do nothing.\n\tif ( source[ index ] ) {\n\t\tconst originClassName = source[ index ]?.attributes.className;\n\t\t// Avoid overriding classes if the transformed block already includes them.\n\t\tif ( originClassName && result.attributes.className === undefined ) {\n\t\t\treturn {\n\t\t\t\t...result,\n\t\t\t\tattributes: {\n\t\t\t\t\t...result.attributes,\n\t\t\t\t\tclassName: originClassName,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t}\n\treturn result;\n}\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/editor/custom-class-name/attribute',\n\taddAttribute\n);\n\naddFilter(\n\t'blocks.switchToBlockType.transformedBlock',\n\t'core/customClassName/addTransforms',\n\taddTransforms\n);\n"],
5
- "mappings": ";AAGA,OAAO,UAAU;AAKjB,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;AAC5B,SAAS,UAAU;AACnB,SAAS,uBAAuB;AAKhC,SAAS,yBAAyB;AAClC,SAAS,2BAA2B;AA+BjC;AAtBI,SAAS,aAAc,UAAW;AACxC,MAAK,gBAAiB,UAAU,mBAAmB,IAAK,GAAI;AAE3D,aAAS,aAAa;AAAA,MACrB,GAAG,SAAS;AAAA,MACZ,WAAW;AAAA,QACV,MAAM;AAAA,MACP;AAAA,IACD;AAAA,EACD;AAEA,SAAO;AACR;AAEA,SAAS,4BAA6B,EAAE,WAAW,cAAc,GAAI;AACpE,QAAM,mBAAmB,oBAAoB;AAC7C,MAAK,qBAAqB,WAAY;AACrC,WAAO;AAAA,EACR;AAEA,SACC,oBAAC,qBAAkB,OAAM,YACxB;AAAA,IAAC;AAAA;AAAA,MACA,uBAAqB;AAAA,MACrB,cAAa;AAAA,MACb,OAAQ,GAAI,0BAA2B;AAAA,MACvC,OAAQ,aAAa;AAAA,MACrB,UAAW,CAAE,cAAe;AAC3B,sBAAe;AAAA,UACd,WAAW,cAAc,KAAK,YAAY;AAAA,QAC3C,CAAE;AAAA,MACH;AAAA,MACA,MAAO,GAAI,wCAAyC;AAAA;AAAA,EACrD,GACD;AAEF;AAEA,IAAO,4BAAQ;AAAA,EACd,MAAM;AAAA,EACN;AAAA,EACA,eAAe,CAAE,WAAY;AAAA,EAC7B,WAAY,MAAO;AAClB,WAAO,gBAAiB,MAAM,mBAAmB,IAAK;AAAA,EACvD;AACD;AAaO,SAAS,aAAc,YAAY,WAAW,YAAa;AACjE,MACC,gBAAiB,WAAW,mBAAmB,IAAK,KACpD,WAAW,WACV;AACD,eAAW,YAAY;AAAA,MACtB,WAAW;AAAA,MACX,WAAW;AAAA,IACZ;AAAA,EACD;AAEA,SAAO;AACR;AAEO,SAAS,cAAe,QAAQ,QAAQ,OAAO,SAAU;AAC/D,MAAK,CAAE,gBAAiB,OAAO,MAAM,mBAAmB,IAAK,GAAI;AAChE,WAAO;AAAA,EACR;AAIA,MAAK,QAAQ,WAAW,KAAK,OAAO,YAAY,WAAW,OAAO,QAAS;AAC1E,WAAO;AAAA,EACR;AAIA,MACG,QAAQ,WAAW,KAAK,OAAO,SAAS,KACxC,QAAQ,SAAS,KAAK,OAAO,WAAW,GACzC;AACD,WAAO;AAAA,EACR;AAMA,MAAK,OAAQ,KAAM,GAAI;AACtB,UAAM,kBAAkB,OAAQ,KAAM,GAAG,WAAW;AAEpD,QAAK,mBAAmB,OAAO,WAAW,cAAc,QAAY;AACnE,aAAO;AAAA,QACN,GAAG;AAAA,QACH,YAAY;AAAA,UACX,GAAG,OAAO;AAAA,UACV,WAAW;AAAA,QACZ;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR;AAEA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AACD;AAEA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AACD;",
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { TextControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { hasBlockSupport } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { InspectorControls } from '../components';\nimport { useBlockEditingMode } from '../components/block-editing-mode';\n\n/**\n * Filters registered block settings, extending attributes to include `className`.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nexport function addAttribute( settings ) {\n\tif ( hasBlockSupport( settings, 'customClassName', true ) ) {\n\t\t// Gracefully handle if settings.attributes is undefined.\n\t\tsettings.attributes = {\n\t\t\t...settings.attributes,\n\t\t\tclassName: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t};\n\t}\n\n\treturn settings;\n}\n\nfunction CustomClassNameControlsPure( { className, setAttributes } ) {\n\tconst blockEditingMode = useBlockEditingMode();\n\tif ( blockEditingMode !== 'default' ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<InspectorControls group=\"advanced\">\n\t\t\t<TextControl\n\t\t\t\tautoComplete=\"off\"\n\t\t\t\tlabel={ __( 'Additional CSS class(es)' ) }\n\t\t\t\tvalue={ className || '' }\n\t\t\t\tonChange={ ( nextValue ) => {\n\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\tclassName: nextValue !== '' ? nextValue : undefined,\n\t\t\t\t\t} );\n\t\t\t\t} }\n\t\t\t\thelp={ __( 'Separate multiple classes with spaces.' ) }\n\t\t\t/>\n\t\t</InspectorControls>\n\t);\n}\n\nexport default {\n\tedit: CustomClassNameControlsPure,\n\taddSaveProps,\n\tattributeKeys: [ 'className' ],\n\thasSupport( name ) {\n\t\treturn hasBlockSupport( name, 'customClassName', true );\n\t},\n};\n\n/**\n * Override props assigned to save component to inject the className, if block\n * supports customClassName. This is only applied if the block's save result is an\n * element and not a markup string.\n *\n * @param {Object} extraProps Additional props applied to save element.\n * @param {Object} blockType Block type.\n * @param {Object} attributes Current block attributes.\n *\n * @return {Object} Filtered props applied to save element.\n */\nexport function addSaveProps( extraProps, blockType, attributes ) {\n\tif (\n\t\thasBlockSupport( blockType, 'customClassName', true ) &&\n\t\tattributes.className\n\t) {\n\t\textraProps.className = clsx(\n\t\t\textraProps.className,\n\t\t\tattributes.className\n\t\t);\n\t}\n\n\treturn extraProps;\n}\n\nexport function addTransforms( result, source, index, results ) {\n\tif ( ! hasBlockSupport( result.name, 'customClassName', true ) ) {\n\t\treturn result;\n\t}\n\n\t// If the condition verifies we are probably in the presence of a wrapping transform\n\t// e.g: nesting paragraphs in a group or columns and in that case the class should not be kept.\n\tif ( results.length === 1 && result.innerBlocks.length === source.length ) {\n\t\treturn result;\n\t}\n\n\t// If we are transforming one block to multiple blocks or multiple blocks to one block,\n\t// we ignore the class during the transform.\n\tif (\n\t\t( results.length === 1 && source.length > 1 ) ||\n\t\t( results.length > 1 && source.length === 1 )\n\t) {\n\t\treturn result;\n\t}\n\n\t// If we are in presence of transform between one or more block in the source\n\t// that have one or more blocks in the result\n\t// we apply the class on source N to the result N,\n\t// if source N does not exists we do nothing.\n\tif ( source[ index ] ) {\n\t\tconst originClassName = source[ index ]?.attributes.className;\n\t\t// Avoid overriding classes if the transformed block already includes them.\n\t\tif ( originClassName && result.attributes.className === undefined ) {\n\t\t\treturn {\n\t\t\t\t...result,\n\t\t\t\tattributes: {\n\t\t\t\t\t...result.attributes,\n\t\t\t\t\tclassName: originClassName,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t}\n\treturn result;\n}\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/editor/custom-class-name/attribute',\n\taddAttribute\n);\n\naddFilter(\n\t'blocks.switchToBlockType.transformedBlock',\n\t'core/customClassName/addTransforms',\n\taddTransforms\n);\n"],
5
+ "mappings": ";AAGA,OAAO,UAAU;AAKjB,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;AAC5B,SAAS,UAAU;AACnB,SAAS,uBAAuB;AAKhC,SAAS,yBAAyB;AAClC,SAAS,2BAA2B;AA+BjC;AAtBI,SAAS,aAAc,UAAW;AACxC,MAAK,gBAAiB,UAAU,mBAAmB,IAAK,GAAI;AAE3D,aAAS,aAAa;AAAA,MACrB,GAAG,SAAS;AAAA,MACZ,WAAW;AAAA,QACV,MAAM;AAAA,MACP;AAAA,IACD;AAAA,EACD;AAEA,SAAO;AACR;AAEA,SAAS,4BAA6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,YAAY;AAAA,UACX,GAAG,OAAO;AAAA,UACV,WAAW;AAAA,QACZ;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR;AAEA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AACD;AAEA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AACD;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,115 @@
1
+ // packages/block-editor/src/hooks/elements.js
2
+ import { getBlockSupport } from "@wordpress/blocks";
3
+ import { useMemo, useCallback } from "@wordpress/element";
4
+ import { useSelect } from "@wordpress/data";
5
+ import { __ } from "@wordpress/i18n";
6
+ import InspectorControls from "../components/inspector-controls/index.mjs";
7
+ import {
8
+ useHasColorPanel,
9
+ default as StylesColorPanel
10
+ } from "../components/global-styles/color-panel.mjs";
11
+ import { cleanEmptyObject } from "./utils.mjs";
12
+ import { store as blockEditorStore } from "../store/index.mjs";
13
+ import { COLOR_SUPPORT_KEY } from "./color.mjs";
14
+ import useBlockColorContrastWarning from "./contrast-checker.mjs";
15
+ import {
16
+ getStyleForState,
17
+ isDefaultBlockStyleState,
18
+ setStyleForState,
19
+ useBlockStyleState
20
+ } from "./block-style-state.mjs";
21
+ import { jsx } from "react/jsx-runtime";
22
+ function ElementsInspectorControl({ children, resetAllFilter }) {
23
+ const attributesResetAllFilter = useCallback(
24
+ (attributes) => {
25
+ const updatedStyle = resetAllFilter(attributes.style);
26
+ return {
27
+ ...attributes,
28
+ style: cleanEmptyObject(updatedStyle)
29
+ };
30
+ },
31
+ [resetAllFilter]
32
+ );
33
+ return /* @__PURE__ */ jsx(
34
+ InspectorControls,
35
+ {
36
+ group: "elements",
37
+ resetAllFilter: attributesResetAllFilter,
38
+ children
39
+ }
40
+ );
41
+ }
42
+ function ElementsEdit({
43
+ clientId,
44
+ name,
45
+ setAttributes,
46
+ settings,
47
+ asWrapper,
48
+ label,
49
+ defaultControls
50
+ }) {
51
+ const selectedState = useBlockStyleState();
52
+ const isEnabled = useHasColorPanel(settings);
53
+ const style = useSelect(
54
+ (select) => {
55
+ if (!isEnabled) {
56
+ return void 0;
57
+ }
58
+ const attributes = select(blockEditorStore).getBlockAttributes(clientId);
59
+ return attributes?.style;
60
+ },
61
+ [clientId, isEnabled]
62
+ );
63
+ const isStateSelected = !isDefaultBlockStyleState(selectedState);
64
+ const value = useMemo(() => {
65
+ if (isStateSelected) {
66
+ return getStyleForState(style, selectedState);
67
+ }
68
+ return style;
69
+ }, [isStateSelected, selectedState, style]);
70
+ const onChange = isStateSelected ? (newStyle) => {
71
+ setAttributes({
72
+ style: setStyleForState(style, selectedState, newStyle)
73
+ });
74
+ } : (newStyle) => {
75
+ setAttributes({ style: cleanEmptyObject(newStyle) });
76
+ };
77
+ const enableContrastChecking = !isStateSelected && !!value?.elements?.link?.color?.text && settings?.color?.link && false !== getBlockSupport(name, [
78
+ COLOR_SUPPORT_KEY,
79
+ "enableContrastChecker"
80
+ ]);
81
+ const contrastWarning = useBlockColorContrastWarning({
82
+ clientId,
83
+ name,
84
+ enabled: !!enableContrastChecking,
85
+ checkTextColor: false,
86
+ messageOverride: __(
87
+ "This link color has poor contrast against the background. Consider increasing contrast."
88
+ )
89
+ });
90
+ if (!isEnabled) {
91
+ return null;
92
+ }
93
+ defaultControls = defaultControls ? defaultControls : getBlockSupport(name, [
94
+ COLOR_SUPPORT_KEY,
95
+ "__experimentalDefaultControls"
96
+ ]);
97
+ const Wrapper = asWrapper || ElementsInspectorControl;
98
+ return /* @__PURE__ */ jsx(
99
+ StylesColorPanel,
100
+ {
101
+ as: Wrapper,
102
+ panelId: clientId,
103
+ settings,
104
+ value,
105
+ onChange,
106
+ defaultControls,
107
+ label,
108
+ contrastWarning
109
+ }
110
+ );
111
+ }
112
+ export {
113
+ ElementsEdit
114
+ };
115
+ //# sourceMappingURL=elements.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/hooks/elements.js"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { getBlockSupport } from '@wordpress/blocks';\nimport { useMemo, useCallback } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport InspectorControls from '../components/inspector-controls';\nimport {\n\tuseHasColorPanel,\n\tdefault as StylesColorPanel,\n} from '../components/global-styles/color-panel';\nimport { cleanEmptyObject } from './utils';\nimport { store as blockEditorStore } from '../store';\nimport { COLOR_SUPPORT_KEY } from './color';\nimport useBlockColorContrastWarning from './contrast-checker';\nimport {\n\tgetStyleForState,\n\tisDefaultBlockStyleState,\n\tsetStyleForState,\n\tuseBlockStyleState,\n} from './block-style-state';\n\nfunction ElementsInspectorControl( { children, resetAllFilter } ) {\n\tconst attributesResetAllFilter = useCallback(\n\t\t( attributes ) => {\n\t\t\tconst updatedStyle = resetAllFilter( attributes.style );\n\t\t\treturn {\n\t\t\t\t...attributes,\n\t\t\t\tstyle: cleanEmptyObject( updatedStyle ),\n\t\t\t};\n\t\t},\n\t\t[ resetAllFilter ]\n\t);\n\n\treturn (\n\t\t<InspectorControls\n\t\t\tgroup=\"elements\"\n\t\t\tresetAllFilter={ attributesResetAllFilter }\n\t\t>\n\t\t\t{ children }\n\t\t</InspectorControls>\n\t);\n}\n\nexport function ElementsEdit( {\n\tclientId,\n\tname,\n\tsetAttributes,\n\tsettings,\n\tasWrapper,\n\tlabel,\n\tdefaultControls,\n} ) {\n\tconst selectedState = useBlockStyleState();\n\tconst isEnabled = useHasColorPanel( settings );\n\n\tconst style = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! isEnabled ) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tconst attributes =\n\t\t\t\tselect( blockEditorStore ).getBlockAttributes( clientId );\n\t\t\treturn attributes?.style;\n\t\t},\n\t\t[ clientId, isEnabled ]\n\t);\n\n\tconst isStateSelected = ! isDefaultBlockStyleState( selectedState );\n\n\tconst value = useMemo( () => {\n\t\tif ( isStateSelected ) {\n\t\t\treturn getStyleForState( style, selectedState );\n\t\t}\n\t\treturn style;\n\t}, [ isStateSelected, selectedState, style ] );\n\n\tconst onChange = isStateSelected\n\t\t? ( newStyle ) => {\n\t\t\t\tsetAttributes( {\n\t\t\t\t\tstyle: setStyleForState( style, selectedState, newStyle ),\n\t\t\t\t} );\n\t\t }\n\t\t: ( newStyle ) => {\n\t\t\t\tsetAttributes( { style: cleanEmptyObject( newStyle ) } );\n\t\t };\n\n\t// Text and background color failures are reported by the Typography and\n\t// Background panels, which own those selections.\n\tconst enableContrastChecking =\n\t\t! isStateSelected &&\n\t\t!! value?.elements?.link?.color?.text &&\n\t\tsettings?.color?.link &&\n\t\tfalse !==\n\t\t\tgetBlockSupport( name, [\n\t\t\t\tCOLOR_SUPPORT_KEY,\n\t\t\t\t'enableContrastChecker',\n\t\t\t] );\n\n\tconst contrastWarning = useBlockColorContrastWarning( {\n\t\tclientId,\n\t\tname,\n\t\tenabled: !! enableContrastChecking,\n\t\tcheckTextColor: false,\n\t\tmessageOverride: __(\n\t\t\t'This link color has poor contrast against the background. Consider increasing contrast.'\n\t\t),\n\t} );\n\n\tif ( ! isEnabled ) {\n\t\treturn null;\n\t}\n\n\tdefaultControls = defaultControls\n\t\t? defaultControls\n\t\t: getBlockSupport( name, [\n\t\t\t\tCOLOR_SUPPORT_KEY,\n\t\t\t\t'__experimentalDefaultControls',\n\t\t ] );\n\n\tconst Wrapper = asWrapper || ElementsInspectorControl;\n\n\treturn (\n\t\t<StylesColorPanel\n\t\t\tas={ Wrapper }\n\t\t\tpanelId={ clientId }\n\t\t\tsettings={ settings }\n\t\t\tvalue={ value }\n\t\t\tonChange={ onChange }\n\t\t\tdefaultControls={ defaultControls }\n\t\t\tlabel={ label }\n\t\t\tcontrastWarning={ contrastWarning }\n\t\t/>\n\t);\n}\n"],
5
+ "mappings": ";AAGA,SAAS,uBAAuB;AAChC,SAAS,SAAS,mBAAmB;AACrC,SAAS,iBAAiB;AAC1B,SAAS,UAAU;AAKnB,OAAO,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