aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--package-lock.json50
-rw-r--r--src/client/util/CurrentUserUtils.ts2
-rw-r--r--src/client/util/Scripting.ts27
-rw-r--r--src/client/views/collections/CollectionViewChromes.tsx2
-rw-r--r--src/client/views/nodes/ScriptingBox.tsx52
5 files changed, 104 insertions, 29 deletions
diff --git a/package-lock.json b/package-lock.json
index d4d0e09c3..6e7ed611b 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -2800,7 +2800,8 @@
},
"ansi-regex": {
"version": "2.1.1",
- "bundled": true
+ "bundled": true,
+ "optional": true
},
"aproba": {
"version": "1.2.0",
@@ -2818,11 +2819,13 @@
},
"balanced-match": {
"version": "1.0.0",
- "bundled": true
+ "bundled": true,
+ "optional": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
+ "optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@@ -2835,15 +2838,18 @@
},
"code-point-at": {
"version": "1.1.0",
- "bundled": true
+ "bundled": true,
+ "optional": true
},
"concat-map": {
"version": "0.0.1",
- "bundled": true
+ "bundled": true,
+ "optional": true
},
"console-control-strings": {
"version": "1.1.0",
- "bundled": true
+ "bundled": true,
+ "optional": true
},
"core-util-is": {
"version": "1.0.2",
@@ -2946,7 +2952,8 @@
},
"inherits": {
"version": "2.0.4",
- "bundled": true
+ "bundled": true,
+ "optional": true
},
"ini": {
"version": "1.3.5",
@@ -2956,6 +2963,7 @@
"is-fullwidth-code-point": {
"version": "1.0.0",
"bundled": true,
+ "optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@@ -2968,17 +2976,20 @@
"minimatch": {
"version": "3.0.4",
"bundled": true,
+ "optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
},
"minimist": {
"version": "1.2.5",
- "bundled": true
+ "bundled": true,
+ "optional": true
},
"minipass": {
"version": "2.9.0",
"bundled": true,
+ "optional": true,
"requires": {
"safe-buffer": "^5.1.2",
"yallist": "^3.0.0"
@@ -2995,6 +3006,7 @@
"mkdirp": {
"version": "0.5.3",
"bundled": true,
+ "optional": true,
"requires": {
"minimist": "^1.2.5"
}
@@ -3050,7 +3062,8 @@
},
"npm-normalize-package-bin": {
"version": "1.0.1",
- "bundled": true
+ "bundled": true,
+ "optional": true
},
"npm-packlist": {
"version": "1.4.8",
@@ -3075,7 +3088,8 @@
},
"number-is-nan": {
"version": "1.0.1",
- "bundled": true
+ "bundled": true,
+ "optional": true
},
"object-assign": {
"version": "4.1.1",
@@ -3085,6 +3099,7 @@
"once": {
"version": "1.4.0",
"bundled": true,
+ "optional": true,
"requires": {
"wrappy": "1"
}
@@ -3153,7 +3168,8 @@
},
"safe-buffer": {
"version": "5.1.2",
- "bundled": true
+ "bundled": true,
+ "optional": true
},
"safer-buffer": {
"version": "2.1.2",
@@ -3183,6 +3199,7 @@
"string-width": {
"version": "1.0.2",
"bundled": true,
+ "optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
@@ -3200,6 +3217,7 @@
"strip-ansi": {
"version": "3.0.1",
"bundled": true,
+ "optional": true,
"requires": {
"ansi-regex": "^2.0.0"
}
@@ -3238,11 +3256,13 @@
},
"wrappy": {
"version": "1.0.2",
- "bundled": true
+ "bundled": true,
+ "optional": true
},
"yallist": {
"version": "3.1.1",
- "bundled": true
+ "bundled": true,
+ "optional": true
}
}
}
@@ -11050,7 +11070,7 @@
},
"mkdirp": {
"version": "0.5.4",
- "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.4.tgz",
+ "resolved": false,
"integrity": "sha512-iG9AK/dJLtJ0XNgTuDbSyNS3zECqDlAhnQW4CsNxBG3LQJBbHmRX1egw39DmtOdCAqY+dKXV+sgPgilNWUKMVw==",
"requires": {
"minimist": "^1.2.5"
@@ -11058,7 +11078,7 @@
"dependencies": {
"minimist": {
"version": "1.2.5",
- "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
+ "resolved": false,
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
}
}
@@ -11254,7 +11274,7 @@
},
"npm-registry-fetch": {
"version": "4.0.3",
- "resolved": "https://registry.npmjs.org/npm-registry-fetch/-/npm-registry-fetch-4.0.3.tgz",
+ "resolved": false,
"integrity": "sha512-WGvUx0lkKFhu9MbiGFuT9nG2NpfQ+4dCJwRwwtK2HK5izJEvwDxMeUyqbuMS7N/OkpVCqDorV6rO5E4V9F8lJw==",
"requires": {
"JSONStream": "^1.3.4",
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) :