diff options
Diffstat (limited to 'src/fields/Doc.ts')
-rw-r--r-- | src/fields/Doc.ts | 151 |
1 files changed, 112 insertions, 39 deletions
diff --git a/src/fields/Doc.ts b/src/fields/Doc.ts index 31a50301a..0c7504913 100644 --- a/src/fields/Doc.ts +++ b/src/fields/Doc.ts @@ -5,7 +5,6 @@ import { computedFn } from 'mobx-utils'; import { alias, map, serializable } from 'serializr'; import { DocServer } from '../client/DocServer'; import { DocumentType } from '../client/documents/DocumentTypes'; -import { CurrentUserUtils } from '../client/util/CurrentUserUtils'; import { LinkManager } from '../client/util/LinkManager'; import { scriptingGlobal, ScriptingGlobals } from '../client/util/ScriptingGlobals'; import { SelectionManager } from '../client/util/SelectionManager'; @@ -14,6 +13,7 @@ import { UndoManager } from '../client/util/UndoManager'; import { DashColor, incrementTitleCopy, intersectRect, Utils } from '../Utils'; import { DateField } from './DateField'; import { Copy, HandleUpdate, Id, OnUpdate, Parent, Self, SelfProxy, ToScriptString, ToString, Update } from './FieldSymbols'; +import { InkTool } from './InkField'; import { List } from './List'; import { ObjectField } from './ObjectField'; import { PrefetchProxy, ProxyField } from './Proxy'; @@ -21,7 +21,7 @@ import { FieldId, RefField } from './RefField'; import { RichTextField } from './RichTextField'; import { listSpec } from './Schema'; import { ComputedField, ScriptField } from './ScriptField'; -import { Cast, FieldValue, NumCast, StrCast, ToConstructor } from './Types'; +import { Cast, DocCast, FieldValue, NumCast, StrCast, ToConstructor } from './Types'; import { AudioField, ImageField, MapField, PdfField, VideoField, WebField } from './URLField'; import { deleteProperty, GetEffectiveAcl, getField, getter, makeEditable, makeReadOnly, normalizeEmail, setter, SharingPermissions, updateFunction } from './util'; import JSZip = require('jszip'); @@ -141,6 +141,95 @@ export function updateCachedAcls(doc: Doc) { @scriptingGlobal @Deserializable('Doc', updateCachedAcls).withFields(['id']) export class Doc extends RefField { + //TODO tfs: these should be temporary... + private static mainDocId: string | undefined; + public static get MainDocId() { + return this.mainDocId; + } + public static set MainDocId(id: string | undefined) { + this.mainDocId = id; + } + @observable public static GuestDashboard: Doc | undefined; + @observable public static GuestTarget: Doc | undefined; + @observable public static GuestMobile: Doc | undefined; + public static get MySharedDocs() { + return DocCast(Doc.UserDoc().mySharedDocs); + } + public static get MyUserDocView() { + return DocCast(Doc.UserDoc().myUserDocView); + } + public static get MyDockedBtns() { + return DocCast(Doc.UserDoc().myDockedBtns); + } + public static get MySearcher() { + return DocCast(Doc.UserDoc().mySearcher); + } + public static get MyHeaderBar() { + return DocCast(Doc.UserDoc().myHeaderBar); + } + public static get MyLeftSidebarMenu() { + return DocCast(Doc.UserDoc().myLeftSidebarMenu); + } + public static get MyLeftSidebarPanel() { + return DocCast(Doc.UserDoc().myLeftSidebarPanel); + } + public static get MyContextMenuBtns() { + return DocCast(Doc.UserDoc().myContextMenuBtns); + } + public static get MyRecentlyClosed() { + return DocCast(Doc.UserDoc().myRecentlyClosed); + } + public static get MyTrails() { + return DocCast(Doc.UserDoc().myTrails); + } + public static get MyOverlayDocs() { + return DocCast(Doc.UserDoc().myOverlayDocs); + } + public static get MyPublishedDocs() { + return DocCast(Doc.UserDoc().myPublishedDocs); + } + public static get MyDashboards() { + return DocCast(Doc.UserDoc().myDashboards); + } + public static get MyTemplates() { + return DocCast(Doc.UserDoc().myTemplates); + } + public static get MyImports() { + return DocCast(Doc.UserDoc().myImports); + } + public static get MyFilesystem() { + return DocCast(Doc.UserDoc().myFilesystem); + } + public static get MyFileOrphans() { + return DocCast(Doc.UserDoc().myFileOrphans); + } + public static get MyTools() { + return DocCast(Doc.UserDoc().myTools); + } + public static get ActivePage() { + return StrCast(Doc.UserDoc().activePage); + } + public static set ActivePage(val) { + Doc.UserDoc().activePage = val; + } + public static get ActiveDashboard() { + return DocCast(Doc.UserDoc().activeDashboard); + } + public static set ActiveDashboard(val: Doc | undefined) { + Doc.UserDoc().activeDashboard = val; + } + public static set ActiveTool(tool: InkTool) { + Doc.UserDoc().activeTool = tool; + } + public static get ActiveTool(): InkTool { + return StrCast(Doc.UserDoc().activeTool, InkTool.None) as InkTool; + } + public static get ActivePresentation() { + return DocCast(Doc.UserDoc().activePresentation); + } + public static set ActivePresentation(val) { + Doc.UserDoc().activePresentation = val; + } constructor(id?: FieldId, forceSave?: boolean) { super(id); const doc = new Proxy<this>(this, { @@ -1035,7 +1124,7 @@ export namespace Doc { return manager._user_doc; } export function SharingDoc(): Doc { - return CurrentUserUtils.MySharedDocs; + return Doc.MySharedDocs; } export function LinkDBDoc(): Doc { return Cast(Doc.UserDoc().myLinkDatabase, Doc, null); @@ -1295,50 +1384,34 @@ export namespace Doc { export function isDocPinned(doc: Doc) { //add this new doc to props.Document - const curPres = CurrentUserUtils.ActivePresentation; + const curPres = Doc.ActivePresentation; return !curPres ? false : DocListCast(curPres.data).findIndex(val => Doc.AreProtosEqual(val, doc)) !== -1; } + // prettier-ignore export function toIcon(doc?: Doc, isOpen?: boolean) { switch (StrCast(doc?.type)) { - case DocumentType.IMG: - return 'image'; - case DocumentType.COMPARISON: - return 'columns'; - case DocumentType.RTF: - return 'sticky-note'; + case DocumentType.IMG: return 'image'; + case DocumentType.COMPARISON: return 'columns'; + case DocumentType.RTF: return 'sticky-note'; case DocumentType.COL: const folder: IconProp = isOpen ? 'folder-open' : 'folder'; const chevron: IconProp = isOpen ? 'chevron-down' : 'chevron-right'; return !doc?.isFolder ? folder : chevron; - case DocumentType.WEB: - return 'globe-asia'; - case DocumentType.SCREENSHOT: - return 'photo-video'; - case DocumentType.WEBCAM: - return 'video'; - case DocumentType.AUDIO: - return 'microphone'; - case DocumentType.BUTTON: - return 'bolt'; - case DocumentType.PRES: - return 'tv'; - case DocumentType.SCRIPTING: - return 'terminal'; - case DocumentType.IMPORT: - return 'cloud-upload-alt'; - case DocumentType.VID: - return 'video'; - case DocumentType.INK: - return 'pen-nib'; - case DocumentType.PDF: - return 'file-pdf'; - case DocumentType.LINK: - return 'link'; - case DocumentType.MAP: - return 'map-marker-alt'; - default: - return 'question'; + case DocumentType.WEB: return 'globe-asia'; + case DocumentType.SCREENSHOT: return 'photo-video'; + case DocumentType.WEBCAM: return 'video'; + case DocumentType.AUDIO: return 'microphone'; + case DocumentType.BUTTON: return 'bolt'; + case DocumentType.PRES: return 'tv'; + case DocumentType.SCRIPTING: return 'terminal'; + case DocumentType.IMPORT: return 'cloud-upload-alt'; + case DocumentType.VID: return 'video'; + case DocumentType.INK: return 'pen-nib'; + case DocumentType.PDF: return 'file-pdf'; + case DocumentType.LINK: return 'link'; + case DocumentType.MAP: return 'map-marker-alt'; + default: return 'question'; } } @@ -1551,7 +1624,7 @@ ScriptingGlobals.add(function docCast(doc: FieldResult): any { return DocCastAsync(doc); }); ScriptingGlobals.add(function activePresentationItem() { - const curPres = CurrentUserUtils.ActivePresentation; + const curPres = Doc.ActivePresentation; return curPres && DocListCast(curPres[Doc.LayoutFieldKey(curPres)])[NumCast(curPres._itemIndex)]; }); ScriptingGlobals.add(function selectedDocs(container: Doc, excludeCollections: boolean, prevValue: any) { |