@wordpress/block-editor 16.2.0 → 17.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (328) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/build/components/block-inspector/index.cjs +9 -6
  3. package/build/components/block-inspector/index.cjs.map +2 -2
  4. package/build/components/block-keyboard-shortcuts/index.cjs +201 -0
  5. package/build/components/block-keyboard-shortcuts/index.cjs.map +7 -0
  6. package/build/components/block-list/block.cjs +10 -3
  7. package/build/components/block-list/block.cjs.map +2 -2
  8. package/build/components/block-list/index.cjs +6 -1
  9. package/build/components/block-list/index.cjs.map +2 -2
  10. package/build/components/block-list/use-block-props/use-focus-first-element.cjs +4 -0
  11. package/build/components/block-list/use-block-props/use-focus-first-element.cjs.map +2 -2
  12. package/build/components/block-list/use-block-props/use-selected-block-event-handlers.cjs +6 -7
  13. package/build/components/block-list/use-block-props/use-selected-block-event-handlers.cjs.map +2 -2
  14. package/build/components/block-parent-selector/index.cjs +98 -29
  15. package/build/components/block-parent-selector/index.cjs.map +3 -3
  16. package/build/components/block-popover/inbetween.cjs +2 -2
  17. package/build/components/block-popover/inbetween.cjs.map +2 -2
  18. package/build/components/block-preview/index.cjs +0 -4
  19. package/build/components/block-preview/index.cjs.map +2 -2
  20. package/build/components/block-styles/index.cjs +77 -33
  21. package/build/components/block-styles/index.cjs.map +3 -3
  22. package/build/components/block-visibility/constants.cjs.map +2 -2
  23. package/build/components/child-layout-control/index.cjs.map +2 -2
  24. package/build/components/colors/with-colors.cjs +55 -71
  25. package/build/components/colors/with-colors.cjs.map +2 -2
  26. package/build/components/dimensions-tool/aspect-ratio-tool.cjs +4 -2
  27. package/build/components/dimensions-tool/aspect-ratio-tool.cjs.map +2 -2
  28. package/build/components/dimensions-tool/index.cjs +18 -16
  29. package/build/components/dimensions-tool/index.cjs.map +2 -2
  30. package/build/components/dimensions-tool/utils.cjs +61 -0
  31. package/build/components/dimensions-tool/utils.cjs.map +7 -0
  32. package/build/components/duotone-control/index.cjs +2 -0
  33. package/build/components/duotone-control/index.cjs.map +2 -2
  34. package/build/components/global-styles/advanced-panel.cjs.map +3 -3
  35. package/build/components/global-styles/border-panel.cjs +2 -5
  36. package/build/components/global-styles/border-panel.cjs.map +2 -2
  37. package/build/components/global-styles/color-panel.cjs +14 -2
  38. package/build/components/global-styles/color-panel.cjs.map +2 -2
  39. package/build/components/global-styles/dimensions-panel.cjs +9 -5
  40. package/build/components/global-styles/dimensions-panel.cjs.map +2 -2
  41. package/build/components/global-styles/filters-panel.cjs +12 -8
  42. package/build/components/global-styles/filters-panel.cjs.map +2 -2
  43. package/build/components/global-styles/shadow-panel-components.cjs +16 -11
  44. package/build/components/global-styles/shadow-panel-components.cjs.map +2 -2
  45. package/build/components/global-styles/utils.cjs +9 -0
  46. package/build/components/global-styles/utils.cjs.map +2 -2
  47. package/build/components/inner-blocks/index.cjs +5 -3
  48. package/build/components/inner-blocks/index.cjs.map +2 -2
  49. package/build/components/inserter/block-patterns-explorer/index.cjs +39 -22
  50. package/build/components/inserter/block-patterns-explorer/index.cjs.map +2 -2
  51. package/build/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.cjs +21 -55
  52. package/build/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.cjs.map +2 -2
  53. package/build/components/inserter/block-patterns-explorer/pattern-list.cjs +19 -44
  54. package/build/components/inserter/block-patterns-explorer/pattern-list.cjs.map +3 -3
  55. package/build/components/inserter/hooks/use-insertion-point.cjs +4 -4
  56. package/build/components/inserter/hooks/use-insertion-point.cjs.map +2 -2
  57. package/build/components/inserter/menu.cjs +18 -7
  58. package/build/components/inserter/menu.cjs.map +2 -2
  59. package/build/components/inserter/quick-inserter.cjs +30 -27
  60. package/build/components/inserter/quick-inserter.cjs.map +2 -2
  61. package/build/components/inspector-controls-tabs/styles-tab.cjs +1 -1
  62. package/build/components/inspector-controls-tabs/styles-tab.cjs.map +2 -2
  63. package/build/components/list-view/index.cjs +31 -5
  64. package/build/components/list-view/index.cjs.map +3 -3
  65. package/build/components/list-view/utils.cjs +13 -1
  66. package/build/components/list-view/utils.cjs.map +2 -2
  67. package/build/components/media-placeholder/index.cjs +1 -1
  68. package/build/components/media-placeholder/index.cjs.map +3 -3
  69. package/build/components/provider/index.cjs +5 -1
  70. package/build/components/provider/index.cjs.map +3 -3
  71. package/build/components/publish-date-time-picker/index.cjs +3 -2
  72. package/build/components/publish-date-time-picker/index.cjs.map +2 -2
  73. package/build/components/rich-text/event-listeners/enter.cjs +46 -39
  74. package/build/components/rich-text/event-listeners/enter.cjs.map +2 -2
  75. package/build/components/rich-text/index.cjs +7 -5
  76. package/build/components/rich-text/index.cjs.map +2 -2
  77. package/build/components/rich-text/multiline.cjs +105 -70
  78. package/build/components/rich-text/multiline.cjs.map +3 -3
  79. package/build/components/url-input/index.cjs.map +2 -2
  80. package/build/components/writing-flow/use-input.cjs +65 -13
  81. package/build/components/writing-flow/use-input.cjs.map +3 -3
  82. package/build/hooks/border.cjs +25 -3
  83. package/build/hooks/border.cjs.map +2 -2
  84. package/build/hooks/dimensions.cjs +9 -2
  85. package/build/hooks/dimensions.cjs.map +2 -2
  86. package/build/hooks/duotone.cjs +4 -3
  87. package/build/hooks/duotone.cjs.map +2 -2
  88. package/build/hooks/gap.cjs +8 -2
  89. package/build/hooks/gap.cjs.map +2 -2
  90. package/build/hooks/layout-child.cjs +35 -13
  91. package/build/hooks/layout-child.cjs.map +2 -2
  92. package/build/hooks/layout.cjs +23 -1
  93. package/build/hooks/layout.cjs.map +2 -2
  94. package/build/hooks/states.cjs +7 -4
  95. package/build/hooks/states.cjs.map +2 -2
  96. package/build/layouts/constrained.cjs +8 -1
  97. package/build/layouts/constrained.cjs.map +2 -2
  98. package/build/layouts/flex.cjs +9 -0
  99. package/build/layouts/flex.cjs.map +2 -2
  100. package/build/layouts/flow.cjs +4 -1
  101. package/build/layouts/flow.cjs.map +2 -2
  102. package/build/layouts/grid.cjs +5 -1
  103. package/build/layouts/grid.cjs.map +2 -2
  104. package/build/private-apis.cjs +3 -1
  105. package/build/private-apis.cjs.map +2 -2
  106. package/build/store/actions.cjs +1 -1
  107. package/build/store/actions.cjs.map +2 -2
  108. package/build-module/components/block-inspector/index.mjs +9 -6
  109. package/build-module/components/block-inspector/index.mjs.map +2 -2
  110. package/build-module/components/block-keyboard-shortcuts/index.mjs +173 -0
  111. package/build-module/components/block-keyboard-shortcuts/index.mjs.map +7 -0
  112. package/build-module/components/block-list/block.mjs +10 -3
  113. package/build-module/components/block-list/block.mjs.map +2 -2
  114. package/build-module/components/block-list/index.mjs +6 -1
  115. package/build-module/components/block-list/index.mjs.map +2 -2
  116. package/build-module/components/block-list/use-block-props/use-focus-first-element.mjs +4 -0
  117. package/build-module/components/block-list/use-block-props/use-focus-first-element.mjs.map +2 -2
  118. package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.mjs +6 -7
  119. package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.mjs.map +2 -2
  120. package/build-module/components/block-parent-selector/index.mjs +101 -32
  121. package/build-module/components/block-parent-selector/index.mjs.map +2 -2
  122. package/build-module/components/block-popover/inbetween.mjs +2 -2
  123. package/build-module/components/block-popover/inbetween.mjs.map +2 -2
  124. package/build-module/components/block-preview/index.mjs +0 -4
  125. package/build-module/components/block-preview/index.mjs.map +2 -2
  126. package/build-module/components/block-styles/index.mjs +79 -35
  127. package/build-module/components/block-styles/index.mjs.map +2 -2
  128. package/build-module/components/block-visibility/constants.mjs.map +2 -2
  129. package/build-module/components/child-layout-control/index.mjs +5 -5
  130. package/build-module/components/child-layout-control/index.mjs.map +1 -1
  131. package/build-module/components/colors/with-colors.mjs +56 -72
  132. package/build-module/components/colors/with-colors.mjs.map +2 -2
  133. package/build-module/components/dimensions-tool/aspect-ratio-tool.mjs +4 -2
  134. package/build-module/components/dimensions-tool/aspect-ratio-tool.mjs.map +2 -2
  135. package/build-module/components/dimensions-tool/index.mjs +19 -17
  136. package/build-module/components/dimensions-tool/index.mjs.map +2 -2
  137. package/build-module/components/dimensions-tool/utils.mjs +35 -0
  138. package/build-module/components/dimensions-tool/utils.mjs.map +7 -0
  139. package/build-module/components/duotone-control/index.mjs +2 -0
  140. package/build-module/components/duotone-control/index.mjs.map +2 -2
  141. package/build-module/components/global-styles/advanced-panel.mjs +5 -2
  142. package/build-module/components/global-styles/advanced-panel.mjs.map +2 -2
  143. package/build-module/components/global-styles/border-panel.mjs +2 -5
  144. package/build-module/components/global-styles/border-panel.mjs.map +2 -2
  145. package/build-module/components/global-styles/color-panel.mjs +14 -2
  146. package/build-module/components/global-styles/color-panel.mjs.map +2 -2
  147. package/build-module/components/global-styles/dimensions-panel.mjs +9 -5
  148. package/build-module/components/global-styles/dimensions-panel.mjs.map +2 -2
  149. package/build-module/components/global-styles/filters-panel.mjs +16 -9
  150. package/build-module/components/global-styles/filters-panel.mjs.map +2 -2
  151. package/build-module/components/global-styles/shadow-panel-components.mjs +16 -11
  152. package/build-module/components/global-styles/shadow-panel-components.mjs.map +2 -2
  153. package/build-module/components/global-styles/utils.mjs +8 -0
  154. package/build-module/components/global-styles/utils.mjs.map +2 -2
  155. package/build-module/components/inner-blocks/index.mjs +5 -3
  156. package/build-module/components/inner-blocks/index.mjs.map +2 -2
  157. package/build-module/components/inserter/block-patterns-explorer/index.mjs +39 -22
  158. package/build-module/components/inserter/block-patterns-explorer/index.mjs.map +2 -2
  159. package/build-module/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.mjs +22 -56
  160. package/build-module/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.mjs.map +2 -2
  161. package/build-module/components/inserter/block-patterns-explorer/pattern-list.mjs +20 -45
  162. package/build-module/components/inserter/block-patterns-explorer/pattern-list.mjs.map +2 -2
  163. package/build-module/components/inserter/hooks/use-insertion-point.mjs +4 -4
  164. package/build-module/components/inserter/hooks/use-insertion-point.mjs.map +2 -2
  165. package/build-module/components/inserter/menu.mjs +19 -8
  166. package/build-module/components/inserter/menu.mjs.map +2 -2
  167. package/build-module/components/inserter/quick-inserter.mjs +30 -27
  168. package/build-module/components/inserter/quick-inserter.mjs.map +2 -2
  169. package/build-module/components/inspector-controls-tabs/styles-tab.mjs +1 -1
  170. package/build-module/components/inspector-controls-tabs/styles-tab.mjs.map +2 -2
  171. package/build-module/components/list-view/index.mjs +32 -5
  172. package/build-module/components/list-view/index.mjs.map +3 -3
  173. package/build-module/components/list-view/utils.mjs +13 -1
  174. package/build-module/components/list-view/utils.mjs.map +2 -2
  175. package/build-module/components/media-placeholder/index.mjs +3 -3
  176. package/build-module/components/media-placeholder/index.mjs.map +2 -2
  177. package/build-module/components/provider/index.mjs +6 -2
  178. package/build-module/components/provider/index.mjs.map +2 -2
  179. package/build-module/components/publish-date-time-picker/index.mjs +3 -2
  180. package/build-module/components/publish-date-time-picker/index.mjs.map +2 -2
  181. package/build-module/components/rich-text/event-listeners/enter.mjs +46 -39
  182. package/build-module/components/rich-text/event-listeners/enter.mjs.map +2 -2
  183. package/build-module/components/rich-text/index.mjs +7 -5
  184. package/build-module/components/rich-text/index.mjs.map +2 -2
  185. package/build-module/components/rich-text/multiline.mjs +112 -72
  186. package/build-module/components/rich-text/multiline.mjs.map +2 -2
  187. package/build-module/components/url-input/index.mjs +2 -2
  188. package/build-module/components/url-input/index.mjs.map +1 -1
  189. package/build-module/components/writing-flow/use-input.mjs +66 -14
  190. package/build-module/components/writing-flow/use-input.mjs.map +3 -3
  191. package/build-module/hooks/border.mjs +26 -8
  192. package/build-module/hooks/border.mjs.map +2 -2
  193. package/build-module/hooks/dimensions.mjs +9 -2
  194. package/build-module/hooks/dimensions.mjs.map +2 -2
  195. package/build-module/hooks/duotone.mjs +8 -4
  196. package/build-module/hooks/duotone.mjs.map +2 -2
  197. package/build-module/hooks/gap.mjs +6 -1
  198. package/build-module/hooks/gap.mjs.map +2 -2
  199. package/build-module/hooks/layout-child.mjs +36 -13
  200. package/build-module/hooks/layout-child.mjs.map +2 -2
  201. package/build-module/hooks/layout.mjs +22 -1
  202. package/build-module/hooks/layout.mjs.map +2 -2
  203. package/build-module/hooks/states.mjs +8 -5
  204. package/build-module/hooks/states.mjs.map +2 -2
  205. package/build-module/layouts/constrained.mjs +8 -1
  206. package/build-module/layouts/constrained.mjs.map +2 -2
  207. package/build-module/layouts/flex.mjs +9 -0
  208. package/build-module/layouts/flex.mjs.map +2 -2
  209. package/build-module/layouts/flow.mjs +4 -1
  210. package/build-module/layouts/flow.mjs.map +2 -2
  211. package/build-module/layouts/grid.mjs +5 -1
  212. package/build-module/layouts/grid.mjs.map +2 -2
  213. package/build-module/private-apis.mjs +3 -1
  214. package/build-module/private-apis.mjs.map +2 -2
  215. package/build-module/store/actions.mjs +1 -1
  216. package/build-module/store/actions.mjs.map +2 -2
  217. package/build-style/style-rtl.css +108 -71
  218. package/build-style/style.css +108 -71
  219. package/build-types/components/block-visibility/constants.d.ts +4 -3
  220. package/build-types/components/block-visibility/constants.d.ts.map +1 -1
  221. package/package.json +43 -43
  222. package/src/components/background-image-control/README.md +122 -0
  223. package/src/components/block-edit-visually-button/README.md +39 -0
  224. package/src/components/block-editing-mode/README.md +72 -0
  225. package/src/components/block-inspector/index.js +6 -6
  226. package/src/components/block-keyboard-shortcuts/index.js +256 -0
  227. package/src/components/block-list/block.js +7 -0
  228. package/src/components/block-list/index.js +7 -1
  229. package/src/components/block-list/use-block-props/use-focus-first-element.js +5 -0
  230. package/src/components/block-list/use-block-props/use-selected-block-event-handlers.js +6 -8
  231. package/src/components/block-parent-selector/index.js +111 -30
  232. package/src/components/block-popover/README.md +10 -3
  233. package/src/components/block-popover/inbetween.js +8 -2
  234. package/src/components/block-popover/stories/index.story.jsx +143 -0
  235. package/src/components/block-preview/index.js +0 -2
  236. package/src/components/block-styles/index.js +95 -43
  237. package/src/components/block-styles/style.scss +5 -34
  238. package/src/components/block-tools/style.scss +94 -0
  239. package/src/components/block-visibility/constants.ts +4 -3
  240. package/src/components/child-layout-control/index.js +5 -5
  241. package/src/components/color-palette/test/__snapshots__/control.js.snap +3 -29
  242. package/src/components/colors/test/with-colors.js +6 -7
  243. package/src/components/colors/with-colors.js +79 -105
  244. package/src/components/dimensions-tool/aspect-ratio-tool.js +16 -4
  245. package/src/components/dimensions-tool/index.js +34 -22
  246. package/src/components/dimensions-tool/test/index.js +166 -2
  247. package/src/components/dimensions-tool/test/utils.js +51 -0
  248. package/src/components/dimensions-tool/utils.js +67 -0
  249. package/src/components/duotone-control/index.js +2 -0
  250. package/src/components/duotone-control/test/index.js +100 -0
  251. package/src/components/global-styles/advanced-panel.js +5 -2
  252. package/src/components/global-styles/border-panel.js +11 -9
  253. package/src/components/global-styles/color-panel.js +13 -1
  254. package/src/components/global-styles/dimensions-panel.js +17 -5
  255. package/src/components/global-styles/filters-panel.js +24 -10
  256. package/src/components/global-styles/shadow-panel-components.js +38 -11
  257. package/src/components/global-styles/test/border-panel.js +230 -0
  258. package/src/components/global-styles/test/color-panel.js +24 -0
  259. package/src/components/global-styles/test/dimensions-panel.js +98 -7
  260. package/src/components/global-styles/test/filters-panel.js +84 -0
  261. package/src/components/global-styles/test/utils.js +30 -0
  262. package/src/components/global-styles/utils.js +23 -0
  263. package/src/components/inner-blocks/index.js +11 -2
  264. package/src/components/inner-blocks/stories/index.story.jsx +246 -0
  265. package/src/components/inserter/block-patterns-explorer/index.js +24 -11
  266. package/src/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.js +18 -56
  267. package/src/components/inserter/block-patterns-explorer/pattern-list.js +22 -47
  268. package/src/components/inserter/hooks/use-insertion-point.js +9 -4
  269. package/src/components/inserter/menu.js +23 -10
  270. package/src/components/inserter/quick-inserter.js +15 -13
  271. package/src/components/inserter/style.scss +44 -62
  272. package/src/components/inspector-controls-tabs/README.md +92 -0
  273. package/src/components/inspector-controls-tabs/styles-tab.js +1 -1
  274. package/src/components/link-control/test/index.js +5 -0
  275. package/src/components/list-view/index.js +50 -7
  276. package/src/components/list-view/utils.js +16 -1
  277. package/src/components/media-placeholder/index.js +9 -4
  278. package/src/components/plain-text/stories/index.story.jsx +3 -0
  279. package/src/components/provider/index.js +7 -1
  280. package/src/components/publish-date-time-picker/README.md +10 -0
  281. package/src/components/publish-date-time-picker/index.js +17 -14
  282. package/src/components/rich-text/event-listeners/enter.js +58 -45
  283. package/src/components/rich-text/index.js +9 -4
  284. package/src/components/rich-text/multiline.js +126 -86
  285. package/src/components/url-input/index.js +2 -2
  286. package/src/components/url-input/test/fixtures/validated-input-control-deprecation.js +27 -0
  287. package/src/components/url-input/test/index.js +5 -0
  288. package/src/components/url-popover/README.md +7 -0
  289. package/src/components/url-popover/stories/index.story.jsx +133 -47
  290. package/src/components/writing-flow/use-input.js +105 -15
  291. package/src/hooks/border.js +27 -8
  292. package/src/hooks/dimensions.js +8 -1
  293. package/src/hooks/duotone.js +23 -7
  294. package/src/hooks/gap.js +16 -0
  295. package/src/hooks/layout-child.js +41 -9
  296. package/src/hooks/layout.js +117 -71
  297. package/src/hooks/states.js +8 -5
  298. package/src/hooks/test/gap.js +31 -1
  299. package/src/hooks/test/layout-child.js +60 -1
  300. package/src/hooks/test/layout.js +27 -0
  301. package/src/layouts/constrained.js +9 -1
  302. package/src/layouts/flex.js +15 -0
  303. package/src/layouts/flow.js +4 -1
  304. package/src/layouts/grid.js +9 -1
  305. package/src/layouts/test/constrained.js +26 -0
  306. package/src/layouts/test/flow.js +26 -0
  307. package/src/layouts/test/grid.js +46 -0
  308. package/src/private-apis.js +2 -0
  309. package/src/store/actions.js +14 -1
  310. package/build/components/floating-toolbar/nav-up-icon.cjs +0 -52
  311. package/build/components/floating-toolbar/nav-up-icon.cjs.map +0 -7
  312. package/build/components/gradients/with-gradient.cjs +0 -36
  313. package/build/components/gradients/with-gradient.cjs.map +0 -7
  314. package/build/components/inserter-button/sparkles.cjs +0 -36
  315. package/build/components/inserter-button/sparkles.cjs.map +0 -7
  316. package/build-module/components/floating-toolbar/nav-up-icon.mjs +0 -31
  317. package/build-module/components/floating-toolbar/nav-up-icon.mjs.map +0 -7
  318. package/build-module/components/gradients/with-gradient.mjs +0 -11
  319. package/build-module/components/gradients/with-gradient.mjs.map +0 -7
  320. package/build-module/components/inserter-button/sparkles.mjs +0 -15
  321. package/build-module/components/inserter-button/sparkles.mjs.map +0 -7
  322. package/build-style/default-editor-styles-rtl.css +0 -68
  323. package/build-style/default-editor-styles.css +0 -68
  324. package/src/components/floating-toolbar/nav-up-icon.js +0 -22
  325. package/src/components/gradients/with-gradient.js +0 -9
  326. package/src/components/inserter-button/README.md +0 -62
  327. package/src/components/inserter-button/sparkles.js +0 -12
  328. package/src/default-editor-styles.scss +0 -25
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/child-layout-control/index.js"],
4
- "sourcesContent": ["import {\n\t__experimentalToggleGroupControl as ToggleGroupControl,\n\t__experimentalToggleGroupControlOption as ToggleGroupControlOption,\n\t__experimentalUnitControl as UnitControl,\n\t__experimentalInputControl as InputControl,\n\t__experimentalVStack as VStack,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n\t__experimentalUseCustomUnits as useCustomUnits,\n\tFlex,\n\tFlexItem,\n} from '@wordpress/components';\nimport { __, _x } from '@wordpress/i18n';\nimport { useEffect } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useGetNumberOfBlocksBeforeCell } from '../grid/use-get-number-of-blocks-before-cell';\nimport { store as blockEditorStore } from '../../store';\nimport { useSettings } from '../use-settings';\n\n// These are the serialized `selfStretch` values. `max` used to be called\n// \"Fixed\" in the UI, but was renamed and replaced by `fixedNoShrink`.\nconst FLEX_CHILD_LAYOUT_VALUES = {\n\tfit: 'fit',\n\tgrow: 'fill',\n\tmax: 'fixed',\n\tfixed: 'fixedNoShrink',\n};\n\nconst FLEX_SIZE_VALUES = [\n\tFLEX_CHILD_LAYOUT_VALUES.max,\n\tFLEX_CHILD_LAYOUT_VALUES.fixed,\n];\n\nfunction isFlexSizeValue( value ) {\n\treturn FLEX_SIZE_VALUES.includes( value );\n}\n\nfunction maxSizeLabel( parentLayout ) {\n\tconst { orientation = 'horizontal' } = parentLayout ?? {};\n\treturn orientation === 'horizontal'\n\t\t? _x( 'Max', 'Block with maximum width in flex layout' )\n\t\t: _x( 'Max', 'Block with maximum height in flex layout' );\n}\n\nfunction helpText( flexControlValue, parentLayout ) {\n\tconst { orientation = 'horizontal' } = parentLayout ?? {};\n\n\tif ( flexControlValue === FLEX_CHILD_LAYOUT_VALUES.grow ) {\n\t\treturn __( 'Stretch to fill available space.' );\n\t}\n\tif (\n\t\tflexControlValue === FLEX_CHILD_LAYOUT_VALUES.max &&\n\t\torientation === 'horizontal'\n\t) {\n\t\treturn __( 'Specify a maximum width.' );\n\t} else if ( flexControlValue === FLEX_CHILD_LAYOUT_VALUES.max ) {\n\t\treturn __( 'Specify a maximum height.' );\n\t}\n\tif (\n\t\tflexControlValue === FLEX_CHILD_LAYOUT_VALUES.fixed &&\n\t\torientation === 'horizontal'\n\t) {\n\t\treturn __( 'Specify a fixed width.' );\n\t} else if ( flexControlValue === FLEX_CHILD_LAYOUT_VALUES.fixed ) {\n\t\treturn __( 'Specify a fixed height.' );\n\t}\n\treturn __( 'Fit contents.' );\n}\n\n/**\n * Form to edit the child layout value.\n *\n * @param {Object} props Props.\n * @param {Object} props.value The child layout value.\n * @param {Function} props.onChange Function to update the child layout value.\n * @param {Object} props.parentLayout The parent layout value.\n *\n * @param {boolean} props.isShownByDefault Whether the control is shown by default.\n * @param {string} props.panelId The panel ID.\n * @param {boolean} props.showGridSpanDefaults Whether unset grid span controls should show default values.\n * @return {Element} child layout edit element.\n */\nexport default function ChildLayoutControl( {\n\tvalue: childLayout = {},\n\tonChange,\n\tparentLayout,\n\tisShownByDefault,\n\tpanelId,\n\tshowGridSpanDefaults = true,\n} ) {\n\tconst {\n\t\ttype: parentType,\n\t\tdefault: { type: defaultParentType = 'default' } = {},\n\t} = parentLayout ?? {};\n\tconst parentLayoutType = parentType || defaultParentType;\n\n\tif ( parentLayoutType === 'flex' ) {\n\t\treturn (\n\t\t\t<FlexControls\n\t\t\t\tchildLayout={ childLayout }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tparentLayout={ parentLayout }\n\t\t\t\tisShownByDefault={ isShownByDefault }\n\t\t\t\tpanelId={ panelId }\n\t\t\t/>\n\t\t);\n\t} else if ( parentLayoutType === 'grid' ) {\n\t\treturn (\n\t\t\t<GridControls\n\t\t\t\tchildLayout={ childLayout }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tparentLayout={ parentLayout }\n\t\t\t\tisShownByDefault={ isShownByDefault }\n\t\t\t\tpanelId={ panelId }\n\t\t\t\tshowGridSpanDefaults={ showGridSpanDefaults }\n\t\t\t/>\n\t\t);\n\t}\n\n\treturn null;\n}\n\nfunction FlexControls( {\n\tchildLayout,\n\tonChange,\n\tparentLayout,\n\tisShownByDefault,\n\tpanelId,\n} ) {\n\tconst { selfStretch, flexSize } = childLayout;\n\tconst { orientation = 'horizontal' } = parentLayout ?? {};\n\tconst flexControlValue = selfStretch || FLEX_CHILD_LAYOUT_VALUES.fit;\n\tconst hasFlexSizeValue = isFlexSizeValue( flexControlValue );\n\tconst hasFlexValue = () => !! selfStretch;\n\tconst flexResetLabel =\n\t\torientation === 'horizontal' ? __( 'Width' ) : __( 'Height' );\n\tconst [ availableUnits ] = useSettings( 'spacing.units' );\n\tconst units = useCustomUnits( {\n\t\tavailableUnits: availableUnits || [\n\t\t\t'%',\n\t\t\t'px',\n\t\t\t'em',\n\t\t\t'rem',\n\t\t\t'vh',\n\t\t\t'vw',\n\t\t],\n\t} );\n\tconst resetFlex = () => {\n\t\tonChange( {\n\t\t\tselfStretch: undefined,\n\t\t\tflexSize: undefined,\n\t\t} );\n\t};\n\n\tuseEffect( () => {\n\t\tif ( isFlexSizeValue( selfStretch ) && ! flexSize ) {\n\t\t\tonChange( {\n\t\t\t\t...childLayout,\n\t\t\t\tselfStretch: FLEX_CHILD_LAYOUT_VALUES.fit,\n\t\t\t} );\n\t\t}\n\t}, [] ); // eslint-disable-line react-hooks/exhaustive-deps\n\n\treturn (\n\t\t<VStack\n\t\t\tas={ ToolsPanelItem }\n\t\t\tspacing={ 2 }\n\t\t\thasValue={ hasFlexValue }\n\t\t\tlabel={ flexResetLabel }\n\t\t\tonDeselect={ resetFlex }\n\t\t\tisShownByDefault={ isShownByDefault }\n\t\t\tpanelId={ panelId }\n\t\t>\n\t\t\t<ToggleGroupControl\n\t\t\t\tlabel={ childLayoutOrientation( parentLayout ) }\n\t\t\t\tvalue={ flexControlValue }\n\t\t\t\thelp={ helpText( flexControlValue, parentLayout ) }\n\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\tconst newFlexSize = isFlexSizeValue( value )\n\t\t\t\t\t\t? flexSize\n\t\t\t\t\t\t: null;\n\t\t\t\t\tonChange( {\n\t\t\t\t\t\tselfStretch: value,\n\t\t\t\t\t\tflexSize: newFlexSize,\n\t\t\t\t\t} );\n\t\t\t\t} }\n\t\t\t\tisBlock\n\t\t\t>\n\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\tkey={ FLEX_CHILD_LAYOUT_VALUES.fit }\n\t\t\t\t\tvalue={ FLEX_CHILD_LAYOUT_VALUES.fit }\n\t\t\t\t\tlabel={ _x(\n\t\t\t\t\t\t'Fit',\n\t\t\t\t\t\t'Intrinsic block width in flex layout'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\tkey={ FLEX_CHILD_LAYOUT_VALUES.grow }\n\t\t\t\t\tvalue={ FLEX_CHILD_LAYOUT_VALUES.grow }\n\t\t\t\t\tlabel={ _x(\n\t\t\t\t\t\t'Grow',\n\t\t\t\t\t\t'Block with expanding width in flex layout'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\tkey={ FLEX_CHILD_LAYOUT_VALUES.max }\n\t\t\t\t\tvalue={ FLEX_CHILD_LAYOUT_VALUES.max }\n\t\t\t\t\tlabel={ maxSizeLabel( parentLayout ) }\n\t\t\t\t/>\n\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\tkey={ FLEX_CHILD_LAYOUT_VALUES.fixed }\n\t\t\t\t\tvalue={ FLEX_CHILD_LAYOUT_VALUES.fixed }\n\t\t\t\t\tlabel={ _x(\n\t\t\t\t\t\t'Fixed',\n\t\t\t\t\t\t'Block with fixed width in flex layout'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</ToggleGroupControl>\n\t\t\t{ hasFlexSizeValue && (\n\t\t\t\t<UnitControl\n\t\t\t\t\tunits={ units }\n\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\tonChange( {\n\t\t\t\t\t\t\tselfStretch: flexControlValue,\n\t\t\t\t\t\t\tflexSize: value,\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\tvalue={ flexSize }\n\t\t\t\t\tmin={ 0 }\n\t\t\t\t\tlabel={ flexResetLabel }\n\t\t\t\t\thideLabelFromVision\n\t\t\t\t/>\n\t\t\t) }\n\t\t</VStack>\n\t);\n}\n\nexport function childLayoutOrientation( parentLayout ) {\n\tconst { orientation = 'horizontal' } = parentLayout ?? {};\n\treturn orientation === 'horizontal' ? __( 'Width' ) : __( 'Height' );\n}\n\nfunction GridControls( {\n\tchildLayout,\n\tonChange,\n\tparentLayout,\n\tisShownByDefault,\n\tpanelId,\n\tshowGridSpanDefaults,\n} ) {\n\tconst { columnStart, rowStart, columnSpan, rowSpan } = childLayout;\n\tconst { columnCount, rowCount } = parentLayout ?? {};\n\tconst rootClientId = useSelect( ( select ) =>\n\t\tselect( blockEditorStore ).getBlockRootClientId( panelId )\n\t);\n\tconst { moveBlocksToPosition, __unstableMarkNextChangeAsNotPersistent } =\n\t\tuseDispatch( blockEditorStore );\n\tconst getNumberOfBlocksBeforeCell = useGetNumberOfBlocksBeforeCell(\n\t\trootClientId,\n\t\tcolumnCount || 3\n\t);\n\tconst hasStartValue = () => !! columnStart || !! rowStart;\n\tconst hasSpanValue = () => !! columnSpan || !! rowSpan;\n\tconst resetGridStarts = () => {\n\t\tonChange( {\n\t\t\tcolumnStart: undefined,\n\t\t\trowStart: undefined,\n\t\t} );\n\t};\n\tconst resetGridSpans = () => {\n\t\tonChange( {\n\t\t\tcolumnSpan: undefined,\n\t\t\trowSpan: undefined,\n\t\t} );\n\t};\n\n\t// Calculate max column span based on current position and grid width\n\tconst maxColumnSpan = columnCount\n\t\t? columnCount - ( columnStart ?? 1 ) + 1\n\t\t: undefined;\n\n\t// Calculate max row span based on current position and grid height\n\tconst maxRowSpan =\n\t\twindow.__experimentalEnableGridInteractivity && rowCount\n\t\t\t? rowCount - ( rowStart ?? 1 ) + 1\n\t\t\t: undefined;\n\tconst columnSpanValue =\n\t\tcolumnSpan ?? ( showGridSpanDefaults ? 1 : undefined );\n\tconst rowSpanValue = rowSpan ?? ( showGridSpanDefaults ? 1 : undefined );\n\n\treturn (\n\t\t<>\n\t\t\t<Flex\n\t\t\t\tas={ ToolsPanelItem }\n\t\t\t\thasValue={ hasSpanValue }\n\t\t\t\tlabel={ __( 'Grid span' ) }\n\t\t\t\tonDeselect={ resetGridSpans }\n\t\t\t\tisShownByDefault={ isShownByDefault }\n\t\t\t\tpanelId={ panelId }\n\t\t\t>\n\t\t\t\t<FlexItem style={ { width: '50%' } }>\n\t\t\t\t\t<InputControl\n\t\t\t\t\t\tlabel={ __( 'Column span' ) }\n\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\t// Don't allow unsetting.\n\t\t\t\t\t\t\tconst newColumnSpan =\n\t\t\t\t\t\t\t\tvalue === '' ? 1 : parseInt( value, 10 );\n\t\t\t\t\t\t\tconst constrainedValue = maxColumnSpan\n\t\t\t\t\t\t\t\t? Math.min( newColumnSpan, maxColumnSpan )\n\t\t\t\t\t\t\t\t: newColumnSpan;\n\n\t\t\t\t\t\t\tonChange( {\n\t\t\t\t\t\t\t\tcolumnStart,\n\t\t\t\t\t\t\t\trowStart,\n\t\t\t\t\t\t\t\trowSpan,\n\t\t\t\t\t\t\t\tcolumnSpan: constrainedValue,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tvalue={ columnSpanValue }\n\t\t\t\t\t\tmin={ 1 }\n\t\t\t\t\t\tmax={ maxColumnSpan }\n\t\t\t\t\t/>\n\t\t\t\t</FlexItem>\n\t\t\t\t<FlexItem style={ { width: '50%' } }>\n\t\t\t\t\t<InputControl\n\t\t\t\t\t\tlabel={ __( 'Row span' ) }\n\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\tconst newRowSpan =\n\t\t\t\t\t\t\t\tvalue === '' ? 1 : parseInt( value, 10 );\n\t\t\t\t\t\t\tconst constrainedValue = maxRowSpan\n\t\t\t\t\t\t\t\t? Math.min( newRowSpan, maxRowSpan )\n\t\t\t\t\t\t\t\t: newRowSpan;\n\n\t\t\t\t\t\t\tonChange( {\n\t\t\t\t\t\t\t\tcolumnStart,\n\t\t\t\t\t\t\t\trowStart,\n\t\t\t\t\t\t\t\tcolumnSpan,\n\t\t\t\t\t\t\t\trowSpan: constrainedValue,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tvalue={ rowSpanValue }\n\t\t\t\t\t\tmin={ 1 }\n\t\t\t\t\t\tmax={ maxRowSpan }\n\t\t\t\t\t/>\n\t\t\t\t</FlexItem>\n\t\t\t</Flex>\n\n\t\t\t{ window.__experimentalEnableGridInteractivity && (\n\t\t\t\t// Use Flex with an explicit width on the FlexItem instead of HStack to\n\t\t\t\t// work around an issue in webkit where inputs with a max attribute are\n\t\t\t\t// sized incorrectly.\n\t\t\t\t<Flex\n\t\t\t\t\tas={ ToolsPanelItem }\n\t\t\t\t\thasValue={ hasStartValue }\n\t\t\t\t\tlabel={ __( 'Grid placement' ) }\n\t\t\t\t\tonDeselect={ resetGridStarts }\n\t\t\t\t\tisShownByDefault={ false }\n\t\t\t\t\tpanelId={ panelId }\n\t\t\t\t>\n\t\t\t\t\t<FlexItem style={ { width: '50%' } }>\n\t\t\t\t\t\t<InputControl\n\t\t\t\t\t\t\tlabel={ __( 'Column' ) }\n\t\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\t\t// Don't allow unsetting.\n\t\t\t\t\t\t\t\tconst newColumnStart =\n\t\t\t\t\t\t\t\t\tvalue === '' ? 1 : parseInt( value, 10 );\n\t\t\t\t\t\t\t\tonChange( {\n\t\t\t\t\t\t\t\t\tcolumnStart: newColumnStart,\n\t\t\t\t\t\t\t\t\trowStart,\n\t\t\t\t\t\t\t\t\tcolumnSpan,\n\t\t\t\t\t\t\t\t\trowSpan,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\t\t\t\t\tmoveBlocksToPosition(\n\t\t\t\t\t\t\t\t\t[ panelId ],\n\t\t\t\t\t\t\t\t\trootClientId,\n\t\t\t\t\t\t\t\t\trootClientId,\n\t\t\t\t\t\t\t\t\tgetNumberOfBlocksBeforeCell(\n\t\t\t\t\t\t\t\t\t\tnewColumnStart,\n\t\t\t\t\t\t\t\t\t\trowStart\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} }\n\t\t\t\t\t\t\tvalue={ columnStart ?? 1 }\n\t\t\t\t\t\t\tmin={ 1 }\n\t\t\t\t\t\t\tmax={\n\t\t\t\t\t\t\t\tcolumnCount\n\t\t\t\t\t\t\t\t\t? columnCount - ( columnSpan ?? 1 ) + 1\n\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</FlexItem>\n\t\t\t\t\t<FlexItem style={ { width: '50%' } }>\n\t\t\t\t\t\t<InputControl\n\t\t\t\t\t\t\tlabel={ __( 'Row' ) }\n\t\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\t\t// Don't allow unsetting.\n\t\t\t\t\t\t\t\tconst newRowStart =\n\t\t\t\t\t\t\t\t\tvalue === '' ? 1 : parseInt( value, 10 );\n\t\t\t\t\t\t\t\tonChange( {\n\t\t\t\t\t\t\t\t\tcolumnStart,\n\t\t\t\t\t\t\t\t\trowStart: newRowStart,\n\t\t\t\t\t\t\t\t\tcolumnSpan,\n\t\t\t\t\t\t\t\t\trowSpan,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\t\t\t\t\tmoveBlocksToPosition(\n\t\t\t\t\t\t\t\t\t[ panelId ],\n\t\t\t\t\t\t\t\t\trootClientId,\n\t\t\t\t\t\t\t\t\trootClientId,\n\t\t\t\t\t\t\t\t\tgetNumberOfBlocksBeforeCell(\n\t\t\t\t\t\t\t\t\t\tcolumnStart,\n\t\t\t\t\t\t\t\t\t\tnewRowStart\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} }\n\t\t\t\t\t\t\tvalue={ rowStart ?? 1 }\n\t\t\t\t\t\t\tmin={ 1 }\n\t\t\t\t\t\t\tmax={\n\t\t\t\t\t\t\t\trowCount\n\t\t\t\t\t\t\t\t\t? rowCount - ( rowSpan ?? 1 ) + 1\n\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</FlexItem>\n\t\t\t\t</Flex>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],
4
+ "sourcesContent": ["import {\n\t__experimentalToggleGroupControl as ToggleGroupControl,\n\t__experimentalToggleGroupControlOption as ToggleGroupControlOption,\n\t__experimentalUnitControl as UnitControl,\n\t__experimentalInputControl as WCInputControl,\n\t__experimentalVStack as VStack,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n\t__experimentalUseCustomUnits as useCustomUnits,\n\tFlex,\n\tFlexItem,\n} from '@wordpress/components';\nimport { __, _x } from '@wordpress/i18n';\nimport { useEffect } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useGetNumberOfBlocksBeforeCell } from '../grid/use-get-number-of-blocks-before-cell';\nimport { store as blockEditorStore } from '../../store';\nimport { useSettings } from '../use-settings';\n\n// These are the serialized `selfStretch` values. `max` used to be called\n// \"Fixed\" in the UI, but was renamed and replaced by `fixedNoShrink`.\nconst FLEX_CHILD_LAYOUT_VALUES = {\n\tfit: 'fit',\n\tgrow: 'fill',\n\tmax: 'fixed',\n\tfixed: 'fixedNoShrink',\n};\n\nconst FLEX_SIZE_VALUES = [\n\tFLEX_CHILD_LAYOUT_VALUES.max,\n\tFLEX_CHILD_LAYOUT_VALUES.fixed,\n];\n\nfunction isFlexSizeValue( value ) {\n\treturn FLEX_SIZE_VALUES.includes( value );\n}\n\nfunction maxSizeLabel( parentLayout ) {\n\tconst { orientation = 'horizontal' } = parentLayout ?? {};\n\treturn orientation === 'horizontal'\n\t\t? _x( 'Max', 'Block with maximum width in flex layout' )\n\t\t: _x( 'Max', 'Block with maximum height in flex layout' );\n}\n\nfunction helpText( flexControlValue, parentLayout ) {\n\tconst { orientation = 'horizontal' } = parentLayout ?? {};\n\n\tif ( flexControlValue === FLEX_CHILD_LAYOUT_VALUES.grow ) {\n\t\treturn __( 'Stretch to fill available space.' );\n\t}\n\tif (\n\t\tflexControlValue === FLEX_CHILD_LAYOUT_VALUES.max &&\n\t\torientation === 'horizontal'\n\t) {\n\t\treturn __( 'Specify a maximum width.' );\n\t} else if ( flexControlValue === FLEX_CHILD_LAYOUT_VALUES.max ) {\n\t\treturn __( 'Specify a maximum height.' );\n\t}\n\tif (\n\t\tflexControlValue === FLEX_CHILD_LAYOUT_VALUES.fixed &&\n\t\torientation === 'horizontal'\n\t) {\n\t\treturn __( 'Specify a fixed width.' );\n\t} else if ( flexControlValue === FLEX_CHILD_LAYOUT_VALUES.fixed ) {\n\t\treturn __( 'Specify a fixed height.' );\n\t}\n\treturn __( 'Fit contents.' );\n}\n\n/**\n * Form to edit the child layout value.\n *\n * @param {Object} props Props.\n * @param {Object} props.value The child layout value.\n * @param {Function} props.onChange Function to update the child layout value.\n * @param {Object} props.parentLayout The parent layout value.\n *\n * @param {boolean} props.isShownByDefault Whether the control is shown by default.\n * @param {string} props.panelId The panel ID.\n * @param {boolean} props.showGridSpanDefaults Whether unset grid span controls should show default values.\n * @return {Element} child layout edit element.\n */\nexport default function ChildLayoutControl( {\n\tvalue: childLayout = {},\n\tonChange,\n\tparentLayout,\n\tisShownByDefault,\n\tpanelId,\n\tshowGridSpanDefaults = true,\n} ) {\n\tconst {\n\t\ttype: parentType,\n\t\tdefault: { type: defaultParentType = 'default' } = {},\n\t} = parentLayout ?? {};\n\tconst parentLayoutType = parentType || defaultParentType;\n\n\tif ( parentLayoutType === 'flex' ) {\n\t\treturn (\n\t\t\t<FlexControls\n\t\t\t\tchildLayout={ childLayout }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tparentLayout={ parentLayout }\n\t\t\t\tisShownByDefault={ isShownByDefault }\n\t\t\t\tpanelId={ panelId }\n\t\t\t/>\n\t\t);\n\t} else if ( parentLayoutType === 'grid' ) {\n\t\treturn (\n\t\t\t<GridControls\n\t\t\t\tchildLayout={ childLayout }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tparentLayout={ parentLayout }\n\t\t\t\tisShownByDefault={ isShownByDefault }\n\t\t\t\tpanelId={ panelId }\n\t\t\t\tshowGridSpanDefaults={ showGridSpanDefaults }\n\t\t\t/>\n\t\t);\n\t}\n\n\treturn null;\n}\n\nfunction FlexControls( {\n\tchildLayout,\n\tonChange,\n\tparentLayout,\n\tisShownByDefault,\n\tpanelId,\n} ) {\n\tconst { selfStretch, flexSize } = childLayout;\n\tconst { orientation = 'horizontal' } = parentLayout ?? {};\n\tconst flexControlValue = selfStretch || FLEX_CHILD_LAYOUT_VALUES.fit;\n\tconst hasFlexSizeValue = isFlexSizeValue( flexControlValue );\n\tconst hasFlexValue = () => !! selfStretch;\n\tconst flexResetLabel =\n\t\torientation === 'horizontal' ? __( 'Width' ) : __( 'Height' );\n\tconst [ availableUnits ] = useSettings( 'spacing.units' );\n\tconst units = useCustomUnits( {\n\t\tavailableUnits: availableUnits || [\n\t\t\t'%',\n\t\t\t'px',\n\t\t\t'em',\n\t\t\t'rem',\n\t\t\t'vh',\n\t\t\t'vw',\n\t\t],\n\t} );\n\tconst resetFlex = () => {\n\t\tonChange( {\n\t\t\tselfStretch: undefined,\n\t\t\tflexSize: undefined,\n\t\t} );\n\t};\n\n\tuseEffect( () => {\n\t\tif ( isFlexSizeValue( selfStretch ) && ! flexSize ) {\n\t\t\tonChange( {\n\t\t\t\t...childLayout,\n\t\t\t\tselfStretch: FLEX_CHILD_LAYOUT_VALUES.fit,\n\t\t\t} );\n\t\t}\n\t}, [] ); // eslint-disable-line react-hooks/exhaustive-deps\n\n\treturn (\n\t\t<VStack\n\t\t\tas={ ToolsPanelItem }\n\t\t\tspacing={ 2 }\n\t\t\thasValue={ hasFlexValue }\n\t\t\tlabel={ flexResetLabel }\n\t\t\tonDeselect={ resetFlex }\n\t\t\tisShownByDefault={ isShownByDefault }\n\t\t\tpanelId={ panelId }\n\t\t>\n\t\t\t<ToggleGroupControl\n\t\t\t\tlabel={ childLayoutOrientation( parentLayout ) }\n\t\t\t\tvalue={ flexControlValue }\n\t\t\t\thelp={ helpText( flexControlValue, parentLayout ) }\n\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\tconst newFlexSize = isFlexSizeValue( value )\n\t\t\t\t\t\t? flexSize\n\t\t\t\t\t\t: null;\n\t\t\t\t\tonChange( {\n\t\t\t\t\t\tselfStretch: value,\n\t\t\t\t\t\tflexSize: newFlexSize,\n\t\t\t\t\t} );\n\t\t\t\t} }\n\t\t\t\tisBlock\n\t\t\t>\n\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\tkey={ FLEX_CHILD_LAYOUT_VALUES.fit }\n\t\t\t\t\tvalue={ FLEX_CHILD_LAYOUT_VALUES.fit }\n\t\t\t\t\tlabel={ _x(\n\t\t\t\t\t\t'Fit',\n\t\t\t\t\t\t'Intrinsic block width in flex layout'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\tkey={ FLEX_CHILD_LAYOUT_VALUES.grow }\n\t\t\t\t\tvalue={ FLEX_CHILD_LAYOUT_VALUES.grow }\n\t\t\t\t\tlabel={ _x(\n\t\t\t\t\t\t'Grow',\n\t\t\t\t\t\t'Block with expanding width in flex layout'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\tkey={ FLEX_CHILD_LAYOUT_VALUES.max }\n\t\t\t\t\tvalue={ FLEX_CHILD_LAYOUT_VALUES.max }\n\t\t\t\t\tlabel={ maxSizeLabel( parentLayout ) }\n\t\t\t\t/>\n\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\tkey={ FLEX_CHILD_LAYOUT_VALUES.fixed }\n\t\t\t\t\tvalue={ FLEX_CHILD_LAYOUT_VALUES.fixed }\n\t\t\t\t\tlabel={ _x(\n\t\t\t\t\t\t'Fixed',\n\t\t\t\t\t\t'Block with fixed width in flex layout'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</ToggleGroupControl>\n\t\t\t{ hasFlexSizeValue && (\n\t\t\t\t<UnitControl\n\t\t\t\t\tunits={ units }\n\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\tonChange( {\n\t\t\t\t\t\t\tselfStretch: flexControlValue,\n\t\t\t\t\t\t\tflexSize: value,\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\tvalue={ flexSize }\n\t\t\t\t\tmin={ 0 }\n\t\t\t\t\tlabel={ flexResetLabel }\n\t\t\t\t\thideLabelFromVision\n\t\t\t\t/>\n\t\t\t) }\n\t\t</VStack>\n\t);\n}\n\nexport function childLayoutOrientation( parentLayout ) {\n\tconst { orientation = 'horizontal' } = parentLayout ?? {};\n\treturn orientation === 'horizontal' ? __( 'Width' ) : __( 'Height' );\n}\n\nfunction GridControls( {\n\tchildLayout,\n\tonChange,\n\tparentLayout,\n\tisShownByDefault,\n\tpanelId,\n\tshowGridSpanDefaults,\n} ) {\n\tconst { columnStart, rowStart, columnSpan, rowSpan } = childLayout;\n\tconst { columnCount, rowCount } = parentLayout ?? {};\n\tconst rootClientId = useSelect( ( select ) =>\n\t\tselect( blockEditorStore ).getBlockRootClientId( panelId )\n\t);\n\tconst { moveBlocksToPosition, __unstableMarkNextChangeAsNotPersistent } =\n\t\tuseDispatch( blockEditorStore );\n\tconst getNumberOfBlocksBeforeCell = useGetNumberOfBlocksBeforeCell(\n\t\trootClientId,\n\t\tcolumnCount || 3\n\t);\n\tconst hasStartValue = () => !! columnStart || !! rowStart;\n\tconst hasSpanValue = () => !! columnSpan || !! rowSpan;\n\tconst resetGridStarts = () => {\n\t\tonChange( {\n\t\t\tcolumnStart: undefined,\n\t\t\trowStart: undefined,\n\t\t} );\n\t};\n\tconst resetGridSpans = () => {\n\t\tonChange( {\n\t\t\tcolumnSpan: undefined,\n\t\t\trowSpan: undefined,\n\t\t} );\n\t};\n\n\t// Calculate max column span based on current position and grid width\n\tconst maxColumnSpan = columnCount\n\t\t? columnCount - ( columnStart ?? 1 ) + 1\n\t\t: undefined;\n\n\t// Calculate max row span based on current position and grid height\n\tconst maxRowSpan =\n\t\twindow.__experimentalEnableGridInteractivity && rowCount\n\t\t\t? rowCount - ( rowStart ?? 1 ) + 1\n\t\t\t: undefined;\n\tconst columnSpanValue =\n\t\tcolumnSpan ?? ( showGridSpanDefaults ? 1 : undefined );\n\tconst rowSpanValue = rowSpan ?? ( showGridSpanDefaults ? 1 : undefined );\n\n\treturn (\n\t\t<>\n\t\t\t<Flex\n\t\t\t\tas={ ToolsPanelItem }\n\t\t\t\thasValue={ hasSpanValue }\n\t\t\t\tlabel={ __( 'Grid span' ) }\n\t\t\t\tonDeselect={ resetGridSpans }\n\t\t\t\tisShownByDefault={ isShownByDefault }\n\t\t\t\tpanelId={ panelId }\n\t\t\t>\n\t\t\t\t<FlexItem style={ { width: '50%' } }>\n\t\t\t\t\t<WCInputControl\n\t\t\t\t\t\tlabel={ __( 'Column span' ) }\n\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\t// Don't allow unsetting.\n\t\t\t\t\t\t\tconst newColumnSpan =\n\t\t\t\t\t\t\t\tvalue === '' ? 1 : parseInt( value, 10 );\n\t\t\t\t\t\t\tconst constrainedValue = maxColumnSpan\n\t\t\t\t\t\t\t\t? Math.min( newColumnSpan, maxColumnSpan )\n\t\t\t\t\t\t\t\t: newColumnSpan;\n\n\t\t\t\t\t\t\tonChange( {\n\t\t\t\t\t\t\t\tcolumnStart,\n\t\t\t\t\t\t\t\trowStart,\n\t\t\t\t\t\t\t\trowSpan,\n\t\t\t\t\t\t\t\tcolumnSpan: constrainedValue,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tvalue={ columnSpanValue }\n\t\t\t\t\t\tmin={ 1 }\n\t\t\t\t\t\tmax={ maxColumnSpan }\n\t\t\t\t\t/>\n\t\t\t\t</FlexItem>\n\t\t\t\t<FlexItem style={ { width: '50%' } }>\n\t\t\t\t\t<WCInputControl\n\t\t\t\t\t\tlabel={ __( 'Row span' ) }\n\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\tconst newRowSpan =\n\t\t\t\t\t\t\t\tvalue === '' ? 1 : parseInt( value, 10 );\n\t\t\t\t\t\t\tconst constrainedValue = maxRowSpan\n\t\t\t\t\t\t\t\t? Math.min( newRowSpan, maxRowSpan )\n\t\t\t\t\t\t\t\t: newRowSpan;\n\n\t\t\t\t\t\t\tonChange( {\n\t\t\t\t\t\t\t\tcolumnStart,\n\t\t\t\t\t\t\t\trowStart,\n\t\t\t\t\t\t\t\tcolumnSpan,\n\t\t\t\t\t\t\t\trowSpan: constrainedValue,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tvalue={ rowSpanValue }\n\t\t\t\t\t\tmin={ 1 }\n\t\t\t\t\t\tmax={ maxRowSpan }\n\t\t\t\t\t/>\n\t\t\t\t</FlexItem>\n\t\t\t</Flex>\n\n\t\t\t{ window.__experimentalEnableGridInteractivity && (\n\t\t\t\t// Use Flex with an explicit width on the FlexItem instead of HStack to\n\t\t\t\t// work around an issue in webkit where inputs with a max attribute are\n\t\t\t\t// sized incorrectly.\n\t\t\t\t<Flex\n\t\t\t\t\tas={ ToolsPanelItem }\n\t\t\t\t\thasValue={ hasStartValue }\n\t\t\t\t\tlabel={ __( 'Grid placement' ) }\n\t\t\t\t\tonDeselect={ resetGridStarts }\n\t\t\t\t\tisShownByDefault={ false }\n\t\t\t\t\tpanelId={ panelId }\n\t\t\t\t>\n\t\t\t\t\t<FlexItem style={ { width: '50%' } }>\n\t\t\t\t\t\t<WCInputControl\n\t\t\t\t\t\t\tlabel={ __( 'Column' ) }\n\t\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\t\t// Don't allow unsetting.\n\t\t\t\t\t\t\t\tconst newColumnStart =\n\t\t\t\t\t\t\t\t\tvalue === '' ? 1 : parseInt( value, 10 );\n\t\t\t\t\t\t\t\tonChange( {\n\t\t\t\t\t\t\t\t\tcolumnStart: newColumnStart,\n\t\t\t\t\t\t\t\t\trowStart,\n\t\t\t\t\t\t\t\t\tcolumnSpan,\n\t\t\t\t\t\t\t\t\trowSpan,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\t\t\t\t\tmoveBlocksToPosition(\n\t\t\t\t\t\t\t\t\t[ panelId ],\n\t\t\t\t\t\t\t\t\trootClientId,\n\t\t\t\t\t\t\t\t\trootClientId,\n\t\t\t\t\t\t\t\t\tgetNumberOfBlocksBeforeCell(\n\t\t\t\t\t\t\t\t\t\tnewColumnStart,\n\t\t\t\t\t\t\t\t\t\trowStart\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} }\n\t\t\t\t\t\t\tvalue={ columnStart ?? 1 }\n\t\t\t\t\t\t\tmin={ 1 }\n\t\t\t\t\t\t\tmax={\n\t\t\t\t\t\t\t\tcolumnCount\n\t\t\t\t\t\t\t\t\t? columnCount - ( columnSpan ?? 1 ) + 1\n\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</FlexItem>\n\t\t\t\t\t<FlexItem style={ { width: '50%' } }>\n\t\t\t\t\t\t<WCInputControl\n\t\t\t\t\t\t\tlabel={ __( 'Row' ) }\n\t\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\t\t// Don't allow unsetting.\n\t\t\t\t\t\t\t\tconst newRowStart =\n\t\t\t\t\t\t\t\t\tvalue === '' ? 1 : parseInt( value, 10 );\n\t\t\t\t\t\t\t\tonChange( {\n\t\t\t\t\t\t\t\t\tcolumnStart,\n\t\t\t\t\t\t\t\t\trowStart: newRowStart,\n\t\t\t\t\t\t\t\t\tcolumnSpan,\n\t\t\t\t\t\t\t\t\trowSpan,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\t\t\t\t\tmoveBlocksToPosition(\n\t\t\t\t\t\t\t\t\t[ panelId ],\n\t\t\t\t\t\t\t\t\trootClientId,\n\t\t\t\t\t\t\t\t\trootClientId,\n\t\t\t\t\t\t\t\t\tgetNumberOfBlocksBeforeCell(\n\t\t\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AA,cAClB,MAAK;AAAA,cACL,UAAW,CAAE,UAAW;AAEvB,sBAAM,cACL,UAAU,KAAK,IAAI,SAAU,OAAO,EAAG;AACxC,yBAAU;AAAA,kBACT;AAAA,kBACA,UAAU;AAAA,kBACV;AAAA,kBACA;AAAA,gBACD,CAAE;AACF,wDAAwC;AACxC;AAAA,kBACC,CAAE,OAAQ;AAAA,kBACV;AAAA,kBACA;AAAA,kBACA;AAAA,oBACC;AAAA,oBACA;AAAA,kBACD;AAAA,gBACD;AAAA,cACD;AAAA,cACA,OAAQ,YAAY;AAAA,cACpB,KAAM;AAAA,cACN,KACC,WACG,YAAa,WAAW,KAAM,IAC9B;AAAA;AAAA,UAEL,GACD;AAAA;AAAA;AAAA,IACD;AAAA,KAEF;AAEF;",
6
- "names": ["useCustomUnits", "VStack", "ToolsPanelItem", "ToggleGroupControl", "ToggleGroupControlOption", "UnitControl", "blockEditorStore", "InputControl"]
6
+ "names": ["useCustomUnits", "VStack", "ToolsPanelItem", "ToggleGroupControl", "ToggleGroupControlOption", "UnitControl", "blockEditorStore", "WCInputControl"]
7
7
  }
@@ -66,87 +66,71 @@ function createColorHOC(colorTypes, withColorPalette) {
66
66
  return (0, import_compose.compose)([
67
67
  withColorPalette,
68
68
  (WrappedComponent) => {
69
- return class WithColors extends import_element.Component {
70
- constructor(props) {
71
- super(props);
72
- this.setters = this.createSetters();
73
- this.colorUtils = {
74
- getMostReadableColor: this.getMostReadableColor.bind(this)
75
- };
76
- this.state = {};
77
- }
78
- getMostReadableColor(colorValue) {
79
- const { colors } = this.props;
80
- return (0, import_utils.getMostReadableColor)(colors, colorValue);
81
- }
82
- createSetters() {
83
- return Object.keys(colorMap).reduce(
84
- (settersAccumulator, colorAttributeName) => {
85
- const upperFirstColorAttributeName = upperFirst(colorAttributeName);
86
- const customColorAttributeName = `custom${upperFirstColorAttributeName}`;
87
- settersAccumulator[`set${upperFirstColorAttributeName}`] = this.createSetColor(
88
- colorAttributeName,
89
- customColorAttributeName
90
- );
91
- return settersAccumulator;
92
- },
93
- {}
94
- );
95
- }
96
- createSetColor(colorAttributeName, customColorAttributeName) {
97
- return (colorValue) => {
98
- const colorObject = (0, import_utils.getColorObjectByColorValue)(
99
- this.props.colors,
100
- colorValue
101
- );
102
- this.props.setAttributes({
103
- [colorAttributeName]: colorObject && colorObject.slug ? colorObject.slug : void 0,
104
- [customColorAttributeName]: colorObject && colorObject.slug ? void 0 : colorValue
105
- });
106
- };
107
- }
108
- static getDerivedStateFromProps({ attributes, colors }, previousState) {
109
- return Object.entries(colorMap).reduce(
110
- (newState, [colorAttributeName, colorContext]) => {
111
- const colorObject = (0, import_utils.getColorObjectByAttributeValues)(
112
- colors,
113
- attributes[colorAttributeName],
114
- attributes[`custom${upperFirst(
69
+ return function WithColors(props) {
70
+ const { colors: _colors, ...passedProps } = props;
71
+ const { attributes, setAttributes } = passedProps;
72
+ const prevColorPropsRef = (0, import_element.useRef)(null);
73
+ const colorProps = (0, import_element.useMemo)(() => {
74
+ const prevColorProps = prevColorPropsRef.current;
75
+ const result = Object.fromEntries(
76
+ Object.entries(colorMap).flatMap(
77
+ ([colorAttributeName, colorContext]) => {
78
+ const customAttr = `custom${upperFirst(
115
79
  colorAttributeName
116
- )}`]
117
- );
118
- const previousColorObject = previousState[colorAttributeName];
119
- const previousColor = previousColorObject?.color;
120
- if (previousColor === colorObject.color && previousColorObject) {
121
- newState[colorAttributeName] = previousColorObject;
122
- } else {
123
- newState[colorAttributeName] = {
80
+ )}`;
81
+ const upperFirstColorAttributeName = upperFirst(colorAttributeName);
82
+ const colorObject = (0, import_utils.getColorObjectByAttributeValues)(
83
+ _colors,
84
+ attributes[colorAttributeName],
85
+ attributes[customAttr]
86
+ );
87
+ const prevColorValue = prevColorProps?.[colorAttributeName];
88
+ const colorValue = prevColorValue?.color === colorObject.color && prevColorValue ? prevColorValue : {
124
89
  ...colorObject,
125
90
  class: (0, import_utils.getColorClassName)(
126
91
  colorContext,
127
92
  colorObject.slug
128
93
  )
129
94
  };
95
+ const setter = (newColorValue) => {
96
+ const resolvedColorObject = (0, import_utils.getColorObjectByColorValue)(
97
+ _colors,
98
+ newColorValue
99
+ );
100
+ setAttributes({
101
+ [colorAttributeName]: resolvedColorObject?.slug || void 0,
102
+ [customAttr]: resolvedColorObject?.slug ? void 0 : newColorValue
103
+ });
104
+ };
105
+ return [
106
+ [colorAttributeName, colorValue],
107
+ [
108
+ `set${upperFirstColorAttributeName}`,
109
+ setter
110
+ ]
111
+ ];
130
112
  }
131
- return newState;
132
- },
133
- {}
113
+ )
134
114
  );
135
- }
136
- render() {
137
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
138
- WrappedComponent,
139
- {
140
- ...{
141
- ...this.props,
142
- colors: void 0,
143
- ...this.state,
144
- ...this.setters,
145
- colorUtils: this.colorUtils
146
- }
115
+ prevColorPropsRef.current = result;
116
+ return result;
117
+ }, [attributes, _colors, setAttributes]);
118
+ const colorUtils = (0, import_element.useMemo)(
119
+ () => ({
120
+ getMostReadableColor: (colorValue) => (0, import_utils.getMostReadableColor)(_colors, colorValue)
121
+ }),
122
+ [_colors]
123
+ );
124
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
125
+ WrappedComponent,
126
+ {
127
+ ...{
128
+ ...passedProps,
129
+ ...colorProps,
130
+ colorUtils
147
131
  }
148
- );
149
- }
132
+ }
133
+ );
150
134
  };
151
135
  }
152
136
  ]);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/colors/with-colors.js"],
