aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/DocumentManager.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/util/DocumentManager.ts')
-rw-r--r--src/client/util/DocumentManager.ts50
1 files changed, 28 insertions, 22 deletions
diff --git a/src/client/util/DocumentManager.ts b/src/client/util/DocumentManager.ts
index 8ad6ddf47..83b83240e 100644
--- a/src/client/util/DocumentManager.ts
+++ b/src/client/util/DocumentManager.ts
@@ -17,7 +17,6 @@ export class DocumentManager {
// eslint-disable-next-line no-use-before-define
private static _instance: DocumentManager;
public static get Instance(): DocumentManager {
- // eslint-disable-next-line no-return-assign
return this._instance || (this._instance = new this());
}
@@ -50,22 +49,23 @@ export class DocumentManager {
DocumentView.getLightboxDocumentView = this.getLightboxDocumentView;
observe(Doc.CurrentlyLoading, change => {
// watch CurrentlyLoading-- when something is loaded, it's removed from the list and we have to update its icon if it were iconified since LoadingBox icons are different than the media they become
- switch (change.type as any) {
+ switch (change.type) {
case 'update':
break;
- case 'remove':
- // DocumentManager.Instance.getAllDocumentViews(change as any).forEach(dv => StrCast(dv.Document.layout_fieldKey) === 'layout_icon' && dv.iconify(() => dv.iconify()));
- break;
case 'splice':
- (change as any).removed.forEach((doc: Doc) => DocumentManager.Instance.getAllDocumentViews(doc).forEach(dv => StrCast(dv.Document.layout_fieldKey) === 'layout_icon' && dv.iconify(() => dv.iconify())));
+ change.removed.forEach((doc: Doc) => DocumentManager.Instance.getAllDocumentViews(doc).forEach(dv => StrCast(dv.Document.layout_fieldKey) === 'layout_icon' && dv.iconify(() => dv.iconify())));
break;
default:
}
});
}
- private _viewRenderedCbs: { doc: Doc; func: (dv: DocumentView) => any }[] = [];
- public AddViewRenderedCb = (doc: Opt<Doc>, func: (dv: DocumentView) => any) => {
+ private _anyViewRenderedCbs: ((dv: DocumentView) => unknown)[] = [];
+ public AddAnyViewRenderedCB = (func: (dv: DocumentView) => unknown) => {
+ this._anyViewRenderedCbs.push(func);
+ };
+ private _viewRenderedCbs: { doc: Doc; func: (dv: DocumentView) => unknown }[] = [];
+ public AddViewRenderedCb = (doc: Opt<Doc>, func: (dv: DocumentView) => unknown) => {
if (doc) {
const dv = DocumentView.LightboxDoc() ? this.getLightboxDocumentView(doc) : this.getDocumentView(doc);
this._viewRenderedCbs.push({ doc, func });
@@ -74,18 +74,20 @@ export class DocumentManager {
return true;
}
} else {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
func(undefined as any);
}
return false;
};
callAddViewFuncs = (view: DocumentView) => {
- const callFuncs = this._viewRenderedCbs.filter(vc => vc.doc === view.Document);
+ const docCallFuncs = this._viewRenderedCbs.filter(vc => vc.doc === view.Document);
+ const callFuncs = docCallFuncs.map(vc => vc.func).concat(this._anyViewRenderedCbs);
if (callFuncs.length) {
- this._viewRenderedCbs = this._viewRenderedCbs.filter(vc => !callFuncs.includes(vc));
+ this._viewRenderedCbs = this._viewRenderedCbs.filter(vc => !docCallFuncs.includes(vc));
const intTimer = setInterval(
() => {
if (!view.ComponentView?.incrementalRendering?.()) {
- callFuncs.forEach(cf => cf.func(view));
+ callFuncs.forEach(cf => cf(view));
clearInterval(intTimer);
}
},
@@ -341,20 +343,24 @@ export class DocumentManager {
// if there's an options.effect, it will be handled from linkFollowHighlight. We delay the start of
// the highlight so that the target document can be somewhat centered so that the effect/highlight will be seen
// bcz: should this delay be an options parameter?
- setTimeout(() => Doc.linkFollowHighlight(viewSpec ? [docView.Document, viewSpec] : docView.Document, undefined, options.effect), (options.zoomTime ?? 0) * 0.5);
+ setTimeout(
+ () => {
+ Doc.linkFollowHighlight(viewSpec ? [docView.Document, viewSpec] : docView.Document, undefined, options.effect);
+ if (options.zoomTextSelections && Doc.IsUnhighlightTimerSet() && contextView && targetDoc.text_html) {
+ // if the docView is a text anchor, the contextView is the PDF/Web/Text doc
+ contextView.setTextHtmlOverlay(StrCast(targetDoc.text_html), options.effect);
+ DocumentManager._overlayViews.add(contextView);
+ }
+ Doc.AddUnHighlightWatcher(() => {
+ docView.Document[Animation] = undefined;
+ DocumentManager.removeOverlayViews();
+ });
+ },
+ (options.zoomTime ?? 0) * 0.5
+ );
if (options.playMedia) docView.ComponentView?.playFrom?.(NumCast(docView.Document._layout_currentTimecode));
if (options.playAudio) DocumentManager.playAudioAnno(docView.Document);
if (options.toggleTarget && (!options.didMove || docView.Document.hidden)) docView.Document.hidden = !docView.Document.hidden;
-
- if (options.zoomTextSelections && Doc.IsUnhighlightTimerSet() && contextView && targetDoc.text_html) {
- // if the docView is a text anchor, the contextView is the PDF/Web/Text doc
- contextView.setTextHtmlOverlay(StrCast(targetDoc.text_html), options.effect);
- DocumentManager._overlayViews.add(contextView);
- }
- Doc.AddUnHighlightWatcher(() => {
- docView.Document[Animation] = undefined;
- DocumentManager.removeOverlayViews();
- });
}
}
}