@vantran-se/openchamber-web 1.22.1 → 1.22.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.
- package/README.md +2 -3
- package/bin/cli.js +4 -1
- package/bin/cli.test.js +92 -0
- package/bin/lib/cli-startup.js +49 -0
- package/bin/lib/commands-startup.js +41 -6
- package/dist/assets/{CodeMirrorCommentWidgets-C53Q7pbX.js → CodeMirrorCommentWidgets-CV1HNV5l.js} +1 -1
- package/dist/assets/{DiffView-Dh1ey2x9.js → DiffView-DkkSa30n.js} +3 -3
- package/dist/assets/DirtyBranchSwitchDialog-DW4WaXPc.js +1 -0
- package/dist/assets/FilesView-DDu8zDy5.js +17 -0
- package/dist/assets/GitView-1Ixo8z-M.js +6 -0
- package/dist/assets/{JsonTreeView-Bl0lp9Rs.js → JsonTreeView-DvCLL7dT.js} +1 -1
- package/dist/assets/LinearIssuesView-Bs1rZrF2.js +1 -0
- package/dist/assets/{MarkdownImageGallery-bA0PS-tn.js → MarkdownImageGallery-DyJUc6h9.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-Bdm8vMkS.js +12 -0
- package/dist/assets/{OnboardingScreen-D3kYJIb6.js → OnboardingScreen-Dg66B6oB.js} +1 -1
- package/dist/assets/{PatchDiff-D6NXAfJk.js → PatchDiff-CAduNjfZ.js} +1 -1
- package/dist/assets/{PierreDiffViewer-Ct2A13NO.js → PierreDiffViewer-CTIb1GYD.js} +2 -2
- package/dist/assets/PlanView-trDaszfq.js +5 -0
- package/dist/assets/SettingsView-DStMfBmy.js +28 -0
- package/dist/assets/{SettingsWindow-BiWDBRvb.js → SettingsWindow-DQQFnrSZ.js} +1 -1
- package/dist/assets/{ToolOutputDialog-BQexMQIm.js → ToolOutputDialog-SjY2XZlA.js} +6 -6
- package/dist/assets/ToolPartDiffPreview-DJdzUQPE.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-Dpz2ra8h.js → VirtualizedFileDiff-Iehm4iMH.js} +1 -1
- package/dist/assets/{WalkthroughView-AX-u2pFg.js → WalkthroughView-BALp2d9O.js} +2 -2
- package/dist/assets/{computeVirtualFileMetrics-DtyozJdt.js → computeVirtualFileMetrics-BKZA43vN.js} +2 -2
- package/dist/assets/{contextPanelEmbeddedChat-C9EcRSDF.js → contextPanelEmbeddedChat-D2PM_pEv.js} +1 -1
- package/dist/assets/{de-DqVn5vme.js → de-DlSNLAcy.js} +6 -5
- package/dist/assets/{es-hj43Z53i.js → es-D1GbowZ3.js} +6 -5
- package/dist/assets/{fr-BmkZt2mF.js → fr-BPOLXIAY.js} +6 -5
- package/dist/assets/{index-DmhujXbT.js → index-Ce0LR32V.js} +1 -1
- package/dist/assets/index-D42fPvt4.css +1 -0
- package/dist/assets/index-DlFbCkEy.js +39 -0
- package/dist/assets/{isDiffPlainText-XyulMHxx.js → isDiffPlainText-DaB2u_Kv.js} +1 -1
- package/dist/assets/{isFilePlainText-B19Ddps1.js → isFilePlainText-yJZa2IAC.js} +1 -1
- package/dist/assets/{ja-DioMIEGF.js → ja-Dm2-m9io.js} +7 -6
- package/dist/assets/{ko-BqPgaQJb.js → ko-CIXlzQ5-.js} +7 -6
- package/dist/assets/main-B7qTsd_w.js +930 -0
- package/dist/assets/{main-B2a_JfKZ.js → main-CyQrD9dG.js} +2 -2
- package/dist/assets/{markdownCore-CWRCqSH2.js → markdownCore-CeEwGgEK.js} +2 -2
- package/dist/assets/{miniChat-B3CSU_Ps.js → miniChat-7cPEx4sV.js} +2 -2
- package/dist/assets/{mobile-QNcFIVCW.js → mobile-QtzkPTM8.js} +2 -2
- package/dist/assets/{patchFileDiff-BpMQZnYu.js → patchFileDiff-No55fDiD.js} +1 -1
- package/dist/assets/pl-B2zmkOpw.js +16 -0
- package/dist/assets/{pt-BR-BqH8fuCH.js → pt-BR-C-JE5H6y.js} +6 -5
- package/dist/assets/{renderElectronMiniChatApp-D77bmLqo.js → renderElectronMiniChatApp-ePTkBJNS.js} +2 -2
- package/dist/assets/renderMobileApp-D9RjB9DX.js +25 -0
- package/dist/assets/runtimeEndpointReset-DfJIWwwo.js +17 -0
- package/dist/assets/{scheduledTasksApi-BSRCtP6T.js → scheduledTasksApi-DuhdyYEa.js} +1 -1
- package/dist/assets/{shikiHighlight-DE-OwqGw.js → shikiHighlight-EHEg58-n.js} +1 -1
- package/dist/assets/tr-MJmRIzEY.js +7 -0
- package/dist/assets/{uk-BkkfxbOs.js → uk-BmD7eM8k.js} +6 -5
- package/dist/assets/{useAppFontEffects-COAeIX-D.js → useAppFontEffects-CuJPKtI1.js} +151 -180
- package/dist/assets/useInlineCommentController-DD7_7OP_.js +2 -0
- package/dist/assets/{useRootScrollLock-C0N9mCwz.js → useRootScrollLock-DRGAe8PN.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-BG3v1Ghq.js → vendor-codemirror-language-data-9ZzoH0o0.js} +2 -2
- package/dist/assets/vendor-zod-CK21ihK-.js +39 -0
- package/dist/assets/{web-components-BNMwa0qm.js → web-components-PttKBrhi.js} +1 -1
- package/dist/assets/{zh-CN-C6FMdVgv.js → zh-CN-JJHl4ehT.js} +6 -5
- package/dist/assets/{zh-TW-CdcMjDxv.js → zh-TW-DPc4DEEW.js} +6 -5
- package/dist/index.html +5 -5
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +8 -4
- package/server/index.js +38 -5
- package/server/lib/agent-tool/runtime.js +2 -19
- package/server/lib/changelog/update-notes.js +82 -0
- package/server/lib/changelog/update-notes.test.js +59 -0
- package/server/lib/dev-tunnel/DOCUMENTATION.md +13 -4
- package/server/lib/dev-tunnel/runtime.js +4 -4
- package/server/lib/dev-tunnel/tunnel.test.js +20 -0
- package/server/lib/fs/DOCUMENTATION.md +2 -0
- package/server/lib/fs/routes.js +32 -21
- package/server/lib/fs/routes.test.js +77 -0
- package/server/lib/git/DOCUMENTATION.md +3 -1
- package/server/lib/git/routes.js +16 -0
- package/server/lib/git/service.js +107 -17
- package/server/lib/git/service.test.js +171 -0
- package/server/lib/mcp-reconnect/DOCUMENTATION.md +55 -0
- package/server/lib/mcp-reconnect/runtime.js +122 -0
- package/server/lib/mcp-reconnect/runtime.test.js +140 -0
- package/server/lib/message-queue/DOCUMENTATION.md +158 -0
- package/server/lib/message-queue/runtime.js +870 -0
- package/server/lib/message-queue/runtime.test.js +482 -0
- package/server/lib/openchamber-sessions/routes.js +102 -0
- package/server/lib/openchamber-sessions/routes.test.js +88 -0
- package/server/lib/opencode/DOCUMENTATION.md +13 -5
- package/server/lib/opencode/config-paths.test.js +116 -0
- package/server/lib/opencode/core-routes.js +1 -0
- package/server/lib/opencode/feature-routes-runtime.js +5 -0
- package/server/lib/opencode/input-history-scope.js +14 -0
- package/server/lib/opencode/managed-plugin-config.js +35 -0
- package/server/lib/opencode/openchamber-routes.test.js +2 -2
- package/server/lib/opencode/plugins.js +2 -2
- package/server/lib/opencode/providers.js +44 -2
- package/server/lib/opencode/providers.test.js +131 -4
- package/server/lib/opencode/routes.js +4 -4
- package/server/lib/opencode/server-startup-runtime.js +1 -1
- package/server/lib/opencode/settings-helpers.js +28 -0
- package/server/lib/opencode/settings-helpers.test.js +177 -0
- package/server/lib/opencode/settings-runtime.js +2 -2
- package/server/lib/opencode/settings-runtime.test.js +29 -0
- package/server/lib/opencode/shared.js +4 -1
- package/server/lib/opencode/shutdown-runtime.js +2 -0
- package/server/lib/opencode/skill-routes.js +2 -1
- package/server/lib/opencode/snippets.js +1 -2
- package/server/lib/package-manager.js +4 -29
- package/server/lib/package-manager.test.js +2 -2
- package/server/lib/quota/DOCUMENTATION.md +2 -1
- package/server/lib/quota/credentials/providers.js +4 -0
- package/server/lib/quota/credentials/store.js +1 -1
- package/server/lib/quota/credentials/store.test.js +4 -4
- package/server/lib/quota/providers/exe-dev.js +75 -0
- package/server/lib/quota/providers/exe-dev.test.js +47 -0
- package/server/lib/quota/providers/index.js +7 -0
- package/server/lib/quota/providers/opencode-go.js +1 -0
- package/server/lib/quota/providers/opencode-go.test.js +5 -1
- package/server/lib/quota/routes.js +2 -0
- package/server/lib/quota/utils/auth.js +1 -1
- package/server/lib/relay/DOCUMENTATION.md +1 -1
- package/server/lib/relay/host-client.test.js +9 -1
- package/server/lib/relay/tunnel-host.js +3 -1
- package/server/lib/relay/tunnel-host.test.js +9 -1
- package/server/lib/security/request-security.js +21 -6
- package/server/lib/security/request-security.test.js +42 -8
- package/server/lib/session-assist/runtime.js +1 -0
- package/server/lib/session-goal/DOCUMENTATION.md +20 -7
- package/server/lib/session-goal/create.js +3 -1
- package/server/lib/session-goal/runtime.js +77 -11
- package/server/lib/session-goal/runtime.test.js +426 -0
- package/server/lib/skills-catalog/DOCUMENTATION.md +1 -1
- package/server/lib/skills-catalog/install.js +3 -2
- package/server/lib/small-model/DOCUMENTATION.md +4 -0
- package/server/lib/small-model/call.js +8 -2
- package/server/lib/small-model/call.test.js +23 -0
- package/server/lib/small-model/index.js +2 -1
- package/server/lib/small-model/routes.js +2 -1
- package/server/lib/system-prompt/runtime.js +2 -21
- package/server/lib/terminal/DOCUMENTATION.md +11 -7
- package/server/lib/terminal/runtime.js +180 -26
- package/server/lib/terminal/runtime.test.js +553 -26
- package/server/lib/terminal/shells.js +17 -0
- package/server/lib/terminal/shells.test.js +32 -1
- package/server/lib/ui-auth/ui-auth.js +4 -1
- package/server/lib/ui-auth/ui-auth.test.js +16 -0
- package/server/lib/walkthrough/index.js +1 -0
- package/server/lib/walkthrough/routes.test.js +26 -5
- package/dist/assets/CommitSection-X-f2RgYr.js +0 -1
- package/dist/assets/FilesView-3ZYP72ki.js +0 -17
- package/dist/assets/GitView-CMuN7z2Z.js +0 -6
- package/dist/assets/LinearIssuesView-CQiUDU8b.js +0 -1
- package/dist/assets/MarkdownRendererImpl-BGQi2PLq.js +0 -12
- package/dist/assets/PlanView-6AUjzNQn.js +0 -5
- package/dist/assets/SettingsView-CHI8fFaK.js +0 -28
- package/dist/assets/ToolPartDiffPreview-DPAATNn6.js +0 -8
- package/dist/assets/index-L_ncV-6H.css +0 -1
- package/dist/assets/index-qES19dlJ.js +0 -7
- package/dist/assets/main-CYgSu6dx.js +0 -928
- package/dist/assets/pl-slULBF4R.js +0 -15
- package/dist/assets/renderMobileApp-BQ3Kdm-d.js +0 -25
- package/dist/assets/runtimeEndpointReset-CRGn1gVj.js +0 -16
- package/dist/assets/tr-CjEbw1Aw.js +0 -6
- package/dist/assets/useInlineCommentController-JsBboQwt.js +0 -2
- package/dist/assets/vendor-zod-BLfBSgBh.js +0 -39
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{R as N,j as T,c as xe,r as a}from"./vendor-react-BUCujlKS.js";import{a as Be}from"./web-components-
|
|
1
|
+
import{R as N,j as T,c as xe,r as a}from"./vendor-react-BUCujlKS.js";import{a as Be}from"./web-components-PttKBrhi.js";import{f as Te}from"./computeVirtualFileMetrics-BKZA43vN.js";import{V as je,F as Oe}from"./VirtualizedFileDiff-Iehm4iMH.js";import{V as De}from"./Virtualizer-D_a8gKmg.js";import{ea as Ve,eb as Ce,b7 as Ue,c0 as Ge,h as Pe}from"./useAppFontEffects-CuJPKtI1.js";import{I as Ae,a as Ke,u as _e}from"./useInlineCommentController-DD7_7OP_.js";import"./index-DlFbCkEy.js";import{a6 as Ye}from"./runtimeEndpointReset-DfJIWwwo.js";import{ensurePierreThemeRegistered as Fe,getResolvedShikiTheme as Ie}from"./appThemeRegistry-BK0dHKa6.js";const he=r=>{if(r.type==="new"){const t=Math.min(r.selection.start,r.selection.end),i=Math.max(r.selection.start,r.selection.end);return`new-comment-${r.selection.side??"additions"}-${t}-${i}`}return`draft-${r.draft.id}`},Xe=r=>{const{drafts:t,editingDraftId:i,selection:o}=r,l=[];for(const g of t){if(!Number.isFinite(g.endLine))continue;const E=Math.max(1,Math.floor(g.endLine)),C=g.side==="original"?"deletions":"additions";l.push({lineNumber:E,side:C,metadata:{type:g.id===i?"edit":"saved",draft:g}})}return o&&!i&&l.push({lineNumber:Math.max(o.start,o.end),side:o.side??"additions",metadata:{type:"new",selection:o}}),l};function Je(r){const t=r.trim();if(!t)return null;if(/^-?\d+(\.\d+)?$/.test(t)){const i=Number.parseFloat(t);return Number.isFinite(i)?i:null}if(t.endsWith("px")){const i=Number.parseFloat(t.slice(0,-2));return Number.isFinite(i)?i:null}return null}function ze(r){if(!(!r||r<=0))return Math.max(200,Math.floor(r))}function Qe(r){const{diffRootRef:t,drafts:i,selection:o,editingDraftId:l,commentText:g,onTextChange:E,fileLabel:C,onSave:u,onCancel:q,onEdit:P,onDelete:O}=r,[U,oe]=N.useState(0),[se,Q]=N.useState(null),w=N.useMemo(()=>!o||l?null:he({type:"new",selection:o}),[l,o]),H=N.useMemo(()=>{const c=i.map(b=>he({type:b.id===l?"edit":"saved",draft:b}));return w&&c.push(w),c},[i,l,w]),D=N.useCallback(c=>{const b=t.current;if(!b)return null;const R=b.querySelector("diffs-container");if(!(R instanceof HTMLElement))return null;const S=R.querySelector(`[data-annotation-id="${c}"]`);if(S instanceof HTMLElement)return S;const $=R.shadowRoot;return $?$.querySelector(`[data-annotation-id="${c}"]`):null},[t]);N.useEffect(()=>{if(H.length===0)return;let c=!1,b=0;const R=12,S=()=>{c||H.every(A=>!!D(A))||b>=R||(b+=1,requestAnimationFrame(()=>{c||(oe(A=>A+1),S())}))};return S(),()=>{c=!0}},[H,D]),N.useEffect(()=>{const c=t.current;if(!c)return;const b=()=>{const S=getComputedStyle(c),$=Je(S.getPropertyValue("--oc-context-panel-width")),A=c.getBoundingClientRect(),F=$??A.width;Q(F>0?F:null)};b();const R=new ResizeObserver(()=>{b()});return R.observe(c),window.addEventListener("resize",b),()=>{R.disconnect(),window.removeEventListener("resize",b)}},[t]);const I=N.useCallback(c=>{const R=t.current?.getBoundingClientRect(),S=c.closest("[data-annotation-content]"),$=S instanceof HTMLElement?S.getBoundingClientRect():c.getBoundingClientRect(),A=[$.width];R&&A.push(R.right-$.left);const F=A.filter(V=>Number.isFinite(V)&&V>0);return F.length>0?ze(Math.min(...F)):ze(se)},[t,se]);return T.jsxs(T.Fragment,{children:[i.map(c=>{const b=he({type:c.id===l?"edit":"saved",draft:c}),R=D(b);if(!R)return null;const S=I(R);return c.id===l?xe.createPortal(T.jsx(Ae,{initialText:g,onTextChange:E,fileLabel:C,lineRange:{start:c.startLine,end:c.endLine,side:c.side==="original"?"deletions":"additions"},isEditing:!0,onSave:u,onCancel:q,maxWidth:S}),R,`draft-edit-${c.id}`):xe.createPortal(T.jsx(Ke,{draft:c,onEdit:()=>P(c),onDelete:()=>O(c),maxWidth:S}),R,`draft-card-${c.id}`)}),o&&!l&&w&&(()=>{const c=D(w);if(!c)return null;const b=I(c);return xe.createPortal(T.jsx(Ae,{initialText:g,onTextChange:E,fileLabel:C,lineRange:o,isEditing:!1,onSave:u,onCancel:q,maxWidth:b}),c,w)})()]})}const qe=5e5,Ze=`
|
|
2
2
|
:host {
|
|
3
3
|
font-family: var(--font-mono);
|
|
4
4
|
font-size: var(--text-code);
|
|
@@ -154,4 +154,4 @@ import{R as N,j as T,c as xe,r as a}from"./vendor-react-BUCujlKS.js";import{a as
|
|
|
154
154
|
}
|
|
155
155
|
`;function tt(r){let t=2166136261;for(let i=0;i<r.length;i+=1)t^=r.charCodeAt(i),t=t+((t<<1)+(t<<4)+(t<<7)+(t<<8)+(t<<24))>>>0;return t.toString(16)}function He(r){const t=r.length>400?`${r.slice(0,200)}${r.slice(-200)}`:r;return`${r.length}:${tt(t)}`}const nt=(r,t,i,o)=>{const l=o.side==="deletions",E=(i?(l?i.deletionLines:i.additionLines).join(""):l?r:t).split(`
|
|
156
156
|
`),C=Math.min(o.start,o.end),u=Math.max(o.start,o.end),q=Math.max(1,C),P=Math.min(E.length,u);return q>P?"":E.slice(q-1,P).join(`
|
|
157
|
-
`)},rt=(r,t)=>r===t?!0:!r||!t?!1:r.start===t.start&&r.end===t.end&&r.side===t.side,it=r=>r==="auto"||r==="scroll"||r==="overlay",ot=r=>{let t=r?.parentElement??null;for(;t;){const i=window.getComputedStyle(t);if(it(i.overflowY))return t;t=t.parentElement}return null},st=(r,t)=>{if(!r||!t||typeof window>"u")return()=>{};const i=ot(r);if(!i)return()=>{};const o=t.getBoundingClientRect().height;if(!o)return()=>{};const l=r.getBoundingClientRect().top-i.getBoundingClientRect().top,g=t.style.minHeight;t.style.minHeight=`${Math.ceil(o)}px`;let E=!1;return()=>{if(E)return;E=!0,t.style.minHeight=g;const u=r.getBoundingClientRect().top-i.getBoundingClientRect().top-l;u&&(i.scrollTop+=u)}},at=(r,t)=>{if(typeof window>"u")return()=>{};let i=null,o=null,l=!1;const g=()=>{l||(o?.disconnect(),o=null,i=window.requestAnimationFrame(()=>{i=window.requestAnimationFrame(()=>{l||t()})}))},E=()=>r.querySelector("diffs-container")?.shadowRoot??void 0,C=(u=E())=>!!u?.querySelector("[data-line]");return C()?g():typeof MutationObserver<"u"?(o=new MutationObserver(()=>{const u=E();if(u){if(C(u)){g();return}o?.disconnect(),o=new MutationObserver(()=>{C(u)&&g()}),o.observe(u,{childList:!0,subtree:!0})}}),o.observe(r,{childList:!0,subtree:!0})):i=window.requestAnimationFrame(g),()=>{l=!0,o?.disconnect(),i!==null&&window.cancelAnimationFrame(i)}},fe=new WeakMap,lt={lineHeight:24,hunkSeparatorHeight:24,spacing:0};function ct(r){const t=r.closest("[data-diff-virtual-root]");if(t instanceof HTMLElement){const i=t.querySelector("[data-diff-virtual-content]");return{key:t,root:t,content:i instanceof HTMLElement?i:void 0}}return{key:document,root:document,content:void 0}}function dt(r){if(typeof document>"u")return null;const t=ct(r);let i=fe.get(t.key);if(!i){const l=new De;l.setup(t.root,t.content),i={virtualizer:l,refs:0},fe.set(t.key,i)}i.refs+=1;let o=!1;return{virtualizer:i.virtualizer,root:t.root,release:()=>{if(o)return;o=!0;const l=fe.get(t.key);l&&(l.refs-=1,!(l.refs>0)&&(l.virtualizer.cleanUp(),fe.delete(t.key)))}}}const ut=(r,t,i)=>{if(typeof window>"u")return()=>{};const o=[],l=()=>{try{r.rerender()}catch{}const g=t?.root;g instanceof HTMLElement?g.dispatchEvent(new Event("scroll",{bubbles:!1})):document.dispatchEvent(new Event("scroll",{bubbles:!1})),window.dispatchEvent(new Event("resize")),i()};return o.push(window.requestAnimationFrame(l)),o.push(window.requestAnimationFrame(()=>{o.push(window.requestAnimationFrame(l))})),()=>{for(const g of o)window.cancelAnimationFrame(g)}},xt=({original:r,modified:t,fileDiff:i,language:o,fileName:l,renderSideBySide:g,wrapLines:E,layout:C="fill",enableComments:u=!0})=>{const q=Ve(),P=q?.currentTheme.metadata.variant==="dark",O=q?.availableThemes.find(e=>e.metadata.id===q.lightThemeId)??Ae(!1),U=q?.availableThemes.find(e=>e.metadata.id===q.darkThemeId)??Ae(!0),{isMobile:oe}=Ue(),se=_e({source:"diff",fileLabel:l||"unknown",language:o,getCodeForRange:e=>nt(r,t,i,e),toStoreRange:e=>({startLine:e.start,endLine:e.end,side:e.side==="deletions"?"original":"modified"}),fromDraftRange:e=>({start:e.startLine,end:e.endLine,side:e.side==="original"?"deletions":"additions"})}),{drafts:Q,selection:w,setSelection:H,commentText:D,setCommentText:I,editingDraftId:c,saveComment:b,cancel:R,startEdit:S,deleteDraft:$}=se,A=a.useRef(null),F=a.useRef(null),V=a.useRef(""),W=a.useRef(!1),ae=a.useRef(null);a.useEffect(()=>{A.current=w},[w]),a.useEffect(()=>{F.current=c},[c]),a.useEffect(()=>{V.current=D},[D]);const le=a.useCallback(e=>{if(!u||W.current)return;const n=A.current;if(!(!e&&n&&V.current.trim())){if(oe&&n&&e&&e.side===n.side){const s=Math.min(n.start,e.start),d=Math.max(n.end,e.end);H({...e,start:s,end:d})}else H(e);e&&(F.current||I(""))}},[u,oe,I,H]),$e=a.useCallback(()=>{R()},[R]),ke=a.useCallback(e=>{const n=document.createElement("div");n.style.position="relative";const s=he(e.metadata);return n.dataset.annotationId=s,n.dataset.annotationSide=e.side,n.dataset.annotationLine=String(e.lineNumber),n},[]),Ne=a.useCallback((e,n)=>{b(e,n??w??void 0)},[b,w]),G=a.useCallback(e=>{H(e);const n=z.current;if(n)try{W.current=!0,n.setSelectedLines(e),ae.current=e}catch{}finally{W.current=!1}},[H]),Z=a.useRef(null),me=a.useRef(null);a.useEffect(()=>{if(!u)return;const e=Y.current;if(!e)return;const n=()=>{const f=e.querySelector("diffs-container");return f instanceof HTMLElement?f.shadowRoot:null},s=f=>{const p=e.querySelector("diffs-container");p instanceof HTMLElement&&(f?p.setAttribute("data-oc-comment-drag",""):p.removeAttribute("data-oc-comment-drag"))},d=(f,p)=>{const re=n()?.elementFromPoint(f,p)??document.elementFromPoint(f,p);if(!(re instanceof Element))return null;const we=!!re.closest("[data-column-number]"),ie=re.closest("[data-line]");if(!(ie instanceof HTMLElement))return null;const Re=Number.parseInt(ie.getAttribute("data-line")??"",10);if(!Number.isFinite(Re)||Re<=0)return null;const We=ie.getAttribute("data-line-type")==="change-deletion"||ie.closest("[data-code][data-deletions]")!=null?"deletions":"additions";return{line:Re,side:We,numberColumn:we}};let h=null,m=!1,y=null;const k=f=>{Z.current=f;const p=z.current;if(p)try{W.current=!0,p.setSelectedLines(f)}catch{}finally{W.current=!1}},L=f=>{if(f.button!==0||f.pointerType!=="mouse")return;const p=d(f.clientX,f.clientY);if(!p||p.numberColumn){h=null;return}h={line:p.line,side:p.side},m=!1,y=f.pointerId},M=f=>{if(h==null||f.pointerId!==y)return;const p=d(f.clientX,f.clientY);if(p){if(!m){if(p.line===h.line)return;m=!0,s(!0),window.getSelection()?.removeAllRanges();const v=n();v&&"getSelection"in v&&v.getSelection()?.removeAllRanges()}k({start:Math.min(h.line,p.line),end:Math.max(h.line,p.line),side:h.side})}},x=f=>{if(h==null||f.pointerId!==y)return;const p=m;if(h=null,m=!1,y=null,s(!1),!p)return;const v=Z.current;Z.current=null,v&&(A.current&&V.current.trim()&&!F.current||(G(v),F.current||I("")))};return e.addEventListener("pointerdown",L),document.addEventListener("pointermove",M,{passive:!0}),document.addEventListener("pointerup",x),()=>{e.removeEventListener("pointerdown",L),document.removeEventListener("pointermove",M),document.removeEventListener("pointerup",x),s(!1)}},[G,u,I]);const Le=a.useCallback(e=>{if(!u)return;const n=Z.current,s=n&&e.start>=n.start&&e.end<=n.end&&(e.side==null||e.side===n.side);me.current!==null&&(window.clearTimeout(me.current),me.current=null),Z.current=null,G(s&&n?n:e),F.current||I("")},[G,u,I]),Ee=a.useCallback(e=>{if(!u||e.numberColumn||window.getSelection()?.toString().trim())return;const n=e.annotationSide,s={start:e.lineNumber,end:e.lineNumber,side:n},d=A.current;if(d&&d.start===s.start&&d.end===s.end&&d.side===s.side){if(!V.current.trim()){H(null);const h=z.current;try{W.current=!0,h?.setSelectedLines(null)}finally{W.current=!1}}return}d&&V.current.trim()&&!F.current||(G(s),F.current||I(""))},[G,u,I,H]),Se=a.useCallback(e=>{const n=e.closest("[data-line-type]")?.getAttribute("data-line-type")??e.getAttribute("data-line-type");if(n==="change-deletion")return"deletions";if(n==="change-addition")return"additions";const s=e.getAttribute("data-column-side")??e.getAttribute("data-side")??e.closest("[data-column-side]")?.getAttribute("data-column-side");if(s==="deletions"||s==="left"||s==="original")return"deletions";if(s==="additions"||s==="right"||s==="modified")return"additions";const d=e.closest("[data-line-type]");if(d instanceof HTMLElement){const h=d.getBoundingClientRect(),m=e.getBoundingClientRect(),y=h.left+h.width/2;return m.left+m.width/2<y?"deletions":"additions"}return"additions"},[]);Fe(O),Fe(U);const _=`${O.metadata.id}:${U.metadata.id}:${P?"dark":"light"}`,ee=a.useMemo(()=>{if(i){const e=i.deletionLines.reduce((s,d)=>s+d.length,0),n=i.additionLines.reduce((s,d)=>s+d.length,0);return Math.max(e,n)>qe}return Math.max(r.length,t.length)>qe},[i,t.length,r.length]),Y=a.useRef(null),X=a.useRef(null),z=a.useRef(null),te=a.useRef(null),pe=a.useRef(null),ge=a.useRef(null),ye=a.useRef(void 0),ce=a.useRef(void 0),de=a.useRef(void 0),ue=a.useRef(void 0),[,ve]=N.useReducer(e=>e+1,0),J=Ye(ee?"unified":g?"split":"unified"),B=a.useMemo(()=>Ie(O),[O]),j=a.useMemo(()=>Ie(U),[U]);N.useLayoutEffect(()=>{const e=Y.current;if(!e)return;const n=e.querySelector("diffs-container");if(!n)return;const s=P?j:B,d=(re,we)=>re.colors?.[we],h=d(B,"terminal.ansiGreen"),m=d(B,"terminal.ansiRed"),y=d(B,"terminal.ansiBlue"),k=d(j,"terminal.ansiGreen"),L=d(j,"terminal.ansiRed"),M=d(j,"terminal.ansiBlue");n.style.setProperty("--shiki-light",B.fg),n.style.setProperty("--shiki-light-bg",B.bg),h&&n.style.setProperty("--shiki-light-addition-color",h),m&&n.style.setProperty("--shiki-light-deletion-color",m),y&&n.style.setProperty("--shiki-light-modified-color",y),n.style.setProperty("--shiki-dark",j.fg),n.style.setProperty("--shiki-dark-bg",j.bg),k&&n.style.setProperty("--shiki-dark-addition-color",k),L&&n.style.setProperty("--shiki-dark-deletion-color",L),M&&n.style.setProperty("--shiki-dark-modified-color",M),n.style.setProperty("--diffs-bg",s.bg),n.style.setProperty("--diffs-fg",s.fg);const x=P?k:h,f=P?L:m,p=P?M:y;x&&n.style.setProperty("--diffs-addition-color-override",x),f&&n.style.setProperty("--diffs-deletion-color-override",f),p&&n.style.setProperty("--diffs-modified-color-override",p);const v=n.shadowRoot?.querySelector("pre");v&&(v.style.setProperty("--shiki-light",B.fg),v.style.setProperty("--shiki-light-bg",B.bg),h&&v.style.setProperty("--shiki-light-addition-color",h),m&&v.style.setProperty("--shiki-light-deletion-color",m),y&&v.style.setProperty("--shiki-light-modified-color",y),v.style.setProperty("--shiki-dark",j.fg),v.style.setProperty("--shiki-dark-bg",j.bg),k&&v.style.setProperty("--shiki-dark-addition-color",k),L&&v.style.setProperty("--shiki-dark-deletion-color",L),M&&v.style.setProperty("--shiki-dark-modified-color",M),v.style.setProperty("--diffs-bg",s.bg),v.style.setProperty("--diffs-fg",s.fg),x&&v.style.setProperty("--diffs-addition-color-override",x),f&&v.style.setProperty("--diffs-deletion-color-override",f),p&&v.style.setProperty("--diffs-modified-color-override",p))},[j,_,P,B]);const K=a.useMemo(()=>({theme:{dark:U.metadata.id,light:O.metadata.id},themeType:P?"dark":"light",diffStyle:g?"split":"unified",diffIndicators:"none",hunkSeparators:"line-info-basic",lineDiffType:"none",maxLineDiffLength:ee?0:1e3,maxLineLengthForHighlighting:ee?1:1e3,tokenizeMaxLineLength:ee?1:1e3,collapsedContextThreshold:0,expansionLineCount:20,overflow:E?"wrap":"scroll",disableFileHeader:!0,enableLineSelection:u,enableGutterUtility:u,onGutterUtilityClick:u?Le:void 0,onLineClick:u?Ee:void 0,onLineSelected:u?le:void 0,unsafeCSS:et,renderAnnotation:u?ke:void 0}),[U.metadata.id,u,P,ee,O.metadata.id,g,E,le,Le,Ee,ke]),ne=a.useMemo(()=>u?Xe({drafts:Q,editingDraftId:c,selection:w}):[],[c,u,Q,w]),be=a.useRef(ne);if(a.useEffect(()=>{be.current=ne},[ne]),a.useEffect(()=>{const e=X.current;return()=>{z.current?.cleanUp(),z.current=null,te.current?.release(),te.current=null,pe.current=null,ge.current=null,ye.current=void 0,ce.current=void 0,de.current=void 0,ue.current=void 0,e&&(e.innerHTML="")}},[]),a.useEffect(()=>{if(typeof window>"u")return;const e=X.current,n=Y.current;if(!e||!J)return;const s=st(n,e);let d=te.current;d||(d=dt(e),te.current=d),te.current=d;const h=d?.virtualizer??null,m=i?void 0:{name:l||"",contents:r,lang:o,cacheKey:`old:${_}:${l}:${He(r)}`},y=i?void 0:{name:l||"",contents:t,lang:o,cacheKey:`new:${_}:${l}:${He(t)}`},k=i?ce.current!==i:ce.current!==void 0||!m||!y||!de.current||!ue.current||!Te(de.current,m)||!Te(ue.current,y),L=z.current,M=!!(L&&(pe.current!==h||ge.current!==J||h&&(ye.current!==K.hunkSeparators||k)));M&&(L?.cleanUp(),z.current=null,e.innerHTML="");let x=z.current;const f=!M&&L?!Be(L.options,K):!1;if(x?x.setOptions(K):(x=d?new je(K,d.virtualizer,lt,J):new Oe(K,J),z.current=x,ae.current=null),pe.current=h,ge.current=J,ye.current=h?K.hunkSeparators:void 0,ce.current=i,de.current=m,ue.current=y,i)x.render({fileDiff:i,forceRender:f,lineAnnotations:be.current,containerWrapper:e});else{if(!m||!y)return;x.render({oldFile:m,newFile:y,forceRender:f,lineAnnotations:be.current,containerWrapper:e})}const p=at(e,()=>{s(),ut(x,d,ve)});return()=>{p(),s()}},[_,i,l,o,t,K,r,J]),a.useEffect(()=>{const e=z.current;if(e){try{e.setLineAnnotations(ne)}catch(n){console.error("Failed to apply diff line annotations",n);try{e.setLineAnnotations([])}catch{}}requestAnimationFrame(()=>{if(z.current===e){try{e.rerender()}catch{}ve()}})}},[ne]),a.useEffect(()=>{const e=z.current;if(!e||w!==null)return;const n=ae.current;if(!rt(w,n))try{W.current=!0,e.setSelectedLines(w),ae.current=w}catch{}finally{W.current=!1}},[w]),a.useEffect(()=>{if(!u)return;const e=X.current;if(!e)return;let n=null,s=()=>{};const d=()=>{const m=e.querySelector("diffs-container")?.shadowRoot;if(!m){n=requestAnimationFrame(d);return}const y=k=>{if(!(k instanceof MouseEvent)||k.button!==0||!(k.target instanceof Element))return;const L=k.target.closest("[data-column-number]");if(!(L instanceof HTMLElement))return;const M=L.getAttribute("data-column-number"),x=M?parseInt(M,10):NaN;if(Number.isNaN(x))return;const f=Se(L);le({start:x,end:x,side:f}),k.preventDefault(),k.stopPropagation()};m.addEventListener("click",y,!0),s=()=>{m.removeEventListener("click",y,!0)}};return d(),()=>{n!==null&&cancelAnimationFrame(n),s()}},[_,u,l,le,Se]),a.useEffect(()=>{const e=X.current;if(!e)return;let n=null,s=null;const h=setTimeout(()=>{const m=e.querySelector("diffs-container");if(!(m instanceof HTMLElement))return;const y=m.shadowRoot;n=new MutationObserver(()=>{s&&cancelAnimationFrame(s),s=requestAnimationFrame(()=>{ve(),s=null})}),n.observe(m,{childList:!0,subtree:!0}),y&&n.observe(y,{childList:!0,subtree:!0})},100);return()=>{clearTimeout(h),s&&cancelAnimationFrame(s),n?.disconnect()}},[_,l]),typeof window>"u")return null;const Me=u?T.jsx(Qe,{diffRootRef:Y,drafts:Q,selection:w,editingDraftId:c,commentText:D,onTextChange:I,fileLabel:l?.split("/").pop()??"",onSave:Ne,onCancel:$e,onEdit:e=>{G({start:e.startLine,end:e.endLine,side:e.side==="original"?"deletions":"additions"}),S(e)},onDelete:$}):null;return C==="fill"?T.jsx("div",{className:Ce("flex flex-col relative","size-full"),"data-diff-virtual-root":!0,children:T.jsxs("div",{className:"flex-1 relative min-h-0",children:[T.jsx(Ge,{outerClassName:"pierre-diff-wrapper size-full",disableHorizontal:!1,fillContainer:!0,"data-diff-virtual-content":!0,children:T.jsx("div",{ref:Y,className:"size-full relative",children:T.jsx("div",{ref:X,className:"size-full"})})}),Me]})}):T.jsxs("div",{className:Ce("relative","w-full"),children:[T.jsx("div",{ref:Y,className:"pierre-diff-wrapper w-full overflow-x-auto overflow-y-visible relative",children:T.jsx("div",{ref:X,className:"w-full"})}),Me]})};export{xt as P};
|
|
157
|
+
`)},rt=(r,t)=>r===t?!0:!r||!t?!1:r.start===t.start&&r.end===t.end&&r.side===t.side,it=r=>r==="auto"||r==="scroll"||r==="overlay",ot=r=>{let t=r?.parentElement??null;for(;t;){const i=window.getComputedStyle(t);if(it(i.overflowY))return t;t=t.parentElement}return null},st=(r,t)=>{if(!r||!t||typeof window>"u")return()=>{};const i=ot(r);if(!i)return()=>{};const o=t.getBoundingClientRect().height;if(!o)return()=>{};const l=r.getBoundingClientRect().top-i.getBoundingClientRect().top,g=t.style.minHeight;t.style.minHeight=`${Math.ceil(o)}px`;let E=!1;return()=>{if(E)return;E=!0,t.style.minHeight=g;const u=r.getBoundingClientRect().top-i.getBoundingClientRect().top-l;u&&(i.scrollTop+=u)}},at=(r,t)=>{if(typeof window>"u")return()=>{};let i=null,o=null,l=!1;const g=()=>{l||(o?.disconnect(),o=null,i=window.requestAnimationFrame(()=>{i=window.requestAnimationFrame(()=>{l||t()})}))},E=()=>r.querySelector("diffs-container")?.shadowRoot??void 0,C=(u=E())=>!!u?.querySelector("[data-line]");return C()?g():typeof MutationObserver<"u"?(o=new MutationObserver(()=>{const u=E();if(u){if(C(u)){g();return}o?.disconnect(),o=new MutationObserver(()=>{C(u)&&g()}),o.observe(u,{childList:!0,subtree:!0})}}),o.observe(r,{childList:!0,subtree:!0})):i=window.requestAnimationFrame(g),()=>{l=!0,o?.disconnect(),i!==null&&window.cancelAnimationFrame(i)}},fe=new WeakMap,lt={lineHeight:24,hunkSeparatorHeight:24,spacing:0};function ct(r){const t=r.closest("[data-diff-virtual-root]");if(t instanceof HTMLElement){const i=t.querySelector("[data-diff-virtual-content]");return{key:t,root:t,content:i instanceof HTMLElement?i:void 0}}return{key:document,root:document,content:void 0}}function dt(r){if(typeof document>"u")return null;const t=ct(r);let i=fe.get(t.key);if(!i){const l=new De;l.setup(t.root,t.content),i={virtualizer:l,refs:0},fe.set(t.key,i)}i.refs+=1;let o=!1;return{virtualizer:i.virtualizer,root:t.root,release:()=>{if(o)return;o=!0;const l=fe.get(t.key);l&&(l.refs-=1,!(l.refs>0)&&(l.virtualizer.cleanUp(),fe.delete(t.key)))}}}const ut=(r,t,i)=>{if(typeof window>"u")return()=>{};const o=[],l=()=>{try{r.rerender()}catch{}const g=t?.root;g instanceof HTMLElement?g.dispatchEvent(new Event("scroll",{bubbles:!1})):document.dispatchEvent(new Event("scroll",{bubbles:!1})),window.dispatchEvent(new Event("resize")),i()};return o.push(window.requestAnimationFrame(l)),o.push(window.requestAnimationFrame(()=>{o.push(window.requestAnimationFrame(l))})),()=>{for(const g of o)window.cancelAnimationFrame(g)}},xt=({original:r,modified:t,fileDiff:i,language:o,fileName:l,renderSideBySide:g,wrapLines:E,layout:C="fill",enableComments:u=!0})=>{const q=Ve(),P=q?.currentTheme.metadata.variant==="dark",O=q?.availableThemes.find(e=>e.metadata.id===q.lightThemeId)??Ce(!1),U=q?.availableThemes.find(e=>e.metadata.id===q.darkThemeId)??Ce(!0),{isMobile:oe}=Ue(),se=_e({source:"diff",fileLabel:l||"unknown",language:o,getCodeForRange:e=>nt(r,t,i,e),toStoreRange:e=>({startLine:e.start,endLine:e.end,side:e.side==="deletions"?"original":"modified"}),fromDraftRange:e=>({start:e.startLine,end:e.endLine,side:e.side==="original"?"deletions":"additions"})}),{drafts:Q,selection:w,setSelection:H,commentText:D,setCommentText:I,editingDraftId:c,saveComment:b,cancel:R,startEdit:S,deleteDraft:$}=se,A=a.useRef(null),F=a.useRef(null),V=a.useRef(""),W=a.useRef(!1),ae=a.useRef(null);a.useEffect(()=>{A.current=w},[w]),a.useEffect(()=>{F.current=c},[c]),a.useEffect(()=>{V.current=D},[D]);const le=a.useCallback(e=>{if(!u||W.current)return;const n=A.current;if(!(!e&&n&&V.current.trim())){if(oe&&n&&e&&e.side===n.side){const s=Math.min(n.start,e.start),d=Math.max(n.end,e.end);H({...e,start:s,end:d})}else H(e);e&&(F.current||I(""))}},[u,oe,I,H]),$e=a.useCallback(()=>{R()},[R]),ke=a.useCallback(e=>{const n=document.createElement("div");n.style.position="relative";const s=he(e.metadata);return n.dataset.annotationId=s,n.dataset.annotationSide=e.side,n.dataset.annotationLine=String(e.lineNumber),n},[]),Ne=a.useCallback((e,n)=>{b(e,n??w??void 0)},[b,w]),G=a.useCallback(e=>{H(e);const n=z.current;if(n)try{W.current=!0,n.setSelectedLines(e),ae.current=e}catch{}finally{W.current=!1}},[H]),Z=a.useRef(null),me=a.useRef(null);a.useEffect(()=>{if(!u)return;const e=Y.current;if(!e)return;const n=()=>{const f=e.querySelector("diffs-container");return f instanceof HTMLElement?f.shadowRoot:null},s=f=>{const p=e.querySelector("diffs-container");p instanceof HTMLElement&&(f?p.setAttribute("data-oc-comment-drag",""):p.removeAttribute("data-oc-comment-drag"))},d=(f,p)=>{const re=n()?.elementFromPoint(f,p)??document.elementFromPoint(f,p);if(!(re instanceof Element))return null;const we=!!re.closest("[data-column-number]"),ie=re.closest("[data-line]");if(!(ie instanceof HTMLElement))return null;const Re=Number.parseInt(ie.getAttribute("data-line")??"",10);if(!Number.isFinite(Re)||Re<=0)return null;const We=ie.getAttribute("data-line-type")==="change-deletion"||ie.closest("[data-code][data-deletions]")!=null?"deletions":"additions";return{line:Re,side:We,numberColumn:we}};let h=null,m=!1,y=null;const k=f=>{Z.current=f;const p=z.current;if(p)try{W.current=!0,p.setSelectedLines(f)}catch{}finally{W.current=!1}},L=f=>{if(f.button!==0||f.pointerType!=="mouse")return;const p=d(f.clientX,f.clientY);if(!p||p.numberColumn){h=null;return}h={line:p.line,side:p.side},m=!1,y=f.pointerId},M=f=>{if(h==null||f.pointerId!==y)return;const p=d(f.clientX,f.clientY);if(p){if(!m){if(p.line===h.line)return;m=!0,s(!0),window.getSelection()?.removeAllRanges();const v=n();v&&"getSelection"in v&&v.getSelection()?.removeAllRanges()}k({start:Math.min(h.line,p.line),end:Math.max(h.line,p.line),side:h.side})}},x=f=>{if(h==null||f.pointerId!==y)return;const p=m;if(h=null,m=!1,y=null,s(!1),!p)return;const v=Z.current;Z.current=null,v&&(A.current&&V.current.trim()&&!F.current||(G(v),F.current||I("")))};return e.addEventListener("pointerdown",L),document.addEventListener("pointermove",M,{passive:!0}),document.addEventListener("pointerup",x),()=>{e.removeEventListener("pointerdown",L),document.removeEventListener("pointermove",M),document.removeEventListener("pointerup",x),s(!1)}},[G,u,I]);const Le=a.useCallback(e=>{if(!u)return;const n=Z.current,s=n&&e.start>=n.start&&e.end<=n.end&&(e.side==null||e.side===n.side);me.current!==null&&(window.clearTimeout(me.current),me.current=null),Z.current=null,G(s&&n?n:e),F.current||I("")},[G,u,I]),Ee=a.useCallback(e=>{if(!u||e.numberColumn||window.getSelection()?.toString().trim())return;const n=e.annotationSide,s={start:e.lineNumber,end:e.lineNumber,side:n},d=A.current;if(d&&d.start===s.start&&d.end===s.end&&d.side===s.side){if(!V.current.trim()){H(null);const h=z.current;try{W.current=!0,h?.setSelectedLines(null)}finally{W.current=!1}}return}d&&V.current.trim()&&!F.current||(G(s),F.current||I(""))},[G,u,I,H]),Se=a.useCallback(e=>{const n=e.closest("[data-line-type]")?.getAttribute("data-line-type")??e.getAttribute("data-line-type");if(n==="change-deletion")return"deletions";if(n==="change-addition")return"additions";const s=e.getAttribute("data-column-side")??e.getAttribute("data-side")??e.closest("[data-column-side]")?.getAttribute("data-column-side");if(s==="deletions"||s==="left"||s==="original")return"deletions";if(s==="additions"||s==="right"||s==="modified")return"additions";const d=e.closest("[data-line-type]");if(d instanceof HTMLElement){const h=d.getBoundingClientRect(),m=e.getBoundingClientRect(),y=h.left+h.width/2;return m.left+m.width/2<y?"deletions":"additions"}return"additions"},[]);Fe(O),Fe(U);const _=`${O.metadata.id}:${U.metadata.id}:${P?"dark":"light"}`,ee=a.useMemo(()=>{if(i){const e=i.deletionLines.reduce((s,d)=>s+d.length,0),n=i.additionLines.reduce((s,d)=>s+d.length,0);return Math.max(e,n)>qe}return Math.max(r.length,t.length)>qe},[i,t.length,r.length]),Y=a.useRef(null),X=a.useRef(null),z=a.useRef(null),te=a.useRef(null),pe=a.useRef(null),ge=a.useRef(null),ye=a.useRef(void 0),ce=a.useRef(void 0),de=a.useRef(void 0),ue=a.useRef(void 0),[,ve]=N.useReducer(e=>e+1,0),J=Ye(ee?"unified":g?"split":"unified"),B=a.useMemo(()=>Ie(O),[O]),j=a.useMemo(()=>Ie(U),[U]);N.useLayoutEffect(()=>{const e=Y.current;if(!e)return;const n=e.querySelector("diffs-container");if(!n)return;const s=P?j:B,d=(re,we)=>re.colors?.[we],h=d(B,"terminal.ansiGreen"),m=d(B,"terminal.ansiRed"),y=d(B,"terminal.ansiBlue"),k=d(j,"terminal.ansiGreen"),L=d(j,"terminal.ansiRed"),M=d(j,"terminal.ansiBlue");n.style.setProperty("--shiki-light",B.fg),n.style.setProperty("--shiki-light-bg",B.bg),h&&n.style.setProperty("--shiki-light-addition-color",h),m&&n.style.setProperty("--shiki-light-deletion-color",m),y&&n.style.setProperty("--shiki-light-modified-color",y),n.style.setProperty("--shiki-dark",j.fg),n.style.setProperty("--shiki-dark-bg",j.bg),k&&n.style.setProperty("--shiki-dark-addition-color",k),L&&n.style.setProperty("--shiki-dark-deletion-color",L),M&&n.style.setProperty("--shiki-dark-modified-color",M),n.style.setProperty("--diffs-bg",s.bg),n.style.setProperty("--diffs-fg",s.fg);const x=P?k:h,f=P?L:m,p=P?M:y;x&&n.style.setProperty("--diffs-addition-color-override",x),f&&n.style.setProperty("--diffs-deletion-color-override",f),p&&n.style.setProperty("--diffs-modified-color-override",p);const v=n.shadowRoot?.querySelector("pre");v&&(v.style.setProperty("--shiki-light",B.fg),v.style.setProperty("--shiki-light-bg",B.bg),h&&v.style.setProperty("--shiki-light-addition-color",h),m&&v.style.setProperty("--shiki-light-deletion-color",m),y&&v.style.setProperty("--shiki-light-modified-color",y),v.style.setProperty("--shiki-dark",j.fg),v.style.setProperty("--shiki-dark-bg",j.bg),k&&v.style.setProperty("--shiki-dark-addition-color",k),L&&v.style.setProperty("--shiki-dark-deletion-color",L),M&&v.style.setProperty("--shiki-dark-modified-color",M),v.style.setProperty("--diffs-bg",s.bg),v.style.setProperty("--diffs-fg",s.fg),x&&v.style.setProperty("--diffs-addition-color-override",x),f&&v.style.setProperty("--diffs-deletion-color-override",f),p&&v.style.setProperty("--diffs-modified-color-override",p))},[j,_,P,B]);const K=a.useMemo(()=>({theme:{dark:U.metadata.id,light:O.metadata.id},themeType:P?"dark":"light",diffStyle:g?"split":"unified",diffIndicators:"none",hunkSeparators:"line-info-basic",lineDiffType:"none",maxLineDiffLength:ee?0:1e3,maxLineLengthForHighlighting:ee?1:1e3,tokenizeMaxLineLength:ee?1:1e3,collapsedContextThreshold:0,expansionLineCount:20,overflow:E?"wrap":"scroll",disableFileHeader:!0,enableLineSelection:u,enableGutterUtility:u,onGutterUtilityClick:u?Le:void 0,onLineClick:u?Ee:void 0,onLineSelected:u?le:void 0,unsafeCSS:et,renderAnnotation:u?ke:void 0}),[U.metadata.id,u,P,ee,O.metadata.id,g,E,le,Le,Ee,ke]),ne=a.useMemo(()=>u?Xe({drafts:Q,editingDraftId:c,selection:w}):[],[c,u,Q,w]),be=a.useRef(ne);if(a.useEffect(()=>{be.current=ne},[ne]),a.useEffect(()=>{const e=X.current;return()=>{z.current?.cleanUp(),z.current=null,te.current?.release(),te.current=null,pe.current=null,ge.current=null,ye.current=void 0,ce.current=void 0,de.current=void 0,ue.current=void 0,e&&(e.innerHTML="")}},[]),a.useEffect(()=>{if(typeof window>"u")return;const e=X.current,n=Y.current;if(!e||!J)return;const s=st(n,e);let d=te.current;d||(d=dt(e),te.current=d),te.current=d;const h=d?.virtualizer??null,m=i?void 0:{name:l||"",contents:r,lang:o,cacheKey:`old:${_}:${l}:${He(r)}`},y=i?void 0:{name:l||"",contents:t,lang:o,cacheKey:`new:${_}:${l}:${He(t)}`},k=i?ce.current!==i:ce.current!==void 0||!m||!y||!de.current||!ue.current||!Te(de.current,m)||!Te(ue.current,y),L=z.current,M=!!(L&&(pe.current!==h||ge.current!==J||h&&(ye.current!==K.hunkSeparators||k)));M&&(L?.cleanUp(),z.current=null,e.innerHTML="");let x=z.current;const f=!M&&L?!Be(L.options,K):!1;if(x?x.setOptions(K):(x=d?new je(K,d.virtualizer,lt,J):new Oe(K,J),z.current=x,ae.current=null),pe.current=h,ge.current=J,ye.current=h?K.hunkSeparators:void 0,ce.current=i,de.current=m,ue.current=y,i)x.render({fileDiff:i,forceRender:f,lineAnnotations:be.current,containerWrapper:e});else{if(!m||!y)return;x.render({oldFile:m,newFile:y,forceRender:f,lineAnnotations:be.current,containerWrapper:e})}const p=at(e,()=>{s(),ut(x,d,ve)});return()=>{p(),s()}},[_,i,l,o,t,K,r,J]),a.useEffect(()=>{const e=z.current;if(e){try{e.setLineAnnotations(ne)}catch(n){console.error("Failed to apply diff line annotations",n);try{e.setLineAnnotations([])}catch{}}requestAnimationFrame(()=>{if(z.current===e){try{e.rerender()}catch{}ve()}})}},[ne]),a.useEffect(()=>{const e=z.current;if(!e||w!==null)return;const n=ae.current;if(!rt(w,n))try{W.current=!0,e.setSelectedLines(w),ae.current=w}catch{}finally{W.current=!1}},[w]),a.useEffect(()=>{if(!u)return;const e=X.current;if(!e)return;let n=null,s=()=>{};const d=()=>{const m=e.querySelector("diffs-container")?.shadowRoot;if(!m){n=requestAnimationFrame(d);return}const y=k=>{if(!(k instanceof MouseEvent)||k.button!==0||!(k.target instanceof Element))return;const L=k.target.closest("[data-column-number]");if(!(L instanceof HTMLElement))return;const M=L.getAttribute("data-column-number"),x=M?parseInt(M,10):NaN;if(Number.isNaN(x))return;const f=Se(L);le({start:x,end:x,side:f}),k.preventDefault(),k.stopPropagation()};m.addEventListener("click",y,!0),s=()=>{m.removeEventListener("click",y,!0)}};return d(),()=>{n!==null&&cancelAnimationFrame(n),s()}},[_,u,l,le,Se]),a.useEffect(()=>{const e=X.current;if(!e)return;let n=null,s=null;const h=setTimeout(()=>{const m=e.querySelector("diffs-container");if(!(m instanceof HTMLElement))return;const y=m.shadowRoot;n=new MutationObserver(()=>{s&&cancelAnimationFrame(s),s=requestAnimationFrame(()=>{ve(),s=null})}),n.observe(m,{childList:!0,subtree:!0}),y&&n.observe(y,{childList:!0,subtree:!0})},100);return()=>{clearTimeout(h),s&&cancelAnimationFrame(s),n?.disconnect()}},[_,l]),typeof window>"u")return null;const Me=u?T.jsx(Qe,{diffRootRef:Y,drafts:Q,selection:w,editingDraftId:c,commentText:D,onTextChange:I,fileLabel:l?.split("/").pop()??"",onSave:Ne,onCancel:$e,onEdit:e=>{G({start:e.startLine,end:e.endLine,side:e.side==="original"?"deletions":"additions"}),S(e)},onDelete:$}):null;return C==="fill"?T.jsx("div",{className:Pe("flex flex-col relative","size-full"),"data-diff-virtual-root":!0,children:T.jsxs("div",{className:"flex-1 relative min-h-0",children:[T.jsx(Ge,{outerClassName:"pierre-diff-wrapper size-full",disableHorizontal:!1,fillContainer:!0,"data-diff-virtual-content":!0,children:T.jsx("div",{ref:Y,className:"size-full relative",children:T.jsx("div",{ref:X,className:"size-full"})})}),Me]})}):T.jsxs("div",{className:Pe("relative","w-full"),children:[T.jsx("div",{ref:Y,className:"pierre-diff-wrapper w-full overflow-x-auto overflow-y-visible relative",children:T.jsx("div",{ref:X,className:"w-full"})}),Me]})};export{xt as P};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{R as t,j as n}from"./vendor-react-BUCujlKS.js";import{m as xt,u as Ze,a as he,o as qe,r as Xe,v as jt}from"./index-DlFbCkEy.js";import{c as Ct,s as Rt,P as Pt,C as Mt}from"./shikiHighlight-EHEg58-n.js";import{f as Tt,y as H,c8 as kt,ax as Nt,b as et,ai as Et,ac as It,W as Dt,b7 as Vt,N as Ft,f5 as Lt,Z as At,g_ as Ot,l as tt,f4 as $t,ao as nt,ge as Kt,f2 as Wt,cV as rt,f7 as zt,f8 as _t,m as Bt,g$ as Gt,b6 as st,a7 as ge,a8 as we,b3 as it,B as ne,I as W,a9 as ve,b5 as ot,b2 as re,g as Jt,c0 as Ut,aq as Ht,bZ as Qt,h0 as Yt}from"./useAppFontEffects-CuJPKtI1.js";import{u as Zt,n as qt}from"./useInlineCommentController-DD7_7OP_.js";import{b as Xt}from"./CodeMirrorCommentWidgets-CV1HNV5l.js";import{getResolvedShikiTheme as en}from"./appThemeRegistry-BK0dHKa6.js";import{E as tn}from"./vendor-codemirror-view-CiLROUVV.js";import{a5 as nn}from"./runtimeEndpointReset-DfJIWwwo.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-zod-CK21ihK-.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-codemirror-state-C9awkmn-.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-codemirror-language-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-codemirror-search-BmS-GmcX.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-replit-codemirror-vim-B2DJlAhT.js";import"./vendor-replit-codemirror-vim-core-FHzKdNUS.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-BeMD8X_w.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-D2PM_pEv.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-framer-motion-livSKyyV.js";import"./vendor-motion-dom-D_o3BTI3.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-lang-javascript-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-codemirror-lang-json-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-9ZzoH0o0.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-legendapp-list-gg7YLRW7.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./registerCustomTheme-BBXUCRnG.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";const rn=()=>{const l=new Map,c=new Map;return{schedule:(o,s,f)=>{if(s<=(c.get(o)??Number.NEGATIVE_INFINITY))return l.get(o)??Promise.resolve();c.set(o,s);const g=(l.get(o)??Promise.resolve()).then(f,f);return l.set(o,g.catch(()=>{c.get(o)===s&&c.delete(o)})),g},pendingFor:async o=>{await l.get(o)},reset:o=>{c.delete(o)}}},b=l=>{if(!l)return"";const c=l.replace(/\\/g,"/");return c==="/"?"/":c.replace(/\/+$/,"")},Se=(l,c)=>{const o=b(l),s=c.replace(/\\/g,"/").replace(/^\/+/,"").replace(/\/+$/,"");return!o||o==="/"?`/${s}`:`${o}/${s}`},sn=(l,c,o)=>Se(Se(Se(l,".opencode"),"plans"),`${c}-${o}.md`),on=(l,c)=>`~/.opencode/plans/${l}-${c}.md`,an=(l,c)=>{const o=l.trim();return o.startsWith("~")?o==="~"?c||o:(o.startsWith("~/")||o.startsWith("~\\"))&&c?`${c}${o.slice(1)}`:o:o},ln=(l,c)=>{const o=b(c.currentDirectory),s=b(c.homeDirectory),f=b(l);return o&&f.startsWith(o+"/")?f.slice(o.length+1):s&&f===s?"~":s&&f.startsWith(s+"/")?`~${f.slice(s.length)}`:f},cn=(l,c,o)=>{const s=b(l.trim());if(!s)return null;const f=o?c.find(g=>g.id===o)??null:null;if(f?.path){const g=b(f.path);if(s===g||s.startsWith(`${g}/`))return{id:f.id,path:f.path}}const N=c.filter(g=>{const E=b(g.path);return s===E||s.startsWith(`${E}/`)}).sort((g,E)=>b(E.path).length-b(g.path).length)[0];return N?{id:N.id,path:N.path}:null},un=l=>jt(()=>l()),cs=({targetPath:l=null,savedProjectPlan:c=null,onNavigatedToChat:o})=>{const{t:s}=Tt(),f=H(e=>e.currentSessionId),N=H(e=>e.createSession),g=H(e=>e.initializeNewOpenChamberSession),E=H(e=>e.sendMessage),ye=H(e=>e.setCurrentSession),be=kt(),z=xt(e=>e.homeDirectory),xe=Nt(e=>e.planModeEnabled),je=et(e=>e.projects),Ce=et(e=>e.activeProjectId),Re=Et(e=>e.directories),Pe=It()??"",Me=Ze(e=>e.setSessionSwitcherOpen),_=Dt(),I=t.useSyncExternalStore(un,he,he),{isMobile:Te}=Vt(),{currentTheme:Q}=Ft(),S=t.useMemo(()=>f?be.find(e=>e.id===f)??null:null,[f,be]),R=t.useMemo(()=>{const e=typeof S?.directory=="string"?S.directory:"";return b(e||"")},[S?.directory]),ke=t.useMemo(()=>b(Pe||R),[Pe,R]),B=t.useMemo(()=>cn(ke,je,Ce),[Ce,ke,je]),se=c?.projectRef.id??null,ie=c?.projectRef.path??null,v=t.useMemo(()=>se&&ie?{id:se,path:ie}:null,[se,ie]),P=c?.planId??null,G=v&&P?JSON.stringify(["saved-plan",I,Lt(v),P]):null,L=v?.id===At,Y=t.useMemo(()=>{const e=v??B;return e?Re.get(e.path)?.isGitRepo===!0:!1},[B,Re,v]),[D,A]=t.useState(null),[Ne,Ee]=t.useState(!1),[p,M]=t.useState(null),[oe,ae]=t.useState(null),at=!!p||!!oe,le=t.useMemo(()=>!p||!R||!z?p:ln(p,{currentDirectory:R,homeDirectory:z}),[p,R,z]),[h,x]=t.useState(""),{isPlaying:Z,play:lt,stop:ct}=Ot(),ut=tt(e=>e.showMessageTTSButtons),[Ie,ce]=t.useState(null),[De,ue]=t.useState(null),de=t.useMemo(()=>le&&le.split("/").pop()||s("planView.file.defaultName"),[le,s]),me=t.useMemo(()=>h.trim()?$t(h,s("planView.title.default")).title:s("planView.title.default"),[h,s]),q=t.useMemo(()=>me.trim()||s("planView.title.default"),[me,s]),[dt,V]=t.useState(!1),[mt,Ve]=t.useState(!1),[X,Fe]=t.useState("edit"),J=t.useRef(null),[u,y]=t.useState(null),Le=t.useRef(null),pt=t.useRef(null),Ae="openchamber:plan:md-viewer-mode";t.useEffect(()=>{try{const e=localStorage.getItem(Ae);if(!e)return;const i=JSON.parse(e);(i==="preview"||i==="edit")&&Fe(i)}catch{}},[]);const ft=t.useCallback(e=>{Fe(e);try{localStorage.setItem(Ae,JSON.stringify(e))}catch{}},[]),O=t.useRef(!1),T=t.useRef(null),[Oe,$]=t.useState(!1);t.useEffect(()=>{const e=()=>{O.current=!1,T.current=null,$(!1)};return document.addEventListener("mouseup",e),()=>document.removeEventListener("mouseup",e)},[]);const ht=t.useCallback((e,i)=>{const a=e.split(`
|
|
2
|
+
`),r=Math.max(1,i.start),d=Math.min(a.length,i.end);return r>d?"":a.slice(r-1,d).join(`
|
|
3
|
+
`)},[]),gt=Zt({source:"plan",fileLabel:de,language:p&&nt(p)||"markdown",getCodeForRange:e=>ht(h,qt(e)),toStoreRange:e=>({startLine:e.start,endLine:e.end}),fromDraftRange:e=>({start:e.startLine,end:e.endLine})}),{drafts:$e,commentText:ee,setCommentText:Ke,editingDraftId:pe,setSelection:We,saveComment:ze,cancel:U,reset:_e,startEdit:Be,deleteDraft:Ge}=gt;t.useEffect(()=>{y(null),_e()},[h,_e]),t.useEffect(()=>{We(u)},[u,We]);const Je=t.useCallback(()=>{y(null),U()},[U]),Ue=t.useCallback((e,i)=>{i&&y(i),ze(e,i??u??void 0),y(null)},[u,ze]);t.useEffect(()=>{if(!u)return;const e=a=>{const r=a.target;r.closest('[data-comment-card="true"]')||r.closest('[data-comment-input="true"]')||r.closest(".oc-block-widget")||r.closest(".cm-gutterElement")||r.closest("[data-sonner-toast]")||r.closest("[data-sonner-toaster]")||ee.trim()||(y(null),U())},i=window.setTimeout(()=>{document.addEventListener("click",e)},100);return()=>{window.clearTimeout(i),document.removeEventListener("click",e)}},[U,ee,pe,Te,u]);const fe=Ze(e=>e.editorFontSize),wt=t.useMemo(()=>{const e=p?nt(p):null,i=!!e&&e!=="markdown",a=[Ct(Q,i?{syntaxColors:!1,fontSize:fe}:{fontSize:fe})],r=Kt(p||"plan.md");return r&&a.push(r),i&&e&&a.push(Rt({language:e,themeName:Q.metadata.id,theme:en(Q)})),a.push(tn.lineWrapping),a},[Q,p,fe]),j=t.useRef({key:null,target:null,content:"",editRevision:0,savedRevision:0,runtimeKey:""}),C=t.useState(rn)[0],He=t.useCallback(async(e,i)=>{if("filePath"in e){const r=_.files??qe()?.files;if(r?.writeFile){if(!(await r.writeFile(e.filePath,i))?.success)throw new Error("Plan file write failed");return}const d=await Xe("/api/fs/write",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e.filePath,content:i})});if(!d.ok)throw new Error(`Failed to write plan file (${d.status})`);return}if(!await Wt.getState().savePlan(e.projectRef,e.planId,i))throw new Error("Plan save rejected: the plan no longer exists")},[_.files]),Qe=t.useRef(He);Qe.current=He;const F=t.useCallback(()=>{const e=j.current;if(!e.key||!e.target||e.editRevision<=e.savedRevision)return;const i={key:e.key,target:e.target,content:e.content,revision:e.editRevision,runtimeKey:e.runtimeKey,write:Qe.current};C.schedule(i.key,i.revision,async()=>{if(he()!==i.runtimeKey)return;await i.write(i.target,i.content);const a=j.current;a.key===i.key&&(a.savedRevision=Math.max(a.savedRevision,i.revision),ce(null))}).catch(a=>{j.current.key===i.key&&ce(a instanceof Error?a.message:"Plan save failed")})},[C]);t.useEffect(()=>{if(!xe&&!l&&!P){F(),j.current={key:null,target:null,content:"",editRevision:0,savedRevision:0,runtimeKey:""},M(null),ae(null),x(""),V(!1);return}let e=!1;const i=async r=>{if(_.files?.readFile)return(await _.files.readFile(r))?.content??"";const d=qe()?.files;if(d?.readFile)return(await d.readFile(r,{optional:!0}))?.content??"";const m=await Xe(`/api/fs/read?path=${encodeURIComponent(r)}&optional=true`,{cache:"no-store"});if(!m.ok)throw new Error(`Failed to read plan file (${m.status})`);return m.text()};return(async()=>{if(F(),j.current={key:null,target:null,content:"",editRevision:0,savedRevision:0,runtimeKey:""},M(null),ae(null),x(""),ce(null),ue(null),P&&v&&G){if(await C.pendingFor(G),e)return;C.reset(G),V(!0);try{const r=await Yt(v,P);if(e)return;if(!r){ue("Plan not found");return}j.current={key:G,target:{projectRef:v,planId:P},content:r.raw,editRevision:0,savedRevision:0,runtimeKey:I},x(r.raw),ae(P)}catch(r){if(e)return;ue(r instanceof Error?r.message:"Plan load failed")}finally{e||V(!1)}return}if(l){const r=JSON.stringify(["plan-file",I,l]);if(await C.pendingFor(r),e)return;C.reset(r),V(!0);try{const d=await i(l);if(e)return;j.current={key:r,target:{filePath:l},content:d,editRevision:0,savedRevision:0,runtimeKey:I},M(l),x(d)}catch{if(e)return;M(null),x("")}finally{e||V(!1)}return}if(!S?.slug||!S?.time?.created||!R){M(null),x("");return}V(!0);try{const r=sn(R,S.time.created,S.slug),d=an(on(S.time.created,S.slug),z||null);let m=null;try{await i(r),m=r}catch{}if(!m)try{await i(d),m=d}catch{}if(e)return;if(!m){M(null),x("");return}const w=JSON.stringify(["plan-file",I,m]);if(await C.pendingFor(w),e)return;const K=await i(m);if(e)return;C.reset(w),j.current={key:w,target:{filePath:m},content:K,editRevision:0,savedRevision:0,runtimeKey:I},M(m),x(K)}catch{if(e)return;M(null),x("")}finally{e||V(!1)}})(),()=>{e=!0}},[I,z,xe,_.files,P,G,v,C,F,S?.slug,S?.time?.created,R,l]);const vt=t.useCallback(e=>{j.current.content=e,j.current.editRevision+=1,x(e)},[]);t.useEffect(()=>{if(!p&&!oe)return;const e=window.setTimeout(()=>{F()},350);return()=>{window.clearTimeout(e)}},[h,oe,p,F]),t.useEffect(()=>()=>{F()},[F]),t.useEffect(()=>()=>{J.current!==null&&window.clearTimeout(J.current)},[]);const Ye=t.useCallback(()=>{Me(!1),o?.()},[o,Me]),St=t.useCallback(async e=>{const i=v??B;if(!i||!D||L)return;const a=await rt(D.action==="improve"?"plan.improve.visible":"plan.implement.visible",{plan_title:q}),r=await rt(D.action==="improve"?"plan.improve.instructions":"plan.implement.instructions",{plan_title:q,plan_path:p??""}),m=[{synthetic:!0,text:p?r:[r,"","The plan is not stored as a file in the repository and has no file path. Its full current contents follow below this note and are the source of truth for the plan. Where the instructions above refer to the plan file, treat the plan as stored in OpenChamber project knowledge (it is edited through the OpenChamber UI): propose plan revisions as plan text in the chat rather than editing a file.","",h].join(`
|
|
4
|
+
`)}];Ee(!0);try{Ye();let w=null,K=i.path;if(D.target==="worktree"){if(!Y)return;const k=await zt(i.path,_t());if(!k?.id)return;w=k.id,K=k.path}else{const k=await N(void 0,i.path,null);if(!k?.id)return;w=k.id,K=k.directory??i.path,g(k.id,tt.getState().agents??[])}if(!w)return;const te=Bt.getState();te.saveSessionModelSelection(w,e.providerID,e.modelID),e.agent.trim()&&(te.saveSessionAgentSelection(w,e.agent),te.saveAgentModelForSession(w,e.agent,e.providerID,e.modelID),te.saveAgentModelVariantForSession(w,e.agent,e.providerID,e.modelID,e.variant||void 0)),ye(w,K);const bt=e.runAsGoal===!0?[`Implement the plan "${q}" end-to-end${p?` (plan file: ${p})`:" (the full plan follows)"}.`,p?"Re-read that file for full details — it is the source of truth.":"The full plan follows in this message and is the source of truth.","",h].join(`
|
|
5
|
+
`):null;Gt.getState().setArmed(e.runAsGoal===!0,bt),await E(a,e.providerID,e.modelID,e.agent.trim()||void 0,void 0,void 0,m,e.variant||void 0),A(null)}finally{Ee(!1)}},[Y,h,N,B,g,L,D,p,Ye,v,E,q,ye]),yt=t.useMemo(()=>Xt({drafts:$e,editingDraftId:pe,commentText:ee,onTextChange:Ke,selection:u,isDragging:Oe,fileLabel:de,newWidgetId:"plan-new-comment-input",mapDraftToRange:e=>({start:e.startLine,end:e.endLine}),onSave:Ue,onCancel:Je,onEdit:e=>{Be(e),y({start:e.startLine,end:e.endLine})},onDelete:Ge}),[ee,Ge,pe,Je,Ue,Oe,u,$e,de,Ke,Be]);return n.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden bg-background",children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-2 border-b border-border/40 px-3 py-1.5 flex-shrink-0",children:[n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsx("div",{className:"typography-ui-label font-medium truncate",children:me}),De?n.jsx("div",{className:"typography-micro text-[color:var(--status-error)] truncate",title:De,children:s("planView.error.loadFailed")}):null,Ie?n.jsx("div",{className:"typography-micro text-[color:var(--status-error)] truncate",title:Ie,children:s("planView.error.saveFailed")}):null]}),at?n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsxs(st,{children:[n.jsxs(ge,{children:[n.jsx(we,{asChild:!0,children:n.jsx(it,{asChild:!0,children:n.jsx(ne,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":s("planView.actions.improvePlanAria"),disabled:!h.trim()||L,children:n.jsx(W,{name:"loop-right-ai",className:"size-4"})})})}),n.jsx(ve,{sideOffset:8,children:s("planView.actions.improve")})]}),n.jsxs(ot,{align:"end",children:[n.jsx(re,{onClick:()=>A({action:"improve",target:"session"}),disabled:L,children:s("planView.actions.sendToNewSession")}),n.jsx(re,{onClick:()=>A({action:"improve",target:"worktree"}),disabled:!Y,children:s("planView.actions.sendToNewWorktreeSession")})]})]}),n.jsxs(st,{children:[n.jsxs(ge,{children:[n.jsx(we,{asChild:!0,children:n.jsx(it,{asChild:!0,children:n.jsx(ne,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":s("planView.actions.implementPlanAria"),disabled:!h.trim()||L,children:n.jsx(W,{name:"code-ai",className:"size-4"})})})}),n.jsx(ve,{sideOffset:8,children:s("planView.actions.implement")})]}),n.jsxs(ot,{align:"end",children:[n.jsx(re,{onClick:()=>A({action:"implement",target:"session"}),disabled:L,children:s("planView.actions.sendToNewSession")}),n.jsx(re,{onClick:()=>A({action:"implement",target:"worktree"}),disabled:!Y,children:s("planView.actions.sendToNewWorktreeSession")})]})]}),n.jsx(Pt,{currentMode:X,onToggle:()=>ft(X==="preview"?"edit":"preview")}),X==="preview"&&ut&&n.jsxs(ge,{children:[n.jsx(we,{asChild:!0,children:n.jsx(ne,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":s(Z?"planView.tts.stopSpeaking":"planView.tts.readAloud"),onClick:()=>{Z?ct():h.trim()&<(h)},children:Z?n.jsx(W,{name:"stop",className:"h-4 w-4 text-[color:var(--status-success)]"}):n.jsx(W,{name:"volume-up",className:"h-4 w-4"})})}),n.jsx(ve,{sideOffset:8,children:s(Z?"planView.tts.stopSpeaking":"planView.tts.readAloud")})]}),n.jsx(ne,{variant:"ghost",size:"sm",onClick:async()=>{(await Jt(h)).ok&&(Ve(!0),J.current!==null&&window.clearTimeout(J.current),J.current=window.setTimeout(()=>{Ve(!1)},1200))},className:"h-5 w-5 p-0",title:s("planView.actions.copyPlanContents"),"aria-label":s("planView.actions.copyPlanContents"),children:mt?n.jsx(W,{name:"check",className:"h-4 w-4 text-[color:var(--status-success)]"}):n.jsx(W,{name:"clipboard",className:"h-4 w-4"})})]}):null]}),n.jsx(nn,{open:D!==null,onOpenChange:e=>{!e&&!Ne&&A(null)},target:D?.target??"session",projectDirectory:v?.path??B?.path??null,submitting:Ne,allowRunAsGoal:!0,onConfirm:St}),n.jsx("div",{className:"flex-1 min-h-0 min-w-0 relative",children:n.jsx(Ut,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:dt?n.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:s("planView.state.loading")}):n.jsx("div",{className:"relative h-full",children:n.jsx("div",{className:"h-full",children:X==="preview"?n.jsx("div",{className:"h-full overflow-auto p-3",children:n.jsx(Ht,{fallback:n.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[n.jsx("div",{className:"mb-1 font-medium text-destructive",children:s("planView.error.previewUnavailable")}),n.jsx("div",{className:"text-sm text-muted-foreground",children:s("planView.error.switchToEditMode")})]}),children:n.jsx(Qt,{content:h,className:"typography-markdown-body",enableFileReferences:!1})})}):n.jsx("div",{className:"relative h-full",ref:pt,children:n.jsx(Mt,{value:h,onChange:vt,readOnly:!1,className:"h-full",extensions:wt,onViewReady:e=>{Le.current=e},onViewDestroy:()=>{Le.current=null},blockWidgets:yt,highlightLines:u?{start:Math.min(u.start,u.end),end:Math.max(u.start,u.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(e,i,a)=>{if(!(a instanceof MouseEvent)||a.button!==0)return!1;a.preventDefault();const r=e.state.doc.lineAt(i.from).number;if(u&&!a.shiftKey&&Math.min(u.start,u.end)===r&&Math.max(u.start,u.end)===r)return y(null),U(),O.current=!1,T.current=null,$(!1),!0;if(Te&&u&&!a.shiftKey){const d=Math.min(u.start,u.end,r),m=Math.max(u.start,u.end,r);return y({start:d,end:m}),O.current=!1,T.current=null,$(!1),!0}if(O.current=!0,T.current=r,$(!0),u&&a.shiftKey){const d=Math.min(u.start,r),m=Math.max(u.end,r);y({start:d,end:m})}else y({start:r,end:r});return!0},mouseover:(e,i,a)=>{if(!(a instanceof MouseEvent)||a.buttons!==1||!O.current||T.current===null)return!1;const r=e.state.doc.lineAt(i.from).number,d=Math.min(T.current,r),m=Math.max(T.current,r);return y({start:d,end:m}),$(!0),!1},mouseup:()=>(O.current=!1,T.current=null,$(!1),!1)}}})})})})})})]})};export{cs as PlanView};
|