import * as React from "react"; import * as Constants from "~/common/constants"; import * as SVG from "~/common/svg"; import { css } from "@emotion/react"; import { ProcessedText } from "~/components/system/components/Typography"; import { Boundary } from "~/components/system/components/fragments/Boundary"; import { PopoverNavigation } from "~/components/system/components/PopoverNavigation"; import { TooltipWrapper } from "~/components/system/components/fragments/GlobalTooltip"; import { dispatchCustomEvent } from "~/common/custom-events"; import SlateMediaObjectPreview from "~/components/core/SlateMediaObjectPreview"; const MARGIN = 12; const MIN_WIDTH = 144; const STYLES_MOBILE_HIDDEN = css` @media (max-width: ${Constants.sizes.mobile}px) { display: none; } `; const STYLES_MOBILE_ONLY = css` @media (min-width: ${Constants.sizes.mobile}px) { display: none; } `; const STYLES_CREATE_NEW = css` color: ${Constants.system.darkGray}; box-shadow: 0px 0px 0px 1px rgba(229, 229, 229, 0.5) inset; display: flex; flex-direction: column; align-items: center; justify-content: center; width: 160px; height: 160px; margin: 0px ${MARGIN}px; @media (max-width: ${Constants.sizes.mobile}px) { margin: 0; border-radius: 8; width: 100%; height: 100%; } `; const STYLES_IMAGE_ROW = css` display: flex; flex-direction: row; flex-wrap: wrap; height: 160px; ${"" /* justify-content: space-between; */} overflow: hidden; margin: 0 -${MARGIN}px; @media (max-width: ${Constants.sizes.mobile}px) { justify-content: center; margin: 0 -8px; } `; const STYLES_ITEM_BOX = css` width: 160px; height: 160px; margin: 0px ${MARGIN}px; display: flex; align-items: center; justify-content: center; box-shadow: 0px 0px 0px 1px ${Constants.system.lightBorder} inset; cursor: pointer; @media (max-width: ${Constants.sizes.mobile}px) { margin: 0 8px; } :hover { color: ${Constants.system.brand}; } `; const STYLES_EMPTY_BOX = css` width: 160px; height: 160px; margin: 0px ${MARGIN}px; @media (max-width: ${Constants.sizes.mobile}px) { margin: 0 8px; } `; const STYLES_IMAGE_ROW_SMALL = css` display: flex; flex-direction: row; flex-wrap: wrap; height: 56px; overflow: hidden; margin: 0 -8px; `; const STYLES_ITEM_BOX_SMALL = css` width: 56px; height: 56px; margin: 0px 8px; display: flex; align-items: center; justify-content: center; box-shadow: 0px 0px 0px 1px ${Constants.system.lightBorder} inset; `; const STYLES_EMPTY_BOX_SMALL = css` width: 56px; height: 56px; margin: 0px 8px; `; export class SlatePreviewRow extends React.Component { render() { let numItems = this.props.numItems || 5; let objects; if (this.props.slate.data.objects.length === 0) { objects = [
Add Files
, ]; } else { let trimmed = this.props.slate.data.objects.length > numItems ? this.props.slate.data.objects.slice(0, numItems) : this.props.slate.data.objects; objects = trimmed.map((each) => (
)); } // let numExtra = this.props.numItems // ? this.props.numItems - objects.length // : 5 - objects.length; // let extra = []; // for (let i = 0; i < numExtra; i++) { // extra.push( //
// ); // } return (
{objects} {/* {extra} */}
); } } const STYLES_BLOCK = css` box-shadow: 0 0 0 1px ${Constants.system.lightBorder} inset, 0 0 40px 0 ${Constants.system.shadow}; border-radius: 8px; padding: 32px 40px; font-size: 12px; text-align: left; margin: 24px auto 48px auto; max-width: ${Constants.sizes.desktop}px; cursor: pointer; @media (max-width: ${Constants.sizes.mobile}px) { padding: 16px; margin: 24px auto; } `; const STYLES_TITLE_LINE = css` width: 100%; display: flex; align-items: center; font-size: ${Constants.typescale.lvl1}; margin-bottom: 16px; overflow-wrap: break-word; @media (max-width: ${Constants.sizes.mobile}px) { display: none; } `; const STYLES_COPY_INPUT = css` pointer-events: none; position: absolute; opacity: 0; `; const STYLES_TAG = css` margin-right: 16px; padding: 4px 8px; border-radius: 2px; border: 1px solid ${Constants.system.black}; color: ${Constants.system.black}; font-family: ${Constants.font.semiBold}; font-size: 0.9rem; `; const STYLES_BODY = css` font-family: ${Constants.font.text}; font-size: 0.9rem; margin-bottom: 24px; line-height: 20px; white-space: pre-wrap; word-wrap: break-word; @media (max-width: ${Constants.sizes.mobile}px) { display: none; } `; const STYLES_ICON_BOX = css` height: 32px; width: 32px; display: flex; align-items: center; justify-content: center; position: relative; color: ${Constants.system.darkGray}; `; const STYLES_CONTEXT_MENU = css` position: absolute; `; const STYLES_TITLE = css` font-size: ${Constants.typescale.lvl2}; font-family: ${Constants.font.semiBold}; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-right: 16px; `; export class SlatePreviewBlock extends React.Component { _ref; _test; state = { showMenu: false, copyValue: "", windowWidth: 360, }; componentDidMount = () => { this.calculateWidth(); window.addEventListener("resize", this.calculateWidth); }; componentWillUnmount = () => { window.removeEventListener("resize", this.calculateWidth); }; calculateWidth = () => { this.setState({ windowWidth: window.innerWidth }); }; _handleCopy = (e, value) => { e.stopPropagation(); this.setState({ copyValue: value }, () => { this._ref.select(); document.execCommand("copy"); this._handleHide(); }); }; _handleClick = (e) => { e.stopPropagation(); if (this.state.showMenu) { this._handleHide(); return; } this.setState({ showMenu: true }); // dispatchCustomEvent({ // name: "show-tooltip", // detail: { // id: `slate-tooltip-${this.props.slate.id}`, // }, // }); }; _handleHide = (e) => { this.setState({ showMenu: false }); // dispatchCustomEvent({ // name: "hide-tooltip", // detail: { // id: `slate-tooltip-${this.props.slate.id}`, // }, // }); }; render() { if (!this.props.isOwner && !this.props.slate.data.objects.length) { return null; } let first = this.props.slate.data.objects ? this.props.slate.data.objects[0] : null; let contextMenu = ( this._handleCopy( e, `${window.location.hostname}/${this.props.username}/${this.props.slate.slatename}` ), }, { text: "Copy slate ID", onClick: (e) => this._handleCopy(e, this.props.slate.id), }, ] : [ { text: "Copy URL", onClick: (e) => this._handleCopy( e, `${window.location.hostname}/${this.props.username}/${this.props.slate.slatename}` ), }, ] } /> { this._ref = c; }} value={this.state.copyValue} css={STYLES_COPY_INPUT} /> ); return (
{this.props.slate.data.name}
{this.props.isOwner ? ( this.props.slate.data.public ? (
Public
) : (
Private
) ) : (
)} {this.props.external ? null : this.props.username ? (
{ this._test = c; }} > {/* */}
{this.state.showMenu ?
{contextMenu}
: null}
{/*
*/}
) : null}
{this.props.slate.data.body ? (
) : (
)}
{this.props.slate.data.name}
{this.props.slate.data.objects.length} Object {this.props.slate.data.objects.length === 1 ? "" : "s"}
{first ? ( ) : (
Add Files
)}
); } } const STYLES_LINK = css` color: ${Constants.system.black}; text-decoration: none; `; export default class SlatePreviewBlocks extends React.Component { state = { imageSize: 56, }; componentDidMount = () => { this.calculateWidth(); this.debounceInstance = this.debounce(this.calculateWidth, 350); window.addEventListener("resize", this.debounceInstance); }; componentWillUnmount = () => { window.removeEventListener("resize", this.debounceInstance); }; debounce = (fn, time) => { let timer; return () => { window.clearTimeout(timer); timer = window.setTimeout(fn, time); }; }; calculateWidth = () => { let windowWidth = window.innerWidth; if (windowWidth > Constants.sizes.mobile) { if (this.props.external) { windowWidth -= 48; } else { windowWidth -= Constants.sizes.navigation + 96; } windowWidth = Math.min(windowWidth, Constants.sizes.desktop); windowWidth -= 80; //NOTE(martina): 48px padding on scene page, 40px padding on block for (let i = this.props.numItems || 5; i > 0; i--) { let width = (windowWidth - MARGIN * 2 * (i - 1)) / i; if (width < MIN_WIDTH) { continue; } this.setState({ imageSize: width }); return; } } this.setState({ imageSize: windowWidth - 48 - 32 }); //NOTE(martina): 24px padding on scene page, 16px padding on block on mobile }; render() { if (this.props.external) { return this.props.slates.map((slate) => ( )); } return this.props.slates.map((slate) => (
this.props.onAction({ type: "NAVIGATE", value: "V1_NAVIGATION_SLATE", data: { decorator: "SLATE", ...slate }, }) } >
)); } }