@wordpress/block-library 11.1.0 → 11.2.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 +32 -0
- package/build/accordion-heading/block.json +1 -0
- package/build/archives/block.json +3 -0
- package/build/audio/edit.cjs +2 -1
- package/build/audio/edit.cjs.map +2 -2
- package/build/avatar/block.json +4 -0
- package/build/avatar/edit.cjs +31 -1
- package/build/avatar/edit.cjs.map +3 -3
- package/build/button/block.json +6 -0
- package/build/button/edit.cjs +9 -6
- package/build/button/edit.cjs.map +2 -2
- package/build/buttons/block.json +6 -1
- package/build/code/block.json +4 -0
- package/build/column/edit.cjs +5 -0
- package/build/column/edit.cjs.map +2 -2
- package/build/columns/block.json +4 -0
- package/build/columns/edit.cjs +21 -112
- package/build/columns/edit.cjs.map +3 -3
- package/build/comments/edit/placeholder.cjs +95 -87
- package/build/comments/edit/placeholder.cjs.map +2 -2
- package/build/comments-pagination/block.json +11 -0
- package/build/cover/block.json +2 -1
- package/build/cover/edit/index.cjs +26 -5
- package/build/cover/edit/index.cjs.map +2 -2
- package/build/cover/edit/inspector-controls.cjs +4 -1
- package/build/cover/edit/inspector-controls.cjs.map +2 -2
- package/build/cover/embed-video-utils.cjs +9 -8
- package/build/cover/embed-video-utils.cjs.map +2 -2
- package/build/cover/view.cjs +21 -0
- package/build/cover/view.cjs.map +7 -0
- package/build/details/block.json +3 -0
- package/build/embed/block.json +6 -1
- package/build/file/block.json +5 -0
- package/build/footnotes/block.json +4 -0
- package/build/gallery/block.json +13 -0
- package/build/gallery/dynamic-gallery.cjs +32 -93
- package/build/gallery/dynamic-gallery.cjs.map +3 -3
- package/build/gallery/edit.cjs +103 -40
- package/build/gallery/edit.cjs.map +2 -2
- package/build/gallery/order-controls.cjs +107 -0
- package/build/gallery/order-controls.cjs.map +7 -0
- package/build/gallery/order-images.cjs +92 -0
- package/build/gallery/order-images.cjs.map +7 -0
- package/build/gallery/order-options.cjs +62 -0
- package/build/gallery/order-options.cjs.map +7 -0
- package/build/gallery/use-dynamic-gallery.cjs +1 -7
- package/build/gallery/use-dynamic-gallery.cjs.map +2 -2
- package/build/gallery/use-get-media.cjs +2 -3
- package/build/gallery/use-get-media.cjs.map +2 -2
- package/build/group/edit.cjs +3 -3
- package/build/group/edit.cjs.map +2 -2
- package/build/heading/block.json +5 -0
- package/build/home-link/block.json +12 -0
- package/build/icon/components/custom-inserter/index.cjs +3 -1
- package/build/icon/components/custom-inserter/index.cjs.map +2 -2
- package/build/icon/edit.cjs +49 -5
- package/build/icon/edit.cjs.map +2 -2
- package/build/image/use-open-image-media-editor-modal.cjs +32 -28
- package/build/image/use-open-image-media-editor-modal.cjs.map +2 -2
- package/build/image/view.cjs +44 -50
- package/build/image/view.cjs.map +2 -2
- package/build/latest-comments/block.json +10 -0
- package/build/latest-posts/block.json +4 -0
- package/build/list/block.json +12 -1
- package/build/list-item/block.json +8 -1
- package/build/list-item/index.cjs +4 -0
- package/build/list-item/index.cjs.map +3 -3
- package/build/loginout/block.json +4 -0
- package/build/math/block.json +4 -0
- package/build/media-text/block.json +18 -0
- package/build/navigation-link/link-ui/index.cjs +33 -19
- package/build/navigation-link/link-ui/index.cjs.map +2 -2
- package/build/navigation-link/shared/index.cjs +5 -0
- package/build/navigation-link/shared/index.cjs.map +2 -2
- package/build/navigation-link/shared/use-block-suggestions.cjs +141 -0
- package/build/navigation-link/shared/use-block-suggestions.cjs.map +7 -0
- package/build/page-list/block.json +4 -0
- package/build/paragraph/block.json +1 -0
- package/build/post-author-biography/block.json +1 -0
- package/build/post-comments-form/block.json +5 -0
- package/build/post-content/block.json +2 -1
- package/build/post-excerpt/block.json +4 -0
- package/build/post-featured-image/block.json +1 -0
- package/build/post-featured-image/edit.cjs +1 -1
- package/build/post-featured-image/edit.cjs.map +2 -2
- package/build/post-terms/block.json +4 -0
- package/build/post-time-to-read/block.json +4 -0
- package/build/post-title/block.json +4 -0
- package/build/preformatted/block.json +4 -0
- package/build/pullquote/block.json +2 -1
- package/build/query-no-results/block.json +4 -0
- package/build/query-pagination/block.json +17 -0
- package/build/query-total/block.json +4 -0
- package/build/quote/block.json +2 -0
- package/build/read-more/block.json +5 -0
- package/build/rss/block.json +4 -0
- package/build/search/block.json +2 -1
- package/build/site-tagline/block.json +4 -0
- package/build/site-title/block.json +4 -0
- package/build/social-links/block.json +1 -0
- package/build/tab-list/block.json +4 -0
- package/build/tab-list/edit.cjs +3 -1
- package/build/tab-list/edit.cjs.map +3 -3
- package/build/tab-list/save.cjs +3 -1
- package/build/tab-list/save.cjs.map +3 -3
- package/build/tab-panels/block.json +3 -0
- package/build/tabs/block.json +3 -0
- package/build/term-count/block.json +5 -0
- package/build/term-description/block.json +4 -0
- package/build/term-name/block.json +6 -1
- package/build/term-template/block.json +4 -0
- package/build/utils/waveform-utils.cjs +2 -2
- package/build/utils/waveform-utils.cjs.map +2 -2
- package/build/verse/block.json +4 -0
- package/build/video/block.json +7 -1
- package/build/video/edit.cjs +10 -2
- package/build/video/edit.cjs.map +2 -2
- package/build-module/accordion-heading/block.json +1 -0
- package/build-module/archives/block.json +3 -0
- package/build-module/audio/edit.mjs +2 -1
- package/build-module/audio/edit.mjs.map +2 -2
- package/build-module/avatar/block.json +4 -0
- package/build-module/avatar/edit.mjs +33 -2
- package/build-module/avatar/edit.mjs.map +2 -2
- package/build-module/button/block.json +6 -0
- package/build-module/button/edit.mjs +11 -7
- package/build-module/button/edit.mjs.map +2 -2
- package/build-module/buttons/block.json +6 -1
- package/build-module/code/block.json +4 -0
- package/build-module/column/edit.mjs +5 -0
- package/build-module/column/edit.mjs.map +2 -2
- package/build-module/columns/block.json +4 -0
- package/build-module/columns/edit.mjs +22 -122
- package/build-module/columns/edit.mjs.map +2 -2
- package/build-module/comments/edit/placeholder.mjs +95 -87
- package/build-module/comments/edit/placeholder.mjs.map +2 -2
- package/build-module/comments-pagination/block.json +11 -0
- package/build-module/cover/block.json +2 -1
- package/build-module/cover/edit/index.mjs +32 -6
- package/build-module/cover/edit/index.mjs.map +2 -2
- package/build-module/cover/edit/inspector-controls.mjs +5 -2
- package/build-module/cover/edit/inspector-controls.mjs.map +2 -2
- package/build-module/cover/embed-video-utils.mjs +9 -8
- package/build-module/cover/embed-video-utils.mjs.map +2 -2
- package/build-module/cover/view.mjs +19 -0
- package/build-module/cover/view.mjs.map +7 -0
- package/build-module/details/block.json +3 -0
- package/build-module/embed/block.json +6 -1
- package/build-module/file/block.json +5 -0
- package/build-module/footnotes/block.json +4 -0
- package/build-module/gallery/block.json +13 -0
- package/build-module/gallery/dynamic-gallery.mjs +33 -97
- package/build-module/gallery/dynamic-gallery.mjs.map +2 -2
- package/build-module/gallery/edit.mjs +110 -42
- package/build-module/gallery/edit.mjs.map +2 -2
- package/build-module/gallery/order-controls.mjs +87 -0
- package/build-module/gallery/order-controls.mjs.map +7 -0
- package/build-module/gallery/order-images.mjs +66 -0
- package/build-module/gallery/order-images.mjs.map +7 -0
- package/build-module/gallery/order-options.mjs +33 -0
- package/build-module/gallery/order-options.mjs.map +7 -0
- package/build-module/gallery/use-dynamic-gallery.mjs +1 -7
- package/build-module/gallery/use-dynamic-gallery.mjs.map +2 -2
- package/build-module/gallery/use-get-media.mjs +2 -3
- package/build-module/gallery/use-get-media.mjs.map +2 -2
- package/build-module/group/edit.mjs +4 -4
- package/build-module/group/edit.mjs.map +2 -2
- package/build-module/heading/block.json +5 -0
- package/build-module/home-link/block.json +12 -0
- package/build-module/icon/components/custom-inserter/index.mjs +3 -1
- package/build-module/icon/components/custom-inserter/index.mjs.map +2 -2
- package/build-module/icon/edit.mjs +50 -6
- package/build-module/icon/edit.mjs.map +2 -2
- package/build-module/image/use-open-image-media-editor-modal.mjs +32 -28
- package/build-module/image/use-open-image-media-editor-modal.mjs.map +2 -2
- package/build-module/image/view.mjs +44 -50
- package/build-module/image/view.mjs.map +2 -2
- package/build-module/latest-comments/block.json +10 -0
- package/build-module/latest-posts/block.json +4 -0
- package/build-module/list/block.json +12 -1
- package/build-module/list-item/block.json +8 -1
- package/build-module/list-item/index.mjs +4 -0
- package/build-module/list-item/index.mjs.map +2 -2
- package/build-module/loginout/block.json +4 -0
- package/build-module/math/block.json +4 -0
- package/build-module/media-text/block.json +18 -0
- package/build-module/navigation-link/link-ui/index.mjs +39 -20
- package/build-module/navigation-link/link-ui/index.mjs.map +2 -2
- package/build-module/navigation-link/shared/index.mjs +6 -0
- package/build-module/navigation-link/shared/index.mjs.map +2 -2
- package/build-module/navigation-link/shared/use-block-suggestions.mjs +120 -0
- package/build-module/navigation-link/shared/use-block-suggestions.mjs.map +7 -0
- package/build-module/page-list/block.json +4 -0
- package/build-module/paragraph/block.json +1 -0
- package/build-module/post-author-biography/block.json +1 -0
- package/build-module/post-comments-form/block.json +5 -0
- package/build-module/post-content/block.json +2 -1
- package/build-module/post-excerpt/block.json +4 -0
- package/build-module/post-featured-image/block.json +1 -0
- package/build-module/post-featured-image/edit.mjs +1 -1
- package/build-module/post-featured-image/edit.mjs.map +2 -2
- package/build-module/post-terms/block.json +4 -0
- package/build-module/post-time-to-read/block.json +4 -0
- package/build-module/post-title/block.json +4 -0
- package/build-module/preformatted/block.json +4 -0
- package/build-module/pullquote/block.json +2 -1
- package/build-module/query-no-results/block.json +4 -0
- package/build-module/query-pagination/block.json +17 -0
- package/build-module/query-total/block.json +4 -0
- package/build-module/quote/block.json +2 -0
- package/build-module/read-more/block.json +5 -0
- package/build-module/rss/block.json +4 -0
- package/build-module/search/block.json +2 -1
- package/build-module/site-tagline/block.json +4 -0
- package/build-module/site-title/block.json +4 -0
- package/build-module/social-links/block.json +1 -0
- package/build-module/tab-list/block.json +4 -0
- package/build-module/tab-list/edit.mjs +4 -1
- package/build-module/tab-list/edit.mjs.map +2 -2
- package/build-module/tab-list/save.mjs +4 -1
- package/build-module/tab-list/save.mjs.map +2 -2
- package/build-module/tab-panels/block.json +3 -0
- package/build-module/tabs/block.json +3 -0
- package/build-module/term-count/block.json +5 -0
- package/build-module/term-description/block.json +4 -0
- package/build-module/term-name/block.json +6 -1
- package/build-module/term-template/block.json +4 -0
- package/build-module/utils/waveform-utils.mjs +1 -1
- package/build-module/utils/waveform-utils.mjs.map +1 -1
- package/build-module/verse/block.json +4 -0
- package/build-module/video/block.json +7 -1
- package/build-module/video/edit.mjs +10 -2
- package/build-module/video/edit.mjs.map +2 -2
- package/build-style/avatar/editor-rtl.css +4 -0
- package/build-style/avatar/editor.css +4 -0
- package/build-style/comments-pagination/style-rtl.css +3 -0
- package/build-style/comments-pagination/style.css +3 -0
- package/build-style/common-rtl.css +32 -1
- package/build-style/common.css +35 -2
- package/build-style/editor-rtl.css +11 -4
- package/build-style/editor.css +11 -4
- package/build-style/embed/style-rtl.css +4 -1
- package/build-style/embed/style.css +4 -1
- package/build-style/gallery/editor-rtl.css +1 -3
- package/build-style/gallery/editor.css +1 -3
- package/build-style/image/style-rtl.css +11 -2
- package/build-style/image/style.css +11 -2
- package/build-style/media-text/style-rtl.css +4 -1
- package/build-style/media-text/style.css +4 -1
- package/build-style/query-pagination/style-rtl.css +3 -0
- package/build-style/query-pagination/style.css +3 -0
- package/build-style/style-rtl.css +70 -9
- package/build-style/style.css +73 -10
- package/build-style/table/editor-rtl.css +6 -1
- package/build-style/table/editor.css +6 -1
- package/build-style/table/style-rtl.css +4 -2
- package/build-style/table/style.css +4 -2
- package/build-style/tag-cloud/style-rtl.css +1 -1
- package/build-style/tag-cloud/style.css +1 -1
- package/build-style/verse/style-rtl.css +8 -1
- package/build-style/verse/style.css +8 -1
- package/build-types/gallery/order-controls.d.ts +58 -0
- package/build-types/gallery/order-controls.d.ts.map +1 -0
- package/build-types/gallery/order-options.d.ts +67 -0
- package/build-types/gallery/order-options.d.ts.map +1 -0
- package/package.json +44 -41
- package/src/accordion-heading/README.md +1 -0
- package/src/accordion-heading/block.json +1 -0
- package/src/archives/README.md +2 -0
- package/src/archives/block.json +3 -0
- package/src/audio/edit.jsx +2 -1
- package/src/avatar/README.md +2 -0
- package/src/avatar/block.json +4 -0
- package/src/avatar/edit.jsx +48 -2
- package/src/avatar/editor.scss +4 -0
- package/src/avatar/index.php +5 -3
- package/src/breadcrumbs/index.php +1 -1
- package/src/button/README.md +4 -0
- package/src/button/block.json +6 -0
- package/src/button/edit.jsx +47 -52
- package/src/button/index.php +47 -0
- package/src/buttons/README.md +4 -0
- package/src/buttons/block.json +6 -1
- package/src/code/README.md +3 -0
- package/src/code/block.json +4 -0
- package/src/column/edit.jsx +6 -0
- package/src/columns/README.md +3 -0
- package/src/columns/block.json +4 -0
- package/src/columns/edit.jsx +1 -131
- package/src/comments/edit/placeholder.jsx +5 -1
- package/src/comments-pagination/README.md +4 -0
- package/src/comments-pagination/block.json +11 -0
- package/src/comments-pagination/style.scss +3 -0
- package/src/common.scss +38 -0
- package/src/cover/README.md +1 -0
- package/src/cover/block.json +2 -1
- package/src/cover/edit/index.jsx +38 -6
- package/src/cover/edit/inspector-controls.jsx +10 -1
- package/src/cover/embed-video-utils.js +18 -10
- package/src/cover/index.php +44 -15
- package/src/cover/test/edit.browser.test.js +182 -2
- package/src/cover/test/embed-video-utils.test.js +48 -0
- package/src/cover/view.js +22 -0
- package/src/details/README.md +2 -0
- package/src/details/block.json +3 -0
- package/src/embed/README.md +4 -0
- package/src/embed/block.json +6 -1
- package/src/embed/style.scss +7 -1
- package/src/file/README.md +4 -0
- package/src/file/block.json +5 -0
- package/src/footnotes/README.md +3 -0
- package/src/footnotes/block.json +4 -0
- package/src/gallery/README.md +13 -0
- package/src/gallery/block.json +13 -0
- package/src/gallery/dynamic-gallery.jsx +11 -91
- package/src/gallery/edit.jsx +146 -47
- package/src/gallery/editor.scss +5 -9
- package/src/gallery/order-controls.tsx +143 -0
- package/src/gallery/order-images.js +111 -0
- package/src/gallery/order-options.ts +75 -0
- package/src/gallery/test/edit.jsdom.test.js +87 -10
- package/src/gallery/test/order-images.js +162 -0
- package/src/gallery/use-dynamic-gallery.js +1 -9
- package/src/gallery/use-get-media.js +7 -2
- package/src/group/edit.jsx +5 -5
- package/src/heading/README.md +4 -0
- package/src/heading/block.json +5 -0
- package/src/home-link/README.md +6 -0
- package/src/home-link/block.json +12 -0
- package/src/icon/components/custom-inserter/index.jsx +5 -1
- package/src/icon/edit.jsx +68 -7
- package/src/icon/index.php +1 -1
- package/src/image/index.php +3 -4
- package/src/image/style.scss +14 -2
- package/src/image/test/use-open-image-media-editor-modal.jsdom.test.js +122 -60
- package/src/image/use-open-image-media-editor-modal.js +37 -41
- package/src/image/view.js +64 -68
- package/src/latest-comments/README.md +3 -0
- package/src/latest-comments/block.json +10 -0
- package/src/latest-posts/README.md +3 -0
- package/src/latest-posts/block.json +4 -0
- package/src/list/README.md +6 -0
- package/src/list/block.json +12 -1
- package/src/list-item/README.md +6 -0
- package/src/list-item/block.json +8 -1
- package/src/list-item/index.js +5 -0
- package/src/loginout/README.md +3 -0
- package/src/loginout/block.json +4 -0
- package/src/math/README.md +3 -0
- package/src/math/block.json +4 -0
- package/src/media-text/README.md +17 -0
- package/src/media-text/block.json +18 -0
- package/src/media-text/style.scss +5 -1
- package/src/navigation/test/use-navigation-menu.jsdom.test.js +1 -1
- package/src/navigation-link/README.md +1 -1
- package/src/navigation-link/link-ui/index.jsx +60 -27
- package/src/navigation-link/link-ui/test/get-suggestions-query.jsdom.test.js +67 -0
- package/src/navigation-link/shared/index.js +4 -0
- package/src/navigation-link/shared/test/use-block-suggestions.jsdom.test.js +158 -0
- package/src/navigation-link/shared/test/use-entity-binding.jsdom.test.js +1 -7
- package/src/navigation-link/shared/use-block-suggestions.js +192 -0
- package/src/page-list/README.md +3 -0
- package/src/page-list/block.json +4 -0
- package/src/paragraph/README.md +1 -0
- package/src/paragraph/block.json +1 -0
- package/src/playlist/test/edit-component.jsdom.test.jsx +11 -11
- package/src/playlist-track/test/edit.jsdom.test.jsx +3 -3
- package/src/post-author-biography/README.md +1 -0
- package/src/post-author-biography/block.json +1 -0
- package/src/post-comments-form/README.md +3 -0
- package/src/post-comments-form/block.json +5 -0
- package/src/post-content/README.md +1 -0
- package/src/post-content/block.json +2 -1
- package/src/post-excerpt/README.md +3 -0
- package/src/post-excerpt/block.json +4 -0
- package/src/post-featured-image/block.json +1 -0
- package/src/post-featured-image/edit.jsx +2 -2
- package/src/post-terms/README.md +3 -0
- package/src/post-terms/block.json +4 -0
- package/src/post-time-to-read/README.md +3 -0
- package/src/post-time-to-read/block.json +4 -0
- package/src/post-title/README.md +3 -0
- package/src/post-title/block.json +4 -0
- package/src/preformatted/README.md +3 -0
- package/src/preformatted/block.json +4 -0
- package/src/pullquote/README.md +1 -0
- package/src/pullquote/block.json +2 -1
- package/src/query-no-results/README.md +3 -0
- package/src/query-no-results/block.json +4 -0
- package/src/query-pagination/README.md +4 -0
- package/src/query-pagination/block.json +17 -0
- package/src/query-pagination/style.scss +3 -0
- package/src/query-total/README.md +3 -0
- package/src/query-total/block.json +4 -0
- package/src/quote/README.md +2 -0
- package/src/quote/block.json +2 -0
- package/src/read-more/README.md +3 -0
- package/src/read-more/block.json +5 -0
- package/src/rss/README.md +3 -0
- package/src/rss/block.json +4 -0
- package/src/search/README.md +1 -0
- package/src/search/block.json +2 -1
- package/src/site-tagline/README.md +3 -0
- package/src/site-tagline/block.json +4 -0
- package/src/site-title/README.md +3 -0
- package/src/site-title/block.json +4 -0
- package/src/social-links/README.md +1 -0
- package/src/social-links/block.json +1 -0
- package/src/tab-list/README.md +2 -0
- package/src/tab-list/block.json +4 -0
- package/src/tab-list/edit.jsx +3 -0
- package/src/tab-list/save.jsx +3 -0
- package/src/tab-panels/README.md +2 -0
- package/src/tab-panels/block.json +3 -0
- package/src/table/editor.scss +8 -2
- package/src/table/style.scss +4 -4
- package/src/tabs/README.md +2 -0
- package/src/tabs/block.json +3 -0
- package/src/tag-cloud/style.scss +1 -1
- package/src/template-part/index.php +16 -3
- package/src/term-count/README.md +4 -0
- package/src/term-count/block.json +5 -0
- package/src/term-description/README.md +3 -0
- package/src/term-description/block.json +4 -0
- package/src/term-name/README.md +4 -0
- package/src/term-name/block.json +6 -1
- package/src/term-template/README.md +3 -0
- package/src/term-template/block.json +4 -0
- package/src/utils/test/waveform-player-auto-init.jsdom.test.js +25 -0
- package/src/utils/test/waveform-player-dependency.jsdom.test.js +7 -60
- package/src/utils/test/waveform-utils.browser.test.js +3 -15
- package/src/utils/waveform-utils.js +1 -1
- package/src/verse/README.md +4 -0
- package/src/verse/block.json +4 -0
- package/src/verse/style.scss +11 -2
- package/src/video/README.md +4 -0
- package/src/video/block.json +7 -1
- package/src/video/edit.jsx +13 -2
- package/build/columns/utils.cjs +0 -112
- package/build/columns/utils.cjs.map +0 -7
- package/build-module/columns/utils.mjs +0 -78
- package/build-module/columns/utils.mjs.map +0 -7
- package/src/columns/test/utils.js +0 -331
- package/src/columns/utils.js +0 -176
package/src/image/style.scss
CHANGED
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
|
|
119
119
|
// If a browser supports it, we will switch to using a circular SVG mask.
|
|
120
120
|
@supports (mask-image: none) or (-webkit-mask-image: none) {
|
|
121
|
-
mask-image: url(
|
|
121
|
+
mask-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='50' cy='50' r='50'/%3E%3C/svg%3E");
|
|
122
122
|
mask-mode: alpha;
|
|
123
123
|
mask-repeat: no-repeat;
|
|
124
124
|
mask-size: contain;
|
|
@@ -148,7 +148,7 @@
|
|
|
148
148
|
cursor: zoom-in;
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
img:hover
|
|
151
|
+
&:has(img:hover) button {
|
|
152
152
|
opacity: 1;
|
|
153
153
|
}
|
|
154
154
|
|
|
@@ -305,6 +305,9 @@
|
|
|
305
305
|
width: var(--wp--lightbox-container-width);
|
|
306
306
|
height: var(--wp--lightbox-container-height);
|
|
307
307
|
z-index: 2000001;
|
|
308
|
+
// Clicking the image does not close the lightbox, so it should not
|
|
309
|
+
// appear clickable.
|
|
310
|
+
cursor: default;
|
|
308
311
|
}
|
|
309
312
|
|
|
310
313
|
.wp-block-image {
|
|
@@ -331,6 +334,11 @@
|
|
|
331
334
|
}
|
|
332
335
|
}
|
|
333
336
|
|
|
337
|
+
.lightbox-thumbnail-container {
|
|
338
|
+
--wp--lightbox-image-width: var(--wp--lightbox-thumbnail-width);
|
|
339
|
+
--wp--lightbox-image-height: var(--wp--lightbox-thumbnail-height);
|
|
340
|
+
}
|
|
341
|
+
|
|
334
342
|
button {
|
|
335
343
|
border: none;
|
|
336
344
|
background: none;
|
|
@@ -445,9 +453,11 @@
|
|
|
445
453
|
|
|
446
454
|
@keyframes lightbox-zoom-in {
|
|
447
455
|
0% {
|
|
456
|
+
clip-path: var(--wp--lightbox-initial-clip);
|
|
448
457
|
transform: translate(calc((-100vw + var(--wp--lightbox-scrollbar-width)) / 2 + var(--wp--lightbox-initial-left-position)), calc(-50vh + var(--wp--lightbox-initial-top-position))) scale(var(--wp--lightbox-scale));
|
|
449
458
|
}
|
|
450
459
|
100% {
|
|
460
|
+
clip-path: inset(0);
|
|
451
461
|
transform: translate(-50%, -50%) scale(1, 1);
|
|
452
462
|
}
|
|
453
463
|
}
|
|
@@ -455,6 +465,7 @@
|
|
|
455
465
|
@keyframes lightbox-zoom-out {
|
|
456
466
|
0% {
|
|
457
467
|
visibility: visible;
|
|
468
|
+
clip-path: inset(0);
|
|
458
469
|
transform: translate(-50%, -50%) scale(1, 1);
|
|
459
470
|
}
|
|
460
471
|
99% {
|
|
@@ -462,6 +473,7 @@
|
|
|
462
473
|
}
|
|
463
474
|
100% {
|
|
464
475
|
visibility: hidden;
|
|
476
|
+
clip-path: var(--wp--lightbox-initial-clip);
|
|
465
477
|
transform: translate(calc((-100vw + var(--wp--lightbox-scrollbar-width)) / 2 + var(--wp--lightbox-initial-left-position)), calc(-50vh + var(--wp--lightbox-initial-top-position))) scale(var(--wp--lightbox-scale));
|
|
466
478
|
}
|
|
467
479
|
}
|
|
@@ -318,6 +318,7 @@ describe( 'useOpenImageMediaEditorModal', () => {
|
|
|
318
318
|
expect( openMediaEditorModal ).toHaveBeenCalledWith( {
|
|
319
319
|
id: 1,
|
|
320
320
|
onUpdate: expect.any( Function ),
|
|
321
|
+
onUndo: expect.any( Function ),
|
|
321
322
|
onClose: undefined,
|
|
322
323
|
} );
|
|
323
324
|
expect( setAttributes ).toHaveBeenCalledWith( {
|
|
@@ -360,6 +361,7 @@ describe( 'useOpenImageMediaEditorModal', () => {
|
|
|
360
361
|
expect( openMediaEditorModal ).toHaveBeenCalledWith( {
|
|
361
362
|
id: 1,
|
|
362
363
|
onUpdate: expect.any( Function ),
|
|
364
|
+
onUndo: expect.any( Function ),
|
|
363
365
|
onClose: undefined,
|
|
364
366
|
} );
|
|
365
367
|
expect( setAttributes ).toHaveBeenCalledWith( {
|
|
@@ -623,66 +625,6 @@ describe( 'useOpenImageMediaEditorModal', () => {
|
|
|
623
625
|
} );
|
|
624
626
|
} );
|
|
625
627
|
|
|
626
|
-
it( 'restores the alt text and caption a save overwrote when undoing back to the previous attachment', async () => {
|
|
627
|
-
const originalAttachment = {
|
|
628
|
-
id: 1,
|
|
629
|
-
alt_text: 'Original alt',
|
|
630
|
-
caption: { raw: 'Original caption' },
|
|
631
|
-
};
|
|
632
|
-
const croppedAttachment = {
|
|
633
|
-
id: 2,
|
|
634
|
-
alt_text: 'Updated alt',
|
|
635
|
-
caption: { raw: 'Updated caption' },
|
|
636
|
-
};
|
|
637
|
-
const registry = createRegistry( {
|
|
638
|
-
getEditedEntityRecord: ( kind, name, attachmentId ) =>
|
|
639
|
-
attachmentId === 1 ? originalAttachment : undefined,
|
|
640
|
-
resolveGetEntityRecord: ( kind, name, attachmentId ) =>
|
|
641
|
-
attachmentId === 2 ? croppedAttachment : originalAttachment,
|
|
642
|
-
} );
|
|
643
|
-
useRegistry.mockReturnValue( registry );
|
|
644
|
-
const setAttributes = vi.fn();
|
|
645
|
-
const openMediaEditorModal = vi.fn();
|
|
646
|
-
mockMediaEditorModalSetting( openMediaEditorModal );
|
|
647
|
-
const { result } = renderHook( () =>
|
|
648
|
-
useOpenImageMediaEditorModal( {
|
|
649
|
-
attributes: {
|
|
650
|
-
id: 1,
|
|
651
|
-
url: 'original.jpg',
|
|
652
|
-
alt: 'Original alt',
|
|
653
|
-
caption: 'Original caption',
|
|
654
|
-
},
|
|
655
|
-
setAttributes,
|
|
656
|
-
} )
|
|
657
|
-
);
|
|
658
|
-
|
|
659
|
-
await act( async () => {
|
|
660
|
-
await result.current();
|
|
661
|
-
} );
|
|
662
|
-
const onUpdate = openMediaEditorModal.mock.calls[ 0 ][ 0 ].onUpdate;
|
|
663
|
-
await act( async () => {
|
|
664
|
-
await onUpdate( { id: 2, url: 'cropped.jpg' } );
|
|
665
|
-
} );
|
|
666
|
-
// The media editor's Undo only reports the previous attachment.
|
|
667
|
-
await act( async () => {
|
|
668
|
-
await onUpdate( { id: 1, url: 'original.jpg' } );
|
|
669
|
-
} );
|
|
670
|
-
|
|
671
|
-
expect( setAttributes ).toHaveBeenCalledTimes( 2 );
|
|
672
|
-
expect( setAttributes ).toHaveBeenNthCalledWith( 1, {
|
|
673
|
-
id: 2,
|
|
674
|
-
url: 'cropped.jpg',
|
|
675
|
-
alt: 'Updated alt',
|
|
676
|
-
caption: 'Updated caption',
|
|
677
|
-
} );
|
|
678
|
-
expect( setAttributes ).toHaveBeenNthCalledWith( 2, {
|
|
679
|
-
id: 1,
|
|
680
|
-
url: 'original.jpg',
|
|
681
|
-
alt: 'Original alt',
|
|
682
|
-
caption: 'Original caption',
|
|
683
|
-
} );
|
|
684
|
-
} );
|
|
685
|
-
|
|
686
628
|
it( 'does not restore overwritten metadata when a later session saves back to the previous attachment', async () => {
|
|
687
629
|
const originalAttachment = {
|
|
688
630
|
id: 1,
|
|
@@ -1005,6 +947,126 @@ describe( 'useOpenImageMediaEditorModal', () => {
|
|
|
1005
947
|
} );
|
|
1006
948
|
} );
|
|
1007
949
|
|
|
950
|
+
describe( 'media editor Undo', () => {
|
|
951
|
+
it( 'restores the block metadata, selected image size, and link after restoring an original image', async () => {
|
|
952
|
+
const { setAttributes, openMediaEditorModal } = await runModalUpdate( {
|
|
953
|
+
attributes: {
|
|
954
|
+
id: 2,
|
|
955
|
+
url: 'crop-medium.jpg',
|
|
956
|
+
alt: 'Close-up',
|
|
957
|
+
caption: 'Cropped caption',
|
|
958
|
+
sizeSlug: 'medium',
|
|
959
|
+
linkDestination: 'media',
|
|
960
|
+
href: 'crop.jpg',
|
|
961
|
+
},
|
|
962
|
+
registryOptions: {
|
|
963
|
+
getEditedEntityRecord: () => ( {
|
|
964
|
+
id: 2,
|
|
965
|
+
alt_text: 'Close-up',
|
|
966
|
+
caption: { raw: 'Cropped caption' },
|
|
967
|
+
} ),
|
|
968
|
+
resolveGetEntityRecord: () => ( {
|
|
969
|
+
id: 1,
|
|
970
|
+
source_url: 'original.jpg',
|
|
971
|
+
alt_text: 'Full scene',
|
|
972
|
+
caption: { raw: 'Original caption' },
|
|
973
|
+
media_details: {
|
|
974
|
+
sizes: { full: { source_url: 'original.jpg' } },
|
|
975
|
+
},
|
|
976
|
+
} ),
|
|
977
|
+
},
|
|
978
|
+
updatePayload: { id: 1, url: 'original.jpg' },
|
|
979
|
+
} );
|
|
980
|
+
expect( setAttributes ).toHaveBeenLastCalledWith( {
|
|
981
|
+
id: 1,
|
|
982
|
+
url: 'original.jpg',
|
|
983
|
+
alt: 'Full scene',
|
|
984
|
+
caption: 'Original caption',
|
|
985
|
+
sizeSlug: 'full',
|
|
986
|
+
href: 'original.jpg',
|
|
987
|
+
} );
|
|
988
|
+
|
|
989
|
+
act( () => openMediaEditorModal.mock.calls[ 0 ][ 0 ].onUndo() );
|
|
990
|
+
|
|
991
|
+
expect( setAttributes ).toHaveBeenLastCalledWith( {
|
|
992
|
+
id: 2,
|
|
993
|
+
url: 'crop-medium.jpg',
|
|
994
|
+
alt: 'Close-up',
|
|
995
|
+
caption: 'Cropped caption',
|
|
996
|
+
sizeSlug: 'medium',
|
|
997
|
+
href: 'crop.jpg',
|
|
998
|
+
} );
|
|
999
|
+
} );
|
|
1000
|
+
|
|
1001
|
+
it( 'leaves custom metadata and unrelated block edits out of Undo', async () => {
|
|
1002
|
+
const { setAttributes, openMediaEditorModal } = await runModalUpdate( {
|
|
1003
|
+
attributes: {
|
|
1004
|
+
id: 1,
|
|
1005
|
+
url: 'original.jpg',
|
|
1006
|
+
alt: 'Custom alt',
|
|
1007
|
+
caption: 'Custom caption',
|
|
1008
|
+
width: '300px',
|
|
1009
|
+
linkDestination: 'custom',
|
|
1010
|
+
href: 'https://example.com/custom',
|
|
1011
|
+
},
|
|
1012
|
+
registryOptions: croppedAttachmentRecords(),
|
|
1013
|
+
updatePayload: CROP_UPDATE,
|
|
1014
|
+
} );
|
|
1015
|
+
|
|
1016
|
+
act( () => openMediaEditorModal.mock.calls[ 0 ][ 0 ].onUndo() );
|
|
1017
|
+
|
|
1018
|
+
expect( setAttributes ).toHaveBeenLastCalledWith( {
|
|
1019
|
+
id: 1,
|
|
1020
|
+
url: 'original.jpg',
|
|
1021
|
+
} );
|
|
1022
|
+
} );
|
|
1023
|
+
|
|
1024
|
+
it( 'keeps the previous image when Undo runs before metadata finishes loading', async () => {
|
|
1025
|
+
const pendingAttachment = createDeferred();
|
|
1026
|
+
useRegistry.mockReturnValue(
|
|
1027
|
+
createRegistry( {
|
|
1028
|
+
getEditedEntityRecord: () => ORIGINAL_ATTACHMENT,
|
|
1029
|
+
resolveGetEntityRecord: () => pendingAttachment.promise,
|
|
1030
|
+
} )
|
|
1031
|
+
);
|
|
1032
|
+
const setAttributes = vi.fn();
|
|
1033
|
+
const onUrlChange = vi.fn();
|
|
1034
|
+
const openMediaEditorModal = vi.fn();
|
|
1035
|
+
mockMediaEditorModalSetting( openMediaEditorModal );
|
|
1036
|
+
const { result } = renderHook( () =>
|
|
1037
|
+
useOpenImageMediaEditorModal( {
|
|
1038
|
+
attributes: {
|
|
1039
|
+
id: 1,
|
|
1040
|
+
url: 'original-medium.jpg',
|
|
1041
|
+
alt: '',
|
|
1042
|
+
caption: '',
|
|
1043
|
+
},
|
|
1044
|
+
setAttributes,
|
|
1045
|
+
onUrlChange,
|
|
1046
|
+
} )
|
|
1047
|
+
);
|
|
1048
|
+
await act( () => result.current() );
|
|
1049
|
+
const { onUpdate, onUndo } = openMediaEditorModal.mock.calls[ 0 ][ 0 ];
|
|
1050
|
+
let updatePromise;
|
|
1051
|
+
act( () => {
|
|
1052
|
+
updatePromise = onUpdate( CROP_UPDATE );
|
|
1053
|
+
} );
|
|
1054
|
+
|
|
1055
|
+
act( () => onUndo() );
|
|
1056
|
+
await act( async () => {
|
|
1057
|
+
pendingAttachment.resolve( CROPPED_ATTACHMENT );
|
|
1058
|
+
await updatePromise;
|
|
1059
|
+
} );
|
|
1060
|
+
|
|
1061
|
+
expect( setAttributes ).toHaveBeenCalledTimes( 1 );
|
|
1062
|
+
expect( setAttributes ).toHaveBeenCalledWith( {
|
|
1063
|
+
id: 1,
|
|
1064
|
+
url: 'original-medium.jpg',
|
|
1065
|
+
} );
|
|
1066
|
+
expect( onUrlChange ).toHaveBeenLastCalledWith( 'original-medium.jpg' );
|
|
1067
|
+
} );
|
|
1068
|
+
} );
|
|
1069
|
+
|
|
1008
1070
|
describe( 'getImageBlockMetadataFromAttachment', () => {
|
|
1009
1071
|
it( 'normalizes attachment metadata to image block attributes', () => {
|
|
1010
1072
|
expect(
|
|
@@ -243,7 +243,8 @@ export function useOpenImageMediaEditorModal( {
|
|
|
243
243
|
// the update needs to read — those synced from the attachment's metadata,
|
|
244
244
|
// and those derived from which attachment the block points at; add more
|
|
245
245
|
// here if the sync policy grows.
|
|
246
|
-
const { id, url, alt, caption, sizeSlug, linkDestination } =
|
|
246
|
+
const { id, url, alt, caption, sizeSlug, linkDestination, href } =
|
|
247
|
+
attributes;
|
|
247
248
|
const registry = useRegistry();
|
|
248
249
|
const openMediaEditorModal = useSelect(
|
|
249
250
|
( select ) =>
|
|
@@ -261,6 +262,7 @@ export function useOpenImageMediaEditorModal( {
|
|
|
261
262
|
caption: caption?.toString(),
|
|
262
263
|
sizeSlug,
|
|
263
264
|
linkDestination,
|
|
265
|
+
href,
|
|
264
266
|
} );
|
|
265
267
|
// Snapshot of the attachment's metadata taken just before the modal opens,
|
|
266
268
|
// used as the baseline for detecting what changed during the editing session.
|
|
@@ -268,11 +270,6 @@ export function useOpenImageMediaEditorModal( {
|
|
|
268
270
|
// Incremented on every handleMediaUpdate call; stale async continuations
|
|
269
271
|
// check against this to bail out if a newer update has since started.
|
|
270
272
|
const mediaEditorMetadataSyncRequestRef = useRef( 0 );
|
|
271
|
-
// The alt text and caption a save overwrote on the block, and the
|
|
272
|
-
// attachment it moved the block away from. The media editor's Undo moves
|
|
273
|
-
// the block back but reports only that attachment's id and url, so this is
|
|
274
|
-
// what lets the update restore the block's own metadata too.
|
|
275
|
-
const mediaEditorUndoMetadataRef = useRef();
|
|
276
273
|
|
|
277
274
|
useEffect( () => {
|
|
278
275
|
blockAttributesRef.current = {
|
|
@@ -282,8 +279,9 @@ export function useOpenImageMediaEditorModal( {
|
|
|
282
279
|
caption: caption?.toString(),
|
|
283
280
|
sizeSlug,
|
|
284
281
|
linkDestination,
|
|
282
|
+
href,
|
|
285
283
|
};
|
|
286
|
-
}, [ alt, caption, id, linkDestination, sizeSlug, url ] );
|
|
284
|
+
}, [ alt, caption, href, id, linkDestination, sizeSlug, url ] );
|
|
287
285
|
|
|
288
286
|
// Reads the cached attachment record. The `attachment` postType entity
|
|
289
287
|
// fetches with `context: 'edit'` by default, so `getEditedEntityRecord`
|
|
@@ -340,7 +338,7 @@ export function useOpenImageMediaEditorModal( {
|
|
|
340
338
|
);
|
|
341
339
|
|
|
342
340
|
const handleMediaUpdate = useCallback(
|
|
343
|
-
async ( { id: newId, url: newUrl } ) => {
|
|
341
|
+
async ( { id: newId, url: newUrl }, undoState ) => {
|
|
344
342
|
if ( typeof newId !== 'number' ) {
|
|
345
343
|
return;
|
|
346
344
|
}
|
|
@@ -349,10 +347,6 @@ export function useOpenImageMediaEditorModal( {
|
|
|
349
347
|
// reuse a stale snapshot.
|
|
350
348
|
const originalAttachment = mediaEditorMetadataBaselineRef.current;
|
|
351
349
|
mediaEditorMetadataBaselineRef.current = undefined;
|
|
352
|
-
// Likewise the metadata the last save overwrote: only the update
|
|
353
|
-
// straight after that save, its Undo, may restore it.
|
|
354
|
-
const undoMetadata = mediaEditorUndoMetadataRef.current;
|
|
355
|
-
mediaEditorUndoMetadataRef.current = undefined;
|
|
356
350
|
const syncRequest = ++mediaEditorMetadataSyncRequestRef.current;
|
|
357
351
|
const nextAttributes = {};
|
|
358
352
|
|
|
@@ -360,6 +354,10 @@ export function useOpenImageMediaEditorModal( {
|
|
|
360
354
|
const isNewAttachment = newId !== currentBlockAttributes.id;
|
|
361
355
|
|
|
362
356
|
if ( isNewAttachment ) {
|
|
357
|
+
// Capture the block's selected-size URL, not the attachment's
|
|
358
|
+
// full-size URL supplied by the modal's fallback Undo.
|
|
359
|
+
undoState.undoAttributes.id = currentBlockAttributes.id;
|
|
360
|
+
undoState.undoAttributes.url = currentBlockAttributes.url;
|
|
363
361
|
nextAttributes.id = newId;
|
|
364
362
|
nextAttributes.url = newUrl ?? currentBlockAttributes.url;
|
|
365
363
|
if ( nextAttributes.url !== currentBlockAttributes.url ) {
|
|
@@ -388,6 +386,7 @@ export function useOpenImageMediaEditorModal( {
|
|
|
388
386
|
// A newer update started while we were awaiting; discard
|
|
389
387
|
// this one.
|
|
390
388
|
if (
|
|
389
|
+
undoState.isUndone ||
|
|
391
390
|
syncRequest !== mediaEditorMetadataSyncRequestRef.current
|
|
392
391
|
) {
|
|
393
392
|
return;
|
|
@@ -422,22 +421,6 @@ export function useOpenImageMediaEditorModal( {
|
|
|
422
421
|
nextAttributes,
|
|
423
422
|
resolvedMetadataAttributes
|
|
424
423
|
);
|
|
425
|
-
|
|
426
|
-
// Only a save to a new attachment offers an Undo, so
|
|
427
|
-
// only then keep the values being overwritten.
|
|
428
|
-
if ( isNewAttachment ) {
|
|
429
|
-
mediaEditorUndoMetadataRef.current = {
|
|
430
|
-
id: currentBlockAttributes.id,
|
|
431
|
-
attributes: Object.fromEntries(
|
|
432
|
-
Object.keys(
|
|
433
|
-
resolvedMetadataAttributes
|
|
434
|
-
).map( ( key ) => [
|
|
435
|
-
key,
|
|
436
|
-
latestBlockAttributes[ key ],
|
|
437
|
-
] )
|
|
438
|
-
),
|
|
439
|
-
};
|
|
440
|
-
}
|
|
441
424
|
}
|
|
442
425
|
}
|
|
443
426
|
|
|
@@ -469,14 +452,15 @@ export function useOpenImageMediaEditorModal( {
|
|
|
469
452
|
}
|
|
470
453
|
}
|
|
471
454
|
|
|
472
|
-
// The media editor's Undo: the block is going back to the
|
|
473
|
-
// attachment the last save moved it away from, so put back the
|
|
474
|
-
// alt text and caption that save overwrote.
|
|
475
|
-
if ( undoMetadata?.id === newId ) {
|
|
476
|
-
Object.assign( nextAttributes, undoMetadata.attributes );
|
|
477
|
-
}
|
|
478
|
-
|
|
479
455
|
if ( Object.keys( nextAttributes ).length ) {
|
|
456
|
+
// Only restore values this save changed. Block-specific
|
|
457
|
+
// metadata and unrelated edits must not be overwritten.
|
|
458
|
+
for ( const key of Object.keys( nextAttributes ) ) {
|
|
459
|
+
if ( ! Object.hasOwn( undoState.undoAttributes, key ) ) {
|
|
460
|
+
undoState.undoAttributes[ key ] =
|
|
461
|
+
blockAttributesRef.current[ key ];
|
|
462
|
+
}
|
|
463
|
+
}
|
|
480
464
|
blockAttributesRef.current = {
|
|
481
465
|
...blockAttributesRef.current,
|
|
482
466
|
...nextAttributes,
|
|
@@ -497,11 +481,6 @@ export function useOpenImageMediaEditorModal( {
|
|
|
497
481
|
return;
|
|
498
482
|
}
|
|
499
483
|
|
|
500
|
-
// A new session starts. Drop any metadata kept for the last save's
|
|
501
|
-
// Undo, so a save in this session that returns the block to that same
|
|
502
|
-
// attachment isn't mistaken for it.
|
|
503
|
-
mediaEditorUndoMetadataRef.current = undefined;
|
|
504
|
-
|
|
505
484
|
// Snapshot the attachment's current metadata before the user makes
|
|
506
485
|
// any changes so handleMediaUpdate can compare against it later. Use
|
|
507
486
|
// the cached record when it's already present; only resolve when
|
|
@@ -525,9 +504,24 @@ export function useOpenImageMediaEditorModal( {
|
|
|
525
504
|
: fallbackAttachmentRecord ) ||
|
|
526
505
|
cachedAttachmentRecord;
|
|
527
506
|
|
|
507
|
+
// Each opening owns its Undo snapshot, so a later opening cannot
|
|
508
|
+
// replace the values captured by an earlier snackbar.
|
|
509
|
+
const undoState = { undoAttributes: {}, isUndone: false };
|
|
528
510
|
openMediaEditorModal( {
|
|
529
511
|
id,
|
|
530
|
-
onUpdate: handleMediaUpdate,
|
|
512
|
+
onUpdate: ( updated ) => handleMediaUpdate( updated, undoState ),
|
|
513
|
+
onUndo: () => {
|
|
514
|
+
undoState.isUndone = true;
|
|
515
|
+
const { undoAttributes } = undoState;
|
|
516
|
+
if ( Object.hasOwn( undoAttributes, 'url' ) ) {
|
|
517
|
+
onUrlChange?.( undoAttributes.url );
|
|
518
|
+
}
|
|
519
|
+
blockAttributesRef.current = {
|
|
520
|
+
...blockAttributesRef.current,
|
|
521
|
+
...undoAttributes,
|
|
522
|
+
};
|
|
523
|
+
setAttributes( undoAttributes );
|
|
524
|
+
},
|
|
531
525
|
onClose,
|
|
532
526
|
} );
|
|
533
527
|
}, [
|
|
@@ -535,8 +529,10 @@ export function useOpenImageMediaEditorModal( {
|
|
|
535
529
|
handleMediaUpdate,
|
|
536
530
|
id,
|
|
537
531
|
onClose,
|
|
532
|
+
onUrlChange,
|
|
538
533
|
openMediaEditorModal,
|
|
539
534
|
resolveAttachmentRecord,
|
|
535
|
+
setAttributes,
|
|
540
536
|
] );
|
|
541
537
|
|
|
542
538
|
return id && openMediaEditorModal ? openImageMediaEditorModal : undefined;
|
package/src/image/view.js
CHANGED
|
@@ -30,6 +30,14 @@ const touchStartEvent = {
|
|
|
30
30
|
startTime: 0,
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Elements made inert while the lightbox is open, so only those are restored
|
|
35
|
+
* when it closes.
|
|
36
|
+
*
|
|
37
|
+
* @type {Element[]}
|
|
38
|
+
*/
|
|
39
|
+
let inertElements = [];
|
|
40
|
+
|
|
33
41
|
const focusableSelectors = [
|
|
34
42
|
'.wp-lightbox-close-button',
|
|
35
43
|
'.wp-lightbox-navigation-button',
|
|
@@ -430,7 +438,7 @@ const { state, actions, callbacks } = store(
|
|
|
430
438
|
// Natural ratio of the image clicked to open the lightbox.
|
|
431
439
|
const naturalRatio = naturalWidth / naturalHeight;
|
|
432
440
|
// Original ratio of the image clicked to open the lightbox.
|
|
433
|
-
|
|
441
|
+
const originalRatio = originalWidth / originalHeight;
|
|
434
442
|
|
|
435
443
|
// If it has object-fit: contain, recalculates the original sizes
|
|
436
444
|
// and the screen position without the blank spaces.
|
|
@@ -448,19 +456,18 @@ const { state, actions, callbacks } = store(
|
|
|
448
456
|
originalWidth = widthWithoutSpace;
|
|
449
457
|
}
|
|
450
458
|
}
|
|
451
|
-
originalRatio = originalWidth / originalHeight;
|
|
452
459
|
|
|
453
460
|
// Typically, it uses the image's full-sized dimensions. If those
|
|
454
461
|
// dimensions have not been set (i.e. an external image with only one
|
|
455
462
|
// size), the image's dimensions in the lightbox are the same
|
|
456
463
|
// as those of the image in the content.
|
|
457
|
-
|
|
464
|
+
const imgMaxWidth = parseFloat(
|
|
458
465
|
state.selectedImage.targetWidth &&
|
|
459
466
|
state.selectedImage.targetWidth !== 'none'
|
|
460
467
|
? state.selectedImage.targetWidth
|
|
461
468
|
: naturalWidth
|
|
462
469
|
);
|
|
463
|
-
|
|
470
|
+
const imgMaxHeight = parseFloat(
|
|
464
471
|
state.selectedImage.targetHeight &&
|
|
465
472
|
state.selectedImage.targetHeight !== 'none'
|
|
466
473
|
? state.selectedImage.targetHeight
|
|
@@ -468,54 +475,10 @@ const { state, actions, callbacks } = store(
|
|
|
468
475
|
);
|
|
469
476
|
|
|
470
477
|
// Ratio of the biggest image stored in the database.
|
|
471
|
-
|
|
472
|
-
let containerMaxWidth = imgMaxWidth;
|
|
473
|
-
let containerMaxHeight = imgMaxHeight;
|
|
478
|
+
const fullSizeRatio = imgMaxWidth / imgMaxHeight;
|
|
474
479
|
let containerWidth = imgMaxWidth;
|
|
475
480
|
let containerHeight = imgMaxHeight;
|
|
476
481
|
|
|
477
|
-
// Checks if the target image has a different ratio than the original
|
|
478
|
-
// one (thumbnail). Recalculates the width and height.
|
|
479
|
-
if ( naturalRatio.toFixed( 2 ) !== imgRatio.toFixed( 2 ) ) {
|
|
480
|
-
if ( naturalRatio > imgRatio ) {
|
|
481
|
-
// If the width is reached before the height, it keeps the maxWidth
|
|
482
|
-
// and recalculates the height unless the difference between the
|
|
483
|
-
// maxHeight and the reducedHeight is higher than the maxWidth,
|
|
484
|
-
// where it keeps the reducedHeight and recalculate the width.
|
|
485
|
-
const reducedHeight = imgMaxWidth / naturalRatio;
|
|
486
|
-
if ( imgMaxHeight - reducedHeight > imgMaxWidth ) {
|
|
487
|
-
imgMaxHeight = reducedHeight;
|
|
488
|
-
imgMaxWidth = reducedHeight * naturalRatio;
|
|
489
|
-
} else {
|
|
490
|
-
imgMaxHeight = imgMaxWidth / naturalRatio;
|
|
491
|
-
}
|
|
492
|
-
} else {
|
|
493
|
-
// If the height is reached before the width, it keeps the maxHeight
|
|
494
|
-
// and recalculate the width unlesss the difference between the
|
|
495
|
-
// maxWidth and the reducedWidth is higher than the maxHeight, where
|
|
496
|
-
// it keeps the reducedWidth and recalculate the height.
|
|
497
|
-
const reducedWidth = imgMaxHeight * naturalRatio;
|
|
498
|
-
if ( imgMaxWidth - reducedWidth > imgMaxHeight ) {
|
|
499
|
-
imgMaxWidth = reducedWidth;
|
|
500
|
-
imgMaxHeight = reducedWidth / naturalRatio;
|
|
501
|
-
} else {
|
|
502
|
-
imgMaxWidth = imgMaxHeight * naturalRatio;
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
containerWidth = imgMaxWidth;
|
|
506
|
-
containerHeight = imgMaxHeight;
|
|
507
|
-
imgRatio = imgMaxWidth / imgMaxHeight;
|
|
508
|
-
|
|
509
|
-
// Calculates the max size of the container.
|
|
510
|
-
if ( originalRatio > imgRatio ) {
|
|
511
|
-
containerMaxWidth = imgMaxWidth;
|
|
512
|
-
containerMaxHeight = containerMaxWidth / originalRatio;
|
|
513
|
-
} else {
|
|
514
|
-
containerMaxHeight = imgMaxHeight;
|
|
515
|
-
containerMaxWidth = containerMaxHeight * originalRatio;
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
|
|
519
482
|
// If the image has been pixelated on purpose, it keeps that size.
|
|
520
483
|
if (
|
|
521
484
|
originalWidth > containerWidth ||
|
|
@@ -553,21 +516,35 @@ const { state, actions, callbacks } = store(
|
|
|
553
516
|
);
|
|
554
517
|
const targetContainerRatio = targetMaxWidth / targetMaxHeight;
|
|
555
518
|
|
|
556
|
-
if (
|
|
519
|
+
if ( fullSizeRatio > targetContainerRatio ) {
|
|
557
520
|
// If targetMaxWidth is reached before targetMaxHeight.
|
|
558
521
|
containerWidth = targetMaxWidth;
|
|
559
|
-
containerHeight = containerWidth /
|
|
522
|
+
containerHeight = containerWidth / fullSizeRatio;
|
|
560
523
|
} else {
|
|
561
524
|
// If targetMaxHeight is reached before targetMaxWidth.
|
|
562
525
|
containerHeight = targetMaxHeight;
|
|
563
|
-
containerWidth = containerHeight *
|
|
526
|
+
containerWidth = containerHeight * fullSizeRatio;
|
|
564
527
|
}
|
|
565
528
|
|
|
566
|
-
const
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
529
|
+
const hasCroppedSource =
|
|
530
|
+
naturalRatio.toFixed( 2 ) !== fullSizeRatio.toFixed( 2 );
|
|
531
|
+
const sourceRatio = hasCroppedSource
|
|
532
|
+
? naturalRatio
|
|
533
|
+
: fullSizeRatio;
|
|
534
|
+
|
|
535
|
+
// Include any crop already applied to the thumbnail file.
|
|
536
|
+
const containerScale = Math.max(
|
|
537
|
+
originalWidth / containerWidth,
|
|
538
|
+
originalHeight / containerHeight,
|
|
539
|
+
originalWidth / ( containerHeight * sourceRatio ),
|
|
540
|
+
( originalHeight * sourceRatio ) / containerWidth
|
|
541
|
+
);
|
|
542
|
+
const thumbnailWidth = originalWidth / containerScale;
|
|
543
|
+
const thumbnailHeight = originalHeight / containerScale;
|
|
544
|
+
const cropX = ( containerWidth - thumbnailWidth ) / 2;
|
|
545
|
+
const cropY = ( containerHeight - thumbnailHeight ) / 2;
|
|
546
|
+
screenPosX -= cropX * containerScale;
|
|
547
|
+
screenPosY -= cropY * containerScale;
|
|
571
548
|
|
|
572
549
|
// As of this writing, using the calculations above will render the
|
|
573
550
|
// lightbox with a small, erroneous whitespace on the left side of the
|
|
@@ -580,8 +557,15 @@ const { state, actions, callbacks } = store(
|
|
|
580
557
|
--wp--lightbox-initial-left-position: ${ screenPosX }px;
|
|
581
558
|
--wp--lightbox-container-width: ${ containerWidth + 1 }px;
|
|
582
559
|
--wp--lightbox-container-height: ${ containerHeight + 1 }px;
|
|
583
|
-
--wp--lightbox-image-width: ${
|
|
584
|
-
--wp--lightbox-image-height: ${
|
|
560
|
+
--wp--lightbox-image-width: ${ containerWidth }px;
|
|
561
|
+
--wp--lightbox-image-height: ${ containerHeight }px;
|
|
562
|
+
--wp--lightbox-initial-clip: inset(${ cropY }px ${ cropX }px);
|
|
563
|
+
--wp--lightbox-thumbnail-width: ${
|
|
564
|
+
hasCroppedSource ? thumbnailWidth : containerWidth
|
|
565
|
+
}px;
|
|
566
|
+
--wp--lightbox-thumbnail-height: ${
|
|
567
|
+
hasCroppedSource ? thumbnailHeight : containerHeight
|
|
568
|
+
}px;
|
|
585
569
|
--wp--lightbox-scale: ${ containerScale };
|
|
586
570
|
--wp--lightbox-scrollbar-width: ${
|
|
587
571
|
window.innerWidth - document.documentElement.clientWidth
|
|
@@ -690,16 +674,28 @@ const { state, actions, callbacks } = store(
|
|
|
690
674
|
}
|
|
691
675
|
},
|
|
692
676
|
setInertElements() {
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
677
|
+
if ( ! state.overlayEnabled ) {
|
|
678
|
+
inertElements.forEach( ( el ) =>
|
|
679
|
+
el.removeAttribute( 'inert' )
|
|
680
|
+
);
|
|
681
|
+
inertElements = [];
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
// Inerts the overlay's siblings at each level, not its ancestors.
|
|
685
|
+
const { ref } = getElement();
|
|
686
|
+
let node = ref;
|
|
687
|
+
while ( node && node !== document.body && node.parentElement ) {
|
|
688
|
+
for ( const sibling of node.parentElement.children ) {
|
|
689
|
+
if (
|
|
690
|
+
sibling !== node &&
|
|
691
|
+
! sibling.hasAttribute( 'inert' )
|
|
692
|
+
) {
|
|
693
|
+
sibling.setAttribute( 'inert', '' );
|
|
694
|
+
inertElements.push( sibling );
|
|
701
695
|
}
|
|
702
|
-
}
|
|
696
|
+
}
|
|
697
|
+
node = node.parentElement;
|
|
698
|
+
}
|
|
703
699
|
},
|
|
704
700
|
initTriggerButton() {
|
|
705
701
|
const { imageId } = getContext();
|
|
@@ -33,6 +33,9 @@ _Defined via the [`supports`](https://developer.wordpress.org/block-editor/refer
|
|
|
33
33
|
- [`color`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#color):
|
|
34
34
|
- [`gradients`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#color-gradients): `true`
|
|
35
35
|
- [`link`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#color-link): `true`
|
|
36
|
+
- [`dimensions`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#dimensions):
|
|
37
|
+
- `minHeight`: `true`
|
|
38
|
+
- `minWidth`: `true`
|
|
36
39
|
- [`html`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#html): `false`
|
|
37
40
|
- [`spacing`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#spacing):
|
|
38
41
|
- `margin`: `true`
|
|
@@ -49,11 +49,21 @@
|
|
|
49
49
|
"link": true
|
|
50
50
|
}
|
|
51
51
|
},
|
|
52
|
+
"dimensions": {
|
|
53
|
+
"minHeight": true,
|
|
54
|
+
"minWidth": true
|
|
55
|
+
},
|
|
52
56
|
"html": false,
|
|
53
57
|
"spacing": {
|
|
54
58
|
"margin": true,
|
|
55
59
|
"padding": true
|
|
56
60
|
},
|
|
61
|
+
"__experimentalBorder": {
|
|
62
|
+
"color": true,
|
|
63
|
+
"radius": true,
|
|
64
|
+
"style": true,
|
|
65
|
+
"width": true
|
|
66
|
+
},
|
|
57
67
|
"shadow": true,
|
|
58
68
|
"typography": {
|
|
59
69
|
"fontSize": true,
|
|
@@ -47,6 +47,9 @@ _Defined via the [`supports`](https://developer.wordpress.org/block-editor/refer
|
|
|
47
47
|
- [`color`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#color):
|
|
48
48
|
- [`gradients`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#color-gradients): `true`
|
|
49
49
|
- [`link`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#color-link): `true`
|
|
50
|
+
- [`dimensions`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#dimensions):
|
|
51
|
+
- `minHeight`: `true`
|
|
52
|
+
- `minWidth`: `true`
|
|
50
53
|
- [`spacing`](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#spacing):
|
|
51
54
|
- `margin`: `true`
|
|
52
55
|
- `padding`: `true`
|