import React = require("react"); import { computed } from "mobx"; import { observer } from "mobx-react"; import { DateField } from "../../../fields/DateField"; import { Doc, Field, FieldResult, Opt } from "../../../fields/Doc"; import { List } from "../../../fields/List"; import { VideoField, WebField } from "../../../fields/URLField"; import { DocumentViewSharedProps } from "./DocumentView"; import { VideoBox } from "./VideoBox"; // // 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 extends DocumentViewSharedProps { // FieldView specific props that are not part of DocumentView props fieldKey: string; scrollOverflow?: boolean; // bcz: would like to think this can be avoided -- need to look at further select: (isCtrlPressed: boolean) => void; isContentActive: (outsideReaction?: boolean) => boolean; isSelected: (outsideReaction?: boolean) => boolean; scaling?: () => number; setHeight: (height: number) => void; // properties intended to be used from within layout strings (otherwise use the function equivalents that work more efficiently with React) pointerEvents?: string; fontSize?: number; 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?.toString()}

; } else if (field instanceof List) { return
{field.length ? 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 WebField) { return

{Field.toString(field.url.href)}

; } else if (!(field instanceof Promise)) { return

{Field.toString(field)}

; } else { return

{"Waiting for server..."}

; } } }