UNPKG

@wordpress/block-editor

Version:
64 lines (62 loc) 2.26 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // packages/block-editor/src/components/inserter/media-tab/utils.js var utils_exports = {}; __export(utils_exports, { getBlockAndPreviewFromMedia: () => getBlockAndPreviewFromMedia }); module.exports = __toCommonJS(utils_exports); var import_blocks = require("@wordpress/blocks"); var import_jsx_runtime = require("react/jsx-runtime"); var mediaTypeTag = { image: "img", video: "video", audio: "audio" }; function getBlockAndPreviewFromMedia(media, mediaType) { const attributes = { id: media.id || void 0, caption: media.caption || void 0 }; const mediaSrc = media.url; const alt = media.alt || void 0; if (mediaType === "image") { attributes.url = mediaSrc; attributes.alt = alt; } else if (["video", "audio"].includes(mediaType)) { attributes.src = mediaSrc; } const PreviewTag = mediaTypeTag[mediaType]; const preview = /* @__PURE__ */ (0, import_jsx_runtime.jsx)( PreviewTag, { src: media.previewUrl || mediaSrc, alt, controls: mediaType === "audio" ? true : void 0, inert: "true", onError: ({ currentTarget }) => { if (currentTarget.src === media.previewUrl) { currentTarget.src = mediaSrc; } } } ); return [(0, import_blocks.createBlock)(`core/${mediaType}`, attributes), preview]; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { getBlockAndPreviewFromMedia }); //# sourceMappingURL=utils.js.map