UNPKG

@wordpress/block-library

Version:
141 lines (139 loc) 3.49 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _clsx = _interopRequireDefault(require("clsx")); var _blockEditor = require("@wordpress/block-editor"); var _jsxRuntime = require("react/jsx-runtime"); /** * External dependencies */ /** * Internal dependencies */ const metadata = { $schema: "https://schemas.wp.org/trunk/block.json", apiVersion: 3, name: "core/embed", title: "Embed", category: "embed", description: "Add a block that displays content pulled from other sites, like Twitter or YouTube.", textdomain: "default", attributes: { url: { type: "string", role: "content" }, caption: { type: "rich-text", source: "rich-text", selector: "figcaption", role: "content" }, type: { type: "string", role: "content" }, providerNameSlug: { type: "string", role: "content" }, allowResponsive: { type: "boolean", "default": true }, responsive: { type: "boolean", "default": false, role: "content" }, previewable: { type: "boolean", "default": true, role: "content" } }, supports: { align: true, spacing: { margin: true }, interactivity: { clientNavigation: true } }, editorStyle: "wp-block-embed-editor", style: "wp-block-embed" }; /** * WordPress dependencies */ const { attributes: blockAttributes } = metadata; // In #41140 support was added to global styles for caption elements which added a `wp-element-caption` classname // to the embed figcaption element. const v2 = { attributes: blockAttributes, save({ attributes }) { const { url, caption, type, providerNameSlug } = attributes; if (!url) { return null; } const className = (0, _clsx.default)('wp-block-embed', { [`is-type-${type}`]: type, [`is-provider-${providerNameSlug}`]: providerNameSlug, [`wp-block-embed-${providerNameSlug}`]: providerNameSlug }); return /*#__PURE__*/(0, _jsxRuntime.jsxs)("figure", { ..._blockEditor.useBlockProps.save({ className }), children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", { className: "wp-block-embed__wrapper", children: `\n${url}\n` /* URL needs to be on its own line. */ }), !_blockEditor.RichText.isEmpty(caption) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.RichText.Content, { tagName: "figcaption", value: caption })] }); } }; const v1 = { attributes: blockAttributes, save({ attributes: { url, caption, type, providerNameSlug } }) { if (!url) { return null; } const embedClassName = (0, _clsx.default)('wp-block-embed', { [`is-type-${type}`]: type, [`is-provider-${providerNameSlug}`]: providerNameSlug }); return /*#__PURE__*/(0, _jsxRuntime.jsxs)("figure", { className: embedClassName, children: [`\n${url}\n` /* URL needs to be on its own line. */, !_blockEditor.RichText.isEmpty(caption) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.RichText.Content, { tagName: "figcaption", value: caption })] }); } }; const deprecated = [v2, v1]; var _default = exports.default = deprecated; //# sourceMappingURL=deprecated.js.map