@wordpress/block-editor 12.5.0 → 12.6.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 (298) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +0 -4
  3. package/build/components/block-draggable/index.js +6 -3
  4. package/build/components/block-draggable/index.js.map +1 -1
  5. package/build/components/block-draggable/index.native.js +2 -2
  6. package/build/components/block-draggable/index.native.js.map +1 -1
  7. package/build/components/block-edit/edit.js +25 -13
  8. package/build/components/block-edit/edit.js.map +1 -1
  9. package/build/components/block-list/block-outline.native.js +14 -18
  10. package/build/components/block-list/block-outline.native.js.map +1 -1
  11. package/build/components/block-list/block.native.js +21 -42
  12. package/build/components/block-list/block.native.js.map +1 -1
  13. package/build/components/block-mover/index.native.js +1 -1
  14. package/build/components/block-mover/index.native.js.map +1 -1
  15. package/build/components/block-removal-warning-modal/index.js +1 -4
  16. package/build/components/block-removal-warning-modal/index.js.map +1 -1
  17. package/build/components/block-settings/button.native.js +2 -2
  18. package/build/components/block-settings/button.native.js.map +1 -1
  19. package/build/components/{block-mobile-toolbar/block-actions-menu.native.js → block-toolbar/block-toolbar-menu.native.js} +7 -5
  20. package/build/components/block-toolbar/block-toolbar-menu.native.js.map +1 -0
  21. package/build/components/block-toolbar/index.js +4 -3
  22. package/build/components/block-toolbar/index.js.map +1 -1
  23. package/build/components/block-toolbar/index.native.js +62 -3
  24. package/build/components/block-toolbar/index.native.js.map +1 -1
  25. package/build/components/colors-gradients/control.js +4 -2
  26. package/build/components/colors-gradients/control.js.map +1 -1
  27. package/build/components/global-styles/color-panel.js +21 -15
  28. package/build/components/global-styles/color-panel.js.map +1 -1
  29. package/build/components/global-styles/dimensions-panel.js +13 -2
  30. package/build/components/global-styles/dimensions-panel.js.map +1 -1
  31. package/build/components/global-styles/get-block-css-selector.js +4 -8
  32. package/build/components/global-styles/get-block-css-selector.js.map +1 -1
  33. package/build/components/global-styles/hooks.js +13 -23
  34. package/build/components/global-styles/hooks.js.map +1 -1
  35. package/build/components/global-styles/typography-panel.js +18 -3
  36. package/build/components/global-styles/typography-panel.js.map +1 -1
  37. package/build/components/global-styles/use-global-styles-output.js +12 -18
  38. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  39. package/build/components/global-styles/utils.js +6 -6
  40. package/build/components/global-styles/utils.js.map +1 -1
  41. package/build/components/iframe/index.js +36 -48
  42. package/build/components/iframe/index.js.map +1 -1
  43. package/build/components/iframe/use-compatibility-styles.js +5 -0
  44. package/build/components/iframe/use-compatibility-styles.js.map +1 -1
  45. package/build/components/index.js +1 -10
  46. package/build/components/index.js.map +1 -1
  47. package/build/components/inner-blocks/index.js +3 -1
  48. package/build/components/inner-blocks/index.js.map +1 -1
  49. package/build/components/inner-blocks/index.native.js +3 -1
  50. package/build/components/inner-blocks/index.native.js.map +1 -1
  51. package/build/components/inner-blocks/use-nested-settings-update.js +33 -7
  52. package/build/components/inner-blocks/use-nested-settings-update.js.map +1 -1
  53. package/build/components/inserter/index.js +2 -4
  54. package/build/components/inserter/index.js.map +1 -1
  55. package/build/components/inserter/index.native.js +21 -32
  56. package/build/components/inserter/index.native.js.map +1 -1
  57. package/build/components/inserter/reusable-block-rename-hint.js +23 -3
  58. package/build/components/inserter/reusable-block-rename-hint.js.map +1 -1
  59. package/build/components/link-control/index.js +4 -1
  60. package/build/components/link-control/index.js.map +1 -1
  61. package/build/components/link-control/search-item.js +1 -1
  62. package/build/components/link-control/search-item.js.map +1 -1
  63. package/build/components/list-view/use-list-view-client-ids.js +2 -2
  64. package/build/components/list-view/use-list-view-client-ids.js.map +1 -1
  65. package/build/components/media-placeholder/index.native.js +65 -31
  66. package/build/components/media-placeholder/index.native.js.map +1 -1
  67. package/build/components/preview-options/index.js +2 -2
  68. package/build/components/preview-options/index.js.map +1 -1
  69. package/build/components/rich-text/content.js +0 -36
  70. package/build/components/rich-text/content.js.map +1 -1
  71. package/build/components/rich-text/get-rich-text-values.js +118 -0
  72. package/build/components/rich-text/get-rich-text-values.js.map +1 -0
  73. package/build/components/spacing-sizes-control/hooks/use-spacing-sizes.js +1 -1
  74. package/build/components/spacing-sizes-control/hooks/use-spacing-sizes.js.map +1 -1
  75. package/build/components/spacing-sizes-control/input-controls/axial.js +6 -2
  76. package/build/components/spacing-sizes-control/input-controls/axial.js.map +1 -1
  77. package/build/components/spacing-sizes-control/input-controls/separated.js +5 -1
  78. package/build/components/spacing-sizes-control/input-controls/separated.js.map +1 -1
  79. package/build/components/spacing-sizes-control/input-controls/single.js +5 -1
  80. package/build/components/spacing-sizes-control/input-controls/single.js.map +1 -1
  81. package/build/components/spacing-sizes-control/utils.js +1 -1
  82. package/build/components/spacing-sizes-control/utils.js.map +1 -1
  83. package/build/components/use-block-display-information/index.js +7 -3
  84. package/build/components/use-block-display-information/index.js.map +1 -1
  85. package/build/components/use-block-drop-zone/index.native.js +49 -8
  86. package/build/components/use-block-drop-zone/index.native.js.map +1 -1
  87. package/build/components/use-setting/index.js +5 -9
  88. package/build/components/use-setting/index.js.map +1 -1
  89. package/build/hooks/margin.js +1 -1
  90. package/build/hooks/margin.js.map +1 -1
  91. package/build/hooks/padding.js +1 -1
  92. package/build/hooks/padding.js.map +1 -1
  93. package/build/hooks/utils.js +1 -7
  94. package/build/hooks/utils.js.map +1 -1
  95. package/build/private-apis.js +7 -3
  96. package/build/private-apis.js.map +1 -1
  97. package/build/store/actions.js +1 -1
  98. package/build/store/actions.js.map +1 -1
  99. package/build/store/private-selectors.js +5 -6
  100. package/build/store/private-selectors.js.map +1 -1
  101. package/build/store/reducer.js +0 -1
  102. package/build/store/reducer.js.map +1 -1
  103. package/build/store/selectors.js +19 -8
  104. package/build/store/selectors.js.map +1 -1
  105. package/build/utils/object.js +38 -2
  106. package/build/utils/object.js.map +1 -1
  107. package/build-module/components/block-draggable/index.js +6 -3
  108. package/build-module/components/block-draggable/index.js.map +1 -1
  109. package/build-module/components/block-draggable/index.native.js +2 -2
  110. package/build-module/components/block-draggable/index.native.js.map +1 -1
  111. package/build-module/components/block-edit/edit.js +27 -10
  112. package/build-module/components/block-edit/edit.js.map +1 -1
  113. package/build-module/components/block-list/block-outline.native.js +14 -18
  114. package/build-module/components/block-list/block-outline.native.js.map +1 -1
  115. package/build-module/components/block-list/block.native.js +24 -43
  116. package/build-module/components/block-list/block.native.js.map +1 -1
  117. package/build-module/components/block-mover/index.native.js +3 -3
  118. package/build-module/components/block-mover/index.native.js.map +1 -1
  119. package/build-module/components/block-removal-warning-modal/index.js +1 -4
  120. package/build-module/components/block-removal-warning-modal/index.js.map +1 -1
  121. package/build-module/components/block-settings/button.native.js +3 -3
  122. package/build-module/components/block-settings/button.native.js.map +1 -1
  123. package/build-module/components/{block-mobile-toolbar/block-actions-menu.native.js → block-toolbar/block-toolbar-menu.native.js} +9 -7
  124. package/build-module/components/block-toolbar/block-toolbar-menu.native.js.map +1 -0
  125. package/build-module/components/block-toolbar/index.js +4 -3
  126. package/build-module/components/block-toolbar/index.js.map +1 -1
  127. package/build-module/components/block-toolbar/index.native.js +60 -4
  128. package/build-module/components/block-toolbar/index.native.js.map +1 -1
  129. package/build-module/components/colors-gradients/control.js +3 -2
  130. package/build-module/components/colors-gradients/control.js.map +1 -1
  131. package/build-module/components/global-styles/color-panel.js +21 -15
  132. package/build-module/components/global-styles/color-panel.js.map +1 -1
  133. package/build-module/components/global-styles/dimensions-panel.js +13 -2
  134. package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
  135. package/build-module/components/global-styles/get-block-css-selector.js +4 -8
  136. package/build-module/components/global-styles/get-block-css-selector.js.map +1 -1
  137. package/build-module/components/global-styles/hooks.js +12 -22
  138. package/build-module/components/global-styles/hooks.js.map +1 -1
  139. package/build-module/components/global-styles/typography-panel.js +18 -3
  140. package/build-module/components/global-styles/typography-panel.js.map +1 -1
  141. package/build-module/components/global-styles/use-global-styles-output.js +13 -18
  142. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  143. package/build-module/components/global-styles/utils.js +5 -5
  144. package/build-module/components/global-styles/utils.js.map +1 -1
  145. package/build-module/components/iframe/index.js +37 -49
  146. package/build-module/components/iframe/index.js.map +1 -1
  147. package/build-module/components/iframe/use-compatibility-styles.js +5 -0
  148. package/build-module/components/iframe/use-compatibility-styles.js.map +1 -1
  149. package/build-module/components/index.js +0 -5
  150. package/build-module/components/index.js.map +1 -1
  151. package/build-module/components/inner-blocks/index.js +3 -1
  152. package/build-module/components/inner-blocks/index.js.map +1 -1
  153. package/build-module/components/inner-blocks/index.native.js +3 -1
  154. package/build-module/components/inner-blocks/index.native.js.map +1 -1
  155. package/build-module/components/inner-blocks/use-nested-settings-update.js +30 -7
  156. package/build-module/components/inner-blocks/use-nested-settings-update.js.map +1 -1
  157. package/build-module/components/inserter/index.js +2 -4
  158. package/build-module/components/inserter/index.js.map +1 -1
  159. package/build-module/components/inserter/index.native.js +22 -33
  160. package/build-module/components/inserter/index.native.js.map +1 -1
  161. package/build-module/components/inserter/reusable-block-rename-hint.js +22 -3
  162. package/build-module/components/inserter/reusable-block-rename-hint.js.map +1 -1
  163. package/build-module/components/link-control/index.js +4 -1
  164. package/build-module/components/link-control/index.js.map +1 -1
  165. package/build-module/components/link-control/search-item.js +1 -1
  166. package/build-module/components/link-control/search-item.js.map +1 -1
  167. package/build-module/components/list-view/use-list-view-client-ids.js +2 -2
  168. package/build-module/components/list-view/use-list-view-client-ids.js.map +1 -1
  169. package/build-module/components/media-placeholder/index.native.js +66 -33
  170. package/build-module/components/media-placeholder/index.native.js.map +1 -1
  171. package/build-module/components/preview-options/index.js +2 -2
  172. package/build-module/components/preview-options/index.js.map +1 -1
  173. package/build-module/components/rich-text/content.js +1 -36
  174. package/build-module/components/rich-text/content.js.map +1 -1
  175. package/build-module/components/rich-text/get-rich-text-values.js +105 -0
  176. package/build-module/components/rich-text/get-rich-text-values.js.map +1 -0
  177. package/build-module/components/spacing-sizes-control/hooks/use-spacing-sizes.js +1 -1
  178. package/build-module/components/spacing-sizes-control/hooks/use-spacing-sizes.js.map +1 -1
  179. package/build-module/components/spacing-sizes-control/input-controls/axial.js +7 -3
  180. package/build-module/components/spacing-sizes-control/input-controls/axial.js.map +1 -1
  181. package/build-module/components/spacing-sizes-control/input-controls/separated.js +6 -2
  182. package/build-module/components/spacing-sizes-control/input-controls/separated.js.map +1 -1
  183. package/build-module/components/spacing-sizes-control/input-controls/single.js +6 -2
  184. package/build-module/components/spacing-sizes-control/input-controls/single.js.map +1 -1
  185. package/build-module/components/spacing-sizes-control/utils.js +1 -1
  186. package/build-module/components/spacing-sizes-control/utils.js.map +1 -1
  187. package/build-module/components/use-block-display-information/index.js +7 -3
  188. package/build-module/components/use-block-display-information/index.js.map +1 -1
  189. package/build-module/components/use-block-drop-zone/index.native.js +50 -8
  190. package/build-module/components/use-block-drop-zone/index.native.js.map +1 -1
  191. package/build-module/components/use-setting/index.js +5 -9
  192. package/build-module/components/use-setting/index.js.map +1 -1
  193. package/build-module/hooks/margin.js +1 -1
  194. package/build-module/hooks/margin.js.map +1 -1
  195. package/build-module/hooks/padding.js +1 -1
  196. package/build-module/hooks/padding.js.map +1 -1
  197. package/build-module/hooks/utils.js +2 -7
  198. package/build-module/hooks/utils.js.map +1 -1
  199. package/build-module/private-apis.js +5 -2
  200. package/build-module/private-apis.js.map +1 -1
  201. package/build-module/store/actions.js +2 -2
  202. package/build-module/store/actions.js.map +1 -1
  203. package/build-module/store/private-selectors.js +3 -3
  204. package/build-module/store/private-selectors.js.map +1 -1
  205. package/build-module/store/reducer.js +0 -1
  206. package/build-module/store/reducer.js.map +1 -1
  207. package/build-module/store/selectors.js +16 -6
  208. package/build-module/store/selectors.js.map +1 -1
  209. package/build-module/utils/object.js +34 -2
  210. package/build-module/utils/object.js.map +1 -1
  211. package/build-style/content-rtl.css +2 -1
  212. package/build-style/content.css +2 -1
  213. package/build-style/style-rtl.css +7 -1
  214. package/build-style/style.css +7 -1
  215. package/package.json +32 -32
  216. package/src/components/block-controls/README.md +89 -0
  217. package/src/components/block-draggable/index.js +13 -4
  218. package/src/components/block-draggable/index.native.js +7 -3
  219. package/src/components/block-draggable/test/index.native.js +0 -54
  220. package/src/components/block-edit/edit.js +26 -9
  221. package/src/components/block-edit/test/edit.js +1 -1
  222. package/src/components/block-list/block-outline.native.js +26 -25
  223. package/src/components/block-list/block.native.js +24 -38
  224. package/src/components/block-list/block.native.scss +18 -40
  225. package/src/components/block-list/style.native.scss +3 -3
  226. package/src/components/block-mover/index.native.js +3 -3
  227. package/src/components/block-mover/test/__snapshots__/index.native.js.snap +16 -6
  228. package/src/components/block-removal-warning-modal/index.js +0 -3
  229. package/src/components/block-settings/button.native.js +12 -6
  230. package/src/components/{block-mobile-toolbar/block-actions-menu.native.js → block-toolbar/block-toolbar-menu.native.js} +15 -10
  231. package/src/components/block-toolbar/index.js +2 -3
  232. package/src/components/block-toolbar/index.native.js +86 -6
  233. package/src/components/{block-mobile-toolbar/test/block-actions-menu.native.js → block-toolbar/test/block-toolbar-menu.native.js} +20 -54
  234. package/src/components/block-toolbar/test/index.native.js +42 -0
  235. package/src/components/button-block-appender/styles.native.scss +2 -2
  236. package/src/components/caption/README.md +49 -0
  237. package/src/components/colors-gradients/control.js +3 -2
  238. package/src/components/global-styles/color-panel.js +23 -16
  239. package/src/components/global-styles/dimensions-panel.js +8 -2
  240. package/src/components/global-styles/get-block-css-selector.js +5 -9
  241. package/src/components/global-styles/hooks.js +20 -26
  242. package/src/components/global-styles/typography-panel.js +17 -5
  243. package/src/components/global-styles/use-global-styles-output.js +36 -18
  244. package/src/components/global-styles/utils.js +15 -6
  245. package/src/components/iframe/index.js +30 -56
  246. package/src/components/iframe/use-compatibility-styles.js +5 -0
  247. package/src/components/index.js +0 -5
  248. package/src/components/inner-blocks/README.md +10 -0
  249. package/src/components/inner-blocks/index.js +4 -0
  250. package/src/components/inner-blocks/index.native.js +4 -0
  251. package/src/components/inner-blocks/use-nested-settings-update.js +32 -5
  252. package/src/components/inserter/index.js +2 -3
  253. package/src/components/inserter/index.native.js +17 -36
  254. package/src/components/inserter/reusable-block-rename-hint.js +18 -1
  255. package/src/components/inserter/style.native.scss +10 -15
  256. package/src/components/link-control/index.js +4 -1
  257. package/src/components/link-control/search-item.js +1 -1
  258. package/src/components/link-control/style.scss +8 -1
  259. package/src/components/link-control/test/index.js +26 -0
  260. package/src/components/list-view/use-list-view-client-ids.js +2 -2
  261. package/src/components/media-placeholder/index.native.js +108 -59
  262. package/src/components/media-placeholder/styles.native.scss +59 -24
  263. package/src/components/preview-options/README.md +18 -17
  264. package/src/components/preview-options/index.js +2 -2
  265. package/src/components/rich-text/content.js +1 -46
  266. package/src/components/rich-text/get-rich-text-values.js +105 -0
  267. package/src/components/spacing-sizes-control/hooks/use-spacing-sizes.js +1 -1
  268. package/src/components/spacing-sizes-control/input-controls/axial.js +17 -2
  269. package/src/components/spacing-sizes-control/input-controls/separated.js +17 -2
  270. package/src/components/spacing-sizes-control/input-controls/single.js +12 -2
  271. package/src/components/spacing-sizes-control/utils.js +1 -1
  272. package/src/components/text-transform-control/README.md +44 -0
  273. package/src/components/use-block-display-information/index.js +12 -5
  274. package/src/components/use-block-drop-zone/index.native.js +65 -28
  275. package/src/components/use-setting/index.js +8 -8
  276. package/src/hooks/margin.js +4 -1
  277. package/src/hooks/padding.js +4 -1
  278. package/src/hooks/utils.js +5 -7
  279. package/src/private-apis.js +7 -1
  280. package/src/store/actions.js +1 -2
  281. package/src/store/private-selectors.js +3 -6
  282. package/src/store/reducer.js +0 -1
  283. package/src/store/selectors.js +33 -5
  284. package/src/store/test/actions.js +3 -0
  285. package/src/store/test/private-selectors.js +5 -5
  286. package/src/store/test/reducer.js +14 -7
  287. package/src/store/test/selectors.js +1 -1
  288. package/src/utils/object.js +32 -2
  289. package/src/utils/test/object.js +36 -0
  290. package/build/components/block-mobile-toolbar/block-actions-menu.native.js.map +0 -1
  291. package/build/components/block-mobile-toolbar/index.native.js +0 -135
  292. package/build/components/block-mobile-toolbar/index.native.js.map +0 -1
  293. package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js.map +0 -1
  294. package/build-module/components/block-mobile-toolbar/index.native.js +0 -116
  295. package/build-module/components/block-mobile-toolbar/index.native.js.map +0 -1
  296. package/src/components/block-mobile-toolbar/index.native.js +0 -127
  297. package/src/components/block-mobile-toolbar/style.native.scss +0 -16
  298. /package/src/components/{block-mobile-toolbar/test/__snapshots__/block-actions-menu.native.js.snap → block-toolbar/test/__snapshots__/block-toolbar-menu.native.js.snap} +0 -0
