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 * as Actions from "~/common/actions"; import UnityFrame from "~/components/core/UnityFrame"; import FontFrame from "~/components/core/FontFrame/index.js"; import MarkdownFrame from "~/components/core/MarkdownFrame"; import SlateLinkObject from "~/components/core/SlateLinkObject"; 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() { const file = this.props.file; if (this.props.isMobile) { 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 type = file.data.type || ""; if (file.isLink) { return ; } const url = Strings.getURLfromCID(file.cid); const playType = typeMap[type] ? typeMap[type] : type; let element =
No Preview
; if (Validations.isPdfType(type)) { return ( <> {isMobile ? (
Tap to open PDF in new tab
) : ( { e.stopPropagation(); }} /> )} ); } if (Validations.isVideoType(type)) { return ( ); } if (Validations.isAudioType(type)) { return (
); } if (type.startsWith("text/html")) { return