-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtexprl.js
58 lines (49 loc) · 1.61 KB
/
texprl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import basicSetup from "./codemirror/setup/basic";
import parserPlugin from "./plugins/parser";
import widgetsPlugin from "./plugins/widgets";
import runtimePlugin from "./plugins/runtime/index.js";
export { basicSetup };
export { RuntimeError } from "./errors";
export { toArrayAst, fromArrayAst } from "./parser/index.js";
class TexprlEditor {
constructor(opts = {}) {
this.lookup = opts.lookup ? opts.lookup : [];
this.runtime = opts.runtime ? opts.runtime : () => {};
this.functionRenames = (opts.functions || {}).renames || [];
this.functionAutocomplete =
(opts.functions || {}).functionAutocomplete || (() => []);
this.argAutocomplete = (opts.functions || {}).argAutocomplete || (() => []);
this.functionTypes = (opts.functions || {}).types || {};
this.runtimeEnabled = !!opts.runtimeEnabled;
// Initialize plugins...
this._widgetPlugin = widgetsPlugin(this);
this._parserPlugin = parserPlugin(this);
this._runtimePlugin = runtimePlugin(this);
}
setRuntimeEnabled(bool) {
this.runtimeEnabled = !!bool;
}
checkLookupFromBackendId = (key) => {
const arr = [];
const found = this.lookup().find((item) => {
return item.backendId === key;
});
return found;
};
checkLookup = (key) => {
const arr = [];
const found = this.lookup().find((item) => {
return item.editorId === key;
});
return found;
};
onLookup = () => {
return this.lookup();
};
plugin = () => {
return [this._widgetPlugin, this._parserPlugin, this._runtimePlugin];
};
}
export default function texprl(opts) {
return new TexprlEditor(opts);
}