@@ -0,0 +1,105 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { RawHTML, StrictMode, Fragment } from '@wordpress/element';
5
+ import { getSaveElement, __unstableGetBlockProps as getBlockProps } from '@wordpress/blocks';
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+
10
+ import InnerBlocks from '../inner-blocks';
11
+ import { Content } from './content';
12
+ /*
13
+ * This function is similar to `@wordpress/element`'s `renderToString` function,
14
+ * except that it does not render the elements to a string, but instead collects
15
+ * the values of all rich text `Content` elements.
16
+ */
17
+
18
+ function addValuesForElement(element, ...args) {
19
+ if (null === element || undefined === element || false === element) {
20
+ return;
21
+ }
22
+
23
+ if (Array.isArray(element)) {
24
+ return addValuesForElements(element, ...args);
25
+ }
26
+
27
+ switch (typeof element) {
28
+ case 'string':
29
+ case 'number':
30
+ return;
31
+ }
32
+
33
+ const {
34
+ type,
35
+ props
36
+ } = element;
37
+
38
+ switch (type) {
39
+ case StrictMode:
40
+ case Fragment:
41
+ return addValuesForElements(props.children, ...args);
42
+
43
+ case RawHTML:
44
+ return;
45
+
46
+ case InnerBlocks.Content:
47
+ return addValuesForBlocks(...args);
48
+
49
+ case Content:
50
+ const [values] = args;
51
+ values.push(props.value);
52
+ return;
53
+ }
54
+
55
+ switch (typeof type) {
56
+ case 'string':
57
+ if (typeof props.children !== 'undefined') {
58
+ return addValuesForElements(props.children, ...args);
59
+ }
60
+
61
+ return;
62
+
63
+ case 'function':
64
+ if (type.prototype && typeof type.prototype.render === 'function') {
65
+ return addValuesForElement(new type(props).render(), ...args);
66
+ }
67
+
68
+ return addValuesForElement(type(props), ...args);
69
+ }
70
+ }
71
+
72
+ function addValuesForElements(children, ...args) {
73
+ children = Array.isArray(children) ? children : [children];
74
+
75
+ for (let i = 0; i < children.length; i++) {
76
+ addValuesForElement(children[i], ...args);
77
+ }
78
+ }
79
+
80
+ function _getSaveElement(name, attributes, innerBlocks) {
81
+ return getSaveElement(name, attributes, innerBlocks.map(block => _getSaveElement(block.name, block.attributes, block.innerBlocks)));
82
+ }
83
+
84
+ function addValuesForBlocks(values, blocks) {
85
+ for (let i = 0; i < blocks.length; i++) {
86
+ const {
87
+ name,
88
+ attributes,
89
+ innerBlocks
90
+ } = blocks[i];
91
+
92
+ const saveElement = _getSaveElement(name, attributes, innerBlocks);
93
+
94
+ addValuesForElement(saveElement, values, innerBlocks);
95
+ }
96
+ }
97
+
98
+ export function getRichTextValues(blocks = []) {
99
+ getBlockProps.skipFilters = true;
100
+ const values = [];
101
+ addValuesForBlocks(values, blocks);
102
+ getBlockProps.skipFilters = false;
103
+ return values;
104
+ }
105
+ //# sourceMappingURL=get-rich-text-values.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/get-rich-text-values.js"],"names":["RawHTML","StrictMode","Fragment","getSaveElement","__unstableGetBlockProps","getBlockProps","InnerBlocks","Content","addValuesForElement","element","args","undefined","Array","isArray","addValuesForElements","type","props","children","addValuesForBlocks","values","push","value","prototype","render","i","length","_getSaveElement","name","attributes","innerBlocks","map","block","blocks","saveElement","getRichTextValues","skipFilters"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAT,EAAkBC,UAAlB,EAA8BC,QAA9B,QAA8C,oBAA9C;AACA,SACCC,cADD,EAECC,uBAAuB,IAAIC,aAF5B,QAGO,mBAHP;AAKA;AACA;AACA;;AACA,OAAOC,WAAP,MAAwB,iBAAxB;AACA,SAASC,OAAT,QAAwB,WAAxB;AAEA;AACA;AACA;AACA;AACA;;AACA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B,WAAd,GAA4B,IAA5B;AACA,QAAMhB,MAAM,GAAG,EAAf;AACAD,EAAAA,kBAAkB,CAAEC,MAAF,EAAUa,MAAV,CAAlB;AACA3B,EAAAA,aAAa,CAAC8B,WAAd,GAA4B,KAA5B;AACA,SAAOhB,MAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { RawHTML, StrictMode, Fragment } from '@wordpress/element';\nimport {\n\tgetSaveElement,\n\t__unstableGetBlockProps as getBlockProps,\n} from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport InnerBlocks from '../inner-blocks';\nimport { Content } from './content';\n\n/*\n * This function is similar to `@wordpress/element`'s `renderToString` function,\n * except that it does not render the elements to a string, but instead collects\n * the values of all rich text `Content` elements.\n */\nfunction addValuesForElement( element, ...args ) {\n\tif ( null === element || undefined === element || false === element ) {\n\t\treturn;\n\t}\n\n\tif ( Array.isArray( element ) ) {\n\t\treturn addValuesForElements( element, ...args );\n\t}\n\n\tswitch ( typeof element ) {\n\t\tcase 'string':\n\t\tcase 'number':\n\t\t\treturn;\n\t}\n\n\tconst { type, props } = element;\n\n\tswitch ( type ) {\n\t\tcase StrictMode:\n\t\tcase Fragment:\n\t\t\treturn addValuesForElements( props.children, ...args );\n\t\tcase RawHTML:\n\t\t\treturn;\n\t\tcase InnerBlocks.Content:\n\t\t\treturn addValuesForBlocks( ...args );\n\t\tcase Content:\n\t\t\tconst [ values ] = args;\n\t\t\tvalues.push( props.value );\n\t\t\treturn;\n\t}\n\n\tswitch ( typeof type ) {\n\t\tcase 'string':\n\t\t\tif ( typeof props.children !== 'undefined' ) {\n\t\t\t\treturn addValuesForElements( props.children, ...args );\n\t\t\t}\n\t\t\treturn;\n\t\tcase 'function':\n\t\t\tif (\n\t\t\t\ttype.prototype &&\n\t\t\t\ttypeof type.prototype.render === 'function'\n\t\t\t) {\n\t\t\t\treturn addValuesForElement(\n\t\t\t\t\tnew type( props ).render(),\n\t\t\t\t\t...args\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn addValuesForElement( type( props ), ...args );\n\t}\n}\n\nfunction addValuesForElements( children, ...args ) {\n\tchildren = Array.isArray( children ) ? children : [ children ];\n\n\tfor ( let i = 0; i < children.length; i++ ) {\n\t\taddValuesForElement( children[ i ], ...args );\n\t}\n}\n\nfunction _getSaveElement( name, attributes, innerBlocks ) {\n\treturn getSaveElement(\n\t\tname,\n\t\tattributes,\n\t\tinnerBlocks.map( ( block ) =>\n\t\t\t_getSaveElement( block.name, block.attributes, block.innerBlocks )\n\t\t)\n\t);\n}\n\nfunction addValuesForBlocks( values, blocks ) {\n\tfor ( let i = 0; i < blocks.length; i++ ) {\n\t\tconst { name, attributes, innerBlocks } = blocks[ i ];\n\t\tconst saveElement = _getSaveElement( name, attributes, innerBlocks );\n\t\taddValuesForElement( saveElement, values, innerBlocks );\n\t}\n}\n\nexport function getRichTextValues( blocks = [] ) {\n\tgetBlockProps.skipFilters = true;\n\tconst values = [];\n\taddValuesForBlocks( values, blocks );\n\tgetBlockProps.skipFilters = false;\n\treturn values;\n}\n"]}
@@ -11,7 +11,7 @@ export default function useSpacingSizes() {
11
11
  const spacingSizes = [{
12
12
  name: 0,
13
13
  slug: '0',
14
- side: 0
14
+ size: 0
15
15
  }, ...(useSetting('spacing.spacingSizes') || [])];
16
16
 
17
17
  if (spacingSizes.length > 8) {
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/spacing-sizes-control/hooks/use-spacing-sizes.js"],"names":["__","useSetting","useSpacingSizes","spacingSizes","name","slug","side","length","unshift","size","undefined"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AAEA;AACA;AACA;;AACA,OAAOC,UAAP,MAAuB,mBAAvB;AAEA,eAAe,SAASC,eAAT,GAA2B;AACzC,QAAMC,YAAY,GAAG,CACpB;AAAEC,IAAAA,IAAI,EAAE,CAAR;AAAWC,IAAAA,IAAI,EAAE,GAAjB;AAAsBC,IAAAA,IAAI,EAAE;AAA5B,GADoB,EAEpB,IAAKL,UAAU,CAAE,sBAAF,CAAV,IAAwC,EAA7C,CAFoB,CAArB;;AAKA,MAAKE,YAAY,CAACI,MAAb,GAAsB,CAA3B,EAA+B;AAC9BJ,IAAAA,YAAY,CAACK,OAAb,CAAsB;AACrBJ,MAAAA,IAAI,EAAEJ,EAAE,CAAE,SAAF,CADa;AAErBK,MAAAA,IAAI,EAAE,SAFe;AAGrBI,MAAAA,IAAI,EAAEC;AAHe,KAAtB;AAKA;;AAED,SAAOP,YAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport useSetting from '../../use-setting';\n\nexport default function useSpacingSizes() {\n\tconst spacingSizes = [\n\t\t{ name: 0, slug: '0', side: 0 },\n\t\t...( useSetting( 'spacing.spacingSizes' ) || [] ),\n\t];\n\n\tif ( spacingSizes.length > 8 ) {\n\t\tspacingSizes.unshift( {\n\t\t\tname: __( 'Default' ),\n\t\t\tslug: 'default',\n\t\t\tsize: undefined,\n\t\t} );\n\t}\n\n\treturn spacingSizes;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/spacing-sizes-control/hooks/use-spacing-sizes.js"],"names":["__","useSetting","useSpacingSizes","spacingSizes","name","slug","size","length","unshift","undefined"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AAEA;AACA;AACA;;AACA,OAAOC,UAAP,MAAuB,mBAAvB;AAEA,eAAe,SAASC,eAAT,GAA2B;AACzC,QAAMC,YAAY,GAAG,CACpB;AAAEC,IAAAA,IAAI,EAAE,CAAR;AAAWC,IAAAA,IAAI,EAAE,GAAjB;AAAsBC,IAAAA,IAAI,EAAE;AAA5B,GADoB,EAEpB,IAAKL,UAAU,CAAE,sBAAF,CAAV,IAAwC,EAA7C,CAFoB,CAArB;;AAKA,MAAKE,YAAY,CAACI,MAAb,GAAsB,CAA3B,EAA+B;AAC9BJ,IAAAA,YAAY,CAACK,OAAb,CAAsB;AACrBJ,MAAAA,IAAI,EAAEJ,EAAE,CAAE,SAAF,CADa;AAErBK,MAAAA,IAAI,EAAE,SAFe;AAGrBC,MAAAA,IAAI,EAAEG;AAHe,KAAtB;AAKA;;AAED,SAAON,YAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport useSetting from '../../use-setting';\n\nexport default function useSpacingSizes() {\n\tconst spacingSizes = [\n\t\t{ name: 0, slug: '0', size: 0 },\n\t\t...( useSetting( 'spacing.spacingSizes' ) || [] ),\n\t];\n\n\tif ( spacingSizes.length > 8 ) {\n\t\tspacingSizes.unshift( {\n\t\t\tname: __( 'Default' ),\n\t\t\tslug: 'default',\n\t\t\tsize: undefined,\n\t\t} );\n\t}\n\n\treturn spacingSizes;\n}\n"]}
@@ -4,7 +4,7 @@ import { createElement, Fragment } from "@wordpress/element";
4
4
  * Internal dependencies
5
5
  */
6
6
  import SpacingInputControl from './spacing-input-control';
7
- import { LABELS, ICONS, hasAxisSupport } from '../utils';
7
+ import { LABELS, ICONS, getPresetValueFromCustomValue, hasAxisSupport } from '../utils';
8
8
  const groupedSides = ['vertical', 'horizontal'];
9
9
  export default function AxialInputControls({
10
10
  minimumCustomValue,
@@ -19,9 +19,13 @@ export default function AxialInputControls({
19
19
  const createHandleOnChange = side => next => {
20
20
  if (!onChange) {
21
21
  return;
22
- }
22
+ } // Encode the existing value into the preset value if the passed in value matches the value of one of the spacingSizes.
23
+
23
24
 
24
- const nextValues = { ...values
25
+ const nextValues = { ...Object.keys(values).reduce((acc, key) => {
26
+ acc[key] = getPresetValueFromCustomValue(values[key], spacingSizes);
27
+ return acc;
28
+ }, {})
25
29
  };
26
30
 
27
31
  if (side === 'vertical') {
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/spacing-sizes-control/input-controls/axial.js"],"names":["SpacingInputControl","LABELS","ICONS","hasAxisSupport","groupedSides","AxialInputControls","minimumCustomValue","onChange","onMouseOut","onMouseOver","sides","spacingSizes","type","values","createHandleOnChange","side","next","nextValues","top","bottom","left","right","filteredSides","length","filter","map","axisValue"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,mBAAP,MAAgC,yBAAhC;AACA,SAASC,MAAT,EAAiBC,KAAjB,EAAwBC,cAAxB,QAA8C,UAA9C;AAEA,MAAMC,YAAY,GAAG,CAAE,UAAF,EAAc,YAAd,CAArB;AAEA,eAAe,SAASC,kBAAT,CAA6B;AAC3CC,EAAAA,kBAD2C;AAE3CC,EAAAA,QAF2C;AAG3CC,EAAAA,UAH2C;AAI3CC,EAAAA,WAJ2C;AAK3CC,EAAAA,KAL2C;AAM3CC,EAAAA,YAN2C;AAO3CC,EAAAA,IAP2C;AAQ3CC,EAAAA;AAR2C,CAA7B,EASX;AACH,QAAMC,oBAAoB,GAAKC,IAAF,IAAcC,IAAF,IAAY;AACpD,QAAK,CAAET,QAAP,EAAkB;AACjB;AACA;;AACD,UAAMU,UAAU,GAAG,EAAE,GAAGJ;AAAL,KAAnB;;AAEA,QAAKE,IAAI,KAAK,UAAd,EAA2B;AAC1BE,MAAAA,UAAU,CAACC,GAAX,GAAiBF,IAAjB;AACAC,MAAAA,UAAU,CAACE,MAAX,GAAoBH,IAApB;AACA;;AAED,QAAKD,IAAI,KAAK,YAAd,EAA6B;AAC5BE,MAAAA,UAAU,CAACG,IAAX,GAAkBJ,IAAlB;AACAC,MAAAA,UAAU,CAACI,KAAX,GAAmBL,IAAnB;AACA;;AAEDT,IAAAA,QAAQ,CAAEU,UAAF,CAAR;AACA,GAjBD,CADG,CAoBH;;;AACA,QAAMK,aAAa,GAAGZ,KAAK,EAAEa,MAAP,GACnBnB,YAAY,CAACoB,MAAb,CAAuBT,IAAF,IAAYZ,cAAc,CAAEO,KAAF,EAASK,IAAT,CAA/C,CADmB,GAEnBX,YAFH;AAIA,SACC,8BACGkB,aAAa,CAACG,GAAd,CAAqBV,IAAF,IAAY;AAChC,UAAMW,SAAS,GACdX,IAAI,KAAK,UAAT,GAAsBF,MAAM,CAACK,GAA7B,GAAmCL,MAAM,CAACO,IAD3C;AAEA,WACC,cAAC,mBAAD;AACC,MAAA,GAAG,EAAI,yBAAyBL,IAAM,EADvC;AAEC,MAAA,IAAI,EAAGb,KAAK,CAAEa,IAAF,CAFb;AAGC,MAAA,KAAK,EAAGd,MAAM,CAAEc,IAAF,CAHf;AAIC,MAAA,kBAAkB,EAAGT,kBAJtB;AAKC,MAAA,QAAQ,EAAGQ,oBAAoB,CAAEC,IAAF,CALhC;AAMC,MAAA,UAAU,EAAGP,UANd;AAOC,MAAA,WAAW,EAAGC,WAPf;AAQC,MAAA,IAAI,EAAGM,IARR;AASC,MAAA,YAAY,EAAGJ,YAThB;AAUC,MAAA,IAAI,EAAGC,IAVR;AAWC,MAAA,KAAK,EAAGc,SAXT;AAYC,MAAA,cAAc,EAAG;AAZlB,MADD;AAgBA,GAnBC,CADH,CADD;AAwBA","sourcesContent":["/**\n * Internal dependencies\n */\nimport SpacingInputControl from './spacing-input-control';\nimport { LABELS, ICONS, hasAxisSupport } from '../utils';\n\nconst groupedSides = [ 'vertical', 'horizontal' ];\n\nexport default function AxialInputControls( {\n\tminimumCustomValue,\n\tonChange,\n\tonMouseOut,\n\tonMouseOver,\n\tsides,\n\tspacingSizes,\n\ttype,\n\tvalues,\n} ) {\n\tconst createHandleOnChange = ( side ) => ( next ) => {\n\t\tif ( ! onChange ) {\n\t\t\treturn;\n\t\t}\n\t\tconst nextValues = { ...values };\n\n\t\tif ( side === 'vertical' ) {\n\t\t\tnextValues.top = next;\n\t\t\tnextValues.bottom = next;\n\t\t}\n\n\t\tif ( side === 'horizontal' ) {\n\t\t\tnextValues.left = next;\n\t\t\tnextValues.right = next;\n\t\t}\n\n\t\tonChange( nextValues );\n\t};\n\n\t// Filter sides if custom configuration provided, maintaining default order.\n\tconst filteredSides = sides?.length\n\t\t? groupedSides.filter( ( side ) => hasAxisSupport( sides, side ) )\n\t\t: groupedSides;\n\n\treturn (\n\t\t<>\n\t\t\t{ filteredSides.map( ( side ) => {\n\t\t\t\tconst axisValue =\n\t\t\t\t\tside === 'vertical' ? values.top : values.left;\n\t\t\t\treturn (\n\t\t\t\t\t<SpacingInputControl\n\t\t\t\t\t\tkey={ `spacing-sizes-control-${ side }` }\n\t\t\t\t\t\ticon={ ICONS[ side ] }\n\t\t\t\t\t\tlabel={ LABELS[ side ] }\n\t\t\t\t\t\tminimumCustomValue={ minimumCustomValue }\n\t\t\t\t\t\tonChange={ createHandleOnChange( side ) }\n\t\t\t\t\t\tonMouseOut={ onMouseOut }\n\t\t\t\t\t\tonMouseOver={ onMouseOver }\n\t\t\t\t\t\tside={ side }\n\t\t\t\t\t\tspacingSizes={ spacingSizes }\n\t\t\t\t\t\ttype={ type }\n\t\t\t\t\t\tvalue={ axisValue }\n\t\t\t\t\t\twithInputField={ false }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/spacing-sizes-control/input-controls/axial.js"],"names":["SpacingInputControl","LABELS","ICONS","getPresetValueFromCustomValue","hasAxisSupport","groupedSides","AxialInputControls","minimumCustomValue","onChange","onMouseOut","onMouseOver","sides","spacingSizes","type","values","createHandleOnChange","side","next","nextValues","Object","keys","reduce","acc","key","top","bottom","left","right","filteredSides","length","filter","map","axisValue"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,mBAAP,MAAgC,yBAAhC;AACA,SACCC,MADD,EAECC,KAFD,EAGCC,6BAHD,EAICC,cAJD,QAKO,UALP;AAOA,MAAMC,YAAY,GAAG,CAAE,UAAF,EAAc,YAAd,CAArB;AAEA,eAAe,SAASC,kBAAT,CAA6B;AAC3CC,EAAAA,kBAD2C;AAE3CC,EAAAA,QAF2C;AAG3CC,EAAAA,UAH2C;AAI3CC,EAAAA,WAJ2C;AAK3CC,EAAAA,KA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AI,EAAGd,KAAK,CAAEc,IAAF,CAFb;AAGC,MAAA,KAAK,EAAGf,MAAM,CAAEe,IAAF,CAHf;AAIC,MAAA,kBAAkB,EAAGT,kBAJtB;AAKC,MAAA,QAAQ,EAAGQ,oBAAoB,CAAEC,IAAF,CALhC;AAMC,MAAA,UAAU,EAAGP,UANd;AAOC,MAAA,WAAW,EAAGC,WAPf;AAQC,MAAA,IAAI,EAAGM,IARR;AASC,MAAA,YAAY,EAAGJ,YAThB;AAUC,MAAA,IAAI,EAAGC,IAVR;AAWC,MAAA,KAAK,EAAGmB,SAXT;AAYC,MAAA,cAAc,EAAG;AAZlB,MADD;AAgBA,GAnBC,CADH,CADD;AAwBA","sourcesContent":["/**\n * Internal dependencies\n */\nimport SpacingInputControl from './spacing-input-control';\nimport {\n\tLABELS,\n\tICONS,\n\tgetPresetValueFromCustomValue,\n\thasAxisSupport,\n} from '../utils';\n\nconst groupedSides = [ 'vertical', 'horizontal' ];\n\nexport default function AxialInputControls( {\n\tminimumCustomValue,\n\tonChange,\n\tonMouseOut,\n\tonMouseOver,\n\tsides,\n\tspacingSizes,\n\ttype,\n\tvalues,\n} ) {\n\tconst createHandleOnChange = ( side ) => ( next ) => {\n\t\tif ( ! onChange ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Encode the existing value into the preset value if the passed in value matches the value of one of the spacingSizes.\n\t\tconst nextValues = {\n\t\t\t...Object.keys( values ).reduce( ( acc, key ) => {\n\t\t\t\tacc[ key ] = getPresetValueFromCustomValue(\n\t\t\t\t\tvalues[ key ],\n\t\t\t\t\tspacingSizes\n\t\t\t\t);\n\t\t\t\treturn acc;\n\t\t\t}, {} ),\n\t\t};\n\n\t\tif ( side === 'vertical' ) {\n\t\t\tnextValues.top = next;\n\t\t\tnextValues.bottom = next;\n\t\t}\n\n\t\tif ( side === 'horizontal' ) {\n\t\t\tnextValues.left = next;\n\t\t\tnextValues.right = next;\n\t\t}\n\n\t\tonChange( nextValues );\n\t};\n\n\t// Filter sides if custom configuration provided, maintaining default order.\n\tconst filteredSides = sides?.length\n\t\t? groupedSides.filter( ( side ) => hasAxisSupport( sides, side ) )\n\t\t: groupedSides;\n\n\treturn (\n\t\t<>\n\t\t\t{ filteredSides.map( ( side ) => {\n\t\t\t\tconst axisValue =\n\t\t\t\t\tside === 'vertical' ? values.top : values.left;\n\t\t\t\treturn (\n\t\t\t\t\t<SpacingInputControl\n\t\t\t\t\t\tkey={ `spacing-sizes-control-${ side }` }\n\t\t\t\t\t\ticon={ ICONS[ side ] }\n\t\t\t\t\t\tlabel={ LABELS[ side ] }\n\t\t\t\t\t\tminimumCustomValue={ minimumCustomValue }\n\t\t\t\t\t\tonChange={ createHandleOnChange( side ) }\n\t\t\t\t\t\tonMouseOut={ onMouseOut }\n\t\t\t\t\t\tonMouseOver={ onMouseOver }\n\t\t\t\t\t\tside={ side }\n\t\t\t\t\t\tspacingSizes={ spacingSizes }\n\t\t\t\t\t\ttype={ type }\n\t\t\t\t\t\tvalue={ axisValue }\n\t\t\t\t\t\twithInputField={ false }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</>\n\t);\n}\n"]}
@@ -4,7 +4,7 @@ import { createElement, Fragment } from "@wordpress/element";
4
4
  * Internal dependencies
5
5
  */
6
6
  import SpacingInputControl from './spacing-input-control';
7
- import { ALL_SIDES, LABELS, ICONS } from '../utils';
7
+ import { ALL_SIDES, LABELS, ICONS, getPresetValueFromCustomValue } from '../utils';
8
8
  export default function SeparatedInputControls({
9
9
  minimumCustomValue,
10
10
  onChange,
@@ -19,7 +19,11 @@ export default function SeparatedInputControls({
19
19
  const filteredSides = sides?.length ? ALL_SIDES.filter(side => sides.includes(side)) : ALL_SIDES;
20
20
 
21
21
  const createHandleOnChange = side => next => {
22
- const nextValues = { ...values
22
+ // Encode the existing value into the preset value if the passed in value matches the value of one of the spacingSizes.
23
+ const nextValues = { ...Object.keys(values).reduce((acc, key) => {
24
+ acc[key] = getPresetValueFromCustomValue(values[key], spacingSizes);
25
+ return acc;
26
+ }, {})
23
27
  };
24
28
  nextValues[side] = next;
25
29
  onChange(nextValues);
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/spacing-sizes-control/input-controls/separated.js"],"names":["SpacingInputControl","ALL_SIDES","LABELS","ICONS","SeparatedInputControls","minimumCustomValue","onChange","onMouseOut","onMouseOver","sides","spacingSizes","type","values","filteredSides","length","filter","side","includes","createHandleOnChange","next","nextValues","map"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,mBAAP,MAAgC,yBAAhC;AACA,SAASC,SAAT,EAAoBC,MAApB,EAA4BC,KAA5B,QAAyC,UAAzC;AAEA,eAAe,SAASC,sBAAT,CAAiC;AAC/CC,EAAAA,kBAD+C;AAE/CC,EAAAA,QAF+C;AAG/CC,EAAAA,UAH+C;AAI/CC,EAAAA,WAJ+C;AAK/CC,EAAAA,KAL+C;AAM/CC,EAAAA,YAN+C;AAO/CC,EAAAA,IAP+C;AAQ/CC,EAAAA;AAR+C,CAAjC,EASX;AACH;AACA,QAAMC,aAAa,GAAGJ,KAAK,EAAEK,MAAP,GACnBb,SAAS,CAACc,MAAV,CAAoBC,IAAF,IAAYP,KAAK,CAACQ,QAAN,CAAgBD,IAAhB,CAA9B,CADmB,GAEnBf,SAFH;;AAIA,QAAMiB,oBAAoB,GAAKF,IAAF,IAAcG,IAAF,IAAY;AACpD,UAAMC,UAAU,GAAG,EAAE,GAAGR;AAAL,KAAnB;AACAQ,IAAAA,UAAU,CAAEJ,IAAF,CAAV,GAAqBG,IAArB;AAEAb,IAAAA,QAAQ,CAAEc,UAAF,CAAR;AACA,GALD;;AAOA,SACC,8BACGP,aAAa,CAACQ,GAAd,CAAqBL,IAAF,IAAY;AAChC,WACC,cAAC,mBAAD;AACC,MAAA,GAAG,EAAI,yBAAyBA,IAAM,EADvC;AAEC,MAAA,IAAI,EAAGb,KAAK,CAAEa,IAAF,CAFb;AAGC,MAAA,KAAK,EAAGd,MAAM,CAAEc,IAAF,CAHf;AAIC,MAAA,kBAAkB,EAAGX,kBAJtB;AAKC,MAAA,QAAQ,EAAGa,oBAAoB,CAAEF,IAAF,CALhC;AAMC,MAAA,UAAU,EAAGT,UANd;AAOC,MAAA,WAAW,EAAGC,WAPf;AAQC,MAAA,IAAI,EAAGQ,IARR;AASC,MAAA,YAAY,EAAGN,YAThB;AAUC,MAAA,IAAI,EAAGC,IAVR;AAWC,MAAA,KAAK,EAAGC,MAAM,CAAEI,IAAF,CAXf;AAYC,MAAA,cAAc,EAAG;AAZlB,MADD;AAgBA,GAjBC,CADH,CADD;AAsBA","sourcesContent":["/**\n * Internal dependencies\n */\nimport SpacingInputControl from './spacing-input-control';\nimport { ALL_SIDES, LABELS, ICONS } from '../utils';\n\nexport default function SeparatedInputControls( {\n\tminimumCustomValue,\n\tonChange,\n\tonMouseOut,\n\tonMouseOver,\n\tsides,\n\tspacingSizes,\n\ttype,\n\tvalues,\n} ) {\n\t// Filter sides if custom configuration provided, maintaining default order.\n\tconst filteredSides = sides?.length\n\t\t? ALL_SIDES.filter( ( side ) => sides.includes( side ) )\n\t\t: ALL_SIDES;\n\n\tconst createHandleOnChange = ( side ) => ( next ) => {\n\t\tconst nextValues = { ...values };\n\t\tnextValues[ side ] = next;\n\n\t\tonChange( nextValues );\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t{ filteredSides.map( ( side ) => {\n\t\t\t\treturn (\n\t\t\t\t\t<SpacingInputControl\n\t\t\t\t\t\tkey={ `spacing-sizes-control-${ side }` }\n\t\t\t\t\t\ticon={ ICONS[ side ] }\n\t\t\t\t\t\tlabel={ LABELS[ side ] }\n\t\t\t\t\t\tminimumCustomValue={ minimumCustomValue }\n\t\t\t\t\t\tonChange={ createHandleOnChange( side ) }\n\t\t\t\t\t\tonMouseOut={ onMouseOut }\n\t\t\t\t\t\tonMouseOver={ onMouseOver }\n\t\t\t\t\t\tside={ side }\n\t\t\t\t\t\tspacingSizes={ spacingSizes }\n\t\t\t\t\t\ttype={ type }\n\t\t\t\t\t\tvalue={ values[ side ] }\n\t\t\t\t\t\twithInputField={ false }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/spacing-sizes-control/input-controls/separated.js"],"names":["SpacingInputControl","ALL_SIDES","LABELS","ICONS","getPresetValueFromCustomValue","SeparatedInputControls","minimumCustomValue","onChange","onMouseOut","onMouseOver","sides","spacingSizes","type","values","filteredSides","length","filter","side","includes","createHandleOnChange","next","nextValues","Object","keys","reduce","acc","key","map"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,mBAAP,MAAgC,yBAAhC;AACA,SACCC,SADD,EAECC,MAFD,EAGCC,KAHD,EAICC,6BAJD,QAKO,UALP;AAOA,eAAe,SAASC,sBAAT,CAAiC;AAC/CC,EAAAA,kBAD+C;AAE/CC,EAAAA,QAF+C;AAG/CC,EAAAA,UAH+C;AAI/CC,EAAAA,WAJ+C;AAK/CC,EAAAA,KAL+C;AAM/CC,EAAAA,YAN+C;AAO/CC,EAAAA,IAP+C;AAQ/CC,EAAAA;AAR+C,CAAjC,EASX;AACH;AACA,QAAMC,aAAa,GAAGJ,KAAK,EAAEK,MAAP,GACnBd,SAAS,CAACe,MAAV,CAAoBC,IAAF,IAAYP,KAAK,CAACQ,QAAN,CAAgBD,IAAhB,CAA9B,CADmB,GAEnBhB,SAFH;;AAIA,QAAMkB,oBAAoB,GAAKF,IAAF,IAAcG,IAAF,IAAY;AACpD;AACA,UAAMC,UAAU,GAAG,EAClB,GAAGC,MAAM,CAACC,IAAP,CAAaV,MAAb,EAAsBW,MAAtB,CAA8B,CAAEC,GAAF,EAAOC,GAAP,KAAgB;AAChDD,QAAAA,GAAG,CAAEC,GAAF,CAAH,GAAatB,6BAA6B,CACzCS,MAAM,CAAEa,GAAF,CADmC,EAEzCf,YAFyC,CAA1C;AAIA,eAAOc,GAAP;AACA,OANE,EAMA,EANA;AADe,KAAnB;AAUAJ,IAAAA,UAAU,CAAEJ,IAAF,CAAV,GAAqBG,IAArB;AAEAb,IAAAA,QAAQ,CAAEc,UAAF,CAAR;AACA,GAfD;;AAiBA,SACC,8BACGP,aAAa,CAACa,GAAd,CAAqBV,IAAF,IAAY;AAChC,WACC,cAAC,mBAAD;AACC,MAAA,GAAG,EAAI,yBAAyBA,IAAM,EADvC;AAEC,MAAA,IAAI,EAAGd,KAAK,CAAEc,IAAF,CAFb;AAGC,MAAA,KAAK,EAAGf,MAAM,CAAEe,IAAF,CAHf;AAIC,MAAA,kBAAkB,EAAGX,kBAJtB;AAKC,MAAA,QAAQ,EAAGa,oBAAoB,CAAEF,IAAF,CALhC;AAMC,MAAA,UAAU,EAAGT,UANd;AAOC,MAAA,WAAW,EAAGC,WAPf;AAQC,MAAA,IAAI,EAAGQ,IARR;AASC,MAAA,YAAY,EAAGN,YAThB;AAUC,MAAA,IAAI,EAAGC,IAVR;AAWC,MAAA,KAAK,EAAGC,MAAM,CAAEI,IAAF,CAXf;AAYC,MAAA,cAAc,EAAG;AAZlB,MADD;AAgBA,GAjBC,CADH,CADD;AAsBA","sourcesContent":["/**\n * Internal dependencies\n */\nimport SpacingInputControl from './spacing-input-control';\nimport {\n\tALL_SIDES,\n\tLABELS,\n\tICONS,\n\tgetPresetValueFromCustomValue,\n} from '../utils';\n\nexport default function SeparatedInputControls( {\n\tminimumCustomValue,\n\tonChange,\n\tonMouseOut,\n\tonMouseOver,\n\tsides,\n\tspacingSizes,\n\ttype,\n\tvalues,\n} ) {\n\t// Filter sides if custom configuration provided, maintaining default order.\n\tconst filteredSides = sides?.length\n\t\t? ALL_SIDES.filter( ( side ) => sides.includes( side ) )\n\t\t: ALL_SIDES;\n\n\tconst createHandleOnChange = ( side ) => ( next ) => {\n\t\t// Encode the existing value into the preset value if the passed in value matches the value of one of the spacingSizes.\n\t\tconst nextValues = {\n\t\t\t...Object.keys( values ).reduce( ( acc, key ) => {\n\t\t\t\tacc[ key ] = getPresetValueFromCustomValue(\n\t\t\t\t\tvalues[ key ],\n\t\t\t\t\tspacingSizes\n\t\t\t\t);\n\t\t\t\treturn acc;\n\t\t\t}, {} ),\n\t\t};\n\n\t\tnextValues[ side ] = next;\n\n\t\tonChange( nextValues );\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t{ filteredSides.map( ( side ) => {\n\t\t\t\treturn (\n\t\t\t\t\t<SpacingInputControl\n\t\t\t\t\t\tkey={ `spacing-sizes-control-${ side }` }\n\t\t\t\t\t\ticon={ ICONS[ side ] }\n\t\t\t\t\t\tlabel={ LABELS[ side ] }\n\t\t\t\t\t\tminimumCustomValue={ minimumCustomValue }\n\t\t\t\t\t\tonChange={ createHandleOnChange( side ) }\n\t\t\t\t\t\tonMouseOut={ onMouseOut }\n\t\t\t\t\t\tonMouseOver={ onMouseOver }\n\t\t\t\t\t\tside={ side }\n\t\t\t\t\t\tspacingSizes={ spacingSizes }\n\t\t\t\t\t\ttype={ type }\n\t\t\t\t\t\tvalue={ values[ side ] }\n\t\t\t\t\t\twithInputField={ false }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</>\n\t);\n}\n"]}
@@ -4,7 +4,7 @@ import { createElement } from "@wordpress/element";
4
4
  * Internal dependencies
5
5
  */
6
6
  import SpacingInputControl from './spacing-input-control';
7
- import { LABELS } from '../utils';
7
+ import { LABELS, getPresetValueFromCustomValue } from '../utils';
8
8
  export default function SingleInputControl({
9
9
  minimumCustomValue,
10
10
  onChange,
@@ -17,7 +17,11 @@ export default function SingleInputControl({
17
17
  values
18
18
  }) {
19
19
  const createHandleOnChange = currentSide => next => {
20
- const nextValues = { ...values
20
+ // Encode the existing value into the preset value if the passed in value matches the value of one of the spacingSizes.
21
+ const nextValues = { ...Object.keys(values).reduce((acc, key) => {
22
+ acc[key] = getPresetValueFromCustomValue(values[key], spacingSizes);
23
+ return acc;
24
+ }, {})
21
25
  };
22
26
  nextValues[currentSide] = next;
23
27
  onChange(nextValues);
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/spacing-sizes-control/input-controls/single.js"],"names":["SpacingInputControl","LABELS","SingleInputControl","minimumCustomValue","onChange","onMouseOut","onMouseOver","showSideInLabel","side","spacingSizes","type","values","createHandleOnChange","currentSide","next","nextValues"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,mBAAP,MAAgC,yBAAhC;AACA,SAASC,MAAT,QAAuB,UAAvB;AAEA,eAAe,SAASC,kBAAT,CAA6B;AAC3CC,EAAAA,kBAD2C;AAE3CC,EAAAA,QAF2C;AAG3CC,EAAAA,UAH2C;AAI3CC,EAAAA,WAJ2C;AAK3CC,EAAAA,eAL2C;AAM3CC,EAAAA,IAN2C;AAO3CC,EAAAA,YAP2C;AAQ3CC,EAAAA,IAR2C;AAS3CC,EAAAA;AAT2C,CAA7B,EAUX;AACH,QAAMC,oBAAoB,GAAKC,WAAF,IAAqBC,IAAF,IAAY;AAC3D,UAAMC,UAAU,GAAG,EAAE,GAAGJ;AAAL,KAAnB;AACAI,IAAAA,UAAU,CAAEF,WAAF,CAAV,GAA4BC,IAA5B;AAEAV,IAAAA,QAAQ,CAAEW,UAAF,CAAR;AACA,GALD;;AAOA,SACC,cAAC,mBAAD;AACC,IAAA,KAAK,EAAGd,MAAM,CAAEO,IAAF,CADf;AAEC,IAAA,kBAAkB,EAAGL,kBAFtB;AAGC,IAAA,QAAQ,EAAGS,oBAAoB,CAAEJ,IAAF,CAHhC;AAIC,IAAA,UAAU,EAAGH,UAJd;AAKC,IAAA,WAAW,EAAGC,WALf;AAMC,IAAA,eAAe,EAAGC,eANnB;AAOC,IAAA,IAAI,EAAGC,IAPR;AAQC,IAAA,YAAY,EAAGC,YARhB;AASC,IAAA,IAAI,EAAGC,IATR;AAUC,IAAA,KAAK,EAAGC,MAAM,CAAEH,IAAF,CAVf;AAWC,IAAA,cAAc,EAAG;AAXlB,IADD;AAeA","sourcesContent":["/**\n * Internal dependencies\n */\nimport SpacingInputControl from './spacing-input-control';\nimport { LABELS } from '../utils';\n\nexport default function SingleInputControl( {\n\tminimumCustomValue,\n\tonChange,\n\tonMouseOut,\n\tonMouseOver,\n\tshowSideInLabel,\n\tside,\n\tspacingSizes,\n\ttype,\n\tvalues,\n} ) {\n\tconst createHandleOnChange = ( currentSide ) => ( next ) => {\n\t\tconst nextValues = { ...values };\n\t\tnextValues[ currentSide ] = next;\n\n\t\tonChange( nextValues );\n\t};\n\n\treturn (\n\t\t<SpacingInputControl\n\t\t\tlabel={ LABELS[ side ] }\n\t\t\tminimumCustomValue={ minimumCustomValue }\n\t\t\tonChange={ createHandleOnChange( side ) }\n\t\t\tonMouseOut={ onMouseOut }\n\t\t\tonMouseOver={ onMouseOver }\n\t\t\tshowSideInLabel={ showSideInLabel }\n\t\t\tside={ side }\n\t\t\tspacingSizes={ spacingSizes }\n\t\t\ttype={ type }\n\t\t\tvalue={ values[ side ] }\n\t\t\twithInputField={ false }\n\t\t/>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/spacing-sizes-control/input-controls/single.js"],"names":["SpacingInputControl","LABELS","getPresetValueFromCustomValue","SingleInputControl","minimumCustomValue","onChange","onMouseOut","onMouseOver","showSideInLabel","side","spacingSizes","type","values","createHandleOnChange","currentSide","next","nextValues","Object","keys","reduce","acc","key"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,mBAAP,MAAgC,yBAAhC;AACA,SAASC,MAAT,EAAiBC,6BAAjB,QAAsD,UAAtD;AAEA,eAAe,SAASC,kBAAT,CAA6B;AAC3CC,EAAAA,kBAD2C;AAE3CC,EAAAA,QAF2C;AAG3CC,EAAAA,UAH2C;AAI3CC,EAAAA,WAJ2C;AAK3CC,EAAAA,eAL2C;AAM3CC,EAAAA,IAN2C;AAO3CC,EAAAA,YAP2C;AAQ3CC,EAAAA,IAR2C;AAS3CC,EAAAA;AAT2C,CAA7B,EAUX;AACH,QAAMC,oBAAoB,GAAKC,WAAF,IAAqBC,IAAF,IAAY;AAC3D;AACA,UAAMC,UAAU,GAAG,EAClB,GAAGC,MAAM,CAACC,IAAP,CAAaN,MAAb,EAAsBO,MAAtB,CAA8B,CAAEC,GAAF,EAAOC,GAAP,KAAgB;AAChDD,QAAAA,GAAG,CAAEC,GAAF,CAAH,GAAanB,6BAA6B,CACzCU,MAAM,CAAES,GAAF,CADmC,EAEzCX,YAFyC,CAA1C;AAIA,eAAOU,GAAP;AACA,OANE,EAMA,EANA;AADe,KAAnB;AAUAJ,IAAAA,UAAU,CAAEF,WAAF,CAAV,GAA4BC,IAA5B;AAEAV,IAAAA,QAAQ,CAAEW,UAAF,CAAR;AACA,GAfD;;AAiBA,SACC,cAAC,mBAAD;AACC,IAAA,KAAK,EAAGf,MAAM,CAAEQ,IAAF,CADf;AAEC,IAAA,kBAAkB,EAAGL,kBAFtB;AAGC,IAAA,QAAQ,EAAGS,oBAAoB,CAAEJ,IAAF,CAHhC;AAIC,IAAA,UAAU,EAAGH,UAJd;AAKC,IAAA,WAAW,EAAGC,WALf;AAMC,IAAA,eAAe,EAAGC,eANnB;AAOC,IAAA,IAAI,EAAGC,IAPR;AAQC,IAAA,YAAY,EAAGC,YARhB;AASC,IAAA,IAAI,EAAGC,IATR;AAUC,IAAA,KAAK,EAAGC,MAAM,CAAEH,IAAF,CAVf;AAWC,IAAA,cAAc,EAAG;AAXlB,IADD;AAeA","sourcesContent":["/**\n * Internal dependencies\n */\nimport SpacingInputControl from './spacing-input-control';\nimport { LABELS, getPresetValueFromCustomValue } from '../utils';\n\nexport default function SingleInputControl( {\n\tminimumCustomValue,\n\tonChange,\n\tonMouseOut,\n\tonMouseOver,\n\tshowSideInLabel,\n\tside,\n\tspacingSizes,\n\ttype,\n\tvalues,\n} ) {\n\tconst createHandleOnChange = ( currentSide ) => ( next ) => {\n\t\t// Encode the existing value into the preset value if the passed in value matches the value of one of the spacingSizes.\n\t\tconst nextValues = {\n\t\t\t...Object.keys( values ).reduce( ( acc, key ) => {\n\t\t\t\tacc[ key ] = getPresetValueFromCustomValue(\n\t\t\t\t\tvalues[ key ],\n\t\t\t\t\tspacingSizes\n\t\t\t\t);\n\t\t\t\treturn acc;\n\t\t\t}, {} ),\n\t\t};\n\n\t\tnextValues[ currentSide ] = next;\n\n\t\tonChange( nextValues );\n\t};\n\n\treturn (\n\t\t<SpacingInputControl\n\t\t\tlabel={ LABELS[ side ] }\n\t\t\tminimumCustomValue={ minimumCustomValue }\n\t\t\tonChange={ createHandleOnChange( side ) }\n\t\t\tonMouseOut={ onMouseOut }\n\t\t\tonMouseOver={ onMouseOver }\n\t\t\tshowSideInLabel={ showSideInLabel }\n\t\t\tside={ side }\n\t\t\tspacingSizes={ spacingSizes }\n\t\t\ttype={ type }\n\t\t\tvalue={ values[ side ] }\n\t\t\twithInputField={ false }\n\t\t/>\n\t);\n}\n"]}
@@ -86,7 +86,7 @@ export function getCustomValueFromPreset(value, spacingSizes) {
86
86
 
87
87
  export function getPresetValueFromCustomValue(value, spacingSizes) {
88
88
  // Return value as-is if it is already a preset;
89
- if (isValueSpacingPreset(value)) {
89
+ if (isValueSpacingPreset(value) || value === '0') {
90
90
  return value;
91
91
  }
92
92
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/spacing-sizes-control/utils.js"],"names":["__","sidesAll","sidesAxial","sidesBottom","sidesHorizontal","sidesLeft","sidesRight","sidesTop","sidesVertical","ALL_SIDES","DEFAULT_VALUES","top","undefined","right","bottom","left","ICONS","custom","axial","horizontal","vertical","LABELS","default","mixed","VIEWS","isValueSpacingPreset","value","includes","getCustomValueFromPreset","spacingSizes","slug","getSpacingPresetSlug","spacingSize","find","size","String","getPresetValueFromCustomValue","spacingMatch","getSpacingPresetCssVar","match","getSliderValueFromPreset","presetValue","parseFloat","sliderValue","findIndex","NaN","mode","arr","sort","a","b","filter","v","length","pop","getAllRawValue","values","Object","isValuesMixed","sides","Set","isValuesDefined","hasAxisSupport","axis","hasHorizontalSupport","hasVerticalSupport","getSupportedMenuItems","menuItems","label","icon","numberOfIndividualSides","forEach","side","hasBalancedSidesSupport","counts","getInitialView","sideValues","Boolean","hasMatchingAxialValues","hasNoValuesAndBalancedSides","entries","some","key"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SACCC,QADD,EAECC,UAFD,EAGCC,WAHD,EAICC,eAJD,EAKCC,SALD,EAMCC,UAND,EAOCC,QAPD,EAQCC,aARD,QASO,kBATP;AAWA,OAAO,MAAMC,SAAS,GAAG,CAAE,KAAF,EAAS,OAAT,EAAkB,QAAlB,EAA4B,MAA5B,CAAlB;AAEP,OAAO,MAAMC,cAAc,GAAG;AAC7BC,EAAAA,GAAG,EAAEC,SADwB;AAE7BC,EAAAA,KAAK,EAAED,SAFsB;AAG7BE,EAAAA,MAAM,EAAEF,SAHqB;AAI7BG,EAAAA,IAAI,EAAEH;AAJuB,CAAvB;AAOP,OAAO,MAAMI,KAAK,GAAG;AACpBC,EAAAA,MAAM,EAAEhB,QADY;AAEpBiB,EAAAA,KAAK,EAAEhB,UAFa;AAGpBiB,EAAAA,UAAU,EAAEf,eAHQ;AAIpBgB,EAAAA,QAAQ,EAAEZ,aAJU;AAKpBG,EAAAA,GAAG,EAAEJ,QALe;AAMpBM,EAAAA,KAAK,EAAEP,UANa;AAOpBQ,EAAAA,MAAM,EAAEX,WAPY;AAQpBY,EAAAA,IAAI,EAAEV;AARc,CAAd;AAWP,OAAO,MAAMgB,MAAM,GAAG;AACrBC,EAAAA,OAAO,EAAEtB,EAAE,CAAE,iBAAF,CADU;AAErBW,EAAAA,GAAG,EAAEX,EAAE,CAAE,KAAF,CAFc;AAGrBc,EAAAA,MAAM,EAAEd,EAAE,CAAE,QAAF,CAHW;AAIrBe,EAAAA,IAAI,EAAEf,EAAE,CAAE,MAAF,CAJa;AAKrBa,EAAAA,KAAK,EAAEb,EAAE,CAAE,OAAF,CALY;AAMrBuB,EAAAA,KAAK,EAAEvB,EAAE,CAAE,OAAF,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IAAIC,2BAD5B,CADD,EAGE;AACD,WAAOvD,KAAK,CAACN,KAAb;AACA,GAlBmD,CAoBpD;AACA;;;AACA,MAAK0D,UAAU,CAACvB,MAAX,KAAsB,CAA3B,EAA+B;AAC9B,QAAImB,IAAJ;AAEAf,IAAAA,MAAM,CAACuB,OAAP,CAAgBxB,MAAhB,EAAyByB,IAAzB,CAA+B,CAAE,CAAEC,GAAF,EAAOxD,KAAP,CAAF,KAAsB;AACpD8C,MAAAA,IAAI,GAAGU,GAAP;AACA,aAAOxD,KAAK,KAAKd,SAAjB;AACA,KAHD;AAKA,WAAO4D,IAAP;AACA,GA/BmD,CAiCpD;;;AACA,MAAKb,KAAK,EAAEN,MAAP,KAAkB,CAAlB,IAAuB,CAAEuB,UAAU,CAACvB,MAAzC,EAAkD;AACjD,WAAOM,KAAK,CAAE,CAAF,CAAZ;AACA,GApCmD,CAsCpD;;;AACA,SAAOnC,KAAK,CAACP,MAAb;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\tsidesAll,\n\tsidesAxial,\n\tsidesBottom,\n\tsidesHorizontal,\n\tsidesLeft,\n\tsidesRight,\n\tsidesTop,\n\tsidesVertical,\n} from '@wordpress/icons';\n\nexport const ALL_SIDES = [ 'top', 'right', 'bottom', 'left' ];\n\nexport const DEFAULT_VALUES = {\n\ttop: undefined,\n\tright: undefined,\n\tbottom: undefined,\n\tleft: undefined,\n};\n\nexport const ICONS = {\n\tcustom: sidesAll,\n\taxial: sidesAxial,\n\thorizontal: sidesHorizontal,\n\tvertical: sidesVertical,\n\ttop: sidesTop,\n\tright: sidesRight,\n\tbottom: sidesBottom,\n\tleft: sidesLeft,\n};\n\nexport const LABELS = {\n\tdefault: __( 'Spacing control' ),\n\ttop: __( 'Top' ),\n\tbottom: __( 'Bottom' ),\n\tleft: __( 'Left' ),\n\tright: __( 'Right' ),\n\tmixed: __( 'Mixed' ),\n\tvertical: __( 'Vertical' ),\n\thorizontal: __( 'Horizontal' ),\n\taxial: __( 'Horizontal & vertical' ),\n\tcustom: __( 'Custom' ),\n};\n\nexport const VIEWS = {\n\taxial: 'axial',\n\ttop: 'top',\n\tright: 'right',\n\tbottom: 'bottom',\n\tleft: 'left',\n\tcustom: 'custom',\n};\n\n/**\n * Checks is given value is a spacing preset.\n *\n * @param {string} value Value to check\n *\n * @return {boolean} Return true if value is string in format var:preset|spacing|.\n */\nexport function isValueSpacingPreset( value ) {\n\tif ( ! value?.includes ) {\n\t\treturn false;\n\t}\n\treturn value === '0' || value.includes( 'var:preset|spacing|' );\n}\n\n/**\n * Converts a spacing preset into a custom value.\n *\n * @param {string} value Value to convert\n * @param {Array} spacingSizes Array of the current spacing preset objects\n *\n * @return {string} Mapping of the spacing preset to its equivalent custom value.\n */\nexport function getCustomValueFromPreset( value, spacingSizes ) {\n\tif ( ! isValueSpacingPreset( value ) ) {\n\t\treturn value;\n\t}\n\n\tconst slug = getSpacingPresetSlug( value );\n\tconst spacingSize = spacingSizes.find(\n\t\t( size ) => String( size.slug ) === slug\n\t);\n\n\treturn spacingSize?.size;\n}\n\n/**\n * Converts a custom value to preset value if one can be found.\n *\n * Returns value as-is if no match is found.\n *\n * @param {string} value Value to convert\n * @param {Array} spacingSizes Array of the current spacing preset objects\n *\n * @return {string} The preset value if it can be found.\n */\nexport function getPresetValueFromCustomValue( value, spacingSizes ) {\n\t// Return value as-is if it is already a preset;\n\tif ( isValueSpacingPreset( value ) ) {\n\t\treturn value;\n\t}\n\n\tconst spacingMatch = spacingSizes.find(\n\t\t( size ) => String( size.size ) === String( value )\n\t);\n\n\tif ( spacingMatch?.slug ) {\n\t\treturn `var:preset|spacing|${ spacingMatch.slug }`;\n\t}\n\n\treturn value;\n}\n\n/**\n * Converts a spacing preset into a custom value.\n *\n * @param {string} value Value to convert.\n *\n * @return {string | undefined} CSS var string for given spacing preset value.\n */\nexport function getSpacingPresetCssVar( value ) {\n\tif ( ! value ) {\n\t\treturn;\n\t}\n\n\tconst slug = value.match( /var:preset\\|spacing\\|(.+)/ );\n\n\tif ( ! slug ) {\n\t\treturn value;\n\t}\n\n\treturn `var(--wp--preset--spacing--${ slug[ 1 ] })`;\n}\n\n/**\n * Returns the slug section of the given spacing preset string.\n *\n * @param {string} value Value to extract slug from.\n *\n * @return {string|undefined} The int value of the slug from given spacing preset.\n */\nexport function getSpacingPresetSlug( value ) {\n\tif ( ! value ) {\n\t\treturn;\n\t}\n\n\tif ( value === '0' || value === 'default' ) {\n\t\treturn value;\n\t}\n\n\tconst slug = value.match( /var:preset\\|spacing\\|(.+)/ );\n\n\treturn slug ? slug[ 1 ] : undefined;\n}\n\n/**\n * Converts spacing preset value into a Range component value .\n *\n * @param {string} presetValue Value to convert to Range value.\n * @param {Array} spacingSizes Array of current spacing preset value objects.\n *\n * @return {number} The int value for use in Range control.\n */\nexport function getSliderValueFromPreset( presetValue, spacingSizes ) {\n\tif ( presetValue === undefined ) {\n\t\treturn 0;\n\t}\n\tconst slug =\n\t\tparseFloat( presetValue, 10 ) === 0\n\t\t\t? '0'\n\t\t\t: getSpacingPresetSlug( presetValue );\n\tconst sliderValue = spacingSizes.findIndex( ( spacingSize ) => {\n\t\treturn String( spacingSize.slug ) === slug;\n\t} );\n\n\t// Returning NaN rather than undefined as undefined makes range control thumb sit in center\n\treturn sliderValue !== -1 ? sliderValue : NaN;\n}\n\n/**\n * Gets an items with the most occurrence within an array\n * https://stackoverflow.com/a/20762713\n *\n * @param {Array<any>} arr Array of items to check.\n * @return {any} The item with the most occurrences.\n */\nfunction mode( arr ) {\n\treturn arr\n\t\t.sort(\n\t\t\t( a, b ) =>\n\t\t\t\tarr.filter( ( v ) => v === a ).length -\n\t\t\t\tarr.filter( ( v ) => v === b ).length\n\t\t)\n\t\t.pop();\n}\n\n/**\n * Gets the 'all' input value from values data.\n *\n * @param {Object} values Box spacing values\n *\n * @return {string} The most common value from all sides of box.\n */\nexport function getAllRawValue( values = {} ) {\n\treturn mode( Object.values( values ) );\n}\n\n/**\n * Checks to determine if values are mixed.\n *\n * @param {Object} values Box values.\n * @param {Array} sides Sides that values relate to.\n *\n * @return {boolean} Whether values are mixed.\n */\nexport function isValuesMixed( values = {}, sides = ALL_SIDES ) {\n\treturn (\n\t\t( Object.values( values ).length >= 1 &&\n\t\t\tObject.values( values ).length < sides.length ) ||\n\t\tnew Set( Object.values( values ) ).size > 1\n\t);\n}\n\n/**\n * Checks to determine if values are defined.\n *\n * @param {Object} values Box values.\n *\n * @return {boolean} Whether values are defined.\n */\nexport function isValuesDefined( values ) {\n\tif ( values === undefined || values === null ) {\n\t\treturn false;\n\t}\n\treturn Object.values( values ).filter( ( value ) => !! value ).length > 0;\n}\n\n/**\n * Determines whether a particular axis has support. If no axis is\n * specified, this function checks if either axis is supported.\n *\n * @param {Array} sides Supported sides.\n * @param {string} axis Which axis to check.\n *\n * @return {boolean} Whether there is support for the specified axis or both axes.\n */\nexport function hasAxisSupport( sides, axis ) {\n\tif ( ! sides || ! sides.length ) {\n\t\treturn false;\n\t}\n\n\tconst hasHorizontalSupport =\n\t\tsides.includes( 'horizontal' ) ||\n\t\t( sides.includes( 'left' ) && sides.includes( 'right' ) );\n\n\tconst hasVerticalSupport =\n\t\tsides.includes( 'vertical' ) ||\n\t\t( sides.includes( 'top' ) && sides.includes( 'bottom' ) );\n\n\tif ( axis === 'horizontal' ) {\n\t\treturn hasHorizontalSupport;\n\t}\n\n\tif ( axis === 'vertical' ) {\n\t\treturn hasVerticalSupport;\n\t}\n\n\treturn hasHorizontalSupport || hasVerticalSupport;\n}\n\n/**\n * Determines which menu options should be included in the SidePicker.\n *\n * @param {Array} sides Supported sides.\n *\n * @return {Object} Menu options with each option containing label & icon.\n */\nexport function getSupportedMenuItems( sides ) {\n\tif ( ! sides || ! sides.length ) {\n\t\treturn {};\n\t}\n\n\tconst menuItems = {};\n\n\t// Determine the primary \"side\" menu options.\n\tconst hasHorizontalSupport = hasAxisSupport( sides, 'horizontal' );\n\tconst hasVerticalSupport = hasAxisSupport( sides, 'vertical' );\n\n\tif ( hasHorizontalSupport && hasVerticalSupport ) {\n\t\tmenuItems.axial = { label: LABELS.axial, icon: ICONS.axial };\n\t} else if ( hasHorizontalSupport ) {\n\t\tmenuItems.axial = { label: LABELS.horizontal, icon: ICONS.horizontal };\n\t} else if ( hasVerticalSupport ) {\n\t\tmenuItems.axial = { label: LABELS.vertical, icon: ICONS.vertical };\n\t}\n\n\t// Track whether we have any individual sides so we can omit the custom\n\t// option if required.\n\tlet numberOfIndividualSides = 0;\n\n\tALL_SIDES.forEach( ( side ) => {\n\t\tif ( sides.includes( side ) ) {\n\t\t\tnumberOfIndividualSides += 1;\n\t\t\tmenuItems[ side ] = {\n\t\t\t\tlabel: LABELS[ side ],\n\t\t\t\ticon: ICONS[ side ],\n\t\t\t};\n\t\t}\n\t} );\n\n\t// Add custom item if there are enough sides to warrant a separated view.\n\tif ( numberOfIndividualSides > 1 ) {\n\t\tmenuItems.custom = { label: LABELS.custom, icon: ICONS.custom };\n\t}\n\n\treturn menuItems;\n}\n\n/**\n * Checks if the supported sides are balanced for each axis.\n * - Horizontal - both left and right sides are supported.\n * - Vertical - both top and bottom are supported.\n *\n * @param {Array} sides The supported sides which may be axes as well.\n *\n * @return {boolean} Whether or not the supported sides are balanced.\n */\nexport function hasBalancedSidesSupport( sides = [] ) {\n\tconst counts = { top: 0, right: 0, bottom: 0, left: 0 };\n\tsides.forEach( ( side ) => ( counts[ side ] += 1 ) );\n\n\treturn (\n\t\t( counts.top + counts.bottom ) % 2 === 0 &&\n\t\t( counts.left + counts.right ) % 2 === 0\n\t);\n}\n\n/**\n * Determines which view the SpacingSizesControl should default to on its\n * first render; Axial, Custom, or Single side.\n *\n * @param {Object} values Current side values.\n * @param {Array} sides Supported sides.\n *\n * @return {string} View to display.\n */\nexport function getInitialView( values = {}, sides ) {\n\tconst { top, right, bottom, left } = values;\n\tconst sideValues = [ top, right, bottom, left ].filter( Boolean );\n\n\t// Axial ( Horizontal & vertical ).\n\t// - Has axial side support\n\t// - Has axial side values which match\n\t// - Has no values and the supported sides are balanced\n\tconst hasMatchingAxialValues =\n\t\ttop === bottom && left === right && ( !! top || !! left );\n\tconst hasNoValuesAndBalancedSides =\n\t\t! sideValues.length && hasBalancedSidesSupport( sides );\n\n\tif (\n\t\thasAxisSupport( sides ) &&\n\t\t( hasMatchingAxialValues || hasNoValuesAndBalancedSides )\n\t) {\n\t\treturn VIEWS.axial;\n\t}\n\n\t// Single side.\n\t// - Ensure the side returned is the first side that has a value.\n\tif ( sideValues.length === 1 ) {\n\t\tlet side;\n\n\t\tObject.entries( values ).some( ( [ key, value ] ) => {\n\t\t\tside = key;\n\t\t\treturn value !== undefined;\n\t\t} );\n\n\t\treturn side;\n\t}\n\n\t// Only single side supported and no value defined.\n\tif ( sides?.length === 1 && ! sideValues.length ) {\n\t\treturn sides[ 0 ];\n\t}\n\n\t// Default to the Custom (separated sides) view.\n\treturn VIEWS.custom;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/spacing-sizes-control/utils.js"],"names":["__","sidesAll","sidesAxial","sidesBottom","sidesHorizontal","sidesLeft","sidesRight","sidesTop","sidesVertical","ALL_SIDES","DEFAULT_VALUES","top","undefined","right","bottom","left","ICONS","custom","axial","horizontal","vertical","LABELS","default","mixed","VIEWS","isValueSpacingPreset","value","includes","getCustomValueFromPreset","spacingSizes","slug","getSpacingPresetSlug","spacingSize","find","size","String","getPresetValueFromCustomValue","spacingMatch","getSpacingPresetCssVar","match","getSliderValueFromPreset","presetValue","parseFloat","sliderValue","findIndex","NaN","mode","arr","sort","a","b","filter","v","length","pop","getAllRawValue","values","Object","isValuesMixed","sides","Set","isValuesDefined","hasAxisSupport","axis","hasHorizontalSupport","hasVerticalSupport","getSupportedMenuItems","menuItems","label","icon","numberOfIndividualSides","forEach","side","hasBalancedSidesSupport","counts","getInitialView","sideValues","Boolean","hasMatchingAxialValues","hasNoValuesAndBalancedSides","entries","some","key"],"mappings":"AAAA;AACA;AACA;AAC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B,CAA3B,EAA+B;AAC9B,QAAImB,IAAJ;AAEAf,IAAAA,MAAM,CAACuB,OAAP,CAAgBxB,MAAhB,EAAyByB,IAAzB,CAA+B,CAAE,CAAEC,GAAF,EAAOxD,KAAP,CAAF,KAAsB;AACpD8C,MAAAA,IAAI,GAAGU,GAAP;AACA,aAAOxD,KAAK,KAAKd,SAAjB;AACA,KAHD;AAKA,WAAO4D,IAAP;AACA,GA/BmD,CAiCpD;;;AACA,MAAKb,KAAK,EAAEN,MAAP,KAAkB,CAAlB,IAAuB,CAAEuB,UAAU,CAACvB,MAAzC,EAAkD;AACjD,WAAOM,KAAK,CAAE,CAAF,CAAZ;AACA,GApCmD,CAsCpD;;;AACA,SAAOnC,KAAK,CAACP,MAAb;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\tsidesAll,\n\tsidesAxial,\n\tsidesBottom,\n\tsidesHorizontal,\n\tsidesLeft,\n\tsidesRight,\n\tsidesTop,\n\tsidesVertical,\n} from '@wordpress/icons';\n\nexport const ALL_SIDES = [ 'top', 'right', 'bottom', 'left' ];\n\nexport const DEFAULT_VALUES = {\n\ttop: undefined,\n\tright: undefined,\n\tbottom: undefined,\n\tleft: undefined,\n};\n\nexport const ICONS = {\n\tcustom: sidesAll,\n\taxial: sidesAxial,\n\thorizontal: sidesHorizontal,\n\tvertical: sidesVertical,\n\ttop: sidesTop,\n\tright: sidesRight,\n\tbottom: sidesBottom,\n\tleft: sidesLeft,\n};\n\nexport const LABELS = {\n\tdefault: __( 'Spacing control' ),\n\ttop: __( 'Top' ),\n\tbottom: __( 'Bottom' ),\n\tleft: __( 'Left' ),\n\tright: __( 'Right' ),\n\tmixed: __( 'Mixed' ),\n\tvertical: __( 'Vertical' ),\n\thorizontal: __( 'Horizontal' ),\n\taxial: __( 'Horizontal & vertical' ),\n\tcustom: __( 'Custom' ),\n};\n\nexport const VIEWS = {\n\taxial: 'axial',\n\ttop: 'top',\n\tright: 'right',\n\tbottom: 'bottom',\n\tleft: 'left',\n\tcustom: 'custom',\n};\n\n/**\n * Checks is given value is a spacing preset.\n *\n * @param {string} value Value to check\n *\n * @return {boolean} Return true if value is string in format var:preset|spacing|.\n */\nexport function isValueSpacingPreset( value ) {\n\tif ( ! value?.includes ) {\n\t\treturn false;\n\t}\n\treturn value === '0' || value.includes( 'var:preset|spacing|' );\n}\n\n/**\n * Converts a spacing preset into a custom value.\n *\n * @param {string} value Value to convert\n * @param {Array} spacingSizes Array of the current spacing preset objects\n *\n * @return {string} Mapping of the spacing preset to its equivalent custom value.\n */\nexport function getCustomValueFromPreset( value, spacingSizes ) {\n\tif ( ! isValueSpacingPreset( value ) ) {\n\t\treturn value;\n\t}\n\n\tconst slug = getSpacingPresetSlug( value );\n\tconst spacingSize = spacingSizes.find(\n\t\t( size ) => String( size.slug ) === slug\n\t);\n\n\treturn spacingSize?.size;\n}\n\n/**\n * Converts a custom value to preset value if one can be found.\n *\n * Returns value as-is if no match is found.\n *\n * @param {string} value Value to convert\n * @param {Array} spacingSizes Array of the current spacing preset objects\n *\n * @return {string} The preset value if it can be found.\n */\nexport function getPresetValueFromCustomValue( value, spacingSizes ) {\n\t// Return value as-is if it is already a preset;\n\tif ( isValueSpacingPreset( value ) || value === '0' ) {\n\t\treturn value;\n\t}\n\n\tconst spacingMatch = spacingSizes.find(\n\t\t( size ) => String( size.size ) === String( value )\n\t);\n\n\tif ( spacingMatch?.slug ) {\n\t\treturn `var:preset|spacing|${ spacingMatch.slug }`;\n\t}\n\n\treturn value;\n}\n\n/**\n * Converts a spacing preset into a custom value.\n *\n * @param {string} value Value to convert.\n *\n * @return {string | undefined} CSS var string for given spacing preset value.\n */\nexport function getSpacingPresetCssVar( value ) {\n\tif ( ! value ) {\n\t\treturn;\n\t}\n\n\tconst slug = value.match( /var:preset\\|spacing\\|(.+)/ );\n\n\tif ( ! slug ) {\n\t\treturn value;\n\t}\n\n\treturn `var(--wp--preset--spacing--${ slug[ 1 ] })`;\n}\n\n/**\n * Returns the slug section of the given spacing preset string.\n *\n * @param {string} value Value to extract slug from.\n *\n * @return {string|undefined} The int value of the slug from given spacing preset.\n */\nexport function getSpacingPresetSlug( value ) {\n\tif ( ! value ) {\n\t\treturn;\n\t}\n\n\tif ( value === '0' || value === 'default' ) {\n\t\treturn value;\n\t}\n\n\tconst slug = value.match( /var:preset\\|spacing\\|(.+)/ );\n\n\treturn slug ? slug[ 1 ] : undefined;\n}\n\n/**\n * Converts spacing preset value into a Range component value .\n *\n * @param {string} presetValue Value to convert to Range value.\n * @param {Array} spacingSizes Array of current spacing preset value objects.\n *\n * @return {number} The int value for use in Range control.\n */\nexport function getSliderValueFromPreset( presetValue, spacingSizes ) {\n\tif ( presetValue === undefined ) {\n\t\treturn 0;\n\t}\n\tconst slug =\n\t\tparseFloat( presetValue, 10 ) === 0\n\t\t\t? '0'\n\t\t\t: getSpacingPresetSlug( presetValue );\n\tconst sliderValue = spacingSizes.findIndex( ( spacingSize ) => {\n\t\treturn String( spacingSize.slug ) === slug;\n\t} );\n\n\t// Returning NaN rather than undefined as undefined makes range control thumb sit in center\n\treturn sliderValue !== -1 ? sliderValue : NaN;\n}\n\n/**\n * Gets an items with the most occurrence within an array\n * https://stackoverflow.com/a/20762713\n *\n * @param {Array<any>} arr Array of items to check.\n * @return {any} The item with the most occurrences.\n */\nfunction mode( arr ) {\n\treturn arr\n\t\t.sort(\n\t\t\t( a, b ) =>\n\t\t\t\tarr.filter( ( v ) => v === a ).length -\n\t\t\t\tarr.filter( ( v ) => v === b ).length\n\t\t)\n\t\t.pop();\n}\n\n/**\n * Gets the 'all' input value from values data.\n *\n * @param {Object} values Box spacing values\n *\n * @return {string} The most common value from all sides of box.\n */\nexport function getAllRawValue( values = {} ) {\n\treturn mode( Object.values( values ) );\n}\n\n/**\n * Checks to determine if values are mixed.\n *\n * @param {Object} values Box values.\n * @param {Array} sides Sides that values relate to.\n *\n * @return {boolean} Whether values are mixed.\n */\nexport function isValuesMixed( values = {}, sides = ALL_SIDES ) {\n\treturn (\n\t\t( Object.values( values ).length >= 1 &&\n\t\t\tObject.values( values ).length < sides.length ) ||\n\t\tnew Set( Object.values( values ) ).size > 1\n\t);\n}\n\n/**\n * Checks to determine if values are defined.\n *\n * @param {Object} values Box values.\n *\n * @return {boolean} Whether values are defined.\n */\nexport function isValuesDefined( values ) {\n\tif ( values === undefined || values === null ) {\n\t\treturn false;\n\t}\n\treturn Object.values( values ).filter( ( value ) => !! value ).length > 0;\n}\n\n/**\n * Determines whether a particular axis has support. If no axis is\n * specified, this function checks if either axis is supported.\n *\n * @param {Array} sides Supported sides.\n * @param {string} axis Which axis to check.\n *\n * @return {boolean} Whether there is support for the specified axis or both axes.\n */\nexport function hasAxisSupport( sides, axis ) {\n\tif ( ! sides || ! sides.length ) {\n\t\treturn false;\n\t}\n\n\tconst hasHorizontalSupport =\n\t\tsides.includes( 'horizontal' ) ||\n\t\t( sides.includes( 'left' ) && sides.includes( 'right' ) );\n\n\tconst hasVerticalSupport =\n\t\tsides.includes( 'vertical' ) ||\n\t\t( sides.includes( 'top' ) && sides.includes( 'bottom' ) );\n\n\tif ( axis === 'horizontal' ) {\n\t\treturn hasHorizontalSupport;\n\t}\n\n\tif ( axis === 'vertical' ) {\n\t\treturn hasVerticalSupport;\n\t}\n\n\treturn hasHorizontalSupport || hasVerticalSupport;\n}\n\n/**\n * Determines which menu options should be included in the SidePicker.\n *\n * @param {Array} sides Supported sides.\n *\n * @return {Object} Menu options with each option containing label & icon.\n */\nexport function getSupportedMenuItems( sides ) {\n\tif ( ! sides || ! sides.length ) {\n\t\treturn {};\n\t}\n\n\tconst menuItems = {};\n\n\t// Determine the primary \"side\" menu options.\n\tconst hasHorizontalSupport = hasAxisSupport( sides, 'horizontal' );\n\tconst hasVerticalSupport = hasAxisSupport( sides, 'vertical' );\n\n\tif ( hasHorizontalSupport && hasVerticalSupport ) {\n\t\tmenuItems.axial = { label: LABELS.axial, icon: ICONS.axial };\n\t} else if ( hasHorizontalSupport ) {\n\t\tmenuItems.axial = { label: LABELS.horizontal, icon: ICONS.horizontal };\n\t} else if ( hasVerticalSupport ) {\n\t\tmenuItems.axial = { label: LABELS.vertical, icon: ICONS.vertical };\n\t}\n\n\t// Track whether we have any individual sides so we can omit the custom\n\t// option if required.\n\tlet numberOfIndividualSides = 0;\n\n\tALL_SIDES.forEach( ( side ) => {\n\t\tif ( sides.includes( side ) ) {\n\t\t\tnumberOfIndividualSides += 1;\n\t\t\tmenuItems[ side ] = {\n\t\t\t\tlabel: LABELS[ side ],\n\t\t\t\ticon: ICONS[ side ],\n\t\t\t};\n\t\t}\n\t} );\n\n\t// Add custom item if there are enough sides to warrant a separated view.\n\tif ( numberOfIndividualSides > 1 ) {\n\t\tmenuItems.custom = { label: LABELS.custom, icon: ICONS.custom };\n\t}\n\n\treturn menuItems;\n}\n\n/**\n * Checks if the supported sides are balanced for each axis.\n * - Horizontal - both left and right sides are supported.\n * - Vertical - both top and bottom are supported.\n *\n * @param {Array} sides The supported sides which may be axes as well.\n *\n * @return {boolean} Whether or not the supported sides are balanced.\n */\nexport function hasBalancedSidesSupport( sides = [] ) {\n\tconst counts = { top: 0, right: 0, bottom: 0, left: 0 };\n\tsides.forEach( ( side ) => ( counts[ side ] += 1 ) );\n\n\treturn (\n\t\t( counts.top + counts.bottom ) % 2 === 0 &&\n\t\t( counts.left + counts.right ) % 2 === 0\n\t);\n}\n\n/**\n * Determines which view the SpacingSizesControl should default to on its\n * first render; Axial, Custom, or Single side.\n *\n * @param {Object} values Current side values.\n * @param {Array} sides Supported sides.\n *\n * @return {string} View to display.\n */\nexport function getInitialView( values = {}, sides ) {\n\tconst { top, right, bottom, left } = values;\n\tconst sideValues = [ top, right, bottom, left ].filter( Boolean );\n\n\t// Axial ( Horizontal & vertical ).\n\t// - Has axial side support\n\t// - Has axial side values which match\n\t// - Has no values and the supported sides are balanced\n\tconst hasMatchingAxialValues =\n\t\ttop === bottom && left === right && ( !! top || !! left );\n\tconst hasNoValuesAndBalancedSides =\n\t\t! sideValues.length && hasBalancedSidesSupport( sides );\n\n\tif (\n\t\thasAxisSupport( sides ) &&\n\t\t( hasMatchingAxialValues || hasNoValuesAndBalancedSides )\n\t) {\n\t\treturn VIEWS.axial;\n\t}\n\n\t// Single side.\n\t// - Ensure the side returned is the first side that has a value.\n\tif ( sideValues.length === 1 ) {\n\t\tlet side;\n\n\t\tObject.entries( values ).some( ( [ key, value ] ) => {\n\t\t\tside = key;\n\t\t\treturn value !== undefined;\n\t\t} );\n\n\t\treturn side;\n\t}\n\n\t// Only single side supported and no value defined.\n\tif ( sides?.length === 1 && ! sideValues.length ) {\n\t\treturn sides[ 0 ];\n\t}\n\n\t// Default to the Custom (separated sides) view.\n\treturn VIEWS.custom;\n}\n"]}
@@ -64,7 +64,8 @@ export default function useBlockDisplayInformation(clientId) {
64
64
  if (!clientId) return null;
65
65
  const {
66
66
  getBlockName,
67
- getBlockAttributes
67
+ getBlockAttributes,
68
+ __experimentalGetReusableBlockTitle
68
69
  } = select(blockEditorStore);
69
70
  const {
70
71
  getBlockType,
@@ -75,11 +76,14 @@ export default function useBlockDisplayInformation(clientId) {
75
76
  if (!blockType) return null;
76
77
  const attributes = getBlockAttributes(clientId);
77
78
  const match = getActiveBlockVariation(blockName, attributes);
78
- const isSynced = isReusableBlock(blockType) || isTemplatePart(blockType);
79
+ const isReusable = isReusableBlock(blockType);
80
+ const resusableTitle = isReusable ? __experimentalGetReusableBlockTitle(attributes.ref) : undefined;
81
+ const title = resusableTitle || blockType.title;
82
+ const isSynced = isReusable || isTemplatePart(blockType);
79
83
  const positionLabel = getPositionTypeLabel(attributes);
80
84
  const blockTypeInfo = {
81
85
  isSynced,
82
- title: blockType.title,
86
+ title,
83
87
  icon: blockType.icon,
84
88
  description: blockType.description,
85
89
  anchor: attributes?.anchor,
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/use-block-display-information/index.js"],"names":["useSelect","store","blocksStore","isReusableBlock","isTemplatePart","__","blockEditorStore","getPositionTypeLabel","attributes","positionType","style","position","type","useBlockDisplayInformation","clientId","select","getBlockName","getBlockAttributes","getBlockType","getActiveBlockVariation","blockName","blockType","match","isSynced","positionLabel","blockTypeInfo","title","icon","description","anchor"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,iBAA1B;AACA,SACCC,KAAK,IAAIC,WADV,EAECC,eAFD,EAGCC,cAHD,QAIO,mBAJP;AAKA,SAASC,EAAT,QAAmB,iBAAnB;AAEA;AACA;AACA;;AACA,SAASJ,KAAK,IAAIK,gBAAlB,QAA0C,aAA1C;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,oBAAT,CAA+BC,UAA/B,EAA4C;AAC3C,QAAMC,YAAY,GAAGD,UAAU,EAAEE,KAAZ,EAAmBC,QAAnB,EAA6BC,IAAlD;;AAEA,MAAKH,YAAY,KAAK,QAAtB,EAAiC;AAChC,WAAOJ,EAAE,CAAE,QAAF,CAAT;AACA;;AAED,MAAKI,YAAY,KAAK,OAAtB,EAAgC;AAC/B,WAAOJ,EAAE,CAAE,OAAF,CAAT;AACA;;AAED,SAAO,IAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AAEA,eAAe,SAASQ,0BAAT,CAAqCC,QAArC,EAAgD;AAC9D,SAAOd,SAAS,CACbe,MAAF,IAAc;AACb,QAAK,CAAED,QAAP,EAAkB,OAAO,IAAP;AAClB,UAAM;AAAEE,MAAAA,YAAF;AAAgBC,MAAAA;AAAhB,QACLF,MAAM,CAAET,gBAAF,CADP;AAEA,UAAM;AAAEY,MAAAA,YAAF;AAAgBC,MAAAA;AAAhB,QACLJ,MAAM,CAAEb,WAAF,CADP;AAEA,UAAMkB,SAAS,GAAGJ,YAAY,CAAEF,QAAF,CAA9B;AACA,UAAMO,SAAS,GAAGH,YA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\tstore as blocksStore,\n\tisReusableBlock,\n\tisTemplatePart,\n} from '@wordpress/blocks';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\n/** @typedef {import('@wordpress/blocks').WPIcon} WPIcon */\n\n/**\n * Contains basic block's information for display reasons.\n *\n * @typedef {Object} WPBlockDisplayInformation\n *\n * @property {boolean} isSynced True if is a reusable block or template part\n * @property {string} title Human-readable block type label.\n * @property {WPIcon} icon Block type icon.\n * @property {string} description A detailed block type description.\n * @property {string} anchor HTML anchor.\n */\n\n/**\n * Get the display label for a block's position type.\n *\n * @param {Object} attributes Block attributes.\n * @return {string} The position type label.\n */\nfunction getPositionTypeLabel( attributes ) {\n\tconst positionType = attributes?.style?.position?.type;\n\n\tif ( positionType === 'sticky' ) {\n\t\treturn __( 'Sticky' );\n\t}\n\n\tif ( positionType === 'fixed' ) {\n\t\treturn __( 'Fixed' );\n\t}\n\n\treturn null;\n}\n\n/**\n * Hook used to try to find a matching block variation and return\n * the appropriate information for display reasons. In order to\n * to try to find a match we need to things:\n * 1. Block's client id to extract it's current attributes.\n * 2. A block variation should have set `isActive` prop to a proper function.\n *\n * If for any reason a block variation match cannot be found,\n * the returned information come from the Block Type.\n * If no blockType is found with the provided clientId, returns null.\n *\n * @param {string} clientId Block's client id.\n * @return {?WPBlockDisplayInformation} Block's display information, or `null` when the block or its type not found.\n */\n\nexport default function useBlockDisplayInformation( clientId ) {\n\treturn useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! clientId ) return null;\n\t\t\tconst { getBlockName, getBlockAttributes } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst { getBlockType, getActiveBlockVariation } =\n\t\t\t\tselect( blocksStore );\n\t\t\tconst blockName = getBlockName( clientId );\n\t\t\tconst blockType = getBlockType( blockName );\n\t\t\tif ( ! blockType ) return null;\n\t\t\tconst attributes = getBlockAttributes( clientId );\n\t\t\tconst match = getActiveBlockVariation( blockName, attributes );\n\t\t\tconst isSynced =\n\t\t\t\tisReusableBlock( blockType ) || isTemplatePart( blockType );\n\t\t\tconst positionLabel = getPositionTypeLabel( attributes );\n\t\t\tconst blockTypeInfo = {\n\t\t\t\tisSynced,\n\t\t\t\ttitle: blockType.title,\n\t\t\t\ticon: blockType.icon,\n\t\t\t\tdescription: blockType.description,\n\t\t\t\tanchor: attributes?.anchor,\n\t\t\t\tpositionLabel,\n\t\t\t\tpositionType: attributes?.style?.position?.type,\n\t\t\t};\n\t\t\tif ( ! match ) return blockTypeInfo;\n\n\t\t\treturn {\n\t\t\t\tisSynced,\n\t\t\t\ttitle: match.title || blockType.title,\n\t\t\t\ticon: match.icon || blockType.icon,\n\t\t\t\tdescription: match.description || blockType.description,\n\t\t\t\tanchor: attributes?.anchor,\n\t\t\t\tpositionLabel,\n\t\t\t\tpositionType: attributes?.style?.position?.type,\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/use-block-display-information/index.js"],"names":["useSelect","store","blocksStore","isReusableBlock","isTemplatePart","__","blockEditorStore","getPositionTypeLabel","attributes","positionType","style","position","type","useBlockDisplayInformation","clientId","select","getBlockName","getBlockAttributes","__experimentalGetReusableBlockTitle","getBlockType","getActiveBlockVariation","blockName","blockType","match","isReusable","resusableTitle","ref","undefined","title","isSynced","positionLabel","blockTypeInfo","icon","description","anchor"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,iBAA1B;AACA,SACCC,KAAK,IAAIC,WADV,EAECC,eAFD,EAGCC,cAHD,QAIO,mBAJP;AAKA,SAASC,EAAT,QAAmB,iBAAnB;AAEA;AACA;AACA;;AACA,SAASJ,KAAK,IAAIK,gBAAlB,QAA0C,aAA1C;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,oBAAT,CAA+BC,UAA/B,EAA4C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,oBAAoB,CAAEC,UAAF,CAA1C;AACA,UAAMuB,aAAa,GAAG;AACrBF,MAAAA,QADqB;AAErBD,MAAAA,KAFqB;AAGrBI,MAAAA,IAAI,EAAEV,SAAS,CAACU,IAHK;AAIrBC,MAAAA,WAAW,EAAEX,SAAS,CAACW,WAJF;AAKrBC,MAAAA,MAAM,EAAE1B,UAAU,EAAE0B,MALC;AAMrBJ,MAAAA,aANqB;AAOrBrB,MAAAA,YAAY,EAAED,UAAU,EAAEE,KAAZ,EAAmBC,QAAnB,EAA6BC;AAPtB,KAAtB;AASA,QAAK,CAAEW,KAAP,EAAe,OAAOQ,aAAP;AAEf,WAAO;AACNF,MAAAA,QADM;AAEND,MAAAA,KAAK,EAAEL,KAAK,CAACK,KAAN,IAAeN,SAAS,CAACM,KAF1B;AAGNI,MAAAA,IAAI,EAAET,KAAK,CAACS,IAAN,IAAcV,SAAS,CAACU,IAHxB;AAINC,MAAAA,WAAW,EAAEV,KAAK,CAACU,WAAN,IAAqBX,SAAS,CAACW,WAJtC;AAKNC,MAAAA,MAAM,EAAE1B,UAAU,EAAE0B,MALd;AAMNJ,MAAAA,aANM;AAONrB,MAAAA,YAAY,EAAED,UAAU,EAAEE,KAAZ,EAAmBC,QAAnB,EAA6BC;AAPrC,KAAP;AASA,GA1Cc,EA2Cf,CAAEE,QAAF,CA3Ce,CAAhB;AA6CA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport {\n\tstore as blocksStore,\n\tisReusableBlock,\n\tisTemplatePart,\n} from '@wordpress/blocks';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\n/** @typedef {import('@wordpress/blocks').WPIcon} WPIcon */\n\n/**\n * Contains basic block's information for display reasons.\n *\n * @typedef {Object} WPBlockDisplayInformation\n *\n * @property {boolean} isSynced True if is a reusable block or template part\n * @property {string} title Human-readable block type label.\n * @property {WPIcon} icon Block type icon.\n * @property {string} description A detailed block type description.\n * @property {string} anchor HTML anchor.\n */\n\n/**\n * Get the display label for a block's position type.\n *\n * @param {Object} attributes Block attributes.\n * @return {string} The position type label.\n */\nfunction getPositionTypeLabel( attributes ) {\n\tconst positionType = attributes?.style?.position?.type;\n\n\tif ( positionType === 'sticky' ) {\n\t\treturn __( 'Sticky' );\n\t}\n\n\tif ( positionType === 'fixed' ) {\n\t\treturn __( 'Fixed' );\n\t}\n\n\treturn null;\n}\n\n/**\n * Hook used to try to find a matching block variation and return\n * the appropriate information for display reasons. In order to\n * to try to find a match we need to things:\n * 1. Block's client id to extract it's current attributes.\n * 2. A block variation should have set `isActive` prop to a proper function.\n *\n * If for any reason a block variation match cannot be found,\n * the returned information come from the Block Type.\n * If no blockType is found with the provided clientId, returns null.\n *\n * @param {string} clientId Block's client id.\n * @return {?WPBlockDisplayInformation} Block's display information, or `null` when the block or its type not found.\n */\n\nexport default function useBlockDisplayInformation( clientId ) {\n\treturn useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! clientId ) return null;\n\t\t\tconst {\n\t\t\t\tgetBlockName,\n\t\t\t\tgetBlockAttributes,\n\t\t\t\t__experimentalGetReusableBlockTitle,\n\t\t\t} = select( blockEditorStore );\n\t\t\tconst { getBlockType, getActiveBlockVariation } =\n\t\t\t\tselect( blocksStore );\n\t\t\tconst blockName = getBlockName( clientId );\n\t\t\tconst blockType = getBlockType( blockName );\n\t\t\tif ( ! blockType ) return null;\n\t\t\tconst attributes = getBlockAttributes( clientId );\n\t\t\tconst match = getActiveBlockVariation( blockName, attributes );\n\t\t\tconst isReusable = isReusableBlock( blockType );\n\t\t\tconst resusableTitle = isReusable\n\t\t\t\t? __experimentalGetReusableBlockTitle( attributes.ref )\n\t\t\t\t: undefined;\n\t\t\tconst title = resusableTitle || blockType.title;\n\t\t\tconst isSynced = isReusable || isTemplatePart( blockType );\n\t\t\tconst positionLabel = getPositionTypeLabel( attributes );\n\t\t\tconst blockTypeInfo = {\n\t\t\t\tisSynced,\n\t\t\t\ttitle,\n\t\t\t\ticon: blockType.icon,\n\t\t\t\tdescription: blockType.description,\n\t\t\t\tanchor: attributes?.anchor,\n\t\t\t\tpositionLabel,\n\t\t\t\tpositionType: attributes?.style?.position?.type,\n\t\t\t};\n\t\t\tif ( ! match ) return blockTypeInfo;\n\n\t\t\treturn {\n\t\t\t\tisSynced,\n\t\t\t\ttitle: match.title || blockType.title,\n\t\t\t\ticon: match.icon || blockType.icon,\n\t\t\t\tdescription: match.description || blockType.description,\n\t\t\t\tanchor: attributes?.anchor,\n\t\t\t\tpositionLabel,\n\t\t\t\tpositionType: attributes?.style?.position?.type,\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n}\n"]}
@@ -1,14 +1,13 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { useSharedValue } from 'react-native-reanimated';
4
+ import { runOnJS, useDerivedValue, useSharedValue } from 'react-native-reanimated';
5
5
  /**
6
6
  * WordPress dependencies
7
7
  */
8
8
 
9
9
  import { useSelect } from '@wordpress/data';
10
10
  import { useCallback } from '@wordpress/element';
11
- import { useThrottle } from '@wordpress/compose';
12
11
  /**
13
12
  * Internal dependencies
14
13
  */
@@ -17,6 +16,8 @@ import { store as blockEditorStore } from '../../store';
17
16
  import { useBlockListContext } from '../block-list/block-list-context';
18
17
  import { getDistanceToNearestEdge } from '../../utils/math';
19
18
  import useOnBlockDrop from '../use-on-block-drop';
19
+ const UPDATE_TARGET_BLOCK_INDEX_THRESHOLD = 20; // In pixels
20
+
20
21
  /** @typedef {import('../../utils/math').WPPoint} WPPoint */
21
22
 
22
23
  /**
@@ -97,6 +98,14 @@ export default function useBlockDropZone({
97
98
  rootClientId: targetRootClientId = ''
98
99
  } = {}) {
99
100
  const targetBlockIndex = useSharedValue(null);
101
+ const dragPosition = {
102
+ x: useSharedValue(0),
103
+ y: useSharedValue(0)
104
+ };
105
+ const prevDragPosition = {
106
+ x: useSharedValue(0),
107
+ y: useSharedValue(0)
108
+ };
100
109
  const {
101
110
  getBlockListSettings,
102
111
  getSettings
@@ -106,11 +115,12 @@ export default function useBlockDropZone({
106
115
  getBlockLayoutsOrderedByYCoord
107
116
  } = useBlockListContext();
108
117
  const getSortedBlocksLayouts = useCallback(() => {
109
- return getBlockLayoutsOrderedByYCoord(blocksLayouts.current);
118
+ return getBlockLayoutsOrderedByYCoord(blocksLayouts.current); // We use the value of `blocksLayouts` as the dependency.
119
+ // eslint-disable-next-line react-hooks/exhaustive-deps
110
120
  }, [blocksLayouts.current]);
111
121
  const isRTL = getSettings().isRTL;
112
122
  const onBlockDrop = useOnBlockDrop();
113
- const throttled = useThrottle(useCallback(event => {
123
+ const updateTargetBlockIndex = useCallback(event => {
114
124
  const sortedBlockLayouts = getSortedBlocksLayouts();
115
125
  const targetIndex = getNearestBlockIndex(sortedBlockLayouts, {
116
126
  x: event.x,
@@ -120,14 +130,46 @@ export default function useBlockDropZone({
120
130
  if (targetIndex !== null) {
121
131
  targetBlockIndex.value = targetIndex !== null && targetIndex !== void 0 ? targetIndex : 0;
122
132
  }
123
- }, [getSortedBlocksLayouts, getNearestBlockIndex, getBlockListSettings, targetBlockIndex]), 200);
133
+ }, [getSortedBlocksLayouts, getBlockListSettings, targetRootClientId, isRTL, targetBlockIndex]);
134
+ useDerivedValue(() => {
135
+ const x = dragPosition.x.value;
136
+ const y = dragPosition.y.value;
137
+ const prevX = prevDragPosition.x.value;
138
+ const prevY = prevDragPosition.y.value; // `updateTargetBlockIndex` performs expensive calculations, so we throttle
139
+ // the call using a offset threshold based on the dragging position.
140
+
141
+ if (Math.abs(x - prevX) >= UPDATE_TARGET_BLOCK_INDEX_THRESHOLD || Math.abs(y - prevY) >= UPDATE_TARGET_BLOCK_INDEX_THRESHOLD) {
142
+ runOnJS(updateTargetBlockIndex)({
143
+ x,
144
+ y
145
+ });
146
+ prevDragPosition.x.value = x;
147
+ prevDragPosition.y.value = y;
148
+ return true;
149
+ }
150
+
151
+ return false;
152
+ });
124
153
  return {
125
- onBlockDragOver(event) {
126
- throttled(event);
154
+ onBlockDragOver({
155
+ x,
156
+ y
157
+ }) {
158
+ dragPosition.x.value = x;
159
+ dragPosition.y.value = y;
160
+ },
161
+
162
+ onBlockDragOverWorklet({
163
+ x,
164
+ y
165
+ }) {
166
+ 'worklet';
167
+
168
+ dragPosition.x.value = x;
169
+ dragPosition.y.value = y;
127
170
  },
128
171
 
129
172
  onBlockDragEnd() {
130
- throttled.cancel();
131
173
  targetBlockIndex.value = null;
132
174
  },
133
175
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/use-block-drop-zone/index.native.js"],"names":["useSharedValue","useSelect","useCallback","useThrottle","store","blockEditorStore","useBlockListContext","getDistanceToNearestEdge","useOnBlockDrop","getNearestBlockIndex","blocksLayouts","position","orientation","isRTL","allowedEdges","isRightToLeft","candidateIndex","candidateDistance","forEach","element","index","x","y","width","height","rect","top","right","bottom","left","distance","edge","undefined","isTrailingEdge","offset","useBlockDropZone","rootClientId","targetRootClientId","targetBlockIndex","getBlockListSettings","getSettings","getBlockLayoutsOrderedByYCoord","getSortedBlocksLayouts","current","onBlockDrop","throttled","event","sortedBlockLayouts","targetIndex","value","onBlockDragOver","onBlockDragEnd","cancel"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,cAAT,QAA+B,yBAA/B;AAEA;AACA;AACA;;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,WAAT,QAA4B,oBAA5B;AACA,SAASC,WAAT,QAA4B,oBAA5B;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AACA,SAASC,mBAAT,QAAoC,kCAApC;AACA,SAASC,wBAAT,QAAyC,kBAAzC;AACA,OAAOC,cAAP,MAA2B,sBAA3B;AAEA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,oBAAT,CACNC,aADM,EAENC,QAFM,EAGN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AECjC,oBAFD,EAGC8B,oBAHD,EAICD,gBAJD,CAdU,CADiB,EAsB5B,GAtB4B,CAA7B;AAyBA,SAAO;AACNY,IAAAA,eAAe,CAAEJ,KAAF,EAAU;AACxBD,MAAAA,SAAS,CAAEC,KAAF,CAAT;AACA,KAHK;;AAINK,IAAAA,cAAc,GAAG;AAChBN,MAAAA,SAAS,CAACO,MAAV;AACAd,MAAAA,gBAAgB,CAACW,KAAjB,GAAyB,IAAzB;AACA,KAPK;;AAQNL,IAAAA,WAAW,EAAIE,KAAF,IAAa;AACzB,UAAKR,gBAAgB,CAACW,KAAjB,KAA2B,IAAhC,EAAuC;AACtCL,QAAAA,WAAW,CAAE,EACZ,GAAGE,KADS;AAEZT,UAAAA,kBAFY;AAGZC,UAAAA,gBAAgB,EAAEA,gBAAgB,CAACW;AAHvB,SAAF,CAAX;AAKA;AACD,KAhBK;AAiBNX,IAAAA;AAjBM,GAAP;AAmBA","sourcesContent":["/**\n * External dependencies\n */\nimport { useSharedValue } from 'react-native-reanimated';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { useCallback } from '@wordpress/element';\nimport { useThrottle } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { useBlockListContext } from '../block-list/block-list-context';\nimport { getDistanceToNearestEdge } from '../../utils/math';\nimport useOnBlockDrop from '../use-on-block-drop';\n\n/** @typedef {import('../../utils/math').WPPoint} WPPoint */\n\n/**\n * The orientation of a block list.\n *\n * @typedef {'horizontal'|'vertical'|undefined} WPBlockListOrientation\n */\n\n/**\n * Given a list of blocks layouts finds the index that a block should be dropped at.\n *\n * @param {Object} blocksLayouts Blocks layouts object.\n * @param {WPPoint} position The position of the item being dragged.\n * @param {WPBlockListOrientation} orientation The orientation of a block list.\n * @param {boolean} isRTL Check if current locale is RTL.\n *\n * @return {number|undefined} The block index that's closest to the drag position.\n */\nexport function getNearestBlockIndex(\n\tblocksLayouts,\n\tposition,\n\torientation,\n\tisRTL\n) {\n\tconst allowedEdges =\n\t\torientation === 'horizontal'\n\t\t\t? [ 'left', 'right' ]\n\t\t\t: [ 'top', 'bottom' ];\n\n\tconst isRightToLeft = isRTL;\n\n\tlet candidateIndex;\n\tlet candidateDistance;\n\n\t// Only enabled for root level blocks.\n\tblocksLayouts.forEach( ( element, index ) => {\n\t\tconst { x, y, width, height } = element;\n\t\tconst rect = {\n\t\t\tx: element.x,\n\t\t\ty: element.y,\n\t\t\ttop: y,\n\t\t\tright: x + width,\n\t\t\tbottom: y + height,\n\t\t\tleft: x,\n\t\t\twidth,\n\t\t\theight,\n\t\t};\n\t\tconst [ distance, edge ] = getDistanceToNearestEdge(\n\t\t\tposition,\n\t\t\trect,\n\t\t\tallowedEdges\n\t\t);\n\n\t\tif ( candidateDistance === undefined || distance < candidateDistance ) {\n\t\t\t// If the user is dropping to the trailing edge of the block\n\t\t\t// add 1 to the index to represent dragging after.\n\t\t\t// Take RTL languages into account where the left edge is\n\t\t\t// the trailing edge.\n\t\t\tconst isTrailingEdge =\n\t\t\t\tedge === 'bottom' ||\n\t\t\t\t( ! isRightToLeft && edge === 'right' ) ||\n\t\t\t\t( isRightToLeft && edge === 'left' );\n\t\t\tconst offset = isTrailingEdge ? 1 : 0;\n\n\t\t\t// Update the currently known best candidate.\n\t\t\tcandidateDistance = distance;\n\t\t\tcandidateIndex = index + offset;\n\t\t}\n\t} );\n\treturn candidateIndex;\n}\n\n/**\n * @typedef {Object} WPBlockDropZoneConfig\n * @property {string} rootClientId The root client id for the block list.\n */\n\n/**\n * A React hook that can be used to make a block list handle drag and drop.\n *\n * @param {WPBlockDropZoneConfig} dropZoneConfig configuration data for the drop zone.\n *\n * @return {Object} An object that contains `targetBlockIndex` and the event\n * handlers `onBlockDragOver`, `onBlockDragEnd` and `onBlockDrop`.\n */\nexport default function useBlockDropZone( {\n\t// An undefined value represents a top-level block. Default to an empty\n\t// string for this so that `targetRootClientId` can be easily compared to\n\t// values returned by the `getRootBlockClientId` selector, which also uses\n\t// an empty string to represent top-level blocks.\n\trootClientId: targetRootClientId = '',\n} = {} ) {\n\tconst targetBlockIndex = useSharedValue( null );\n\n\tconst { getBlockListSettings, getSettings } = useSelect( blockEditorStore );\n\tconst { blocksLayouts, getBlockLayoutsOrderedByYCoord } =\n\t\tuseBlockListContext();\n\n\tconst getSortedBlocksLayouts = useCallback( () => {\n\t\treturn getBlockLayoutsOrderedByYCoord( blocksLayouts.current );\n\t}, [ blocksLayouts.current ] );\n\n\tconst isRTL = getSettings().isRTL;\n\n\tconst onBlockDrop = useOnBlockDrop();\n\n\tconst throttled = useThrottle(\n\t\tuseCallback(\n\t\t\t( event ) => {\n\t\t\t\tconst sortedBlockLayouts = getSortedBlocksLayouts();\n\n\t\t\t\tconst targetIndex = getNearestBlockIndex(\n\t\t\t\t\tsortedBlockLayouts,\n\t\t\t\t\t{ x: event.x, y: event.y },\n\t\t\t\t\tgetBlockListSettings( targetRootClientId )?.orientation,\n\t\t\t\t\tisRTL\n\t\t\t\t);\n\t\t\t\tif ( targetIndex !== null ) {\n\t\t\t\t\ttargetBlockIndex.value = targetIndex ?? 0;\n\t\t\t\t}\n\t\t\t},\n\t\t\t[\n\t\t\t\tgetSortedBlocksLayouts,\n\t\t\t\tgetNearestBlockIndex,\n\t\t\t\tgetBlockListSettings,\n\t\t\t\ttargetBlockIndex,\n\t\t\t]\n\t\t),\n\t\t200\n\t);\n\n\treturn {\n\t\tonBlockDragOver( event ) {\n\t\t\tthrottled( event );\n\t\t},\n\t\tonBlockDragEnd() {\n\t\t\tthrottled.cancel();\n\t\t\ttargetBlockIndex.value = null;\n\t\t},\n\t\tonBlockDrop: ( event ) => {\n\t\t\tif ( targetBlockIndex.value !== null ) {\n\t\t\t\tonBlockDrop( {\n\t\t\t\t\t...event,\n\t\t\t\t\ttargetRootClientId,\n\t\t\t\t\ttargetBlockIndex: targetBlockIndex.value,\n\t\t\t\t} );\n\t\t\t}\n\t\t},\n\t\ttargetBlockIndex,\n\t};\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/use-block-drop-zone/index.native.js"],"names":["runOnJS","useDerivedValue","useSharedValue","useSelect","useCallback","store","blockEditorStore","useBlockListContext","getDistanceToNearestEdge","useOnBlockDrop","UPDATE_TARGET_BLOCK_INDEX_THRESHOLD","getNearestBlockIndex","blocksLayouts","position","orientation","isRTL","allowedEdges","isRightToLeft","candidateIndex","candidateDistance","forEach","element","index","x","y","width","height","rect","top","right","bottom","left","distance","edge","undefined","isTrailingEdge","offset","useBlockDropZone","rootClientId","targetRootClientId","targetBlockIndex","dragPosition","prevDragPosition","getBlockListSettings","getSettings","getBlockLayoutsOrderedByYCoord","getSortedBlocksLayouts","current","onBlockDrop","updateTargetBlockIndex","event","sortedBlockLayouts","targetIndex","value","prevX","prevY","Math","abs","onBlockDragOver","onBlockDragOverWorklet","onBlockDragEnd"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,OADD,EAECC,eAFD,EAGCC,cAHD,QAIO,yBAJP;AAMA;AACA;AACA;;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,WAAT,QAA4B,oBAA5B;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AACA,SAASC,mBAAT,QAAoC,kCAApC;AACA,SAASC,wBAAT,QAAyC,kBAAzC;AACA,OAAOC,cAAP,MAA2B,sBAA3B;AAEA,MAAMC,mCAAmC,GAAG,EAA5C,C,CAAgD;;AAEhD;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,oBAAT,CACNC,aADM,EAENC,QAFM,EAGNC,WAHM,EAINC,KAJM,EAKL;AACD,QAAMC,YAAY,GACjBF,WAAW,KAAK,YAAhB,GACG,CAAE,MAAF,EAAU,OAAV,CADH,GAEG,CAAE,KAAF,EAAS,QAAT,CAHJ;AAKA,QAAMG,aAAa,GAAGF,KA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MAAAA,CAAF;AAAKC,MAAAA;AAAL,KAAF,EAAa;AAClC;;AACAiB,MAAAA,YAAY,CAAClB,CAAb,CAAe8B,KAAf,GAAuB9B,CAAvB;AACAkB,MAAAA,YAAY,CAACjB,CAAb,CAAe6B,KAAf,GAAuB7B,CAAvB;AACA,KATK;;AAUNoC,IAAAA,cAAc,GAAG;AAChBpB,MAAAA,gBAAgB,CAACa,KAAjB,GAAyB,IAAzB;AACA,KAZK;;AAaNL,IAAAA,WAAW,EAAIE,KAAF,IAAa;AACzB,UAAKV,gBAAgB,CAACa,KAAjB,KAA2B,IAAhC,EAAuC;AACtCL,QAAAA,WAAW,CAAE,EACZ,GAAGE,KADS;AAEZX,UAAAA,kBAFY;AAGZC,UAAAA,gBAAgB,EAAEA,gBAAgB,CAACa;AAHvB,SAAF,CAAX;AAKA;AACD,KArBK;AAsBNb,IAAAA;AAtBM,GAAP;AAwBA","sourcesContent":["/**\n * External dependencies\n */\nimport {\n\trunOnJS,\n\tuseDerivedValue,\n\tuseSharedValue,\n} from 'react-native-reanimated';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { useCallback } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { useBlockListContext } from '../block-list/block-list-context';\nimport { getDistanceToNearestEdge } from '../../utils/math';\nimport useOnBlockDrop from '../use-on-block-drop';\n\nconst UPDATE_TARGET_BLOCK_INDEX_THRESHOLD = 20; // In pixels\n\n/** @typedef {import('../../utils/math').WPPoint} WPPoint */\n\n/**\n * The orientation of a block list.\n *\n * @typedef {'horizontal'|'vertical'|undefined} WPBlockListOrientation\n */\n\n/**\n * Given a list of blocks layouts finds the index that a block should be dropped at.\n *\n * @param {Object} blocksLayouts Blocks layouts object.\n * @param {WPPoint} position The position of the item being dragged.\n * @param {WPBlockListOrientation} orientation The orientation of a block list.\n * @param {boolean} isRTL Check if current locale is RTL.\n *\n * @return {number|undefined} The block index that's closest to the drag position.\n */\nexport function getNearestBlockIndex(\n\tblocksLayouts,\n\tposition,\n\torientation,\n\tisRTL\n) {\n\tconst allowedEdges =\n\t\torientation === 'horizontal'\n\t\t\t? [ 'left', 'right' ]\n\t\t\t: [ 'top', 'bottom' ];\n\n\tconst isRightToLeft = isRTL;\n\n\tlet candidateIndex;\n\tlet candidateDistance;\n\n\t// Only enabled for root level blocks.\n\tblocksLayouts.forEach( ( element, index ) => {\n\t\tconst { x, y, width, height } = element;\n\t\tconst rect = {\n\t\t\tx: element.x,\n\t\t\ty: element.y,\n\t\t\ttop: y,\n\t\t\tright: x + width,\n\t\t\tbottom: y + height,\n\t\t\tleft: x,\n\t\t\twidth,\n\t\t\theight,\n\t\t};\n\t\tconst [ distance, edge ] = getDistanceToNearestEdge(\n\t\t\tposition,\n\t\t\trect,\n\t\t\tallowedEdges\n\t\t);\n\n\t\tif ( candidateDistance === undefined || distance < candidateDistance ) {\n\t\t\t// If the user is dropping to the trailing edge of the block\n\t\t\t// add 1 to the index to represent dragging after.\n\t\t\t// Take RTL languages into account where the left edge is\n\t\t\t// the trailing edge.\n\t\t\tconst isTrailingEdge =\n\t\t\t\tedge === 'bottom' ||\n\t\t\t\t( ! isRightToLeft && edge === 'right' ) ||\n\t\t\t\t( isRightToLeft && edge === 'left' );\n\t\t\tconst offset = isTrailingEdge ? 1 : 0;\n\n\t\t\t// Update the currently known best candidate.\n\t\t\tcandidateDistance = distance;\n\t\t\tcandidateIndex = index + offset;\n\t\t}\n\t} );\n\treturn candidateIndex;\n}\n\n/**\n * @typedef {Object} WPBlockDropZoneConfig\n * @property {string} rootClientId The root client id for the block list.\n */\n\n/**\n * A React hook that can be used to make a block list handle drag and drop.\n *\n * @param {WPBlockDropZoneConfig} dropZoneConfig configuration data for the drop zone.\n *\n * @return {Object} An object that contains `targetBlockIndex` and the event\n * handlers `onBlockDragOver`, `onBlockDragEnd` and `onBlockDrop`.\n */\nexport default function useBlockDropZone( {\n\t// An undefined value represents a top-level block. Default to an empty\n\t// string for this so that `targetRootClientId` can be easily compared to\n\t// values returned by the `getRootBlockClientId` selector, which also uses\n\t// an empty string to represent top-level blocks.\n\trootClientId: targetRootClientId = '',\n} = {} ) {\n\tconst targetBlockIndex = useSharedValue( null );\n\tconst dragPosition = {\n\t\tx: useSharedValue( 0 ),\n\t\ty: useSharedValue( 0 ),\n\t};\n\tconst prevDragPosition = {\n\t\tx: useSharedValue( 0 ),\n\t\ty: useSharedValue( 0 ),\n\t};\n\n\tconst { getBlockListSettings, getSettings } = useSelect( blockEditorStore );\n\tconst { blocksLayouts, getBlockLayoutsOrderedByYCoord } =\n\t\tuseBlockListContext();\n\n\tconst getSortedBlocksLayouts = useCallback( () => {\n\t\treturn getBlockLayoutsOrderedByYCoord( blocksLayouts.current );\n\t\t// We use the value of `blocksLayouts` as the dependency.\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, [ blocksLayouts.current ] );\n\n\tconst isRTL = getSettings().isRTL;\n\n\tconst onBlockDrop = useOnBlockDrop();\n\n\tconst updateTargetBlockIndex = useCallback(\n\t\t( event ) => {\n\t\t\tconst sortedBlockLayouts = getSortedBlocksLayouts();\n\n\t\t\tconst targetIndex = getNearestBlockIndex(\n\t\t\t\tsortedBlockLayouts,\n\t\t\t\t{ x: event.x, y: event.y },\n\t\t\t\tgetBlockListSettings( targetRootClientId )?.orientation,\n\t\t\t\tisRTL\n\t\t\t);\n\t\t\tif ( targetIndex !== null ) {\n\t\t\t\ttargetBlockIndex.value = targetIndex ?? 0;\n\t\t\t}\n\t\t},\n\t\t[\n\t\t\tgetSortedBlocksLayouts,\n\t\t\tgetBlockListSettings,\n\t\t\ttargetRootClientId,\n\t\t\tisRTL,\n\t\t\ttargetBlockIndex,\n\t\t]\n\t);\n\n\tuseDerivedValue( () => {\n\t\tconst x = dragPosition.x.value;\n\t\tconst y = dragPosition.y.value;\n\t\tconst prevX = prevDragPosition.x.value;\n\t\tconst prevY = prevDragPosition.y.value;\n\t\t// `updateTargetBlockIndex` performs expensive calculations, so we throttle\n\t\t// the call using a offset threshold based on the dragging position.\n\t\tif (\n\t\t\tMath.abs( x - prevX ) >= UPDATE_TARGET_BLOCK_INDEX_THRESHOLD ||\n\t\t\tMath.abs( y - prevY ) >= UPDATE_TARGET_BLOCK_INDEX_THRESHOLD\n\t\t) {\n\t\t\trunOnJS( updateTargetBlockIndex )( { x, y } );\n\t\t\tprevDragPosition.x.value = x;\n\t\t\tprevDragPosition.y.value = y;\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t} );\n\n\treturn {\n\t\tonBlockDragOver( { x, y } ) {\n\t\t\tdragPosition.x.value = x;\n\t\t\tdragPosition.y.value = y;\n\t\t},\n\t\tonBlockDragOverWorklet( { x, y } ) {\n\t\t\t'worklet';\n\t\t\tdragPosition.x.value = x;\n\t\t\tdragPosition.y.value = y;\n\t\t},\n\t\tonBlockDragEnd() {\n\t\t\ttargetBlockIndex.value = null;\n\t\t},\n\t\tonBlockDrop: ( event ) => {\n\t\t\tif ( targetBlockIndex.value !== null ) {\n\t\t\t\tonBlockDrop( {\n\t\t\t\t\t...event,\n\t\t\t\t\ttargetRootClientId,\n\t\t\t\t\ttargetBlockIndex: targetBlockIndex.value,\n\t\t\t\t} );\n\t\t\t}\n\t\t},\n\t\ttargetBlockIndex,\n\t};\n}\n"]}