Files
aigc-home/calliope-web/src/lib/canvas/EntityNode.svelte
T
施工员2号andmultica-agent 433fd719f1 feat(HEL-884): locate canvas occupancy, accurate card handling, close the delete loop
- GET /api/library/media/usage: read-only occupancy report per file —
  every live canvas card with canvas title, project/session scope, and
  the real consequence of deleting that card (deletes_file / keep reason)
- _path_on_canvas joins canvas: orphan nodes (canvas row gone, FK-cascade
  dead metadata) no longer count as occupancy; they are reported as
  invalid references with totals instead of blocking deletion
- canvas deleteNode: keep_file=true release-only variant (card removed,
  file always preserved); artifact cards with a live pending/running job
  refuse deletion (409) so completion events cannot resurrect them
- library UI: occupancy modal on kept(on_canvas) with locate / delete
  card (accurate impact text) / release-only actions, per-path free-file
  delete closing the loop, invalid-reference note, offset paging for
  large counts, library selection persisted across canvas round-trips
- canvas UI: ?locate=<node> deep-link centers the card (computed
  viewport, no store.fitView — its nodes write-back looped the graph
  rebuild effect), gold ring highlight + dismiss, back-to-library chip
- i18n keys for all 7 languages; e2e runner + 32-check real-browser
  regression on isolated data

Co-authored-by: multica-agent <github@multica.ai>
2026-10-26 23:48:15 +08:00

123 lines
3.4 KiB
Svelte

<script lang="ts">
import { type Node, type NodeProps } from '@xyflow/svelte';
import SafeMedia from '$lib/components/SafeMedia.svelte';
import Icon from '$lib/components/ui/Icon.svelte';
import { assetUrl } from '$lib/api';
import type { IconName } from '$lib/components/ui/icons';
interface EntityNodeData extends Record<string, unknown> {
canvasNodeId: number;
entityType: 'character' | 'location' | 'item' | 'scene';
title: string;
/** Poster image (env image / reference sheet) — shown while not playing. */
imagePath: string | null;
/** Clip path — when set the card becomes a playable video card. */
videoPath: string | null;
/** HEL-884 locate deep-link: this card is the one being looked for. */
located?: boolean;
/** Called on card click: opens the large media preview (no navigation). */
onOpenMedia?: (kind: 'image' | 'video') => void;
}
type EntityNode = Node<EntityNodeData, 'entity'>;
function iconFor(entityType: EntityNodeData['entityType']): IconName {
switch (entityType) {
case 'character':
return 'sparkle';
case 'location':
return 'image';
case 'item':
return 'folder';
case 'scene':
return 'film';
}
}
let { data, selected }: NodeProps<EntityNode> = $props();
const posterSrc = $derived(assetUrl(data.imagePath));
// '#t=0.1' media fragment: with preload="metadata" browsers paint nothing
// until playback, so the thumbnail sat black. The fragment seeks+paints
// the first frame without playing (same trick as ClipMonitor).
const videoSrc = $derived(
data.videoPath ? assetUrl(data.videoPath) + '#t=0.1' : null,
);
function activate() {
// One rule for every card (artifact and entity alike): click opens the
// modal player/lightbox — video cards NEVER play in-card.
if (videoSrc) {
data.onOpenMedia?.('video');
} else if (posterSrc) {
data.onOpenMedia?.('image');
}
}
</script>
<div
class="canvas-card entity-node a-viewfinder"
class:a-in-frame={selected}
class:located={data.located}
data-kind={data.entityType}
data-testid={data.located ? 'located-card' : undefined}
role="button"
tabindex="0"
onclick={activate}
onkeydown={(e) => {
if (e.key === 'Enter') activate();
}}
>
<header>
<span class="kind-icon"
><Icon name={iconFor(data.entityType)} size={14} /></span
>
<span class="title" title={data.title}>{data.title}</span>
{#if videoSrc}
<span class="play-badge" aria-hidden="true">
<Icon name="play" size={10} />
</span>
{/if}
</header>
<div class="media">
{#if videoSrc && posterSrc}
<!-- Idle video card: show the poster (cheap static file, never a
mounted <video>). Click opens the modal player. -->
<SafeMedia
class="media-el"
src={posterSrc}
alt={data.title}
kind="image"
controls={false}
/>
{:else if videoSrc}
<!-- No poster available: #t=0.1 first-frame thumbnail. -->
<video
class="media-el"
src={videoSrc}
muted
playsinline
preload="metadata"
></video>
{:else if posterSrc}
<SafeMedia
class="media-el"
src={posterSrc}
alt={data.title}
kind="image"
controls={false}
/>
{:else}
<span class="placeholder">{data.entityType}</span>
{/if}
{#if videoSrc}<span class="out-kind">video</span>{:else if posterSrc}<span
class="out-kind">image</span
>{/if}
</div>
<footer>
<span>{data.entityType}</span><span class="node-id"
>#{data.canvasNodeId}</span
>
</footer>
</div>