@wordpress/block-editor 14.7.0 → 14.7.1-next.082ed6819.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 (190) hide show
  1. package/build/components/block-controls/slot.js +6 -3
  2. package/build/components/block-controls/slot.js.map +1 -1
  3. package/build/components/block-inspector/index.js +1 -2
  4. package/build/components/block-inspector/index.js.map +1 -1
  5. package/build/components/block-lock/modal.js +1 -1
  6. package/build/components/block-lock/modal.js.map +1 -1
  7. package/build/components/block-manager/category.js +79 -0
  8. package/build/components/block-manager/category.js.map +1 -0
  9. package/build/components/block-manager/checklist.js +40 -0
  10. package/build/components/block-manager/checklist.js.map +1 -0
  11. package/build/components/block-manager/index.js +108 -0
  12. package/build/components/block-manager/index.js.map +1 -0
  13. package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  14. package/build/components/block-settings-menu/index.js.map +1 -1
  15. package/build/components/block-toolbar/index.js +7 -2
  16. package/build/components/block-toolbar/index.js.map +1 -1
  17. package/build/components/block-toolbar/switch-section-style.js +105 -0
  18. package/build/components/block-toolbar/switch-section-style.js.map +1 -0
  19. package/build/components/collab/block-comment-icon-slot.js +2 -6
  20. package/build/components/collab/block-comment-icon-slot.js.map +1 -1
  21. package/build/components/collab/block-comment-icon-toolbar-slot.js +2 -6
  22. package/build/components/collab/block-comment-icon-toolbar-slot.js.map +1 -1
  23. package/build/components/color-palette/with-color-context.js +4 -2
  24. package/build/components/color-palette/with-color-context.js.map +1 -1
  25. package/build/components/font-family/index.js +14 -13
  26. package/build/components/font-family/index.js.map +1 -1
  27. package/build/components/global-styles/use-global-styles-output.js +1 -1
  28. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  29. package/build/components/iframe/index.js +140 -23
  30. package/build/components/iframe/index.js.map +1 -1
  31. package/build/components/inserter/block-patterns-tab/pattern-category-previews.js +1 -5
  32. package/build/components/inserter/block-patterns-tab/pattern-category-previews.js.map +1 -1
  33. package/build/components/inserter/category-tabs/index.js +7 -8
  34. package/build/components/inserter/category-tabs/index.js.map +1 -1
  35. package/build/components/inserter-draggable-blocks/index.js +2 -1
  36. package/build/components/inserter-draggable-blocks/index.js.map +1 -1
  37. package/build/components/inspector-controls/slot.js +7 -4
  38. package/build/components/inspector-controls/slot.js.map +1 -1
  39. package/build/components/inspector-controls-tabs/position-controls-panel.js +1 -1
  40. package/build/components/inspector-controls-tabs/position-controls-panel.js.map +1 -1
  41. package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js +4 -4
  42. package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +1 -1
  43. package/build/components/media-placeholder/index.js +29 -21
  44. package/build/components/media-placeholder/index.js.map +1 -1
  45. package/build/hooks/border.js +3 -3
  46. package/build/hooks/border.js.map +1 -1
  47. package/build/hooks/color.js +1 -1
  48. package/build/hooks/color.js.map +1 -1
  49. package/build/hooks/dimensions.js +2 -2
  50. package/build/hooks/dimensions.js.map +1 -1
  51. package/build/hooks/style.js +6 -6
  52. package/build/hooks/style.js.map +1 -1
  53. package/build/hooks/supports.js +1 -1
  54. package/build/hooks/supports.js.map +1 -1
  55. package/build/hooks/typography.js +1 -1
  56. package/build/hooks/typography.js.map +1 -1
  57. package/build/hooks/utils.js +1 -1
  58. package/build/hooks/utils.js.map +1 -1
  59. package/build/layouts/flex.js +11 -9
  60. package/build/layouts/flex.js.map +1 -1
  61. package/build/private-apis.js +4 -4
  62. package/build/private-apis.js.map +1 -1
  63. package/build/store/private-selectors.js +1 -1
  64. package/build/store/private-selectors.js.map +1 -1
  65. package/build/store/selectors.js +3 -0
  66. package/build/store/selectors.js.map +1 -1
  67. package/build-module/components/block-controls/slot.js +6 -3
  68. package/build-module/components/block-controls/slot.js.map +1 -1
  69. package/build-module/components/block-inspector/index.js +1 -2
  70. package/build-module/components/block-inspector/index.js.map +1 -1
  71. package/build-module/components/block-lock/modal.js +1 -1
  72. package/build-module/components/block-lock/modal.js.map +1 -1
  73. package/build-module/components/block-manager/category.js +71 -0
  74. package/build-module/components/block-manager/category.js.map +1 -0
  75. package/build-module/components/block-manager/checklist.js +32 -0
  76. package/build-module/components/block-manager/checklist.js.map +1 -0
  77. package/build-module/components/block-manager/index.js +102 -0
  78. package/build-module/components/block-manager/index.js.map +1 -0
  79. package/build-module/components/block-settings-menu/block-settings-dropdown.js +2 -2
  80. package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  81. package/build-module/components/block-settings-menu/index.js +2 -2
  82. package/build-module/components/block-settings-menu/index.js.map +1 -1
  83. package/build-module/components/block-toolbar/index.js +7 -2
  84. package/build-module/components/block-toolbar/index.js.map +1 -1
  85. package/build-module/components/block-toolbar/switch-section-style.js +97 -0
  86. package/build-module/components/block-toolbar/switch-section-style.js.map +1 -0
  87. package/build-module/components/collab/block-comment-icon-slot.js +2 -6
  88. package/build-module/components/collab/block-comment-icon-slot.js.map +1 -1
  89. package/build-module/components/collab/block-comment-icon-toolbar-slot.js +2 -6
  90. package/build-module/components/collab/block-comment-icon-toolbar-slot.js.map +1 -1
  91. package/build-module/components/color-palette/with-color-context.js +4 -2
  92. package/build-module/components/color-palette/with-color-context.js.map +1 -1
  93. package/build-module/components/font-family/index.js +15 -14
  94. package/build-module/components/font-family/index.js.map +1 -1
  95. package/build-module/components/global-styles/use-global-styles-output.js +1 -1
  96. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  97. package/build-module/components/iframe/index.js +141 -24
  98. package/build-module/components/iframe/index.js.map +1 -1
  99. package/build-module/components/inserter/block-patterns-tab/pattern-category-previews.js +1 -5
  100. package/build-module/components/inserter/block-patterns-tab/pattern-category-previews.js.map +1 -1
  101. package/build-module/components/inserter/category-tabs/index.js +8 -9
  102. package/build-module/components/inserter/category-tabs/index.js.map +1 -1
  103. package/build-module/components/inserter-draggable-blocks/index.js +2 -1
  104. package/build-module/components/inserter-draggable-blocks/index.js.map +1 -1
  105. package/build-module/components/inspector-controls/slot.js +7 -4
  106. package/build-module/components/inspector-controls/slot.js.map +1 -1
  107. package/build-module/components/inspector-controls-tabs/position-controls-panel.js +1 -1
  108. package/build-module/components/inspector-controls-tabs/position-controls-panel.js.map +1 -1
  109. package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js +4 -4
  110. package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +1 -1
  111. package/build-module/components/media-placeholder/index.js +29 -21
  112. package/build-module/components/media-placeholder/index.js.map +1 -1
  113. package/build-module/hooks/border.js +3 -3
  114. package/build-module/hooks/border.js.map +1 -1
  115. package/build-module/hooks/color.js +1 -1
  116. package/build-module/hooks/color.js.map +1 -1
  117. package/build-module/hooks/dimensions.js +2 -2
  118. package/build-module/hooks/dimensions.js.map +1 -1
  119. package/build-module/hooks/style.js +6 -6
  120. package/build-module/hooks/style.js.map +1 -1
  121. package/build-module/hooks/supports.js +1 -1
  122. package/build-module/hooks/supports.js.map +1 -1
  123. package/build-module/hooks/typography.js +1 -1
  124. package/build-module/hooks/typography.js.map +1 -1
  125. package/build-module/hooks/utils.js +1 -1
  126. package/build-module/hooks/utils.js.map +1 -1
  127. package/build-module/layouts/flex.js +11 -9
  128. package/build-module/layouts/flex.js.map +1 -1
  129. package/build-module/private-apis.js +6 -6
  130. package/build-module/private-apis.js.map +1 -1
  131. package/build-module/store/private-selectors.js +1 -1
  132. package/build-module/store/private-selectors.js.map +1 -1
  133. package/build-module/store/selectors.js +3 -0
  134. package/build-module/store/selectors.js.map +1 -1
  135. package/build-style/content-rtl.css +23 -9
  136. package/build-style/content.css +23 -9
  137. package/build-style/style-rtl.css +78 -0
  138. package/build-style/style.css +78 -0
  139. package/package.json +31 -31
  140. package/src/components/block-controls/slot.js +5 -3
  141. package/src/components/block-inspector/index.js +0 -2
  142. package/src/components/block-lock/modal.js +1 -1
  143. package/src/components/block-manager/category.js +102 -0
  144. package/src/components/block-manager/checklist.js +34 -0
  145. package/src/components/block-manager/index.js +127 -0
  146. package/src/components/block-manager/style.scss +82 -0
  147. package/src/components/block-mover/README.md +15 -8
  148. package/src/components/block-mover/stories/index.story.js +73 -71
  149. package/src/components/block-mover/style.scss +3 -0
  150. package/src/components/block-settings-menu/block-settings-dropdown.js +2 -2
  151. package/src/components/block-settings-menu/index.js +2 -2
  152. package/src/components/block-toolbar/index.js +6 -0
  153. package/src/components/block-toolbar/switch-section-style.js +115 -0
  154. package/src/components/collab/block-comment-icon-slot.js +2 -6
  155. package/src/components/collab/block-comment-icon-toolbar-slot.js +3 -5
  156. package/src/components/color-palette/with-color-context.js +25 -7
  157. package/src/components/font-family/index.js +13 -13
  158. package/src/components/global-styles/test/use-global-styles-output.js +1 -1
  159. package/src/components/global-styles/use-global-styles-output.js +1 -1
  160. package/src/components/iframe/content.scss +16 -3
  161. package/src/components/iframe/index.js +187 -44
  162. package/src/components/inserter/block-patterns-tab/pattern-category-previews.js +7 -16
  163. package/src/components/inserter/category-tabs/index.js +8 -9
  164. package/src/components/inserter-draggable-blocks/index.js +10 -1
  165. package/src/components/inspector-controls/README.md +2 -0
  166. package/src/components/inspector-controls/slot.js +6 -4
  167. package/src/components/inspector-controls-tabs/position-controls-panel.js +1 -3
  168. package/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js +10 -10
  169. package/src/components/media-placeholder/index.js +37 -33
  170. package/src/components/provider/test/use-block-sync.js +3 -1
  171. package/src/components/rich-text/content.scss +15 -10
  172. package/src/hooks/border.js +3 -9
  173. package/src/hooks/color.js +1 -1
  174. package/src/hooks/dimensions.js +2 -2
  175. package/src/hooks/style.js +6 -12
  176. package/src/hooks/supports.js +1 -1
  177. package/src/hooks/test/style.js +1 -2
  178. package/src/hooks/typography.js +1 -1
  179. package/src/hooks/utils.js +1 -1
  180. package/src/layouts/flex.js +26 -18
  181. package/src/private-apis.js +6 -6
  182. package/src/store/private-selectors.js +1 -1
  183. package/src/store/selectors.js +3 -0
  184. package/src/store/test/selectors.js +87 -58
  185. package/src/style.scss +1 -0
  186. package/build/components/block-info-slot-fill/index.js +0 -39
  187. package/build/components/block-info-slot-fill/index.js.map +0 -1
  188. package/build-module/components/block-info-slot-fill/index.js +0 -32
  189. package/build-module/components/block-info-slot-fill/index.js.map +0 -1
  190. package/src/components/block-info-slot-fill/index.js +0 -27
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { SelectControl } from '@wordpress/components';
4
+ import { CustomSelectControl } from '@wordpress/components';
5
5
  import deprecated from '@wordpress/deprecated';
