@@ -33,15 +33,18 @@ import { useIsPhone } from '@/hooks/useMediaQuery';
3333import type { CardLayout } from '@/lib/chat/history' ;
3434import type { Widget } from '@/lib/chat/widgets' ;
3535import { cardRefOf } from '@/lib/studio/cardDownload' ;
36+ import { cardImageName , cardNode , downloadCardImage } from '@/lib/studio/cardImage' ;
3637import { cardLiveOf , type LiveCanvas } from '@/lib/studio/liveCards' ;
3738import { type ThemeDerived , themeVars } from '@/lib/studio/theme' ;
3839
39- // A card's note waits for the pointer to settle — crossing a sheet of cards
40- // should not trail popups behind it — and then outlives the pointer leaving
41- // by enough to cross the few px down to it, where its remove button is
42- // (CardNote).
43- const NOTE_INTENT_MS = 500 ;
40+ // A card's note outlives the pointer leaving by enough to cross the few px
41+ // down to it, where its remove button is (CardNote).
4442const NOTE_GRACE_MS = 150 ;
43+ // And it stays down this long after a card is dropped, then comes back by
44+ // itself. The drag ends under the pointer: nothing leaves, nothing
45+ // re-enters, and the pointer may not move again at all, so the note has to
46+ // be put back rather than wait to be asked for.
47+ const NOTE_DROP_MS = 400 ;
4548
4649export type WhiteboardProps = {
4750 widgets : Widget [ ] ;
@@ -152,29 +155,23 @@ const Whiteboard = ({
152155 } ) ;
153156 const widgetIds = useMemo ( ( ) => new Set ( widgets . map ( ( widget ) => widget . id ) ) , [ widgets ] ) ;
154157 // Which card the pointer is resting on — the whole card, not a tag in it,
155- // is what brings a user's note up (see CardNote). Leaving one is held for
156- // a moment: the note hangs a few px below the card, and the pointer has
157- // to cross that gap to reach the remove button inside it.
158+ // is what brings a user's note up (see CardNote), and it comes up at
159+ // once. Leaving is what is held for a moment: the note hangs a few px
160+ // below the card, and the pointer has to cross that gap to reach the
161+ // remove button inside it.
158162 const [ hoveredId , setHoveredId ] = useState < string | null > ( null ) ;
159- const showNote = useRef ( 0 ) ;
160163 const hideNote = useRef ( 0 ) ;
161- const holdHover = ( id : string ) => {
162- // Back on the card whose note is already up: keep it, and do not
163- // make the reader wait the intent out a second time.
164- if ( hoveredId === id ) {
165- window . clearTimeout ( hideNote . current ) ;
164+ const afterDrop = useRef ( 0 ) ;
166165
167- return ;
168- }
169-
170- window . clearTimeout ( showNote . current ) ;
171- showNote . current = window . setTimeout ( ( ) => setHoveredId ( id ) , NOTE_INTENT_MS ) ;
166+ const holdHover = ( id : string ) => {
167+ window . clearTimeout ( hideNote . current ) ;
168+ setHoveredId ( id ) ;
172169 } ;
173170 const releaseHover = ( id : string ) => {
174- window . clearTimeout ( showNote . current ) ;
171+ // The pointer left: a note queued by a drop is no longer wanted.
172+ window . clearTimeout ( afterDrop . current ) ;
175173
176- // Left before its note ever came up, or left a different card: the
177- // pending hide belongs to whichever note is actually showing.
174+ // The pending hide belongs to whichever note is actually showing.
178175 if ( hoveredId !== id ) {
179176 return ;
180177 }
@@ -184,24 +181,36 @@ const Whiteboard = ({
184181 NOTE_GRACE_MS ,
185182 ) ;
186183 } ;
187-
188- // A dropped card keeps the pointer that was dragging it, so nothing
189- // leaves and nothing re-enters — the note would simply reappear the
190- // instant the drag ended. The wait starts over instead.
191- const restartHover = ( id : string ) => {
192- window . clearTimeout ( showNote . current ) ;
184+ // Take the note down for the drop, then put it back where it was: the
185+ // card is still under the pointer, and no event is coming to say so.
186+ const settleHover = ( id : string ) => {
193187 window . clearTimeout ( hideNote . current ) ;
188+ window . clearTimeout ( afterDrop . current ) ;
194189 setHoveredId ( null ) ;
195- showNote . current = window . setTimeout ( ( ) => setHoveredId ( id ) , NOTE_INTENT_MS ) ;
190+ afterDrop . current = window . setTimeout ( ( ) => setHoveredId ( id ) , NOTE_DROP_MS ) ;
196191 } ;
197192
198193 useEffect (
199194 ( ) => ( ) => {
200- window . clearTimeout ( showNote . current ) ;
201195 window . clearTimeout ( hideNote . current ) ;
196+ window . clearTimeout ( afterDrop . current ) ;
202197 } ,
203198 [ ] ,
204199 ) ;
200+
201+ // Download Image. The card is found in the document rather than held in
202+ // a ref: the menu that asks for it is rendered inside the very card
203+ // being photographed, and the sheet already labels each slot with its
204+ // widget id.
205+ const saveCardImage = ( id : string , title : string ) => {
206+ const node = cardNode ( id ) ;
207+
208+ if ( ! node ) {
209+ return ;
210+ }
211+
212+ void downloadCardImage ( node , cardImageName ( title ) ) ;
213+ } ;
205214 const dragging = useCardDrag ( { boardRef, CELL , f, slots, setSlots, raise, widgetIds } ) ;
206215 const pan = usePan ( boardRef ) ;
207216 const { canvasRef : fxCanvasRef , spawnWave } = useShockwave ( {
@@ -425,6 +434,11 @@ const Whiteboard = ({
425434 onInfo : isText ? null : ( ) => onCardInfo ( widget . id ) ,
426435 onDownload :
427436 onDownload && cardRefOf ( widget ) ? ( ) => onDownload ( widget . id ) : null ,
437+ // Every kind of card photographs the same way, a text
438+ // card included — it is the card's own face, not its
439+ // data, so there is nothing to have or lack.
440+ onDownloadImage :
441+ isLeaving || readOnly ? null : ( ) => saveCardImage ( widget . id , title ) ,
428442 onEdit : isText ? ( ) => onEditText ( widget . id ) : ( ) => onEditTitle ( widget . id ) ,
429443 editLabel : isText ? 'Edit Card' : 'Edit Title' ,
430444 note : isText ? undefined : notes [ widget . id ] ,
@@ -461,6 +475,7 @@ const Whiteboard = ({
461475 ) }
462476 // The card's own module reads these (lift tint, inert
463477 // when filtered out).
478+ data-card-id = { widget . id }
464479 data-dragging = { isDragged ? '' : undefined }
465480 data-dimmed = { dimmed ? '' : undefined }
466481 style = {
@@ -505,14 +520,14 @@ const Whiteboard = ({
505520 onPointerMove : dragging . moveDrag ,
506521 onPointerUp : ( ) => {
507522 if ( drag && extras . note ) {
508- restartHover ( widget . id ) ;
523+ settleHover ( widget . id ) ;
509524 }
510525
511526 dragging . endDrag ( true ) ( ) ;
512527 } ,
513528 onPointerCancel : ( ) => {
514529 if ( drag && extras . note ) {
515- restartHover ( widget . id ) ;
530+ settleHover ( widget . id ) ;
516531 }
517532
518533 dragging . endDrag ( false ) ( ) ;
0 commit comments