@wordpress/block-library 8.5.0 → 8.6.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/buttons/edit.native.js +1 -1
- package/build/buttons/edit.native.js.map +1 -1
- package/build/columns/edit.js +10 -8
- package/build/columns/edit.js.map +1 -1
- package/build/columns/edit.native.js +1 -1
- package/build/columns/edit.native.js.map +1 -1
- package/build/comments/edit/placeholder.js +8 -5
- package/build/comments/edit/placeholder.js.map +1 -1
- package/build/cover/index.js +13 -4
- package/build/cover/index.js.map +1 -1
- package/build/cover/variations.js +29 -0
- package/build/cover/variations.js.map +1 -0
- package/build/embed/edit.js +13 -14
- package/build/embed/edit.js.map +1 -1
- package/build/embed/edit.native.js +18 -14
- package/build/embed/edit.native.js.map +1 -1
- package/build/embed/util.js +39 -12
- package/build/embed/util.js.map +1 -1
- package/build/gallery/edit.js +1 -0
- package/build/gallery/edit.js.map +1 -1
- package/build/latest-posts/edit.js +10 -10
- package/build/latest-posts/edit.js.map +1 -1
- package/build/latest-posts/edit.native.js +3 -3
- package/build/latest-posts/edit.native.js.map +1 -1
- package/build/media-text/constants.js +17 -1
- package/build/media-text/constants.js.map +1 -1
- package/build/media-text/edit.js +7 -19
- package/build/media-text/edit.js.map +1 -1
- package/build/media-text/edit.native.js +6 -5
- package/build/media-text/edit.native.js.map +1 -1
- package/build/media-text/transforms.js +32 -44
- package/build/media-text/transforms.js.map +1 -1
- package/build/navigation/edit/index.js +56 -86
- package/build/navigation/edit/index.js.map +1 -1
- package/build/navigation/edit/inner-blocks.js +4 -1
- package/build/navigation/edit/inner-blocks.js.map +1 -1
- package/build/navigation/edit/menu-inspector-controls.js +2 -5
- package/build/navigation/edit/menu-inspector-controls.js.map +1 -1
- package/build/navigation/edit/navigation-menu-selector.js +26 -22
- package/build/navigation/edit/navigation-menu-selector.js.map +1 -1
- package/build/navigation/edit/unsaved-inner-blocks.js +14 -1
- package/build/navigation/edit/unsaved-inner-blocks.js.map +1 -1
- package/build/navigation/edit/use-convert-classic-menu-to-block-menu.js +2 -4
- package/build/navigation/edit/use-convert-classic-menu-to-block-menu.js.map +1 -1
- package/build/navigation/edit/use-create-navigation-menu.js +1 -1
- package/build/navigation/edit/use-create-navigation-menu.js.map +1 -1
- package/build/navigation/edit/use-navigation-notice.js +1 -1
- package/build/navigation/edit/use-navigation-notice.js.map +1 -1
- package/build/navigation-link/edit.js +0 -11
- package/build/navigation-link/edit.js.map +1 -1
- package/build/navigation-link/link-ui.js +0 -1
- package/build/navigation-link/link-ui.js.map +1 -1
- package/build/navigation-submenu/edit.js +1 -13
- package/build/navigation-submenu/edit.js.map +1 -1
- package/build/page-list/edit.js +59 -45
- package/build/page-list/edit.js.map +1 -1
- package/build/page-list-item/edit.js +3 -2
- package/build/page-list-item/edit.js.map +1 -1
- package/build/post-content/edit.js +6 -1
- package/build/post-content/edit.js.map +1 -1
- package/build/post-featured-image/dimension-controls.js +0 -6
- package/build/post-featured-image/dimension-controls.js.map +1 -1
- package/build/post-featured-image/edit.js +1 -1
- package/build/post-featured-image/edit.js.map +1 -1
- package/build/pullquote/deprecated.js +3 -3
- package/build/pullquote/deprecated.js.map +1 -1
- package/build/query/edit/query-placeholder.js +3 -2
- package/build/query/edit/query-placeholder.js.map +1 -1
- package/build/query/utils.js +26 -9
- package/build/query/utils.js.map +1 -1
- package/build/table/state.js +12 -4
- package/build/table/state.js.map +1 -1
- package/build/template-part/edit/import-controls.js +4 -24
- package/build/template-part/edit/import-controls.js.map +1 -1
- package/build/template-part/edit/utils/transformers.js +69 -19
- package/build/template-part/edit/utils/transformers.js.map +1 -1
- package/build/text-columns/edit.js +3 -7
- package/build/text-columns/edit.js.map +1 -1
- package/build/text-columns/save.js +11 -13
- package/build/text-columns/save.js.map +1 -1
- package/build-module/buttons/edit.native.js +1 -1
- package/build-module/buttons/edit.native.js.map +1 -1
- package/build-module/columns/edit.js +10 -7
- package/build-module/columns/edit.js.map +1 -1
- package/build-module/columns/edit.native.js +1 -1
- package/build-module/columns/edit.native.js.map +1 -1
- package/build-module/comments/edit/placeholder.js +9 -5
- package/build-module/comments/edit/placeholder.js.map +1 -1
- package/build-module/cover/index.js +12 -4
- package/build-module/cover/index.js.map +1 -1
- package/build-module/cover/variations.js +19 -0
- package/build-module/cover/variations.js.map +1 -0
- package/build-module/embed/edit.js +14 -15
- package/build-module/embed/edit.js.map +1 -1
- package/build-module/embed/edit.native.js +19 -15
- package/build-module/embed/edit.native.js.map +1 -1
- package/build-module/embed/util.js +34 -10
- package/build-module/embed/util.js.map +1 -1
- package/build-module/gallery/edit.js +1 -0
- package/build-module/gallery/edit.js.map +1 -1
- package/build-module/latest-posts/edit.js +10 -9
- package/build-module/latest-posts/edit.js.map +1 -1
- package/build-module/latest-posts/edit.native.js +3 -3
- package/build-module/latest-posts/edit.native.js.map +1 -1
- package/build-module/media-text/constants.js +10 -0
- package/build-module/media-text/constants.js.map +1 -1
- package/build-module/media-text/edit.js +2 -14
- package/build-module/media-text/edit.js.map +1 -1
- package/build-module/media-text/edit.native.js +4 -3
- package/build-module/media-text/edit.native.js.map +1 -1
- package/build-module/media-text/transforms.js +32 -44
- package/build-module/media-text/transforms.js.map +1 -1
- package/build-module/navigation/edit/index.js +58 -88
- package/build-module/navigation/edit/index.js.map +1 -1
- package/build-module/navigation/edit/inner-blocks.js +4 -1
- package/build-module/navigation/edit/inner-blocks.js.map +1 -1
- package/build-module/navigation/edit/menu-inspector-controls.js +2 -5
- package/build-module/navigation/edit/menu-inspector-controls.js.map +1 -1
- package/build-module/navigation/edit/navigation-menu-selector.js +25 -22
- package/build-module/navigation/edit/navigation-menu-selector.js.map +1 -1
- package/build-module/navigation/edit/unsaved-inner-blocks.js +14 -1
- package/build-module/navigation/edit/unsaved-inner-blocks.js.map +1 -1
- package/build-module/navigation/edit/use-convert-classic-menu-to-block-menu.js +2 -4
- package/build-module/navigation/edit/use-convert-classic-menu-to-block-menu.js.map +1 -1
- package/build-module/navigation/edit/use-create-navigation-menu.js +1 -1
- package/build-module/navigation/edit/use-create-navigation-menu.js.map +1 -1
- package/build-module/navigation/edit/use-navigation-notice.js +1 -1
- package/build-module/navigation/edit/use-navigation-notice.js.map +1 -1
- package/build-module/navigation-link/edit.js +0 -11
- package/build-module/navigation-link/edit.js.map +1 -1
- package/build-module/navigation-link/link-ui.js +0 -1
- package/build-module/navigation-link/link-ui.js.map +1 -1
- package/build-module/navigation-submenu/edit.js +1 -13
- package/build-module/navigation-submenu/edit.js.map +1 -1
- package/build-module/page-list/edit.js +61 -47
- package/build-module/page-list/edit.js.map +1 -1
- package/build-module/page-list-item/edit.js +3 -2
- package/build-module/page-list-item/edit.js.map +1 -1
- package/build-module/post-content/edit.js +6 -1
- package/build-module/post-content/edit.js.map +1 -1
- package/build-module/post-featured-image/dimension-controls.js +0 -6
- package/build-module/post-featured-image/dimension-controls.js.map +1 -1
- package/build-module/post-featured-image/edit.js +1 -1
- package/build-module/post-featured-image/edit.js.map +1 -1
- package/build-module/pullquote/deprecated.js +3 -2
- package/build-module/pullquote/deprecated.js.map +1 -1
- package/build-module/query/edit/query-placeholder.js +4 -3
- package/build-module/query/edit/query-placeholder.js.map +1 -1
- package/build-module/query/utils.js +21 -6
- package/build-module/query/utils.js.map +1 -1
- package/build-module/table/state.js +13 -5
- package/build-module/table/state.js.map +1 -1
- package/build-module/template-part/edit/import-controls.js +4 -23
- package/build-module/template-part/edit/import-controls.js.map +1 -1
- package/build-module/template-part/edit/utils/transformers.js +69 -20
- package/build-module/template-part/edit/utils/transformers.js.map +1 -1
- package/build-module/text-columns/edit.js +3 -6
- package/build-module/text-columns/edit.js.map +1 -1
- package/build-module/text-columns/save.js +11 -12
- package/build-module/text-columns/save.js.map +1 -1
- package/build-style/cover/style-rtl.css +11 -5
- package/build-style/cover/style.css +11 -5
- package/build-style/editor-rtl.css +5 -1
- package/build-style/editor.css +5 -1
- package/build-style/navigation/editor-rtl.css +1 -1
- package/build-style/navigation/editor.css +1 -1
- package/build-style/page-list/editor-rtl.css +4 -0
- package/build-style/page-list/editor.css +4 -0
- package/build-style/post-featured-image/style-rtl.css +1 -0
- package/build-style/post-featured-image/style.css +1 -0
- package/build-style/style-rtl.css +12 -5
- package/build-style/style.css +12 -5
- package/package.json +31 -31
- package/src/audio/test/__snapshots__/edit.native.js.snap +44 -4
- package/src/audio/test/__snapshots__/transforms.native.js.snap +25 -0
- package/src/audio/test/transforms.native.js +42 -0
- package/src/block/test/__snapshots__/transforms.native.js.snap +15 -0
- package/src/block/test/transforms.native.js +40 -0
- package/src/buttons/edit.native.js +1 -1
- package/src/buttons/test/__snapshots__/transforms.native.js.snap +31 -0
- package/src/buttons/test/transforms.native.js +48 -0
- package/src/columns/edit.js +28 -17
- package/src/columns/edit.native.js +1 -1
- package/src/columns/test/__snapshots__/transforms.native.js.snap +61 -0
- package/src/columns/test/transforms.native.js +91 -0
- package/src/comment-template/index.php +1 -2
- package/src/comments/edit/placeholder.js +16 -4
- package/src/cover/block.json +9 -3
- package/src/cover/index.js +2 -0
- package/src/cover/style.scss +16 -7
- package/src/cover/test/__snapshots__/transforms.native.js.snap +73 -0
- package/src/cover/test/transforms.native.js +112 -0
- package/src/cover/variations.js +20 -0
- package/src/embed/edit.js +16 -12
- package/src/embed/edit.native.js +28 -18
- package/src/embed/test/__snapshots__/transforms.native.js.snap +23 -0
- package/src/embed/test/index.js +12 -0
- package/src/embed/test/transforms.native.js +44 -0
- package/src/embed/util.js +29 -8
- package/src/file/test/__snapshots__/edit.native.js.snap +18 -2
- package/src/file/test/__snapshots__/transforms.native.js.snap +19 -0
- package/src/file/test/transforms.native.js +42 -0
- package/src/freeform/test/__snapshots__/transforms.native.js.snap +19 -0
- package/src/freeform/test/transforms.native.js +39 -0
- package/src/gallery/edit.js +3 -0
- package/src/gallery/test/__snapshots__/transforms.native.js.snap +53 -0
- package/src/gallery/test/transforms.native.js +52 -0
- package/src/group/test/__snapshots__/transforms.native.js.snap +35 -0
- package/src/group/test/transforms.native.js +75 -0
- package/src/heading/test/__snapshots__/transforms.native.js.snap +47 -0
- package/src/heading/test/transforms.native.js +46 -0
- package/src/image/test/__snapshots__/transforms.native.js.snap +49 -0
- package/src/image/test/transforms.native.js +48 -0
- package/src/latest-posts/edit.js +11 -16
- package/src/latest-posts/edit.native.js +3 -3
- package/src/latest-posts/test/__snapshots__/transforms.native.js.snap +15 -0
- package/src/latest-posts/test/transforms.native.js +61 -0
- package/src/list/test/__snapshots__/transforms.native.js.snap +85 -0
- package/src/list/test/transforms.native.js +56 -0
- package/src/media-text/constants.js +16 -0
- package/src/media-text/edit.js +8 -18
- package/src/media-text/edit.native.js +3 -9
- package/src/media-text/test/__snapshots__/transforms.native.js.snap +73 -0
- package/src/media-text/test/transforms.native.js +112 -0
- package/src/media-text/transforms.js +24 -51
- package/src/missing/test/__snapshots__/edit.native.js.snap +20 -2
- package/src/more/test/__snapshots__/transforms.native.js.snap +19 -0
- package/src/more/test/transforms.native.js +42 -0
- package/src/navigation/edit/index.js +104 -107
- package/src/navigation/edit/inner-blocks.js +3 -0
- package/src/navigation/edit/menu-inspector-controls.js +2 -7
- package/src/navigation/edit/navigation-menu-selector.js +41 -25
- package/src/navigation/edit/unsaved-inner-blocks.js +46 -33
- package/src/navigation/edit/use-convert-classic-menu-to-block-menu.js +82 -83
- package/src/navigation/edit/use-create-navigation-menu.js +1 -1
- package/src/navigation/edit/use-navigation-notice.js +1 -1
- package/src/navigation/editor.scss +23 -20
- package/src/navigation/index.php +18 -39
- package/src/navigation-link/edit.js +0 -9
- package/src/navigation-link/index.php +5 -8
- package/src/navigation-link/link-ui.js +0 -1
- package/src/navigation-submenu/edit.js +0 -10
- package/src/navigation-submenu/index.php +23 -6
- package/src/nextpage/test/__snapshots__/transforms.native.js.snap +19 -0
- package/src/nextpage/test/transforms.native.js +42 -0
- package/src/page-list/edit.js +78 -44
- package/src/page-list/editor.scss +6 -0
- package/src/page-list-item/edit.js +2 -3
- package/src/paragraph/test/__snapshots__/transforms.native.js.snap +59 -0
- package/src/paragraph/test/transforms.native.js +50 -0
- package/src/post-content/edit.js +5 -1
- package/src/post-excerpt/index.php +1 -2
- package/src/post-featured-image/dimension-controls.js +0 -8
- package/src/post-featured-image/edit.js +1 -1
- package/src/post-featured-image/style.scss +1 -0
- package/src/preformatted/test/__snapshots__/transforms.native.js.snap +31 -0
- package/src/preformatted/test/transforms.native.js +42 -0
- package/src/pullquote/deprecated.js +2 -6
- package/src/pullquote/test/__snapshots__/transforms.native.js.snap +47 -0
- package/src/pullquote/test/transforms.native.js +46 -0
- package/src/query/edit/query-placeholder.js +10 -5
- package/src/query/test/utils.js +33 -1
- package/src/query/utils.js +19 -6
- package/src/quote/test/__snapshots__/transforms.native.js.snap +39 -0
- package/src/quote/test/transforms.native.js +67 -0
- package/src/search/test/__snapshots__/edit.native.js.snap +11 -1
- package/src/search/test/__snapshots__/transforms.native.js.snap +15 -0
- package/src/search/test/transforms.native.js +40 -0
- package/src/separator/test/__snapshots__/transforms.native.js.snap +19 -0
- package/src/separator/test/transforms.native.js +42 -0
- package/src/shortcode/test/__snapshots__/transforms.native.js.snap +19 -0
- package/src/shortcode/test/transforms.native.js +42 -0
- package/src/social-links/test/__snapshots__/transforms.native.js.snap +31 -0
- package/src/social-links/test/transforms.native.js +53 -0
- package/src/spacer/test/__snapshots__/transforms.native.js.snap +19 -0
- package/src/spacer/test/transforms.native.js +42 -0
- package/src/table/state.js +8 -17
- package/src/template-part/edit/import-controls.js +2 -29
- package/src/template-part/edit/utils/transformers.js +96 -19
- package/src/text-columns/edit.js +1 -6
- package/src/text-columns/save.js +1 -6
- package/src/verse/test/__snapshots__/transforms.native.js.snap +25 -0
- package/src/verse/test/transforms.native.js +42 -0
- package/src/video/test/__snapshots__/transforms.native.js.snap +41 -0
- package/src/video/test/transforms.native.js +48 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -100,14 +100,17 @@ const metadata = {
|
|
|
100
100
|
spacing: {
|
|
101
101
|
padding: true,
|
|
102
102
|
margin: ["top", "bottom"],
|
|
103
|
+
blockGap: true,
|
|
103
104
|
__experimentalDefaultControls: {
|
|
104
|
-
padding: true
|
|
105
|
+
padding: true,
|
|
106
|
+
blockGap: true
|
|
105
107
|
}
|
|
106
108
|
},
|
|
107
109
|
color: {
|
|
108
110
|
__experimentalDuotone: "> .wp-block-cover__image-background, > .wp-block-cover__video-background",
|
|
109
|
-
text:
|
|
110
|
-
background: false
|
|
111
|
+
text: true,
|
|
112
|
+
background: false,
|
|
113
|
+
__experimentalSkipSerialization: ["gradients"]
|
|
111
114
|
},
|
|
112
115
|
typography: {
|
|
113
116
|
fontSize: true,
|
|
@@ -121,6 +124,9 @@ const metadata = {
|
|
|
121
124
|
__experimentalDefaultControls: {
|
|
122
125
|
fontSize: true
|
|
123
126
|
}
|
|
127
|
+
},
|
|
128
|
+
__experimentalLayout: {
|
|
129
|
+
allowJustification: false
|
|
124
130
|
}
|
|
125
131
|
},
|
|
126
132
|
editorStyle: "wp-block-cover-editor",
|
|
@@ -128,6 +134,7 @@ const metadata = {
|
|
|
128
134
|
};
|
|
129
135
|
import save from './save';
|
|
130
136
|
import transforms from './transforms';
|
|
137
|
+
import variations from './variations';
|
|
131
138
|
const {
|
|
132
139
|
name
|
|
133
140
|
} = metadata;
|
|
@@ -159,7 +166,8 @@ export const settings = {
|
|
|
159
166
|
transforms,
|
|
160
167
|
save,
|
|
161
168
|
edit,
|
|
162
|
-
deprecated
|
|
169
|
+
deprecated,
|
|
170
|
+
variations
|
|
163
171
|
};
|
|
164
172
|
export const init = () => initBlock({
|
|
165
173
|
name,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/cover/index.js"],"names":["__","cover","icon","initBlock","deprecated","edit","save","transforms","name","metadata","settings","example","attributes","customOverlayColor","dimRatio","url","innerBlocks","content","align","style","typography","fontSize","color","text","init"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,KAAK,IAAIC,IAAlB,QAA8B,kBAA9B;AAEA;AACA;AACA;;AACA,OAAOC,SAAP,MAAsB,qBAAtB;AACA,OAAOC,UAAP,MAAuB,cAAvB;AACA,OAAOC,IAAP,MAAiB,QAAjB
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/cover/index.js"],"names":["__","cover","icon","initBlock","deprecated","edit","save","transforms","variations","name","metadata","settings","example","attributes","customOverlayColor","dimRatio","url","innerBlocks","content","align","style","typography","fontSize","color","text","init"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,KAAK,IAAIC,IAAlB,QAA8B,kBAA9B;AAEA;AACA;AACA;;AACA,OAAOC,SAAP,MAAsB,qBAAtB;AACA,OAAOC,UAAP,MAAuB,cAAvB;AACA,OAAOC,IAAP,MAAiB,QAAjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,OAAOC,IAAP,MAAiB,QAAjB;AACA,OAAOC,UAAP,MAAuB,cAAvB;AACA,OAAOC,UAAP,MAAuB,cAAvB;AAEA,MAAM;AAAEC,EAAAA;AAAF,IAAWC,QAAjB;AAEA,SAASA,QAAT,EAAmBD,IAAnB;AAEA,OAAO,MAAME,QAAQ,GAAG;AACvBT,EAAAA,IADuB;AAEvBU,EAAAA,OAAO,EAAE;AACRC,IAAAA,UAAU,EAAE;AACXC,MAAAA,kBAAkB,EAAE,SADT;AAEXC,MAAAA,QAAQ,EAAE,EAFC;AAGXC,MAAAA,GAAG,EAAE;AAHM,KADJ;AAMRC,IAAAA,WAAW,EAAE,CACZ;AACCR,MAAAA,IAAI,EAAE,gBADP;AAECI,MAAAA,UAAU,EAAE;AACXK,QAAAA,OAAO,EAAElB,EAAE,CAAE,8BAAF,CADA;AAEXmB,QAAAA,KAAK,EAAE,QAFI;AAGXC,QAAAA,KAAK,EAAE;AACNC,UAAAA,UAAU,EAAE;AACXC,YAAAA,QAAQ,EAAE;AADC,WADN;AAINC,UAAAA,KAAK,EAAE;AACNC,YAAAA,IAAI,EAAE;AADA;AAJD;AAHI;AAFb,KADY;AANL,GAFc;AA0BvBjB,EAAAA,UA1BuB;AA2BvBD,EAAAA,IA3BuB;AA4BvBD,EAAAA,IA5BuB;AA6BvBD,EAAAA,UA7BuB;AA8BvBI,EAAAA;AA9BuB,CAAjB;AAiCP,OAAO,MAAMiB,IAAI,GAAG,MAAMtB,SAAS,CAAE;AAAEM,EAAAA,IAAF;AAAQC,EAAAA,QAAR;AAAkBC,EAAAA;AAAlB,CAAF,CAA5B","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { cover as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\nimport transforms from './transforms';\nimport variations from './variations';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\tcustomOverlayColor: '#065174',\n\t\t\tdimRatio: 40,\n\t\t\turl: 'https://s.w.org/images/core/5.3/Windbuchencom.jpg',\n\t\t},\n\t\tinnerBlocks: [\n\t\t\t{\n\t\t\t\tname: 'core/paragraph',\n\t\t\t\tattributes: {\n\t\t\t\t\tcontent: __( '<strong>Snow Patrol</strong>' ),\n\t\t\t\t\talign: 'center',\n\t\t\t\t\tstyle: {\n\t\t\t\t\t\ttypography: {\n\t\t\t\t\t\t\tfontSize: 48,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcolor: {\n\t\t\t\t\t\t\ttext: 'white',\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t},\n\ttransforms,\n\tsave,\n\tedit,\n\tdeprecated,\n\tvariations,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __ } from '@wordpress/i18n';
|
|
5
|
+
import { cover } from '@wordpress/icons';
|
|
6
|
+
const variations = [{
|
|
7
|
+
name: 'cover',
|
|
8
|
+
title: __('Cover'),
|
|
9
|
+
description: __('Add an image or video with a text overlay — great for headers.'),
|
|
10
|
+
attributes: {
|
|
11
|
+
layout: {
|
|
12
|
+
type: 'constrained'
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
isDefault: true,
|
|
16
|
+
icon: cover
|
|
17
|
+
}];
|
|
18
|
+
export default variations;
|
|
19
|
+
//# sourceMappingURL=variations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/cover/variations.js"],"names":["__","cover","variations","name","title","description","attributes","layout","type","isDefault","icon"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,KAAT,QAAsB,kBAAtB;AAEA,MAAMC,UAAU,GAAG,CAClB;AACCC,EAAAA,IAAI,EAAE,OADP;AAECC,EAAAA,KAAK,EAAEJ,EAAE,CAAE,OAAF,CAFV;AAGCK,EAAAA,WAAW,EAAEL,EAAE,CACd,gEADc,CAHhB;AAMCM,EAAAA,UAAU,EAAE;AAAEC,IAAAA,MAAM,EAAE;AAAEC,MAAAA,IAAI,EAAE;AAAR;AAAV,GANb;AAOCC,EAAAA,SAAS,EAAE,IAPZ;AAQCC,EAAAA,IAAI,EAAET;AARP,CADkB,CAAnB;AAaA,eAAeC,UAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { cover } from '@wordpress/icons';\n\nconst variations = [\n\t{\n\t\tname: 'cover',\n\t\ttitle: __( 'Cover' ),\n\t\tdescription: __(\n\t\t\t'Add an image or video with a text overlay — great for headers.'\n\t\t),\n\t\tattributes: { layout: { type: 'constrained' } },\n\t\tisDefault: true,\n\t\ticon: cover,\n\t},\n];\n\nexport default variations;\n"]}
|
|
@@ -3,7 +3,7 @@ import { createElement, Fragment } from "@wordpress/element";
|
|
|
3
3
|
/**
|
|
4
4
|
* Internal dependencies
|
|
5
5
|
*/
|
|
6
|
-
import { createUpgradedEmbedBlock, getClassNames, fallback, getEmbedInfoByProvider, getMergedAttributesWithPreview } from './util';
|
|
6
|
+
import { createUpgradedEmbedBlock, getClassNames, removeAspectRatioClasses, fallback, getEmbedInfoByProvider, getMergedAttributesWithPreview } from './util';
|
|
7
7
|
import EmbedControls from './embed-controls';
|
|
8
8
|
import { embedContentIcon } from './icons';
|
|
9
9
|
import EmbedLoading from './embed-loading';
|
|
@@ -94,14 +94,10 @@ const EmbedEdit = props => {
|
|
|
94
94
|
/**
|
|
95
95
|
* Returns the attributes derived from the preview, merged with the current attributes.
|
|
96
96
|
*
|
|
97
|
-
* @param {boolean} ignorePreviousClassName Determines if the previous className attribute should be ignored when merging.
|
|
98
97
|
* @return {Object} Merged attributes.
|
|
99
98
|
*/
|
|
100
99
|
|
|
101
|
-
const getMergedAttributes =
|
|
102
|
-
let ignorePreviousClassName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
103
|
-
return getMergedAttributesWithPreview(attributes, preview, title, responsive, ignorePreviousClassName);
|
|
104
|
-
};
|
|
100
|
+
const getMergedAttributes = () => getMergedAttributesWithPreview(attributes, preview, title, responsive);
|
|
105
101
|
|
|
106
102
|
const toggleResponsive = () => {
|
|
107
103
|
const {
|
|
@@ -131,18 +127,17 @@ const EmbedEdit = props => {
|
|
|
131
127
|
setAttributes({
|
|
132
128
|
url: newURL
|
|
133
129
|
});
|
|
134
|
-
}, [preview === null || preview === void 0 ? void 0 : preview.html, attributesUrl]); // Handle incoming preview.
|
|
130
|
+
}, [preview === null || preview === void 0 ? void 0 : preview.html, attributesUrl, cannotEmbed, fetching]); // Handle incoming preview.
|
|
135
131
|
|
|
136
132
|
useEffect(() => {
|
|
137
133
|
if (preview && !isEditingURL) {
|
|
138
|
-
// When obtaining an incoming preview,
|
|
139
|
-
//
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
setAttributes(getMergedAttributes(true));
|
|
134
|
+
// When obtaining an incoming preview,
|
|
135
|
+
// we set the attributes derived from the preview data.
|
|
136
|
+
const mergedAttributes = getMergedAttributes();
|
|
137
|
+
setAttributes(mergedAttributes);
|
|
143
138
|
|
|
144
139
|
if (onReplace) {
|
|
145
|
-
const upgradedBlock = createUpgradedEmbedBlock(props,
|
|
140
|
+
const upgradedBlock = createUpgradedEmbedBlock(props, mergedAttributes);
|
|
146
141
|
|
|
147
142
|
if (upgradedBlock) {
|
|
148
143
|
onReplace(upgradedBlock);
|
|
@@ -169,11 +164,15 @@ const EmbedEdit = props => {
|
|
|
169
164
|
onSubmit: event => {
|
|
170
165
|
if (event) {
|
|
171
166
|
event.preventDefault();
|
|
172
|
-
}
|
|
167
|
+
} // If the embed URL was changed, we need to reset the aspect ratio class.
|
|
168
|
+
// To do this we have to remove the existing ratio class so it can be recalculated.
|
|
169
|
+
|
|
173
170
|
|
|
171
|
+
const blockClass = removeAspectRatioClasses(attributes.className);
|
|
174
172
|
setIsEditingURL(false);
|
|
175
173
|
setAttributes({
|
|
176
|
-
url
|
|
174
|
+
url,
|
|
175
|
+
className: blockClass
|
|
177
176
|
});
|
|
178
177
|
},
|
|
179
178
|
value: url,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/embed/edit.js"],"names":["createUpgradedEmbedBlock","getClassNames","fallback","getEmbedInfoByProvider","getMergedAttributesWithPreview","EmbedControls","embedContentIcon","EmbedLoading","EmbedPlaceholder","EmbedPreview","classnames","__","_x","sprintf","useState","useEffect","useDispatch","useSelect","useBlockProps","store","coreStore","View","EmbedEdit","props","attributes","providerNameSlug","previewable","responsive","url","attributesUrl","isSelected","onReplace","setAttributes","insertBlocksAfter","onFocus","defaultEmbedInfo","title","icon","setURL","isEditingURL","setIsEditingURL","invalidateResolution","preview","fetching","themeSupportsResponsive","cannotEmbed","select","getEmbedPreview","isPreviewEmbedFallback","isRequestingEmbedPreview","getThemeSupports","embedPreview","previewIsFallback","badEmbedProvider","html","type","undefined","wordpressCantEmbed","data","status","validPreview","getMergedAttributes","ignorePreviousClassName","toggleResponsive","allowResponsive","className","newAllowResponsive","newURL","replace","upgradedBlock","blockProps","label","showEmbedPlaceholder","event","preventDefault","target","value","caption","classFromPreview"],"mappings":";;AAAA;AACA;AACA;AACA,SACCA,wBADD,EAECC,aAFD,EAGCC,QAHD,EAICC,sBAJD,EAKCC,8BALD,QAMO,QANP;AAOA,OAAOC,aAAP,MAA0B,kBAA1B;AACA,SAASC,gBAAT,QAAiC,SAAjC;AACA,OAAOC,YAAP,MAAyB,iBAAzB;AACA,OAAOC,gBAAP,MAA6B,qBAA7B;AACA,OAAOC,YAAP,MAAyB,iBAAzB;AAEA;AACA;AACA;;AACA,OAAOC,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,EAAT,EAAaC,EAAb,EAAiBC,OAAjB,QAAgC,iBAAhC;AACA,SAASC,QAAT,EAAmBC,SAAnB,QAAoC,oBAApC;AACA,SAASC,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SAASC,aAAT,QAA8B,yBAA9B;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AACA,SAASC,IAAT,QAAqB,uBAArB;;AAEA,MAAMC,SAAS,GAAKC,KAAF,IAAa;AAC9B,QAAM;AACLC,IAAAA,UAAU,EAAE;AACXC,MAAAA,gBADW;AAEXC,MAAAA,WAFW;AAGXC,MAAAA,UAHW;AAIXC,MAAAA,GAAG,EAAEC;AAJM,KADP;AAOLL,IAAAA,UAPK;AAQLM,IAAAA,UARK;AASLC,IAAAA,SATK;AAULC,IAAAA,aAVK;AAWLC,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AAe,CAAE,IAAF;AAN7C,IADD,EASC,cAAC,IAAD,EAAW8B,UAAX,EACC,cAAC,YAAD;AACC,IAAA,OAAO,EAAG5B,OADX;AAEC,IAAA,WAAW,EAAGhB,WAFf;AAGC,IAAA,SAAS,EAAGuC,SAHb;AAIC,IAAA,GAAG,EAAGrC,GAJP;AAKC,IAAA,IAAI,EAAG2B,IALR;AAMC,IAAA,OAAO,EAAGsB,OANX;AAOC,IAAA,eAAe,EAAKD,KAAF,IACjB5C,aAAa,CAAE;AAAE6C,MAAAA,OAAO,EAAED;AAAX,KAAF,CARf;AAUC,IAAA,UAAU,EAAG9C,UAVd;AAWC,IAAA,IAAI,EAAGO,IAXR;AAYC,IAAA,KAAK,EAAGkC,KAZT;AAaC,IAAA,iBAAiB,EAAGtC;AAbrB,IADD,CATD,CADD;AA6BA,CA3ND;;AA6NA,eAAeX,SAAf","sourcesContent":["/**\n * Internal dependencies\n */\nimport {\n\tcreateUpgradedEmbedBlock,\n\tgetClassNames,\n\tfallback,\n\tgetEmbedInfoByProvider,\n\tgetMergedAttributesWithPreview,\n} from './util';\nimport EmbedControls from './embed-controls';\nimport { embedContentIcon } from './icons';\nimport EmbedLoading from './embed-loading';\nimport EmbedPlaceholder from './embed-placeholder';\nimport EmbedPreview from './embed-preview';\n\n/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { useState, useEffect } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { View } from '@wordpress/primitives';\n\nconst EmbedEdit = ( props ) => {\n\tconst {\n\t\tattributes: {\n\t\t\tproviderNameSlug,\n\t\t\tpreviewable,\n\t\t\tresponsive,\n\t\t\turl: attributesUrl,\n\t\t},\n\t\tattributes,\n\t\tisSelected,\n\t\tonReplace,\n\t\tsetAttributes,\n\t\tinsertBlocksAfter,\n\t\tonFocus,\n\t} = props;\n\n\tconst defaultEmbedInfo = {\n\t\ttitle: _x( 'Embed', 'block title' ),\n\t\ticon: embedContentIcon,\n\t};\n\tconst { icon, title } =\n\t\tgetEmbedInfoByProvider( providerNameSlug ) || defaultEmbedInfo;\n\n\tconst [ url, setURL ] = useState( attributesUrl );\n\tconst [ isEditingURL, setIsEditingURL ] = useState( false );\n\tconst { invalidateResolution } = useDispatch( coreStore );\n\n\tconst { preview, fetching, themeSupportsResponsive, cannotEmbed } =\n\t\tuseSelect(\n\t\t\t( select ) => {\n\t\t\t\tconst {\n\t\t\t\t\tgetEmbedPreview,\n\t\t\t\t\tisPreviewEmbedFallback,\n\t\t\t\t\tisRequestingEmbedPreview,\n\t\t\t\t\tgetThemeSupports,\n\t\t\t\t} = select( coreStore );\n\t\t\t\tif ( ! attributesUrl ) {\n\t\t\t\t\treturn { fetching: false, cannotEmbed: false };\n\t\t\t\t}\n\n\t\t\t\tconst embedPreview = getEmbedPreview( attributesUrl );\n\t\t\t\tconst previewIsFallback =\n\t\t\t\t\tisPreviewEmbedFallback( attributesUrl );\n\n\t\t\t\t// The external oEmbed provider does not exist. We got no type info and no html.\n\t\t\t\tconst badEmbedProvider =\n\t\t\t\t\tembedPreview?.html === false &&\n\t\t\t\t\tembedPreview?.type === undefined;\n\t\t\t\t// Some WordPress URLs that can't be embedded will cause the API to return\n\t\t\t\t// a valid JSON response with no HTML and `data.status` set to 404, rather\n\t\t\t\t// than generating a fallback response as other embeds do.\n\t\t\t\tconst wordpressCantEmbed = embedPreview?.data?.status === 404;\n\t\t\t\tconst validPreview =\n\t\t\t\t\t!! embedPreview &&\n\t\t\t\t\t! badEmbedProvider &&\n\t\t\t\t\t! wordpressCantEmbed;\n\t\t\t\treturn {\n\t\t\t\t\tpreview: validPreview ? embedPreview : undefined,\n\t\t\t\t\tfetching: isRequestingEmbedPreview( attributesUrl ),\n\t\t\t\t\tthemeSupportsResponsive:\n\t\t\t\t\t\tgetThemeSupports()[ 'responsive-embeds' ],\n\t\t\t\t\tcannotEmbed: ! validPreview || previewIsFallback,\n\t\t\t\t};\n\t\t\t},\n\t\t\t[ attributesUrl ]\n\t\t);\n\n\t/**\n\t * Returns the attributes derived from the preview, merged with the current attributes.\n\t *\n\t * @param {boolean} ignorePreviousClassName Determines if the previous className attribute should be ignored when merging.\n\t * @return {Object} Merged attributes.\n\t */\n\tconst getMergedAttributes = ( ignorePreviousClassName = false ) =>\n\t\tgetMergedAttributesWithPreview(\n\t\t\tattributes,\n\t\t\tpreview,\n\t\t\ttitle,\n\t\t\tresponsive,\n\t\t\tignorePreviousClassName\n\t\t);\n\n\tconst toggleResponsive = () => {\n\t\tconst { allowResponsive, className } = attributes;\n\t\tconst { html } = preview;\n\t\tconst newAllowResponsive = ! allowResponsive;\n\n\t\tsetAttributes( {\n\t\t\tallowResponsive: newAllowResponsive,\n\t\t\tclassName: getClassNames(\n\t\t\t\thtml,\n\t\t\t\tclassName,\n\t\t\t\tresponsive && newAllowResponsive\n\t\t\t),\n\t\t} );\n\t};\n\n\tuseEffect( () => {\n\t\tif ( ! preview?.html || ! cannotEmbed || fetching ) {\n\t\t\treturn;\n\t\t}\n\t\t// At this stage, we're not fetching the preview and know it can't be embedded,\n\t\t// so try removing any trailing slash, and resubmit.\n\t\tconst newURL = attributesUrl.replace( /\\/$/, '' );\n\t\tsetURL( newURL );\n\t\tsetIsEditingURL( false );\n\t\tsetAttributes( { url: newURL } );\n\t}, [ preview?.html, attributesUrl ] );\n\n\t// Handle incoming preview.\n\tuseEffect( () => {\n\t\tif ( preview && ! isEditingURL ) {\n\t\t\t// When obtaining an incoming preview, we set the attributes derived from\n\t\t\t// the preview data. In this case when getting the merged attributes,\n\t\t\t// we ignore the previous classname because it might not match the expected\n\t\t\t// classes by the new preview.\n\t\t\tsetAttributes( getMergedAttributes( true ) );\n\n\t\t\tif ( onReplace ) {\n\t\t\t\tconst upgradedBlock = createUpgradedEmbedBlock(\n\t\t\t\t\tprops,\n\t\t\t\t\tgetMergedAttributes()\n\t\t\t\t);\n\n\t\t\t\tif ( upgradedBlock ) {\n\t\t\t\t\tonReplace( upgradedBlock );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}, [ preview, isEditingURL ] );\n\n\tconst blockProps = useBlockProps();\n\n\tif ( fetching ) {\n\t\treturn (\n\t\t\t<View { ...blockProps }>\n\t\t\t\t<EmbedLoading />\n\t\t\t</View>\n\t\t);\n\t}\n\n\t// translators: %s: type of embed e.g: \"YouTube\", \"Twitter\", etc. \"Embed\" is used when no specific type exists\n\tconst label = sprintf( __( '%s URL' ), title );\n\n\t// No preview, or we can't embed the current URL, or we've clicked the edit button.\n\tconst showEmbedPlaceholder = ! preview || cannotEmbed || isEditingURL;\n\n\tif ( showEmbedPlaceholder ) {\n\t\treturn (\n\t\t\t<View { ...blockProps }>\n\t\t\t\t<EmbedPlaceholder\n\t\t\t\t\ticon={ icon }\n\t\t\t\t\tlabel={ label }\n\t\t\t\t\tonFocus={ onFocus }\n\t\t\t\t\tonSubmit={ ( event ) => {\n\t\t\t\t\t\tif ( event ) {\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tsetIsEditingURL( false );\n\t\t\t\t\t\tsetAttributes( { url } );\n\t\t\t\t\t} }\n\t\t\t\t\tvalue={ url }\n\t\t\t\t\tcannotEmbed={ cannotEmbed }\n\t\t\t\t\tonChange={ ( event ) => setURL( event.target.value ) }\n\t\t\t\t\tfallback={ () => fallback( url, onReplace ) }\n\t\t\t\t\ttryAgain={ () => {\n\t\t\t\t\t\tinvalidateResolution( 'getEmbedPreview', [ url ] );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t</View>\n\t\t);\n\t}\n\n\t// Even though we set attributes that get derived from the preview,\n\t// we don't access them directly because for the initial render,\n\t// the `setAttributes` call will not have taken effect. If we're\n\t// rendering responsive content, setting the responsive classes\n\t// after the preview has been rendered can result in unwanted\n\t// clipping or scrollbars. The `getAttributesFromPreview` function\n\t// that `getMergedAttributes` uses is memoized so that we're not\n\t// calculating them on every render.\n\tconst {\n\t\tcaption,\n\t\ttype,\n\t\tallowResponsive,\n\t\tclassName: classFromPreview,\n\t} = getMergedAttributes();\n\tconst className = classnames( classFromPreview, props.className );\n\n\treturn (\n\t\t<>\n\t\t\t<EmbedControls\n\t\t\t\tshowEditButton={ preview && ! cannotEmbed }\n\t\t\t\tthemeSupportsResponsive={ themeSupportsResponsive }\n\t\t\t\tblockSupportsResponsive={ responsive }\n\t\t\t\tallowResponsive={ allowResponsive }\n\t\t\t\ttoggleResponsive={ toggleResponsive }\n\t\t\t\tswitchBackToURLInput={ () => setIsEditingURL( true ) }\n\t\t\t/>\n\t\t\t<View { ...blockProps }>\n\t\t\t\t<EmbedPreview\n\t\t\t\t\tpreview={ preview }\n\t\t\t\t\tpreviewable={ previewable }\n\t\t\t\t\tclassName={ className }\n\t\t\t\t\turl={ url }\n\t\t\t\t\ttype={ type }\n\t\t\t\t\tcaption={ caption }\n\t\t\t\t\tonCaptionChange={ ( value ) =>\n\t\t\t\t\t\tsetAttributes( { caption: value } )\n\t\t\t\t\t}\n\t\t\t\t\tisSelected={ isSelected }\n\t\t\t\t\ticon={ icon }\n\t\t\t\t\tlabel={ label }\n\t\t\t\t\tinsertBlocksAfter={ insertBlocksAfter }\n\t\t\t\t/>\n\t\t\t</View>\n\t\t</>\n\t);\n};\n\nexport default EmbedEdit;\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/embed/edit.js"],"names":["createUpgradedEmbedBlock","getClassNames","removeAspectRatioClasses","fallback","getEmbedInfoByProvider","getMergedAttributesWithPreview","EmbedControls","embedContentIcon","EmbedLoading","EmbedPlaceholder","EmbedPreview","classnames","__","_x","sprintf","useState","useEffect","useDispatch","useSelect","useBlockProps","store","coreStore","View","EmbedEdit","props","attributes","providerNameSlug","previewable","responsive","url","attributesUrl","isSelected","onReplace","setAttributes","insertBlocksAfter","onFocus","defaultEmbedInfo","title","icon","setURL","isEditingURL","setIsEditingURL","invalidateResolution","preview","fetching","themeSupportsResponsive","cannotEmbed","select","getEmbedPreview","isPreviewEmbedFallback","isRequestingEmbedPreview","getThemeSupports","embedPreview","previewIsFallback","badEmbedProvider","html","type","undefined","wordpressCantEmbed","data","status","validPreview","getMergedAttributes","toggleResponsive","allowResponsive","className","newAllowResponsive","newURL","replace","mergedAttributes","upgradedBlock","blockProps","label","showEmbedPlaceholder","event","preventDefault","blockClass","target","value","caption","classFromPreview"],"mappings":";;AAAA;AACA;AACA;AACA,SACCA,wBADD,EAECC,aAFD,EAGCC,wBAHD,EAICC,QAJD,EAKCC,sBALD,EAMCC,8BAND,QAOO,QAPP;AAQA,OAAOC,aAAP,MAA0B,kBAA1B;AACA,SAASC,gBAAT,QAAiC,SAAjC;AACA,OAAOC,YAAP,MAAyB,iBAAzB;AACA,OAAOC,gBAAP,MAA6B,qBAA7B;AACA,OAAOC,YAAP,MAAyB,iBAAzB;AAEA;AACA;AACA;;AACA,OAAOC,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,EAAT,EAAaC,EAAb,EAAiBC,OAAjB,QAAgC,iBAAhC;AACA,SAASC,QAAT,EAAmBC,SAAnB,QAAoC,oBAApC;AACA,SAASC,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SAASC,aAAT,QAA8B,yBAA9B;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AACA,SAASC,IAAT,QAAqB,uBAArB;;AAEA,MAAMC,SAAS,GAAKC,KAAF,IAAa;AAC9B,QAAM;AACLC,IAAAA,UAAU,EAAE;AACXC,MAAAA,gBADW;AAEXC,MAAAA,WAFW;AAGXC,MAAAA,UAHW;AAIXC,MAAAA,GAAG,EAAEC;AAJM,KADP;AAOLL,IAAAA,UAPK;AAQLM,IAAAA,UARK;AASLC,IAAAA,SATK;AAULC,IAAAA,aAVK;AAWLC,IAAAA,iBAXK;AAYLC,IAAAA;AAZK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AAKC,IAAA,gBAAgB,EAAGD,gBALpB;AAMC,IAAA,oBAAoB,EAAG,MAAMtB,eAAe,CAAE,IAAF;AAN7C,IADD,EASC,cAAC,IAAD,EAAW8B,UAAX,EACC,cAAC,YAAD;AACC,IAAA,OAAO,EAAG5B,OADX;AAEC,IAAA,WAAW,EAAGhB,WAFf;AAGC,IAAA,SAAS,EAAGsC,SAHb;AAIC,IAAA,GAAG,EAAGpC,GAJP;AAKC,IAAA,IAAI,EAAG2B,IALR;AAMC,IAAA,OAAO,EAAGuB,OANX;AAOC,IAAA,eAAe,EAAKD,KAAF,IACjB7C,aAAa,CAAE;AAAE8C,MAAAA,OAAO,EAAED;AAAX,KAAF,CARf;AAUC,IAAA,UAAU,EAAG/C,UAVd;AAWC,IAAA,IAAI,EAAGO,IAXR;AAYC,IAAA,KAAK,EAAGkC,KAZT;AAaC,IAAA,iBAAiB,EAAGtC;AAbrB,IADD,CATD,CADD;AA6BA,CA9ND;;AAgOA,eAAeX,SAAf","sourcesContent":["/**\n * Internal dependencies\n */\nimport {\n\tcreateUpgradedEmbedBlock,\n\tgetClassNames,\n\tremoveAspectRatioClasses,\n\tfallback,\n\tgetEmbedInfoByProvider,\n\tgetMergedAttributesWithPreview,\n} from './util';\nimport EmbedControls from './embed-controls';\nimport { embedContentIcon } from './icons';\nimport EmbedLoading from './embed-loading';\nimport EmbedPlaceholder from './embed-placeholder';\nimport EmbedPreview from './embed-preview';\n\n/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { useState, useEffect } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { View } from '@wordpress/primitives';\n\nconst EmbedEdit = ( props ) => {\n\tconst {\n\t\tattributes: {\n\t\t\tproviderNameSlug,\n\t\t\tpreviewable,\n\t\t\tresponsive,\n\t\t\turl: attributesUrl,\n\t\t},\n\t\tattributes,\n\t\tisSelected,\n\t\tonReplace,\n\t\tsetAttributes,\n\t\tinsertBlocksAfter,\n\t\tonFocus,\n\t} = props;\n\n\tconst defaultEmbedInfo = {\n\t\ttitle: _x( 'Embed', 'block title' ),\n\t\ticon: embedContentIcon,\n\t};\n\tconst { icon, title } =\n\t\tgetEmbedInfoByProvider( providerNameSlug ) || defaultEmbedInfo;\n\n\tconst [ url, setURL ] = useState( attributesUrl );\n\tconst [ isEditingURL, setIsEditingURL ] = useState( false );\n\tconst { invalidateResolution } = useDispatch( coreStore );\n\n\tconst { preview, fetching, themeSupportsResponsive, cannotEmbed } =\n\t\tuseSelect(\n\t\t\t( select ) => {\n\t\t\t\tconst {\n\t\t\t\t\tgetEmbedPreview,\n\t\t\t\t\tisPreviewEmbedFallback,\n\t\t\t\t\tisRequestingEmbedPreview,\n\t\t\t\t\tgetThemeSupports,\n\t\t\t\t} = select( coreStore );\n\t\t\t\tif ( ! attributesUrl ) {\n\t\t\t\t\treturn { fetching: false, cannotEmbed: false };\n\t\t\t\t}\n\n\t\t\t\tconst embedPreview = getEmbedPreview( attributesUrl );\n\t\t\t\tconst previewIsFallback =\n\t\t\t\t\tisPreviewEmbedFallback( attributesUrl );\n\n\t\t\t\t// The external oEmbed provider does not exist. We got no type info and no html.\n\t\t\t\tconst badEmbedProvider =\n\t\t\t\t\tembedPreview?.html === false &&\n\t\t\t\t\tembedPreview?.type === undefined;\n\t\t\t\t// Some WordPress URLs that can't be embedded will cause the API to return\n\t\t\t\t// a valid JSON response with no HTML and `data.status` set to 404, rather\n\t\t\t\t// than generating a fallback response as other embeds do.\n\t\t\t\tconst wordpressCantEmbed = embedPreview?.data?.status === 404;\n\t\t\t\tconst validPreview =\n\t\t\t\t\t!! embedPreview &&\n\t\t\t\t\t! badEmbedProvider &&\n\t\t\t\t\t! wordpressCantEmbed;\n\t\t\t\treturn {\n\t\t\t\t\tpreview: validPreview ? embedPreview : undefined,\n\t\t\t\t\tfetching: isRequestingEmbedPreview( attributesUrl ),\n\t\t\t\t\tthemeSupportsResponsive:\n\t\t\t\t\t\tgetThemeSupports()[ 'responsive-embeds' ],\n\t\t\t\t\tcannotEmbed: ! validPreview || previewIsFallback,\n\t\t\t\t};\n\t\t\t},\n\t\t\t[ attributesUrl ]\n\t\t);\n\n\t/**\n\t * Returns the attributes derived from the preview, merged with the current attributes.\n\t *\n\t * @return {Object} Merged attributes.\n\t */\n\tconst getMergedAttributes = () =>\n\t\tgetMergedAttributesWithPreview(\n\t\t\tattributes,\n\t\t\tpreview,\n\t\t\ttitle,\n\t\t\tresponsive\n\t\t);\n\n\tconst toggleResponsive = () => {\n\t\tconst { allowResponsive, className } = attributes;\n\t\tconst { html } = preview;\n\t\tconst newAllowResponsive = ! allowResponsive;\n\n\t\tsetAttributes( {\n\t\t\tallowResponsive: newAllowResponsive,\n\t\t\tclassName: getClassNames(\n\t\t\t\thtml,\n\t\t\t\tclassName,\n\t\t\t\tresponsive && newAllowResponsive\n\t\t\t),\n\t\t} );\n\t};\n\n\tuseEffect( () => {\n\t\tif ( ! preview?.html || ! cannotEmbed || fetching ) {\n\t\t\treturn;\n\t\t}\n\t\t// At this stage, we're not fetching the preview and know it can't be embedded,\n\t\t// so try removing any trailing slash, and resubmit.\n\t\tconst newURL = attributesUrl.replace( /\\/$/, '' );\n\t\tsetURL( newURL );\n\t\tsetIsEditingURL( false );\n\t\tsetAttributes( { url: newURL } );\n\t}, [ preview?.html, attributesUrl, cannotEmbed, fetching ] );\n\n\t// Handle incoming preview.\n\tuseEffect( () => {\n\t\tif ( preview && ! isEditingURL ) {\n\t\t\t// When obtaining an incoming preview,\n\t\t\t// we set the attributes derived from the preview data.\n\t\t\tconst mergedAttributes = getMergedAttributes();\n\t\t\tsetAttributes( mergedAttributes );\n\n\t\t\tif ( onReplace ) {\n\t\t\t\tconst upgradedBlock = createUpgradedEmbedBlock(\n\t\t\t\t\tprops,\n\t\t\t\t\tmergedAttributes\n\t\t\t\t);\n\n\t\t\t\tif ( upgradedBlock ) {\n\t\t\t\t\tonReplace( upgradedBlock );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}, [ preview, isEditingURL ] );\n\n\tconst blockProps = useBlockProps();\n\n\tif ( fetching ) {\n\t\treturn (\n\t\t\t<View { ...blockProps }>\n\t\t\t\t<EmbedLoading />\n\t\t\t</View>\n\t\t);\n\t}\n\n\t// translators: %s: type of embed e.g: \"YouTube\", \"Twitter\", etc. \"Embed\" is used when no specific type exists\n\tconst label = sprintf( __( '%s URL' ), title );\n\n\t// No preview, or we can't embed the current URL, or we've clicked the edit button.\n\tconst showEmbedPlaceholder = ! preview || cannotEmbed || isEditingURL;\n\n\tif ( showEmbedPlaceholder ) {\n\t\treturn (\n\t\t\t<View { ...blockProps }>\n\t\t\t\t<EmbedPlaceholder\n\t\t\t\t\ticon={ icon }\n\t\t\t\t\tlabel={ label }\n\t\t\t\t\tonFocus={ onFocus }\n\t\t\t\t\tonSubmit={ ( event ) => {\n\t\t\t\t\t\tif ( event ) {\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// If the embed URL was changed, we need to reset the aspect ratio class.\n\t\t\t\t\t\t// To do this we have to remove the existing ratio class so it can be recalculated.\n\t\t\t\t\t\tconst blockClass = removeAspectRatioClasses(\n\t\t\t\t\t\t\tattributes.className\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tsetIsEditingURL( false );\n\t\t\t\t\t\tsetAttributes( { url, className: blockClass } );\n\t\t\t\t\t} }\n\t\t\t\t\tvalue={ url }\n\t\t\t\t\tcannotEmbed={ cannotEmbed }\n\t\t\t\t\tonChange={ ( event ) => setURL( event.target.value ) }\n\t\t\t\t\tfallback={ () => fallback( url, onReplace ) }\n\t\t\t\t\ttryAgain={ () => {\n\t\t\t\t\t\tinvalidateResolution( 'getEmbedPreview', [ url ] );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t</View>\n\t\t);\n\t}\n\n\t// Even though we set attributes that get derived from the preview,\n\t// we don't access them directly because for the initial render,\n\t// the `setAttributes` call will not have taken effect. If we're\n\t// rendering responsive content, setting the responsive classes\n\t// after the preview has been rendered can result in unwanted\n\t// clipping or scrollbars. The `getAttributesFromPreview` function\n\t// that `getMergedAttributes` uses is memoized so that we're not\n\t// calculating them on every render.\n\tconst {\n\t\tcaption,\n\t\ttype,\n\t\tallowResponsive,\n\t\tclassName: classFromPreview,\n\t} = getMergedAttributes();\n\tconst className = classnames( classFromPreview, props.className );\n\n\treturn (\n\t\t<>\n\t\t\t<EmbedControls\n\t\t\t\tshowEditButton={ preview && ! cannotEmbed }\n\t\t\t\tthemeSupportsResponsive={ themeSupportsResponsive }\n\t\t\t\tblockSupportsResponsive={ responsive }\n\t\t\t\tallowResponsive={ allowResponsive }\n\t\t\t\ttoggleResponsive={ toggleResponsive }\n\t\t\t\tswitchBackToURLInput={ () => setIsEditingURL( true ) }\n\t\t\t/>\n\t\t\t<View { ...blockProps }>\n\t\t\t\t<EmbedPreview\n\t\t\t\t\tpreview={ preview }\n\t\t\t\t\tpreviewable={ previewable }\n\t\t\t\t\tclassName={ className }\n\t\t\t\t\turl={ url }\n\t\t\t\t\ttype={ type }\n\t\t\t\t\tcaption={ caption }\n\t\t\t\t\tonCaptionChange={ ( value ) =>\n\t\t\t\t\t\tsetAttributes( { caption: value } )\n\t\t\t\t\t}\n\t\t\t\t\tisSelected={ isSelected }\n\t\t\t\t\ticon={ icon }\n\t\t\t\t\tlabel={ label }\n\t\t\t\t\tinsertBlocksAfter={ insertBlocksAfter }\n\t\t\t\t/>\n\t\t\t</View>\n\t\t</>\n\t);\n};\n\nexport default EmbedEdit;\n"]}
|
|
@@ -3,7 +3,7 @@ import { createElement, Fragment } from "@wordpress/element";
|
|
|
3
3
|
/**
|
|
4
4
|
* Internal dependencies
|
|
5
5
|
*/
|
|
6
|
-
import { createUpgradedEmbedBlock, getClassNames, fallback, getEmbedInfoByProvider, getMergedAttributesWithPreview } from './util';
|
|
6
|
+
import { createUpgradedEmbedBlock, getClassNames, removeAspectRatioClasses, fallback, getEmbedInfoByProvider, getMergedAttributesWithPreview } from './util';
|
|
7
7
|
import EmbedControls from './embed-controls';
|
|
8
8
|
import { embedContentIcon } from './icons';
|
|
9
9
|
import EmbedLoading from './embed-loading';
|
|
@@ -109,14 +109,10 @@ const EmbedEdit = props => {
|
|
|
109
109
|
/**
|
|
110
110
|
* Returns the attributes derived from the preview, merged with the current attributes.
|
|
111
111
|
*
|
|
112
|
-
* @param {boolean} ignorePreviousClassName Determines if the previous className attribute should be ignored when merging.
|
|
113
112
|
* @return {Object} Merged attributes.
|
|
114
113
|
*/
|
|
115
114
|
|
|
116
|
-
const getMergedAttributes =
|
|
117
|
-
let ignorePreviousClassName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
118
|
-
return getMergedAttributesWithPreview(attributes, preview, title, responsive, ignorePreviousClassName);
|
|
119
|
-
};
|
|
115
|
+
const getMergedAttributes = () => getMergedAttributesWithPreview(attributes, preview, title, responsive);
|
|
120
116
|
|
|
121
117
|
const toggleResponsive = () => {
|
|
122
118
|
const {
|
|
@@ -145,18 +141,17 @@ const EmbedEdit = props => {
|
|
|
145
141
|
setAttributes({
|
|
146
142
|
url: newURL
|
|
147
143
|
});
|
|
148
|
-
}, [preview === null || preview === void 0 ? void 0 : preview.html, url]); // Handle incoming preview.
|
|
144
|
+
}, [preview === null || preview === void 0 ? void 0 : preview.html, url, cannotEmbed, fetching]); // Handle incoming preview.
|
|
149
145
|
|
|
150
146
|
useEffect(() => {
|
|
151
147
|
if (preview && !isEditingURL) {
|
|
152
|
-
// When obtaining an incoming preview,
|
|
153
|
-
//
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
setAttributes(getMergedAttributes(true));
|
|
148
|
+
// When obtaining an incoming preview,
|
|
149
|
+
// we set the attributes derived from the preview data.
|
|
150
|
+
const mergedAttributes = getMergedAttributes();
|
|
151
|
+
setAttributes(mergedAttributes);
|
|
157
152
|
|
|
158
153
|
if (onReplace) {
|
|
159
|
-
const upgradedBlock = createUpgradedEmbedBlock(props,
|
|
154
|
+
const upgradedBlock = createUpgradedEmbedBlock(props, mergedAttributes);
|
|
160
155
|
|
|
161
156
|
if (upgradedBlock) {
|
|
162
157
|
onReplace(upgradedBlock);
|
|
@@ -166,14 +161,23 @@ const EmbedEdit = props => {
|
|
|
166
161
|
}, [preview, isEditingURL]);
|
|
167
162
|
useEffect(() => setShowEmbedBottomSheet(isEditingURL), [isEditingURL]);
|
|
168
163
|
const onEditURL = useCallback(value => {
|
|
169
|
-
//
|
|
164
|
+
// If the embed URL was changed, we need to reset the aspect ratio class.
|
|
165
|
+
// To do this we have to remove the existing ratio class so it can be recalculated.
|
|
166
|
+
if (attributes.url !== value) {
|
|
167
|
+
const blockClass = removeAspectRatioClasses(attributes.className);
|
|
168
|
+
setAttributes({
|
|
169
|
+
className: blockClass
|
|
170
|
+
});
|
|
171
|
+
} // The order of the following calls is important, we need to update the URL attribute before changing `isEditingURL`,
|
|
170
172
|
// otherwise the side-effect that potentially replaces the block when updating the local state won't use the new URL
|
|
171
173
|
// for creating the new block.
|
|
174
|
+
|
|
175
|
+
|
|
172
176
|
setAttributes({
|
|
173
177
|
url: value
|
|
174
178
|
});
|
|
175
179
|
setIsEditingURL(false);
|
|
176
|
-
}, []);
|
|
180
|
+
}, [attributes, setAttributes]);
|
|
177
181
|
const blockProps = useBlockProps();
|
|
178
182
|
|
|
179
183
|
if (fetching) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/embed/edit.native.js"],"names":["createUpgradedEmbedBlock","getClassNames","fallback","getEmbedInfoByProvider","getMergedAttributesWithPreview","EmbedControls","embedContentIcon","EmbedLoading","EmbedPlaceholder","EmbedPreview","EmbedLinkSettings","classnames","_x","useCallback","useState","useEffect","useDispatch","useSelect","useBlockProps","store","blockEditorStore","coreStore","View","PREVIEWABLE_PROVIDERS","NOT_PREVIEWABLE_WP_EMBED_PROVIDERS","WP_EMBED_TYPE","EmbedEdit","props","attributes","align","providerNameSlug","previewable","responsive","url","isSelected","onReplace","setAttributes","insertBlocksAfter","onFocus","clientId","defaultEmbedInfo","title","icon","embedInfoByProvider","wasBlockJustInserted","select","isEditingURL","setIsEditingURL","showEmbedBottomSheet","setShowEmbedBottomSheet","invalidateResolution","preview","fetching","themeSupportsResponsive","cannotEmbed","getEmbedPreview","hasFinishedResolution","isPreviewEmbedFallback","getThemeSupports","embedPreview","hasResolvedEmbedPreview","previewIsFallback","badEmbedProvider","html","type","undefined","wordpressCantEmbed","code","validPreview","getMergedAttributes","ignorePreviousClassName","toggleResponsive","allowResponsive","className","newAllowResponsive","newURL","replace","upgradedBlock","onEditURL","value","blockProps","showEmbedPlaceholder","classFromPreview","isProviderPreviewable","includes","linkLabel","event"],"mappings":";;AAAA;AACA;AACA;AACA,SACCA,wBADD,EAECC,aAFD,EAGCC,QAHD,EAICC,sBAJD,EAKCC,8BALD,QAMO,QANP;AAOA,OAAOC,aAAP,MAA0B,kBAA1B;AACA,SAASC,gBAAT,QAAiC,SAAjC;AACA,OAAOC,YAAP,MAAyB,iBAAzB;AACA,OAAOC,gBAAP,MAA6B,qBAA7B;AACA,OAAOC,YAAP,MAAyB,iBAAzB;AACA,OAAOC,iBAAP,MAA8B,uBAA9B;AAEA;AACA;AACA;;AACA,OAAOC,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,WAAT,EAAsBC,QAAtB,EAAgCC,SAAhC,QAAiD,oBAAjD;AACA,SAASC,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SACCC,aADD,EAECC,KAAK,IAAIC,gBAFV,QAGO,yBAHP;AAIA,SAASD,KAAK,IAAIE,SAAlB,QAAmC,sBAAnC;AACA,SAASC,IAAT,QAAqB,uBAArB,C,CAEA;AACA;;AACA,MAAMC,qBAAqB,GAAG,CAAE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AA,UAAU,EAAGH,UANd;AAOC,IAAA,KAAK,EAAGO,KAPT;AAQC,IAAA,OAAO,EAAGH,OARX;AASC,IAAA,OAAO,EAAGa,OATX;AAUC,IAAA,qBAAqB,EAAGgC,qBAVzB;AAWC,IAAA,WAAW,EAAGpD,WAXf;AAYC,IAAA,IAAI,EAAGiC,IAZR;AAaC,IAAA,GAAG,EAAG/B,GAbP;AAcC,IAAA,kBAAkB,EAAG,CAAEU;AAdxB,IADD,CAVD,CA1BF,EAwDC,cAAC,iBAAD,CACC;AADD;AAEC,IAAA,SAAS,MAFV;AAGC,IAAA,KAAK,EAAGV,GAHT;AAIC,IAAA,KAAK,EAAGoD,SAJT;AAKC,IAAA,SAAS,EAAGrC,oBALb;AAMC,IAAA,OAAO,EAAG,MAAMC,uBAAuB,CAAE,KAAF,CANxC;AAOC,IAAA,QAAQ,EAAG6B,SAPZ;AAQC,IAAA,eAAe;AARhB,IAxDD,CADD;AAqEA,CAnQD;;AAqQA,eAAepD,SAAf","sourcesContent":["/**\n * Internal dependencies\n */\nimport {\n\tcreateUpgradedEmbedBlock,\n\tgetClassNames,\n\tfallback,\n\tgetEmbedInfoByProvider,\n\tgetMergedAttributesWithPreview,\n} from './util';\nimport EmbedControls from './embed-controls';\nimport { embedContentIcon } from './icons';\nimport EmbedLoading from './embed-loading';\nimport EmbedPlaceholder from './embed-placeholder';\nimport EmbedPreview from './embed-preview';\nimport EmbedLinkSettings from './embed-link-settings';\n\n/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { _x } from '@wordpress/i18n';\nimport { useCallback, useState, useEffect } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport {\n\tuseBlockProps,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { View } from '@wordpress/primitives';\n\n// The inline preview feature will be released progressible, for this reason\n// the embed will only be considered previewable for the following providers list.\nconst PREVIEWABLE_PROVIDERS = [ 'youtube', 'twitter', 'instagram', 'vimeo' ];\n// Some providers are rendering the inline preview as a WordPress embed and\n// are not supported yet, so we need to disallow them with a fixed providers list.\nconst NOT_PREVIEWABLE_WP_EMBED_PROVIDERS = [ 'pinterest' ];\n\nconst WP_EMBED_TYPE = 'wp-embed';\n\nconst EmbedEdit = ( props ) => {\n\tconst {\n\t\tattributes: { align, providerNameSlug, previewable, responsive, url },\n\t\tattributes,\n\t\tisSelected,\n\t\tonReplace,\n\t\tsetAttributes,\n\t\tinsertBlocksAfter,\n\t\tonFocus,\n\t\tclientId,\n\t} = props;\n\n\tconst defaultEmbedInfo = {\n\t\ttitle: _x( 'Embed', 'block title' ),\n\t\ticon: embedContentIcon,\n\t};\n\tconst embedInfoByProvider = getEmbedInfoByProvider( providerNameSlug );\n\tconst { icon, title } = embedInfoByProvider || defaultEmbedInfo;\n\n\tconst { wasBlockJustInserted } = useSelect(\n\t\t( select ) => ( {\n\t\t\twasBlockJustInserted: select(\n\t\t\t\tblockEditorStore\n\t\t\t).wasBlockJustInserted( clientId, 'inserter_menu' ),\n\t\t} ),\n\t\t[ clientId ]\n\t);\n\tconst [ isEditingURL, setIsEditingURL ] = useState(\n\t\tisSelected && wasBlockJustInserted && ! url\n\t);\n\tconst [ showEmbedBottomSheet, setShowEmbedBottomSheet ] =\n\t\tuseState( isEditingURL );\n\tconst { invalidateResolution } = useDispatch( coreStore );\n\n\tconst { preview, fetching, themeSupportsResponsive, cannotEmbed } =\n\t\tuseSelect(\n\t\t\t( select ) => {\n\t\t\t\tconst {\n\t\t\t\t\tgetEmbedPreview,\n\t\t\t\t\thasFinishedResolution,\n\t\t\t\t\tisPreviewEmbedFallback,\n\t\t\t\t\tgetThemeSupports,\n\t\t\t\t} = select( coreStore );\n\t\t\t\tif ( ! url ) {\n\t\t\t\t\treturn { fetching: false, cannotEmbed: false };\n\t\t\t\t}\n\n\t\t\t\tconst embedPreview = getEmbedPreview( url );\n\t\t\t\tconst hasResolvedEmbedPreview = hasFinishedResolution(\n\t\t\t\t\t'getEmbedPreview',\n\t\t\t\t\t[ url ]\n\t\t\t\t);\n\t\t\t\tconst previewIsFallback = isPreviewEmbedFallback( url );\n\n\t\t\t\t// The external oEmbed provider does not exist. We got no type info and no html.\n\t\t\t\tconst badEmbedProvider =\n\t\t\t\t\tembedPreview?.html === false &&\n\t\t\t\t\tembedPreview?.type === undefined;\n\t\t\t\t// Some WordPress URLs that can't be embedded will cause the API to return\n\t\t\t\t// a valid JSON response with no HTML and `code` set to 404, rather\n\t\t\t\t// than generating a fallback response as other embeds do.\n\t\t\t\tconst wordpressCantEmbed = embedPreview?.code === '404';\n\t\t\t\tconst validPreview =\n\t\t\t\t\t!! embedPreview &&\n\t\t\t\t\t! badEmbedProvider &&\n\t\t\t\t\t! wordpressCantEmbed;\n\n\t\t\t\treturn {\n\t\t\t\t\tpreview: validPreview ? embedPreview : undefined,\n\t\t\t\t\tfetching: ! hasResolvedEmbedPreview,\n\t\t\t\t\tthemeSupportsResponsive:\n\t\t\t\t\t\tgetThemeSupports()[ 'responsive-embeds' ],\n\t\t\t\t\tcannotEmbed: ! validPreview || previewIsFallback,\n\t\t\t\t};\n\t\t\t},\n\t\t\t[ url ]\n\t\t);\n\n\t/**\n\t * Returns the attributes derived from the preview, merged with the current attributes.\n\t *\n\t * @param {boolean} ignorePreviousClassName Determines if the previous className attribute should be ignored when merging.\n\t * @return {Object} Merged attributes.\n\t */\n\tconst getMergedAttributes = ( ignorePreviousClassName = false ) =>\n\t\tgetMergedAttributesWithPreview(\n\t\t\tattributes,\n\t\t\tpreview,\n\t\t\ttitle,\n\t\t\tresponsive,\n\t\t\tignorePreviousClassName\n\t\t);\n\n\tconst toggleResponsive = () => {\n\t\tconst { allowResponsive, className } = attributes;\n\t\tconst { html } = preview;\n\t\tconst newAllowResponsive = ! allowResponsive;\n\n\t\tsetAttributes( {\n\t\t\tallowResponsive: newAllowResponsive,\n\t\t\tclassName: getClassNames(\n\t\t\t\thtml,\n\t\t\t\tclassName,\n\t\t\t\tresponsive && newAllowResponsive\n\t\t\t),\n\t\t} );\n\t};\n\n\tuseEffect( () => {\n\t\tif ( ! preview?.html || ! cannotEmbed || fetching ) {\n\t\t\treturn;\n\t\t}\n\t\t// At this stage, we're not fetching the preview and know it can't be embedded,\n\t\t// so try removing any trailing slash, and resubmit.\n\t\tconst newURL = url.replace( /\\/$/, '' );\n\t\tsetIsEditingURL( false );\n\t\tsetAttributes( { url: newURL } );\n\t}, [ preview?.html, url ] );\n\n\t// Handle incoming preview.\n\tuseEffect( () => {\n\t\tif ( preview && ! isEditingURL ) {\n\t\t\t// When obtaining an incoming preview, we set the attributes derived from\n\t\t\t// the preview data. In this case when getting the merged attributes,\n\t\t\t// we ignore the previous classname because it might not match the expected\n\t\t\t// classes by the new preview.\n\t\t\tsetAttributes( getMergedAttributes( true ) );\n\n\t\t\tif ( onReplace ) {\n\t\t\t\tconst upgradedBlock = createUpgradedEmbedBlock(\n\t\t\t\t\tprops,\n\t\t\t\t\tgetMergedAttributes()\n\t\t\t\t);\n\n\t\t\t\tif ( upgradedBlock ) {\n\t\t\t\t\tonReplace( upgradedBlock );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}, [ preview, isEditingURL ] );\n\n\tuseEffect(\n\t\t() => setShowEmbedBottomSheet( isEditingURL ),\n\t\t[ isEditingURL ]\n\t);\n\n\tconst onEditURL = useCallback( ( value ) => {\n\t\t// The order of the following calls is important, we need to update the URL attribute before changing `isEditingURL`,\n\t\t// otherwise the side-effect that potentially replaces the block when updating the local state won't use the new URL\n\t\t// for creating the new block.\n\t\tsetAttributes( { url: value } );\n\t\tsetIsEditingURL( false );\n\t}, [] );\n\n\tconst blockProps = useBlockProps();\n\n\tif ( fetching ) {\n\t\treturn (\n\t\t\t<View { ...blockProps }>\n\t\t\t\t<EmbedLoading />\n\t\t\t</View>\n\t\t);\n\t}\n\n\tconst showEmbedPlaceholder = ! preview || cannotEmbed;\n\n\t// Even though we set attributes that get derived from the preview,\n\t// we don't access them directly because for the initial render,\n\t// the `setAttributes` call will not have taken effect. If we're\n\t// rendering responsive content, setting the responsive classes\n\t// after the preview has been rendered can result in unwanted\n\t// clipping or scrollbars. The `getAttributesFromPreview` function\n\t// that `getMergedAttributes` uses is memoized so that we're not\n\t// calculating them on every render.\n\tconst {\n\t\ttype,\n\t\tallowResponsive,\n\t\tclassName: classFromPreview,\n\t} = getMergedAttributes();\n\tconst className = classnames( classFromPreview, props.className );\n\n\tconst isProviderPreviewable =\n\t\tPREVIEWABLE_PROVIDERS.includes( providerNameSlug ) ||\n\t\t// For WordPress embeds, we enable the inline preview for all its providers\n\t\t// except the ones that are not supported yet.\n\t\t( WP_EMBED_TYPE === type &&\n\t\t\t! NOT_PREVIEWABLE_WP_EMBED_PROVIDERS.includes( providerNameSlug ) );\n\n\tconst linkLabel = WP_EMBED_TYPE === type ? 'WordPress' : title;\n\n\treturn (\n\t\t<>\n\t\t\t{ showEmbedPlaceholder ? (\n\t\t\t\t<>\n\t\t\t\t\t<View { ...blockProps }>\n\t\t\t\t\t\t<EmbedPlaceholder\n\t\t\t\t\t\t\ticon={ icon }\n\t\t\t\t\t\t\tisSelected={ isSelected }\n\t\t\t\t\t\t\tlabel={ title }\n\t\t\t\t\t\t\tonPress={ ( event ) => {\n\t\t\t\t\t\t\t\tonFocus( event );\n\t\t\t\t\t\t\t\tsetIsEditingURL( true );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tcannotEmbed={ cannotEmbed }\n\t\t\t\t\t\t\tfallback={ () => fallback( url, onReplace ) }\n\t\t\t\t\t\t\ttryAgain={ () => {\n\t\t\t\t\t\t\t\tinvalidateResolution( 'getEmbedPreview', [\n\t\t\t\t\t\t\t\t\turl,\n\t\t\t\t\t\t\t\t] );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\topenEmbedLinkSettings={ () =>\n\t\t\t\t\t\t\t\tsetShowEmbedBottomSheet( true )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</View>\n\t\t\t\t</>\n\t\t\t) : (\n\t\t\t\t<>\n\t\t\t\t\t<EmbedControls\n\t\t\t\t\t\tthemeSupportsResponsive={ themeSupportsResponsive }\n\t\t\t\t\t\tblockSupportsResponsive={ responsive }\n\t\t\t\t\t\tallowResponsive={ allowResponsive }\n\t\t\t\t\t\ttoggleResponsive={ toggleResponsive }\n\t\t\t\t\t\turl={ url }\n\t\t\t\t\t\tlinkLabel={ linkLabel }\n\t\t\t\t\t\tonEditURL={ onEditURL }\n\t\t\t\t\t/>\n\t\t\t\t\t<View { ...blockProps }>\n\t\t\t\t\t\t<EmbedPreview\n\t\t\t\t\t\t\talign={ align }\n\t\t\t\t\t\t\tclassName={ className }\n\t\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\t\ticon={ icon }\n\t\t\t\t\t\t\tinsertBlocksAfter={ insertBlocksAfter }\n\t\t\t\t\t\t\tisSelected={ isSelected }\n\t\t\t\t\t\t\tlabel={ title }\n\t\t\t\t\t\t\tonFocus={ onFocus }\n\t\t\t\t\t\t\tpreview={ preview }\n\t\t\t\t\t\t\tisProviderPreviewable={ isProviderPreviewable }\n\t\t\t\t\t\t\tpreviewable={ previewable }\n\t\t\t\t\t\t\ttype={ type }\n\t\t\t\t\t\t\turl={ url }\n\t\t\t\t\t\t\tisDefaultEmbedInfo={ ! embedInfoByProvider }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</View>\n\t\t\t\t</>\n\t\t\t) }\n\t\t\t<EmbedLinkSettings\n\t\t\t\t// eslint-disable-next-line jsx-a11y/no-autofocus\n\t\t\t\tautoFocus\n\t\t\t\tvalue={ url }\n\t\t\t\tlabel={ linkLabel }\n\t\t\t\tisVisible={ showEmbedBottomSheet }\n\t\t\t\tonClose={ () => setShowEmbedBottomSheet( false ) }\n\t\t\t\tonSubmit={ onEditURL }\n\t\t\t\twithBottomSheet\n\t\t\t/>\n\t\t</>\n\t);\n};\n\nexport default EmbedEdit;\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/embed/edit.native.js"],"names":["createUpgradedEmbedBlock","getClassNames","removeAspectRatioClasses","fallback","getEmbedInfoByProvider","getMergedAttributesWithPreview","EmbedControls","embedContentIcon","EmbedLoading","EmbedPlaceholder","EmbedPreview","EmbedLinkSettings","classnames","_x","useCallback","useState","useEffect","useDispatch","useSelect","useBlockProps","store","blockEditorStore","coreStore","View","PREVIEWABLE_PROVIDERS","NOT_PREVIEWABLE_WP_EMBED_PROVIDERS","WP_EMBED_TYPE","EmbedEdit","props","attributes","align","providerNameSlug","previewable","responsive","url","isSelected","onReplace","setAttributes","insertBlocksAfter","onFocus","clientId","defaultEmbedInfo","title","icon","embedInfoByProvider","wasBlockJustInserted","select","isEditingURL","setIsEditingURL","showEmbedBottomSheet","setShowEmbedBottomSheet","invalidateResolution","preview","fetching","themeSupportsResponsive","cannotEmbed","getEmbedPreview","hasFinishedResolution","isPreviewEmbedFallback","getThemeSupports","embedPreview","hasResolvedEmbedPreview","previewIsFallback","badEmbedProvider","html","type","undefined","wordpressCantEmbed","code","validPreview","getMergedAttributes","toggleResponsive","allowResponsive","className","newAllowResponsive","newURL","replace","mergedAttributes","upgradedBlock","onEditURL","value","blockClass","blockProps","showEmbedPlaceholder","classFromPreview","isProviderPreviewable","includes","linkLabel","event"],"mappings":";;AAAA;AACA;AACA;AACA,SACCA,wBADD,EAECC,aAFD,EAGCC,wBAHD,EAICC,QAJD,EAKCC,sBALD,EAMCC,8BAND,QAOO,QAPP;AAQA,OAAOC,aAAP,MAA0B,kBAA1B;AACA,SAASC,gBAAT,QAAiC,SAAjC;AACA,OAAOC,YAAP,MAAyB,iBAAzB;AACA,OAAOC,gBAAP,MAA6B,qBAA7B;AACA,OAAOC,YAAP,MAAyB,iBAAzB;AACA,OAAOC,iBAAP,MAA8B,uBAA9B;AAEA;AACA;AACA;;AACA,OAAOC,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,EAAT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ames,\n\tremoveAspectRatioClasses,\n\tfallback,\n\tgetEmbedInfoByProvider,\n\tgetMergedAttributesWithPreview,\n} from './util';\nimport EmbedControls from './embed-controls';\nimport { embedContentIcon } from './icons';\nimport EmbedLoading from './embed-loading';\nimport EmbedPlaceholder from './embed-placeholder';\nimport EmbedPreview from './embed-preview';\nimport EmbedLinkSettings from './embed-link-settings';\n\n/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { _x } from '@wordpress/i18n';\nimport { useCallback, useState, useEffect } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport {\n\tuseBlockProps,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { View } from '@wordpress/primitives';\n\n// The inline preview feature will be released progressible, for this reason\n// the embed will only be considered previewable for the following providers list.\nconst PREVIEWABLE_PROVIDERS = [ 'youtube', 'twitter', 'instagram', 'vimeo' ];\n// Some providers are rendering the inline preview as a WordPress embed and\n// are not supported yet, so we need to disallow them with a fixed providers list.\nconst NOT_PREVIEWABLE_WP_EMBED_PROVIDERS = [ 'pinterest' ];\n\nconst WP_EMBED_TYPE = 'wp-embed';\n\nconst EmbedEdit = ( props ) => {\n\tconst {\n\t\tattributes: { align, providerNameSlug, previewable, responsive, url },\n\t\tattributes,\n\t\tisSelected,\n\t\tonReplace,\n\t\tsetAttributes,\n\t\tinsertBlocksAfter,\n\t\tonFocus,\n\t\tclientId,\n\t} = props;\n\n\tconst defaultEmbedInfo = {\n\t\ttitle: _x( 'Embed', 'block title' ),\n\t\ticon: embedContentIcon,\n\t};\n\tconst embedInfoByProvider = getEmbedInfoByProvider( providerNameSlug );\n\tconst { icon, title } = embedInfoByProvider || defaultEmbedInfo;\n\n\tconst { wasBlockJustInserted } = useSelect(\n\t\t( select ) => ( {\n\t\t\twasBlockJustInserted: select(\n\t\t\t\tblockEditorStore\n\t\t\t).wasBlockJustInserted( clientId, 'inserter_menu' ),\n\t\t} ),\n\t\t[ clientId ]\n\t);\n\tconst [ isEditingURL, setIsEditingURL ] = useState(\n\t\tisSelected && wasBlockJustInserted && ! url\n\t);\n\tconst [ showEmbedBottomSheet, setShowEmbedBottomSheet ] =\n\t\tuseState( isEditingURL );\n\tconst { invalidateResolution } = useDispatch( coreStore );\n\n\tconst { preview, fetching, themeSupportsResponsive, cannotEmbed } =\n\t\tuseSelect(\n\t\t\t( select ) => {\n\t\t\t\tconst {\n\t\t\t\t\tgetEmbedPreview,\n\t\t\t\t\thasFinishedResolution,\n\t\t\t\t\tisPreviewEmbedFallback,\n\t\t\t\t\tgetThemeSupports,\n\t\t\t\t} = select( coreStore );\n\t\t\t\tif ( ! url ) {\n\t\t\t\t\treturn { fetching: false, cannotEmbed: false };\n\t\t\t\t}\n\n\t\t\t\tconst embedPreview = getEmbedPreview( url );\n\t\t\t\tconst hasResolvedEmbedPreview = hasFinishedResolution(\n\t\t\t\t\t'getEmbedPreview',\n\t\t\t\t\t[ url ]\n\t\t\t\t);\n\t\t\t\tconst previewIsFallback = isPreviewEmbedFallback( url );\n\n\t\t\t\t// The external oEmbed provider does not exist. We got no type info and no html.\n\t\t\t\tconst badEmbedProvider =\n\t\t\t\t\tembedPreview?.html === false &&\n\t\t\t\t\tembedPreview?.type === undefined;\n\t\t\t\t// Some WordPress URLs that can't be embedded will cause the API to return\n\t\t\t\t// a valid JSON response with no HTML and `code` set to 404, rather\n\t\t\t\t// than generating a fallback response as other embeds do.\n\t\t\t\tconst wordpressCantEmbed = embedPreview?.code === '404';\n\t\t\t\tconst validPreview =\n\t\t\t\t\t!! embedPreview &&\n\t\t\t\t\t! badEmbedProvider &&\n\t\t\t\t\t! wordpressCantEmbed;\n\n\t\t\t\treturn {\n\t\t\t\t\tpreview: validPreview ? embedPreview : undefined,\n\t\t\t\t\tfetching: ! hasResolvedEmbedPreview,\n\t\t\t\t\tthemeSupportsResponsive:\n\t\t\t\t\t\tgetThemeSupports()[ 'responsive-embeds' ],\n\t\t\t\t\tcannotEmbed: ! validPreview || previewIsFallback,\n\t\t\t\t};\n\t\t\t},\n\t\t\t[ url ]\n\t\t);\n\n\t/**\n\t * Returns the attributes derived from the preview, merged with the current attributes.\n\t *\n\t * @return {Object} Merged attributes.\n\t */\n\tconst getMergedAttributes = () =>\n\t\tgetMergedAttributesWithPreview(\n\t\t\tattributes,\n\t\t\tpreview,\n\t\t\ttitle,\n\t\t\tresponsive\n\t\t);\n\n\tconst toggleResponsive = () => {\n\t\tconst { allowResponsive, className } = attributes;\n\t\tconst { html } = preview;\n\t\tconst newAllowResponsive = ! allowResponsive;\n\n\t\tsetAttributes( {\n\t\t\tallowResponsive: newAllowResponsive,\n\t\t\tclassName: getClassNames(\n\t\t\t\thtml,\n\t\t\t\tclassName,\n\t\t\t\tresponsive && newAllowResponsive\n\t\t\t),\n\t\t} );\n\t};\n\n\tuseEffect( () => {\n\t\tif ( ! preview?.html || ! cannotEmbed || fetching ) {\n\t\t\treturn;\n\t\t}\n\t\t// At this stage, we're not fetching the preview and know it can't be embedded,\n\t\t// so try removing any trailing slash, and resubmit.\n\t\tconst newURL = url.replace( /\\/$/, '' );\n\t\tsetIsEditingURL( false );\n\t\tsetAttributes( { url: newURL } );\n\t}, [ preview?.html, url, cannotEmbed, fetching ] );\n\n\t// Handle incoming preview.\n\tuseEffect( () => {\n\t\tif ( preview && ! isEditingURL ) {\n\t\t\t// When obtaining an incoming preview,\n\t\t\t// we set the attributes derived from the preview data.\n\t\t\tconst mergedAttributes = getMergedAttributes();\n\t\t\tsetAttributes( mergedAttributes );\n\n\t\t\tif ( onReplace ) {\n\t\t\t\tconst upgradedBlock = createUpgradedEmbedBlock(\n\t\t\t\t\tprops,\n\t\t\t\t\tmergedAttributes\n\t\t\t\t);\n\n\t\t\t\tif ( upgradedBlock ) {\n\t\t\t\t\tonReplace( upgradedBlock );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}, [ preview, isEditingURL ] );\n\n\tuseEffect(\n\t\t() => setShowEmbedBottomSheet( isEditingURL ),\n\t\t[ isEditingURL ]\n\t);\n\n\tconst onEditURL = useCallback(\n\t\t( value ) => {\n\t\t\t// If the embed URL was changed, we need to reset the aspect ratio class.\n\t\t\t// To do this we have to remove the existing ratio class so it can be recalculated.\n\t\t\tif ( attributes.url !== value ) {\n\t\t\t\tconst blockClass = removeAspectRatioClasses(\n\t\t\t\t\tattributes.className\n\t\t\t\t);\n\t\t\t\tsetAttributes( { className: blockClass } );\n\t\t\t}\n\n\t\t\t// The order of the following calls is important, we need to update the URL attribute before changing `isEditingURL`,\n\t\t\t// otherwise the side-effect that potentially replaces the block when updating the local state won't use the new URL\n\t\t\t// for creating the new block.\n\t\t\tsetAttributes( { url: value } );\n\t\t\tsetIsEditingURL( false );\n\t\t},\n\t\t[ attributes, setAttributes ]\n\t);\n\n\tconst blockProps = useBlockProps();\n\n\tif ( fetching ) {\n\t\treturn (\n\t\t\t<View { ...blockProps }>\n\t\t\t\t<EmbedLoading />\n\t\t\t</View>\n\t\t);\n\t}\n\n\tconst showEmbedPlaceholder = ! preview || cannotEmbed;\n\n\t// Even though we set attributes that get derived from the preview,\n\t// we don't access them directly because for the initial render,\n\t// the `setAttributes` call will not have taken effect. If we're\n\t// rendering responsive content, setting the responsive classes\n\t// after the preview has been rendered can result in unwanted\n\t// clipping or scrollbars. The `getAttributesFromPreview` function\n\t// that `getMergedAttributes` uses is memoized so that we're not\n\t// calculating them on every render.\n\tconst {\n\t\ttype,\n\t\tallowResponsive,\n\t\tclassName: classFromPreview,\n\t} = getMergedAttributes();\n\tconst className = classnames( classFromPreview, props.className );\n\n\tconst isProviderPreviewable =\n\t\tPREVIEWABLE_PROVIDERS.includes( providerNameSlug ) ||\n\t\t// For WordPress embeds, we enable the inline preview for all its providers\n\t\t// except the ones that are not supported yet.\n\t\t( WP_EMBED_TYPE === type &&\n\t\t\t! NOT_PREVIEWABLE_WP_EMBED_PROVIDERS.includes( providerNameSlug ) );\n\n\tconst linkLabel = WP_EMBED_TYPE === type ? 'WordPress' : title;\n\n\treturn (\n\t\t<>\n\t\t\t{ showEmbedPlaceholder ? (\n\t\t\t\t<>\n\t\t\t\t\t<View { ...blockProps }>\n\t\t\t\t\t\t<EmbedPlaceholder\n\t\t\t\t\t\t\ticon={ icon }\n\t\t\t\t\t\t\tisSelected={ isSelected }\n\t\t\t\t\t\t\tlabel={ title }\n\t\t\t\t\t\t\tonPress={ ( event ) => {\n\t\t\t\t\t\t\t\tonFocus( event );\n\t\t\t\t\t\t\t\tsetIsEditingURL( true );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tcannotEmbed={ cannotEmbed }\n\t\t\t\t\t\t\tfallback={ () => fallback( url, onReplace ) }\n\t\t\t\t\t\t\ttryAgain={ () => {\n\t\t\t\t\t\t\t\tinvalidateResolution( 'getEmbedPreview', [\n\t\t\t\t\t\t\t\t\turl,\n\t\t\t\t\t\t\t\t] );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\topenEmbedLinkSettings={ () =>\n\t\t\t\t\t\t\t\tsetShowEmbedBottomSheet( true )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</View>\n\t\t\t\t</>\n\t\t\t) : (\n\t\t\t\t<>\n\t\t\t\t\t<EmbedControls\n\t\t\t\t\t\tthemeSupportsResponsive={ themeSupportsResponsive }\n\t\t\t\t\t\tblockSupportsResponsive={ responsive }\n\t\t\t\t\t\tallowResponsive={ allowResponsive }\n\t\t\t\t\t\ttoggleResponsive={ toggleResponsive }\n\t\t\t\t\t\turl={ url }\n\t\t\t\t\t\tlinkLabel={ linkLabel }\n\t\t\t\t\t\tonEditURL={ onEditURL }\n\t\t\t\t\t/>\n\t\t\t\t\t<View { ...blockProps }>\n\t\t\t\t\t\t<EmbedPreview\n\t\t\t\t\t\t\talign={ align }\n\t\t\t\t\t\t\tclassName={ className }\n\t\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\t\ticon={ icon }\n\t\t\t\t\t\t\tinsertBlocksAfter={ insertBlocksAfter }\n\t\t\t\t\t\t\tisSelected={ isSelected }\n\t\t\t\t\t\t\tlabel={ title }\n\t\t\t\t\t\t\tonFocus={ onFocus }\n\t\t\t\t\t\t\tpreview={ preview }\n\t\t\t\t\t\t\tisProviderPreviewable={ isProviderPreviewable }\n\t\t\t\t\t\t\tpreviewable={ previewable }\n\t\t\t\t\t\t\ttype={ type }\n\t\t\t\t\t\t\turl={ url }\n\t\t\t\t\t\t\tisDefaultEmbedInfo={ ! embedInfoByProvider }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</View>\n\t\t\t\t</>\n\t\t\t) }\n\t\t\t<EmbedLinkSettings\n\t\t\t\t// eslint-disable-next-line jsx-a11y/no-autofocus\n\t\t\t\tautoFocus\n\t\t\t\tvalue={ url }\n\t\t\t\tlabel={ linkLabel }\n\t\t\t\tisVisible={ showEmbedBottomSheet }\n\t\t\t\tonClose={ () => setShowEmbedBottomSheet( false ) }\n\t\t\t\tonSubmit={ onEditURL }\n\t\t\t\twithBottomSheet\n\t\t\t/>\n\t\t</>\n\t);\n};\n\nexport default EmbedEdit;\n"]}
|
|
@@ -205,6 +205,25 @@ export const createUpgradedEmbedBlock = function (props) {
|
|
|
205
205
|
...attributesFromPreview
|
|
206
206
|
});
|
|
207
207
|
};
|
|
208
|
+
/**
|
|
209
|
+
* Determine if the block already has an aspect ratio class applied.
|
|
210
|
+
*
|
|
211
|
+
* @param {string} existingClassNames Existing block classes.
|
|
212
|
+
* @return {boolean} True or false if the classnames contain an aspect ratio class.
|
|
213
|
+
*/
|
|
214
|
+
|
|
215
|
+
export const hasAspectRatioClass = existingClassNames => {
|
|
216
|
+
if (!existingClassNames) {
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return ASPECT_RATIOS.some(_ref4 => {
|
|
221
|
+
let {
|
|
222
|
+
className
|
|
223
|
+
} = _ref4;
|
|
224
|
+
return existingClassNames.includes(className);
|
|
225
|
+
});
|
|
226
|
+
};
|
|
208
227
|
/**
|
|
209
228
|
* Removes all previously set aspect ratio related classes and return the rest
|
|
210
229
|
* existing class names.
|
|
@@ -221,10 +240,10 @@ export const removeAspectRatioClasses = existingClassNames => {
|
|
|
221
240
|
return existingClassNames;
|
|
222
241
|
}
|
|
223
242
|
|
|
224
|
-
const aspectRatioClassNames = ASPECT_RATIOS.reduce((accumulator,
|
|
243
|
+
const aspectRatioClassNames = ASPECT_RATIOS.reduce((accumulator, _ref5) => {
|
|
225
244
|
let {
|
|
226
245
|
className
|
|
227
|
-
} =
|
|
246
|
+
} = _ref5;
|
|
228
247
|
accumulator[className] = false;
|
|
229
248
|
return accumulator;
|
|
230
249
|
}, {
|
|
@@ -330,6 +349,13 @@ export const getAttributesFromPreview = memoize(function (preview, title, curren
|
|
|
330
349
|
if (html || 'photo' === type) {
|
|
331
350
|
attributes.type = type;
|
|
332
351
|
attributes.providerNameSlug = providerNameSlug;
|
|
352
|
+
} // Aspect ratio classes are removed when the embed URL is updated.
|
|
353
|
+
// If the embed already has an aspect ratio class, that means the URL has not changed.
|
|
354
|
+
// Which also means no need to regenerate it with getClassNames.
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
if (hasAspectRatioClass(currentClassNames)) {
|
|
358
|
+
return attributes;
|
|
333
359
|
}
|
|
334
360
|
|
|
335
361
|
attributes.className = getClassNames(html, currentClassNames, isResponsive && allowResponsive);
|
|
@@ -338,22 +364,20 @@ export const getAttributesFromPreview = memoize(function (preview, title, curren
|
|
|
338
364
|
/**
|
|
339
365
|
* Returns the attributes derived from the preview, merged with the current attributes.
|
|
340
366
|
*
|
|
341
|
-
* @param {Object} currentAttributes
|
|
342
|
-
* @param {Object} preview
|
|
343
|
-
* @param {string} title
|
|
344
|
-
* @param {boolean} isResponsive
|
|
345
|
-
* @param {boolean} ignorePreviousClassName Determines if the previous className attribute should be ignored when merging.
|
|
367
|
+
* @param {Object} currentAttributes The current attributes of the block.
|
|
368
|
+
* @param {Object} preview The preview data.
|
|
369
|
+
* @param {string} title The block's title, e.g. Twitter.
|
|
370
|
+
* @param {boolean} isResponsive Boolean indicating if the block supports responsive content.
|
|
346
371
|
* @return {Object} Merged attributes.
|
|
347
372
|
*/
|
|
348
373
|
|
|
349
|
-
export const getMergedAttributesWithPreview =
|
|
350
|
-
let ignorePreviousClassName = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
374
|
+
export const getMergedAttributesWithPreview = (currentAttributes, preview, title, isResponsive) => {
|
|
351
375
|
const {
|
|
352
376
|
allowResponsive,
|
|
353
377
|
className
|
|
354
378
|
} = currentAttributes;
|
|
355
379
|
return { ...currentAttributes,
|
|
356
|
-
...getAttributesFromPreview(preview, title,
|
|
380
|
+
...getAttributesFromPreview(preview, title, className, isResponsive, allowResponsive)
|
|
357
381
|
};
|
|
358
382
|
};
|
|
359
383
|
//# sourceMappingURL=util.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/embed/util.js"],"names":["ASPECT_RATIOS","WP_EMBED_TYPE","kebabCase","classnames","memoize","renderToString","createBlock","getBlockType","getBlockVariations","name","DEFAULT_EMBED_BLOCK","metadata","getEmbedInfoByProvider","provider","find","matchesPatterns","url","patterns","some","pattern","match","findMoreSuitableBlock","isFromWordPress","html","includes","getPhotoHtml","photo","imageUrl","thumbnail_url","photoPreview","title","createUpgradedEmbedBlock","props","attributesFromPreview","preview","attributes","providerNameSlug","type","restAttributes","matchedBlock","isCurrentBlockWP","shouldCreateNewBlock","wpVariation","removeAspectRatioClasses","existingClassNames","aspectRatioClassNames","reduce","accumulator","className","getClassNames","allowResponsive","previewDocument","document","implementation","createHTMLDocument","body","innerHTML","iframe","querySelector","height","width","aspectRatio","toFixed","ratioIndex","length","potentialRatio","ratio","ratioDiff","fallback","onReplace","link","content","getAttributesFromPreview","currentClassNames","isResponsive","provider_name","providerName","toLowerCase","getMergedAttributesWithPreview","currentAttributes","ignorePreviousClassName","undefined"],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,MADJM,uBACI,uEADsB,KACtB;AACJ,QAAM;AAAE9B,IAAAA,eAAF;AAAmBF,IAAAA;AAAnB,MAAiC+B,iBAAvC;AACA,SAAO,EACN,GAAGA,iBADG;AAEN,OAAGP,wBAAwB,CAC1BtC,OAD0B,EAE1BJ,KAF0B,EAG1BkD,uBAAuB,GAAGC,SAAH,GAAejC,SAHZ,EAI1B0B,YAJ0B,EAK1BxB,eAL0B;AAFrB,GAAP;AAUA,CAlBM","sourcesContent":["/**\n * Internal dependencies\n */\nimport { ASPECT_RATIOS, WP_EMBED_TYPE } from './constants';\n\n/**\n * External dependencies\n */\nimport { kebabCase } from 'lodash';\nimport classnames from 'classnames/dedupe';\nimport memoize from 'memize';\n\n/**\n * WordPress dependencies\n */\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';\n\nconst { name: DEFAULT_EMBED_BLOCK } = metadata;\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 agains.\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 ) ) return;\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 * 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 emtpy string.\n\t\treturn existingClassNames;\n\t}\n\tconst aspectRatioClassNames = ASPECT_RATIOS.reduce(\n\t\t( accumulator, { className } ) => {\n\t\t\taccumulator[ className ] = false;\n\t\t\treturn accumulator;\n\t\t},\n\t\t{ 'wp-has-aspect-ratio': false }\n\t);\n\treturn classnames( existingClassNames, aspectRatioClassNames );\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\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 classnames(\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\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 * @param {boolean} ignorePreviousClassName Determines if the previous className attribute should be ignored when merging.\n * @return {Object} Merged attributes.\n */\nexport const getMergedAttributesWithPreview = (\n\tcurrentAttributes,\n\tpreview,\n\ttitle,\n\tisResponsive,\n\tignorePreviousClassName = false\n) => {\n\tconst { allowResponsive, className } = currentAttributes;\n\treturn {\n\t\t...currentAttributes,\n\t\t...getAttributesFromPreview(\n\t\t\tpreview,\n\t\t\ttitle,\n\t\t\tignorePreviousClassName ? undefined : className,\n\t\t\tisResponsive,\n\t\t\tallowResponsive\n\t\t),\n\t};\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/embed/util.js"],"names":["ASPECT_RATIOS","WP_EMBED_TYPE","kebabCase","classnames","memoize","renderToString","createBlock","getBlockType","getBlockVariations","name","DEFAULT_EMBED_BLOCK","metadata","getEmbedInfoByProvider","provider","find","matchesPatterns","url","patterns","some","pattern","match","findMoreSuitableBlock","isFromWordPress","html","includes","getPhotoHtml","photo","imageUrl","thumbnail_url","photoPreview","title","createUpgradedEmbedBlock","props","attributesFromPreview","preview","attributes","providerNameSlug","type","restAttributes","matchedBlock","isCurrentBlockWP","shouldCreateNewBlock","wpVariation","hasAspectRatioClass","existingClassNames","className","removeAspectRatioClasses","aspectRatioClassNames","reduce","accumulator","getClassNames","allowResponsive","previewDocument","document","implementation","createHTMLDocument","body","innerHTML","iframe","querySelector","height","width","aspectRatio","toFixed","ratioIndex","length","potentialRatio","ratio","ratioDiff","fallback","onReplace","link","content","getAttributesFromPreview","currentClassNames","isResponsive","provider_name","providerName","toLowerCase","getMergedAttributesWithPreview","currentAttributes"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,aAAT,EAAwBC,aAAxB,QAA6C,aAA7C;AAEA;AACA;AACA;;AACA,SAASC,SAAT,QAA0B,QAA1B;AACA,OAAOC,UAAP,MAAuB,mBAAvB;AACA,OAAOC,OAAP,MAAoB,QAApB;AAEA;AACA;AACA;;AACA,SAASC,cAAT,QAA+B,oBAA/B;AACA,SACCC,WADD,EAECC,YAFD,EAGCC,kBAHD,QAIO,mBAJP;AAMA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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9C,OAF6C,EAG7CJ,KAH6C,EAI7C6C,YAJ6C,KAKzC;AACJ,QAAM;AAAExB,IAAAA,eAAF;AAAmBN,IAAAA;AAAnB,MAAiCmC,iBAAvC;AAEA,SAAO,EACN,GAAGA,iBADG;AAEN,OAAGP,wBAAwB,CAC1BvC,OAD0B,EAE1BJ,KAF0B,EAG1Be,SAH0B,EAI1B8B,YAJ0B,EAK1BxB,eAL0B;AAFrB,GAAP;AAUA,CAlBM","sourcesContent":["/**\n * Internal dependencies\n */\nimport { ASPECT_RATIOS, WP_EMBED_TYPE } from './constants';\n\n/**\n * External dependencies\n */\nimport { kebabCase } from 'lodash';\nimport classnames from 'classnames/dedupe';\nimport memoize from 'memize';\n\n/**\n * WordPress dependencies\n */\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';\n\nconst { name: DEFAULT_EMBED_BLOCK } = metadata;\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 agains.\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 ) ) return;\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 emtpy string.\n\t\treturn existingClassNames;\n\t}\n\tconst aspectRatioClassNames = ASPECT_RATIOS.reduce(\n\t\t( accumulator, { className } ) => {\n\t\t\taccumulator[ className ] = false;\n\t\t\treturn accumulator;\n\t\t},\n\t\t{ 'wp-has-aspect-ratio': false }\n\t);\n\treturn classnames( existingClassNames, aspectRatioClassNames );\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\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 classnames(\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"]}
|
|
@@ -460,6 +460,7 @@ function GalleryEdit(props) {
|
|
|
460
460
|
}), (imageSizeOptions === null || imageSizeOptions === void 0 ? void 0 : imageSizeOptions.length) > 0 && createElement(SelectControl, {
|
|
461
461
|
__nextHasNoMarginBottom: true,
|
|
462
462
|
label: __('Image size'),
|
|
463
|
+
help: __('Select the size of the source images.'),
|
|
463
464
|
value: sizeSlug,
|
|
464
465
|
options: imageSizeOptions,
|
|
465
466
|
onChange: updateImagesSize,
|