From 729114c0867e3cc8d8e0668bae451976b387cb34 Mon Sep 17 00:00:00 2001 From: bobzel Date: Sun, 28 Apr 2024 13:08:09 -0400 Subject: simplified explore mode implementation --- src/client/views/nodes/DocumentView.tsx | 35 ++++++++++++++-------- src/client/views/nodes/FieldView.tsx | 1 - src/client/views/nodes/ImageBox.tsx | 18 +++++------ .../views/nodes/MapboxMapBox/MapboxContainer.tsx | 1 - src/client/views/nodes/VideoBox.tsx | 4 +++ .../views/nodes/formattedText/FormattedTextBox.tsx | 2 +- 6 files changed, 36 insertions(+), 25 deletions(-) (limited to 'src/client/views/nodes') diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx index 5962cd09f..555b4ba92 100644 --- a/src/client/views/nodes/DocumentView.tsx +++ b/src/client/views/nodes/DocumentView.tsx @@ -165,7 +165,7 @@ export class DocumentViewInternal extends DocComponent this._titleRef.current?.setIsFocused(true)); // use timeout in case title wasn't shown to allow re-render so that titleref will be defined }; + onBrowseClick = (e: React.MouseEvent) => { + const browseTransitionTime = 500; + SelectionManager.DeselectAll(); + DocumentManager.Instance.showDocument(this.Document, { zoomScale: 0.8, willZoomCentered: true }, (focused: boolean) => { + if (!focused && this._docView) { + this._docView + .docViewPath() + .reverse() + .find(cont => cont.ComponentView?.browseTo?.(e.clientX, e.clientY, browseTransitionTime)); + Doc.linkFollowHighlight(this.Document, false); + } + }); + e.stopPropagation(); + }; onClick = action((e: React.MouseEvent | React.PointerEvent) => { if (this._props.isGroupActive?.() === 'child' && !this._props.isDocumentActive?.()) return; const documentView = this._docView; @@ -393,10 +407,8 @@ export class DocumentViewInternal extends DocComponent 0))) { // click events stop here if the document is active and no modes are overriding it // if this is part of a template, let the event go up to the template root unless right/ctrl clicking - if ( - // prettier-ignore - (this._props.isDocumentActive?.() || this._props.isContentActive?.()) && - !this._props.onBrowseClickScript?.() && + if ((this._props.isDocumentActive?.() || this._props.isContentActive?.()) && + !SnappingManager.ExploreMode && !this.Document.ignoreClick && e.button === 0 && !Doc.IsInMyOverlay(this.layoutDoc) @@ -408,7 +420,7 @@ export class DocumentViewInternal extends DocComponent (!SnappingManager.IsDragging || SnappingManager.CanEmbed) && Doc.BrushDoc(this.Document)} onPointerOver={() => (!SnappingManager.IsDragging || SnappingManager.CanEmbed) && Doc.BrushDoc(this.Document)} onPointerLeave={e => !isParentOf(this._contentDiv, document.elementFromPoint(e.nativeEvent.x, e.nativeEvent.y)) && Doc.UnBrushDoc(this.Document)} @@ -1055,7 +1067,7 @@ export class DocumentViewInternal extends DocComponent { recorder.stop(); - DictationManager.Controls.stop(false); + DictationManager.Controls.stop(/* false */); dataDoc.audioAnnoState = AudioAnnoState.stopped; gumStream.getAudioTracks()[0].stop(); }; @@ -1086,9 +1098,6 @@ export class DocumentView extends DocComponent. used by LinkBox's Xanchor to find the arrowhead locations. public DocUniqueId = DocumentView.UniquifyId(LightboxView.Contains(this), this.Document[Id]); - @computed public static get exploreMode() { - return () => (SnappingManager.ExploreMode ? ScriptField.MakeScript('CollectionBrowseClick(documentView, clientX, clientY)', { documentView: 'any', clientX: 'number', clientY: 'number' })! : undefined); - } constructor(props: DocumentViewProps & { CollectionFreeFormDocumentView?: () => CollectionFreeFormDocumentView }) { super(props); diff --git a/src/client/views/nodes/FieldView.tsx b/src/client/views/nodes/FieldView.tsx index 3f453eb93..c2f946a88 100644 --- a/src/client/views/nodes/FieldView.tsx +++ b/src/client/views/nodes/FieldView.tsx @@ -74,7 +74,6 @@ export interface FieldViewSharedProps { onDoubleClickScript?: () => ScriptField; onPointerDownScript?: () => ScriptField; onPointerUpScript?: () => ScriptField; - onBrowseClickScript?: () => ScriptField | undefined; // eslint-disable-next-line no-use-before-define onKey?: (e: React.KeyboardEvent, fieldProps: FieldViewProps) => boolean | undefined; layout_fitWidth?: (doc: Doc) => boolean | undefined; diff --git a/src/client/views/nodes/ImageBox.tsx b/src/client/views/nodes/ImageBox.tsx index 90b4a6740..617c45715 100644 --- a/src/client/views/nodes/ImageBox.tsx +++ b/src/client/views/nodes/ImageBox.tsx @@ -70,7 +70,13 @@ export class ImageBox extends ViewBoxAnnotatableComponent() impl private _getAnchor: (savedAnnotations: Opt>, addAsAnnotation: boolean) => Opt = () => undefined; private _overlayIconRef = React.createRef(); private _marqueeref = React.createRef(); + private _mainCont: React.RefObject = React.createRef(); + private _annotationLayer: React.RefObject = React.createRef(); + @observable _savedAnnotations = new ObservableMap(); @observable _curSuffix = ''; + @observable _error = ''; + @observable _isHovering = false; // flag to switch between primary and alternate images on hover + _ffref = React.createRef(); constructor(props: FieldViewProps) { super(props); @@ -274,7 +280,7 @@ export class ImageBox extends ViewBoxAnnotatableComponent() impl } }; - choosePath(url: URL) { + choosePath = (url: URL) => { if (!url?.href) return ''; const lower = url.href.toLowerCase(); if (url.protocol === 'data') return url.href; @@ -283,7 +289,7 @@ export class ImageBox extends ViewBoxAnnotatableComponent() impl const ext = extname(url.href); return url.href.replace(ext, (this._error ? '_o' : this._curSuffix) + ext); - } + }; getScrollHeight = () => (this._props.layout_fitWidth?.(this.Document) !== false && NumCast(this.layoutDoc._freeform_scale, 1) === NumCast(this.dataDoc._freeform_scaleMin, 1) ? this.nativeSize.nativeHeight : undefined); @computed get nativeSize() { @@ -346,9 +352,6 @@ export class ImageBox extends ViewBoxAnnotatableComponent() impl return paths.length ? paths : [defaultUrl.href]; } - @observable _error = ''; - - @observable _isHovering = false; // flag to switch between primary and alternate images on hover @computed get content() { TraceMobx(); @@ -407,13 +410,11 @@ export class ImageBox extends ViewBoxAnnotatableComponent() impl ); } - private _mainCont: React.RefObject = React.createRef(); - private _annotationLayer: React.RefObject = React.createRef(); - @observable _savedAnnotations = new ObservableMap(); @computed get annotationLayer() { TraceMobx(); return
; } + browseTo = (clientX: number, clientY: number, browseTransitionTime: number) => !!this._ffref.current?.browseTo?.(clientX, clientY, browseTransitionTime); screenToLocalTransform = () => this.ScreenToLocalBoxXf().translate(0, NumCast(this.layoutDoc._layout_scrollTop) * this.ScreenToLocalBoxXf().Scale); marqueeDown = (e: React.PointerEvent) => { if (!this.dataDoc[this.fieldKey]) { @@ -447,7 +448,6 @@ export class ImageBox extends ViewBoxAnnotatableComponent() impl }; focus = (anchor: Doc, options: FocusViewOptions) => (anchor.type === DocumentType.CONFIG ? undefined : this._ffref.current?.focus(anchor, options)); - _ffref = React.createRef(); savedAnnotations = () => this._savedAnnotations; render() { TraceMobx(); diff --git a/src/client/views/nodes/MapboxMapBox/MapboxContainer.tsx b/src/client/views/nodes/MapboxMapBox/MapboxContainer.tsx index 67872efc3..c19528af6 100644 --- a/src/client/views/nodes/MapboxMapBox/MapboxContainer.tsx +++ b/src/client/views/nodes/MapboxMapBox/MapboxContainer.tsx @@ -802,7 +802,6 @@ export class MapBoxContainer extends ViewBoxAnnotatableComponent NativeHeight={returnOne} onKey={undefined} onDoubleClickScript={undefined} - onBrowseClickScript={undefined} childFilters={returnEmptyFilter} childFiltersByRanges={returnEmptyFilter} searchFilterDocs={returnEmptyDoclist} diff --git a/src/client/views/nodes/VideoBox.tsx b/src/client/views/nodes/VideoBox.tsx index 4b80f2485..fd7997248 100644 --- a/src/client/views/nodes/VideoBox.tsx +++ b/src/client/views/nodes/VideoBox.tsx @@ -64,6 +64,7 @@ export class VideoBox extends ViewBoxAnnotatableComponent() impl private _annotationLayer: React.RefObject = React.createRef(); private _playRegionTimer: any = null; // timeout for playback private _controlsFadeTimer: any = null; // timeout for controls fade + private _ffref = React.createRef(); constructor(props: FieldViewProps) { super(props); @@ -978,6 +979,8 @@ export class VideoBox extends ViewBoxAnnotatableComponent() impl this._props.bringToFront?.(cropping); return cropping; }; + browseTo = (clientX: number, clientY: number, browseTransitionTime: number) => !!this._ffref.current?.browseTo(clientX, clientY, browseTransitionTime); + focus = (anchor: Doc, options: FocusViewOptions) => (anchor.type === DocumentType.CONFIG ? undefined : this._ffref.current?.focus(anchor, options)); savedAnnotations = () => this._savedAnnotations; render() { const borderRad = this._props.styleProvider?.(this.layoutDoc, this._props, StyleProp.BorderRounding); @@ -1005,6 +1008,7 @@ export class VideoBox extends ViewBoxAnnotatableComponent() impl