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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (279) hide show
  1. package/build/components/block-alignment-control/use-available-alignments.js +1 -1
  2. package/build/components/block-alignment-control/use-available-alignments.js.map +1 -1
  3. package/build/components/block-edit-visually-button/index.js +46 -0
  4. package/build/components/block-edit-visually-button/index.js.map +1 -0
  5. package/build/components/block-popover/inbetween.js +4 -2
  6. package/build/components/block-popover/inbetween.js.map +1 -1
  7. package/build/components/block-settings-menu/index.js +2 -6
  8. package/build/components/block-settings-menu/index.js.map +1 -1
  9. package/build/components/block-switcher/index.js +10 -16
  10. package/build/components/block-switcher/index.js.map +1 -1
  11. package/build/components/block-toolbar/index.js +5 -1
  12. package/build/components/block-toolbar/index.js.map +1 -1
  13. package/build/components/border-radius-control/all-input-control.js +31 -3
  14. package/build/components/border-radius-control/all-input-control.js.map +1 -1
  15. package/build/components/border-radius-control/index.js +20 -6
  16. package/build/components/border-radius-control/index.js.map +1 -1
  17. package/build/components/border-radius-control/input-controls.js +21 -6
  18. package/build/components/border-radius-control/input-controls.js.map +1 -1
  19. package/build/components/border-radius-control/utils.js +13 -16
  20. package/build/components/border-radius-control/utils.js.map +1 -1
  21. package/build/components/colors/with-colors.js +17 -4
  22. package/build/components/colors/with-colors.js.map +1 -1
  23. package/build/components/copy-handler/index.js +6 -0
  24. package/build/components/copy-handler/index.js.map +1 -1
  25. package/build/components/date-format-picker/index.js +2 -7
  26. package/build/components/date-format-picker/index.js.map +1 -1
  27. package/build/components/duotone/components.js +5 -5
  28. package/build/components/duotone/components.js.map +1 -1
  29. package/build/components/font-family/index.js +1 -1
  30. package/build/components/font-family/index.js.map +1 -1
  31. package/build/components/font-sizes/with-font-sizes.js +17 -4
  32. package/build/components/font-sizes/with-font-sizes.js.map +1 -1
  33. package/build/components/index.js +9 -0
  34. package/build/components/index.js.map +1 -1
  35. package/build/components/inserter/search-items.js +22 -4
  36. package/build/components/inserter/search-items.js.map +1 -1
  37. package/build/components/link-control/link-preview.js +0 -1
  38. package/build/components/link-control/link-preview.js.map +1 -1
  39. package/build/components/list-view/block-select-button.js +5 -2
  40. package/build/components/list-view/block-select-button.js.map +1 -1
  41. package/build/components/list-view/use-block-selection.js +1 -7
  42. package/build/components/list-view/use-block-selection.js.map +1 -1
  43. package/build/components/rich-text/use-enter.js +0 -4
  44. package/build/components/rich-text/use-enter.js.map +1 -1
  45. package/build/components/rich-text/use-format-types.js +8 -11
  46. package/build/components/rich-text/use-format-types.js.map +1 -1
  47. package/build/components/spacing-sizes-control/all-input-control.js +53 -0
  48. package/build/components/spacing-sizes-control/all-input-control.js.map +1 -0
  49. package/build/components/spacing-sizes-control/axial-input-controls.js +69 -0
  50. package/build/components/spacing-sizes-control/axial-input-controls.js.map +1 -0
  51. package/build/components/spacing-sizes-control/index.js +100 -0
  52. package/build/components/spacing-sizes-control/index.js.map +1 -0
  53. package/build/components/spacing-sizes-control/input-controls.js +52 -0
  54. package/build/components/spacing-sizes-control/input-controls.js.map +1 -0
  55. package/build/components/spacing-sizes-control/linked-button.js +38 -0
  56. package/build/components/spacing-sizes-control/linked-button.js.map +1 -0
  57. package/build/components/spacing-sizes-control/spacing-input-control.js +208 -0
  58. package/build/components/spacing-sizes-control/spacing-input-control.js.map +1 -0
  59. package/build/components/spacing-sizes-control/utils.js +202 -0
  60. package/build/components/spacing-sizes-control/utils.js.map +1 -0
  61. package/build/components/url-input/index.js +1 -1
  62. package/build/components/url-input/index.js.map +1 -1
  63. package/build/components/writing-flow/use-multi-selection.js +4 -2
  64. package/build/components/writing-flow/use-multi-selection.js.map +1 -1
  65. package/build/components/writing-flow/use-selection-observer.js +10 -2
  66. package/build/components/writing-flow/use-selection-observer.js.map +1 -1
  67. package/build/hooks/border-radius.js +2 -7
  68. package/build/hooks/border-radius.js.map +1 -1
  69. package/build/hooks/border.js +2 -2
  70. package/build/hooks/border.js.map +1 -1
  71. package/build/hooks/color.js +4 -1
  72. package/build/hooks/color.js.map +1 -1
  73. package/build/hooks/dimensions.js +15 -0
  74. package/build/hooks/dimensions.js.map +1 -1
  75. package/build/hooks/duotone.js +4 -4
  76. package/build/hooks/duotone.js.map +1 -1
  77. package/build/hooks/gap.js +6 -4
  78. package/build/hooks/gap.js.map +1 -1
  79. package/build/hooks/generated-class-name.js +1 -7
  80. package/build/hooks/generated-class-name.js.map +1 -1
  81. package/build/hooks/layout.js +20 -12
  82. package/build/hooks/layout.js.map +1 -1
  83. package/build/hooks/margin.js +28 -12
  84. package/build/hooks/margin.js.map +1 -1
  85. package/build/hooks/padding.js +19 -8
  86. package/build/hooks/padding.js.map +1 -1
  87. package/build/hooks/style.js +4 -50
  88. package/build/hooks/style.js.map +1 -1
  89. package/build/layouts/constrained.js +215 -0
  90. package/build/layouts/constrained.js.map +1 -0
  91. package/build/layouts/flex.js +1 -1
  92. package/build/layouts/flex.js.map +1 -1
  93. package/build/layouts/flow.js +7 -169
  94. package/build/layouts/flow.js.map +1 -1
  95. package/build/layouts/index.js +3 -1
  96. package/build/layouts/index.js.map +1 -1
  97. package/build/layouts/utils.js +43 -0
  98. package/build/layouts/utils.js.map +1 -1
  99. package/build/store/actions.js +25 -3
  100. package/build/store/actions.js.map +1 -1
  101. package/build/store/selectors.js +4 -6
  102. package/build/store/selectors.js.map +1 -1
  103. package/build-module/components/block-alignment-control/use-available-alignments.js +1 -1
  104. package/build-module/components/block-alignment-control/use-available-alignments.js.map +1 -1
  105. package/build-module/components/block-edit-visually-button/index.js +35 -0
  106. package/build-module/components/block-edit-visually-button/index.js.map +1 -0
  107. package/build-module/components/block-popover/inbetween.js +4 -2
  108. package/build-module/components/block-popover/inbetween.js.map +1 -1
  109. package/build-module/components/block-settings-menu/index.js +3 -6
  110. package/build-module/components/block-settings-menu/index.js.map +1 -1
  111. package/build-module/components/block-switcher/index.js +10 -16
  112. package/build-module/components/block-switcher/index.js.map +1 -1
  113. package/build-module/components/block-toolbar/index.js +4 -1
  114. package/build-module/components/block-toolbar/index.js.map +1 -1
  115. package/build-module/components/border-radius-control/all-input-control.js +32 -4
  116. package/build-module/components/border-radius-control/all-input-control.js.map +1 -1
  117. package/build-module/components/border-radius-control/index.js +20 -6
  118. package/build-module/components/border-radius-control/index.js.map +1 -1
  119. package/build-module/components/border-radius-control/input-controls.js +22 -7
  120. package/build-module/components/border-radius-control/input-controls.js.map +1 -1
  121. package/build-module/components/border-radius-control/utils.js +13 -16
  122. package/build-module/components/border-radius-control/utils.js.map +1 -1
  123. package/build-module/components/colors/with-colors.js +16 -3
  124. package/build-module/components/colors/with-colors.js.map +1 -1
  125. package/build-module/components/copy-handler/index.js +7 -1
  126. package/build-module/components/copy-handler/index.js.map +1 -1
  127. package/build-module/components/date-format-picker/index.js +2 -6
  128. package/build-module/components/date-format-picker/index.js.map +1 -1
  129. package/build-module/components/duotone/components.js +5 -5
  130. package/build-module/components/duotone/components.js.map +1 -1
  131. package/build-module/components/font-family/index.js +1 -1
  132. package/build-module/components/font-family/index.js.map +1 -1
  133. package/build-module/components/font-sizes/with-font-sizes.js +16 -3
  134. package/build-module/components/font-sizes/with-font-sizes.js.map +1 -1
  135. package/build-module/components/index.js +1 -0
  136. package/build-module/components/index.js.map +1 -1
  137. package/build-module/components/inserter/search-items.js +19 -5
  138. package/build-module/components/inserter/search-items.js.map +1 -1
  139. package/build-module/components/link-control/link-preview.js +0 -1
  140. package/build-module/components/link-control/link-preview.js.map +1 -1
  141. package/build-module/components/list-view/block-select-button.js +5 -2
  142. package/build-module/components/list-view/block-select-button.js.map +1 -1
  143. package/build-module/components/list-view/use-block-selection.js +1 -6
  144. package/build-module/components/list-view/use-block-selection.js.map +1 -1
  145. package/build-module/components/rich-text/use-enter.js +0 -4
  146. package/build-module/components/rich-text/use-enter.js.map +1 -1
  147. package/build-module/components/rich-text/use-format-types.js +8 -10
  148. package/build-module/components/rich-text/use-format-types.js.map +1 -1
  149. package/build-module/components/spacing-sizes-control/all-input-control.js +41 -0
  150. package/build-module/components/spacing-sizes-control/all-input-control.js.map +1 -0
  151. package/build-module/components/spacing-sizes-control/axial-input-controls.js +57 -0
  152. package/build-module/components/spacing-sizes-control/axial-input-controls.js.map +1 -0
  153. package/build-module/components/spacing-sizes-control/index.js +83 -0
  154. package/build-module/components/spacing-sizes-control/index.js.map +1 -0
  155. package/build-module/components/spacing-sizes-control/input-controls.js +41 -0
  156. package/build-module/components/spacing-sizes-control/input-controls.js.map +1 -0
  157. package/build-module/components/spacing-sizes-control/linked-button.js +28 -0
  158. package/build-module/components/spacing-sizes-control/linked-button.js.map +1 -0
  159. package/build-module/components/spacing-sizes-control/spacing-input-control.js +192 -0
  160. package/build-module/components/spacing-sizes-control/spacing-input-control.js.map +1 -0
  161. package/build-module/components/spacing-sizes-control/utils.js +174 -0
  162. package/build-module/components/spacing-sizes-control/utils.js.map +1 -0
  163. package/build-module/components/url-input/index.js +1 -1
  164. package/build-module/components/url-input/index.js.map +1 -1
  165. package/build-module/components/writing-flow/use-multi-selection.js +4 -2
  166. package/build-module/components/writing-flow/use-multi-selection.js.map +1 -1
  167. package/build-module/components/writing-flow/use-selection-observer.js +10 -2
  168. package/build-module/components/writing-flow/use-selection-observer.js.map +1 -1
  169. package/build-module/hooks/border-radius.js +2 -7
  170. package/build-module/hooks/border-radius.js.map +1 -1
  171. package/build-module/hooks/border.js +2 -2
  172. package/build-module/hooks/border.js.map +1 -1
  173. package/build-module/hooks/color.js +4 -1
  174. package/build-module/hooks/color.js.map +1 -1
  175. package/build-module/hooks/dimensions.js +13 -0
  176. package/build-module/hooks/dimensions.js.map +1 -1
  177. package/build-module/hooks/duotone.js +4 -4
  178. package/build-module/hooks/duotone.js.map +1 -1
  179. package/build-module/hooks/gap.js +3 -2
  180. package/build-module/hooks/gap.js.map +1 -1
  181. package/build-module/hooks/generated-class-name.js +1 -6
  182. package/build-module/hooks/generated-class-name.js.map +1 -1
  183. package/build-module/hooks/layout.js +20 -12
  184. package/build-module/hooks/layout.js.map +1 -1
  185. package/build-module/hooks/margin.js +26 -12
  186. package/build-module/hooks/margin.js.map +1 -1
  187. package/build-module/hooks/padding.js +17 -8
  188. package/build-module/hooks/padding.js.map +1 -1
  189. package/build-module/hooks/style.js +7 -53
  190. package/build-module/hooks/style.js.map +1 -1
  191. package/build-module/layouts/constrained.js +197 -0
  192. package/build-module/layouts/constrained.js.map +1 -0
  193. package/build-module/layouts/flex.js +1 -1
  194. package/build-module/layouts/flex.js.map +1 -1
  195. package/build-module/layouts/flow.js +8 -163
  196. package/build-module/layouts/flow.js.map +1 -1
  197. package/build-module/layouts/index.js +2 -1
  198. package/build-module/layouts/index.js.map +1 -1
  199. package/build-module/layouts/utils.js +40 -0
  200. package/build-module/layouts/utils.js.map +1 -1
  201. package/build-module/store/actions.js +25 -3
  202. package/build-module/store/actions.js.map +1 -1
  203. package/build-module/store/selectors.js +5 -7
  204. package/build-module/store/selectors.js.map +1 -1
  205. package/build-style/style-rtl.css +115 -20
  206. package/build-style/style.css +115 -20
  207. package/package.json +30 -28
  208. package/src/components/block-alignment-control/use-available-alignments.js +1 -1
  209. package/src/components/block-edit-visually-button/index.js +39 -0
  210. package/src/components/block-popover/inbetween.js +4 -1
  211. package/src/components/block-settings-menu/index.js +11 -15
  212. package/src/components/block-switcher/index.js +9 -13
  213. package/src/components/block-switcher/test/index.js +1 -0
  214. package/src/components/block-toolbar/index.js +2 -0
  215. package/src/components/border-radius-control/all-input-control.js +41 -4
  216. package/src/components/border-radius-control/index.js +25 -5
  217. package/src/components/border-radius-control/input-controls.js +40 -13
  218. package/src/components/border-radius-control/test/utils.js +22 -60
  219. package/src/components/border-radius-control/utils.js +12 -16
  220. package/src/components/colors/with-colors.js +11 -1
  221. package/src/components/copy-handler/index.js +18 -0
  222. package/src/components/date-format-picker/index.js +12 -14
  223. package/src/components/date-format-picker/style.scss +0 -4
  224. package/src/components/duotone/components.js +5 -5
  225. package/src/components/duotone-control/style.scss +0 -4
  226. package/src/components/font-appearance-control/style.scss +0 -2
  227. package/src/components/font-family/index.js +1 -1
  228. package/src/components/font-sizes/with-font-sizes.js +11 -1
  229. package/src/components/index.js +1 -0
  230. package/src/components/inserter/search-items.js +17 -5
  231. package/src/components/link-control/link-preview.js +0 -1
  232. package/src/components/link-control/test/index.js +540 -893
  233. package/src/components/list-view/block-select-button.js +7 -2
  234. package/src/components/list-view/style.scss +11 -4
  235. package/src/components/list-view/use-block-selection.js +2 -8
  236. package/src/components/media-replace-flow/style.scss +1 -0
  237. package/src/components/rich-text/use-enter.js +0 -3
  238. package/src/components/rich-text/use-format-types.js +6 -6
  239. package/src/components/spacing-sizes-control/all-input-control.js +40 -0
  240. package/src/components/spacing-sizes-control/axial-input-controls.js +62 -0
  241. package/src/components/spacing-sizes-control/index.js +91 -0
  242. package/src/components/spacing-sizes-control/input-controls.js +46 -0
  243. package/src/components/spacing-sizes-control/linked-button.js +25 -0
  244. package/src/components/spacing-sizes-control/spacing-input-control.js +280 -0
  245. package/src/components/spacing-sizes-control/style.scss +122 -0
  246. package/src/components/spacing-sizes-control/test/utils.js +156 -0
  247. package/src/components/spacing-sizes-control/utils.js +195 -0
  248. package/src/components/url-input/index.js +1 -1
  249. package/src/components/url-input/style.scss +2 -2
  250. package/src/components/url-popover/style.scss +0 -3
  251. package/src/components/writing-flow/use-multi-selection.js +4 -1
  252. package/src/components/writing-flow/use-selection-observer.js +10 -2
  253. package/src/hooks/border-radius.js +2 -6
  254. package/src/hooks/border.js +2 -2
  255. package/src/hooks/color.js +13 -3
  256. package/src/hooks/dimensions.js +15 -0
  257. package/src/hooks/duotone.js +4 -4
  258. package/src/hooks/gap.js +7 -2
  259. package/src/hooks/generated-class-name.js +6 -9
  260. package/src/hooks/layout.js +45 -14
  261. package/src/hooks/margin.js +49 -17
  262. package/src/hooks/padding.js +41 -14
  263. package/src/hooks/style.js +5 -56
  264. package/src/hooks/test/gap.js +22 -0
  265. package/src/hooks/typography.scss +0 -1
  266. package/src/layouts/constrained.js +217 -0
  267. package/src/layouts/flex.js +1 -1
  268. package/src/layouts/flow.js +6 -173
  269. package/src/layouts/index.js +2 -1
  270. package/src/layouts/test/constrained.js +21 -0
  271. package/src/layouts/utils.js +34 -0
  272. package/src/store/actions.js +32 -4
  273. package/src/store/selectors.js +5 -4
  274. package/src/style.scss +1 -0
  275. package/build/components/block-settings-menu/block-edit-visually-button.js +0 -70
  276. package/build/components/block-settings-menu/block-edit-visually-button.js.map +0 -1
  277. package/build-module/components/block-settings-menu/block-edit-visually-button.js +0 -56
  278. package/build-module/components/block-settings-menu/block-edit-visually-button.js.map +0 -1
  279. package/src/components/block-settings-menu/block-edit-visually-button.js +0 -52
