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.scss | 76 ++++++++++++++++++++++ src/client/views/nodes/ScriptingBox.tsx | 108 +++++++++++++++++++++++-------- 2 files changed, 157 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/client/views/nodes/ScriptingBox.scss b/src/client/views/nodes/ScriptingBox.scss index d369045f4..256119809 100644 --- a/src/client/views/nodes/ScriptingBox.scss +++ b/src/client/views/nodes/ScriptingBox.scss @@ -32,6 +32,82 @@ resize: none; padding: 7px; overflow-y: scroll; + + body { + font-family: Arial, Helvetica, sans-serif; + border: 1px solid red; + } + + .rta { + position: relative; + font-size: 18px; + width: 100%; + height: 100%; + margin-bottom: 60px !important; + } + .rta__loader.rta__loader--empty-suggestion-data { + border-radius: 3px; + box-shadow: 0 0 5px rgba(27, 31, 35, 0.1); + padding: 5px; + } + .rta--loading .rta__loader.rta__loader--suggestion-data { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + background: rgba(255, 255, 255, 0.8); + } + .rta--loading .rta__loader.rta__loader--suggestion-data > * { + position: relative; + top: 50%; + } + .rta__textarea { + width: 100%; + height: 100%; + font-size: 1em; + } + .rta__autocomplete { + position: absolute; + display: block; + margin-top: 1em; + } + .rta__autocomplete--top { + margin-top: 0; + margin-bottom: 1em; + max-height: 100px; + overflow-y: auto; + } + .rta__list { + margin: 0; + padding: 0; + background: #fff; + border: 1px solid #dfe2e5; + border-radius: 3px; + box-shadow: 0 0 5px rgba(27, 31, 35, 0.1); + list-style: none; + } + .rta__entity { + background: white; + width: 100%; + text-align: left; + outline: none; + } + .rta__entity:hover { + cursor: pointer; + } + .rta__item:not(:last-child) { + border-bottom: 1px solid #dfe2e5; + } + .rta__entity > * { + padding-left: 4px; + padding-right: 4px; + } + .rta__entity--selected { + color: #fff; + text-decoration: none; + background: #0366d6; + } } .scriptingBox-plist { 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 = + //