@wordpress/block-editor 14.7.0 → 14.8.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 (204) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/block-controls/slot.js +6 -3
  3. package/build/components/block-controls/slot.js.map +1 -1
  4. package/build/components/block-inspector/index.js +1 -2
  5. package/build/components/block-inspector/index.js.map +1 -1
  6. package/build/components/block-lock/modal.js +1 -1
  7. package/build/components/block-lock/modal.js.map +1 -1
  8. package/build/components/block-manager/category.js +79 -0
  9. package/build/components/block-manager/category.js.map +1 -0
  10. package/build/components/block-manager/checklist.js +40 -0
  11. package/build/components/block-manager/checklist.js.map +1 -0
  12. package/build/components/block-manager/index.js +108 -0
  13. package/build/components/block-manager/index.js.map +1 -0
  14. package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  15. package/build/components/block-settings-menu/index.js.map +1 -1
  16. package/build/components/block-toolbar/index.js +16 -4
  17. package/build/components/block-toolbar/index.js.map +1 -1
  18. package/build/components/block-toolbar/switch-section-style.js +105 -0
  19. package/build/components/block-toolbar/switch-section-style.js.map +1 -0
  20. package/build/components/collab/block-comment-icon-slot.js +2 -6
  21. package/build/components/collab/block-comment-icon-slot.js.map +1 -1
  22. package/build/components/collab/block-comment-icon-toolbar-slot.js +2 -6
  23. package/build/components/collab/block-comment-icon-toolbar-slot.js.map +1 -1
  24. package/build/components/color-palette/with-color-context.js +4 -2
  25. package/build/components/color-palette/with-color-context.js.map +1 -1
  26. package/build/components/font-family/index.js +14 -13
  27. package/build/components/font-family/index.js.map +1 -1
  28. package/build/components/global-styles/use-global-styles-output.js +1 -1
  29. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  30. package/build/components/iframe/index.js +13 -100
  31. package/build/components/iframe/index.js.map +1 -1
  32. package/build/components/iframe/use-scale-canvas.js +377 -0
  33. package/build/components/iframe/use-scale-canvas.js.map +1 -0
  34. package/build/components/image-editor/use-save-image.js +22 -3
  35. package/build/components/image-editor/use-save-image.js.map +1 -1
  36. package/build/components/inserter/block-patterns-tab/pattern-category-previews.js +1 -5
  37. package/build/components/inserter/block-patterns-tab/pattern-category-previews.js.map +1 -1
  38. package/build/components/inserter/category-tabs/index.js +7 -8
  39. package/build/components/inserter/category-tabs/index.js.map +1 -1
  40. package/build/components/inserter-draggable-blocks/index.js +2 -1
  41. package/build/components/inserter-draggable-blocks/index.js.map +1 -1
  42. package/build/components/inspector-controls/slot.js +7 -4
  43. package/build/components/inspector-controls/slot.js.map +1 -1
  44. package/build/components/inspector-controls-tabs/position-controls-panel.js +1 -1
  45. package/build/components/inspector-controls-tabs/position-controls-panel.js.map +1 -1
  46. package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js +4 -4
  47. package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +1 -1
  48. package/build/components/media-placeholder/index.js +29 -21
  49. package/build/components/media-placeholder/index.js.map +1 -1
  50. package/build/hooks/border.js +3 -3
  51. package/build/hooks/border.js.map +1 -1
  52. package/build/hooks/color.js +1 -1
  53. package/build/hooks/color.js.map +1 -1
  54. package/build/hooks/dimensions.js +2 -2
  55. package/build/hooks/dimensions.js.map +1 -1
  56. package/build/hooks/style.js +6 -6
  57. package/build/hooks/style.js.map +1 -1
  58. package/build/hooks/supports.js +1 -1
  59. package/build/hooks/supports.js.map +1 -1
  60. package/build/hooks/typography.js +1 -1
  61. package/build/hooks/typography.js.map +1 -1
  62. package/build/hooks/utils.js +1 -1
  63. package/build/hooks/utils.js.map +1 -1
  64. package/build/layouts/flex.js +11 -9
  65. package/build/layouts/flex.js.map +1 -1
  66. package/build/private-apis.js +4 -4
  67. package/build/private-apis.js.map +1 -1
  68. package/build/store/private-selectors.js +1 -1
  69. package/build/store/private-selectors.js.map +1 -1
  70. package/build/store/selectors.js +3 -0
  71. package/build/store/selectors.js.map +1 -1
  72. package/build-module/components/block-controls/slot.js +6 -3
  73. package/build-module/components/block-controls/slot.js.map +1 -1
  74. package/build-module/components/block-inspector/index.js +1 -2
  75. package/build-module/components/block-inspector/index.js.map +1 -1
  76. package/build-module/components/block-lock/modal.js +1 -1
  77. package/build-module/components/block-lock/modal.js.map +1 -1
  78. package/build-module/components/block-manager/category.js +71 -0
  79. package/build-module/components/block-manager/category.js.map +1 -0
  80. package/build-module/components/block-manager/checklist.js +32 -0
  81. package/build-module/components/block-manager/checklist.js.map +1 -0
  82. package/build-module/components/block-manager/index.js +102 -0
  83. package/build-module/components/block-manager/index.js.map +1 -0
  84. package/build-module/components/block-settings-menu/block-settings-dropdown.js +2 -2
  85. package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  86. package/build-module/components/block-settings-menu/index.js +2 -2
  87. package/build-module/components/block-settings-menu/index.js.map +1 -1
  88. package/build-module/components/block-toolbar/index.js +16 -4
  89. package/build-module/components/block-toolbar/index.js.map +1 -1
  90. package/build-module/components/block-toolbar/switch-section-style.js +97 -0
  91. package/build-module/components/block-toolbar/switch-section-style.js.map +1 -0
  92. package/build-module/components/collab/block-comment-icon-slot.js +2 -6
  93. package/build-module/components/collab/block-comment-icon-slot.js.map +1 -1
  94. package/build-module/components/collab/block-comment-icon-toolbar-slot.js +2 -6
  95. package/build-module/components/collab/block-comment-icon-toolbar-slot.js.map +1 -1
  96. package/build-module/components/color-palette/with-color-context.js +4 -2
  97. package/build-module/components/color-palette/with-color-context.js.map +1 -1
  98. package/build-module/components/font-family/index.js +15 -14
  99. package/build-module/components/font-family/index.js.map +1 -1
  100. package/build-module/components/global-styles/use-global-styles-output.js +1 -1
  101. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  102. package/build-module/components/iframe/index.js +15 -102
  103. package/build-module/components/iframe/index.js.map +1 -1
  104. package/build-module/components/iframe/use-scale-canvas.js +371 -0
  105. package/build-module/components/iframe/use-scale-canvas.js.map +1 -0
  106. package/build-module/components/image-editor/use-save-image.js +22 -3
  107. package/build-module/components/image-editor/use-save-image.js.map +1 -1
  108. package/build-module/components/inserter/block-patterns-tab/pattern-category-previews.js +1 -5
  109. package/build-module/components/inserter/block-patterns-tab/pattern-category-previews.js.map +1 -1
  110. package/build-module/components/inserter/category-tabs/index.js +8 -9
  111. package/build-module/components/inserter/category-tabs/index.js.map +1 -1
  112. package/build-module/components/inserter-draggable-blocks/index.js +2 -1
  113. package/build-module/components/inserter-draggable-blocks/index.js.map +1 -1
  114. package/build-module/components/inspector-controls/slot.js +7 -4
  115. package/build-module/components/inspector-controls/slot.js.map +1 -1
  116. package/build-module/components/inspector-controls-tabs/position-controls-panel.js +1 -1
  117. package/build-module/components/inspector-controls-tabs/position-controls-panel.js.map +1 -1
  118. package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js +4 -4
  119. package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +1 -1
  120. package/build-module/components/media-placeholder/index.js +29 -21
  121. package/build-module/components/media-placeholder/index.js.map +1 -1
  122. package/build-module/hooks/border.js +3 -3
  123. package/build-module/hooks/border.js.map +1 -1
  124. package/build-module/hooks/color.js +1 -1
  125. package/build-module/hooks/color.js.map +1 -1
  126. package/build-module/hooks/dimensions.js +2 -2
  127. package/build-module/hooks/dimensions.js.map +1 -1
  128. package/build-module/hooks/style.js +6 -6
  129. package/build-module/hooks/style.js.map +1 -1
  130. package/build-module/hooks/supports.js +1 -1
  131. package/build-module/hooks/supports.js.map +1 -1
  132. package/build-module/hooks/typography.js +1 -1
  133. package/build-module/hooks/typography.js.map +1 -1
  134. package/build-module/hooks/utils.js +1 -1
  135. package/build-module/hooks/utils.js.map +1 -1
  136. package/build-module/layouts/flex.js +11 -9
  137. package/build-module/layouts/flex.js.map +1 -1
  138. package/build-module/private-apis.js +6 -6
  139. package/build-module/private-apis.js.map +1 -1
  140. package/build-module/store/private-selectors.js +1 -1
  141. package/build-module/store/private-selectors.js.map +1 -1
  142. package/build-module/store/selectors.js +3 -0
  143. package/build-module/store/selectors.js.map +1 -1
  144. package/build-style/content-rtl.css +27 -28
  145. package/build-style/content.css +27 -28
  146. package/build-style/style-rtl.css +108 -0
  147. package/build-style/style.css +108 -0
  148. package/package.json +2 -2
  149. package/src/components/block-canvas/style.scss +2 -1
  150. package/src/components/block-controls/slot.js +5 -3
  151. package/src/components/block-inspector/index.js +0 -2
  152. package/src/components/block-lock/modal.js +1 -1
  153. package/src/components/block-manager/category.js +102 -0
  154. package/src/components/block-manager/checklist.js +34 -0
  155. package/src/components/block-manager/index.js +127 -0
  156. package/src/components/block-manager/style.scss +82 -0
  157. package/src/components/block-mover/README.md +15 -8
  158. package/src/components/block-mover/stories/index.story.js +73 -71
  159. package/src/components/block-mover/style.scss +3 -0
  160. package/src/components/block-settings-menu/block-settings-dropdown.js +2 -2
  161. package/src/components/block-settings-menu/index.js +2 -2
  162. package/src/components/block-toolbar/index.js +14 -0
  163. package/src/components/block-toolbar/switch-section-style.js +115 -0
  164. package/src/components/block-tools/style.scss +39 -0
  165. package/src/components/collab/block-comment-icon-slot.js +2 -6
  166. package/src/components/collab/block-comment-icon-toolbar-slot.js +3 -5
  167. package/src/components/color-palette/test/__snapshots__/control.js.snap +2 -2
  168. package/src/components/color-palette/with-color-context.js +25 -7
  169. package/src/components/font-family/index.js +13 -13
  170. package/src/components/global-styles/test/use-global-styles-output.js +1 -1
  171. package/src/components/global-styles/use-global-styles-output.js +1 -1
  172. package/src/components/iframe/content.scss +49 -43
  173. package/src/components/iframe/index.js +14 -171
  174. package/src/components/iframe/use-scale-canvas.js +468 -0
  175. package/src/components/image-editor/use-save-image.js +27 -2
  176. package/src/components/inserter/block-patterns-tab/pattern-category-previews.js +7 -16
  177. package/src/components/inserter/category-tabs/index.js +8 -9
  178. package/src/components/inserter-draggable-blocks/index.js +10 -1
  179. package/src/components/inspector-controls/README.md +2 -0
  180. package/src/components/inspector-controls/slot.js +6 -4
  181. package/src/components/inspector-controls-tabs/position-controls-panel.js +1 -3
  182. package/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js +10 -10
  183. package/src/components/media-placeholder/index.js +37 -33
  184. package/src/components/provider/test/use-block-sync.js +3 -1
  185. package/src/components/rich-text/content.scss +15 -10
  186. package/src/hooks/border.js +3 -9
  187. package/src/hooks/color.js +1 -1
  188. package/src/hooks/dimensions.js +2 -2
  189. package/src/hooks/style.js +6 -12
  190. package/src/hooks/supports.js +1 -1
  191. package/src/hooks/test/style.js +1 -2
  192. package/src/hooks/typography.js +1 -1
  193. package/src/hooks/utils.js +1 -1
  194. package/src/layouts/flex.js +26 -18
  195. package/src/private-apis.js +6 -6
  196. package/src/store/private-selectors.js +1 -1
  197. package/src/store/selectors.js +3 -0
  198. package/src/store/test/selectors.js +87 -58
  199. package/src/style.scss +1 -0
  200. package/build/components/block-info-slot-fill/index.js +0 -39
  201. package/build/components/block-info-slot-fill/index.js.map +0 -1
  202. package/build-module/components/block-info-slot-fill/index.js +0 -32
  203. package/build-module/components/block-info-slot-fill/index.js.map +0 -1
  204. package/src/components/block-info-slot-fill/index.js +0 -27
