From 7b8651a1a1f824e6c6a5135a4420766686f35175 Mon Sep 17 00:00:00 2001 From: anika-ahluwalia Date: Wed, 29 Apr 2020 17:20:37 -0500 Subject: parameters now editable and partial drag and drop --- src/client/views/nodes/ScriptingBox.tsx | 55 ++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 21 deletions(-) (limited to 'src/client/views/nodes/ScriptingBox.tsx') diff --git a/src/client/views/nodes/ScriptingBox.tsx b/src/client/views/nodes/ScriptingBox.tsx index 0d6f688c8..f810d178c 100644 --- a/src/client/views/nodes/ScriptingBox.tsx +++ b/src/client/views/nodes/ScriptingBox.tsx @@ -14,6 +14,7 @@ import "./ScriptingBox.scss"; import { OverlayView } from "../OverlayView"; import { DocumentIconContainer } from "./DocumentIcon"; import { List } from "../../../new_fields/List"; +import { DragManager } from "../../util/DragManager"; const ScriptingSchema = createSchema({}); type ScriptingDocument = makeInterface<[typeof ScriptingSchema, typeof documentSchema]>; @@ -30,7 +31,8 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent void; @observable private _errorMessage: string = ""; - @observable private paramNum: number = -1; + @observable private _paramNum: number = 0; + @observable private _dropped: boolean = false; @computed get rawScript() { return StrCast(this.dataDoc[this.props.fieldKey + "-rawScript"], StrCast(this.layoutDoc[this.props.fieldKey + "-rawScript"])); } @computed get compileParams() { return Cast(this.dataDoc[this.props.fieldKey + "-params"], listSpec("string"), Cast(this.layoutDoc[this.props.fieldKey + "-params"], listSpec("string"), [])); } @@ -120,14 +122,17 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent, { x: 0, y: 0 }); } - keyPressed(event: { key: string; }) { - if (event.key === "Enter") { + onDrop = (e: Event, de: DragManager.DropEvent, index: any) => { + this._dropped = true; + const firstParam = this.compileParams[index].split("="); + this.compileParams[index] = firstParam[0] + " = " + de.complete.docDragData?.droppedDocuments[0]; + } - } + onDelete = (parameter: any) => { + this.compileParams.filter(s => s !== parameter); } render() { - //this.compileParams = new List(); const params = ""} SetValue={value => { if (value !== "" && value !== " ") { - this.paramNum++; + this._paramNum++; const par = this.compileParams; this.compileParams = new List(value.split(";").filter(s => s !== " ")); this.compileParams.push.apply(this.compileParams, par); @@ -148,20 +153,28 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent; - const listParams = this.compileParams.map((parameter) => - parameter} - SetValue={value => { - if (value !== "" && value !== " ") { - parameter = value; - } return false; - }} - /> + const listParams = this.compileParams.map((parameter, i) => +
+ parameter} + onDrop={(e: Event, de: DragManager.DropEvent) => this.onDrop(e, de, i)} + SetValue={value => { + if (value !== "" && value !== " ") { + this.compileParams[i] = value; + parameter = value; + return true; + } else { + this.onDelete(parameter); + return true; + } + }} + /> +
); return ( @@ -185,7 +198,7 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent : null} -
{params}
+
{params}
{this._errorMessage}
{this.rootDoc.layout === "layout" ?
: (null)} -- cgit v1.2.3-70-g09d2