aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBob Zeleznik <zzzman@gmail.com>2019-10-15 00:23:00 -0400
committerBob Zeleznik <zzzman@gmail.com>2019-10-15 00:23:00 -0400
commit26e215b0cddbb4c14cfd8eb7a720a373e797c615 (patch)
tree6fee5686953a7926627cc10f4f5cf27f79bb231a /src
parente8e713173e93eaa9fc2d2865d5efabdcca51b1f3 (diff)
cleaned up current_user_utils. cleaned up some interactions with colorBox, textbox height
Diffstat (limited to 'src')
-rw-r--r--src/client/documents/Documents.ts19
-rw-r--r--src/client/views/DocComponent.tsx34
-rw-r--r--src/client/views/InkingControl.tsx8
-rw-r--r--src/client/views/MainView.tsx16
-rw-r--r--src/client/views/nodes/ColorBox.scss7
-rw-r--r--src/client/views/nodes/ColorBox.tsx12
-rw-r--r--src/client/views/nodes/FormattedTextBox.tsx13
-rw-r--r--src/client/views/nodes/PDFBox.tsx3
-rw-r--r--src/server/authentication/models/current_user_utils.ts295
9 files changed, 229 insertions, 178 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index 1f89d2993..13cc7815c 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -40,7 +40,7 @@ import { ButtonBox } from "../views/nodes/ButtonBox";
import { FontIconBox } from "../views/nodes/FontIconBox";
import { SchemaHeaderField, RandomPastel } from "../../new_fields/SchemaHeaderField";
import { PresBox } from "../views/nodes/PresBox";
-import { ComputedField } from "../../new_fields/ScriptField";
+import { ComputedField, ScriptField } from "../../new_fields/ScriptField";
import { ProxyField } from "../../new_fields/Proxy";
import { DocumentType } from "./DocumentTypes";
import { LinkFollowBox } from "../views/linking/LinkFollowBox";
@@ -65,7 +65,10 @@ export interface DocumentOptions {
page?: number;
scale?: number;
fitWidth?: boolean;
+ forceActive?: boolean;
+ preventTreeViewOpen?: boolean; // ignores the treeViewOpen Doc flag which allows a treeViewItem's expande/collapse state to be independent of other views of the same document in the tree view
layout?: string | Doc;
+ hideHeadings?: boolean; // whether stacking view column headings should be hidden
isTemplate?: boolean;
templates?: List<string>;
viewType?: number;
@@ -84,11 +87,21 @@ export interface DocumentOptions {
documentText?: string;
borderRounding?: string;
boxShadow?: string;
+ sectionFilter?: string; // field key used to determine headings for sections in stacking and masonry views
schemaColumns?: List<SchemaHeaderField>;
dockingConfig?: string;
autoHeight?: boolean;
+ removeDropProperties?: List<string>; // list of properties that should be removed from a document when it is dropped. e.g., a creator button may be forceActive to allow it be dragged, but the forceActive property can be removed from the dropped document
dbDoc?: Doc;
+ onClick?: ScriptField;
+ onDragStart?: ScriptField; //script to execute at start of drag operation -- e.g., when a "creator" button is dragged this script generates a different document to drop
icon?: string;
+ gridGap?: number; // gap between items in masonry view
+ xMargin?: number; // gap between left edge of document and start of masonry/stacking layouts
+ yMargin?: number; // gap between top edge of dcoument and start of masonry/stacking layouts
+ panel?: Doc; // panel to display in 'targetContainer' as the result of a button onClick script
+ targetContainer?: Doc; // document whose proto will be set to 'panel' as the result of a onClick click script
+ convertToButtons?: boolean; // whether documents dropped onto a collection should be converted to buttons that will construct the dropped document
// [key: string]: Opt<Field>;
}
@@ -457,6 +470,10 @@ export namespace Docs {
return InstanceFromProto(Prototypes.get(DocumentType.COL), new List(documents), { chromeStatus: "collapsed", schemaColumns: new List([new SchemaHeaderField("title", "#f1efeb")]), ...options, viewType: CollectionViewType.Freeform }, id);
}
+ export function LinearDocument(documents: Array<Doc>, options: DocumentOptions, id?: string) {
+ return InstanceFromProto(Prototypes.get(DocumentType.COL), new List(documents), { chromeStatus: "collapsed", schemaColumns: new List([new SchemaHeaderField("title", "#f1efeb")]), ...options, viewType: CollectionViewType.Linear }, id);
+ }
+
export function SchemaDocument(schemaColumns: SchemaHeaderField[], documents: Array<Doc>, options: DocumentOptions) {
return InstanceFromProto(Prototypes.get(DocumentType.COL), new List(documents), { chromeStatus: "collapsed", schemaColumns: new List(schemaColumns), ...options, viewType: CollectionViewType.Schema });
}
diff --git a/src/client/views/DocComponent.tsx b/src/client/views/DocComponent.tsx
index 2c5992259..b05966bb5 100644
--- a/src/client/views/DocComponent.tsx
+++ b/src/client/views/DocComponent.tsx
@@ -1,10 +1,17 @@
import * as React from 'react';
import { Doc } from '../../new_fields/Doc';
import { computed, action } from 'mobx';
-import { Cast } from '../../new_fields/Types';
+import { Cast, BoolCast } from '../../new_fields/Types';
import { listSpec } from '../../new_fields/Schema';
+import { InkingControl } from './InkingControl';
+import { InkTool } from '../../new_fields/InkField';
-export function DocComponent<P extends { Document: Doc }, T>(schemaCtor: (doc: Doc) => T) {
+
+/// DocComponents returns a generic base class for React views of document fields that are not interactive
+interface DocComponentProps {
+ Document: Doc;
+}
+export function DocComponent<P extends DocComponentProps, T>(schemaCtor: (doc: Doc) => T) {
class Component extends React.Component<P> {
//TODO This might be pretty inefficient if doc isn't observed, because computed doesn't cache then
@computed
@@ -15,6 +22,27 @@ export function DocComponent<P extends { Document: Doc }, T>(schemaCtor: (doc: D
return Component;
}
+
+/// DocStaticProps return a base class for React views of document fields that are interactive only when selected (e.g. ColorBox)
+interface DocStaticProps {
+ Document: Doc;
+ isSelected: () => boolean;
+ renderDepth: number;
+}
+export function DocStaticComponent<P extends DocStaticProps, T>(schemaCtor: (doc: Doc) => T) {
+ class Component extends React.Component<P> {
+ //TODO This might be pretty inefficient if doc isn't observed, because computed doesn't cache then
+ @computed
+ get Document(): T {
+ return schemaCtor(this.props.Document);
+ }
+ active = () => (this.props.Document.forceActive || this.props.isSelected() || this.props.renderDepth === 0) && !InkingControl.Instance.selectedTool;
+ }
+ return Component;
+}
+
+
+/// DocAnnotatbleComponent return a base class for React views of document fields that are annotatable *and* interactive when selected (e.g., pdf, image)
interface DocAnnotatableProps {
Document: Doc;
DataDoc?: Doc;
@@ -57,7 +85,7 @@ export function DocAnnotatableComponent<P extends DocAnnotatableProps, T>(schema
return Doc.AddDocToList(this.extensionDoc, this.props.fieldExt, doc);
}
whenActiveChanged = (isActive: boolean) => this.props.whenActiveChanged(this._isChildActive = isActive);
- active = () => this.props.isSelected() || this._isChildActive || this.props.renderDepth === 0;
+ active = () => (InkingControl.Instance.selectedTool === InkTool.None) && (BoolCast(this.props.Document.forceActive) || this.props.isSelected() || this._isChildActive || this.props.renderDepth === 0);
}
return Component;
} \ No newline at end of file
diff --git a/src/client/views/InkingControl.tsx b/src/client/views/InkingControl.tsx
index 38734a03d..d42d8d2d9 100644
--- a/src/client/views/InkingControl.tsx
+++ b/src/client/views/InkingControl.tsx
@@ -48,6 +48,14 @@ export class InkingControl extends React.Component {
let selected = SelectionManager.SelectedDocuments();
let oldColors = selected.map(view => {
let targetDoc = view.props.Document.layout instanceof Doc ? view.props.Document.layout : view.props.Document.isTemplate ? view.props.Document : Doc.GetProto(view.props.Document);
+ let sel = window.getSelection();
+ if (StrCast(targetDoc.layout).indexOf("FormattedTextBox") !== -1 && (!sel || sel.toString() !== "")) {
+ targetDoc.color = this._selectedColor;
+ return {
+ target: targetDoc,
+ previous: StrCast(targetDoc.color)
+ };
+ }
let oldColor = StrCast(targetDoc.backgroundColor);
let matchedColor = this._selectedColor;
const cvd = view.props.ContainingCollectionDoc;
diff --git a/src/client/views/MainView.tsx b/src/client/views/MainView.tsx
index ddea3e223..701f094e2 100644
--- a/src/client/views/MainView.tsx
+++ b/src/client/views/MainView.tsx
@@ -343,12 +343,12 @@ export class MainView extends React.Component {
if (!(sidebarContent instanceof Doc)) {
return (null);
}
- let libraryButtonDoc = Cast(CurrentUserUtils.UserDocument.libraryButtons, Doc) as Doc;
- libraryButtonDoc.columnWidth = this.flyoutWidth / 3 - 30;
+ let sidebarButtonsDoc = Cast(CurrentUserUtils.UserDocument.sidebarButtons, Doc) as Doc;
+ sidebarButtonsDoc.columnWidth = this.flyoutWidth / 3 - 30;
return <div className="mainView-flyoutContainer">
<div className="mainView-tabButtons" style={{ height: `${this._buttonBarHeight}px` }}>
<DocumentView
- Document={libraryButtonDoc}
+ Document={sidebarButtonsDoc}
DataDoc={undefined}
addDocument={undefined}
addDocTab={this.addDocTabFunc}
@@ -443,18 +443,20 @@ export class MainView extends React.Component {
}
addButtonDoc = (doc: Doc) => {
- Doc.AddDocToList(CurrentUserUtils.UserDocument, "docButtons", doc);
+ Doc.AddDocToList(CurrentUserUtils.UserDocument.expandingButtons as Doc, "data", doc);
return true;
}
remButtonDoc = (doc: Doc) => {
- Doc.RemoveDocFromList(CurrentUserUtils.UserDocument, "docButtons", doc);
+ Doc.RemoveDocFromList(CurrentUserUtils.UserDocument.expandingButtons as Doc, "data", doc);
return true;
}
@computed get docButtons() {
return <div className="mainView-docButtons" style={{ left: (this._flyoutTranslate ? this.flyoutWidth : 0) + 20 }} >
<MainViewNotifs />
- <CollectionLinearView Document={CurrentUserUtils.UserDocument} DataDoc={undefined}
- fieldKey={"docButtons"}
+ <CollectionLinearView
+ Document={CurrentUserUtils.UserDocument.expandingButtons as Doc}
+ DataDoc={undefined}
+ fieldKey={"data"}
fieldExt={""}
showHiddenControls={true}
select={emptyFunction}
diff --git a/src/client/views/nodes/ColorBox.scss b/src/client/views/nodes/ColorBox.scss
index 8df617fca..32a7891c6 100644
--- a/src/client/views/nodes/ColorBox.scss
+++ b/src/client/views/nodes/ColorBox.scss
@@ -1,10 +1,13 @@
-.colorBox-container {
+.colorBox-container, .colorBox-container-interactive {
width:100%;
height:100%;
position: relative;
- pointer-events:all;
+ pointer-events: none;
.sketch-picker {
margin:auto;
}
+}
+.colorBox-container-interactive {
+ pointer-events:all;
} \ No newline at end of file
diff --git a/src/client/views/nodes/ColorBox.tsx b/src/client/views/nodes/ColorBox.tsx
index 4aff770f9..d280258ae 100644
--- a/src/client/views/nodes/ColorBox.tsx
+++ b/src/client/views/nodes/ColorBox.tsx
@@ -4,13 +4,19 @@ import { SketchPicker } from 'react-color';
import { FieldView, FieldViewProps } from './FieldView';
import "./ColorBox.scss";
import { InkingControl } from "../InkingControl";
+import { DocStaticComponent } from "../DocComponent";
+import { documentSchema } from "./DocumentView";
+import { makeInterface } from "../../../new_fields/Schema";
+
+type ColorDocument = makeInterface<[typeof documentSchema]>;
+const ColorDocument = makeInterface(documentSchema);
@observer
-export class ColorBox extends React.Component<FieldViewProps> {
+export class ColorBox extends DocStaticComponent<FieldViewProps, ColorDocument>(ColorDocument) {
public static LayoutString(fieldKey?: string) { return FieldView.LayoutString(ColorBox, fieldKey); }
render() {
- return <div className="colorBox-container" >
+ return <div className={`colorBox-container${this.active() ? "-interactive" : ""}`} onPointerDown={e => e.button === 0 && !e.ctrlKey && e.stopPropagation()}>
<SketchPicker color={InkingControl.Instance.selectedColor} onChange={InkingControl.Instance.switchColor} />
</div>;
}
-} \ No newline at end of file
+} \ No newline at end of file
diff --git a/src/client/views/nodes/FormattedTextBox.tsx b/src/client/views/nodes/FormattedTextBox.tsx
index b05d0046c..181f37d36 100644
--- a/src/client/views/nodes/FormattedTextBox.tsx
+++ b/src/client/views/nodes/FormattedTextBox.tsx
@@ -43,7 +43,6 @@ import { FormattedTextBoxComment, formattedTextBoxCommentPlugin } from './Format
import React = require("react");
import { ContextMenuProps } from '../ContextMenuItem';
import { ContextMenu } from '../ContextMenu';
-import { TextShadowProperty } from 'csstype';
library.add(faEdit);
library.add(faSmile, faTextHeight, faUpload);
@@ -490,7 +489,7 @@ export class FormattedTextBox extends DocComponent<(FieldViewProps & FormattedTe
);
this._heightReactionDisposer = reaction(
- () => this.props.Document[WidthSym](),
+ () => [this.props.Document[WidthSym](), this.props.Document.autoHeight],
() => this.tryUpdateHeight()
);
@@ -984,13 +983,13 @@ export class FormattedTextBox extends DocComponent<(FieldViewProps & FormattedTe
@action
tryUpdateHeight() {
- const ChromeHeight = this.props.ChromeHeight;
- let sh = this._ref.current ? this._ref.current.scrollHeight : 0;
- if (!this.props.Document.isAnimating && this.props.Document.autoHeight && sh !== 0 && getComputedStyle(this._ref.current!.parentElement!).top === "0px") {
+ let scrollHeight = this._ref.current ? this._ref.current.scrollHeight : 0;
+ if (!this.props.Document.isAnimating && this.props.Document.autoHeight && scrollHeight !== 0 &&
+ getComputedStyle(this._ref.current!.parentElement!).top === "0px") { // if top === 0, then the text box is growing upward (as the overlay caption) which doesn't contribute to the height computation
let nh = this.props.Document.isTemplate ? 0 : NumCast(this.dataDoc.nativeHeight, 0);
let dh = NumCast(this.props.Document.height, 0);
- this.props.Document.height = Math.max(10, (nh ? dh / nh * sh : sh) + (ChromeHeight ? ChromeHeight() : 0));
- this.dataDoc.nativeHeight = nh ? sh : undefined;
+ this.props.Document.height = Math.max(10, (nh ? dh / nh * scrollHeight : scrollHeight) + (this.props.ChromeHeight ? this.props.ChromeHeight() : 0));
+ this.dataDoc.nativeHeight = nh ? scrollHeight : undefined;
}
}
diff --git a/src/client/views/nodes/PDFBox.tsx b/src/client/views/nodes/PDFBox.tsx
index 63b412a23..19797400f 100644
--- a/src/client/views/nodes/PDFBox.tsx
+++ b/src/client/views/nodes/PDFBox.tsx
@@ -115,7 +115,6 @@ export class PDFBox extends DocAnnotatableComponent<FieldViewProps, PdfDocument>
private newScriptChange = (e: React.ChangeEvent<HTMLInputElement>) => this._scriptValue = e.currentTarget.value;
whenActiveChanged = (isActive: boolean) => this.props.whenActiveChanged(this._isChildActive = isActive);
- active = () => this.props.isSelected() || this._isChildActive || this.props.renderDepth === 0;
setPdfViewer = (pdfViewer: PDFViewer) => { this._pdfViewer = pdfViewer; };
searchStringChanged = (e: React.ChangeEvent<HTMLInputElement>) => this._searchString = e.currentTarget.value;
@@ -205,7 +204,7 @@ export class PDFBox extends DocAnnotatableComponent<FieldViewProps, PdfDocument>
_initialScale: number | undefined; // the initial scale of the PDF when first rendered which determines whether the document will be live on startup or not. Getting bigger after startup won't make it automatically be live....
render() {
const pdfUrl = Cast(this.dataDoc[this.props.fieldKey], PdfField);
- let classname = "pdfBox-cont" + (InkingControl.Instance.selectedTool || !this.active ? "" : "-interactive");
+ let classname = "pdfBox-cont" + (this.active() ? "-interactive" : "");
let noPdf = !(pdfUrl instanceof PdfField) || !this._pdf;
if (this._initialScale === undefined) this._initialScale = this.props.ScreenToLocalTransform().Scale;
if (this.props.isSelected() || this.props.Document.scrollY !== undefined) this._everActive = true;
diff --git a/src/server/authentication/models/current_user_utils.ts b/src/server/authentication/models/current_user_utils.ts
index 73cac879e..8af6bbfd5 100644
--- a/src/server/authentication/models/current_user_utils.ts
+++ b/src/server/authentication/models/current_user_utils.ts
@@ -1,20 +1,17 @@
-import { action, computed, observable, runInAction, reaction } from "mobx";
+import { action, computed, observable, reaction, runInAction } from "mobx";
import * as rp from 'request-promise';
import { DocServer } from "../../../client/DocServer";
import { Docs } from "../../../client/documents/Documents";
import { Attribute, AttributeGroup, Catalog, Schema } from "../../../client/northstar/model/idea/idea";
import { ArrayUtil } from "../../../client/northstar/utils/ArrayUtil";
-import { CollectionViewType } from "../../../client/views/collections/CollectionBaseView";
-import { CollectionView } from "../../../client/views/collections/CollectionView";
+import { UndoManager } from "../../../client/util/UndoManager";
import { Doc, DocListCast } from "../../../new_fields/Doc";
import { List } from "../../../new_fields/List";
import { listSpec } from "../../../new_fields/Schema";
-import { Cast, StrCast, PromiseValue } from "../../../new_fields/Types";
+import { ScriptField } from "../../../new_fields/ScriptField";
+import { Cast, PromiseValue } from "../../../new_fields/Types";
import { Utils } from "../../../Utils";
import { RouteStore } from "../../RouteStore";
-import { ScriptField } from "../../../new_fields/ScriptField";
-import { ButtonBox } from "../../../client/views/nodes/ButtonBox";
-import { UndoManager } from "../../../client/util/UndoManager";
export class CurrentUserUtils {
private static curr_id: string;
@@ -22,176 +19,172 @@ export class CurrentUserUtils {
private static mainDocId: string | undefined;
public static get id() { return this.curr_id; }
- @computed public static get UserDocument() { return Doc.UserDoc(); }
public static get MainDocId() { return this.mainDocId; }
public static set MainDocId(id: string | undefined) { this.mainDocId = id; }
+ @computed public static get UserDocument() { return Doc.UserDoc(); }
@observable public static GuestTarget: Doc | undefined;
@observable public static GuestWorkspace: Doc | undefined;
private static createUserDocument(id: string): Doc {
let doc = new Doc(id, true);
- doc.viewType = CollectionViewType.Tree;
- doc.layout = CollectionView.LayoutString();
doc.title = Doc.CurrentUserEmail;
- doc.data = new List<Doc>();
- doc.gridGap = 5;
- doc.xMargin = 5;
- doc.yMargin = 5;
- doc.height = 42;
- doc.boxShadow = "0 0";
- doc.convertToButtons = true; // for CollectionLinearView used as the docButton layout
- doc.optionalRightCollection = Docs.Create.StackingDocument([], { title: "New mobile uploads" });
return this.updateUserDocument(doc);// this should be the last
}
- static updateUserDocument(doc: Doc) {
+ // a default set of note types .. not being used yet...
+ static setupNoteTypes(doc: Doc) {
+ let notes = [
+ Docs.Create.TextDocument({ title: "Note", backgroundColor: "yellow", isTemplate: true }),
+ Docs.Create.TextDocument({ title: "Idea", backgroundColor: "pink", isTemplate: true }),
+ Docs.Create.TextDocument({ title: "Topic", backgroundColor: "lightBlue", isTemplate: true }),
+ Docs.Create.TextDocument({ title: "Person", backgroundColor: "lightGreen", isTemplate: true })
+ ];
+ doc.noteTypes = Docs.Create.TreeDocument(notes, { title: "Note Types", height: 75 });
+ }
- if (doc.undoBtn === undefined) {
- doc.undoBtn = Docs.Create.FontIconDocument({ nativeWidth: 100, nativeHeight: 100, width: 100, height: 100, title: "Collection", icon: "undo-alt" });
- (doc.undoBtn as Doc).onClick = ScriptField.MakeScript('undo()');
- Doc.AddDocToList(doc, "docButtons", doc.undoBtn as Doc);
- }
- if (doc.redoBtn === undefined) {
- doc.redoBtn = Docs.Create.FontIconDocument({ nativeWidth: 100, nativeHeight: 100, width: 100, height: 100, title: "Collection", icon: "redo-alt" });
- (doc.redoBtn as Doc).onClick = ScriptField.MakeScript('redo()');
- Doc.AddDocToList(doc, "docButtons", doc.redoBtn as Doc);
- }
+ // setup the "creator" buttons for the sidebar-- eg. the default set of draggable document creation tools
+ static setupCreatorButtons() {
+ let docProtoData = [
+ { title: "collection", icon: "folder", script: 'Docs.Create.FreeformDocument([], { nativeWidth: undefined, nativeHeight: undefined, width: 150, height: 100, title: "freeform" })' },
+ { title: "web page", icon: "globe-asia", script: 'Docs.Create.WebDocument("https://en.wikipedia.org/wiki/Hedgehog", { width: 300, height: 300, title: "New Webpage" })' },
+ { title: "image", icon: "cat", script: 'Docs.Create.ImageDocument("https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg", { width: 200, title: "an image of a cat" })' },
+ { title: "button", icon: "bolt", script: 'Docs.Create.ButtonDocument({ width: 150, height: 50, title: "Button" })' },
+ { title: "presentation", icon: "tv", script: 'Doc.UserDoc().curPresentation = Docs.Create.PresDocument(new List<Doc>(), { width: 200, height: 500, title: "a presentation trail" })' },
+ { title: "import folder", icon: "cloud-upload-alt", script: 'Docs.Create.DirectoryImportDocument({ title: "Directory Import", width: 400, height: 400 })' },
+ ];
+ return docProtoData.map(data => Docs.Create.FontIconDocument({
+ nativeWidth: 100, nativeHeight: 100, width: 100, height: 100,
+ title: data.title, icon: data.icon, onDragStart: ScriptField.MakeFunction(data.script)
+ }));
+ }
+
+ // setup the Creator button which will display the creator panel. This panel will include the drag creators and the color picker. when clicked, this panel will be displayed in the target container (ie, sidebarContainer)
+ static setupCreatePanel(sidebarContainer: Doc) {
+ // setup a masonry view of all he creators
+ const dragCreators = Docs.Create.MasonryDocument(CurrentUserUtils.setupCreatorButtons(), {
+ width: 500, autoHeight: true, columnWidth: 35, ignoreClick: true, lockedPosition: true, chromeStatus: "disabled", title: "buttons"
+ });
+ // setup a color picker
+ const color = Docs.Create.ColorDocument({
+ title: "color picker", width: 400, removeDropProperties: new List<string>(["dropAction", "forceActive"])
+ });
+ color.dropAction = "alias"; // these must be set on the view document so they can't be part of the creator above.
+ color.forceActive = true;
+
+ return Docs.Create.ButtonDocument({
+ width: 35, height: 35, borderRounding: "50%", boxShadow: "2px 2px 1px", title: "Create", targetContainer: sidebarContainer,
+ panel: Docs.Create.StackingDocument([dragCreators, color], {
+ width: 500, height: 800, chromeStatus: "disabled", title: "creator stack"
+ }),
+ onClick: ScriptField.MakeScript("this.targetContainer.proto = this.panel")
+ });
+ }
+
+ // setup the Library button which will display the library panel. This panel includes a collection of workspaces, documents, and recently closed views
+ static setupLibraryPanel(sidebarContainer: Doc, doc: Doc) {
// setup workspaces library item
- if (doc.workspaces === undefined) {
- const workspaces = Docs.Create.TreeDocument([], { title: "WORKSPACES", height: 100 });
- workspaces.boxShadow = "0 0";
- doc.workspaces = workspaces;
- }
- PromiseValue(Cast(doc.workspaces, Doc)).then(workspaces => {
- if (workspaces) {
- workspaces.backgroundColor = "#eeeeee";
- workspaces.preventTreeViewOpen = true;
- workspaces.forceActive = true;
- workspaces.lockedPosition = true;
- if (StrCast(workspaces.title) === "Workspaces") {
- workspaces.title = "WORKSPACES";
- }
- }
+ doc.workspaces = Docs.Create.TreeDocument([], {
+ title: "WORKSPACES", height: 100, forceActive: true, boxShadow: "0 0", lockedPosition: true, backgroundColor: "#eeeeee"
});
- // setup notes list
- if (doc.noteTypes === undefined) {
- let notes = [Docs.Create.TextDocument({ title: "Note", backgroundColor: "yellow", isTemplate: true }),
- Docs.Create.TextDocument({ title: "Idea", backgroundColor: "pink", isTemplate: true }),
- Docs.Create.TextDocument({ title: "Topic", backgroundColor: "lightBlue", isTemplate: true }),
- Docs.Create.TextDocument({ title: "Person", backgroundColor: "lightGreen", isTemplate: true })];
- const noteTypes = Docs.Create.TreeDocument(notes, { title: "Note Types", height: 75 });
- doc.noteTypes = noteTypes;
- }
- PromiseValue(Cast(doc.noteTypes, Doc)).then(noteTypes => noteTypes && PromiseValue(noteTypes.data).then(DocListCast));
+ doc.documents = Docs.Create.TreeDocument([], {
+ title: "DOCUMENTS", gridGap: 5, xMargin: 5, yMargin: 5, height: 42, width: 100, boxShadow: "0 0", backgroundColor: "#eeeeee", preventTreeViewOpen: true, forceActive: true, lockedPosition: true
+ });
// setup Recently Closed library item
- if (doc.recentlyClosed === undefined) {
- const recentlyClosed = Docs.Create.TreeDocument([], { title: "Recently Closed".toUpperCase(), height: 75 });
- recentlyClosed.boxShadow = "0 0";
- doc.recentlyClosed = recentlyClosed;
- }
- PromiseValue(Cast(doc.recentlyClosed, Doc)).then(recent => {
- if (recent) {
- recent.backgroundColor = "#eeeeee";
- recent.preventTreeViewOpen = true;
- recent.forceActive = true;
- recent.lockedPosition = true;
- if (StrCast(recent.title) === "Recently Closed") {
- recent.title = "RECENTLY CLOSED";
- }
- }
+ doc.recentlyClosed = Docs.Create.TreeDocument([], {
+ title: "Recently Closed".toUpperCase(), height: 75, boxShadow: "0 0", preventTreeViewOpen: true, forceActive: true, lockedPosition: true, backgroundColor: "#eeeeee"
});
+ return Docs.Create.ButtonDocument({
+ width: 50, height: 35, borderRounding: "50%", boxShadow: "2px 2px 1px", title: "Library",
+ panel: Docs.Create.TreeDocument([doc.workspaces as Doc, doc, doc.recentlyClosed as Doc], {
+ title: "Library", xMargin: 5, yMargin: 5, gridGap: 5, forceActive: true, dropAction: "alias", lockedPosition: true
+ }),
+ targetContainer: sidebarContainer,
+ onClick: ScriptField.MakeScript("this.targetContainer.proto = this.panel")
+ });
+ }
- if (doc.curPresentation === undefined) {
- const curPresentation = Docs.Create.PresDocument(new List<Doc>(), { title: "Presentation" });
- curPresentation.boxShadow = "0 0";
- doc.curPresentation = curPresentation;
- }
+ // setup the Search button which will display the search panel.
+ static setupSearchPanel(sidebarContainer: Doc) {
+ return Docs.Create.ButtonDocument({
+ width: 50, height: 35, borderRounding: "50%", boxShadow: "2px 2px 1px", title: "Search",
+ panel: Docs.Create.QueryDocument({
+ title: "search stack", ignoreClick: true
+ }),
+ targetContainer: sidebarContainer,
+ onClick: ScriptField.MakeScript("this.targetContainer.proto = this.panel")
+ });
+ }
- if (doc.Library === undefined) {
- let Search = Docs.Create.ButtonDocument({ width: 50, height: 35, borderRounding: "50%", boxShadow: "2px 2px 1px", title: "Search" });
- let Library = Docs.Create.ButtonDocument({ width: 50, height: 35, borderRounding: "50%", boxShadow: "2px 2px 1px", title: "Library" });
- let Create = Docs.Create.ButtonDocument({ width: 35, height: 35, borderRounding: "50%", boxShadow: "2px 2px 1px", title: "Create" });
- if (doc.sidebarContainer === undefined) {
- doc.sidebarContainer = new Doc();
- (doc.sidebarContainer as Doc).chromeStatus = "disabled";
- }
+ // setup the list of sidebar mode buttons which determine what is displayed in the sidebar
+ static setupSidebarButtons(doc: Doc) {
+ doc.sidebarContainer = new Doc();
+ (doc.sidebarContainer as Doc).chromeStatus = "disabled";
- const library = Docs.Create.TreeDocument([doc.workspaces as Doc, doc, doc.recentlyClosed as Doc], { title: "Library" });
- library.forceActive = true;
- library.lockedPosition = true;
- library.gridGap = 5;
- library.xMargin = 5;
- library.yMargin = 5;
- library.dropAction = "alias";
- Library.targetContainer = doc.sidebarContainer;
- Library.library = library;
- Library.onClick = ScriptField.MakeScript("this.targetContainer.proto = this.library");
+ doc.CreateBtn = this.setupCreatePanel(doc.sidebarContainer as Doc);
+ doc.LibraryBtn = this.setupLibraryPanel(doc.sidebarContainer as Doc, doc);
+ doc.SearchBtn = this.setupSearchPanel(doc.sidebarContainer as Doc);
- const searchBox = Docs.Create.QueryDocument({ title: "search stack" });
- searchBox.ignoreClick = true;
- Search.searchBox = searchBox;
- Search.targetContainer = doc.sidebarContainer;
- Search.onClick = ScriptField.MakeScript("this.targetContainer.proto = this.searchBox");
+ // Finally, setup the list of buttons to display in the sidebar
+ doc.sidebarButtons = Docs.Create.StackingDocument([doc.SearchBtn as Doc, doc.LibraryBtn as Doc, doc.CreateBtn as Doc], {
+ width: 500, height: 80, boxShadow: "0 0", sectionFilter: "title", hideHeadings: true, ignoreClick: true,
+ backgroundColor: "lightgrey", chromeStatus: "disabled", title: "library stack"
+ });
+ }
- let createCollection = Docs.Create.FontIconDocument({ nativeWidth: 100, nativeHeight: 100, width: 100, height: 100, title: "Collection", icon: "folder" });
- createCollection.onDragStart = ScriptField.MakeFunction('Docs.Create.FreeformDocument([], { nativeWidth: undefined, nativeHeight: undefined, width: 150, height: 100, title: "freeform" })');
- let createWebPage = Docs.Create.FontIconDocument({ nativeWidth: 100, nativeHeight: 100, width: 100, height: 100, title: "Web Page", icon: "globe-asia" });
- createWebPage.onDragStart = ScriptField.MakeFunction('Docs.Create.WebDocument("https://en.wikipedia.org/wiki/Hedgehog", { width: 300, height: 300, title: "New Webpage" })');
- let createCatImage = Docs.Create.FontIconDocument({ nativeWidth: 100, nativeHeight: 100, width: 100, height: 100, title: "Image", icon: "cat" });
- createCatImage.onDragStart = ScriptField.MakeFunction('Docs.Create.ImageDocument("https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg", { width: 200, title: "an image of a cat" })');
- let createButton = Docs.Create.FontIconDocument({ nativeWidth: 100, nativeHeight: 100, width: 100, height: 100, title: "Button", icon: "bolt" });
- createButton.onDragStart = ScriptField.MakeFunction('Docs.Create.ButtonDocument({ width: 150, height: 50, title: "Button" })');
- let createPresentation = Docs.Create.FontIconDocument({ nativeWidth: 100, nativeHeight: 100, width: 100, height: 100, title: "Presentation", icon: "tv" });
- createPresentation.onDragStart = ScriptField.MakeFunction('Doc.UserDoc().curPresentation = Docs.Create.PresDocument(new List<Doc>(), { width: 200, height: 500, title: "a presentation trail" })');
- let createFolderImport = Docs.Create.FontIconDocument({ nativeWidth: 100, nativeHeight: 100, width: 100, height: 100, title: "Import Folder", icon: "cloud-upload-alt" });
- createFolderImport.onDragStart = ScriptField.MakeFunction('Docs.Create.DirectoryImportDocument({ title: "Directory Import", width: 400, height: 400 })');
- const dragCreators = Docs.Create.MasonryDocument([createCollection, createWebPage, createCatImage, createButton, createPresentation, createFolderImport], { width: 500, autoHeight: true, columnWidth: 35, ignoreClick: true, lockedPosition: true, chromeStatus: "disabled", title: "buttons" });
- const color = Docs.Create.ColorDocument({ title: "color picker", width: 400 });
- color.dropAction = "alias";
- color.ignoreClick = true;
- color.removeDropProperties = new List<string>(["dropAction", "ignoreClick"]);
- const creators = Docs.Create.StackingDocument([dragCreators, color], { width: 500, height: 800, chromeStatus: "disabled", title: "creator stack" });
- Create.targetContainer = doc.sidebarContainer;
- Create.creators = creators;
- Create.onClick = ScriptField.MakeScript("this.targetContainer.proto = this.creators");
+ /// sets up the default list of buttons to be shown in the expanding button menu at the bottom of the Dash window
+ static setupExpandingButtons(doc: Doc) {
+ doc.undoBtn = Docs.Create.FontIconDocument(
+ { nativeWidth: 100, nativeHeight: 100, width: 100, height: 100, onClick: ScriptField.MakeScript("undo()"), title: "undo button", icon: "undo-alt" });
+ doc.redoBtn = Docs.Create.FontIconDocument(
+ { nativeWidth: 100, nativeHeight: 100, width: 100, height: 100, onClick: ScriptField.MakeScript("redo()"), title: "redo button", icon: "redo-alt" });
- const libraryButtons = Docs.Create.StackingDocument([Search, Library, Create], { width: 500, height: 80, chromeStatus: "disabled", title: "library stack" });
- libraryButtons.sectionFilter = "title";
- libraryButtons.boxShadow = "0 0";
- libraryButtons.ignoreClick = true;
- libraryButtons.hideHeadings = true;
- libraryButtons.backgroundColor = "lightgrey";
+ doc.expandingButtons = Docs.Create.LinearDocument([doc.undoBtn as Doc, doc.redoBtn as Doc], {
+ title: "expanding buttons", gridGap: 5, xMargin: 5, yMargin: 5, height: 42, width: 100, boxShadow: "0 0",
+ backgroundColor: "#eeeeee", preventTreeViewOpen: true, forceActive: true, lockedPosition: true, convertToButtons: true
+ });
+ }
- doc.libraryButtons = libraryButtons;
- doc.Library = Library;
- doc.Create = Create;
- doc.Search = Search;
- }
- PromiseValue(Cast(doc.libraryButtons, Doc)).then(libraryButtons => { });
- PromiseValue(Cast(doc.Library, Doc)).then(library => library && library.library && library.targetContainer && (library.onClick as ScriptField).script.run({ this: library }));
- PromiseValue(Cast(doc.Create, Doc)).then(async create => create && create.creators && create.targetContainer);
- PromiseValue(Cast(doc.Search, Doc)).then(async search => search && search.searchBox && search.targetContainer);
+ // sets up the default set of documents to be shown in the Overlay layer
+ static setupOverlays(doc: Doc) {
+ doc.overlays = Docs.Create.FreeformDocument([], { title: "Overlays", backgroundColor: "#aca3a6" });
+ doc.linkFollowBox = Docs.Create.LinkFollowBoxDocument({ x: 250, y: 20, width: 500, height: 370, title: "Link Follower" });
+ Doc.AddDocToList(doc.overlays as Doc, "data", doc.linkFollowBox as Doc);
+ }
- if (doc.overlays === undefined) {
- const overlays = Docs.Create.FreeformDocument([], { title: "Overlays" });
- Doc.GetProto(overlays).backgroundColor = "#aca3a6";
- doc.overlays = overlays;
- }
+ // the initial presentation Doc to use
+ static setupDefaultPresentation(doc: Doc) {
+ doc.curPresentation = Docs.Create.PresDocument(new List<Doc>(), { title: "Presentation", boxShadow: "0 0" });
+ }
- if (doc.linkFollowBox === undefined) {
- PromiseValue(Cast(doc.overlays, Doc)).then(overlays => overlays && Doc.AddDocToList(overlays, "data", doc.linkFollowBox = Docs.Create.LinkFollowBoxDocument({ x: 250, y: 20, width: 500, height: 370, title: "Link Follower" })));
- }
+ static setupMobileUploads(doc: Doc) {
+ doc.optionalRightCollection = Docs.Create.StackingDocument([], { title: "New mobile uploads" });
+ }
+
+ static updateUserDocument(doc: Doc) {
+ (doc.optionalRightCollection === undefined) && CurrentUserUtils.setupMobileUploads(doc);
+ (doc.noteTypes === undefined) && CurrentUserUtils.setupNoteTypes(doc);
+ (doc.overlays === undefined) && CurrentUserUtils.setupOverlays(doc);
+ (doc.expandingButtons === undefined) && CurrentUserUtils.setupExpandingButtons(doc);
+ (doc.curPresentation === undefined) && CurrentUserUtils.setupDefaultPresentation(doc);
+ (doc.sidebarButtons === undefined) && CurrentUserUtils.setupSidebarButtons(doc);
+
+ // this is equivalent to using PrefetchProxies to make sure all the sidebarButtons and noteType internal Doc's have been retrieved.
+ PromiseValue(Cast(doc.noteTypes, Doc)).then(noteTypes => noteTypes && PromiseValue(noteTypes.data).then(DocListCast));
+ PromiseValue(Cast(doc.sidebarButtons, Doc)).then(stackingDoc => {
+ stackingDoc && PromiseValue(Cast(stackingDoc.data, listSpec(Doc))).then(sidebarButtons => {
+ sidebarButtons && sidebarButtons.map((sidebarBtn, i) => {
+ sidebarBtn && PromiseValue(Cast(sidebarBtn, Doc)).then(async btn => {
+ btn && btn.panel && btn.targetContainer && i === 1 && (btn.onClick as ScriptField).script.run({ this: btn });
+ });
+ });
+ });
+ });
- doc.title = "DOCUMENTS";
- doc.backgroundColor = "#eeeeee";
- doc.width = 100;
- doc.preventTreeViewOpen = true;
- doc.forceActive = true;
- doc.lockedPosition = true;
+ // setup reactions to change the highlights on the undo/redo buttons -- would be better to encode this in the undo/redo buttons, but the undo/redo stacks are not wired up that way yet
doc.undoBtn && reaction(() => UndoManager.undoStack.slice(), () => (doc.undoBtn as Doc).opacity = UndoManager.CanUndo() ? 1 : 0.4, { fireImmediately: true });
doc.redoBtn && reaction(() => UndoManager.redoStack.slice(), () => (doc.redoBtn as Doc).opacity = UndoManager.CanRedo() ? 1 : 0.4, { fireImmediately: true });
@@ -215,12 +208,8 @@ export class CurrentUserUtils {
await rp.get(Utils.prepend(RouteStore.getUserDocumentId)).then(id => {
if (id && id !== "guest") {
return DocServer.GetRefField(id).then(async field => {
- if (field instanceof Doc) {
- await this.updateUserDocument(field);
- runInAction(() => Doc.SetUserDoc(field));
- } else {
- runInAction(() => Doc.SetUserDoc(this.createUserDocument(id)));
- }
+ let userDoc = field instanceof Doc ? await this.updateUserDocument(field) : this.createUserDocument(id);
+ runInAction(() => Doc.SetUserDoc(userDoc));
});
} else {
throw new Error("There should be a user id! Why does Dash think there isn't one?");