import React = require("react") import { Document } from "../../fields/Document"; import { observer } from "mobx-react"; import { computed } from "mobx"; import { Field, Opt } from "../../fields/Field"; import { TextField } from "../../fields/TextField"; import { NumberField } from "../../fields/NumberField"; import { RichTextField } from "../../fields/RichTextField"; import { FormattedTextBox } from "./FormattedTextBox"; import { ImageField } from "../../fields/ImageField"; import { ImageBox } from "./ImageBox"; import { Key } from "../../fields/Key"; import { DocumentView } from "./DocumentView"; // // 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: Key; doc: Document; DocumentViewForField: Opt } @observer export class FieldView extends React.Component { public static LayoutString(fieldType: string) { return `<${fieldType} doc={Document} DocumentViewForField={DocumentView} fieldKey={DataKey} />`; } @computed get field(): Opt { const { doc, fieldKey } = this.props; return doc.GetField(fieldKey); } render() { const field = this.field; if (!field) { return

{''}

} if (field instanceof TextField) { return

{field.Data}

} else if (field instanceof RichTextField) { return } else if (field instanceof ImageField) { return } else if (field instanceof NumberField) { return

{field.Data}

} else { return

{field.GetValue}

} } }