@@ -3,10 +3,8 @@
3
3
  */
4
4
  import { createSlotFill } from '@wordpress/components';
5
5
 
6
- const { Fill: __unstableCommentIconToolbarFill, Slot } = createSlotFill(
7
- '__unstableCommentIconToolbarFill'
6
+ const CommentIconToolbarSlotFill = createSlotFill(
7
+ Symbol( 'CommentIconToolbarSlotFill' )
8
8
  );
9
9
 
10
- __unstableCommentIconToolbarFill.Slot = Slot;
11
-
12
- export default __unstableCommentIconToolbarFill;
10
+ export default CommentIconToolbarSlotFill;
@@ -219,7 +219,7 @@ exports[`ColorPaletteControl matches the snapshot 1`] = `
219
219
  <button
220
220
  aria-label="Color: red"
221
221
  aria-selected="true"
222
- class="components-button components-circular-option-picker__option"
222
+ class="components-button components-circular-option-picker__option is-next-40px-default-size"
223
223
  data-active-item="true"
224
224
  id="components-circular-option-picker-0-0"
225
225
  role="option"
@@ -247,7 +247,7 @@ exports[`ColorPaletteControl matches the snapshot 1`] = `
247
247
  class="components-circular-option-picker__custom-clear-wrapper"
248
248
  >
249
249
  <button
250
- class="components-button components-circular-option-picker__clear is-tertiary"
250
+ class="components-button components-circular-option-picker__clear is-next-40px-default-size is-tertiary"
251
251
  type="button"
252
252
  >
253
253
  Clear
@@ -10,14 +10,32 @@ import { useSettings } from '../use-settings';
10
10
 
11
11
  export default createHigherOrderComponent( ( WrappedComponent ) => {
12
12
  return ( props ) => {
13
- const [ colorsFeature, enableCustomColors ] = useSettings(
14
- 'color.palette',
15
- 'color.custom'
13
+ // Get the default colors, theme colors, and custom colors
14
+ const [
15
+ defaultColors,
16
+ themeColors,
17
+ customColors,
18
+ enableCustomColors,
19
+ enableDefaultColors,
20
+ ] = useSettings(
21
+ 'color.palette.default',
22
+ 'color.palette.theme',
23
+ 'color.palette.custom',
24
+ 'color.custom',
25
+ 'color.defaultPalette'
16
26
  );
17
- const {
18
- colors = colorsFeature,
19
- disableCustomColors = ! enableCustomColors,
20
- } = props;
27
+
28
+ const _colors = enableDefaultColors
29
+ ? [
30
+ ...( themeColors || [] ),
31
+ ...( defaultColors || [] ),
32
+ ...( customColors || [] ),
33
+ ]
34
+ : [ ...( themeColors || [] ), ...( customColors || [] ) ];
35
+
36
+ const { colors = _colors, disableCustomColors = ! enableCustomColors } =
37
+ props;
38
+
21
39
  const hasColorsToChoose =
22
40
  ( colors && colors.length > 0 ) || ! disableCustomColors;
23
41
  return (
@@ -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',
@@ -4,54 +4,60 @@
4
4
 
5
5
  .block-editor-iframe__html {
6
6
  transform-origin: top center;
7
- // We don't want to animate the transform of the translateX because it is used
8
- // to "center" the canvas. Leaving it on causes the canvas to slide around in
9
- // odd ways.
10
- @include editor-canvas-resize-animation(transform 0s, scale 0s, padding 0s);
7
+ // Prevents a flash of background color change when entering/exiting zoom out
8
+ transition: background-color 400ms;
11
9
 
12
10
  &.zoom-out-animation {
13
- // we only want to animate the scaling when entering zoom out. When sidebars
14
- // are toggled, the resizing of the iframe handles scaling the canvas as well,
15
- // and the doubled animations cause very odd animations.
16
- @include editor-canvas-resize-animation(transform 0s);
11
+ $scroll-top: var(--wp-block-editor-iframe-zoom-out-scroll-top, 0);
12
+ $scroll-top-next: var(--wp-block-editor-iframe-zoom-out-scroll-top-next, 0);
13
+
14
+ position: fixed;
15
+ left: 0;
16
+ right: 0;
17
+ top: calc(-1 * #{$scroll-top});
18
+ bottom: 0;
19
+ // Force preserving a scrollbar gutter as scrollbar-gutter isn't supported in all browsers yet,
20
+ // and removing the scrollbar causes the content to shift.
21
+ overflow-y: scroll;
17
22
  }
18
- }
19
23
 
20
- .block-editor-iframe__html.is-zoomed-out {
21
- $scale: var(--wp-block-editor-iframe-zoom-out-scale);
22
- $frame-size: var(--wp-block-editor-iframe-zoom-out-frame-size);
23
- $inner-height: var(--wp-block-editor-iframe-zoom-out-inner-height);
24
- $content-height: var(--wp-block-editor-iframe-zoom-out-content-height);
25
- $scale-container-width: var(--wp-block-editor-iframe-zoom-out-scale-container-width);
26
- $container-width: var(--wp-block-editor-iframe-zoom-out-container-width, 100vw);
27
- // Apply an X translation to center the scaled content within the available space.
28
- transform: translateX(calc((#{$scale-container-width} - #{$container-width}) / 2 / #{$scale}));
29
- scale: #{$scale};
30
- background-color: $gray-300;
31
-
32
- // Chrome seems to respect that transform scale shouldn't affect the layout size of the element,
33
- // so we need to adjust the height of the content to match the scale by using negative margins.
34
- $extra-content-height: calc(#{$content-height} * (1 - #{$scale}));
35
- $total-frame-height: calc(2 * #{$frame-size} / #{$scale});
36
- $total-height: calc(#{$extra-content-height} + #{$total-frame-height} + 2px);
37
- margin-bottom: calc(-1 * #{$total-height});
38
- // Add the top/bottom frame size. We use scaling to account for the left/right, as
39
- // the padding left/right causes the contents to reflow, which breaks the 1:1 scaling
40
- // of the content.
41
- padding-top: calc(#{$frame-size} / #{$scale});
42
- padding-bottom: calc(#{$frame-size} / #{$scale});
43
-
44
- body {
45
- min-height: calc((#{$inner-height} - #{$total-frame-height}) / #{$scale});
46
-
47
- > .is-root-container:not(.wp-block-post-content) {
48
- flex: 1;
49
- display: flex;
50
- flex-direction: column;
51
- height: 100%;
52
-
53
- > main {
24
+ &.is-zoomed-out {
25
+ $scale: var(--wp-block-editor-iframe-zoom-out-scale, 1);
26
+ $frame-size: var(--wp-block-editor-iframe-zoom-out-frame-size, 0);
27
+ $inner-height: var(--wp-block-editor-iframe-zoom-out-inner-height);
28
+ $content-height: var(--wp-block-editor-iframe-zoom-out-content-height);
29
+ $scale-container-width: var(--wp-block-editor-iframe-zoom-out-scale-container-width);
30
+ $container-width: var(--wp-block-editor-iframe-zoom-out-container-width, 100vw);
31
+ // Apply an X translation to center the scaled content within the available space.
32
+ transform: translateX(calc((#{$scale-container-width} - #{$container-width}) / 2 / #{$scale}));
33
+ scale: $scale;
34
+ background-color: $gray-300;
35
+
36
+ // Chrome seems to respect that transform scale shouldn't affect the layout size of the element,
37
+ // so we need to adjust the height of the content to match the scale by using negative margins.
38
+ $extra-content-height: calc(#{$content-height} * (1 - #{$scale}));
39
+ $total-frame-height: calc(2 * #{$frame-size} / #{$scale});
40
+ $total-height: calc(#{$extra-content-height} + #{$total-frame-height} + 2px);
41
+ margin-bottom: calc(-1 * #{$total-height});
42
+
43
+ // Add the top/bottom frame size. We use scaling to account for the left/right, as
44
+ // the padding left/right causes the contents to reflow, which breaks the 1:1 scaling
45
+ // of the content.
46
+ padding-top: calc(#{$frame-size} / #{$scale});
47
+ padding-bottom: calc(#{$frame-size} / #{$scale});
48
+
49
+ body {
50
+ min-height: calc((#{$inner-height} - #{$total-frame-height}) / #{$scale});
51
+
52
+ > .is-root-container:not(.wp-block-post-content) {
54
53
  flex: 1;
54
+ display: flex;
55
+ flex-direction: column;
56
+ height: 100%;
57
+
58
+ > main {
59
+ flex: 1;
60
+ }
55
61
  }
56
62
  }
57
63
  }
@@ -12,15 +12,9 @@ import {
12
12
  forwardRef,
13
13
  useMemo,
14
14
  useEffect,
15
- useRef,
16
15
  } from '@wordpress/element';
17
16
  import { __ } from '@wordpress/i18n';
18
- import {
19
- useResizeObserver,
20
- useMergeRefs,
21
- useRefEffect,
22
- useDisabled,
23
- } from '@wordpress/compose';
17
+ import { useMergeRefs, useRefEffect, useDisabled } from '@wordpress/compose';
24
18
  import { __experimentalStyleProvider as StyleProvider } from '@wordpress/components';
25
19
  import { useSelect } from '@wordpress/data';
26
20
 
@@ -30,6 +24,7 @@ import { useSelect } from '@wordpress/data';
30
24
  import { useBlockSelectionClearer } from '../block-selection-clearer';
31
25
  import { useWritingFlow } from '../writing-flow';
32
26
  import { getCompatibilityStyles } from './get-compatibility-styles';
27
+ import { useScaleCanvas } from './use-scale-canvas';
33
28
  import { store as blockEditorStore } from '../../store';
34
29
 
35
30
  function bubbleEvent( event, Constructor, frame ) {
@@ -121,15 +116,11 @@ function Iframe( {
121
116
  };
122
117
  }, [] );
123
118
  const { styles = '', scripts = '' } = resolvedAssets;
119
+ /** @type {[Document, import('react').Dispatch<Document>]} */
124
120
  const [ iframeDocument, setIframeDocument ] = useState();
125
- const initialContainerWidthRef = useRef( 0 );
126
121
  const [ bodyClasses, setBodyClasses ] = useState( [] );
127
122
  const clearerRef = useBlockSelectionClearer();
128
123
  const [ before, writingFlowRef, after ] = useWritingFlow();
129
- const [ contentResizeListener, { height: contentHeight } ] =
130
- useResizeObserver();
131
- const [ containerResizeListener, { width: containerWidth } ] =
132
- useResizeObserver();
133
124
 
134
125
  const setRef = useRefEffect( ( node ) => {
135
126
  node._load = () => {
@@ -225,48 +216,16 @@ function Iframe( {
225
216
  };
226
217
  }, [] );
227
218
 
228
- const [ iframeWindowInnerHeight, setIframeWindowInnerHeight ] = useState();
229
-
230
- const iframeResizeRef = useRefEffect( ( node ) => {
231
- const nodeWindow = node.ownerDocument.defaultView;
232
-
233
- setIframeWindowInnerHeight( nodeWindow.innerHeight );
234
- const onResize = () => {
235
- setIframeWindowInnerHeight( nodeWindow.innerHeight );
236
- };
237
- nodeWindow.addEventListener( 'resize', onResize );
238
- return () => {
239
- nodeWindow.removeEventListener( 'resize', onResize );
240
- };
241
- }, [] );
242
-
243
- const [ windowInnerWidth, setWindowInnerWidth ] = useState();
244
-
245
- const windowResizeRef = useRefEffect( ( node ) => {
246
- const nodeWindow = node.ownerDocument.defaultView;
247
-
248
- setWindowInnerWidth( nodeWindow.innerWidth );
249
- const onResize = () => {
250
- setWindowInnerWidth( nodeWindow.innerWidth );
251
- };
252
- nodeWindow.addEventListener( 'resize', onResize );
253
- return () => {
254
- nodeWindow.removeEventListener( 'resize', onResize );
255
- };
256
- }, [] );
257
-
258
- const isZoomedOut = scale !== 1;
259
-
260
- useEffect( () => {
261
- if ( ! isZoomedOut ) {
262
- initialContainerWidthRef.current = containerWidth;
263
- }
264
- }, [ containerWidth, isZoomedOut ] );
265
-
266
- const scaleContainerWidth = Math.max(
267
- initialContainerWidthRef.current,
268
- containerWidth
269
- );
219
+ const {
220
+ contentResizeListener,
221
+ containerResizeListener,
222
+ isZoomedOut,
223
+ scaleContainerWidth,
224
+ } = useScaleCanvas( {
225
+ scale,
226
+ frameSize: parseInt( frameSize ),
227
+ iframeDocument,
228
+ } );
270
229
 
271
230
  const disabledRef = useDisabled( { isDisabled: ! readonly } );
272
231
  const bodyRef = useMergeRefs( [
@@ -275,10 +234,6 @@ function Iframe( {
275
234
  clearerRef,
276
235
  writingFlowRef,
277
236
  disabledRef,
278
- // Avoid resize listeners when not needed, these will trigger
279
- // unnecessary re-renders when animating the iframe width, or when
280
- // expanding preview iframes.
281
- isZoomedOut ? iframeResizeRef : null,
282
237
  ] );
283
238
 
284
239
  // Correct doctype is required to enable rendering in standards
@@ -320,118 +275,6 @@ function Iframe( {
320
275
 
321
276
  useEffect( () => cleanup, [ cleanup ] );
322
277
 
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
- useEffect( () => {
330
- if ( ! iframeDocument || ! isZoomedOut ) {
331
- return;
332
- }
333
-
334
- const handleZoomOutAnimationClassname = () => {
335
- clearTimeout( zoomOutAnimationClassnameRef.current );
336
-
337
- iframeDocument.documentElement.classList.add(
338
- 'zoom-out-animation'
339
- );
340
-
341
- zoomOutAnimationClassnameRef.current = setTimeout( () => {
342
- iframeDocument.documentElement.classList.remove(
343
- 'zoom-out-animation'
344
- );
345
- }, 400 ); // 400ms should match the animation speed used in components/iframe/content.scss
346
- };
347
-
348
- handleZoomOutAnimationClassname();
349
- iframeDocument.documentElement.classList.add( 'is-zoomed-out' );
350
-
351
- return () => {
352
- handleZoomOutAnimationClassname();
353
- iframeDocument.documentElement.classList.remove( 'is-zoomed-out' );
354
- };
355
- }, [ iframeDocument, isZoomedOut ] );
356
-
357
- // Calculate the scaling and CSS variables for the zoom out canvas
358
- useEffect( () => {
359
- if ( ! iframeDocument || ! isZoomedOut ) {
360
- return;
361
- }
362
-
363
- const maxWidth = 750;
364
- // Note: When we initialize the zoom out when the canvas is smaller (sidebars open),
365
- // initialContainerWidthRef will be smaller than the full page, and reflow will happen
366
- // when the canvas area becomes larger due to sidebars closing. This is a known but
367
- // minor divergence for now.
368
-
369
- // This scaling calculation has to happen within the JS because CSS calc() can
370
- // only divide and multiply by a unitless value. I.e. calc( 100px / 2 ) is valid
371
- // but calc( 100px / 2px ) is not.
372
- iframeDocument.documentElement.style.setProperty(
373
- '--wp-block-editor-iframe-zoom-out-scale',
374
- scale === 'auto-scaled'
375
- ? ( Math.min( containerWidth, maxWidth ) -
376
- parseInt( frameSize ) * 2 ) /
377
- scaleContainerWidth
378
- : scale
379
- );
380
-
381
- // frameSize has to be a px value for the scaling and frame size to be computed correctly.
382
- iframeDocument.documentElement.style.setProperty(
383
- '--wp-block-editor-iframe-zoom-out-frame-size',
384
- typeof frameSize === 'number' ? `${ frameSize }px` : frameSize
385
- );
386
- iframeDocument.documentElement.style.setProperty(
387
- '--wp-block-editor-iframe-zoom-out-content-height',
388
- `${ contentHeight }px`
389
- );
390
- iframeDocument.documentElement.style.setProperty(
391
- '--wp-block-editor-iframe-zoom-out-inner-height',
392
- `${ iframeWindowInnerHeight }px`
393
- );
394
- iframeDocument.documentElement.style.setProperty(
395
- '--wp-block-editor-iframe-zoom-out-container-width',
396
- `${ containerWidth }px`
397
- );
398
- iframeDocument.documentElement.style.setProperty(
399
- '--wp-block-editor-iframe-zoom-out-scale-container-width',
400
- `${ scaleContainerWidth }px`
401
- );
402
-
403
- 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
- );
422
- };
423
- }, [
424
- scale,
425
- frameSize,
426
- iframeDocument,
427
- iframeWindowInnerHeight,
428
- contentHeight,
429
- containerWidth,
430
- windowInnerWidth,
431
- isZoomedOut,
432
- scaleContainerWidth,
433
- ] );
434
-
435
278
  // Make sure to not render the before and after focusable div elements in view
436
279
  // mode. They're only needed to capture focus in edit mode.
437
280
  const shouldRenderFocusCaptureElements = tabIndex >= 0 && ! isPreviewMode;
@@ -511,7 +354,7 @@ function Iframe( {
511
354
  );
512
355
 
513
356
  return (
514
- <div className="block-editor-iframe__container" ref={ windowResizeRef }>
357
+ <div className="block-editor-iframe__container">
515
358
  { containerResizeListener }
516
359
  <div
517
360
  className={ clsx(