@wordpress/block-editor 9.5.0 → 9.7.1-next.d6164808d3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (548) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/components/block-alignment-control/use-available-alignments.js +1 -1
  3. package/build/components/block-alignment-control/use-available-alignments.js.map +1 -1
  4. package/build/components/block-edit-visually-button/index.js +46 -0
  5. package/build/components/block-edit-visually-button/index.js.map +1 -0
  6. package/build/components/block-list/block.js +12 -2
  7. package/build/components/block-list/block.js.map +1 -1
  8. package/build/components/block-list/index.native.js +1 -1
  9. package/build/components/block-list/index.native.js.map +1 -1
  10. package/build/components/block-lock/modal.js +2 -2
  11. package/build/components/block-lock/modal.js.map +1 -1
  12. package/build/components/block-mobile-toolbar/block-actions-menu.native.js +1 -1
  13. package/build/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
  14. package/build/components/block-mover/mover-description.js +95 -32
  15. package/build/components/block-mover/mover-description.js.map +1 -1
  16. package/build/components/block-popover/inbetween.js +5 -3
  17. package/build/components/block-popover/inbetween.js.map +1 -1
  18. package/build/components/block-settings-menu/index.js +2 -6
  19. package/build/components/block-settings-menu/index.js.map +1 -1
  20. package/build/components/block-settings-menu-controls/index.js +1 -1
  21. package/build/components/block-settings-menu-controls/index.js.map +1 -1
  22. package/build/components/block-styles/index.js +3 -6
  23. package/build/components/block-styles/index.js.map +1 -1
  24. package/build/components/block-styles/preview.native.js +1 -3
  25. package/build/components/block-styles/preview.native.js.map +1 -1
  26. package/build/components/block-switcher/index.js +10 -16
  27. package/build/components/block-switcher/index.js.map +1 -1
  28. package/build/components/block-toolbar/index.js +5 -1
  29. package/build/components/block-toolbar/index.js.map +1 -1
  30. package/build/components/block-tools/block-selection-button.js +1 -7
  31. package/build/components/block-tools/block-selection-button.js.map +1 -1
  32. package/build/components/block-tools/index.js +4 -1
  33. package/build/components/block-tools/index.js.map +1 -1
  34. package/build/components/block-types-list/index.js +1 -1
  35. package/build/components/block-types-list/index.js.map +1 -1
  36. package/build/components/block-types-list/index.native.js +65 -23
  37. package/build/components/block-types-list/index.native.js.map +1 -1
  38. package/build/components/border-radius-control/all-input-control.js +31 -3
  39. package/build/components/border-radius-control/all-input-control.js.map +1 -1
  40. package/build/components/border-radius-control/index.js +23 -7
  41. package/build/components/border-radius-control/index.js.map +1 -1
  42. package/build/components/border-radius-control/input-controls.js +21 -6
  43. package/build/components/border-radius-control/input-controls.js.map +1 -1
  44. package/build/components/border-radius-control/utils.js +13 -16
  45. package/build/components/border-radius-control/utils.js.map +1 -1
  46. package/build/components/colors/utils.js +6 -2
  47. package/build/components/colors/utils.js.map +1 -1
  48. package/build/components/colors/with-colors.js +17 -4
  49. package/build/components/colors/with-colors.js.map +1 -1
  50. package/build/components/colors-gradients/control.js +8 -4
  51. package/build/components/colors-gradients/control.js.map +1 -1
  52. package/build/components/colors-gradients/dropdown.js +9 -3
  53. package/build/components/colors-gradients/dropdown.js.map +1 -1
  54. package/build/components/copy-handler/index.js +6 -0
  55. package/build/components/copy-handler/index.js.map +1 -1
  56. package/build/components/date-format-picker/index.js +2 -7
  57. package/build/components/date-format-picker/index.js.map +1 -1
  58. package/build/components/duotone/components.js +5 -5
  59. package/build/components/duotone/components.js.map +1 -1
  60. package/build/components/font-appearance-control/index.js +10 -4
  61. package/build/components/font-appearance-control/index.js.map +1 -1
  62. package/build/components/font-family/index.js +1 -1
  63. package/build/components/font-family/index.js.map +1 -1
  64. package/build/components/font-sizes/with-font-sizes.js +17 -4
  65. package/build/components/font-sizes/with-font-sizes.js.map +1 -1
  66. package/build/components/image-editor/cropper.js +4 -3
  67. package/build/components/image-editor/cropper.js.map +1 -1
  68. package/build/components/image-editor/index.js +3 -1
  69. package/build/components/image-editor/index.js.map +1 -1
  70. package/build/components/image-size-control/index.js +3 -1
  71. package/build/components/image-size-control/index.js.map +1 -1
  72. package/build/components/index.js +22 -6
  73. package/build/components/index.js.map +1 -1
  74. package/build/components/index.native.js +11 -4
  75. package/build/components/index.native.js.map +1 -1
  76. package/build/components/inserter/block-types-tab.native.js +30 -16
  77. package/build/components/inserter/block-types-tab.native.js.map +1 -1
  78. package/build/components/inserter/index.native.js +8 -3
  79. package/build/components/inserter/index.native.js.map +1 -1
  80. package/build/components/inserter/preview-panel.js +8 -8
  81. package/build/components/inserter/preview-panel.js.map +1 -1
  82. package/build/components/inserter/reusable-blocks-tab.native.js +5 -1
  83. package/build/components/inserter/reusable-blocks-tab.native.js.map +1 -1
  84. package/build/components/inserter/search-items.js +22 -4
  85. package/build/components/inserter/search-items.js.map +1 -1
  86. package/build/components/inserter/search-results.native.js +5 -2
  87. package/build/components/inserter/search-results.native.js.map +1 -1
  88. package/build/components/inserter/utils.native.js +21 -0
  89. package/build/components/inserter/utils.native.js.map +1 -1
  90. package/build/components/inserter-list-item/index.js +7 -20
  91. package/build/components/inserter-list-item/index.js.map +1 -1
  92. package/build/components/letter-spacing-control/index.js +6 -3
  93. package/build/components/letter-spacing-control/index.js.map +1 -1
  94. package/build/components/line-height-control/index.js +6 -3
  95. package/build/components/line-height-control/index.js.map +1 -1
  96. package/build/components/link-control/is-url-like.js +1 -7
  97. package/build/components/link-control/is-url-like.js.map +1 -1
  98. package/build/components/link-control/link-preview.js +0 -1
  99. package/build/components/link-control/link-preview.js.map +1 -1
  100. package/build/components/link-control/use-search-handler.js +1 -7
  101. package/build/components/link-control/use-search-handler.js.map +1 -1
  102. package/build/components/list-view/block-select-button.js +5 -2
  103. package/build/components/list-view/block-select-button.js.map +1 -1
  104. package/build/components/list-view/branch.js +1 -7
  105. package/build/components/list-view/branch.js.map +1 -1
  106. package/build/components/list-view/expander.js +3 -1
  107. package/build/components/list-view/expander.js.map +1 -1
  108. package/build/components/list-view/use-block-selection.js +1 -7
  109. package/build/components/list-view/use-block-selection.js.map +1 -1
  110. package/build/components/media-upload/index.native.js +8 -3
  111. package/build/components/media-upload/index.native.js.map +1 -1
  112. package/build/components/observe-typing/index.js +22 -8
  113. package/build/components/observe-typing/index.js.map +1 -1
  114. package/build/components/preview-options/index.js +2 -2
  115. package/build/components/preview-options/index.js.map +1 -1
  116. package/build/components/{use-no-recursive-renders → recursion-provider}/index.js +40 -18
  117. package/build/components/recursion-provider/index.js.map +1 -0
  118. package/build/components/rich-text/format-toolbar-container.js +61 -12
  119. package/build/components/rich-text/format-toolbar-container.js.map +1 -1
  120. package/build/components/rich-text/index.js +8 -2
  121. package/build/components/rich-text/index.js.map +1 -1
  122. package/build/components/rich-text/index.native.js +3 -1
  123. package/build/components/rich-text/index.native.js.map +1 -1
  124. package/build/components/rich-text/use-before-input-rules.js +110 -0
  125. package/build/components/rich-text/use-before-input-rules.js.map +1 -0
  126. package/build/components/rich-text/use-enter.js +0 -4
  127. package/build/components/rich-text/use-enter.js.map +1 -1
  128. package/build/components/rich-text/use-format-types.js +39 -22
  129. package/build/components/rich-text/use-format-types.js.map +1 -1
  130. package/build/components/spacing-sizes-control/all-input-control.js +53 -0
  131. package/build/components/spacing-sizes-control/all-input-control.js.map +1 -0
  132. package/build/components/spacing-sizes-control/axial-input-controls.js +69 -0
  133. package/build/components/spacing-sizes-control/axial-input-controls.js.map +1 -0
  134. package/build/components/spacing-sizes-control/index.js +100 -0
  135. package/build/components/spacing-sizes-control/index.js.map +1 -0
  136. package/build/components/spacing-sizes-control/input-controls.js +52 -0
  137. package/build/components/spacing-sizes-control/input-controls.js.map +1 -0
  138. package/build/components/spacing-sizes-control/linked-button.js +38 -0
  139. package/build/components/spacing-sizes-control/linked-button.js.map +1 -0
  140. package/build/components/spacing-sizes-control/spacing-input-control.js +208 -0
  141. package/build/components/spacing-sizes-control/spacing-input-control.js.map +1 -0
  142. package/build/components/spacing-sizes-control/utils.js +202 -0
  143. package/build/components/spacing-sizes-control/utils.js.map +1 -0
  144. package/build/components/text-decoration-control/index.js +3 -1
  145. package/build/components/text-decoration-control/index.js.map +1 -1
  146. package/build/components/text-transform-control/index.js +3 -1
  147. package/build/components/text-transform-control/index.js.map +1 -1
  148. package/build/components/url-input/index.js +1 -1
  149. package/build/components/url-input/index.js.map +1 -1
  150. package/build/components/url-popover/image-url-input-ui.js +4 -1
  151. package/build/components/url-popover/image-url-input-ui.js.map +1 -1
  152. package/build/components/writing-flow/use-arrow-nav.js +4 -25
  153. package/build/components/writing-flow/use-arrow-nav.js.map +1 -1
  154. package/build/components/writing-flow/use-drag-selection.js +9 -2
  155. package/build/components/writing-flow/use-drag-selection.js.map +1 -1
  156. package/build/components/writing-flow/use-multi-selection.js +4 -2
  157. package/build/components/writing-flow/use-multi-selection.js.map +1 -1
  158. package/build/components/writing-flow/use-select-all.js +3 -1
  159. package/build/components/writing-flow/use-select-all.js.map +1 -1
  160. package/build/components/writing-flow/use-selection-observer.js +10 -2
  161. package/build/components/writing-flow/use-selection-observer.js.map +1 -1
  162. package/build/components/writing-flow/use-tab-nav.js +1 -1
  163. package/build/components/writing-flow/use-tab-nav.js.map +1 -1
  164. package/build/hooks/border-radius.js +2 -7
  165. package/build/hooks/border-radius.js.map +1 -1
  166. package/build/hooks/border.js +2 -2
  167. package/build/hooks/border.js.map +1 -1
  168. package/build/hooks/color.js +4 -1
  169. package/build/hooks/color.js.map +1 -1
  170. package/build/hooks/dimensions.js +15 -0
  171. package/build/hooks/dimensions.js.map +1 -1
  172. package/build/hooks/duotone.js +4 -4
  173. package/build/hooks/duotone.js.map +1 -1
  174. package/build/hooks/gap.js +6 -4
  175. package/build/hooks/gap.js.map +1 -1
  176. package/build/hooks/generated-class-name.js +1 -7
  177. package/build/hooks/generated-class-name.js.map +1 -1
  178. package/build/hooks/layout.js +42 -15
  179. package/build/hooks/layout.js.map +1 -1
  180. package/build/hooks/margin.js +28 -12
  181. package/build/hooks/margin.js.map +1 -1
  182. package/build/hooks/padding.js +19 -8
  183. package/build/hooks/padding.js.map +1 -1
  184. package/build/hooks/style.js +40 -76
  185. package/build/hooks/style.js.map +1 -1
  186. package/build/layouts/constrained.js +215 -0
  187. package/build/layouts/constrained.js.map +1 -0
  188. package/build/layouts/flex.js +1 -1
  189. package/build/layouts/flex.js.map +1 -1
  190. package/build/layouts/flow.js +6 -145
  191. package/build/layouts/flow.js.map +1 -1
  192. package/build/layouts/index.js +3 -1
  193. package/build/layouts/index.js.map +1 -1
  194. package/build/layouts/utils.js +43 -0
  195. package/build/layouts/utils.js.map +1 -1
  196. package/build/store/actions.js +25 -3
  197. package/build/store/actions.js.map +1 -1
  198. package/build/store/selectors.js +4 -6
  199. package/build/store/selectors.js.map +1 -1
  200. package/build/utils/block-variation-transforms.js +15 -9
  201. package/build/utils/block-variation-transforms.js.map +1 -1
  202. package/build/utils/pasting.js +9 -1
  203. package/build/utils/pasting.js.map +1 -1
  204. package/build-module/components/block-alignment-control/use-available-alignments.js +1 -1
  205. package/build-module/components/block-alignment-control/use-available-alignments.js.map +1 -1
  206. package/build-module/components/block-edit-visually-button/index.js +35 -0
  207. package/build-module/components/block-edit-visually-button/index.js.map +1 -0
  208. package/build-module/components/block-list/block.js +13 -3
  209. package/build-module/components/block-list/block.js.map +1 -1
  210. package/build-module/components/block-list/index.native.js +1 -1
  211. package/build-module/components/block-list/index.native.js.map +1 -1
  212. package/build-module/components/block-lock/modal.js +2 -2
  213. package/build-module/components/block-lock/modal.js.map +1 -1
  214. package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js +2 -2
  215. package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
  216. package/build-module/components/block-mover/mover-description.js +97 -33
  217. package/build-module/components/block-mover/mover-description.js.map +1 -1
  218. package/build-module/components/block-popover/inbetween.js +5 -3
  219. package/build-module/components/block-popover/inbetween.js.map +1 -1
  220. package/build-module/components/block-settings-menu/index.js +3 -6
  221. package/build-module/components/block-settings-menu/index.js.map +1 -1
  222. package/build-module/components/block-settings-menu-controls/index.js +2 -2
  223. package/build-module/components/block-settings-menu-controls/index.js.map +1 -1
  224. package/build-module/components/block-styles/index.js +4 -7
  225. package/build-module/components/block-styles/index.js.map +1 -1
  226. package/build-module/components/block-styles/preview.native.js +2 -3
  227. package/build-module/components/block-styles/preview.native.js.map +1 -1
  228. package/build-module/components/block-switcher/index.js +10 -16
  229. package/build-module/components/block-switcher/index.js.map +1 -1
  230. package/build-module/components/block-toolbar/index.js +4 -1
  231. package/build-module/components/block-toolbar/index.js.map +1 -1
  232. package/build-module/components/block-tools/block-selection-button.js +1 -7
  233. package/build-module/components/block-tools/block-selection-button.js.map +1 -1
  234. package/build-module/components/block-tools/index.js +4 -1
  235. package/build-module/components/block-tools/index.js.map +1 -1
  236. package/build-module/components/block-types-list/index.js +1 -1
  237. package/build-module/components/block-types-list/index.js.map +1 -1
  238. package/build-module/components/block-types-list/index.native.js +67 -25
  239. package/build-module/components/block-types-list/index.native.js.map +1 -1
  240. package/build-module/components/border-radius-control/all-input-control.js +32 -4
  241. package/build-module/components/border-radius-control/all-input-control.js.map +1 -1
  242. package/build-module/components/border-radius-control/index.js +24 -8
  243. package/build-module/components/border-radius-control/index.js.map +1 -1
  244. package/build-module/components/border-radius-control/input-controls.js +22 -7
  245. package/build-module/components/border-radius-control/input-controls.js.map +1 -1
  246. package/build-module/components/border-radius-control/utils.js +13 -16
  247. package/build-module/components/border-radius-control/utils.js.map +1 -1
  248. package/build-module/components/colors/utils.js +7 -3
  249. package/build-module/components/colors/utils.js.map +1 -1
  250. package/build-module/components/colors/with-colors.js +16 -3
  251. package/build-module/components/colors/with-colors.js.map +1 -1
  252. package/build-module/components/colors-gradients/control.js +8 -4
  253. package/build-module/components/colors-gradients/control.js.map +1 -1
  254. package/build-module/components/colors-gradients/dropdown.js +10 -4
  255. package/build-module/components/colors-gradients/dropdown.js.map +1 -1
  256. package/build-module/components/copy-handler/index.js +7 -1
  257. package/build-module/components/copy-handler/index.js.map +1 -1
  258. package/build-module/components/date-format-picker/index.js +2 -6
  259. package/build-module/components/date-format-picker/index.js.map +1 -1
  260. package/build-module/components/duotone/components.js +5 -5
  261. package/build-module/components/duotone/components.js.map +1 -1
  262. package/build-module/components/font-appearance-control/index.js +7 -4
  263. package/build-module/components/font-appearance-control/index.js.map +1 -1
  264. package/build-module/components/font-family/index.js +1 -1
  265. package/build-module/components/font-family/index.js.map +1 -1
  266. package/build-module/components/font-sizes/with-font-sizes.js +16 -3
  267. package/build-module/components/font-sizes/with-font-sizes.js.map +1 -1
  268. package/build-module/components/image-editor/cropper.js +4 -3
  269. package/build-module/components/image-editor/cropper.js.map +1 -1
  270. package/build-module/components/image-editor/index.js +3 -1
  271. package/build-module/components/image-editor/index.js.map +1 -1
  272. package/build-module/components/image-size-control/index.js +3 -1
  273. package/build-module/components/image-size-control/index.js.map +1 -1
  274. package/build-module/components/index.js +2 -1
  275. package/build-module/components/index.js.map +1 -1
  276. package/build-module/components/index.native.js +1 -1
  277. package/build-module/components/index.native.js.map +1 -1
  278. package/build-module/components/inserter/block-types-tab.native.js +31 -15
  279. package/build-module/components/inserter/block-types-tab.native.js.map +1 -1
  280. package/build-module/components/inserter/index.native.js +9 -2
  281. package/build-module/components/inserter/index.native.js.map +1 -1
  282. package/build-module/components/inserter/preview-panel.js +9 -9
  283. package/build-module/components/inserter/preview-panel.js.map +1 -1
  284. package/build-module/components/inserter/reusable-blocks-tab.native.js +6 -2
  285. package/build-module/components/inserter/reusable-blocks-tab.native.js.map +1 -1
  286. package/build-module/components/inserter/search-items.js +19 -5
  287. package/build-module/components/inserter/search-items.js.map +1 -1
  288. package/build-module/components/inserter/search-results.native.js +6 -3
  289. package/build-module/components/inserter/search-results.native.js.map +1 -1
  290. package/build-module/components/inserter/utils.native.js +19 -0
  291. package/build-module/components/inserter/utils.native.js.map +1 -1
  292. package/build-module/components/inserter-list-item/index.js +5 -18
  293. package/build-module/components/inserter-list-item/index.js.map +1 -1
  294. package/build-module/components/letter-spacing-control/index.js +5 -3
  295. package/build-module/components/letter-spacing-control/index.js.map +1 -1
  296. package/build-module/components/line-height-control/index.js +5 -3
  297. package/build-module/components/line-height-control/index.js.map +1 -1
  298. package/build-module/components/link-control/is-url-like.js +1 -6
  299. package/build-module/components/link-control/is-url-like.js.map +1 -1
  300. package/build-module/components/link-control/link-preview.js +0 -1
  301. package/build-module/components/link-control/link-preview.js.map +1 -1
  302. package/build-module/components/link-control/use-search-handler.js +1 -6
  303. package/build-module/components/link-control/use-search-handler.js.map +1 -1
  304. package/build-module/components/list-view/block-select-button.js +5 -2
  305. package/build-module/components/list-view/block-select-button.js.map +1 -1
  306. package/build-module/components/list-view/branch.js +1 -6
  307. package/build-module/components/list-view/branch.js.map +1 -1
  308. package/build-module/components/list-view/expander.js +3 -2
  309. package/build-module/components/list-view/expander.js.map +1 -1
  310. package/build-module/components/list-view/use-block-selection.js +1 -6
  311. package/build-module/components/list-view/use-block-selection.js.map +1 -1
  312. package/build-module/components/media-upload/index.native.js +9 -2
  313. package/build-module/components/media-upload/index.native.js.map +1 -1
  314. package/build-module/components/observe-typing/index.js +22 -8
  315. package/build-module/components/observe-typing/index.js.map +1 -1
  316. package/build-module/components/preview-options/index.js +2 -2
  317. package/build-module/components/preview-options/index.js.map +1 -1
  318. package/build-module/components/{use-no-recursive-renders → recursion-provider}/index.js +39 -19
  319. package/build-module/components/recursion-provider/index.js.map +1 -0
  320. package/build-module/components/rich-text/format-toolbar-container.js +58 -12
  321. package/build-module/components/rich-text/format-toolbar-container.js.map +1 -1
  322. package/build-module/components/rich-text/index.js +7 -2
  323. package/build-module/components/rich-text/index.js.map +1 -1
  324. package/build-module/components/rich-text/index.native.js +3 -1
  325. package/build-module/components/rich-text/index.native.js.map +1 -1
  326. package/build-module/components/rich-text/use-before-input-rules.js +96 -0
  327. package/build-module/components/rich-text/use-before-input-rules.js.map +1 -0
  328. package/build-module/components/rich-text/use-enter.js +0 -4
  329. package/build-module/components/rich-text/use-enter.js.map +1 -1
  330. package/build-module/components/rich-text/use-format-types.js +39 -22
  331. package/build-module/components/rich-text/use-format-types.js.map +1 -1
  332. package/build-module/components/spacing-sizes-control/all-input-control.js +41 -0
  333. package/build-module/components/spacing-sizes-control/all-input-control.js.map +1 -0
  334. package/build-module/components/spacing-sizes-control/axial-input-controls.js +57 -0
  335. package/build-module/components/spacing-sizes-control/axial-input-controls.js.map +1 -0
  336. package/build-module/components/spacing-sizes-control/index.js +83 -0
  337. package/build-module/components/spacing-sizes-control/index.js.map +1 -0
  338. package/build-module/components/spacing-sizes-control/input-controls.js +41 -0
  339. package/build-module/components/spacing-sizes-control/input-controls.js.map +1 -0
  340. package/build-module/components/spacing-sizes-control/linked-button.js +28 -0
  341. package/build-module/components/spacing-sizes-control/linked-button.js.map +1 -0
  342. package/build-module/components/spacing-sizes-control/spacing-input-control.js +192 -0
  343. package/build-module/components/spacing-sizes-control/spacing-input-control.js.map +1 -0
  344. package/build-module/components/spacing-sizes-control/utils.js +174 -0
  345. package/build-module/components/spacing-sizes-control/utils.js.map +1 -0
  346. package/build-module/components/text-decoration-control/index.js +4 -2
  347. package/build-module/components/text-decoration-control/index.js.map +1 -1
  348. package/build-module/components/text-transform-control/index.js +4 -2
  349. package/build-module/components/text-transform-control/index.js.map +1 -1
  350. package/build-module/components/url-input/index.js +1 -1
  351. package/build-module/components/url-input/index.js.map +1 -1
  352. package/build-module/components/url-popover/image-url-input-ui.js +4 -1
  353. package/build-module/components/url-popover/image-url-input-ui.js.map +1 -1
  354. package/build-module/components/writing-flow/use-arrow-nav.js +5 -26
  355. package/build-module/components/writing-flow/use-arrow-nav.js.map +1 -1
  356. package/build-module/components/writing-flow/use-drag-selection.js +9 -2
  357. package/build-module/components/writing-flow/use-drag-selection.js.map +1 -1
  358. package/build-module/components/writing-flow/use-multi-selection.js +4 -2
  359. package/build-module/components/writing-flow/use-multi-selection.js.map +1 -1
  360. package/build-module/components/writing-flow/use-select-all.js +3 -1
  361. package/build-module/components/writing-flow/use-select-all.js.map +1 -1
  362. package/build-module/components/writing-flow/use-selection-observer.js +10 -2
  363. package/build-module/components/writing-flow/use-selection-observer.js.map +1 -1
  364. package/build-module/components/writing-flow/use-tab-nav.js +1 -1
  365. package/build-module/components/writing-flow/use-tab-nav.js.map +1 -1
  366. package/build-module/hooks/border-radius.js +2 -7
  367. package/build-module/hooks/border-radius.js.map +1 -1
  368. package/build-module/hooks/border.js +2 -2
  369. package/build-module/hooks/border.js.map +1 -1
  370. package/build-module/hooks/color.js +4 -1
  371. package/build-module/hooks/color.js.map +1 -1
  372. package/build-module/hooks/dimensions.js +13 -0
  373. package/build-module/hooks/dimensions.js.map +1 -1
  374. package/build-module/hooks/duotone.js +4 -4
  375. package/build-module/hooks/duotone.js.map +1 -1
  376. package/build-module/hooks/gap.js +3 -2
  377. package/build-module/hooks/gap.js.map +1 -1
  378. package/build-module/hooks/generated-class-name.js +1 -6
  379. package/build-module/hooks/generated-class-name.js.map +1 -1
  380. package/build-module/hooks/layout.js +42 -15
  381. package/build-module/hooks/layout.js.map +1 -1
  382. package/build-module/hooks/margin.js +26 -12
  383. package/build-module/hooks/margin.js.map +1 -1
  384. package/build-module/hooks/padding.js +17 -8
  385. package/build-module/hooks/padding.js.map +1 -1
  386. package/build-module/hooks/style.js +44 -81
  387. package/build-module/hooks/style.js.map +1 -1
  388. package/build-module/layouts/constrained.js +197 -0
  389. package/build-module/layouts/constrained.js.map +1 -0
  390. package/build-module/layouts/flex.js +1 -1
  391. package/build-module/layouts/flex.js.map +1 -1
  392. package/build-module/layouts/flow.js +7 -140
  393. package/build-module/layouts/flow.js.map +1 -1
  394. package/build-module/layouts/index.js +2 -1
  395. package/build-module/layouts/index.js.map +1 -1
  396. package/build-module/layouts/utils.js +40 -0
  397. package/build-module/layouts/utils.js.map +1 -1
  398. package/build-module/store/actions.js +25 -3
  399. package/build-module/store/actions.js.map +1 -1
  400. package/build-module/store/selectors.js +5 -7
  401. package/build-module/store/selectors.js.map +1 -1
  402. package/build-module/utils/block-variation-transforms.js +14 -7
  403. package/build-module/utils/block-variation-transforms.js.map +1 -1
  404. package/build-module/utils/pasting.js +9 -1
  405. package/build-module/utils/pasting.js.map +1 -1
  406. package/build-style/style-rtl.css +154 -27
  407. package/build-style/style.css +154 -27
  408. package/package.json +30 -28
  409. package/src/components/block-alignment-control/use-available-alignments.js +1 -1
  410. package/src/components/block-edit-visually-button/index.js +39 -0
  411. package/src/components/block-list/block.js +13 -2
  412. package/src/components/block-list/index.native.js +1 -1
  413. package/src/components/block-lock/modal.js +5 -5
  414. package/src/components/block-mobile-toolbar/block-actions-menu.native.js +3 -3
  415. package/src/components/block-mover/mover-description.js +131 -48
  416. package/src/components/block-mover/test/mover-description.js +55 -3
  417. package/src/components/block-popover/inbetween.js +5 -1
  418. package/src/components/block-popover/style.scss +25 -2
  419. package/src/components/block-settings-menu/index.js +11 -15
  420. package/src/components/block-settings-menu-controls/index.js +2 -2
  421. package/src/components/block-styles/index.js +4 -7
  422. package/src/components/block-styles/preview.native.js +2 -2
  423. package/src/components/block-styles/style.scss +10 -0
  424. package/src/components/block-switcher/index.js +9 -13
  425. package/src/components/block-switcher/test/index.js +1 -0
  426. package/src/components/block-toolbar/index.js +2 -0
  427. package/src/components/block-tools/block-selection-button.js +0 -5
  428. package/src/components/block-tools/index.js +4 -1
  429. package/src/components/block-types-list/index.js +1 -1
  430. package/src/components/block-types-list/index.native.js +76 -24
  431. package/src/components/block-types-list/style.native.scss +18 -0
  432. package/src/components/border-radius-control/all-input-control.js +41 -4
  433. package/src/components/border-radius-control/index.js +29 -6
  434. package/src/components/border-radius-control/input-controls.js +40 -13
  435. package/src/components/border-radius-control/test/utils.js +22 -60
  436. package/src/components/border-radius-control/utils.js +12 -16
  437. package/src/components/color-palette/test/__snapshots__/control.js.snap +91 -79
  438. package/src/components/colors/test/__snapshots__/with-colors.js.snap +1 -1
  439. package/src/components/colors/test/with-colors.js +1 -1
  440. package/src/components/colors/utils.js +5 -2
  441. package/src/components/colors/with-colors.js +11 -1
  442. package/src/components/colors-gradients/control.js +13 -8
  443. package/src/components/colors-gradients/dropdown.js +14 -3
  444. package/src/components/colors-gradients/style.scss +33 -12
  445. package/src/components/colors-gradients/test/control.js +3 -3
  446. package/src/components/copy-handler/index.js +18 -0
  447. package/src/components/date-format-picker/index.js +12 -14
  448. package/src/components/date-format-picker/style.scss +0 -4
  449. package/src/components/duotone/components.js +5 -5
  450. package/src/components/duotone-control/style.scss +0 -4
  451. package/src/components/font-appearance-control/index.js +3 -0
  452. package/src/components/font-appearance-control/style.scss +0 -2
  453. package/src/components/font-family/index.js +1 -1
  454. package/src/components/font-sizes/with-font-sizes.js +11 -1
  455. package/src/components/image-editor/cropper.js +9 -3
  456. package/src/components/image-editor/index.js +2 -0
  457. package/src/components/image-size-control/README.md +7 -0
  458. package/src/components/image-size-control/index.js +2 -0
  459. package/src/components/index.js +5 -1
  460. package/src/components/index.native.js +4 -1
  461. package/src/components/inserter/block-types-tab.native.js +42 -21
  462. package/src/components/inserter/index.native.js +7 -2
  463. package/src/components/inserter/preview-panel.js +6 -14
  464. package/src/components/inserter/reusable-blocks-tab.native.js +4 -2
  465. package/src/components/inserter/search-items.js +17 -5
  466. package/src/components/inserter/search-results.native.js +4 -2
  467. package/src/components/inserter/test/block-types-tab.native.js +2 -0
  468. package/src/components/inserter/test/utils.native.js +37 -0
  469. package/src/components/inserter/utils.native.js +11 -0
  470. package/src/components/inserter-list-item/index.js +5 -18
  471. package/src/components/letter-spacing-control/index.js +2 -0
  472. package/src/components/line-height-control/index.js +2 -0
  473. package/src/components/link-control/is-url-like.js +1 -6
  474. package/src/components/link-control/link-preview.js +0 -1
  475. package/src/components/link-control/test/index.js +540 -893
  476. package/src/components/link-control/use-search-handler.js +1 -6
  477. package/src/components/list-view/block-select-button.js +7 -2
  478. package/src/components/list-view/branch.js +1 -6
  479. package/src/components/list-view/expander.js +4 -2
  480. package/src/components/list-view/style.scss +11 -4
  481. package/src/components/list-view/use-block-selection.js +2 -8
  482. package/src/components/media-replace-flow/style.scss +1 -0
  483. package/src/components/media-upload/index.native.js +7 -3
  484. package/src/components/observe-typing/index.js +17 -14
  485. package/src/components/preview-options/index.js +2 -2
  486. package/src/components/{use-no-recursive-renders → recursion-provider}/index.js +39 -28
  487. package/src/components/{use-no-recursive-renders/test/use-no-recursive-renders.js → recursion-provider/test/index.js} +5 -6
  488. package/src/components/rich-text/README.md +13 -1
  489. package/src/components/rich-text/format-toolbar-container.js +63 -14
  490. package/src/components/rich-text/index.js +3 -0
  491. package/src/components/rich-text/index.native.js +2 -0
  492. package/src/components/rich-text/use-before-input-rules.js +91 -0
  493. package/src/components/rich-text/use-enter.js +0 -3
  494. package/src/components/rich-text/use-format-types.js +38 -17
  495. package/src/components/spacing-sizes-control/all-input-control.js +40 -0
  496. package/src/components/spacing-sizes-control/axial-input-controls.js +62 -0
  497. package/src/components/spacing-sizes-control/index.js +91 -0
  498. package/src/components/spacing-sizes-control/input-controls.js +46 -0
  499. package/src/components/spacing-sizes-control/linked-button.js +25 -0
  500. package/src/components/spacing-sizes-control/spacing-input-control.js +280 -0
  501. package/src/components/spacing-sizes-control/style.scss +122 -0
  502. package/src/components/spacing-sizes-control/test/utils.js +156 -0
  503. package/src/components/spacing-sizes-control/utils.js +195 -0
  504. package/src/components/text-decoration-control/index.js +4 -2
  505. package/src/components/text-transform-control/index.js +4 -2
  506. package/src/components/url-input/index.js +1 -1
  507. package/src/components/url-input/style.scss +2 -2
  508. package/src/components/url-popover/image-url-input-ui.js +3 -0
  509. package/src/components/url-popover/style.scss +0 -3
  510. package/src/components/writing-flow/use-arrow-nav.js +4 -33
  511. package/src/components/writing-flow/use-drag-selection.js +7 -1
  512. package/src/components/writing-flow/use-multi-selection.js +4 -1
  513. package/src/components/writing-flow/use-select-all.js +2 -1
  514. package/src/components/writing-flow/use-selection-observer.js +10 -2
  515. package/src/components/writing-flow/use-tab-nav.js +1 -1
  516. package/src/hooks/border-radius.js +2 -6
  517. package/src/hooks/border.js +2 -2
  518. package/src/hooks/color.js +13 -3
  519. package/src/hooks/dimensions.js +15 -0
  520. package/src/hooks/duotone.js +4 -4
  521. package/src/hooks/gap.js +7 -2
  522. package/src/hooks/generated-class-name.js +6 -9
  523. package/src/hooks/layout.js +66 -18
  524. package/src/hooks/margin.js +49 -17
  525. package/src/hooks/padding.js +41 -14
  526. package/src/hooks/style.js +42 -86
  527. package/src/hooks/test/gap.js +22 -0
  528. package/src/hooks/typography.scss +0 -1
  529. package/src/layouts/constrained.js +217 -0
  530. package/src/layouts/flex.js +1 -1
  531. package/src/layouts/flow.js +6 -151
  532. package/src/layouts/index.js +2 -1
  533. package/src/layouts/test/constrained.js +21 -0
  534. package/src/layouts/utils.js +34 -0
  535. package/src/store/actions.js +32 -4
  536. package/src/store/selectors.js +5 -4
  537. package/src/style.scss +1 -0
  538. package/src/utils/block-variation-transforms.js +13 -6
  539. package/src/utils/pasting.js +10 -1
  540. package/src/utils/test/block-variation-transforms.js +24 -0
  541. package/src/utils/test/pasting.js +10 -0
  542. package/build/components/block-settings-menu/block-edit-visually-button.js +0 -70
  543. package/build/components/block-settings-menu/block-edit-visually-button.js.map +0 -1
  544. package/build/components/use-no-recursive-renders/index.js.map +0 -1
  545. package/build-module/components/block-settings-menu/block-edit-visually-button.js +0 -56
  546. package/build-module/components/block-settings-menu/block-edit-visually-button.js.map +0 -1
  547. package/build-module/components/use-no-recursive-renders/index.js.map +0 -1
  548. package/src/components/block-settings-menu/block-edit-visually-button.js +0 -52
