From 38c977ea797478b5c7581c283950333f7dd128f3 Mon Sep 17 00:00:00 2001 From: anika-ahluwalia Date: Mon, 1 Jun 2020 11:16:07 -0500 Subject: playing around with autosuggest module --- src/client/views/nodes/ScriptingBox.tsx | 108 ++++++++++++++++++++++++-------- 1 file changed, 81 insertions(+), 27 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 51d4cb56e..0831d7042 100644 --- a/src/client/views/nodes/ScriptingBox.tsx +++ b/src/client/views/nodes/ScriptingBox.tsx @@ -18,8 +18,10 @@ import { FieldView, FieldViewProps } from "../nodes/FieldView"; import { OverlayView } from "../OverlayView"; import { DocumentIconContainer } from "./DocumentIcon"; import "./ScriptingBox.scss"; -import Autosuggest from "react-autosuggest"; -import { emptyFunction } from '../../../Utils'; + +import ReactTextareaAutocomplete from "@webscopeio/react-textarea-autocomplete"; +import "@webscopeio/react-textarea-autocomplete/style.css"; + const ScriptingSchema = createSchema({}); type ScriptingDocument = makeInterface<[typeof ScriptingSchema, typeof documentSchema]>; @@ -30,16 +32,15 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent void; @observable private _errorMessage: string = ""; @observable private _applied: boolean = false; - @observable private _suggested: boolean = false; @observable private _scriptKeys: any = Scripting.getGlobals(); - @observable private _scriptingGlobals: any = Scripting.getGlobalObj(); @observable private _currWord: string = ""; - @observable private _suggestions: any[] = []; + @observable private _suggestions: string[] = []; // vars included in fields that store parameters types and names and the script itself @computed get paramsNames() { return this.compileParams.map(p => p.split(":")[0].trim()); } @@ -153,7 +154,7 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent { + specificContextMenu = (): void => { const existingOptions = ContextMenu.Instance.findByDescription("Options..."); const options = existingOptions && "subitems" in existingOptions ? existingOptions.subitems : []; options.push({ description: "Create a Copy", event: this.onCopy, icon: "copy" }); @@ -166,7 +167,7 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent this._overlayDisposer?.()} + return
this._overlayDisposer?.()} ref={ele => ele && this.createDashEventsTarget(ele, (e, de) => this.onDrop(e, de, parameter))} > suggestion; - renderSuggestion = (suggestion: string) => { - return (null); + // @action + // handleKeyPress(e: React.ChangeEvent) { + + // this.rawScript = e.target.value; + // this._currWord = e.target.value.split(" ")[e.target.value.split(" ").length - 1]; + // this._suggestions = []; + + // this._scriptKeys.forEach((element: string | string[]) => { + // if (element.indexOf(this._currWord) >= 0) { + // this._suggestions.push(element); + // } + // }); + // console.log(this._suggestions); + // } + + @action + handleKeyPress(num: number) { + + const scriptString = this.rawScript.slice(0, num); + + this._currWord = scriptString.split(" ")[scriptString.split(" ").length - 1]; + this._suggestions = []; + + this._scriptKeys.forEach((element: string) => { + if (element.indexOf(this._currWord) >= 0) { + this._suggestions.push(StrCast(element)); + } + }); + + console.log(this._suggestions); + return (this._suggestions); } @action - handleKeyPress(e: React.ChangeEvent) { + handleToken(str: string) { - this.rawScript = e.target.value; - this._currWord = e.target.value.split(" ")[e.target.value.split(" ").length - 1]; + this._currWord = str; this._suggestions = []; - this._scriptKeys.forEach((element: string | string[]) => { + this._scriptKeys.forEach((element: string) => { if (element.indexOf(this._currWord) >= 0) { - this._suggestions.push(element); + this._suggestions.push(StrCast(element)); } }); + console.log(this._suggestions); + return (this._suggestions); } // inputs for scripting div (script box, params box, and params column) @@ -323,22 +353,46 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent
; + // const scriptText = + //