HEL-871: preview existing reference media from composer slots
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import ImageLightbox from '$lib/components/ImageLightbox.svelte';
|
||||
import Icon from '$lib/components/ui/Icon.svelte';
|
||||
import { assetUrl } from '$lib/api';
|
||||
import {
|
||||
@@ -12,7 +13,7 @@
|
||||
|
||||
/**
|
||||
* Reference-media list as numbered composer tiles (spec-v2 §3.3 参考图):
|
||||
* 1…N in the order they reach the workflow — click a tile to replace it,
|
||||
* 1…N in the order they reach the workflow — click a tile to preview it (replace from the preview toolbar),
|
||||
* ✕ to remove; a dashed add tile while below `max`; rejected files show
|
||||
* as red tiles that take no place in the list.
|
||||
*/
|
||||
@@ -21,6 +22,7 @@
|
||||
message: string;
|
||||
}
|
||||
interface Props {
|
||||
previewContext?: unknown;
|
||||
label: string;
|
||||
paths: string[];
|
||||
max: number;
|
||||
@@ -48,6 +50,7 @@
|
||||
}
|
||||
|
||||
let {
|
||||
previewContext,
|
||||
label,
|
||||
paths,
|
||||
max,
|
||||
@@ -68,6 +71,17 @@
|
||||
onFromScene,
|
||||
}: Props = $props();
|
||||
|
||||
let previewIndex = $state<number | null>(null);
|
||||
$effect(() => {
|
||||
void previewContext;
|
||||
void paths;
|
||||
void mediaKind;
|
||||
previewIndex = null;
|
||||
});
|
||||
const previewPath = $derived(
|
||||
previewIndex == null ? '' : (paths[previewIndex] ?? ''),
|
||||
);
|
||||
|
||||
let addInput = $state<HTMLInputElement | null>(null);
|
||||
let replaceInput = $state<HTMLInputElement | null>(null);
|
||||
let replaceIndex = $state(-1);
|
||||
@@ -77,7 +91,9 @@
|
||||
|
||||
const uploading = $derived(!!uploadingName);
|
||||
const remaining = $derived(Math.max(0, max - paths.length));
|
||||
const accept = $derived(mediaKind === 'image' ? IMAGE_SLOT_ACCEPT : mediaSlotAccept(mediaKind));
|
||||
const accept = $derived(
|
||||
mediaKind === 'image' ? IMAGE_SLOT_ACCEPT : mediaSlotAccept(mediaKind),
|
||||
);
|
||||
const isMedia = $derived(mediaKind !== 'image');
|
||||
const hintLabel = $derived(
|
||||
isMedia
|
||||
@@ -130,6 +146,22 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<ImageLightbox
|
||||
src={previewPath ? assetUrl(previewPath) : null}
|
||||
kind={mediaKind}
|
||||
alt={label}
|
||||
caption={previewPath ? metaOf(previewPath) : ''}
|
||||
images={paths.map((path) => assetUrl(path) ?? '')}
|
||||
index={previewIndex ?? 0}
|
||||
onnavigate={(i) => (previewIndex = i)}
|
||||
onClose={() => (previewIndex = null)}
|
||||
onReplace={() => {
|
||||
const i = previewIndex;
|
||||
previewIndex = null;
|
||||
if (i != null) pickReplace(i);
|
||||
}}
|
||||
/>
|
||||
|
||||
<div class="a-slot">
|
||||
<div class="a-slot-label">
|
||||
<span>{label}</span>
|
||||
@@ -175,10 +207,10 @@
|
||||
<button
|
||||
type="button"
|
||||
class="a-tile-hit"
|
||||
title={`${t('studio.refReplace')} · ${metaOf(path)}`}
|
||||
aria-label={`${t('studio.refReplace')} ${label} ${i + 1}`}
|
||||
title={`${t('lightbox.mediaPreview')} · ${metaOf(path)}`}
|
||||
aria-label={`${t('lightbox.mediaPreview')} ${label} ${i + 1}`}
|
||||
disabled={uploading}
|
||||
onclick={() => pickReplace(i)}
|
||||
onclick={() => (previewIndex = i)}
|
||||
>
|
||||
{#if mediaKind === 'image'}
|
||||
<img src={assetUrl(path)} alt="" onload={(e) => noteDims(path, e)} />
|
||||
|
||||
Reference in New Issue
Block a user