@wordpress/block-library 7.11.0 → 7.12.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 (261) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/archives/edit.js +7 -0
  3. package/build/archives/edit.js.map +1 -1
  4. package/build/archives/index.js +4 -0
  5. package/build/archives/index.js.map +1 -1
  6. package/build/block/edit.js +4 -2
  7. package/build/block/edit.js.map +1 -1
  8. package/build/block/edit.native.js +4 -2
  9. package/build/block/edit.native.js.map +1 -1
  10. package/build/calendar/edit.js +12 -5
  11. package/build/calendar/edit.js.map +1 -1
  12. package/build/columns/edit.native.js +2 -1
  13. package/build/columns/edit.native.js.map +1 -1
  14. package/build/cover/edit/resizable-cover.js +6 -0
  15. package/build/cover/edit/resizable-cover.js.map +1 -1
  16. package/build/group/transforms.js +5 -0
  17. package/build/group/transforms.js.map +1 -1
  18. package/build/index.native.js +17 -4
  19. package/build/index.native.js.map +1 -1
  20. package/build/list/index.js +6 -0
  21. package/build/list/index.js.map +1 -1
  22. package/build/list/v2/edit.js +16 -5
  23. package/build/list/v2/edit.js.map +1 -1
  24. package/build/list/v2/tag-name.js +31 -0
  25. package/build/list/v2/tag-name.js.map +1 -0
  26. package/build/list/v2/tag-name.native.js +32 -0
  27. package/build/list/v2/tag-name.native.js.map +1 -0
  28. package/build/list/v2/transforms.js +1 -11
  29. package/build/list/v2/transforms.js.map +1 -1
  30. package/build/list-item/edit.js +1 -0
  31. package/build/list-item/edit.js.map +1 -1
  32. package/build/list-item/edit.native.js +158 -0
  33. package/build/list-item/edit.native.js.map +1 -0
  34. package/build/list-item/icons.native.js +53 -0
  35. package/build/list-item/icons.native.js.map +1 -0
  36. package/build/list-item/list-style-type.native.js +136 -0
  37. package/build/list-item/list-style-type.native.js.map +1 -0
  38. package/build/media-text/deprecated.js +188 -66
  39. package/build/media-text/deprecated.js.map +1 -1
  40. package/build/media-text/edit.js +2 -1
  41. package/build/media-text/edit.js.map +1 -1
  42. package/build/media-text/media-container.js +1 -1
  43. package/build/media-text/media-container.js.map +1 -1
  44. package/build/navigation/edit/index.js +68 -123
  45. package/build/navigation/edit/index.js.map +1 -1
  46. package/build/navigation/edit/navigation-menu-selector.js +11 -14
  47. package/build/navigation/edit/navigation-menu-selector.js.map +1 -1
  48. package/build/navigation/edit/placeholder/index.js +4 -2
  49. package/build/navigation/edit/placeholder/index.js.map +1 -1
  50. package/build/navigation/edit/responsive-wrapper.js +13 -3
  51. package/build/navigation/edit/responsive-wrapper.js.map +1 -1
  52. package/build/navigation/edit/use-create-navigation-menu.js +5 -1
  53. package/build/navigation/edit/use-create-navigation-menu.js.map +1 -1
  54. package/build/navigation/edit/use-inner-blocks.js +43 -0
  55. package/build/navigation/edit/use-inner-blocks.js.map +1 -0
  56. package/build/navigation/edit/utils.js +28 -0
  57. package/build/navigation/edit/utils.js.map +1 -0
  58. package/build/navigation/use-navigation-menu.js +7 -3
  59. package/build/navigation/use-navigation-menu.js.map +1 -1
  60. package/build/post-author/edit.js +5 -2
  61. package/build/post-author/edit.js.map +1 -1
  62. package/build/post-author-biography/edit.js +7 -1
  63. package/build/post-author-biography/edit.js.map +1 -1
  64. package/build/post-content/edit.js +4 -2
  65. package/build/post-content/edit.js.map +1 -1
  66. package/build/post-featured-image/edit.js +16 -2
  67. package/build/post-featured-image/edit.js.map +1 -1
  68. package/build/post-featured-image/index.js +9 -0
  69. package/build/post-featured-image/index.js.map +1 -1
  70. package/build/query/edit/inspector-controls/index.js +42 -9
  71. package/build/query/edit/inspector-controls/index.js.map +1 -1
  72. package/build/query/edit/inspector-controls/taxonomy-controls.js +21 -14
  73. package/build/query/edit/inspector-controls/taxonomy-controls.js.map +1 -1
  74. package/build/query-title/edit.js +20 -7
  75. package/build/query-title/edit.js.map +1 -1
  76. package/build/query-title/index.js +4 -0
  77. package/build/query-title/index.js.map +1 -1
  78. package/build/query-title/variations.js +10 -0
  79. package/build/query-title/variations.js.map +1 -1
  80. package/build/quote/transforms.js +2 -2
  81. package/build/quote/transforms.js.map +1 -1
  82. package/build/separator/edit.js +1 -1
  83. package/build/separator/edit.js.map +1 -1
  84. package/build/social-links/edit.js +1 -0
  85. package/build/social-links/edit.js.map +1 -1
  86. package/build/template-part/edit/index.js +4 -2
  87. package/build/template-part/edit/index.js.map +1 -1
  88. package/build-module/archives/edit.js +7 -0
  89. package/build-module/archives/edit.js.map +1 -1
  90. package/build-module/archives/index.js +4 -0
  91. package/build-module/archives/index.js.map +1 -1
  92. package/build-module/block/edit.js +5 -3
  93. package/build-module/block/edit.js.map +1 -1
  94. package/build-module/block/edit.native.js +5 -3
  95. package/build-module/block/edit.native.js.map +1 -1
  96. package/build-module/calendar/edit.js +12 -4
  97. package/build-module/calendar/edit.js.map +1 -1
  98. package/build-module/columns/edit.native.js +3 -2
  99. package/build-module/columns/edit.native.js.map +1 -1
  100. package/build-module/cover/edit/resizable-cover.js +6 -0
  101. package/build-module/cover/edit/resizable-cover.js.map +1 -1
  102. package/build-module/group/transforms.js +5 -0
  103. package/build-module/group/transforms.js.map +1 -1
  104. package/build-module/index.native.js +16 -4
  105. package/build-module/index.native.js.map +1 -1
  106. package/build-module/list/index.js +1 -1
  107. package/build-module/list/index.js.map +1 -1
  108. package/build-module/list/v2/edit.js +15 -5
  109. package/build-module/list/v2/edit.js.map +1 -1
  110. package/build-module/list/v2/tag-name.js +21 -0
  111. package/build-module/list/v2/tag-name.js.map +1 -0
  112. package/build-module/list/v2/tag-name.native.js +21 -0
  113. package/build-module/list/v2/tag-name.native.js.map +1 -0
  114. package/build-module/list/v2/transforms.js +1 -10
  115. package/build-module/list/v2/transforms.js.map +1 -1
  116. package/build-module/list-item/edit.js +1 -3
  117. package/build-module/list-item/edit.js.map +1 -1
  118. package/build-module/list-item/edit.native.js +141 -0
  119. package/build-module/list-item/edit.native.js.map +1 -0
  120. package/build-module/list-item/icons.native.js +37 -0
  121. package/build-module/list-item/icons.native.js.map +1 -0
  122. package/build-module/list-item/list-style-type.native.js +124 -0
  123. package/build-module/list-item/list-style-type.native.js.map +1 -0
  124. package/build-module/media-text/deprecated.js +189 -65
  125. package/build-module/media-text/deprecated.js.map +1 -1
  126. package/build-module/media-text/edit.js +2 -1
  127. package/build-module/media-text/edit.js.map +1 -1
  128. package/build-module/media-text/media-container.js +1 -1
  129. package/build-module/media-text/media-container.js.map +1 -1
  130. package/build-module/navigation/edit/index.js +66 -122
  131. package/build-module/navigation/edit/index.js.map +1 -1
  132. package/build-module/navigation/edit/navigation-menu-selector.js +12 -15
  133. package/build-module/navigation/edit/navigation-menu-selector.js.map +1 -1
  134. package/build-module/navigation/edit/placeholder/index.js +4 -2
  135. package/build-module/navigation/edit/placeholder/index.js.map +1 -1
  136. package/build-module/navigation/edit/responsive-wrapper.js +12 -3
  137. package/build-module/navigation/edit/responsive-wrapper.js.map +1 -1
  138. package/build-module/navigation/edit/use-create-navigation-menu.js +5 -1
  139. package/build-module/navigation/edit/use-create-navigation-menu.js.map +1 -1
  140. package/build-module/navigation/edit/use-inner-blocks.js +33 -0
  141. package/build-module/navigation/edit/use-inner-blocks.js.map +1 -0
  142. package/build-module/navigation/edit/utils.js +21 -0
  143. package/build-module/navigation/edit/utils.js.map +1 -0
  144. package/build-module/navigation/use-navigation-menu.js +7 -3
  145. package/build-module/navigation/use-navigation-menu.js.map +1 -1
  146. package/build-module/post-author/edit.js +5 -2
  147. package/build-module/post-author/edit.js.map +1 -1
  148. package/build-module/post-author-biography/edit.js +6 -1
  149. package/build-module/post-author-biography/edit.js.map +1 -1
  150. package/build-module/post-content/edit.js +5 -3
  151. package/build-module/post-content/edit.js.map +1 -1
  152. package/build-module/post-featured-image/edit.js +17 -3
  153. package/build-module/post-featured-image/edit.js.map +1 -1
  154. package/build-module/post-featured-image/index.js +9 -0
  155. package/build-module/post-featured-image/index.js.map +1 -1
  156. package/build-module/query/edit/inspector-controls/index.js +42 -9
  157. package/build-module/query/edit/inspector-controls/index.js.map +1 -1
  158. package/build-module/query/edit/inspector-controls/taxonomy-controls.js +16 -12
  159. package/build-module/query/edit/inspector-controls/taxonomy-controls.js.map +1 -1
  160. package/build-module/query-title/edit.js +20 -8
  161. package/build-module/query-title/edit.js.map +1 -1
  162. package/build-module/query-title/index.js +4 -0
  163. package/build-module/query-title/index.js.map +1 -1
  164. package/build-module/query-title/variations.js +10 -0
  165. package/build-module/query-title/variations.js.map +1 -1
  166. package/build-module/quote/transforms.js +3 -3
  167. package/build-module/quote/transforms.js.map +1 -1
  168. package/build-module/separator/edit.js +1 -1
  169. package/build-module/separator/edit.js.map +1 -1
  170. package/build-module/social-links/edit.js +1 -0
  171. package/build-module/social-links/edit.js.map +1 -1
  172. package/build-module/template-part/edit/index.js +5 -3
  173. package/build-module/template-part/edit/index.js.map +1 -1
  174. package/build-style/editor-rtl.css +10 -0
  175. package/build-style/editor.css +10 -0
  176. package/build-style/latest-posts/editor-rtl.css +3 -0
  177. package/build-style/latest-posts/editor.css +3 -0
  178. package/build-style/navigation/style-rtl.css +17 -19
  179. package/build-style/navigation/style.css +17 -19
  180. package/build-style/query/editor-rtl.css +7 -0
  181. package/build-style/query/editor.css +7 -0
  182. package/build-style/query-pagination/style-rtl.css +6 -0
  183. package/build-style/query-pagination/style.css +6 -0
  184. package/build-style/search/style-rtl.css +2 -0
  185. package/build-style/search/style.css +2 -0
  186. package/build-style/style-rtl.css +26 -19
  187. package/build-style/style.css +26 -19
  188. package/build-style/tag-cloud/style-rtl.css +1 -0
  189. package/build-style/tag-cloud/style.css +1 -0
  190. package/package.json +28 -29
  191. package/src/archives/block.json +4 -0
  192. package/src/archives/edit.js +12 -1
  193. package/src/archives/index.php +5 -3
  194. package/src/audio/test/__snapshots__/edit.native.js.snap +16 -2
  195. package/src/block/edit.js +4 -4
  196. package/src/block/edit.native.js +4 -4
  197. package/src/calendar/edit.js +11 -4
  198. package/src/columns/edit.native.js +4 -2
  199. package/src/cover/edit/resizable-cover.js +6 -0
  200. package/src/cover/index.php +2 -2
  201. package/src/file/test/__snapshots__/edit.native.js.snap +32 -4
  202. package/src/group/transforms.js +7 -0
  203. package/src/home-link/index.php +8 -17
  204. package/src/image/test/edit.native.js +6 -10
  205. package/src/index.native.js +15 -2
  206. package/src/latest-posts/editor.scss +5 -0
  207. package/src/list/index.js +1 -1
  208. package/src/list/test/__snapshots__/edit.native.js.snap +133 -0
  209. package/src/list/test/edit.native.js +511 -7
  210. package/src/list/v2/edit.js +12 -4
  211. package/src/list/v2/tag-name.js +13 -0
  212. package/src/list/v2/tag-name.native.js +12 -0
  213. package/src/list/v2/transforms.js +1 -9
  214. package/src/list-item/edit.js +1 -1
  215. package/src/list-item/edit.native.js +148 -0
  216. package/src/list-item/icons.native.js +34 -0
  217. package/src/list-item/list-style-type.native.js +139 -0
  218. package/src/list-item/style.native.scss +45 -0
  219. package/src/media-text/deprecated.js +561 -415
  220. package/src/media-text/edit.js +1 -0
  221. package/src/media-text/media-container.js +3 -1
  222. package/src/media-text/test/media-container.js +24 -0
  223. package/src/navigation/edit/index.js +83 -164
  224. package/src/navigation/edit/navigation-menu-selector.js +12 -26
  225. package/src/navigation/edit/placeholder/index.js +4 -2
  226. package/src/navigation/edit/responsive-wrapper.js +24 -3
  227. package/src/navigation/edit/use-create-navigation-menu.js +4 -0
  228. package/src/navigation/edit/use-inner-blocks.js +39 -0
  229. package/src/navigation/edit/utils.js +30 -0
  230. package/src/navigation/index.php +6 -0
  231. package/src/navigation/style.scss +12 -22
  232. package/src/navigation/use-navigation-menu.js +9 -5
  233. package/src/navigation-link/index.php +1 -1
  234. package/src/navigation-submenu/index.php +1 -1
  235. package/src/page-list/index.php +4 -4
  236. package/src/post-author/edit.js +6 -3
  237. package/src/post-author-biography/edit.js +4 -1
  238. package/src/post-content/edit.js +4 -4
  239. package/src/post-featured-image/block.json +9 -0
  240. package/src/post-featured-image/edit.js +23 -1
  241. package/src/post-featured-image/index.php +3 -1
  242. package/src/post-title/index.php +2 -1
  243. package/src/preformatted/test/__snapshots__/edit.native.js.snap +16 -2
  244. package/src/query/edit/inspector-controls/index.js +129 -65
  245. package/src/query/edit/inspector-controls/taxonomy-controls.js +17 -10
  246. package/src/query/editor.scss +9 -0
  247. package/src/query-pagination/style.scss +14 -0
  248. package/src/query-title/block.json +4 -0
  249. package/src/query-title/edit.js +33 -6
  250. package/src/query-title/index.php +17 -1
  251. package/src/query-title/variations.js +13 -0
  252. package/src/quote/transforms.js +3 -7
  253. package/src/search/style.scss +2 -0
  254. package/src/search/test/__snapshots__/edit.native.js.snap +56 -7
  255. package/src/separator/edit.js +1 -1
  256. package/src/separator/test/edit.js +5 -3
  257. package/src/site-title/index.php +8 -9
  258. package/src/social-link/index.php +1 -1
  259. package/src/social-links/edit.js +1 -0
  260. package/src/tag-cloud/style.scss +1 -0
  261. package/src/template-part/edit/index.js +4 -4
