From a439a7be3c5cb001d55c78b99cb8da6506afb31a Mon Sep 17 00:00:00 2001 From: bobzel Date: Thu, 17 Oct 2024 11:16:25 -0400 Subject: fixed drag/drop of faces from one face to another. --- .../collectionFreeForm/FaceCollectionBox.tsx | 23 +++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src/client/views/collections') diff --git a/src/client/views/collections/collectionFreeForm/FaceCollectionBox.tsx b/src/client/views/collections/collectionFreeForm/FaceCollectionBox.tsx index 534f67927..6d51ecac6 100644 --- a/src/client/views/collections/collectionFreeForm/FaceCollectionBox.tsx +++ b/src/client/views/collections/collectionFreeForm/FaceCollectionBox.tsx @@ -8,7 +8,7 @@ import { observer } from 'mobx-react'; import React from 'react'; import { DivHeight, lightOrDark, returnTrue, setupMoveUpEvents } from '../../../../ClientUtils'; import { emptyFunction } from '../../../../Utils'; -import { Doc, Opt } from '../../../../fields/Doc'; +import { Doc, DocListCast, Opt } from '../../../../fields/Doc'; import { DocData } from '../../../../fields/DocSymbols'; import { List } from '../../../../fields/List'; import { DocCast, ImageCast, NumCast, StrCast } from '../../../../fields/Types'; @@ -54,7 +54,7 @@ export class UniqueFaceBox extends ViewBoxBaseComponent() { @observable _headerRef: HTMLDivElement | null = null; @observable _listRef: HTMLDivElement | null = null; - observer = new ResizeObserver(a => { + observer = new ResizeObserver(() => { this._props.setHeight?.( (this.props.Document._face_showImages ? 20 : 0) + // (!this._headerRef ? 0 : DivHeight(this._headerRef)) + @@ -97,9 +97,9 @@ export class UniqueFaceBox extends ViewBoxBaseComponent() { const faceMatcher = new FaceMatcher([labeledFaceDescriptor], 1); const faceAnno = FaceRecognitionHandler.ImageDocFaceAnnos(imgDoc).reduce( - (prev, faceAnno) => { - const match = faceMatcher.matchDescriptor(new Float32Array(Array.from(faceAnno.faceDescriptor as List))); - return match.distance < prev.dist ? { dist: match.distance, faceAnno } : prev; + (prev, fAnno) => { + const match = faceMatcher.matchDescriptor(new Float32Array(Array.from(fAnno.faceDescriptor as List))); + return match.distance < prev.dist ? { dist: match.distance, faceAnno: fAnno } : prev; }, { dist: 1, faceAnno: undefined as Opt } ).faceAnno ?? imgDoc; @@ -108,10 +108,18 @@ export class UniqueFaceBox extends ViewBoxBaseComponent() { if (faceAnno) { faceAnno.face && FaceRecognitionHandler.UniqueFaceRemoveFaceImage(faceAnno, DocCast(faceAnno.face)); FaceRecognitionHandler.UniqueFaceAddFaceImage(faceAnno, this.Document); - faceAnno.face = this.Document; + faceAnno[DocData].face = this.Document[DocData]; } } }); + de.complete.docDragData?.droppedDocuments + ?.filter(doc => DocCast(doc.face)?.type === DocumentType.UFACE) + .forEach(faceAnno => { + const imgDoc = faceAnno; + faceAnno.face && FaceRecognitionHandler.UniqueFaceRemoveFaceImage(imgDoc, DocCast(faceAnno.face)); + FaceRecognitionHandler.UniqueFaceAddFaceImage(faceAnno, this.Document); + faceAnno[DocData].face = this.Document[DocData]; + }); e.stopPropagation(); return true; } @@ -189,7 +197,8 @@ export class UniqueFaceBox extends ViewBoxBaseComponent() { this, e, () => { - DragManager.StartDocumentDrag([e.target as HTMLElement], new DragManager.DocumentDragData([doc], dropActionType.embed), e.clientX, e.clientY); + const dragDoc = DocListCast(doc.data_annotations).find(a => a.face === this.Document[DocData]) ?? this.Document; + DragManager.StartDocumentDrag([e.target as HTMLElement], new DragManager.DocumentDragData([dragDoc], dropActionType.embed), e.clientX, e.clientY); return true; }, emptyFunction, -- cgit v1.2.3-70-g09d2 From dd93f5175064850c6c0e47f025cd7bbba1f23106 Mon Sep 17 00:00:00 2001 From: bobzel Date: Thu, 17 Oct 2024 17:19:11 -0400 Subject: fixed quizMode to actually render and to get pointer events. --- src/client/views/collections/CollectionCardDeckView.tsx | 14 +++++++++++++- src/client/views/nodes/ComparisonBox.scss | 3 +++ src/client/views/nodes/ComparisonBox.tsx | 5 +++-- 3 files changed, 19 insertions(+), 3 deletions(-) (limited to 'src/client/views/collections') diff --git a/src/client/views/collections/CollectionCardDeckView.tsx b/src/client/views/collections/CollectionCardDeckView.tsx index 5faabacf4..b86dad9d7 100644 --- a/src/client/views/collections/CollectionCardDeckView.tsx +++ b/src/client/views/collections/CollectionCardDeckView.tsx @@ -4,7 +4,7 @@ import { computedFn } from 'mobx-utils'; import * as React from 'react'; import { ClientUtils, DashColor, imageUrlToBase64, returnFalse, returnNever, returnZero } from '../../../ClientUtils'; import { emptyFunction } from '../../../Utils'; -import { Doc } from '../../../fields/Doc'; +import { Doc, DocListCast, Opt } from '../../../fields/Doc'; import { Animation, DocData } from '../../../fields/DocSymbols'; import { Id } from '../../../fields/FieldSymbols'; import { List } from '../../../fields/List'; @@ -24,6 +24,7 @@ import { DocumentView, DocumentViewProps } from '../nodes/DocumentView'; import { GPTPopup, GPTPopupMode } from '../pdf/GPTPopup/GPTPopup'; import './CollectionCardDeckView.scss'; import { CollectionSubView, SubCollectionViewProps } from './CollectionSubView'; +import { FocusViewOptions } from '../nodes/FocusViewOptions'; enum cardSortings { Time = 'time', @@ -342,6 +343,7 @@ export class CollectionCardView extends CollectionSubView() { fitWidth={returnFalse} waitForDoubleClickToClick={returnNever} scriptContext={this} + focus={this.focus} onDoubleClickScript={this.onChildDoubleClick} onClickScript={this._curDoc === doc ? undefined : this._clickScript} dontCenter="y" // Don't center it vertically, because the grid it's in is already doing that and we don't want to do it twice. @@ -593,6 +595,16 @@ export class CollectionCardView extends CollectionSubView() { } }); + focus = action((anchor: Doc, options: FocusViewOptions): Opt => { + const docs = DocListCast(this.Document[this.fieldKey ?? Doc.LayoutFieldKey(this.Document)]); + if (anchor.type !== DocumentType.CONFIG && !docs.includes(anchor)) return undefined; + options.didMove = true; + const target = DocCast(anchor.annotationOn) ?? anchor; + const index = docs.indexOf(target); + index !== -1 && (this._curDoc = target); + return undefined; + }); + /** * Actually renders all the cards */ diff --git a/src/client/views/nodes/ComparisonBox.scss b/src/client/views/nodes/ComparisonBox.scss index d1cc48051..d2ba9796b 100644 --- a/src/client/views/nodes/ComparisonBox.scss +++ b/src/client/views/nodes/ComparisonBox.scss @@ -236,6 +236,9 @@ } } } +.comparisonBox-interactive { + pointer-events: all; +} .comparisonBox-explain { position: absolute; diff --git a/src/client/views/nodes/ComparisonBox.tsx b/src/client/views/nodes/ComparisonBox.tsx index 3c126ea4a..f6c33d6ba 100644 --- a/src/client/views/nodes/ComparisonBox.tsx +++ b/src/client/views/nodes/ComparisonBox.tsx @@ -792,8 +792,9 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent() const renderMode = new Map JSX.Element>([ [flashcardRevealOp.FLIP, this.renderAsFlip], [flashcardRevealOp.SLIDE, this.renderAsBeforeAfter]]); // prettier-ignore - if (this.isQuizMode) this.renderAsQuiz(this.frontText); - return ( + return this.isQuizMode ? ( + this.renderAsQuiz(this.frontText) + ) : (
{renderMode.get(this.revealOp)?.() ?? null} {this.loading ? ( -- cgit v1.2.3-70-g09d2