@@ -0,0 +1,122 @@
1
+ .tools-panel-item-spacing {
2
+ display: grid;
3
+ grid-template-columns: auto 1fr auto;
4
+ grid-row-gap: $grid-unit-05;
5
+ }
6
+
7
+ .component-spacing-sizes-control {
8
+ box-sizing: border-box;
9
+ padding-bottom: 12px;
10
+ width: 100%;
11
+ display: contents;
12
+
13
+ legend {
14
+ padding: 0;
15
+ grid-column: 1 / 1;
16
+ grid-row: 1 / 1;
17
+ align-self: center;
18
+ }
19
+
20
+ .components-spacing-sizes-control__side-labels {
21
+ grid-column: 1 / 1;
22
+ min-height: 30px;
23
+ justify-content: left;
24
+ }
25
+
26
+ .components-spacing-sizes-control__hint-single {
27
+ margin-top: 0;
28
+ margin-left: 0;
29
+ }
30
+
31
+ .components-spacing-sizes-control__hint-single,
32
+ .components-spacing-sizes-control__hint-all {
33
+ color: $gray-700;
34
+ font-size: 12px;
35
+ }
36
+
37
+ .components-spacing-sizes-control__hint-all {
38
+ grid-column: 2 / 2;
39
+ justify-self: left;
40
+ grid-row: 1 / 1;
41
+ align-self: center;
42
+ margin-left: $grid-unit-05;
43
+ }
44
+
45
+ .components-spacing-sizes-control__custom-toggle-all {
46
+ grid-column: 2 / 2;
47
+ grid-row: 1 / 1;
48
+ justify-self: end;
49
+ margin-right: $grid-unit-05;
50
+ padding: 0;
51
+ }
52
+
53
+ .components-spacing-sizes-control__custom-toggle-single {
54
+ grid-column: 3 / 3;
55
+ justify-self: end;
56
+ }
57
+
58
+ .components-spacing-sizes-control__custom-toggle-all,
59
+ .components-spacing-sizes-control__custom-toggle-single {
60
+ &.is-small.has-icon {
61
+ padding: 0;
62
+ min-width: $icon-size;
63
+ }
64
+ }
65
+
66
+ .component-spacing-sizes-control__linked-button {
67
+ grid-column: 3 / 3;
68
+ grid-row: 1 / 1;
69
+ justify-self: end;
70
+ }
71
+
72
+ .components-spacing-sizes-control__custom-value-range {
73
+ grid-column: span 2;
74
+ margin-left: $grid-unit-10;
75
+ padding-right: $grid-unit-10;
76
+ height: 30px;
77
+ }
78
+
79
+ .components-spacing-sizes-control__custom-value-input {
80
+ width: 124px;
81
+ }
82
+
83
+ .components-spacing-sizes-control__range-control {
84
+ grid-column: span 3;
85
+ padding-right: $grid-unit-10;
86
+ height: 30px;
87
+ }
88
+
89
+ .components-range-control__wrapper {
90
+ margin-bottom: 0;
91
+ }
92
+
93
+ .components-range-control__mark {
94
+ height: $grid-unit-05;
95
+ width: 3px;
96
+ background-color: #fff;
97
+ z-index: 1;
98
+ }
99
+
100
+ .components-range-control__marks {
101
+ margin-top: 17px;
102
+
103
+ :first-child {
104
+ display: none;
105
+ }
106
+ }
107
+
108
+ [class*="ThumbWrapper-thumbColor"] {
109
+ z-index: 3;
110
+ }
111
+
112
+ .components-spacing-sizes-control__side-label {
113
+ margin-right: $grid-unit-05;
114
+ grid-column: 1 / 1;
115
+ justify-self: left;
116
+ font-size: 12px;
117
+ }
118
+
119
+ .components-spacing-sizes-control__custom-select-control {
120
+ grid-column: span 3;
121
+ }
122
+ }
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import {
5
+ isValueSpacingPreset,
6
+ getCustomValueFromPreset,
7
+ getSpacingPresetCssVar,
8
+ getSpacingPresetSlug,
9
+ getSliderValueFromPreset,
10
+ getAllRawValue,
11
+ isValuesMixed,
12
+ isValuesDefined,
13
+ } from '../utils';
14
+
15
+ describe( 'isValueSpacingPreset', () => {
16
+ it( 'should return true if value is string in spacing presets var format', () => {
17
+ expect( isValueSpacingPreset( 'var:preset|spacing|20' ) ).toBe( true );
18
+ } );
19
+ it( 'should return false if value is not a string in spacing presets var format', () => {
20
+ expect( isValueSpacingPreset( '30px' ) ).toBe( false );
21
+ } );
22
+ } );
23
+
24
+ describe( 'getCustomValueFromPreset', () => {
25
+ const spacingSizes = [ { name: 'Small', slug: 20, size: '8px' } ];
26
+ it( 'should return original value if not a string in spacing presets var format', () => {
27
+ expect( getCustomValueFromPreset( '20px', spacingSizes ) ).toBe(
28
+ '20px'
29
+ );
30
+ } );
31
+ it( 'should return value from matching spacingSizes array entry if string in spacing presets var format', () => {
32
+ expect(
33
+ getCustomValueFromPreset( 'var:preset|spacing|20', spacingSizes )
34
+ ).toBe( '8px' );
35
+ } );
36
+ it( 'should return undefined if no matching preset in spacingSizes array', () => {
37
+ expect(
38
+ getCustomValueFromPreset( 'var:preset|spacing|30', spacingSizes )
39
+ ).toBe( undefined );
40
+ } );
41
+ } );
42
+
43
+ describe( 'getSpacingPresetCssVar', () => {
44
+ it( 'should return original value if not a string in spacing presets var format', () => {
45
+ expect( getSpacingPresetCssVar( '20px' ) ).toBe( '20px' );
46
+ } );
47
+ it( 'should return a string in spacing presets css var format with slug from provided value', () => {
48
+ expect( getSpacingPresetCssVar( 'var:preset|spacing|20' ) ).toBe(
49
+ 'var(--wp--preset--spacing--20)'
50
+ );
51
+ } );
52
+ } );
53
+
54
+ describe( 'getSpacingPresetSlug', () => {
55
+ it( 'should return original value if 0 or default', () => {
56
+ expect( getSpacingPresetSlug( '0' ) ).toBe( '0' );
57
+ expect( getSpacingPresetSlug( 'default' ) ).toBe( 'default' );
58
+ } );
59
+ it( 'should return the int value of the slug portion of a valid preset var', () => {
60
+ expect( getSpacingPresetSlug( 'var:preset|spacing|20' ) ).toBe( '20' );
61
+ } );
62
+ } );
63
+
64
+ describe( 'getSliderValueFromPreset', () => {
65
+ const spacingSizes = [
66
+ { name: 'Small', slug: 20, size: '8px' },
67
+ { name: 'Large', slug: 30, size: '24px' },
68
+ ];
69
+ it( 'should return NaN if no matching preset found - NaN makes range control go to start', () => {
70
+ expect( getSliderValueFromPreset( '10px', spacingSizes ) ).toBe( NaN );
71
+ } );
72
+ it( 'should return the int value of the slug portion of a valid preset var', () => {
73
+ expect(
74
+ getSliderValueFromPreset( 'var:preset|spacing|30', spacingSizes )
75
+ ).toBe( 1 );
76
+ } );
77
+ } );
78
+
79
+ describe( 'getAllRawValue', () => {
80
+ const customValues = {
81
+ top: '5px',
82
+ bottom: '5px',
83
+ left: '6px',
84
+ right: '2px',
85
+ };
86
+ it( 'should return the most common custom value from the values object', () => {
87
+ expect( getAllRawValue( customValues ) ).toBe( '5px' );
88
+ } );
89
+ const presetValues = {
90
+ top: 'var:preset|spacing|30',
91
+ bottom: 'var:preset|spacing|20',
92
+ left: 'var:preset|spacing|10',
93
+ right: 'var:preset|spacing|30',
94
+ };
95
+ it( 'should return the most common preset value from the values object', () => {
96
+ expect( getAllRawValue( presetValues ) ).toBe(
97
+ 'var:preset|spacing|30'
98
+ );
99
+ } );
100
+ } );
101
+
102
+ describe( 'isValuesMixed', () => {
103
+ const unmixedValues = {
104
+ top: '5px',
105
+ bottom: '5px',
106
+ left: '5px',
107
+ right: '5px',
108
+ };
109
+ it( 'should return false if all values are the same', () => {
110
+ expect( isValuesMixed( unmixedValues ) ).toBe( false );
111
+ } );
112
+ const mixedValues = {
113
+ top: 'var:preset|spacing|30',
114
+ bottom: 'var:preset|spacing|20',
115
+ left: 'var:preset|spacing|10',
116
+ right: 'var:preset|spacing|30',
117
+ };
118
+ it( 'should return true if all the values are not the same', () => {
119
+ expect( isValuesMixed( mixedValues ) ).toBe( true );
120
+ } );
121
+ const singleValue = {
122
+ top: 'var:preset|spacing|30',
123
+ };
124
+ it( 'should return true if only one side set', () => {
125
+ expect( isValuesMixed( singleValue ) ).toBe( true );
126
+ } );
127
+ const incompleteValues = {
128
+ top: 'var:preset|spacing|30',
129
+ bottom: 'var:preset|spacing|30',
130
+ left: 'var:preset|spacing|30',
131
+ };
132
+ it( 'should return true if all sides not set', () => {
133
+ expect( isValuesMixed( incompleteValues ) ).toBe( true );
134
+ } );
135
+ } );
136
+
137
+ describe( 'isValuesDefined', () => {
138
+ const undefinedValues = {
139
+ top: undefined,
140
+ bottom: undefined,
141
+ left: undefined,
142
+ right: undefined,
143
+ };
144
+ it( 'should return false if values are not defined', () => {
145
+ expect( isValuesDefined( undefinedValues ) ).toBe( false );
146
+ } );
147
+ const definedValues = {
148
+ top: 'var:preset|spacing|30',
149
+ bottom: 'var:preset|spacing|20',
150
+ left: 'var:preset|spacing|10',
151
+ right: 'var:preset|spacing|30',
152
+ };
153
+ it( 'should return true if all the values are not the same', () => {
154
+ expect( isValuesDefined( definedValues ) ).toBe( true );
155
+ } );
156
+ } );
@@ -0,0 +1,195 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { isEmpty } from 'lodash';
5
+
6
+ /**
7
+ * WordPress dependencies
8
+ */
9
+ import { __ } from '@wordpress/i18n';
10
+
11
+ /**
12
+ * Checks is given value is a spacing preset.
13
+ *
14
+ * @param {string} value Value to check
15
+ *
16
+ * @return {boolean} Return true if value is string in format var:preset|spacing|.
17
+ */
18
+ export function isValueSpacingPreset( value ) {
19
+ if ( ! value?.includes ) {
20
+ return false;
21
+ }
22
+ return value === '0' || value.includes( 'var:preset|spacing|' );
23
+ }
24
+
25
+ /**
26
+ * Converts a spacing preset into a custom value.
27
+ *
28
+ * @param {string} value Value to convert
29
+ * @param {Array} spacingSizes Array of the current spacing preset objects
30
+ *
31
+ * @return {string} Mapping of the spacing preset to its equivalent custom value.
32
+ */
33
+ export function getCustomValueFromPreset( value, spacingSizes ) {
34
+ if ( ! isValueSpacingPreset( value ) ) {
35
+ return value;
36
+ }
37
+
38
+ const slug = getSpacingPresetSlug( value );
39
+ const spacingSize = spacingSizes.find(
40
+ ( size ) => String( size.slug ) === slug
41
+ );
42
+
43
+ return spacingSize?.size;
44
+ }
45
+
46
+ /**
47
+ * Converts a spacing preset into a custom value.
48
+ *
49
+ * @param {string} value Value to convert.
50
+ *
51
+ * @return {string} CSS var string for given spacing preset value.
52
+ */
53
+ export function getSpacingPresetCssVar( value ) {
54
+ if ( ! value ) {
55
+ return;
56
+ }
57
+
58
+ const slug = value.match( /var:preset\|spacing\|(.+)/ );
59
+
60
+ if ( ! slug ) {
61
+ return value;
62
+ }
63
+
64
+ return `var(--wp--preset--spacing--${ slug[ 1 ] })`;
65
+ }
66
+
67
+ /**
68
+ * Returns the slug section of the given spacing preset string.
69
+ *
70
+ * @param {string} value Value to extract slug from.
71
+ *
72
+ * @return {number} The int value of the slug from given spacing preset.
73
+ */
74
+ export function getSpacingPresetSlug( value ) {
75
+ if ( ! value ) {
76
+ return;
77
+ }
78
+
79
+ if ( value === '0' || value === 'default' ) {
80
+ return value;
81
+ }
82
+
83
+ const slug = value.match( /var:preset\|spacing\|(.+)/ );
84
+
85
+ return slug ? slug[ 1 ] : undefined;
86
+ }
87
+
88
+ /**
89
+ * Converts spacing preset value into a Range component value .
90
+ *
91
+ * @param {string} presetValue Value to convert to Range value.
92
+ * @param {Array} spacingSizes Array of current spacing preset value objects.
93
+ *
94
+ * @return {number} The int value for use in Range control.
95
+ */
96
+ export function getSliderValueFromPreset( presetValue, spacingSizes ) {
97
+ if ( presetValue === undefined ) {
98
+ return 0;
99
+ }
100
+ const slug =
101
+ parseFloat( presetValue, 10 ) === 0
102
+ ? '0'
103
+ : getSpacingPresetSlug( presetValue );
104
+ const sliderValue = spacingSizes.findIndex( ( spacingSize ) => {
105
+ return String( spacingSize.slug ) === slug;
106
+ } );
107
+
108
+ // Returning NaN rather than undefined as undefined makes range control thumb sit in center
109
+ return sliderValue !== -1 ? sliderValue : NaN;
110
+ }
111
+
112
+ export const LABELS = {
113
+ all: __( 'All sides' ),
114
+ top: __( 'Top' ),
115
+ bottom: __( 'Bottom' ),
116
+ left: __( 'Left' ),
117
+ right: __( 'Right' ),
118
+ mixed: __( 'Mixed' ),
119
+ vertical: __( 'Vertical' ),
120
+ horizontal: __( 'Horizontal' ),
121
+ };
122
+
123
+ export const DEFAULT_VALUES = {
124
+ top: undefined,
125
+ right: undefined,
126
+ bottom: undefined,
127
+ left: undefined,
128
+ };
129
+
130
+ export const ALL_SIDES = [ 'top', 'right', 'bottom', 'left' ];
131
+
132
+ /**
133
+ * Gets an items with the most occurrence within an array
134
+ * https://stackoverflow.com/a/20762713
135
+ *
136
+ * @param {Array<any>} arr Array of items to check.
137
+ * @return {any} The item with the most occurrences.
138
+ */
139
+ function mode( arr ) {
140
+ return arr
141
+ .sort(
142
+ ( a, b ) =>
143
+ arr.filter( ( v ) => v === a ).length -
144
+ arr.filter( ( v ) => v === b ).length
145
+ )
146
+ .pop();
147
+ }
148
+
149
+ /**
150
+ * Gets the 'all' input value from values data.
151
+ *
152
+ * @param {Object} values Box spacing values
153
+ *
154
+ * @return {string} The most common value from all sides of box.
155
+ */
156
+ export function getAllRawValue( values = {} ) {
157
+ return mode( Object.values( values ) );
158
+ }
159
+
160
+ /**
161
+ * Checks to determine if values are mixed.
162
+ *
163
+ * @param {Object} values Box values.
164
+ * @param {Array} sides Sides that values relate to.
165
+ *
166
+ * @return {boolean} Whether values are mixed.
167
+ */
168
+ export function isValuesMixed( values = {}, sides = ALL_SIDES ) {
169
+ return (
170
+ ( Object.values( values ).length >= 1 &&
171
+ Object.values( values ).length < sides.length ) ||
172
+ new Set( Object.values( values ) ).size > 1
173
+ );
174
+ }
175
+
176
+ /**
177
+ * Checks to determine if values are defined.
178
+ *
179
+ * @param {Object} values Box values.
180
+ *
181
+ * @return {boolean} Whether values are defined.
182
+ */
183
+ export function isValuesDefined( values ) {
184
+ return (
185
+ values !== undefined &&
186
+ ! isEmpty(
187
+ Object.values( values ).filter(
188
+ // Switching units when input is empty causes values only
189
+ // containing units. This gives false positive on mixed values
190
+ // unless filtered.
191
+ ( value ) => !! value && /\d/.test( value )
192
+ )
193
+ )
194
+ );
195
+ }
@@ -462,7 +462,7 @@ class URLInput extends Component {
462
462
  'aria-label': label ? undefined : __( 'URL' ), // Ensure input always has an accessible label
463
463
  'aria-expanded': showSuggestions,
464
464
  'aria-autocomplete': 'list',
465
- 'aria-owns': suggestionsListboxId,
465
+ 'aria-controls': suggestionsListboxId,
466
466
  'aria-activedescendant':
467
467
  selectedSuggestion !== null
468
468
  ? `${ suggestionOptionIdPrefix }-${ selectedSuggestion }`
@@ -45,9 +45,9 @@ $input-size: 300px;
45
45
 
46
46
  .components-spinner {
47
47
  position: absolute;
48
- right: $input-padding;
49
- bottom: $input-padding + $grid-unit-10 + 1;
50
48
  margin: 0;
49
+ top: calc(50% - #{$spinner-size} / 2);
50
+ right: $grid-unit;
51
51
  }
52
52
  }
53
53
 
@@ -72,9 +72,6 @@
72
72
  .block-editor-url-input .components-base-control__field {
73
73
  margin-bottom: 0;
74
74
  }
75
- .block-editor-url-input .components-spinner {
76
- bottom: $input-padding + 1;
77
- }
78
75
  }
