import React = require("react"); import { computed } from "mobx"; import { observer } from "mobx-react"; import { DateField } from "../../../fields/DateField"; import { Doc, FieldResult, Opt, Field } from "../../../fields/Doc"; import { List } from "../../../fields/List"; import { ScriptField } from "../../../fields/ScriptField"; import { AudioField, VideoField } from "../../../fields/URLField"; import { Transform } from "../../util/Transform"; import { CollectionView } from "../collections/CollectionView"; import { AudioBox } from "./AudioBox"; import { VideoBox } from "./VideoBox"; import { dropActionType } from "../../util/DragManager"; // // these properties get assigned through the render() method of the DocumentView when it creates this node. // However, that only happens because the properties are "defined" in the markup for the field view. // See the LayoutString method on each field view : ImageBox, FormattedTextBox, etc. // export interface FieldViewProps { fieldKey: string; fitToBox?: boolean; ContainingCollectionView: Opt; ContainingCollectionDoc: Opt; Document: Doc; DataDoc?: Doc; LibraryPath: Doc[]; onClick?: ScriptField; dropAction: dropActionType; isSelected: (outsideReaction?: boolean) => boolean; select: (isCtrlPressed: boolean) => void; rootSelected: (outsideReaction?: boolean) => boolean; renderDepth: number; addDocument?: (document: Doc | Doc[]) => boolean; addDocTab: (document: Doc, where: string) => boolean; pinToPres: (document: Doc) => void; removeDocument?: (document: Doc | Doc[]) => boolean; moveDocument?: (document: Doc | Doc[], targetCollection: Doc | undefined, addDocument: (document: Doc | Doc[]) => boolean) => boolean; backgroundColor?: (document: Doc) => string | undefined; ScreenToLocalTransform: () => Transform; bringToFront: (doc: Doc, sendToBack?: boolean) => void; active: (outsideReaction?: boolean) => boolean; whenActiveChanged: (isActive: boolean) => void; dontRegisterView?: boolean; focus: (doc: Doc) => void; ignoreAutoHeight?: boolean; PanelWidth: () => number; PanelHeight: () => number; NativeHeight: () => number; NativeWidth: () => number; setVideoBox?: (player: VideoBox) => void; ContentScaling: () => number; ChromeHeight?: () => number; // properties intended to be used from within layout strings (otherwise use the function equivalents that work more efficiently with React) height?: number; width?: number; background?: string; color?: string; xMargin?: number; yMargin?: number; } @observer export class FieldView extends React.Component { public static LayoutString(fieldType: { name: string }, fieldStr: string) { return `<${fieldType.name} {...props} fieldKey={'${fieldStr}'}/>`; //e.g., "" } @computed get field(): FieldResult { const { Document, fieldKey } = this.props; return Document[fieldKey]; } render() { const field = this.field; if (field === undefined) { return

{''}

; } // if (typeof field === "string") { // return

{field}

; // } // else if (field instanceof RichTextField) { // return ; // } // else if (field instanceof ImageField) { // return ; // } // else if (field instaceof PresBox) { // return ; // } else if (field instanceof VideoField) { return ; } else if (field instanceof AudioField) { return ; } else if (field instanceof DateField) { return

{field.date.toLocaleString()}

; } else if (field instanceof Doc) { return

{field.title && field.title.toString()}

; //return

{field.title + " : id= " + field[Id]}

; // let returnHundred = () => 100; // return ( // // ); } else if (field instanceof List) { return
{field.map(f => Field.toString(f)).join(", ")}
; } // bcz: this belongs here, but it doesn't render well so taking it out for now // else if (field instanceof HtmlField) { // return // } else if (!(field instanceof Promise)) { return

{Field.toString(field)}

; } else { return

{"Waiting for server..."}

; } } }