Clear deleted stills from the stage and library detail pane.

The file and catalog row were already removed, but the selected object stayed on screen so its prompt could still be applied.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Towsty
2026-10-25 19:54:18 -05:00
co-authored by Cursor
parent 20359bfbd4
commit 68469d9c71
3 changed files with 263 additions and 84 deletions
+217 -68
View File
@@ -238,7 +238,7 @@
@click="libraryOpen=true" @click="libraryOpen=true"
>Library<span v-if="familyStillCount" class="stage-library-count">{{ familyStillCount }}</span></button> >Library<span v-if="familyStillCount" class="stage-library-count">{{ familyStillCount }}</span></button>
<div <div
v-if="selected && selected.kind!=='track' && (selected.kind==='clip' || showSelectedStill)" v-if="selectedClipLive || showSelectedStill"
class="stage-actions" class="stage-actions"
aria-label="Selected still actions" aria-label="Selected still actions"
> >
@@ -283,7 +283,7 @@
<button type="button" class="stage-action-danger" @click="deleteOutput">Delete</button> <button type="button" class="stage-action-danger" @click="deleteOutput">Delete</button>
</div> </div>
<button <button
v-if="selected && (selected.kind==='clip' || selected.kind==='track' || showSelectedStill)" v-if="selectedClipLive || selectedTrackLive || showSelectedStill"
type="button" type="button"
class="eye-viewer" class="eye-viewer"
:aria-pressed="eyeOpen" :aria-pressed="eyeOpen"
@@ -304,15 +304,15 @@
>‹</button> >‹</button>
<div class="viewer-frame"> <div class="viewer-frame">
<p <p
v-show="selected && isHidden(selected)" v-show="(selectedClipLive || selectedTrackLive || showSelectedStill) && isHidden(selected)"
class="placeholder-still viewer-veil-label" class="placeholder-still viewer-veil-label"
>{{ selected?.kind==='track' ? 'Track loaded · preview hidden' : 'Output hidden' }}</p> >{{ selected?.kind==='track' ? 'Track loaded · preview hidden' : 'Output hidden' }}</p>
<template v-if="selected?.kind==='track'"> <template v-if="selectedTrackLive">
<div v-show="!isHidden(selected)" class="w-full max-w-xl px-6 py-4"> <div v-show="!isHidden(selected)" class="w-full max-w-xl px-6 py-4">
<AudioPlayer :key="selected.id" :src="`/api/library/tracks/${selected.id}/audio`" :download-name="`${selected.name || 'track'}.${selected.ext || 'wav'}`" :label="selected.name || 'Track'" /> <AudioPlayer :key="selected.id" :src="`/api/library/tracks/${selected.id}/audio`" :download-name="`${selected.name || 'track'}.${selected.ext || 'wav'}`" :label="selected.name || 'Track'" />
</div> </div>
</template> </template>
<template v-else-if="selected?.kind==='clip'"> <template v-else-if="selectedClipLive">
<video <video
v-show="!isHidden(selected)" v-show="!isHidden(selected)"
ref="viewerVideo" ref="viewerVideo"
@@ -323,7 +323,7 @@
@loadedmetadata="onVideoTime" @loadedmetadata="onVideoTime"
/> />
</template> </template>
<template v-else-if="selected && showSelectedStill"> <template v-else-if="showSelectedStill">
<img <img
v-show="!isHidden(selected)" v-show="!isHidden(selected)"
:key="selected.id+'-'+stagePreviewNonce" :key="selected.id+'-'+stagePreviewNonce"
@@ -721,9 +721,13 @@ function restoreBenchDraft(){
if(draft.lockFace!=null)form.lockFace=!!draft.lockFace if(draft.lockFace!=null)form.lockFace=!!draft.lockFace
if(draft.lockOutfit!=null)form.lockOutfit=!!draft.lockOutfit if(draft.lockOutfit!=null)form.lockOutfit=!!draft.lockOutfit
if(draft.promptSections)form.promptSections=sectionsFrom(draft.promptSections) if(draft.promptSections)form.promptSections=sectionsFrom(draft.promptSections)
if(Array.isArray(draft.photos))form.photos=draft.photos if(Array.isArray(draft.photos)){
const known=libraryLoadedAt?new Set((library.value.stills||[]).map((s:any)=>s.id)):null
form.photos=draft.photos
.filter((p:any)=>p && typeof p.stillId==='string' && p.stillId) .filter((p:any)=>p && typeof p.stillId==='string' && p.stillId)
.map((p:any)=>({stillId:String(p.stillId),role:String(p.role||'change')})) .map((p:any)=>({stillId:String(p.stillId),role:String(p.role||'change')}))
.filter((p:any)=>!removedStillIds.has(p.stillId) && (!known || known.has(p.stillId)))
}
if(draft.imageStyles)form.imageStyles={ if(draft.imageStyles)form.imageStyles={
positive:Array.isArray(draft.imageStyles.positive)?draft.imageStyles.positive.map((s:any)=>String(s||'')).filter(Boolean):[], positive:Array.isArray(draft.imageStyles.positive)?draft.imageStyles.positive.map((s:any)=>String(s||'')).filter(Boolean):[],
negative:Array.isArray(draft.imageStyles.negative)?draft.imageStyles.negative.map((s:any)=>String(s||'')).filter(Boolean):[] negative:Array.isArray(draft.imageStyles.negative)?draft.imageStyles.negative.map((s:any)=>String(s||'')).filter(Boolean):[]
@@ -753,12 +757,51 @@ function restoreBenchDraft(){
if(draft.music.name!=null)music.name=String(draft.music.name) if(draft.music.name!=null)music.name=String(draft.music.name)
} }
syncPhotosBindings() syncPhotosBindings()
if(libraryLoadedAt) restoreDraftSelection()
}catch{ }catch{
clearDraftStores() clearDraftStores()
}finally{ }finally{
restoringDraft=false restoringDraft=false
} }
} }
function restoreDraftSelection(){
const raw=readDraftRaw()
let draft:any=null
try{draft=raw?JSON.parse(raw):null}catch{return}
const stillsNow=library.value.stills||[]
const stillIds=new Set(stillsNow.map((s:any)=>s.id))
const liveStill=(id:string)=>!!id && !removedStillIds.has(id) && stillIds.has(id)
if(form.imageAId && !liveStill(form.imageAId)) form.imageAId=''
if(form.identityStillId && !liveStill(form.identityStillId)){
form.identityStillId=''
try{localStorage.removeItem(`studio2-hero:${form.folderId}`)}catch{/* ignore */}
}
form.photos=(form.photos||[]).filter((p:any)=>liveStill(p?.stillId))
syncPhotosBindings()
const selectedId=String(draft?.selectedId||'')
if(!selectedId){
if(selected.value?.id && !assetInLibrary(selected.value)){
selected.value=null
selectionPinned.value=false
}
return
}
if(removedStillIds.has(selectedId)){
selected.value=null
selectionPinned.value=false
return
}
const still=stillsNow.find((s:any)=>s.id===selectedId)
const clip=(library.value.clips||[]).find((c:any)=>c.id===selectedId)
const track=(library.value.tracks||[]).find((t:any)=>t.id===selectedId)
if(still) selected.value={...still,kind:'still'}
else if(clip) selected.value={...clip,kind:'clip'}
else if(track) selected.value={...track,kind:'track'}
else {
selected.value=null
selectionPinned.value=false
}
}
const xaigen=isXaigenStudio(useRuntimeConfig().public) const xaigen=isXaigenStudio(useRuntimeConfig().public)
const instanceName=String(useRuntimeConfig().public.instanceName || 'AIGen') const instanceName=String(useRuntimeConfig().public.instanceName || 'AIGen')
@@ -770,7 +813,9 @@ const picker=ref('')
const pickerRevealAll=ref(false) const pickerRevealAll=ref(false)
const uploading=ref(false),uploadMessage=ref('') const uploading=ref(false),uploadMessage=ref('')
const revealed=ref<Set<string>>(new Set()) const revealed=ref<Set<string>>(new Set())
const measured=reactive<Record<string,{width:number;height:number}>>({}),seenOutputs=new Set<string>() const measured=reactive<Record<string,{width:number;height:number}>>({}),seenOutputs=new Set<string>(),removedStillIds=new Set<string>(),watchedJobIds=new Set<string>()
let holdEmptyStage=false
let libraryLoadedAt=0
const loraNames=ref<any>({image:[],video:[]}),now=ref(Date.now()),healthState=ref<any>(null),upscales=ref<any[]>([]) const loraNames=ref<any>({image:[],video:[]}),now=ref(Date.now()),healthState=ref<any>(null),upscales=ref<any[]>([])
const library=ref<any>({folders:[],stills:[],clips:[],tracks:[]}),jobs=ref<any[]>([]),selected=ref<any>(null) const library=ref<any>({folders:[],stills:[],clips:[],tracks:[]}),jobs=ref<any[]>([]),selected=ref<any>(null)
const studioQueue=ref<any[]>([]) const studioQueue=ref<any[]>([])
@@ -916,7 +961,10 @@ watch(()=>form.folderId,(id,prev)=>{
form.startClipId='' form.startClipId=''
} }
loadRevealed(id) loadRevealed(id)
if(import.meta.client && form.engine!=='qwen21')form.identityStillId=localStorage.getItem(`studio2-hero:${id}`)||'' if(import.meta.client && form.engine!=='qwen21'){
const hero=localStorage.getItem(`studio2-hero:${id}`)||''
form.identityStillId=hero && !removedStillIds.has(hero)?hero:''
}
void loadLibraryOnce().catch(()=>null) void loadLibraryOnce().catch(()=>null)
},{flush:'sync'}) },{flush:'sync'})
watch(()=>form.identityStillId,id=>{if(import.meta.client&&form.folderId&&form.engine!=='qwen21')localStorage.setItem(`studio2-hero:${form.folderId}`,id)}) watch(()=>form.identityStillId,id=>{if(import.meta.client&&form.folderId&&form.engine!=='qwen21')localStorage.setItem(`studio2-hero:${form.folderId}`,id)})
@@ -973,20 +1021,53 @@ const forgottenStillIds=ref(new Set<string>())
const libraryRefreshKey=ref(0) const libraryRefreshKey=ref(0)
const pickerAssets=computed(()=>{ const pickerAssets=computed(()=>{
const forget=forgottenStillIds.value const forget=forgottenStillIds.value
if(picker.value==='startClipId')return clips.value.filter((a:any)=>!forget.has(a.id)).map((a:any)=>({...a,kind:'clip'})) if(picker.value==='startClipId')return clips.value.filter((a:any)=>!forget.has(a.id)&&!removedStillIds.has(a.id)).map((a:any)=>({...a,kind:'clip'}))
return stills.value.filter((a:any)=>!forget.has(a.id)).map((a:any)=>({...a,kind:'still'})) return stills.value.filter((a:any)=>!forget.has(a.id)&&!removedStillIds.has(a.id)).map((a:any)=>({...a,kind:'still'}))
})
const inputStill=computed(()=>stills.value.find((s:any)=>s.id===form.imageAId&&!forgottenStillIds.value.has(s.id)&&!removedStillIds.has(s.id)))
const family=computed(()=>{
const folder=(library.value.folders||[]).find((f:any)=>f.id===form.folderId)
const emptyImages=!!folder && typeof folder.imageCount==='number' && folder.imageCount===0
return folderAssets(library.value,jobs.value,form.folderId).filter((asset:any)=>{
if(!asset?.id || forgottenStillIds.value.has(asset.id) || removedStillIds.has(asset.id)) return false
if(emptyImages && asset.kind==='still') return false
return true
})
}) })
const inputStill=computed(()=>stills.value.find((s:any)=>s.id===form.imageAId&&!forgottenStillIds.value.has(s.id)))
const family=computed(()=>folderAssets(library.value,jobs.value,form.folderId))
const familyStillCount=computed(()=>folderImageCount( const familyStillCount=computed(()=>folderImageCount(
(library.value.folders||[]).find((f:any)=>f.id===form.folderId), (library.value.folders||[]).find((f:any)=>f.id===form.folderId),
family.value.filter((a:any)=>a.kind==='still').length family.value.filter((a:any)=>a.kind==='still').length
)) ))
function assetInLibrary(item:any){
if(!item?.id || forgottenStillIds.value.has(item.id) || removedStillIds.has(item.id)) return false
if(item.kind==='clip') return (library.value.clips||[]).some((row:any)=>row.id===item.id)
if(item.kind==='track') return (library.value.tracks||[]).some((row:any)=>row.id===item.id)
return (library.value.stills||[]).some((row:any)=>row.id===item.id)
}
const selectedClipLive=computed(()=>selected.value?.kind==='clip' && assetInLibrary(selected.value))
const selectedTrackLive=computed(()=>selected.value?.kind==='track' && assetInLibrary(selected.value))
const showSelectedStill=computed(()=>{ const showSelectedStill=computed(()=>{
const item=selected.value const item=selected.value
if(!item?.id || item.kind==='clip' || item.kind==='track') return false if(!item?.id || item.kind==='clip' || item.kind==='track') return false
if(forgottenStillIds.value.has(item.id)) return false if(forgottenStillIds.value.has(item.id) || removedStillIds.has(item.id)) return false
return (library.value.stills||[]).some((s:any)=>s.id===item.id) const row=(library.value.stills||[]).find((s:any)=>s.id===item.id)
if(!row) return false
const folder=(library.value.folders||[]).find((f:any)=>f.id===(row.folderId||item.folderId||form.folderId))
if(folder && typeof folder.imageCount==='number' && folder.imageCount===0) return false
return row.id===item.id
})
watch(()=>[selected.value?.id, selected.value?.kind, showSelectedStill.value, selectedClipLive.value, selectedTrackLive.value], ()=>{
const item=selected.value
if(!item?.id) return
if(item.kind==='clip'){
if(!selectedClipLive.value){selected.value=null;selectionPinned.value=false}
return
}
if(item.kind==='track'){
if(!selectedTrackLive.value){selected.value=null;selectionPinned.value=false}
return
}
if(!showSelectedStill.value){selected.value=null;selectionPinned.value=false}
}) })
const sourceAsset=computed(()=>form.startClipId?clips.value.find((c:any)=>c.id===form.startClipId):stills.value.find((s:any)=>s.id===(form.imageAId||form.identityStillId||form.photos?.[0]?.stillId))) const sourceAsset=computed(()=>form.startClipId?clips.value.find((c:any)=>c.id===form.startClipId):stills.value.find((s:any)=>s.id===(form.imageAId||form.identityStillId||form.photos?.[0]?.stillId)))
const sourceSize=computed(()=>measured[sourceAsset.value?.id] || sourceAsset.value) const sourceSize=computed(()=>measured[sourceAsset.value?.id] || sourceAsset.value)
@@ -1111,7 +1192,7 @@ function addNegative(){
negativeDraft.value='' negativeDraft.value=''
} }
function stillById(id:string){ function stillById(id:string){
if(!id||forgottenStillIds.value.has(id))return null if(!id||forgottenStillIds.value.has(id)||removedStillIds.has(id))return null
return stills.value.find((s:any)=>s.id===id) return stills.value.find((s:any)=>s.id===id)
|| (library.value.stills||[]).find((s:any)=>s.id===id) || (library.value.stills||[]).find((s:any)=>s.id===id)
|| null || null
@@ -1122,7 +1203,10 @@ function clearFormSlots(ids:string[]){
const touched=gone.has(form.imageAId)||gone.has(form.imageBId)||gone.has(form.identityStillId)||(form.photos||[]).some((p:any)=>gone.has(p?.stillId)) const touched=gone.has(form.imageAId)||gone.has(form.imageBId)||gone.has(form.identityStillId)||(form.photos||[]).some((p:any)=>gone.has(p?.stillId))
if(gone.has(form.imageAId))form.imageAId='' if(gone.has(form.imageAId))form.imageAId=''
if(gone.has(form.imageBId))form.imageBId='' if(gone.has(form.imageBId))form.imageBId=''
if(gone.has(form.identityStillId))form.identityStillId='' if(gone.has(form.identityStillId)){
form.identityStillId=''
try{localStorage.removeItem(`studio2-hero:${form.folderId}`)}catch{/* ignore */}
}
if(gone.has(form.maskId))form.maskId='' if(gone.has(form.maskId))form.maskId=''
if(gone.has(form.endStillId))form.endStillId='' if(gone.has(form.endStillId))form.endStillId=''
if(gone.has(form.startClipId))form.startClipId='' if(gone.has(form.startClipId))form.startClipId=''
@@ -1152,7 +1236,7 @@ function clearRefsMissingFromLibrary(){
const sel=selected.value const sel=selected.value
if(sel?.id){ if(sel?.id){
const ok=sel.kind==='clip'?clipIds.has(sel.id):sel.kind==='track'?trackIds.has(sel.id):ids.has(sel.id) const ok=sel.kind==='clip'?clipIds.has(sel.id):sel.kind==='track'?trackIds.has(sel.id):ids.has(sel.id)
if(!ok){ if(!ok || removedStillIds.has(sel.id)){
selected.value=null selected.value=null
selectionPinned.value=false selectionPinned.value=false
} }
@@ -1280,8 +1364,13 @@ function sourceStillIdsOf(item:any){
} }
function resolveActionAsset(item?:any){ function resolveActionAsset(item?:any){
// Stage @click handlers pass a MouseEvent as the first arg — never treat events as library assets. // Stage @click handlers pass a MouseEvent as the first arg — never treat events as library assets.
if(item && typeof item.id==='string' && item.id) return item if(item && typeof item.id==='string' && item.id){
return selected.value if(forgottenStillIds.value.has(item.id) || !assetInLibrary(item)) return null
return item
}
if(showSelectedStill.value) return selected.value
if(selectedClipLive.value || selectedTrackLive.value) return selected.value
return null
} }
function useImageRole(){ function useImageRole(){
const plan=photosPlanState.value const plan=photosPlanState.value
@@ -1511,20 +1600,34 @@ async function deleteOutput(explicit?:any){
if(import.meta.client && !window.confirm(`Delete ${label}?`))return if(import.meta.client && !window.confirm(`Delete ${label}?`))return
const id=String(target.id) const id=String(target.id)
const kind=target.kind==='clip'?'clips/':target.kind==='track'?'tracks/':'stills/' const kind=target.kind==='clip'?'clips/':target.kind==='track'?'tracks/':'stills/'
holdEmptyStage=true
if(String(selected.value?.id||'')===id){
selected.value=null
selectionPinned.value=false
}
try{ try{
await $fetch('/api/library/'+kind+id,{method:'DELETE'}) await $fetch('/api/library/'+kind+id,{method:'DELETE'})
}catch(e:any){ }catch(e:any){
const status=Number(e?.statusCode||e?.status||e?.response?.status||0) const status=Number(e?.statusCode||e?.status||e?.response?.status||0)
if(status!==404){ if(status!==404){
error.value=e?.data?.statusMessage||e?.message error.value=e?.data?.statusMessage||e?.message
holdEmptyStage=false
libraryRefreshKey.value+=1
return return
} }
} }
seenOutputs.add(id) seenOutputs.add(id)
removedStillIds.add(id)
forgottenStillIds.value=new Set([...forgottenStillIds.value,id]) forgottenStillIds.value=new Set([...forgottenStillIds.value,id])
clearFormSlots([id]) clearFormSlots([id])
const countKey=kind==='clips/'?'clipCount':kind==='tracks/'?'trackCount':'imageCount'
library.value={ library.value={
...library.value, ...library.value,
folders:(library.value.folders||[]).map((folder:any)=>{
if(String(folder?.id||'')!==String(target.folderId||form.folderId||'')) return folder
if(typeof folder[countKey]!=='number') return folder
return {...folder,[countKey]:Math.max(0,folder[countKey]-1)}
}),
stills:(library.value.stills||[]).filter((s:any)=>s.id!==id), stills:(library.value.stills||[]).filter((s:any)=>s.id!==id),
clips:(library.value.clips||[]).filter((c:any)=>c.id!==id), clips:(library.value.clips||[]).filter((c:any)=>c.id!==id),
tracks:(library.value.tracks||[]).filter((t:any)=>t.id!==id) tracks:(library.value.tracks||[]).filter((t:any)=>t.id!==id)
@@ -1550,29 +1653,45 @@ function runStageMenu(fn:()=>void|Promise<void>){
stageMenu.value='' stageMenu.value=''
void fn() void fn()
} }
function libraryActionItem(item:any){
if(!item?.id || forgottenStillIds.value.has(item.id) || removedStillIds.has(item.id)) return null
return item
}
function onLibraryUseImage(item:any){ function onLibraryUseImage(item:any){
if(item)selectOutput(item) const asset=libraryActionItem(item)
applyUseImage(item) if(!asset) return
selectOutput(asset)
applyUseImage(asset)
} }
function onLibraryUsePrompt(item:any){ function onLibraryUsePrompt(item:any){
if(item)selectOutput(item) const asset=libraryActionItem(item)
applyUsePrompt(item) if(!asset) return
selectOutput(asset)
applyUsePrompt(asset)
} }
function onLibraryCopyPrompt(item:any){ function onLibraryCopyPrompt(item:any){
if(item)selectOutput(item) const asset=libraryActionItem(item)
void copySelectedPrompt(item) if(!asset) return
selectOutput(asset)
void copySelectedPrompt(asset)
} }
function onLibraryCopyRawPrompt(item:any){ function onLibraryCopyRawPrompt(item:any){
if(item)selectOutput(item) const asset=libraryActionItem(item)
void copySelectedRawPrompt(item) if(!asset) return
selectOutput(asset)
void copySelectedRawPrompt(asset)
} }
function onLibraryLoadInput(item:any){ function onLibraryLoadInput(item:any){
if(item)selectOutput(item) const asset=libraryActionItem(item)
loadInputUsed(item) if(!asset) return
selectOutput(asset)
loadInputUsed(asset)
} }
function onLibraryLoadInputRaw(item:any){ function onLibraryLoadInputRaw(item:any){
if(item)selectOutput(item) const asset=libraryActionItem(item)
loadInputRaw(item) if(!asset) return
selectOutput(asset)
loadInputRaw(asset)
} }
function onLibraryDelete(item:any){ function onLibraryDelete(item:any){
void deleteOutput(item) void deleteOutput(item)
@@ -1585,7 +1704,8 @@ function onLibraryWiped(result:any){
...(library.value.clips||[]).filter((s:any)=>String(s.folderId||'')===folderId).map((s:any)=>s.id), ...(library.value.clips||[]).filter((s:any)=>String(s.folderId||'')===folderId).map((s:any)=>s.id),
...(library.value.tracks||[]).filter((s:any)=>String(s.folderId||'')===folderId).map((s:any)=>s.id) ...(library.value.tracks||[]).filter((s:any)=>String(s.folderId||'')===folderId).map((s:any)=>s.id)
] ]
for(const id of deleted) seenOutputs.add(id) for(const id of deleted){seenOutputs.add(id);removedStillIds.add(id)}
holdEmptyStage=true
const next=libraryAfterWipe({ const next=libraryAfterWipe({
folders:library.value.folders, folders:library.value.folders,
stills:library.value.stills, stills:library.value.stills,
@@ -1781,15 +1901,25 @@ function onTaskSelect(event:Event){chooseTask((event.target as HTMLSelectElement
function chooseClip(id:string){if(!id){form.startClipId='';return}const clip=clips.value.find((c:any)=>c.id===id);if(clip){try{Object.assign(form,bindClip(form,clip,xaigen,loraMemory))}catch(e:any){error.value=e?.message||'Could not copy clip settings.';form.startClipId=clip.id;form.mode='extend';form.engine=xaigen && form.engine==='ltx'?'ltx':'minimax'}}} function chooseClip(id:string){if(!id){form.startClipId='';return}const clip=clips.value.find((c:any)=>c.id===id);if(clip){try{Object.assign(form,bindClip(form,clip,xaigen,loraMemory))}catch(e:any){error.value=e?.message||'Could not copy clip settings.';form.startClipId=clip.id;form.mode='extend';form.engine=xaigen && form.engine==='ltx'?'ltx':'minimax'}}}
function selectOutput(item:any){ function selectOutput(item:any){
stageMenu.value='' stageMenu.value=''
if(item?.id && !forgottenStillIds.value.has(item.id)){ if(!item?.id || forgottenStillIds.value.has(item.id) || removedStillIds.has(item.id)){
selected.value=null
selectionPinned.value=false
return
}
holdEmptyStage=false
const kind=item.kind==='clip'?'clips':item.kind==='track'?'tracks':'stills' const kind=item.kind==='clip'?'clips':item.kind==='track'?'tracks':'stills'
const list=library.value[kind]||[] const list=library.value[kind]||[]
if(!list.some((row:any)=>row.id===item.id)){ if(!list.some((row:any)=>row.id===item.id)){
library.value={...library.value,[kind]:[...list,{...item,folderId:item.folderId||form.folderId}]} const folderId=item.folderId||form.folderId
} const folders=kind==='clips'
? bumpFolderCount(library.value.folders,folderId,'clipCount')
: kind==='stills'
? bumpFolderCount(library.value.folders,folderId,'imageCount')
: library.value.folders
library.value={...library.value,[kind]:[...list,{...item,folderId}],folders}
} }
selected.value=item selected.value=item
selectionPinned.value=!!item selectionPinned.value=true
if(form.mode==='extend' && item?.kind==='clip')chooseClip(item.id) if(form.mode==='extend' && item?.kind==='clip')chooseClip(item.id)
} }
function restore(item:any){Object.assign(form,restoreAll(form,item,xaigen,loraMemory));form.guides=form.guides||[];batchText.value=''} function restore(item:any){Object.assign(form,restoreAll(form,item,xaigen,loraMemory));form.guides=form.guides||[];batchText.value=''}
@@ -1830,17 +1960,42 @@ async function refreshJobs(){
liveCaption.value=nextCaption liveCaption.value=nextCaption
ingestNewOutputs(nextJobs) ingestNewOutputs(nextJobs)
} }
/** Merge freshly completed outputs into the local catalog — never refetch the whole library. */ function bumpFolderCount(folders:any[]|undefined, folderId:string, key:'imageCount'|'clipCount'){
return (folders||[]).map((folder:any)=>{
if(folder?.id!==folderId || typeof folder[key]!=='number') return folder
return {...folder,[key]:folder[key]+1}
})
}
/** Merge a job output only when it is already in the catalog or it finished after this page loaded. */
function ingestNewOutputs(nextJobs:any[]){ function ingestNewOutputs(nextJobs:any[]){
const catalogIds=new Set<string>([
...(library.value.stills||[]).map((s:any)=>s.id),
...(library.value.clips||[]).map((c:any)=>c.id),
...(library.value.tracks||[]).map((t:any)=>t.id)
])
const fresh=newestOutput(nextJobs,seenOutputs,form.folderId) const fresh=newestOutput(nextJobs,seenOutputs,form.folderId)
for(const job of nextJobs){ for(const job of nextJobs){
const live=['waiting','waking','enhancing','submitting','rendering','saving'].includes(job.state)
if(live && job.id) watchedJobIds.add(job.id)
for(const output of job.outputs||[]){ for(const output of job.outputs||[]){
if(seenOutputs.has(output.id) || forgottenStillIds.value.has(output.id)){ if(!output?.id) continue
if(seenOutputs.has(output.id) || forgottenStillIds.value.has(output.id) || removedStillIds.has(output.id)){
seenOutputs.add(output.id)
continue
}
const meta=output.studio2||{}
const savedAt=Number(meta.savedAt||0)
const bornHere=libraryLoadedAt>0 && savedAt>=libraryLoadedAt-2000
const watched=!!(job.id && watchedJobIds.has(job.id))
if(!catalogIds.has(output.id) && !watched && !bornHere){
seenOutputs.add(output.id)
continue
}
if(catalogIds.has(output.id)){
seenOutputs.add(output.id) seenOutputs.add(output.id)
continue continue
} }
seenOutputs.add(output.id) seenOutputs.add(output.id)
const meta=output.studio2||{}
const folderId=job.request?.folderId||form.folderId const folderId=job.request?.folderId||form.folderId
if(output.kind==='clip'){ if(output.kind==='clip'){
if(!(library.value.clips||[]).some((c:any)=>c.id===output.id)){ if(!(library.value.clips||[]).some((c:any)=>c.id===output.id)){
@@ -1848,7 +2003,7 @@ function ingestNewOutputs(nextJobs:any[]){
id:output.id,folderId,createdAt:meta.savedAt||Date.now(), id:output.id,folderId,createdAt:meta.savedAt||Date.now(),
name:meta.name||output.id.slice(0,8),hasThumbnail:true,hasVideo:true, name:meta.name||output.id.slice(0,8),hasThumbnail:true,hasVideo:true,
width:meta.outputWidth,height:meta.outputHeight,studio2:meta width:meta.outputWidth,height:meta.outputHeight,studio2:meta
}]} }],folders:bumpFolderCount(library.value.folders,folderId,'clipCount')}
} }
}else if(output.kind!=='track'){ }else if(output.kind!=='track'){
if(!(library.value.stills||[]).some((s:any)=>s.id===output.id)){ if(!(library.value.stills||[]).some((s:any)=>s.id===output.id)){
@@ -1857,37 +2012,27 @@ function ingestNewOutputs(nextJobs:any[]){
name:meta.name||output.id.slice(0,8),role:'output', name:meta.name||output.id.slice(0,8),role:'output',
width:meta.outputWidth,height:meta.outputHeight, width:meta.outputWidth,height:meta.outputHeight,
prompt:meta.prompt,promptRaw:meta.promptRaw,studio2:meta prompt:meta.prompt,promptRaw:meta.promptRaw,studio2:meta
}]} }],folders:bumpFolderCount(library.value.folders,folderId,'imageCount')}
} }
} }
} }
} }
if(fresh && !forgottenStillIds.value.has(fresh.id)){ const freshLive=fresh?.id && !forgottenStillIds.value.has(fresh.id) && !removedStillIds.has(fresh.id) && family.value.some((a:any)=>a.id===fresh.id)
// Merge into catalog above; only auto-select when the user has not pinned a pick. if(freshLive){
if(!selectionPinned.value){ if(!selectionPinned.value && !holdEmptyStage){
const existingFresh=family.value.find(a=>a.id===fresh.id) const existingFresh=family.value.find((a:any)=>a.id===fresh.id)
if(existingFresh) selected.value=existingFresh if(existingFresh) selected.value=existingFresh
else{
const kind=fresh.kind==='clip'?'clip':'still'
selected.value={...fresh,kind,folderId:form.folderId,studio2:fresh.studio2}
} }
} }else if(selected.value && (forgottenStillIds.value.has(selected.value.id) || removedStillIds.has(selected.value.id) || !family.value.some((a:any)=>a.id===selected.value.id))){
}else if(selected.value && forgottenStillIds.value.has(selected.value.id)){
selected.value=null selected.value=null
selectionPinned.value=false selectionPinned.value=false
}else if(selected.value){ }else if(!selected.value && !holdEmptyStage){
const next=reconcileSelection(selected.value,family.value) const next=reconcileSelection(null,family.value)
if(form.mode!=='music' && next?.kind==='track'){ if(next?.id && !removedStillIds.has(next.id)) selected.value=next
const nonTrack=family.value.find((a:any)=>a.kind!=='track') || null else selected.value=null
if(nonTrack && !selectionPinned.value) selected.value=nonTrack
else if(next?.id===selected.value.id) selected.value=next
}else if(next) selected.value=next
else { selected.value=null; selectionPinned.value=false }
}else{
selected.value=reconcileSelection(null,family.value.filter((a:any)=>!forgottenStillIds.value.has(a.id)))
} }
const newestTrack=(library.value.tracks||[]).filter((t:any)=>t.folderId===form.folderId).sort((a:any,b:any)=>(b.createdAt||0)-(a.createdAt||0))[0] const newestTrack=(library.value.tracks||[]).filter((t:any)=>t.folderId===form.folderId).sort((a:any,b:any)=>(b.createdAt||0)-(a.createdAt||0))[0]
if(form.mode==='music' && newestTrack && !seenOutputs.has(newestTrack.id)){ if(form.mode==='music' && newestTrack && !seenOutputs.has(newestTrack.id) && !removedStillIds.has(newestTrack.id)){
seenOutputs.add(newestTrack.id) seenOutputs.add(newestTrack.id)
selected.value={...newestTrack,kind:'track'} selected.value={...newestTrack,kind:'track'}
} }
@@ -2061,13 +2206,13 @@ async function loadLibraryOnce(deletedIds?: string[]){
qs.set('_',String(Date.now())) qs.set('_',String(Date.now()))
const page=await $fetch<any>(`/api/library?${qs.toString()}`) const page=await $fetch<any>(`/api/library?${qs.toString()}`)
if(gen!==libraryLoadGen) return if(gen!==libraryLoadGen) return
const pageStills=(page.stills||[]).filter((s:any)=>s?.id&&!gone.has(s.id)) const pageStills=(page.stills||[]).filter((s:any)=>s?.id&&!gone.has(s.id)&&!removedStillIds.has(s.id))
const forget=forgottenStillIds.value const forget=forgottenStillIds.value
const keepIds=[ const keepIds=[
...(form.photos||[]).map((p:any)=>p?.stillId).filter(Boolean), ...(form.photos||[]).map((p:any)=>p?.stillId).filter(Boolean),
form.imageAId,form.imageBId,form.identityStillId,form.maskId,form.endStillId, form.imageAId,form.imageBId,form.identityStillId,form.maskId,form.endStillId,
...(form.guides||[]).map((g:any)=>g?.stillId).filter(Boolean) ...(form.guides||[]).map((g:any)=>g?.stillId).filter(Boolean)
].filter((id:string)=>id&&!forget.has(id)&&!gone.has(id)) as string[] ].filter((id:string)=>id&&!forget.has(id)&&!gone.has(id)&&!removedStillIds.has(id)) as string[]
let kept=replacing?[]:(library.value.stills||[]).filter((s:any)=>keepIds.includes(s.id)&&!pageStills.some((p:any)=>p.id===s.id)&&!forget.has(s.id)&&!gone.has(s.id)) let kept=replacing?[]:(library.value.stills||[]).filter((s:any)=>keepIds.includes(s.id)&&!pageStills.some((p:any)=>p.id===s.id)&&!forget.has(s.id)&&!gone.has(s.id))
const stillMissing=keepIds.filter(id=>!pageStills.some((s:any)=>s.id===id)&&!kept.some((s:any)=>s.id===id)) const stillMissing=keepIds.filter(id=>!pageStills.some((s:any)=>s.id===id)&&!kept.some((s:any)=>s.id===id))
let epoch=page.catalogEpoch let epoch=page.catalogEpoch
@@ -2078,16 +2223,16 @@ async function loadLibraryOnce(deletedIds?: string[]){
const full=await $fetch<any>(`/api/library?light=1&_=${Date.now()}`) const full=await $fetch<any>(`/api/library?light=1&_=${Date.now()}`)
if(gen!==libraryLoadGen) return if(gen!==libraryLoadGen) return
if(typeof full?.catalogEpoch==='number') epoch=full.catalogEpoch if(typeof full?.catalogEpoch==='number') epoch=full.catalogEpoch
const recovered=(full.stills||[]).filter((s:any)=>stillMissing.includes(s.id)&&!forget.has(s.id)&&!gone.has(s.id)) const recovered=(full.stills||[]).filter((s:any)=>stillMissing.includes(s.id)&&!forget.has(s.id)&&!gone.has(s.id)&&!removedStillIds.has(s.id))
kept=[...kept,...recovered.filter((s:any)=>!kept.some((k:any)=>k.id===s.id))] kept=[...kept,...recovered.filter((s:any)=>!kept.some((k:any)=>k.id===s.id))]
}catch{if(replacing) kept=[]} }catch{if(replacing) kept=[]}
} }
if(gen!==libraryLoadGen) return if(gen!==libraryLoadGen) return
library.value={ library.value={
folders:page.folders||library.value.folders||[], folders:page.folders||library.value.folders||[],
stills:[...pageStills,...kept].filter((s:any)=>s?.id&&!forget.has(s.id)&&!gone.has(s.id)), stills:[...pageStills,...kept].filter((s:any)=>s?.id&&!forget.has(s.id)&&!gone.has(s.id)&&!removedStillIds.has(s.id)),
clips:(page.clips||[]).filter((c:any)=>c?.id&&!forget.has(c.id)&&!gone.has(c.id)), clips:(page.clips||[]).filter((c:any)=>c?.id&&!forget.has(c.id)&&!gone.has(c.id)&&!removedStillIds.has(c.id)),
tracks:(page.tracks||[]).filter((t:any)=>t?.id&&!forget.has(t.id)&&!gone.has(t.id)), tracks:(page.tracks||[]).filter((t:any)=>t?.id&&!forget.has(t.id)&&!gone.has(t.id)&&!removedStillIds.has(t.id)),
drafts:page.drafts||library.value.drafts||[], drafts:page.drafts||library.value.drafts||[],
loraAliases:page.loraAliases||library.value.loraAliases||{}, loraAliases:page.loraAliases||library.value.loraAliases||{},
loraTriggers:page.loraTriggers||library.value.loraTriggers||{}, loraTriggers:page.loraTriggers||library.value.loraTriggers||{},
@@ -2095,6 +2240,7 @@ async function loadLibraryOnce(deletedIds?: string[]){
catalogEpoch:typeof epoch==='number'?epoch:(library.value.catalogEpoch??0) catalogEpoch:typeof epoch==='number'?epoch:(library.value.catalogEpoch??0)
} }
clearRefsMissingFromLibrary() clearRefsMissingFromLibrary()
libraryLoadedAt=Date.now()
} }
async function fetchHealth(){ async function fetchHealth(){
@@ -2136,6 +2282,7 @@ onMounted(()=>{
// Folder page in background — never blocks Generate / prompt // Folder page in background — never blocks Generate / prompt
void loadLibraryOnce().then(()=>{ void loadLibraryOnce().then(()=>{
restoreBenchDraft() restoreBenchDraft()
restoreDraftSelection()
clearRefsMissingFromLibrary() clearRefsMissingFromLibrary()
if(!form.folderId)form.folderId=library.value.folders[0]?.id||'' if(!form.folderId)form.folderId=library.value.folders[0]?.id||''
loadRevealed(form.folderId) loadRevealed(form.folderId)
@@ -2201,6 +2348,8 @@ const mobileCtx=computed(()=>({
clipThumbUrl, clipThumbUrl,
clipVideoUrl, clipVideoUrl,
showSelectedStill:showSelectedStill.value, showSelectedStill:showSelectedStill.value,
selectedClipLive:selectedClipLive.value,
selectedTrackLive:selectedTrackLive.value,
libraryOpen:libraryOpen.value, libraryOpen:libraryOpen.value,
eyeOpen:eyeOpen.value, eyeOpen:eyeOpen.value,
hideInputs:hideInputs.value, hideInputs:hideInputs.value,
+34 -4
View File
@@ -120,7 +120,7 @@
</div> </div>
</article> </article>
</div> </div>
<aside v-if="detailAsset" class="lib-modal-detail"> <aside v-if="entries.length && detailAsset" class="lib-modal-detail">
<p class="lib-modal-detail-name">{{ detailLabel }}</p> <p class="lib-modal-detail-name">{{ detailLabel }}</p>
<div v-if="detailAsset.kind !== 'track'" class="lib-modal-actions"> <div v-if="detailAsset.kind !== 'track'" class="lib-modal-actions">
<button type="button" @click="$emit('use-image', detailAsset)">Use image</button> <button type="button" @click="$emit('use-image', detailAsset)">Use image</button>
@@ -228,19 +228,43 @@ const entries = computed(() => buildLibraryEntries({
sort: 'date-desc' sort: 'date-desc'
})) }))
const dismissedId = ref('')
function entryHasId(entry: LibraryEntry, id: string) {
if (!id) return false
if (entry.kind === 'clip' && entry.group) {
return entry.group.head.id === id || entry.group.parts.some(part => part.id === id)
}
if (entry.kind === 'track' && entry.track) return entry.track.id === id
if (entry.stillGroup) {
return entry.stillGroup.head.id === id || entry.stillGroup.parts.some(part => part.id === id)
}
return false
}
const focusedKey = computed(() => { const focusedKey = computed(() => {
const id = props.selected?.id const id = props.selected?.id
if (!id) return '' if (!id || id === dismissedId.value) return ''
const hit = entries.value.find(entry => assetFromEntry(entry)?.id === id) const hit = entries.value.find(entry => entryHasId(entry, id))
return hit?.key || '' return hit?.key || ''
}) })
const detailAsset = computed(() => { const detailAsset = computed(() => {
if (props.selected) return props.selected if (!entries.value.length) return null
const id = String(props.selected?.id || '')
if (id && id === dismissedId.value) return null
if (id) {
const hit = entries.value.find(entry => entryHasId(entry, id))
return hit ? assetFromEntry(hit) : null
}
const first = entries.value[0] const first = entries.value[0]
return first ? assetFromEntry(first) : null return first ? assetFromEntry(first) : null
}) })
watch(() => props.selected?.id, (id) => {
if (id && id !== dismissedId.value) dismissedId.value = ''
})
const detailLabel = computed(() => assetLabel(detailAsset.value)) const detailLabel = computed(() => assetLabel(detailAsset.value))
const detailRows = computed(() => { const detailRows = computed(() => {
@@ -297,6 +321,12 @@ function useAndClose() {
function onDeleteClick() { function onDeleteClick() {
const asset = detailAsset.value const asset = detailAsset.value
if (!asset?.id) return if (!asset?.id) return
const id = String(asset.id)
dismissedId.value = id
stills.value = stills.value.filter(item => item.id !== id)
clips.value = clips.value.filter(item => item.id !== id)
tracks.value = tracks.value.filter(item => item.id !== id)
emit('select', null)
emit('delete', asset) emit('delete', asset)
} }
+7 -7
View File
@@ -75,7 +75,7 @@
</button> </button>
<div class="m-stage-chrome-end"> <div class="m-stage-chrome-end">
<button <button
v-if="ctx.selected && ctx.selected.kind!=='track'" v-if="ctx.showSelectedStill || ctx.selectedClipLive"
type="button" type="button"
class="m-icon-btn" class="m-icon-btn"
aria-label="More" aria-label="More"
@@ -83,7 +83,7 @@
@click.stop="toggleSheet('actions')" @click.stop="toggleSheet('actions')"
>•••</button> >•••</button>
<button <button
v-if="ctx.selected" v-if="ctx.showSelectedStill || ctx.selectedClipLive || ctx.selectedTrackLive"
type="button" type="button"
class="m-icon-btn m-eye" class="m-icon-btn m-eye"
:aria-label="ctx.eyeOpen ? 'Hide output' : 'Show output'" :aria-label="ctx.eyeOpen ? 'Hide output' : 'Show output'"
@@ -108,16 +108,16 @@
@click.stop="ctx.stepFamily(1)" @click.stop="ctx.stepFamily(1)"
>›</button> >›</button>
<p <p
v-show="ctx.selected && ctx.isHidden(ctx.selected)" v-show="(ctx.showSelectedStill || ctx.selectedClipLive || ctx.selectedTrackLive) && ctx.isHidden(ctx.selected)"
class="m-hidden-note" class="m-hidden-note"
>{{ ctx.selected?.kind==='track' ? 'Track hidden' : 'Output hidden' }}</p> >{{ ctx.selected?.kind==='track' ? 'Track hidden' : 'Output hidden' }}</p>
<template v-if="ctx.selected?.kind==='track'"> <template v-if="ctx.selectedTrackLive">
<div v-show="!ctx.isHidden(ctx.selected)" class="m-audio"> <div v-show="!ctx.isHidden(ctx.selected)" class="m-audio">
<AudioPlayer :src="`/api/library/tracks/${ctx.selected.id}/audio`" :download-name="`${ctx.selected.name || 'track'}.${ctx.selected.ext || 'wav'}`" :label="ctx.selected.name || 'Track'" /> <AudioPlayer :src="`/api/library/tracks/${ctx.selected.id}/audio`" :download-name="`${ctx.selected.name || 'track'}.${ctx.selected.ext || 'wav'}`" :label="ctx.selected.name || 'Track'" />
</div> </div>
</template> </template>
<video <video
v-else-if="ctx.selected?.kind==='clip'" v-else-if="ctx.selectedClipLive"
v-show="!ctx.isHidden(ctx.selected)" v-show="!ctx.isHidden(ctx.selected)"
:key="ctx.selected.id" :key="ctx.selected.id"
:src="ctx.clipVideoUrl(ctx.selected.id)" :src="ctx.clipVideoUrl(ctx.selected.id)"
@@ -125,7 +125,7 @@
playsinline playsinline
/> />
<img <img
v-else-if="ctx.selected && ctx.showSelectedStill" v-else-if="ctx.showSelectedStill"
v-show="!ctx.isHidden(ctx.selected)" v-show="!ctx.isHidden(ctx.selected)"
:key="ctx.selected.id+'-'+(ctx.stagePreviewNonce||0)" :key="ctx.selected.id+'-'+(ctx.stagePreviewNonce||0)"
class="m-stage-still" class="m-stage-still"
@@ -169,7 +169,7 @@
<!-- Sheets --> <!-- Sheets -->
<div v-if="sheet" class="m-sheet-backdrop" @click="sheet=''" /> <div v-if="sheet" class="m-sheet-backdrop" @click="sheet=''" />
<aside v-if="sheet==='actions'" class="m-sheet m-sheet-actions" role="dialog" aria-label="Still actions"> <aside v-if="sheet==='actions' && (ctx.showSelectedStill || ctx.selectedClipLive)" class="m-sheet m-sheet-actions" role="dialog" aria-label="Still actions">
<button type="button" class="m-handle" aria-label="Close" @click="sheet=''" /> <button type="button" class="m-handle" aria-label="Close" @click="sheet=''" />
<div class="m-sheet-head"><strong>Actions</strong><button type="button" @click="sheet=''">Done</button></div> <div class="m-sheet-head"><strong>Actions</strong><button type="button" @click="sheet=''">Done</button></div>
<div class="m-sheet-body m-actions-list"> <div class="m-sheet-body m-actions-list">