You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2 lines
10 KiB
2 lines
10 KiB
import{j as t}from"./markdown-vendor-BZI_VWzW.js";import{u as je,r as e}from"./data-vendor-BOGugMqL.js";import{a as ve,g as Le}from"./react-vendor-wlKWdfEb.js";import{bk as Me,a as J,bl as me,f as Oe,R as Ae}from"./index-CpDY2xe_.js";import{c as we}from"./imageDragTransfer-vBkaf40H.js";import{D as Ee}from"./arco-vendor-CAnKnMnO.js";function F(m){const o=m;return Array.isArray(o?.data?.list)?o.data.list:[]}const M="keyword",ke=350,Pe=new URL("/assets/ic_search-DREI2NzL.png",import.meta.url).href,Fe=new URL("/assets/ic_plus-DsKUbTM-.png",import.meta.url).href,Te=new URL("/assets/ic_arrow_right_gray-DM6GPP4g.png",import.meta.url).href,_={OFFICIAL:"official",COMMUNITY:"community"},S=30,Ue="160px";function De(...m){const o=new Set;return m.forEach(i=>{i.forEach(f=>{const d=String(f??"").trim();d&&o.add(d)})}),Array.from(o)}function ye(m,o){const i=new Set;for(const g of m){const s=g?.id;s==null||s===""||i.add(String(s))}const f=[];let d=0;for(const g of o){const s=g?.id;if(s==null||s===""){f.push(g),d+=1;continue}const y=String(s);i.has(y)||(i.add(y),f.push(g),d+=1)}return d===0?{merged:m,appendedCount:0}:{merged:[...m,...f],appendedCount:d}}const pe=e.memo(function({item:o,isButton:i=!1,onOpen:f,onHover:d,onDragStart:g}){const s=e.useCallback(()=>{d(o?.threeViewImage)},[o,d]),y=e.useCallback(O=>{g(O,o?.threeViewImage)},[o,g]),j=e.useCallback(()=>{f(o)},[o,f]);return i?t.jsxs("button",{type:"button",className:"character_library_sections__card",draggable:!0,onMouseEnter:s,onDragStart:y,onClick:j,children:[t.jsx("img",{className:"character_library_sections__card_image",src:o.avatar,alt:"",draggable:!1}),t.jsx("span",{className:"character_library_sections__card_tag",children:o.title})]}):t.jsxs("div",{className:"character_library_sections__card",draggable:!0,onMouseEnter:s,onDragStart:y,onClick:j,children:[t.jsx("img",{className:"character_library_sections__card_image",src:o.avatar,alt:"",draggable:!1}),t.jsx("span",{className:"character_library_sections__card_tag",children:o.title})]})});function He({showDiyEntry:m=!0}){const o=ve(),{t:i}=je(),[f,d]=Le(),g=e.useRef(null),s=f.get(M)?.trim()??"",[y,j]=e.useState(()=>f.get(M)??""),O=e.useDeferredValue(y),[p,T]=e.useState([]),[b,v]=e.useState([]),[u,X]=e.useState(_.OFFICIAL),[U,ee]=e.useState([]),[h,re]=e.useState(null),[ae,L]=e.useState(!1),[Ye,te]=e.useState(1),[D,N]=e.useState(!0),[H,se]=e.useState(!1),[A,Y]=e.useState(!1),[Be,ce]=e.useState(1),[B,R]=e.useState(!0),[z,ne]=e.useState(!1),[w,K]=e.useState(!1),[V,E]=e.useState([]),x=e.useMemo(()=>we(),[]),ie=e.useRef(null),C=e.useRef(""),I=e.useRef(""),q=e.useRef(1),G=e.useRef(1),oe=e.useRef(p),le=e.useRef(b),k=e.useRef(!1),P=e.useRef(!1),ue=e.useRef(()=>{});e.useEffect(()=>()=>{x.dispose()},[x]),e.useEffect(()=>{oe.current=p},[p]),e.useEffect(()=>{le.current=b},[b]),e.useEffect(()=>{Me().then(r=>{const a=r.data,c=Array.isArray(a)?a:[];c.sort((l,n)=>(l.sortNum??0)-(n.sortNum??0)),ee(c)}).catch(()=>{ee([])})},[]),e.useEffect(()=>{j(f.get(M)??"")},[f]),e.useEffect(()=>{const r=window.setTimeout(()=>{const a=O.trim();a!==s&&d(c=>{const l=new URLSearchParams(c);return a?l.set(M,a):l.delete(M),l},{replace:!0})},ke);return()=>window.clearTimeout(r)},[O,s,d]),e.useEffect(()=>{const r={uploadCharacter:!0,page:1,pageSize:30};s&&(r.keyword=s);let a=!1;return J(r).then(c=>{a||E(c.data.list)}).catch(()=>{a||E([])}),()=>{a=!0}},[s]),e.useEffect(()=>{if(u!==_.OFFICIAL)return;const r=`${String(h??"all")}|${s}`;C.current=r,te(1),q.current=1,N(!0),se(!0);const a={type:1,page:1,pageSize:S};h!=null&&(a.categoryId=h),s&&(a.keyword=s);let c=!1;return J(a).then(l=>{if(c||C.current!==r)return;const n=F(l);T(n),N(n.length>=S)}).catch(()=>{c||C.current===r&&(T([]),N(!1))}).finally(()=>{c||C.current===r&&(se(!1),Y(!1),k.current=!1)}),()=>{c=!0}},[u,h,s]),e.useEffect(()=>{if(u!==_.COMMUNITY)return;const r=`${String(s??"")}`;I.current=r,ce(1),G.current=1,R(!0),ne(!0);const a={page:1,pageSize:S};s&&(a.keyword=s);let c=!1;return me(a).then(l=>{if(c||I.current!==r)return;const n=F(l);v(n),R(n.length>=S)}).catch(()=>{c||I.current===r&&(v([]),R(!1))}).finally(()=>{c||I.current===r&&(ne(!1),K(!1),P.current=!1)}),()=>{c=!0}},[u,s]);const _e=e.useCallback(async()=>{if(!D||H||A||k.current)return;k.current=!0,Y(!0);const r=C.current,a=q.current+1;try{const c={type:1,page:a,pageSize:S};h!=null&&(c.categoryId=h),s&&(c.keyword=s);const l=await J(c);if(C.current!==r)return;const n=F(l),{appendedCount:W,merged:Z}=ye(oe.current,n);T(Z),te(a),q.current=a,N(W===0?!1:n.length>=S)}catch{if(C.current!==r)return;N(!1)}finally{k.current=!1,C.current===r&&Y(!1)}},[D,H,A,h,s]),fe=e.useCallback(async()=>{if(!B||z||w||P.current)return;P.current=!0,K(!0);const r=I.current,a=G.current+1;try{const c={page:a,pageSize:S};s&&(c.keyword=s);const l=await me(c);if(I.current!==r)return;const n=F(l),{appendedCount:W,merged:Z}=ye(le.current,n);v(Z),ce(a),G.current=a,R(W===0?!1:n.length>=S)}catch{if(I.current!==r)return;R(!1)}finally{P.current=!1,I.current===r&&K(!1)}},[B,z,w,s]);e.useEffect(()=>{ue.current=()=>{u===_.OFFICIAL?_e():fe()}},[u,_e,fe]);const Q=u===_.OFFICIAL?D:B,$=u===_.OFFICIAL?H||A:z||w;e.useEffect(()=>{const r=ie.current;if(!r||!Q||$)return;const a=new IntersectionObserver(c=>{c[0]?.isIntersecting&&ue.current()},{root:null,rootMargin:Ue,threshold:0});return a.observe(r),()=>a.disconnect()},[Q,$,p.length,b.length]),e.useEffect(()=>{const r=De(V.map(a=>a?.threeViewImage),p.map(a=>String(a?.threeViewImage??"")),b.map(a=>a?.threeViewImage));r.length!==0&&x.warmupPreviewImages(r)},[b,x,V,p]);const be=e.useMemo(()=>h==null?i("pages.characters.category_all"):U.find(a=>a.id===h)?.name??i("pages.characters.category_label"),[U,h,i]),de=e.useCallback(r=>{Oe({id:r.id,onDeleted:a=>{const c=String(a);E(l=>l.filter(n=>String(n?.id??"")!==c)),v(l=>l.filter(n=>String(n?.id??"")!==c))},onUpdated:a=>{const c=String(a.id),l=n=>String(n?.id??"")!==c?n:{...n,title:a.title,description:a.description,isPublic:a.isPublic,avatar:a.avatar||n?.avatar};E(n=>n.map(l)),v(n=>n.map(l))}})},[]),Ce=e.useCallback(()=>{o(Ae.CHARACTERS_CREATE)},[o]),Ie=e.useMemo(()=>u===_.OFFICIAL?p:b,[u,b,p]),Se=e.useCallback(()=>{X(_.OFFICIAL),L(!1)},[]),xe=e.useCallback(()=>{X(_.COMMUNITY),L(!1)},[]),Ne=e.useCallback(()=>{re(null),L(!1)},[]),Re=e.useCallback(r=>{re(r),L(!1)},[]),he=(r,a)=>{x.startImageDrag({evt:r,dragUrl:a,previewUrl:a})},ge=e.useCallback(r=>{x.ensurePreviewImage(r)},[x]);return t.jsxs("div",{className:"character_library_sections",children:[t.jsxs("section",{className:"character_library_sections__section","aria-labelledby":"character-library-my-heading",children:[t.jsxs("div",{className:"character_library_sections__section_head",children:[t.jsx("div",{className:"character_library_sections__title_wrap",children:t.jsx("h2",{id:"character-library-my-heading",className:"character_library_sections__section_title",children:i("pages.characters.my_section")})}),t.jsxs("label",{className:"character_library_sections__search",children:[t.jsx("img",{className:"character_library_sections__search_icon",src:Pe,alt:""}),t.jsx("input",{className:"character_library_sections__search_input",type:"search",placeholder:i("pages.characters.search_placeholder"),name:"keyword",value:y,onChange:r=>{j(r.target.value)},"aria-label":i("pages.characters.search_aria")})]})]}),t.jsxs("div",{className:"character_library_sections__grid",children:[m?t.jsxs("button",{type:"button",className:"character_library_sections__card character_library_sections__diy_card",onClick:()=>{Ce()},"aria-label":i("pages.characters.diy_aria"),children:[t.jsx("img",{className:"character_library_sections__diy_icon",src:Fe,alt:""}),t.jsx("p",{className:"character_library_sections__diy_label",children:i("pages.characters.diy_label")})]}):null,V.map((r,a)=>t.jsx(pe,{item:r,isButton:!0,onHover:ge,onDragStart:he,onOpen:de},String(r.id??a)))]})]}),t.jsxs("section",{className:"character_library_sections__section","aria-label":i("pages.characters.official_section"),children:[t.jsxs("div",{className:"character_library_sections__section_head",children:[t.jsx("div",{className:"character_library_sections__title_wrap",children:t.jsxs("div",{className:"character_library_sections__tabs",role:"tablist","aria-label":i("pages.characters.official_section"),children:[t.jsx("button",{type:"button",role:"tab","aria-selected":u===_.OFFICIAL,className:["character_library_sections__section_tab",u===_.OFFICIAL?"character_library_sections__section_tab_active":""].filter(Boolean).join(" "),onClick:Se,children:i("pages.characters.official_section")}),t.jsx("button",{type:"button",role:"tab","aria-selected":u===_.COMMUNITY,className:["character_library_sections__section_tab",u===_.COMMUNITY?"character_library_sections__section_tab_active":""].filter(Boolean).join(" "),onClick:xe,children:i("pages.characters.community_section")})]})}),u===_.OFFICIAL?t.jsx("div",{ref:g,children:t.jsx(Ee,{trigger:"click",position:"br",popupVisible:ae,onVisibleChange:L,triggerProps:{style:{zIndex:2e3}},getPopupContainer:()=>g.current??document.body,droplist:t.jsxs("div",{className:"character_library_sections__category_dropdown",role:"menu","aria-label":i("pages.characters.category_aria"),children:[t.jsx("button",{type:"button",className:["character_library_sections__category_menu_item",h===null?"character_library_sections__category_menu_item_active":""].filter(Boolean).join(" "),role:"menuitem",onClick:Ne,children:i("pages.characters.category_all")}),U.map(r=>t.jsx("button",{type:"button",className:["character_library_sections__category_menu_item",h===r.id?"character_library_sections__category_menu_item_active":""].filter(Boolean).join(" "),role:"menuitem",onClick:()=>{Re(r.id)},children:r.name},r.id))]}),children:t.jsxs("button",{type:"button",className:"character_library_sections__category","aria-label":i("pages.characters.category_aria"),"aria-expanded":ae,"aria-haspopup":"menu",children:[t.jsx("span",{children:be}),t.jsx("img",{className:"character_library_sections__category_icon",src:Te,alt:""})]})})}):null]}),t.jsx("div",{className:"character_library_sections__grid",children:Ie.map((r,a)=>t.jsx(pe,{item:r,onHover:ge,onDragStart:he,onOpen:de},String(r.id??a)))}),u===_.OFFICIAL&&A?t.jsx("p",{className:"character_library_sections__loading_more",children:i("common.loading")}):null,u===_.COMMUNITY&&w?t.jsx("p",{className:"character_library_sections__loading_more",children:i("common.loading")}):null,Q&&!$?t.jsx("div",{ref:ie,className:"character_library_sections__sentinel","aria-hidden":!0}):null]})]})}function $e(){return t.jsx("div",{className:"charactersPage",children:t.jsx(He,{})})}export{He as CharacterLibrarySections,$e as default};
|
|
//# sourceMappingURL=index-BIlzV-Wd.js.map
|
|
|