diff options
Diffstat (limited to 'src/client/util')
| -rw-r--r-- | src/client/util/CaptureManager.tsx | 5 | ||||
| -rw-r--r-- | src/client/util/DocumentManager.ts | 15 | ||||
| -rw-r--r-- | src/client/util/ReplayMovements.ts | 51 | ||||
| -rw-r--r-- | src/client/util/SnappingManager.ts | 3 | ||||
| -rw-r--r-- | src/client/util/UndoManager.ts | 10 |
5 files changed, 47 insertions, 37 deletions
diff --git a/src/client/util/CaptureManager.tsx b/src/client/util/CaptureManager.tsx index 4fd934774..253cdd8b5 100644 --- a/src/client/util/CaptureManager.tsx +++ b/src/client/util/CaptureManager.tsx @@ -7,10 +7,9 @@ import * as React from 'react'; import { addStyleSheet } from '../../ClientUtils'; import { Doc } from '../../fields/Doc'; import { DocCast, StrCast } from '../../fields/Types'; -import { LightboxView } from '../views/LightboxView'; import { MainViewModal } from '../views/MainViewModal'; -import './CaptureManager.scss'; import { DocumentView } from '../views/nodes/DocumentView'; +import './CaptureManager.scss'; @observer export class CaptureManager extends React.Component<{}> { @@ -79,7 +78,7 @@ export class CaptureManager extends React.Component<{}> { <div className="save" onClick={() => { - LightboxView.Instance.SetLightboxDoc(this._document); + DocumentView.SetLightboxDoc(this._document); this.close(); }}> Save diff --git a/src/client/util/DocumentManager.ts b/src/client/util/DocumentManager.ts index 5bcac7330..97051207b 100644 --- a/src/client/util/DocumentManager.ts +++ b/src/client/util/DocumentManager.ts @@ -7,7 +7,6 @@ import { listSpec } from '../../fields/Schema'; import { Cast, DocCast, NumCast, StrCast } from '../../fields/Types'; import { AudioField } from '../../fields/URLField'; import { CollectionViewType } from '../documents/DocumentTypes'; -import { LightboxView } from '../views/LightboxView'; import { DocumentView, DocumentViewInternal } from '../views/nodes/DocumentView'; import { FocusViewOptions } from '../views/nodes/FocusViewOptions'; import { OpenWhere } from '../views/nodes/OpenWhere'; @@ -25,7 +24,7 @@ export class DocumentManager { // global holds all of the nodes (regardless of which collection they're in) @observable private _documentViews = new Set<DocumentView>(); @computed public get DocumentViews() { - return Array.from(this._documentViews).filter(view => (!view.ComponentView?.dontRegisterView?.() && !LightboxView.LightboxDoc) || LightboxView.Contains(view)); + return Array.from(this._documentViews).filter(view => (!view.ComponentView?.dontRegisterView?.() && !DocumentView.LightboxDoc()) || DocumentView.LightboxContains(view)); } public AddDocumentView(dv: DocumentView) { this._documentViews.add(dv); @@ -68,7 +67,7 @@ export class DocumentManager { private _viewRenderedCbs: { doc: Doc; func: (dv: DocumentView) => any }[] = []; public AddViewRenderedCb = (doc: Opt<Doc>, func: (dv: DocumentView) => any) => { if (doc) { - const dv = LightboxView.LightboxDoc ? this.getLightboxDocumentView(doc) : this.getDocumentView(doc); + const dv = DocumentView.LightboxDoc() ? this.getLightboxDocumentView(doc) : this.getDocumentView(doc); this._viewRenderedCbs.push({ doc, func }); if (dv) { this.callAddViewFuncs(dv); @@ -141,18 +140,18 @@ export class DocumentManager { public getLightboxDocumentView = (toFind: Doc): DocumentView | undefined => { const views: DocumentView[] = []; - DocumentManager.Instance.DocumentViews.forEach(view => LightboxView.Contains(view) && Doc.AreProtosEqual(view.Document, toFind) && views.push(view)); + DocumentManager.Instance.DocumentViews.forEach(view => DocumentView.LightboxContains(view) && Doc.AreProtosEqual(view.Document, toFind) && views.push(view)); return views?.find(view => view.ContentDiv?.getBoundingClientRect().width /* && view._props.focus !== returnFalse) || views?.find(view => view._props.focus !== returnFalse */) || (views.length ? views[0] : undefined); }; public getFirstDocumentView = (toFind: Doc): DocumentView | undefined => { - if (LightboxView.LightboxDoc) return DocumentManager.Instance.getLightboxDocumentView(toFind); + if (DocumentView.LightboxDoc()) return DocumentManager.Instance.getLightboxDocumentView(toFind); const views = this.getDocumentViews(toFind); // .filter(view => view.Document !== originatingDoc); return views?.find(view => view.ContentDiv?.getBoundingClientRect().width /* && view._props.focus !== returnFalse) || views?.find(view => view._props.focus !== returnFalse */) || (views.length ? views[0] : undefined); }; public getDocumentViews(toFind: Doc): DocumentView[] { const toReturn: DocumentView[] = []; - const docViews = DocumentManager.Instance.DocumentViews.filter(view => !LightboxView.Contains(view)); - const lightViews = DocumentManager.Instance.DocumentViews.filter(view => LightboxView.Contains(view)); + const docViews = DocumentManager.Instance.DocumentViews.filter(view => !DocumentView.LightboxContains(view)); + const lightViews = DocumentManager.Instance.DocumentViews.filter(view => DocumentView.LightboxContains(view)); // heuristic to return the "best" documents first: // choose a document in the lightbox first @@ -262,7 +261,7 @@ export class DocumentManager { return; } options.didMove = true; - (!LightboxView.LightboxDoc && docContextPath.some(doc => DocumentView.activateTabView(doc))) || DocumentViewInternal.addDocTabFunc(docContextPath[0], options.openLocation ?? OpenWhere.addRight); + (!DocumentView.LightboxDoc() && docContextPath.some(doc => DocumentView.activateTabView(doc))) || DocumentViewInternal.addDocTabFunc(docContextPath[0], options.openLocation ?? OpenWhere.addRight); this.AddViewRenderedCb(docContextPath[0], dv => res(dv)); })); if (options.openLocation === OpenWhere.lightbox) { diff --git a/src/client/util/ReplayMovements.ts b/src/client/util/ReplayMovements.ts index 530fcf211..c5afe549c 100644 --- a/src/client/util/ReplayMovements.ts +++ b/src/client/util/ReplayMovements.ts @@ -1,16 +1,17 @@ import { IReactionDisposer, makeObservable, observable, reaction } from 'mobx'; import { Doc, IdToDoc } from '../../fields/Doc'; -import { CollectionDockingView } from '../views/collections/CollectionDockingView'; import { CollectionFreeFormView } from '../views/collections/collectionFreeForm'; +import { DocumentView } from '../views/nodes/DocumentView'; import { OpenWhereMod } from '../views/nodes/OpenWhere'; -import { VideoBox } from '../views/nodes/VideoBox'; +import { SnappingManager } from './SnappingManager'; import { Movement, Presentation } from './TrackMovements'; -import { DocumentView } from '../views/nodes/DocumentView'; +import { ViewBoxInterface } from '../views/ViewBoxInterface'; +import { StrCast } from '../../fields/Types'; export class ReplayMovements { private timers: NodeJS.Timeout[] | null; private videoBoxDisposeFunc: IReactionDisposer | null; - private videoBox: VideoBox | null; + private videoBox: ViewBoxInterface<any> | null; private isPlaying: boolean; // create static instance and getter for global use @@ -29,6 +30,22 @@ export class ReplayMovements { this.videoBoxDisposeFunc = null; this.videoBox = null; this.isPlaying = false; + + reaction( + () => SnappingManager.UserPanned, + () => { + if (Doc.UserDoc()?.presentationMode === 'watching') this.pauseFromInteraction(); + } + ); + reaction( + () => DocumentView.Selected().slice(), + selviews => { + const selVideo = selviews.find(dv => dv.ComponentView?.playFrom); + if (selVideo?.ComponentView?.Play) { + this.setVideoBox(selVideo.ComponentView); + } else this.removeVideoBox(); + } + ); } // pausing movements will dispose all timers that are planned to replay the movements @@ -45,18 +62,16 @@ export class ReplayMovements { this.timers?.map(timer => clearTimeout(timer)); }; - setVideoBox = async (videoBox: VideoBox) => { - // console.info('setVideoBox', videoBox); + setVideoBox = async (videoBox: ViewBoxInterface<any>) => { if (this.videoBox !== null) { console.warn('setVideoBox on already videoBox'); } - if (this.videoBoxDisposeFunc !== null) { - console.warn('setVideoBox on already videoBox dispose func'); - this.videoBoxDisposeFunc(); - } + this.videoBoxDisposeFunc?.(); + + const data = StrCast(videoBox.dataDoc?.[videoBox.fieldKey + '_presentation']); + const presentation = data ? JSON.parse(data) : null; - const { presentation } = videoBox; - if (presentation == null) { + if (presentation === null) { console.warn('setVideoBox on null videoBox presentation'); return; } @@ -64,18 +79,14 @@ export class ReplayMovements { this.loadPresentation(presentation); this.videoBoxDisposeFunc = reaction( - () => ({ playing: videoBox._playing, timeViewed: videoBox.player?.currentTime || 0 }), + () => ({ playing: videoBox.IsPlaying?.(), timeViewed: videoBox.PlayerTime?.() || 0 }), ({ playing, timeViewed }) => (playing ? this.playMovements(presentation, timeViewed) : this.pauseMovements()) ); this.videoBox = videoBox; }; removeVideoBox = () => { - if (this.videoBoxDisposeFunc == null) { - console.warn('removeVideoBox on null videoBox'); - return; - } - this.videoBoxDisposeFunc(); + this.videoBoxDisposeFunc?.(); this.videoBox = null; this.videoBoxDisposeFunc = null; @@ -83,7 +94,7 @@ export class ReplayMovements { // should be called from interacting with the screen pauseFromInteraction = () => { - this.videoBox?.Pause(); + this.videoBox?.Pause?.(); this.pauseMovements(); }; @@ -117,7 +128,7 @@ export class ReplayMovements { return undefined; } // console.log('openTab', docId, doc); - CollectionDockingView.AddSplit(doc, OpenWhereMod.right); + DocumentView.addSplit(doc, OpenWhereMod.right); const docView = DocumentView.getDocumentView(doc); // BUG - this returns undefined if the doc is already open return docView?.ComponentView as CollectionFreeFormView; diff --git a/src/client/util/SnappingManager.ts b/src/client/util/SnappingManager.ts index 6789c2ab8..1337d271f 100644 --- a/src/client/util/SnappingManager.ts +++ b/src/client/util/SnappingManager.ts @@ -26,6 +26,7 @@ export class SnappingManager { @observable _serverVersion: string = ''; @observable _lastBtnId: string = ''; @observable _propertyWid: number = 0; + @observable _printToConsole: boolean = false; private constructor() { SnappingManager._manager = this; @@ -55,6 +56,7 @@ export class SnappingManager { public static get ServerVersion() { return this.Instance._serverVersion; } // prettier-ignore public static get LastPressedBtn() { return this.Instance._lastBtnId; } // prettier-ignore public static get PropertiesWidth(){ return this.Instance._propertyWid; } // prettier-ignore + public static get PrintToConsole() { return this.Instance._printToConsole; } // prettier-ignore public static SetShiftKey = (down: boolean) => runInAction(() => {this.Instance._shiftKey = down}); // prettier-ignore public static SetCtrlKey = (down: boolean) => runInAction(() => {this.Instance._ctrlKey = down}); // prettier-ignore @@ -69,6 +71,7 @@ export class SnappingManager { public static SetServerVersion = (version:string) =>runInAction(() => {this.Instance._serverVersion = version}); // prettier-ignore public static SetLastPressedBtn = (id:string) =>runInAction(() => {this.Instance._lastBtnId = id}); // prettier-ignore public static SetPropertiesWidth= (wid:number) =>runInAction(() => {this.Instance._propertyWid = wid}); // prettier-ignore + public static SetPrintToConsole = (state:boolean) =>runInAction(() => {this.Instance._printToConsole = state}); // prettier-ignore public static userColor: string | undefined; public static userVariantColor: string | undefined; diff --git a/src/client/util/UndoManager.ts b/src/client/util/UndoManager.ts index 956c0e674..534ffd2c8 100644 --- a/src/client/util/UndoManager.ts +++ b/src/client/util/UndoManager.ts @@ -3,9 +3,7 @@ import { action, observable, runInAction } from 'mobx'; import { Without } from '../../Utils'; import { RichTextField } from '../../fields/RichTextField'; - -// eslint-disable-next-line prefer-const -let printToConsole = false; // Doc.MyDockedBtns.linearView_IsOpen +import { SnappingManager } from './SnappingManager'; function getBatchName(target: any, key: string | symbol): string { const keyName = key.toString(); @@ -108,7 +106,7 @@ export namespace UndoManager { export function AddEvent(event: UndoEvent, value?: any): void { if (currentBatch && batchCounter.get() && !undoing) { - printToConsole && + SnappingManager.PrintToConsole && console.log( ' '.slice(0, batchCounter.get()) + 'UndoEvent : ' + @@ -183,7 +181,7 @@ export namespace UndoManager { } export function StartBatch(batchName: string): Batch { - printToConsole && console.log(' '.slice(0, batchCounter.get()) + 'Start ' + batchCounter + ' ' + batchName); + SnappingManager.PrintToConsole && console.log(' '.slice(0, batchCounter.get()) + 'Start ' + batchCounter + ' ' + batchName); runInAction(() => batchCounter.set(batchCounter.get() + 1)); if (currentBatch === undefined) { currentBatch = []; @@ -193,7 +191,7 @@ export namespace UndoManager { const EndBatch = action((batchName: string, cancel: boolean = false) => { runInAction(() => batchCounter.set(batchCounter.get() - 1)); - printToConsole && console.log(' '.slice(0, batchCounter.get()) + 'End ' + batchName + ' (' + (currentBatch?.length ?? 0) + ')'); + SnappingManager.PrintToConsole && console.log(' '.slice(0, batchCounter.get()) + 'End ' + batchName + ' (' + (currentBatch?.length ?? 0) + ')'); if (batchCounter.get() === 0 && currentBatch?.length) { if (!cancel) { undoStack.push(currentBatch); |
