import { Entity } from '../../../framework'; import { LiveData } from '../../../livedata'; import { MemoryMemento } from '../../../storage'; import type { DocMode } from '../../doc'; export class GlobalContext extends Entity { memento = new MemoryMemento(); workspaceId = this.define('workspaceId'); /** * is in doc page */ isDoc = this.define('isDoc'); isTrashDoc = this.define('isTrashDoc'); docId = this.define('docId'); docMode = this.define('docMode'); /** * is in collection page */ isCollection = this.define('isCollection'); collectionId = this.define('collectionId'); /** * is in trash page */ isTrash = this.define('isTrash'); /** * is in tag page */ isTag = this.define('isTag'); tagId = this.define('tagId'); /** * is in all docs page */ isAllDocs = this.define('isAllDocs'); define(key: string) { this.memento.set(key, null); const livedata$ = LiveData.from(this.memento.watch(key), null); return { get: () => this.memento.get(key) as T | null, set: (value: T | null) => this.memento.set(key, value), $: livedata$, }; } }