@wordpress/block-library 8.13.0 → 8.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/archives/index.js +5 -1
- package/build/archives/index.js.map +1 -1
- package/build/audio/index.js +5 -1
- package/build/audio/index.js.map +1 -1
- package/build/avatar/index.js +1 -1
- package/build/block/edit.js +1 -1
- package/build/block/edit.js.map +1 -1
- package/build/block/edit.native.js +6 -9
- package/build/block/edit.native.js.map +1 -1
- package/build/buttons/edit.js +5 -1
- package/build/buttons/edit.js.map +1 -1
- package/build/categories/index.js +5 -1
- package/build/categories/index.js.map +1 -1
- package/build/code/index.js +5 -1
- package/build/code/index.js.map +1 -1
- package/build/column/index.js +1 -0
- package/build/column/index.js.map +1 -1
- package/build/comments/index.js +1 -0
- package/build/comments/index.js.map +1 -1
- package/build/cover/edit/inspector-controls.js +2 -1
- package/build/cover/edit/inspector-controls.js.map +1 -1
- package/build/cover/index.js +1 -0
- package/build/cover/index.js.map +1 -1
- package/build/details/index.js +5 -1
- package/build/details/index.js.map +1 -1
- package/build/embed/util.js +9 -8
- package/build/embed/util.js.map +1 -1
- package/build/file/index.js +2 -1
- package/build/file/index.js.map +1 -1
- package/build/file/view.js +15 -1
- package/build/file/view.js.map +1 -1
- package/build/gallery/index.js +3 -1
- package/build/gallery/index.js.map +1 -1
- package/build/group/index.js +1 -0
- package/build/group/index.js.map +1 -1
- package/build/heading/index.js +5 -1
- package/build/heading/index.js.map +1 -1
- package/build/heading/transforms.js +5 -1
- package/build/heading/transforms.js.map +1 -1
- package/build/image/deprecated.js +453 -175
- package/build/image/deprecated.js.map +1 -1
- package/build/image/edit.js +0 -4
- package/build/image/edit.js.map +1 -1
- package/build/image/image.js +96 -43
- package/build/image/image.js.map +1 -1
- package/build/image/index.js +6 -0
- package/build/image/index.js.map +1 -1
- package/build/image/save.js +8 -1
- package/build/image/save.js.map +1 -1
- package/build/image/utils.js +18 -0
- package/build/image/utils.js.map +1 -1
- package/build/image/{interactivity.js → view-interactivity.js} +86 -44
- package/build/image/view-interactivity.js.map +1 -0
- package/build/index.js +12 -3
- package/build/index.js.map +1 -1
- package/build/list/index.js +5 -1
- package/build/list/index.js.map +1 -1
- package/build/list-item/utils.js +6 -1
- package/build/list-item/utils.js.map +1 -1
- package/build/media-text/index.js +1 -0
- package/build/media-text/index.js.map +1 -1
- package/build/missing/edit.js +22 -8
- package/build/missing/edit.js.map +1 -1
- package/build/navigation/edit/index.js +1 -1
- package/build/navigation/edit/index.js.map +1 -1
- package/build/navigation/edit/menu-inspector-controls.js +0 -1
- package/build/navigation/edit/menu-inspector-controls.js.map +1 -1
- package/build/navigation/index.js +3 -2
- package/build/navigation/index.js.map +1 -1
- package/build/navigation/view.js +174 -50
- package/build/navigation/view.js.map +1 -1
- package/build/navigation-link/edit.js +0 -11
- package/build/navigation-link/edit.js.map +1 -1
- package/build/navigation-link/link-ui.js +12 -2
- package/build/navigation-link/link-ui.js.map +1 -1
- package/build/page-list/convert-to-links-modal.js +3 -3
- package/build/page-list/convert-to-links-modal.js.map +1 -1
- package/build/page-list/edit.js +34 -39
- package/build/page-list/edit.js.map +1 -1
- package/build/page-list/use-convert-to-navigation-links.js +2 -15
- package/build/page-list/use-convert-to-navigation-links.js.map +1 -1
- package/build/paragraph/index.js +1 -0
- package/build/paragraph/index.js.map +1 -1
- package/build/paragraph/transforms.js +1 -0
- package/build/paragraph/transforms.js.map +1 -1
- package/build/post-comments-form/index.js +1 -0
- package/build/post-comments-form/index.js.map +1 -1
- package/build/post-navigation-link/index.js +1 -0
- package/build/post-navigation-link/index.js.map +1 -1
- package/build/post-time-to-read/index.js +5 -1
- package/build/post-time-to-read/index.js.map +1 -1
- package/build/query-pagination-numbers/index.js +1 -1
- package/build/quote/index.js +1 -0
- package/build/quote/index.js.map +1 -1
- package/build/site-logo/index.js +5 -1
- package/build/site-logo/index.js.map +1 -1
- package/build/site-tagline/icon.js +1 -1
- package/build/site-tagline/icon.js.map +1 -1
- package/build/site-tagline/index.js +5 -1
- package/build/site-tagline/index.js.map +1 -1
- package/build/site-title/index.js +5 -1
- package/build/site-title/index.js.map +1 -1
- package/build/social-links/index.js +3 -1
- package/build/social-links/index.js.map +1 -1
- package/build/table/index.js +5 -1
- package/build/table/index.js.map +1 -1
- package/build/term-description/index.js +1 -0
- package/build/term-description/index.js.map +1 -1
- package/build/verse/index.js +5 -1
- package/build/verse/index.js.map +1 -1
- package/build/video/deprecated.js +5 -1
- package/build/video/deprecated.js.map +1 -1
- package/build/video/index.js +5 -1
- package/build/video/index.js.map +1 -1
- package/build-module/archives/index.js +5 -1
- package/build-module/archives/index.js.map +1 -1
- package/build-module/audio/index.js +5 -1
- package/build-module/audio/index.js.map +1 -1
- package/build-module/avatar/index.js +1 -1
- package/build-module/block/edit.js +1 -1
- package/build-module/block/edit.js.map +1 -1
- package/build-module/block/edit.native.js +7 -9
- package/build-module/block/edit.native.js.map +1 -1
- package/build-module/buttons/edit.js +5 -1
- package/build-module/buttons/edit.js.map +1 -1
- package/build-module/categories/index.js +5 -1
- package/build-module/categories/index.js.map +1 -1
- package/build-module/code/index.js +5 -1
- package/build-module/code/index.js.map +1 -1
- package/build-module/column/index.js +1 -0
- package/build-module/column/index.js.map +1 -1
- package/build-module/comments/index.js +1 -0
- package/build-module/comments/index.js.map +1 -1
- package/build-module/cover/edit/inspector-controls.js +2 -1
- package/build-module/cover/edit/inspector-controls.js.map +1 -1
- package/build-module/cover/index.js +1 -0
- package/build-module/cover/index.js.map +1 -1
- package/build-module/details/index.js +5 -1
- package/build-module/details/index.js.map +1 -1
- package/build-module/embed/util.js +6 -6
- package/build-module/embed/util.js.map +1 -1
- package/build-module/file/index.js +2 -1
- package/build-module/file/index.js.map +1 -1
- package/build-module/file/view.js +15 -2
- package/build-module/file/view.js.map +1 -1
- package/build-module/gallery/index.js +3 -1
- package/build-module/gallery/index.js.map +1 -1
- package/build-module/group/index.js +1 -0
- package/build-module/group/index.js.map +1 -1
- package/build-module/heading/index.js +5 -1
- package/build-module/heading/index.js.map +1 -1
- package/build-module/heading/transforms.js +5 -1
- package/build-module/heading/transforms.js.map +1 -1
- package/build-module/image/deprecated.js +454 -176
- package/build-module/image/deprecated.js.map +1 -1
- package/build-module/image/edit.js +0 -4
- package/build-module/image/edit.js.map +1 -1
- package/build-module/image/image.js +96 -46
- package/build-module/image/image.js.map +1 -1
- package/build-module/image/index.js +6 -0
- package/build-module/image/index.js.map +1 -1
- package/build-module/image/save.js +8 -1
- package/build-module/image/save.js.map +1 -1
- package/build-module/image/utils.js +16 -0
- package/build-module/image/utils.js.map +1 -1
- package/build-module/image/{interactivity.js → view-interactivity.js} +86 -44
- package/build-module/image/view-interactivity.js.map +1 -0
- package/build-module/index.js +12 -3
- package/build-module/index.js.map +1 -1
- package/build-module/list/index.js +5 -1
- package/build-module/list/index.js.map +1 -1
- package/build-module/list-item/utils.js +6 -1
- package/build-module/list-item/utils.js.map +1 -1
- package/build-module/media-text/index.js +1 -0
- package/build-module/media-text/index.js.map +1 -1
- package/build-module/missing/edit.js +22 -8
- package/build-module/missing/edit.js.map +1 -1
- package/build-module/navigation/edit/index.js +1 -1
- package/build-module/navigation/edit/index.js.map +1 -1
- package/build-module/navigation/edit/menu-inspector-controls.js +0 -1
- package/build-module/navigation/edit/menu-inspector-controls.js.map +1 -1
- package/build-module/navigation/index.js +3 -2
- package/build-module/navigation/index.js.map +1 -1
- package/build-module/navigation/view.js +173 -50
- package/build-module/navigation/view.js.map +1 -1
- package/build-module/navigation-link/edit.js +1 -12
- package/build-module/navigation-link/edit.js.map +1 -1
- package/build-module/navigation-link/link-ui.js +13 -3
- package/build-module/navigation-link/link-ui.js.map +1 -1
- package/build-module/page-list/convert-to-links-modal.js +3 -3
- package/build-module/page-list/convert-to-links-modal.js.map +1 -1
- package/build-module/page-list/edit.js +34 -39
- package/build-module/page-list/edit.js.map +1 -1
- package/build-module/page-list/use-convert-to-navigation-links.js +3 -16
- package/build-module/page-list/use-convert-to-navigation-links.js.map +1 -1
- package/build-module/paragraph/index.js +1 -0
- package/build-module/paragraph/index.js.map +1 -1
- package/build-module/paragraph/transforms.js +1 -0
- package/build-module/paragraph/transforms.js.map +1 -1
- package/build-module/post-comments-form/index.js +1 -0
- package/build-module/post-comments-form/index.js.map +1 -1
- package/build-module/post-navigation-link/index.js +1 -0
- package/build-module/post-navigation-link/index.js.map +1 -1
- package/build-module/post-time-to-read/index.js +5 -1
- package/build-module/post-time-to-read/index.js.map +1 -1
- package/build-module/query-pagination-numbers/index.js +1 -1
- package/build-module/quote/index.js +1 -0
- package/build-module/quote/index.js.map +1 -1
- package/build-module/site-logo/index.js +5 -1
- package/build-module/site-logo/index.js.map +1 -1
- package/build-module/site-tagline/icon.js +1 -1
- package/build-module/site-tagline/icon.js.map +1 -1
- package/build-module/site-tagline/index.js +5 -1
- package/build-module/site-tagline/index.js.map +1 -1
- package/build-module/site-title/index.js +5 -1
- package/build-module/site-title/index.js.map +1 -1
- package/build-module/social-links/index.js +3 -1
- package/build-module/social-links/index.js.map +1 -1
- package/build-module/table/index.js +5 -1
- package/build-module/table/index.js.map +1 -1
- package/build-module/term-description/index.js +1 -0
- package/build-module/term-description/index.js.map +1 -1
- package/build-module/verse/index.js +5 -1
- package/build-module/verse/index.js.map +1 -1
- package/build-module/video/deprecated.js +5 -1
- package/build-module/video/deprecated.js.map +1 -1
- package/build-module/video/index.js +5 -1
- package/build-module/video/index.js.map +1 -1
- package/build-style/footnotes/style-rtl.css +2 -2
- package/build-style/footnotes/style.css +2 -2
- package/build-style/image/style-rtl.css +16 -2
- package/build-style/image/style.css +16 -2
- package/build-style/style-rtl.css +18 -4
- package/build-style/style.css +18 -4
- package/package.json +33 -38
- package/src/archives/block.json +5 -1
- package/src/audio/block.json +5 -1
- package/src/avatar/block.json +1 -1
- package/src/block/edit.js +2 -2
- package/src/block/edit.native.js +8 -12
- package/src/block/test/edit.native.js +4 -4
- package/src/buttons/edit.js +2 -2
- package/src/categories/block.json +5 -1
- package/src/code/block.json +5 -1
- package/src/column/block.json +1 -0
- package/src/comments/block.json +1 -0
- package/src/cover/block.json +1 -0
- package/src/cover/edit/inspector-controls.js +1 -0
- package/src/details/block.json +5 -1
- package/src/embed/util.js +4 -6
- package/src/file/block.json +2 -1
- package/src/file/index.php +0 -17
- package/src/file/view.js +14 -5
- package/src/footnotes/index.php +11 -9
- package/src/footnotes/style.scss +2 -2
- package/src/gallery/block.json +3 -1
- package/src/group/block.json +1 -0
- package/src/heading/block.json +5 -1
- package/src/heading/test/index.native.js +18 -0
- package/src/image/block.json +6 -0
- package/src/image/deprecated.js +597 -320
- package/src/image/edit.js +0 -4
- package/src/image/image.js +131 -62
- package/src/image/save.js +9 -1
- package/src/image/style.scss +15 -2
- package/src/image/utils.js +16 -0
- package/src/image/{interactivity.js → view-interactivity.js} +99 -50
- package/src/index.js +18 -1
- package/src/latest-posts/index.php +1 -1
- package/src/list/block.json +5 -1
- package/src/media-text/block.json +1 -0
- package/src/missing/edit.js +31 -11
- package/src/navigation/block.json +3 -2
- package/src/navigation/edit/index.js +1 -2
- package/src/navigation/edit/menu-inspector-controls.js +0 -1
- package/src/navigation/index.php +39 -30
- package/src/navigation/view.js +189 -67
- package/src/navigation-link/edit.js +1 -15
- package/src/navigation-link/link-ui.js +14 -2
- package/src/navigation-submenu/index.php +2 -12
- package/src/page-list/convert-to-links-modal.js +3 -3
- package/src/page-list/edit.js +65 -62
- package/src/page-list/use-convert-to-navigation-links.js +3 -20
- package/src/paragraph/block.json +1 -0
- package/src/post-comments-form/block.json +1 -0
- package/src/post-navigation-link/block.json +1 -0
- package/src/post-time-to-read/block.json +5 -1
- package/src/query-pagination-numbers/block.json +1 -1
- package/src/quote/block.json +1 -0
- package/src/site-logo/block.json +5 -1
- package/src/site-tagline/block.json +5 -1
- package/src/site-tagline/icon.js +1 -1
- package/src/site-title/block.json +5 -1
- package/src/social-links/block.json +3 -1
- package/src/table/block.json +5 -1
- package/src/term-description/block.json +1 -0
- package/src/verse/block.json +5 -1
- package/src/video/block.json +5 -1
- package/build/file/interactivity.js +0 -19
- package/build/file/interactivity.js.map +0 -1
- package/build/heading/heading-level-icon.js +0 -61
- package/build/heading/heading-level-icon.js.map +0 -1
- package/build/image/interactivity.js.map +0 -1
- package/build/navigation/interactivity.js +0 -167
- package/build/navigation/interactivity.js.map +0 -1
- package/build/navigation/view-modal.js +0 -64
- package/build/navigation/view-modal.js.map +0 -1
- package/build/utils/interactivity/constants.js +0 -9
- package/build/utils/interactivity/constants.js.map +0 -1
- package/build/utils/interactivity/directives.js +0 -222
- package/build/utils/interactivity/directives.js.map +0 -1
- package/build/utils/interactivity/hooks.js +0 -159
- package/build/utils/interactivity/hooks.js.map +0 -1
- package/build/utils/interactivity/hydration.js +0 -34
- package/build/utils/interactivity/hydration.js.map +0 -1
- package/build/utils/interactivity/index.js +0 -32
- package/build/utils/interactivity/index.js.map +0 -1
- package/build/utils/interactivity/portals.js +0 -108
- package/build/utils/interactivity/portals.js.map +0 -1
- package/build/utils/interactivity/store.js +0 -66
- package/build/utils/interactivity/store.js.map +0 -1
- package/build/utils/interactivity/utils.js +0 -87
- package/build/utils/interactivity/utils.js.map +0 -1
- package/build/utils/interactivity/vdom.js +0 -119
- package/build/utils/interactivity/vdom.js.map +0 -1
- package/build-module/file/interactivity.js +0 -15
- package/build-module/file/interactivity.js.map +0 -1
- package/build-module/heading/heading-level-icon.js +0 -53
- package/build-module/heading/heading-level-icon.js.map +0 -1
- package/build-module/image/interactivity.js.map +0 -1
- package/build-module/navigation/interactivity.js +0 -164
- package/build-module/navigation/interactivity.js.map +0 -1
- package/build-module/navigation/view-modal.js +0 -58
- package/build-module/navigation/view-modal.js.map +0 -1
- package/build-module/utils/interactivity/constants.js +0 -2
- package/build-module/utils/interactivity/constants.js.map +0 -1
- package/build-module/utils/interactivity/directives.js +0 -209
- package/build-module/utils/interactivity/directives.js.map +0 -1
- package/build-module/utils/interactivity/hooks.js +0 -145
- package/build-module/utils/interactivity/hooks.js.map +0 -1
- package/build-module/utils/interactivity/hydration.js +0 -21
- package/build-module/utils/interactivity/hydration.js.map +0 -1
- package/build-module/utils/interactivity/index.js +0 -15
- package/build-module/utils/interactivity/index.js.map +0 -1
- package/build-module/utils/interactivity/portals.js +0 -100
- package/build-module/utils/interactivity/portals.js.map +0 -1
- package/build-module/utils/interactivity/store.js +0 -55
- package/build-module/utils/interactivity/store.js.map +0 -1
- package/build-module/utils/interactivity/utils.js +0 -75
- package/build-module/utils/interactivity/utils.js.map +0 -1
- package/build-module/utils/interactivity/vdom.js +0 -107
- package/build-module/utils/interactivity/vdom.js.map +0 -1
- package/src/file/interactivity.js +0 -15
- package/src/heading/heading-level-icon.js +0 -48
- package/src/navigation/interactivity.js +0 -169
- package/src/navigation/view-modal.js +0 -78
- package/src/utils/interactivity/constants.js +0 -1
- package/src/utils/interactivity/directives.js +0 -200
- package/src/utils/interactivity/hooks.js +0 -145
- package/src/utils/interactivity/hydration.js +0 -22
- package/src/utils/interactivity/index.js +0 -15
- package/src/utils/interactivity/portals.js +0 -98
- package/src/utils/interactivity/store.js +0 -45
- package/src/utils/interactivity/utils.js +0 -66
- package/src/utils/interactivity/vdom.js +0 -111
package/src/image/edit.js
CHANGED
|
@@ -183,8 +183,6 @@ export function ImageEdit( {
|
|
|
183
183
|
// Reset the dimension attributes if changing to a different image.
|
|
184
184
|
if ( ! media.id || media.id !== id ) {
|
|
185
185
|
additionalAttributes = {
|
|
186
|
-
width: undefined,
|
|
187
|
-
height: undefined,
|
|
188
186
|
// Fallback to size "full" if there's no default image size.
|
|
189
187
|
// It means the image is smaller, and the block will use a full-size URL.
|
|
190
188
|
sizeSlug: hasDefaultSize( media, imageDefaultSize )
|
|
@@ -248,8 +246,6 @@ export function ImageEdit( {
|
|
|
248
246
|
setAttributes( {
|
|
249
247
|
url: newURL,
|
|
250
248
|
id: undefined,
|
|
251
|
-
width: undefined,
|
|
252
|
-
height: undefined,
|
|
253
249
|
sizeSlug: imageDefaultSize,
|
|
254
250
|
} );
|
|
255
251
|
}
|
package/src/image/image.js
CHANGED
|
@@ -4,13 +4,15 @@
|
|
|
4
4
|
import { isBlobURL } from '@wordpress/blob';
|
|
5
5
|
import {
|
|
6
6
|
ExternalLink,
|
|
7
|
-
PanelBody,
|
|
8
7
|
ResizableBox,
|
|
9
8
|
Spinner,
|
|
10
9
|
TextareaControl,
|
|
11
10
|
TextControl,
|
|
12
11
|
ToolbarButton,
|
|
13
12
|
ToolbarGroup,
|
|
13
|
+
__experimentalToolsPanel as ToolsPanel,
|
|
14
|
+
__experimentalToolsPanelItem as ToolsPanelItem,
|
|
15
|
+
__experimentalUseCustomUnits as useCustomUnits,
|
|
14
16
|
} from '@wordpress/components';
|
|
15
17
|
import { useViewportMatch, usePrevious } from '@wordpress/compose';
|
|
16
18
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
@@ -18,7 +20,6 @@ import {
|
|
|
18
20
|
BlockControls,
|
|
19
21
|
InspectorControls,
|
|
20
22
|
RichText,
|
|
21
|
-
__experimentalImageSizeControl as ImageSizeControl,
|
|
22
23
|
__experimentalImageURLInputUI as ImageURLInputUI,
|
|
23
24
|
MediaReplaceFlow,
|
|
24
25
|
store as blockEditorStore,
|
|
@@ -26,6 +27,7 @@ import {
|
|
|
26
27
|
__experimentalImageEditor as ImageEditor,
|
|
27
28
|
__experimentalGetElementClassName,
|
|
28
29
|
__experimentalUseBorderProps as useBorderProps,
|
|
30
|
+
privateApis as blockEditorPrivateApis,
|
|
29
31
|
} from '@wordpress/block-editor';
|
|
30
32
|
import {
|
|
31
33
|
useEffect,
|
|
@@ -34,7 +36,7 @@ import {
|
|
|
34
36
|
useRef,
|
|
35
37
|
useCallback,
|
|
36
38
|
} from '@wordpress/element';
|
|
37
|
-
import { __, sprintf, isRTL } from '@wordpress/i18n';
|
|
39
|
+
import { __, _x, sprintf, isRTL } from '@wordpress/i18n';
|
|
38
40
|
import { getFilename } from '@wordpress/url';
|
|
39
41
|
import {
|
|
40
42
|
createBlock,
|
|
@@ -53,6 +55,7 @@ import { store as coreStore } from '@wordpress/core-data';
|
|
|
53
55
|
/**
|
|
54
56
|
* Internal dependencies
|
|
55
57
|
*/
|
|
58
|
+
import { unlock } from '../lock-unlock';
|
|
56
59
|
import { createUpgradedEmbedBlock } from '../embed/util';
|
|
57
60
|
import useClientWidth from './use-client-width';
|
|
58
61
|
import { isExternalImage } from './edit';
|
|
@@ -61,6 +64,22 @@ import { isExternalImage } from './edit';
|
|
|
61
64
|
* Module constants
|
|
62
65
|
*/
|
|
63
66
|
import { MIN_SIZE, ALLOWED_MEDIA_TYPES } from './constants';
|
|
67
|
+
import { evalAspectRatio } from './utils';
|
|
68
|
+
|
|
69
|
+
const { DimensionsTool, ResolutionTool } = unlock( blockEditorPrivateApis );
|
|
70
|
+
|
|
71
|
+
const scaleOptions = [
|
|
72
|
+
{
|
|
73
|
+
value: 'cover',
|
|
74
|
+
label: _x( 'Cover', 'Scale option for dimensions control' ),
|
|
75
|
+
help: __( 'Image covers the space evenly.' ),
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
value: 'contain',
|
|
79
|
+
label: _x( 'Contain', 'Scale option for dimensions control' ),
|
|
80
|
+
help: __( 'Image is contained without distortion.' ),
|
|
81
|
+
},
|
|
82
|
+
];
|
|
64
83
|
|
|
65
84
|
export default function Image( {
|
|
66
85
|
temporaryURL,
|
|
@@ -90,6 +109,8 @@ export default function Image( {
|
|
|
90
109
|
title,
|
|
91
110
|
width,
|
|
92
111
|
height,
|
|
112
|
+
aspectRatio,
|
|
113
|
+
scale,
|
|
93
114
|
linkTarget,
|
|
94
115
|
sizeSlug,
|
|
95
116
|
} = attributes;
|
|
@@ -272,8 +293,6 @@ export default function Image( {
|
|
|
272
293
|
|
|
273
294
|
setAttributes( {
|
|
274
295
|
url: newUrl,
|
|
275
|
-
width: undefined,
|
|
276
|
-
height: undefined,
|
|
277
296
|
sizeSlug: newSizeSlug,
|
|
278
297
|
} );
|
|
279
298
|
}
|
|
@@ -329,6 +348,13 @@ export default function Image( {
|
|
|
329
348
|
);
|
|
330
349
|
}
|
|
331
350
|
|
|
351
|
+
// TODO: Can allow more units after figuring out how they should interact
|
|
352
|
+
// with the ResizableBox and ImageEditor components. Calculations later on
|
|
353
|
+
// for those components are currently assuming px units.
|
|
354
|
+
const dimensionsUnitsOptions = useCustomUnits( {
|
|
355
|
+
availableUnits: [ 'px' ],
|
|
356
|
+
} );
|
|
357
|
+
|
|
332
358
|
const controls = (
|
|
333
359
|
<>
|
|
334
360
|
<BlockControls group="block">
|
|
@@ -407,41 +433,78 @@ export default function Image( {
|
|
|
407
433
|
</BlockControls>
|
|
408
434
|
) }
|
|
409
435
|
<InspectorControls>
|
|
410
|
-
<
|
|
436
|
+
<ToolsPanel
|
|
437
|
+
label={ __( 'Settings' ) }
|
|
438
|
+
resetAll={ () =>
|
|
439
|
+
setAttributes( {
|
|
440
|
+
width: undefined,
|
|
441
|
+
height: undefined,
|
|
442
|
+
scale: undefined,
|
|
443
|
+
aspectRatio: undefined,
|
|
444
|
+
} )
|
|
445
|
+
}
|
|
446
|
+
>
|
|
411
447
|
{ ! multiImageSelection && (
|
|
412
|
-
<
|
|
413
|
-
__nextHasNoMarginBottom
|
|
448
|
+
<ToolsPanelItem
|
|
414
449
|
label={ __( 'Alternative text' ) }
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
<ExternalLink href="https://www.w3.org/WAI/tutorials/images/decision-tree">
|
|
420
|
-
{ __(
|
|
421
|
-
'Describe the purpose of the image.'
|
|
422
|
-
) }
|
|
423
|
-
</ExternalLink>
|
|
424
|
-
<br />
|
|
425
|
-
{ __( 'Leave empty if decorative.' ) }
|
|
426
|
-
</>
|
|
450
|
+
isShownByDefault={ true }
|
|
451
|
+
hasValue={ () => alt !== '' }
|
|
452
|
+
onDeselect={ () =>
|
|
453
|
+
setAttributes( { alt: undefined } )
|
|
427
454
|
}
|
|
428
|
-
|
|
455
|
+
>
|
|
456
|
+
<TextareaControl
|
|
457
|
+
label={ __( 'Alternative text' ) }
|
|
458
|
+
value={ alt }
|
|
459
|
+
onChange={ updateAlt }
|
|
460
|
+
help={
|
|
461
|
+
<>
|
|
462
|
+
<ExternalLink href="https://www.w3.org/WAI/tutorials/images/decision-tree">
|
|
463
|
+
{ __(
|
|
464
|
+
'Describe the purpose of the image.'
|
|
465
|
+
) }
|
|
466
|
+
</ExternalLink>
|
|
467
|
+
<br />
|
|
468
|
+
{ __( 'Leave empty if decorative.' ) }
|
|
469
|
+
</>
|
|
470
|
+
}
|
|
471
|
+
__nextHasNoMarginBottom
|
|
472
|
+
/>
|
|
473
|
+
</ToolsPanelItem>
|
|
429
474
|
) }
|
|
430
|
-
<
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
475
|
+
<DimensionsTool
|
|
476
|
+
value={ {
|
|
477
|
+
width: width && `${ width }px`,
|
|
478
|
+
height: height && `${ height }px`,
|
|
479
|
+
scale,
|
|
480
|
+
aspectRatio,
|
|
481
|
+
} }
|
|
482
|
+
onChange={ ( newValue ) => {
|
|
483
|
+
// Rebuilding the object forces setting `undefined`
|
|
484
|
+
// for values that are removed since setAttributes
|
|
485
|
+
// doesn't do anything with keys that aren't set.
|
|
486
|
+
setAttributes( {
|
|
487
|
+
width:
|
|
488
|
+
newValue.width &&
|
|
489
|
+
parseInt( newValue.width, 10 ),
|
|
490
|
+
height:
|
|
491
|
+
newValue.height &&
|
|
492
|
+
parseInt( newValue.height, 10 ),
|
|
493
|
+
scale: newValue.scale,
|
|
494
|
+
aspectRatio: newValue.aspectRatio,
|
|
495
|
+
} );
|
|
496
|
+
} }
|
|
497
|
+
defaultScale="cover"
|
|
498
|
+
defaultAspectRatio="auto"
|
|
499
|
+
scaleOptions={ scaleOptions }
|
|
500
|
+
unitsOptions={ dimensionsUnitsOptions }
|
|
501
|
+
/>
|
|
502
|
+
<ResolutionTool
|
|
503
|
+
value={ sizeSlug }
|
|
504
|
+
onChange={ updateImage }
|
|
505
|
+
options={ imageSizeOptions }
|
|
443
506
|
/>
|
|
444
|
-
</
|
|
507
|
+
</ToolsPanel>
|
|
445
508
|
</InspectorControls>
|
|
446
509
|
<InspectorControls group="advanced">
|
|
447
510
|
<TextControl
|
|
@@ -483,9 +546,6 @@ export default function Image( {
|
|
|
483
546
|
|
|
484
547
|
const borderProps = useBorderProps( attributes );
|
|
485
548
|
const isRounded = attributes.className?.includes( 'is-style-rounded' );
|
|
486
|
-
const hasCustomBorder =
|
|
487
|
-
!! borderProps.className ||
|
|
488
|
-
( borderProps.style && Object.keys( borderProps.style ).length > 0 );
|
|
489
549
|
|
|
490
550
|
let img = (
|
|
491
551
|
// Disable reason: Image itself is not meant to be interactive, but
|
|
@@ -504,25 +564,20 @@ export default function Image( {
|
|
|
504
564
|
} }
|
|
505
565
|
ref={ imageRef }
|
|
506
566
|
className={ borderProps.className }
|
|
507
|
-
style={
|
|
567
|
+
style={ {
|
|
568
|
+
width:
|
|
569
|
+
( width && height ) || aspectRatio ? '100%' : 'inherit',
|
|
570
|
+
height:
|
|
571
|
+
( width && height ) || aspectRatio ? '100%' : 'inherit',
|
|
572
|
+
objectFit: scale,
|
|
573
|
+
...borderProps.style,
|
|
574
|
+
} }
|
|
508
575
|
/>
|
|
509
576
|
{ temporaryURL && <Spinner /> }
|
|
510
577
|
</>
|
|
511
578
|
/* eslint-enable jsx-a11y/no-noninteractive-element-interactions, jsx-a11y/click-events-have-key-events */
|
|
512
579
|
);
|
|
513
580
|
|
|
514
|
-
let imageWidthWithinContainer;
|
|
515
|
-
let imageHeightWithinContainer;
|
|
516
|
-
|
|
517
|
-
if ( clientWidth && naturalWidth && naturalHeight ) {
|
|
518
|
-
const exceedMaxWidth = naturalWidth > clientWidth;
|
|
519
|
-
const ratio = naturalHeight / naturalWidth;
|
|
520
|
-
imageWidthWithinContainer = exceedMaxWidth ? clientWidth : naturalWidth;
|
|
521
|
-
imageHeightWithinContainer = exceedMaxWidth
|
|
522
|
-
? clientWidth * ratio
|
|
523
|
-
: naturalHeight;
|
|
524
|
-
}
|
|
525
|
-
|
|
526
581
|
// clientWidth needs to be a number for the image Cropper to work, but sometimes it's 0
|
|
527
582
|
// So we try using the imageRef width first and fallback to clientWidth.
|
|
528
583
|
const fallbackClientWidth = imageRef.current?.width || clientWidth;
|
|
@@ -546,13 +601,18 @@ export default function Image( {
|
|
|
546
601
|
borderProps={ isRounded ? undefined : borderProps }
|
|
547
602
|
/>
|
|
548
603
|
);
|
|
549
|
-
} else if ( ! isResizable
|
|
550
|
-
img = <div style={ { width, height } }>{ img }</div>;
|
|
604
|
+
} else if ( ! isResizable ) {
|
|
605
|
+
img = <div style={ { width, height, aspectRatio } }>{ img }</div>;
|
|
551
606
|
} else {
|
|
552
|
-
const
|
|
553
|
-
|
|
607
|
+
const ratio =
|
|
608
|
+
( aspectRatio && evalAspectRatio( aspectRatio ) ) ||
|
|
609
|
+
( width && height && width / height ) ||
|
|
610
|
+
naturalWidth / naturalHeight ||
|
|
611
|
+
1;
|
|
612
|
+
|
|
613
|
+
const currentWidth = ! width && height ? height * ratio : width;
|
|
614
|
+
const currentHeight = ! height && width ? width / ratio : height;
|
|
554
615
|
|
|
555
|
-
const ratio = naturalWidth / naturalHeight;
|
|
556
616
|
const minWidth =
|
|
557
617
|
naturalWidth < naturalHeight ? MIN_SIZE : MIN_SIZE * ratio;
|
|
558
618
|
const minHeight =
|
|
@@ -600,16 +660,24 @@ export default function Image( {
|
|
|
600
660
|
|
|
601
661
|
img = (
|
|
602
662
|
<ResizableBox
|
|
663
|
+
style={ {
|
|
664
|
+
display: 'block',
|
|
665
|
+
objectFit: scale,
|
|
666
|
+
aspectRatio:
|
|
667
|
+
! width && ! height && aspectRatio
|
|
668
|
+
? aspectRatio
|
|
669
|
+
: undefined,
|
|
670
|
+
} }
|
|
603
671
|
size={ {
|
|
604
|
-
width:
|
|
605
|
-
height:
|
|
672
|
+
width: currentWidth ?? 'auto',
|
|
673
|
+
height: currentHeight ?? 'auto',
|
|
606
674
|
} }
|
|
607
675
|
showHandle={ isSelected }
|
|
608
676
|
minWidth={ minWidth }
|
|
609
677
|
maxWidth={ maxWidthBuffer }
|
|
610
678
|
minHeight={ minHeight }
|
|
611
679
|
maxHeight={ maxWidthBuffer / ratio }
|
|
612
|
-
lockAspectRatio
|
|
680
|
+
lockAspectRatio={ ratio }
|
|
613
681
|
enable={ {
|
|
614
682
|
top: false,
|
|
615
683
|
right: showRightHandle,
|
|
@@ -617,11 +685,12 @@ export default function Image( {
|
|
|
617
685
|
left: showLeftHandle,
|
|
618
686
|
} }
|
|
619
687
|
onResizeStart={ onResizeStart }
|
|
620
|
-
onResizeStop={ ( event, direction, elt
|
|
688
|
+
onResizeStop={ ( event, direction, elt ) => {
|
|
621
689
|
onResizeStop();
|
|
622
690
|
setAttributes( {
|
|
623
|
-
width:
|
|
624
|
-
height:
|
|
691
|
+
width: elt.offsetWidth,
|
|
692
|
+
height: elt.offsetHeight,
|
|
693
|
+
aspectRatio: undefined,
|
|
625
694
|
} );
|
|
626
695
|
} }
|
|
627
696
|
resizeRatio={ align === 'center' ? 2 : 1 }
|
package/src/image/save.js
CHANGED
|
@@ -24,6 +24,8 @@ export default function save( { attributes } ) {
|
|
|
24
24
|
linkClass,
|
|
25
25
|
width,
|
|
26
26
|
height,
|
|
27
|
+
aspectRatio,
|
|
28
|
+
scale,
|
|
27
29
|
id,
|
|
28
30
|
linkTarget,
|
|
29
31
|
sizeSlug,
|
|
@@ -52,7 +54,13 @@ export default function save( { attributes } ) {
|
|
|
52
54
|
src={ url }
|
|
53
55
|
alt={ alt }
|
|
54
56
|
className={ imageClasses || undefined }
|
|
55
|
-
style={
|
|
57
|
+
style={ {
|
|
58
|
+
...borderProps.style,
|
|
59
|
+
aspectRatio,
|
|
60
|
+
objectFit: scale,
|
|
61
|
+
width,
|
|
62
|
+
height,
|
|
63
|
+
} }
|
|
56
64
|
width={ width }
|
|
57
65
|
height={ height }
|
|
58
66
|
title={ title }
|
package/src/image/style.scss
CHANGED
|
@@ -184,11 +184,12 @@
|
|
|
184
184
|
width: 100vw;
|
|
185
185
|
height: 100vh;
|
|
186
186
|
visibility: hidden;
|
|
187
|
+
cursor: zoom-out;
|
|
187
188
|
|
|
188
189
|
.close-button {
|
|
189
190
|
position: absolute;
|
|
190
|
-
top: 12.5px;
|
|
191
|
-
right: 12.5px;
|
|
191
|
+
top: calc(env(safe-area-inset-top) + 12.5px);
|
|
192
|
+
right: calc(env(safe-area-inset-right) + 12.5px);
|
|
192
193
|
padding: 0;
|
|
193
194
|
cursor: pointer;
|
|
194
195
|
z-index: 5000000;
|
|
@@ -231,6 +232,18 @@
|
|
|
231
232
|
}
|
|
232
233
|
|
|
233
234
|
&.fade {
|
|
235
|
+
.wp-block-image {
|
|
236
|
+
padding: 40px 0;
|
|
237
|
+
|
|
238
|
+
@media screen and (min-width: 480px) {
|
|
239
|
+
padding: 40px;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
@media screen and (min-width: 1920px) {
|
|
243
|
+
padding: 40px 80px;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
234
247
|
&.active {
|
|
235
248
|
visibility: visible;
|
|
236
249
|
animation: both turn-on-visibility 0.25s;
|
package/src/image/utils.js
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { NEW_TAB_REL } from './constants';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Evaluates a CSS aspect-ratio property value as a number.
|
|
8
|
+
*
|
|
9
|
+
* Degenerate or invalid ratios behave as 'auto'. And 'auto' ratios return NaN.
|
|
10
|
+
*
|
|
11
|
+
* @see https://drafts.csswg.org/css-sizing-4/#aspect-ratio
|
|
12
|
+
*
|
|
13
|
+
* @param {string} value CSS aspect-ratio property value.
|
|
14
|
+
* @return {number} Numerical aspect ratio or NaN if invalid.
|
|
15
|
+
*/
|
|
16
|
+
export function evalAspectRatio( value ) {
|
|
17
|
+
const [ width, height = 1 ] = value.split( '/' ).map( Number );
|
|
18
|
+
const aspectRatio = width / height;
|
|
19
|
+
return aspectRatio === Infinity || aspectRatio === 0 ? NaN : aspectRatio;
|
|
20
|
+
}
|
|
21
|
+
|
|
6
22
|
export function removeNewTabRel( currentRel ) {
|
|
7
23
|
let newRel = currentRel;
|
|
8
24
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { store } from '
|
|
4
|
+
import { store } from '@wordpress/interactivity';
|
|
5
5
|
|
|
6
6
|
const focusableSelectors = [
|
|
7
7
|
'a[href]',
|
|
@@ -22,32 +22,43 @@ store( {
|
|
|
22
22
|
core: {
|
|
23
23
|
image: {
|
|
24
24
|
showLightbox: ( { context, event } ) => {
|
|
25
|
+
// We can't initialize the lightbox until the reference
|
|
26
|
+
// image is loaded, otherwise the UX is broken.
|
|
27
|
+
if ( ! context.core.image.imageLoaded ) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
25
30
|
context.core.image.initialized = true;
|
|
26
31
|
context.core.image.lastFocusedElement =
|
|
27
32
|
window.document.activeElement;
|
|
28
33
|
context.core.image.scrollDelta = 0;
|
|
29
34
|
|
|
35
|
+
context.core.image.lightboxEnabled = true;
|
|
36
|
+
if ( context.core.image.lightboxAnimation === 'zoom' ) {
|
|
37
|
+
setZoomStyles(
|
|
38
|
+
event.target.nextElementSibling,
|
|
39
|
+
context,
|
|
40
|
+
event
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
// Hide overflow only when the animation is in progress,
|
|
44
|
+
// otherwise the removal of the scrollbars will draw attention
|
|
45
|
+
// to itself and look like an error
|
|
46
|
+
document.documentElement.classList.add(
|
|
47
|
+
'has-lightbox-open'
|
|
48
|
+
);
|
|
49
|
+
|
|
30
50
|
// Since the img is hidden and its src not loaded until
|
|
31
51
|
// the lightbox is opened, let's create an img element on the fly
|
|
32
52
|
// so we can get the dimensions we need to calculate the styles
|
|
53
|
+
context.core.image.preloadInitialized = true;
|
|
33
54
|
const imgDom = document.createElement( 'img' );
|
|
34
|
-
|
|
35
55
|
imgDom.onload = function () {
|
|
36
|
-
|
|
37
|
-
// is loaded to prevent flashing of unstyled content
|
|
38
|
-
context.core.image.lightboxEnabled = true;
|
|
39
|
-
if ( context.core.image.lightboxAnimation === 'zoom' ) {
|
|
40
|
-
setZoomStyles( imgDom, context, event );
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Hide overflow only when the animation is in progress,
|
|
44
|
-
// otherwise the removal of the scrollbars will draw attention
|
|
45
|
-
// to itself and look like an error
|
|
46
|
-
document.documentElement.classList.add(
|
|
47
|
-
'has-lightbox-open'
|
|
48
|
-
);
|
|
56
|
+
context.core.image.activateLargeImage = true;
|
|
49
57
|
};
|
|
50
|
-
imgDom.setAttribute(
|
|
58
|
+
imgDom.setAttribute(
|
|
59
|
+
'src',
|
|
60
|
+
context.core.image.imageUploadedSrc
|
|
61
|
+
);
|
|
51
62
|
},
|
|
52
63
|
hideLightbox: async ( { context, event } ) => {
|
|
53
64
|
context.core.image.hideAnimationEnabled = true;
|
|
@@ -122,6 +133,16 @@ store( {
|
|
|
122
133
|
}
|
|
123
134
|
}
|
|
124
135
|
},
|
|
136
|
+
preloadLightboxImage: ( { context } ) => {
|
|
137
|
+
if ( ! context.core.image.preloadInitialized ) {
|
|
138
|
+
context.core.image.preloadInitialized = true;
|
|
139
|
+
const imgDom = document.createElement( 'img' );
|
|
140
|
+
imgDom.setAttribute(
|
|
141
|
+
'src',
|
|
142
|
+
context.core.image.imageUploadedSrc
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
},
|
|
125
146
|
},
|
|
126
147
|
},
|
|
127
148
|
},
|
|
@@ -131,9 +152,15 @@ store( {
|
|
|
131
152
|
roleAttribute: ( { context } ) => {
|
|
132
153
|
return context.core.image.lightboxEnabled ? 'dialog' : '';
|
|
133
154
|
},
|
|
134
|
-
|
|
155
|
+
responsiveImgSrc: ( { context } ) => {
|
|
156
|
+
return context.core.image.activateLargeImage &&
|
|
157
|
+
context.core.image.hideAnimationEnabled
|
|
158
|
+
? ''
|
|
159
|
+
: context.core.image.imageCurrentSrc;
|
|
160
|
+
},
|
|
161
|
+
enlargedImgSrc: ( { context } ) => {
|
|
135
162
|
return context.core.image.initialized
|
|
136
|
-
? context.core.image.
|
|
163
|
+
? context.core.image.imageUploadedSrc
|
|
137
164
|
: '';
|
|
138
165
|
},
|
|
139
166
|
},
|
|
@@ -142,6 +169,18 @@ store( {
|
|
|
142
169
|
effects: {
|
|
143
170
|
core: {
|
|
144
171
|
image: {
|
|
172
|
+
setCurrentSrc: ( { context, ref } ) => {
|
|
173
|
+
if ( ref.complete ) {
|
|
174
|
+
context.core.image.imageLoaded = true;
|
|
175
|
+
context.core.image.imageCurrentSrc = ref.currentSrc;
|
|
176
|
+
} else {
|
|
177
|
+
ref.addEventListener( 'load', function () {
|
|
178
|
+
context.core.image.imageLoaded = true;
|
|
179
|
+
context.core.image.imageCurrentSrc =
|
|
180
|
+
this.currentSrc;
|
|
181
|
+
} );
|
|
182
|
+
}
|
|
183
|
+
},
|
|
145
184
|
initLightbox: async ( { context, ref } ) => {
|
|
146
185
|
context.core.image.figureRef =
|
|
147
186
|
ref.querySelector( 'figure' );
|
|
@@ -163,51 +202,61 @@ store( {
|
|
|
163
202
|
} );
|
|
164
203
|
|
|
165
204
|
function setZoomStyles( imgDom, context, event ) {
|
|
166
|
-
|
|
167
|
-
|
|
205
|
+
// Typically, we use the image's full-sized dimensions. If those
|
|
206
|
+
// dimensions have not been set (i.e. an external image with only one size),
|
|
207
|
+
// the image's dimensions in the lightbox are the same
|
|
208
|
+
// as those of the image in the content.
|
|
209
|
+
let targetWidth =
|
|
210
|
+
context.core.image.targetWidth !== 'none'
|
|
211
|
+
? context.core.image.targetWidth
|
|
212
|
+
: event.target.nextElementSibling.naturalWidth;
|
|
213
|
+
let targetHeight =
|
|
214
|
+
context.core.image.targetHeight !== 'none'
|
|
215
|
+
? context.core.image.targetHeight
|
|
216
|
+
: event.target.nextElementSibling.naturalHeight;
|
|
168
217
|
|
|
169
|
-
|
|
218
|
+
// Since the lightbox image has `position:absolute`, it
|
|
219
|
+
// ignores its parent's padding, so we need to set padding here
|
|
220
|
+
// to calculate dimensions and positioning.
|
|
170
221
|
|
|
171
|
-
// As per the design, let's
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const
|
|
222
|
+
// As per the design, let's constrain the height with fixed padding
|
|
223
|
+
const containerOuterHeight = window.innerHeight;
|
|
224
|
+
const verticalPadding = 40;
|
|
225
|
+
const containerInnerHeight = containerOuterHeight - verticalPadding * 2;
|
|
175
226
|
|
|
176
|
-
//
|
|
177
|
-
|
|
178
|
-
// to be used when calculating the image width and positioning
|
|
227
|
+
// Let's set a variable horizontal padding based on the container width
|
|
228
|
+
const containerOuterWidth = window.innerWidth;
|
|
179
229
|
let horizontalPadding = 0;
|
|
180
|
-
if (
|
|
230
|
+
if ( containerOuterWidth > 480 ) {
|
|
181
231
|
horizontalPadding = 40;
|
|
182
|
-
} else if (
|
|
232
|
+
} else if ( containerOuterWidth > 1920 ) {
|
|
183
233
|
horizontalPadding = 80;
|
|
184
234
|
}
|
|
185
|
-
|
|
186
|
-
const containerHeight =
|
|
187
|
-
context.core.image.figureRef.clientHeight - verticalPadding * 2;
|
|
235
|
+
const containerInnerWidth = containerOuterWidth - horizontalPadding * 2;
|
|
188
236
|
|
|
189
237
|
// Check difference between the image and figure dimensions
|
|
190
238
|
const widthOverflow = Math.abs(
|
|
191
|
-
Math.min(
|
|
239
|
+
Math.min( containerInnerWidth - targetWidth, 0 )
|
|
192
240
|
);
|
|
193
241
|
const heightOverflow = Math.abs(
|
|
194
|
-
Math.min(
|
|
242
|
+
Math.min( containerInnerHeight - targetHeight, 0 )
|
|
195
243
|
);
|
|
196
244
|
|
|
197
|
-
// If image is larger than
|
|
198
|
-
//
|
|
245
|
+
// If the image is larger than the container, let's resize
|
|
246
|
+
// it along the greater axis relative to the container
|
|
199
247
|
if ( widthOverflow > 0 || heightOverflow > 0 ) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
248
|
+
const containerInnerAspectRatio =
|
|
249
|
+
containerInnerWidth / containerInnerHeight;
|
|
250
|
+
const imageAspectRatio = targetWidth / targetHeight;
|
|
251
|
+
|
|
252
|
+
if ( imageAspectRatio > containerInnerAspectRatio ) {
|
|
253
|
+
targetWidth = containerInnerWidth;
|
|
205
254
|
targetHeight =
|
|
206
|
-
imgDom.naturalHeight
|
|
255
|
+
( targetWidth * imgDom.naturalHeight ) / imgDom.naturalWidth;
|
|
207
256
|
} else {
|
|
208
|
-
targetHeight =
|
|
257
|
+
targetHeight = containerInnerHeight;
|
|
209
258
|
targetWidth =
|
|
210
|
-
imgDom.naturalWidth
|
|
259
|
+
( targetHeight * imgDom.naturalWidth ) / imgDom.naturalHeight;
|
|
211
260
|
}
|
|
212
261
|
}
|
|
213
262
|
|
|
@@ -221,16 +270,16 @@ function setZoomStyles( imgDom, context, event ) {
|
|
|
221
270
|
|
|
222
271
|
// Get values used to center the image
|
|
223
272
|
let targetLeft = 0;
|
|
224
|
-
if ( targetWidth >=
|
|
273
|
+
if ( targetWidth >= containerInnerWidth ) {
|
|
225
274
|
targetLeft = horizontalPadding;
|
|
226
275
|
} else {
|
|
227
|
-
targetLeft = (
|
|
276
|
+
targetLeft = ( containerOuterWidth - targetWidth ) / 2;
|
|
228
277
|
}
|
|
229
278
|
let targetTop = 0;
|
|
230
|
-
if ( targetHeight >=
|
|
279
|
+
if ( targetHeight >= containerInnerHeight ) {
|
|
231
280
|
targetTop = verticalPadding;
|
|
232
281
|
} else {
|
|
233
|
-
targetTop = (
|
|
282
|
+
targetTop = ( containerOuterHeight - targetHeight ) / 2;
|
|
234
283
|
}
|
|
235
284
|
|
|
236
285
|
const root = document.documentElement;
|
package/src/index.js
CHANGED
|
@@ -142,7 +142,6 @@ const getAllBlocks = () => {
|
|
|
142
142
|
buttons,
|
|
143
143
|
calendar,
|
|
144
144
|
categories,
|
|
145
|
-
...( window.wp && window.wp.oldEditor ? [ classic ] : [] ), // Only add the classic block in WP Context.
|
|
146
145
|
code,
|
|
147
146
|
column,
|
|
148
147
|
columns,
|
|
@@ -229,6 +228,24 @@ const getAllBlocks = () => {
|
|
|
229
228
|
queryTitle,
|
|
230
229
|
postAuthorBiography,
|
|
231
230
|
];
|
|
231
|
+
|
|
232
|
+
// When in a WordPress context, conditionally
|
|
233
|
+
// add the classic block and TinyMCE editor
|
|
234
|
+
// under any of the following conditions:
|
|
235
|
+
// - the current post contains a classic block
|
|
236
|
+
// - the experiment to disable TinyMCE isn't active.
|
|
237
|
+
// - a query argument specifies that TinyMCE should be loaded
|
|
238
|
+
if (
|
|
239
|
+
window?.wp?.oldEditor &&
|
|
240
|
+
( window?.wp?.needsClassicBlock ||
|
|
241
|
+
! window?.__experimentalDisableTinymce ||
|
|
242
|
+
!! new URLSearchParams( window?.location?.search ).get(
|
|
243
|
+
'requiresTinymce'
|
|
244
|
+
) )
|
|
245
|
+
) {
|
|
246
|
+
blocks.push( classic );
|
|
247
|
+
}
|
|
248
|
+
|
|
232
249
|
return blocks.filter( Boolean );
|
|
233
250
|
};
|
|
234
251
|
|