@wordpress/block-library 9.44.0 → 9.45.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/accordion/edit.cjs +0 -2
- package/build/accordion/edit.cjs.map +2 -2
- package/build/accordion-item/block.json +1 -0
- package/build/button/constants.cjs +1 -1
- package/build/button/constants.cjs.map +1 -1
- package/build/categories/edit.cjs +5 -1
- package/build/categories/edit.cjs.map +2 -2
- package/build/embed/edit.cjs +38 -34
- package/build/embed/edit.cjs.map +3 -3
- package/build/embed/transforms.cjs +3 -1
- package/build/embed/transforms.cjs.map +2 -2
- package/build/embed/util.cjs +13 -2
- package/build/embed/util.cjs.map +2 -2
- package/build/form/block.json +1 -1
- package/build/form-input/block.json +1 -1
- package/build/form-submission-notification/block.json +1 -1
- package/build/form-submit-button/block.json +1 -1
- package/build/group/block.json +2 -1
- package/build/image/constants.cjs +1 -1
- package/build/image/constants.cjs.map +2 -2
- package/build/image/edit.cjs +2 -4
- package/build/image/edit.cjs.map +2 -2
- package/build/image/image.cjs +49 -19
- package/build/image/image.cjs.map +3 -3
- package/build/index.cjs +4 -4
- package/build/index.cjs.map +2 -2
- package/build/latest-posts/edit.cjs +1 -1
- package/build/latest-posts/edit.cjs.map +1 -1
- package/build/math/edit.cjs +2 -2
- package/build/math/edit.cjs.map +2 -2
- package/build/navigation/edit/accessible-description.cjs +2 -2
- package/build/navigation/edit/accessible-description.cjs.map +2 -2
- package/build/navigation/edit/overlay-template-part-selector.cjs.map +2 -2
- package/build/navigation-link/edit.cjs +2 -1
- package/build/navigation-link/edit.cjs.map +2 -2
- package/build/navigation-link/link-ui/dialog-wrapper.cjs +2 -1
- package/build/navigation-link/link-ui/dialog-wrapper.cjs.map +2 -2
- package/build/navigation-link/link-ui/index.cjs +2 -1
- package/build/navigation-link/link-ui/index.cjs.map +2 -2
- package/build/paragraph/use-enter.cjs +12 -23
- package/build/paragraph/use-enter.cjs.map +2 -2
- package/build/post-author/edit.cjs.map +3 -3
- package/build/post-comments-form/edit.cjs +2 -2
- package/build/post-comments-form/edit.cjs.map +2 -2
- package/build/post-featured-image/edit.cjs +2 -5
- package/build/post-featured-image/edit.cjs.map +2 -2
- package/build/post-template/edit.cjs +8 -2
- package/build/post-template/edit.cjs.map +2 -2
- package/build/pullquote/block.json +1 -4
- package/build/query/edit/inspector-controls/author-control.cjs +1 -1
- package/build/query/edit/inspector-controls/author-control.cjs.map +2 -2
- package/build/query/edit/inspector-controls/format-controls.cjs +1 -1
- package/build/query/edit/inspector-controls/format-controls.cjs.map +2 -2
- package/build/query/edit/inspector-controls/parent-control.cjs +1 -1
- package/build/query/edit/inspector-controls/parent-control.cjs.map +2 -2
- package/build/query/edit/inspector-controls/taxonomy-controls.cjs +1 -1
- package/build/query/edit/inspector-controls/taxonomy-controls.cjs.map +2 -2
- package/build/site-logo/edit.cjs +34 -20
- package/build/site-logo/edit.cjs.map +2 -2
- package/build/tab/block.json +23 -23
- package/build/tab/controls.cjs +5 -48
- package/build/tab/controls.cjs.map +3 -3
- package/build/tab/edit.cjs +76 -92
- package/build/tab/edit.cjs.map +3 -3
- package/build/tab/save.cjs +3 -3
- package/build/tab/save.cjs.map +2 -2
- package/{src/tabs-menu → build/tab-list}/block.json +4 -4
- package/build/{tabs-menu → tab-list}/edit.cjs +9 -14
- package/build/tab-list/edit.cjs.map +7 -0
- package/build/{tabs-menu → tab-list}/index.cjs +5 -5
- package/build/tab-list/index.cjs.map +7 -0
- package/build/{tabs-menu → tab-list}/save.cjs +1 -1
- package/build/{tabs-menu → tab-list}/save.cjs.map +1 -1
- package/build/{tab → tab-panel}/add-tab-toolbar-control.cjs +16 -16
- package/build/tab-panel/add-tab-toolbar-control.cjs.map +7 -0
- package/build/tab-panel/block.json +27 -37
- package/build/tab-panel/controls.cjs +89 -0
- package/build/tab-panel/controls.cjs.map +7 -0
- package/build/tab-panel/edit.cjs +88 -18
- package/build/tab-panel/edit.cjs.map +3 -3
- package/build/tab-panel/index.cjs +1 -1
- package/build/tab-panel/index.cjs.map +1 -1
- package/build/{tab → tab-panel}/init.cjs +1 -1
- package/build/{tab → tab-panel}/init.cjs.map +1 -1
- package/build/{tab → tab-panel}/remove-tab-toolbar-control.cjs +16 -16
- package/build/tab-panel/remove-tab-toolbar-control.cjs.map +7 -0
- package/build/tab-panel/save.cjs +4 -2
- package/build/tab-panel/save.cjs.map +2 -2
- package/build/tab-panels/block.json +66 -0
- package/build/{tabs-menu-item/controls.cjs → tab-panels/edit.cjs} +25 -11
- package/build/tab-panels/edit.cjs.map +7 -0
- package/build/{tabs-menu-item → tab-panels}/index.cjs +5 -5
- package/build/{tabs-menu → tab-panels}/index.cjs.map +2 -2
- package/build/{tabs-menu-item → tab-panels}/save.cjs +4 -6
- package/build/tab-panels/save.cjs.map +7 -0
- package/build/tabs/block.json +1 -2
- package/build/tabs/controls.cjs +2 -2
- package/build/tabs/controls.cjs.map +1 -1
- package/build/tabs/edit.cjs +29 -100
- package/build/tabs/edit.cjs.map +3 -3
- package/build/tabs/index.cjs +5 -5
- package/build/tabs/index.cjs.map +1 -1
- package/build/tabs/use-tab-list-sync.cjs +190 -0
- package/build/tabs/use-tab-list-sync.cjs.map +7 -0
- package/build/terms-query/edit/inspector-controls/include-control.cjs +1 -1
- package/build/terms-query/edit/inspector-controls/include-control.cjs.map +2 -2
- package/build/video/tracks-editor.cjs +2 -2
- package/build/video/tracks-editor.cjs.map +2 -2
- package/build-module/accordion/edit.mjs +0 -2
- package/build-module/accordion/edit.mjs.map +2 -2
- package/build-module/accordion-item/block.json +1 -0
- package/build-module/button/constants.mjs +1 -1
- package/build-module/button/constants.mjs.map +1 -1
- package/build-module/categories/edit.mjs +5 -2
- package/build-module/categories/edit.mjs.map +2 -2
- package/build-module/embed/edit.mjs +45 -36
- package/build-module/embed/edit.mjs.map +2 -2
- package/build-module/embed/transforms.mjs +8 -2
- package/build-module/embed/transforms.mjs.map +2 -2
- package/build-module/embed/util.mjs +11 -1
- package/build-module/embed/util.mjs.map +2 -2
- package/build-module/form/block.json +1 -1
- package/build-module/form-input/block.json +1 -1
- package/build-module/form-submission-notification/block.json +1 -1
- package/build-module/form-submit-button/block.json +1 -1
- package/build-module/group/block.json +2 -1
- package/build-module/image/constants.mjs +1 -1
- package/build-module/image/constants.mjs.map +2 -2
- package/build-module/image/edit.mjs +2 -4
- package/build-module/image/edit.mjs.map +2 -2
- package/build-module/image/image.mjs +49 -19
- package/build-module/image/image.mjs.map +3 -3
- package/build-module/index.mjs +4 -4
- package/build-module/index.mjs.map +2 -2
- package/build-module/latest-posts/edit.mjs +1 -1
- package/build-module/latest-posts/edit.mjs.map +1 -1
- package/build-module/math/edit.mjs +2 -2
- package/build-module/math/edit.mjs.map +2 -2
- package/build-module/navigation/edit/accessible-description.mjs +1 -1
- package/build-module/navigation/edit/accessible-description.mjs.map +1 -1
- package/build-module/navigation/edit/overlay-template-part-selector.mjs +2 -2
- package/build-module/navigation/edit/overlay-template-part-selector.mjs.map +1 -1
- package/build-module/navigation-link/edit.mjs +2 -5
- package/build-module/navigation-link/edit.mjs.map +2 -2
- package/build-module/navigation-link/link-ui/dialog-wrapper.mjs +2 -1
- package/build-module/navigation-link/link-ui/dialog-wrapper.mjs.map +2 -2
- package/build-module/navigation-link/link-ui/index.mjs +1 -1
- package/build-module/navigation-link/link-ui/index.mjs.map +2 -2
- package/build-module/paragraph/use-enter.mjs +13 -23
- package/build-module/paragraph/use-enter.mjs.map +2 -2
- package/build-module/post-author/edit.mjs +2 -2
- package/build-module/post-author/edit.mjs.map +2 -2
- package/build-module/post-comments-form/edit.mjs +1 -1
- package/build-module/post-comments-form/edit.mjs.map +2 -2
- package/build-module/post-featured-image/edit.mjs +2 -5
- package/build-module/post-featured-image/edit.mjs.map +2 -2
- package/build-module/post-template/edit.mjs +8 -2
- package/build-module/post-template/edit.mjs.map +2 -2
- package/build-module/pullquote/block.json +1 -4
- package/build-module/query/edit/inspector-controls/author-control.mjs +1 -1
- package/build-module/query/edit/inspector-controls/author-control.mjs.map +2 -2
- package/build-module/query/edit/inspector-controls/format-controls.mjs +1 -1
- package/build-module/query/edit/inspector-controls/format-controls.mjs.map +2 -2
- package/build-module/query/edit/inspector-controls/parent-control.mjs +1 -1
- package/build-module/query/edit/inspector-controls/parent-control.mjs.map +2 -2
- package/build-module/query/edit/inspector-controls/taxonomy-controls.mjs +1 -1
- package/build-module/query/edit/inspector-controls/taxonomy-controls.mjs.map +2 -2
- package/build-module/site-logo/edit.mjs +34 -20
- package/build-module/site-logo/edit.mjs.map +2 -2
- package/build-module/tab/block.json +23 -23
- package/build-module/tab/controls.mjs +7 -57
- package/build-module/tab/controls.mjs.map +2 -2
- package/build-module/tab/edit.mjs +80 -96
- package/build-module/tab/edit.mjs.map +3 -3
- package/build-module/tab/save.mjs +4 -4
- package/build-module/tab/save.mjs.map +2 -2
- package/build-module/{tabs-menu → tab-list}/block.json +4 -4
- package/build-module/{tabs-menu → tab-list}/edit.mjs +9 -14
- package/build-module/tab-list/edit.mjs.map +7 -0
- package/build-module/{tabs-menu → tab-list}/index.mjs +2 -2
- package/build-module/tab-list/index.mjs.map +7 -0
- package/build-module/{tabs-menu → tab-list}/save.mjs +1 -1
- package/build-module/{tabs-menu → tab-list}/save.mjs.map +1 -1
- package/build-module/{tab → tab-panel}/add-tab-toolbar-control.mjs +16 -16
- package/build-module/tab-panel/add-tab-toolbar-control.mjs.map +7 -0
- package/build-module/tab-panel/block.json +27 -37
- package/build-module/tab-panel/controls.mjs +65 -0
- package/build-module/tab-panel/controls.mjs.map +7 -0
- package/build-module/tab-panel/edit.mjs +90 -20
- package/build-module/tab-panel/edit.mjs.map +2 -2
- package/build-module/tab-panel/index.mjs +1 -1
- package/build-module/tab-panel/index.mjs.map +1 -1
- package/build-module/{tab → tab-panel}/init.mjs +1 -1
- package/build-module/{tab → tab-panel}/init.mjs.map +1 -1
- package/build-module/{tab → tab-panel}/remove-tab-toolbar-control.mjs +16 -16
- package/build-module/tab-panel/remove-tab-toolbar-control.mjs.map +7 -0
- package/build-module/tab-panel/save.mjs +4 -2
- package/build-module/tab-panel/save.mjs.map +2 -2
- package/build-module/tab-panels/block.json +66 -0
- package/build-module/tab-panels/edit.mjs +33 -0
- package/build-module/tab-panels/edit.mjs.map +7 -0
- package/build-module/{tabs-menu-item → tab-panels}/index.mjs +2 -2
- package/build-module/{tabs-menu → tab-panels}/index.mjs.map +2 -2
- package/build-module/tab-panels/save.mjs +12 -0
- package/build-module/tab-panels/save.mjs.map +7 -0
- package/build-module/tabs/block.json +1 -2
- package/build-module/tabs/controls.mjs +2 -2
- package/build-module/tabs/controls.mjs.map +1 -1
- package/build-module/tabs/edit.mjs +31 -102
- package/build-module/tabs/edit.mjs.map +2 -2
- package/build-module/tabs/index.mjs +5 -5
- package/build-module/tabs/index.mjs.map +1 -1
- package/build-module/tabs/use-tab-list-sync.mjs +169 -0
- package/build-module/tabs/use-tab-list-sync.mjs.map +7 -0
- package/build-module/terms-query/edit/inspector-controls/include-control.mjs +1 -1
- package/build-module/terms-query/edit/inspector-controls/include-control.mjs.map +2 -2
- package/build-module/video/tracks-editor.mjs +2 -2
- package/build-module/video/tracks-editor.mjs.map +2 -2
- package/build-style/classic-rtl.css +14 -0
- package/build-style/classic.css +14 -0
- package/build-style/editor-rtl.css +9 -5
- package/build-style/editor.css +9 -5
- package/build-style/latest-comments/style-rtl.css +4 -4
- package/build-style/latest-comments/style.css +4 -4
- package/build-style/post-template/style-rtl.css +1 -1
- package/build-style/post-template/style.css +1 -1
- package/build-style/style-rtl.css +45 -48
- package/build-style/style.css +45 -48
- package/build-style/tab/editor-rtl.css +11 -0
- package/build-style/tab/editor.css +11 -0
- package/build-style/tab/style-rtl.css +29 -16
- package/build-style/tab/style.css +29 -16
- package/build-style/tab-list/editor-rtl.css +6 -0
- package/build-style/tab-list/editor.css +6 -0
- package/build-style/tab-panel/style-rtl.css +17 -1
- package/build-style/tab-panel/style.css +17 -1
- package/build-style/tab-panels/style-rtl.css +4 -0
- package/build-style/tab-panels/style.css +4 -0
- package/build-style/tabs/style-rtl.css +0 -3
- package/build-style/tabs/style.css +0 -3
- package/build-style/video/editor-rtl.css +4 -0
- package/build-style/video/editor.css +4 -0
- package/package.json +39 -38
- package/src/accordion/edit.js +0 -2
- package/src/accordion-item/block.json +1 -0
- package/src/block/test/edit.native.js +1 -1
- package/src/button/constants.js +1 -1
- package/src/button/test/get-updated-link-attributes.js +6 -10
- package/src/categories/edit.js +3 -2
- package/src/classic.scss +25 -0
- package/src/editor.scss +2 -2
- package/src/embed/edit.js +61 -52
- package/src/embed/edit.native.js +71 -57
- package/src/embed/transforms.js +8 -2
- package/src/embed/util.js +17 -0
- package/src/form/block.json +1 -1
- package/src/form-input/block.json +1 -1
- package/src/form-submission-notification/block.json +1 -1
- package/src/form-submit-button/block.json +1 -1
- package/src/group/block.json +2 -1
- package/src/image/constants.js +1 -1
- package/src/image/edit.js +5 -3
- package/src/image/edit.native.js +3 -3
- package/src/image/image.js +63 -27
- package/src/image/test/edit.native.js +2 -2
- package/src/index.js +4 -4
- package/src/latest-comments/style.scss +7 -7
- package/src/latest-posts/edit.js +1 -1
- package/src/latest-posts/index.php +1 -1
- package/src/math/edit.js +3 -3
- package/src/navigation/edit/accessible-description.js +1 -1
- package/src/navigation/edit/overlay-template-part-selector.js +3 -3
- package/src/navigation/edit/test/overlay-template-part-selector.js +1 -0
- package/src/navigation-link/edit.js +2 -5
- package/src/navigation-link/link-ui/dialog-wrapper.js +2 -1
- package/src/navigation-link/link-ui/index.js +1 -1
- package/src/paragraph/use-enter.js +18 -24
- package/src/post-author/edit.js +3 -5
- package/src/post-comments-form/edit.js +1 -1
- package/src/post-featured-image/edit.js +2 -9
- package/src/post-template/edit.js +7 -1
- package/src/post-template/index.php +3 -0
- package/src/post-template/style.scss +2 -2
- package/src/pullquote/block.json +1 -4
- package/src/query/edit/inspector-controls/author-control.js +1 -1
- package/src/query/edit/inspector-controls/format-controls.js +1 -1
- package/src/query/edit/inspector-controls/parent-control.js +1 -1
- package/src/query/edit/inspector-controls/taxonomy-controls.js +1 -1
- package/src/site-logo/edit.js +40 -20
- package/src/style.scss +1 -1
- package/src/tab/block.json +23 -23
- package/src/tab/controls.js +6 -52
- package/src/tab/edit.js +94 -123
- package/src/{tabs-menu-item → tab}/editor.scss +3 -3
- package/src/tab/index.php +32 -51
- package/src/tab/save.js +4 -4
- package/src/tab/style.scss +34 -17
- package/{build/tabs-menu → src/tab-list}/block.json +4 -4
- package/src/{tabs-menu → tab-list}/edit.js +9 -18
- package/src/{tabs-menu → tab-list}/editor.scss +2 -2
- package/src/{tabs-menu → tab-list}/index.js +1 -1
- package/src/tab-list/index.php +80 -0
- package/src/{tab → tab-panel}/add-tab-toolbar-control.js +19 -19
- package/src/tab-panel/block.json +27 -37
- package/src/tab-panel/controls.js +65 -0
- package/src/tab-panel/edit.js +121 -20
- package/src/tab-panel/index.js +1 -1
- package/src/tab-panel/index.php +88 -0
- package/src/{tab → tab-panel}/remove-tab-toolbar-control.js +20 -19
- package/src/tab-panel/save.js +4 -2
- package/src/tab-panel/style.scss +20 -1
- package/src/tab-panels/block.json +66 -0
- package/src/tab-panels/edit.js +42 -0
- package/src/{tabs-menu-item → tab-panels}/index.js +1 -1
- package/src/tab-panels/save.js +11 -0
- package/src/tab-panels/style.scss +4 -0
- package/src/tabs/block.json +1 -2
- package/src/tabs/controls.js +2 -2
- package/src/tabs/edit.js +32 -150
- package/src/tabs/index.js +5 -5
- package/src/tabs/index.php +5 -5
- package/src/tabs/style.scss +0 -3
- package/src/tabs/use-tab-list-sync.js +237 -0
- package/src/terms-query/edit/inspector-controls/include-control.js +1 -1
- package/src/video/editor.scss +5 -0
- package/src/video/tracks-editor.js +2 -2
- package/build/tab/add-tab-toolbar-control.cjs.map +0 -7
- package/build/tab/remove-tab-toolbar-control.cjs.map +0 -7
- package/build/tab/slug-from-label.cjs +0 -37
- package/build/tab/slug-from-label.cjs.map +0 -7
- package/build/tabs-menu/edit.cjs.map +0 -7
- package/build/tabs-menu-item/block.json +0 -59
- package/build/tabs-menu-item/controls.cjs.map +0 -7
- package/build/tabs-menu-item/edit.cjs +0 -144
- package/build/tabs-menu-item/edit.cjs.map +0 -7
- package/build/tabs-menu-item/index.cjs.map +0 -7
- package/build/tabs-menu-item/save.cjs.map +0 -7
- package/build-module/tab/add-tab-toolbar-control.mjs.map +0 -7
- package/build-module/tab/remove-tab-toolbar-control.mjs.map +0 -7
- package/build-module/tab/slug-from-label.mjs +0 -16
- package/build-module/tab/slug-from-label.mjs.map +0 -7
- package/build-module/tabs-menu/edit.mjs.map +0 -7
- package/build-module/tabs-menu-item/block.json +0 -59
- package/build-module/tabs-menu-item/controls.mjs +0 -15
- package/build-module/tabs-menu-item/controls.mjs.map +0 -7
- package/build-module/tabs-menu-item/edit.mjs +0 -117
- package/build-module/tabs-menu-item/edit.mjs.map +0 -7
- package/build-module/tabs-menu-item/index.mjs.map +0 -7
- package/build-module/tabs-menu-item/save.mjs +0 -14
- package/build-module/tabs-menu-item/save.mjs.map +0 -7
- package/build-style/tabs-menu/editor-rtl.css +0 -6
- package/build-style/tabs-menu/editor.css +0 -6
- package/build-style/tabs-menu-item/editor-rtl.css +0 -11
- package/build-style/tabs-menu-item/editor.css +0 -11
- package/build-style/tabs-menu-item/style-rtl.css +0 -33
- package/build-style/tabs-menu-item/style.css +0 -33
- package/src/tab/slug-from-label.js +0 -26
- package/src/tabs-menu/index.php +0 -80
- package/src/tabs-menu-item/block.json +0 -59
- package/src/tabs-menu-item/controls.js +0 -19
- package/src/tabs-menu-item/edit.js +0 -150
- package/src/tabs-menu-item/index.php +0 -70
- package/src/tabs-menu-item/save.js +0 -13
- package/src/tabs-menu-item/style.scss +0 -40
- /package/src/{tabs-menu → tab-list}/save.js +0 -0
- /package/src/{tab → tab-panel}/init.js +0 -0
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
getBlockType,
|
|
9
9
|
getBlockVariations
|
|
10
10
|
} from "@wordpress/blocks";
|
|
11
|
+
import { getAuthority } from "@wordpress/url";
|
|
11
12
|
import metadata from "./block.json";
|
|
12
13
|
import { ASPECT_RATIOS, WP_EMBED_TYPE } from "./constants.mjs";
|
|
13
14
|
import { unlock } from "../lock-unlock.mjs";
|
|
@@ -21,6 +22,14 @@ var matchesPatterns = (url, patterns = []) => patterns.some((pattern) => url.mat
|
|
|
21
22
|
var findMoreSuitableBlock = (url) => getBlockVariations(DEFAULT_EMBED_BLOCK)?.find(
|
|
22
23
|
({ patterns }) => matchesPatterns(url, patterns)
|
|
23
24
|
);
|
|
25
|
+
function rewriteXToTwitter(url) {
|
|
26
|
+
if (!url || getAuthority(url) !== "x.com") {
|
|
27
|
+
return url;
|
|
28
|
+
}
|
|
29
|
+
const rewritten = new URL(url);
|
|
30
|
+
rewritten.host = "twitter.com";
|
|
31
|
+
return rewritten.toString();
|
|
32
|
+
}
|
|
24
33
|
var isFromWordPress = (html) => html && html.includes('class="wp-embedded-content"');
|
|
25
34
|
var getPhotoHtml = (photo) => {
|
|
26
35
|
const imageUrl = photo.url || photo.thumbnail_url;
|
|
@@ -181,6 +190,7 @@ export {
|
|
|
181
190
|
hasInlineResponsivePadding,
|
|
182
191
|
isFromWordPress,
|
|
183
192
|
matchesPatterns,
|
|
184
|
-
removeAspectRatioClasses
|
|
193
|
+
removeAspectRatioClasses,
|
|
194
|
+
rewriteXToTwitter
|
|
185
195
|
};
|
|
186
196
|
//# sourceMappingURL=util.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/embed/util.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport memoize from 'memize';\n\n/**\n * WordPress dependencies\n */\nimport { privateApis as componentsPrivateApis } from '@wordpress/components';\nimport { renderToString } from '@wordpress/element';\nimport {\n\tcreateBlock,\n\tgetBlockType,\n\tgetBlockVariations,\n} from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport metadata from './block.json';\nimport { ASPECT_RATIOS, WP_EMBED_TYPE } from './constants';\nimport { unlock } from '../lock-unlock';\n\nconst { name: DEFAULT_EMBED_BLOCK } = metadata;\nconst { kebabCase } = unlock( componentsPrivateApis );\n\n/** @typedef {import('@wordpress/blocks').WPBlockVariation} WPBlockVariation */\n\n/**\n * Returns the embed block's information by matching the provided service provider\n *\n * @param {string} provider The embed block's provider\n * @return {WPBlockVariation} The embed block's information\n */\nexport const getEmbedInfoByProvider = ( provider ) =>\n\tgetBlockVariations( DEFAULT_EMBED_BLOCK )?.find(\n\t\t( { name } ) => name === provider\n\t);\n\n/**\n * Returns true if any of the regular expressions match the URL.\n *\n * @param {string} url The URL to test.\n * @param {Array} patterns The list of regular expressions to test against.\n * @return {boolean} True if any of the regular expressions match the URL.\n */\nexport const matchesPatterns = ( url, patterns = [] ) =>\n\tpatterns.some( ( pattern ) => url.match( pattern ) );\n\n/**\n * Finds the block variation that should be used for the URL,\n * based on the provided URL and the variation's patterns.\n *\n * @param {string} url The URL to test.\n * @return {WPBlockVariation} The block variation that should be used for this URL\n */\nexport const findMoreSuitableBlock = ( url ) =>\n\tgetBlockVariations( DEFAULT_EMBED_BLOCK )?.find( ( { patterns } ) =>\n\t\tmatchesPatterns( url, patterns )\n\t);\n\nexport const isFromWordPress = ( html ) =>\n\thtml && html.includes( 'class=\"wp-embedded-content\"' );\n\nexport const getPhotoHtml = ( photo ) => {\n\t// If full image url not found use thumbnail.\n\tconst imageUrl = photo.url || photo.thumbnail_url;\n\n\t// 100% width for the preview so it fits nicely into the document, some \"thumbnails\" are\n\t// actually the full size photo.\n\tconst photoPreview = (\n\t\t<p>\n\t\t\t<img src={ imageUrl } alt={ photo.title } width=\"100%\" />\n\t\t</p>\n\t);\n\treturn renderToString( photoPreview );\n};\n\n/**\n * Creates a more suitable embed block based on the passed in props\n * and attributes generated from an embed block's preview.\n *\n * We require `attributesFromPreview` to be generated from the latest attributes\n * and preview, and because of the way the react lifecycle operates, we can't\n * guarantee that the attributes contained in the block's props are the latest\n * versions, so we require that these are generated separately.\n * See `getAttributesFromPreview` in the generated embed edit component.\n *\n * @param {Object} props The block's props.\n * @param {Object} [attributesFromPreview] Attributes generated from the block's most up to date preview.\n * @return {Object|undefined} A more suitable embed block if one exists.\n */\nexport const createUpgradedEmbedBlock = (\n\tprops,\n\tattributesFromPreview = {}\n) => {\n\tconst { preview, attributes = {} } = props;\n\tconst { url, providerNameSlug, type, ...restAttributes } = attributes;\n\n\tif ( ! url || ! getBlockType( DEFAULT_EMBED_BLOCK ) ) {\n\t\treturn;\n\t}\n\n\tconst matchedBlock = findMoreSuitableBlock( url );\n\n\t// WordPress blocks can work on multiple sites, and so don't have patterns,\n\t// so if we're in a WordPress block, assume the user has chosen it for a WordPress URL.\n\tconst isCurrentBlockWP =\n\t\tproviderNameSlug === 'wordpress' || type === WP_EMBED_TYPE;\n\t// If current block is not WordPress and a more suitable block found\n\t// that is different from the current one, create the new matched block.\n\tconst shouldCreateNewBlock =\n\t\t! isCurrentBlockWP &&\n\t\tmatchedBlock &&\n\t\t( matchedBlock.attributes.providerNameSlug !== providerNameSlug ||\n\t\t\t! providerNameSlug );\n\tif ( shouldCreateNewBlock ) {\n\t\treturn createBlock( DEFAULT_EMBED_BLOCK, {\n\t\t\turl,\n\t\t\t...restAttributes,\n\t\t\t...matchedBlock.attributes,\n\t\t} );\n\t}\n\n\tconst wpVariation = getBlockVariations( DEFAULT_EMBED_BLOCK )?.find(\n\t\t( { name } ) => name === 'wordpress'\n\t);\n\n\t// We can't match the URL for WordPress embeds, we have to check the HTML instead.\n\tif (\n\t\t! wpVariation ||\n\t\t! preview ||\n\t\t! isFromWordPress( preview.html ) ||\n\t\tisCurrentBlockWP\n\t) {\n\t\treturn;\n\t}\n\n\t// This is not the WordPress embed block so transform it into one.\n\treturn createBlock( DEFAULT_EMBED_BLOCK, {\n\t\turl,\n\t\t...wpVariation.attributes,\n\t\t// By now we have the preview, but when the new block first renders, it\n\t\t// won't have had all the attributes set, and so won't get the correct\n\t\t// type and it won't render correctly. So, we pass through the current attributes\n\t\t// here so that the initial render works when we switch to the WordPress\n\t\t// block. This only affects the WordPress block because it can't be\n\t\t// rendered in the usual Sandbox (it has a sandbox of its own) and it\n\t\t// relies on the preview to set the correct render type.\n\t\t...attributesFromPreview,\n\t} );\n};\n\n/**\n * Determine if the block already has an aspect ratio class applied.\n *\n * @param {string} existingClassNames Existing block classes.\n * @return {boolean} True or false if the classnames contain an aspect ratio class.\n */\nexport const hasAspectRatioClass = ( existingClassNames ) => {\n\tif ( ! existingClassNames ) {\n\t\treturn false;\n\t}\n\treturn ASPECT_RATIOS.some( ( { className } ) =>\n\t\texistingClassNames.includes( className )\n\t);\n};\n\n/**\n * Removes all previously set aspect ratio related classes and return the rest\n * existing class names.\n *\n * @param {string} existingClassNames Any existing class names.\n * @return {string} The class names without any aspect ratio related class.\n */\nexport const removeAspectRatioClasses = ( existingClassNames ) => {\n\tif ( ! existingClassNames ) {\n\t\t// Avoids extraneous work and also, by returning the same value as\n\t\t// received, ensures the post is not dirtied by a change of the block\n\t\t// attribute from `undefined` to an empty string.\n\t\treturn existingClassNames;\n\t}\n\tconst aspectRatioClassNames = ASPECT_RATIOS.reduce(\n\t\t( accumulator, { className } ) => {\n\t\t\taccumulator.push( className );\n\t\t\treturn accumulator;\n\t\t},\n\t\t[ 'wp-has-aspect-ratio' ]\n\t);\n\tlet outputClassNames = existingClassNames;\n\tfor ( const className of aspectRatioClassNames ) {\n\t\toutputClassNames = outputClassNames.replace( className, '' );\n\t}\n\treturn outputClassNames.trim();\n};\n\n/**\n * Checks if HTML already contains responsive aspect ratio styling.\n * Some embed providers (like Flickr) include their own responsive wrapper\n * with padding-bottom or padding-top percentages for aspect ratio.\n *\n * @param {string} html The embed HTML to check.\n * @return {boolean} True if the HTML already has responsive styling.\n */\nexport function hasInlineResponsivePadding( html ) {\n\t// Check for padding-bottom or padding-top with percentage values in style attributes\n\t// This pattern matches: padding-bottom: 56.25%; or padding-top: 50%; etc.\n\tconst paddingPattern = /padding-(top|bottom)\\s*:\\s*[\\d.]+%/i;\n\treturn paddingPattern.test( html );\n}\n\n/**\n * Returns class names with any relevant responsive aspect ratio names.\n *\n * @param {string} html The preview HTML that possibly contains an iframe with width and height set.\n * @param {string} existingClassNames Any existing class names.\n * @param {boolean} allowResponsive If the responsive class names should be added, or removed.\n * @return {string} Deduped class names.\n */\nexport function getClassNames(\n\thtml,\n\texistingClassNames,\n\tallowResponsive = true\n) {\n\tif ( ! allowResponsive ) {\n\t\treturn removeAspectRatioClasses( existingClassNames );\n\t}\n\n\t// If the embed HTML already contains responsive wrapper styling (like Flickr),\n\t// don't add our own aspect ratio classes to avoid double padding.\n\tif ( hasInlineResponsivePadding( html ) ) {\n\t\treturn removeAspectRatioClasses( existingClassNames );\n\t}\n\n\tconst previewDocument = document.implementation.createHTMLDocument( '' );\n\tpreviewDocument.body.innerHTML = html;\n\tconst iframe = previewDocument.body.querySelector( 'iframe' );\n\n\t// If we have a fixed aspect iframe, and it's a responsive embed block.\n\tif ( iframe && iframe.height && iframe.width ) {\n\t\tconst aspectRatio = ( iframe.width / iframe.height ).toFixed( 2 );\n\t\t// Given the actual aspect ratio, find the widest ratio to support it.\n\t\tfor (\n\t\t\tlet ratioIndex = 0;\n\t\t\tratioIndex < ASPECT_RATIOS.length;\n\t\t\tratioIndex++\n\t\t) {\n\t\t\tconst potentialRatio = ASPECT_RATIOS[ ratioIndex ];\n\t\t\tif ( aspectRatio >= potentialRatio.ratio ) {\n\t\t\t\t// Evaluate the difference between actual aspect ratio and closest match.\n\t\t\t\t// If the difference is too big, do not scale the embed according to aspect ratio.\n\t\t\t\tconst ratioDiff = aspectRatio - potentialRatio.ratio;\n\t\t\t\tif ( ratioDiff > 0.1 ) {\n\t\t\t\t\t// No close aspect ratio match found.\n\t\t\t\t\treturn removeAspectRatioClasses( existingClassNames );\n\t\t\t\t}\n\t\t\t\t// Close aspect ratio match found.\n\t\t\t\treturn clsx(\n\t\t\t\t\tremoveAspectRatioClasses( existingClassNames ),\n\t\t\t\t\tpotentialRatio.className,\n\t\t\t\t\t'wp-has-aspect-ratio'\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn existingClassNames;\n}\n\n/**\n * Fallback behaviour for unembeddable URLs.\n * Creates a paragraph block containing a link to the URL, and calls `onReplace`.\n *\n * @param {string} url The URL that could not be embedded.\n * @param {Function} onReplace Function to call with the created fallback block.\n */\nexport function fallback( url, onReplace ) {\n\tconst link = <a href={ url }>{ url }</a>;\n\tonReplace(\n\t\tcreateBlock( 'core/paragraph', { content: renderToString( link ) } )\n\t);\n}\n\n/***\n * Gets block attributes based on the preview and responsive state.\n *\n * @param {Object} preview The preview data.\n * @param {string} title The block's title, e.g. Twitter.\n * @param {Object} currentClassNames The block's current class names.\n * @param {boolean} isResponsive Boolean indicating if the block supports responsive content.\n * @param {boolean} allowResponsive Apply responsive classes to fixed size content.\n * @return {Object} Attributes and values.\n */\nexport const getAttributesFromPreview = memoize(\n\t(\n\t\tpreview,\n\t\ttitle,\n\t\tcurrentClassNames,\n\t\tisResponsive,\n\t\tallowResponsive = true\n\t) => {\n\t\tif ( ! preview ) {\n\t\t\treturn {};\n\t\t}\n\n\t\tconst attributes = {};\n\t\t// Some plugins only return HTML with no type info, so default this to 'rich'.\n\t\tlet { type = 'rich' } = preview;\n\t\t// If we got a provider name from the API, use it for the slug, otherwise we use the title,\n\t\t// because not all embed code gives us a provider name.\n\t\tconst { html, provider_name: providerName } = preview;\n\t\tconst providerNameSlug = kebabCase(\n\t\t\t( providerName || title ).toLowerCase()\n\t\t);\n\n\t\tif ( isFromWordPress( html ) ) {\n\t\t\ttype = WP_EMBED_TYPE;\n\t\t}\n\n\t\tif ( html || 'photo' === type ) {\n\t\t\tattributes.type = type;\n\t\t\tattributes.providerNameSlug = providerNameSlug;\n\t\t}\n\n\t\t// Aspect ratio classes are removed when the embed URL is updated.\n\t\t// If the embed already has an aspect ratio class, that means the URL has not changed.\n\t\t// Which also means no need to regenerate it with getClassNames.\n\t\tif ( hasAspectRatioClass( currentClassNames ) ) {\n\t\t\treturn attributes;\n\t\t}\n\n\t\tattributes.className = getClassNames(\n\t\t\thtml,\n\t\t\tcurrentClassNames,\n\t\t\tisResponsive && allowResponsive\n\t\t);\n\n\t\treturn attributes;\n\t}\n);\n\n/**\n * Returns the attributes derived from the preview, merged with the current attributes.\n *\n * @param {Object} currentAttributes The current attributes of the block.\n * @param {Object} preview The preview data.\n * @param {string} title The block's title, e.g. Twitter.\n * @param {boolean} isResponsive Boolean indicating if the block supports responsive content.\n * @return {Object} Merged attributes.\n */\nexport const getMergedAttributesWithPreview = (\n\tcurrentAttributes,\n\tpreview,\n\ttitle,\n\tisResponsive\n) => {\n\tconst { allowResponsive, className } = currentAttributes;\n\n\treturn {\n\t\t...currentAttributes,\n\t\t...getAttributesFromPreview(\n\t\t\tpreview,\n\t\t\ttitle,\n\t\t\tclassName,\n\t\t\tisResponsive,\n\t\t\tallowResponsive\n\t\t),\n\t};\n};\n"],
|
|
5
|
-
"mappings": ";AAGA,OAAO,UAAU;AACjB,OAAO,aAAa;AAKpB,SAAS,eAAe,6BAA6B;AACrD,SAAS,sBAAsB;AAC/B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport memoize from 'memize';\n\n/**\n * WordPress dependencies\n */\nimport { privateApis as componentsPrivateApis } from '@wordpress/components';\nimport { renderToString } from '@wordpress/element';\nimport {\n\tcreateBlock,\n\tgetBlockType,\n\tgetBlockVariations,\n} from '@wordpress/blocks';\nimport { getAuthority } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport metadata from './block.json';\nimport { ASPECT_RATIOS, WP_EMBED_TYPE } from './constants';\nimport { unlock } from '../lock-unlock';\n\nconst { name: DEFAULT_EMBED_BLOCK } = metadata;\nconst { kebabCase } = unlock( componentsPrivateApis );\n\n/** @typedef {import('@wordpress/blocks').WPBlockVariation} WPBlockVariation */\n\n/**\n * Returns the embed block's information by matching the provided service provider\n *\n * @param {string} provider The embed block's provider\n * @return {WPBlockVariation} The embed block's information\n */\nexport const getEmbedInfoByProvider = ( provider ) =>\n\tgetBlockVariations( DEFAULT_EMBED_BLOCK )?.find(\n\t\t( { name } ) => name === provider\n\t);\n\n/**\n * Returns true if any of the regular expressions match the URL.\n *\n * @param {string} url The URL to test.\n * @param {Array} patterns The list of regular expressions to test against.\n * @return {boolean} True if any of the regular expressions match the URL.\n */\nexport const matchesPatterns = ( url, patterns = [] ) =>\n\tpatterns.some( ( pattern ) => url.match( pattern ) );\n\n/**\n * Finds the block variation that should be used for the URL,\n * based on the provided URL and the variation's patterns.\n *\n * @param {string} url The URL to test.\n * @return {WPBlockVariation} The block variation that should be used for this URL\n */\nexport const findMoreSuitableBlock = ( url ) =>\n\tgetBlockVariations( DEFAULT_EMBED_BLOCK )?.find( ( { patterns } ) =>\n\t\tmatchesPatterns( url, patterns )\n\t);\n\n/**\n * Rewrites `x.com` URLs to `twitter.com` as a workaround while the\n * WordPress oEmbed registry lacks an X provider. See: https://core.trac.wordpress.org/ticket/59142.\n *\n * @param {string} url The URL to rewrite.\n * @return {string} The (possibly) rewritten URL.\n */\nexport function rewriteXToTwitter( url ) {\n\tif ( ! url || getAuthority( url ) !== 'x.com' ) {\n\t\treturn url;\n\t}\n\tconst rewritten = new URL( url );\n\trewritten.host = 'twitter.com';\n\treturn rewritten.toString();\n}\n\nexport const isFromWordPress = ( html ) =>\n\thtml && html.includes( 'class=\"wp-embedded-content\"' );\n\nexport const getPhotoHtml = ( photo ) => {\n\t// If full image url not found use thumbnail.\n\tconst imageUrl = photo.url || photo.thumbnail_url;\n\n\t// 100% width for the preview so it fits nicely into the document, some \"thumbnails\" are\n\t// actually the full size photo.\n\tconst photoPreview = (\n\t\t<p>\n\t\t\t<img src={ imageUrl } alt={ photo.title } width=\"100%\" />\n\t\t</p>\n\t);\n\treturn renderToString( photoPreview );\n};\n\n/**\n * Creates a more suitable embed block based on the passed in props\n * and attributes generated from an embed block's preview.\n *\n * We require `attributesFromPreview` to be generated from the latest attributes\n * and preview, and because of the way the react lifecycle operates, we can't\n * guarantee that the attributes contained in the block's props are the latest\n * versions, so we require that these are generated separately.\n * See `getAttributesFromPreview` in the generated embed edit component.\n *\n * @param {Object} props The block's props.\n * @param {Object} [attributesFromPreview] Attributes generated from the block's most up to date preview.\n * @return {Object|undefined} A more suitable embed block if one exists.\n */\nexport const createUpgradedEmbedBlock = (\n\tprops,\n\tattributesFromPreview = {}\n) => {\n\tconst { preview, attributes = {} } = props;\n\tconst { url, providerNameSlug, type, ...restAttributes } = attributes;\n\n\tif ( ! url || ! getBlockType( DEFAULT_EMBED_BLOCK ) ) {\n\t\treturn;\n\t}\n\n\tconst matchedBlock = findMoreSuitableBlock( url );\n\n\t// WordPress blocks can work on multiple sites, and so don't have patterns,\n\t// so if we're in a WordPress block, assume the user has chosen it for a WordPress URL.\n\tconst isCurrentBlockWP =\n\t\tproviderNameSlug === 'wordpress' || type === WP_EMBED_TYPE;\n\t// If current block is not WordPress and a more suitable block found\n\t// that is different from the current one, create the new matched block.\n\tconst shouldCreateNewBlock =\n\t\t! isCurrentBlockWP &&\n\t\tmatchedBlock &&\n\t\t( matchedBlock.attributes.providerNameSlug !== providerNameSlug ||\n\t\t\t! providerNameSlug );\n\tif ( shouldCreateNewBlock ) {\n\t\treturn createBlock( DEFAULT_EMBED_BLOCK, {\n\t\t\turl,\n\t\t\t...restAttributes,\n\t\t\t...matchedBlock.attributes,\n\t\t} );\n\t}\n\n\tconst wpVariation = getBlockVariations( DEFAULT_EMBED_BLOCK )?.find(\n\t\t( { name } ) => name === 'wordpress'\n\t);\n\n\t// We can't match the URL for WordPress embeds, we have to check the HTML instead.\n\tif (\n\t\t! wpVariation ||\n\t\t! preview ||\n\t\t! isFromWordPress( preview.html ) ||\n\t\tisCurrentBlockWP\n\t) {\n\t\treturn;\n\t}\n\n\t// This is not the WordPress embed block so transform it into one.\n\treturn createBlock( DEFAULT_EMBED_BLOCK, {\n\t\turl,\n\t\t...wpVariation.attributes,\n\t\t// By now we have the preview, but when the new block first renders, it\n\t\t// won't have had all the attributes set, and so won't get the correct\n\t\t// type and it won't render correctly. So, we pass through the current attributes\n\t\t// here so that the initial render works when we switch to the WordPress\n\t\t// block. This only affects the WordPress block because it can't be\n\t\t// rendered in the usual Sandbox (it has a sandbox of its own) and it\n\t\t// relies on the preview to set the correct render type.\n\t\t...attributesFromPreview,\n\t} );\n};\n\n/**\n * Determine if the block already has an aspect ratio class applied.\n *\n * @param {string} existingClassNames Existing block classes.\n * @return {boolean} True or false if the classnames contain an aspect ratio class.\n */\nexport const hasAspectRatioClass = ( existingClassNames ) => {\n\tif ( ! existingClassNames ) {\n\t\treturn false;\n\t}\n\treturn ASPECT_RATIOS.some( ( { className } ) =>\n\t\texistingClassNames.includes( className )\n\t);\n};\n\n/**\n * Removes all previously set aspect ratio related classes and return the rest\n * existing class names.\n *\n * @param {string} existingClassNames Any existing class names.\n * @return {string} The class names without any aspect ratio related class.\n */\nexport const removeAspectRatioClasses = ( existingClassNames ) => {\n\tif ( ! existingClassNames ) {\n\t\t// Avoids extraneous work and also, by returning the same value as\n\t\t// received, ensures the post is not dirtied by a change of the block\n\t\t// attribute from `undefined` to an empty string.\n\t\treturn existingClassNames;\n\t}\n\tconst aspectRatioClassNames = ASPECT_RATIOS.reduce(\n\t\t( accumulator, { className } ) => {\n\t\t\taccumulator.push( className );\n\t\t\treturn accumulator;\n\t\t},\n\t\t[ 'wp-has-aspect-ratio' ]\n\t);\n\tlet outputClassNames = existingClassNames;\n\tfor ( const className of aspectRatioClassNames ) {\n\t\toutputClassNames = outputClassNames.replace( className, '' );\n\t}\n\treturn outputClassNames.trim();\n};\n\n/**\n * Checks if HTML already contains responsive aspect ratio styling.\n * Some embed providers (like Flickr) include their own responsive wrapper\n * with padding-bottom or padding-top percentages for aspect ratio.\n *\n * @param {string} html The embed HTML to check.\n * @return {boolean} True if the HTML already has responsive styling.\n */\nexport function hasInlineResponsivePadding( html ) {\n\t// Check for padding-bottom or padding-top with percentage values in style attributes\n\t// This pattern matches: padding-bottom: 56.25%; or padding-top: 50%; etc.\n\tconst paddingPattern = /padding-(top|bottom)\\s*:\\s*[\\d.]+%/i;\n\treturn paddingPattern.test( html );\n}\n\n/**\n * Returns class names with any relevant responsive aspect ratio names.\n *\n * @param {string} html The preview HTML that possibly contains an iframe with width and height set.\n * @param {string} existingClassNames Any existing class names.\n * @param {boolean} allowResponsive If the responsive class names should be added, or removed.\n * @return {string} Deduped class names.\n */\nexport function getClassNames(\n\thtml,\n\texistingClassNames,\n\tallowResponsive = true\n) {\n\tif ( ! allowResponsive ) {\n\t\treturn removeAspectRatioClasses( existingClassNames );\n\t}\n\n\t// If the embed HTML already contains responsive wrapper styling (like Flickr),\n\t// don't add our own aspect ratio classes to avoid double padding.\n\tif ( hasInlineResponsivePadding( html ) ) {\n\t\treturn removeAspectRatioClasses( existingClassNames );\n\t}\n\n\tconst previewDocument = document.implementation.createHTMLDocument( '' );\n\tpreviewDocument.body.innerHTML = html;\n\tconst iframe = previewDocument.body.querySelector( 'iframe' );\n\n\t// If we have a fixed aspect iframe, and it's a responsive embed block.\n\tif ( iframe && iframe.height && iframe.width ) {\n\t\tconst aspectRatio = ( iframe.width / iframe.height ).toFixed( 2 );\n\t\t// Given the actual aspect ratio, find the widest ratio to support it.\n\t\tfor (\n\t\t\tlet ratioIndex = 0;\n\t\t\tratioIndex < ASPECT_RATIOS.length;\n\t\t\tratioIndex++\n\t\t) {\n\t\t\tconst potentialRatio = ASPECT_RATIOS[ ratioIndex ];\n\t\t\tif ( aspectRatio >= potentialRatio.ratio ) {\n\t\t\t\t// Evaluate the difference between actual aspect ratio and closest match.\n\t\t\t\t// If the difference is too big, do not scale the embed according to aspect ratio.\n\t\t\t\tconst ratioDiff = aspectRatio - potentialRatio.ratio;\n\t\t\t\tif ( ratioDiff > 0.1 ) {\n\t\t\t\t\t// No close aspect ratio match found.\n\t\t\t\t\treturn removeAspectRatioClasses( existingClassNames );\n\t\t\t\t}\n\t\t\t\t// Close aspect ratio match found.\n\t\t\t\treturn clsx(\n\t\t\t\t\tremoveAspectRatioClasses( existingClassNames ),\n\t\t\t\t\tpotentialRatio.className,\n\t\t\t\t\t'wp-has-aspect-ratio'\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn existingClassNames;\n}\n\n/**\n * Fallback behaviour for unembeddable URLs.\n * Creates a paragraph block containing a link to the URL, and calls `onReplace`.\n *\n * @param {string} url The URL that could not be embedded.\n * @param {Function} onReplace Function to call with the created fallback block.\n */\nexport function fallback( url, onReplace ) {\n\tconst link = <a href={ url }>{ url }</a>;\n\tonReplace(\n\t\tcreateBlock( 'core/paragraph', { content: renderToString( link ) } )\n\t);\n}\n\n/***\n * Gets block attributes based on the preview and responsive state.\n *\n * @param {Object} preview The preview data.\n * @param {string} title The block's title, e.g. Twitter.\n * @param {Object} currentClassNames The block's current class names.\n * @param {boolean} isResponsive Boolean indicating if the block supports responsive content.\n * @param {boolean} allowResponsive Apply responsive classes to fixed size content.\n * @return {Object} Attributes and values.\n */\nexport const getAttributesFromPreview = memoize(\n\t(\n\t\tpreview,\n\t\ttitle,\n\t\tcurrentClassNames,\n\t\tisResponsive,\n\t\tallowResponsive = true\n\t) => {\n\t\tif ( ! preview ) {\n\t\t\treturn {};\n\t\t}\n\n\t\tconst attributes = {};\n\t\t// Some plugins only return HTML with no type info, so default this to 'rich'.\n\t\tlet { type = 'rich' } = preview;\n\t\t// If we got a provider name from the API, use it for the slug, otherwise we use the title,\n\t\t// because not all embed code gives us a provider name.\n\t\tconst { html, provider_name: providerName } = preview;\n\t\tconst providerNameSlug = kebabCase(\n\t\t\t( providerName || title ).toLowerCase()\n\t\t);\n\n\t\tif ( isFromWordPress( html ) ) {\n\t\t\ttype = WP_EMBED_TYPE;\n\t\t}\n\n\t\tif ( html || 'photo' === type ) {\n\t\t\tattributes.type = type;\n\t\t\tattributes.providerNameSlug = providerNameSlug;\n\t\t}\n\n\t\t// Aspect ratio classes are removed when the embed URL is updated.\n\t\t// If the embed already has an aspect ratio class, that means the URL has not changed.\n\t\t// Which also means no need to regenerate it with getClassNames.\n\t\tif ( hasAspectRatioClass( currentClassNames ) ) {\n\t\t\treturn attributes;\n\t\t}\n\n\t\tattributes.className = getClassNames(\n\t\t\thtml,\n\t\t\tcurrentClassNames,\n\t\t\tisResponsive && allowResponsive\n\t\t);\n\n\t\treturn attributes;\n\t}\n);\n\n/**\n * Returns the attributes derived from the preview, merged with the current attributes.\n *\n * @param {Object} currentAttributes The current attributes of the block.\n * @param {Object} preview The preview data.\n * @param {string} title The block's title, e.g. Twitter.\n * @param {boolean} isResponsive Boolean indicating if the block supports responsive content.\n * @return {Object} Merged attributes.\n */\nexport const getMergedAttributesWithPreview = (\n\tcurrentAttributes,\n\tpreview,\n\ttitle,\n\tisResponsive\n) => {\n\tconst { allowResponsive, className } = currentAttributes;\n\n\treturn {\n\t\t...currentAttributes,\n\t\t...getAttributesFromPreview(\n\t\t\tpreview,\n\t\t\ttitle,\n\t\t\tclassName,\n\t\t\tisResponsive,\n\t\t\tallowResponsive\n\t\t),\n\t};\n};\n"],
|
|
5
|
+
"mappings": ";AAGA,OAAO,UAAU;AACjB,OAAO,aAAa;AAKpB,SAAS,eAAe,6BAA6B;AACrD,SAAS,sBAAsB;AAC/B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,oBAAoB;AAK7B,OAAO,cAAc;AACrB,SAAS,eAAe,qBAAqB;AAC7C,SAAS,cAAc;AAmEpB;AAjEH,IAAM,EAAE,MAAM,oBAAoB,IAAI;AACtC,IAAM,EAAE,UAAU,IAAI,OAAQ,qBAAsB;AAU7C,IAAM,yBAAyB,CAAE,aACvC,mBAAoB,mBAAoB,GAAG;AAAA,EAC1C,CAAE,EAAE,KAAK,MAAO,SAAS;A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AAiB,UAAU,IAAI;AAEvC,SAAO;AAAA,IACN,GAAG;AAAA,IACH,GAAG;AAAA,MACF;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"__experimental": true,
|
|
5
5
|
"name": "core/form-submission-notification",
|
|
6
6
|
"title": "Form Submission Notification",
|
|
7
|
-
"category": "
|
|
7
|
+
"category": "widgets",
|
|
8
8
|
"ancestor": [ "core/form" ],
|
|
9
9
|
"description": "Provide a notification message after the form has been submitted.",
|
|
10
10
|
"keywords": [ "form", "feedback", "notification", "message" ],
|
|
@@ -4,7 +4,7 @@ var LINK_DESTINATION_NONE = "none";
|
|
|
4
4
|
var LINK_DESTINATION_MEDIA = "media";
|
|
5
5
|
var LINK_DESTINATION_ATTACHMENT = "attachment";
|
|
6
6
|
var LINK_DESTINATION_CUSTOM = "custom";
|
|
7
|
-
var NEW_TAB_REL = ["
|
|
7
|
+
var NEW_TAB_REL = ["noopener"];
|
|
8
8
|
var ALLOWED_MEDIA_TYPES = ["image"];
|
|
9
9
|
var MEDIA_ID_NO_FEATURED_IMAGE_SET = 0;
|
|
10
10
|
var SIZED_LAYOUTS = ["flex", "grid"];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/image/constants.js"],
|
|
4
|
-
"sourcesContent": ["export const MIN_SIZE = 20;\nexport const LINK_DESTINATION_NONE = 'none';\nexport const LINK_DESTINATION_MEDIA = 'media';\nexport const LINK_DESTINATION_ATTACHMENT = 'attachment';\nexport const LINK_DESTINATION_CUSTOM = 'custom';\nexport const NEW_TAB_REL = [ '
|
|
5
|
-
"mappings": ";AAAO,IAAM,WAAW;AACjB,IAAM,wBAAwB;AAC9B,IAAM,yBAAyB;AAC/B,IAAM,8BAA8B;AACpC,IAAM,0BAA0B;AAChC,IAAM,cAAc,CAAE,
|
|
4
|
+
"sourcesContent": ["export const MIN_SIZE = 20;\nexport const LINK_DESTINATION_NONE = 'none';\nexport const LINK_DESTINATION_MEDIA = 'media';\nexport const LINK_DESTINATION_ATTACHMENT = 'attachment';\nexport const LINK_DESTINATION_CUSTOM = 'custom';\nexport const NEW_TAB_REL = [ 'noopener' ];\nexport const ALLOWED_MEDIA_TYPES = [ 'image' ];\nexport const MEDIA_ID_NO_FEATURED_IMAGE_SET = 0;\nexport const SIZED_LAYOUTS = [ 'flex', 'grid' ];\nexport const DEFAULT_MEDIA_SIZE_SLUG = 'full';\n\n/**\n * Delay in milliseconds before preloading an image after hovering.\n * This prevents unnecessary preloading during quick scrolling or mouse movements.\n */\nexport const IMAGE_PRELOAD_DELAY = 200;\n"],
|
|
5
|
+
"mappings": ";AAAO,IAAM,WAAW;AACjB,IAAM,wBAAwB;AAC9B,IAAM,yBAAyB;AAC/B,IAAM,8BAA8B;AACpC,IAAM,0BAA0B;AAChC,IAAM,cAAc,CAAE,UAAW;AACjC,IAAM,sBAAsB,CAAE,OAAQ;AACtC,IAAM,iCAAiC;AACvC,IAAM,gBAAgB,CAAE,QAAQ,MAAO;AACvC,IAAM,0BAA0B;AAMhC,IAAM,sBAAsB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -86,9 +86,7 @@ function ImageEdit({
|
|
|
86
86
|
__unstableMarkNextChangeAsNotPersistent();
|
|
87
87
|
setAttributes({
|
|
88
88
|
width: void 0,
|
|
89
|
-
height: void 0
|
|
90
|
-
aspectRatio: void 0,
|
|
91
|
-
scale: void 0
|
|
89
|
+
height: void 0
|
|
92
90
|
});
|
|
93
91
|
}
|
|
94
92
|
}, [__unstableMarkNextChangeAsNotPersistent, align, setAttributes]);
|
|
@@ -249,7 +247,7 @@ function ImageEdit({
|
|
|
249
247
|
const src = isExternal ? url : void 0;
|
|
250
248
|
const isSideloading = useSelect(
|
|
251
249
|
(select) => {
|
|
252
|
-
if (!window.__clientSideMediaProcessing || !id) {
|
|
250
|
+
if (!window.__clientSideMediaProcessing && !window.__heicUploadSupport || !id) {
|
|
253
251
|
return false;
|
|
254
252
|
}
|
|
255
253
|
return select(uploadStore).isUploadingById(id);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/image/edit.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { isBlobURL, createBlobURL } from '@wordpress/blob';\nimport { createBlock, getBlockBindingsSource } from '@wordpress/blocks';\nimport { Placeholder } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport {\n\tBlockIcon,\n\tuseBlockProps,\n\tMediaPlaceholder,\n\tstore as blockEditorStore,\n\t__experimentalUseBorderProps as useBorderProps,\n\t__experimentalGetShadowClassesAndStyles as getShadowClassesAndStyles,\n\tuseBlockEditingMode,\n} from '@wordpress/block-editor';\nimport { useEffect, useRef, useState } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { image as icon, plugins as pluginsIcon } from '@wordpress/icons';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useResizeObserver } from '@wordpress/compose';\nimport { getProtocol, prependHTTPS } from '@wordpress/url';\nimport { store as uploadStore } from '@wordpress/upload-media';\n\n/**\n * Internal dependencies\n */\nimport { useUploadMediaFromBlobURL } from '../utils/hooks';\nimport Image from './image';\nimport { isValidFileType } from './utils';\nimport { useMaxWidthObserver } from './use-max-width-observer';\n\n/**\n * Module constants\n */\nimport {\n\tLINK_DESTINATION_ATTACHMENT,\n\tLINK_DESTINATION_CUSTOM,\n\tLINK_DESTINATION_MEDIA,\n\tLINK_DESTINATION_NONE,\n\tALLOWED_MEDIA_TYPES,\n\tDEFAULT_MEDIA_SIZE_SLUG,\n} from './constants';\n\nexport const pickRelevantMediaFiles = ( image, size ) => {\n\tconst imageProps = Object.fromEntries(\n\t\tObject.entries( image ?? {} ).filter( ( [ key ] ) =>\n\t\t\t[ 'alt', 'id', 'link', 'caption' ].includes( key )\n\t\t)\n\t);\n\n\timageProps.url =\n\t\timage?.sizes?.[ size ]?.url ||\n\t\timage?.media_details?.sizes?.[ size ]?.source_url ||\n\t\timage.url;\n\treturn imageProps;\n};\n\n/**\n * Is the url for the image hosted externally. An externally hosted image has no\n * id and is not a blob url.\n *\n * @param {number=} id The id of the image.\n * @param {string=} url The url of the image.\n *\n * @return {boolean} Is the url an externally hosted url?\n */\nexport const isExternalImage = ( id, url ) => url && ! id && ! isBlobURL( url );\n\n/**\n * Checks if WP generated the specified image size. Size generation is skipped\n * when the image is smaller than the said size.\n *\n * @param {Object} image\n * @param {string} size\n *\n * @return {boolean} Whether or not it has default image size.\n */\nfunction hasSize( image, size ) {\n\treturn (\n\t\t'url' in ( image?.sizes?.[ size ] ?? {} ) ||\n\t\t'source_url' in ( image?.media_details?.sizes?.[ size ] ?? {} )\n\t);\n}\n\nexport function ImageEdit( {\n\tattributes,\n\tsetAttributes,\n\tisSelected: isSingleSelected,\n\tclassName,\n\tinsertBlocksAfter,\n\tonReplace,\n\tcontext,\n\tclientId,\n\t__unstableParentLayout: parentLayout,\n} ) {\n\tconst {\n\t\turl = '',\n\t\tcaption,\n\t\tid,\n\t\twidth,\n\t\theight,\n\t\tsizeSlug,\n\t\taspectRatio,\n\t\tscale,\n\t\talign,\n\t\tmetadata,\n\t} = attributes;\n\n\tconst [ temporaryURL, setTemporaryURL ] = useState( attributes.blob );\n\n\tconst containerRef = useRef();\n\t// Only observe the max width from the parent container when the parent layout is not flex nor grid.\n\t// This won't work for them because the container width changes with the image.\n\t// TODO: Find a way to observe the container width for flex and grid layouts.\n\tconst layoutType = parentLayout?.type || parentLayout?.default?.type;\n\tconst isMaxWidthContainerWidth =\n\t\t! layoutType || ( layoutType !== 'flex' && layoutType !== 'grid' );\n\tconst [ maxWidthObserver, maxContentWidth ] = useMaxWidthObserver();\n\n\tconst [ placeholderResizeListener, { width: placeholderWidth } ] =\n\t\tuseResizeObserver();\n\n\tconst isSmallContainer = placeholderWidth && placeholderWidth < 160;\n\n\tconst captionRef = useRef();\n\tuseEffect( () => {\n\t\tcaptionRef.current = caption;\n\t}, [ caption ] );\n\n\tconst { __unstableMarkNextChangeAsNotPersistent, replaceBlock } =\n\t\tuseDispatch( blockEditorStore );\n\n\tuseEffect( () => {\n\t\tif ( [ 'wide', 'full' ].includes( align ) ) {\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\tsetAttributes( {\n\t\t\t\twidth: undefined,\n\t\t\t\theight: undefined,\n\t\t\t\taspectRatio: undefined,\n\t\t\t\tscale: undefined,\n\t\t\t} );\n\t\t}\n\t}, [ __unstableMarkNextChangeAsNotPersistent, align, setAttributes ] );\n\n\tconst {\n\t\tgetSettings,\n\t\tgetBlockRootClientId,\n\t\tgetBlockName,\n\t\tcanInsertBlockType,\n\t} = useSelect( blockEditorStore );\n\tconst blockEditingMode = useBlockEditingMode();\n\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tfunction onUploadError( message ) {\n\t\tcreateErrorNotice( message, { type: 'snackbar' } );\n\t\tsetTemporaryURL();\n\t\tsetAttributes( {\n\t\t\tsrc: undefined,\n\t\t\tid: undefined,\n\t\t\turl: undefined,\n\t\t\tblob: undefined,\n\t\t} );\n\t}\n\n\tfunction onFilesPreUpload( files ) {\n\t\tif ( files.length === 1 ) {\n\t\t\tsetTemporaryURL( createBlobURL( files[ 0 ] ) );\n\t\t}\n\t}\n\n\tfunction onSelectImagesList( images ) {\n\t\tconst win = containerRef.current?.ownerDocument.defaultView;\n\n\t\tif ( images.every( ( file ) => file instanceof win.File ) ) {\n\t\t\t/** @type {File[]} */\n\t\t\tconst files = images;\n\t\t\tconst rootClientId = getBlockRootClientId( clientId );\n\n\t\t\tif ( files.some( ( file ) => ! isValidFileType( file ) ) ) {\n\t\t\t\t// Copied from the same notice in the gallery block.\n\t\t\t\tcreateErrorNotice(\n\t\t\t\t\t__(\n\t\t\t\t\t\t'If uploading to a gallery all files need to be image formats'\n\t\t\t\t\t),\n\t\t\t\t\t{ id: 'gallery-upload-invalid-file', type: 'snackbar' }\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst imageBlocks = files\n\t\t\t\t.filter( ( file ) => isValidFileType( file ) )\n\t\t\t\t.map( ( file ) =>\n\t\t\t\t\tcreateBlock( 'core/image', {\n\t\t\t\t\t\tblob: createBlobURL( file ),\n\t\t\t\t\t} )\n\t\t\t\t);\n\n\t\t\tif ( getBlockName( rootClientId ) === 'core/gallery' ) {\n\t\t\t\treplaceBlock( clientId, imageBlocks );\n\t\t\t} else if ( canInsertBlockType( 'core/gallery', rootClientId ) ) {\n\t\t\t\tconst galleryBlock = createBlock(\n\t\t\t\t\t'core/gallery',\n\t\t\t\t\t{},\n\t\t\t\t\timageBlocks\n\t\t\t\t);\n\n\t\t\t\treplaceBlock( clientId, galleryBlock );\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction onSelectImage( media ) {\n\t\tif ( Array.isArray( media ) ) {\n\t\t\tonSelectImagesList( media );\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! media || ! media.url ) {\n\t\t\tsetAttributes( {\n\t\t\t\turl: undefined,\n\t\t\t\talt: undefined,\n\t\t\t\tid: undefined,\n\t\t\t\ttitle: undefined,\n\t\t\t\tcaption: undefined,\n\t\t\t\tblob: undefined,\n\t\t\t} );\n\t\t\tsetTemporaryURL();\n\n\t\t\treturn;\n\t\t}\n\n\t\tif ( isBlobURL( media.url ) ) {\n\t\t\tsetTemporaryURL( media.url );\n\t\t\treturn;\n\t\t}\n\n\t\tconst { imageDefaultSize } = getSettings();\n\n\t\t// Try to use the previous selected image size if its available\n\t\t// otherwise try the default image size or fallback to \"full\"\n\t\tlet newSize = DEFAULT_MEDIA_SIZE_SLUG;\n\t\tif ( sizeSlug && hasSize( media, sizeSlug ) ) {\n\t\t\tnewSize = sizeSlug;\n\t\t} else if ( hasSize( media, imageDefaultSize ) ) {\n\t\t\tnewSize = imageDefaultSize;\n\t\t}\n\n\t\tlet mediaAttributes = pickRelevantMediaFiles( media, newSize );\n\n\t\t// Normalize newline characters in caption to <br />\n\t\t// to preserve line breaks in both editor and frontend.\n\t\tif (\n\t\t\ttypeof mediaAttributes.caption === 'string' &&\n\t\t\tmediaAttributes.caption.includes( '\\n' )\n\t\t) {\n\t\t\tmediaAttributes.caption = mediaAttributes.caption.replace(\n\t\t\t\t/\\n/g,\n\t\t\t\t'<br>'\n\t\t\t);\n\t\t}\n\n\t\t// If a caption text was meanwhile written by the user,\n\t\t// make sure the text is not overwritten by empty captions.\n\t\tif ( captionRef.current && ! mediaAttributes.caption ) {\n\t\t\tconst { caption: omittedCaption, ...restMediaAttributes } =\n\t\t\t\tmediaAttributes;\n\t\t\tmediaAttributes = restMediaAttributes;\n\t\t}\n\n\t\tlet additionalAttributes;\n\t\t// Reset the dimension attributes if changing to a different image.\n\t\tif ( ! media.id || media.id !== id ) {\n\t\t\tadditionalAttributes = {\n\t\t\t\tsizeSlug: newSize,\n\t\t\t};\n\t\t}\n\n\t\t// Check if default link setting should be used.\n\t\tlet linkDestination = attributes.linkDestination;\n\t\tif ( ! linkDestination ) {\n\t\t\t// Use the WordPress option to determine the proper default.\n\t\t\t// The constants used in Gutenberg do not match WP options so a little more complicated than ideal.\n\t\t\tswitch (\n\t\t\t\twindow?.wp?.media?.view?.settings?.defaultProps?.link ||\n\t\t\t\tLINK_DESTINATION_NONE\n\t\t\t) {\n\t\t\t\tcase 'file':\n\t\t\t\tcase LINK_DESTINATION_MEDIA:\n\t\t\t\t\tlinkDestination = LINK_DESTINATION_MEDIA;\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'post':\n\t\t\t\tcase LINK_DESTINATION_ATTACHMENT:\n\t\t\t\t\tlinkDestination = LINK_DESTINATION_ATTACHMENT;\n\t\t\t\t\tbreak;\n\t\t\t\tcase LINK_DESTINATION_CUSTOM:\n\t\t\t\t\tlinkDestination = LINK_DESTINATION_CUSTOM;\n\t\t\t\t\tbreak;\n\t\t\t\tcase LINK_DESTINATION_NONE:\n\t\t\t\t\tlinkDestination = LINK_DESTINATION_NONE;\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\t// Check if the image is linked to it's media.\n\t\tlet href;\n\t\tswitch ( linkDestination ) {\n\t\t\tcase LINK_DESTINATION_MEDIA:\n\t\t\t\thref = media.url;\n\t\t\t\tbreak;\n\t\t\tcase LINK_DESTINATION_ATTACHMENT:\n\t\t\t\thref = media.link;\n\t\t\t\tbreak;\n\t\t}\n\t\tmediaAttributes.href = href;\n\n\t\tsetAttributes( {\n\t\t\tblob: undefined,\n\t\t\t...mediaAttributes,\n\t\t\t...additionalAttributes,\n\t\t\tlinkDestination,\n\t\t} );\n\t\tsetTemporaryURL();\n\t}\n\n\tfunction onSelectURL( newURL ) {\n\t\t// Handle URLs without protocol.\n\t\tconst normalizedNewURL = getProtocol( newURL )\n\t\t\t? newURL\n\t\t\t: prependHTTPS( newURL );\n\t\tif ( normalizedNewURL !== url ) {\n\t\t\tsetAttributes( {\n\t\t\t\tblob: undefined,\n\t\t\t\turl: normalizedNewURL,\n\t\t\t\tid: undefined,\n\t\t\t\tsizeSlug: getSettings().imageDefaultSize,\n\t\t\t} );\n\t\t\tsetTemporaryURL();\n\t\t}\n\t}\n\n\tuseUploadMediaFromBlobURL( {\n\t\turl: temporaryURL,\n\t\tallowedTypes: ALLOWED_MEDIA_TYPES,\n\t\tonChange: onSelectImage,\n\t\tonError: onUploadError,\n\t} );\n\n\tconst isExternal = isExternalImage( id, url );\n\tconst src = isExternal ? url : undefined;\n\n\tconst isSideloading = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! window.__clientSideMediaProcessing || ! id ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn select( uploadStore ).isUploadingById( id );\n\t\t},\n\t\t[ id ]\n\t);\n\n\tconst mediaPreview = !! url && (\n\t\t<img\n\t\t\talt={ __( 'Edit image' ) }\n\t\t\ttitle={ __( 'Edit image' ) }\n\t\t\tclassName=\"edit-image-preview\"\n\t\t\tsrc={ url }\n\t\t/>\n\t);\n\n\tconst borderProps = useBorderProps( attributes );\n\tconst shadowProps = getShadowClassesAndStyles( attributes );\n\n\tconst classes = clsx( className, {\n\t\t'is-transient': !! temporaryURL || isSideloading,\n\t\t'is-resized': !! width || !! height,\n\t\t[ `size-${ sizeSlug }` ]: sizeSlug,\n\t\t'has-custom-border':\n\t\t\t!! borderProps.className ||\n\t\t\t( borderProps.style &&\n\t\t\t\tObject.keys( borderProps.style ).length > 0 ),\n\t} );\n\n\tconst blockProps = useBlockProps( {\n\t\tref: containerRef,\n\t\tclassName: classes,\n\t} );\n\n\t// Much of this description is duplicated from MediaPlaceholder.\n\tconst { lockUrlControls = false, lockUrlControlsMessage } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! isSingleSelected ) {\n\t\t\t\treturn {};\n\t\t\t}\n\n\t\t\tconst blockBindingsSource = getBlockBindingsSource(\n\t\t\t\tmetadata?.bindings?.url?.source\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tlockUrlControls:\n\t\t\t\t\t!! metadata?.bindings?.url &&\n\t\t\t\t\t! blockBindingsSource?.canUserEditValue?.( {\n\t\t\t\t\t\tselect,\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t\targs: metadata?.bindings?.url?.args,\n\t\t\t\t\t} ),\n\t\t\t\tlockUrlControlsMessage: blockBindingsSource?.label\n\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t/* translators: %s: Label of the bindings source. */\n\t\t\t\t\t\t\t__( 'Connected to %s' ),\n\t\t\t\t\t\t\tblockBindingsSource.label\n\t\t\t\t\t )\n\t\t\t\t\t: __( 'Connected to dynamic data' ),\n\t\t\t};\n\t\t},\n\t\t[ context, isSingleSelected, metadata?.bindings?.url ]\n\t);\n\tconst placeholder = ( content ) => {\n\t\treturn (\n\t\t\t<Placeholder\n\t\t\t\tclassName={ clsx( 'block-editor-media-placeholder', {\n\t\t\t\t\t[ borderProps.className ]:\n\t\t\t\t\t\t!! borderProps.className && ! isSingleSelected,\n\t\t\t\t} ) }\n\t\t\t\ticon={\n\t\t\t\t\t! isSmallContainer &&\n\t\t\t\t\t( lockUrlControls ? pluginsIcon : icon )\n\t\t\t\t}\n\t\t\t\twithIllustration={ ! isSingleSelected || isSmallContainer }\n\t\t\t\tlabel={ ! isSmallContainer && __( 'Image' ) }\n\t\t\t\tinstructions={\n\t\t\t\t\t! lockUrlControls &&\n\t\t\t\t\t! isSmallContainer &&\n\t\t\t\t\t__(\n\t\t\t\t\t\t'Drag and drop an image, upload, or choose from your library.'\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tstyle={ {\n\t\t\t\t\taspectRatio:\n\t\t\t\t\t\t! ( width && height ) && aspectRatio\n\t\t\t\t\t\t\t? aspectRatio\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\twidth: height && aspectRatio ? '100%' : width,\n\t\t\t\t\theight: width && aspectRatio ? '100%' : height,\n\t\t\t\t\tobjectFit: scale,\n\t\t\t\t\t...borderProps.style,\n\t\t\t\t\t...shadowProps.style,\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ lockUrlControls &&\n\t\t\t\t\t! isSmallContainer &&\n\t\t\t\t\tlockUrlControlsMessage }\n\n\t\t\t\t{ ! lockUrlControls && ! isSmallContainer && content }\n\t\t\t\t{ placeholderResizeListener }\n\t\t\t</Placeholder>\n\t\t);\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t<figure { ...blockProps }>\n\t\t\t\t<Image\n\t\t\t\t\ttemporaryURL={ temporaryURL }\n\t\t\t\t\tisSideloading={ isSideloading }\n\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\tisSingleSelected={ isSingleSelected }\n\t\t\t\t\tinsertBlocksAfter={ insertBlocksAfter }\n\t\t\t\t\tonReplace={ onReplace }\n\t\t\t\t\tonSelectImage={ onSelectImage }\n\t\t\t\t\tonSelectURL={ onSelectURL }\n\t\t\t\t\tonUploadError={ onUploadError }\n\t\t\t\t\tcontext={ context }\n\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\tblockEditingMode={ blockEditingMode }\n\t\t\t\t\tparentLayoutType={ layoutType }\n\t\t\t\t\tmaxContentWidth={ maxContentWidth }\n\t\t\t\t/>\n\t\t\t\t<MediaPlaceholder\n\t\t\t\t\ticon={ <BlockIcon icon={ icon } /> }\n\t\t\t\t\tonSelect={ onSelectImage }\n\t\t\t\t\tonSelectURL={ onSelectURL }\n\t\t\t\t\tonFilesPreUpload={ onFilesPreUpload }\n\t\t\t\t\tonError={ onUploadError }\n\t\t\t\t\tplaceholder={ placeholder }\n\t\t\t\t\tallowedTypes={ ALLOWED_MEDIA_TYPES }\n\t\t\t\t\thandleUpload={ ( files ) => files.length === 1 }\n\t\t\t\t\tvalue={ { id, src } }\n\t\t\t\t\tmediaPreview={ mediaPreview }\n\t\t\t\t\tdisableMediaButtons={ temporaryURL || url }\n\t\t\t\t/>\n\t\t\t</figure>\n\t\t\t{\n\t\t\t\t// The listener cannot be placed as the first element as it will break the in-between inserter.\n\t\t\t\t// See https://github.com/WordPress/gutenberg/blob/71134165868298fc15e22896d0c28b41b3755ff7/packages/block-editor/src/components/block-list/use-in-between-inserter.js#L120\n\t\t\t\tisSingleSelected && isMaxWidthContainerWidth && maxWidthObserver\n\t\t\t}\n\t\t</>\n\t);\n}\n\nexport default ImageEdit;\n"],
|
|
5
|
-
"mappings": ";AAGA,OAAO,UAAU;AAKjB,SAAS,WAAW,qBAAqB;AACzC,SAAS,aAAa,8BAA8B;AACpD,SAAS,mBAAmB;AAC5B,SAAS,aAAa,iBAAiB;AACvC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT,gCAAgC;AAAA,EAChC,2CAA2C;AAAA,EAC3C;AAAA,OACM;AACP,SAAS,WAAW,QAAQ,gBAAgB;AAC5C,SAAS,IAAI,eAAe;AAC5B,SAAS,SAAS,MAAM,WAAW,mBAAmB;AACtD,SAAS,SAAS,oBAAoB;AACtC,SAAS,yBAAyB;AAClC,SAAS,aAAa,oBAAoB;AAC1C,SAAS,SAAS,mBAAmB;AAKrC,SAAS,iCAAiC;AAC1C,OAAO,WAAW;AAClB,SAAS,uBAAuB;AAChC,SAAS,2BAA2B;AAKpC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { isBlobURL, createBlobURL } from '@wordpress/blob';\nimport { createBlock, getBlockBindingsSource } from '@wordpress/blocks';\nimport { Placeholder } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport {\n\tBlockIcon,\n\tuseBlockProps,\n\tMediaPlaceholder,\n\tstore as blockEditorStore,\n\t__experimentalUseBorderProps as useBorderProps,\n\t__experimentalGetShadowClassesAndStyles as getShadowClassesAndStyles,\n\tuseBlockEditingMode,\n} from '@wordpress/block-editor';\nimport { useEffect, useRef, useState } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { image as icon, plugins as pluginsIcon } from '@wordpress/icons';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useResizeObserver } from '@wordpress/compose';\nimport { getProtocol, prependHTTPS } from '@wordpress/url';\nimport { store as uploadStore } from '@wordpress/upload-media';\n\n/**\n * Internal dependencies\n */\nimport { useUploadMediaFromBlobURL } from '../utils/hooks';\nimport Image from './image';\nimport { isValidFileType } from './utils';\nimport { useMaxWidthObserver } from './use-max-width-observer';\n\n/**\n * Module constants\n */\nimport {\n\tLINK_DESTINATION_ATTACHMENT,\n\tLINK_DESTINATION_CUSTOM,\n\tLINK_DESTINATION_MEDIA,\n\tLINK_DESTINATION_NONE,\n\tALLOWED_MEDIA_TYPES,\n\tDEFAULT_MEDIA_SIZE_SLUG,\n} from './constants';\n\nexport const pickRelevantMediaFiles = ( image, size ) => {\n\tconst imageProps = Object.fromEntries(\n\t\tObject.entries( image ?? {} ).filter( ( [ key ] ) =>\n\t\t\t[ 'alt', 'id', 'link', 'caption' ].includes( key )\n\t\t)\n\t);\n\n\timageProps.url =\n\t\timage?.sizes?.[ size ]?.url ||\n\t\timage?.media_details?.sizes?.[ size ]?.source_url ||\n\t\timage.url;\n\treturn imageProps;\n};\n\n/**\n * Is the url for the image hosted externally. An externally hosted image has no\n * id and is not a blob url.\n *\n * @param {number=} id The id of the image.\n * @param {string=} url The url of the image.\n *\n * @return {boolean} Is the url an externally hosted url?\n */\nexport const isExternalImage = ( id, url ) => url && ! id && ! isBlobURL( url );\n\n/**\n * Checks if WP generated the specified image size. Size generation is skipped\n * when the image is smaller than the said size.\n *\n * @param {Object} image\n * @param {string} size\n *\n * @return {boolean} Whether or not it has default image size.\n */\nfunction hasSize( image, size ) {\n\treturn (\n\t\t'url' in ( image?.sizes?.[ size ] ?? {} ) ||\n\t\t'source_url' in ( image?.media_details?.sizes?.[ size ] ?? {} )\n\t);\n}\n\nexport function ImageEdit( {\n\tattributes,\n\tsetAttributes,\n\tisSelected: isSingleSelected,\n\tclassName,\n\tinsertBlocksAfter,\n\tonReplace,\n\tcontext,\n\tclientId,\n\t__unstableParentLayout: parentLayout,\n} ) {\n\tconst {\n\t\turl = '',\n\t\tcaption,\n\t\tid,\n\t\twidth,\n\t\theight,\n\t\tsizeSlug,\n\t\taspectRatio,\n\t\tscale,\n\t\talign,\n\t\tmetadata,\n\t} = attributes;\n\n\tconst [ temporaryURL, setTemporaryURL ] = useState( attributes.blob );\n\n\tconst containerRef = useRef();\n\t// Only observe the max width from the parent container when the parent layout is not flex nor grid.\n\t// This won't work for them because the container width changes with the image.\n\t// TODO: Find a way to observe the container width for flex and grid layouts.\n\tconst layoutType = parentLayout?.type || parentLayout?.default?.type;\n\tconst isMaxWidthContainerWidth =\n\t\t! layoutType || ( layoutType !== 'flex' && layoutType !== 'grid' );\n\tconst [ maxWidthObserver, maxContentWidth ] = useMaxWidthObserver();\n\n\tconst [ placeholderResizeListener, { width: placeholderWidth } ] =\n\t\tuseResizeObserver();\n\n\tconst isSmallContainer = placeholderWidth && placeholderWidth < 160;\n\n\tconst captionRef = useRef();\n\tuseEffect( () => {\n\t\tcaptionRef.current = caption;\n\t}, [ caption ] );\n\n\tconst { __unstableMarkNextChangeAsNotPersistent, replaceBlock } =\n\t\tuseDispatch( blockEditorStore );\n\n\tuseEffect( () => {\n\t\tif ( [ 'wide', 'full' ].includes( align ) ) {\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\tsetAttributes( {\n\t\t\t\twidth: undefined,\n\t\t\t\theight: undefined,\n\t\t\t} );\n\t\t}\n\t}, [ __unstableMarkNextChangeAsNotPersistent, align, setAttributes ] );\n\n\tconst {\n\t\tgetSettings,\n\t\tgetBlockRootClientId,\n\t\tgetBlockName,\n\t\tcanInsertBlockType,\n\t} = useSelect( blockEditorStore );\n\tconst blockEditingMode = useBlockEditingMode();\n\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tfunction onUploadError( message ) {\n\t\tcreateErrorNotice( message, { type: 'snackbar' } );\n\t\tsetTemporaryURL();\n\t\tsetAttributes( {\n\t\t\tsrc: undefined,\n\t\t\tid: undefined,\n\t\t\turl: undefined,\n\t\t\tblob: undefined,\n\t\t} );\n\t}\n\n\tfunction onFilesPreUpload( files ) {\n\t\tif ( files.length === 1 ) {\n\t\t\tsetTemporaryURL( createBlobURL( files[ 0 ] ) );\n\t\t}\n\t}\n\n\tfunction onSelectImagesList( images ) {\n\t\tconst win = containerRef.current?.ownerDocument.defaultView;\n\n\t\tif ( images.every( ( file ) => file instanceof win.File ) ) {\n\t\t\t/** @type {File[]} */\n\t\t\tconst files = images;\n\t\t\tconst rootClientId = getBlockRootClientId( clientId );\n\n\t\t\tif ( files.some( ( file ) => ! isValidFileType( file ) ) ) {\n\t\t\t\t// Copied from the same notice in the gallery block.\n\t\t\t\tcreateErrorNotice(\n\t\t\t\t\t__(\n\t\t\t\t\t\t'If uploading to a gallery all files need to be image formats'\n\t\t\t\t\t),\n\t\t\t\t\t{ id: 'gallery-upload-invalid-file', type: 'snackbar' }\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst imageBlocks = files\n\t\t\t\t.filter( ( file ) => isValidFileType( file ) )\n\t\t\t\t.map( ( file ) =>\n\t\t\t\t\tcreateBlock( 'core/image', {\n\t\t\t\t\t\tblob: createBlobURL( file ),\n\t\t\t\t\t} )\n\t\t\t\t);\n\n\t\t\tif ( getBlockName( rootClientId ) === 'core/gallery' ) {\n\t\t\t\treplaceBlock( clientId, imageBlocks );\n\t\t\t} else if ( canInsertBlockType( 'core/gallery', rootClientId ) ) {\n\t\t\t\tconst galleryBlock = createBlock(\n\t\t\t\t\t'core/gallery',\n\t\t\t\t\t{},\n\t\t\t\t\timageBlocks\n\t\t\t\t);\n\n\t\t\t\treplaceBlock( clientId, galleryBlock );\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction onSelectImage( media ) {\n\t\tif ( Array.isArray( media ) ) {\n\t\t\tonSelectImagesList( media );\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! media || ! media.url ) {\n\t\t\tsetAttributes( {\n\t\t\t\turl: undefined,\n\t\t\t\talt: undefined,\n\t\t\t\tid: undefined,\n\t\t\t\ttitle: undefined,\n\t\t\t\tcaption: undefined,\n\t\t\t\tblob: undefined,\n\t\t\t} );\n\t\t\tsetTemporaryURL();\n\n\t\t\treturn;\n\t\t}\n\n\t\tif ( isBlobURL( media.url ) ) {\n\t\t\tsetTemporaryURL( media.url );\n\t\t\treturn;\n\t\t}\n\n\t\tconst { imageDefaultSize } = getSettings();\n\n\t\t// Try to use the previous selected image size if its available\n\t\t// otherwise try the default image size or fallback to \"full\"\n\t\tlet newSize = DEFAULT_MEDIA_SIZE_SLUG;\n\t\tif ( sizeSlug && hasSize( media, sizeSlug ) ) {\n\t\t\tnewSize = sizeSlug;\n\t\t} else if ( hasSize( media, imageDefaultSize ) ) {\n\t\t\tnewSize = imageDefaultSize;\n\t\t}\n\n\t\tlet mediaAttributes = pickRelevantMediaFiles( media, newSize );\n\n\t\t// Normalize newline characters in caption to <br />\n\t\t// to preserve line breaks in both editor and frontend.\n\t\tif (\n\t\t\ttypeof mediaAttributes.caption === 'string' &&\n\t\t\tmediaAttributes.caption.includes( '\\n' )\n\t\t) {\n\t\t\tmediaAttributes.caption = mediaAttributes.caption.replace(\n\t\t\t\t/\\n/g,\n\t\t\t\t'<br>'\n\t\t\t);\n\t\t}\n\n\t\t// If a caption text was meanwhile written by the user,\n\t\t// make sure the text is not overwritten by empty captions.\n\t\tif ( captionRef.current && ! mediaAttributes.caption ) {\n\t\t\tconst { caption: omittedCaption, ...restMediaAttributes } =\n\t\t\t\tmediaAttributes;\n\t\t\tmediaAttributes = restMediaAttributes;\n\t\t}\n\n\t\tlet additionalAttributes;\n\t\t// Reset the dimension attributes if changing to a different image.\n\t\tif ( ! media.id || media.id !== id ) {\n\t\t\tadditionalAttributes = {\n\t\t\t\tsizeSlug: newSize,\n\t\t\t};\n\t\t}\n\n\t\t// Check if default link setting should be used.\n\t\tlet linkDestination = attributes.linkDestination;\n\t\tif ( ! linkDestination ) {\n\t\t\t// Use the WordPress option to determine the proper default.\n\t\t\t// The constants used in Gutenberg do not match WP options so a little more complicated than ideal.\n\t\t\tswitch (\n\t\t\t\twindow?.wp?.media?.view?.settings?.defaultProps?.link ||\n\t\t\t\tLINK_DESTINATION_NONE\n\t\t\t) {\n\t\t\t\tcase 'file':\n\t\t\t\tcase LINK_DESTINATION_MEDIA:\n\t\t\t\t\tlinkDestination = LINK_DESTINATION_MEDIA;\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'post':\n\t\t\t\tcase LINK_DESTINATION_ATTACHMENT:\n\t\t\t\t\tlinkDestination = LINK_DESTINATION_ATTACHMENT;\n\t\t\t\t\tbreak;\n\t\t\t\tcase LINK_DESTINATION_CUSTOM:\n\t\t\t\t\tlinkDestination = LINK_DESTINATION_CUSTOM;\n\t\t\t\t\tbreak;\n\t\t\t\tcase LINK_DESTINATION_NONE:\n\t\t\t\t\tlinkDestination = LINK_DESTINATION_NONE;\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\t// Check if the image is linked to it's media.\n\t\tlet href;\n\t\tswitch ( linkDestination ) {\n\t\t\tcase LINK_DESTINATION_MEDIA:\n\t\t\t\thref = media.url;\n\t\t\t\tbreak;\n\t\t\tcase LINK_DESTINATION_ATTACHMENT:\n\t\t\t\thref = media.link;\n\t\t\t\tbreak;\n\t\t}\n\t\tmediaAttributes.href = href;\n\n\t\tsetAttributes( {\n\t\t\tblob: undefined,\n\t\t\t...mediaAttributes,\n\t\t\t...additionalAttributes,\n\t\t\tlinkDestination,\n\t\t} );\n\t\tsetTemporaryURL();\n\t}\n\n\tfunction onSelectURL( newURL ) {\n\t\t// Handle URLs without protocol.\n\t\tconst normalizedNewURL = getProtocol( newURL )\n\t\t\t? newURL\n\t\t\t: prependHTTPS( newURL );\n\t\tif ( normalizedNewURL !== url ) {\n\t\t\tsetAttributes( {\n\t\t\t\tblob: undefined,\n\t\t\t\turl: normalizedNewURL,\n\t\t\t\tid: undefined,\n\t\t\t\tsizeSlug: getSettings().imageDefaultSize,\n\t\t\t} );\n\t\t\tsetTemporaryURL();\n\t\t}\n\t}\n\n\tuseUploadMediaFromBlobURL( {\n\t\turl: temporaryURL,\n\t\tallowedTypes: ALLOWED_MEDIA_TYPES,\n\t\tonChange: onSelectImage,\n\t\tonError: onUploadError,\n\t} );\n\n\tconst isExternal = isExternalImage( id, url );\n\tconst src = isExternal ? url : undefined;\n\n\tconst isSideloading = useSelect(\n\t\t( select ) => {\n\t\t\tif (\n\t\t\t\t( ! window.__clientSideMediaProcessing &&\n\t\t\t\t\t! window.__heicUploadSupport ) ||\n\t\t\t\t! id\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn select( uploadStore ).isUploadingById( id );\n\t\t},\n\t\t[ id ]\n\t);\n\n\tconst mediaPreview = !! url && (\n\t\t<img\n\t\t\talt={ __( 'Edit image' ) }\n\t\t\ttitle={ __( 'Edit image' ) }\n\t\t\tclassName=\"edit-image-preview\"\n\t\t\tsrc={ url }\n\t\t/>\n\t);\n\n\tconst borderProps = useBorderProps( attributes );\n\tconst shadowProps = getShadowClassesAndStyles( attributes );\n\n\tconst classes = clsx( className, {\n\t\t'is-transient': !! temporaryURL || isSideloading,\n\t\t'is-resized': !! width || !! height,\n\t\t[ `size-${ sizeSlug }` ]: sizeSlug,\n\t\t'has-custom-border':\n\t\t\t!! borderProps.className ||\n\t\t\t( borderProps.style &&\n\t\t\t\tObject.keys( borderProps.style ).length > 0 ),\n\t} );\n\n\tconst blockProps = useBlockProps( {\n\t\tref: containerRef,\n\t\tclassName: classes,\n\t} );\n\n\t// Much of this description is duplicated from MediaPlaceholder.\n\tconst { lockUrlControls = false, lockUrlControlsMessage } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! isSingleSelected ) {\n\t\t\t\treturn {};\n\t\t\t}\n\n\t\t\tconst blockBindingsSource = getBlockBindingsSource(\n\t\t\t\tmetadata?.bindings?.url?.source\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tlockUrlControls:\n\t\t\t\t\t!! metadata?.bindings?.url &&\n\t\t\t\t\t! blockBindingsSource?.canUserEditValue?.( {\n\t\t\t\t\t\tselect,\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t\targs: metadata?.bindings?.url?.args,\n\t\t\t\t\t} ),\n\t\t\t\tlockUrlControlsMessage: blockBindingsSource?.label\n\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t/* translators: %s: Label of the bindings source. */\n\t\t\t\t\t\t\t__( 'Connected to %s' ),\n\t\t\t\t\t\t\tblockBindingsSource.label\n\t\t\t\t\t )\n\t\t\t\t\t: __( 'Connected to dynamic data' ),\n\t\t\t};\n\t\t},\n\t\t[ context, isSingleSelected, metadata?.bindings?.url ]\n\t);\n\tconst placeholder = ( content ) => {\n\t\treturn (\n\t\t\t<Placeholder\n\t\t\t\tclassName={ clsx( 'block-editor-media-placeholder', {\n\t\t\t\t\t[ borderProps.className ]:\n\t\t\t\t\t\t!! borderProps.className && ! isSingleSelected,\n\t\t\t\t} ) }\n\t\t\t\ticon={\n\t\t\t\t\t! isSmallContainer &&\n\t\t\t\t\t( lockUrlControls ? pluginsIcon : icon )\n\t\t\t\t}\n\t\t\t\twithIllustration={ ! isSingleSelected || isSmallContainer }\n\t\t\t\tlabel={ ! isSmallContainer && __( 'Image' ) }\n\t\t\t\tinstructions={\n\t\t\t\t\t! lockUrlControls &&\n\t\t\t\t\t! isSmallContainer &&\n\t\t\t\t\t__(\n\t\t\t\t\t\t'Drag and drop an image, upload, or choose from your library.'\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tstyle={ {\n\t\t\t\t\taspectRatio:\n\t\t\t\t\t\t! ( width && height ) && aspectRatio\n\t\t\t\t\t\t\t? aspectRatio\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\twidth: height && aspectRatio ? '100%' : width,\n\t\t\t\t\theight: width && aspectRatio ? '100%' : height,\n\t\t\t\t\tobjectFit: scale,\n\t\t\t\t\t...borderProps.style,\n\t\t\t\t\t...shadowProps.style,\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ lockUrlControls &&\n\t\t\t\t\t! isSmallContainer &&\n\t\t\t\t\tlockUrlControlsMessage }\n\n\t\t\t\t{ ! lockUrlControls && ! isSmallContainer && content }\n\t\t\t\t{ placeholderResizeListener }\n\t\t\t</Placeholder>\n\t\t);\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t<figure { ...blockProps }>\n\t\t\t\t<Image\n\t\t\t\t\ttemporaryURL={ temporaryURL }\n\t\t\t\t\tisSideloading={ isSideloading }\n\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\tisSingleSelected={ isSingleSelected }\n\t\t\t\t\tinsertBlocksAfter={ insertBlocksAfter }\n\t\t\t\t\tonReplace={ onReplace }\n\t\t\t\t\tonSelectImage={ onSelectImage }\n\t\t\t\t\tonSelectURL={ onSelectURL }\n\t\t\t\t\tonUploadError={ onUploadError }\n\t\t\t\t\tcontext={ context }\n\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\tblockEditingMode={ blockEditingMode }\n\t\t\t\t\tparentLayoutType={ layoutType }\n\t\t\t\t\tmaxContentWidth={ maxContentWidth }\n\t\t\t\t/>\n\t\t\t\t<MediaPlaceholder\n\t\t\t\t\ticon={ <BlockIcon icon={ icon } /> }\n\t\t\t\t\tonSelect={ onSelectImage }\n\t\t\t\t\tonSelectURL={ onSelectURL }\n\t\t\t\t\tonFilesPreUpload={ onFilesPreUpload }\n\t\t\t\t\tonError={ onUploadError }\n\t\t\t\t\tplaceholder={ placeholder }\n\t\t\t\t\tallowedTypes={ ALLOWED_MEDIA_TYPES }\n\t\t\t\t\thandleUpload={ ( files ) => files.length === 1 }\n\t\t\t\t\tvalue={ { id, src } }\n\t\t\t\t\tmediaPreview={ mediaPreview }\n\t\t\t\t\tdisableMediaButtons={ temporaryURL || url }\n\t\t\t\t/>\n\t\t\t</figure>\n\t\t\t{\n\t\t\t\t// The listener cannot be placed as the first element as it will break the in-between inserter.\n\t\t\t\t// See https://github.com/WordPress/gutenberg/blob/71134165868298fc15e22896d0c28b41b3755ff7/packages/block-editor/src/components/block-list/use-in-between-inserter.js#L120\n\t\t\t\tisSingleSelected && isMaxWidthContainerWidth && maxWidthObserver\n\t\t\t}\n\t\t</>\n\t);\n}\n\nexport default ImageEdit;\n"],
|
|
5
|
+
"mappings": ";AAGA,OAAO,UAAU;AAKjB,SAAS,WAAW,qBAAqB;AACzC,SAAS,aAAa,8BAA8B;AACpD,SAAS,mBAAmB;AAC5B,SAAS,aAAa,iBAAiB;AACvC;AAAA,E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AAC;AAAA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA,kBAAmB;AAAA,UACnB;AAAA;AAAA,MACD;AAAA,MACA;AAAA,QAAC;AAAA;AAAA,UACA,MAAO,oBAAC,aAAU,MAAc;AAAA,UAChC,UAAW;AAAA,UACX;AAAA,UACA;AAAA,UACA,SAAU;AAAA,UACV;AAAA,UACA,cAAe;AAAA,UACf,cAAe,CAAE,UAAW,MAAM,WAAW;AAAA,UAC7C,OAAQ,EAAE,IAAI,IAAI;AAAA,UAClB;AAAA,UACA,qBAAsB,gBAAgB;AAAA;AAAA,MACvC;AAAA,OACD;AAAA;AAAA;AAAA,IAIC,oBAAoB,4BAA4B;AAAA,KAElD;AAEF;AAEA,IAAO,eAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -64,9 +64,12 @@ import {
|
|
|
64
64
|
} from "./constants.mjs";
|
|
65
65
|
import { evalAspectRatio, mediaPosition } from "./utils.mjs";
|
|
66
66
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
67
|
-
var {
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
var {
|
|
68
|
+
DimensionsTool,
|
|
69
|
+
ResolutionTool,
|
|
70
|
+
mediaEditKey,
|
|
71
|
+
openMediaEditorModalKey
|
|
72
|
+
} = unlock(blockEditorPrivateApis);
|
|
70
73
|
var scaleOptions = [
|
|
71
74
|
{
|
|
72
75
|
value: "cover",
|
|
@@ -313,14 +316,6 @@ function Image({
|
|
|
313
316
|
},
|
|
314
317
|
[id, isSingleSelected]
|
|
315
318
|
);
|
|
316
|
-
useEffect(() => {
|
|
317
|
-
if (!id || !isSingleSelected) {
|
|
318
|
-
return;
|
|
319
|
-
}
|
|
320
|
-
if (attachmentResolutionError?.status === 404) {
|
|
321
|
-
setAttributes({ id: void 0 });
|
|
322
|
-
}
|
|
323
|
-
}, [id, isSingleSelected, attachmentResolutionError, setAttributes]);
|
|
324
319
|
const {
|
|
325
320
|
canInsertCover,
|
|
326
321
|
imageEditing,
|
|
@@ -331,12 +326,12 @@ function Image({
|
|
|
331
326
|
(select) => {
|
|
332
327
|
const { getBlockRootClientId, canInsertBlockType, getSettings: getSettings2 } = select(blockEditorStore);
|
|
333
328
|
const rootClientId = getBlockRootClientId(clientId);
|
|
334
|
-
const
|
|
329
|
+
const settings2 = getSettings2();
|
|
335
330
|
return {
|
|
336
|
-
imageEditing:
|
|
337
|
-
imageSizes:
|
|
338
|
-
maxWidth:
|
|
339
|
-
editMediaEntity:
|
|
331
|
+
imageEditing: settings2.imageEditing,
|
|
332
|
+
imageSizes: settings2.imageSizes,
|
|
333
|
+
maxWidth: settings2.maxWidth,
|
|
334
|
+
editMediaEntity: settings2?.[mediaEditKey],
|
|
340
335
|
canInsertCover: canInsertBlockType(
|
|
341
336
|
"core/cover",
|
|
342
337
|
rootClientId
|
|
@@ -346,8 +341,25 @@ function Image({
|
|
|
346
341
|
[clientId]
|
|
347
342
|
);
|
|
348
343
|
const { getBlock, getSettings } = useSelect(blockEditorStore);
|
|
349
|
-
const
|
|
350
|
-
const {
|
|
344
|
+
const settings = getSettings();
|
|
345
|
+
const { onNavigateToEntityRecord } = settings;
|
|
346
|
+
const openMediaEditorModal = settings[openMediaEditorModalKey];
|
|
347
|
+
const handleMediaUpdate = useCallback(
|
|
348
|
+
({ id: newId, url: newUrl }) => {
|
|
349
|
+
if (typeof newId === "number" && newId !== id) {
|
|
350
|
+
setAttributes({
|
|
351
|
+
id: newId,
|
|
352
|
+
url: newUrl ?? url
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
},
|
|
356
|
+
[id, url, setAttributes]
|
|
357
|
+
);
|
|
358
|
+
const {
|
|
359
|
+
replaceBlocks,
|
|
360
|
+
toggleSelection,
|
|
361
|
+
__unstableMarkNextChangeAsNotPersistent
|
|
362
|
+
} = useDispatch(blockEditorStore);
|
|
351
363
|
const { createErrorNotice, createSuccessNotice } = useDispatch(noticesStore);
|
|
352
364
|
const { editEntityRecord } = useDispatch(coreStore);
|
|
353
365
|
const isLargeViewport = useViewportMatch("medium");
|
|
@@ -367,6 +379,21 @@ function Image({
|
|
|
367
379
|
const imageSizeOptions = imageSizes.filter(
|
|
368
380
|
({ slug }) => image?.media_details?.sizes?.[slug]?.source_url
|
|
369
381
|
).map(({ name, slug }) => ({ value: slug, label: name }));
|
|
382
|
+
useEffect(() => {
|
|
383
|
+
if (!id || !isSingleSelected) {
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
if (attachmentResolutionError?.status === 404) {
|
|
387
|
+
__unstableMarkNextChangeAsNotPersistent();
|
|
388
|
+
setAttributes({ id: void 0 });
|
|
389
|
+
}
|
|
390
|
+
}, [
|
|
391
|
+
id,
|
|
392
|
+
isSingleSelected,
|
|
393
|
+
attachmentResolutionError,
|
|
394
|
+
setAttributes,
|
|
395
|
+
__unstableMarkNextChangeAsNotPersistent
|
|
396
|
+
]);
|
|
370
397
|
useEffect(() => {
|
|
371
398
|
if (!isExternalImage(id, url) || !isSingleSelected || !getSettings().mediaUpload) {
|
|
372
399
|
setExternalBlob();
|
|
@@ -675,7 +702,10 @@ function Image({
|
|
|
675
702
|
allowCrop && /* @__PURE__ */ jsx(
|
|
676
703
|
ToolbarButton,
|
|
677
704
|
{
|
|
678
|
-
onClick: () =>
|
|
705
|
+
onClick: openMediaEditorModal && id ? () => openMediaEditorModal({
|
|
706
|
+
id,
|
|
707
|
+
onUpdate: handleMediaUpdate
|
|
708
|
+
}) : () => setIsEditingImage(true),
|
|
679
709
|
icon: crop,
|
|
680
710
|
label: __("Crop")
|
|
681
711
|
}
|