diff options
author | anika-ahluwalia <anika.ahluwalia@gmail.com> | 2020-05-30 12:52:40 -0500 |
---|---|---|
committer | anika-ahluwalia <anika.ahluwalia@gmail.com> | 2020-05-30 12:52:40 -0500 |
commit | 0f178f1d74e17b15cec0fc98a12ccb2acaec937a (patch) | |
tree | c356c9fad8b3070b7fe5c9efe8b5682a0afc7f5e /src | |
parent | 4ae38a5a1aaeaef101ee5b0bcad3debf9b1a5092 (diff) |
generating suggestions for methods
Diffstat (limited to 'src')
-rw-r--r-- | src/client/util/CurrentUserUtils.ts | 2 | ||||
-rw-r--r-- | src/client/util/Scripting.ts | 27 | ||||
-rw-r--r-- | src/client/views/collections/CollectionViewChromes.tsx | 2 | ||||
-rw-r--r-- | src/client/views/nodes/ScriptingBox.tsx | 52 |
4 files changed, 69 insertions, 14 deletions
diff --git a/src/client/util/CurrentUserUtils.ts b/src/client/util/CurrentUserUtils.ts index 496099557..1fdf50dd4 100644 --- a/src/client/util/CurrentUserUtils.ts +++ b/src/client/util/CurrentUserUtils.ts @@ -736,6 +736,6 @@ export class CurrentUserUtils { } } -Scripting.addGlobal(function setupMobileInkingDoc(userDoc: Doc) { return CurrentUserUtils.setupMobileInkingDoc(userDoc); }); +Scripting.addGlobal("setupMobileInkingDoc", function setupMobileInkingDoc(userDoc: Doc) { return CurrentUserUtils.setupMobileInkingDoc(userDoc); }); Scripting.addGlobal(function setupMobileUploadDoc(userDoc: Doc) { return CurrentUserUtils.setupMobileUploadDoc(userDoc); }); Scripting.addGlobal(function createNewWorkspace() { return MainView.Instance.createNewWorkspace(); });
\ No newline at end of file diff --git a/src/client/util/Scripting.ts b/src/client/util/Scripting.ts index ab577315c..817e6b29d 100644 --- a/src/client/util/Scripting.ts +++ b/src/client/util/Scripting.ts @@ -49,12 +49,25 @@ export function isCompileError(toBeDetermined: CompileResult): toBeDetermined is export namespace Scripting { export function addGlobal(global: { name: string }): void; export function addGlobal(name: string, global: any): void; - export function addGlobal(nameOrGlobal: any, global?: any) { - let n: string; + + export function addGlobal(global: { name: string }, decription?: string, params?: any): void; + + export function addGlobal(nameOrGlobal: any, global?: any, params?: any) { + let n: any; let obj: any; - if (global !== undefined && typeof nameOrGlobal === "string") { - n = nameOrGlobal; - obj = global; + + if (global !== undefined) { + if (typeof nameOrGlobal === "string") { + n = nameOrGlobal; + obj = global; + } else { + n = nameOrGlobal.name; + obj = [nameOrGlobal]; + obj.push(global); + if (params) { + obj.push(params); + } + } } else if (nameOrGlobal && typeof nameOrGlobal.name === "string") { n = nameOrGlobal.name; obj = nameOrGlobal; @@ -87,6 +100,10 @@ export namespace Scripting { export function getGlobals() { return Object.keys(scriptingGlobals); } + + export function getGlobalObj() { + return _scriptingGlobals; + } } export function scriptingGlobal(constructor: { new(...args: any[]): any }) { diff --git a/src/client/views/collections/CollectionViewChromes.tsx b/src/client/views/collections/CollectionViewChromes.tsx index 29a3e559a..3dc740c25 100644 --- a/src/client/views/collections/CollectionViewChromes.tsx +++ b/src/client/views/collections/CollectionViewChromes.tsx @@ -93,7 +93,7 @@ export class CollectionViewBaseChrome extends React.Component<CollectionViewChro this.props.collapse?.(true); break; } - }) + }); @undoBatch viewChanged = (e: React.ChangeEvent) => { diff --git a/src/client/views/nodes/ScriptingBox.tsx b/src/client/views/nodes/ScriptingBox.tsx index 181db4b51..51d4cb56e 100644 --- a/src/client/views/nodes/ScriptingBox.tsx +++ b/src/client/views/nodes/ScriptingBox.tsx @@ -10,7 +10,7 @@ import { Cast, NumCast, ScriptCast, StrCast } from "../../../fields/Types"; import { returnEmptyString } from "../../../Utils"; import { DragManager } from "../../util/DragManager"; import { InteractionUtils } from "../../util/InteractionUtils"; -import { CompileScript, ScriptParam } from "../../util/Scripting"; +import { CompileScript, ScriptParam, Scripting } from "../../util/Scripting"; import { ContextMenu } from "../ContextMenu"; import { ViewBoxAnnotatableComponent } from "../DocComponent"; import { EditableView } from "../EditableView"; @@ -18,6 +18,8 @@ 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'; const ScriptingSchema = createSchema({}); type ScriptingDocument = makeInterface<[typeof ScriptingSchema, typeof documentSchema]>; @@ -33,6 +35,11 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent<FieldViewProps, Sc @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[] = []; // 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()); } @@ -283,6 +290,27 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent<FieldViewProps, Sc return false; } + getSuggestionValue = (suggestion: string) => suggestion; + + renderSuggestion = (suggestion: string) => { + return (null); + } + + @action + handleKeyPress(e: React.ChangeEvent<HTMLTextAreaElement>) { + + 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); + } + // inputs for scripting div (script box, params box, and params column) renderScriptingInputs() { @@ -296,12 +324,22 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent<FieldViewProps, Sc </div>; // main scripting input box - const scriptingInputText = <textarea onFocus={this.onFocus} onBlur={e => this._overlayDisposer?.()} - onChange={e => this.rawScript = e.target.value} - placeholder="write your script here" - value={this.rawScript} - style={{ width: this.compileParams.length > 0 ? "70%" : "100%", resize: "none", height: "100%" }} - />; + const scriptingInputText = + // <Autosuggest + // inputProps={{ value: this.rawScript, onChange: this.handleKeyPress }} + // getSuggestionValue={this.getSuggestionValue} + // suggestions={this._suggestions} + // //alwaysRenderSuggestions={false} + // renderSuggestion={this.renderSuggestion} + // onSuggestionsFetchRequested={emptyFunction} + // onSuggestionsClearRequested={emptyFunction} + // />; + <textarea onFocus={this.onFocus} onBlur={e => this._overlayDisposer?.()} + onChange={e => this.handleKeyPress(e)} + placeholder="write your script here" + value={this.rawScript} + style={{ width: this.compileParams.length > 0 ? "70%" : "100%", resize: "none", height: "100%" }} + />; // params column on right side (list) const definedParameters = !this.compileParams.length ? (null) : |