2 lines
2.6 KiB
JavaScript
2 lines
2.6 KiB
JavaScript
import{bd as F,v as g,b$ as R,c0 as x,aj as A,ag as q,bN as D,b3 as j,c1 as z}from"./index-423bec18.js";import{u as G,b as L,f as O,c as Q,d as H,e as T,h as U}from"./FileItem-08fb0ce5.js";let W=0;const $=()=>++W,B=(o,c,{dataUpdateStrategy:l="replace"}={})=>{const n=F([""]),u=g(!1),t=g(),a=g(!1);let f=g(-1);const v=new Set,w=e=>{var s;l==="replace"?t.value=e:l==="merge"&&(A((Array.isArray(t.value)||typeof t.value>"u")&&Array.isArray(e),"数据更新策略为合并时仅可用于值为数组的情况"),t.value=[...(s=t==null?void 0:t.value)!==null&&s!==void 0?s:[],...e])},d=e=>x(void 0,void 0,void 0,function*(){if(a.value||u.value&&typeof e>"u")return!1;a.value=!0;const s=$();f.value=s;try{let r;if(typeof e=="number"){if(r=n[e],typeof r!="string")return!1}else r=n[n.length-1];const m=yield o(r);if(v.has(s))return v.delete(s),!1;w(c(m));const i=m.cursor;if((e===n.length-1||typeof e!="number")&&(u.value=!i.has_next,i.has_next)){const p=i.next_cursor||i.next;A(typeof p=="string"),n.push(p)}}finally{f.value===s&&(a.value=!1)}return!0}),h=()=>{v.add(f.value),a.value=!1},S=(e=!1)=>x(void 0,void 0,void 0,function*(){const{refetch:s,force:r}=typeof e=="object"?e:{refetch:e};r&&h(),A(!a.value),n.splice(0,n.length,""),a.value=!1,t.value=void 0,u.value=!1,s&&(yield d())}),I=()=>({next:()=>x(void 0,void 0,void 0,function*(){if(a.value)throw new Error("不允许同时迭代");return{done:!(yield d()),value:t.value}})});return R({abort:h,load:u,next:d,res:t,loading:a,cursorStack:n,reset:S,[Symbol.asyncIterator]:I,iter:{[Symbol.asyncIterator]:I}})},Y=o=>F(B(o,c=>c.files,{dataUpdateStrategy:"merge"})),Z=o=>{const c=F(new Set),l=q(()=>(o.res??[]).filter(y=>!c.has(y.fullpath))),n=D(),{stackViewEl:u,multiSelectedIdxs:t,stack:a,scroller:f}=G({images:l}).toRefs(),{itemSize:v,gridItems:w,cellWidth:d,onScroll:h}=L({fetchNext:()=>o.next()}),{showMenuIdx:S}=O(),{onFileDragStart:I,onFileDragEnd:e}=Q(),{showGenInfo:s,imageGenInfo:r,q:m,onContextMenuClick:i,onFileItemClick:p}=H({openNext:j}),{previewIdx:C,previewing:_,onPreviewVisibleChange:E,previewImgMove:M,canPreview:J}=T(),N=async(y,b,P)=>{a.value=[{curr:"",files:l.value}],await i(y,b,P)};U("removeFiles",async({paths:y})=>{y.forEach(b=>c.add(b))});const k=()=>{z(l.value)};return{images:l,scroller:f,queue:n,iter:o,onContextMenuClickU:N,stackViewEl:u,previewIdx:C,previewing:_,onPreviewVisibleChange:E,previewImgMove:M,canPreview:J,itemSize:v,gridItems:w,showGenInfo:s,imageGenInfo:r,q:m,onContextMenuClick:i,onFileItemClick:p,showMenuIdx:S,multiSelectedIdxs:t,onFileDragStart:I,onFileDragEnd:e,cellWidth:d,onScroll:h,saveLoadedFileAsJson:k,saveAllFileAsJson:async()=>{for(;!o.load;)await o.next();k()}}};export{Y as c,Z as u};
|