aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/util/CurrentUserUtils.ts4
-rw-r--r--src/client/util/Scripting.ts10
-rw-r--r--src/client/views/collections/TabDocView.tsx4
-rw-r--r--src/client/views/nodes/button/FontIconBox.tsx31
4 files changed, 24 insertions, 25 deletions
diff --git a/src/client/util/CurrentUserUtils.ts b/src/client/util/CurrentUserUtils.ts
index 0898221f1..2903b84e3 100644
--- a/src/client/util/CurrentUserUtils.ts
+++ b/src/client/util/CurrentUserUtils.ts
@@ -931,8 +931,8 @@ export class CurrentUserUtils {
// { title: "Strikethrough", tooltip: "Strikethrough", btnType: ButtonType.ToggleButton, icon: "strikethrough", click: 'toggleStrikethrough()'},
// { title: "Superscript", tooltip: "Superscript", btnType: ButtonType.ToggleButton, icon: "superscript", click: 'toggleSuperscript()'},
// { title: "Subscript", tooltip: "Subscript", btnType: ButtonType.ToggleButton, icon: "subscript", click: 'toggleSubscript()'},
- { title: "Highlight", toolTip: "Highlight", btnType: ButtonType.ColorButton, icon: "highlighter", ignoreClick: true, scriptDoc: Doc.UserDoc(), userColorBtn: 'userDoc._highlightColor' },
- { title: "Text color", toolTip: "Text color", btnType: ButtonType.ColorButton, icon: "fill-drip", ignoreClick: true, scriptDoc: Doc.UserDoc(), script:'console.log("test")', userColorBtn: 'userDoc._textColor' },
+ { title: "Highlight", toolTip: "Highlight", btnType: ButtonType.ColorButton, icon: "highlighter", ignoreClick: true, script:'changeFontColor' },
+ { title: "Text color", toolTip: "Text color", btnType: ButtonType.ColorButton, icon: "highlighter", ignoreClick: true, script:'changeHighlightColor' },
];
}
diff --git a/src/client/util/Scripting.ts b/src/client/util/Scripting.ts
index eac87d31e..aa7c23527 100644
--- a/src/client/util/Scripting.ts
+++ b/src/client/util/Scripting.ts
@@ -171,10 +171,18 @@ function Run(script: string | undefined, customParams: string[], diagnostics: an
if (!options.editable) {
batch = Doc.MakeReadOnly();
}
+ const result1 = compiledFunction.apply(thisParam, params);
+
const result = compiledFunction.apply(thisParam, params).apply(thisParam, argsArray);
if (batch) {
batch.end();
}
+
+ if (script.includes('toggleOverlay(true)')){
+ console.log("[Scripting.ts] r1: ", result1);
+ console.log("[Scripting.ts]: ", result);
+ }
+
return { success: true, result };
} catch (error) {
@@ -315,7 +323,7 @@ export function CompileScript(script: string, options: ScriptOptions = {}): Comp
}
const paramString = paramList.join(", ");
const funcScript = `(function(${paramString})${requiredType ? `: ${requiredType}` : ''} {
- ${addReturn ? `return ${script};` : script}
+ ${addReturn ? `return ${script};` : `return ${script};`}
})`;
host.writeFile("file.ts", funcScript);
diff --git a/src/client/views/collections/TabDocView.tsx b/src/client/views/collections/TabDocView.tsx
index 9ff1a0f61..00de36400 100644
--- a/src/client/views/collections/TabDocView.tsx
+++ b/src/client/views/collections/TabDocView.tsx
@@ -124,8 +124,8 @@ export class TabDocView extends React.Component<TabDocViewProps> {
tab.element[0].prepend(iconWrap);
tab._disposers.layerDisposer = reaction(() => ({ layer: tab.DashDoc.activeLayer, color: this.tabColor }),
({ layer, color }) => {
- console.log("TabDocView: " + this.tabColor);
- console.log("lightOrDark: " + lightOrDark(this.tabColor));
+ // console.log("TabDocView: " + this.tabColor);
+ // console.log("lightOrDark: " + lightOrDark(this.tabColor));
const textColor = lightOrDark(this.tabColor); //not working with StyleProp.Color
titleEle.style.color = textColor;
titleEle.style.backgroundColor = "transparent";
diff --git a/src/client/views/nodes/button/FontIconBox.tsx b/src/client/views/nodes/button/FontIconBox.tsx
index bc4b56a2d..aa3a1ada4 100644
--- a/src/client/views/nodes/button/FontIconBox.tsx
+++ b/src/client/views/nodes/button/FontIconBox.tsx
@@ -8,7 +8,7 @@ import { ColorState, SketchPicker } from 'react-color';
import { Doc, StrListCast } from '../../../../fields/Doc';
import { createSchema, makeInterface } from '../../../../fields/Schema';
import { ScriptField } from '../../../../fields/ScriptField';
-import { BoolCast, Cast, StrCast } from '../../../../fields/Types';
+import { BoolCast, Cast, NumCast, StrCast } from '../../../../fields/Types';
import { DocumentType } from '../../../documents/DocumentTypes';
import { Scripting } from "../../../util/Scripting";
import { SelectionManager } from '../../../util/SelectionManager';
@@ -277,15 +277,8 @@ export class FontIconBox extends DocComponent<ButtonProps, FontIconDocument>(Fon
}
@computed get toggleButton() {
- const numSelected = SelectionManager.Views().length;
- const selectedDoc = numSelected > 0 ? SelectionManager.Views()[0].Document : undefined;
-
const script: string = StrCast(this.rootDoc.script) + "(true)";
- console.log(script);
- const boolResult = ScriptField.MakeScript(script)?.script.run().success;
- if (script.includes("toggleOverlay")) {
- console.log("boolResult: " + boolResult);
- }
+ const boolResult = ScriptField.MakeScript(script)?.script.run().result;
const color = this.props.styleProvider?.(this.rootDoc, this.props, StyleProp.Color);
const backgroundColor = this.props.styleProvider?.(this.rootDoc, this.props, StyleProp.BackgroundColor);
@@ -426,15 +419,15 @@ Scripting.addGlobal(function changeBackgroundColor(color?: string, checkResult?:
// toggle: Set overlay status of selected document
Scripting.addGlobal(function toggleOverlay(checkResult?: boolean) {
const selected = SelectionManager.Views().length ? SelectionManager.Views()[0] : undefined;
- if (checkResult) {
- return selected && selected.Document.z == 1;
+ if (checkResult && selected) {
+ console.log("z: ", NumCast(selected.Document.z) === 1);
+ return NumCast(selected.Document.z) === 1;
}
selected ? selected.props.CollectionFreeFormDocumentView?.().float() : console.log("[FontIconBox.tsx] toggleOverlay failed");
});
// toggle: Set overlay status of selected document
Scripting.addGlobal(function changeFont(font: string) {
- // TODO: glr check if font selected and change selected font
SelectionManager.Views().map(dv => dv.props.Document._fontFamily = font);
console.log(font);
Doc.UserDoc()._fontFamily = font;
@@ -443,40 +436,38 @@ Scripting.addGlobal(function changeFont(font: string) {
// toggle: Set overlay status of selected document
Scripting.addGlobal(function changeFontColor(color: string) {
- // TODO: glr check if font selected and change selected font
console.log(color);
Doc.UserDoc()._fontColor = color;
});
// toggle: Set overlay status of selected document
Scripting.addGlobal(function changeFontSize(size: string) {
- // TODO: glr check if font selected and change selected font
console.log(size);
Doc.UserDoc()._fontSize = size;
});
Scripting.addGlobal(function toggleBold(checkResult?: boolean) {
if (checkResult) {
- console.log("got here");
return Doc.UserDoc().bold;
}
- // TODO: glr check if font selected and change selected font
SelectionManager.Views().map(dv => dv.props.Document.bold = !dv.props.Document.bold);
Doc.UserDoc().bold = !Doc.UserDoc().bold;
return Doc.UserDoc().bold;
});
Scripting.addGlobal(function toggleUnderline(checkResult?: boolean) {
- if (checkResult) return Doc.UserDoc().underline;
- // TODO: glr check if font selected and change selected font
+ if (checkResult) {
+ return Doc.UserDoc().underline;
+ }
SelectionManager.Views().map(dv => dv.props.Document.underline = !dv.props.Document.underline);
Doc.UserDoc().bold = !Doc.UserDoc().underline;
return Doc.UserDoc().underline;
});
Scripting.addGlobal(function toggleItalic(checkResult?: boolean) {
- if (checkResult) return Doc.UserDoc().italic;
- // TODO: glr check if font selected and change selected font
+ if (checkResult) {
+ return Doc.UserDoc().italic;
+ }
SelectionManager.Views().map(dv => dv.props.Document.italic = !dv.props.Document.italic);
Doc.UserDoc().bold = !Doc.UserDoc().italic;
return Doc.UserDoc().italic;