From 1f753c81fe6b3ea5858890bf5da8173a5fe56c41 Mon Sep 17 00:00:00 2001 From: Brandon Date: Mon, 11 Mar 2019 18:52:33 -0400 Subject: finished kvp? --- src/client/views/nodes/KeyValueBox.tsx | 36 ++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/client/views/nodes/KeyValueBox.tsx b/src/client/views/nodes/KeyValueBox.tsx index 8025f00d6..7de5bda92 100644 --- a/src/client/views/nodes/KeyValueBox.tsx +++ b/src/client/views/nodes/KeyValueBox.tsx @@ -16,6 +16,7 @@ import { Key } from '../../../fields/Key'; import { TextField } from '../../../fields/TextField'; import { EditorView } from "prosemirror-view"; import { IReactionDisposer } from "mobx"; +import { observable, action } from "mobx"; @observer export class KeyValueBox extends React.Component { @@ -26,16 +27,14 @@ export class KeyValueBox extends React.Component { private _reactionDisposer: Opt; private _newKey = ''; private _newValue = ''; + @observable private _keyInput: string = ""; + @observable private _valueInput: string = ""; constructor(props: FieldViewProps) { super(props); this._ref = React.createRef(); - this.state = { - key: '', - value: '' - } } @@ -52,13 +51,22 @@ export class KeyValueBox extends React.Component { return } let realDoc = doc; - realDoc.Set(new Key(this._newKey), new TextField(this._newValue)); - if (this.refs.newKVPKey instanceof HTMLInputElement) { - this.refs.newKVPKey.value = '' + + let script = CompileScript(this._newValue, undefined, true); + if (!script.compiled) { + return; } - if (this.refs.newKVPValue instanceof HTMLInputElement) { - this.refs.newKVPValue.value = '' + let field = script(); + if (field instanceof Field) { + realDoc.Set(new Key(this._newKey), field); + } else { + let dataField = ToField(field); + if (dataField) { + realDoc.Set(new Key(this._newKey), field); + } } + this._keyInput = "" + this._valueInput = "" this._newKey = '' this._newValue = '' } @@ -99,19 +107,21 @@ export class KeyValueBox extends React.Component { return rows; } + @action keyChanged = (e: React.ChangeEvent) => { - this._newKey = e.currentTarget.value; + this._keyInput = e.currentTarget.value; } + @action valueChanged = (e: React.ChangeEvent) => { - this._newValue = e.currentTarget.value; + this._valueInput = e.currentTarget.value; } newKeyValue = () => { return ( - - + + ) } -- cgit v1.2.3-70-g09d2