aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/newlightbox/NewLightboxView.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/newlightbox/NewLightboxView.tsx')
-rw-r--r--src/client/views/newlightbox/NewLightboxView.tsx62
1 files changed, 13 insertions, 49 deletions
diff --git a/src/client/views/newlightbox/NewLightboxView.tsx b/src/client/views/newlightbox/NewLightboxView.tsx
index 558ce7e38..c86ddb745 100644
--- a/src/client/views/newlightbox/NewLightboxView.tsx
+++ b/src/client/views/newlightbox/NewLightboxView.tsx
@@ -1,6 +1,5 @@
/* eslint-disable jsx-a11y/no-static-element-interactions */
/* eslint-disable jsx-a11y/click-events-have-key-events */
-import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { action, computed, observable } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
@@ -12,7 +11,6 @@ import { Cast, NumCast, StrCast, toList } from '../../../fields/Types';
import { SnappingManager } from '../../util/SnappingManager';
import { Transform } from '../../util/Transform';
import { GestureOverlay } from '../GestureOverlay';
-import { LightboxView } from '../LightboxView';
import { DefaultStyleProvider } from '../StyleProvider';
import { DocumentView } from '../nodes/DocumentView';
import { OpenWhere } from '../nodes/OpenWhere';
@@ -108,7 +106,7 @@ export class NewLightboxView extends React.Component<LightboxViewProps> {
DocumentView.CurrentlyPlaying?.forEach(dv => dv.ComponentView?.Pause?.());
// DocumentView.PinDoc(doc, { hidePresBox: true });
this._history ? this._history.push({ doc, target }) : (this._history = [{ doc, target }]);
- if (doc !== LightboxView.LightboxDoc) {
+ if (doc !== DocumentView.LightboxDoc()) {
this._savedState = {
layout_fieldKey: StrCast(doc.layout_fieldKey),
panX: Cast(doc.freeform_panX, 'number', null),
@@ -151,11 +149,12 @@ export class NewLightboxView extends React.Component<LightboxViewProps> {
if (NewLightboxView._history?.lastElement().target !== target) NewLightboxView._history?.push({ doc, target });
} else if (!target && NewLightboxView.path.length) {
const saved = NewLightboxView._savedState;
- if (LightboxView.LightboxDoc && saved) {
- LightboxView.LightboxDoc._freeform_panX = saved.panX;
- LightboxView.LightboxDoc._freeform_panY = saved.panY;
- LightboxView.LightboxDoc._freeform_scale = saved.scale;
- LightboxView.LightboxDoc._layout_scrollTop = saved.scrollTop;
+ const lightboxDoc = DocumentView.LightboxDoc();
+ if (lightboxDoc && saved) {
+ lightboxDoc._freeform_panX = saved.panX;
+ lightboxDoc._freeform_panY = saved.panY;
+ lightboxDoc._freeform_scale = saved.scale;
+ lightboxDoc._layout_scrollTop = saved.scrollTop;
}
const pop = NewLightboxView.path.pop();
if (pop) {
@@ -176,7 +175,7 @@ export class NewLightboxView extends React.Component<LightboxViewProps> {
NewLightboxView.SetNewLightboxDoc(undefined);
return;
}
- const { doc, target } = NewLightboxView._history?.lastElement();
+ const { doc, target } = NewLightboxView._history?.lastElement() ?? { doc: undefined, target: undefined };
const docView = DocumentView.getLightboxDocumentView(target || doc);
if (docView) {
NewLightboxView._docTarget = target;
@@ -248,14 +247,15 @@ export class NewLightboxView extends React.Component<LightboxViewProps> {
@computed
get documentView() {
- if (!LightboxView.LightboxDoc) return null;
+ const lightboxDoc = DocumentView.LightboxDoc();
+ if (!lightboxDoc) return null;
return (
<GestureOverlay isActive>
<DocumentView
ref={action((r: DocumentView | null) => {
NewLightboxView._docView = r !== null ? r : undefined;
})}
- Document={LightboxView.LightboxDoc}
+ Document={lightboxDoc}
PanelWidth={this.newLightboxWidth}
PanelHeight={this.newLightboxHeight}
LayoutTemplate={NewLightboxView.LightboxDocTemplate}
@@ -281,50 +281,14 @@ export class NewLightboxView extends React.Component<LightboxViewProps> {
newLightboxWidth = () => this.props.PanelWidth - 420;
newLightboxHeight = () => this.props.PanelHeight - 140;
newLightboxScreenToLocal = () => new Transform(-this.leftBorder, -this.topBorder, 1);
- navBtn = (left: Opt<string | number>, bottom: Opt<number>, top: number, icon: string, display: () => string, click: (e: React.MouseEvent) => void, color?: string) => (
- <div
- className="newLightboxView-navBtn-frame"
- style={{
- display: display(),
- left,
- width: bottom !== undefined ? undefined : Math.min(this.props.PanelWidth / 4, this.props.maxBorder[0]),
- bottom,
- }}>
- <div className="newLightboxView-navBtn" title={color} style={{ top, color: color ? 'red' : 'white', background: color ? 'white' : undefined }} onClick={click}>
- <div style={{ height: 10 }}>{color}</div>
- <FontAwesomeIcon icon={icon as any} size="3x" />
- </div>
- </div>
- );
docFilters = () => NewLightboxView._docFilters || [];
- @action
- stepInto = () => {
- NewLightboxView.path.push({
- doc: LightboxView.LightboxDoc,
- target: NewLightboxView._docTarget,
- future: NewLightboxView._future,
- history: NewLightboxView._history,
- saved: NewLightboxView._savedState,
- });
- const coll = NewLightboxView._docTarget;
- if (coll) {
- const fieldKey = Doc.LayoutFieldKey(coll);
- const contents = [...DocListCast(coll[fieldKey]), ...DocListCast(coll[fieldKey + '_annotations'])];
- const links = Doc.Links(coll)
- .map(link => Doc.getOppositeAnchor(link, coll))
- .filter(doc => doc)
- .map(doc => doc!);
- NewLightboxView.SetNewLightboxDoc(coll, undefined, contents.length ? contents : links);
- }
- };
- future = () => NewLightboxView._future;
render() {
const newLightboxHeaderHeight = 100;
let downx = 0;
let downy = 0;
- return !LightboxView.LightboxDoc ? null : (
+ return !DocumentView.LightboxDoc() ? null : (
<div
className="newLightboxView-frame"
onPointerDown={e => {
@@ -376,7 +340,7 @@ export class NewLightboxTourBtn extends React.Component<NewLightboxTourBtnProps>
0,
0,
'chevron-down',
- () => (LightboxView.LightboxDoc /* && this.props.future()?.length */ ? '' : 'none'),
+ () => (DocumentView.LightboxDoc() /* && this.props.future()?.length */ ? '' : 'none'),
e => {
e.stopPropagation();
this.props.stepInto();