From 6a3407a2d70542752305e4360fec0dffcc1a2dfa Mon Sep 17 00:00:00 2001 From: Tyler Schicke Date: Wed, 13 Mar 2019 16:32:20 -0400 Subject: Made document contents class --- src/client/views/nodes/DocumentView.tsx | 63 ++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx index 77aadabdf..a91d2071b 100644 --- a/src/client/views/nodes/DocumentView.tsx +++ b/src/client/views/nodes/DocumentView.tsx @@ -85,10 +85,27 @@ export function FakeJsxArgs(keys: string[], fields: string[] = []): JsxArgs { return args; } +interface JsxBindings { + Document: Document; + layout: string; + [prop: string]: any; +} + +export class DocumentContents extends React.PureComponent { + render() { + return { console.log(test) }} + /> + } +} + @observer export class DocumentView extends React.Component { private _mainCont = React.createRef(); - private _documentBindings: any = null; private _downX: number = 0; private _downY: number = 0; private _reactionDisposer: Opt; @@ -276,16 +293,6 @@ export class DocumentView extends React.Component { SelectionManager.SelectDoc(this, e.ctrlKey); } - @computed - get mainContent() { - return { console.log(test) }} - /> - } isSelected = () => { return SelectionManager.IsSelected(this); @@ -295,28 +302,34 @@ export class DocumentView extends React.Component { SelectionManager.SelectDoc(this, ctrlPressed) } - render() { - if (!this.props.Document) { - return (null); - } - let lkeys = this.props.Document.GetT(KeyStore.LayoutKeys, ListField); - if (!lkeys || lkeys === "") { - return

Error loading layout keys

; - } - this._documentBindings = { + @computed + get getProps() { + let bindings: any = { ...this.props, isSelected: this.isSelected, select: this.select, - focus: this.props.focus + layout: this.layout }; for (const key of this.layoutKeys) { - this._documentBindings[key.Name + "Key"] = key; // this maps string values of the form Key to an actual key Kestore.keyname e.g, "DataKey" => KeyStore.Data + bindings[key.Name + "Key"] = key; // this maps string values of the form Key to an actual key Kestore.keyname e.g, "DataKey" => KeyStore.Data } for (const key of this.layoutFields) { let field = this.props.Document.Get(key); - this._documentBindings[key.Name] = field && field != FieldWaiting ? field.GetValue() : field; + bindings[key.Name] = field && field != FieldWaiting ? field.GetValue() : field; + } + bindings.bindings = bindings; + + return bindings + } + + render() { + if (!this.props.Document) { + return (null); + } + let lkeys = this.props.Document.GetT(KeyStore.LayoutKeys, ListField); + if (!lkeys || lkeys === "") { + return

Error loading layout keys

; } - this._documentBindings.bindings = this._documentBindings; var scaling = this.props.ContentScaling(); var nativeWidth = this.props.Document.GetNumber(KeyStore.NativeWidth, 0); var nativeHeight = this.props.Document.GetNumber(KeyStore.NativeHeight, 0); @@ -330,7 +343,7 @@ export class DocumentView extends React.Component { }} onContextMenu={this.onContextMenu} onPointerDown={this.onPointerDown} > - {this.mainContent} + ) } -- cgit v1.2.3-70-g09d2