import * as React from "react"; import * as Constants from "~/common/constants"; import * as Validations from "~/common/validations"; import * as Events from "~/common/custom-events"; import * as Strings from "~/common/strings"; import UnityFrame from "~/components/core/UnityFrame"; import FontFrame from "~/components/core/FontFrame/index.js"; import MarkdownFrame from "~/components/core/MarkdownFrame"; import { endsWithAny } from "~/common/utilities"; import { css } from "@emotion/react"; const STYLES_FAILURE = css` color: ${Constants.system.white}; display: flex; align-items: center; justify-content: center; font-size: 24px; margin: 0; padding: 24px 36px; height: 100px; border-radius: 4px; width: 100%; min-height: 10%; height: 100%; text-decoration: none; background-color: rgba(20, 20, 20, 0.8); `; const STYLES_OBJECT = css` display: block; margin: 0; padding: 0; width: 100%; min-height: 10%; height: 100%; user-select: none; `; const STYLES_ASSET = css` user-select: none; width: 100%; margin: 0; padding: 0; min-height: 10%; height: 100%; display: flex; align-items: center; justify-content: center; position: relative; `; const STYLES_IMAGE = css` user-select: none; display: block; max-width: 100%; max-height: 100%; `; const STYLES_IFRAME = (theme) => css` display: block; width: 100%; height: 100%; // NOTE(Amine): lightbackground as fallback when html file doesn't have any background-color: ${theme.system.grayLight6}; `; const typeMap = { "video/quicktime": "video/mp4", }; export default class SlateMediaObject extends React.Component { openLink = (url) => { window.open(url, "_blank"); }; componentDidMount() { if (this.props.isMobile) { const file = this.props.file; if (file.data.type && file.data.type.startsWith("application/pdf")) { const url = Strings.getURLfromCID(file.cid); this.openLink(url); } } } render() { const { file, isMobile } = this.props; const url = Strings.getURLfromCID(file.cid); const type = file.data.type || ""; const playType = typeMap[type] ? typeMap[type] : type; let element =
No Preview
; if (type.startsWith("application/pdf")) { return ( <> {isMobile ? (
Tap to open PDF in new tab
) : ( { e.stopPropagation(); }} /> )} ); } if (type.startsWith("video/")) { return ( ); } if (type.startsWith("audio/")) { return (
); } if (type.startsWith("text/html")) { return