@fungi.computer/inkcap 0.8.6 → 0.8.8

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.
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Br as t,Gn as n,Un as r,Vr as i,an as a,i as o,in as s,l as c,nn as l,o as u,s as d,u as f}from"./tree-path-D47zLaQq.js";import{Pt as p,i as m,t as h}from"./folder-open-vITejO7G.js";import{t as g}from"./refresh-cw-BRt_5ZtY.js";import{C as _,_ as v,a as y,b,c as x,d as S,f as C,g as w,h as T,l as E,m as D,n as O,p as k,t as A,u as j,v as M,y as N}from"./index-CCQdYVlj.js";import{n as P,t as F}from"./useFileTree-Cj1d2pkx.js";var I=s(`GitBranch`,[[`line`,{x1:`6`,x2:`6`,y1:`3`,y2:`15`,key:`17qcm7`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`path`,{d:`M18 9a9 9 0 0 1-9 9`,key:`n2h4wq`}]]),L=s(`History`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),R=e(i(),1),z=256;async function B(e,t,n,i,a){i.throwIfAborted();let o=await n(e,t);if(!v.safeParse(o).success)return o;a(!0);try{let a=null,o=!1;for(let e=0;e<z&&!o;e++){i.throwIfAborted();let e=E.parse(await n(`rebuildCopies`,{cursor:a}));o=e.done,a=e.cursor}if(!o)throw new r(`Bonsai is still preparing this repository. Try again shortly.`,{code:`TIMEOUT`,retryable:!0});i.throwIfAborted();let s=await n(e,t);if(v.safeParse(s).success)throw Error(`The repository changed while loading. Refresh to retry.`);return s}finally{a(!1)}}function V({repository:e,branch:t,request:n,onSaved:i,onSaveState:a}){let o=new Map;async function s(i,a){a.throwIfAborted();let o=j.parse(await n(`files.read`,{repo:e,ref:t,path:i}));if(a.throwIfAborted(),o.binary)throw Error(`This Bonsai file is not a text document.`);if(o.text===null&&o.blob!==null)throw new r(`This Bonsai file is too large to edit.`,{code:`FILE_TOO_LARGE`,retryable:!1});return o}async function c(s,c){c.throwIfAborted();let l=w.parse(await n(`files.sync`,{}));c.throwIfAborted();let u=l.settled.find(n=>n.repo===e&&n.branch===t&&n.path===s);if(u){if(u.result.kind===`refused`)throw new r(`Bonsai refused sync: ${u.result.reason}`,{code:`CAPABILITY_DENIED`,retryable:u.result.reason===`background-unavailable`});let e=o.get(s);if(u.result.revision!==e?.version)throw new r(`Your saved file changed. Compare before syncing.`,{code:`CONFLICT`,retryable:!0});a(s,u.result)}i()}async function l(l,u,d,f){f.throwIfAborted();let p=o.get(l);if(d===void 0){let e=await s(l,f);p={file:e,contents:e.pending?.text??e.text??``,version:e.version}}if(!p)throw Error(`Reopen this Bonsai file before saving.`);if(d!==void 0&&p.contents!==d)throw new r(`The file baseline changed. Compare before saving.`,{code:`CONFLICT`,retryable:!0});if(d!==void 0){let e=await s(l,f);if(e.version!==p.version||(e.pending?.text??e.text??``)!==p.contents)throw new r(`The file changed. Compare before saving.`,{code:`CONFLICT`,retryable:!0});e.pending===void 0&&(p.file=e)}let m=D.parse({repo:e,branch:t,path:l,baseCommit:p.file.commit,baseBlob:p.file.blob,text:u,revision:p.version}),h=T.parse(await n(`files.save`,m));if(h.kind===`refused`)throw new r(`Bonsai refused this save: ${h.reason}`,{code:`CAPABILITY_DENIED`,retryable:h.reason===`background-unavailable`});if(a(l,h),h.kind===`conflict`)throw new r(`Your saved file changed. Compare before saving.`,{code:`CONFLICT`,retryable:!0});o.set(l,{file:p.file,contents:u,version:h.revision}),i(),h.kind===`saved`&&c(l,f).catch(e=>{console.error(`Bonsai sync status could not be refreshed`,e),!(o.get(l)?.version!==h.revision||f.aborted)&&a(l,{kind:`failed`,revision:h.revision,reason:`sync_failed`})})}return{kind:`repository`,id:`${e}:${t}`,label:`${e} · ${t}`,async read(e,t,n){let r=n?.revision,i=await s(e,t);if(n?.closed)return{kind:`closed`};if(n&&n.revision!==r)return{kind:`changed`};let c=i.pending?.text??i.text??``;o.set(e,{file:i,contents:c,version:i.version});let l=i.pending;return l?.state===`pending`?a(e,{kind:`saved`,revision:l.revision,state:`pending`}):l?.state===`conflict`?a(e,{kind:`conflict`,revision:l.revision,theirs:l.theirs}):l?.state===`failed`?a(e,{kind:`failed`,revision:l.revision,reason:l.failure??`sync_failed`}):i.version!==null&&a(e,{kind:`synced`,revision:i.version,commit:i.commit}),{kind:`text`,contents:c}},replace:(e,t,n,r)=>l(e,t,n,r),write:(e,t,n)=>l(e,t,void 0,n),retry:c,async discard(s,c){c.throwIfAborted();let l=o.get(s);if(!l)throw Error(`Reopen this saved file before discarding it.`);if(l.version===null)return;let u=S.parse({repo:e,branch:t,path:s,revision:l.version}),d=C.parse(await n(`files.discard`,u));if(c.throwIfAborted(),d.kind===`conflict`)throw new r(`Your saved file changed. Refresh before discarding.`,{code:`CONFLICT`,retryable:!0});o.delete(s),a(s,null),i()},async readCommitted(e,t){let n=await s(e,t),r=n.text??``;return o.has(e)||o.set(e,{file:n,contents:r,version:n.version}),r}}}async function H(e,t,n){let r={repo:t,ref:n},i=M.parse(await e(`files.tree`,{...r,path:``})),a=k.parse(await e(`files.list`,r)),o=x.parse(await e(`commits.list`,{...r,limit:20}));if(i.commit.hash!==a.commit.hash)throw Error(`The repository changed while loading. Refresh to retry.`);return{head:i.commit.hash,branch:n,files:a.paths.map(e=>({path:e})),history:o.commits.map(e=>e.commit),truncated:a.truncated}}var U=t();function W({files:e,rowHeight:t,dirtyPaths:n,activePath:r,busy:i,onRefresh:a,onOpenFile:o}){let s=(0,R.useRef)({files:e,onOpenFile:o});s.current={files:e,onOpenFile:o};let{model:c}=F({paths:[],initialExpansion:`open`,itemHeight:t,onSelectionChange(e){let t=e[0];t&&!t.endsWith(`/`)&&s.current.files.some(e=>e.path===t)&&s.current.onOpenFile(t)}}),u=(0,R.useMemo)(()=>{let t=new Set(n);return e.flatMap(e=>t.has(e.path)?[{path:e.path,status:`modified`}]:[])},[e,n]);(0,R.useEffect)(()=>{c.resetPaths(e.map(e=>e.path))},[c,e]),(0,R.useEffect)(()=>{c.setGitStatus(u)},[c,u]),(0,R.useEffect)(()=>{for(let e of c.getSelectedPaths())e!==r&&c.getItem(e)?.deselect();r&&c.getItem(r)?.select()},[c,r]);let d={flex:`1`,"--trees-item-height":`${String(t)}px`,"--trees-padding-inline-override":`var(--spacing-xs)`,"--trees-item-margin-x-override":`0px`,"--trees-item-padding-x-override":`var(--spacing-xs)`,"--trees-item-row-gap-override":`var(--spacing-xs)`,"--trees-border-radius-override":`var(--radius-field)`,"--trees-bg-override":`var(--color-base-100)`,"--trees-fg-override":`var(--color-base-content)`,"--trees-bg-muted-override":`var(--color-base-200)`,"--trees-selected-bg-override":`var(--color-base-300)`,"--trees-font-family-override":`var(--font-sans)`,"--trees-font-size-override":`12px`};return(0,U.jsxs)(`aside`,{className:`inkcap-tree`,"aria-label":`Repository files`,children:[(0,U.jsxs)(`div`,{className:`inkcap-tree-toolbar`,children:[(0,U.jsxs)(`span`,{children:[(0,U.jsx)(h,{"aria-hidden":`true`}),` Explorer`]}),(0,U.jsx)(l,{icon:(0,U.jsx)(g,{}),"aria-label":`Refresh repository`,variant:`ghost`,size:`responsive`,disabled:i,onClick:a})]}),(0,U.jsx)(`p`,{className:`inkcap-repository-legend`,children:`Changes in latest commit · drafts marked modified`}),(0,U.jsx)(P,{model:c,style:d})]})}var G={all:(e,t)=>[`inkcap-repository`,e,t],branch:(e,t,n)=>[...G.all(e,t),n]},K={branch_missing:`The repository branch no longer exists. Your text is saved; restore the branch before retrying.`,access_changed:`Repository access changed. Your text is saved; restore Bonsai's Git access before retrying.`,sync_failed:`Git could not publish this change. Your text is saved; retry sync.`,permanent_material:`The saved change no longer matches the repository state. Save again to publish your text from the current state.`};function q({connection:e,repository:t,initialBranch:r,initialPath:i,openRequestId:s,transport:l,onReady:h}){let g=p(),[v,x]=(0,R.useState)(!1),[S,C]=(0,R.useState)(0),[w,T]=(0,R.useState)(new Map),[E,D]=(0,R.useState)(``),k=(0,R.useRef)(new AbortController);(0,R.useEffect)(()=>{let e=new AbortController;return k.current=e,()=>{e.abort()}},[]);let j=(0,R.useCallback)((t,n)=>l?l(t,n):e.app.capabilities.require(b).call(`app_bonsai`,t,JSON.stringify(n)),[e.app,l]),M=(0,R.useCallback)((e,t)=>B(e,t,j,k.current.signal,e=>{C(t=>t+(e?1:-1))}),[j]),P=(0,R.useCallback)(()=>{g.invalidateQueries({queryKey:G.all(e.app.identity.surfaceId,t)})},[g,e.app,t]),F=(0,R.useRef)(new Map),z=(0,R.useMemo)(()=>{let n=`${e.app.identity.surfaceId}:${t}:${r}`,i=F.current.get(n);if(i?.app===e.app)return i;let a=V({repository:t,branch:r,request:M,onSaved:P,onSaveState:(e,n)=>{k.current.signal.aborted||T(i=>{let a=new Map(i),o=`${t}:${r}:${e}`;return n===null?a.delete(o):a.set(o,n),a})}}),o={app:e.app,source:a};return F.current.set(n,o),o},[t,r,M,P,e.app]),q=A({connection:z}),J=_({queryKey:G.branch(e.app.identity.surfaceId,t,r),queryFn:()=>H(M,t,r),refetchInterval:15e3});(0,R.useEffect)(()=>e.app.window.onBeforeClose(q.requestWindowClose),[e.app,q.requestWindowClose]),(0,R.useEffect)(()=>{h?.({requestWindowClose:q.requestWindowClose})},[h,q.requestWindowClose]);let Y=(0,R.useRef)(),X=(0,R.useRef)(new Map),Z=(0,R.useRef)(new Set);(0,R.useEffect)(()=>{if(!J.data)return;let e=`${z.app.identity.surfaceId}:${z.source.id}:${s}`;Y.current!==e&&(Y.current=e,q.onOpenFile(i));let t=X.current.get(z.source.id),n=t!==void 0&&t!==J.data.head;X.current.set(z.source.id,J.data.head);let r=new Set(q.tabs.map(e=>e.tabKey));for(let e of Z.current)r.has(e)||Z.current.delete(e);for(let e of q.tabs)if(!(e.target.closed||e.connection!==z||!n&&!Z.current.has(e.tabKey))){if(e.target.saving){Z.current.add(e.tabKey);continue}Z.current.delete(e.tabKey),e.target.dirty||q.onReopen(e,{background:!0})}},[J.data,z,i,s,q]);let Q=q.tabs.find(e=>e.tabKey===q.active),$=Q?.connection?.source?w.get(`${Q.connection.source.id}:${Q.path}`):void 0,ee=$?.kind===`saved`?`Saved · syncing`:$?.kind===`synced`?`Synced · ${$.commit.slice(0,7)}`:$?.kind===`conflict`?`Sync conflict · Compare`:$?.kind===`failed`?`Sync failed · Retry`:void 0;async function te(){if(!Q?.connection?.source)return;let e=F.current.get(`${Q.connection.app.identity.surfaceId}:${Q.connection.source.id}`);if(e)try{D(``),await e.source.retry(Q.path,k.current.signal)}catch(e){console.error(`Bonsai sync retry failed`,e),D(`${n(e).message} Your saved text remains in Bonsai.`)}}async function ne(){if(!Q?.connection?.source)return;let e=()=>!Q.target.dirty&&!Q.target.saving&&!Q.target.closed;if(!e())return;let t=F.current.get(`${Q.connection.app.identity.surfaceId}:${Q.connection.source.id}`);if(t)try{D(``);let n=await t.source.read(Q.path,k.current.signal);if(n.kind!==`text`)throw Error(`This saved text is unavailable.`);if(!e())return;await t.source.replace(Q.path,n.contents,n.contents,k.current.signal)}catch(e){console.error(`Bonsai explicit re-save failed`,e),D(`${n(e).message} Your saved text and open edits remain available.`)}}return(0,U.jsxs)(`div`,{className:`inkcap-repository`,children:[(0,U.jsxs)(`div`,{className:`inkcap-repository-toolbar`,children:[(0,U.jsxs)(`span`,{className:`inkcap-repository-name`,children:[(0,U.jsx)(I,{"aria-hidden":`true`}),` `,t,` · `,r]}),(0,U.jsxs)(a,{size:`sm`,variant:`outline`,onClick:()=>{x(!0)},children:[(0,U.jsx)(L,{"aria-hidden":`true`,className:`size-[var(--stipe-icon-size-sm)]`}),` `,`History`]})]}),S>0&&(0,U.jsx)(y,{message:`Loading this repository…`}),J.data?.truncated&&(0,U.jsx)(N,{tone:`info`,title:`Only the indexed files are shown`}),E&&(0,U.jsx)(m,{message:E,onDismiss:()=>{D(``)}}),$?.kind===`failed`&&!E&&(0,U.jsx)(N,{tone:`warning`,title:$.reason===`permanent_material`?`Sync needs a new save`:`Sync failed`,description:K[$.reason],action:(0,U.jsx)(a,{size:`sm`,disabled:$.reason===`permanent_material`&&Q!==void 0&&(Q.target.dirty||Q.target.saving),onClick:()=>void($.reason===`permanent_material`?ne():te()),children:$.reason===`permanent_material`?`Save again`:`Retry`})}),(0,U.jsx)(O,{model:{...q,repositoryStatus:ee,repositoryStates:w,canList:!0,sourceLabel:z.source.label,onReadCurrent:async(e,t)=>{if(e.connection?.source?.kind!==`repository`)return q.onReadCurrent(e);let n=F.current.get(`${e.connection.app.identity.surfaceId}:${e.connection.source.id}`);if(!n||e.target.closed)throw Error(`This Bonsai file is no longer open.`);return t&&await n.source.discard(e.path,k.current.signal),n.source.readCommitted(e.path,k.current.signal)},error:J.error?`${n(J.error).message} Your open edits remain available.`:q.error,fileTree:(e,t)=>(0,U.jsx)(W,{rowHeight:t?44:32,files:J.data?.files??[],dirtyPaths:q.tabs.filter(e=>e.connection===z&&e.dirty).map(e=>e.path),activePath:Q?.connection===z?Q.path:null,busy:J.isFetching,onRefresh:P,onOpenFile:e},t?`phone`:`desktop`)}}),(0,U.jsx)(o,{open:v,onOpenChange:x,children:(0,U.jsxs)(u,{children:[(0,U.jsxs)(c,{children:[(0,U.jsx)(f,{children:`Commit history`}),(0,U.jsxs)(d,{children:[t,` · `,r]})]}),(0,U.jsx)(`ol`,{className:`inkcap-repository-history`,children:J.data?.history.map(e=>(0,U.jsxs)(`li`,{children:[(0,U.jsx)(`code`,{children:e.hash.slice(0,7)}),` `,e.message,(0,U.jsx)(`span`,{className:`text-dim`,children:e.author.name})]},e.hash))})]})})]})}export{q as InkcapRepositoryApp};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Br as t,Gn as n,Un as r,Vr as i,an as a,i as o,in as s,l as c,nn as l,o as u,s as d,u as f}from"./tree-path-D47zLaQq.js";import{Pt as p,i as m,t as h}from"./folder-open-vITejO7G.js";import{t as g}from"./refresh-cw-BRt_5ZtY.js";import{C as _,_ as v,a as y,b,c as x,d as S,f as C,g as w,h as T,l as E,m as D,n as O,p as k,t as A,u as j,v as M,y as N}from"./index-xYhj0tFy.js";import{n as P,t as F}from"./useFileTree-Cj1d2pkx.js";var I=s(`GitBranch`,[[`line`,{x1:`6`,x2:`6`,y1:`3`,y2:`15`,key:`17qcm7`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`path`,{d:`M18 9a9 9 0 0 1-9 9`,key:`n2h4wq`}]]),L=s(`History`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),R=e(i(),1),z=256;async function B(e,t,n,i,a){i.throwIfAborted();let o=await n(e,t);if(!v.safeParse(o).success)return o;a(!0);try{let a=null,o=!1;for(let e=0;e<z&&!o;e++){i.throwIfAborted();let e=E.parse(await n(`rebuildCopies`,{cursor:a}));o=e.done,a=e.cursor}if(!o)throw new r(`Bonsai is still preparing this repository. Try again shortly.`,{code:`TIMEOUT`,retryable:!0});i.throwIfAborted();let s=await n(e,t);if(v.safeParse(s).success)throw Error(`The repository changed while loading. Refresh to retry.`);return s}finally{a(!1)}}function V({repository:e,branch:t,request:n,onSaved:i,onSaveState:a}){let o=new Map;async function s(i,a){a.throwIfAborted();let o=j.parse(await n(`files.read`,{repo:e,ref:t,path:i}));if(a.throwIfAborted(),o.binary)throw Error(`This Bonsai file is not a text document.`);if(o.text===null&&o.blob!==null)throw new r(`This Bonsai file is too large to edit.`,{code:`FILE_TOO_LARGE`,retryable:!1});return o}async function c(s,c){c.throwIfAborted();let l=w.parse(await n(`files.sync`,{}));c.throwIfAborted();let u=l.settled.find(n=>n.repo===e&&n.branch===t&&n.path===s);if(u){if(u.result.kind===`refused`)throw new r(`Bonsai refused sync: ${u.result.reason}`,{code:`CAPABILITY_DENIED`,retryable:u.result.reason===`background-unavailable`});let e=o.get(s);if(u.result.revision!==e?.version)throw new r(`Your saved file changed. Compare before syncing.`,{code:`CONFLICT`,retryable:!0});a(s,u.result)}i()}async function l(l,u,d,f){f.throwIfAborted();let p=o.get(l);if(d===void 0){let e=await s(l,f);p={file:e,contents:e.pending?.text??e.text??``,version:e.version}}if(!p)throw Error(`Reopen this Bonsai file before saving.`);if(d!==void 0&&p.contents!==d)throw new r(`The file baseline changed. Compare before saving.`,{code:`CONFLICT`,retryable:!0});if(d!==void 0){let e=await s(l,f);if(e.version!==p.version||(e.pending?.text??e.text??``)!==p.contents)throw new r(`The file changed. Compare before saving.`,{code:`CONFLICT`,retryable:!0});e.pending===void 0&&(p.file=e)}let m=D.parse({repo:e,branch:t,path:l,baseCommit:p.file.commit,baseBlob:p.file.blob,text:u,revision:p.version}),h=T.parse(await n(`files.save`,m));if(h.kind===`refused`)throw new r(`Bonsai refused this save: ${h.reason}`,{code:`CAPABILITY_DENIED`,retryable:h.reason===`background-unavailable`});if(a(l,h),h.kind===`conflict`)throw new r(`Your saved file changed. Compare before saving.`,{code:`CONFLICT`,retryable:!0});o.set(l,{file:p.file,contents:u,version:h.revision}),i(),h.kind===`saved`&&c(l,f).catch(e=>{console.error(`Bonsai sync status could not be refreshed`,e),!(o.get(l)?.version!==h.revision||f.aborted)&&a(l,{kind:`failed`,revision:h.revision,reason:`sync_failed`})})}return{kind:`repository`,id:`${e}:${t}`,label:`${e} · ${t}`,async read(e,t,n){let r=n?.revision,i=await s(e,t);if(n?.closed)return{kind:`closed`};if(n&&n.revision!==r)return{kind:`changed`};let c=i.pending?.text??i.text??``;o.set(e,{file:i,contents:c,version:i.version});let l=i.pending;return l?.state===`pending`?a(e,{kind:`saved`,revision:l.revision,state:`pending`}):l?.state===`conflict`?a(e,{kind:`conflict`,revision:l.revision,theirs:l.theirs}):l?.state===`failed`?a(e,{kind:`failed`,revision:l.revision,reason:l.failure??`sync_failed`}):i.version!==null&&a(e,{kind:`synced`,revision:i.version,commit:i.commit}),{kind:`text`,contents:c}},replace:(e,t,n,r)=>l(e,t,n,r),write:(e,t,n)=>l(e,t,void 0,n),retry:c,async discard(s,c){c.throwIfAborted();let l=o.get(s);if(!l)throw Error(`Reopen this saved file before discarding it.`);if(l.version===null)return;let u=S.parse({repo:e,branch:t,path:s,revision:l.version}),d=C.parse(await n(`files.discard`,u));if(c.throwIfAborted(),d.kind===`conflict`)throw new r(`Your saved file changed. Refresh before discarding.`,{code:`CONFLICT`,retryable:!0});o.delete(s),a(s,null),i()},async readCommitted(e,t){let n=await s(e,t),r=n.text??``;return o.has(e)||o.set(e,{file:n,contents:r,version:n.version}),r}}}async function H(e,t,n){let r={repo:t,ref:n},i=M.parse(await e(`files.tree`,{...r,path:``})),a=k.parse(await e(`files.list`,r)),o=x.parse(await e(`commits.list`,{...r,limit:20}));if(i.commit.hash!==a.commit.hash)throw Error(`The repository changed while loading. Refresh to retry.`);return{head:i.commit.hash,branch:n,files:a.paths.map(e=>({path:e})),history:o.commits.map(e=>e.commit),truncated:a.truncated}}var U=t();function W({files:e,rowHeight:t,dirtyPaths:n,activePath:r,busy:i,onRefresh:a,onOpenFile:o}){let s=(0,R.useRef)({files:e,onOpenFile:o});s.current={files:e,onOpenFile:o};let{model:c}=F({paths:[],initialExpansion:`open`,itemHeight:t,onSelectionChange(e){let t=e[0];t&&!t.endsWith(`/`)&&s.current.files.some(e=>e.path===t)&&s.current.onOpenFile(t)}}),u=(0,R.useMemo)(()=>{let t=new Set(n);return e.flatMap(e=>t.has(e.path)?[{path:e.path,status:`modified`}]:[])},[e,n]);(0,R.useEffect)(()=>{c.resetPaths(e.map(e=>e.path))},[c,e]),(0,R.useEffect)(()=>{c.setGitStatus(u)},[c,u]),(0,R.useEffect)(()=>{for(let e of c.getSelectedPaths())e!==r&&c.getItem(e)?.deselect();r&&c.getItem(r)?.select()},[c,r]);let d={flex:`1`,"--trees-item-height":`${String(t)}px`,"--trees-padding-inline-override":`var(--spacing-xs)`,"--trees-item-margin-x-override":`0px`,"--trees-item-padding-x-override":`var(--spacing-xs)`,"--trees-item-row-gap-override":`var(--spacing-xs)`,"--trees-border-radius-override":`var(--radius-field)`,"--trees-bg-override":`var(--color-base-100)`,"--trees-fg-override":`var(--color-base-content)`,"--trees-bg-muted-override":`var(--color-base-200)`,"--trees-selected-bg-override":`var(--color-base-300)`,"--trees-font-family-override":`var(--font-sans)`,"--trees-font-size-override":`12px`};return(0,U.jsxs)(`aside`,{className:`inkcap-tree`,"aria-label":`Repository files`,children:[(0,U.jsxs)(`div`,{className:`inkcap-tree-toolbar`,children:[(0,U.jsxs)(`span`,{children:[(0,U.jsx)(h,{"aria-hidden":`true`}),` Explorer`]}),(0,U.jsx)(l,{icon:(0,U.jsx)(g,{}),"aria-label":`Refresh repository`,variant:`ghost`,size:`responsive`,disabled:i,onClick:a})]}),(0,U.jsx)(`p`,{className:`inkcap-repository-legend`,children:`Changes in latest commit · drafts marked modified`}),(0,U.jsx)(P,{model:c,style:d})]})}var G={all:(e,t)=>[`inkcap-repository`,e,t],branch:(e,t,n)=>[...G.all(e,t),n]},K={branch_missing:`The repository branch no longer exists. Your text is saved; restore the branch before retrying.`,access_changed:`Repository access changed. Your text is saved; restore Bonsai's Git access before retrying.`,sync_failed:`Git could not publish this change. Your text is saved; retry sync.`,permanent_material:`The saved change no longer matches the repository state. Save again to publish your text from the current state.`};function q({connection:e,repository:t,initialBranch:r,initialPath:i,openRequestId:s,transport:l,onReady:h}){let g=p(),[v,x]=(0,R.useState)(!1),[S,C]=(0,R.useState)(0),[w,T]=(0,R.useState)(new Map),[E,D]=(0,R.useState)(``),k=(0,R.useRef)(new AbortController);(0,R.useEffect)(()=>{let e=new AbortController;return k.current=e,()=>{e.abort()}},[]);let j=(0,R.useCallback)((t,n)=>l?l(t,n):e.app.capabilities.require(b).call(`app_bonsai`,t,JSON.stringify(n)),[e.app,l]),M=(0,R.useCallback)((e,t)=>B(e,t,j,k.current.signal,e=>{C(t=>t+(e?1:-1))}),[j]),P=(0,R.useCallback)(()=>{g.invalidateQueries({queryKey:G.all(e.app.identity.surfaceId,t)})},[g,e.app,t]),F=(0,R.useRef)(new Map),z=(0,R.useMemo)(()=>{let n=`${e.app.identity.surfaceId}:${t}:${r}`,i=F.current.get(n);if(i?.app===e.app)return i;let a=V({repository:t,branch:r,request:M,onSaved:P,onSaveState:(e,n)=>{k.current.signal.aborted||T(i=>{let a=new Map(i),o=`${t}:${r}:${e}`;return n===null?a.delete(o):a.set(o,n),a})}}),o={app:e.app,source:a};return F.current.set(n,o),o},[t,r,M,P,e.app]),q=A({connection:z}),J=_({queryKey:G.branch(e.app.identity.surfaceId,t,r),queryFn:()=>H(M,t,r),refetchInterval:15e3});(0,R.useEffect)(()=>e.app.window.onBeforeClose(q.requestWindowClose),[e.app,q.requestWindowClose]),(0,R.useEffect)(()=>{h?.({requestWindowClose:q.requestWindowClose})},[h,q.requestWindowClose]);let Y=(0,R.useRef)(),X=(0,R.useRef)(new Map),Z=(0,R.useRef)(new Set);(0,R.useEffect)(()=>{if(!J.data)return;let e=`${z.app.identity.surfaceId}:${z.source.id}:${s}`;Y.current!==e&&(Y.current=e,q.onOpenFile(i));let t=X.current.get(z.source.id),n=t!==void 0&&t!==J.data.head;X.current.set(z.source.id,J.data.head);let r=new Set(q.tabs.map(e=>e.tabKey));for(let e of Z.current)r.has(e)||Z.current.delete(e);for(let e of q.tabs)if(!(e.target.closed||e.connection!==z||!n&&!Z.current.has(e.tabKey))){if(e.target.saving){Z.current.add(e.tabKey);continue}Z.current.delete(e.tabKey),e.target.dirty||q.onReopen(e,{background:!0})}},[J.data,z,i,s,q]);let Q=q.tabs.find(e=>e.tabKey===q.active),$=Q?.connection?.source?w.get(`${Q.connection.source.id}:${Q.path}`):void 0,ee=$?.kind===`saved`?`Saved · syncing`:$?.kind===`synced`?`Synced · ${$.commit.slice(0,7)}`:$?.kind===`conflict`?`Sync conflict · Compare`:$?.kind===`failed`?`Sync failed · Retry`:void 0;async function te(){if(!Q?.connection?.source)return;let e=F.current.get(`${Q.connection.app.identity.surfaceId}:${Q.connection.source.id}`);if(e)try{D(``),await e.source.retry(Q.path,k.current.signal)}catch(e){console.error(`Bonsai sync retry failed`,e),D(`${n(e).message} Your saved text remains in Bonsai.`)}}async function ne(){if(!Q?.connection?.source)return;let e=()=>!Q.target.dirty&&!Q.target.saving&&!Q.target.closed;if(!e())return;let t=F.current.get(`${Q.connection.app.identity.surfaceId}:${Q.connection.source.id}`);if(t)try{D(``);let n=await t.source.read(Q.path,k.current.signal);if(n.kind!==`text`)throw Error(`This saved text is unavailable.`);if(!e())return;await t.source.replace(Q.path,n.contents,n.contents,k.current.signal)}catch(e){console.error(`Bonsai explicit re-save failed`,e),D(`${n(e).message} Your saved text and open edits remain available.`)}}return(0,U.jsxs)(`div`,{className:`inkcap-repository`,children:[(0,U.jsxs)(`div`,{className:`inkcap-repository-toolbar`,children:[(0,U.jsxs)(`span`,{className:`inkcap-repository-name`,children:[(0,U.jsx)(I,{"aria-hidden":`true`}),` `,t,` · `,r]}),(0,U.jsxs)(a,{size:`sm`,variant:`outline`,onClick:()=>{x(!0)},children:[(0,U.jsx)(L,{"aria-hidden":`true`,className:`size-[var(--stipe-icon-size-sm)]`}),` `,`History`]})]}),S>0&&(0,U.jsx)(y,{message:`Loading this repository…`}),J.data?.truncated&&(0,U.jsx)(N,{tone:`info`,title:`Only the indexed files are shown`}),E&&(0,U.jsx)(m,{message:E,onDismiss:()=>{D(``)}}),$?.kind===`failed`&&!E&&(0,U.jsx)(N,{tone:`warning`,title:$.reason===`permanent_material`?`Sync needs a new save`:`Sync failed`,description:K[$.reason],action:(0,U.jsx)(a,{size:`sm`,disabled:$.reason===`permanent_material`&&Q!==void 0&&(Q.target.dirty||Q.target.saving),onClick:()=>void($.reason===`permanent_material`?ne():te()),children:$.reason===`permanent_material`?`Save again`:`Retry`})}),(0,U.jsx)(O,{model:{...q,repositoryStatus:ee,repositoryStates:w,canList:!0,sourceLabel:z.source.label,onReadCurrent:async(e,t)=>{if(e.connection?.source?.kind!==`repository`)return q.onReadCurrent(e);let n=F.current.get(`${e.connection.app.identity.surfaceId}:${e.connection.source.id}`);if(!n||e.target.closed)throw Error(`This Bonsai file is no longer open.`);return t&&await n.source.discard(e.path,k.current.signal),n.source.readCommitted(e.path,k.current.signal)},error:J.error?`${n(J.error).message} Your open edits remain available.`:q.error,fileTree:(e,t)=>(0,U.jsx)(W,{rowHeight:t?44:32,files:J.data?.files??[],dirtyPaths:q.tabs.filter(e=>e.connection===z&&e.dirty).map(e=>e.path),activePath:Q?.connection===z?Q.path:null,busy:J.isFetching,onRefresh:P,onOpenFile:e},t?`phone`:`desktop`)}}),(0,U.jsx)(o,{open:v,onOpenChange:x,children:(0,U.jsxs)(u,{children:[(0,U.jsxs)(c,{children:[(0,U.jsx)(f,{children:`Commit history`}),(0,U.jsxs)(d,{children:[t,` · `,r]})]}),(0,U.jsx)(`ol`,{className:`inkcap-repository-history`,children:J.data?.history.map(e=>(0,U.jsxs)(`li`,{children:[(0,U.jsx)(`code`,{children:e.hash.slice(0,7)}),` `,e.message,(0,U.jsx)(`span`,{className:`text-dim`,children:e.author.name})]},e.hash))})]})})]})}export{q as InkcapRepositoryApp};