import { action, computed, IReactionDisposer, reaction, runInAction } from "mobx"; import { observer } from "mobx-react"; import { Document } from "../../../fields/Document"; import { Field, Opt, FieldWaiting } from "../../../fields/Field"; import { Key } from "../../../fields/Key"; import { KeyStore } from "../../../fields/KeyStore"; import { ListField } from "../../../fields/ListField"; import { TextField } from "../../../fields/TextField"; import { Utils } from "../../../Utils"; import { Documents } from "../../documents/Documents"; import { DocumentManager } from "../../util/DocumentManager"; import { DragManager } from "../../util/DragManager"; import { SelectionManager } from "../../util/SelectionManager"; import { Transform } from "../../util/Transform"; import { CollectionDockingView } from "../collections/CollectionDockingView"; import { CollectionView, CollectionViewType } from "../collections/CollectionView"; import { ContextMenu } from "../ContextMenu"; import { DocumentContentsView } from "./DocumentContentsView"; import { Template } from "./../Templates" import "./DocumentView.scss"; import React = require("react"); import { ServerUtils } from "../../../server/ServerUtil"; export interface DocumentViewProps { ContainingCollectionView: Opt; Document: Document; AddDocument?: (doc: Document, allowDuplicates: boolean) => boolean; RemoveDocument?: (doc: Document) => boolean; ScreenToLocalTransform: () => Transform; isTopMost: boolean; ContentScaling: () => number; PanelWidth: () => number; PanelHeight: () => number; focus: (doc: Document) => void; SelectOnLoad: boolean; } export interface JsxArgs extends DocumentViewProps { Keys: { [name: string]: Key } Fields: { [name: string]: Field } } /* This function is pretty much a hack that lets us fill out the fields in JsxArgs with something that jsx-to-string can recover the jsx from Example usage of this function: public static LayoutString() { let args = FakeJsxArgs(["Data"]); return jsxToString( , { useFunctionCode: true, functionNameOnly: true } ) } */ export function FakeJsxArgs(keys: string[], fields: string[] = []): JsxArgs { let Keys: { [name: string]: any } = {} let Fields: { [name: string]: any } = {} for (const key of keys) { let fn = () => { } Object.defineProperty(fn, "name", { value: key + "Key" }) Keys[key] = fn; } for (const field of fields) { let fn = () => { } Object.defineProperty(fn, "name", { value: field }) Fields[field] = fn; } let args: JsxArgs = { Document: function Document() { }, DocumentView: function DocumentView() { }, Keys, Fields } as any; return args; } export interface JsxBindings { Document: Document; isSelected: () => boolean; select: (isCtrlPressed: boolean) => void; isTopMost: boolean; SelectOnLoad: boolean; [prop: string]: any; } @observer export class DocumentView extends React.Component { private _mainCont = React.createRef(); private _downX: number = 0; private _downY: number = 0; private _reactionDisposer: Opt; private _templates: Set