@wordpress/block-library 8.12.6 → 8.14.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 (305) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/archives/index.js +5 -1
  3. package/build/archives/index.js.map +1 -1
  4. package/build/audio/index.js +5 -1
  5. package/build/audio/index.js.map +1 -1
  6. package/build/block/edit.native.js +2 -2
  7. package/build/block/edit.native.js.map +1 -1
  8. package/build/categories/index.js +5 -1
  9. package/build/categories/index.js.map +1 -1
  10. package/build/code/index.js +5 -1
  11. package/build/code/index.js.map +1 -1
  12. package/build/column/index.js +1 -0
  13. package/build/column/index.js.map +1 -1
  14. package/build/comments/index.js +1 -0
  15. package/build/comments/index.js.map +1 -1
  16. package/build/cover/edit/inspector-controls.js +2 -1
  17. package/build/cover/edit/inspector-controls.js.map +1 -1
  18. package/build/cover/index.js +1 -0
  19. package/build/cover/index.js.map +1 -1
  20. package/build/details/index.js +5 -1
  21. package/build/details/index.js.map +1 -1
  22. package/build/embed/util.js +9 -8
  23. package/build/embed/util.js.map +1 -1
  24. package/build/file/index.js +2 -1
  25. package/build/file/index.js.map +1 -1
  26. package/build/file/view.js +15 -1
  27. package/build/file/view.js.map +1 -1
  28. package/build/gallery/index.js +3 -1
  29. package/build/gallery/index.js.map +1 -1
  30. package/build/group/index.js +1 -0
  31. package/build/group/index.js.map +1 -1
  32. package/build/heading/index.js +5 -1
  33. package/build/heading/index.js.map +1 -1
  34. package/build/heading/transforms.js +5 -1
  35. package/build/heading/transforms.js.map +1 -1
  36. package/build/image/deprecated.js +453 -175
  37. package/build/image/deprecated.js.map +1 -1
  38. package/build/image/image.js +1 -1
  39. package/build/image/image.js.map +1 -1
  40. package/build/image/save.js +3 -1
  41. package/build/image/save.js.map +1 -1
  42. package/build/image/{interactivity.js → view-interactivity.js} +86 -44
  43. package/build/image/view-interactivity.js.map +1 -0
  44. package/build/index.js +12 -3
  45. package/build/index.js.map +1 -1
  46. package/build/list/index.js +5 -1
  47. package/build/list/index.js.map +1 -1
  48. package/build/list-item/utils.js +6 -1
  49. package/build/list-item/utils.js.map +1 -1
  50. package/build/media-text/index.js +1 -0
  51. package/build/media-text/index.js.map +1 -1
  52. package/build/missing/edit.js +22 -8
  53. package/build/missing/edit.js.map +1 -1
  54. package/build/navigation/index.js +3 -2
  55. package/build/navigation/index.js.map +1 -1
  56. package/build/navigation/view.js +174 -50
  57. package/build/navigation/view.js.map +1 -1
  58. package/build/page-list/convert-to-links-modal.js +3 -3
  59. package/build/page-list/convert-to-links-modal.js.map +1 -1
  60. package/build/page-list/edit.js +34 -39
  61. package/build/page-list/edit.js.map +1 -1
  62. package/build/page-list/use-convert-to-navigation-links.js +2 -15
  63. package/build/page-list/use-convert-to-navigation-links.js.map +1 -1
  64. package/build/paragraph/index.js +1 -0
  65. package/build/paragraph/index.js.map +1 -1
  66. package/build/paragraph/transforms.js +1 -0
  67. package/build/paragraph/transforms.js.map +1 -1
  68. package/build/post-comments-form/index.js +1 -0
  69. package/build/post-comments-form/index.js.map +1 -1
  70. package/build/post-navigation-link/index.js +1 -0
  71. package/build/post-navigation-link/index.js.map +1 -1
  72. package/build/post-time-to-read/index.js +5 -1
  73. package/build/post-time-to-read/index.js.map +1 -1
  74. package/build/quote/index.js +1 -0
  75. package/build/quote/index.js.map +1 -1
  76. package/build/site-logo/index.js +5 -1
  77. package/build/site-logo/index.js.map +1 -1
  78. package/build/site-tagline/index.js +5 -1
  79. package/build/site-tagline/index.js.map +1 -1
  80. package/build/site-title/index.js +5 -1
  81. package/build/site-title/index.js.map +1 -1
  82. package/build/social-links/index.js +3 -1
  83. package/build/social-links/index.js.map +1 -1
  84. package/build/table/index.js +5 -1
  85. package/build/table/index.js.map +1 -1
  86. package/build/term-description/index.js +1 -0
  87. package/build/term-description/index.js.map +1 -1
  88. package/build/verse/index.js +5 -1
  89. package/build/verse/index.js.map +1 -1
  90. package/build/video/deprecated.js +5 -1
  91. package/build/video/deprecated.js.map +1 -1
  92. package/build/video/index.js +5 -1
  93. package/build/video/index.js.map +1 -1
  94. package/build-module/archives/index.js +5 -1
  95. package/build-module/archives/index.js.map +1 -1
  96. package/build-module/audio/index.js +5 -1
  97. package/build-module/audio/index.js.map +1 -1
  98. package/build-module/block/edit.native.js +2 -2
  99. package/build-module/block/edit.native.js.map +1 -1
  100. package/build-module/categories/index.js +5 -1
  101. package/build-module/categories/index.js.map +1 -1
  102. package/build-module/code/index.js +5 -1
  103. package/build-module/code/index.js.map +1 -1
  104. package/build-module/column/index.js +1 -0
  105. package/build-module/column/index.js.map +1 -1
  106. package/build-module/comments/index.js +1 -0
  107. package/build-module/comments/index.js.map +1 -1
  108. package/build-module/cover/edit/inspector-controls.js +2 -1
  109. package/build-module/cover/edit/inspector-controls.js.map +1 -1
  110. package/build-module/cover/index.js +1 -0
  111. package/build-module/cover/index.js.map +1 -1
  112. package/build-module/details/index.js +5 -1
  113. package/build-module/details/index.js.map +1 -1
  114. package/build-module/embed/util.js +6 -6
  115. package/build-module/embed/util.js.map +1 -1
  116. package/build-module/file/index.js +2 -1
  117. package/build-module/file/index.js.map +1 -1
  118. package/build-module/file/view.js +15 -2
  119. package/build-module/file/view.js.map +1 -1
  120. package/build-module/gallery/index.js +3 -1
  121. package/build-module/gallery/index.js.map +1 -1
  122. package/build-module/group/index.js +1 -0
  123. package/build-module/group/index.js.map +1 -1
  124. package/build-module/heading/index.js +5 -1
  125. package/build-module/heading/index.js.map +1 -1
  126. package/build-module/heading/transforms.js +5 -1
  127. package/build-module/heading/transforms.js.map +1 -1
  128. package/build-module/image/deprecated.js +454 -176
  129. package/build-module/image/deprecated.js.map +1 -1
  130. package/build-module/image/image.js +1 -1
  131. package/build-module/image/image.js.map +1 -1
  132. package/build-module/image/save.js +3 -1
  133. package/build-module/image/save.js.map +1 -1
  134. package/build-module/image/{interactivity.js → view-interactivity.js} +86 -44
  135. package/build-module/image/view-interactivity.js.map +1 -0
  136. package/build-module/index.js +12 -3
  137. package/build-module/index.js.map +1 -1
  138. package/build-module/list/index.js +5 -1
  139. package/build-module/list/index.js.map +1 -1
  140. package/build-module/list-item/utils.js +6 -1
  141. package/build-module/list-item/utils.js.map +1 -1
  142. package/build-module/media-text/index.js +1 -0
  143. package/build-module/media-text/index.js.map +1 -1
  144. package/build-module/missing/edit.js +22 -8
  145. package/build-module/missing/edit.js.map +1 -1
  146. package/build-module/navigation/index.js +3 -2
  147. package/build-module/navigation/index.js.map +1 -1
  148. package/build-module/navigation/view.js +173 -50
  149. package/build-module/navigation/view.js.map +1 -1
  150. package/build-module/page-list/convert-to-links-modal.js +3 -3
  151. package/build-module/page-list/convert-to-links-modal.js.map +1 -1
  152. package/build-module/page-list/edit.js +34 -39
  153. package/build-module/page-list/edit.js.map +1 -1
  154. package/build-module/page-list/use-convert-to-navigation-links.js +3 -16
  155. package/build-module/page-list/use-convert-to-navigation-links.js.map +1 -1
  156. package/build-module/paragraph/index.js +1 -0
  157. package/build-module/paragraph/index.js.map +1 -1
  158. package/build-module/paragraph/transforms.js +1 -0
  159. package/build-module/paragraph/transforms.js.map +1 -1
  160. package/build-module/post-comments-form/index.js +1 -0
  161. package/build-module/post-comments-form/index.js.map +1 -1
  162. package/build-module/post-navigation-link/index.js +1 -0
  163. package/build-module/post-navigation-link/index.js.map +1 -1
  164. package/build-module/post-time-to-read/index.js +5 -1
  165. package/build-module/post-time-to-read/index.js.map +1 -1
  166. package/build-module/quote/index.js +1 -0
  167. package/build-module/quote/index.js.map +1 -1
  168. package/build-module/site-logo/index.js +5 -1
  169. package/build-module/site-logo/index.js.map +1 -1
  170. package/build-module/site-tagline/index.js +5 -1
  171. package/build-module/site-tagline/index.js.map +1 -1
  172. package/build-module/site-title/index.js +5 -1
  173. package/build-module/site-title/index.js.map +1 -1
  174. package/build-module/social-links/index.js +3 -1
  175. package/build-module/social-links/index.js.map +1 -1
  176. package/build-module/table/index.js +5 -1
  177. package/build-module/table/index.js.map +1 -1
  178. package/build-module/term-description/index.js +1 -0
  179. package/build-module/term-description/index.js.map +1 -1
  180. package/build-module/verse/index.js +5 -1
  181. package/build-module/verse/index.js.map +1 -1
  182. package/build-module/video/deprecated.js +5 -1
  183. package/build-module/video/deprecated.js.map +1 -1
  184. package/build-module/video/index.js +5 -1
  185. package/build-module/video/index.js.map +1 -1
  186. package/build-style/image/style-rtl.css +16 -2
  187. package/build-style/image/style.css +16 -2
  188. package/build-style/style-rtl.css +16 -2
  189. package/build-style/style.css +16 -2
  190. package/package.json +33 -38
  191. package/src/archives/block.json +5 -1
  192. package/src/audio/block.json +5 -1
  193. package/src/block/edit.native.js +2 -2
  194. package/src/block/test/edit.native.js +4 -4
  195. package/src/categories/block.json +5 -1
  196. package/src/code/block.json +5 -1
  197. package/src/column/block.json +1 -0
  198. package/src/comments/block.json +1 -0
  199. package/src/cover/block.json +1 -0
  200. package/src/cover/edit/inspector-controls.js +1 -0
  201. package/src/details/block.json +5 -1
  202. package/src/embed/util.js +4 -6
  203. package/src/file/block.json +2 -1
  204. package/src/file/index.php +0 -17
  205. package/src/file/view.js +14 -5
  206. package/src/gallery/block.json +3 -1
  207. package/src/group/block.json +1 -0
  208. package/src/heading/block.json +5 -1
  209. package/src/heading/test/index.native.js +18 -0
  210. package/src/image/deprecated.js +597 -320
  211. package/src/image/image.js +2 -1
  212. package/src/image/save.js +2 -0
  213. package/src/image/style.scss +15 -2
  214. package/src/image/{interactivity.js → view-interactivity.js} +99 -50
  215. package/src/index.js +18 -1
  216. package/src/list/block.json +5 -1
  217. package/src/media-text/block.json +1 -0
  218. package/src/missing/edit.js +31 -11
  219. package/src/navigation/block.json +3 -2
  220. package/src/navigation/index.php +15 -20
  221. package/src/navigation/view.js +189 -67
  222. package/src/navigation-submenu/index.php +0 -10
  223. package/src/page-list/convert-to-links-modal.js +3 -3
  224. package/src/page-list/edit.js +65 -62
  225. package/src/page-list/use-convert-to-navigation-links.js +3 -20
  226. package/src/paragraph/block.json +1 -0
  227. package/src/post-comments-form/block.json +1 -0
  228. package/src/post-navigation-link/block.json +1 -0
  229. package/src/post-time-to-read/block.json +5 -1
  230. package/src/quote/block.json +1 -0
  231. package/src/site-logo/block.json +5 -1
  232. package/src/site-tagline/block.json +5 -1
  233. package/src/site-title/block.json +5 -1
  234. package/src/social-links/block.json +3 -1
  235. package/src/table/block.json +5 -1
  236. package/src/term-description/block.json +1 -0
  237. package/src/verse/block.json +5 -1
  238. package/src/video/block.json +5 -1
  239. package/build/file/interactivity.js +0 -19
  240. package/build/file/interactivity.js.map +0 -1
  241. package/build/heading/heading-level-icon.js +0 -61
  242. package/build/heading/heading-level-icon.js.map +0 -1
  243. package/build/image/interactivity.js.map +0 -1
  244. package/build/navigation/interactivity.js +0 -167
  245. package/build/navigation/interactivity.js.map +0 -1
  246. package/build/navigation/view-modal.js +0 -64
  247. package/build/navigation/view-modal.js.map +0 -1
  248. package/build/utils/interactivity/constants.js +0 -9
  249. package/build/utils/interactivity/constants.js.map +0 -1
  250. package/build/utils/interactivity/directives.js +0 -222
  251. package/build/utils/interactivity/directives.js.map +0 -1
  252. package/build/utils/interactivity/hooks.js +0 -159
  253. package/build/utils/interactivity/hooks.js.map +0 -1
  254. package/build/utils/interactivity/hydration.js +0 -34
  255. package/build/utils/interactivity/hydration.js.map +0 -1
  256. package/build/utils/interactivity/index.js +0 -32
  257. package/build/utils/interactivity/index.js.map +0 -1
  258. package/build/utils/interactivity/portals.js +0 -108
  259. package/build/utils/interactivity/portals.js.map +0 -1
  260. package/build/utils/interactivity/store.js +0 -66
  261. package/build/utils/interactivity/store.js.map +0 -1
  262. package/build/utils/interactivity/utils.js +0 -87
  263. package/build/utils/interactivity/utils.js.map +0 -1
  264. package/build/utils/interactivity/vdom.js +0 -119
  265. package/build/utils/interactivity/vdom.js.map +0 -1
  266. package/build-module/file/interactivity.js +0 -15
  267. package/build-module/file/interactivity.js.map +0 -1
  268. package/build-module/heading/heading-level-icon.js +0 -53
  269. package/build-module/heading/heading-level-icon.js.map +0 -1
  270. package/build-module/image/interactivity.js.map +0 -1
  271. package/build-module/navigation/interactivity.js +0 -164
  272. package/build-module/navigation/interactivity.js.map +0 -1
  273. package/build-module/navigation/view-modal.js +0 -58
  274. package/build-module/navigation/view-modal.js.map +0 -1
  275. package/build-module/utils/interactivity/constants.js +0 -2
  276. package/build-module/utils/interactivity/constants.js.map +0 -1
  277. package/build-module/utils/interactivity/directives.js +0 -209
  278. package/build-module/utils/interactivity/directives.js.map +0 -1
  279. package/build-module/utils/interactivity/hooks.js +0 -145
  280. package/build-module/utils/interactivity/hooks.js.map +0 -1
  281. package/build-module/utils/interactivity/hydration.js +0 -21
  282. package/build-module/utils/interactivity/hydration.js.map +0 -1
  283. package/build-module/utils/interactivity/index.js +0 -15
  284. package/build-module/utils/interactivity/index.js.map +0 -1
  285. package/build-module/utils/interactivity/portals.js +0 -100
  286. package/build-module/utils/interactivity/portals.js.map +0 -1
  287. package/build-module/utils/interactivity/store.js +0 -55
  288. package/build-module/utils/interactivity/store.js.map +0 -1
  289. package/build-module/utils/interactivity/utils.js +0 -75
  290. package/build-module/utils/interactivity/utils.js.map +0 -1
  291. package/build-module/utils/interactivity/vdom.js +0 -107
  292. package/build-module/utils/interactivity/vdom.js.map +0 -1
  293. package/src/file/interactivity.js +0 -15
  294. package/src/heading/heading-level-icon.js +0 -48
  295. package/src/navigation/interactivity.js +0 -169
  296. package/src/navigation/view-modal.js +0 -78
  297. package/src/utils/interactivity/constants.js +0 -1
  298. package/src/utils/interactivity/directives.js +0 -200
  299. package/src/utils/interactivity/hooks.js +0 -145
  300. package/src/utils/interactivity/hydration.js +0 -22
  301. package/src/utils/interactivity/index.js +0 -15
  302. package/src/utils/interactivity/portals.js +0 -98
  303. package/src/utils/interactivity/store.js +0 -45
  304. package/src/utils/interactivity/utils.js +0 -66
  305. package/src/utils/interactivity/vdom.js +0 -111