@@ -17,9 +17,19 @@ import {
17
17
  /**
18
18
  * Internal dependencies
19
19
  */
20
- import { imageFillStyles } from './media-container';
21
20
  import { DEFAULT_MEDIA_SIZE_SLUG } from './constants';
22
21
 
22
+ const v1ToV5ImageFillStyles = ( url, focalPoint ) => {
23
+ return url
24
+ ? {
25
+ backgroundImage: `url(${ url })`,
26
+ backgroundPosition: focalPoint
27
+ ? `${ focalPoint.x * 100 }% ${ focalPoint.y * 100 }%`
28
+ : `50% 50%`,
29
+ }
30
+ : {};
31
+ };
32
+
23
33
  const DEFAULT_MEDIA_WIDTH = 50;
24
34
  const noop = () => {};
25
35
 
@@ -43,9 +53,6 @@ const baseAttributes = {
43
53
  type: 'string',
44
54
  default: 'wide',
45
55
  },
46
- backgroundColor: {
47
- type: 'string',
48
- },
49
56
  mediaAlt: {
50
57
  type: 'string',
51
58
  source: 'attribute',
@@ -73,217 +80,464 @@ const baseAttributes = {
73
80
  },
74
81
  };
75
82
 
76
- export default [
77
- // Version with CSS grid
78
- {
79
- attributes: {
80
- ...baseAttributes,
81
- mediaUrl: {
82
- type: 'string',
83
- source: 'attribute',
84
- selector: 'figure video,figure img',
85
- attribute: 'src',
86
- },
87
- mediaLink: {
88
- type: 'string',
89
- },
90
- linkDestination: {
91
- type: 'string',
92
- },
93
- linkTarget: {
94
- type: 'string',
95
- source: 'attribute',
96
- selector: 'figure a',
97
- attribute: 'target',
98
- },
99
- href: {
100
- type: 'string',
101
- source: 'attribute',
102
- selector: 'figure a',
103
- attribute: 'href',
104
- },
105
- rel: {
106
- type: 'string',
107
- source: 'attribute',
108
- selector: 'figure a',
109
- attribute: 'rel',
110
- },
111
- linkClass: {
112
- type: 'string',
113
- source: 'attribute',
114
- selector: 'figure a',
115
- attribute: 'class',
116
- },
117
- verticalAlignment: {
118
- type: 'string',
119
- },
120
- imageFill: {
121
- type: 'boolean',
122
- },
123
- focalPoint: {
124
- type: 'object',
125
- },
126
- },
127
- save( { attributes } ) {
128
- const {
129
- isStackedOnMobile,
130
- mediaAlt,
131
- mediaPosition,
132
- mediaType,
133
- mediaUrl,
134
- mediaWidth,
135
- mediaId,
136
- verticalAlignment,
137
- imageFill,
138
- focalPoint,
139
- linkClass,
140
- href,
141
- linkTarget,
142
- rel,
143
- } = attributes;
144
- const mediaSizeSlug =
145
- attributes.mediaSizeSlug || DEFAULT_MEDIA_SIZE_SLUG;
146
- const newRel = isEmpty( rel ) ? undefined : rel;
147
-
148
- const imageClasses = classnames( {
149
- [ `wp-image-${ mediaId }` ]: mediaId && mediaType === 'image',
150
- [ `size-${ mediaSizeSlug }` ]: mediaId && mediaType === 'image',
151
- } );
152
-
153
- let image = (
154
- <img
155
- src={ mediaUrl }
156
- alt={ mediaAlt }
157
- className={ imageClasses || null }
158
- />
83
+ const v4ToV5BlockAttributes = {
84
+ ...baseAttributes,
85
+ mediaUrl: {
86
+ type: 'string',
87
+ source: 'attribute',
88
+ selector: 'figure video,figure img',
89
+ attribute: 'src',
90
+ },
91
+ mediaLink: {
92
+ type: 'string',
93
+ },
94
+ linkDestination: {
95
+ type: 'string',
96
+ },
97
+ linkTarget: {
98
+ type: 'string',
99
+ source: 'attribute',
100
+ selector: 'figure a',
101
+ attribute: 'target',
102
+ },
103
+ href: {
104
+ type: 'string',
105
+ source: 'attribute',
106
+ selector: 'figure a',
107
+ attribute: 'href',
108
+ },
109
+ rel: {
110
+ type: 'string',
111
+ source: 'attribute',
112
+ selector: 'figure a',
113
+ attribute: 'rel',
114
+ },
115
+ linkClass: {
116
+ type: 'string',
117
+ source: 'attribute',
118
+ selector: 'figure a',
119
+ attribute: 'class',
120
+ },
121
+ mediaSizeSlug: {
122
+ type: 'string',
123
+ },
124
+ verticalAlignment: {
125
+ type: 'string',
126
+ },
127
+ imageFill: {
128
+ type: 'boolean',
129
+ },
130
+ focalPoint: {
131
+ type: 'object',
132
+ },
133
+ };
134
+
135
+ const v4ToV5Supports = {
136
+ anchor: true,
137
+ align: [ 'wide', 'full' ],
138
+ html: false,
139
+ color: {
140
+ gradients: true,
141
+ link: true,
142
+ },
143
+ };
144
+
145
+ const v5 = {
146
+ attributes: v4ToV5BlockAttributes,
147
+ supports: v4ToV5Supports,
148
+ save( { attributes } ) {
149
+ const {
150
+ isStackedOnMobile,
151
+ mediaAlt,
152
+ mediaPosition,
153
+ mediaType,
154
+ mediaUrl,
155
+ mediaWidth,
156
+ mediaId,
157
+ verticalAlignment,
158
+ imageFill,
159
+ focalPoint,
160
+ linkClass,
161
+ href,
162
+ linkTarget,
163
+ rel,
164
+ } = attributes;
165
+ const mediaSizeSlug =
166
+ attributes.mediaSizeSlug || DEFAULT_MEDIA_SIZE_SLUG;
167
+ const newRel = isEmpty( rel ) ? undefined : rel;
168
+
169
+ const imageClasses = classnames( {
170
+ [ `wp-image-${ mediaId }` ]: mediaId && mediaType === 'image',
171
+ [ `size-${ mediaSizeSlug }` ]: mediaId && mediaType === 'image',
172
+ } );
173
+
174
+ let image = (
175
+ <img
176
+ src={ mediaUrl }
177
+ alt={ mediaAlt }
178
+ className={ imageClasses || null }
179
+ />
180
+ );
181
+
182
+ if ( href ) {
183
+ image = (
184
+ <a
185
+ className={ linkClass }
186
+ href={ href }
187
+ target={ linkTarget }
188
+ rel={ newRel }
189
+ >
190
+ { image }
191
+ </a>
159
192
  );
193
+ }
160
194
 
161
- if ( href ) {
162
- image = (
163
- <a
164
- className={ linkClass }
165
- href={ href }
166
- target={ linkTarget }
167
- rel={ newRel }
168
- >
169
- { image }
170
- </a>
171
- );
172
- }
173
-
174
- const mediaTypeRenders = {
175
- image: () => image,
176
- video: () => <video controls src={ mediaUrl } />,
177
- };
178
-
179
- const className = classnames( {
180
- 'has-media-on-the-right': 'right' === mediaPosition,
181
- 'is-stacked-on-mobile': isStackedOnMobile,
182
- [ `is-vertically-aligned-${ verticalAlignment }` ]:
183
- verticalAlignment,
184
- 'is-image-fill': imageFill,
185
- } );
186
- const backgroundStyles = imageFill
187
- ? imageFillStyles( mediaUrl, focalPoint )
188
- : {};
189
-
190
- let gridTemplateColumns;
191
- if ( mediaWidth !== DEFAULT_MEDIA_WIDTH ) {
192
- gridTemplateColumns =
193
- 'right' === mediaPosition
194
- ? `auto ${ mediaWidth }%`
195
- : `${ mediaWidth }% auto`;
196
- }
197
- const style = {
198
- gridTemplateColumns,
199
- };
195
+ const mediaTypeRenders = {
196
+ image: () => image,
197
+ video: () => <video controls src={ mediaUrl } />,
198
+ };
199
+ const className = classnames( {
200
+ 'has-media-on-the-right': 'right' === mediaPosition,
201
+ 'is-stacked-on-mobile': isStackedOnMobile,
202
+ [ `is-vertically-aligned-${ verticalAlignment }` ]:
203
+ verticalAlignment,
204
+ 'is-image-fill': imageFill,
205
+ } );
206
+ const backgroundStyles = imageFill
207
+ ? v1ToV5ImageFillStyles( mediaUrl, focalPoint )
208
+ : {};
209
+
210
+ let gridTemplateColumns;
211
+ if ( mediaWidth !== DEFAULT_MEDIA_WIDTH ) {
212
+ gridTemplateColumns =
213
+ 'right' === mediaPosition
214
+ ? `auto ${ mediaWidth }%`
215
+ : `${ mediaWidth }% auto`;
216
+ }
217
+ const style = {
218
+ gridTemplateColumns,
219
+ };
200
220
 
221
+ if ( 'right' === mediaPosition ) {
201
222
  return (
202
223
  <div { ...useBlockProps.save( { className, style } ) }>
224
+ <div
225
+ { ...useInnerBlocksProps.save( {
226
+ className: 'wp-block-media-text__content',
227
+ } ) }
228
+ />
203
229
  <figure
204
230
  className="wp-block-media-text__media"
205
231
  style={ backgroundStyles }
206
232
  >
207
233
  { ( mediaTypeRenders[ mediaType ] || noop )() }
208
234
  </figure>
209
- <div
210
- { ...useInnerBlocksProps.save( {
211
- className: 'wp-block-media-text__content',
212
- } ) }
213
- />
214
235
  </div>
215
236
  );
216
- },
237
+ }
238
+ return (
239
+ <div { ...useBlockProps.save( { className, style } ) }>
240
+ <figure
241
+ className="wp-block-media-text__media"
242
+ style={ backgroundStyles }
243
+ >
244
+ { ( mediaTypeRenders[ mediaType ] || noop )() }
245
+ </figure>
246
+ <div
247
+ { ...useInnerBlocksProps.save( {
248
+ className: 'wp-block-media-text__content',
249
+ } ) }
250
+ />
251
+ </div>
252
+ );
217
253
  },
218
- {
219
- attributes: {
220
- ...baseAttributes,
221
- customBackgroundColor: {
222
- type: 'string',
223
- },
224
- mediaLink: {
225
- type: 'string',
226
- },
227
- linkDestination: {
228
- type: 'string',
229
- },
230
- linkTarget: {
231
- type: 'string',
232
- source: 'attribute',
233
- selector: 'figure a',
234
- attribute: 'target',
235
- },
236
- href: {
237
- type: 'string',
238
- source: 'attribute',
239
- selector: 'figure a',
240
- attribute: 'href',
241
- },
242
- rel: {
243
- type: 'string',
244
- source: 'attribute',
245
- selector: 'figure a',
246
- attribute: 'rel',
247
- },
248
- linkClass: {
249
- type: 'string',
250
- source: 'attribute',
251
- selector: 'figure a',
252
- attribute: 'class',
253
- },
254
- verticalAlignment: {
255
- type: 'string',
256
- },
257
- imageFill: {
258
- type: 'boolean',
259
- },
260
- focalPoint: {
261
- type: 'object',
262
- },
254
+ };
255
+
256
+ // Version with CSS grid
257
+ const v4 = {
258
+ attributes: v4ToV5BlockAttributes,
259
+ supports: v4ToV5Supports,
260
+ save( { attributes } ) {
261
+ const {
262
+ isStackedOnMobile,
263
+ mediaAlt,
264
+ mediaPosition,
265
+ mediaType,
266
+ mediaUrl,
267
+ mediaWidth,
268
+ mediaId,
269
+ verticalAlignment,
270
+ imageFill,
271
+ focalPoint,
272
+ linkClass,
273
+ href,
274
+ linkTarget,
275
+ rel,
276
+ } = attributes;
277
+ const mediaSizeSlug =
278
+ attributes.mediaSizeSlug || DEFAULT_MEDIA_SIZE_SLUG;
279
+ const newRel = isEmpty( rel ) ? undefined : rel;
280
+
281
+ const imageClasses = classnames( {
282
+ [ `wp-image-${ mediaId }` ]: mediaId && mediaType === 'image',
283
+ [ `size-${ mediaSizeSlug }` ]: mediaId && mediaType === 'image',
284
+ } );
285
+
286
+ let image = (
287
+ <img
288
+ src={ mediaUrl }
289
+ alt={ mediaAlt }
290
+ className={ imageClasses || null }
291
+ />
292
+ );
293
+
294
+ if ( href ) {
295
+ image = (
296
+ <a
297
+ className={ linkClass }
298
+ href={ href }
299
+ target={ linkTarget }
300
+ rel={ newRel }
301
+ >
302
+ { image }
303
+ </a>
304
+ );
305
+ }
306
+
307
+ const mediaTypeRenders = {
308
+ image: () => image,
309
+ video: () => <video controls src={ mediaUrl } />,
310
+ };
311
+
312
+ const className = classnames( {
313
+ 'has-media-on-the-right': 'right' === mediaPosition,
314
+ 'is-stacked-on-mobile': isStackedOnMobile,
315
+ [ `is-vertically-aligned-${ verticalAlignment }` ]:
316
+ verticalAlignment,
317
+ 'is-image-fill': imageFill,
318
+ } );
319
+ const backgroundStyles = imageFill
320
+ ? v1ToV5ImageFillStyles( mediaUrl, focalPoint )
321
+ : {};
322
+
323
+ let gridTemplateColumns;
324
+ if ( mediaWidth !== DEFAULT_MEDIA_WIDTH ) {
325
+ gridTemplateColumns =
326
+ 'right' === mediaPosition
327
+ ? `auto ${ mediaWidth }%`
328
+ : `${ mediaWidth }% auto`;
329
+ }
330
+ const style = {
331
+ gridTemplateColumns,
332
+ };
333
+
334
+ return (
335
+ <div { ...useBlockProps.save( { className, style } ) }>
336
+ <figure
337
+ className="wp-block-media-text__media"
338
+ style={ backgroundStyles }
339
+ >
340
+ { ( mediaTypeRenders[ mediaType ] || noop )() }
341
+ </figure>
342
+ <div
343
+ { ...useInnerBlocksProps.save( {
344
+ className: 'wp-block-media-text__content',
345
+ } ) }
346
+ />
347
+ </div>
348
+ );
349
+ },
350
+ };
351
+
352
+ const v3 = {
353
+ attributes: {
354
+ ...baseAttributes,
355
+ backgroundColor: {
356
+ type: 'string',
357
+ },
358
+ customBackgroundColor: {
359
+ type: 'string',
360
+ },
361
+ mediaLink: {
362
+ type: 'string',
363
+ },
364
+ linkDestination: {
365
+ type: 'string',
366
+ },
367
+ linkTarget: {
368
+ type: 'string',
369
+ source: 'attribute',
370
+ selector: 'figure a',
371
+ attribute: 'target',
372
+ },
373
+ href: {
374
+ type: 'string',
375
+ source: 'attribute',
376
+ selector: 'figure a',
377
+ attribute: 'href',
263
378
  },
264
- migrate: migrateCustomColors,
265
- save( { attributes } ) {
266
- const {
267
- backgroundColor,
268
- customBackgroundColor,
269
- isStackedOnMobile,
270
- mediaAlt,
271
- mediaPosition,
272
- mediaType,
273
- mediaUrl,
274
- mediaWidth,
275
- mediaId,
379
+ rel: {
380
+ type: 'string',
381
+ source: 'attribute',
382
+ selector: 'figure a',
383
+ attribute: 'rel',
384
+ },
385
+ linkClass: {
386
+ type: 'string',
387
+ source: 'attribute',
388
+ selector: 'figure a',
389
+ attribute: 'class',
390
+ },
391
+ verticalAlignment: {
392
+ type: 'string',
393
+ },
394
+ imageFill: {
395
+ type: 'boolean',
396
+ },
397
+ focalPoint: {
398
+ type: 'object',
399
+ },
400
+ },
401
+ migrate: migrateCustomColors,
402
+ save( { attributes } ) {
403
+ const {
404
+ backgroundColor,
405
+ customBackgroundColor,
406
+ isStackedOnMobile,
407
+ mediaAlt,
408
+ mediaPosition,
409
+ mediaType,
410
+ mediaUrl,
411
+ mediaWidth,
412
+ mediaId,
413
+ verticalAlignment,
414
+ imageFill,
415
+ focalPoint,
416
+ linkClass,
417
+ href,
418
+ linkTarget,
419
+ rel,
420
+ } = attributes;
421
+ const newRel = isEmpty( rel ) ? undefined : rel;
422
+
423
+ let image = (
424
+ <img
425
+ src={ mediaUrl }
426
+ alt={ mediaAlt }
427
+ className={
428
+ mediaId && mediaType === 'image'
429
+ ? `wp-image-${ mediaId }`
430
+ : null
431
+ }
432
+ />
433
+ );
434
+
435
+ if ( href ) {
436
+ image = (
437
+ <a
438
+ className={ linkClass }
439
+ href={ href }
440
+ target={ linkTarget }
441
+ rel={ newRel }
442
+ >
443
+ { image }
444
+ </a>
445
+ );
446
+ }
447
+
448
+ const mediaTypeRenders = {
449
+ image: () => image,
450
+ video: () => <video controls src={ mediaUrl } />,
451
+ };
452
+ const backgroundClass = getColorClassName(
453
+ 'background-color',
454
+ backgroundColor
455
+ );
456
+ const className = classnames( {
457
+ 'has-media-on-the-right': 'right' === mediaPosition,
458
+ 'has-background': backgroundClass || customBackgroundColor,
459
+ [ backgroundClass ]: backgroundClass,
460
+ 'is-stacked-on-mobile': isStackedOnMobile,
461
+ [ `is-vertically-aligned-${ verticalAlignment }` ]:
276
462
  verticalAlignment,
277
- imageFill,
278
- focalPoint,
279
- linkClass,
280
- href,
281
- linkTarget,
282
- rel,
283
- } = attributes;
284
- const newRel = isEmpty( rel ) ? undefined : rel;
285
-
286
- let image = (
463
+ 'is-image-fill': imageFill,
464
+ } );
465
+ const backgroundStyles = imageFill
466
+ ? v1ToV5ImageFillStyles( mediaUrl, focalPoint )
467
+ : {};
468
+
469
+ let gridTemplateColumns;
470
+ if ( mediaWidth !== DEFAULT_MEDIA_WIDTH ) {
471
+ gridTemplateColumns =
472
+ 'right' === mediaPosition
473
+ ? `auto ${ mediaWidth }%`
474
+ : `${ mediaWidth }% auto`;
475
+ }
476
+ const style = {
477
+ backgroundColor: backgroundClass
478
+ ? undefined
479
+ : customBackgroundColor,
480
+ gridTemplateColumns,
481
+ };
482
+ return (
483
+ <div className={ className } style={ style }>
484
+ <figure
485
+ className="wp-block-media-text__media"
486
+ style={ backgroundStyles }
487
+ >
488
+ { ( mediaTypeRenders[ mediaType ] || noop )() }
489
+ </figure>
490
+ <div className="wp-block-media-text__content">
491
+ <InnerBlocks.Content />
492
+ </div>
493
+ </div>
494
+ );
495
+ },
496
+ };
497
+
498
+ const v2 = {
499
+ attributes: {
500
+ ...baseAttributes,
501
+ backgroundColor: {
502
+ type: 'string',
503
+ },
504
+ customBackgroundColor: {
505
+ type: 'string',
506
+ },
507
+ mediaUrl: {
508
+ type: 'string',
509
+ source: 'attribute',
510
+ selector: 'figure video,figure img',
511
+ attribute: 'src',
512
+ },
513
+ verticalAlignment: {
514
+ type: 'string',
515
+ },
516
+ imageFill: {
517
+ type: 'boolean',
518
+ },
519
+ focalPoint: {
520
+ type: 'object',
521
+ },
522
+ },
523
+ migrate: migrateCustomColors,
524
+ save( { attributes } ) {
525
+ const {
526
+ backgroundColor,
527
+ customBackgroundColor,
528
+ isStackedOnMobile,
529
+ mediaAlt,
530
+ mediaPosition,
531
+ mediaType,
532
+ mediaUrl,
533
+ mediaWidth,
534
+ mediaId,
535
+ verticalAlignment,
536
+ imageFill,
537
+ focalPoint,
538
+ } = attributes;
539
+ const mediaTypeRenders = {
540
+ image: () => (
287
541
  <img
288
542
  src={ mediaUrl }
289
543
  alt={ mediaAlt }
@@ -293,227 +547,119 @@ export default [
293
547
  : null
294
548
  }
295
549
  />
296
- );
550
+ ),
551
+ video: () => <video controls src={ mediaUrl } />,
552
+ };
553
+ const backgroundClass = getColorClassName(
554
+ 'background-color',
555
+ backgroundColor
556
+ );
557
+ const className = classnames( {
558
+ 'has-media-on-the-right': 'right' === mediaPosition,
559
+ [ backgroundClass ]: backgroundClass,
560
+ 'is-stacked-on-mobile': isStackedOnMobile,
561
+ [ `is-vertically-aligned-${ verticalAlignment }` ]:
562
+ verticalAlignment,
563
+ 'is-image-fill': imageFill,
564
+ } );
565
+ const backgroundStyles = imageFill
566
+ ? v1ToV5ImageFillStyles( mediaUrl, focalPoint )
567
+ : {};
297
568
 
298
- if ( href ) {
299
- image = (
300
- <a
301
- className={ linkClass }
302
- href={ href }
303
- target={ linkTarget }
304
- rel={ newRel }
305
- >
306
- { image }
307
- </a>
308
- );
309
- }
310
-
311
- const mediaTypeRenders = {
312
- image: () => image,
313
- video: () => <video controls src={ mediaUrl } />,
314
- };
315
- const backgroundClass = getColorClassName(
316
- 'background-color',
317
- backgroundColor
318
- );
319
- const className = classnames( {
320
- 'has-media-on-the-right': 'right' === mediaPosition,
321
- 'has-background': backgroundClass || customBackgroundColor,
322
- [ backgroundClass ]: backgroundClass,
323
- 'is-stacked-on-mobile': isStackedOnMobile,
324
- [ `is-vertically-aligned-${ verticalAlignment }` ]:
325
- verticalAlignment,
326
- 'is-image-fill': imageFill,
327
- } );
328
- const backgroundStyles = imageFill
329
- ? imageFillStyles( mediaUrl, focalPoint )
330
- : {};
331
-
332
- let gridTemplateColumns;
333
- if ( mediaWidth !== DEFAULT_MEDIA_WIDTH ) {
334
- gridTemplateColumns =
335
- 'right' === mediaPosition
336
- ? `auto ${ mediaWidth }%`
337
- : `${ mediaWidth }% auto`;
338
- }
339
- const style = {
340
- backgroundColor: backgroundClass
341
- ? undefined
342
- : customBackgroundColor,
343
- gridTemplateColumns,
344
- };
345
- return (
346
- <div className={ className } style={ style }>
347
- <figure
348
- className="wp-block-media-text__media"
349
- style={ backgroundStyles }
350
- >
351
- { ( mediaTypeRenders[ mediaType ] || noop )() }
352
- </figure>
353
- <div className="wp-block-media-text__content">
354
- <InnerBlocks.Content />
355
- </div>
569
+ let gridTemplateColumns;
570
+ if ( mediaWidth !== DEFAULT_MEDIA_WIDTH ) {
571
+ gridTemplateColumns =
572
+ 'right' === mediaPosition
573
+ ? `auto ${ mediaWidth }%`
574
+ : `${ mediaWidth }% auto`;
575
+ }
576
+ const style = {
577
+ backgroundColor: backgroundClass
578
+ ? undefined
579
+ : customBackgroundColor,
580
+ gridTemplateColumns,
581
+ };
582
+ return (
583
+ <div className={ className } style={ style }>
584
+ <figure
585
+ className="wp-block-media-text__media"
586
+ style={ backgroundStyles }
587
+ >
588
+ { ( mediaTypeRenders[ mediaType ] || noop )() }
589
+ </figure>
590
+ <div className="wp-block-media-text__content">
591
+ <InnerBlocks.Content />
356
592
  </div>
357
- );
358
- },
593
+ </div>
594
+ );
359
595
  },
360
- {
361
- attributes: {
362
- ...baseAttributes,
363
- customBackgroundColor: {
364
- type: 'string',
365
- },
366
- mediaUrl: {
367
- type: 'string',
368
- source: 'attribute',
369
- selector: 'figure video,figure img',
370
- attribute: 'src',
371
- },
372
- verticalAlignment: {
373
- type: 'string',
374
- },
375
- imageFill: {
376
- type: 'boolean',
377
- },
378
- focalPoint: {
379
- type: 'object',
380
- },
596
+ };
597
+
598
+ const v1 = {
599
+ attributes: {
600
+ ...baseAttributes,
601
+ backgroundColor: {
602
+ type: 'string',
381
603
  },
382
- migrate: migrateCustomColors,
383
- save( { attributes } ) {
384
- const {
385
- backgroundColor,
386
- customBackgroundColor,
387
- isStackedOnMobile,
388
- mediaAlt,
389
- mediaPosition,
390
- mediaType,
391
- mediaUrl,
392
- mediaWidth,
393
- mediaId,
394
- verticalAlignment,
395
- imageFill,
396
- focalPoint,
397
- } = attributes;
398
- const mediaTypeRenders = {
399
- image: () => (
400
- <img
401
- src={ mediaUrl }
402
- alt={ mediaAlt }
403
- className={
404
- mediaId && mediaType === 'image'
405
- ? `wp-image-${ mediaId }`
406
- : null
407
- }
408
- />
409
- ),
410
- video: () => <video controls src={ mediaUrl } />,
411
- };
412
- const backgroundClass = getColorClassName(
413
- 'background-color',
414
- backgroundColor
415
- );
416
- const className = classnames( {
417
- 'has-media-on-the-right': 'right' === mediaPosition,
418
- [ backgroundClass ]: backgroundClass,
419
- 'is-stacked-on-mobile': isStackedOnMobile,
420
- [ `is-vertically-aligned-${ verticalAlignment }` ]:
421
- verticalAlignment,
422
- 'is-image-fill': imageFill,
423
- } );
424
- const backgroundStyles = imageFill
425
- ? imageFillStyles( mediaUrl, focalPoint )
426
- : {};
427
-
428
- let gridTemplateColumns;
429
- if ( mediaWidth !== DEFAULT_MEDIA_WIDTH ) {
430
- gridTemplateColumns =
431
- 'right' === mediaPosition
432
- ? `auto ${ mediaWidth }%`
433
- : `${ mediaWidth }% auto`;
434
- }
435
- const style = {
436
- backgroundColor: backgroundClass
437
- ? undefined
438
- : customBackgroundColor,
439
- gridTemplateColumns,
440
- };
441
- return (
442
- <div className={ className } style={ style }>
443
- <figure
444
- className="wp-block-media-text__media"
445
- style={ backgroundStyles }
446
- >
447
- { ( mediaTypeRenders[ mediaType ] || noop )() }
448
- </figure>
449
- <div className="wp-block-media-text__content">
450
- <InnerBlocks.Content />
451
- </div>
452
- </div>
453
- );
604
+ customBackgroundColor: {
605
+ type: 'string',
454
606
  },
455
- },
456
- {
457
- attributes: {
458
- ...baseAttributes,
459
- customBackgroundColor: {
460
- type: 'string',
461
- },
462
- mediaUrl: {
463
- type: 'string',
464
- source: 'attribute',
465
- selector: 'figure video,figure img',
466
- attribute: 'src',
467
- },
607
+ mediaUrl: {
608
+ type: 'string',
609
+ source: 'attribute',
610
+ selector: 'figure video,figure img',
611
+ attribute: 'src',
468
612
  },
469
- save( { attributes } ) {
470
- const {
471
- backgroundColor,
472
- customBackgroundColor,
473
- isStackedOnMobile,
474
- mediaAlt,
475
- mediaPosition,
476
- mediaType,
477
- mediaUrl,
478
- mediaWidth,
479
- } = attributes;
480
- const mediaTypeRenders = {
481
- image: () => <img src={ mediaUrl } alt={ mediaAlt } />,
482
- video: () => <video controls src={ mediaUrl } />,
483
- };
484
- const backgroundClass = getColorClassName(
485
- 'background-color',
486
- backgroundColor
487
- );
488
- const className = classnames( {
489
- 'has-media-on-the-right': 'right' === mediaPosition,
490
- [ backgroundClass ]: backgroundClass,
491
- 'is-stacked-on-mobile': isStackedOnMobile,
492
- } );
493
-
494
- let gridTemplateColumns;
495
- if ( mediaWidth !== DEFAULT_MEDIA_WIDTH ) {
496
- gridTemplateColumns =
497
- 'right' === mediaPosition
498
- ? `auto ${ mediaWidth }%`
499
- : `${ mediaWidth }% auto`;
500
- }
501
- const style = {
502
- backgroundColor: backgroundClass
503
- ? undefined
504
- : customBackgroundColor,
505
- gridTemplateColumns,
506
- };
507
- return (
508
- <div className={ className } style={ style }>
509
- <figure className="wp-block-media-text__media">
510
- { ( mediaTypeRenders[ mediaType ] || noop )() }
511
- </figure>
512
- <div className="wp-block-media-text__content">
513
- <InnerBlocks.Content />
514
- </div>
613
+ },
614
+ save( { attributes } ) {
615
+ const {
616
+ backgroundColor,
617
+ customBackgroundColor,
618
+ isStackedOnMobile,
619
+ mediaAlt,
620
+ mediaPosition,
621
+ mediaType,
622
+ mediaUrl,
623
+ mediaWidth,
624
+ } = attributes;
625
+ const mediaTypeRenders = {
626
+ image: () => <img src={ mediaUrl } alt={ mediaAlt } />,
627
+ video: () => <video controls src={ mediaUrl } />,
628
+ };
629
+ const backgroundClass = getColorClassName(
630
+ 'background-color',
631
+ backgroundColor
632
+ );
633
+ const className = classnames( {
634
+ 'has-media-on-the-right': 'right' === mediaPosition,
635
+ [ backgroundClass ]: backgroundClass,
636
+ 'is-stacked-on-mobile': isStackedOnMobile,
637
+ } );
638
+
639
+ let gridTemplateColumns;
640
+ if ( mediaWidth !== DEFAULT_MEDIA_WIDTH ) {
641
+ gridTemplateColumns =
642
+ 'right' === mediaPosition
643
+ ? `auto ${ mediaWidth }%`
644
+ : `${ mediaWidth }% auto`;
645
+ }
646
+ const style = {
647
+ backgroundColor: backgroundClass
648
+ ? undefined
649
+ : customBackgroundColor,
650
+ gridTemplateColumns,
651
+ };
652
+ return (
653
+ <div className={ className } style={ style }>
654
+ <figure className="wp-block-media-text__media">
655
+ { ( mediaTypeRenders[ mediaType ] || noop )() }
656
+ </figure>
657
+ <div className="wp-block-media-text__content">
658
+ <InnerBlocks.Content />
515
659
  </div>
516
- );
517
- },
660
+ </div>
661
+ );
518
662
  },
519
- ];
663
+ };
664
+
665
+ export default [ v5, v4, v3, v2, v1 ];