@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.
- package/CHANGELOG.md +2 -0
- package/build/components/block-controls/slot.js +6 -3
- package/build/components/block-controls/slot.js.map +1 -1
- package/build/components/block-inspector/index.js +1 -2
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-lock/modal.js +1 -1
- package/build/components/block-lock/modal.js.map +1 -1
- package/build/components/block-manager/category.js +79 -0
- package/build/components/block-manager/category.js.map +1 -0
- package/build/components/block-manager/checklist.js +40 -0
- package/build/components/block-manager/checklist.js.map +1 -0
- package/build/components/block-manager/index.js +108 -0
- package/build/components/block-manager/index.js.map +1 -0
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-settings-menu/index.js.map +1 -1
- package/build/components/block-toolbar/index.js +16 -4
- package/build/components/block-toolbar/index.js.map +1 -1
- package/build/components/block-toolbar/switch-section-style.js +105 -0
- package/build/components/block-toolbar/switch-section-style.js.map +1 -0
- package/build/components/collab/block-comment-icon-slot.js +2 -6
- package/build/components/collab/block-comment-icon-slot.js.map +1 -1
- package/build/components/collab/block-comment-icon-toolbar-slot.js +2 -6
- package/build/components/collab/block-comment-icon-toolbar-slot.js.map +1 -1
- package/build/components/color-palette/with-color-context.js +4 -2
- package/build/components/color-palette/with-color-context.js.map +1 -1
- package/build/components/font-family/index.js +14 -13
- package/build/components/font-family/index.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +1 -1
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/iframe/index.js +13 -100
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/iframe/use-scale-canvas.js +377 -0
- package/build/components/iframe/use-scale-canvas.js.map +1 -0
- package/build/components/image-editor/use-save-image.js +22 -3
- package/build/components/image-editor/use-save-image.js.map +1 -1
- package/build/components/inserter/block-patterns-tab/pattern-category-previews.js +1 -5
- package/build/components/inserter/block-patterns-tab/pattern-category-previews.js.map +1 -1
- package/build/components/inserter/category-tabs/index.js +7 -8
- package/build/components/inserter/category-tabs/index.js.map +1 -1
- package/build/components/inserter-draggable-blocks/index.js +2 -1
- package/build/components/inserter-draggable-blocks/index.js.map +1 -1
- package/build/components/inspector-controls/slot.js +7 -4
- package/build/components/inspector-controls/slot.js.map +1 -1
- package/build/components/inspector-controls-tabs/position-controls-panel.js +1 -1
- package/build/components/inspector-controls-tabs/position-controls-panel.js.map +1 -1
- package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js +4 -4
- package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +1 -1
- package/build/components/media-placeholder/index.js +29 -21
- package/build/components/media-placeholder/index.js.map +1 -1
- package/build/hooks/border.js +3 -3
- package/build/hooks/border.js.map +1 -1
- package/build/hooks/color.js +1 -1
- package/build/hooks/color.js.map +1 -1
- package/build/hooks/dimensions.js +2 -2
- package/build/hooks/dimensions.js.map +1 -1
- package/build/hooks/style.js +6 -6
- package/build/hooks/style.js.map +1 -1
- package/build/hooks/supports.js +1 -1
- package/build/hooks/supports.js.map +1 -1
- package/build/hooks/typography.js +1 -1
- package/build/hooks/typography.js.map +1 -1
- package/build/hooks/utils.js +1 -1
- package/build/hooks/utils.js.map +1 -1
- package/build/layouts/flex.js +11 -9
- package/build/layouts/flex.js.map +1 -1
- package/build/private-apis.js +4 -4
- package/build/private-apis.js.map +1 -1
- package/build/store/private-selectors.js +1 -1
- package/build/store/private-selectors.js.map +1 -1
- package/build/store/selectors.js +3 -0
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/block-controls/slot.js +6 -3
- package/build-module/components/block-controls/slot.js.map +1 -1
- package/build-module/components/block-inspector/index.js +1 -2
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-lock/modal.js +1 -1
- package/build-module/components/block-lock/modal.js.map +1 -1
- package/build-module/components/block-manager/category.js +71 -0
- package/build-module/components/block-manager/category.js.map +1 -0
- package/build-module/components/block-manager/checklist.js +32 -0
- package/build-module/components/block-manager/checklist.js.map +1 -0
- package/build-module/components/block-manager/index.js +102 -0
- package/build-module/components/block-manager/index.js.map +1 -0
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +2 -2
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-settings-menu/index.js +2 -2
- package/build-module/components/block-settings-menu/index.js.map +1 -1
- package/build-module/components/block-toolbar/index.js +16 -4
- package/build-module/components/block-toolbar/index.js.map +1 -1
- package/build-module/components/block-toolbar/switch-section-style.js +97 -0
- package/build-module/components/block-toolbar/switch-section-style.js.map +1 -0
- package/build-module/components/collab/block-comment-icon-slot.js +2 -6
- package/build-module/components/collab/block-comment-icon-slot.js.map +1 -1
- package/build-module/components/collab/block-comment-icon-toolbar-slot.js +2 -6
- package/build-module/components/collab/block-comment-icon-toolbar-slot.js.map +1 -1
- package/build-module/components/color-palette/with-color-context.js +4 -2
- package/build-module/components/color-palette/with-color-context.js.map +1 -1
- package/build-module/components/font-family/index.js +15 -14
- package/build-module/components/font-family/index.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/iframe/index.js +15 -102
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/iframe/use-scale-canvas.js +371 -0
- package/build-module/components/iframe/use-scale-canvas.js.map +1 -0
- package/build-module/components/image-editor/use-save-image.js +22 -3
- package/build-module/components/image-editor/use-save-image.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab/pattern-category-previews.js +1 -5
- package/build-module/components/inserter/block-patterns-tab/pattern-category-previews.js.map +1 -1
- package/build-module/components/inserter/category-tabs/index.js +8 -9
- package/build-module/components/inserter/category-tabs/index.js.map +1 -1
- package/build-module/components/inserter-draggable-blocks/index.js +2 -1
- package/build-module/components/inserter-draggable-blocks/index.js.map +1 -1
- package/build-module/components/inspector-controls/slot.js +7 -4
- package/build-module/components/inspector-controls/slot.js.map +1 -1
- package/build-module/components/inspector-controls-tabs/position-controls-panel.js +1 -1
- package/build-module/components/inspector-controls-tabs/position-controls-panel.js.map +1 -1
- package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js +4 -4
- package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +1 -1
- package/build-module/components/media-placeholder/index.js +29 -21
- package/build-module/components/media-placeholder/index.js.map +1 -1
- package/build-module/hooks/border.js +3 -3
- package/build-module/hooks/border.js.map +1 -1
- package/build-module/hooks/color.js +1 -1
- package/build-module/hooks/color.js.map +1 -1
- package/build-module/hooks/dimensions.js +2 -2
- package/build-module/hooks/dimensions.js.map +1 -1
- package/build-module/hooks/style.js +6 -6
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/hooks/supports.js +1 -1
- package/build-module/hooks/supports.js.map +1 -1
- package/build-module/hooks/typography.js +1 -1
- package/build-module/hooks/typography.js.map +1 -1
- package/build-module/hooks/utils.js +1 -1
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/layouts/flex.js +11 -9
- package/build-module/layouts/flex.js.map +1 -1
- package/build-module/private-apis.js +6 -6
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/private-selectors.js +1 -1
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-module/store/selectors.js +3 -0
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/content-rtl.css +27 -28
- package/build-style/content.css +27 -28
- package/build-style/style-rtl.css +108 -0
- package/build-style/style.css +108 -0
- package/package.json +2 -2
- package/src/components/block-canvas/style.scss +2 -1
- package/src/components/block-controls/slot.js +5 -3
- package/src/components/block-inspector/index.js +0 -2
- package/src/components/block-lock/modal.js +1 -1
- package/src/components/block-manager/category.js +102 -0
- package/src/components/block-manager/checklist.js +34 -0
- package/src/components/block-manager/index.js +127 -0
- package/src/components/block-manager/style.scss +82 -0
- package/src/components/block-mover/README.md +15 -8
- package/src/components/block-mover/stories/index.story.js +73 -71
- package/src/components/block-mover/style.scss +3 -0
- package/src/components/block-settings-menu/block-settings-dropdown.js +2 -2
- package/src/components/block-settings-menu/index.js +2 -2
- package/src/components/block-toolbar/index.js +14 -0
- package/src/components/block-toolbar/switch-section-style.js +115 -0
- package/src/components/block-tools/style.scss +39 -0
- package/src/components/collab/block-comment-icon-slot.js +2 -6
- package/src/components/collab/block-comment-icon-toolbar-slot.js +3 -5
- package/src/components/color-palette/test/__snapshots__/control.js.snap +2 -2
- package/src/components/color-palette/with-color-context.js +25 -7
- package/src/components/font-family/index.js +13 -13
- package/src/components/global-styles/test/use-global-styles-output.js +1 -1
- package/src/components/global-styles/use-global-styles-output.js +1 -1
- package/src/components/iframe/content.scss +49 -43
- package/src/components/iframe/index.js +14 -171
- package/src/components/iframe/use-scale-canvas.js +468 -0
- package/src/components/image-editor/use-save-image.js +27 -2
- package/src/components/inserter/block-patterns-tab/pattern-category-previews.js +7 -16
- package/src/components/inserter/category-tabs/index.js +8 -9
- package/src/components/inserter-draggable-blocks/index.js +10 -1
- package/src/components/inspector-controls/README.md +2 -0
- package/src/components/inspector-controls/slot.js +6 -4
- package/src/components/inspector-controls-tabs/position-controls-panel.js +1 -3
- package/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js +10 -10
- package/src/components/media-placeholder/index.js +37 -33
- package/src/components/provider/test/use-block-sync.js +3 -1
- package/src/components/rich-text/content.scss +15 -10
- package/src/hooks/border.js +3 -9
- package/src/hooks/color.js +1 -1
- package/src/hooks/dimensions.js +2 -2
- package/src/hooks/style.js +6 -12
- package/src/hooks/supports.js +1 -1
- package/src/hooks/test/style.js +1 -2
- package/src/hooks/typography.js +1 -1
- package/src/hooks/utils.js +1 -1
- package/src/layouts/flex.js +26 -18
- package/src/private-apis.js +6 -6
- package/src/store/private-selectors.js +1 -1
- package/src/store/selectors.js +3 -0
- package/src/store/test/selectors.js +87 -58
- package/src/style.scss +1 -0
- package/build/components/block-info-slot-fill/index.js +0 -39
- package/build/components/block-info-slot-fill/index.js.map +0 -1
- package/build-module/components/block-info-slot-fill/index.js +0 -32
- package/build-module/components/block-info-slot-fill/index.js.map +0 -1
- 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
|
|
7
|
-
'
|
|
6
|
+
const CommentIconToolbarSlotFill = createSlotFill(
|
|
7
|
+
Symbol( 'CommentIconToolbarSlotFill' )
|
|
8
8
|
);
|
|
9
9
|
|
|
10
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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 {
|
|
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
|
-
{
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
<
|
|
56
|
+
<CustomSelectControl
|
|
55
57
|
__next40pxDefaultSize={ __next40pxDefaultSize }
|
|
56
|
-
__nextHasNoMarginBottom={ __nextHasNoMarginBottom }
|
|
57
58
|
label={ __( 'Font' ) }
|
|
58
|
-
options={ options }
|
|
59
59
|
value={ value }
|
|
60
|
-
onChange={ onChange }
|
|
61
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
8
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
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"
|
|
357
|
+
<div className="block-editor-iframe__container">
|
|
515
358
|
{ containerResizeListener }
|
|
516
359
|
<div
|
|
517
360
|
className={ clsx(
|