@@ -15,6 +15,8 @@ var _reactNative = require("react-native");
15
15
 
16
16
  var _components = require("@wordpress/components");
17
17
 
18
+ var _compose = require("@wordpress/compose");
19
+
18
20
  var _style = _interopRequireDefault(require("./style.scss"));
19
21
 
20
22
  /**
@@ -33,7 +35,7 @@ const MIN_COL_NUM = 3;
33
35
  function BlockTypesList(_ref) {
34
36
  let {
35
37
  name,
36
- items,
38
+ sections,
37
39
  onSelect,
38
40
  listProps,
39
41
  initialNumToRender = 3
@@ -82,32 +84,72 @@ function BlockTypesList(_ref) {
82
84
 
83
85
  const contentContainerStyle = _reactNative.StyleSheet.flatten(listProps.contentContainerStyle);
84
86
 
85
- return (0, _element.createElement)(_reactNative.FlatList, (0, _extends2.default)({
87
+ const renderSection = _ref2 => {
88
+ let {
89
+ item
90
+ } = _ref2;
91
+ return (0, _element.createElement)(_reactNative.TouchableWithoutFeedback, {
92
+ accessible: false
93
+ }, (0, _element.createElement)(_reactNative.FlatList, {
94
+ data: item.list,
95
+ key: `InserterUI-${name}-${numberOfColumns}` // Re-render when numberOfColumns changes.
96
+ ,
97
+ numColumns: numberOfColumns,
98
+ ItemSeparatorComponent: () => (0, _element.createElement)(_reactNative.TouchableWithoutFeedback, {
99
+ accessible: false
100
+ }, (0, _element.createElement)(_reactNative.View, {
101
+ style: _style.default['block-types-list__row-separator']
102
+ })),
103
+ scrollEnabled: false,
104
+ renderItem: renderListItem
105
+ }));
106
+ };
107
+
108
+ const renderListItem = _ref3 => {
109
+ let {
110
+ item
111
+ } = _ref3;
112
+ return (0, _element.createElement)(_components.InserterButton, {
113
+ item: item,
114
+ itemWidth: itemWidth,
115
+ maxWidth: maxWidth,
116
+ onSelect: onSelect
117
+ });
118
+ };
119
+
120
+ const colorScheme = (0, _compose.usePreferredColorScheme)();
121
+ const sectionHeaderGradientValue = colorScheme === 'light' ? 'linear-gradient(#fff 70%, rgba(255, 255, 255, 0))' : 'linear-gradient(#2e2e2e 70%, rgba(46, 46, 46, 0))';
122
+ const sectionHeaderTitleStyles = (0, _compose.usePreferredColorSchemeStyle)(_style.default['block-types-list__section-header-title'], _style.default['block-types-list__section-header-title--dark']);
123
+
124
+ const renderSectionHeader = _ref4 => {
125
+ let {
126
+ section: {
127
+ metadata
128
+ }
129
+ } = _ref4;
130
+
131
+ if (!(metadata !== null && metadata !== void 0 && metadata.icon) || !(metadata !== null && metadata !== void 0 && metadata.title)) {
132
+ return null;
133
+ }
134
+
135
+ return (0, _element.createElement)(_reactNative.TouchableWithoutFeedback, {
136
+ accessible: false
137
+ }, (0, _element.createElement)(_components.Gradient, {
138
+ gradientValue: sectionHeaderGradientValue,
139
+ style: _style.default['block-types-list__section-header']
140
+ }, metadata === null || metadata === void 0 ? void 0 : metadata.icon, (0, _element.createElement)(_reactNative.Text, {
141
+ style: sectionHeaderTitleStyles
142
+ }, metadata === null || metadata === void 0 ? void 0 : metadata.title)));
143
+ };
144
+
145
+ return (0, _element.createElement)(_reactNative.SectionList, (0, _extends2.default)({
86
146
  onLayout: onLayout,
87
- key: `InserterUI-${name}-${numberOfColumns}` // Re-render when numberOfColumns changes.
88
- ,
89
147
  testID: `InserterUI-${name}`,
90
148
  keyboardShouldPersistTaps: "always",
91
- numColumns: numberOfColumns,
92
- data: items,
149
+ sections: sections,
93
150
  initialNumToRender: initialNumToRender,
94
- ItemSeparatorComponent: () => (0, _element.createElement)(_reactNative.TouchableWithoutFeedback, {
95
- accessible: false
96
- }, (0, _element.createElement)(_reactNative.View, {
97
- style: _style.default['block-types-list__row-separator']
98
- })),
99
- keyExtractor: item => item.id,
100
- renderItem: _ref2 => {
101
- let {
102
- item
103
- } = _ref2;
104
- return (0, _element.createElement)(_components.InserterButton, {
105
- item,
106
- itemWidth,
107
- maxWidth,
108
- onSelect
109
- });
110
- }
151
+ renderItem: renderSection,
152
+ renderSectionHeader: renderSectionHeader
111
153
  }, listProps, {
112
154
  contentContainerStyle: { ...contentContainerStyle,
113
155
  paddingBottom: Math.max(listProps.safeAreaBottomInset, contentContainerStyle.paddingBottom)
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/block-types-list/index.native.js"],"names":["MIN_COL_NUM","BlockTypesList","name","items","onSelect","listProps","initialNumToRender","numberOfColumns","setNumberOfColumns","itemWidth","setItemWidth","maxWidth","setMaxWidth","dimensionsChangeSubscription","Dimensions","addEventListener","onLayout","remove","calculateItemWidth","paddingLeft","itemPaddingLeft","paddingRight","itemPaddingRight","InserterButton","Styles","modalItem","width","modalIconWrapper","columnStyle","styles","sumLeftRightPadding","bottomSheetWidth","BottomSheet","getWidth","containerTotalWidth","itemTotalWidth","columnsFitToWidth","Math","floor","numColumns","max","updatedItemWidth","contentContainerStyle","StyleSheet","flatten","item","id","paddingBottom","safeAreaBottom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F,QADY;AAAA;AAhBd,KA0BMC,SA1BN;AA2BC,IAAA,qBAAqB,EAAG,EACvB,GAAGqC,qBADoB;AAEvBK,MAAAA,aAAa,EAAEV,IAAI,CAACG,GAAL,CACdnC,SAAS,CAAC2C,mBADI,EAEdN,qBAAqB,CAACK,aAFR;AAFQ;AA3BzB,KADD;AAqCA","sourcesContent":["/**\n * External dependencies\n */\nimport {\n\tDimensions,\n\tFlatList,\n\tStyleSheet,\n\tTouchableWithoutFeedback,\n\tView,\n} from 'react-native';\n\n/**\n * WordPress dependencies\n */\nimport { useState, useEffect } from '@wordpress/element';\nimport { BottomSheet, InserterButton } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport styles from './style.scss';\n\nconst MIN_COL_NUM = 3;\n\nexport default function BlockTypesList( {\n\tname,\n\titems,\n\tonSelect,\n\tlistProps,\n\tinitialNumToRender = 3,\n} ) {\n\tconst [ numberOfColumns, setNumberOfColumns ] = useState( MIN_COL_NUM );\n\tconst [ itemWidth, setItemWidth ] = useState();\n\tconst [ maxWidth, setMaxWidth ] = useState();\n\n\tuseEffect( () => {\n\t\tconst dimensionsChangeSubscription = Dimensions.addEventListener(\n\t\t\t'change',\n\t\t\tonLayout\n\t\t);\n\t\tonLayout();\n\t\treturn () => {\n\t\t\tdimensionsChangeSubscription.remove();\n\t\t};\n\t}, [] );\n\n\tfunction calculateItemWidth() {\n\t\tconst { paddingLeft: itemPaddingLeft, paddingRight: itemPaddingRight } =\n\t\t\tInserterButton.Styles.modalItem;\n\t\tconst { width } = InserterButton.Styles.modalIconWrapper;\n\t\treturn width + itemPaddingLeft + itemPaddingRight;\n\t}\n\n\tfunction onLayout() {\n\t\tconst columnStyle = styles[ 'block-types-list__column' ];\n\t\tconst sumLeftRightPadding =\n\t\t\tcolumnStyle.paddingLeft + columnStyle.paddingRight;\n\n\t\tconst bottomSheetWidth = BottomSheet.getWidth();\n\t\tconst containerTotalWidth = bottomSheetWidth - sumLeftRightPadding;\n\t\tconst itemTotalWidth = calculateItemWidth();\n\n\t\tconst columnsFitToWidth = Math.floor(\n\t\t\tcontainerTotalWidth / itemTotalWidth\n\t\t);\n\n\t\tconst numColumns = Math.max( MIN_COL_NUM, columnsFitToWidth );\n\n\t\tsetNumberOfColumns( numColumns );\n\t\tsetMaxWidth( containerTotalWidth / numColumns );\n\n\t\tif ( columnsFitToWidth < MIN_COL_NUM ) {\n\t\t\tconst updatedItemWidth =\n\t\t\t\t( bottomSheetWidth - 2 * sumLeftRightPadding ) / MIN_COL_NUM;\n\t\t\tsetItemWidth( updatedItemWidth );\n\t\t}\n\t}\n\n\tconst contentContainerStyle = StyleSheet.flatten(\n\t\tlistProps.contentContainerStyle\n\t);\n\n\treturn (\n\t\t<FlatList\n\t\t\tonLayout={ onLayout }\n\t\t\tkey={ `InserterUI-${ name }-${ numberOfColumns }` } // Re-render when numberOfColumns changes.\n\t\t\ttestID={ `InserterUI-${ name }` }\n\t\t\tkeyboardShouldPersistTaps=\"always\"\n\t\t\tnumColumns={ numberOfColumns }\n\t\t\tdata={ items }\n\t\t\tinitialNumToRender={ initialNumToRender }\n\t\t\tItemSeparatorComponent={ () => (\n\t\t\t\t<TouchableWithoutFeedback accessible={ false }>\n\t\t\t\t\t<View\n\t\t\t\t\t\tstyle={ styles[ 'block-types-list__row-separator' ] }\n\t\t\t\t\t/>\n\t\t\t\t</TouchableWithoutFeedback>\n\t\t\t) }\n\t\t\tkeyExtractor={ ( item ) => item.id }\n\t\t\trenderItem={ ( { item } ) => (\n\t\t\t\t<InserterButton\n\t\t\t\t\t{ ...{\n\t\t\t\t\t\titem,\n\t\t\t\t\t\titemWidth,\n\t\t\t\t\t\tmaxWidth,\n\t\t\t\t\t\tonSelect,\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ ...listProps }\n\t\t\tcontentContainerStyle={ {\n\t\t\t\t...contentContainerStyle,\n\t\t\t\tpaddingBottom: Math.max(\n\t\t\t\t\tlistProps.safeAreaBottomInset,\n\t\t\t\t\tcontentContainerStyle.paddingBottom\n\t\t\t\t),\n\t\t\t} }\n\t\t/>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/block-types-list/index.native.js"],"names":["MIN_COL_NUM","BlockTypesList","name","sections","onSelect","listProps","initialNumToRender","numberOfColumns","setNumberOfColumns","itemWidth","setItemWidth","maxWidth","setMaxWidth","dimensionsChangeSubscription","Dimensions","addEventListener","onLayout","remove","calculateItemWidth","paddingLeft","itemPaddingLeft","paddingRight","itemPaddingRight","InserterButton","Styles","modalItem","width","modalIconWrapper","columnStyle","styles","sumLeftRightPadding","bottomSheetWidth","BottomSheet","getWidth","containerTotalWidth","itemTotalWidth","columnsFitToWidth","Math","floor","numColumns","max","updatedItemWidth","contentContainerStyle","StyleSheet","flatten","renderSection","item","list","renderListItem","colorScheme","sectionHeaderGradientValue","sectionHeaderTitleStyles","renderSectionHeader","section","metadata","icon","title","paddingBottom","safeAreaBottomInset"],"mappings":";;;;;;;;;AAgBA;;;;AAbA;;AAcA;;AACA;;AAQA;;AA1BA;AACA;AACA;;AAWA;AACA;AACA;;AAQA;AACA;AACA;AAGA,MAAMA,WAAW,GAAG,CAApB;;AAEe,SAASC,cAAT,OAMX;AAAA,MANoC;AACvCC,IAAAA,IADuC;AAEvCC,IAAAA,QAFuC;AAGvCC,IAAAA,QAHuC;AAIvCC,IAAAA,SAJuC;AAKvCC,IAAAA,kBAAkB,GAAG;AALkB,GAMpC;AACH,QAAM,CAAEC,eAAF,EAAmBC,kBAAnB,IAA0C,uBAAUR,WAAV,CAAhD;AACA,QAAM,CAAES,SAAF,EAAaC,YAAb,IAA8B,wBAApC;AACA,QAAM,CAAEC,QAAF,EAAYC,WAAZ,IAA4B,wBAAlC;AAEA,0BAAW,MAAM;AAChB,UAAMC,4BAA4B,GAAGC,wBAAWC,gBAAX,CACpC,QADoC,EAEpCC,QAFoC,CAArC;;AAIAA,IAAAA,QAAQ;AACR,WAAO,MAAM;AACZH,MAA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AAvC,OACC,4BAAC,oBAAD;AACC,MAAA,aAAa,EAAGN,0BADjB;AAEC,MAAA,KAAK,EAAGrB,eAAQ,kCAAR;AAFT,OAIGyB,QAJH,aAIGA,QAJH,uBAIGA,QAAQ,CAAEC,IAJb,EAKC,4BAAC,iBAAD;AAAM,MAAA,KAAK,EAAGJ;AAAd,OACGG,QADH,aACGA,QADH,uBACGA,QAAQ,CAAEE,KADb,CALD,CADD,CADD;AAaA,GAlBD;;AAoBA,SACC,4BAAC,wBAAD;AACC,IAAA,QAAQ,EAAGxC,QADZ;AAEC,IAAA,MAAM,EAAI,cAAcd,IAAM,EAF/B;AAGC,IAAA,yBAAyB,EAAC,QAH3B;AAIC,IAAA,QAAQ,EAAGC,QAJZ;AAKC,IAAA,kBAAkB,EAAGG,kBALtB;AAMC,IAAA,UAAU,EAAGuC,aANd;AAOC,IAAA,mBAAmB,EAAGO;AAPvB,KAQM/C,SARN;AASC,IAAA,qBAAqB,EAAG,EACvB,GAAGqC,qBADoB;AAEvBe,MAAAA,aAAa,EAAEpB,IAAI,CAACG,GAAL,CACdnC,SAAS,CAACqD,mBADI,EAEdhB,qBAAqB,CAACe,aAFR;AAFQ;AATzB,KADD;AAmBA","sourcesContent":["/**\n * External dependencies\n */\nimport {\n\tDimensions,\n\tFlatList,\n\tSectionList,\n\tStyleSheet,\n\tText,\n\tTouchableWithoutFeedback,\n\tView,\n} from 'react-native';\n\n/**\n * WordPress dependencies\n */\nimport { useState, useEffect } from '@wordpress/element';\nimport { BottomSheet, Gradient, InserterButton } from '@wordpress/components';\nimport {\n\tusePreferredColorScheme,\n\tusePreferredColorSchemeStyle,\n} from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport styles from './style.scss';\n\nconst MIN_COL_NUM = 3;\n\nexport default function BlockTypesList( {\n\tname,\n\tsections,\n\tonSelect,\n\tlistProps,\n\tinitialNumToRender = 3,\n} ) {\n\tconst [ numberOfColumns, setNumberOfColumns ] = useState( MIN_COL_NUM );\n\tconst [ itemWidth, setItemWidth ] = useState();\n\tconst [ maxWidth, setMaxWidth ] = useState();\n\n\tuseEffect( () => {\n\t\tconst dimensionsChangeSubscription = Dimensions.addEventListener(\n\t\t\t'change',\n\t\t\tonLayout\n\t\t);\n\t\tonLayout();\n\t\treturn () => {\n\t\t\tdimensionsChangeSubscription.remove();\n\t\t};\n\t}, [] );\n\n\tfunction calculateItemWidth() {\n\t\tconst { paddingLeft: itemPaddingLeft, paddingRight: itemPaddingRight } =\n\t\t\tInserterButton.Styles.modalItem;\n\t\tconst { width } = InserterButton.Styles.modalIconWrapper;\n\t\treturn width + itemPaddingLeft + itemPaddingRight;\n\t}\n\n\tfunction onLayout() {\n\t\tconst columnStyle = styles[ 'block-types-list__column' ];\n\t\tconst sumLeftRightPadding =\n\t\t\tcolumnStyle.paddingLeft + columnStyle.paddingRight;\n\n\t\tconst bottomSheetWidth = BottomSheet.getWidth();\n\t\tconst containerTotalWidth = bottomSheetWidth - sumLeftRightPadding;\n\t\tconst itemTotalWidth = calculateItemWidth();\n\n\t\tconst columnsFitToWidth = Math.floor(\n\t\t\tcontainerTotalWidth / itemTotalWidth\n\t\t);\n\n\t\tconst numColumns = Math.max( MIN_COL_NUM, columnsFitToWidth );\n\n\t\tsetNumberOfColumns( numColumns );\n\t\tsetMaxWidth( containerTotalWidth / numColumns );\n\n\t\tif ( columnsFitToWidth < MIN_COL_NUM ) {\n\t\t\tconst updatedItemWidth =\n\t\t\t\t( bottomSheetWidth - 2 * sumLeftRightPadding ) / MIN_COL_NUM;\n\t\t\tsetItemWidth( updatedItemWidth );\n\t\t}\n\t}\n\n\tconst contentContainerStyle = StyleSheet.flatten(\n\t\tlistProps.contentContainerStyle\n\t);\n\n\tconst renderSection = ( { item } ) => {\n\t\treturn (\n\t\t\t<TouchableWithoutFeedback accessible={ false }>\n\t\t\t\t<FlatList\n\t\t\t\t\tdata={ item.list }\n\t\t\t\t\tkey={ `InserterUI-${ name }-${ numberOfColumns }` } // Re-render when numberOfColumns changes.\n\t\t\t\t\tnumColumns={ numberOfColumns }\n\t\t\t\t\tItemSeparatorComponent={ () => (\n\t\t\t\t\t\t<TouchableWithoutFeedback accessible={ false }>\n\t\t\t\t\t\t\t<View\n\t\t\t\t\t\t\t\tstyle={\n\t\t\t\t\t\t\t\t\tstyles[ 'block-types-list__row-separator' ]\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</TouchableWithoutFeedback>\n\t\t\t\t\t) }\n\t\t\t\t\tscrollEnabled={ false }\n\t\t\t\t\trenderItem={ renderListItem }\n\t\t\t\t/>\n\t\t\t</TouchableWithoutFeedback>\n\t\t);\n\t};\n\n\tconst renderListItem = ( { item } ) => {\n\t\treturn (\n\t\t\t<InserterButton\n\t\t\t\titem={ item }\n\t\t\t\titemWidth={ itemWidth }\n\t\t\t\tmaxWidth={ maxWidth }\n\t\t\t\tonSelect={ onSelect }\n\t\t\t/>\n\t\t);\n\t};\n\n\tconst colorScheme = usePreferredColorScheme();\n\tconst sectionHeaderGradientValue =\n\t\tcolorScheme === 'light'\n\t\t\t? 'linear-gradient(#fff 70%, rgba(255, 255, 255, 0))'\n\t\t\t: 'linear-gradient(#2e2e2e 70%, rgba(46, 46, 46, 0))';\n\tconst sectionHeaderTitleStyles = usePreferredColorSchemeStyle(\n\t\tstyles[ 'block-types-list__section-header-title' ],\n\t\tstyles[ 'block-types-list__section-header-title--dark' ]\n\t);\n\n\tconst renderSectionHeader = ( { section: { metadata } } ) => {\n\t\tif ( ! metadata?.icon || ! metadata?.title ) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn (\n\t\t\t<TouchableWithoutFeedback accessible={ false }>\n\t\t\t\t<Gradient\n\t\t\t\t\tgradientValue={ sectionHeaderGradientValue }\n\t\t\t\t\tstyle={ styles[ 'block-types-list__section-header' ] }\n\t\t\t\t>\n\t\t\t\t\t{ metadata?.icon }\n\t\t\t\t\t<Text style={ sectionHeaderTitleStyles }>\n\t\t\t\t\t\t{ metadata?.title }\n\t\t\t\t\t</Text>\n\t\t\t\t</Gradient>\n\t\t\t</TouchableWithoutFeedback>\n\t\t);\n\t};\n\n\treturn (\n\t\t<SectionList\n\t\t\tonLayout={ onLayout }\n\t\t\ttestID={ `InserterUI-${ name }` }\n\t\t\tkeyboardShouldPersistTaps=\"always\"\n\t\t\tsections={ sections }\n\t\t\tinitialNumToRender={ initialNumToRender }\n\t\t\trenderItem={ renderSection }\n\t\t\trenderSectionHeader={ renderSectionHeader }\n\t\t\t{ ...listProps }\n\t\t\tcontentContainerStyle={ {\n\t\t\t\t...contentContainerStyle,\n\t\t\t\tpaddingBottom: Math.max(\n\t\t\t\t\tlistProps.safeAreaBottomInset,\n\t\t\t\t\tcontentContainerStyle.paddingBottom\n\t\t\t\t),\n\t\t\t} }\n\t\t/>\n\t);\n}\n"]}
@@ -27,19 +27,47 @@ var _utils = require("./utils");
27
27
  function AllInputControl(_ref) {
28
28
  let {
29
29
  onChange,
30
+ selectedUnits,
31
+ setSelectedUnits,
30
32
  values,
31
33
  ...props
32
34
  } = _ref;
33
- const allValue = (0, _utils.getAllValue)(values);
35
+ let allValue = (0, _utils.getAllValue)(values);
36
+
37
+ if (allValue === undefined) {
38
+ // If we don't have any value set the unit to any current selection
39
+ // or the most common unit from the individual radii values.
40
+ allValue = (0, _utils.getAllUnit)(selectedUnits);
41
+ }
42
+
34
43
  const hasValues = (0, _utils.hasDefinedValues)(values);
35
44
  const isMixed = hasValues && (0, _utils.hasMixedValues)(values);
36
- const allPlaceholder = isMixed ? (0, _i18n.__)('Mixed') : null;
45
+ const allPlaceholder = isMixed ? (0, _i18n.__)('Mixed') : null; // Filter out CSS-unit-only values to prevent invalid styles.
46
+
47
+ const handleOnChange = next => {
48
+ const isNumeric = !isNaN(parseFloat(next));
49
+ const nextValue = isNumeric ? next : undefined;
50
+ onChange(nextValue);
51
+ }; // Store current unit selection for use as fallback for individual
52
+ // radii controls.
53
+
54
+
55
+ const handleOnUnitChange = unit => {
56
+ setSelectedUnits({
57
+ topLeft: unit,
58
+ topRight: unit,
59
+ bottomLeft: unit,
60
+ bottomRight: unit
61
+ });
62
+ };
63
+
37
64
  return (0, _element.createElement)(_components.__experimentalUnitControl, (0, _extends2.default)({}, props, {
38
65
  "aria-label": (0, _i18n.__)('Border radius'),
39
66
  disableUnits: isMixed,
40
67
  isOnly: true,
41
68
  value: allValue,
42
- onChange: onChange,
69
+ onChange: handleOnChange,
70
+ onUnitChange: handleOnUnitChange,
43
71
  placeholder: allPlaceholder
44
72
  }));
45
73
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/border-radius-control/all-input-control.js"],"names":["AllInputControl","onChange","values","props","allValue","hasValues","isMixed","allPlaceholder"],"mappings":";;;;;;;;;;;;;AAGA;;AACA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;AAGe,SAASA,eAAT,OAA2D;AAAA,MAAjC;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,MAAZ;AAAoB,OAAGC;AAAvB,GAAiC;AACzE,QAAMC,QAAQ,GAAG,wBAAaF,MAAb,CAAjB;AACA,QAAMG,SAAS,GAAG,6BAAkBH,MAAlB,CAAlB;AACA,QAAMI,OAAO,GAAGD,SAAS,IAAI,2BAAgBH,MAAhB,CAA7B;AACA,QAAMK,cAAc,GAAGD,OAAO,GAAG,cAAI,OAAJ,CAAH,GAAmB,IAAjD;AAEA,SACC,4BAAC,qCAAD,6BACMH,KADN;AAEC,kBAAa,cAAI,eAAJ,CAFd;AAGC,IAAA,YAAY,EAAGG,OAHhB;AAIC,IAAA,MAAM,MAJP;AAKC,IAAA,KAAK,EAAGF,QALT;AAMC,IAAA,QAAQ,EAAGH,QANZ;AAOC,IAAA,WAAW,EAAGM;AAPf,KADD;AAWA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __experimentalUnitControl as UnitControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { getAllValue, hasMixedValues, hasDefinedValues } from './utils';\n\nexport default function AllInputControl( { onChange, values, ...props } ) {\n\tconst allValue = getAllValue( values );\n\tconst hasValues = hasDefinedValues( values );\n\tconst isMixed = hasValues && hasMixedValues( values );\n\tconst allPlaceholder = isMixed ? __( 'Mixed' ) : null;\n\n\treturn (\n\t\t<UnitControl\n\t\t\t{ ...props }\n\t\t\taria-label={ __( 'Border radius' ) }\n\t\t\tdisableUnits={ isMixed }\n\t\t\tisOnly\n\t\t\tvalue={ allValue }\n\t\t\tonChange={ onChange }\n\t\t\tplaceholder={ allPlaceholder }\n\t\t/>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/border-radius-control/all-input-control.js"],"names":["AllInputControl","onChange","selectedUnits","setSelectedUnits","values","props","allValue","undefined","hasValues","isMixed","allPlaceholder","handleOnChange","next","isNumeric","isNaN","parseFloat","nextValue","handleOnUnitChange","unit","topLeft","topRight","bottomLeft","bottomRight"],"mappings":";;;;;;;;;;;;;AAGA;;AACA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;AAQe,SAASA,eAAT,OAMX;AAAA,MANqC;AACxCC,IAAAA,QADwC;AAExCC,IAAAA,aAFwC;AAGxCC,IAAAA,gBAHwC;AAIxCC,IAAAA,MAJwC;AAKxC,OAAGC;AALqC,GAMrC;AACH,MAAIC,QAAQ,GAAG,wBAAaF,MAAb,CAAf;;AAEA,MAAKE,QAAQ,KAAKC,SAAlB,EAA8B;AAC7B;AACA;AACAD,IAAAA,QAAQ,GAAG,uBAAYJ,aAAZ,CAAX;AACA;;AAED,QAAMM,SAAS,GAAG,6BAAkBJ,MAAlB,CAAlB;AACA,QAAMK,OAAO,GAAGD,SAAS,IAAI,2BAAgBJ,MAAhB,CAA7B;AACA,QAAMM,cAAc,GAAGD,OAAO,GAAG,cAAI,OAAJ,CAAH,GAAmB,IAAjD,CAXG,CAaH;;AACA,QAAME,cAAc,GAAKC,IAAF,IAAY;AAClC,UAAMC,SAAS,GAAG,CAAEC,KAAK,CAAEC,UAAU,CAAEH,IAAF,CAAZ,CAAzB;AACA,UAAMI,SAAS,GAAGH,SAAS,GAAGD,IAAH,GAAUL,SAArC;AACAN,IAAAA,QAAQ,CAAEe,SAAF,CAAR;AACA,GAJD,CAdG,CAoBH;AACA;;;AACA,QAAMC,kBAAkB,GAAKC,IAAF,IAAY;AACtCf,IAAAA,gBAAgB,CAAE;AACjBgB,MAAAA,OAAO,EAAED,IADQ;AAEjBE,MAAAA,QAAQ,EAAEF,IAFO;AAGjBG,MAAAA,UAAU,EAAEH,IAHK;AAIjBI,MAAAA,WAAW,EAAEJ;AAJI,KAAF,CAAhB;AAMA,GAPD;;AASA,SACC,4BAAC,qCAAD,6BACMb,KADN;AAEC,kBAAa,cAAI,eAAJ,CAFd;AAGC,IAAA,YAAY,EAAGI,OAHhB;AAIC,IAAA,MAAM,MAJP;AAKC,IAAA,KAAK,EAAGH,QALT;AAMC,IAAA,QAAQ,EAAGK,cANZ;AAOC,IAAA,YAAY,EAAGM,kBAPhB;AAQC,IAAA,WAAW,EAAGP;AARf,KADD;AAYA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __experimentalUnitControl as UnitControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetAllValue,\n\tgetAllUnit,\n\thasMixedValues,\n\thasDefinedValues,\n} from './utils';\n\nexport default function AllInputControl( {\n\tonChange,\n\tselectedUnits,\n\tsetSelectedUnits,\n\tvalues,\n\t...props\n} ) {\n\tlet allValue = getAllValue( values );\n\n\tif ( allValue === undefined ) {\n\t\t// If we don't have any value set the unit to any current selection\n\t\t// or the most common unit from the individual radii values.\n\t\tallValue = getAllUnit( selectedUnits );\n\t}\n\n\tconst hasValues = hasDefinedValues( values );\n\tconst isMixed = hasValues && hasMixedValues( values );\n\tconst allPlaceholder = isMixed ? __( 'Mixed' ) : null;\n\n\t// Filter out CSS-unit-only values to prevent invalid styles.\n\tconst handleOnChange = ( next ) => {\n\t\tconst isNumeric = ! isNaN( parseFloat( next ) );\n\t\tconst nextValue = isNumeric ? next : undefined;\n\t\tonChange( nextValue );\n\t};\n\n\t// Store current unit selection for use as fallback for individual\n\t// radii controls.\n\tconst handleOnUnitChange = ( unit ) => {\n\t\tsetSelectedUnits( {\n\t\t\ttopLeft: unit,\n\t\t\ttopRight: unit,\n\t\t\tbottomLeft: unit,\n\t\t\tbottomRight: unit,\n\t\t} );\n\t};\n\n\treturn (\n\t\t<UnitControl\n\t\t\t{ ...props }\n\t\t\taria-label={ __( 'Border radius' ) }\n\t\t\tdisableUnits={ isMixed }\n\t\t\tisOnly\n\t\t\tvalue={ allValue }\n\t\t\tonChange={ handleOnChange }\n\t\t\tonUnitChange={ handleOnUnitChange }\n\t\t\tplaceholder={ allPlaceholder }\n\t\t/>\n\t);\n}\n"]}
@@ -31,10 +31,10 @@ var _utils = require("./utils");
31
31
  * Internal dependencies
32
32
  */
33
33
  const DEFAULT_VALUES = {
34
- topLeft: null,
35
- topRight: null,
36
- bottomLeft: null,
37
- bottomRight: null
34
+ topLeft: undefined,
35
+ topRight: undefined,
36
+ bottomLeft: undefined,
37
+ bottomRight: undefined
38
38
  };
39
39
  const MIN_BORDER_RADIUS_VALUE = 0;
40
40
  const MAX_BORDER_RADIUS_VALUES = {
@@ -57,11 +57,21 @@ function BorderRadiusControl(_ref) {
57
57
  onChange,
58
58
  values
59
59
  } = _ref;
60
- const [isLinked, setIsLinked] = (0, _element.useState)(!(0, _utils.hasDefinedValues)(values) || !(0, _utils.hasMixedValues)(values));
60
+ const [isLinked, setIsLinked] = (0, _element.useState)(!(0, _utils.hasDefinedValues)(values) || !(0, _utils.hasMixedValues)(values)); // Tracking selected units via internal state allows filtering of CSS unit
61
+ // only values from being saved while maintaining preexisting unit selection
62
+ // behaviour. Filtering CSS unit only values prevents invalid style values.
63
+
64
+ const [selectedUnits, setSelectedUnits] = (0, _element.useState)({
65
+ flat: typeof values === 'string' ? (0, _components.__experimentalParseQuantityAndUnitFromRawValue)(values)[1] : undefined,
66
+ topLeft: (0, _components.__experimentalParseQuantityAndUnitFromRawValue)(values === null || values === void 0 ? void 0 : values.topLeft)[1],
67
+ topRight: (0, _components.__experimentalParseQuantityAndUnitFromRawValue)(values === null || values === void 0 ? void 0 : values.topRight)[1],
68
+ bottomLeft: (0, _components.__experimentalParseQuantityAndUnitFromRawValue)(values === null || values === void 0 ? void 0 : values.bottomLeft)[1],
69
+ bottomRight: (0, _components.__experimentalParseQuantityAndUnitFromRawValue)(values === null || values === void 0 ? void 0 : values.bottomRight)[1]
70
+ });
61
71
  const units = (0, _components.__experimentalUseCustomUnits)({
62
72
  availableUnits: (0, _useSetting.default)('spacing.units') || ['px', 'em', 'rem']
63
73
  });
64
- const unit = (0, _utils.getAllUnit)(values);
74
+ const unit = (0, _utils.getAllUnit)(selectedUnits);
65
75
  const unitConfig = units && units.find(item => item.value === unit);
66
76
  const step = (unitConfig === null || unitConfig === void 0 ? void 0 : unitConfig.step) || 1;
67
77
  const [allValue] = (0, _components.__experimentalParseQuantityAndUnitFromRawValue)((0, _utils.getAllValue)(values));
@@ -74,13 +84,17 @@ function BorderRadiusControl(_ref) {
74
84
 
75
85
  return (0, _element.createElement)("fieldset", {
76
86
  className: "components-border-radius-control"
77
- }, (0, _element.createElement)("legend", null, (0, _i18n.__)('Radius')), (0, _element.createElement)("div", {
87
+ }, (0, _element.createElement)(_components.BaseControl.VisualLabel, {
88
+ as: "legend"
89
+ }, (0, _i18n.__)('Radius')), (0, _element.createElement)("div", {
78
90
  className: "components-border-radius-control__wrapper"
79
91
  }, isLinked ? (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_allInputControl.default, {
80
92
  className: "components-border-radius-control__unit-control",
81
93
  values: values,
82
94
  min: MIN_BORDER_RADIUS_VALUE,
83
95
  onChange: onChange,
96
+ selectedUnits: selectedUnits,
97
+ setSelectedUnits: setSelectedUnits,
84
98
  units: units
85
99
  }), (0, _element.createElement)(_components.RangeControl, {
86
100
  label: (0, _i18n.__)('Border radius'),
@@ -96,6 +110,8 @@ function BorderRadiusControl(_ref) {
96
110
  })) : (0, _element.createElement)(_inputControls.default, {
97
111
  min: MIN_BORDER_RADIUS_VALUE,
98
112
  onChange: onChange,
113
+ selectedUnits: selectedUnits,
114
+ setSelectedUnits: setSelectedUnits,
99
115
  values: values || DEFAULT_VALUES,
100
116
  units: units
101
117
  }), (0, _element.createElement)(_linkedButton.default, {
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/border-radius-control/index.js"],"names":["DEFAULT_VALUES","topLeft","topRight","bottomLeft","bottomRight","MIN_BORDER_RADIUS_VALUE","MAX_BORDER_RADIUS_VALUES","px","em","rem","BorderRadiusControl","onChange","values","isLinked","setIsLinked","units","availableUnits","unit","unitConfig","find","item","value","step","allValue","toggleLinked","handleSliderChange","next","undefined"],"mappings":";;;;;;;;;AAQA;;AALA;;AAMA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AAlBA;AACA;AACA;;AASA;AACA;AACA;AAYA,MAAMA,cAAc,GAAG;AACtBC,EAAAA,OAAO,EAAE,IADa;AAEtBC,EAAAA,QAAQ,EAAE,IAFY;AAGtBC,EAAAA,UAAU,EAAE,IAHU;AAItBC,EAAAA,WAAW,EAAE;AAJS,CAAvB;AAMA,MAAMC,uBAAuB,GAAG,CAAhC;AACA,MAAMC,wBAAwB,GAAG;AAChCC,EAAAA,EAAE,EAAE,GAD4B;AAEhCC,EAAAA,EAAE,EAAE,EAF4B;AAGhCC,EAAAA,GAAG,EAAE;AAH2B,CAAjC;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACe,SAASC,mBAAT,OAAqD;AAAA,MAAvB;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,GAAuB;AACnE,QAAM,CAAEC,QAAF,EAAYC,WAAZ,IAA4B,uBACjC,CAAE,6BAAkBF,MAAlB,CAAF,IAAgC,CAAE,2BAAgBA,MAAhB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AAA,GAAG,EAAGlB,uBALP;AAMC,IAAA,GAAG,EAAGC,wBAAwB,CAAEW,IAAF,CAN/B;AAOC,IAAA,eAAe,EAAG,CAPnB;AAQC,IAAA,cAAc,EAAG,KARlB;AASC,IAAA,QAAQ,EAAGQ,kBATZ;AAUC,IAAA,IAAI,EAAGH;AAVR,IARD,CADS,GAuBT,4BAAC,sBAAD;AACC,IAAA,GAAG,EAAGjB,uBADP;AAEC,IAAA,QAAQ,EAAGM,QAFZ;AAGC,IAAA,MAAM,EAAGC,MAAM,IAAIZ,cAHpB;AAIC,IAAA,KAAK,EAAGe;AAJT,IAxBF,EA+BC,4BAAC,qBAAD;AAAc,IAAA,OAAO,EAAGS,YAAxB;AAAuC,IAAA,QAAQ,EAAGX;AAAlD,IA/BD,CAFD,CADD;AAsCA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tRangeControl,\n\t__experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue,\n\t__experimentalUseCustomUnits as useCustomUnits,\n} from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport AllInputControl from './all-input-control';\nimport InputControls from './input-controls';\nimport LinkedButton from './linked-button';\nimport useSetting from '../use-setting';\nimport {\n\tgetAllValue,\n\tgetAllUnit,\n\thasDefinedValues,\n\thasMixedValues,\n} from './utils';\n\nconst DEFAULT_VALUES = {\n\ttopLeft: null,\n\ttopRight: null,\n\tbottomLeft: null,\n\tbottomRight: null,\n};\nconst MIN_BORDER_RADIUS_VALUE = 0;\nconst MAX_BORDER_RADIUS_VALUES = {\n\tpx: 100,\n\tem: 20,\n\trem: 20,\n};\n\n/**\n * Control to display border radius options.\n *\n * @param {Object} props Component props.\n * @param {Function} props.onChange Callback to handle onChange.\n * @param {Object} props.values Border radius values.\n *\n * @return {WPElement} Custom border radius control.\n */\nexport default function BorderRadiusControl( { onChange, values } ) {\n\tconst [ isLinked, setIsLinked ] = useState(\n\t\t! hasDefinedValues( values ) || ! hasMixedValues( values )\n\t);\n\n\tconst units = useCustomUnits( {\n\t\tavailableUnits: useSetting( 'spacing.units' ) || [ 'px', 'em', 'rem' ],\n\t} );\n\n\tconst unit = getAllUnit( values );\n\tconst unitConfig = units && units.find( ( item ) => item.value === unit );\n\tconst step = unitConfig?.step || 1;\n\n\tconst [ allValue ] = parseQuantityAndUnitFromRawValue(\n\t\tgetAllValue( values )\n\t);\n\n\tconst toggleLinked = () => setIsLinked( ! isLinked );\n\n\tconst handleSliderChange = ( next ) => {\n\t\tonChange( next !== undefined ? `${ next }${ unit }` : undefined );\n\t};\n\n\treturn (\n\t\t<fieldset className=\"components-border-radius-control\">\n\t\t\t<legend>{ __( 'Radius' ) }</legend>\n\t\t\t<div className=\"components-border-radius-control__wrapper\">\n\t\t\t\t{ isLinked ? (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<AllInputControl\n\t\t\t\t\t\t\tclassName=\"components-border-radius-control__unit-control\"\n\t\t\t\t\t\t\tvalues={ values }\n\t\t\t\t\t\t\tmin={ MIN_BORDER_RADIUS_VALUE }\n\t\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\t\tunits={ units }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<RangeControl\n\t\t\t\t\t\t\tlabel={ __( 'Border radius' ) }\n\t\t\t\t\t\t\thideLabelFromVision\n\t\t\t\t\t\t\tclassName=\"components-border-radius-control__range-control\"\n\t\t\t\t\t\t\tvalue={ allValue ?? '' }\n\t\t\t\t\t\t\tmin={ MIN_BORDER_RADIUS_VALUE }\n\t\t\t\t\t\t\tmax={ MAX_BORDER_RADIUS_VALUES[ unit ] }\n\t\t\t\t\t\t\tinitialPosition={ 0 }\n\t\t\t\t\t\t\twithInputField={ false }\n\t\t\t\t\t\t\tonChange={ handleSliderChange }\n\t\t\t\t\t\t\tstep={ step }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</>\n\t\t\t\t) : (\n\t\t\t\t\t<InputControls\n\t\t\t\t\t\tmin={ MIN_BORDER_RADIUS_VALUE }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\tvalues={ values || DEFAULT_VALUES }\n\t\t\t\t\t\tunits={ units }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t<LinkedButton onClick={ toggleLinked } isLinked={ isLinked } />\n\t\t\t</div>\n\t\t</fieldset>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/border-radius-control/index.js"],"names":["DEFAULT_VALUES","topLeft","undefined","topRight","bottomLeft","bottomRight","MIN_BORDER_RADIUS_VALUE","MAX_BORDER_RADIUS_VALUES","px","em","rem","BorderRadiusControl","onChange","values","isLinked","setIsLinked","selectedUnits","setSelectedUnits","flat","units","availableUnits","unit","unitConfig","find","item","value","step","allValue","toggleLinked","handleSliderChange","next"],"mappings":";;;;;;;;;AASA;;AANA;;AAOA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AAnBA;AACA;AACA;;AAUA;AACA;AACA;AAYA,MAAMA,cAAc,GAAG;AACtBC,EAAAA,OAAO,EAAEC,SADa;AAEtBC,EAAAA,QAAQ,EAAED,SAFY;AAGtBE,EAAAA,UAAU,EAAEF,SAHU;AAItBG,EAAAA,WAAW,EAAEH;AAJS,CAAvB;AAMA,MAAMI,uBAAuB,GAAG,CAAhC;AACA,MAAMC,wBAAwB,GAAG;AAChCC,EAAAA,EAAE,EAAE,GAD4B;AAEhCC,EAAAA,EAAE,EAAE,EAF4B;AAGhCC,EAAAA,GAAG,EAAE;AAH2B,CAAjC;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACe,SAASC,mBAAT,OAAqD;AAAA,MAAvB;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,GAAuB;AACnE,QAAM,CAAEC,QAAF,EAAYC,WAAZ,IAA4B,uBACjC,CAAE,6BAAkBF,MAAlB,CAAF,IAAgC,CAAE,2BAAgBA,MAAhB,CAD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AAc,IAAA,OAAO,EAAGS,YAAxB;AAAuC,IAAA,QAAQ,EAAGd;AAAlD,IAnCD,CAJD,CADD;AA4CA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tBaseControl,\n\tRangeControl,\n\t__experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue,\n\t__experimentalUseCustomUnits as useCustomUnits,\n} from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport AllInputControl from './all-input-control';\nimport InputControls from './input-controls';\nimport LinkedButton from './linked-button';\nimport useSetting from '../use-setting';\nimport {\n\tgetAllValue,\n\tgetAllUnit,\n\thasDefinedValues,\n\thasMixedValues,\n} from './utils';\n\nconst DEFAULT_VALUES = {\n\ttopLeft: undefined,\n\ttopRight: undefined,\n\tbottomLeft: undefined,\n\tbottomRight: undefined,\n};\nconst MIN_BORDER_RADIUS_VALUE = 0;\nconst MAX_BORDER_RADIUS_VALUES = {\n\tpx: 100,\n\tem: 20,\n\trem: 20,\n};\n\n/**\n * Control to display border radius options.\n *\n * @param {Object} props Component props.\n * @param {Function} props.onChange Callback to handle onChange.\n * @param {Object} props.values Border radius values.\n *\n * @return {WPElement} Custom border radius control.\n */\nexport default function BorderRadiusControl( { onChange, values } ) {\n\tconst [ isLinked, setIsLinked ] = useState(\n\t\t! hasDefinedValues( values ) || ! hasMixedValues( values )\n\t);\n\n\t// Tracking selected units via internal state allows filtering of CSS unit\n\t// only values from being saved while maintaining preexisting unit selection\n\t// behaviour. Filtering CSS unit only values prevents invalid style values.\n\tconst [ selectedUnits, setSelectedUnits ] = useState( {\n\t\tflat:\n\t\t\ttypeof values === 'string'\n\t\t\t\t? parseQuantityAndUnitFromRawValue( values )[ 1 ]\n\t\t\t\t: undefined,\n\t\ttopLeft: parseQuantityAndUnitFromRawValue( values?.topLeft )[ 1 ],\n\t\ttopRight: parseQuantityAndUnitFromRawValue( values?.topRight )[ 1 ],\n\t\tbottomLeft: parseQuantityAndUnitFromRawValue( values?.bottomLeft )[ 1 ],\n\t\tbottomRight: parseQuantityAndUnitFromRawValue(\n\t\t\tvalues?.bottomRight\n\t\t)[ 1 ],\n\t} );\n\n\tconst units = useCustomUnits( {\n\t\tavailableUnits: useSetting( 'spacing.units' ) || [ 'px', 'em', 'rem' ],\n\t} );\n\n\tconst unit = getAllUnit( selectedUnits );\n\tconst unitConfig = units && units.find( ( item ) => item.value === unit );\n\tconst step = unitConfig?.step || 1;\n\n\tconst [ allValue ] = parseQuantityAndUnitFromRawValue(\n\t\tgetAllValue( values )\n\t);\n\n\tconst toggleLinked = () => setIsLinked( ! isLinked );\n\n\tconst handleSliderChange = ( next ) => {\n\t\tonChange( next !== undefined ? `${ next }${ unit }` : undefined );\n\t};\n\n\treturn (\n\t\t<fieldset className=\"components-border-radius-control\">\n\t\t\t<BaseControl.VisualLabel as=\"legend\">\n\t\t\t\t{ __( 'Radius' ) }\n\t\t\t</BaseControl.VisualLabel>\n\t\t\t<div className=\"components-border-radius-control__wrapper\">\n\t\t\t\t{ isLinked ? (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<AllInputControl\n\t\t\t\t\t\t\tclassName=\"components-border-radius-control__unit-control\"\n\t\t\t\t\t\t\tvalues={ values }\n\t\t\t\t\t\t\tmin={ MIN_BORDER_RADIUS_VALUE }\n\t\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\t\tselectedUnits={ selectedUnits }\n\t\t\t\t\t\t\tsetSelectedUnits={ setSelectedUnits }\n\t\t\t\t\t\t\tunits={ units }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<RangeControl\n\t\t\t\t\t\t\tlabel={ __( 'Border radius' ) }\n\t\t\t\t\t\t\thideLabelFromVision\n\t\t\t\t\t\t\tclassName=\"components-border-radius-control__range-control\"\n\t\t\t\t\t\t\tvalue={ allValue ?? '' }\n\t\t\t\t\t\t\tmin={ MIN_BORDER_RADIUS_VALUE }\n\t\t\t\t\t\t\tmax={ MAX_BORDER_RADIUS_VALUES[ unit ] }\n\t\t\t\t\t\t\tinitialPosition={ 0 }\n\t\t\t\t\t\t\twithInputField={ false }\n\t\t\t\t\t\t\tonChange={ handleSliderChange }\n\t\t\t\t\t\t\tstep={ step }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</>\n\t\t\t\t) : (\n\t\t\t\t\t<InputControls\n\t\t\t\t\t\tmin={ MIN_BORDER_RADIUS_VALUE }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\tselectedUnits={ selectedUnits }\n\t\t\t\t\t\tsetSelectedUnits={ setSelectedUnits }\n\t\t\t\t\t\tvalues={ values || DEFAULT_VALUES }\n\t\t\t\t\t\tunits={ units }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t<LinkedButton onClick={ toggleLinked } isLinked={ isLinked } />\n\t\t\t</div>\n\t\t</fieldset>\n\t);\n}\n"]}
@@ -28,6 +28,8 @@ const CORNERS = {
28
28
  function BoxInputControls(_ref) {
29
29
  let {
30
30
  onChange,
31
+ selectedUnits,
32
+ setSelectedUnits,
31
33
  values: valuesProp,
32
34
  ...props
33
35
  } = _ref;
@@ -35,11 +37,21 @@ function BoxInputControls(_ref) {
35
37
  const createHandleOnChange = corner => next => {
36
38
  if (!onChange) {
37
39
  return;
38
- }
40
+ } // Filter out CSS-unit-only values to prevent invalid styles.
39
41
 
42
+
43
+ const isNumeric = !isNaN(parseFloat(next));
44
+ const nextValue = isNumeric ? next : undefined;
40
45
  onChange({ ...values,
41
- [corner]: next ? next : undefined
46
+ [corner]: nextValue
42
47
  });
48
+ };
49
+
50
+ const createHandleOnUnitChange = side => next => {
51
+ const newUnits = { ...selectedUnits
52
+ };
53
+ newUnits[side] = next;
54
+ setSelectedUnits(newUnits);
43
55
  }; // For shorthand style & backwards compatibility, handle flat string value.
44
56
 
45
57
 
@@ -55,17 +67,20 @@ function BoxInputControls(_ref) {
55
67
  return (0, _element.createElement)("div", {
56
68
  className: "components-border-radius-control__input-controls-wrapper"
57
69
  }, Object.entries(CORNERS).map(_ref2 => {
58
- let [key, label] = _ref2;
70
+ let [corner, label] = _ref2;
71
+ const [parsedQuantity, parsedUnit] = (0, _components.__experimentalParseQuantityAndUnitFromRawValue)(values[corner]);
72
+ const computedUnit = values[corner] ? parsedUnit : selectedUnits[corner] || selectedUnits.flat;
59
73
  return (0, _element.createElement)(_components.Tooltip, {
60
74
  text: label,
61
75
  position: "top",
62
- key: key
76
+ key: corner
63
77
  }, (0, _element.createElement)("div", {
64
78
  className: "components-border-radius-control__tooltip-wrapper"
65
79
  }, (0, _element.createElement)(_components.__experimentalUnitControl, (0, _extends2.default)({}, props, {
66
80
  "aria-label": label,
67
- value: values[key],
68
- onChange: createHandleOnChange(key)
81
+ value: [parsedQuantity, computedUnit].join(''),
82
+ onChange: createHandleOnChange(corner),
83
+ onUnitChange: createHandleOnUnitChange(corner)
69
84
  }))));
70
85
  }));
71
86
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/border-radius-control/input-controls.js"],"names":["CORNERS","topLeft","topRight","bottomLeft","bottomRight","BoxInputControls","onChange","values","valuesProp","props","createHandleOnChange","corner","next","undefined","Object","entries","map","key","label"],"mappings":";;;;;;;;;;;;;AAGA;;AAIA;;AAPA;AACA;AACA;AAOA,MAAMA,OAAO,GAAG;AACfC,EAAAA,OAAO,EAAE,cAAI,UAAJ,CADM;AAEfC,EAAAA,QAAQ,EAAE,cAAI,WAAJ,CAFK;AAGfC,EAAAA,UAAU,EAAE,cAAI,aAAJ,CAHG;AAIfC,EAAAA,WAAW,EAAE,cAAI,cAAJ;AAJE,CAAhB;;AAOe,SAASC,gBAAT,OAIX;AAAA,MAJsC;AACzCC,IAAAA,QADyC;AAEzCC,IAAAA,MAAM,EAAEC,UAFiC;AAGzC,OAAGC;AAHsC,GAItC;;AACH,QAAMC,oBAAoB,GAAKC,MAAF,IAAgBC,IAAF,IAAY;AACtD,QAAK,CAAEN,QAAP,EAAkB;AACjB;AACA;;AAEDA,IAAAA,QAAQ,CAAE,EACT,GAAGC,MADM;AAET,OAAEI,MAAF,GAAYC,IAAI,GAAGA,IAAH,GAAUC;AAFjB,KAAF,CAAR;AAIA,GATD,CADG,CAYH;;;AACA,QAAMN,MAAM,GACX,OAAOC,UAAP,KAAsB,QAAtB,GACGA,UADH,GAEG;AACAP,IAAAA,OAAO,EAAEO,UADT;AAEAN,IAAAA,QAAQ,EAAEM,UAFV;AAGAL,IAAAA,UAAU,EAAEK,UAHZ;AAIAJ,IAAAA,WAAW,EAAEI;AAJb,GAHJ,CAbG,CAuBH;AACA;AACA;;AACA,SACC;AAAK,IAAA,SAAS,EAAC;AAAf,KACGM,MAAM,CAACC,OAAP,CAAgBf,OAAhB,EAA0BgB,GAA1B,CAA+B;AAAA,QAAE,CAAEC,GAAF,EAAOC,KAAP,CAAF;AAAA,WAChC,4BAAC,mBAAD;AAAS,MAAA,IAAI,EAAGA,KAAhB;AAAwB,MAAA,QAAQ,EAAC,KAAjC;AAAuC,MAAA,GAAG,EAAGD;AAA7C,OACC;AAAK,MAAA,SAAS,EAAC;AAAf,OACC,4BAAC,qCAAD,6BACMR,KADN;AAEC,oBAAaS,KAFd;AAGC,MAAA,KAAK,EAAGX,MAAM,CAAEU,GAAF,CAHf;AAIC,MAAA,QAAQ,EAAGP,oBAAoB,CAAEO,GAAF;AAJhC,OADD,CADD,CADgC;AAAA,GAA/B,CADH,CADD;AAgBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalUnitControl as UnitControl,\n\tTooltip,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\nconst CORNERS = {\n\ttopLeft: __( 'Top left' ),\n\ttopRight: __( 'Top right' ),\n\tbottomLeft: __( 'Bottom left' ),\n\tbottomRight: __( 'Bottom right' ),\n};\n\nexport default function BoxInputControls( {\n\tonChange,\n\tvalues: valuesProp,\n\t...props\n} ) {\n\tconst createHandleOnChange = ( corner ) => ( next ) => {\n\t\tif ( ! onChange ) {\n\t\t\treturn;\n\t\t}\n\n\t\tonChange( {\n\t\t\t...values,\n\t\t\t[ corner ]: next ? next : undefined,\n\t\t} );\n\t};\n\n\t// For shorthand style & backwards compatibility, handle flat string value.\n\tconst values =\n\t\ttypeof valuesProp !== 'string'\n\t\t\t? valuesProp\n\t\t\t: {\n\t\t\t\t\ttopLeft: valuesProp,\n\t\t\t\t\ttopRight: valuesProp,\n\t\t\t\t\tbottomLeft: valuesProp,\n\t\t\t\t\tbottomRight: valuesProp,\n\t\t\t };\n\n\t// Controls are wrapped in tooltips as visible labels aren't desired here.\n\t// Tooltip rendering also requires the UnitControl to be wrapped. See:\n\t// https://github.com/WordPress/gutenberg/pull/24966#issuecomment-685875026\n\treturn (\n\t\t<div className=\"components-border-radius-control__input-controls-wrapper\">\n\t\t\t{ Object.entries( CORNERS ).map( ( [ key, label ] ) => (\n\t\t\t\t<Tooltip text={ label } position=\"top\" key={ key }>\n\t\t\t\t\t<div className=\"components-border-radius-control__tooltip-wrapper\">\n\t\t\t\t\t\t<UnitControl\n\t\t\t\t\t\t\t{ ...props }\n\t\t\t\t\t\t\taria-label={ label }\n\t\t\t\t\t\t\tvalue={ values[ key ] }\n\t\t\t\t\t\t\tonChange={ createHandleOnChange( key ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t</Tooltip>\n\t\t\t) ) }\n\t\t</div>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/border-radius-control/input-controls.js"],"names":["CORNERS","topLeft","topRight","bottomLeft","bottomRight","BoxInputControls","onChange","selectedUnits","setSelectedUnits","values","valuesProp","props","createHandleOnChange","corner","next","isNumeric","isNaN","parseFloat","nextValue","undefined","createHandleOnUnitChange","side","newUnits","Object","entries","map","label","parsedQuantity","parsedUnit","computedUnit","flat","join"],"mappings":";;;;;;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;AAQA,MAAMA,OAAO,GAAG;AACfC,EA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AAgBxB,OAAhB,EAA0ByB,GAA1B,CAA+B,SAAyB;AAAA,QAAvB,CAAEZ,MAAF,EAAUa,KAAV,CAAuB;AACzD,UAAM,CAAEC,cAAF,EAAkBC,UAAlB,IACL,gEAAkCnB,MAAM,CAAEI,MAAF,CAAxC,CADD;AAGA,UAAMgB,YAAY,GAAGpB,MAAM,CAAEI,MAAF,CAAN,GAClBe,UADkB,GAElBrB,aAAa,CAAEM,MAAF,CAAb,IAA2BN,aAAa,CAACuB,IAF5C;AAIA,WACC,4BAAC,mBAAD;AAAS,MAAA,IAAI,EAAGJ,KAAhB;AAAwB,MAAA,QAAQ,EAAC,KAAjC;AAAuC,MAAA,GAAG,EAAGb;AAA7C,OACC;AAAK,MAAA,SAAS,EAAC;AAAf,OACC,4BAAC,qCAAD,6BACMF,KADN;AAEC,oBAAae,KAFd;AAGC,MAAA,KAAK,EAAG,CAAEC,cAAF,EAAkBE,YAAlB,EAAiCE,IAAjC,CACP,EADO,CAHT;AAMC,MAAA,QAAQ,EAAGnB,oBAAoB,CAAEC,MAAF,CANhC;AAOC,MAAA,YAAY,EAAGO,wBAAwB,CACtCP,MADsC;AAPxC,OADD,CADD,CADD;AAiBA,GAzBC,CADH,CADD;AA8BA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue,\n\t__experimentalUnitControl as UnitControl,\n\tTooltip,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\nconst CORNERS = {\n\ttopLeft: __( 'Top left' ),\n\ttopRight: __( 'Top right' ),\n\tbottomLeft: __( 'Bottom left' ),\n\tbottomRight: __( 'Bottom right' ),\n};\n\nexport default function BoxInputControls( {\n\tonChange,\n\tselectedUnits,\n\tsetSelectedUnits,\n\tvalues: valuesProp,\n\t...props\n} ) {\n\tconst createHandleOnChange = ( corner ) => ( next ) => {\n\t\tif ( ! onChange ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Filter out CSS-unit-only values to prevent invalid styles.\n\t\tconst isNumeric = ! isNaN( parseFloat( next ) );\n\t\tconst nextValue = isNumeric ? next : undefined;\n\n\t\tonChange( {\n\t\t\t...values,\n\t\t\t[ corner ]: nextValue,\n\t\t} );\n\t};\n\n\tconst createHandleOnUnitChange = ( side ) => ( next ) => {\n\t\tconst newUnits = { ...selectedUnits };\n\t\tnewUnits[ side ] = next;\n\t\tsetSelectedUnits( newUnits );\n\t};\n\n\t// For shorthand style & backwards compatibility, handle flat string value.\n\tconst values =\n\t\ttypeof valuesProp !== 'string'\n\t\t\t? valuesProp\n\t\t\t: {\n\t\t\t\t\ttopLeft: valuesProp,\n\t\t\t\t\ttopRight: valuesProp,\n\t\t\t\t\tbottomLeft: valuesProp,\n\t\t\t\t\tbottomRight: valuesProp,\n\t\t\t };\n\n\t// Controls are wrapped in tooltips as visible labels aren't desired here.\n\t// Tooltip rendering also requires the UnitControl to be wrapped. See:\n\t// https://github.com/WordPress/gutenberg/pull/24966#issuecomment-685875026\n\treturn (\n\t\t<div className=\"components-border-radius-control__input-controls-wrapper\">\n\t\t\t{ Object.entries( CORNERS ).map( ( [ corner, label ] ) => {\n\t\t\t\tconst [ parsedQuantity, parsedUnit ] =\n\t\t\t\t\tparseQuantityAndUnitFromRawValue( values[ corner ] );\n\n\t\t\t\tconst computedUnit = values[ corner ]\n\t\t\t\t\t? parsedUnit\n\t\t\t\t\t: selectedUnits[ corner ] || selectedUnits.flat;\n\n\t\t\t\treturn (\n\t\t\t\t\t<Tooltip text={ label } position=\"top\" key={ corner }>\n\t\t\t\t\t\t<div className=\"components-border-radius-control__tooltip-wrapper\">\n\t\t\t\t\t\t\t<UnitControl\n\t\t\t\t\t\t\t\t{ ...props }\n\t\t\t\t\t\t\t\taria-label={ label }\n\t\t\t\t\t\t\t\tvalue={ [ parsedQuantity, computedUnit ].join(\n\t\t\t\t\t\t\t\t\t''\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tonChange={ createHandleOnChange( corner ) }\n\t\t\t\t\t\t\t\tonUnitChange={ createHandleOnUnitChange(\n\t\t\t\t\t\t\t\t\tcorner\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</Tooltip>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</div>\n\t);\n}\n"]}
@@ -33,27 +33,24 @@ function mode(inputArray) {
33
33
  return arr.sort((a, b) => inputArray.filter(v => v === b).length - inputArray.filter(v => v === a).length).shift();
34
34
  }
35
35
  /**
36
- * Returns the most common CSS unit in the radius values.
37
- * Falls back to `px` as a default unit.
36
+ * Returns the most common CSS unit from the current CSS unit selections.
38
37
  *
39
- * @param {Object|string} values Radius values.
40
- * @return {string} Most common CSS unit in values. Default: `px`.
38
+ * - If a single flat border radius is set, its unit will be used
39
+ * - If individual corner selections, the most common of those will be used
40
+ * - Failing any unit selections a default of 'px' is returned.
41
+ *
42
+ * @param {Object} selectedUnits Unit selections for flat radius & each corner.
43
+ * @return {string} Most common CSS unit from current selections. Default: `px`.
41
44
  */
42
45
 
43
46
 
44
47
  function getAllUnit() {
45
- let values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
46
-
47
- if (typeof values === 'string') {
48
- const [, unit] = (0, _components.__experimentalParseQuantityAndUnitFromRawValue)(values);
49
- return unit || 'px';
50
- }
51
-
52
- const allUnits = Object.values(values).map(value => {
53
- const [, unit] = (0, _components.__experimentalParseQuantityAndUnitFromRawValue)(value);
54
- return unit;
55
- });
56
- return mode(allUnits) || 'px';
48
+ let selectedUnits = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
49
+ const {
50
+ flat,
51
+ ...cornerUnits
52
+ } = selectedUnits;
53
+ return flat || mode(Object.values(cornerUnits).filter(Boolean)) || 'px';
57
54
  }
58
55
  /**
59
56
  * Gets the 'all' input value and unit from values data.
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/border-radius-control/utils.js"],"names":["mode","inputArray","arr","sort","a","b","filter","v","length","shift","getAllUnit","values","unit","allUnits","Object","map","value","getAllValue","parsedQuantitiesAndUnits","allValues","every","allValue","undefined","hasMixedValues","isMixed","isNaN","parseFloat","hasDefinedValues","filteredValues"],"mappings":";;;;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,IAAT,CAAeC,UAAf,EAA4B;AAClC,QAAMC,GAAG,GAAG,CAAE,GAAGD,UAAL,CAAZ;AACA,SAAOC,GAAG,CACRC,IADK,CAEL,CAAEC,CAAF,EAAKC,CAAL,KACCJ,UAAU,CAACK,MAAX,CAAqBC,CAAF,IAASA,CAAC,KAAKF,CAAlC,EAAsCG,MAAtC,GACAP,UAAU,CAACK,MAAX,CAAqBC,CAAF,IAASA,CAAC,KAAKH,CAAlC,EAAsCI,MAJlC,EAMLC,KANK,EAAP;AAOA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,UAAT,GAAmC;AAAA,MAAdC,MAAc,uEAAL,EAAK;;AACzC,MAAK,OAAOA,MAAP,KAAkB,QAAvB,EAAkC;AACjC,UAAM,GAAIC,IAAJ,IAAa,gEAAkCD,MAAlC,CAAnB;AACA,WAAOC,IAAI,IAAI,IAAf;AACA;;AAED,QAAMC,QAAQ,GAAGC,MAAM,CAACH,MAAP,CAAeA,MAAf,EAAwBI,GAAxB,CAA+BC,KAAF,IAAa;AAC1D,UAAM,GAAIJ,IAAJ,IAAa,gEAAkCI,KAAlC,CAAnB;AACA,WAAOJ,IAAP;AACA,GAHgB,CAAjB;AAKA,SAAOZ,IAAI,CAAEa,QAAF,CAAJ,IAAoB,IAA3B;AACA;AAED;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASI,WAAT,GAAoC;AAAA,MAAdN,MAAc,uEAAL,EAAK;;AAC1C;AACD;AACA;AACA;AACA;AACC,MAAK,OAAOA,MAAP,KAAkB,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kC;AACjC,WAAO,IAAP;AACA,GARyC,CAU1C;AACA;;;AACA,QAAMiB,cAAc,GAAGd,MAAM,CAACH,MAAP,CAAeA,MAAf,EAAwBL,MAAxB,CAAkCU,KAAF,IAAa;AACnE,WAAO,CAAC,CAAEA,KAAH,IAAYA,KAAK,KAAK,CAA7B;AACA,GAFsB,CAAvB;AAIA,SAAO,CAAC,CAAEY,cAAc,CAACpB,MAAzB;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue } from '@wordpress/components';\n\n/**\n * Gets the (non-undefined) item with the highest occurrence within an array\n * Based in part on: https://stackoverflow.com/a/20762713\n *\n * Undefined values are always sorted to the end by `sort`, so this function\n * returns the first element, to always prioritize real values over undefined\n * values.\n *\n * See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#description\n *\n * @param {Array<any>} inputArray Array of items to check.\n * @return {any} The item with the most occurrences.\n */\nexport function mode( inputArray ) {\n\tconst arr = [ ...inputArray ];\n\treturn arr\n\t\t.sort(\n\t\t\t( a, b ) =>\n\t\t\t\tinputArray.filter( ( v ) => v === b ).length -\n\t\t\t\tinputArray.filter( ( v ) => v === a ).length\n\t\t)\n\t\t.shift();\n}\n\n/**\n * Returns the most common CSS unit in the radius values.\n * Falls back to `px` as a default unit.\n *\n * @param {Object|string} values Radius values.\n * @return {string} Most common CSS unit in values. Default: `px`.\n */\nexport function getAllUnit( values = {} ) {\n\tif ( typeof values === 'string' ) {\n\t\tconst [ , unit ] = parseQuantityAndUnitFromRawValue( values );\n\t\treturn unit || 'px';\n\t}\n\n\tconst allUnits = Object.values( values ).map( ( value ) => {\n\t\tconst [ , unit ] = parseQuantityAndUnitFromRawValue( value );\n\t\treturn unit;\n\t} );\n\n\treturn mode( allUnits ) || 'px';\n}\n\n/**\n * Gets the 'all' input value and unit from values data.\n *\n * @param {Object|string} values Radius values.\n * @return {string} A value + unit for the 'all' input.\n */\nexport function getAllValue( values = {} ) {\n\t/**\n\t * Border radius support was originally a single pixel value.\n\t *\n\t * To maintain backwards compatibility treat this case as the all value.\n\t */\n\tif ( typeof values === 'string' ) {\n\t\treturn values;\n\t}\n\n\tconst parsedQuantitiesAndUnits = Object.values( values ).map( ( value ) =>\n\t\tparseQuantityAndUnitFromRawValue( value )\n\t);\n\n\tconst allValues = parsedQuantitiesAndUnits.map(\n\t\t( value ) => value[ 0 ] ?? ''\n\t);\n\tconst allUnits = parsedQuantitiesAndUnits.map( ( value ) => value[ 1 ] );\n\n\tconst value = allValues.every( ( v ) => v === allValues[ 0 ] )\n\t\t? allValues[ 0 ]\n\t\t: '';\n\tconst unit = mode( allUnits );\n\n\tconst allValue = value === 0 || value ? `${ value }${ unit }` : undefined;\n\n\treturn allValue;\n}\n\n/**\n * Checks to determine if values are mixed.\n *\n * @param {Object} values Radius values.\n * @return {boolean} Whether values are mixed.\n */\nexport function hasMixedValues( values = {} ) {\n\tconst allValue = getAllValue( values );\n\tconst isMixed =\n\t\ttypeof values === 'string' ? false : isNaN( parseFloat( allValue ) );\n\n\treturn isMixed;\n}\n\n/**\n * Checks to determine if values are defined.\n *\n * @param {Object} values Radius values.\n * @return {boolean} Whether values are mixed.\n */\nexport function hasDefinedValues( values ) {\n\tif ( ! values ) {\n\t\treturn false;\n\t}\n\n\t// A string value represents a shorthand value.\n\tif ( typeof values === 'string' ) {\n\t\treturn true;\n\t}\n\n\t// An object represents longhand border radius values, if any are set\n\t// flag values as being defined.\n\tconst filteredValues = Object.values( values ).filter( ( value ) => {\n\t\treturn !! value || value === 0;\n\t} );\n\n\treturn !! filteredValues.length;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/border-radius-control/utils.js"],"names":["mode","inputArray","arr","sort","a","b","filter","v","length","shift","getAllUnit","selectedUnits","flat","cornerUnits","Object","values","Boolean","getAllValue","parsedQuantitiesAndUnits","map","value","allValues","allUnits","every","unit","allValue","undefined","hasMixedValues","is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n */\nimport { __experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue } from '@wordpress/components';\n\n/**\n * Gets the (non-undefined) item with the highest occurrence within an array\n * Based in part on: https://stackoverflow.com/a/20762713\n *\n * Undefined values are always sorted to the end by `sort`, so this function\n * returns the first element, to always prioritize real values over undefined\n * values.\n *\n * See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#description\n *\n * @param {Array<any>} inputArray Array of items to check.\n * @return {any} The item with the most occurrences.\n */\nexport function mode( inputArray ) {\n\tconst arr = [ ...inputArray ];\n\treturn arr\n\t\t.sort(\n\t\t\t( a, b ) =>\n\t\t\t\tinputArray.filter( ( v ) => v === b ).length -\n\t\t\t\tinputArray.filter( ( v ) => v === a ).length\n\t\t)\n\t\t.shift();\n}\n\n/**\n * Returns the most common CSS unit from the current CSS unit selections.\n *\n * - If a single flat border radius is set, its unit will be used\n * - If individual corner selections, the most common of those will be used\n * - Failing any unit selections a default of 'px' is returned.\n *\n * @param {Object} selectedUnits Unit selections for flat radius & each corner.\n * @return {string} Most common CSS unit from current selections. Default: `px`.\n */\nexport function getAllUnit( selectedUnits = {} ) {\n\tconst { flat, ...cornerUnits } = selectedUnits;\n\treturn (\n\t\tflat || mode( Object.values( cornerUnits ).filter( Boolean ) ) || 'px'\n\t);\n}\n\n/**\n * Gets the 'all' input value and unit from values data.\n *\n * @param {Object|string} values Radius values.\n * @return {string} A value + unit for the 'all' input.\n */\nexport function getAllValue( values = {} ) {\n\t/**\n\t * Border radius support was originally a single pixel value.\n\t *\n\t * To maintain backwards compatibility treat this case as the all value.\n\t */\n\tif ( typeof values === 'string' ) {\n\t\treturn values;\n\t}\n\n\tconst parsedQuantitiesAndUnits = Object.values( values ).map( ( value ) =>\n\t\tparseQuantityAndUnitFromRawValue( value )\n\t);\n\n\tconst allValues = parsedQuantitiesAndUnits.map(\n\t\t( value ) => value[ 0 ] ?? ''\n\t);\n\tconst allUnits = parsedQuantitiesAndUnits.map( ( value ) => value[ 1 ] );\n\n\tconst value = allValues.every( ( v ) => v === allValues[ 0 ] )\n\t\t? allValues[ 0 ]\n\t\t: '';\n\tconst unit = mode( allUnits );\n\n\tconst allValue = value === 0 || value ? `${ value }${ unit }` : undefined;\n\n\treturn allValue;\n}\n\n/**\n * Checks to determine if values are mixed.\n *\n * @param {Object} values Radius values.\n * @return {boolean} Whether values are mixed.\n */\nexport function hasMixedValues( values = {} ) {\n\tconst allValue = getAllValue( values );\n\tconst isMixed =\n\t\ttypeof values === 'string' ? false : isNaN( parseFloat( allValue ) );\n\n\treturn isMixed;\n}\n\n/**\n * Checks to determine if values are defined.\n *\n * @param {Object} values Radius values.\n * @return {boolean} Whether values are mixed.\n */\nexport function hasDefinedValues( values ) {\n\tif ( ! values ) {\n\t\treturn false;\n\t}\n\n\t// A string value represents a shorthand value.\n\tif ( typeof values === 'string' ) {\n\t\treturn true;\n\t}\n\n\t// An object represents longhand border radius values, if any are set\n\t// flag values as being defined.\n\tconst filteredValues = Object.values( values ).filter( ( value ) => {\n\t\treturn !! value || value === 0;\n\t} );\n\n\treturn !! filteredValues.length;\n}\n"]}
@@ -99,11 +99,15 @@ function getColorClassName(colorContextName, colorSlug) {
99
99
 
100
100
  function getMostReadableColor(colors, colorValue) {
101
101
  const colordColor = (0, _colord.colord)(colorValue);
102
- return (0, _lodash.maxBy)(colors, _ref => {
102
+
103
+ const getColorContrast = _ref => {
103
104
  let {
104
105
  color
105
106
  } = _ref;
106
107
  return colordColor.contrast(color);
107
- }).color;
108
+ };
109
+
110
+ const maxContrast = Math.max(...colors.map(getColorContrast));
111
+ return colors.find(color => getColorContrast(color) === maxContrast).color;
108
112
  }
109
113
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/colors/utils.js"],"names":["namesPlugin","a11yPlugin","getColorObjectByAttributeValues","colors","definedColor","customColor","colorObj","slug","color","getColorObjectByColorValue","colorValue","getColorClassName","colorContextName","colorSlug","undefined","getMostReadableColor","colordColor","contrast"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AANA;AACA;AACA;AAMA,oBAAQ,CAAEA,cAAF,EAAeC,aAAf,CAAR;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,MAAMC,+BAA+B,GAAG,CAC9CC,MAD8C,EAE9CC,YAF8C,EAG9CC,WAH8C,KAI1C;AACJ,MAAKD,YAAL,EAAoB;AACnB,UAAME,QAAQ,GAAG,kBAAMH,MAAN,EAAc;AAAEI,MAAAA,IAAI,EAAEH;AAAR,KAAd,CAAjB;;AAEA,QAAKE,QAAL,EAAgB;AACf,aAAOA,QAAP;AACA;AACD;;AACD,SAAO;AACNE,IAAAA,KAAK,EAAEH;AADD,GAAP;AAGA,CAfM;AAiBP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAMI,0BAA0B,GAAG,CAAEN,MAAF,EAAUO,UAAV,KAA0B;AACnE,SAAO,kBAAMP,MAAN,EAAc;AAAEK,IAAAA,KAAK,EAAEE;AAAT,GAAd,CAAP;AACA,CAFM;AAIP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,SAASC,iBAAT,CAA4BC,gBAA5B,EAA8CC,SAA9C,EAA0D;AAChE,MAAK,CAAED,gBAAF,IAAsB,CAAEC,SAA7B,EAAyC;AACxC,WAAOC,SAAP;AACA;;AAED,SAAQ,OAAO,uBAAWD,SAAX,CAAwB,IAAID,gBAAkB,EAA7D;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASG,oBAAT,CAA+BZ,MAA/B,EAAuCO,UAAvC,EAAoD;AAC1D,QAAMM,WAAW,GAAG,oBAAQN,UAAR,CAApB;AACA,SAAO,mBAAOP,MAAP,EAAe;AAAA,QAAE;AAAEK,MAAAA;AAAF,KAAF;AAAA,WAAiBQ,WAAW,CAACC,QAAZ,CAAsBT,KAAtB,CAAjB;AAAA,GAAf,EACLA,KADF;AAEA","sourcesContent":["/**\n * External dependencies\n */\nimport { find, kebabCase, maxBy } from 'lodash';\nimport { colord, extend } from 'colord';\nimport namesPlugin from 'colord/plugins/names';\nimport a11yPlugin from 'colord/plugins/a11y';\n\nextend( [ namesPlugin, a11yPlugin ] );\n\n/**\n * Provided an array of color objects as set by the theme or by the editor defaults,\n * and the values of the defined color or custom color returns a color object describing the color.\n *\n * @param {Array} colors Array of color objects as set by the theme or by the editor defaults.\n * @param {?string} definedColor A string containing the color slug.\n * @param {?string} customColor A string containing the customColor value.\n *\n * @return {?Object} If definedColor is passed and the name is found in colors,\n * the color object exactly as set by the theme or editor defaults is returned.\n * Otherwise, an object that just sets the color is defined.\n */\nexport const getColorObjectByAttributeValues = (\n\tcolors,\n\tdefinedColor,\n\tcustomColor\n) => {\n\tif ( definedColor ) {\n\t\tconst colorObj = find( colors, { slug: definedColor } );\n\n\t\tif ( colorObj ) {\n\t\t\treturn colorObj;\n\t\t}\n\t}\n\treturn {\n\t\tcolor: customColor,\n\t};\n};\n\n/**\n * Provided an array of color objects as set by the theme or by the editor defaults, and a color value returns the color object matching that value or undefined.\n *\n * @param {Array} colors Array of color objects as set by the theme or by the editor defaults.\n * @param {?string} colorValue A string containing the color value.\n *\n * @return {?Object} Color object included in the colors array whose color property equals colorValue.\n * Returns undefined if no color object matches this requirement.\n */\nexport const getColorObjectByColorValue = ( colors, colorValue ) => {\n\treturn find( colors, { color: colorValue } );\n};\n\n/**\n * Returns a class based on the context a color is being used and its slug.\n *\n * @param {string} colorContextName Context/place where color is being used e.g: background, text etc...\n * @param {string} colorSlug Slug of the color.\n *\n * @return {?string} String with the class corresponding to the color in the provided context.\n * Returns undefined if either colorContextName or colorSlug are not provided.\n */\nexport function getColorClassName( colorContextName, colorSlug ) {\n\tif ( ! colorContextName || ! colorSlug ) {\n\t\treturn undefined;\n\t}\n\n\treturn `has-${ kebabCase( colorSlug ) }-${ colorContextName }`;\n}\n\n/**\n * Given an array of color objects and a color value returns the color value of the most readable color in the array.\n *\n * @param {Array} colors Array of color objects as set by the theme or by the editor defaults.\n * @param {?string} colorValue A string containing the color value.\n *\n * @return {string} String with the color value of the most readable color.\n */\nexport function getMostReadableColor( colors, colorValue ) {\n\tconst colordColor = colord( colorValue );\n\treturn maxBy( colors, ( { color } ) => colordColor.contrast( color ) )\n\t\t.color;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/colors/utils.js"],"names":["namesPlugin","a11yPlugin","getColorObjectByAttributeValues","colors","definedColor","customColor","colorObj","slug","color","getColorObjectByColorValue","colorValue","getColorClassName","colorContextName","colorSlug","undefined","getMostReadableColor","colordColor","getColorContrast","contrast","maxContrast","Math","max","map","find"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AANA;AACA;AACA;AAMA,oBAAQ,CAAEA,cAAF,EAAeC,aAAf,CAAR;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,MAAMC,+BAA+B,GAAG,CAC9CC,MAD8C,EAE9CC,YAF8C,EAG9CC,WAH8C,KAI1C;AACJ,MAAKD,YAAL,EAAoB;AACnB,UAAME,QAAQ,GAAG,kBAAMH,MAAN,EAAc;AAAEI,MAAAA,IAAI,EAAEH;AAAR,KAAd,CAAjB;;AAEA,QAAKE,QAAL,EAAgB;AACf,aAAOA,QAAP;AACA;AACD;;AACD,SAAO;AACNE,IAAAA,KAAK,EAAEH;AADD,GAAP;AAGA,CAfM;AAiBP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAMI,0BAA0B,GAAG,CAAEN,MAAF,EAAUO,UAAV,KAA0B;AACnE,SAAO,kBAAMP,MAAN,EAAc;AAAEK,IAAAA,KAAK,EAAEE;AAAT,GAAd,CAAP;AACA,CAFM;AAIP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,SAASC,iBAAT,CAA4BC,gBAA5B,EAA8CC,SAA9C,EAA0D;AAChE,MAAK,CAAED,gBAAF,IAAsB,CAAEC,SAA7B,EAAyC;AACxC,WAAOC,SAAP;AACA;;AAED,SAAQ,OAAO,uBAAWD,SAAX,CAAwB,IAAID,gBAAkB,EAA7D;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASG,oBAAT,CAA+BZ,MAA/B,EAAuCO,UAAvC,EAAoD;AAC1D,QAAMM,WAAW,GAAG,oBAAQN,UAAR,CAApB;;AACA,QAAMO,gBAAgB,GAAG;AAAA,QAAE;AAAET,MAAAA;AAAF,KAAF;AAAA,WAAiBQ,WAAW,CAACE,QAAZ,CAAsBV,KAAtB,CAAjB;AAAA,GAAzB;;AAEA,QAAMW,WAAW,GAAGC,IAAI,CAACC,GAAL,CAAU,GAAGlB,MAAM,CAACmB,GAAP,CAAYL,gBAAZ,CAAb,CAApB;AACA,SAAOd,MAAM,CAACoB,IAAP,CAAef,KAAF,IAAaS,gBAAgB,CAAET,KAAF,CAAhB,KAA8BW,WAAxD,EACLX,KADF;AAEA","sourcesContent":["/**\n * External dependencies\n */\nimport { find, kebabCase } from 'lodash';\nimport { colord, extend } from 'colord';\nimport namesPlugin from 'colord/plugins/names';\nimport a11yPlugin from 'colord/plugins/a11y';\n\nextend( [ namesPlugin, a11yPlugin ] );\n\n/**\n * Provided an array of color objects as set by the theme or by the editor defaults,\n * and the values of the defined color or custom color returns a color object describing the color.\n *\n * @param {Array} colors Array of color objects as set by the theme or by the editor defaults.\n * @param {?string} definedColor A string containing the color slug.\n * @param {?string} customColor A string containing the customColor value.\n *\n * @return {?Object} If definedColor is passed and the name is found in colors,\n * the color object exactly as set by the theme or editor defaults is returned.\n * Otherwise, an object that just sets the color is defined.\n */\nexport const getColorObjectByAttributeValues = (\n\tcolors,\n\tdefinedColor,\n\tcustomColor\n) => {\n\tif ( definedColor ) {\n\t\tconst colorObj = find( colors, { slug: definedColor } );\n\n\t\tif ( colorObj ) {\n\t\t\treturn colorObj;\n\t\t}\n\t}\n\treturn {\n\t\tcolor: customColor,\n\t};\n};\n\n/**\n * Provided an array of color objects as set by the theme or by the editor defaults, and a color value returns the color object matching that value or undefined.\n *\n * @param {Array} colors Array of color objects as set by the theme or by the editor defaults.\n * @param {?string} colorValue A string containing the color value.\n *\n * @return {?Object} Color object included in the colors array whose color property equals colorValue.\n * Returns undefined if no color object matches this requirement.\n */\nexport const getColorObjectByColorValue = ( colors, colorValue ) => {\n\treturn find( colors, { color: colorValue } );\n};\n\n/**\n * Returns a class based on the context a color is being used and its slug.\n *\n * @param {string} colorContextName Context/place where color is being used e.g: background, text etc...\n * @param {string} colorSlug Slug of the color.\n *\n * @return {?string} String with the class corresponding to the color in the provided context.\n * Returns undefined if either colorContextName or colorSlug are not provided.\n */\nexport function getColorClassName( colorContextName, colorSlug ) {\n\tif ( ! colorContextName || ! colorSlug ) {\n\t\treturn undefined;\n\t}\n\n\treturn `has-${ kebabCase( colorSlug ) }-${ colorContextName }`;\n}\n\n/**\n * Given an array of color objects and a color value returns the color value of the most readable color in the array.\n *\n * @param {Array} colors Array of color objects as set by the theme or by the editor defaults.\n * @param {?string} colorValue A string containing the color value.\n *\n * @return {string} String with the color value of the most readable color.\n */\nexport function getMostReadableColor( colors, colorValue ) {\n\tconst colordColor = colord( colorValue );\n\tconst getColorContrast = ( { color } ) => colordColor.contrast( color );\n\n\tconst maxContrast = Math.max( ...colors.map( getColorContrast ) );\n\treturn colors.find( ( color ) => getColorContrast( color ) === maxContrast )\n\t\t.color;\n}\n"]}
@@ -32,6 +32,17 @@ var _useSetting = _interopRequireDefault(require("../use-setting"));
32
32
  * Internal dependencies
33
33
  */
34
34
 
35
+ /**
36
+ * Capitalizes the first letter in a string.
37
+ *
38
+ * @param {string} str The string whose first letter the function will capitalize.
39
+ *
40
+ * @return {string} Capitalized string.
41
+ */
42
+ const upperFirst = _ref => {
43
+ let [firstLetter, ...rest] = _ref;
44
+ return firstLetter.toUpperCase() + rest.join('');
45
+ };
35
46
  /**
36
47
  * Higher order component factory for injecting the `colorsArray` argument as
37
48
  * the colors prop in the `withCustomColors` HOC.
@@ -40,6 +51,8 @@ var _useSetting = _interopRequireDefault(require("../use-setting"));
40
51
  *
41
52
  * @return {Function} The higher order component.
42
53
  */
54
+
55
+
43
56
  const withCustomColorPalette = colorsArray => (0, _compose.createHigherOrderComponent)(WrappedComponent => props => (0, _element.createElement)(WrappedComponent, (0, _extends2.default)({}, props, {
44
57
  colors: colorsArray
45
58
  })), 'withCustomColorPalette');
@@ -102,7 +115,7 @@ function createColorHOC(colorTypes, withColorPalette) {
102
115
 
103
116
  createSetters() {
104
117
  return (0, _lodash.reduce)(colorMap, (settersAccumulator, colorContext, colorAttributeName) => {
105
- const upperFirstColorAttributeName = (0, _lodash.upperFirst)(colorAttributeName);
118
+ const upperFirstColorAttributeName = upperFirst(colorAttributeName);
106
119
  const customColorAttributeName = `custom${upperFirstColorAttributeName}`;
107
120
  settersAccumulator[`set${upperFirstColorAttributeName}`] = this.createSetColor(colorAttributeName, customColorAttributeName);
108
121
  return settersAccumulator;
@@ -119,13 +132,13 @@ function createColorHOC(colorTypes, withColorPalette) {
119
132
  };
120
133
  }
121
134
 
122
- static getDerivedStateFromProps(_ref, previousState) {
135
+ static getDerivedStateFromProps(_ref2, previousState) {
123
136
  let {
124
137
  attributes,
125
138
  colors
126
- } = _ref;
139
+ } = _ref2;
127
140
  return (0, _lodash.reduce)(colorMap, (newState, colorContext, colorAttributeName) => {
128
- const colorObject = (0, _utils.getColorObjectByAttributeValues)(colors, attributes[colorAttributeName], attributes[`custom${(0, _lodash.upperFirst)(colorAttributeName)}`]);
141
+ const colorObject = (0, _utils.getColorObjectByAttributeValues)(colors, attributes[colorAttributeName], attributes[`custom${upperFirst(colorAttributeName)}`]);
129
142
  const previousColorObject = previousState[colorAttributeName];
130
143
  const previousColor = previousColorObject === null || previousColorObject === void 0 ? void 0 : previousColorObject.color;
131
144
  /**