4
- "sourcesContent": ["import { useMemo, Component } from '@wordpress/element';\nimport { compose, createHigherOrderComponent } from '@wordpress/compose';\nimport { kebabCase } from '@wordpress/kebab-case';\nimport {\n\tgetColorClassName,\n\tgetColorObjectByColorValue,\n\tgetColorObjectByAttributeValues,\n\tgetMostReadableColor,\n} from './utils';\nimport { useSettings } from '../use-settings';\n\n/**\n * Capitalizes the first letter in a string.\n *\n * @param {string} str The string whose first letter the function will capitalize.\n *\n * @return {string} Capitalized string.\n */\nconst upperFirst = ( [ firstLetter, ...rest ] ) =>\n\tfirstLetter.toUpperCase() + rest.join( '' );\n\n/**\n * Higher order component factory for injecting the `colorsArray` argument as\n * the colors prop in the `withCustomColors` HOC.\n *\n * @param {Array} colorsArray An array of color objects.\n *\n * @return {Function} The higher order component.\n */\nconst withCustomColorPalette = ( colorsArray ) =>\n\tcreateHigherOrderComponent(\n\t\t( WrappedComponent ) =>\n\t\t\tfunction WithCustomColorPalette( props ) {\n\t\t\t\treturn <WrappedComponent { ...props } colors={ colorsArray } />;\n\t\t\t},\n\t\t'withCustomColorPalette'\n\t);\n\n/**\n * Higher order component factory for injecting the editor colors as the\n * `colors` prop in the `withColors` HOC.\n *\n * @return {Function} The higher order component.\n */\nconst withEditorColorPalette = () =>\n\tcreateHigherOrderComponent(\n\t\t( WrappedComponent ) =>\n\t\t\tfunction WithEditorColorPalette( props ) {\n\t\t\t\tconst [ userPalette, themePalette, defaultPalette ] =\n\t\t\t\t\tuseSettings(\n\t\t\t\t\t\t'color.palette.custom',\n\t\t\t\t\t\t'color.palette.theme',\n\t\t\t\t\t\t'color.palette.default'\n\t\t\t\t\t);\n\t\t\t\tconst allColors = useMemo(\n\t\t\t\t\t() => [\n\t\t\t\t\t\t...( userPalette || [] ),\n\t\t\t\t\t\t...( themePalette || [] ),\n\t\t\t\t\t\t...( defaultPalette || [] ),\n\t\t\t\t\t],\n\t\t\t\t\t[ userPalette, themePalette, defaultPalette ]\n\t\t\t\t);\n\t\t\t\treturn <WrappedComponent { ...props } colors={ allColors } />;\n\t\t\t},\n\t\t'withEditorColorPalette'\n\t);\n\n/**\n * Helper function used with `createHigherOrderComponent` to create\n * higher order components for managing color logic.\n *\n * @param {Array} colorTypes An array of color types (e.g. 'backgroundColor, borderColor).\n * @param {Function} withColorPalette A HOC for injecting the 'colors' prop into the WrappedComponent.\n *\n * @return {Component} The component that can be used as a HOC.\n */\nfunction createColorHOC( colorTypes, withColorPalette ) {\n\tconst colorMap = colorTypes.reduce( ( colorObject, colorType ) => {\n\t\treturn {\n\t\t\t...colorObject,\n\t\t\t...( typeof colorType === 'string'\n\t\t\t\t? { [ colorType ]: kebabCase( colorType ) }\n\t\t\t\t: colorType ),\n\t\t};\n\t}, {} );\n\n\treturn compose( [\n\t\twithColorPalette,\n\t\t( WrappedComponent ) => {\n\t\t\treturn class WithColors extends Component {\n\t\t\t\tconstructor( props ) {\n\t\t\t\t\tsuper( props );\n\n\t\t\t\t\tthis.setters = this.createSetters();\n\t\t\t\t\tthis.colorUtils = {\n\t\t\t\t\t\tgetMostReadableColor:\n\t\t\t\t\t\t\tthis.getMostReadableColor.bind( this ),\n\t\t\t\t\t};\n\n\t\t\t\t\tthis.state = {};\n\t\t\t\t}\n\n\t\t\t\tgetMostReadableColor( colorValue ) {\n\t\t\t\t\tconst { colors } = this.props;\n\t\t\t\t\treturn getMostReadableColor( colors, colorValue );\n\t\t\t\t}\n\n\t\t\t\tcreateSetters() {\n\t\t\t\t\treturn Object.keys( colorMap ).reduce(\n\t\t\t\t\t\t( settersAccumulator, colorAttributeName ) => {\n\t\t\t\t\t\t\tconst upperFirstColorAttributeName =\n\t\t\t\t\t\t\t\tupperFirst( colorAttributeName );\n\t\t\t\t\t\t\tconst customColorAttributeName = `custom${ upperFirstColorAttributeName }`;\n\t\t\t\t\t\t\tsettersAccumulator[\n\t\t\t\t\t\t\t\t`set${ upperFirstColorAttributeName }`\n\t\t\t\t\t\t\t] = this.createSetColor(\n\t\t\t\t\t\t\t\tcolorAttributeName,\n\t\t\t\t\t\t\t\tcustomColorAttributeName\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn settersAccumulator;\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{}\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tcreateSetColor( colorAttributeName, customColorAttributeName ) {\n\t\t\t\t\treturn ( colorValue ) => {\n\t\t\t\t\t\tconst colorObject = getColorObjectByColorValue(\n\t\t\t\t\t\t\tthis.props.colors,\n\t\t\t\t\t\t\tcolorValue\n\t\t\t\t\t\t);\n\t\t\t\t\t\tthis.props.setAttributes( {\n\t\t\t\t\t\t\t[ colorAttributeName ]:\n\t\t\t\t\t\t\t\tcolorObject && colorObject.slug\n\t\t\t\t\t\t\t\t\t? colorObject.slug\n\t\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t\t[ customColorAttributeName ]:\n\t\t\t\t\t\t\t\tcolorObject && colorObject.slug\n\t\t\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t\t\t: colorValue,\n\t\t\t\t\t\t} );\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tstatic getDerivedStateFromProps(\n\t\t\t\t\t{ attributes, colors },\n\t\t\t\t\tpreviousState\n\t\t\t\t) {\n\t\t\t\t\treturn Object.entries( colorMap ).reduce(\n\t\t\t\t\t\t( newState, [ colorAttributeName, colorContext ] ) => {\n\t\t\t\t\t\t\tconst colorObject = getColorObjectByAttributeValues(\n\t\t\t\t\t\t\t\tcolors,\n\t\t\t\t\t\t\t\tattributes[ colorAttributeName ],\n\t\t\t\t\t\t\t\tattributes[\n\t\t\t\t\t\t\t\t\t`custom${ upperFirst(\n\t\t\t\t\t\t\t\t\t\tcolorAttributeName\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);\n\n\t\t\t\t\t\t\tconst previousColorObject =\n\t\t\t\t\t\t\t\tpreviousState[ colorAttributeName ];\n\t\t\t\t\t\t\tconst previousColor = previousColorObject?.color;\n\t\t\t\t\t\t\t/**\n\t\t\t\t\t\t\t * The \"and previousColorObject\" condition checks that a previous color object was already computed.\n\t\t\t\t\t\t\t * At the start previousColorObject and colorValue are both equal to undefined\n\t\t\t\t\t\t\t * bus as previousColorObject does not exist we should compute the object.\n\t\t\t\t\t\t\t */\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tpreviousColor === colorObject.color &&\n\t\t\t\t\t\t\t\tpreviousColorObject\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tnewState[ colorAttributeName ] =\n\t\t\t\t\t\t\t\t\tpreviousColorObject;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tnewState[ colorAttributeName ] = {\n\t\t\t\t\t\t\t\t\t...colorObject,\n\t\t\t\t\t\t\t\t\tclass: getColorClassName(\n\t\t\t\t\t\t\t\t\t\tcolorContext,\n\t\t\t\t\t\t\t\t\t\tcolorObject.slug\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}\n\t\t\t\t\t\t\treturn newState;\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{}\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\trender() {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<WrappedComponent\n\t\t\t\t\t\t\t{ ...{\n\t\t\t\t\t\t\t\t...this.props,\n\t\t\t\t\t\t\t\tcolors: undefined,\n\t\t\t\t\t\t\t\t...this.state,\n\t\t\t\t\t\t\t\t...this.setters,\n\t\t\t\t\t\t\t\tcolorUtils: this.colorUtils,\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t};\n\t\t},\n\t] );\n}\n\n/**\n * A higher-order component factory for creating a 'withCustomColors' HOC, which handles color logic\n * for class generation color value, retrieval and color attribute setting.\n *\n * Use this higher-order component to work with a custom set of colors.\n *\n * @example\n *\n * ```jsx\n * const CUSTOM_COLORS = [ { name: 'Red', slug: 'red', color: '#ff0000' }, { name: 'Blue', slug: 'blue', color: '#0000ff' } ];\n * const withCustomColors = createCustomColorsHOC( CUSTOM_COLORS );\n * // ...\n * export default compose(\n * withCustomColors( 'backgroundColor', 'borderColor' ),\n * MyColorfulComponent,\n * );\n * ```\n *\n * @param {Array} colorsArray The array of color objects (name, slug, color, etc... ).\n *\n * @return {Function} Higher-order component.\n */\nexport function createCustomColorsHOC( colorsArray ) {\n\treturn ( ...colorTypes ) => {\n\t\tconst withColorPalette = withCustomColorPalette( colorsArray );\n\t\treturn createHigherOrderComponent(\n\t\t\tcreateColorHOC( colorTypes, withColorPalette ),\n\t\t\t'withCustomColors'\n\t\t);\n\t};\n}\n\n/**\n * A higher-order component, which handles color logic for class generation color value, retrieval and color attribute setting.\n *\n * For use with the default editor/theme color palette.\n *\n * @example\n *\n * ```jsx\n * export default compose(\n * withColors( 'backgroundColor', { textColor: 'color' } ),\n * MyColorfulComponent,\n * );\n * ```\n *\n * @param {...(Object|string)} colorTypes The arguments can be strings or objects. If the argument is an object,\n * it should contain the color attribute name as key and the color context as value.\n * If the argument is a string the value should be the color attribute name,\n * the color context is computed by applying a kebab case transform to the value.\n * Color context represents the context/place where the color is going to be used.\n * The class name of the color is generated using 'has' followed by the color name\n * and ending with the color context all in kebab case e.g: has-green-background-color.\n *\n * @return {Function} Higher-order component.\n */\nexport default function withColors( ...colorTypes ) {\n\tconst withColorPalette = withEditorColorPalette();\n\treturn createHigherOrderComponent(\n\t\tcreateColorHOC( colorTypes, withColorPalette ),\n\t\t'withColors'\n\t);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAmC;AACnC,qBAAoD;AACpD,wBAA0B;AAC1B,mBAKO;AACP,0BAA4B;AAwBjB;AAfX,IAAM,aAAa,CAAE,CAAE,aAAgB,OAAK,MAC3C,YAAY,YAAY,IAAI,KAAK,KAAM,EAAG;AAU3C,IAAM,yBAAyB,CAAE,oBAChC;AAAA,EACC,CAAE,qBACD,SAAS,uBAAwB,OAAQ;AACxC,WAAO,4CAAC,oBAAmB,GAAG,OAAQ,QAAS,aAAc;AAAA,EAC9D;AAAA,EACD;AACD;AAQD,IAAM,yBAAyB,UAC9B;AAAA,EACC,CAAE,qBACD,SAAS,uBAAwB,OAAQ;AACxC,UAAM,CAAE,aAAa,cAAc,cAA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ACpD,SAAO,IAAK,eAAgB;AAC3B,UAAM,mBAAmB,uBAAwB,WAAY;AAC7D,eAAO;AAAA,MACN,eAAgB,YAAY,gBAAiB;AAAA,MAC7C;AAAA,IACD;AAAA,EACD;AACD;AA0Be,SAAR,cAAgC,YAAa;AACnD,QAAM,mBAAmB,uBAAuB;AAChD,aAAO;AAAA,IACN,eAAgB,YAAY,gBAAiB;AAAA,IAC7C;AAAA,EACD;AACD;",
4
+ "sourcesContent": ["import { useMemo, useRef } from '@wordpress/element';\nimport { compose, createHigherOrderComponent } from '@wordpress/compose';\nimport { kebabCase } from '@wordpress/kebab-case';\nimport {\n\tgetColorClassName,\n\tgetColorObjectByColorValue,\n\tgetColorObjectByAttributeValues,\n\tgetMostReadableColor,\n} from './utils';\nimport { useSettings } from '../use-settings';\n\n/**\n * Capitalizes the first letter in a string.\n *\n * @param {string} str The string whose first letter the function will capitalize.\n *\n * @return {string} Capitalized string.\n */\nconst upperFirst = ( [ firstLetter, ...rest ] ) =>\n\tfirstLetter.toUpperCase() + rest.join( '' );\n\n/**\n * Higher order component factory for injecting the `colorsArray` argument as\n * the colors prop in the `withCustomColors` HOC.\n *\n * @param {Array} colorsArray An array of color objects.\n *\n * @return {Function} The higher order component.\n */\nconst withCustomColorPalette = ( colorsArray ) =>\n\tcreateHigherOrderComponent(\n\t\t( WrappedComponent ) =>\n\t\t\tfunction WithCustomColorPalette( props ) {\n\t\t\t\treturn <WrappedComponent { ...props } colors={ colorsArray } />;\n\t\t\t},\n\t\t'withCustomColorPalette'\n\t);\n\n/**\n * Higher order component factory for injecting the editor colors as the\n * `colors` prop in the `withColors` HOC.\n *\n * @return {Function} The higher order component.\n */\nconst withEditorColorPalette = () =>\n\tcreateHigherOrderComponent(\n\t\t( WrappedComponent ) =>\n\t\t\tfunction WithEditorColorPalette( props ) {\n\t\t\t\tconst [ userPalette, themePalette, defaultPalette ] =\n\t\t\t\t\tuseSettings(\n\t\t\t\t\t\t'color.palette.custom',\n\t\t\t\t\t\t'color.palette.theme',\n\t\t\t\t\t\t'color.palette.default'\n\t\t\t\t\t);\n\t\t\t\tconst allColors = useMemo(\n\t\t\t\t\t() => [\n\t\t\t\t\t\t...( userPalette || [] ),\n\t\t\t\t\t\t...( themePalette || [] ),\n\t\t\t\t\t\t...( defaultPalette || [] ),\n\t\t\t\t\t],\n\t\t\t\t\t[ userPalette, themePalette, defaultPalette ]\n\t\t\t\t);\n\t\t\t\treturn <WrappedComponent { ...props } colors={ allColors } />;\n\t\t\t},\n\t\t'withEditorColorPalette'\n\t);\n\n/**\n * Helper function used with `createHigherOrderComponent` to create\n * higher order components for managing color logic.\n *\n * @param {Array} colorTypes An array of color types (e.g. 'backgroundColor, borderColor).\n * @param {Function} withColorPalette A HOC for injecting the 'colors' prop into the WrappedComponent.\n *\n * @return {Component} The component that can be used as a HOC.\n */\nfunction createColorHOC( colorTypes, withColorPalette ) {\n\tconst colorMap = colorTypes.reduce( ( colorObject, colorType ) => {\n\t\treturn {\n\t\t\t...colorObject,\n\t\t\t...( typeof colorType === 'string'\n\t\t\t\t? { [ colorType ]: kebabCase( colorType ) }\n\t\t\t\t: colorType ),\n\t\t};\n\t}, {} );\n\n\treturn compose( [\n\t\twithColorPalette,\n\t\t( WrappedComponent ) => {\n\t\t\treturn function WithColors( props ) {\n\t\t\t\tconst { colors: _colors, ...passedProps } = props;\n\t\t\t\tconst { attributes, setAttributes } = passedProps;\n\t\t\t\tconst prevColorPropsRef = useRef( null );\n\n\t\t\t\tconst colorProps = useMemo( () => {\n\t\t\t\t\tconst prevColorProps = prevColorPropsRef.current;\n\n\t\t\t\t\tconst result = Object.fromEntries(\n\t\t\t\t\t\tObject.entries( colorMap ).flatMap(\n\t\t\t\t\t\t\t( [ colorAttributeName, colorContext ] ) => {\n\t\t\t\t\t\t\t\tconst customAttr = `custom${ upperFirst(\n\t\t\t\t\t\t\t\t\tcolorAttributeName\n\t\t\t\t\t\t\t\t) }`;\n\t\t\t\t\t\t\t\tconst upperFirstColorAttributeName =\n\t\t\t\t\t\t\t\t\tupperFirst( colorAttributeName );\n\n\t\t\t\t\t\t\t\tconst colorObject =\n\t\t\t\t\t\t\t\t\tgetColorObjectByAttributeValues(\n\t\t\t\t\t\t\t\t\t\t_colors,\n\t\t\t\t\t\t\t\t\t\tattributes[ colorAttributeName ],\n\t\t\t\t\t\t\t\t\t\tattributes[ customAttr ]\n\t\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\tconst prevColorValue =\n\t\t\t\t\t\t\t\t\tprevColorProps?.[ colorAttributeName ];\n\t\t\t\t\t\t\t\tconst colorValue =\n\t\t\t\t\t\t\t\t\tprevColorValue?.color ===\n\t\t\t\t\t\t\t\t\t\tcolorObject.color && prevColorValue\n\t\t\t\t\t\t\t\t\t\t? prevColorValue\n\t\t\t\t\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\t\t\t\t\t...colorObject,\n\t\t\t\t\t\t\t\t\t\t\t\tclass: getColorClassName(\n\t\t\t\t\t\t\t\t\t\t\t\t\tcolorContext,\n\t\t\t\t\t\t\t\t\t\t\t\t\tcolorObject.slug\n\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t };\n\n\t\t\t\t\t\t\t\tconst setter = ( newColorValue ) => {\n\t\t\t\t\t\t\t\t\tconst resolvedColorObject =\n\t\t\t\t\t\t\t\t\t\tgetColorObjectByColorValue(\n\t\t\t\t\t\t\t\t\t\t\t_colors,\n\t\t\t\t\t\t\t\t\t\t\tnewColorValue\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\t[ colorAttributeName ]:\n\t\t\t\t\t\t\t\t\t\t\tresolvedColorObject?.slug ||\n\t\t\t\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\t\t\t[ customAttr ]:\n\t\t\t\t\t\t\t\t\t\t\tresolvedColorObject?.slug\n\t\t\t\t\t\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t\t\t\t\t\t: newColorValue,\n\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\t\t\t[ colorAttributeName, colorValue ],\n\t\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t\t`set${ upperFirstColorAttributeName }`,\n\t\t\t\t\t\t\t\t\t\tsetter,\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}\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\n\t\t\t\t\tprevColorPropsRef.current = result;\n\t\t\t\t\treturn result;\n\t\t\t\t}, [ attributes, _colors, setAttributes ] );\n\n\t\t\t\tconst colorUtils = useMemo(\n\t\t\t\t\t() => ( {\n\t\t\t\t\t\tgetMostReadableColor: ( colorValue ) =>\n\t\t\t\t\t\t\tgetMostReadableColor( _colors, colorValue ),\n\t\t\t\t\t} ),\n\t\t\t\t\t[ _colors ]\n\t\t\t\t);\n\n\t\t\t\treturn (\n\t\t\t\t\t<WrappedComponent\n\t\t\t\t\t\t{ ...{\n\t\t\t\t\t\t\t...passedProps,\n\t\t\t\t\t\t\t...colorProps,\n\t\t\t\t\t\t\tcolorUtils,\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t};\n\t\t},\n\t] );\n}\n\n/**\n * A higher-order component factory for creating a 'withCustomColors' HOC, which handles color logic\n * for class generation color value, retrieval and color attribute setting.\n *\n * Use this higher-order component to work with a custom set of colors.\n *\n * @example\n *\n * ```jsx\n * const CUSTOM_COLORS = [ { name: 'Red', slug: 'red', color: '#ff0000' }, { name: 'Blue', slug: 'blue', color: '#0000ff' } ];\n * const withCustomColors = createCustomColorsHOC( CUSTOM_COLORS );\n * // ...\n * export default compose(\n * withCustomColors( 'backgroundColor', 'borderColor' ),\n * MyColorfulComponent,\n * );\n * ```\n *\n * @param {Array} colorsArray The array of color objects (name, slug, color, etc... ).\n *\n * @return {Function} Higher-order component.\n */\nexport function createCustomColorsHOC( colorsArray ) {\n\treturn ( ...colorTypes ) => {\n\t\tconst withColorPalette = withCustomColorPalette( colorsArray );\n\t\treturn createHigherOrderComponent(\n\t\t\tcreateColorHOC( colorTypes, withColorPalette ),\n\t\t\t'withCustomColors'\n\t\t);\n\t};\n}\n\n/**\n * A higher-order component, which handles color logic for class generation color value, retrieval and color attribute setting.\n *\n * For use with the default editor/theme color palette.\n *\n * @example\n *\n * ```jsx\n * export default compose(\n * withColors( 'backgroundColor', { textColor: 'color' } ),\n * MyColorfulComponent,\n * );\n * ```\n *\n * @param {...(Object|string)} colorTypes The arguments can be strings or objects. If the argument is an object,\n * it should contain the color attribute name as key and the color context as value.\n * If the argument is a string the value should be the color attribute name,\n * the color context is computed by applying a kebab case transform to the value.\n * Color context represents the context/place where the color is going to be used.\n * The class name of the color is generated using 'has' followed by the color name\n * and ending with the color context all in kebab case e.g: has-green-background-color.\n *\n * @return {Function} Higher-order component.\n */\nexport default function withColors( ...colorTypes ) {\n\tconst withColorPalette = withEditorColorPalette();\n\treturn createHigherOrderComponent(\n\t\tcreateColorHOC( colorTypes, withColorPalette ),\n\t\t'withColors'\n\t);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAgC;AAChC,qBAAoD;AACpD,wBAA0B;AAC1B,mBAKO;AACP,0BAA4B;AAwBjB;AAfX,IAAM,aAAa,CAAE,CAAE,aAAgB,OAAK,MAC3C,YAAY,YAAY,IAAI,KAAK,KAAM,EAAG;AAU3C,IAAM,yBAAyB,CAAE,oBAChC;AAAA,EACC,CAAE,qBACD,SAAS,uBAAwB,OAAQ;AACxC,WAAO,4CAAC,oBAAmB,GAAG,OAAQ,QAAS,aAAc;AAAA,EAC9D;AAAA,EACD;AACD;AAQD,IAAM,yBAAyB,UAC9B;AAAA,EACC,CAAE,qBACD,SAAS,u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 +27,7 @@ var import_components = require("@wordpress/components");
27
27
  var import_i18n = require("@wordpress/i18n");
28
28
  var import_use_settings = require("../use-settings/index.cjs");
29
29
  var import_inheritance = require("../global-styles/inheritance/index.cjs");
30
+ var import_utils = require("./utils.cjs");
30
31
  var import_jsx_runtime = require("react/jsx-runtime");
31
32
  function AspectRatioTool({
32
33
  panelId,
@@ -41,7 +42,6 @@ function AspectRatioTool({
41
42
  isInherited,
42
43
  hasLocalOverride
43
44
  }) {
44
- const displayValue = value ?? "auto";
45
45
  const [defaultRatios, themeRatios, showDefaultRatios] = (0, import_use_settings.useSettings)(
46
46
  "dimensions.aspectRatios.default",
47
47
  "dimensions.aspectRatios.theme",
@@ -72,6 +72,8 @@ function AspectRatioTool({
72
72
  hidden: true
73
73
  }
74
74
  ];
75
+ const resolvedOptions = options ?? aspectRatioOptions;
76
+ const displayValue = value === void 0 || value === null || value === "auto" ? "auto" : (0, import_utils.findAspectRatioOption)(value, resolvedOptions)?.value ?? "custom";
75
77
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
76
78
  import_inheritance.InheritanceToolsPanelItem,
77
79
  {
@@ -88,7 +90,7 @@ function AspectRatioTool({
88
90
  {
89
91
  label: (0, import_i18n.__)("Aspect ratio"),
90
92
  value: displayValue,
91
- options: options ?? aspectRatioOptions,
93
+ options: resolvedOptions,
92
94
  onChange
93
95
  }
94
96
  )
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/dimensions-tool/aspect-ratio-tool.js"],
4
- "sourcesContent": ["import { SelectControl } from '@wordpress/components';\nimport { __, _x } from '@wordpress/i18n';\nimport { useSettings } from '../use-settings';\nimport { InheritanceToolsPanelItem } from '../global-styles/inheritance';\n\n/**\n * @typedef {import('@wordpress/components/build-types/select-control/types').SelectControlProps} SelectControlProps\n */\n\n/**\n * @callback AspectRatioToolPropsOnChange\n * @param {string} [value] New aspect ratio value.\n * @return {void} No return.\n */\n\n/**\n * @typedef {Object} AspectRatioToolProps\n * @property {string} [panelId] ID of the panel this tool is associated with.\n * @property {string} [value] Current aspect ratio value.\n * @property {AspectRatioToolPropsOnChange} [onChange] Callback to update the aspect ratio value.\n * @property {SelectControlProps[]} [options] Aspect ratio options.\n * @property {string} [defaultValue] Default aspect ratio value.\n * @property {boolean} [isShownByDefault] Whether the tool is shown by default.\n * @property {string} [className] Additional CSS class on the wrapping panel item.\n * @property {boolean} [isInherited] Whether the control is displaying an inherited Global Styles value.\n * @property {boolean} [hasLocalOverride] Whether a local value is overriding an inherited Global Styles value.\n */\n\nexport default function AspectRatioTool( {\n\tpanelId,\n\tvalue,\n\tonChange = () => {},\n\toptions,\n\tdefaultValue = 'auto',\n\thasValue,\n\tisShownByDefault = true,\n\tclassName,\n\tisInherited,\n\thasLocalOverride,\n} ) {\n\t// Match the CSS default so if the value is used directly in CSS it will look correct in the control.\n\tconst displayValue = value ?? 'auto';\n\n\tconst [ defaultRatios, themeRatios, showDefaultRatios ] = useSettings(\n\t\t'dimensions.aspectRatios.default',\n\t\t'dimensions.aspectRatios.theme',\n\t\t'dimensions.defaultAspectRatios'\n\t);\n\n\tconst themeOptions = themeRatios?.map( ( { name, ratio } ) => ( {\n\t\tlabel: name,\n\t\tvalue: ratio,\n\t} ) );\n\n\tconst defaultOptions = defaultRatios?.map( ( { name, ratio } ) => ( {\n\t\tlabel: name,\n\t\tvalue: ratio,\n\t} ) );\n\n\tconst aspectRatioOptions = [\n\t\t{\n\t\t\tlabel: _x(\n\t\t\t\t'Original',\n\t\t\t\t'Aspect ratio option for dimensions control'\n\t\t\t),\n\t\t\tvalue: 'auto',\n\t\t},\n\t\t...( showDefaultRatios ? defaultOptions : [] ),\n\t\t...( themeOptions ? themeOptions : [] ),\n\t\t{\n\t\t\tlabel: _x( 'Custom', 'Aspect ratio option for dimensions control' ),\n\t\t\tvalue: 'custom',\n\t\t\tdisabled: true,\n\t\t\thidden: true,\n\t\t},\n\t];\n\n\treturn (\n\t\t<InheritanceToolsPanelItem\n\t\t\tclassName={ className }\n\t\t\tisInherited={ isInherited }\n\t\t\thasLocalOverride={ hasLocalOverride }\n\t\t\thasValue={\n\t\t\t\thasValue ? hasValue : () => displayValue !== defaultValue\n\t\t\t}\n\t\t\tlabel={ __( 'Aspect ratio' ) }\n\t\t\tonDeselect={ () => onChange( undefined ) }\n\t\t\tisShownByDefault={ isShownByDefault }\n\t\t\tpanelId={ panelId }\n\t\t>\n\t\t\t<SelectControl\n\t\t\t\tlabel={ __( 'Aspect ratio' ) }\n\t\t\t\tvalue={ displayValue }\n\t\t\t\toptions={ options ?? aspectRatioOptions }\n\t\t\t\tonChange={ onChange }\n\t\t\t/>\n\t\t</InheritanceToolsPanelItem>\n\t);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAA8B;AAC9B,kBAAuB;AACvB,0BAA4B;AAC5B,yBAA0C;AAuFvC;AA9DY,SAAR,gBAAkC;AAAA,EACxC;AAAA,EACA;AAAA,EACA,WAAW,MAAM;AAAA,EAAC;AAAA,EAClB;AAAA,EACA,eAAe;AAAA,EACf;AAAA,EACA,mBAAmB;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AACD,GAAI;AAEH,QAAM,eAAe,SAAS;AAE9B,QAAM,CAAE,eAAe,aAAa,iBAAkB,QAAI;AAAA,IACzD;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAEA,QAAM,eAAe,aAAa,IAAK,CAAE,EAAE,MAAM,MAAM,OAAS;AAAA,IAC/D,OAAO;AAAA,IACP,OAAO;AAAA,EACR,EAAI;AAEJ,QAAM,iBAAiB,eAAe,IAAK,CAAE,EAAE,MAAM,MAAM,OAAS;AAAA,IACnE,OAAO;AAAA,IACP,OAAO;AAAA,EACR,EAAI;AAEJ,QAAM,qBAAqB;AAAA,IAC1B;AAAA,MACC,WAAO;AAAA,QACN;AAAA,QACA;AAAA,MACD;AAAA,MACA,OAAO;AAAA,IACR;AAAA,IACA,GAAK,oBAAoB,iBAAiB,CAAC;AAAA,IAC3C,GAAK,eAAe,eAAe,CAAC;AAAA,IACpC;AAAA,MACC,WAAO,gBAAI,UAAU,4CAA6C;AAAA,MAClE,OAAO;AAAA,MACP,UAAU;AAAA,MACV,QAAQ;AAAA,IACT;AAAA,EACD;AAEA,SACC;AAAA,IAAC;AAAA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,UACC,WAAW,WAAW,MAAM,iBAAiB;AAAA,MAE9C,WAAQ,gBAAI,cAAe;AAAA,MAC3B,YAAa,MAAM,SAAU,MAAU;AAAA,MACvC;AAAA,MACA;AAAA,MAEA;AAAA,QAAC;AAAA;AAAA,UACA,WAAQ,gBAAI,cAAe;AAAA,UAC3B,OAAQ;AAAA,UACR,SAAU,WAAW;AAAA,UACrB;AAAA;AAAA,MACD;AAAA;AAAA,EACD;AAEF;",
4
+ "sourcesContent": ["import { SelectControl } from '@wordpress/components';\nimport { __, _x } from '@wordpress/i18n';\nimport { useSettings } from '../use-settings';\nimport { InheritanceToolsPanelItem } from '../global-styles/inheritance';\nimport { findAspectRatioOption } from './utils';\n\n/**\n * @typedef {import('@wordpress/components/build-types/select-control/types').SelectControlProps} SelectControlProps\n */\n\n/**\n * @callback AspectRatioToolPropsOnChange\n * @param {string} [value] New aspect ratio value.\n * @return {void} No return.\n */\n\n/**\n * @typedef {Object} AspectRatioToolProps\n * @property {string} [panelId] ID of the panel this tool is associated with.\n * @property {string} [value] Current aspect ratio value.\n * @property {AspectRatioToolPropsOnChange} [onChange] Callback to update the aspect ratio value.\n * @property {SelectControlProps[]} [options] Aspect ratio options.\n * @property {string} [defaultValue] Default aspect ratio value.\n * @property {boolean} [isShownByDefault] Whether the tool is shown by default.\n * @property {string} [className] Additional CSS class on the wrapping panel item.\n * @property {boolean} [isInherited] Whether the control is displaying an inherited Global Styles value.\n * @property {boolean} [hasLocalOverride] Whether a local value is overriding an inherited Global Styles value.\n */\n\nexport default function AspectRatioTool( {\n\tpanelId,\n\tvalue,\n\tonChange = () => {},\n\toptions,\n\tdefaultValue = 'auto',\n\thasValue,\n\tisShownByDefault = true,\n\tclassName,\n\tisInherited,\n\thasLocalOverride,\n} ) {\n\tconst [ defaultRatios, themeRatios, showDefaultRatios ] = useSettings(\n\t\t'dimensions.aspectRatios.default',\n\t\t'dimensions.aspectRatios.theme',\n\t\t'dimensions.defaultAspectRatios'\n\t);\n\n\tconst themeOptions = themeRatios?.map( ( { name, ratio } ) => ( {\n\t\tlabel: name,\n\t\tvalue: ratio,\n\t} ) );\n\n\tconst defaultOptions = defaultRatios?.map( ( { name, ratio } ) => ( {\n\t\tlabel: name,\n\t\tvalue: ratio,\n\t} ) );\n\n\tconst aspectRatioOptions = [\n\t\t{\n\t\t\tlabel: _x(\n\t\t\t\t'Original',\n\t\t\t\t'Aspect ratio option for dimensions control'\n\t\t\t),\n\t\t\tvalue: 'auto',\n\t\t},\n\t\t...( showDefaultRatios ? defaultOptions : [] ),\n\t\t...( themeOptions ? themeOptions : [] ),\n\t\t{\n\t\t\tlabel: _x( 'Custom', 'Aspect ratio option for dimensions control' ),\n\t\t\tvalue: 'custom',\n\t\t\tdisabled: true,\n\t\t\thidden: true,\n\t\t},\n\t];\n\n\tconst resolvedOptions = options ?? aspectRatioOptions;\n\n\t// The value is free-form CSS, so it doesn't necessarily match an option as\n\t// written, e.g. '1/1' and '1' describe the same ratio. Resolve it to the\n\t// option that represents it, falling back to 'custom' so that a ratio\n\t// without a matching preset isn't displayed as one of the presets. Values\n\t// that are empty match the CSS default, so if the value is used directly in\n\t// CSS it will look correct in the control.\n\tconst displayValue =\n\t\tvalue === undefined || value === null || value === 'auto'\n\t\t\t? 'auto'\n\t\t\t: findAspectRatioOption( value, resolvedOptions )?.value ??\n\t\t\t 'custom';\n\n\treturn (\n\t\t<InheritanceToolsPanelItem\n\t\t\tclassName={ className }\n\t\t\tisInherited={ isInherited }\n\t\t\thasLocalOverride={ hasLocalOverride }\n\t\t\thasValue={\n\t\t\t\thasValue ? hasValue : () => displayValue !== defaultValue\n\t\t\t}\n\t\t\tlabel={ __( 'Aspect ratio' ) }\n\t\t\tonDeselect={ () => onChange( undefined ) }\n\t\t\tisShownByDefault={ isShownByDefault }\n\t\t\tpanelId={ panelId }\n\t\t>\n\t\t\t<SelectControl\n\t\t\t\tlabel={ __( 'Aspect ratio' ) }\n\t\t\t\tvalue={ displayValue }\n\t\t\t\toptions={ resolvedOptions }\n\t\t\t\tonChange={ onChange }\n\t\t\t/>\n\t\t</InheritanceToolsPanelItem>\n\t);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAA8B;AAC9B,kBAAuB;AACvB,0BAA4B;AAC5B,yBAA0C;AAC1C,mBAAsC;AAkGnC;AAzEY,SAAR,gBAAkC;AAAA,EACxC;AAAA,EACA;AAAA,EACA,WAAW,MAAM;AAAA,EAAC;AAAA,EAClB;AAAA,EACA,eAAe;AAAA,EACf;AAAA,EACA,mBAAmB;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AACD,GAAI;AACH,QAAM,CAAE,eAAe,aAAa,iBAAkB,QAAI;AAAA,IACzD;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAEA,QAAM,eAAe,aAAa,IAAK,CAAE,EAAE,MAAM,MAAM,OAAS;AAAA,IAC/D,OAAO;AAAA,IACP,OAAO;AAAA,EACR,EAAI;AAEJ,QAAM,iBAAiB,eAAe,IAAK,CAAE,EAAE,MAAM,MAAM,OAAS;AAAA,IACnE,OAAO;AAAA,IACP,OAAO;AAAA,EACR,EAAI;AAEJ,QAAM,qBAAqB;AAAA,IAC1B;AAAA,MACC,WAAO;AAAA,QACN;AAAA,QACA;AAAA,MACD;AAAA,MACA,OAAO;AAAA,IACR;AAAA,IACA,GAAK,oBAAoB,iBAAiB,CAAC;AAAA,IAC3C,GAAK,eAAe,eAAe,CAAC;AAAA,IACpC;AAAA,MACC,WAAO,gBAAI,UAAU,4CAA6C;AAAA,MAClE,OAAO;AAAA,MACP,UAAU;AAAA,MACV,QAAQ;AAAA,IACT;AAAA,EACD;AAEA,QAAM,kBAAkB,WAAW;AAQnC,QAAM,eACL,UAAU,UAAa,UAAU,QAAQ,UAAU,SAChD,aACA,oCAAuB,OAAO,eAAgB,GAAG,SACjD;AAEJ,SACC;AAAA,IAAC;AAAA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,UACC,WAAW,WAAW,MAAM,iBAAiB;AAAA,MAE9C,WAAQ,gBAAI,cAAe;AAAA,MAC3B,YAAa,MAAM,SAAU,MAAU;AAAA,MACvC;AAAA,MACA;AAAA,MAEA;AAAA,QAAC;AAAA;AAAA,UACA,WAAQ,gBAAI,cAAe;AAAA,UAC3B,OAAQ;AAAA,UACR,SAAU;AAAA,UACV;AAAA;AAAA,MACD;AAAA;AAAA,EACD;AAEF;",
6
6
  "names": []
7
7
  }
@@ -58,9 +58,19 @@ function DimensionsTool({
58
58
  const height = value.height === void 0 || value.height === "auto" ? null : value.height;
59
59
  const aspectRatio = value.aspectRatio === void 0 || value.aspectRatio === "auto" ? null : value.aspectRatio;
60
60
  const scale = value.scale === void 0 ? null : value.scale;
61
- const [lastScale, setLastScale] = (0, import_element.useState)(scale);
62
- const [lastAspectRatio, setLastAspectRatio] = (0, import_element.useState)(aspectRatio);
63
61
  const hasCustomAspectRatio = !!(width && height);
62
+ const lastScaleRef = (0, import_element.useRef)(scale);
63
+ const lastAspectRatioRef = (0, import_element.useRef)(aspectRatio);
64
+ (0, import_element.useEffect)(() => {
65
+ if (scale) {
66
+ lastScaleRef.current = scale;
67
+ }
68
+ }, [scale]);
69
+ (0, import_element.useEffect)(() => {
70
+ if (!hasCustomAspectRatio) {
71
+ lastAspectRatioRef.current = aspectRatio;
72
+ }
73
+ }, [aspectRatio, hasCustomAspectRatio]);
64
74
  const aspectRatioValue = hasCustomAspectRatio ? "custom" : aspectRatio;
65
75
  const showScaleControl = aspectRatio || width && height;
66
76
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
@@ -74,7 +84,6 @@ function DimensionsTool({
74
84
  onChange: (nextAspectRatio) => {
75
85
  const nextValue = { ...value };
76
86
  nextAspectRatio = nextAspectRatio === "auto" ? null : nextAspectRatio;
77
- setLastAspectRatio(nextAspectRatio);
78
87
  if (!nextAspectRatio) {
79
88
  delete nextValue.aspectRatio;
80
89
  } else {
@@ -82,11 +91,8 @@ function DimensionsTool({
82
91
  }
83
92
  if (!nextAspectRatio) {
84
93
  delete nextValue.scale;
85
- } else if (lastScale) {
86
- nextValue.scale = lastScale;
87
94
  } else {
88
- nextValue.scale = defaultScale;
89
- setLastScale(defaultScale);
95
+ nextValue.scale = lastScaleRef.current ?? defaultScale;
90
96
  }
91
97
  if ("custom" !== nextAspectRatio && width && height) {
92
98
  delete nextValue.height;
@@ -117,17 +123,14 @@ function DimensionsTool({
117
123
  }
118
124
  if (nextWidth && nextHeight) {
119
125
  delete nextValue.aspectRatio;
120
- } else if (lastAspectRatio) {
121
- nextValue.aspectRatio = lastAspectRatio;
126
+ } else if (lastAspectRatioRef.current) {
127
+ nextValue.aspectRatio = lastAspectRatioRef.current;
122
128
  } else {
123
129
  }
124
- if (!lastAspectRatio && !!nextWidth !== !!nextHeight) {
130
+ if (!lastAspectRatioRef.current && !!nextWidth !== !!nextHeight) {
125
131
  delete nextValue.scale;
126
- } else if (lastScale) {
127
- nextValue.scale = lastScale;
128
132
  } else {
129
- nextValue.scale = defaultScale;
130
- setLastScale(defaultScale);
133
+ nextValue.scale = lastScaleRef.current ?? defaultScale;
131
134
  }
132
135
  onChange(nextValue);
133
136
  }
@@ -139,10 +142,9 @@ function DimensionsTool({
139
142
  panelId,
140
143
  options: scaleOptions,
141
144
  defaultValue: defaultScale,
142
- value: lastScale,
145
+ value: scale,
143
146
  onChange: (nextScale) => {
144
147
  const nextValue = { ...value };
145
- setLastScale(nextScale);
146
148
  if (!nextScale) {
147
149
  delete nextValue.scale;
148
150
  } else {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/dimensions-tool/index.js"],
4
- "sourcesContent": ["import { useState } from '@wordpress/element';\nimport AspectRatioTool from './aspect-ratio-tool';\nimport ScaleTool from './scale-tool';\nimport WidthHeightTool from './width-height-tool';\n\n/**\n * @typedef {import('@wordpress/components/build-types/select-control/types').SelectControlProps} SelectControlProps\n */\n\n/**\n * @typedef {import('@wordpress/components/build-types/unit-control/types').WPUnitControlUnit} WPUnitControlUnit\n */\n\n/**\n * @typedef {Object} Dimensions\n * @property {string} [width] CSS width property.\n * @property {string} [height] CSS height property.\n * @property {string} [scale] CSS object-fit property.\n * @property {string} [aspectRatio] CSS aspect-ratio property.\n */\n\n/**\n * @callback DimensionsControlsOnChange\n * @param {Dimensions} nextValue\n * @return {void}\n */\n\n/**\n * @typedef {Object} DimensionsControlsProps\n * @property {string} [panelId] ID of the panel that contains the controls.\n * @property {Dimensions} [value] Current dimensions values.\n * @property {DimensionsControlsOnChange} [onChange] Callback to update the dimensions values.\n * @property {SelectControlProps[]} [aspectRatioOptions] Aspect ratio options.\n * @property {SelectControlProps[]} [scaleOptions] Scale options.\n * @property {WPUnitControlUnit[]} [unitsOptions] Units options.\n */\n\n/**\n * Component that renders controls to edit the dimensions of an image or container.\n *\n * @param {DimensionsControlsProps} props The component props.\n *\n * @return {Element} The dimensions controls.\n */\nfunction DimensionsTool( {\n\tpanelId,\n\tvalue = {},\n\tonChange = () => {},\n\taspectRatioOptions, // Default options handled by AspectRatioTool.\n\tdefaultAspectRatio = 'auto', // Match CSS default value for aspect-ratio.\n\tscaleOptions, // Default options handled by ScaleTool.\n\tdefaultScale = 'cover',\n\tunitsOptions, // Default options handled by UnitControl.\n\ttools = [ 'aspectRatio', 'widthHeight', 'scale' ],\n} ) {\n\t// Coerce undefined and CSS default values to be null.\n\tconst width =\n\t\tvalue.width === undefined || value.width === 'auto'\n\t\t\t? null\n\t\t\t: value.width;\n\tconst height =\n\t\tvalue.height === undefined || value.height === 'auto'\n\t\t\t? null\n\t\t\t: value.height;\n\tconst aspectRatio =\n\t\tvalue.aspectRatio === undefined || value.aspectRatio === 'auto'\n\t\t\t? null\n\t\t\t: value.aspectRatio;\n\tconst scale = value.scale === undefined ? null : value.scale;\n\n\t// Keep track of state internally, so when the value is cleared by means\n\t// other than directly editing that field, it's easier to restore the\n\t// previous value.\n\tconst [ lastScale, setLastScale ] = useState( scale );\n\tconst [ lastAspectRatio, setLastAspectRatio ] = useState( aspectRatio );\n\tconst hasCustomAspectRatio = !! ( width && height );\n\n\t// 'custom' is not a valid value for CSS aspect-ratio, but it is used in the\n\t// dropdown to indicate that setting both the width and height is the same\n\t// as a custom aspect ratio.\n\tconst aspectRatioValue = hasCustomAspectRatio ? 'custom' : aspectRatio;\n\n\tconst showScaleControl = aspectRatio || ( width && height );\n\n\treturn (\n\t\t<>\n\t\t\t{ tools.includes( 'aspectRatio' ) && (\n\t\t\t\t<AspectRatioTool\n\t\t\t\t\tpanelId={ panelId }\n\t\t\t\t\toptions={ aspectRatioOptions }\n\t\t\t\t\tdefaultValue={ defaultAspectRatio }\n\t\t\t\t\tvalue={ aspectRatioValue }\n\t\t\t\t\tonChange={ ( nextAspectRatio ) => {\n\t\t\t\t\t\tconst nextValue = { ...value };\n\n\t\t\t\t\t\t// 'auto' is CSS default, so it gets treated as null.\n\t\t\t\t\t\tnextAspectRatio =\n\t\t\t\t\t\t\tnextAspectRatio === 'auto' ? null : nextAspectRatio;\n\n\t\t\t\t\t\tsetLastAspectRatio( nextAspectRatio );\n\n\t\t\t\t\t\t// Update aspectRatio.\n\t\t\t\t\t\tif ( ! nextAspectRatio ) {\n\t\t\t\t\t\t\tdelete nextValue.aspectRatio;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tnextValue.aspectRatio = nextAspectRatio;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Auto-update scale.\n\t\t\t\t\t\tif ( ! nextAspectRatio ) {\n\t\t\t\t\t\t\tdelete nextValue.scale;\n\t\t\t\t\t\t} else if ( lastScale ) {\n\t\t\t\t\t\t\tnextValue.scale = lastScale;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tnextValue.scale = defaultScale;\n\t\t\t\t\t\t\tsetLastScale( defaultScale );\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Auto-update width and height.\n\t\t\t\t\t\tif ( 'custom' !== nextAspectRatio && width && height ) {\n\t\t\t\t\t\t\tdelete nextValue.height;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tonChange( nextValue );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ tools.includes( 'widthHeight' ) && (\n\t\t\t\t<WidthHeightTool\n\t\t\t\t\tpanelId={ panelId }\n\t\t\t\t\tunits={ unitsOptions }\n\t\t\t\t\tvalue={ { width, height } }\n\t\t\t\t\tonChange={ ( { width: nextWidth, height: nextHeight } ) => {\n\t\t\t\t\t\tconst nextValue = { ...value };\n\n\t\t\t\t\t\t// 'auto' is CSS default, so it gets treated as null.\n\t\t\t\t\t\tnextWidth = nextWidth === 'auto' ? null : nextWidth;\n\t\t\t\t\t\tnextHeight = nextHeight === 'auto' ? null : nextHeight;\n\n\t\t\t\t\t\t// Update width.\n\t\t\t\t\t\tif ( ! nextWidth ) {\n\t\t\t\t\t\t\tdelete nextValue.width;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tnextValue.width = nextWidth;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Update height.\n\t\t\t\t\t\tif ( ! nextHeight ) {\n\t\t\t\t\t\t\tdelete nextValue.height;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tnextValue.height = nextHeight;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Auto-update aspectRatio.\n\t\t\t\t\t\tif ( nextWidth && nextHeight ) {\n\t\t\t\t\t\t\tdelete nextValue.aspectRatio;\n\t\t\t\t\t\t} else if ( lastAspectRatio ) {\n\t\t\t\t\t\t\tnextValue.aspectRatio = lastAspectRatio;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// No setting defaultAspectRatio here, because\n\t\t\t\t\t\t\t// aspectRatio is optional in this scenario,\n\t\t\t\t\t\t\t// unlike scale.\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Auto-update scale.\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t! lastAspectRatio &&\n\t\t\t\t\t\t\t!! nextWidth !== !! nextHeight\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tdelete nextValue.scale;\n\t\t\t\t\t\t} else if ( lastScale ) {\n\t\t\t\t\t\t\tnextValue.scale = lastScale;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tnextValue.scale = defaultScale;\n\t\t\t\t\t\t\tsetLastScale( defaultScale );\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tonChange( nextValue );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ tools.includes( 'scale' ) && showScaleControl && (\n\t\t\t\t<ScaleTool\n\t\t\t\t\tpanelId={ panelId }\n\t\t\t\t\toptions={ scaleOptions }\n\t\t\t\t\tdefaultValue={ defaultScale }\n\t\t\t\t\tvalue={ lastScale }\n\t\t\t\t\tonChange={ ( nextScale ) => {\n\t\t\t\t\t\tconst nextValue = { ...value };\n\n\t\t\t\t\t\tsetLastScale( nextScale );\n\n\t\t\t\t\t\t// Update scale.\n\t\t\t\t\t\tif ( ! nextScale ) {\n\t\t\t\t\t\t\tdelete nextValue.scale;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tnextValue.scale = nextScale;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tonChange( nextValue );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default DimensionsTool;\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAA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,EAAE,GAAG,MAAM;AAE7B,uBAAc,SAAU;AAGxB,cAAK,CAAE,WAAY;AAClB,mBAAO,UAAU;AAAA,UAClB,OAAO;AACN,sBAAU,QAAQ;AAAA,UACnB;AAEA,mBAAU,SAAU;AAAA,QACrB;AAAA;AAAA,IACD;AAAA,KAEF;AAEF;AAEA,IAAO,0BAAQ;",
4
+ "sourcesContent": ["import { useEffect, useRef } from '@wordpress/element';\nimport AspectRatioTool from './aspect-ratio-tool';\nimport ScaleTool from './scale-tool';\nimport WidthHeightTool from './width-height-tool';\n\n/**\n * @typedef {import('@wordpress/components/build-types/select-control/types').SelectControlProps} SelectControlProps\n */\n\n/**\n * @typedef {import('@wordpress/components/build-types/unit-control/types').WPUnitControlUnit} WPUnitControlUnit\n */\n\n/**\n * @typedef {Object} Dimensions\n * @property {string} [width] CSS width property.\n * @property {string} [height] CSS height property.\n * @property {string} [scale] CSS object-fit property.\n * @property {string} [aspectRatio] CSS aspect-ratio property.\n */\n\n/**\n * @callback DimensionsControlsOnChange\n * @param {Dimensions} nextValue\n * @return {void}\n */\n\n/**\n * @typedef {Object} DimensionsControlsProps\n * @property {string} [panelId] ID of the panel that contains the controls.\n * @property {Dimensions} [value] Current dimensions values.\n * @property {DimensionsControlsOnChange} [onChange] Callback to update the dimensions values.\n * @property {SelectControlProps[]} [aspectRatioOptions] Aspect ratio options.\n * @property {SelectControlProps[]} [scaleOptions] Scale options.\n * @property {WPUnitControlUnit[]} [unitsOptions] Units options.\n */\n\n/**\n * Component that renders controls to edit the dimensions of an image or container.\n *\n * @param {DimensionsControlsProps} props The component props.\n *\n * @return {Element} The dimensions controls.\n */\nfunction DimensionsTool( {\n\tpanelId,\n\tvalue = {},\n\tonChange = () => {},\n\taspectRatioOptions, // Default options handled by AspectRatioTool.\n\tdefaultAspectRatio = 'auto', // Match CSS default value for aspect-ratio.\n\tscaleOptions, // Default options handled by ScaleTool.\n\tdefaultScale = 'cover',\n\tunitsOptions, // Default options handled by UnitControl.\n\ttools = [ 'aspectRatio', 'widthHeight', 'scale' ],\n} ) {\n\t// Coerce undefined and CSS default values to be null.\n\tconst width =\n\t\tvalue.width === undefined || value.width === 'auto'\n\t\t\t? null\n\t\t\t: value.width;\n\tconst height =\n\t\tvalue.height === undefined || value.height === 'auto'\n\t\t\t? null\n\t\t\t: value.height;\n\tconst aspectRatio =\n\t\tvalue.aspectRatio === undefined || value.aspectRatio === 'auto'\n\t\t\t? null\n\t\t\t: value.aspectRatio;\n\tconst scale = value.scale === undefined ? null : value.scale;\n\n\tconst hasCustomAspectRatio = !! ( width && height );\n\n\t// Keep track of the previous values, so when a value is cleared by means\n\t// other than directly editing that field, it's easier to restore it. These\n\t// are only ever read while handling a change, so they're kept in refs and\n\t// synced from the value to stay correct when it is updated externally, e.g.\n\t// by undo or by another client.\n\tconst lastScaleRef = useRef( scale );\n\tconst lastAspectRatioRef = useRef( aspectRatio );\n\n\tuseEffect( () => {\n\t\t// Scale is cleared alongside the aspect ratio, so only remember the\n\t\t// values it is actually set to.\n\t\tif ( scale ) {\n\t\t\tlastScaleRef.current = scale;\n\t\t}\n\t}, [ scale ] );\n\n\tuseEffect( () => {\n\t\t// A custom aspect ratio, i.e. both a width and a height, clears the\n\t\t// aspect ratio value. Keep the remembered one so it can be restored\n\t\t// once the custom aspect ratio is removed.\n\t\tif ( ! hasCustomAspectRatio ) {\n\t\t\tlastAspectRatioRef.current = aspectRatio;\n\t\t}\n\t}, [ aspectRatio, hasCustomAspectRatio ] );\n\n\t// 'custom' is not a valid value for CSS aspect-ratio, but it is used in the\n\t// dropdown to indicate that setting both the width and height is the same\n\t// as a custom aspect ratio.\n\tconst aspectRatioValue = hasCustomAspectRatio ? 'custom' : aspectRatio;\n\n\tconst showScaleControl = aspectRatio || ( width && height );\n\n\treturn (\n\t\t<>\n\t\t\t{ tools.includes( 'aspectRatio' ) && (\n\t\t\t\t<AspectRatioTool\n\t\t\t\t\tpanelId={ panelId }\n\t\t\t\t\toptions={ aspectRatioOptions }\n\t\t\t\t\tdefaultValue={ defaultAspectRatio }\n\t\t\t\t\tvalue={ aspectRatioValue }\n\t\t\t\t\tonChange={ ( nextAspectRatio ) => {\n\t\t\t\t\t\tconst nextValue = { ...value };\n\n\t\t\t\t\t\t// 'auto' is CSS default, so it gets treated as null.\n\t\t\t\t\t\tnextAspectRatio =\n\t\t\t\t\t\t\tnextAspectRatio === 'auto' ? null : nextAspectRatio;\n\n\t\t\t\t\t\t// Update aspectRatio.\n\t\t\t\t\t\tif ( ! nextAspectRatio ) {\n\t\t\t\t\t\t\tdelete nextValue.aspectRatio;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tnextValue.aspectRatio = nextAspectRatio;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Auto-update scale.\n\t\t\t\t\t\tif ( ! nextAspectRatio ) {\n\t\t\t\t\t\t\tdelete nextValue.scale;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tnextValue.scale =\n\t\t\t\t\t\t\t\tlastScaleRef.current ?? defaultScale;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Auto-update width and height.\n\t\t\t\t\t\tif ( 'custom' !== nextAspectRatio && width && height ) {\n\t\t\t\t\t\t\tdelete nextValue.height;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tonChange( nextValue );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ tools.includes( 'widthHeight' ) && (\n\t\t\t\t<WidthHeightTool\n\t\t\t\t\tpanelId={ panelId }\n\t\t\t\t\tunits={ unitsOptions }\n\t\t\t\t\tvalue={ { width, height } }\n\t\t\t\t\tonChange={ ( { width: nextWidth, height: nextHeight } ) => {\n\t\t\t\t\t\tconst nextValue = { ...value };\n\n\t\t\t\t\t\t// 'auto' is CSS default, so it gets treated as null.\n\t\t\t\t\t\tnextWidth = nextWidth === 'auto' ? null : nextWidth;\n\t\t\t\t\t\tnextHeight = nextHeight === 'auto' ? null : nextHeight;\n\n\t\t\t\t\t\t// Update width.\n\t\t\t\t\t\tif ( ! nextWidth ) {\n\t\t\t\t\t\t\tdelete nextValue.width;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tnextValue.width = nextWidth;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Update height.\n\t\t\t\t\t\tif ( ! nextHeight ) {\n\t\t\t\t\t\t\tdelete nextValue.height;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tnextValue.height = nextHeight;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Auto-update aspectRatio.\n\t\t\t\t\t\tif ( nextWidth && nextHeight ) {\n\t\t\t\t\t\t\tdelete nextValue.aspectRatio;\n\t\t\t\t\t\t} else if ( lastAspectRatioRef.current ) {\n\t\t\t\t\t\t\tnextValue.aspectRatio = lastAspectRatioRef.current;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// No setting defaultAspectRatio here, because\n\t\t\t\t\t\t\t// aspectRatio is optional in this scenario,\n\t\t\t\t\t\t\t// unlike scale.\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Auto-update scale.\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t! lastAspectRatioRef.current &&\n\t\t\t\t\t\t\t!! nextWidth !== !! nextHeight\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tdelete nextValue.scale;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tnextValue.scale =\n\t\t\t\t\t\t\t\tlastScaleRef.current ?? defaultScale;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tonChange( nextValue );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ tools.includes( 'scale' ) && showScaleControl && (\n\t\t\t\t<ScaleTool\n\t\t\t\t\tpanelId={ panelId }\n\t\t\t\t\toptions={ scaleOptions }\n\t\t\t\t\tdefaultValue={ defaultScale }\n\t\t\t\t\tvalue={ scale }\n\t\t\t\t\tonChange={ ( nextScale ) => {\n\t\t\t\t\t\tconst nextValue = { ...value };\n\n\t\t\t\t\t\t// Update scale.\n\t\t\t\t\t\tif ( ! nextScale ) {\n\t\t\t\t\t\t\tdelete nextValue.scale;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tnextValue.scale = nextScale;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tonChange( nextValue );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default DimensionsTool;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAkC;AAClC,+BAA4B;AAC5B,wBAAsB;AACtB,+BAA4B;AAsG1B;AA7DF,SAAS,eAAgB;AAAA,EACxB;AAAA,EACA,QAAQ,CAAC;AAAA,EACT,WAAW,MAAM;AAAA,EAAC;AAAA,EAClB;AAAA;AAAA,EACA,qBAAqB;AAAA;AAAA,EACrB;AAAA;AAAA,EACA,eAAe;AAAA,EACf;AAAA;AAAA,EACA,QAAQ,CAAE,eAAe,eAAe,OAAQ;AACjD,GAAI;AAEH,QAAM,QACL,MAAM,UAAU,UAAa,MAAM,UAAU,SAC1C,OACA,MAAM;AACV,QAAM,SACL,MAAM,WAAW,UAAa,MAAM,WAAW,SAC5C,OACA,MAAM;AACV,QAAM,cACL,MAAM,gBAAgB,UAAa,MAAM,gBAAgB,SACtD,OACA,MAAM;AACV,QAAM,QAAQ,MAAM,UAAU,SAAY,OAAO,MAAM;AAEvD,QAAM,uBAAuB,CAAC,EAAI,SAAS;AAO3C,QAAM,mBAAe,uBAAQ,KAAM;AACnC,QAAM,yBAAqB,uBAAQ,WAAY;AAE/C,gCAAW,MAAM;AAGhB,QAAK,OAAQ;AACZ,mBAAa,UAAU;AAAA,IACxB;AAAA,EACD,GAAG,CAAE,KAAM,CAAE;AAEb,gCAAW,MAAM;AAIhB,QAAK,CAAE,sBAAuB;AAC7B,yBAAmB,UAAU;AAAA,IAC9B;AAAA,EACD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AACxC,sBAAU,cAAc,mBAAmB;AAAA,UAC5C,OAAO;AAAA,UAIP;AAGA,cACC,CAAE,mBAAmB,WACrB,CAAC,CAAE,cAAc,CAAC,CAAE,YACnB;AACD,mBAAO,UAAU;AAAA,UAClB,OAAO;AACN,sBAAU,QACT,aAAa,WAAW;AAAA,UAC1B;AAEA,mBAAU,SAAU;AAAA,QACrB;AAAA;AAAA,IACD;AAAA,IAEC,MAAM,SAAU,OAAQ,KAAK,oBAC9B;AAAA,MAAC,kBAAAC;AAAA,MAAA;AAAA,QACA;AAAA,QACA,SAAU;AAAA,QACV,cAAe;AAAA,QACf,OAAQ;AAAA,QACR,UAAW,CAAE,cAAe;AAC3B,gBAAM,YAAY,EAAE,GAAG,MAAM;AAG7B,cAAK,CAAE,WAAY;AAClB,mBAAO,UAAU;AAAA,UAClB,OAAO;AACN,sBAAU,QAAQ;AAAA,UACnB;AAEA,mBAAU,SAAU;AAAA,QACrB;AAAA;AAAA,IACD;AAAA,KAEF;AAEF;AAEA,IAAO,0BAAQ;",
6
6
  "names": ["AspectRatioTool", "WidthHeightTool", "ScaleTool"]
7
7
  }
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // packages/block-editor/src/components/dimensions-tool/utils.js
21
+ var utils_exports = {};
22
+ __export(utils_exports, {
23
+ findAspectRatioOption: () => findAspectRatioOption,
24
+ parseAspectRatio: () => parseAspectRatio
25
+ });
26
+ module.exports = __toCommonJS(utils_exports);
27
+ function parseAspectRatio(value) {
28
+ if (typeof value !== "string") {
29
+ return null;
30
+ }
31
+ const parts = value.split("/");
32
+ if (parts.length > 2) {
33
+ return null;
34
+ }
35
+ const [width, height = "1"] = parts;
36
+ const numericWidth = Number(width.trim());
37
+ const numericHeight = Number(height.trim());
38
+ if (!Number.isFinite(numericWidth) || !Number.isFinite(numericHeight) || numericWidth <= 0 || numericHeight <= 0) {
39
+ return null;
40
+ }
41
+ return numericWidth / numericHeight;
42
+ }
43
+ function findAspectRatioOption(value, options) {
44
+ const exactMatch = options.find((option) => option.value === value);
45
+ if (exactMatch) {
46
+ return exactMatch;
47
+ }
48
+ const ratio = parseAspectRatio(value);
49
+ if (ratio === null) {
50
+ return null;
51
+ }
52
+ return options.find(
53
+ (option) => parseAspectRatio(option.value) === ratio
54
+ ) ?? null;
55
+ }
56
+ // Annotate the CommonJS export names for ESM import in node:
57
+ 0 && (module.exports = {
58
+ findAspectRatioOption,
59
+ parseAspectRatio
60
+ });
61
+ //# sourceMappingURL=utils.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/dimensions-tool/utils.js"],
4
+ "sourcesContent": ["/**\n * Parses a CSS `aspect-ratio` value into a number so that values that are\n * written differently but describe the same ratio, e.g. `1` and `1/1`, can be\n * compared.\n *\n * @param {string} [value] CSS aspect-ratio value, e.g. '16/9' or '1.5'.\n *\n * @return {?number} The ratio as a number, or null when it cannot be parsed.\n */\nexport function parseAspectRatio( value ) {\n\tif ( typeof value !== 'string' ) {\n\t\treturn null;\n\t}\n\n\tconst parts = value.split( '/' );\n\n\tif ( parts.length > 2 ) {\n\t\treturn null;\n\t}\n\n\tconst [ width, height = '1' ] = parts;\n\tconst numericWidth = Number( width.trim() );\n\tconst numericHeight = Number( height.trim() );\n\n\tif (\n\t\t! Number.isFinite( numericWidth ) ||\n\t\t! Number.isFinite( numericHeight ) ||\n\t\tnumericWidth <= 0 ||\n\t\tnumericHeight <= 0\n\t) {\n\t\treturn null;\n\t}\n\n\treturn numericWidth / numericHeight;\n}\n\n/**\n * Finds the option that represents the given CSS `aspect-ratio` value.\n *\n * Aspect ratio values are free-form CSS, while the options are a fixed list of\n * presets, so an exact string match isn't enough: `1/1` and `1` describe the\n * same ratio but only one of them is a preset value.\n *\n * @param {string} value CSS aspect-ratio value.\n * @param {Object[]} options Aspect ratio options.\n *\n * @return {?Object} The matching option, or null when there is none.\n */\nexport function findAspectRatioOption( value, options ) {\n\tconst exactMatch = options.find( ( option ) => option.value === value );\n\n\tif ( exactMatch ) {\n\t\treturn exactMatch;\n\t}\n\n\tconst ratio = parseAspectRatio( value );\n\n\tif ( ratio === null ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\toptions.find(\n\t\t\t( option ) => parseAspectRatio( option.value ) === ratio\n\t\t) ?? null\n\t);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASO,SAAS,iBAAkB,OAAQ;AACzC,MAAK,OAAO,UAAU,UAAW;AAChC,WAAO;AAAA,EACR;AAEA,QAAM,QAAQ,MAAM,MAAO,GAAI;AAE/B,MAAK,MAAM,SAAS,GAAI;AACvB,WAAO;AAAA,EACR;AAEA,QAAM,CAAE,OAAO,SAAS,GAAI,IAAI;AAChC,QAAM,eAAe,OAAQ,MAAM,KAAK,CAAE;AAC1C,QAAM,gBAAgB,OAAQ,OAAO,KAAK,CAAE;AAE5C,MACC,CAAE,OAAO,SAAU,YAAa,KAChC,CAAE,OAAO,SAAU,aAAc,KACjC,gBAAgB,KAChB,iBAAiB,GAChB;AACD,WAAO;AAAA,EACR;AAEA,SAAO,eAAe;AACvB;AAcO,SAAS,sBAAuB,OAAO,SAAU;AACvD,QAAM,aAAa,QAAQ,KAAM,CAAE,WAAY,OAAO,UAAU,KAAM;AAEtE,MAAK,YAAa;AACjB,WAAO;AAAA,EACR;AAEA,QAAM,QAAQ,iBAAkB,KAAM;AAEtC,MAAK,UAAU,MAAO;AACrB,WAAO;AAAA,EACR;AAEA,SACC,QAAQ;AAAA,IACP,CAAE,WAAY,iBAAkB,OAAO,KAAM,MAAM;AAAA,EACpD,KAAK;AAEP;",
6
+ "names": []
7
+ }
@@ -36,6 +36,7 @@ function DuotoneControl({
36
36
  disableCustomColors,
37
37
  disableCustomDuotone,
38
38
  value,
39
+ selectedSlug,
39
40
  onChange
40
41
  }) {
41
42
  let toolbarIcon;
@@ -90,6 +91,7 @@ function DuotoneControl({
90
91
  disableCustomColors,
91
92
  disableCustomDuotone,
92
93
  value,
94
+ selectedSlug,
93
95
  onChange
94
96
  }
95
97
  )