@wordpress/block-library 7.3.0 → 7.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/archives/edit.js +1 -1
- package/build/archives/edit.js.map +1 -1
- package/build/audio/edit.js +2 -2
- package/build/audio/edit.js.map +1 -1
- package/build/audio/edit.native.js +1 -1
- package/build/audio/edit.native.js.map +1 -1
- package/build/categories/edit.js +8 -3
- package/build/categories/edit.js.map +1 -1
- package/build/categories/index.js +4 -0
- package/build/categories/index.js.map +1 -1
- package/build/column/index.js +10 -0
- package/build/column/index.js.map +1 -1
- package/build/comment-template/edit.js +3 -1
- package/build/comment-template/edit.js.map +1 -1
- package/build/comment-template/hooks.js +14 -4
- package/build/comment-template/hooks.js.map +1 -1
- package/build/comments-pagination/edit.js +18 -1
- package/build/comments-pagination/edit.js.map +1 -1
- package/build/comments-query-loop/edit.js +1 -1
- package/build/comments-query-loop/edit.js.map +1 -1
- package/build/comments-title/edit.js +149 -0
- package/build/comments-title/edit.js.map +1 -0
- package/build/comments-title/index.js +101 -0
- package/build/comments-title/index.js.map +1 -0
- package/build/cover/transforms.js +33 -32
- package/build/cover/transforms.js.map +1 -1
- package/build/embed/edit.js +12 -18
- package/build/embed/edit.js.map +1 -1
- package/build/embed/edit.native.js +1 -7
- package/build/embed/edit.native.js.map +1 -1
- package/build/embed/util.js +29 -4
- package/build/embed/util.js.map +1 -1
- package/build/file/inspector.js +2 -4
- package/build/file/inspector.js.map +1 -1
- package/build/gallery/edit.js +1 -1
- package/build/gallery/edit.js.map +1 -1
- package/build/gallery/v1/edit.js +1 -1
- package/build/gallery/v1/edit.js.map +1 -1
- package/build/html/edit.js +2 -2
- package/build/html/edit.js.map +1 -1
- package/build/image/edit.js +4 -6
- package/build/image/edit.js.map +1 -1
- package/build/image/edit.native.js +1 -1
- package/build/image/edit.native.js.map +1 -1
- package/build/image/image.js +1 -1
- package/build/image/image.js.map +1 -1
- package/build/index.js +5 -3
- package/build/index.js.map +1 -1
- package/build/index.native.js +14 -3
- package/build/index.native.js.map +1 -1
- package/build/latest-comments/edit.js +1 -1
- package/build/latest-comments/edit.js.map +1 -1
- package/build/list/index.js +13 -2
- package/build/list/index.js.map +1 -1
- package/build/loginout/edit.js +1 -1
- package/build/loginout/edit.js.map +1 -1
- package/build/media-text/edit.js +1 -2
- package/build/media-text/edit.js.map +1 -1
- package/build/media-text/edit.native.js +1 -1
- package/build/media-text/edit.native.js.map +1 -1
- package/build/navigation/edit/index.js +17 -1
- package/build/navigation/edit/index.js.map +1 -1
- package/build/navigation/edit/navigation-menu-selector.js +7 -2
- package/build/navigation/edit/navigation-menu-selector.js.map +1 -1
- package/build/navigation/edit/unsaved-inner-blocks.js +5 -4
- package/build/navigation/edit/unsaved-inner-blocks.js.map +1 -1
- package/build/navigation/index.js +1 -1
- package/build/navigation/view-modal.js +37 -0
- package/build/navigation/view-modal.js.map +1 -0
- package/build/navigation/view.js +1 -34
- package/build/navigation/view.js.map +1 -1
- package/build/paragraph/edit.native.js +6 -2
- package/build/paragraph/edit.native.js.map +1 -1
- package/build/post-author/edit.js +1 -1
- package/build/post-author/edit.js.map +1 -1
- package/build/post-comments/index.js +4 -3
- package/build/post-comments/index.js.map +1 -1
- package/build/post-excerpt/edit.js +1 -1
- package/build/post-excerpt/edit.js.map +1 -1
- package/build/post-featured-image/edit.js +19 -7
- package/build/post-featured-image/edit.js.map +1 -1
- package/build/query/edit/index.js +84 -22
- package/build/query/edit/index.js.map +1 -1
- package/build/query/edit/query-placeholder.js +7 -14
- package/build/query/edit/query-placeholder.js.map +1 -1
- package/build/query/edit/query-toolbar.js +6 -1
- package/build/query/edit/query-toolbar.js.map +1 -1
- package/build/quote/index.js +19 -2
- package/build/quote/index.js.map +1 -1
- package/build/quote/v2/edit.js +11 -3
- package/build/quote/v2/edit.js.map +1 -1
- package/build/rss/edit.js +1 -1
- package/build/rss/edit.js.map +1 -1
- package/build/search/edit.js +11 -9
- package/build/search/edit.js.map +1 -1
- package/build/spacer/constants.js +9 -0
- package/build/spacer/constants.js.map +1 -0
- package/build/spacer/controls.js +3 -3
- package/build/spacer/controls.js.map +1 -1
- package/build/spacer/controls.native.js +2 -2
- package/build/spacer/controls.native.js.map +1 -1
- package/build/spacer/edit.js +5 -6
- package/build/spacer/edit.js.map +1 -1
- package/build/table/edit.js +8 -2
- package/build/table/edit.js.map +1 -1
- package/build/tag-cloud/edit.js +1 -1
- package/build/tag-cloud/edit.js.map +1 -1
- package/build/video/edit.js +1 -1
- package/build/video/edit.js.map +1 -1
- package/build/video/edit.native.js +1 -1
- package/build/video/edit.native.js.map +1 -1
- package/build-module/archives/edit.js +1 -1
- package/build-module/archives/edit.js.map +1 -1
- package/build-module/audio/edit.js +2 -2
- package/build-module/audio/edit.js.map +1 -1
- package/build-module/audio/edit.native.js +1 -1
- package/build-module/audio/edit.native.js.map +1 -1
- package/build-module/categories/edit.js +8 -3
- package/build-module/categories/edit.js.map +1 -1
- package/build-module/categories/index.js +4 -0
- package/build-module/categories/index.js.map +1 -1
- package/build-module/column/index.js +10 -0
- package/build-module/column/index.js.map +1 -1
- package/build-module/comment-template/edit.js +3 -1
- package/build-module/comment-template/edit.js.map +1 -1
- package/build-module/comment-template/hooks.js +14 -4
- package/build-module/comment-template/hooks.js.map +1 -1
- package/build-module/comments-pagination/edit.js +19 -2
- package/build-module/comments-pagination/edit.js.map +1 -1
- package/build-module/comments-query-loop/edit.js +1 -1
- package/build-module/comments-query-loop/edit.js.map +1 -1
- package/build-module/comments-title/edit.js +133 -0
- package/build-module/comments-title/edit.js.map +1 -0
- package/build-module/comments-title/index.js +88 -0
- package/build-module/comments-title/index.js.map +1 -0
- package/build-module/cover/transforms.js +33 -32
- package/build-module/cover/transforms.js.map +1 -1
- package/build-module/embed/edit.js +13 -19
- package/build-module/embed/edit.js.map +1 -1
- package/build-module/embed/edit.native.js +2 -8
- package/build-module/embed/edit.native.js.map +1 -1
- package/build-module/embed/util.js +25 -3
- package/build-module/embed/util.js.map +1 -1
- package/build-module/file/inspector.js +2 -4
- package/build-module/file/inspector.js.map +1 -1
- package/build-module/gallery/edit.js +1 -1
- package/build-module/gallery/edit.js.map +1 -1
- package/build-module/gallery/v1/edit.js +1 -1
- package/build-module/gallery/v1/edit.js.map +1 -1
- package/build-module/html/edit.js +2 -2
- package/build-module/html/edit.js.map +1 -1
- package/build-module/image/edit.js +4 -6
- package/build-module/image/edit.js.map +1 -1
- package/build-module/image/edit.native.js +1 -1
- package/build-module/image/edit.native.js.map +1 -1
- package/build-module/image/image.js +1 -1
- package/build-module/image/image.js.map +1 -1
- package/build-module/index.js +4 -3
- package/build-module/index.js.map +1 -1
- package/build-module/index.native.js +14 -3
- package/build-module/index.native.js.map +1 -1
- package/build-module/latest-comments/edit.js +1 -1
- package/build-module/latest-comments/edit.js.map +1 -1
- package/build-module/list/index.js +9 -3
- package/build-module/list/index.js.map +1 -1
- package/build-module/loginout/edit.js +1 -1
- package/build-module/loginout/edit.js.map +1 -1
- package/build-module/media-text/edit.js +1 -2
- package/build-module/media-text/edit.js.map +1 -1
- package/build-module/media-text/edit.native.js +1 -1
- package/build-module/media-text/edit.native.js.map +1 -1
- package/build-module/navigation/edit/index.js +17 -1
- package/build-module/navigation/edit/index.js.map +1 -1
- package/build-module/navigation/edit/navigation-menu-selector.js +6 -2
- package/build-module/navigation/edit/navigation-menu-selector.js.map +1 -1
- package/build-module/navigation/edit/unsaved-inner-blocks.js +5 -4
- package/build-module/navigation/edit/unsaved-inner-blocks.js.map +1 -1
- package/build-module/navigation/index.js +1 -1
- package/build-module/navigation/view-modal.js +32 -0
- package/build-module/navigation/view-modal.js.map +1 -0
- package/build-module/navigation/view.js +1 -30
- package/build-module/navigation/view.js.map +1 -1
- package/build-module/paragraph/edit.native.js +6 -2
- package/build-module/paragraph/edit.native.js.map +1 -1
- package/build-module/post-author/edit.js +1 -1
- package/build-module/post-author/edit.js.map +1 -1
- package/build-module/post-comments/index.js +4 -3
- package/build-module/post-comments/index.js.map +1 -1
- package/build-module/post-excerpt/edit.js +1 -1
- package/build-module/post-excerpt/edit.js.map +1 -1
- package/build-module/post-featured-image/edit.js +19 -7
- package/build-module/post-featured-image/edit.js.map +1 -1
- package/build-module/query/edit/index.js +87 -26
- package/build-module/query/edit/index.js.map +1 -1
- package/build-module/query/edit/query-placeholder.js +8 -15
- package/build-module/query/edit/query-placeholder.js.map +1 -1
- package/build-module/query/edit/query-toolbar.js +6 -1
- package/build-module/query/edit/query-toolbar.js.map +1 -1
- package/build-module/quote/index.js +10 -4
- package/build-module/quote/index.js.map +1 -1
- package/build-module/quote/v2/edit.js +10 -3
- package/build-module/quote/v2/edit.js.map +1 -1
- package/build-module/rss/edit.js +1 -1
- package/build-module/rss/edit.js.map +1 -1
- package/build-module/search/edit.js +11 -9
- package/build-module/search/edit.js.map +1 -1
- package/build-module/spacer/constants.js +2 -0
- package/build-module/spacer/constants.js.map +1 -0
- package/build-module/spacer/controls.js +2 -2
- package/build-module/spacer/controls.js.map +1 -1
- package/build-module/spacer/controls.native.js +1 -1
- package/build-module/spacer/controls.native.js.map +1 -1
- package/build-module/spacer/edit.js +1 -1
- package/build-module/spacer/edit.js.map +1 -1
- package/build-module/table/edit.js +9 -3
- package/build-module/table/edit.js.map +1 -1
- package/build-module/tag-cloud/edit.js +1 -1
- package/build-module/tag-cloud/edit.js.map +1 -1
- package/build-module/video/edit.js +1 -1
- package/build-module/video/edit.js.map +1 -1
- package/build-module/video/edit.native.js +1 -1
- package/build-module/video/edit.native.js.map +1 -1
- package/build-style/comments-title/editor-rtl.css +79 -0
- package/build-style/comments-title/editor.css +79 -0
- package/build-style/common-rtl.css +32 -0
- package/build-style/common.css +32 -0
- package/build-style/editor-rtl.css +51 -0
- package/build-style/editor.css +51 -0
- package/build-style/post-comments-form/style-rtl.css +9 -0
- package/build-style/post-comments-form/style.css +9 -0
- package/build-style/query/editor-rtl.css +39 -0
- package/build-style/query/editor.css +39 -0
- package/build-style/style-rtl.css +79 -0
- package/build-style/style.css +79 -0
- package/build-style/table/editor-rtl.css +8 -0
- package/build-style/table/editor.css +8 -0
- package/build-style/table/style-rtl.css +38 -0
- package/build-style/table/style.css +38 -0
- package/package.json +28 -28
- package/src/archives/edit.js +1 -1
- package/src/audio/edit.js +2 -2
- package/src/audio/edit.native.js +1 -1
- package/src/categories/block.json +4 -0
- package/src/categories/edit.js +8 -2
- package/src/categories/index.php +1 -0
- package/src/column/block.json +10 -0
- package/src/comment-template/edit.js +5 -2
- package/src/comment-template/hooks.js +15 -2
- package/src/comment-template/index.php +23 -2
- package/src/comments-pagination/edit.js +23 -0
- package/src/comments-query-loop/edit.js +1 -0
- package/src/comments-title/block.json +70 -0
- package/src/comments-title/edit.js +197 -0
- package/src/comments-title/editor.scss +4 -0
- package/src/comments-title/index.js +18 -0
- package/src/comments-title/index.php +68 -0
- package/src/common.scss +24 -1
- package/src/cover/transforms.js +51 -28
- package/src/editor.scss +1 -0
- package/src/embed/edit.js +19 -24
- package/src/embed/edit.native.js +9 -14
- package/src/embed/util.js +34 -2
- package/src/file/inspector.js +1 -3
- package/src/gallery/edit.js +1 -1
- package/src/gallery/v1/edit.js +1 -1
- package/src/html/edit.js +2 -2
- package/src/image/edit.js +2 -4
- package/src/image/edit.native.js +1 -1
- package/src/image/image.js +1 -1
- package/src/index.js +7 -1
- package/src/index.native.js +12 -2
- package/src/latest-comments/edit.js +1 -1
- package/src/list/index.js +7 -3
- package/src/loginout/edit.js +1 -1
- package/src/media-text/edit.js +1 -2
- package/src/media-text/edit.native.js +1 -1
- package/src/navigation/block.json +1 -1
- package/src/navigation/edit/index.js +24 -0
- package/src/navigation/edit/navigation-menu-selector.js +15 -9
- package/src/navigation/edit/unsaved-inner-blocks.js +5 -4
- package/src/navigation/index.php +5 -0
- package/src/navigation/view-modal.js +36 -0
- package/src/navigation/view.js +0 -35
- package/src/paragraph/edit.native.js +13 -1
- package/src/post-author/edit.js +1 -1
- package/src/post-comments/block.json +4 -3
- package/src/post-comments-form/index.php +12 -4
- package/src/post-comments-form/style.scss +11 -0
- package/src/post-excerpt/edit.js +1 -1
- package/src/post-featured-image/edit.js +24 -12
- package/src/query/edit/index.js +125 -26
- package/src/query/edit/query-placeholder.js +3 -13
- package/src/query/edit/query-toolbar.js +6 -0
- package/src/query/editor.scss +38 -0
- package/src/quote/index.js +8 -4
- package/src/quote/v2/edit.js +3 -0
- package/src/rss/edit.js +1 -1
- package/src/search/edit.js +13 -7
- package/src/search/index.php +84 -33
- package/src/spacer/constants.js +1 -0
- package/src/spacer/controls.js +2 -2
- package/src/spacer/controls.native.js +1 -1
- package/src/spacer/edit.js +1 -2
- package/src/table/edit.js +11 -2
- package/src/table/editor.scss +13 -0
- package/src/table/style.scss +52 -0
- package/src/tag-cloud/edit.js +1 -1
- package/src/video/edit.js +1 -1
- package/src/video/edit.native.js +1 -1
|
@@ -68,48 +68,49 @@ const transforms = {
|
|
|
68
68
|
}, {
|
|
69
69
|
type: 'block',
|
|
70
70
|
blocks: ['core/group'],
|
|
71
|
-
|
|
72
|
-
var _style$color2, _style$color3;
|
|
73
|
-
|
|
74
|
-
let {
|
|
75
|
-
backgroundColor,
|
|
76
|
-
gradient,
|
|
77
|
-
style
|
|
78
|
-
} = _ref3;
|
|
71
|
+
transform: (attributes, innerBlocks) => {
|
|
72
|
+
var _style$color2, _style$color3, _style$color4, _style$color5, _attributes$style;
|
|
79
73
|
|
|
80
|
-
|
|
81
|
-
* Make this transformation available only if the Group has background
|
|
82
|
-
* or gradient set, because otherwise `Cover` block displays a Placeholder.
|
|
83
|
-
*
|
|
84
|
-
* This helps avoid arbitrary decisions about the Cover block's background
|
|
85
|
-
* and user confusion about the existence of previous content.
|
|
86
|
-
*/
|
|
87
|
-
return backgroundColor || (style === null || style === void 0 ? void 0 : (_style$color2 = style.color) === null || _style$color2 === void 0 ? void 0 : _style$color2.background) || (style === null || style === void 0 ? void 0 : (_style$color3 = style.color) === null || _style$color3 === void 0 ? void 0 : _style$color3.gradient) || gradient;
|
|
88
|
-
},
|
|
89
|
-
transform: (_ref4, innerBlocks) => {
|
|
90
|
-
var _style$color4, _style$color5;
|
|
91
|
-
|
|
92
|
-
let {
|
|
74
|
+
const {
|
|
93
75
|
align,
|
|
94
76
|
anchor,
|
|
95
77
|
backgroundColor,
|
|
96
78
|
gradient,
|
|
97
79
|
style
|
|
98
|
-
} =
|
|
99
|
-
|
|
80
|
+
} = attributes; // If no background or gradient color is provided, default to 50% opacity.
|
|
81
|
+
// This matches the styling of a Cover block with a background image,
|
|
82
|
+
// in the state where a background image has been removed.
|
|
83
|
+
|
|
84
|
+
const dimRatio = backgroundColor || gradient || style !== null && style !== void 0 && (_style$color2 = style.color) !== null && _style$color2 !== void 0 && _style$color2.background || style !== null && style !== void 0 && (_style$color3 = style.color) !== null && _style$color3 !== void 0 && _style$color3.gradient ? undefined : 50; // Move the background or gradient color to the parent Cover block.
|
|
85
|
+
|
|
86
|
+
const parentAttributes = {
|
|
100
87
|
align,
|
|
101
88
|
anchor,
|
|
89
|
+
dimRatio,
|
|
102
90
|
overlayColor: backgroundColor,
|
|
103
91
|
customOverlayColor: style === null || style === void 0 ? void 0 : (_style$color4 = style.color) === null || _style$color4 === void 0 ? void 0 : _style$color4.background,
|
|
104
92
|
gradient,
|
|
105
93
|
customGradient: style === null || style === void 0 ? void 0 : (_style$color5 = style.color) === null || _style$color5 === void 0 ? void 0 : _style$color5.gradient
|
|
106
|
-
}
|
|
94
|
+
};
|
|
95
|
+
const attributesWithoutBackgroundColors = { ...attributes,
|
|
96
|
+
backgroundColor: undefined,
|
|
97
|
+
gradient: undefined,
|
|
98
|
+
style: { ...(attributes === null || attributes === void 0 ? void 0 : attributes.style),
|
|
99
|
+
color: { ...(attributes === null || attributes === void 0 ? void 0 : (_attributes$style = attributes.style) === null || _attributes$style === void 0 ? void 0 : _attributes$style.color),
|
|
100
|
+
background: undefined,
|
|
101
|
+
gradient: undefined
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}; // Preserve the block by nesting it within the Cover block,
|
|
105
|
+
// instead of converting the Group block directly to the Cover block.
|
|
106
|
+
|
|
107
|
+
return createBlock('core/cover', parentAttributes, [createBlock('core/group', attributesWithoutBackgroundColors, innerBlocks)]);
|
|
107
108
|
}
|
|
108
109
|
}],
|
|
109
110
|
to: [{
|
|
110
111
|
type: 'block',
|
|
111
112
|
blocks: ['core/image'],
|
|
112
|
-
isMatch:
|
|
113
|
+
isMatch: _ref3 => {
|
|
113
114
|
let {
|
|
114
115
|
backgroundType,
|
|
115
116
|
url,
|
|
@@ -117,7 +118,7 @@ const transforms = {
|
|
|
117
118
|
customOverlayColor,
|
|
118
119
|
gradient,
|
|
119
120
|
customGradient
|
|
120
|
-
} =
|
|
121
|
+
} = _ref3;
|
|
121
122
|
|
|
122
123
|
if (url) {
|
|
123
124
|
// If a url exists the transform could happen if that URL represents an image background.
|
|
@@ -127,7 +128,7 @@ const transforms = {
|
|
|
127
128
|
|
|
128
129
|
return !overlayColor && !customOverlayColor && !gradient && !customGradient;
|
|
129
130
|
},
|
|
130
|
-
transform:
|
|
131
|
+
transform: _ref4 => {
|
|
131
132
|
var _style$color6;
|
|
132
133
|
|
|
133
134
|
let {
|
|
@@ -138,7 +139,7 @@ const transforms = {
|
|
|
138
139
|
id,
|
|
139
140
|
anchor,
|
|
140
141
|
style
|
|
141
|
-
} =
|
|
142
|
+
} = _ref4;
|
|
142
143
|
return createBlock('core/image', {
|
|
143
144
|
caption: title,
|
|
144
145
|
url,
|
|
@@ -156,7 +157,7 @@ const transforms = {
|
|
|
156
157
|
}, {
|
|
157
158
|
type: 'block',
|
|
158
159
|
blocks: ['core/video'],
|
|
159
|
-
isMatch:
|
|
160
|
+
isMatch: _ref5 => {
|
|
160
161
|
let {
|
|
161
162
|
backgroundType,
|
|
162
163
|
url,
|
|
@@ -164,7 +165,7 @@ const transforms = {
|
|
|
164
165
|
customOverlayColor,
|
|
165
166
|
gradient,
|
|
166
167
|
customGradient
|
|
167
|
-
} =
|
|
168
|
+
} = _ref5;
|
|
168
169
|
|
|
169
170
|
if (url) {
|
|
170
171
|
// If a url exists the transform could happen if that URL represents a video background.
|
|
@@ -174,14 +175,14 @@ const transforms = {
|
|
|
174
175
|
|
|
175
176
|
return !overlayColor && !customOverlayColor && !gradient && !customGradient;
|
|
176
177
|
},
|
|
177
|
-
transform:
|
|
178
|
+
transform: _ref6 => {
|
|
178
179
|
let {
|
|
179
180
|
title,
|
|
180
181
|
url,
|
|
181
182
|
align,
|
|
182
183
|
id,
|
|
183
184
|
anchor
|
|
184
|
-
} =
|
|
185
|
+
} = _ref6;
|
|
185
186
|
return createBlock('core/video', {
|
|
186
187
|
caption: title,
|
|
187
188
|
src: url,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/cover/transforms.js"],"names":["createBlock","IMAGE_BACKGROUND_TYPE","VIDEO_BACKGROUND_TYPE","transforms","from","type","blocks","transform","caption","url","alt","align","id","anchor","style","dimRatio","color","duotone","content","fontSize","src","backgroundType","isMatch","backgroundColor","gradient","background","innerBlocks","overlayColor","customOverlayColor","customGradient","to","title"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAT,QAA4B,mBAA5B;AAEA;AACA;AACA;;AACA,SAASC,qBAAT,EAAgCC,qBAAhC,QAA6D,UAA7D;AAEA,MAAMC,UAAU,GAAG;AAClBC,EAAAA,IAAI,EAAE,CACL;AACCC,IAAAA,IAAI,EAAE,OADP;AAECC,IAAAA,MAAM,EAAE,CAAE,YAAF,CAFT;AAGCC,IAAAA,SAAS,EAAE;AAAA;;AAAA,UAAE;AAAEC,QAAAA,OAAF;AAAWC,QAAAA,GAAX;AAAgBC,QAAAA,GAAhB;AAAqBC,QAAAA,KAArB;AAA4BC,QAAAA,EAA5B;AAAgCC,QAAAA,MAAhC;AAAwCC,QAAAA;AAAxC,OAAF;AAAA,aACVd,WAAW,CACV,YADU,EAEV;AACCe,QAAAA,QAAQ,EAAE,EADX;AAECN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;AAAzB,OAAF;AAAA,aACVb,WAAW,CAAE,YAAF,EAAgB;AAC1BQ,QAAAA,OAAO,EAAEuB,KADiB;AAE1BX,QAAAA,GAAG,EAAEX,GAFqB;AAG1BG,QAAAA,EAH0B;AAI1BD,QAAAA,KAJ0B;AAK1BE,QAAAA;AAL0B,OAAhB,CADD;AAAA;AAvBZ,GAvCG;AA1Fc,CAAnB;AAoKA,eAAeV,UAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createBlock } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { IMAGE_BACKGROUND_TYPE, VIDEO_BACKGROUND_TYPE } from './shared';\n\nconst transforms = {\n\tfrom: [\n\t\t{\n\t\t\ttype: 'block',\n\t\t\tblocks: [ 'core/image' ],\n\t\t\ttransform: ( { caption, url, alt, align, id, anchor, style } ) =>\n\t\t\t\tcreateBlock(\n\t\t\t\t\t'core/cover',\n\t\t\t\t\t{\n\t\t\t\t\t\tdimRatio: 50,\n\t\t\t\t\t\turl,\n\t\t\t\t\t\talt,\n\t\t\t\t\t\talign,\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tanchor,\n\t\t\t\t\t\tstyle: {\n\t\t\t\t\t\t\tcolor: {\n\t\t\t\t\t\t\t\tduotone: style?.color?.duotone,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t[\n\t\t\t\t\t\tcreateBlock( 'core/paragraph', {\n\t\t\t\t\t\t\tcontent: caption,\n\t\t\t\t\t\t\tfontSize: 'large',\n\t\t\t\t\t\t\talign: 'center',\n\t\t\t\t\t\t} ),\n\t\t\t\t\t]\n\t\t\t\t),\n\t\t},\n\t\t{\n\t\t\ttype: 'block',\n\t\t\tblocks: [ 'core/video' ],\n\t\t\ttransform: ( { caption, src, align, id, anchor } ) =>\n\t\t\t\tcreateBlock(\n\t\t\t\t\t'core/cover',\n\t\t\t\t\t{\n\t\t\t\t\t\tdimRatio: 50,\n\t\t\t\t\t\turl: src,\n\t\t\t\t\t\talign,\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tbackgroundType: VIDEO_BACKGROUND_TYPE,\n\t\t\t\t\t\tanchor,\n\t\t\t\t\t},\n\t\t\t\t\t[\n\t\t\t\t\t\tcreateBlock( 'core/paragraph', {\n\t\t\t\t\t\t\tcontent: caption,\n\t\t\t\t\t\t\tfontSize: 'large',\n\t\t\t\t\t\t\talign: 'center',\n\t\t\t\t\t\t} ),\n\t\t\t\t\t]\n\t\t\t\t),\n\t\t},\n\t\t{\n\t\t\ttype: 'block',\n\t\t\tblocks: [ 'core/group' ],\n\t\t\tisMatch: ( { backgroundColor, gradient, style } ) => {\n\t\t\t\t/*\n\t\t\t\t * Make this transformation available only if the Group has background\n\t\t\t\t * or gradient set, because otherwise `Cover` block displays a Placeholder.\n\t\t\t\t *\n\t\t\t\t * This helps avoid arbitrary decisions about the Cover block's background\n\t\t\t\t * and user confusion about the existence of previous content.\n\t\t\t\t */\n\t\t\t\treturn (\n\t\t\t\t\tbackgroundColor ||\n\t\t\t\t\tstyle?.color?.background ||\n\t\t\t\t\tstyle?.color?.gradient ||\n\t\t\t\t\tgradient\n\t\t\t\t);\n\t\t\t},\n\t\t\ttransform: (\n\t\t\t\t{ align, anchor, backgroundColor, gradient, style },\n\t\t\t\tinnerBlocks\n\t\t\t) => {\n\t\t\t\treturn createBlock(\n\t\t\t\t\t'core/cover',\n\t\t\t\t\t{\n\t\t\t\t\t\talign,\n\t\t\t\t\t\tanchor,\n\t\t\t\t\t\toverlayColor: backgroundColor,\n\t\t\t\t\t\tcustomOverlayColor: style?.color?.background,\n\t\t\t\t\t\tgradient,\n\t\t\t\t\t\tcustomGradient: style?.color?.gradient,\n\t\t\t\t\t},\n\t\t\t\t\tinnerBlocks\n\t\t\t\t);\n\t\t\t},\n\t\t},\n\t],\n\tto: [\n\t\t{\n\t\t\ttype: 'block',\n\t\t\tblocks: [ 'core/image' ],\n\t\t\tisMatch: ( {\n\t\t\t\tbackgroundType,\n\t\t\t\turl,\n\t\t\t\toverlayColor,\n\t\t\t\tcustomOverlayColor,\n\t\t\t\tgradient,\n\t\t\t\tcustomGradient,\n\t\t\t} ) => {\n\t\t\t\tif ( url ) {\n\t\t\t\t\t// If a url exists the transform could happen if that URL represents an image background.\n\t\t\t\t\treturn backgroundType === IMAGE_BACKGROUND_TYPE;\n\t\t\t\t}\n\t\t\t\t// If a url is not set the transform could happen if the cover has no background color or gradient;\n\t\t\t\treturn (\n\t\t\t\t\t! overlayColor &&\n\t\t\t\t\t! customOverlayColor &&\n\t\t\t\t\t! gradient &&\n\t\t\t\t\t! customGradient\n\t\t\t\t);\n\t\t\t},\n\t\t\ttransform: ( { title, url, alt, align, id, anchor, style } ) =>\n\t\t\t\tcreateBlock( 'core/image', {\n\t\t\t\t\tcaption: title,\n\t\t\t\t\turl,\n\t\t\t\t\talt,\n\t\t\t\t\talign,\n\t\t\t\t\tid,\n\t\t\t\t\tanchor,\n\t\t\t\t\tstyle: {\n\t\t\t\t\t\tcolor: {\n\t\t\t\t\t\t\tduotone: style?.color?.duotone,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t} ),\n\t\t},\n\t\t{\n\t\t\ttype: 'block',\n\t\t\tblocks: [ 'core/video' ],\n\t\t\tisMatch: ( {\n\t\t\t\tbackgroundType,\n\t\t\t\turl,\n\t\t\t\toverlayColor,\n\t\t\t\tcustomOverlayColor,\n\t\t\t\tgradient,\n\t\t\t\tcustomGradient,\n\t\t\t} ) => {\n\t\t\t\tif ( url ) {\n\t\t\t\t\t// If a url exists the transform could happen if that URL represents a video background.\n\t\t\t\t\treturn backgroundType === VIDEO_BACKGROUND_TYPE;\n\t\t\t\t}\n\t\t\t\t// If a url is not set the transform could happen if the cover has no background color or gradient;\n\t\t\t\treturn (\n\t\t\t\t\t! overlayColor &&\n\t\t\t\t\t! customOverlayColor &&\n\t\t\t\t\t! gradient &&\n\t\t\t\t\t! customGradient\n\t\t\t\t);\n\t\t\t},\n\t\t\ttransform: ( { title, url, align, id, anchor } ) =>\n\t\t\t\tcreateBlock( 'core/video', {\n\t\t\t\t\tcaption: title,\n\t\t\t\t\tsrc: url,\n\t\t\t\t\tid,\n\t\t\t\t\talign,\n\t\t\t\t\tanchor,\n\t\t\t\t} ),\n\t\t},\n\t],\n};\n\nexport default transforms;\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/cover/transforms.js"],"names":["createBlock","IMAGE_BACKGROUND_TYPE","VIDEO_BACKGROUND_TYPE","transforms","from","type","blocks","transform","caption","url","alt","align","id","anchor","style","dimRatio","color","duotone","content","fontSize","src","backgroundType","attributes","innerBlocks","backgroundColor","gradient","background","undefined","parentAttributes","overlayColor","customOverlayColor","customGradient","attributesWithoutBackgroundColors","to","isMatch","title"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAT,QAA4B,mBAA5B;AAEA;AACA;AACA;;AACA,SAASC,qBAAT,EAAgCC,qBAAhC,QAA6D,UAA7D;AAEA,MAAMC,UAAU,GAAG;AAClBC,EAAAA,IAAI,EAAE,CACL;AACCC,IAAAA,IAAI,EAAE,OADP;AAECC,IAAAA,MAAM,EAAE,CAAE,YAAF,CAFT;AAGCC,IAAAA,SAAS,EAAE;AAAA;;AAAA,UAAE;AAAEC,QAAAA,OAAF;AAAWC,QAAAA,GAAX;AAAgBC,QAAAA,GAAhB;AAAqBC,QAAAA,KAArB;AAA4BC,QAAAA,EAA5B;AAAgCC,QAAAA,MAAhC;AAAwCC,QAAAA;AAAxC,OAAF;AAAA,aACVd,WAAW,CACV,YADU,EAEV;AACCe,QAAAA,QAAQ,EAAE,EADX;AAECN,QAAAA,GAFD;AAGCC,QAAAA,GAHD;AAICC,QAAAA,KAJD;AAKCC,QAAAA,EALD;AAMCC,QAAAA,MAND;AAOCC,QAAAA,KAAK,EAAE;AACNE,UAAAA,KAAK,EAAE;AACNC,YAAAA,OAAO,EAAEH,KAAF,aAAEA,KAAF,uCAAEA,KAAK,CAAEE,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1B;AACA,OAJK,CAKN;;;AACA,aACC,CAAE2B,YAAF,IACA,CAAEC,kBADF,IAEA,CAAEL,QAFF,IAGA,CAAEM,cAJH;AAMA,KAtBF;AAuBCxB,IAAAA,SAAS,EAAE;AAAA,UAAE;AAAE4B,QAAAA,KAAF;AAAS1B,QAAAA,GAAT;AAAcE,QAAAA,KAAd;AAAqBC,QAAAA,EAArB;AAAyBC,QAAAA;AAAzB,OAAF;AAAA,aACVb,WAAW,CAAE,YAAF,EAAgB;AAC1BQ,QAAAA,OAAO,EAAE2B,KADiB;AAE1Bf,QAAAA,GAAG,EAAEX,GAFqB;AAG1BG,QAAAA,EAH0B;AAI1BD,QAAAA,KAJ0B;AAK1BE,QAAAA;AAL0B,OAAhB,CADD;AAAA;AAvBZ,GAvCG;AAjHc,CAAnB;AA2LA,eAAeV,UAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createBlock } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { IMAGE_BACKGROUND_TYPE, VIDEO_BACKGROUND_TYPE } from './shared';\n\nconst transforms = {\n\tfrom: [\n\t\t{\n\t\t\ttype: 'block',\n\t\t\tblocks: [ 'core/image' ],\n\t\t\ttransform: ( { caption, url, alt, align, id, anchor, style } ) =>\n\t\t\t\tcreateBlock(\n\t\t\t\t\t'core/cover',\n\t\t\t\t\t{\n\t\t\t\t\t\tdimRatio: 50,\n\t\t\t\t\t\turl,\n\t\t\t\t\t\talt,\n\t\t\t\t\t\talign,\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tanchor,\n\t\t\t\t\t\tstyle: {\n\t\t\t\t\t\t\tcolor: {\n\t\t\t\t\t\t\t\tduotone: style?.color?.duotone,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t[\n\t\t\t\t\t\tcreateBlock( 'core/paragraph', {\n\t\t\t\t\t\t\tcontent: caption,\n\t\t\t\t\t\t\tfontSize: 'large',\n\t\t\t\t\t\t\talign: 'center',\n\t\t\t\t\t\t} ),\n\t\t\t\t\t]\n\t\t\t\t),\n\t\t},\n\t\t{\n\t\t\ttype: 'block',\n\t\t\tblocks: [ 'core/video' ],\n\t\t\ttransform: ( { caption, src, align, id, anchor } ) =>\n\t\t\t\tcreateBlock(\n\t\t\t\t\t'core/cover',\n\t\t\t\t\t{\n\t\t\t\t\t\tdimRatio: 50,\n\t\t\t\t\t\turl: src,\n\t\t\t\t\t\talign,\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tbackgroundType: VIDEO_BACKGROUND_TYPE,\n\t\t\t\t\t\tanchor,\n\t\t\t\t\t},\n\t\t\t\t\t[\n\t\t\t\t\t\tcreateBlock( 'core/paragraph', {\n\t\t\t\t\t\t\tcontent: caption,\n\t\t\t\t\t\t\tfontSize: 'large',\n\t\t\t\t\t\t\talign: 'center',\n\t\t\t\t\t\t} ),\n\t\t\t\t\t]\n\t\t\t\t),\n\t\t},\n\t\t{\n\t\t\ttype: 'block',\n\t\t\tblocks: [ 'core/group' ],\n\t\t\ttransform: ( attributes, innerBlocks ) => {\n\t\t\t\tconst {\n\t\t\t\t\talign,\n\t\t\t\t\tanchor,\n\t\t\t\t\tbackgroundColor,\n\t\t\t\t\tgradient,\n\t\t\t\t\tstyle,\n\t\t\t\t} = attributes;\n\n\t\t\t\t// If no background or gradient color is provided, default to 50% opacity.\n\t\t\t\t// This matches the styling of a Cover block with a background image,\n\t\t\t\t// in the state where a background image has been removed.\n\t\t\t\tconst dimRatio =\n\t\t\t\t\tbackgroundColor ||\n\t\t\t\t\tgradient ||\n\t\t\t\t\tstyle?.color?.background ||\n\t\t\t\t\tstyle?.color?.gradient\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: 50;\n\n\t\t\t\t// Move the background or gradient color to the parent Cover block.\n\t\t\t\tconst parentAttributes = {\n\t\t\t\t\talign,\n\t\t\t\t\tanchor,\n\t\t\t\t\tdimRatio,\n\t\t\t\t\toverlayColor: backgroundColor,\n\t\t\t\t\tcustomOverlayColor: style?.color?.background,\n\t\t\t\t\tgradient,\n\t\t\t\t\tcustomGradient: style?.color?.gradient,\n\t\t\t\t};\n\n\t\t\t\tconst attributesWithoutBackgroundColors = {\n\t\t\t\t\t...attributes,\n\t\t\t\t\tbackgroundColor: undefined,\n\t\t\t\t\tgradient: undefined,\n\t\t\t\t\tstyle: {\n\t\t\t\t\t\t...attributes?.style,\n\t\t\t\t\t\tcolor: {\n\t\t\t\t\t\t\t...attributes?.style?.color,\n\t\t\t\t\t\t\tbackground: undefined,\n\t\t\t\t\t\t\tgradient: undefined,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t};\n\n\t\t\t\t// Preserve the block by nesting it within the Cover block,\n\t\t\t\t// instead of converting the Group block directly to the Cover block.\n\t\t\t\treturn createBlock( 'core/cover', parentAttributes, [\n\t\t\t\t\tcreateBlock(\n\t\t\t\t\t\t'core/group',\n\t\t\t\t\t\tattributesWithoutBackgroundColors,\n\t\t\t\t\t\tinnerBlocks\n\t\t\t\t\t),\n\t\t\t\t] );\n\t\t\t},\n\t\t},\n\t],\n\tto: [\n\t\t{\n\t\t\ttype: 'block',\n\t\t\tblocks: [ 'core/image' ],\n\t\t\tisMatch: ( {\n\t\t\t\tbackgroundType,\n\t\t\t\turl,\n\t\t\t\toverlayColor,\n\t\t\t\tcustomOverlayColor,\n\t\t\t\tgradient,\n\t\t\t\tcustomGradient,\n\t\t\t} ) => {\n\t\t\t\tif ( url ) {\n\t\t\t\t\t// If a url exists the transform could happen if that URL represents an image background.\n\t\t\t\t\treturn backgroundType === IMAGE_BACKGROUND_TYPE;\n\t\t\t\t}\n\t\t\t\t// If a url is not set the transform could happen if the cover has no background color or gradient;\n\t\t\t\treturn (\n\t\t\t\t\t! overlayColor &&\n\t\t\t\t\t! customOverlayColor &&\n\t\t\t\t\t! gradient &&\n\t\t\t\t\t! customGradient\n\t\t\t\t);\n\t\t\t},\n\t\t\ttransform: ( { title, url, alt, align, id, anchor, style } ) =>\n\t\t\t\tcreateBlock( 'core/image', {\n\t\t\t\t\tcaption: title,\n\t\t\t\t\turl,\n\t\t\t\t\talt,\n\t\t\t\t\talign,\n\t\t\t\t\tid,\n\t\t\t\t\tanchor,\n\t\t\t\t\tstyle: {\n\t\t\t\t\t\tcolor: {\n\t\t\t\t\t\t\tduotone: style?.color?.duotone,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t} ),\n\t\t},\n\t\t{\n\t\t\ttype: 'block',\n\t\t\tblocks: [ 'core/video' ],\n\t\t\tisMatch: ( {\n\t\t\t\tbackgroundType,\n\t\t\t\turl,\n\t\t\t\toverlayColor,\n\t\t\t\tcustomOverlayColor,\n\t\t\t\tgradient,\n\t\t\t\tcustomGradient,\n\t\t\t} ) => {\n\t\t\t\tif ( url ) {\n\t\t\t\t\t// If a url exists the transform could happen if that URL represents a video background.\n\t\t\t\t\treturn backgroundType === VIDEO_BACKGROUND_TYPE;\n\t\t\t\t}\n\t\t\t\t// If a url is not set the transform could happen if the cover has no background color or gradient;\n\t\t\t\treturn (\n\t\t\t\t\t! overlayColor &&\n\t\t\t\t\t! customOverlayColor &&\n\t\t\t\t\t! gradient &&\n\t\t\t\t\t! customGradient\n\t\t\t\t);\n\t\t\t},\n\t\t\ttransform: ( { title, url, align, id, anchor } ) =>\n\t\t\t\tcreateBlock( 'core/video', {\n\t\t\t\t\tcaption: title,\n\t\t\t\t\tsrc: url,\n\t\t\t\t\tid,\n\t\t\t\t\talign,\n\t\t\t\t\tanchor,\n\t\t\t\t} ),\n\t\t},\n\t],\n};\n\nexport default transforms;\n"]}
|
|
@@ -3,7 +3,7 @@ import { createElement, Fragment } from "@wordpress/element";
|
|
|
3
3
|
/**
|
|
4
4
|
* Internal dependencies
|
|
5
5
|
*/
|
|
6
|
-
import { createUpgradedEmbedBlock, getClassNames, fallback,
|
|
6
|
+
import { createUpgradedEmbedBlock, getClassNames, 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';
|
|
@@ -92,17 +92,15 @@ const EmbedEdit = props => {
|
|
|
92
92
|
};
|
|
93
93
|
}, [attributesUrl]);
|
|
94
94
|
/**
|
|
95
|
-
*
|
|
95
|
+
* Returns the attributes derived from the preview, merged with the current attributes.
|
|
96
|
+
*
|
|
97
|
+
* @param {boolean} ignorePreviousClassName Determines if the previous className attribute should be ignored when merging.
|
|
98
|
+
* @return {Object} Merged attributes.
|
|
96
99
|
*/
|
|
97
100
|
|
|
98
|
-
const getMergedAttributes = ()
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
className
|
|
102
|
-
} = attributes;
|
|
103
|
-
return { ...attributes,
|
|
104
|
-
...getAttributesFromPreview(preview, title, className, responsive, allowResponsive)
|
|
105
|
-
};
|
|
101
|
+
const getMergedAttributes = function () {
|
|
102
|
+
let ignorePreviousClassName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
103
|
+
return getMergedAttributesWithPreview(attributes, preview, title, responsive, ignorePreviousClassName);
|
|
106
104
|
};
|
|
107
105
|
|
|
108
106
|
const toggleResponsive = () => {
|
|
@@ -137,15 +135,11 @@ const EmbedEdit = props => {
|
|
|
137
135
|
|
|
138
136
|
useEffect(() => {
|
|
139
137
|
if (preview && !isEditingURL) {
|
|
140
|
-
//
|
|
141
|
-
//
|
|
142
|
-
// the
|
|
143
|
-
//
|
|
144
|
-
|
|
145
|
-
// clipping or scrollbars. The `getAttributesFromPreview` function
|
|
146
|
-
// that `getMergedAttributes` uses is memoized so that we're not
|
|
147
|
-
// calculating them on every render.
|
|
148
|
-
setAttributes(getMergedAttributes());
|
|
138
|
+
// When obtaining an incoming preview, we set the attributes derived from
|
|
139
|
+
// the preview data. In this case when getting the merged attributes,
|
|
140
|
+
// we ignore the previous classname because it might not match the expected
|
|
141
|
+
// classes by the new preview.
|
|
142
|
+
setAttributes(getMergedAttributes(true));
|
|
149
143
|
|
|
150
144
|
if (onReplace) {
|
|
151
145
|
const upgradedBlock = createUpgradedEmbedBlock(props, getMergedAttributes());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/embed/edit.js"],"names":["createUpgradedEmbedBlock","getClassNames","fallback","getAttributesFromPreview","getEmbedInfoByProvider","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","allowResponsive","className","toggleResponsive","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,wBAJD,EAKCC,sBALD,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,iBA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;AAELrB,IAAAA,IAFK;AAGLO,IAAAA,eAHK;AAILC,IAAAA,SAAS,EAAEc;AAJN,MAKFhB,mBAAmB,EALvB;AAMA,QAAME,SAAS,GAAGrD,UAAU,CAAEmE,gBAAF,EAAoBtD,KAAK,CAACwC,SAA1B,CAA5B;AAEA,SACC,8BACC,cAAC,aAAD;AACC,IAAA,cAAc,EAAGrB,OAAO,IAAI,CAAEG,WAD/B;AAEC,IAAA,uBAAuB,EAAGD,uBAF3B;AAGC,IAAA,uBAAuB,EAAGjB,UAH3B;AAIC,IAAA,eAAe,EAAGmC,eAJnB;AAKC,IAAA,gBAAgB,EAAGE,gBALpB;AAMC,IAAA,oBAAoB,EAAG,MAAMxB,eAAe,CAAE,IAAF;AAN7C,IADD,EASC,cAAC,IAAD,EAAW6B,UAAX,EACC,cAAC,YAAD;AACC,IAAA,OAAO,EAAG3B,OADX;AAEC,IAAA,WAAW,EAAGhB,WAFf;AAGC,IAAA,SAAS,EAAGqC,SAHb;AAIC,IAAA,GAAG,EAAGnC,GAJP;AAKC,IAAA,IAAI,EAAG2B,IALR;AAMC,IAAA,OAAO,EAAGqB,OANX;AAOC,IAAA,eAAe,EAAKD,KAAF,IACjB3C,aAAa,CAAE;AAAE4C,MAAAA,OAAO,EAAED;AAAX,KAAF,CARf;AAUC,IAAA,UAAU,EAAG7C,UAVd;AAWC,IAAA,IAAI,EAAGO,IAXR;AAYC,IAAA,KAAK,EAAGiC,KAZT;AAaC,IAAA,iBAAiB,EAAGrC;AAbrB,IADD,CATD,CADD;AA6BA,CAlOD;;AAoOA,eAAeX,SAAf","sourcesContent":["/**\n * Internal dependencies\n */\nimport {\n\tcreateUpgradedEmbedBlock,\n\tgetClassNames,\n\tfallback,\n\tgetAttributesFromPreview,\n\tgetEmbedInfoByProvider,\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 {\n\t\tpreview,\n\t\tfetching,\n\t\tthemeSupportsResponsive,\n\t\tcannotEmbed,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetEmbedPreview,\n\t\t\t\tisPreviewEmbedFallback,\n\t\t\t\tisRequestingEmbedPreview,\n\t\t\t\tgetThemeSupports,\n\t\t\t} = select( coreStore );\n\t\t\tif ( ! attributesUrl ) {\n\t\t\t\treturn { fetching: false, cannotEmbed: false };\n\t\t\t}\n\n\t\t\tconst embedPreview = getEmbedPreview( attributesUrl );\n\t\t\tconst previewIsFallback = isPreviewEmbedFallback( attributesUrl );\n\n\t\t\t// The external oEmbed provider does not exist. We got no type info and no html.\n\t\t\tconst badEmbedProvider =\n\t\t\t\tembedPreview?.html === false &&\n\t\t\t\tembedPreview?.type === undefined;\n\t\t\t// Some WordPress URLs that can't be embedded will cause the API to return\n\t\t\t// a valid JSON response with no HTML and `data.status` set to 404, rather\n\t\t\t// than generating a fallback response as other embeds do.\n\t\t\tconst wordpressCantEmbed = embedPreview?.data?.status === 404;\n\t\t\tconst validPreview =\n\t\t\t\t!! embedPreview && ! badEmbedProvider && ! wordpressCantEmbed;\n\t\t\treturn {\n\t\t\t\tpreview: validPreview ? embedPreview : undefined,\n\t\t\t\tfetching: isRequestingEmbedPreview( attributesUrl ),\n\t\t\t\tthemeSupportsResponsive: getThemeSupports()[\n\t\t\t\t\t'responsive-embeds'\n\t\t\t\t],\n\t\t\t\tcannotEmbed: ! validPreview || previewIsFallback,\n\t\t\t};\n\t\t},\n\t\t[ attributesUrl ]\n\t);\n\n\t/**\n\t * @return {Object} Attributes derived from the preview, merged with the current attributes.\n\t */\n\tconst getMergedAttributes = () => {\n\t\tconst { allowResponsive, className } = attributes;\n\t\treturn {\n\t\t\t...attributes,\n\t\t\t...getAttributesFromPreview(\n\t\t\t\tpreview,\n\t\t\t\ttitle,\n\t\t\t\tclassName,\n\t\t\t\tresponsive,\n\t\t\t\tallowResponsive\n\t\t\t),\n\t\t};\n\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// Even though we set attributes that get derived from the preview,\n\t\t\t// we don't access them directly because for the initial render,\n\t\t\t// the `setAttributes` call will not have taken effect. If we're\n\t\t\t// rendering responsive content, setting the responsive classes\n\t\t\t// after the preview has been rendered can result in unwanted\n\t\t\t// clipping or scrollbars. The `getAttributesFromPreview` function\n\t\t\t// that `getMergedAttributes` uses is memoized so that we're not\n\t\t\t// calculating them on every render.\n\t\t\tsetAttributes( getMergedAttributes() );\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","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,EAAs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AILC,IAAAA,SAAS,EAAEa;AAJN,MAKFjB,mBAAmB,EALvB;AAMA,QAAMI,SAAS,GAAGvD,UAAU,CAAEoE,gBAAF,EAAoBvD,KAAK,CAAC0C,SAA1B,CAA5B;AAEA,SACC,8BACC,cAAC,aAAD;AACC,IAAA,cAAc,EAAGvB,OAAO,IAAI,CAAEG,WAD/B;AAEC,IAAA,uBAAuB,EAAGD,uBAF3B;AAGC,IAAA,uBAAuB,EAAGjB,UAH3B;AAIC,IAAA,eAAe,EAAGqC,eAJnB;AAKC,IAAA,gBAAgB,EAAGD,gBALpB;AAMC,IAAA,oBAAoB,EAAG,MAAMvB,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,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,CA7ND;;AA+NA,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 {\n\t\tpreview,\n\t\tfetching,\n\t\tthemeSupportsResponsive,\n\t\tcannotEmbed,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetEmbedPreview,\n\t\t\t\tisPreviewEmbedFallback,\n\t\t\t\tisRequestingEmbedPreview,\n\t\t\t\tgetThemeSupports,\n\t\t\t} = select( coreStore );\n\t\t\tif ( ! attributesUrl ) {\n\t\t\t\treturn { fetching: false, cannotEmbed: false };\n\t\t\t}\n\n\t\t\tconst embedPreview = getEmbedPreview( attributesUrl );\n\t\t\tconst previewIsFallback = isPreviewEmbedFallback( attributesUrl );\n\n\t\t\t// The external oEmbed provider does not exist. We got no type info and no html.\n\t\t\tconst badEmbedProvider =\n\t\t\t\tembedPreview?.html === false &&\n\t\t\t\tembedPreview?.type === undefined;\n\t\t\t// Some WordPress URLs that can't be embedded will cause the API to return\n\t\t\t// a valid JSON response with no HTML and `data.status` set to 404, rather\n\t\t\t// than generating a fallback response as other embeds do.\n\t\t\tconst wordpressCantEmbed = embedPreview?.data?.status === 404;\n\t\t\tconst validPreview =\n\t\t\t\t!! embedPreview && ! badEmbedProvider && ! wordpressCantEmbed;\n\t\t\treturn {\n\t\t\t\tpreview: validPreview ? embedPreview : undefined,\n\t\t\t\tfetching: isRequestingEmbedPreview( attributesUrl ),\n\t\t\t\tthemeSupportsResponsive: getThemeSupports()[\n\t\t\t\t\t'responsive-embeds'\n\t\t\t\t],\n\t\t\t\tcannotEmbed: ! validPreview || previewIsFallback,\n\t\t\t};\n\t\t},\n\t\t[ attributesUrl ]\n\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"]}
|
|
@@ -3,7 +3,7 @@ import { createElement, Fragment } from "@wordpress/element";
|
|
|
3
3
|
/**
|
|
4
4
|
* Internal dependencies
|
|
5
5
|
*/
|
|
6
|
-
import { createUpgradedEmbedBlock, getClassNames, fallback,
|
|
6
|
+
import { createUpgradedEmbedBlock, getClassNames, 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';
|
|
@@ -115,13 +115,7 @@ const EmbedEdit = props => {
|
|
|
115
115
|
|
|
116
116
|
const getMergedAttributes = function () {
|
|
117
117
|
let ignorePreviousClassName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
118
|
-
|
|
119
|
-
allowResponsive,
|
|
120
|
-
className
|
|
121
|
-
} = attributes;
|
|
122
|
-
return { ...attributes,
|
|
123
|
-
...getAttributesFromPreview(preview, title, ignorePreviousClassName ? undefined : className, responsive, allowResponsive)
|
|
124
|
-
};
|
|
118
|
+
return getMergedAttributesWithPreview(attributes, preview, title, responsive, ignorePreviousClassName);
|
|
125
119
|
};
|
|
126
120
|
|
|
127
121
|
const toggleResponsive = () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/embed/edit.native.js"],"names":["createUpgradedEmbedBlock","getClassNames","fallback","getAttributesFromPreview","getEmbedInfoByProvider","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","allowResponsive","className","toggleResponsive","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,wBAJD,EAKCC,sBALD,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,SAAF,EAAa,SAAb,EAAwB,WAAxB,EAAqC,OAArC,CAA9B,C,CACA;AACA;;AACA,MAAMC,kCAAkC,GAAG,CAAE,WAAF,CAA3C;AAEA,MAAMC,aAAa,GAAG,UAAtB;;AAEA,MAAMC,SAAS,GAAKC,KAAF,IAAa;AAC9B,Q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AGO,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,CA3QD;;AA6QA,eAAepD,SAAf","sourcesContent":["/**\n * Internal dependencies\n */\nimport {\n\tcreateUpgradedEmbedBlock,\n\tgetClassNames,\n\tfallback,\n\tgetAttributesFromPreview,\n\tgetEmbedInfoByProvider,\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 ] = useState(\n\t\tisEditingURL\n\t);\n\tconst { invalidateResolution } = useDispatch( coreStore );\n\n\tconst {\n\t\tpreview,\n\t\tfetching,\n\t\tthemeSupportsResponsive,\n\t\tcannotEmbed,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetEmbedPreview,\n\t\t\t\thasFinishedResolution,\n\t\t\t\tisPreviewEmbedFallback,\n\t\t\t\tgetThemeSupports,\n\t\t\t} = select( coreStore );\n\t\t\tif ( ! url ) {\n\t\t\t\treturn { fetching: false, cannotEmbed: false };\n\t\t\t}\n\n\t\t\tconst embedPreview = getEmbedPreview( url );\n\t\t\tconst hasResolvedEmbedPreview = hasFinishedResolution(\n\t\t\t\t'getEmbedPreview',\n\t\t\t\t[ url ]\n\t\t\t);\n\t\t\tconst previewIsFallback = isPreviewEmbedFallback( url );\n\n\t\t\t// The external oEmbed provider does not exist. We got no type info and no html.\n\t\t\tconst badEmbedProvider =\n\t\t\t\tembedPreview?.html === false &&\n\t\t\t\tembedPreview?.type === undefined;\n\t\t\t// Some WordPress URLs that can't be embedded will cause the API to return\n\t\t\t// a valid JSON response with no HTML and `code` set to 404, rather\n\t\t\t// than generating a fallback response as other embeds do.\n\t\t\tconst wordpressCantEmbed = embedPreview?.code === '404';\n\t\t\tconst validPreview =\n\t\t\t\t!! embedPreview && ! badEmbedProvider && ! wordpressCantEmbed;\n\n\t\t\treturn {\n\t\t\t\tpreview: validPreview ? embedPreview : undefined,\n\t\t\t\tfetching: ! hasResolvedEmbedPreview,\n\t\t\t\tthemeSupportsResponsive: getThemeSupports()[\n\t\t\t\t\t'responsive-embeds'\n\t\t\t\t],\n\t\t\t\tcannotEmbed: ! validPreview || previewIsFallback,\n\t\t\t};\n\t\t},\n\t\t[ url ]\n\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\tconst { allowResponsive, className } = attributes;\n\t\treturn {\n\t\t\t...attributes,\n\t\t\t...getAttributesFromPreview(\n\t\t\t\tpreview,\n\t\t\t\ttitle,\n\t\t\t\tignorePreviousClassName ? undefined : className,\n\t\t\t\tresponsive,\n\t\t\t\tallowResponsive\n\t\t\t),\n\t\t};\n\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( () => setShowEmbedBottomSheet( isEditingURL ), [\n\t\tisEditingURL,\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","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,QA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,IAAA,SAAS,EAAGP;AAPb,IADD,EAUC,cAAC,IAAD,EAAWE,UAAX,EACC,cAAC,YAAD;AACC,IAAA,KAAK,EAAGnD,KADT;AAEC,IAAA,SAAS,EAAG4C,SAFb;AAGC,IAAA,QAAQ,EAAGlC,QAHZ;AAIC,IAAA,IAAI,EAAGG,IAJR;AAKC,IAAA,iBAAiB,EAAGL,iBALrB;AAMC,IAAA,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,CAtQD;;AAwQA,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 ] = useState(\n\t\tisEditingURL\n\t);\n\tconst { invalidateResolution } = useDispatch( coreStore );\n\n\tconst {\n\t\tpreview,\n\t\tfetching,\n\t\tthemeSupportsResponsive,\n\t\tcannotEmbed,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetEmbedPreview,\n\t\t\t\thasFinishedResolution,\n\t\t\t\tisPreviewEmbedFallback,\n\t\t\t\tgetThemeSupports,\n\t\t\t} = select( coreStore );\n\t\t\tif ( ! url ) {\n\t\t\t\treturn { fetching: false, cannotEmbed: false };\n\t\t\t}\n\n\t\t\tconst embedPreview = getEmbedPreview( url );\n\t\t\tconst hasResolvedEmbedPreview = hasFinishedResolution(\n\t\t\t\t'getEmbedPreview',\n\t\t\t\t[ url ]\n\t\t\t);\n\t\t\tconst previewIsFallback = isPreviewEmbedFallback( url );\n\n\t\t\t// The external oEmbed provider does not exist. We got no type info and no html.\n\t\t\tconst badEmbedProvider =\n\t\t\t\tembedPreview?.html === false &&\n\t\t\t\tembedPreview?.type === undefined;\n\t\t\t// Some WordPress URLs that can't be embedded will cause the API to return\n\t\t\t// a valid JSON response with no HTML and `code` set to 404, rather\n\t\t\t// than generating a fallback response as other embeds do.\n\t\t\tconst wordpressCantEmbed = embedPreview?.code === '404';\n\t\t\tconst validPreview =\n\t\t\t\t!! embedPreview && ! badEmbedProvider && ! wordpressCantEmbed;\n\n\t\t\treturn {\n\t\t\t\tpreview: validPreview ? embedPreview : undefined,\n\t\t\t\tfetching: ! hasResolvedEmbedPreview,\n\t\t\t\tthemeSupportsResponsive: getThemeSupports()[\n\t\t\t\t\t'responsive-embeds'\n\t\t\t\t],\n\t\t\t\tcannotEmbed: ! validPreview || previewIsFallback,\n\t\t\t};\n\t\t},\n\t\t[ url ]\n\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( () => setShowEmbedBottomSheet( isEditingURL ), [\n\t\tisEditingURL,\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"]}
|
|
@@ -117,9 +117,10 @@ export const findMoreSuitableBlock = url => {
|
|
|
117
117
|
};
|
|
118
118
|
export const isFromWordPress = html => html && html.includes('class="wp-embedded-content"');
|
|
119
119
|
export const getPhotoHtml = photo => {
|
|
120
|
-
//
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
// If full image url not found use thumbnail.
|
|
121
|
+
const imageUrl = photo.url || photo.thumbnail_url; // 100% width for the preview so it fits nicely into the document, some "thumbnails" are
|
|
122
|
+
// actually the full size photo.
|
|
123
|
+
|
|
123
124
|
const photoPreview = createElement("p", null, createElement("img", {
|
|
124
125
|
src: imageUrl,
|
|
125
126
|
alt: photo.title,
|
|
@@ -328,4 +329,25 @@ export const getAttributesFromPreview = memoize(function (preview, title, curren
|
|
|
328
329
|
attributes.className = getClassNames(html, currentClassNames, isResponsive && allowResponsive);
|
|
329
330
|
return attributes;
|
|
330
331
|
});
|
|
332
|
+
/**
|
|
333
|
+
* Returns the attributes derived from the preview, merged with the current attributes.
|
|
334
|
+
*
|
|
335
|
+
* @param {Object} currentAttributes The current attributes of the block.
|
|
336
|
+
* @param {Object} preview The preview data.
|
|
337
|
+
* @param {string} title The block's title, e.g. Twitter.
|
|
338
|
+
* @param {boolean} isResponsive Boolean indicating if the block supports responsive content.
|
|
339
|
+
* @param {boolean} ignorePreviousClassName Determines if the previous className attribute should be ignored when merging.
|
|
340
|
+
* @return {Object} Merged attributes.
|
|
341
|
+
*/
|
|
342
|
+
|
|
343
|
+
export const getMergedAttributesWithPreview = function (currentAttributes, preview, title, isResponsive) {
|
|
344
|
+
let ignorePreviousClassName = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
345
|
+
const {
|
|
346
|
+
allowResponsive,
|
|
347
|
+
className
|
|
348
|
+
} = currentAttributes;
|
|
349
|
+
return { ...currentAttributes,
|
|
350
|
+
...getAttributesFromPreview(preview, title, ignorePreviousClassName ? undefined : className, isResponsive, allowResponsive)
|
|
351
|
+
};
|
|
352
|
+
};
|
|
331
353
|
//# 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"],"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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,MAAM;AAAEC,EAAAA,IAAI,EAAEC;AAAR,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,IAAAA,IAAI,GAAG;AAAT,MAAoBH,OAAxB,CAPI,CAQJ;AACA;;AACA,QAAM;AAAEX,IAAAA,IAAF;AAAQoD,IAAAA,aAAa,EAAEC;AAAvB,MAAwC1C,OAA9C;AACA,QAAME,gBAAgB,GAAGlC,SAAS,CACjC,CAAE0E,YAAY,IAAI9C,KAAlB,EAA0B+C,WAA1B,EADiC,CAAlC;;AAIA,MAAKvD,eAAe,CAAEC,IAAF,CAApB,EAA+B;AAC9Bc,IAAAA,IAAI,GAAGpC,aAAP;AACA;;AAED,MAAKsB,IAAI,IAAI,YAAYc,IAAzB,EAAgC;AAC/BF,IAAAA,UAAU,CAACE,IAAX,GAAkBA,IAAlB;AACAF,IAAAA,UAAU,CAACC,gBAAX,GAA8BA,gBAA9B;AACA;;AAEDD,EAAAA,UAAU,CAACa,SAAX,GAAuBC,aAAa,CACnC1B,IADmC,EAEnCkD,iBAFmC,EAGnCC,YAAY,IAAIxB,eAHmB,CAApC;AAMA,SAAOf,UAAP;AACA,CAtC6C,CAAxC","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// 100% width for the preview so it fits nicely into the document, some \"thumbnails\" are\n\t// actually the full size photo. If thumbnails not found, use full image.\n\tconst imageUrl = photo.thumbnail_url || photo.url;\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"]}
|
|
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"],"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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,MAAM;AAAEC,EAAAA,IAAI,EAAEC;AAAR,IAAgCC,QAAtC;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,sBAAsB,GAAKC,QAAF;AAAA;;AAAA,gCACrC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,IAAAA,aAAa,EAAEC;AAAvB,MAAwC1C,OAA9C;AACA,QAAME,gBAAgB,GAAGlC,SAAS,CACjC,CAAE0E,YAAY,IAAI9C,KAAlB,EAA0B+C,WAA1B,EADiC,CAAlC;;AAIA,MAAKvD,eAAe,CAAEC,IAAF,CAApB,EAA+B;AAC9Bc,IAAAA,IAAI,GAAGpC,aAAP;AACA;;AAED,MAAKsB,IAAI,IAAI,YAAYc,IAAzB,EAAgC;AAC/BF,IAAAA,UAAU,CAACE,IAAX,GAAkBA,IAAlB;AACAF,IAAAA,UAAU,CAACC,gBAAX,GAA8BA,gBAA9B;AACA;;AAEDD,EAAAA,UAAU,CAACa,SAAX,GAAuBC,aAAa,CACnC1B,IADmC,EAEnCkD,iBAFmC,EAGnCC,YAAY,IAAIxB,eAHmB,CAApC;AAMA,SAAOf,UAAP;AACA,CAtC6C,CAAxC;AAyCP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAM2C,8BAA8B,GAAG,UAC7CC,iBAD6C,EAE7C7C,OAF6C,EAG7CJ,KAH6C,EAI7C4C,YAJ6C,EAMzC;AAAA,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"]}
|
|
@@ -58,7 +58,7 @@ export default function FileBlockInspector(_ref) {
|
|
|
58
58
|
value: previewHeight,
|
|
59
59
|
onChange: changePreviewHeight
|
|
60
60
|
})), createElement(PanelBody, {
|
|
61
|
-
title: __('
|
|
61
|
+
title: __('Settings')
|
|
62
62
|
}, createElement(SelectControl, {
|
|
63
63
|
label: __('Link to'),
|
|
64
64
|
value: textLinkHref,
|
|
@@ -68,9 +68,7 @@ export default function FileBlockInspector(_ref) {
|
|
|
68
68
|
label: __('Open in new tab'),
|
|
69
69
|
checked: openInNewWindow,
|
|
70
70
|
onChange: changeOpenInNewWindow
|
|
71
|
-
})
|
|
72
|
-
title: __('Download button settings')
|
|
73
|
-
}, createElement(ToggleControl, {
|
|
71
|
+
}), createElement(ToggleControl, {
|
|
74
72
|
label: __('Show download button'),
|
|
75
73
|
checked: showDownloadButton,
|
|
76
74
|
onChange: changeShowDownloadButton
|