79
76
 
80
77
  .block-editor-url-popover__link-viewer-url {
@@ -75,8 +75,11 @@ export default function useMultiSelection() {
75
75
  // able to select across instances immediately.
76
76
  node.contentEditable = true;
77
77
 
78
- defaultView.getSelection().removeAllRanges();
78
+ // For some browsers, like Safari, it is important that focus
79
+ // happens BEFORE selection removal.
79
80
  node.focus();
81
+
82
+ defaultView.getSelection().removeAllRanges();
80
83
  },
81
84
  [
82
85
  hasMultiSelection,
@@ -25,7 +25,11 @@ function extractSelectionStartNode( selection ) {
25
25
  return anchorNode;
26
26
  }
27
27
 
28
- return anchorNode.childNodes[ anchorOffset ];
28
+ if ( anchorOffset === 0 ) {
29
+ return anchorNode;
30
+ }
31
+
32
+ return anchorNode.childNodes[ anchorOffset - 1 ];
29
33
  }
30
34
 
31
35
  /**
@@ -44,7 +48,11 @@ function extractSelectionEndNode( selection ) {
44
48
  return focusNode;
45
49
  }
46
50
 
47
- return focusNode.childNodes[ focusOffset - 1 ];
51
+ if ( focusOffset === focusNode.childNodes.length ) {
52
+ return focusNode;
53
+ }
54
+
55
+ return focusNode.childNodes[ focusOffset ];
48
56
  }
49
57
 
50
58
  function findDepth( a, b ) {
@@ -19,17 +19,13 @@ export function BorderRadiusEdit( props ) {
19
19
  } = props;
20
20
 
21
21
  const onChange = ( newRadius ) => {
22
- let newStyle = {
22
+ const newStyle = cleanEmptyObject( {
23
23
  ...style,
24
24
  border: {
25
25
  ...style?.border,
26
26
  radius: newRadius,
27
27
  },
28
- };
29
-
30
- if ( newRadius === undefined || newRadius === '' ) {
31
- newStyle = cleanEmptyObject( newStyle );
32
- }
28
+ } );
33
29
 
34
30
  setAttributes( { style: newStyle } );
35
31
  };
@@ -268,10 +268,10 @@ export function BorderPanel( props ) {
268
268
  <BorderBoxControl
269
269
  colors={ colors }
270
270
  enableAlpha={ true }
271
+ enableStyle={ isStyleSupported }
271
272
  onChange={ onBorderChange }
272
- popoverPlacement="left-start"
273
273
  popoverOffset={ 40 }
274
- showStyle={ isStyleSupported }
274
+ popoverPlacement="left-start"
275
275
  value={ hydratedBorder }
276
276
  __experimentalHasMultipleOrigins={ true }
277
277
  __experimentalIsRenderedInSidebar={ true }
@@ -450,14 +450,24 @@ export function ColorEdit( props ) {
450
450
  };
451
451
  };
452
452
 
453
- const enableContrastChecking =
454
- Platform.OS === 'web' && ! gradient && ! style?.color?.gradient;
455
-
456
453
  const defaultColorControls = getBlockSupport( props.name, [
457
454
  COLOR_SUPPORT_KEY,
458
455
  '__experimentalDefaultControls',
459
456
  ] );
460
457
 
458
+ const enableContrastChecking =
459
+ Platform.OS === 'web' &&
460
+ ! gradient &&
461
+ ! style?.color?.gradient &&
462
+ // Contrast checking is enabled by default.
463
+ // Deactivating it requires `enableContrastChecker` to have
464
+ // an explicit value of `false`.
465
+ false !==
466
+ getBlockSupport( props.name, [
467
+ COLOR_SUPPORT_KEY,
468
+ 'enableContrastChecker',
469
+ ] );
470
+
461
471
  return (
462
472
  <ColorPanel
463
473
  enableContrastChecking={ enableContrastChecking }
@@ -1,3 +1,8 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import classnames from 'classnames';
5
+
1
6
  /**
2
7
  * WordPress dependencies
3
8
  */
@@ -33,6 +38,7 @@ import {
33
38
  resetPadding,
34
39
  useIsPaddingDisabled,
35
40
  } from './padding';
41
+ import useSetting from '../components/use-setting';
36
42
 
37
43
  export const SPACING_SUPPORT_KEY = 'spacing';
38
44
  export const ALL_SIDES = [ 'top', 'right', 'bottom', 'left' ];
@@ -51,6 +57,7 @@ export function DimensionsPanel( props ) {
51
57
  const isMarginDisabled = useIsMarginDisabled( props );
52
58
  const isDisabled = useIsDimensionsDisabled( props );
53
59
  const isSupported = hasDimensionsSupport( props.name );
60
+ const spacingSizes = useSetting( 'spacing.spacingSizes' );
54
61
 
55
62
  if ( isDisabled || ! isSupported ) {
56
63
  return null;
@@ -77,6 +84,10 @@ export function DimensionsPanel( props ) {
77
84
  <InspectorControls __experimentalGroup="dimensions">
78
85
  { ! isPaddingDisabled && (
79
86
  <ToolsPanelItem
87
+ className={ classnames( {
88
+ 'tools-panel-item-spacing':
89
+ spacingSizes && spacingSizes.length > 0,
90
+ } ) }
80
91
  hasValue={ () => hasPaddingValue( props ) }
81
92
  label={ __( 'Padding' ) }
82
93
  onDeselect={ () => resetPadding( props ) }
@@ -89,6 +100,10 @@ export function DimensionsPanel( props ) {
89
100
  ) }
90
101
  { ! isMarginDisabled && (
91
102
  <ToolsPanelItem
103
+ className={ classnames( {
104
+ 'tools-panel-item-spacing':
105
+ spacingSizes && spacingSizes.length > 0,
106
+ } ) }
92
107
  hasValue={ () => hasMarginValue( props ) }
93
108
  label={ __( 'Margin' ) }
94
109
  onDeselect={ () => resetMargin( props ) }
@@ -35,10 +35,10 @@ extend( [ namesPlugin ] );
35
35
  /**
36
36
  * SVG and stylesheet needed for rendering the duotone filter.
37
37
  *
38
- * @param {Object} props Duotone props.
39
- * @param {string} props.selector Selector to apply the filter to.
40
- * @param {string} props.id Unique id for this duotone filter.
41
- * @param {string[]|"unset"} props.colors Array of RGB color strings ordered from dark to light.
38
+ * @param {Object} props Duotone props.
39
+ * @param {string} props.selector Selector to apply the filter to.
40
+ * @param {string} props.id Unique id for this duotone filter.
41
+ * @param {string[]|"unset"} props.colors Array of RGB color strings ordered from dark to light.
42
42
  *
43
43
  * @return {WPElement} Duotone element.
44
44
  */
package/src/hooks/gap.js CHANGED
@@ -14,6 +14,7 @@ import {
14
14
  * Internal dependencies
15
15
  */
16
16
  import { __unstableUseBlockRef as useBlockRef } from '../components/block-list/use-block-props/use-block-refs';
17
+ import { getSpacingPresetCssVar } from '../components/spacing-sizes-control/utils';
17
18
  import useSetting from '../components/use-setting';
18
19
  import { AXIAL_SIDES, SPACING_SUPPORT_KEY, useCustomSides } from './dimensions';
19
20
  import { cleanEmptyObject } from './utils';
@@ -54,8 +55,12 @@ export function getGapBoxControlValueFromStyle( blockGapValue ) {
54
55
 
55
56
  const isValueString = typeof blockGapValue === 'string';
56
57
  return {
57
- top: isValueString ? blockGapValue : blockGapValue?.top,
58
- left: isValueString ? blockGapValue : blockGapValue?.left,
58
+ top: isValueString
59
+ ? getSpacingPresetCssVar( blockGapValue )
60
+ : getSpacingPresetCssVar( blockGapValue?.top ),
61
+ left: isValueString
62
+ ? getSpacingPresetCssVar( blockGapValue )
63
+ : getSpacingPresetCssVar( blockGapValue?.left ),
59
64
  };
60
65
  }
61
66