aboutsummaryrefslogtreecommitdiff
path: root/src/client/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/util')
-rw-r--r--src/client/util/CurrentUserUtils.ts249
-rw-r--r--src/client/util/DictationManager.ts353
-rw-r--r--src/client/util/DocumentManager.ts8
-rw-r--r--src/client/util/DragManager.ts2
-rw-r--r--src/client/util/DropConverter.ts4
-rw-r--r--src/client/util/History.ts6
-rw-r--r--src/client/util/Import & Export/DirectoryImportBox.tsx7
-rw-r--r--src/client/util/LinkManager.ts2
-rw-r--r--src/client/util/ScriptManager.ts12
-rw-r--r--src/client/util/Scripting.ts109
-rw-r--r--src/client/util/ScriptingGlobals.ts81
-rw-r--r--src/client/util/UndoManager.ts3
12 files changed, 385 insertions, 451 deletions
diff --git a/src/client/util/CurrentUserUtils.ts b/src/client/util/CurrentUserUtils.ts
index 8cb735d10..0db8bebd8 100644
--- a/src/client/util/CurrentUserUtils.ts
+++ b/src/client/util/CurrentUserUtils.ts
@@ -7,7 +7,6 @@ import { List } from "../../fields/List";
import { PrefetchProxy } from "../../fields/Proxy";
import { RichTextField } from "../../fields/RichTextField";
import { listSpec } from "../../fields/Schema";
-import { SchemaHeaderField } from "../../fields/SchemaHeaderField";
import { ComputedField, ScriptField } from "../../fields/ScriptField";
import { BoolCast, Cast, DateCast, NumCast, PromiseValue, StrCast } from "../../fields/Types";
import { nullAudio } from "../../fields/URLField";
@@ -16,9 +15,7 @@ import { Utils } from "../../Utils";
import { DocServer } from "../DocServer";
import { Docs, DocumentOptions, DocUtils } from "../documents/Documents";
import { DocumentType } from "../documents/DocumentTypes";
-import { Networking } from "../Network";
import { CollectionDockingView } from "../views/collections/CollectionDockingView";
-import { DimUnit } from "../views/collections/collectionMulticolumn/CollectionMulticolumnView";
import { CollectionView, CollectionViewType } from "../views/collections/CollectionView";
import { TreeView } from "../views/collections/TreeView";
import { Colors } from "../views/global/globalEnums";
@@ -32,7 +29,7 @@ import { DragManager } from "./DragManager";
import { makeTemplate } from "./DropConverter";
import { HistoryUtil } from "./History";
import { LinkManager } from "./LinkManager";
-import { Scripting } from "./Scripting";
+import { ScriptingGlobals } from "./ScriptingGlobals";
import { SearchUtil } from "./SearchUtil";
import { SelectionManager } from "./SelectionManager";
import { ColorScheme } from "./SettingsManager";
@@ -51,7 +48,6 @@ interface Button {
numBtnMax?: number;
switchToggle?: boolean;
script?: string;
- checkResult?: string;
width?: number;
list?: string[];
ignoreClick?: boolean;
@@ -162,90 +158,37 @@ export class CurrentUserUtils {
});
}
- if (doc["template-button-switch"] === undefined) {
- const { FreeformDocument, MulticolumnDocument, TextDocument } = Docs.Create;
-
- const yes = FreeformDocument([], { title: "yes", _height: 35, _width: 50, _dimUnit: DimUnit.Pixel, _dimMagnitude: 40, system: true });
- const name = TextDocument("name", { title: "name", _height: 35, _width: 70, _dimMagnitude: 1, system: true });
- const no = FreeformDocument([], { title: "no", _height: 100, _width: 100, system: true });
- const labelTemplate = {
- doc: {
- type: "doc", content: [{
- type: "paragraph",
- content: [{ type: "dashField", attrs: { fieldKey: "PARAMS", hideKey: true } }]
- }]
- },
- selection: { type: "text", anchor: 1, head: 1 },
- storedMarks: []
- };
- Doc.GetProto(name).text = new RichTextField(JSON.stringify(labelTemplate), "PARAMS");
- Doc.GetProto(yes).backgroundColor = ComputedField.MakeFunction("self[this.PARAMS] ? 'green':'red'");
- // Doc.GetProto(no).backgroundColor = ComputedField.MakeFunction("!self[this.PARAMS] ? 'red':'white'");
- // Doc.GetProto(yes).onClick = ScriptField.MakeScript("self[this.PARAMS] = true");
- Doc.GetProto(yes).onClick = ScriptField.MakeScript("self[this.PARAMS] = !self[this.PARAMS]");
- // Doc.GetProto(no).onClick = ScriptField.MakeScript("self[this.PARAMS] = false");
- const box = MulticolumnDocument([/*no, */ yes, name], { title: "value", _width: 120, _height: 35, system: true });
- box.isTemplateDoc = makeTemplate(box, true, "switch");
-
- doc["template-button-switch"] = CurrentUserUtils.createToolButton({
- onDragStart: ScriptField.MakeFunction('copyDragFactory(this.dragFactory)'),
- dragFactory: new PrefetchProxy(box) as any as Doc, title: "data switch", icon: "toggle-on", system: true,
- btnType: ButtonType.ToolButton
- });
- }
-
- if (doc["template-button-detail"] === undefined) {
- const { TextDocument, MasonryDocument, CarouselDocument } = Docs.Create;
-
- const openInTarget = ScriptField.MakeScript("openOnRight(self.doubleClickView)");
- const carousel = CarouselDocument([], {
- title: "data", _height: 350, _itemIndex: 0, "_carousel-caption-xMargin": 10, "_carousel-caption-yMargin": 10,
- onChildDoubleClick: openInTarget, backgroundColor: "#9b9b9b3F", system: true
- });
-
- const details = TextDocument("", { title: "details", _height: 200, _autoHeight: true, system: true });
- const short = TextDocument("", { title: "shortDescription", treeViewOpen: true, treeViewExpandedView: "layout", _height: 75, _autoHeight: true, system: true });
- const long = TextDocument("", { title: "longDescription", treeViewOpen: false, treeViewExpandedView: "layout", _height: 150, _autoHeight: true, system: true });
-
- const buxtonFieldKeys = ["year", "originalPrice", "degreesOfFreedom", "company", "attribute", "primaryKey", "secondaryKey", "dimensions"];
- const detailedTemplate = {
- doc: {
- type: "doc", content: buxtonFieldKeys.map(fieldKey => ({
- type: "paragraph",
- content: [{ type: "dashField", attrs: { fieldKey } }]
- }))
- },
- selection: { type: "text", anchor: 1, head: 1 },
- storedMarks: []
- };
- details.text = new RichTextField(JSON.stringify(detailedTemplate), buxtonFieldKeys.join(" "));
-
- const shared = { _autoHeight: true, _xMargin: 0 };
- const detailViewOpts = { title: "detailView", _width: 300, _fontFamily: "Arial", _fontSize: "12px" };
- const descriptionWrapperOpts = { title: "descriptions", _height: 300, _columnWidth: -1, treeViewHideTitle: true, _pivotField: "title", system: true };
-
- const descriptionWrapper = MasonryDocument([details, short, long], { ...shared, ...descriptionWrapperOpts });
- descriptionWrapper._columnHeaders = new List<SchemaHeaderField>([
- new SchemaHeaderField("[A Short Description]", "dimgray", undefined, undefined, undefined, false),
- new SchemaHeaderField("[Long Description]", "dimgray", undefined, undefined, undefined, true),
- new SchemaHeaderField("[Details]", "dimgray", undefined, undefined, undefined, true),
- ]);
- const detailView = Docs.Create.StackingDocument([carousel, descriptionWrapper], { ...shared, ...detailViewOpts, _chromeHidden: true, system: true });
- detailView.isTemplateDoc = makeTemplate(detailView);
-
- details.title = "Details";
- short.title = "A Short Description";
- long.title = "Long Description";
-
- doc["template-button-detail"] = CurrentUserUtils.createToolButton({
- onDragStart: ScriptField.MakeFunction('copyDragFactory(this.dragFactory)'),
- dragFactory: new PrefetchProxy(detailView) as any as Doc,
- title: "detailView",
- icon: "window-maximize",
- system: true,
- btnType: ButtonType.ToolButton,
- });
- }
+ // if (doc["template-button-switch"] === undefined) {
+ // const { FreeformDocument, MulticolumnDocument, TextDocument } = Docs.Create;
+
+ // const yes = FreeformDocument([], { title: "yes", _height: 35, _width: 50, _dimUnit: DimUnit.Pixel, _dimMagnitude: 40, system: true });
+ // const name = TextDocument("name", { title: "name", _height: 35, _width: 70, _dimMagnitude: 1, system: true });
+ // const no = FreeformDocument([], { title: "no", _height: 100, _width: 100, system: true });
+ // const labelTemplate = {
+ // doc: {
+ // type: "doc", content: [{
+ // type: "paragraph",
+ // content: [{ type: "dashField", attrs: { fieldKey: "PARAMS", hideKey: true } }]
+ // }]
+ // },
+ // selection: { type: "text", anchor: 1, head: 1 },
+ // storedMarks: []
+ // };
+ // Doc.GetProto(name).text = new RichTextField(JSON.stringify(labelTemplate), "PARAMS");
+ // Doc.GetProto(yes).backgroundColor = ComputedField.MakeFunction("self[this.PARAMS] ? 'green':'red'");
+ // // Doc.GetProto(no).backgroundColor = ComputedField.MakeFunction("!self[this.PARAMS] ? 'red':'white'");
+ // // Doc.GetProto(yes).onClick = ScriptField.MakeScript("self[this.PARAMS] = true");
+ // Doc.GetProto(yes).onClick = ScriptField.MakeScript("self[this.PARAMS] = !self[this.PARAMS]");
+ // // Doc.GetProto(no).onClick = ScriptField.MakeScript("self[this.PARAMS] = false");
+ // const box = MulticolumnDocument([/*no, */ yes, name], { title: "value", _width: 120, _height: 35, system: true });
+ // box.isTemplateDoc = makeTemplate(box, true, "switch");
+
+ // doc["template-button-switch"] = CurrentUserUtils.createToolButton({
+ // onDragStart: ScriptField.MakeFunction('copyDragFactory(this.dragFactory)'),
+ // dragFactory: new PrefetchProxy(box) as any as Doc, title: "data switch", icon: "toggle-on", system: true,
+ // btnType: ButtonType.ToolButton
+ // });
+ // }
const requiredTypes = [
doc["template-button-slides"] as Doc,
@@ -539,11 +482,11 @@ export class CurrentUserUtils {
// setup the "creator" buttons for the sidebar-- eg. the default set of draggable document creation tools
static async setupCreatorButtons(doc: Doc) {
let alreadyCreatedButtons: string[] = [];
- const dragCreatorSet = await Cast(doc.myItemCreators, Doc, null);
+ const dragCreatorSet = Cast(doc.myItemCreators, Doc, null);
if (dragCreatorSet) {
- const dragCreators = await Cast(dragCreatorSet.data, listSpec(Doc));
+ const dragCreators = Cast(dragCreatorSet.data, listSpec(Doc));
if (dragCreators) {
- const dragDocs = await Promise.all(dragCreators);
+ const dragDocs = await Promise.all(Array.from(dragCreators));
alreadyCreatedButtons = dragDocs.map(d => StrCast(d.title));
}
}
@@ -736,12 +679,16 @@ export class CurrentUserUtils {
];
return docProtoData.map(data => Docs.Create.FontIconDocument({
_nativeWidth: 10, _nativeHeight: 10, _width: 10, _height: 10, title: data.title, icon: data.icon,
- _dropAction: data.pointerDown ? "copy" : undefined, ignoreClick: data.ignoreClick,
+ _dropAction: data.pointerDown ? "copy" : undefined,
+ ignoreClick: data.ignoreClick,
onDragStart: data.drag ? ScriptField.MakeFunction(data.drag) : undefined,
clipboard: data.clipboard,
- onPointerUp: data.pointerUp ? ScriptField.MakeScript(data.pointerUp) : undefined, onPointerDown: data.pointerDown ? ScriptField.MakeScript(data.pointerDown) : undefined,
+ onPointerUp: data.pointerUp ? ScriptField.MakeScript(data.pointerUp) : undefined,
+ onPointerDown: data.pointerDown ? ScriptField.MakeScript(data.pointerDown) : undefined,
backgroundColor: data.backgroundColor,
- _removeDropProperties: new List<string>(["dropAction"]), dragFactory: data.dragFactory, system: true
+ _removeDropProperties: new List<string>(["dropAction"]),
+ dragFactory: data.dragFactory,
+ system: true
}));
}
@@ -988,37 +935,37 @@ export class CurrentUserUtils {
title: "Font", toolTip: "Font", width: 100, btnType: ButtonType.DropdownList, ignoreClick: true,
list: ["Roboto", "Roboto Mono", "Nunito", "Times New Roman", "Arial", "Georgia",
"Comic Sans MS", "Tahoma", "Impact", "Crimson Text"],
- script: 'setFont'
+ script: 'setFont(value, _readOnly_)'
},
- { title: "Font size", toolTip: "Font size", width: 75, btnType: ButtonType.NumberButton, numBtnMax: 200, numBtnMin: 0, numBtnType: NumButtonType.DropdownOptions, ignoreClick: true, script: 'setFontSize' },
- { title: "Font color", toolTip: "Font color", btnType: ButtonType.ColorButton, icon: "font", ignoreClick: true, script: 'setFontColor' },
- { title: "Bold", toolTip: "Bold (Ctrl+B)", btnType: ButtonType.ToggleButton, icon: "bold", click: 'toggleBold()', checkResult: 'toggleBold(true)' },
- { title: "Italic", toolTip: "Italic (Ctrl+I)", btnType: ButtonType.ToggleButton, icon: "italic", click: 'toggleItalic()', checkResult: 'toggleItalic(true)' },
- { title: "Underline", toolTip: "Underline (Ctrl+U)", btnType: ButtonType.ToggleButton, icon: "underline", click: 'toggleUnderline()', checkResult: 'toggleUnderline(true)' },
- { title: "Bullet List", toolTip: "Bullet", btnType: ButtonType.ToggleButton, icon: "list", click: 'setBulletList("bullet")', checkResult: 'setBulletList("bullet", true)' },
- { title: "Number List", toolTip: "Number", btnType: ButtonType.ToggleButton, icon: "list-ol", click: 'setBulletList("decimal")', checkResult: 'setBulletList("decimal", true)' },
+ { title: "Font size", toolTip: "Font size", width: 75, btnType: ButtonType.NumberButton, numBtnMax: 200, numBtnMin: 0, numBtnType: NumButtonType.DropdownOptions, ignoreClick: true, script: 'setFontSize(value, _readOnly_)' },
+ { title: "Font color", toolTip: "Font color", btnType: ButtonType.ColorButton, icon: "font", ignoreClick: true, script: 'setFontColor(value, _readOnly_)' },
+ { title: "Bold", toolTip: "Bold (Ctrl+B)", btnType: ButtonType.ToggleButton, icon: "bold", click: 'toggleBold(_readOnly_)' },
+ { title: "Italic", toolTip: "Italic (Ctrl+I)", btnType: ButtonType.ToggleButton, icon: "italic", click: 'toggleItalic(_readOnly_)' },
+ { title: "Underline", toolTip: "Underline (Ctrl+U)", btnType: ButtonType.ToggleButton, icon: "underline", click: 'toggleUnderline(_readOnly_)' },
+ { title: "Bullet List", toolTip: "Bullet", btnType: ButtonType.ToggleButton, icon: "list", click: 'setBulletList("bullet", _readOnly_)' },
+ { title: "Number List", toolTip: "Number", btnType: ButtonType.ToggleButton, icon: "list-ol", click: 'setBulletList("decimal", _readOnly_)' },
// { 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: "Left align", toolTip: "Left align", btnType: ButtonType.ToggleButton, icon: "align-left", click: 'setAlignment("left")', checkResult: 'setAlignment("left", true)' },
- { title: "Center align", toolTip: "Center align", btnType: ButtonType.ToggleButton, icon: "align-center", click: 'setAlignment("center")', checkResult: 'setAlignment("center", true)' },
- { title: "Right align", toolTip: "Right align", btnType: ButtonType.ToggleButton, icon: "align-right", click: 'setAlignment("right")', checkResult: 'setAlignment("right", true)' },
+ { title: "Left align", toolTip: "Left align", btnType: ButtonType.ToggleButton, icon: "align-left", click: 'setAlignment("left", _readOnly_)' },
+ { title: "Center align", toolTip: "Center align", btnType: ButtonType.ToggleButton, icon: "align-center", click: 'setAlignment("center", _readOnly_)' },
+ { title: "Right align", toolTip: "Right align", btnType: ButtonType.ToggleButton, icon: "align-right", click: 'setAlignment("right", _readOnly_)' },
];
return tools;
}
static inkTools(doc: Doc) {
const tools: Button[] = [
- { title: "Pen", toolTip: "Pen (Ctrl+P)", btnType: ButtonType.ToggleButton, icon: "pen", click: 'setActiveInkTool("pen")', checkResult: 'setActiveInkTool("pen" , true)' },
- { title: "Eraser", toolTip: "Eraser (Ctrl+E)", btnType: ButtonType.ToggleButton, icon: "eraser", click: 'setActiveInkTool("eraser")', checkResult: 'setActiveInkTool("eraser" , true)' },
- // { title: "Highlighter", toolTip: "Highlighter (Ctrl+H)", btnType: ButtonType.ToggleButton, icon: "highlighter", click: 'setActiveInkTool("highlighter")', checkResult: 'setActiveInkTool("highlighter", true)' },
- { title: "Circle", toolTip: "Circle (Ctrl+Shift+C)", btnType: ButtonType.ToggleButton, icon: "circle", click: 'setActiveInkTool("circle")', checkResult: 'setActiveInkTool("circle" , true)' },
- // { title: "Square", toolTip: "Square (Ctrl+Shift+S)", btnType: ButtonType.ToggleButton, icon: "square", click: 'setActiveInkTool("square")', checkResult: 'setActiveInkTool("square" , true)' },
- { title: "Line", toolTip: "Line (Ctrl+Shift+L)", btnType: ButtonType.ToggleButton, icon: "minus", click: 'setActiveInkTool("line")', checkResult: 'setActiveInkTool("line" , true)' },
- { title: "Fill color", toolTip: "Fill color", btnType: ButtonType.ColorButton, ignoreClick: true, icon: "fill-drip", script: "setFillColor" },
- { title: "Stroke width", toolTip: "Stroke width", btnType: ButtonType.NumberButton, numBtnType: NumButtonType.Slider, numBtnMin: 1, ignoreClick: true, script: 'setStrokeWidth' },
- { title: "Stroke color", toolTip: "Stroke color", btnType: ButtonType.ColorButton, icon: "pen", ignoreClick: true, script: 'setStrokeColor' },
+ { title: "Pen", toolTip: "Pen (Ctrl+P)", btnType: ButtonType.ToggleButton, icon: "pen", click: 'setActiveInkTool("pen", _readOnly_)' },
+ { title: "Eraser", toolTip: "Eraser (Ctrl+E)", btnType: ButtonType.ToggleButton, icon: "eraser", click: 'setActiveInkTool("eraser", _readOnly_)' },
+ // { title: "Highlighter", toolTip: "Highlighter (Ctrl+H)", btnType: ButtonType.ToggleButton, icon: "highlighter", click: 'setActiveInkTool("highlighter")' },
+ { title: "Circle", toolTip: "Circle (Ctrl+Shift+C)", btnType: ButtonType.ToggleButton, icon: "circle", click: 'setActiveInkTool("circle", _readOnly_)' },
+ // { title: "Square", toolTip: "Square (Ctrl+Shift+S)", btnType: ButtonType.ToggleButton, icon: "square", click: 'setActiveInkTool("square")' },
+ { title: "Line", toolTip: "Line (Ctrl+Shift+L)", btnType: ButtonType.ToggleButton, icon: "minus", click: 'setActiveInkTool("line", _readOnly_)' },
+ { title: "Fill color", toolTip: "Fill color", btnType: ButtonType.ColorButton, ignoreClick: true, icon: "fill-drip", script: "setFillColor(value, _readOnly_)" },
+ { title: "Stroke width", toolTip: "Stroke width", btnType: ButtonType.NumberButton, numBtnType: NumButtonType.Slider, numBtnMin: 1, ignoreClick: true, script: 'setStrokeWidth(value, _readOnly_)' },
+ { title: "Stroke color", toolTip: "Stroke color", btnType: ButtonType.ColorButton, icon: "pen", ignoreClick: true, script: 'setStrokeColor(value, _readOnly_)' },
];
return tools;
}
@@ -1032,8 +979,7 @@ export class CurrentUserUtils {
btnType: ButtonType.ToggleButton,
buttonText: "Show Preview",
icon: "eye",
- click: 'toggleSchemaPreview()',
- checkResult: 'toggleSchemaPreview(true)'
+ click: 'toggleSchemaPreview(_readOnly_)',
},
];
return tools;
@@ -1042,10 +988,10 @@ export class CurrentUserUtils {
static webTools(doc: Doc) {
const tools: Button[] =
[
- { title: "Back", toolTip: "Go back", btnType: ButtonType.ClickButton, icon: "arrow-left", click: 'webBack()' },
- { title: "Forward", toolTip: "Go forward", btnType: ButtonType.ClickButton, icon: "arrow-right", click: 'webForward()' },
+ { title: "Back", toolTip: "Go back", btnType: ButtonType.ClickButton, icon: "arrow-left", click: 'webBack(_readOnly_)' },
+ { title: "Forward", toolTip: "Go forward", btnType: ButtonType.ClickButton, icon: "arrow-right", click: 'webForward(_readOnly_)' },
//{ title: "Reload", toolTip: "Reload webpage", btnType: ButtonType.ClickButton, icon: "redo-alt", click: 'webReload()' },
- { title: "URL", toolTip: "URL", width: 250, btnType: ButtonType.EditableText, icon: "lock", ignoreClick: true, script: 'webSetURL' },
+ { title: "URL", toolTip: "URL", width: 250, btnType: ButtonType.EditableText, icon: "lock", ignoreClick: true, script: 'webSetURL(value, _readOnly_)' },
];
return tools;
@@ -1059,18 +1005,18 @@ export class CurrentUserUtils {
CollectionViewType.Stacking, CollectionViewType.Masonry, CollectionViewType.Multicolumn,
CollectionViewType.Multirow, CollectionViewType.Time, CollectionViewType.Carousel,
CollectionViewType.Carousel3D, CollectionViewType.Linear, CollectionViewType.Map,
- CollectionViewType.NoteTaking, CollectionViewType.Grid],
- script: 'setView',
+ CollectionViewType.Grid, CollectionViewType.NoteTaking],
+ script: 'setView(value, _readOnly_)',
}, // Always show
{
title: "Background Color", toolTip: "Background Color", btnType: ButtonType.ColorButton, ignoreClick: true, icon: "fill-drip",
- script: "setBackgroundColor", hidden: 'selectedDocumentType()'
+ script: "setBackgroundColor(value, _readOnly_)", hidden: 'selectedDocumentType()'
}, // Only when a document is selected
{
title: "Header Color", toolTip: "Header Color", btnType: ButtonType.ColorButton, ignoreClick: true, icon: "heading",
- script: "setHeaderColor", hidden: 'selectedDocumentType()',
+ script: "setHeaderColor(value, _readOnly_)", hidden: 'selectedDocumentType()',
}, // Only when a document is selected
- { title: "Overlay", toolTip: "Overlay", btnType: ButtonType.ToggleButton, icon: "layer-group", click: 'toggleOverlay()', checkResult: 'toggleOverlay(true)', hidden: 'selectedDocumentType(undefined, "freeform", true)' }, // Only when floating document is selected in freeform
+ { title: "Overlay", toolTip: "Overlay", btnType: ButtonType.ToggleButton, icon: "layer-group", click: 'toggleOverlay(_readOnly_)', hidden: 'selectedDocumentType(undefined, "freeform", true)' }, // Only when floating document is selected in freeform
// { title: "Alias", btnType: ButtonType.ClickButton, icon: "copy", hidden: 'selectedDocumentType()' }, // Only when a document is selected
{ title: "Text", type: "textTools", subMenu: true, expanded: 'selectedDocumentType("rtf")' }, // Always available
{ title: "Ink", type: "inkTools", subMenu: true, expanded: 'selectedDocumentType("ink")' }, // Always available
@@ -1084,7 +1030,7 @@ export class CurrentUserUtils {
if (doc.contextMenuBtns === undefined) {
const docList: Doc[] = [];
- (await CurrentUserUtils.contextMenuTools(doc)).map(({ title, width, list, toolTip, ignoreClick, icon, type, btnType, click, script, subMenu, hidden, expanded, checkResult }) => {
+ (await CurrentUserUtils.contextMenuTools(doc)).map(({ title, width, list, toolTip, ignoreClick, icon, type, btnType, click, script, subMenu, hidden, expanded }) => {
const menuDocList: Doc[] = [];
if (subMenu) {
// default is textTools
@@ -1106,7 +1052,8 @@ export class CurrentUserUtils {
tools = CurrentUserUtils.textTools(doc);
break;
}
- tools.map(({ title, toolTip, icon, btnType, numBtnType, numBtnMax, numBtnMin, click, script, width, list, ignoreClick, switchToggle, checkResult }) => {
+ tools.map(({ title, toolTip, icon, btnType, numBtnType, numBtnMax, numBtnMin, click, script, width, list, ignoreClick, switchToggle }) => {
+ const computed = click ? ComputedField.MakeFunction(click) as any : "transparent";
menuDocList.push(Docs.Create.FontIconDocument({
_nativeWidth: width ? width : 25,
_nativeHeight: 25,
@@ -1117,7 +1064,7 @@ export class CurrentUserUtils {
numBtnType,
numBtnMin,
numBtnMax,
- script,
+ script: script ? ScriptField.MakeScript(script, { value: "any" }) : undefined,
btnType: btnType,
btnList: new List<string>(list),
ignoreClick: ignoreClick,
@@ -1129,10 +1076,10 @@ export class CurrentUserUtils {
title,
switchToggle,
color: Colors.WHITE,
- backgroundColor: checkResult ? ComputedField.MakeFunction(checkResult) as any : "transparent",
+ backgroundColor: computed,
_dropAction: "alias",
_removeDropProperties: new List<string>(["dropAction", "_stayInCollection"]),
- onClick: click ? ScriptField.MakeScript(click, { doc: Doc.name }) : undefined
+ onClick: click ? ScriptField.MakeScript(click) : undefined
}));
});
docList.push(CurrentUserUtils.linearButtonList({
@@ -1142,7 +1089,7 @@ export class CurrentUserUtils {
linearViewExpandable: true,
icon: title,
_height: 30,
- backgroundColor: checkResult ? ComputedField.MakeFunction(checkResult) as any : "transparent",
+ // backgroundColor: hidden ? ComputedField.MakeFunction(hidden, { }, { _readOnly_: true }) as any : "transparent",
linearViewIsExpanded: expanded ? !(ComputedField.MakeFunction(expanded) as any) : undefined,
hidden: hidden ? ComputedField.MakeFunction(hidden) as any : undefined,
}, menuDocList));
@@ -1154,7 +1101,7 @@ export class CurrentUserUtils {
_height: 25,
icon,
toolTip,
- script,
+ script: script ? ScriptField.MakeScript(script, { value: "any" }) : undefined,
btnType,
btnList: new List<string>(list),
ignoreClick,
@@ -1165,11 +1112,11 @@ export class CurrentUserUtils {
dontUndo: true,
title,
color: Colors.WHITE,
- backgroundColor: checkResult ? ComputedField.MakeFunction(checkResult) as any : "transparent",
+ // backgroundColor: checkResult ? ComputedField.MakeFunction(checkResult, {}, {_readOnly_:true}) as any : "transparent",
_dropAction: "alias",
hidden: hidden ? ComputedField.MakeFunction(hidden) as any : undefined,
_removeDropProperties: new List<string>(["dropAction", "_stayInCollection"]),
- onClick: click ? ScriptField.MakeScript(click, { scriptContext: "any" }) : undefined
+ onClick: click ? ScriptField.MakeScript(click, { scriptContext: "any" }, { _readOnly_: false }) : undefined
}));
}
});
@@ -1384,7 +1331,7 @@ export class CurrentUserUtils {
if (response) {
const result: { id: string, email: string, cacheDocumentIds: string } = JSON.parse(response);
Doc.CurrentUserEmail = result.email;
- resolvedPorts = JSON.parse(await Networking.FetchFromServer("/resolvedPorts"));
+ resolvedPorts = JSON.parse(await (await fetch("/resolvedPorts")).text());
DocServer.init(window.location.protocol, window.location.hostname, resolvedPorts.socket, result.email);
result.cacheDocumentIds && (await DocServer.GetRefFields(result.cacheDocumentIds.split(";")));
return result;
@@ -1567,7 +1514,7 @@ export class CurrentUserUtils {
@computed public static get SelectedTool(): InkTool { return StrCast(Doc.UserDoc().activeInkTool, InkTool.None) as InkTool; }
}
-Scripting.addGlobal(function openDragFactory(dragFactory: Doc) {
+ScriptingGlobals.add(function openDragFactory(dragFactory: Doc) {
const copy = Doc.copyDragFactory(dragFactory);
if (copy) {
CollectionDockingView.AddSplit(copy, "right");
@@ -1575,27 +1522,27 @@ Scripting.addGlobal(function openDragFactory(dragFactory: Doc) {
view && SelectionManager.SelectView(view, false);
}
});
-Scripting.addGlobal(function MySharedDocs() { return Doc.SharingDoc(); },
+ScriptingGlobals.add(function MySharedDocs() { return Doc.SharingDoc(); },
"document containing all shared Docs");
-Scripting.addGlobal(function IsNoviceMode() { return Doc.UserDoc().noviceMode; },
+ScriptingGlobals.add(function IsNoviceMode() { return Doc.UserDoc().noviceMode; },
"is Dash in novice mode");
-Scripting.addGlobal(function snapshotDashboard() { CurrentUserUtils.snapshotDashboard(Doc.UserDoc()); },
+ScriptingGlobals.add(function snapshotDashboard() { CurrentUserUtils.snapshotDashboard(Doc.UserDoc()); },
"creates a snapshot copy of a dashboard");
-Scripting.addGlobal(function createNewDashboard() { return CurrentUserUtils.createNewDashboard(Doc.UserDoc()); },
+ScriptingGlobals.add(function createNewDashboard() { return CurrentUserUtils.createNewDashboard(Doc.UserDoc()); },
"creates a new dashboard when called");
-Scripting.addGlobal(function createNewPresentation() { return MainView.Instance.createNewPresentation(); },
+ScriptingGlobals.add(function createNewPresentation() { return MainView.Instance.createNewPresentation(); },
"creates a new presentation when called");
-Scripting.addGlobal(function createNewFolder() { return MainView.Instance.createNewFolder(); },
+ScriptingGlobals.add(function createNewFolder() { return MainView.Instance.createNewFolder(); },
"creates a new folder in myFiles when called");
-Scripting.addGlobal(function links(doc: any) { return new List(LinkManager.Instance.getAllRelatedLinks(doc)); },
+ScriptingGlobals.add(function links(doc: any) { return new List(LinkManager.Instance.getAllRelatedLinks(doc)); },
"returns all the links to the document or its annotations", "(doc: any)");
-Scripting.addGlobal(function importDocument() { return CurrentUserUtils.importDocument(); },
+ScriptingGlobals.add(function importDocument() { return CurrentUserUtils.importDocument(); },
"imports files from device directly into the import sidebar");
-Scripting.addGlobal(function shareDashboard(dashboard: Doc) {
+ScriptingGlobals.add(function shareDashboard(dashboard: Doc) {
SharingManager.Instance.open(undefined, dashboard);
},
"opens sharing dialog for Dashboard");
-Scripting.addGlobal(async function removeDashboard(dashboard: Doc) {
+ScriptingGlobals.add(async function removeDashboard(dashboard: Doc) {
const dashboards = await DocListCastAsync(CurrentUserUtils.MyDashboards.data);
if (dashboards && dashboards.length > 1) {
if (dashboard === CurrentUserUtils.ActiveDashboard) CurrentUserUtils.openDashboard(Doc.UserDoc(), dashboards.find(doc => doc !== dashboard)!);
@@ -1603,7 +1550,7 @@ Scripting.addGlobal(async function removeDashboard(dashboard: Doc) {
}
},
"Remove Dashboard from Dashboards");
-Scripting.addGlobal(async function addToDashboards(dashboard: Doc) {
+ScriptingGlobals.add(async function addToDashboards(dashboard: Doc) {
const dashboardAlias = Doc.MakeAlias(dashboard);
const allDocs = await DocListCastAsync(dashboard[DataSym]["data-all"]);
@@ -1627,7 +1574,7 @@ Scripting.addGlobal(async function addToDashboards(dashboard: Doc) {
/**
* Dynamically computes which docs should be rendered in the off-screen tabs tree of a dashboard.
*/
-Scripting.addGlobal(function dynamicOffScreenDocs(dashboard: Doc) {
+ScriptingGlobals.add(function dynamicOffScreenDocs(dashboard: Doc) {
if (dashboard[DataSym] instanceof Doc) {
const allDocs = DocListCast(dashboard["data-all"]);
const onScreenTab = DocListCast(dashboard.data)[0];
@@ -1639,7 +1586,7 @@ Scripting.addGlobal(function dynamicOffScreenDocs(dashboard: Doc) {
}
return [];
});
-Scripting.addGlobal(function selectedDocumentType(docType?: DocumentType, colType?: CollectionViewType, checkParent?: boolean) {
+ScriptingGlobals.add(function selectedDocumentType(docType?: DocumentType, colType?: CollectionViewType, checkParent?: boolean) {
let selected = SelectionManager.Docs().length ? SelectionManager.Docs()[0] : undefined;
if (selected && checkParent) {
const parentDoc: Doc = Cast(selected.context, Doc, null);
@@ -1650,11 +1597,11 @@ Scripting.addGlobal(function selectedDocumentType(docType?: DocumentType, colTyp
else if (selected && !colType && !docType) return false;
else return true;
});
-Scripting.addGlobal(function makeTopLevelFolder() {
+ScriptingGlobals.add(function makeTopLevelFolder() {
const folder = Docs.Create.TreeDocument([], { title: "Untitled folder", _stayInCollection: true, isFolder: true });
TreeView._editTitleOnLoad = { id: folder[Id], parent: undefined };
return Doc.AddDocToList(Doc.UserDoc().myFilesystem as Doc, "data", folder);
});
-Scripting.addGlobal(function toggleComicMode() {
+ScriptingGlobals.add(function toggleComicMode() {
Doc.UserDoc().renderStyle = Doc.UserDoc().renderStyle === "comic" ? undefined : "comic";
}); \ No newline at end of file
diff --git a/src/client/util/DictationManager.ts b/src/client/util/DictationManager.ts
index a93b2f573..a6dcda4bc 100644
--- a/src/client/util/DictationManager.ts
+++ b/src/client/util/DictationManager.ts
@@ -1,4 +1,6 @@
import * as interpreter from "words-to-numbers";
+// @ts-ignore bcz: how are you supposed to include these definitions since dom-speech-recognition isn't a module?
+import type { } from "@types/dom-speech-recognition";
import { Doc, Opt } from "../../fields/Doc";
import { List } from "../../fields/List";
import { RichTextField } from "../../fields/RichTextField";
@@ -13,6 +15,7 @@ import { DocumentView } from "../views/nodes/DocumentView";
import { SelectionManager } from "./SelectionManager";
import { UndoManager } from "./UndoManager";
+
/**
* This namespace provides a singleton instance of a manager that
* handles the listening and text-conversion of user speech.
@@ -102,17 +105,17 @@ export namespace DictationManager {
try {
results = await (pendingListen = listenImpl(options));
pendingListen = undefined;
- if (results) {
- Utils.CopyText(results);
- if (overlay) {
- DictationOverlay.Instance.isListening = false;
- const execute = options?.tryExecute;
- DictationOverlay.Instance.dictatedPhrase = execute ? results.toLowerCase() : results;
- DictationOverlay.Instance.dictationSuccess = execute ? await DictationManager.Commands.execute(results) : true;
- }
- options?.tryExecute && await DictationManager.Commands.execute(results);
- }
- } catch (e) {
+ // if (results) {
+ // Utils.CopyText(results);
+ // if (overlay) {
+ // DictationOverlay.Instance.isListening = false;
+ // const execute = options?.tryExecute;
+ // DictationOverlay.Instance.dictatedPhrase = execute ? results.toLowerCase() : results;
+ // DictationOverlay.Instance.dictationSuccess = execute ? await DictationManager.Commands.execute(results) : true;
+ // }
+ // options?.tryExecute && await DictationManager.Commands.execute(results);
+ // }
+ } catch (e: any) {
console.log(e);
if (overlay) {
DictationOverlay.Instance.isListening = false;
@@ -188,7 +191,7 @@ export namespace DictationManager {
current && sessionResults.push(current);
sessionResults.length && resolve(sessionResults.join(inter || interSession));
} else {
- resolve(current);
+ resolve(current || "");
}
current = undefined;
sessionResults = [];
@@ -222,168 +225,168 @@ export namespace DictationManager {
}
- export namespace Commands {
-
- export const dictationFadeDuration = 2000;
-
- export type IndependentAction = (target: DocumentView) => any | Promise<any>;
- export type IndependentEntry = { action: IndependentAction, restrictTo?: DocumentType[] };
-
- export type DependentAction = (target: DocumentView, matches: RegExpExecArray) => any | Promise<any>;
- export type DependentEntry = { expression: RegExp, action: DependentAction, restrictTo?: DocumentType[] };
-
- export const RegisterIndependent = (key: string, value: IndependentEntry) => Independent.set(key, value);
- export const RegisterDependent = (entry: DependentEntry) => Dependent.push(entry);
-
- export const execute = async (phrase: string) => {
- return UndoManager.RunInBatch(async () => {
- const targets = SelectionManager.Views();
- if (!targets || !targets.length) {
- return;
- }
-
- phrase = phrase.toLowerCase();
- const entry = Independent.get(phrase);
-
- if (entry) {
- let success = false;
- const restrictTo = entry.restrictTo;
- for (const target of targets) {
- if (!restrictTo || validate(target, restrictTo)) {
- await entry.action(target);
- success = true;
- }
- }
- return success;
- }
-
- for (const entry of Dependent) {
- const regex = entry.expression;
- const matches = regex.exec(phrase);
- regex.lastIndex = 0;
- if (matches !== null) {
- let success = false;
- const restrictTo = entry.restrictTo;
- for (const target of targets) {
- if (!restrictTo || validate(target, restrictTo)) {
- await entry.action(target, matches);
- success = true;
- }
- }
- return success;
- }
- }
-
- return false;
- }, "Execute Command");
- };
-
- const ConstructorMap = new Map<DocumentType, CastCtor>([
- [DocumentType.COL, listSpec(Doc)],
- [DocumentType.AUDIO, AudioField],
- [DocumentType.IMG, ImageField],
- [DocumentType.IMPORT, listSpec(Doc)],
- [DocumentType.RTF, "string"]
- ]);
-
- const tryCast = (view: DocumentView, type: DocumentType) => {
- const ctor = ConstructorMap.get(type);
- if (!ctor) {
- return false;
- }
- return Cast(Doc.GetProto(view.props.Document).data, ctor) !== undefined;
- };
-
- const validate = (target: DocumentView, types: DocumentType[]) => {
- for (const type of types) {
- if (tryCast(target, type)) {
- return true;
- }
- }
- return false;
- };
-
- const interpretNumber = (number: string) => {
- const initial = parseInt(number);
- if (!isNaN(initial)) {
- return initial;
- }
- const converted = interpreter.wordsToNumbers(number, { fuzzy: true });
- if (converted === null) {
- return NaN;
- }
- return typeof converted === "string" ? parseInt(converted) : converted;
- };
-
- const Independent = new Map<string, IndependentEntry>([
-
- ["clear", {
- action: (target: DocumentView) => Doc.GetProto(target.props.Document).data = new List(),
- restrictTo: [DocumentType.COL]
- }],
-
- ["open fields", {
- action: (target: DocumentView) => {
- const kvp = Docs.Create.KVPDocument(target.props.Document, { _width: 300, _height: 300 });
- target.props.addDocTab(kvp, "add:right");
- }
- }],
-
- ["new outline", {
- action: (target: DocumentView) => {
- const newBox = Docs.Create.TextDocument("", { _width: 400, _height: 200, title: "My Outline", _autoHeight: true });
- const proto = newBox.proto!;
- const prompt = "Press alt + r to start dictating here...";
- const head = 3;
- const anchor = head + prompt.length;
- const proseMirrorState = `{"doc":{"type":"doc","content":[{"type":"ordered_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"type":"text","text":"${prompt}"}]}]}]}]},"selection":{"type":"text","anchor":${anchor},"head":${head}}}`;
- proto.data = new RichTextField(proseMirrorState);
- proto.backgroundColor = "#eeffff";
- target.props.addDocTab(newBox, "add:right");
- }
- }]
-
- ]);
-
- const Dependent = new Array<DependentEntry>(
-
- {
- expression: /create (\w+) documents of type (image|nested collection)/g,
- action: (target: DocumentView, matches: RegExpExecArray) => {
- const count = interpretNumber(matches[1]);
- const what = matches[2];
- const dataDoc = Doc.GetProto(target.props.Document);
- const fieldKey = "data";
- if (isNaN(count)) {
- return;
- }
- for (let i = 0; i < count; i++) {
- let created: Doc | undefined;
- switch (what) {
- case "image":
- created = Docs.Create.ImageDocument("https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg");
- break;
- case "nested collection":
- created = Docs.Create.FreeformDocument([], {});
- break;
- }
- created && Doc.AddDocToList(dataDoc, fieldKey, created);
- }
- },
- restrictTo: [DocumentType.COL]
- },
-
- {
- expression: /view as (freeform|stacking|masonry|schema|tree)/g,
- action: (target: DocumentView, matches: RegExpExecArray) => {
- const mode = matches[1];
- mode && (target.props.Document._viewType = mode);
- },
- restrictTo: [DocumentType.COL]
- }
-
- );
-
- }
+ // export namespace Commands {
+
+ // export const dictationFadeDuration = 2000;
+
+ // export type IndependentAction = (target: DocumentView) => any | Promise<any>;
+ // export type IndependentEntry = { action: IndependentAction, restrictTo?: DocumentType[] };
+
+ // export type DependentAction = (target: DocumentView, matches: RegExpExecArray) => any | Promise<any>;
+ // export type DependentEntry = { expression: RegExp, action: DependentAction, restrictTo?: DocumentType[] };
+
+ // export const RegisterIndependent = (key: string, value: IndependentEntry) => Independent.set(key, value);
+ // export const RegisterDependent = (entry: DependentEntry) => Dependent.push(entry);
+
+ // export const execute = async (phrase: string) => {
+ // return UndoManager.RunInBatch(async () => {
+ // const targets = SelectionManager.Views();
+ // if (!targets || !targets.length) {
+ // return;
+ // }
+
+ // phrase = phrase.toLowerCase();
+ // const entry = Independent.get(phrase);
+
+ // if (entry) {
+ // let success = false;
+ // const restrictTo = entry.restrictTo;
+ // for (const target of targets) {
+ // if (!restrictTo || validate(target, restrictTo)) {
+ // await entry.action(target);
+ // success = true;
+ // }
+ // }
+ // return success;
+ // }
+
+ // for (const entry of Dependent) {
+ // const regex = entry.expression;
+ // const matches = regex.exec(phrase);
+ // regex.lastIndex = 0;
+ // if (matches !== null) {
+ // let success = false;
+ // const restrictTo = entry.restrictTo;
+ // for (const target of targets) {
+ // if (!restrictTo || validate(target, restrictTo)) {
+ // await entry.action(target, matches);
+ // success = true;
+ // }
+ // }
+ // return success;
+ // }
+ // }
+
+ // return false;
+ // }, "Execute Command");
+ // };
+
+ // const ConstructorMap = new Map<DocumentType, CastCtor>([
+ // [DocumentType.COL, listSpec(Doc)],
+ // [DocumentType.AUDIO, AudioField],
+ // [DocumentType.IMG, ImageField],
+ // [DocumentType.IMPORT, listSpec(Doc)],
+ // [DocumentType.RTF, "string"]
+ // ]);
+
+ // const tryCast = (view: DocumentView, type: DocumentType) => {
+ // const ctor = ConstructorMap.get(type);
+ // if (!ctor) {
+ // return false;
+ // }
+ // return Cast(Doc.GetProto(view.props.Document).data, ctor) !== undefined;
+ // };
+
+ // const validate = (target: DocumentView, types: DocumentType[]) => {
+ // for (const type of types) {
+ // if (tryCast(target, type)) {
+ // return true;
+ // }
+ // }
+ // return false;
+ // };
+
+ // const interpretNumber = (number: string) => {
+ // const initial = parseInt(number);
+ // if (!isNaN(initial)) {
+ // return initial;
+ // }
+ // const converted = interpreter.wordsToNumbers(number, { fuzzy: true });
+ // if (converted === null) {
+ // return NaN;
+ // }
+ // return typeof converted === "string" ? parseInt(converted) : converted;
+ // };
+
+ // const Independent = new Map<string, IndependentEntry>([
+
+ // ["clear", {
+ // action: (target: DocumentView) => Doc.GetProto(target.props.Document).data = new List(),
+ // restrictTo: [DocumentType.COL]
+ // }],
+
+ // ["open fields", {
+ // action: (target: DocumentView) => {
+ // const kvp = Docs.Create.KVPDocument(target.props.Document, { _width: 300, _height: 300 });
+ // target.props.addDocTab(kvp, "add:right");
+ // }
+ // }],
+
+ // ["new outline", {
+ // action: (target: DocumentView) => {
+ // const newBox = Docs.Create.TextDocument("", { _width: 400, _height: 200, title: "My Outline", _autoHeight: true });
+ // const proto = newBox.proto!;
+ // const prompt = "Press alt + r to start dictating here...";
+ // const head = 3;
+ // const anchor = head + prompt.length;
+ // const proseMirrorState = `{"doc":{"type":"doc","content":[{"type":"ordered_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"type":"text","text":"${prompt}"}]}]}]}]},"selection":{"type":"text","anchor":${anchor},"head":${head}}}`;
+ // proto.data = new RichTextField(proseMirrorState);
+ // proto.backgroundColor = "#eeffff";
+ // target.props.addDocTab(newBox, "add:right");
+ // }
+ // }]
+
+ // ]);
+
+ // const Dependent = new Array<DependentEntry>(
+
+ // {
+ // expression: /create (\w+) documents of type (image|nested collection)/g,
+ // action: (target: DocumentView, matches: RegExpExecArray) => {
+ // const count = interpretNumber(matches[1]);
+ // const what = matches[2];
+ // const dataDoc = Doc.GetProto(target.props.Document);
+ // const fieldKey = "data";
+ // if (isNaN(count)) {
+ // return;
+ // }
+ // for (let i = 0; i < count; i++) {
+ // let created: Doc | undefined;
+ // switch (what) {
+ // case "image":
+ // created = Docs.Create.ImageDocument("https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg");
+ // break;
+ // case "nested collection":
+ // created = Docs.Create.FreeformDocument([], {});
+ // break;
+ // }
+ // created && Doc.AddDocToList(dataDoc, fieldKey, created);
+ // }
+ // },
+ // restrictTo: [DocumentType.COL]
+ // },
+
+ // {
+ // expression: /view as (freeform|stacking|masonry|schema|tree)/g,
+ // action: (target: DocumentView, matches: RegExpExecArray) => {
+ // const mode = matches[1];
+ // mode && (target.props.Document._viewType = mode);
+ // },
+ // restrictTo: [DocumentType.COL]
+ // }
+
+ // );
+
+ // }
} \ No newline at end of file
diff --git a/src/client/util/DocumentManager.ts b/src/client/util/DocumentManager.ts
index 66b6a1e44..0a00ab6e0 100644
--- a/src/client/util/DocumentManager.ts
+++ b/src/client/util/DocumentManager.ts
@@ -9,7 +9,7 @@ import { CollectionView } from '../views/collections/CollectionView';
import { LightboxView } from '../views/LightboxView';
import { DocumentView, ViewAdjustment } from '../views/nodes/DocumentView';
import { LinkAnchorBox } from '../views/nodes/LinkAnchorBox';
-import { Scripting } from './Scripting';
+import { ScriptingGlobals } from './ScriptingGlobals';
import { SelectionManager } from './SelectionManager';
export class DocumentManager {
@@ -198,7 +198,7 @@ export class DocumentManager {
originalTarget, willZoom, scale: presZoom, afterFocus: (didFocus: boolean) =>
new Promise<ViewAdjustment>(res => {
focusAndFinish(didFocus);
- res();
+ res(ViewAdjustment.doNothing);
})
});
} else {
@@ -227,7 +227,7 @@ export class DocumentManager {
willZoom, afterFocus: (didFocus: boolean) =>
new Promise<ViewAdjustment>(res => {
!noSelect && focusAndFinish(didFocus);
- res();
+ res(ViewAdjustment.doNothing);
})
}); // focus on the target in the context
} else if (delay > 1500) {
@@ -252,7 +252,7 @@ export class DocumentManager {
}
}
-Scripting.addGlobal(function DocFocusOrOpen(doc: any) {
+ScriptingGlobals.add(function DocFocusOrOpen(doc: any) {
const dv = DocumentManager.Instance.getDocumentView(doc);
if (dv && dv.props.Document === doc) {
dv.props.focus(doc, { willZoom: true });
diff --git a/src/client/util/DragManager.ts b/src/client/util/DragManager.ts
index ae3fa3170..c9c499fff 100644
--- a/src/client/util/DragManager.ts
+++ b/src/client/util/DragManager.ts
@@ -499,7 +499,7 @@ export namespace DragManager {
screenX: e.screenX,
screenY: e.screenY,
detail: e.detail,
- view: e.view ? e.view : new Window,
+ view: e.view ? e.view : new Window as any,
nativeEvent: new DragEvent("dashDragAutoScroll"),
currentTarget: target,
target: target,
diff --git a/src/client/util/DropConverter.ts b/src/client/util/DropConverter.ts
index 32817eefd..082b6d8bd 100644
--- a/src/client/util/DropConverter.ts
+++ b/src/client/util/DropConverter.ts
@@ -7,7 +7,7 @@ import { Docs } from "../documents/Documents";
import { ScriptField, ComputedField } from "../../fields/ScriptField";
import { RichTextField } from "../../fields/RichTextField";
import { ImageField } from "../../fields/URLField";
-import { Scripting } from "./Scripting";
+import { ScriptingGlobals } from "./ScriptingGlobals";
import { listSpec } from "../../fields/Schema";
//
@@ -81,5 +81,5 @@ export function convertDropDataToButtons(data: DragManager.DocumentDragData) {
data.droppedDocuments[i] = dbox;
});
}
-Scripting.addGlobal(function convertToButtons(dragData: any) { convertDropDataToButtons(dragData as DragManager.DocumentDragData); },
+ScriptingGlobals.add(function convertToButtons(dragData: any) { convertDropDataToButtons(dragData as DragManager.DocumentDragData); },
"converts the dropped data to buttons", "(dragData: any)"); \ No newline at end of file
diff --git a/src/client/util/History.ts b/src/client/util/History.ts
index cbe36b401..e6f75a7db 100644
--- a/src/client/util/History.ts
+++ b/src/client/util/History.ts
@@ -103,8 +103,7 @@ export namespace HistoryUtil {
return undefined;
}
const parser = requiredFields[required];
- let value = opts[required];
- value = parse(parser, value);
+ const value = parse(parser, opts[required]);
if (value !== null && value !== undefined) {
current[required] = value;
}
@@ -114,8 +113,7 @@ export namespace HistoryUtil {
continue;
}
const parser = optionalFields[opt];
- let value = opts[opt];
- value = parse(parser, value);
+ const value = parse(parser, opts[opt]);
if (value !== undefined) {
current[opt] = value;
}
diff --git a/src/client/util/Import & Export/DirectoryImportBox.tsx b/src/client/util/Import & Export/DirectoryImportBox.tsx
index 925b74efa..39e9251a5 100644
--- a/src/client/util/Import & Export/DirectoryImportBox.tsx
+++ b/src/client/util/Import & Export/DirectoryImportBox.tsx
@@ -1,9 +1,8 @@
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { BatchedArray } from "array-batcher";
-import "fs";
import { action, computed, IReactionDisposer, observable, reaction, runInAction } from "mobx";
import { observer } from "mobx-react";
-import * as path from 'path';
+import { extname } from "path";
import Measure, { ContentRect } from "react-measure";
import { Doc, DocListCast, DocListCastAsync, Opt } from "../../../fields/Doc";
import { Id } from "../../../fields/FieldSymbols";
@@ -86,7 +85,7 @@ export class DirectoryImportBox extends React.Component<FieldViewProps> {
for (let i = 0; i < files.length; i++) {
const file = files.item(i);
if (file && !unsupported.includes(file.type)) {
- const ext = path.extname(file.name).toLowerCase();
+ const ext = extname(file.name).toLowerCase();
if (AcceptableMedia.imageFormats.includes(ext)) {
validated.push(file);
}
@@ -120,7 +119,7 @@ export class DirectoryImportBox extends React.Component<FieldViewProps> {
}
const { accessPaths, exifData } = result;
const path = Utils.prepend(accessPaths.agnostic.client);
- const document = await DocUtils.DocumentFromType(type, path, { _width: 300, title: name });
+ const document = type && await DocUtils.DocumentFromType(type, path, { _width: 300 });
const { data, error } = exifData;
if (document) {
Doc.GetProto(document).exif = error || Doc.Get.FromJson({ data });
diff --git a/src/client/util/LinkManager.ts b/src/client/util/LinkManager.ts
index 62b13e2c6..df2c02a8d 100644
--- a/src/client/util/LinkManager.ts
+++ b/src/client/util/LinkManager.ts
@@ -194,7 +194,7 @@ export class LinkManager {
afterFocus: (didFocus: boolean) => {
finished?.();
res(ViewAdjustment.resetView);
- return new Promise<ViewAdjustment>(res2 => res2());
+ return new Promise<ViewAdjustment>(res2 => res2(ViewAdjustment.doNothing));
}
});
} else {
diff --git a/src/client/util/ScriptManager.ts b/src/client/util/ScriptManager.ts
index 94806a7ba..42a6493ea 100644
--- a/src/client/util/ScriptManager.ts
+++ b/src/client/util/ScriptManager.ts
@@ -1,9 +1,9 @@
import { Doc, DocListCast } from "../../fields/Doc";
import { List } from "../../fields/List";
-import { Scripting } from "./Scripting";
-import { StrCast, Cast } from "../../fields/Types";
import { listSpec } from "../../fields/Schema";
+import { Cast, StrCast } from "../../fields/Types";
import { Docs } from "../documents/Documents";
+import { ScriptingGlobals } from "./ScriptingGlobals";
export class ScriptManager {
@@ -44,7 +44,7 @@ export class ScriptManager {
public deleteScript(scriptDoc: Doc): boolean {
if (scriptDoc.name) {
- Scripting.removeGlobal(StrCast(scriptDoc.name));
+ ScriptingGlobals.removeGlobal(StrCast(scriptDoc.name));
}
const scriptList = this.getAllScripts();
const index = scriptList.indexOf(scriptDoc);
@@ -60,7 +60,7 @@ export class ScriptManager {
public static addScriptToGlobals(scriptDoc: Doc): void {
- Scripting.removeGlobal(StrCast(scriptDoc.name));
+ ScriptingGlobals.removeGlobal(StrCast(scriptDoc.name));
const params = Cast(scriptDoc["data-params"], listSpec("string"), []);
const paramNames = params.reduce((o: string, p: string) => {
@@ -86,9 +86,9 @@ export class ScriptManager {
});
if (parameters === "(") {
- Scripting.addGlobal(f, StrCast(scriptDoc.description));
+ ScriptingGlobals.add(f, StrCast(scriptDoc.description));
} else {
- Scripting.addGlobal(f, StrCast(scriptDoc.description), parameters);
+ ScriptingGlobals.add(f, StrCast(scriptDoc.description), parameters);
}
}
} \ No newline at end of file
diff --git a/src/client/util/Scripting.ts b/src/client/util/Scripting.ts
index 40b94024e..3b0a47b54 100644
--- a/src/client/util/Scripting.ts
+++ b/src/client/util/Scripting.ts
@@ -1,16 +1,15 @@
-import * as ts from "typescript";
-export { ts };
-
// export const ts = (window as any).ts;
-
// // @ts-ignore
// import * as typescriptlib from '!!raw-loader!../../../node_modules/typescript/lib/lib.d.ts'
// // @ts-ignore
// import * as typescriptes5 from '!!raw-loader!../../../node_modules/typescript/lib/lib.es5.d.ts'
-
// @ts-ignore
import * as typescriptlib from '!!raw-loader!./type_decls.d';
-import { Doc, Field } from '../../fields/Doc';
+import * as ts from "typescript";
+import { Doc, Field } from "../../fields/Doc";
+import { scriptingGlobals, ScriptingGlobals } from "./ScriptingGlobals";
+export { ts };
+
export interface ScriptSuccess {
success: true;
@@ -47,98 +46,6 @@ export function isCompileError(toBeDetermined: CompileResult): toBeDetermined is
return false;
}
-export namespace Scripting {
- export function addGlobal(global: { name: string }): void;
- export function addGlobal(name: string, global: any): void;
-
- export function addGlobal(global: { name: string }, decription?: string, params?: string): void;
-
- export function addGlobal(first: any, second?: any, third?: string) {
- let n: any;
- let obj: any;
-
- if (second !== undefined) {
- if (typeof first === "string") {
- n = first;
- obj = second;
- } else {
- obj = first;
- n = first.name;
- _scriptingDescriptions[n] = second;
- if (third !== undefined) {
- _scriptingParams[n] = third;
- }
- }
- } else if (first && typeof first.name === "string") {
- n = first.name;
- obj = first;
- } else {
- throw new Error("Must either register an object with a name, or give a name and an object");
- }
- if (n === undefined || n === "undefined") {
- return false;
- } else if (_scriptingGlobals.hasOwnProperty(n)) {
- throw new Error(`Global with name ${n} is already registered, choose another name`);
- }
- _scriptingGlobals[n] = obj;
- }
-
- export function makeMutableGlobalsCopy(globals?: { [name: string]: any }) {
- return { ..._scriptingGlobals, ...(globals || {}) };
- }
-
- export function setScriptingGlobals(globals: { [key: string]: any }) {
- scriptingGlobals = globals;
- }
-
- export function removeGlobal(name: string) {
- if (getGlobals().includes(name)) {
- delete _scriptingGlobals[name];
- if (_scriptingDescriptions[name]) {
- delete _scriptingDescriptions[name];
- }
- if (_scriptingParams[name]) {
- delete _scriptingParams[name];
- }
- return true;
- }
- return false;
- }
-
- export function resetScriptingGlobals() {
- scriptingGlobals = _scriptingGlobals;
- }
-
- // const types = Object.keys(ts.SyntaxKind).map(kind => ts.SyntaxKind[kind]);
- export function printNodeType(node: any, indentation = "") {
- console.log(indentation + ts.SyntaxKind[node.kind]);
- }
-
- export function getGlobals() {
- return Object.keys(_scriptingGlobals);
- }
-
- export function getGlobalObj() {
- return _scriptingGlobals;
- }
-
- export function getDescriptions() {
- return _scriptingDescriptions;
- }
-
- export function getParameters() {
- return _scriptingParams;
- }
-}
-
-export function scriptingGlobal(constructor: { new(...args: any[]): any }) {
- Scripting.addGlobal(constructor);
-}
-
-export const _scriptingGlobals: { [name: string]: any } = {};
-let scriptingGlobals: { [name: string]: any } = _scriptingGlobals;
-const _scriptingDescriptions: { [name: string]: any } = {};
-const _scriptingParams: { [name: string]: any } = {};
function Run(script: string | undefined, customParams: string[], diagnostics: any[], originalScript: string, options: ScriptOptions): CompileResult {
const errors = diagnostics.filter(diag => diag.category === ts.DiagnosticCategory.Error);
@@ -273,7 +180,7 @@ export function CompileScript(script: string, options: ScriptOptions = {}): Comp
if (options.params && !options.params.this) options.params.this = Doc.name;
if (options.params && !options.params.self) options.params.self = Doc.name;
if (options.globals) {
- Scripting.setScriptingGlobals(options.globals);
+ ScriptingGlobals.setScriptingGlobals(options.globals);
}
const host = new ScriptingCompilerHost;
if (options.traverser) {
@@ -331,9 +238,9 @@ export function CompileScript(script: string, options: ScriptOptions = {}): Comp
const result = Run(outputText, paramNames, diagnostics, script, options);
if (options.globals) {
- Scripting.resetScriptingGlobals();
+ ScriptingGlobals.resetScriptingGlobals();
}
return result;
}
-Scripting.addGlobal(CompileScript); \ No newline at end of file
+ScriptingGlobals.add(CompileScript);
diff --git a/src/client/util/ScriptingGlobals.ts b/src/client/util/ScriptingGlobals.ts
new file mode 100644
index 000000000..f151acd81
--- /dev/null
+++ b/src/client/util/ScriptingGlobals.ts
@@ -0,0 +1,81 @@
+
+import * as ts from "typescript";
+export { ts };
+
+export namespace ScriptingGlobals {
+ export function add(global: { name: string }): void;
+ export function add(name: string, global: any): void;
+ export function add(global: { name: string }, decription?: string, params?: string): void;
+ export function add(first: any, second?: any, third?: string) {
+ let n: any;
+ let obj: any;
+
+ if (second !== undefined) {
+ if (typeof first === "string") {
+ n = first;
+ obj = second;
+ } else {
+ obj = first;
+ n = first.name;
+ _scriptingDescriptions[n] = second;
+ if (third !== undefined) {
+ _scriptingParams[n] = third;
+ }
+ }
+ } else if (first && typeof first.name === "string") {
+ n = first.name;
+ obj = first;
+ } else {
+ throw new Error("Must either register an object with a name, or give a name and an object");
+ }
+ if (n === undefined || n === "undefined") {
+ return false;
+ } else if (_scriptingGlobals.hasOwnProperty(n)) {
+ throw new Error(`Global with name ${n} is already registered, choose another name`);
+ }
+ _scriptingGlobals[n] = obj;
+ }
+ export function makeMutableGlobalsCopy(globals?: { [name: string]: any }) {
+ return { ..._scriptingGlobals, ...(globals || {}) };
+ }
+
+ export function setScriptingGlobals(globals: { [key: string]: any }) {
+ scriptingGlobals = globals;
+ }
+
+ export function removeGlobal(name: string) {
+ if (getGlobals().includes(name)) {
+ delete _scriptingGlobals[name];
+ if (_scriptingDescriptions[name]) {
+ delete _scriptingDescriptions[name];
+ }
+ if (_scriptingParams[name]) {
+ delete _scriptingParams[name];
+ }
+ return true;
+ }
+ return false;
+ }
+
+ export function resetScriptingGlobals() { scriptingGlobals = _scriptingGlobals; }
+
+ // const types = Object.keys(ts.SyntaxKind).map(kind => ts.SyntaxKind[kind]);
+ export function printNodeType(node: any, indentation = "") { console.log(indentation + ts.SyntaxKind[node.kind]); }
+
+ export function getGlobals() { return Object.keys(_scriptingGlobals); }
+
+ export function getGlobalObj() { return _scriptingGlobals; }
+
+ export function getDescriptions() { return _scriptingDescriptions; }
+
+ export function getParameters() { return _scriptingParams; }
+}
+
+export function scriptingGlobal(constructor: { new(...args: any[]): any }) {
+ ScriptingGlobals.add(constructor);
+}
+
+const _scriptingGlobals: { [name: string]: any } = {};
+export let scriptingGlobals: { [name: string]: any } = _scriptingGlobals;
+const _scriptingDescriptions: { [name: string]: any } = {};
+const _scriptingParams: { [name: string]: any } = {}; \ No newline at end of file
diff --git a/src/client/util/UndoManager.ts b/src/client/util/UndoManager.ts
index 44e44d335..d1f1a0099 100644
--- a/src/client/util/UndoManager.ts
+++ b/src/client/util/UndoManager.ts
@@ -1,5 +1,4 @@
import { observable, action, runInAction } from "mobx";
-import 'source-map-support/register';
import { Without } from "../../Utils";
function getBatchName(target: any, key: string | symbol): string {
@@ -107,7 +106,7 @@ export namespace UndoManager {
}
export function FilterBatches(fieldTypes: string[]) {
const fieldCounts: { [key: string]: number } = {};
- const lastStack = UndoManager.undoStack.lastElement();
+ const lastStack = UndoManager.undoStack.slice(-1)[0];//.lastElement();
if (lastStack) {
lastStack.forEach(ev => fieldTypes.includes(ev.prop) && (fieldCounts[ev.prop] = (fieldCounts[ev.prop] || 0) + 1));
const fieldCount2: { [key: string]: number } = {};