@@ -607,7 +607,8 @@ export default function Image( {
607
607
  const ratio =
608
608
  ( aspectRatio && evalAspectRatio( aspectRatio ) ) ||
609
609
  ( width && height && width / height ) ||
610
- naturalWidth / naturalHeight;
610
+ naturalWidth / naturalHeight ||
611
+ 1;
611
612
 
612
613
  const currentWidth = ! width && height ? height * ratio : width;
613
614
  const currentHeight = ! height && width ? width / ratio : height;
package/src/image/save.js CHANGED
@@ -58,6 +58,8 @@ export default function save( { attributes } ) {
58
58
  ...borderProps.style,
59
59
  aspectRatio,
60
60
  objectFit: scale,
61
+ width,
62
+ height,
61
63
  } }
62
64
  width={ width }
63
65
  height={ height }
@@ -184,11 +184,12 @@
184
184
  width: 100vw;
185
185
  height: 100vh;
186
186
  visibility: hidden;
187
+ cursor: zoom-out;
187
188
 
188
189
  .close-button {
189
190
  position: absolute;
190
- top: 12.5px;
191
- right: 12.5px;
191
+ top: calc(env(safe-area-inset-top) + 12.5px);
192
+ right: calc(env(safe-area-inset-right) + 12.5px);
192
193
  padding: 0;
193
194
  cursor: pointer;
194
195
  z-index: 5000000;
@@ -231,6 +232,18 @@
231
232
  }
232
233
 
233
234
  &.fade {
235
+ .wp-block-image {
236
+ padding: 40px 0;
237
+
238
+ @media screen and (min-width: 480px) {
239
+ padding: 40px;
240
+ }
241
+
242
+ @media screen and (min-width: 1920px) {
243
+ padding: 40px 80px;
244
+ }
245
+ }
246
+
234
247
  &.active {
235
248
  visibility: visible;
236
249
  animation: both turn-on-visibility 0.25s;
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Internal dependencies
2
+ * WordPress dependencies
3
3
  */
4
- import { store } from '../utils/interactivity';
4
+ import { store } from '@wordpress/interactivity';
5
5
 
6
6
  const focusableSelectors = [
7
7
  'a[href]',
@@ -22,32 +22,43 @@ store( {
22
22
  core: {
23
23
  image: {
24
24
  showLightbox: ( { context, event } ) => {
25
+ // We can't initialize the lightbox until the reference
26
+ // image is loaded, otherwise the UX is broken.
27
+ if ( ! context.core.image.imageLoaded ) {
28
+ return;
29
+ }
25
30
  context.core.image.initialized = true;
26
31
  context.core.image.lastFocusedElement =
27
32
  window.document.activeElement;
28
33
  context.core.image.scrollDelta = 0;
29
34
 
35
+ context.core.image.lightboxEnabled = true;
36
+ if ( context.core.image.lightboxAnimation === 'zoom' ) {
37
+ setZoomStyles(
38
+ event.target.nextElementSibling,
39
+ context,
40
+ event
41
+ );
42
+ }
43
+ // Hide overflow only when the animation is in progress,
44
+ // otherwise the removal of the scrollbars will draw attention
45
+ // to itself and look like an error
46
+ document.documentElement.classList.add(
47
+ 'has-lightbox-open'
48
+ );
49
+
30
50
  // Since the img is hidden and its src not loaded until
31
51
  // the lightbox is opened, let's create an img element on the fly
32
52
  // so we can get the dimensions we need to calculate the styles
53
+ context.core.image.preloadInitialized = true;
33
54
  const imgDom = document.createElement( 'img' );
34
-
35
55
  imgDom.onload = function () {
36
- // Enable the lightbox only after the image
37
- // is loaded to prevent flashing of unstyled content
38
- context.core.image.lightboxEnabled = true;
39
- if ( context.core.image.lightboxAnimation === 'zoom' ) {
40
- setZoomStyles( imgDom, context, event );
41
- }
42
-
43
- // Hide overflow only when the animation is in progress,
44
- // otherwise the removal of the scrollbars will draw attention
45
- // to itself and look like an error
46
- document.documentElement.classList.add(
47
- 'has-lightbox-open'
48
- );
56
+ context.core.image.activateLargeImage = true;
49
57
  };
50
- imgDom.setAttribute( 'src', context.core.image.imageSrc );
58
+ imgDom.setAttribute(
59
+ 'src',
60
+ context.core.image.imageUploadedSrc
61
+ );
51
62
  },
52
63
  hideLightbox: async ( { context, event } ) => {
53
64
  context.core.image.hideAnimationEnabled = true;
@@ -122,6 +133,16 @@ store( {
122
133
  }
123
134
  }
124
135
  },
136
+ preloadLightboxImage: ( { context } ) => {
137
+ if ( ! context.core.image.preloadInitialized ) {
138
+ context.core.image.preloadInitialized = true;
139
+ const imgDom = document.createElement( 'img' );
140
+ imgDom.setAttribute(
141
+ 'src',
142
+ context.core.image.imageUploadedSrc
143
+ );
144
+ }
145
+ },
125
146
  },
126
147
  },
127
148
  },
@@ -131,9 +152,15 @@ store( {
131
152
  roleAttribute: ( { context } ) => {
132
153
  return context.core.image.lightboxEnabled ? 'dialog' : '';
133
154
  },
134
- imageSrc: ( { context } ) => {
155
+ responsiveImgSrc: ( { context } ) => {
156
+ return context.core.image.activateLargeImage &&
157
+ context.core.image.hideAnimationEnabled
158
+ ? ''
159
+ : context.core.image.imageCurrentSrc;
160
+ },
161
+ enlargedImgSrc: ( { context } ) => {
135
162
  return context.core.image.initialized
136
- ? context.core.image.imageSrc
163
+ ? context.core.image.imageUploadedSrc
137
164
  : '';
138
165
  },
139
166
  },
@@ -142,6 +169,18 @@ store( {
142
169
  effects: {
143
170
  core: {
144
171
  image: {
172
+ setCurrentSrc: ( { context, ref } ) => {
173
+ if ( ref.complete ) {
174
+ context.core.image.imageLoaded = true;
175
+ context.core.image.imageCurrentSrc = ref.currentSrc;
176
+ } else {
177
+ ref.addEventListener( 'load', function () {
178
+ context.core.image.imageLoaded = true;
179
+ context.core.image.imageCurrentSrc =
180
+ this.currentSrc;
181
+ } );
182
+ }
183
+ },
145
184
  initLightbox: async ( { context, ref } ) => {
146
185
  context.core.image.figureRef =
147
186
  ref.querySelector( 'figure' );
@@ -163,51 +202,61 @@ store( {
163
202
  } );
164
203
 
165
204
  function setZoomStyles( imgDom, context, event ) {
166
- let targetWidth = imgDom.naturalWidth;
167
- let targetHeight = imgDom.naturalHeight;
205
+ // Typically, we use the image's full-sized dimensions. If those
206
+ // dimensions have not been set (i.e. an external image with only one size),
207
+ // the image's dimensions in the lightbox are the same
208
+ // as those of the image in the content.
209
+ let targetWidth =
210
+ context.core.image.targetWidth !== 'none'
211
+ ? context.core.image.targetWidth
212
+ : event.target.nextElementSibling.naturalWidth;
213
+ let targetHeight =
214
+ context.core.image.targetHeight !== 'none'
215
+ ? context.core.image.targetHeight
216
+ : event.target.nextElementSibling.naturalHeight;
168
217
 
169
- const verticalPadding = 40;
218
+ // Since the lightbox image has `position:absolute`, it
219
+ // ignores its parent's padding, so we need to set padding here
220
+ // to calculate dimensions and positioning.
170
221
 
171
- // As per the design, let's allow the image to stretch
172
- // to the full width of its containing figure, but for the height,
173
- // constrain it with a fixed padding
174
- const containerWidth = context.core.image.figureRef.clientWidth;
222
+ // As per the design, let's constrain the height with fixed padding
223
+ const containerOuterHeight = window.innerHeight;
224
+ const verticalPadding = 40;
225
+ const containerInnerHeight = containerOuterHeight - verticalPadding * 2;
175
226
 
176
- // The lightbox image has `positione:absolute` and
177
- // ignores its parent's padding, so let's set the padding here,
178
- // to be used when calculating the image width and positioning
227
+ // Let's set a variable horizontal padding based on the container width
228
+ const containerOuterWidth = window.innerWidth;
179
229
  let horizontalPadding = 0;
180
- if ( containerWidth > 480 ) {
230
+ if ( containerOuterWidth > 480 ) {
181
231
  horizontalPadding = 40;
182
- } else if ( containerWidth > 1920 ) {
232
+ } else if ( containerOuterWidth > 1920 ) {
183
233
  horizontalPadding = 80;
184
234
  }
185
-
186
- const containerHeight =
187
- context.core.image.figureRef.clientHeight - verticalPadding * 2;
235
+ const containerInnerWidth = containerOuterWidth - horizontalPadding * 2;
188
236
 
189
237
  // Check difference between the image and figure dimensions
190
238
  const widthOverflow = Math.abs(
191
- Math.min( containerWidth - targetWidth, 0 )
239
+ Math.min( containerInnerWidth - targetWidth, 0 )
192
240
  );
193
241
  const heightOverflow = Math.abs(
194
- Math.min( containerHeight - targetHeight, 0 )
242
+ Math.min( containerInnerHeight - targetHeight, 0 )
195
243
  );
196
244
 
197
- // If image is larger than its container any dimension, resize along its largest axis.
198
- // For vertically oriented devices, always maximize the width.
245
+ // If the image is larger than the container, let's resize
246
+ // it along the greater axis relative to the container
199
247
  if ( widthOverflow > 0 || heightOverflow > 0 ) {
200
- if (
201
- widthOverflow >= heightOverflow ||
202
- containerHeight >= containerWidth
203
- ) {
204
- targetWidth = containerWidth - horizontalPadding * 2;
248
+ const containerInnerAspectRatio =
249
+ containerInnerWidth / containerInnerHeight;
250
+ const imageAspectRatio = targetWidth / targetHeight;
251
+
252
+ if ( imageAspectRatio > containerInnerAspectRatio ) {
253
+ targetWidth = containerInnerWidth;
205
254
  targetHeight =
206
- imgDom.naturalHeight * ( targetWidth / imgDom.naturalWidth );
255
+ ( targetWidth * imgDom.naturalHeight ) / imgDom.naturalWidth;
207
256
  } else {
208
- targetHeight = containerHeight;
257
+ targetHeight = containerInnerHeight;
209
258
  targetWidth =
210
- imgDom.naturalWidth * ( targetHeight / imgDom.naturalHeight );
259
+ ( targetHeight * imgDom.naturalWidth ) / imgDom.naturalHeight;
211
260
  }
212
261
  }
213
262
 
@@ -221,16 +270,16 @@ function setZoomStyles( imgDom, context, event ) {
221
270
 
222
271
  // Get values used to center the image
223
272
  let targetLeft = 0;
224
- if ( targetWidth >= containerWidth ) {
273
+ if ( targetWidth >= containerInnerWidth ) {
225
274
  targetLeft = horizontalPadding;
226
275
  } else {
227
- targetLeft = ( containerWidth - targetWidth ) / 2;
276
+ targetLeft = ( containerOuterWidth - targetWidth ) / 2;
228
277
  }
229
278
  let targetTop = 0;
230
- if ( targetHeight >= containerHeight ) {
279
+ if ( targetHeight >= containerInnerHeight ) {
231
280
  targetTop = verticalPadding;
232
281
  } else {
233
- targetTop = ( containerHeight - targetHeight ) / 2 + verticalPadding;
282
+ targetTop = ( containerOuterHeight - targetHeight ) / 2;
234
283
  }
235
284
 
236
285
  const root = document.documentElement;
package/src/index.js CHANGED
@@ -142,7 +142,6 @@ const getAllBlocks = () => {
142
142
  buttons,
143
143
  calendar,
144
144
  categories,
145
- ...( window.wp && window.wp.oldEditor ? [ classic ] : [] ), // Only add the classic block in WP Context.
146
145
  code,
147
146
  column,
148
147
  columns,
@@ -229,6 +228,24 @@ const getAllBlocks = () => {
229
228
  queryTitle,
230
229
  postAuthorBiography,
231
230
  ];
231
+
232
+ // When in a WordPress context, conditionally
233
+ // add the classic block and TinyMCE editor
234
+ // under any of the following conditions:
235
+ // - the current post contains a classic block
236
+ // - the experiment to disable TinyMCE isn't active.
237
+ // - a query argument specifies that TinyMCE should be loaded
238
+ if (
239
+ window?.wp?.oldEditor &&
240
+ ( window?.wp?.needsClassicBlock ||
241
+ ! window?.__experimentalDisableTinymce ||
242
+ !! new URLSearchParams( window?.location?.search ).get(
243
+ 'requiresTinymce'
244
+ ) )
245
+ ) {
246
+ blocks.push( classic );
247
+ }
248
+
232
249
  return blocks.filter( Boolean );
233
250
  };
234
251
 
@@ -61,7 +61,11 @@
61
61
  },
62
62
  "spacing": {
63
63
  "margin": true,
64
- "padding": true
64
+ "padding": true,
65
+ "__experimentalDefaultControls": {
66
+ "margin": false,
67
+ "padding": false
68
+ }
65
69
  },
66
70
  "__unstablePasteTextInline": true,
67
71
  "__experimentalSelector": "ol,ul",
@@ -100,6 +100,7 @@
100
100
  "html": false,
101
101
  "color": {
102
102
  "gradients": true,
103
+ "heading": true,
103
104
  "link": true,
104
105
  "__experimentalDefaultControls": {
105
106
  "background": true,
@@ -16,22 +16,46 @@ import { safeHTML } from '@wordpress/dom';
16
16
  function MissingBlockWarning( { attributes, convertToHTML, clientId } ) {
17
17
  const { originalName, originalUndelimitedContent } = attributes;
18
18
  const hasContent = !! originalUndelimitedContent;
19
- const hasHTMLBlock = useSelect(
19
+ const { hasFreeformBlock, hasHTMLBlock } = useSelect(
20
20
  ( select ) => {
21
21
  const { canInsertBlockType, getBlockRootClientId } =
22
22
  select( blockEditorStore );
23
23
 
24
- return canInsertBlockType(
25
- 'core/html',
26
- getBlockRootClientId( clientId )
27
- );
24
+ return {
25
+ hasFreeformBlock: canInsertBlockType(
26
+ 'core/freeform',
27
+ getBlockRootClientId( clientId )
28
+ ),
29
+ hasHTMLBlock: canInsertBlockType(
30
+ 'core/html',
31
+ getBlockRootClientId( clientId )
32
+ ),
33
+ };
28
34
  },
29
35
  [ clientId ]
30
36
  );
31
37
 
32
38
  const actions = [];
33
39
  let messageHTML;
34
- if ( hasContent && hasHTMLBlock ) {
40
+
41
+ const convertToHtmlButton = (
42
+ <Button key="convert" onClick={ convertToHTML } variant="primary">
43
+ { __( 'Keep as HTML' ) }
44
+ </Button>
45
+ );
46
+
47
+ if ( hasContent && ! hasFreeformBlock && ! originalName ) {
48
+ if ( hasHTMLBlock ) {
49
+ messageHTML = __(
50
+ 'It appears you are trying to use the deprecated Classic block. You can leave this block intact, convert its content to a Custom HTML block, or remove it entirely. Alternatively, you can refresh the page to use the Classic block.'
51
+ );
52
+ actions.push( convertToHtmlButton );
53
+ } else {
54
+ messageHTML = __(
55
+ 'It appears you are trying to use the deprecated Classic block. You can leave this block intact, or remove it entirely. Alternatively, you can refresh the page to use the Classic block.'
56
+ );
57
+ }
58
+ } else if ( hasContent && hasHTMLBlock ) {
35
59
  messageHTML = sprintf(
36
60
  /* translators: %s: block name */
37
61
  __(
@@ -39,11 +63,7 @@ function MissingBlockWarning( { attributes, convertToHTML, clientId } ) {
39
63
  ),
40
64
  originalName
41
65
  );
42
- actions.push(
43
- <Button key="convert" onClick={ convertToHTML } variant="primary">
44
- { __( 'Keep as HTML' ) }
45
- </Button>
46
- );
66
+ actions.push( convertToHtmlButton );
47
67
  } else {
48
68
  messageHTML = sprintf(
49
69
  /* translators: %s: block name */
@@ -131,9 +131,10 @@
131
131
  }
132
132
  }
133
133
  }
134
- }
134
+ },
135
+ "interactivity": true
135
136
  },
136
- "viewScript": [ "file:./view.min.js", "file:./view-modal.min.js" ],
137
+ "viewScript": "file:./view.min.js",
137
138
  "editorStyle": "wp-block-navigation-editor",
138
139
  "style": "wp-block-navigation"
139
140
  }
@@ -103,7 +103,7 @@ if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) {
103
103
  ) ) {
104
104
  // Add directives to the parent `<li>`.
105
105
  $w->set_attribute( 'data-wp-interactive', true );
106
- $w->set_attribute( 'data-wp-context', '{ "core": { "navigation": { "isMenuOpen": { "click": false, "hover": false }, "overlay": false } } }' );
106
+ $w->set_attribute( 'data-wp-context', '{ "core": { "navigation": { "submenuOpenedBy": {}, "type": "submenu" } } }' );
107
107
  $w->set_attribute( 'data-wp-effect', 'effects.core.navigation.initMenu' );
108
108
  $w->set_attribute( 'data-wp-on--focusout', 'actions.core.navigation.handleMenuFocusout' );
109
109
  $w->set_attribute( 'data-wp-on--keydown', 'actions.core.navigation.handleMenuKeydown' );
@@ -123,26 +123,21 @@ if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) {
123
123
  $w->set_attribute( 'data-wp-bind--aria-expanded', 'selectors.core.navigation.isMenuOpen' );
124
124
  };
125
125
 
126
+ // Add directives to the submenu.
127
+ if ( $w->next_tag(
128
+ array(
129
+ 'tag_name' => 'UL',
130
+ 'class_name' => 'wp-block-navigation__submenu-container',
131
+ )
132
+ ) ) {
133
+ $w->set_attribute( 'data-wp-on--focusin', 'actions.core.navigation.openMenuOnFocus' );
134
+ }
135
+
126
136
  // Iterate through subitems if exist.
127
137
  block_core_navigation_add_directives_to_submenu( $w, $block_attributes );
128
138
  }
129
139
  return $w->get_updated_html();
130
140
  };
131
-
132
- /**
133
- * Replaces view script for the Navigation block with version using Interactivity API.
134
- *
135
- * @param array $metadata Block metadata as read in via block.json.
136
- *
137
- * @return array Filtered block type metadata.
138
- */
139
- function gutenberg_block_core_navigation_update_interactive_view_script( $metadata ) {
140
- if ( 'core/navigation' === $metadata['name'] ) {
141
- $metadata['viewScript'] = array( 'file:./interactivity.min.js' );
142
- }
143
- return $metadata;
144
- }
145
- add_filter( 'block_type_metadata', 'gutenberg_block_core_navigation_update_interactive_view_script', 10, 1 );
146
141
  }
147
142
 
148
143
 
@@ -726,7 +721,7 @@ function render_block_core_navigation( $attributes, $content, $block ) {
726
721
  if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN && $should_load_view_script ) {
727
722
  $nav_element_directives = '
728
723
  data-wp-interactive
729
- data-wp-context=\'{ "core": { "navigation": { "isMenuOpen": { "click": false, "hover": false }, "overlay": true, "roleAttribute": "" } } }\'
724
+ data-wp-context=\'{ "core": { "navigation": { "overlayOpenedBy": {}, "type": "overlay", "roleAttribute": "" } } }\'
730
725
  ';
731
726
  $open_button_directives = '
732
727
  data-wp-on--click="actions.core.navigation.openMenuOnClick"
@@ -751,11 +746,11 @@ function render_block_core_navigation( $attributes, $content, $block ) {
751
746
  }
752
747
 
753
748
  $responsive_container_markup = sprintf(
754
- '<button aria-haspopup="true" %3$s class="%6$s" data-micromodal-trigger="%1$s" %11$s>%9$s</button>
749
+ '<button aria-haspopup="true" %3$s class="%6$s" %11$s>%9$s</button>
755
750
  <div class="%5$s" style="%7$s" id="%1$s" %12$s>
756
- <div class="wp-block-navigation__responsive-close" tabindex="-1" data-micromodal-close>
751
+ <div class="wp-block-navigation__responsive-close" tabindex="-1">
757
752
  <div class="wp-block-navigation__responsive-dialog" aria-label="%8$s" %13$s>
758
- <button %4$s data-micromodal-close class="wp-block-navigation__responsive-container-close" %14$s>%10$s</button>
753
+ <button %4$s class="wp-block-navigation__responsive-container-close" %14$s>%10$s</button>
759
754
  <div class="wp-block-navigation__responsive-container-content" id="%1$s-content">
760
755
  %2$s
761
756
  </div>