PageSourceSearch

https://shiwhen.com/assets/index-BbcktIYk.js

js shiwhen.com collected 2026-10-02 01:43:31 UTC 28,957 bytes, 1 lines download raw bytes

1import{j as e,U as W,V as re,W as oe,X as Se,Y as ke,Z as _,r as s,_ as Ee,$ as Ae,a0 as U,a1 as R,a2 as H,a3 as ae,a4 as Fe,a5 as Le,a6 as Te,a7 as Ie,a8 as fe,a9 as Oe,aa as Pe,ab as Re,ac as _e,ad as ze,ae as Me,af as Be,ag as $e,ah as Ke,B as J,ai as He,L as We,aj as Ue,ak as qe,al as Qe,am as se,an as Ve,ao as Ye,ap as Xe,aq as Je,ar as Ze,as as et,at as tt,au as nt,av as rt,aw as ot,ax as at,ay as st,az as it,aA as ct,aB as lt,aC as ut,aD as ie,aE as dt,aF as mt,aG as pt,aH as B,aI as q,aJ as ft,aK as ht,aL as xt,aM as ce,aN as gt,aO as bt,aP as vt,aQ as yt,aR as wt,aS as Ct,u as jt,aT as Gt,aU as Dt,aV as Nt,aW as St}from"./index-BR60WJvU.js";import{aX as xn,aY as gn}from"./index-BR60WJvU.js";import{P as kt,D as Et,a as At,d as Ft,p as Lt,F as ne,C as le,c as Z,b as ue,e as Tt,f as It,g as Ot}from"./PexelsCover-DfbLHtrz.js";import"./with-selector-C5BgAbRA.js";function Pt(t){const n=new Date(t);return Number.isNaN(n.getTime())?"刚刚更新":new Intl.DateTimeFormat("zh-CN",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(n)}function he({document:t,showReferenceCount:n=!0}){var o;const r=t.title||"未命名文稿";return e.jsxs("article",{className:"document-card group/card min-w-0","data-card-kind":"text","data-document-id":t.id,"data-shared-shell":"source","data-tour":"document-card",children:[e.jsxs("div",{className:"relative",children:[e.jsx(W,{className:"block aspect-[4/3] overflow-hidden rounded-card bg-surface text-ink no-underline outline-none focus-visible:ring-2 focus-visible:ring-ink/35",to:`/documents/${t.id}`,"aria-label":`编辑文稿:${r}`,"data-overlay-link":!0,children:e.jsx(kt,{cover:t,alt:r,className:oe,imageClassName:re,fallback:e.jsx(Et,{alt:`${r}的默认封面`,className:oe,imageClassName:re})})}),e.jsx(At,{cover:t})]}),e.jsxs(W,{className:"mt-2.5 block text-ink no-underline outline-none focus-visible:ring-2 focus-visible:ring-ink/35",to:`/documents/${t.id}`,"aria-hidden":"true",tabIndex:-1,"data-overlay-link":!0,children:[e.jsx("h2",{className:Se("min-w-0 max-w-full m-0 truncate font-display text-body-sm leading-card font-normal tracking-card",ke),title:r,children:r}),e.jsxs("footer",{className:"mt-1.5 flex items-center justify-between gap-3 font-utility text-caption text-muted",children:[e.jsx("span",{children:Pt(t.updated_at)}),n&&e.jsxs("span",{children:[((o=t.references)==null?void 0:o.length)||0," 处引用"]})]})]})]})}function Rt({sharedProps:t,grouping:n}){return e.jsxs(e.Fragment,{children:[n.orderedGroupKeys.map((r,o)=>{var a;const l=r===_?n.grouped.ungrouped:((a=n.grouped.sections.find(({group:f})=>String(f.id)===r))==null?void 0:a.items)||[];if(r===_&&!l.length&&!n.categories.length)return null;const i=n.grouped.sections.find(({group:f})=>String(f.id)===r);return s.createElement(Ee,{...t,key:r,group:(i==null?void 0:i.group)||null,sectionKey:r,items:l,index:o,collapsed:!!n.collapsedGroups[r],onCollapsedChange:f=>n.setGroupCollapsed(r,f)})}),n.creatingGroup&&e.jsx(Ae,{name:n.newGroupName,busy:n.groupEditorBusy,onNameChange:n.setNewGroupName,onSave:()=>void n.saveNewGroup(),onCancel:()=>n.setCreatingGroup(!1)})]})}function Q(t){return Ft(Lt(t.body)).replace(/\s+/g," ").trim()||"还没有写下正文"}function _t({focusedDocument:t,documentSourceRect:n,documentMenuPlacement:r,onFinishCardAction:o,onOpenDocumentCover:l,onDocumentDelete:i,drag:a}){const f=(t==null?void 0:t.title)||"未命名文稿";return e.jsxs(e.Fragment,{children:[e.jsx(U,{children:t&&n&&!a&&e.jsxs(e.Fragment,{children:[e.jsx(R.button,{type:"button",className:"fixed inset-0 z-[55] cursor-default border-0 bg-canvas/45 p-0 backdrop-blur-[14px]","data-document-action-overlay":!0,"aria-label":"退出文稿操作",initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},transition:H.micro,onClick:o}),e.jsx(R.div,{className:"pointer-events-none fixed z-[70] drop-shadow-xl","data-document-focus-preview":!0,style:{left:n.left,top:n.top,width:n.width},"aria-hidden":"true",initial:{opacity:0,scale:.96},animate:{opacity:1,scale:1.01},exit:{opacity:0,scale:.96},transition:ae,children:e.jsx(he,{document:t,summary:Q(t),showReferenceCount:!1})}),r&&e.jsxs(Fe,{placement:r,widthClass:"w-33",menuKey:"document",children:[e.jsx(W,{to:`/documents/${t.id}`,className:"flex h-full min-w-0 flex-1 items-center justify-center text-ink outline-none transition-colors hover:bg-ink/5 focus-visible:bg-ink/5","data-document-edit-action":!0,"aria-label":`编辑文稿${f}`,onClick:o,children:e.jsx(Le,{size:19,strokeWidth:1.65})}),e.jsx("span",{className:"h-7 w-px shrink-0 bg-line","aria-hidden":"true"}),e.jsx("button",{type:"button",className:"flex h-full min-w-0 flex-1 cursor-pointer items-center justify-center border-0 bg-transparent text-ink outline-none transition-colors hover:bg-ink/5 focus-visible:bg-ink/5","data-document-cover-action":!0,"aria-label":`设置文稿封面:${f}`,onClick:()=>{l(t),o()},children:e.jsx(Te,{size:19,strokeWidth:1.65})}),e.jsx("span",{className:"h-7 w-px shrink-0 bg-line","aria-hidden":"true"}),e.jsx("button",{type:"button",className:"flex h-full min-w-0 flex-1 cursor-pointer items-center justify-center border-0 bg-transparent text-ink outline-none transition-colors hover:bg-danger-soft hover:text-danger-ink focus-visible:bg-danger-soft focus-visible:text-danger-ink","data-document-delete-action":!0,"aria-label":`删除文稿${f}`,onClick:()=>{i(t),o()},children:e.jsx(Ie,{size:20,strokeWidth:1.65})})]})]})}),e.jsx(U,{children:a&&a.moving&&e.jsx("div",{className:"pointer-events-none fixed z-[70] w-28","data-document-drag-preview":!0,style:{left:a.point.x,top:a.point.y},"aria-hidden":"true",children:e.jsxs(R.div,{className:"overflow-hidden rounded-control bg-surface p-1.5 shadow-card ring-1 ring-ink/10",initial:{opacity:0,scale:.72,rotate:-2},animate:{opacity:.96,scale:1,rotate:0},exit:{opacity:0,scale:.78},transition:ae,children:[e.jsx("div",{className:"relative flex aspect-[4/3] items-center justify-center overflow-hidden rounded-card bg-canvas",children:e.jsx("span",{className:"flex size-8 items-center justify-center rounded-full bg-surface text-muted",children:e.jsx(fe,{size:15,strokeWidth:1.35})})}),e.jsx("strong",{className:"min-w-0 max-w-full [overflow-wrap:anywhere] mt-1.5 line-clamp-2 px-0.5 pb-0.5 font-display text-meta leading-tight font-normal text-ink",title:a.document.title||"未命名文稿",children:a.document.title||"未命名文稿"})]})})})]})}function zt(t){const l=t.bottom+10+52<=window.innerHeight-16,i=t.top-10-52>=16,a=window.innerHeight-16-t.bottom,f=t.top-16,u=i||!l&&f>=a?"top":"bottom";return{side:u,left:t.left+Math.min(t.width/2,110),top:u==="bottom"?Math.min(window.innerHeight-16-52,t.bottom+10):Math.max(16,t.top-10-52)}}function Mt({documents:t,categories:n,focusedGroupId:r,groupSourceRect:o,editingFocusedGroup:l,groupEditName:i,onGroupEditNameChange:a,onSaveFocusedGroup:f,onFinishGroupAction:u,onEditFocusedGroup:y,onOpenGroupDelete:h,draggedGroupId:v,groupSortTarget:b,groupDragPoint:D,groupTitleForKey:d,overlayClickSuppressed:x}){const m=r!==null&&n.find(k=>String(k.id)===r)||null,p=m?t.filter(k=>((m==null?void 0:m.document_ids)||[]).includes(k.id)).length:0,C=o&&m?zt(o):null,[j,L]=s.useState(null);return s.useEffect(()=>{if(!b||!v){L(null);return}const k=document.querySelector(`[data-group-sort-id="${b.id}"] .group-section-heading`);if(!k){L(null);return}const G=k.getBoundingClientRect();L({left:G.left,top:b.edge==="before"?G.top:G.bottom,width:G.width})},[v,b]),e.jsxs(e.Fragment,{children:[e.jsx(U,{children:r!==null&&o&&v===null&&e.jsxs(e.Fragment,{children:[e.jsx(R.button,{type:"button",className:`fixed inset-0 z-[55] cursor-default border-0 bg-canvas/45 p-0 backdrop-blur-[14px] ${x()?"pointer-events-none":""}`,"data-group-action-overlay":!0,"aria-label":"退出分组操作",initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0,pointerEvents:"none"},transition:H.micro,onClick:()=>{x()||u()}}),e.jsxs(R.div,{className:`fixed z-[70] flex min-h-11 items-center gap-1.5 px-1 ${l?"pointer-events-auto":"pointer-events-none"}`,"data-group-focus-preview":!0,style:{left:o.left,top:o.top,width:o.width,height:o.height},"aria-hidden":l?void 0:!0,initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:H.micro,children:[p>0?e.jsx("span",{className:"flex w-5 shrink-0 items-center justify-center text-muted","aria-hidden":"true",children:e.jsx(Oe,{size:14})}):e.jsx("span",{className:"w-5 shrink-0","aria-hidden":"true"}),l&&m?e.jsx(Pe,{name:i,onNameChange:a,onSave:f,onCancel:u}):e.jsx(Re,{title:d(r),count:p})]}),m&&C&&!l&&e.jsx(_e,{placement:C,onRename:y,onDelete:h})]})}),e.jsx(U,{children:v!==null&&D&&e.jsx(ze,{marker:"group",point:D,label:d(v)})}),j&&b&&v&&e.jsx("svg",{className:"pointer-events-none fixed z-50 h-1 overflow-visible text-ink/50","data-group-sort-indicator":!0,"data-target-id":b.id,"data-target-edge":b.edge,style:{left:j.left,top:j.top,width:j.width,transform:"translateY(-50%)"},viewBox:"0 0 100 4",preserveAspectRatio:"none","aria-hidden":"true",children:e.jsx("line",{x1:"0",y1:"2",x2:"100",y2:"2",stroke:"currentColor",strokeWidth:"1",strokeDasharray:"5 4",vectorEffect:"non-scaling-stroke"})})]})}function Bt({hasDocuments:t,hasGroups:n,loading:r,error:o,searchOpen:l,creating:i,onCreateDocument:a}){return e.jsxs(e.Fragment,{children:[o&&e.jsx(Me,{variant:"destructive",className:"documents-error mt-4",children:e.jsx(Be,{children:o})}),r?e.jsx($e,{kind:"documents"}):!l&&!t&&!n&&!i?e.jsx(Ke,{variant:"page","data-layout":"empty-document-library",icon:e.jsx(fe,{"aria-hidden":"true"}),title:"写下第一篇自己的文章",description:"把收藏里的文章、视频和批注引进来,慢慢写成自己的观点。",action:e.jsx("div",{className:"flex flex-wrap items-center justify-center gap-2",children:e.jsxs(J,{onClick:a,disabled:i,children:[e.jsx(ne,{size:17})," 写第一篇文稿"]})})}):null]})}function $t({searchOpen:t,categories:n,searchGroupId:r,searchInput:o,query:l,searching:i,collapsibleCount:a,allCollapsed:f,onCloseSearch:u,onGroupChange:y,onQueryChange:h,onToggleAll:v,onOpenSearch:b,onCreateGroup:D,onCreateDocument:d}){return e.jsx(He,{title:"我的文稿",searchOpen:t,searchHeader:e.jsx(Qe,{categories:n,groupId:r,input:o,query:l,searching:i,onClose:u,onGroupChange:y,onQueryChange:h,itemLabel:"文稿"}),collapsibleCount:a,allCollapsed:f,onToggleAll:v,onOpenSearch:b,onCreateGroup:D,createGroupIcon:e.jsx(qe,{size:18,strokeWidth:1.5}),trailingAction:e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",className:"home-utility-button flex h-11 items-center justify-center gap-1.5 rounded-control px-3 outline-none hover:bg-surface focus-visible:ring-2 focus-visible:ring-ink/40","aria-label":"新建文稿","data-tour":"create-document",onClick:d,children:[e.jsx(ne,{size:18,strokeWidth:1.5}),e.jsx("span",{className:"font-utility text-caption",children:"文稿"})]}),e.jsx(We,{to:"/account",className:"home-utility-button flex size-11 items-center justify-center rounded-control outline-none hover:bg-surface focus-visible:ring-2 focus-visible:ring-ink/40","aria-label":"账户设置",children:e.jsx(Ue,{size:18,strokeWidth:1.5})})]})})}function Kt({pendingDelete:t,onPendingDeleteChange:n,confirmDeleteDocument:r,pendingDeleteGroup:o,onPendingDeleteGroupChange:l,confirmDeleteGroup:i}){return e.jsxs(e.Fragment,{children:[e.jsx(se,{open:!!t,onOpenChange:n,title:"确认删除文稿?",description:`“${(t==null?void 0:t.title)||"未命名文稿"}”及其中的来源引用将被删除,原始收藏不会受影响。`,confirmLabel:"确认删除",onConfirm:r}),e.jsx(se,{open:!!o,onOpenChange:l,title:"确认删除分组?",description:`删除“${(o==null?void 0:o.name)||"这个分组"}”后,其中的文稿会保留并移到未分组。`,confirmLabel:"确认删除",onConfirm:i})]})}function Ht(t){const n=new Date(t);return Number.isNaN(n.getTime())?"刚刚更新":new Intl.DateTimeFormat("zh-CN",{month:"short",day:"numeric"}).format(n)}function Wt({document:t,index:n}){const r=t.title||"未命名文稿";return e.jsx(R.article,{className:"rounded-control bg-surface p-2.5","data-document-search-result":!0,"data-shared-shell":"source",initial:{opacity:0,y:8}
1,animate:{opacity:1,y:0},transition:{...H.base,delay:Math.min(n,6)*.035},children:e.jsxs(W,{to:`/documents/${t.id}`,"data-overlay-link":!0,className:"flex min-h-20 gap-3 text-inherit outline-none focus-visible:ring-2 focus-visible:ring-ink/40","aria-label":`编辑文稿:${r}`,children:[e.jsx("span",{className:"flex size-20 shrink-0 items-center justify-center rounded-card bg-canvas text-muted",children:e.jsx(Ye,{size:22,strokeWidth:1.3,"aria-hidden":"true"})}),e.jsxs("span",{className:"min-w-0 flex-1 py-0.5",children:[e.jsx("strong",{className:"min-w-0 max-w-full [overflow-wrap:anywhere] m-0 line-clamp-2 block font-display text-body-sm leading-card font-normal",title:r,children:r}),e.jsx("span",{className:"mt-1.5 mb-2 line-clamp-2 block text-meta leading-relaxed text-muted",children:Q(t)}),e.jsxs("span",{className:"block truncate font-utility text-caption text-muted",children:[Ht(t.updated_at)," · ",t.references.length," 处引用"]})]})]})})}function Ut({documents:t,filtering:n,searching:r}){return e.jsx(Ve,{itemLabel:"文稿",items:t,filtering:n,searching:r,renderItem:(o,l)=>e.jsx(Wt,{document:o,index:l},o.id)})}function qt({documents:t,renderCard:n}){return e.jsx("div",{className:"grid w-full grid-cols-2 gap-3 lg:grid-cols-4","data-layout":"document-masonry",children:t.map((r,o)=>e.jsx("div",{className:"min-w-0",children:n(r,o)},r.id))})}const X="none";function Qt(t,n){const r=Xe(),[o,l]=s.useState(!1),[i,a]=s.useState(!1);async function f(u){a(!0);try{const y=await t.create();u!==null&&await t.setGroup(y.id,u),l(!1),r(`/documents/${y.id}`)}finally{a(!1)}}return{open:o,setOpen:l,creating:i,create:f,groups:n}}function Vt({open:t,onOpenChange:n,groups:r,creating:o,onCreate:l}){const[i,a]=s.useState(X);function f(){l(i===X?null:Number(i))}return e.jsx(Je,{open:t,onOpenChange:u=>!o&&n(u),children:e.jsxs(Ze,{className:"new-document-dialog max-w-128 overflow-x-hidden",motionName:"new-document-dialog",children:[e.jsxs(et,{className:"sheet-header mb-5",children:[e.jsx(tt,{children:e.jsx(ne,{size:18,strokeWidth:1.7})}),e.jsxs(nt,{children:[e.jsx(rt,{children:"新建文稿"}),e.jsx(ot,{children:"选择文稿存放的分组,也可以稍后在文稿列表里移动。"})]}),e.jsx(at,{label:"关闭新建文稿"})]}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex min-h-11 items-center gap-2 rounded-control bg-inset px-3",children:[e.jsx(st,{className:"shrink-0 text-muted",size:17,strokeWidth:1.6,"aria-hidden":"true"}),e.jsx("label",{className:"shrink-0 font-utility text-caption text-muted",htmlFor:"new-document-group",children:"添加到"}),e.jsxs(it,{value:i,onValueChange:u=>u&&a(u),children:[e.jsx(ct,{id:"new-document-group",className:"h-11 min-w-0 max-w-none flex-1 shrink justify-end rounded-control border-0 bg-transparent px-2 text-body-sm text-ink shadow-none focus-visible:ring-2 focus-visible:ring-ink/35","aria-label":"选择文稿分组",children:e.jsx(lt,{placeholder:"未分组"})}),e.jsxs(ut,{className:"z-[120] max-h-64 max-w-[calc(100vw-32px)]",children:[e.jsx(ie,{value:X,children:"未分组"}),r.map(u=>e.jsx(ie,{value:String(u.id),children:u.name},u.id))]})]})]}),e.jsxs(dt,{className:"mt-1",children:[e.jsx(J,{variant:"ghost",onClick:()=>n(!1),disabled:o,children:"取消"}),e.jsx(J,{variant:"primary",className:"is-primary",disabled:o,onClick:f,children:o?"正在创建…":"创建文稿"})]})]})]})})}function Yt({onMoveToGroup:t,collapseGroupsForDrag:n,restoreCollapsedGroups:r,scrollContainer:o}){const l=mt({markerPrefix:"document",itemId:i=>i.id,onMoveToGroup:t,collapseGroupsForDrag:n,restoreCollapsedGroups:r,scrollContainer:o});return{...l,drag:l.drag?{...l.drag,document:l.drag.item}:null}}const ee=new Map,te=new Map;function de(t){return ee.has(t)?ee.get(t):null}function me(t,n){ee.set(t,n)}function Xt(t){return te.has(t)?te.get(t):null}function pe(t,n){te.set(t,n)}function Jt(t,n){const r=new Map(t.map(a=>[a.id,a])),o=new Set,l=n.map(a=>{const f=a.document_ids.map(u=>r.get(u)).filter(u=>!!u);return f.forEach(u=>o.add(u.id)),{group:a,items:f}}),i=t.filter(a=>!o.has(a.id));return{sections:l,ungrouped:i}}function Zt(t){return[...t.map(n=>String(n.id)),_]}function en(t,n){var r;return t===_?"未分组":((r=n.find(o=>String(o.id)===t))==null?void 0:r.name)||"分组"}function tn(t,n){var r;return t===_?n.ungrouped:((r=n.sections.find(({group:o})=>String(o.id)===t))==null?void 0:r.items)||[]}function nn({documents:t,userId:n,api:r,refreshVersion:o=0}){const l=s.useRef(Xt(n)).current,[i,a]=s.useState(l??[]),[f,u]=s.useState(l===null),[y,h]=s.useState(()=>pt("documents")),[v,b]=s.useState(!1),[D,d]=s.useState(""),[x,m]=s.useState(!1),[p,C]=s.useState(null),[j,L]=s.useState(null),[k,G]=s.useState(!1),[A,F]=s.useState(""),[z,$]=s.useState(null),O=s.useRef(null),P=s.useRef(null);function T(c){a(g=>{const N=c(g);return pe(n,N),N})}const M=s.useCallback(async c=>{try{const g=await r.listGroups(c);if(c!=null&&c.aborted)return;a(g),pe(n,g)}catch(g){if(c!=null&&c.aborted||g instanceof DOMException&&g.name==="AbortError")return;B.error(g instanceof Error?g.message:"文稿分组读取失败")}finally{c!=null&&c.aborted||u(!1)}},[r,n]);s.useEffect(()=>{const c=new AbortController;return M(c.signal),()=>c.abort()},[M,o]),s.useEffect(()=>{const c=g=>{const{scopes:N}=g.detail||{};N&&!N.includes("documents")||M()};return window.addEventListener(q,c),()=>window.removeEventListener(q,c)},[M]);const w=s.useMemo(()=>Jt(t,i),[i,t]),K=s.useMemo(()=>new Set,[]),V=s.useMemo(()=>Zt(i),[i]);function xe(c,g){h(N=>{const S={...N};return g?S[c]=!0:delete S[c],ht(S,"documents"),S})}function ge(){O.current||(O.current={...y},h(Object.fromEntries(V.map(c=>[c,!0]))))}function be(){O.current&&(h(O.current),O.current=null)}function ve(c,g,N){C(c),L(g),G(!1),F(""),P.current=N}function Y(){C(null),L(null),G(!1),F(""),P.current=null}function ye(){const c=i.find(g=>String(g.id)===p);c&&(F(c.name),G(!0))}async function we(){const c=i.find(g=>String(g.id)===p);if(!(!c||!A.trim()||x)){m(!0),Y();try{const g=await r.renameGroup(c.id,A.trim());T(N=>N.map(S=>S.id===g.id?g:S))}catch(g){B.error(g instanceof Error?g.message:"重命名分组失败")}finally{m(!1)}}}function Ce(){const c=i.find(g=>String(g.id)===p);c&&($(c),Y())}async function je(){if(z)try{await r.deleteGroup(z.id),T(c=>c.filter(g=>g.id!==z.id)),$(null)}catch(c){B.error(c instanceof Error?c.message:"删除分组失败")}}async function Ge(){if(!(!D.trim()||x)){m(!0);try{const c=await r.createGroup(D.trim());T(g=>[...g,c]),b(!1),d("")}catch(c){B.error(c instanceof Error?c.message:"新建分组失败")}finally{m(!1)}}}async function De(c,g){const N=g&&g!==_?Number(g):null;try{await r.setGroup(c,N),T(S=>S.map(E=>({...E,document_ids:E.id===N?Array.from(new Set([c,...E.document_ids])):E.document_ids.filter(I=>I!==c)})))}catch(S){B.error(S instanceof Error?S.message:"移动文稿失败")}}async function Ne(c,g){if(!g||g.id===c)return;const S=ft(V,c,g).filter(E=>E!==_).map(Number);try{const E=new Map(i.map(I=>[I.id,I]));T(()=>S.map(I=>E.get(I)).filter(I=>!!I)),await r.reorderGroups(S)}catch(E){B.error(E instanceof Error?E.message:"调整分组顺序失败")}}return{loading:f,categories:i,grouped:w,memberGroupKeys:K,orderedGroupKeys:V,collapsedGroups:y,setGroupCollapsed:xe,collapseGroupsForDrag:ge,restoreCollapsedGroups:be,focusedGroupId:p,groupSourceRect:j,editingFocusedGroup:k,groupEditName:A,setGroupEditName:F,pendingDeleteGroup:z,setPendingDeleteGroup:$,beginGroupAction:ve,finishGroupAction:Y,editFocusedGroup:ye,saveFocusedGroup:we,openGroupDeleteConfirmation:Ce,confirmDeleteGroup:je,creatingGroup:v,setCreatingGroup:b,newGroupName:D,setNewGroupName:d,groupEditorBusy:x,saveNewGroup:Ge,moveDocumentToGroup:De,reorderGroups:Ne,groupTitleForKey:c=>en(c,i),documentsForGroupKey:c=>tn(c,w)}}function rn({cardGestures:t,groupGestures:n,grouping:r,documents:o,renderCard:l,renderWaterfall:i}){const a=s.useMemo(()=>new Map(o.map(u=>[u.id,u])),[o]);
1function f(u,y){const h=a.get(y);h&&t.onPressStart(u,h)}return{markerPrefix:"document",itemKindLabel:"文稿",itemId:u=>u.id,renderCard:l,renderWaterfall:i,animateLayout:!0,draggedItemId:t.drag?t.drag.document.id:null,organizingItems:t.drag!==null,itemDropTarget:t.dropTarget,onItemDragOver:t.setDropTarget,onItemDrop:r.moveDocumentToGroup,onItemOpenActions:(u,y)=>{const h=a.get(u);h&&t.openAction(h,y)},onItemTouchStart:f,onItemTouchMove:t.onPressMove,onItemTouchEnd:t.onPressEnd,onItemClickCapture:t.onClickCapture,draggedGroupId:n.draggedGroupId,groupSortTarget:n.groupSortTarget,onGroupPointerDown:n.onGroupPointerDown,onGroupTouchStart:n.onGroupTouchStart,onGroupTouchMove:n.onGroupTouchMove,onGroupTouchEnd:n.onGroupTouchEnd,onGroupClickCapture:n.onGroupClickCapture}}function on({api:t,userId:n,refreshVersion:r}){const o=s.useRef(de(n)).current,[l,i]=s.useState(o??[]),[a,f]=s.useState(o===null),[u,y]=s.useState(""),h=s.useCallback(x=>{i(m=>{const p=x(m);return me(n,p),p})},[n]),v=s.useCallback(async x=>{try{const m=await t.list(x);i(m),me(n,m),y("")}catch(m){if(x!=null&&x.aborted)return;de(n)===null&&y(m instanceof Error?m.message:"文稿列表读取失败")}finally{x!=null&&x.aborted||f(!1)}},[t,n]);s.useEffect(()=>{const x=new AbortController;return v(x.signal),()=>x.abort()},[v,r]),s.useEffect(()=>{const x=m=>{const{scopes:p}=m.detail||{};p&&!p.includes("documents")||v()};return window.addEventListener(q,x),()=>window.removeEventListener(q,x)},[v]),s.useEffect(()=>{const x=m=>{const p=m.detail;(p==null?void 0:p.kind)==="document"&&h(C=>C.map(j=>j.id===p.id?{...j,...p.cover}:j))};return window.addEventListener(le,x),()=>window.removeEventListener(le,x)},[h]);const b=s.useCallback(async x=>{await t.remove(x.id),h(m=>m.filter(p=>p.id!==x.id))},[t,h]),D=s.useCallback(async(x,m)=>{const p=await t.setCover(x,m);h(C=>C.map(j=>j.id===p.id?{...j,...Z(p)}:j)),ue({kind:"document",id:p.id,cover:p})},[t,h]),d=s.useCallback(async x=>{const m=await t.removeCover(x);h(p=>p.map(C=>C.id===m.id?{...C,...Z(m)}:C)),ue({kind:"document",id:m.id,cover:m})},[t,h]);return{documents:l,loading:a,error:u,updateDocuments:h,removeDocument:b,setDocumentCover:D,removeDocumentCover:d}}function an(t,n,r,o,l,i){const a=s.useRef(xt("documents")),f=s.useRef(null),u=s.useRef(null),y=s.useRef(!1),h=s.useRef(!1),v=s.useRef(n);v.current=n;function b(){var p;return{top:((p=t.current)==null?void 0:p.scrollTop)||0}}function D(){v.current.trim()||u.current!==null||(u.current=window.requestAnimationFrame(()=>{u.current=null,ce(b(),"documents")}))}function d(p){const C=t.current;C&&(C.scrollTop=p.top)}s.useLayoutEffect(()=>{if(!r||y.current)return;y.current=!0;const p=window.requestAnimationFrame(()=>d(a.current));return()=>window.cancelAnimationFrame(p)},[l,r,o]),s.useEffect(()=>{var p;if(i&&!h.current)(p=t.current)==null||p.scrollTo({top:0,behavior:"auto"});else if(!i&&h.current){const C=f.current||a.current;f.current=null;const j=window.requestAnimationFrame(()=>{window.requestAnimationFrame(()=>d(C))});return h.current=i,()=>window.cancelAnimationFrame(j)}h.current=i},[i,t]),s.useEffect(()=>()=>{u.current!==null&&window.cancelAnimationFrame(u.current)},[]);function x(){f.current||(f.current=b(),ce(f.current,"documents"))}function m(p){!v.current.trim()&&p.trim()&&x()}return{persistScroll:D,changeQuery:m,captureForSearchStart:x}}function sn({documents:t,categories:n,loading:r}){const o=s.useRef(null),l=s.useCallback(async h=>{const v=h.toLocaleLowerCase();return t.filter(b=>`${b.title} ${Q(b)}`.toLocaleLowerCase().includes(v))},[t]),i=s.useCallback(h=>h.document_ids,[]),a=gt({search:l,groups:n,itemIdsForGroup:i}),f=a.searchOpen&&!!(a.query.trim()&&!a.query.startsWith("/")),u=an(o,a.query,!r,t.length,n.length,f),y=s.useCallback(h=>{u.changeQuery(h),a.changeQuery(h)},[a,u]);return{mainScroll:o,documentSearch:a,filtering:f,handleQueryChange:y,...u}}function cn({api:t,refreshVersion:n=0}){const{me:r}=bt(),o=(r==null?void 0:r.user.id)??0,{documents:l,loading:i,error:a,removeDocument:f,setDocumentCover:u,removeDocumentCover:y}=on({api:t,userId:o,refreshVersion:n}),[h,v]=s.useState(null),[b,D]=s.useState(null),d=nn({documents:l,userId:o,api:t,refreshVersion:n}),{mainScroll:x,documentSearch:m,filtering:p,handleQueryChange:C,persistScroll:j,captureForSearchStart:L}=sn({documents:l,categories:d.categories,loading:i||d.loading}),k=i||d.loading,G=Qt(t,d.categories),A=Yt({onMoveToGroup:d.moveDocumentToGroup,collapseGroupsForDrag:d.collapseGroupsForDrag,restoreCollapsedGroups:d.restoreCollapsedGroups,scrollContainer:x}),F=vt({memberGroupKeys:d.memberGroupKeys,onGroupSort:d.reorderGroups,collapseGroupsForDrag:d.collapseGroupsForDrag,restoreCollapsedGroups:d.restoreCollapsedGroups,onBeginGroupAction:d.beginGroupAction,onFinishGroupAction:d.finishGroupAction,scrollContainer:x});function z(w){return e.jsx(he,{document:w,summary:Q(w)})}function $(){h&&f(h).then(()=>v(null))}const O=rn({cardGestures:A,groupGestures:F,grouping:d,documents:l,renderCard:z,renderWaterfall:(w,K)=>e.jsx(qt,{documents:w,renderCard:K})}),P=d.orderedGroupKeys.filter(w=>d.documentsForGroupKey(w).length>0),T=P.length>0&&P.every(w=>!!d.collapsedGroups[w]);function M(){const w=!T;P.forEach(K=>d.setGroupCollapsed(K,w))}return e.jsxs(yt,{mode:"browse",rail:"collection",className:"documents-screen",children:[e.jsx($t,{searchOpen:m.searchOpen,categories:d.categories,searchGroupId:m.searchGroupId,searchInput:m.searchInput,query:m.query,collapsibleCount:P.length,allCollapsed:T,onCloseSearch:m.closeSearch,onGroupChange:m.setSearchGroupId,onQueryChange:C,searching:m.searching,onToggleAll:M,onOpenSearch:()=>{L(),m.setSearchOpen(!0)},onCreateGroup:()=>d.setCreatingGroup(!0),onCreateDocument:()=>G.setOpen(!0)}),e.jsx(wt,{ref:x,onScroll:j,children:e.jsxs(Ct,{rail:"collection","data-tour":"documents-library",children:[e.jsx(Bt,{hasDocuments:l.length>0,hasGroups:d.categories.length>0,loading:k,error:a,searchOpen:m.searchOpen,creating:d.creatingGroup,onCreateDocument:()=>G.setOpen(!0)}),k?null:m.searchOpen?e.jsx(Ut,{documents:m.visible,filtering:p,searching:m.searching}):e.jsx(R.section,{className:"grouped-library flex w-full flex-col gap-0","aria-label":"文稿列表",initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},transition:H.micro,children:e.jsx(Rt,{sharedProps:O,grouping:d})},"grouped-documents")]})}),e.jsx(_t,{focusedDocument:A.target,documentSourceRect:A.sourceRect,documentMenuPlacement:A.placement,onFinishCardAction:A.finish,onOpenDocumentCover:D,onDocumentDelete:v,drag:A.drag}),e.jsx(Mt,{documents:l,categories:d.categories,focusedGroupId:d.focusedGroupId,groupSourceRect:d.groupSourceRect,editingFocusedGroup:d.editingFocusedGroup,groupEditName:d.groupEditName,onGroupEditNameChange:d.setGroupEditName,onSaveFocusedGroup:()=>void d.saveFocusedGroup(),onFinishGroupAction:d.finishGroupAction,onEditFocusedGroup:d.editFocusedGroup,onOpenGroupDelete:d.openGroupDeleteConfirmation,draggedGroupId:F.draggedGroupId,groupSortTarget:F.groupSortTarget,groupDragPoint:F.groupDragPoint,groupTitleForKey:d.groupTitleForKey,overlayClickSuppressed:F.overlayClickSuppressed}),e.jsx(Kt,{pendingDelete:h,onPendingDeleteChange:w=>{w||v(null)},confirmDeleteDocument:$,pendingDeleteGroup:d.pendingDeleteGroup,onPendingDeleteGroupChange:w=>{w||d.setPendingDeleteGroup(null)},confirmDeleteGroup:()=>void d.confirmDeleteGroup()}),e.jsx(Vt,{open:G.open,onOpenChange:G.setOpen,groups:G.groups,creating:G.creating,onCreate:G.create}),e.jsx(Tt,{open:!!b,onOpenChange:w=>{w||D(null)},initialQuery:(b==null?void 0:b.title)||"我的文稿",currentCover:b?Z(b):It(),returnFocus:()=>b?document.querySelector(`[data-document-id="${b.id}"] [data-overlay-link]`):null,onSelect:async w=>{b&&await u(b.id,w)},onRemove:async()=>{b&&await y(b.id)}})]})}function ln({api:t}){const n=Dt(),r=Nt(),o=s.useRef(!1),[l,i]=s.useState("");return s.useEffect(()=>{o.current||(o.current=!0,t.create().then(a=>n(`/documents/${a.id}`,{replace:!0,state:r.state})).catch(a=>i(a instanceof Error?a.message:"新建文稿失败")))},[t,r.state,n]),l?e.jsx("main",{className:"document-message flex min-h-dvh flex-col items-center justify-center gap-3 bg-canvas px-6 text-center text-body-sm text-muted","aria-label":"新建文稿失败",children:e.jsx("p",{children:l})}):e.jsx(St,{label:"正在新建文稿"})}function pn({api:t,userId:n}){const{id:r}=jt();if(!r)return e.jsx(cn,{api:t});if(r==="new")return e.jsx(ln,{api:t});const o=Number(r);return!Number.isSafeInteger(o)||o<=0?e.jsx("main",{className:"document-message flex min-h-dvh items-center justify-center bg-canvas px-6 text-center text-ink","aria-label":"文稿不存在",children:e.jsx("h1",{className:"font-display text-2xl font-normal",children:"文稿不存在"})}):e.jsx(Gt,{children:e.jsx(Ot,{api:t,documentId:o,userId:n})})}export{cn as DocumentListScreen,pn as DocumentsScreen,xn as createDocumentsApi,gn as documentsApi};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.