6
6
  import { __ } from '@wordpress/i18n';
7
7
 
@@ -30,13 +30,15 @@ export default function FontFamilyControl( {
30
30
  }
31
31
 
32
32
  const options = [
33
- { value: '', label: __( 'Default' ) },
34
- ...fontFamilies.map( ( { fontFamily, name } ) => {
35
- return {
36
- value: fontFamily,
37
- label: name || fontFamily,
38
- };
39
- } ),
33
+ {
34
+ key: '',
35
+ name: __( 'Default' ),
36
+ },
37
+ ...fontFamilies.map( ( { fontFamily, name } ) => ( {
38
+ key: fontFamily,
39
+ name: name || fontFamily,
40
+ style: { fontFamily },
41
+ } ) ),
40
42
  ];
41
43
 
42
44
  if ( ! __nextHasNoMarginBottom ) {
@@ -51,14 +53,12 @@ export default function FontFamilyControl( {
51
53
  }
52
54
 
53
55
  return (
54
- <SelectControl
56
+ <CustomSelectControl
55
57
  __next40pxDefaultSize={ __next40pxDefaultSize }
56
- __nextHasNoMarginBottom={ __nextHasNoMarginBottom }
57
58
  label={ __( 'Font' ) }
58
- options={ options }
59
59
  value={ value }
60
- onChange={ onChange }
61
- labelPosition="top"
60
+ onChange={ ( { selectedItem } ) => onChange( selectedItem.key ) }
61
+ options={ options }
62
62
  { ...props }
63
63
  />
64
64
  );
@@ -855,7 +855,7 @@ describe( 'global styles renderer', () => {
855
855
 
856
856
  it( 'should return block selectors data with old experimental selectors', () => {
857
857
  const imageSupports = {
858
- __experimentalBorder: {
858
+ border: {
859
859
  radius: true,
860
860
  __experimentalSelector: 'img, .crop-area',
861
861
  },
@@ -47,7 +47,7 @@ const ELEMENT_CLASS_NAMES = {
47
47
  // List of block support features that can have their related styles
48
48
  // generated under their own feature level selector rather than the block's.
49
49
  const BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS = {
50
- __experimentalBorder: 'border',
50
+ border: 'border',
51
51
  color: 'color',
52
52
  spacing: 'spacing',
53
53
  typography: 'typography',
@@ -7,13 +7,26 @@
7
7
  // We don't want to animate the transform of the translateX because it is used
8
8
  // to "center" the canvas. Leaving it on causes the canvas to slide around in
9
9
  // odd ways.
10
- @include editor-canvas-resize-animation(transform 0s, scale 0s, padding 0s);
10
+ @include editor-canvas-resize-animation( transform 0s, scale 0s, padding 0s, translate 0s);
11
11
 
12
12
  &.zoom-out-animation {
13
- // we only want to animate the scaling when entering zoom out. When sidebars
13
+ $scroll-top: var(--wp-block-editor-iframe-zoom-out-scroll-top, 0);
14
+ $scroll-top-next: var(--wp-block-editor-iframe-zoom-out-scroll-top-next, 0);
15
+
16
+ position: fixed;
17
+ left: 0;
18
+ right: 0;
19
+ top: calc(-1 * #{$scroll-top});
20
+ bottom: 0;
21
+ translate: 0 calc(#{$scroll-top} - #{$scroll-top-next});
22
+ // Force preserving a scrollbar gutter as scrollbar-gutter isn't supported in all browsers yet,
23
+ // and removing the scrollbar causes the content to shift.
24
+ overflow-y: scroll;
25
+
26
+ // We only want to animate the scaling when entering zoom out. When sidebars
14
27
  // are toggled, the resizing of the iframe handles scaling the canvas as well,
15
28
  // and the doubled animations cause very odd animations.
16
- @include editor-canvas-resize-animation(transform 0s);
29
+ @include editor-canvas-resize-animation( transform 0s, top 0s, bottom 0s, right 0s, left 0s );
17
30
  }
18
31
  }
19
32
 
@@ -20,6 +20,7 @@ import {
20
20
  useMergeRefs,
21
21
  useRefEffect,
22
22
  useDisabled,
23
+ useReducedMotion,
23
24
  } from '@wordpress/compose';
24
25
  import { __experimentalStyleProvider as StyleProvider } from '@wordpress/components';
25
26
  import { useSelect } from '@wordpress/data';
@@ -121,6 +122,7 @@ function Iframe( {
121
122
  };
122
123
  }, [] );
123
124
  const { styles = '', scripts = '' } = resolvedAssets;
125
+ /** @type {[Document, import('react').Dispatch<Document>]} */
124
126
  const [ iframeDocument, setIframeDocument ] = useState();
125
127
  const initialContainerWidthRef = useRef( 0 );
126
128
  const [ bodyClasses, setBodyClasses ] = useState( [] );
@@ -130,6 +132,7 @@ function Iframe( {
130
132
  useResizeObserver();
131
133
  const [ containerResizeListener, { width: containerWidth } ] =
132
134
  useResizeObserver();
135
+ const prefersReducedMotion = useReducedMotion();
133
136
 
134
137
  const setRef = useRefEffect( ( node ) => {
135
138
  node._load = () => {
@@ -268,6 +271,19 @@ function Iframe( {
268
271
  containerWidth
269
272
  );
270
273
 
274
+ const frameSizeValue = parseInt( frameSize );
275
+
276
+ const maxWidth = 750;
277
+ const scaleValue =
278
+ scale === 'auto-scaled'
279
+ ? ( Math.min( containerWidth, maxWidth ) - frameSizeValue * 2 ) /
280
+ scaleContainerWidth
281
+ : scale;
282
+
283
+ const prevScaleRef = useRef( scaleValue );
284
+ const prevFrameSizeRef = useRef( frameSizeValue );
285
+ const prevClientHeightRef = useRef( /* Initialized in the useEffect. */ );
286
+
271
287
  const disabledRef = useDisabled( { isDisabled: ! readonly } );
272
288
  const bodyRef = useMergeRefs( [
273
289
  useBubbleEvents( iframeDocument ),
@@ -320,47 +336,176 @@ function Iframe( {
320
336
 
321
337
  useEffect( () => cleanup, [ cleanup ] );
322
338
 
323
- const zoomOutAnimationClassnameRef = useRef( null );
324
-
325
- // Toggle zoom out CSS Classes only when zoom out mode changes. We could add these into the useEffect
326
- // that controls settings the CSS variables, but then we would need to do more work to ensure we're
327
- // only toggling these when the zoom out mode changes, as that useEffect is also triggered by a large
328
- // number of dependencies.
329
339
  useEffect( () => {
330
- if ( ! iframeDocument || ! isZoomedOut ) {
340
+ if (
341
+ ! iframeDocument ||
342
+ // HACK: Checking if isZoomedOut differs from prevIsZoomedOut here
343
+ // instead of the dependency array to appease the linter.
344
+ ( scaleValue === 1 ) === ( prevScaleRef.current === 1 )
345
+ ) {
331
346
  return;
332
347
  }
333
348
 
334
- const handleZoomOutAnimationClassname = () => {
335
- clearTimeout( zoomOutAnimationClassnameRef.current );
349
+ // Unscaled height of the current iframe container.
350
+ const clientHeight = iframeDocument.documentElement.clientHeight;
351
+
352
+ // Scaled height of the current iframe content.
353
+ const scrollHeight = iframeDocument.documentElement.scrollHeight;
354
+
355
+ // Previous scale value.
356
+ const prevScale = prevScaleRef.current;
357
+
358
+ // Unscaled size of the previous padding around the iframe content.
359
+ const prevFrameSize = prevFrameSizeRef.current;
360
+
361
+ // Unscaled height of the previous iframe container.
362
+ const prevClientHeight = prevClientHeightRef.current ?? clientHeight;
363
+
364
+ // We can't trust the set value from contentHeight, as it was measured
365
+ // before the zoom out mode was changed. After zoom out mode is changed,
366
+ // appenders may appear or disappear, so we need to get the height from
367
+ // the iframe at this point when we're about to animate the zoom out.
368
+ // The iframe scrollTop, scrollHeight, and clientHeight will all be
369
+ // accurate. The client height also does change when the zoom out mode
370
+ // is toggled, as the bottom bar about selecting the template is
371
+ // added/removed when toggling zoom out mode.
372
+ const scrollTop = iframeDocument.documentElement.scrollTop;
373
+
374
+ // Step 0: Start with the current scrollTop.
375
+ let scrollTopNext = scrollTop;
376
+
377
+ // Step 1: Undo the effects of the previous scale and frame around the
378
+ // midpoint of the visible area.
379
+ scrollTopNext =
380
+ ( scrollTopNext + prevClientHeight / 2 - prevFrameSize ) /
381
+ prevScale -
382
+ prevClientHeight / 2;
383
+
384
+ // Step 2: Apply the new scale and frame around the midpoint of the
385
+ // visible area.
386
+ scrollTopNext =
387
+ ( scrollTopNext + clientHeight / 2 ) * scaleValue +
388
+ frameSizeValue -
389
+ clientHeight / 2;
390
+
391
+ // Step 3: Handle an edge case so that you scroll to the top of the
392
+ // iframe if the top of the iframe content is visible in the container.
393
+ // The same edge case for the bottom is skipped because changing content
394
+ // makes calculating it impossible.
395
+ scrollTopNext = scrollTop <= prevFrameSize ? 0 : scrollTopNext;
396
+
397
+ // This is the scrollTop value if you are scrolled to the bottom of the
398
+ // iframe. We can't just let the browser handle it because we need to
399
+ // animate the scaling.
400
+ const maxScrollTop =
401
+ scrollHeight * ( scaleValue / prevScale ) +
402
+ frameSizeValue * 2 -
403
+ clientHeight;
404
+
405
+ // Step 4: Clamp the scrollTopNext between the minimum and maximum
406
+ // possible scrollTop positions. Round the value to avoid subpixel
407
+ // truncation by the browser which sometimes causes a 1px error.
408
+ scrollTopNext = Math.round(
409
+ Math.min(
410
+ Math.max( 0, scrollTopNext ),
411
+ Math.max( 0, maxScrollTop )
412
+ )
413
+ );
336
414
 
337
- iframeDocument.documentElement.classList.add(
415
+ iframeDocument.documentElement.style.setProperty(
416
+ '--wp-block-editor-iframe-zoom-out-scroll-top',
417
+ `${ scrollTop }px`
418
+ );
419
+
420
+ iframeDocument.documentElement.style.setProperty(
421
+ '--wp-block-editor-iframe-zoom-out-scroll-top-next',
422
+ `${ scrollTopNext }px`
423
+ );
424
+
425
+ iframeDocument.documentElement.classList.add( 'zoom-out-animation' );
426
+
427
+ function onZoomOutTransitionEnd() {
428
+ // Remove the position fixed for the animation.
429
+ iframeDocument.documentElement.classList.remove(
338
430
  'zoom-out-animation'
339
431
  );
340
432
 
341
- zoomOutAnimationClassnameRef.current = setTimeout( () => {
342
- iframeDocument.documentElement.classList.remove(
343
- 'zoom-out-animation'
433
+ // Update previous values.
434
+ prevClientHeightRef.current = clientHeight;
435
+ prevFrameSizeRef.current = frameSizeValue;
436
+ prevScaleRef.current = scaleValue;
437
+
438
+ // Set the final scroll position that was just animated to.
439
+ // Disable reason: Eslint isn't smart enough to know that this is a
440
+ // DOM element. https://github.com/facebook/react/issues/31483
441
+ // eslint-disable-next-line react-compiler/react-compiler
442
+ iframeDocument.documentElement.scrollTop = scrollTopNext;
443
+ }
444
+
445
+ let raf;
446
+ if ( prefersReducedMotion ) {
447
+ // Hack: Wait for the window values to recalculate.
448
+ raf = iframeDocument.defaultView.requestAnimationFrame(
449
+ onZoomOutTransitionEnd
450
+ );
451
+ } else {
452
+ iframeDocument.documentElement.addEventListener(
453
+ 'transitionend',
454
+ onZoomOutTransitionEnd,
455
+ { once: true }
456
+ );
457
+ }
458
+
459
+ return () => {
460
+ iframeDocument.documentElement.style.removeProperty(
461
+ '--wp-block-editor-iframe-zoom-out-scroll-top'
462
+ );
463
+ iframeDocument.documentElement.style.removeProperty(
464
+ '--wp-block-editor-iframe-zoom-out-scroll-top-next'
465
+ );
466
+ iframeDocument.documentElement.classList.remove(
467
+ 'zoom-out-animation'
468
+ );
469
+ if ( prefersReducedMotion ) {
470
+ iframeDocument.defaultView.cancelAnimationFrame( raf );
471
+ } else {
472
+ iframeDocument.documentElement.removeEventListener(
473
+ 'transitionend',
474
+ onZoomOutTransitionEnd
344
475
  );
345
- }, 400 ); // 400ms should match the animation speed used in components/iframe/content.scss
476
+ }
346
477
  };
478
+ }, [ iframeDocument, scaleValue, frameSizeValue, prefersReducedMotion ] );
347
479
 
348
- handleZoomOutAnimationClassname();
349
- iframeDocument.documentElement.classList.add( 'is-zoomed-out' );
480
+ // Toggle zoom out CSS Classes only when zoom out mode changes. We could add these into the useEffect
481
+ // that controls settings the CSS variables, but then we would need to do more work to ensure we're
482
+ // only toggling these when the zoom out mode changes, as that useEffect is also triggered by a large
483
+ // number of dependencies.
484
+ useEffect( () => {
485
+ if ( ! iframeDocument ) {
486
+ return;
487
+ }
350
488
 
351
- return () => {
352
- handleZoomOutAnimationClassname();
489
+ if ( isZoomedOut ) {
490
+ iframeDocument.documentElement.classList.add( 'is-zoomed-out' );
491
+ } else {
492
+ // HACK: Since we can't remove this in the cleanup, we need to do it here.
353
493
  iframeDocument.documentElement.classList.remove( 'is-zoomed-out' );
494
+ }
495
+
496
+ return () => {
497
+ // HACK: Skipping cleanup because it causes issues with the zoom out
498
+ // animation. More refactoring is needed to fix this properly.
499
+ // iframeDocument.documentElement.classList.remove( 'is-zoomed-out' );
354
500
  };
355
501
  }, [ iframeDocument, isZoomedOut ] );
356
502
 
357
503
  // Calculate the scaling and CSS variables for the zoom out canvas
358
504
  useEffect( () => {
359
- if ( ! iframeDocument || ! isZoomedOut ) {
505
+ if ( ! iframeDocument ) {
360
506
  return;
361
507
  }
362
508
 
363
- const maxWidth = 750;
364
509
  // Note: When we initialize the zoom out when the canvas is smaller (sidebars open),
365
510
  // initialContainerWidthRef will be smaller than the full page, and reflow will happen
366
511
  // when the canvas area becomes larger due to sidebars closing. This is a known but
@@ -371,11 +516,7 @@ function Iframe( {
371
516
  // but calc( 100px / 2px ) is not.
372
517
  iframeDocument.documentElement.style.setProperty(
373
518
  '--wp-block-editor-iframe-zoom-out-scale',
374
- scale === 'auto-scaled'
375
- ? ( Math.min( containerWidth, maxWidth ) -
376
- parseInt( frameSize ) * 2 ) /
377
- scaleContainerWidth
378
- : scale
519
+ scaleValue
379
520
  );
380
521
 
381
522
  // frameSize has to be a px value for the scaling and frame size to be computed correctly.
@@ -401,27 +542,29 @@ function Iframe( {
401
542
  );
402
543
 
403
544
  return () => {
404
- iframeDocument.documentElement.style.removeProperty(
405
- '--wp-block-editor-iframe-zoom-out-scale'
406
- );
407
- iframeDocument.documentElement.style.removeProperty(
408
- '--wp-block-editor-iframe-zoom-out-frame-size'
409
- );
410
- iframeDocument.documentElement.style.removeProperty(
411
- '--wp-block-editor-iframe-zoom-out-content-height'
412
- );
413
- iframeDocument.documentElement.style.removeProperty(
414
- '--wp-block-editor-iframe-zoom-out-inner-height'
415
- );
416
- iframeDocument.documentElement.style.removeProperty(
417
- '--wp-block-editor-iframe-zoom-out-container-width'
418
- );
419
- iframeDocument.documentElement.style.removeProperty(
420
- '--wp-block-editor-iframe-zoom-out-scale-container-width'
421
- );
545
+ // HACK: Skipping cleanup because it causes issues with the zoom out
546
+ // animation. More refactoring is needed to fix this properly.
547
+ // iframeDocument.documentElement.style.removeProperty(
548
+ // '--wp-block-editor-iframe-zoom-out-scale'
549
+ // );
550
+ // iframeDocument.documentElement.style.removeProperty(
551
+ // '--wp-block-editor-iframe-zoom-out-frame-size'
552
+ // );
553
+ // iframeDocument.documentElement.style.removeProperty(
554
+ // '--wp-block-editor-iframe-zoom-out-content-height'
555
+ // );
556
+ // iframeDocument.documentElement.style.removeProperty(
557
+ // '--wp-block-editor-iframe-zoom-out-inner-height'
558
+ // );
559
+ // iframeDocument.documentElement.style.removeProperty(
560
+ // '--wp-block-editor-iframe-zoom-out-container-width'
561
+ // );
562
+ // iframeDocument.documentElement.style.removeProperty(
563
+ // '--wp-block-editor-iframe-zoom-out-scale-container-width'
564
+ // );
422
565
  };
423
566
  }, [
424
- scale,
567
+ scaleValue,
425
568
  frameSize,
426
569
  iframeDocument,
427
570
  iframeWindowInnerHeight,
@@ -17,7 +17,6 @@ import {
17
17
  __experimentalText as Text,
18
18
  FlexBlock,
19
19
  } from '@wordpress/components';
20
- import { useSelect } from '@wordpress/data';
21
20
 
22
21
  /**
23
22
  * Internal dependencies
@@ -34,8 +33,6 @@ import {
34
33
  starterPatternsCategory,
35
34
  INSERTER_PATTERN_TYPES,
36
35
  } from './utils';
37
- import { store as blockEditorStore } from '../../../store';
38
- import { unlock } from '../../../lock-unlock';
39
36
 
40
37
  const noop = () => {};
41
38
 
@@ -46,10 +43,6 @@ export function PatternCategoryPreviews( {
46
43
  category,
47
44
  showTitlesAsTooltip,
48
45
  } ) {
49
- const isZoomOutMode = useSelect(
50
- ( select ) => unlock( select( blockEditorStore ) ).isZoomOut(),
51
- []
52
- );
53
46
  const [ allPatterns, , onClickPattern ] = usePatternsState(
54
47
  onInsert,
55
48
  rootClientId,
@@ -179,15 +172,13 @@ export function PatternCategoryPreviews( {
179
172
  </VStack>
180
173
  { currentCategoryPatterns.length > 0 && (
181
174
  <>
182
- { isZoomOutMode && (
183
- <Text
184
- size="12"
185
- as="p"
186
- className="block-editor-inserter__help-text"
187
- >
188
- { __( 'Drag and drop patterns into the canvas.' ) }
189
- </Text>
190
- ) }
175
+ <Text
176
+ size="12"
177
+ as="p"
178
+ className="block-editor-inserter__help-text"
179
+ >
180
+ { __( 'Drag and drop patterns into the canvas.' ) }
181
+ </Text>
191
182
  <BlockPatternsList
192
183
  ref={ scrollContainerRef }
193
184
  blockPatterns={ pagingProps.categoryPatterns }
@@ -6,7 +6,7 @@ import {
6
6
  privateApis as componentsPrivateApis,
7
7
  __unstableMotion as motion,
8
8
  } from '@wordpress/components';
9
- import { useState, useEffect } from '@wordpress/element';
9
+ import { useState } from '@wordpress/element';
10
10
 
11
11
  /**
12
12
  * Internal dependencies
@@ -35,14 +35,13 @@ function CategoryTabs( {
35
35
  const selectedTabId = selectedCategory ? selectedCategory.name : null;
36
36
  const [ activeTabId, setActiveId ] = useState();
37
37
  const firstTabId = categories?.[ 0 ]?.name;
38
- useEffect( () => {
39
- // If there is no active tab, make the first tab the active tab, so that
40
- // when focus is moved to the tablist, the first tab will be focused
41
- // despite not being selected
42
- if ( selectedTabId === null && ! activeTabId && firstTabId ) {
43
- setActiveId( firstTabId );
44
- }
45
- }, [ selectedTabId, activeTabId, firstTabId, setActiveId ] );
38
+
39
+ // If there is no active tab, make the first tab the active tab, so that
40
+ // when focus is moved to the tablist, the first tab will be focused
41
+ // despite not being selected
42
+ if ( selectedTabId === null && ! activeTabId && firstTabId ) {
43
+ setActiveId( firstTabId );
44
+ }
46
45
 
47
46
  return (
48
47
  <Tabs
@@ -29,6 +29,15 @@ const InserterDraggableBlocks = ( {
29
29
  blocks,
30
30
  };
31
31
 
32
+ const blocksContainMedia =
33
+ blocks.filter(
34
+ ( block ) =>
35
+ ( block.name === 'core/image' ||
36
+ block.name === 'core/audio' ||
37
+ block.name === 'core/video' ) &&
38
+ ( block.attributes.url || block.attributes.src )
39
+ ).length > 0;
40
+
32
41
  const blockTypeIcon = useSelect(
33
42
  ( select ) => {
34
43
  const { getBlockType } = select( blocksStore );
@@ -63,7 +72,7 @@ const InserterDraggableBlocks = ( {
63
72
  ? [ createBlock( 'core/block', { ref: pattern.id } ) ]
64
73
  : blocks;
65
74
  event.dataTransfer.setData(
66
- 'text/html',
75
+ blocksContainMedia ? 'default' : 'text/html',
67
76
  serialize( parsedBlocks )
68
77
  );
69
78
  } }
@@ -116,6 +116,7 @@ registerBlockType( 'my-plugin/inspector-controls-example', {
116
116
 
117
117
  <TextControl
118
118
  __nextHasNoMarginBottom
119
+ __next40pxDefaultSize
119
120
  label="Text Field"
120
121
  help="Additional help text"
121
122
  value={ textField }
@@ -208,6 +209,7 @@ function MyBlockEdit( { attributes, setAttributes } ) {
208
209
  <InspectorAdvancedControls>
209
210
  <TextControl
210
211
  __nextHasNoMarginBottom
212
+ __next40pxDefaultSize
211
213
  label="HTML anchor"
212
214
  value={ attributes.anchor }
213
215
  onChange={ ( nextValue ) => {
@@ -34,14 +34,14 @@ export default function InspectorControlsSlot( {
34
34
  );
35
35
  group = __experimentalGroup;
36
36
  }
37
- const Slot = groups[ group ]?.Slot;
38
- const fills = useSlotFills( Slot?.__unstableName );
37
+ const slotFill = groups[ group ];
38
+ const fills = useSlotFills( slotFill?.name );
39
39
 
40
40
  const motionContextValue = useContext( MotionContext );
41
41
 
42
42
  const computedFillProps = useMemo(
43
43
  () => ( {
44
- ...( fillProps ?? {} ),
44
+ ...fillProps,
45
45
  forwardedContext: [
46
46
  ...( fillProps?.forwardedContext ?? [] ),
47
47
  [ MotionContext.Provider, { value: motionContextValue } ],
@@ -50,7 +50,7 @@ export default function InspectorControlsSlot( {
50
50
  [ motionContextValue, fillProps ]
51
51
  );
52
52
 
53
- if ( ! Slot ) {
53
+ if ( ! slotFill ) {
54
54
  warning( `Unknown InspectorControls group "${ group }" provided.` );
55
55
  return null;
56
56
  }
@@ -59,6 +59,8 @@ export default function InspectorControlsSlot( {
59
59
  return null;
60
60
  }
61
61
 
62
+ const { Slot } = slotFill;
63
+
62
64
  if ( label ) {
63
65
  return (
64
66
  <BlockSupportToolsPanel group={ group } label={ label }>
@@ -53,9 +53,7 @@ const PositionControlsPanel = () => {
53
53
  };
54
54
 
55
55
  const PositionControls = () => {
56
- const fills = useSlotFills(
57
- InspectorControlsGroups.position.Slot.__unstableName
58
- );
56
+ const fills = useSlotFills( InspectorControlsGroups.position.name );
59
57
  const hasFills = Boolean( fills && fills.length );
60
58
 
61
59
  if ( ! hasFills ) {
@@ -46,18 +46,18 @@ export default function useInspectorControlsTabs( blockName ) {
46
46
 
47
47
  // List View Tab: If there are any fills for the list group add that tab.
48
48
  const listViewDisabled = useIsListViewTabDisabled( blockName );
49
- const listFills = useSlotFills( listGroup.Slot.__unstableName );
49
+ const listFills = useSlotFills( listGroup.name );
50
50
  const hasListFills = ! listViewDisabled && !! listFills && listFills.length;
51
51
 
52
52
  // Styles Tab: Add this tab if there are any fills for block supports
53
53
  // e.g. border, color, spacing, typography, etc.
54
54
  const styleFills = [
55
- ...( useSlotFills( borderGroup.Slot.__unstableName ) || [] ),
56
- ...( useSlotFills( colorGroup.Slot.__unstableName ) || [] ),
57
- ...( useSlotFills( dimensionsGroup.Slot.__unstableName ) || [] ),
58
- ...( useSlotFills( stylesGroup.Slot.__unstableName ) || [] ),
59
- ...( useSlotFills( typographyGroup.Slot.__unstableName ) || [] ),
60
- ...( useSlotFills( effectsGroup.Slot.__unstableName ) || [] ),
55
+ ...( useSlotFills( borderGroup.name ) || [] ),
56
+ ...( useSlotFills( colorGroup.name ) || [] ),
57
+ ...( useSlotFills( dimensionsGroup.name ) || [] ),
58
+ ...( useSlotFills( stylesGroup.name ) || [] ),
59
+ ...( useSlotFills( typographyGroup.name ) || [] ),
60
+ ...( useSlotFills( effectsGroup.name ) || [] ),
61
61
  ];
62
62
  const hasStyleFills = styleFills.length;
63
63
 
@@ -67,12 +67,12 @@ export default function useInspectorControlsTabs( blockName ) {
67
67
  // the advanced controls slot as well to ensure they are rendered.
68
68
  const advancedFills = [
69
69
  ...( useSlotFills( InspectorAdvancedControls.slotName ) || [] ),
70
- ...( useSlotFills( bindingsGroup.Slot.__unstableName ) || [] ),
70
+ ...( useSlotFills( bindingsGroup.name ) || [] ),
71
71
  ];
72
72
 
73
73
  const settingsFills = [
74
- ...( useSlotFills( defaultGroup.Slot.__unstableName ) || [] ),
75
- ...( useSlotFills( positionGroup.Slot.__unstableName ) || [] ),
74
+ ...( useSlotFills( defaultGroup.name ) || [] ),
75
+ ...( useSlotFills( positionGroup.name ) || [] ),
76
76
  ...( hasListFills && hasStyleFills > 1 ? advancedFills : [] ),
77
77
  ];
78
78