pi-webapp 0.1.53 → 0.1.54-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dist/extension.js +34 -31
  2. package/dist/hosted-recovery.js +2 -2
  3. package/dist/hosted-worker.js +2 -2
  4. package/package.json +2 -2
  5. package/web/dist/.vite/manifest.json +41 -41
  6. package/web/dist/assets/{MarkdownText-CBiL97gk.js → MarkdownText-ozc5ubjI.js} +4 -4
  7. package/web/dist/assets/app-zBuL5kvH.js +47 -0
  8. package/web/dist/assets/app.css +1 -1
  9. package/web/dist/assets/app.js +4 -4
  10. package/web/dist/assets/{code-editor-DeAOkPrq.js → code-editor-Bqv_YjkY.js} +4 -4
  11. package/web/dist/assets/{dist-B5emzMvH.js → dist-BR6sl7cV.js} +2 -2
  12. package/web/dist/assets/{dist-DTjHomg3.js → dist-CEWKL9kJ.js} +2 -2
  13. package/web/dist/assets/{dist-rREmcN_F.js → dist-CR7xsvSD.js} +2 -2
  14. package/web/dist/assets/{dist-ekmOAsAL.js → dist-D8zBFk2N.js} +2 -2
  15. package/web/dist/assets/{dist-C3T17C1Q.js → dist-D94MLsYm.js} +2 -2
  16. package/web/dist/assets/{dist-Bp1qxOA-.js → dist-DPMSomV_.js} +2 -2
  17. package/web/dist/assets/{dist-ThlP4B0-.js → dist-DSv6YTbw.js} +2 -2
  18. package/web/dist/assets/{dist-CYNv_x25.js → dist-DcCXZ8Rj.js} +2 -2
  19. package/web/dist/assets/{dist-to0Y4VHe.js → dist-Dofxo368.js} +2 -2
  20. package/web/dist/assets/{dist-y5XhVIrr.js → dist-DtgEbjMA.js} +2 -2
  21. package/web/dist/assets/{dist-BNmsN76A.js → dist-DxkYOh1x.js} +2 -2
  22. package/web/dist/assets/{graphql-BfvlZifS.js → graphql-t5l6XeUa.js} +2 -2
  23. package/web/dist/assets/{http-CMFHpKAi.js → http-CA54Nmhu.js} +2 -2
  24. package/web/dist/assets/{php-AbwdN8Ef.js → php-DjAwqY1k.js} +2 -2
  25. package/web/dist/assets/{plugin-kH2lR7pE.js → plugin-CmmnhL_a.js} +2 -2
  26. package/web/dist/assets/plugin-DgvXwDBK.js +6 -0
  27. package/web/dist/assets/{plugin-CnTnCTg7.js → plugin-muXBtnku.js} +2 -2
  28. package/web/dist/assets/{rst-DPJzqmXX.js → rst-6Nsa0tEe.js} +2 -2
  29. package/web/dist/assets/{ruby-Hx9so-WR.js → ruby-BIfqPC89.js} +2 -2
  30. package/web/dist/assets/{svelte-DLqN0QFL.js → svelte-DXhPh5aW.js} +2 -2
  31. package/web/dist/assets/{vue-XwJifyVN.js → vue-DpKsjiHm.js} +2 -2
  32. package/web/dist/assets/app-CRTzSso6.js +0 -38
  33. package/web/dist/assets/plugin-Bfd7f_vy.js +0 -6
