aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2021-02-25 01:25:36 -0500
committerbobzel <zzzman@gmail.com>2021-02-25 01:25:36 -0500
commit260744fb08aca76f5c1810e0af815df3f851a853 (patch)
tree306c8df9ceba43e2dbd1ea5405b3465e6d3d3c2c /src
parent3410e107435410a5635a70f12ee05e2d874ff01c (diff)
cleaned up DoccomponentView to just have general api fields. fixed lightbox to animate back properly & shinkwrap.
Diffstat (limited to 'src')
-rw-r--r--src/client/views/LightboxView.tsx34
-rw-r--r--src/client/views/collections/TabDocView.tsx8
-rw-r--r--src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx14
-rw-r--r--src/client/views/nodes/DocumentView.tsx5
4 files changed, 28 insertions, 33 deletions
diff --git a/src/client/views/LightboxView.tsx b/src/client/views/LightboxView.tsx
index e967a5b07..1b21bd073 100644
--- a/src/client/views/LightboxView.tsx
+++ b/src/client/views/LightboxView.tsx
@@ -13,7 +13,7 @@ import { SelectionManager } from '../util/SelectionManager';
import { Transform } from '../util/Transform';
import { TabDocView } from './collections/TabDocView';
import "./LightboxView.scss";
-import { DocumentView } from './nodes/DocumentView';
+import { DocumentView, ViewAdjustment } from './nodes/DocumentView';
import { DefaultStyleProvider } from './StyleProvider';
interface LightboxViewProps {
@@ -103,8 +103,7 @@ export class LightboxView extends React.Component<LightboxViewProps> {
[...DocListCast(doc[Doc.LayoutFieldKey(doc)]),
...DocListCast(doc[Doc.LayoutFieldKey(doc) + "-annotations"]),
...(LightboxView._future ?? [])
- ]
- .sort((a: Doc, b: Doc) => NumCast(b._timecodeToShow) - NumCast(a._timecodeToShow)));
+ ].sort((a: Doc, b: Doc) => NumCast(b._timecodeToShow) - NumCast(a._timecodeToShow)));
}
docFilters = () => LightboxView._docFilters || [];
addDocTab = LightboxView.AddDocTab;
@@ -113,8 +112,8 @@ export class LightboxView extends React.Component<LightboxViewProps> {
const target = LightboxView._docTarget = LightboxView._future?.pop();
const docView = target && DocumentManager.Instance.getLightboxDocumentView(target);
if (docView && target) {
- docView.focus(target, { willZoom: true, scale: 0.9 });
- if (LightboxView._history?.lastElement().target !== target) LightboxView._history?.push({ doc, target: LightboxView._docTarget });
+ docView.focus(target, { originalTarget: target, willZoom: true, scale: 0.9 });
+ if (LightboxView._history?.lastElement().target !== target) LightboxView._history?.push({ doc, target });
} else {
if (!target && LightboxView.path.length) {
const saved = LightboxView._savedState;
@@ -149,16 +148,14 @@ export class LightboxView extends React.Component<LightboxViewProps> {
return;
}
const { doc, target } = LightboxView._history?.lastElement();
- const docView = target && DocumentManager.Instance.getLightboxDocumentView(target);
- if (docView && target) {
- LightboxView._doc = doc;
- LightboxView._docTarget = target || doc;
- if (LightboxView._future?.lastElement() !== previous.target || previous.doc) LightboxView._future?.push(previous.target || previous.doc);
- docView.focus(target, { willZoom: true, scale: 0.9 });
- } else {
- LightboxView._doc = doc;
- LightboxView._docTarget = target || doc;
- }
+ const docView = DocumentManager.Instance.getLightboxDocumentView(target || doc);
+ const focusSpeed = 1000;
+ doc._viewTransition = `transform ${focusSpeed}ms`;
+ LightboxView._doc = doc;
+ LightboxView._docTarget = target || doc;
+ docView?.focus(doc, { willZoom: true, scale: 0.9 });
+ setTimeout(() => doc._viewTransition = undefined, focusSpeed);
+ if (LightboxView._future?.lastElement() !== previous.target || previous.doc) LightboxView._future?.push(previous.target || previous.doc);
LightboxView._tourMap = DocListCast(LightboxView._docTarget?.links).map(link => {
const opp = LinkManager.getOppositeAnchor(link, LightboxView._docTarget!);
return opp?.TourMap ? opp : undefined;
@@ -208,11 +205,8 @@ export class LightboxView extends React.Component<LightboxViewProps> {
<DocumentView ref={action((r: DocumentView | null) => {
LightboxView._docView = r !== null ? r : undefined;
setTimeout(action(() => {
- const vals = r?.ComponentView?.freeformData?.();
- if (vals && r) {
- r.layoutDoc._panX = vals.panX;
- r.layoutDoc._panY = vals.panY;
- r.layoutDoc._viewScale = vals.scale;
+ if (r && LightboxView._docTarget === r.props.Document) {
+ r.ComponentView?.shrinkWrap?.();
}
r && (LightboxView._docTarget = undefined);
}));
diff --git a/src/client/views/collections/TabDocView.tsx b/src/client/views/collections/TabDocView.tsx
index 80ddf2f48..3f8794665 100644
--- a/src/client/views/collections/TabDocView.tsx
+++ b/src/client/views/collections/TabDocView.tsx
@@ -273,12 +273,10 @@ export class TabDocView extends React.Component<TabDocViewProps> {
}
@action
focusFunc = (doc: Doc, options?: DocFocusOptions) => {
- const vals = (!options?.originalTarget || options?.originalTarget === this._document) && this.view?.ComponentView?.freeformData?.(true);
- if (vals && this._document) {
+ const shrinkwrap = options?.originalTarget === this._document && this.view?.ComponentView?.shrinkWrap;
+ if (shrinkwrap && this._document) {
const focusSpeed = 1000;
- this._document._panX = vals.panX;
- this._document._panY = vals.panY;
- this._document._viewScale = vals.scale;
+ shrinkwrap();
this._document._viewTransition = `transform ${focusSpeed}ms`;
setTimeout(action(() => {
this._document!._viewTransition = undefined;
diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
index 92c09ff3f..dfca2ba07 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
@@ -120,9 +120,7 @@ export class CollectionFreeFormView extends CollectionSubView<PanZoomDocument, P
@computed get backgroundActive() { return this.props.layerProvider?.(this.layoutDoc) === false && (this.props.ContainingCollectionView?.active() || this.props.active()); }
@computed get fitToContentVals() {
return {
- bounds: this.contentBounds,
- panX: (this.contentBounds.x + this.contentBounds.r) / 2,
- panY: (this.contentBounds.y + this.contentBounds.b) / 2,
+ bounds: { ...this.contentBounds, cx: (this.contentBounds.x + this.contentBounds.r) / 2, cy: (this.contentBounds.y + this.contentBounds.b) / 2 },
scale: !this.childDocs.length ? 1 :
Math.min(this.props.PanelHeight() / (this.contentBounds.b - this.contentBounds.y),
this.props.PanelWidth() / (this.contentBounds.r - this.contentBounds.x))
@@ -154,12 +152,18 @@ export class CollectionFreeFormView extends CollectionSubView<PanZoomDocument, P
onChildDoubleClickHandler = () => this.props.childDoubleClickScript || ScriptCast(this.Document.onChildDoubleClick);
parentActive = (outsideReaction: boolean) => this.props.active(outsideReaction) || this.props.parentActive?.(outsideReaction) || this.backgroundActive || this.layoutDoc._viewType === CollectionViewType.Pile ? true : false;
elementFunc = () => this._layoutElements;
+ shrinkWrap = () => {
+ const vals = this.fitToContentVals;
+ this.layoutDoc._panX = vals.bounds.cx;
+ this.layoutDoc._panY = vals.bounds.cy;
+ this.layoutDoc._viewScale = vals.scale;
+ }
freeformData = (force?: boolean) => this.fitToContent || force ? this.fitToContentVals : undefined;
freeformDocFilters = () => this._focusFilters || this.docFilters();
freeformRangeDocFilters = () => this._focusRangeFilters || this.docRangeFilters();
reverseNativeScaling = () => this.fitToContent ? true : false;
- panX = () => this.freeformData()?.panX ?? NumCast(this.Document._panX);
- panY = () => this.freeformData()?.panY ?? NumCast(this.Document._panY);
+ panX = () => this.freeformData()?.bounds.cx ?? NumCast(this.Document._panX);
+ panY = () => this.freeformData()?.bounds.cy ?? NumCast(this.Document._panY);
zoomScaling = () => (this.freeformData()?.scale ?? NumCast(this.Document[this.scaleFieldKey], 1));
contentTransform = () => `translate(${this.cachedCenteringShiftX}px, ${this.cachedCenteringShiftY}px) scale(${this.zoomScaling()}) translate(${-this.panX()}px, ${-this.panY()}px)`;
getTransform = () => this.cachedGetTransform.copy();
diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx
index ec2c77a82..01d799255 100644
--- a/src/client/views/nodes/DocumentView.tsx
+++ b/src/client/views/nodes/DocumentView.tsx
@@ -80,9 +80,8 @@ export interface DocComponentView {
scrollFocus?: (doc: Doc, smooth: boolean) => Opt<number>; // returns the duration of the focus
setViewSpec?: (anchor: Doc, preview: boolean) => void; // sets viewing information for a componentview, typically when following a link. 'preview' tells the view to use the values without writing to the document
reverseNativeScaling?: () => boolean; // DocumentView's setup screenToLocal based on the doc having a nativeWidth/Height. However, some content views (e.g., FreeFormView w/ fitToBox set) may ignore the native dimensions so this flags the DocumentView to not do Nativre scaling.
- menuControls?: any; // controls to display in the top menu bar when the document is selected.
- // this is kind of hacky since it's not really a generic interface. need to think about how to do this better (it's used to fit a tab's contents to view when shown in a lightbox and to setup the minimap)
- freeformData?: (force?: boolean) => Opt<{ panX: number, panY: number, scale: number, bounds: { x: number, y: number, r: number, b: number } }>; // the content bounds, pan position and zoom scale of a content view (typically for FreeformViews)
+ shrinkWrap?: () => boolean; // requests a document to display all of its contents with no white space. currently only implemented (needed?) for freeform views
+ menuControls?: () => JSX.Element; // controls to display in the top menu bar when the document is selected.
}
export interface DocumentViewSharedProps {
renderDepth: number;