import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { action, observable, computed } from 'mobx'; import { observer } from 'mobx-react'; import "normalize.css"; import * as React from 'react'; import { Doc, Opt } from '../../fields/Doc'; import { emptyFunction, emptyPath, returnEmptyDoclist, returnEmptyFilter, returnFalse, returnTrue } from '../../Utils'; import { Transform } from '../util/Transform'; import "./LightboxView.scss"; import { DocumentView } from './nodes/DocumentView'; import { DefaultStyleProvider } from './StyleProvider'; import { DocUtils } from '../documents/Documents'; import { DocumentManager } from '../util/DocumentManager'; interface LightboxViewProps { PanelWidth: number; PanelHeight: number; maxBorder: number[]; } @observer export class LightboxView extends React.Component { @observable static LightboxDoc: Opt; @action public static SetLightboxDoc(doc: Opt, future?: Doc[]) { LightboxView.LightboxDoc = doc; if (!doc) { LightboxView.LightboxFuture = LightboxView.LightboxHistory = []; } else if (future) { LightboxView.LightboxFuture = future; } return true; } public static IsLightboxDocView(path: DocumentView[]) { return path.includes(LightboxView.LightboxDocView.current!); } public static LightboxHistory: (Opt)[] = []; public static LightboxFuture: (Opt)[] = []; public static LightboxDocView = React.createRef(); @computed get leftBorder() { return Math.min(this.props.PanelWidth / 4, this.props.maxBorder[0]); } @computed get topBorder() { return Math.min(this.props.PanelHeight / 4, this.props.maxBorder[1]); } lightboxWidth = () => this.props.PanelWidth - this.leftBorder * 2; lightboxHeight = () => this.props.PanelHeight - this.topBorder * 2; lightboxScreenToLocal = () => new Transform(-this.leftBorder, -this.topBorder, 1); navBtn = (left: Opt, icon: string, display: () => string, click: (e: React.MouseEvent) => void) => { return
; } render() { if (LightboxView.LightboxHistory.lastElement() !== LightboxView.LightboxDoc) LightboxView.LightboxHistory.push(LightboxView.LightboxDoc); let downx = 0, downy = 0; return !LightboxView.LightboxDoc ? (null) :
{ downx = e.clientX; downy = e.clientY; }} onClick={e => { if (Math.abs(downx - e.clientX) < 4 && Math.abs(downy - e.clientY) < 4) { LightboxView.SetLightboxDoc(undefined); } }} >
{this.navBtn(undefined, "chevron-left", () => LightboxView.LightboxDoc && LightboxView.LightboxHistory.length ? "" : "none", e => { e.stopPropagation(); const previous = LightboxView.LightboxHistory.pop(); const target = LightboxView.LightboxHistory.lastElement(); const docView = target && DocumentManager.Instance.getLightboxDocumentView(target); if (docView && target) { if (LightboxView.LightboxFuture.lastElement() !== previous) LightboxView.LightboxFuture.push(previous); docView.focus(target, true, 0.9); } else { LightboxView.SetLightboxDoc(target); } })} {this.navBtn(this.props.PanelWidth - Math.min(this.props.PanelWidth / 4, this.props.maxBorder[0]), "chevron-right", () => LightboxView.LightboxDoc && LightboxView.LightboxFuture.length ? "" : "none", e => { e.stopPropagation(); const target = LightboxView.LightboxFuture.pop(); const docView = target && DocumentManager.Instance.getLightboxDocumentView(target); if (docView && target) { docView.focus(target, true, 0.9); if (LightboxView.LightboxHistory.lastElement() !== target) LightboxView.LightboxHistory.push(target); } else { LightboxView.SetLightboxDoc(target); } })}
; } }