@@ -1,6 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/code-editor-DeAOkPrq.js","assets/rolldown-runtime-CgmABjMJ.js","assets/dist-IkQ96Etc.js","assets/app.js","assets/app-CRTzSso6.js","assets/react-CLFE7TFE.js","assets/icons-D8yiYkWB.js","assets/clsx-DQAHfk8w.js","assets/WorkspacePanel.module-V6gI-nG1.js","assets/WorkspacePanel.css","assets/app.css"])))=>i.map(i=>d[i]);
2
- (function(){try{var e=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]=`5401c0ca-a76c-4ca6-ab71-a847200db27d`,e._sentryDebugIdIdentifier=`sentry-dbid-5401c0ca-a76c-4ca6-ab71-a847200db27d`)}catch{}})();import{r as e}from"./rolldown-runtime-CgmABjMJ.js";import{a as t,c as n,d as r,h as i,m as a,n as o,o as s,p as c,s as l}from"./app-CRTzSso6.js";import{a as u,c as d,o as f,t as p}from"./WorkspacePanel.module-V6gI-nG1.js";import{t as m}from"./react-CLFE7TFE.js";import{F as h,S as g,g as _,x as v}from"./icons-D8yiYkWB.js";import{a as y,s as b}from"./app.js";import{n as x}from"./clsx-DQAHfk8w.js";var S={id:l.files,kind:`builtin`,version:`1.0.0`,name:{zh:`工作区文件`,en:`Workspace files`},description:{zh:`浏览、搜索工作区文件,预览代码、Markdown 与图片,并编辑文本文件。`,en:`Browse and search workspace files, preview code, Markdown and images, and edit text files.`}},C=e(m(),1);async function w(e,n,r,i){return s(await t(`/api/workspace/files/${e}`,{method:`POST`,headers:{Authorization:`Bearer ${b()}`,"Content-Type":`application/json`},body:JSON.stringify({sessionId:n,...r}),signal:i}))}async function T(e,n,r){let i=await t(`/api/workspace/files/raw`,{method:`POST`,headers:{Authorization:`Bearer ${b()}`,"Content-Type":`application/json`},body:JSON.stringify({sessionId:e,path:n}),signal:r});return i.response.ok?i.response.blob():s(i)}var E={raw:T,list:(e,t,n)=>w(`list`,e,{path:t},n),preview:(e,t,n)=>w(`preview`,e,{path:t},n),write:(e,t,n,r)=>w(`write`,e,{path:t,text:n,version:r}),status:(e,t)=>w(`status`,e,{},t),search:(e,t,n,r)=>w(`search`,e,{query:t,mode:n},r)},D=x(),O,k=()=>O??=y(()=>import(`./code-editor-DeAOkPrq.js`).then(e=>e.t),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10]));function ee({text:e,filename:t,label:n,reveal:r,autoFocus:a,onChange:o,onSave:s}){let c=(0,C.useRef)(null),[l,u]=(0,C.useState)(),[d,f]=(0,C.useState)(!1),m=(0,C.useRef)({onChange:o,onSave:s});(0,C.useLayoutEffect)(()=>{m.current={onChange:o,onSave:s}});let h=(0,C.useRef)(e);return(0,C.useEffect)(()=>{let e,r=!1;return k().then(({createCodeEditor:i})=>{!r&&c.current&&(e=i(c.current,{text:h.current,filename:t,label:n,onChange:e=>m.current.onChange(e),onSave:()=>m.current.onSave()}),u(e))}).catch(()=>{r||f(!0)}),()=>{r=!0,e?.destroy()}},[t,n]),(0,C.useEffect)(()=>{l?.setText(e)},[l,e]),(0,C.useEffect)(()=>{l&&r&&l.reveal(r.line)},[l,r]),(0,C.useEffect)(()=>{l&&a&&l.focus()},[l,a]),d?(0,D.jsx)(`p`,{className:p.state,role:`status`,children:i(`编辑器加载失败,请重新读取文件。`,`The editor could not load. Reload the file to try again.`)}):(0,D.jsx)(`div`,{ref:c,className:p.codeEditor,"aria-busy":!l,children:!l&&(0,D.jsx)(`p`,{className:p.state,children:i(`正在打开编辑器…`,`Opening the editor…`)})})}function A(e,t){let n=t.replace(/[?#].*$/u,``);try{n=decodeURI(n)}catch{}if(n===``||n.includes(`\\`)||n.includes(`\0`)||/^[a-z][a-z\d+.-]*:/iu.test(n)||n.startsWith(`//`))return;let r=n.startsWith(`/`)?[]:e.split(`/`).slice(0,-1);for(let e of n.split(`/`))if(e!==``&&e!==`.`){if(e===`..`){if(r.pop()===void 0)return}else r.push(e)}return r.length?r.join(`/`):void 0}var te=e=>e.replace(/\r\n/gu,`
3
- `),j=(0,C.memo)(function({sessionId:e,path:t,renderMarkdown:a,breadcrumb:o,trailing:s,refresh:c=0,reveal:l,onDirtyChange:u,onSaved:d}){let[f,m]=(0,C.useState)(null),[h,g]=(0,C.useState)(!0),[_,y]=(0,C.useState)(!1),[b,x]=(0,C.useState)(0),[S,w]=(0,C.useState)(!1),[T,O]=(0,C.useState)(!1),[k,j]=(0,C.useState)(null),[M,N]=(0,C.useState)(!1),[P,F]=(0,C.useState)(!1),[I,L]=(0,C.useState)(null);(0,C.useEffect)(()=>{let n=new AbortController;return g(!0),y(!1),O(!1),w(!1),E.preview(e,t,n.signal).then(e=>{n.signal.aborted||(m(e),g(!1))}).catch(()=>{n.signal.aborted||(y(!0),g(!1))}),()=>n.abort()},[e,t,b]);let R=k!==null,z=(0,C.useRef)(R);(0,C.useLayoutEffect)(()=>{z.current=R});let B=(0,C.useRef)(c);(0,C.useEffect)(()=>{c===B.current||z.current||x(e=>e+1)},[c]);let V=/\.(?:md|markdown|mdown)$/i.test(t),H=t.split(`/`).at(-1),[U,W]=(0,C.useState)(0),G=(0,C.useRef)(new Map);(0,C.useEffect)(()=>{let e=G.current;return e.clear(),()=>{for(let t of e.values())t&&URL.revokeObjectURL(t);e.clear()}},[e,t,b]);let K=(0,C.useMemo)(()=>({resolve(n){let r=A(t,n);if(r===void 0)return;let i=G.current,a=i.get(r);if(a!==void 0)return a??void 0;i.set(r,null),E.raw(e,r,new AbortController().signal).then(e=>{G.current===i&&i.get(r)===null&&(i.set(r,URL.createObjectURL(e)),W(e=>e+1))}).catch(()=>{})}}),[e,t,b,U]),q=f?.kind===`text`?f:null,J=q?te(q.text):``,Y=k??J,X=q!==null&&(!V||M);(0,C.useEffect)(()=>{u?.(R)},[R,u]),(0,C.useEffect)(()=>()=>u?.(!1),[u]),(0,C.useEffect)(()=>{l&&V&&N(!0)},[l,V]);let ne=()=>!R||window.confirm(i(`放弃未保存的更改?`,`Discard unsaved changes?`)),Z=()=>{ne()&&(j(null),L(null),x(e=>e+1))},Q=async(r=!1)=>{if(q&&k!==null&&!P){F(!0),L(null);try{let n=q.version;if(r){let r=await E.preview(e,t,new AbortController().signal);if(r.kind!==`text`)throw Error(`not text`);n=r.version}let i=q.text.includes(`\r
4
- `)?k.replace(/\n/gu,`\r
5
- `):k,a=await E.write(e,t,i,n);m({...q,text:i,version:a.version,size:a.size}),j(null),d?.()}catch(e){e instanceof n&&e.status===409&&e.reason===`conflict`?L({kind:`conflict`}):e instanceof n&&e.status===413?L({kind:`error`,message:i(`内容过大,无法保存(最多 5 MB、200,000 行)。`,`Too large to save (5 MB or 200,000 lines at most).`)}):e instanceof n&&e.status===409?L({kind:`error`,message:i(`会话已切换,未保存。`,`The session changed, so nothing was saved.`)}):L({kind:`error`,message:i(`保存失败,文件可能已移动、删除或无权写入。`,`Could not save. The file may have moved, been deleted, or be read-only.`)})}finally{F(!1)}}},$=(0,C.useMemo)(()=>f?.kind===`image`?`data:${f.mimeType};base64,${f.data}`:null,[f]);return(0,D.jsxs)(`div`,{className:p.body,children:[(0,D.jsxs)(`div`,{className:p.toolbar,children:[o??(0,D.jsx)(`span`,{className:p.path,title:t,children:t}),R&&(0,D.jsx)(`span`,{className:p.unsaved,role:`status`,children:i(`未保存`,`Unsaved`)}),!q&&(0,D.jsx)(`span`,{className:p.readonly,children:i(`只读`,`Read only`)}),V&&q&&(0,D.jsx)(`button`,{type:`button`,className:p.textButton,"aria-pressed":M,onClick:()=>N(e=>!e),children:M?i(`预览`,`Preview`):i(`编辑`,`Edit`)}),q&&(0,D.jsx)(`button`,{type:`button`,className:`${p.textButton} ${p.primaryButton}`,disabled:!R||P,title:i(`保存(⌘/Ctrl+S)`,`Save (⌘/Ctrl+S)`),onClick:()=>void Q(),children:P?i(`正在保存…`,`Saving…`):i(`保存`,`Save`)}),(0,D.jsx)(`button`,{type:`button`,className:p.iconButton,"aria-label":i(`重新读取文件`,`Reload file`),title:i(`重新读取文件`,`Reload file`),onClick:Z,children:(0,D.jsx)(v,{})}),s]}),I&&(0,D.jsx)(`div`,{className:p.saveProblem,role:`alert`,children:I.kind===`conflict`?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`span`,{children:i(`文件在你编辑期间已在磁盘上更改。`,`This file changed on disk while you were editing.`)}),(0,D.jsx)(`button`,{type:`button`,className:p.textButton,onClick:()=>{j(null),L(null),x(e=>e+1)},children:i(`放弃我的更改并重新读取`,`Discard mine and reload`)}),(0,D.jsx)(`button`,{type:`button`,className:p.textButton,onClick:()=>void Q(!0),children:i(`覆盖`,`Overwrite`)})]}):(0,D.jsx)(`span`,{children:I.message})}),(0,D.jsx)(`div`,{className:p.preview,"aria-busy":h,children:h&&!f?(0,D.jsx)(`p`,{className:p.state,role:`status`,children:i(`正在读取…`,`Reading…`)}):_?(0,D.jsxs)(`div`,{className:p.state,role:`status`,children:[(0,D.jsx)(`p`,{children:i(`文件读取失败,可能已移动、删除或无权访问。`,`Could not read this file. It may have moved, been deleted, or be inaccessible.`)}),(0,D.jsx)(`button`,{type:`button`,className:p.textButton,onClick:Z,children:i(`重试`,`Retry`)})]}):f?f.kind===`too-large`?(0,D.jsx)(`p`,{className:p.state,children:f.unit===`lines`?i(`文件行数过多,最多打开 ${f.limit.toLocaleString()} 行。`,`File has too many lines. Limit: ${f.limit.toLocaleString()} lines.`):i(`文件过大,无法打开。大小上限:${f.limit/1024/1024} MB`,`File is too large to open. Limit: ${f.limit/1024/1024} MB`)}):f.kind===`unsupported`?(0,D.jsx)(`p`,{className:p.state,children:i(`暂不支持预览此文件类型。`,`Preview is unavailable for this file type.`)}):f.kind===`image`&&$?T?(0,D.jsx)(`p`,{className:p.state,children:i(`图片无法解码。`,`This image could not be decoded.`)}):(0,D.jsx)(`button`,{type:`button`,className:p.imageButton,"aria-label":i(`放大图片`,`Enlarge image`),onClick:()=>w(!0),children:(0,D.jsx)(`img`,{className:p.image,src:$,alt:H,onError:()=>O(!0)})}):f.kind===`text`?X?(0,D.jsx)(ee,{text:Y,filename:H,label:i(`编辑 ${H}`,`Edit ${H}`),reveal:l,autoFocus:V,onChange:e=>j(e===J?null:e),onSave:()=>void Q()}):Y.trim()===``?(0,D.jsx)(`p`,{className:p.state,children:i(`空文件`,`Empty file`)}):(0,D.jsx)(`div`,{className:p.markdown,children:a(Y,K)}):null:null}),S&&$&&(0,D.jsx)(r,{src:$,alt:H,labels:{dialog:i(`图片预览`,`Image preview`),close:i(`关闭图片预览`,`Close image preview`)},onClose:()=>w(!1)})]})}),M=h(),N={ignored:0,untracked:1,added:2,modified:3,conflict:4},P={of:()=>void 0};function F(e){let t=new Map,n=[],r=new Map,i=(e,t)=>{let n=r.get(e);(n===void 0||N[t]>N[n])&&r.set(e,t)};for(let{path:r,state:a}of e.entries){let e=a===`deleted`?`modified`:a,o=r.endsWith(`/`),s=o?r.slice(0,-1):r;if(o?n.push([s,e]):a!==`deleted`&&t.set(s,e),e===`ignored`)continue;let c=s.split(`/`);for(let t=1;t<c.length;t++)i(c.slice(0,t).join(`/`),e)}return{of(e){let i=t.get(e);if(i)return i;for(let[t,r]of n)if(e===t||e.startsWith(`${t}/`))return r;return r.get(e)}}}var I=(e,t)=>({modified:t(`已修改`,`Modified`),added:t(`已添加`,`Added`),untracked:t(`未跟踪`,`Untracked`),conflict:t(`有冲突`,`Conflict`),ignored:t(`已忽略`,`Ignored`)})[e];function L({size:e,className:t}){return(0,D.jsxs)(`svg`,{width:e,height:e,className:t,viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,children:[(0,D.jsx)(`path`,{d:`M2.9 2.26h2.3c.55 0 1.06.27 1.37.73l.46.7c.15.23.41.37.69.37h4.58a1.95 1.95 0 0 1 1.95 1.95v5.83a1.95 1.95 0 0 1-1.95 1.95H2.9A1.95 1.95 0 0 1 .95 11.84V4.21A1.95 1.95 0 0 1 2.9 2.26Z`,fill:`currentColor`,fillOpacity:`.2`,stroke:`currentColor`,strokeWidth:`1.3`,strokeLinejoin:`round`}),(0,D.jsx)(`path`,{d:`M1.2 6.45h13.6`,stroke:`currentColor`,strokeWidth:`1.3`})]})}function R({path:e,depth:t,tree:n}){let[r,o]=(0,C.useState)(()=>n.levels.get(e)),[s,c]=(0,C.useState)(!0),[l,u]=(0,C.useState)(!1),[d,m]=(0,C.useState)(0);(0,C.useEffect)(()=>{let t=new AbortController;return c(!0),u(!1),E.list(n.sessionId,e,t.signal).then(r=>{t.signal.aborted||(n.levels.set(e,r),o(r),c(!1))}).catch(()=>{t.signal.aborted||(u(!0),c(!1))}),()=>t.abort()},[n.sessionId,n.levels,e,n.revision,d]);let h=n.compact?14:16,g=n.status??P;return(0,D.jsxs)(D.Fragment,{children:[s&&!r&&(0,D.jsx)(`li`,{role:`none`,className:p.state,"aria-live":`polite`,children:i(`正在读取…`,`Reading…`)}),l&&(0,D.jsxs)(`li`,{role:`none`,className:p.state,children:[(0,D.jsx)(`span`,{role:`status`,children:i(`目录读取失败,可能已移动、删除或无权访问。`,`Could not read this directory. It may have moved, been deleted, or be inaccessible.`)}),` `,(0,D.jsx)(`button`,{type:`button`,className:p.textButton,onClick:()=>m(e=>e+1),children:i(`重试`,`Retry`)})]}),!s&&!l&&r?.entries.length===0&&(0,D.jsx)(`li`,{role:`none`,className:p.state,children:i(`空目录`,`Empty directory`)}),r?.entries.map(e=>{let r=e.kind===`directory`,o=r&&n.expanded.has(e.path),s=e.kind===`other`,c=g.of(e.path);return(0,D.jsxs)(`li`,{role:`treeitem`,tabIndex:s?-1:0,"aria-label":e.name,"aria-level":t,"aria-expanded":r?o:void 0,"aria-disabled":s||void 0,"aria-description":c&&I(c,i),"data-git-status":c,"aria-selected":r||s?void 0:e.path===n.selected,"data-files-path":e.path,children:[(0,D.jsxs)(`div`,{className:p.row,style:{paddingInlineStart:`${(n.compact?8:10)+(t-1)*(n.compact?12:14)}px`},title:s?i(`此条目不可访问或位于工作区之外`,`This entry is unavailable or outside the workspace`):e.path,onClick:t=>{s||(t.currentTarget.parentElement?.focus(),r?n.toggle(e.path):n.open(e.path))},children:[r?o?(0,D.jsx)(a,{size:h,className:p.folderIcon}):(0,D.jsx)(L,{size:h,className:p.folderIcon}):(0,D.jsx)(f,{path:e.name,size:h}),(0,D.jsx)(`span`,{className:p.name,children:e.name}),c&&c!==`ignored`&&(0,D.jsx)(`span`,{className:p.statusDot,"aria-hidden":`true`})]}),o&&(0,D.jsx)(`ul`,{role:`group`,className:p.level,children:(0,D.jsx)(R,{path:e.path,depth:t+1,tree:n})})]},e.path)}),r?.truncated&&(0,D.jsx)(`li`,{role:`none`,className:p.state,children:i(`条目太多,只显示前 1000 项。`,`Too many entries. Showing the first 1,000.`)})]})}function z({root:e,label:t,...n}){let{toggle:r,open:i}=n;return(0,D.jsx)(`ul`,{role:`tree`,"aria-label":t,className:p.tree,onKeyDown:e=>{let t=e.target;if(t.getAttribute(`role`)!==`treeitem`||t.getAttribute(`aria-disabled`)===`true`)return;let n=t.dataset.filesPath,a=t.hasAttribute(`aria-expanded`),o=t.getAttribute(`aria-expanded`)===`true`,s=[...e.currentTarget.querySelectorAll(`[role="treeitem"]:not([aria-disabled="true"])`)],c=s.indexOf(t),l;switch(e.key){case`ArrowDown`:l=s[c+1];break;case`ArrowUp`:l=s[c-1];break;case`Home`:l=s[0];break;case`End`:l=s.at(-1);break;case`ArrowRight`:a&&!o?r(n):o&&(l=s[c+1]);break;case`ArrowLeft`:o?r(n):l=t.parentElement?.closest(`[role="treeitem"]`)??void 0;break;case`Enter`:case` `:a?r(n):i(n);break;default:return}e.preventDefault(),e.stopPropagation(),l?.focus()},children:(0,D.jsx)(R,{path:e,depth:1,tree:n})})}var B=4,V=8,H=360;function U(e,t){let n=t?.split(`/`).slice(0,-1)??[],r=n.map((e,t)=>n.slice(0,t+1).join(`/`));return new Set(r.filter(t=>e===``||t.startsWith(`${e}/`)))}function W({anchor:e,segment:t,sessionId:n,levels:r,selected:a,onOpen:o,onDismiss:s}){let c=(0,C.useRef)(null),[l,f]=(0,C.useState)(()=>U(t.path,a)),[m,h]=(0,C.useState)();(0,C.useLayoutEffect)(()=>{let t=c.current,n=e.getBoundingClientRect(),r=n.bottom+B,i=Math.max(V,Math.min(n.left,window.innerWidth-t.offsetWidth-V));h({top:r,left:i,maxHeight:Math.min(H,Math.max(160,window.innerHeight-r-V))}),u(t)},[e]),(0,C.useEffect)(()=>{let t=t=>{t.target instanceof Node&&(c.current?.contains(t.target)||e.contains(t.target))||s()},n=t=>{if(t.key!==`Escape`||t.isComposing||t.defaultPrevented||t.ctrlKey||t.altKey||t.metaKey||t.shiftKey)return;t.preventDefault(),t.stopPropagation();let n=c.current?.contains(document.activeElement)||document.activeElement===document.body||document.activeElement===e;s(),n&&u(e)};return window.addEventListener(`pointerdown`,t,!0),window.addEventListener(`resize`,s),document.addEventListener(`keydown`,n,!0),()=>{window.removeEventListener(`pointerdown`,t,!0),window.removeEventListener(`resize`,s),document.removeEventListener(`keydown`,n,!0)}},[e,s]);let g=e=>f(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),_=i(`${t.name} 中的文件`,`Files in ${t.name}`),{maxHeight:v,...y}=m??{visibility:`hidden`,top:0,left:0};return(0,M.createPortal)((0,D.jsx)(d,{ref:c,role:`dialog`,"aria-label":_,tabIndex:-1,className:p.crumbMenu,style:y,onKeyDown:e=>{e.target===c.current&&e.key===`ArrowDown`&&(e.preventDefault(),c.current.querySelector(`[role="treeitem"]:not([aria-disabled="true"])`)?.focus())},children:(0,D.jsx)(`div`,{className:p.crumbMenuScroll,style:{maxHeight:v},children:(0,D.jsx)(z,{root:t.path,label:_,sessionId:n,levels:r,revision:0,compact:!0,expanded:l,selected:a,toggle:g,open:e=>{s(),o(e)}})})}),document.body)}function G({sessionId:e,cwd:t,path:n,levels:r,onOpen:a}){let[o,s]=(0,C.useState)(null),c=`${t}\0${n??``}`,l=o?.target===c?o:null,u=n?.split(`/`)??[],d=u.length?u.at(-1):void 0,f=[{name:t.split(/[\\/]/u).filter(Boolean).at(-1)??t,path:``,title:t},...u.slice(0,-1).map((e,t)=>{let n=u.slice(0,t+1).join(`/`);return{name:e,path:n,title:n}})],m=(0,C.useRef)(()=>s(null)).current;return(0,D.jsxs)(`nav`,{className:p.crumbs,"aria-label":i(`文件路径`,`File path`),children:[(0,D.jsxs)(`ol`,{children:[f.map((e,t)=>(0,D.jsxs)(`li`,{children:[t>0&&(0,D.jsx)(`span`,{className:p.crumbSeparator,"aria-hidden":`true`,children:`/`}),(0,D.jsx)(`button`,{type:`button`,className:p.crumb,title:e.title,"aria-haspopup":`dialog`,"aria-expanded":l?.segment.path===e.path,onClick:t=>{let n=t.currentTarget;s(t=>t?.target===c&&t.segment.path===e.path?null:{segment:e,anchor:n,target:c})},children:e.name})]},e.path)),d&&(0,D.jsxs)(`li`,{className:p.crumbFile,children:[(0,D.jsx)(`span`,{className:p.crumbSeparator,"aria-hidden":`true`,children:`/`}),(0,D.jsx)(`span`,{className:p.crumbCurrent,title:n,"aria-current":`page`,children:d})]})]}),l&&(0,D.jsx)(W,{anchor:l.anchor,segment:l.segment,sessionId:e,levels:r,selected:n,onOpen:a,onDismiss:m},l.segment.path)]})}function K(e){return e.startsWith(`?`)?{mode:`content`,text:e.slice(1).trim()}:{mode:`name`,text:e.trim()}}function q(e,t){let n=e.toLowerCase().indexOf(t.toLowerCase());return!t||n<0?e:(0,D.jsxs)(D.Fragment,{children:[e.slice(0,n),(0,D.jsx)(`mark`,{className:p.match,children:e.slice(n,n+t.length)}),e.slice(n+t.length)]})}function J(e,t){if(e.key!==`ArrowDown`&&e.key!==`ArrowUp`)return;let n=[...e.currentTarget.querySelectorAll(`button[data-search-result]`)],r=n.indexOf(document.activeElement),i=e.key===`ArrowDown`?n[r+1]:r<=0?t:n[r-1];i&&(e.preventDefault(),i.focus())}function Y({sessionId:e,query:t,input:n,onOpen:r}){let{mode:a,text:o}=K(t),[s,c]=(0,C.useState)(null),[l,u]=(0,C.useState)(`idle`);if((0,C.useEffect)(()=>{if(!o||a===`content`&&o.length<2){c(null),u(`idle`);return}let t=new AbortController;u(`loading`);let n=window.setTimeout(()=>{E.search(e,o,a,t.signal).then(e=>{t.signal.aborted||(c(e),u(`idle`))}).catch(()=>{t.signal.aborted||u(`error`)})},a===`content`?300:150);return()=>{t.abort(),window.clearTimeout(n)}},[e,a,o]),!o||a===`content`&&o.length<2)return a===`content`?(0,D.jsx)(`p`,{className:p.state,children:i(`输入至少 2 个字符,在文件内容中搜索。`,`Type at least 2 characters to search file contents.`)}):null;if(l===`error`)return(0,D.jsx)(`p`,{className:p.state,role:`status`,children:i(`搜索失败,请重试。`,`Search failed. Try again.`)});if(!s||s.kind!==a)return(0,D.jsx)(`p`,{className:p.state,role:`status`,children:i(`正在搜索…`,`Searching…`)});if(!s.results.length)return(0,D.jsx)(`p`,{className:p.state,role:`status`,children:i(`没有匹配的结果。`,`No matches.`)});let d=s.truncated&&(0,D.jsx)(`p`,{className:p.state,children:i(`结果太多,只显示一部分。请输入更具体的内容。`,`Showing some results only. Type something more specific.`)});if(s.kind===`name`)return(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`ul`,{className:p.results,"aria-label":i(`匹配的文件`,`Matching files`),onKeyDown:e=>J(e,n),children:s.results.map(({path:e})=>{let t=e.lastIndexOf(`/`);return(0,D.jsx)(`li`,{children:(0,D.jsxs)(`button`,{type:`button`,"data-search-result":!0,className:p.result,title:e,onClick:()=>r(e),children:[(0,D.jsx)(f,{path:e,size:16}),(0,D.jsx)(`span`,{className:p.name,children:q(e.slice(t+1),o)}),t>0&&(0,D.jsx)(`span`,{className:p.resultDirectory,children:e.slice(0,t)})]})},e)})}),d]});let m=new Map;for(let e of s.results)m.set(e.path,[...m.get(e.path)??[],e]);return(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`ul`,{className:p.results,"aria-label":i(`内容匹配`,`Content matches`),onKeyDown:e=>J(e,n),children:[...m].map(([e,t])=>(0,D.jsxs)(`li`,{children:[(0,D.jsxs)(`div`,{className:p.resultFile,title:e,children:[(0,D.jsx)(f,{path:e,size:14}),(0,D.jsx)(`span`,{className:p.name,children:e}),(0,D.jsx)(`span`,{className:p.resultCount,children:t.length})]}),(0,D.jsx)(`ul`,{children:t.map(t=>(0,D.jsx)(`li`,{children:(0,D.jsxs)(`button`,{type:`button`,"data-search-result":!0,className:p.resultLine,"aria-label":i(`${e} 第 ${t.line} 行:${t.text}`,`${e} line ${t.line}: ${t.text}`),onClick:()=>r(e,t.line),children:[(0,D.jsx)(`span`,{className:p.lineNumber,children:t.line}),(0,D.jsx)(`span`,{className:p.lineText,children:q(t.text,o)})]})},t.line))})]},e))}),d]})}var X=()=>({expanded:new Set,levels:new Map,scrollTop:0,selected:null,treeOpen:!0,query:``,status:P}),ne=420;function Z({open:e,controls:t,onToggle:n}){let r=e?i(`隐藏文件目录`,`Hide file tree`):i(`显示文件目录`,`Show file tree`);return(0,D.jsx)(`button`,{type:`button`,className:`${p.iconButton} ${p.treeToggle}`,"aria-label":r,title:r,"aria-expanded":e,"aria-controls":t,onClick:n,children:(0,D.jsx)(_,{})})}var Q=(0,C.memo)(function({sessionId:e,cwd:t,idle:n,state:r,renderMarkdown:a}){let[o,s]=(0,C.useState)(()=>new Set(r.expanded)),[l,u]=(0,C.useState)(()=>r.selected),[d,f]=(0,C.useState)(r.treeOpen),[m,h]=(0,C.useState)(0),[_,y]=(0,C.useState)(!1),[b,x]=(0,C.useState)(r.query),[S,w]=(0,C.useState)(r.status),[T,O]=(0,C.useState)(),[k,ee]=(0,C.useState)(null),A=(0,C.useRef)(null),te=(0,C.useRef)(!1),M=(0,C.useCallback)(e=>{te.current=e},[]),N=(0,C.useRef)(null),P=(0,C.useCallback)(()=>{N.current?.abort();let t=new AbortController;N.current=t,E.status(e,t.signal).then(e=>{if(t.signal.aborted)return;let n=F(e);r.status=n,w(n)}).catch(()=>{})},[e,r]);(0,C.useEffect)(()=>(P(),()=>N.current?.abort()),[P]);let I=(0,C.useCallback)(()=>{h(e=>e+1),P()},[P]),L=(0,C.useRef)(n);(0,C.useEffect)(()=>{n&&!L.current&&I(),L.current=n},[n,I]);let R=P,B=e=>{r.query=e,x(e)},V=`files-tree-${e}`,H=l?.cwd===t?l.path:void 0,U=(0,C.useCallback)(e=>{e&&(e.scrollTop=r.scrollTop)},[r]);(0,C.useLayoutEffect)(()=>{let e=A.current;if(!e)return;let t=()=>y(e.clientWidth<ne);t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let W=e=>s(t=>{let n=e(t);return r.expanded=n,n}),K=e=>W(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),q=e=>{r.treeOpen=e,f(e)},J=(e,n)=>{if(e!==H&&te.current&&!window.confirm(i(`放弃未保存的更改?`,`Discard unsaved changes?`)))return;O(n?{line:n}:void 0);let a={cwd:t,path:e};r.selected=a,u(a);let o=e.split(`/`).slice(0,-1);o.length&&W(e=>{let t=o.map((e,t)=>o.slice(0,t+1).join(`/`));return t.every(t=>e.has(t))?e:new Set([...e,...t])}),_&&q(!1)},X=(0,D.jsx)(G,{sessionId:e,cwd:t,path:H,levels:r.levels,onOpen:J}),Q=!d&&(0,D.jsx)(Z,{open:!1,controls:V,onToggle:()=>q(!0)});return(0,D.jsxs)(`div`,{ref:A,className:p.files,"data-narrow":_||void 0,"data-tree-open":d||void 0,children:[(0,D.jsx)(`div`,{className:p.filesMain,children:H?(0,D.jsx)(j,{sessionId:e,path:H,renderMarkdown:a,breadcrumb:X,trailing:Q,refresh:m,reveal:T,onDirtyChange:M,onSaved:R},H):(0,D.jsxs)(`div`,{className:p.body,children:[(0,D.jsxs)(`div`,{className:p.toolbar,children:[X,Q]}),(0,D.jsxs)(`div`,{className:p.emptyFile,children:[(0,D.jsx)(c,{size:28,className:p.emptyFileIcon}),(0,D.jsx)(`p`,{className:p.emptyFileTitle,children:i(`打开的文件显示在这里`,`Open files appear here`)}),(0,D.jsx)(`p`,{className:p.emptyFileHint,children:i(`请在目录树中选择一个文件,或在对话中点击文件路径。`,`Choose a file in the tree, or click a file path in the chat.`)})]})]})}),d&&(0,D.jsxs)(`aside`,{id:V,className:p.filesSide,"aria-label":i(`文件目录`,`File tree`),children:[(0,D.jsxs)(`div`,{className:p.toolbar,children:[(0,D.jsxs)(`label`,{className:p.search,title:t,children:[(0,D.jsx)(g,{}),(0,D.jsx)(`input`,{ref:ee,type:`search`,value:b,placeholder:i(`筛选,或输入 ? 在文件中搜索`,`Filter, or type ? to search in files`),"aria-label":i(`筛选文件,或以 ? 开头在文件内容中搜索`,`Filter files, or start with ? to search file contents`),onChange:e=>B(e.target.value),onKeyDown:e=>{if(e.key===`Escape`&&b)e.preventDefault(),e.stopPropagation(),B(``);else if(e.key===`Enter`||e.key===`ArrowDown`){let t=e.currentTarget.closest(`aside`)?.querySelector(`button[data-search-result]`);if(!t)return;e.preventDefault(),e.key===`Enter`?t.click():t.focus()}}})]}),(0,D.jsx)(`button`,{type:`button`,className:p.iconButton,"aria-label":i(`重新读取文件列表`,`Reload files`),title:i(`重新读取文件列表`,`Reload files`),onClick:I,children:(0,D.jsx)(v,{})}),(0,D.jsx)(Z,{open:!0,controls:V,onToggle:()=>q(!1)})]}),b.trim()?(0,D.jsx)(`div`,{className:p.scroll,children:(0,D.jsx)(Y,{sessionId:e,query:b,input:k,onOpen:J},m)}):(0,D.jsx)(`div`,{ref:U,className:p.scroll,onScroll:e=>{r.scrollTop=e.currentTarget.scrollTop},children:(0,D.jsx)(z,{root:``,label:i(`工作区文件`,`Workspace files`),sessionId:e,levels:r.levels,revision:m,expanded:o,selected:H,status:S,toggle:K,open:J})})]})]})});function $({sessionId:e,cwd:t,path:n,levels:r,renderMarkdown:i,open:a}){let o=(0,C.useRef)(a);(0,C.useLayoutEffect)(()=>{o.current=a});let s=(0,C.useCallback)(e=>o.current(e),[]),c=(0,C.useMemo)(()=>(0,D.jsx)(G,{sessionId:e,cwd:t,path:n,levels:r,onOpen:s}),[e,t,n,r,s]);return(0,D.jsx)(j,{sessionId:e,path:n,renderMarkdown:i,breadcrumb:c})}var re=o({id:S.id,apiVersion:1,activate(){},workbench:{apiVersion:1,entry:{label:S.name,panelTitle:{zh:`文件`,en:`Files`},description:{zh:`浏览当前会话的文件并打开预览`,en:`Browse this session’s files and open previews`},kind:`files`,icon:({size:e})=>(0,D.jsx)(f,{kind:`folder`,size:e})},panels:[{kind:`files`,component:e=>(0,D.jsx)(Q,{sessionId:e.session.sessionId,cwd:e.session.cwd,idle:e.session.idle,state:e.resource(X),renderMarkdown:e.renderMarkdown})},{kind:`file-preview`,title:(e,t)=>(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(f,{path:e,size:16}),(0,D.jsx)(`span`,{children:t})]}),component:e=>(0,D.jsx)($,{sessionId:e.session.sessionId,cwd:e.session.cwd,path:e.contentId,renderMarkdown:e.renderMarkdown,levels:e.resource(()=>new Map),open:t=>e.open(`file-preview`,t,t.split(`/`).at(-1))})}]}});export{re as default};
6
- //# debugId=5401c0ca-a76c-4ca6-ab71-a847200db27d