From a60c12ddef3db4123dffb2c91b446d20633f523a Mon Sep 17 00:00:00 2001 From: geireann Date: Sun, 13 Oct 2024 16:24:17 -0400 Subject: fixes to scripting to generate errors to allow schema view to enter strings that conflict with function names. --- src/client/util/CurrentUserUtils.ts | 2 +- src/client/util/Scripting.ts | 12 +++++------- src/client/util/node_modules/type_decls.d | 3 +++ src/client/views/nodes/KeyValueBox.tsx | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/client/util/CurrentUserUtils.ts b/src/client/util/CurrentUserUtils.ts index 274bc79be..798cdf5a9 100644 --- a/src/client/util/CurrentUserUtils.ts +++ b/src/client/util/CurrentUserUtils.ts @@ -782,7 +782,7 @@ pie title Minerals in my tap water return [ {title: "Preview", toolTip: "Show selection preview", btnType: ButtonType.ToggleButton, icon: "portrait", scripts:{ onClick: '{ return toggleSchemaPreview(_readOnly_); }'} }, {title: "1 Line", toolTip: "Single Line Rows", btnType: ButtonType.ToggleButton, icon: "eye", scripts:{ onClick: '{ return toggleSingleLineSchema(_readOnly_); }'} }, - {title: "DataViz", toolTip: "Turn Schema Table into Data Visualization Doc", btnType: ButtonType.ClickButton, icon: "chart-bar", scripts:{ onClick: '{ datavizFromSchema()'} }, ]; + {title: "DataViz", toolTip: "Turn Schema Table into Data Visualization Doc", btnType: ButtonType.ClickButton, icon: "chart-bar", scripts:{ onClick: 'datavizFromSchema()'} }, ]; } static webTools() { diff --git a/src/client/util/Scripting.ts b/src/client/util/Scripting.ts index b1db0bf39..5d78c2fab 100644 --- a/src/client/util/Scripting.ts +++ b/src/client/util/Scripting.ts @@ -48,7 +48,7 @@ export function isCompileError(toBeDetermined: CompileResult): toBeDetermined is // eslint-disable-next-line no-use-before-define function Run(script: string | undefined, customParams: string[], diagnostics: ts.Diagnostic[], originalScript: string, options: ScriptOptions): CompileResult { - const errors = diagnostics.filter(diag => diag.category === ts.DiagnosticCategory.Error); + const errors = diagnostics.filter(diag => diag.category === ts.DiagnosticCategory.Error).filter(diag => diag.code !== 2304 && diag.code !== 2339); if ((options.typecheck !== false && errors.length) || !script) { return { compiled: false, errors }; } @@ -188,6 +188,7 @@ export function CompileScript(script: string, options: ScriptOptions = {}): Comp }, ''); const found = ScriptField.GetScriptFieldCache(script + ':' + signature); // if already compiled, found is the result; cache set below if (found) return found as CompiledScript; + options.typecheck = true; const { requiredType = '', addReturn = false, params = {}, capturedVariables = {}, typecheck = true } = options; if (options.params && !options.params.this) options.params.this = Doc.name; if (options.globals) { @@ -221,13 +222,10 @@ export function CompileScript(script: string, options: ScriptOptions = {}): Comp if ('this' in params || 'this' in capturedVariables) { paramNames.push('this'); } - for (const key in params) { - if (key !== 'this') { - paramNames.push(key); - } - } + paramNames.push(...Object.keys(params).filter(p => p!== 'this' && !Object.keys(capturedVariables).includes(p))); + const paramList = paramNames.map(key => { - const val = params[key]; + const val = typeof params[key] === "string" && params[key].length && !"\"'`".includes(params[key][0]) ? `"${params[key]}"` : params[key]; return `${key}: ${val}`; }); for (const key in capturedVariables) { diff --git a/src/client/util/node_modules/type_decls.d b/src/client/util/node_modules/type_decls.d index 1a93bbe59..9058b4394 100644 --- a/src/client/util/node_modules/type_decls.d +++ b/src/client/util/node_modules/type_decls.d @@ -198,6 +198,9 @@ declare class InkField extends ObjectField { constructor(data:Array<{X:number, Y:number}>); [Copy](): ObjectField; } +declare class DocumentDragData { + constructor(dragDoc: Doc[], dropAction?: string); +} // @ts-ignore declare const console: any; diff --git a/src/client/views/nodes/KeyValueBox.tsx b/src/client/views/nodes/KeyValueBox.tsx index 3daacc9bb..40c687b7e 100644 --- a/src/client/views/nodes/KeyValueBox.tsx +++ b/src/client/views/nodes/KeyValueBox.tsx @@ -114,7 +114,7 @@ export class KeyValueBox extends ViewBoxBaseComponent() { if (key) target[key] = script.originalScript; return false; } - field === undefined && (field = res.result instanceof Array ? new List(res.result) : (res.result as FieldType)); + field === undefined && (field = res.result instanceof Array ? new List(res.result) : (typeof res.result === 'function' ? res.result.name : res.result as FieldType)); } } if (!key) return false; -- cgit v1.2.3-70-g09d2