From bcb3106513b5a7ddc1aac8b7e6a448de4c4ded21 Mon Sep 17 00:00:00 2001 From: anika-ahluwalia Date: Mon, 18 May 2020 21:18:20 -0500 Subject: adding stirng and doc types --- src/client/views/nodes/ScriptingBox.tsx | 231 +++++++++++++++++++------------- 1 file changed, 135 insertions(+), 96 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 f088fc5d2..86baa0f6f 100644 --- a/src/client/views/nodes/ScriptingBox.tsx +++ b/src/client/views/nodes/ScriptingBox.tsx @@ -1,4 +1,4 @@ -import { action, observable, computed, _allowStateChangesInsideComputed } from "mobx"; +import { action, observable, computed, _allowStateChangesInsideComputed, runInAction } from "mobx"; import { observer } from "mobx-react"; import * as React from "react"; import { documentSchema } from "../../../fields/documentSchemas"; @@ -16,6 +16,7 @@ import { DocumentIconContainer, DocumentIcon } from "./DocumentIcon"; import { List } from "../../../fields/List"; import { DragManager } from "../../util/DragManager"; import { Doc } from "../../../fields/Doc"; +import { Dropdown } from "prosemirror-menu"; const ScriptingSchema = createSchema({}); type ScriptingDocument = makeInterface<[typeof ScriptingSchema, typeof documentSchema]>; @@ -34,10 +35,9 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent { const params = this.compileParams.reduce((o: ScriptParam, p: string) => { @@ -167,16 +168,6 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent { - const param = element.split(":"); - this._paramsNames.push(param[0].trim()); - this._paramsTypes.push(param[1].trim()); - } - ); } @action @@ -196,7 +187,7 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent(value.split(";").filter(s => s !== " ")); - this.compileParams.push.apply(this.compileParams, par); - return true; - // } else { - // this._errorMessage = "this name has already been used"; - // return false; - // } + if (parameter[1].trim() === "Doc" || parameter[1].trim() === "string" || parameter[1].split("|")) { + if (!!!this._paramsNames.includes(parameter[0].trim())) { + this._errorMessage = ""; + this._paramNum++; + const par = this.compileParams; + this.compileParams = new List(value.split(";").filter(s => s !== " ")); + this.compileParams.push.apply(this.compileParams, par); + this._paramsNames.push(parameter[0].trim()); + this._paramsTypes.push(parameter[1].trim()); + this._paramsValues.push("j"); + return true; + } else { + this._errorMessage = "this name has already been used"; + return false; + } } else { this._errorMessage = "this type is not supported"; return false; @@ -277,73 +275,114 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent ); - // const settingParams = this._paramsNames.map((parameter: string, i: number) => - //
{ - // if (e.key === "Enter") { - // this._overlayDisposer?.(); - // } - // } - // } - // > - - // {this._paramsTypes[i] === "Doc" ?
- //
- - //
- // {parameter + ":" + this._paramsValues[i] + " = "} - //
- - //
- // this._paramsValues[i]} - // onDrop={(e: Event, de: DragManager.DropEvent) => this.onDrop(e, de, i)} - // SetValue={value => { - // this._paramsValues[i] = value; - // return true; - // }} - // /> - //
- //
- //
: null} - - // {this._paramsTypes[i] === "string" ?
- //
- - //
- // {parameter + ":" + this._paramsValues[i] + " = "} - //
- - //
- // this._paramsValues[i]} - // SetValue={value => { - // this._paramsValues[i] = value; - // return true; - // }} - // /> - //
- //
- //
: null} - - - - //
- // ); + const settingParams = this._paramsNames.map((parameter: string, i: number) => +
{ + if (e.key === "Enter") { + this._overlayDisposer?.(); + } + } + } + > + + {this._paramsTypes[i] === "Doc" ?
+
+ +
+ {parameter + ":" + this._paramsTypes[i] + " = "} +
+ +
+ StrCast(this.props.Document[parameter]) ?? "undefined"} + onDrop={(e: Event, de: DragManager.DropEvent) => this.onDrop(e, de, parameter)} + SetValue={value => { + runInAction(() => { + const script = CompileScript( + value, { + addReturn: true, typecheck: false, + transformer: DocumentIconContainer.getTransformer(), + params: { makeInterface: "any" } + }); + if (!script.compiled) { + return false; + } else { + const results = script.run(); + if (results.success) { + + this.props.Document[parameter] = results.result; + return true; + } else { + return false; + } + } + + }); + return true; + }} + /> +
+
+
: null} + + {this._paramsTypes[i] === "string" ?
+
+ +
+ {parameter + ":" + this._paramsValues[i] + " = "} +
+ +
+ StrCast(this.props.Document[parameter]) ?? "undefined"} + SetValue={value => { + runInAction(() => { + this.props.Document[parameter] = value; + return true; + }); + return true; + }} + /> +
+
+
: null} + + {/* {this._paramsTypes[i].split("|")[1] ?
+
+ +
+ {parameter + ":" + this._paramsValues[i] + " = "} +
+ +
+ + Profile + +
{this._paramsTypes[0]}
+
{this._paramsTypes[1]}
+
+
+
+
+
: null} */} + +
+ ); const scriptingInputs =
this.props.isSelected(true) && e.stopPropagation()} > @@ -386,7 +425,7 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent this.props.isSelected(true) && e.stopPropagation()} > {this.compileParams.length > 0 ?
- {this.compileParams} + {settingParams}
: null}
; -- cgit v1.2.3-70-g09d2