@fungi.computer/inkcap 0.13.3 → 0.14.1
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/dist/assets/{FileTab-BNVCSYIo.js → FileTab-6hI4uuHO.js} +1 -1
- package/dist/assets/{InkcapRepositoryApp-D3WRciiD.js → InkcapRepositoryApp-Cjq0FYN8.js} +1 -1
- package/dist/assets/{index-HgxZcM-A.js → index-1TT7jjTY.js} +2 -2
- package/dist/assets/{index-ch--E_d5.css → index-IdEGYLLS.css} +1 -1
- package/dist/index.html +2 -2
- package/package.json +6 -6
|
@@ -551,4 +551,4 @@ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Bn as t,Ji as n,Jn as
|
|
|
551
551
|
`,n),i=r<0?e.length:r;t.push({start:n,end:i,className:`comment`}),n=i;continue}n++}return t}function Cc(e){let t=[],n=/:\s*([^\n]*)/g,r;for(;r=n.exec(e);){let n=r[1],i=n.trimEnd();if(!i)continue;let a=r.index+r[0].indexOf(n),o=a+i.length,s=/\s+#/.exec(i);for(s&&(o=a+s.index);o>a&&/\s/.test(e[o-1]);)o--;o>a&&t.push({start:a,end:o,className:`string`})}return t}var wc=/[ \t]*(?:(?:\/\/|#)[ \t]*\[!code[ \t]+(\+\+|--)\]|\/\*[ \t]*\[!code[ \t]+(\+\+|--)\][ \t]*\*\/|<!--[ \t]*\[!code[ \t]+(\+\+|--)\][ \t]*-->)[ \t]*$/;function Tc(e){let t=[];return{code:e.split(`
|
|
552
552
|
`).map((e,n)=>{let r=wc.exec(e);if(!r)return e;let i=r[1]||r[2]||r[3];return t.push({className:i===`++`?`th-line--inserted`:`th-line--deleted`,lines:n+1}),e.slice(0,r.index)}).join(`
|
|
553
553
|
`),decorations:t}}function Ec(e){return(t,n=`plaintext`,r={})=>{let i=Tc(t);return us(ls(e.tokenize(i.code,{lang:n}).tokens,{...r.lineNumbers===void 0?{}:{lineNumbers:r.lineNumbers},...i.decorations.length||r.highlightLines?.length?{decorations:[...i.decorations,...(r.highlightLines||[]).map(e=>({className:`th-line--highlighted`,lines:e}))]}:{}}))}}var Dc=Ec(cs({fallbackLanguage:`plaintext`,languages:[Ms,Ns,Vs,rc,ic,ac,oc,lc,uc,dc,_c,vc,yc,bc]})),Oc=(0,V.forwardRef)(function({className:e,variant:t=`default`,...n},r){return(0,B.jsx)(`article`,{...n,className:a(`prose prose-caps`,t===`dropcap`&&`caps-prose-dropcap`,e),ref:r})});function kc(e){return URL.parse(e)?.protocol??null}function Ac(e){if(e===``||e.startsWith(`//`))return!1;let t=kc(e);return t===null||t===`http:`||t===`https:`||t===`mailto:`}function jc(e){let t=kc(e);return t===`http:`||t===`https:`}function Mc(e){if(e===``||e.startsWith(`//`))return!1;let t=kc(e);return t===null||t===`http:`||t===`https:`}function Nc({children:e,className:t,components:n,frontmatter:r=!0,policy:i=`default`,typography:o=`prose`}){let s=(0,V.useMemo)(()=>Po(e,{allowHtml:!1,frontmatter:r}),[e,r]),c=(0,V.useMemo)(()=>({...n,a(e){let t=e.href??``;if(i===`visitor`){let n=URL.parse(t);return n===null||!jc(n.href)?(0,B.jsx)(`span`,{children:e.children}):(0,B.jsx)(`a`,{href:n.href,target:`_blank`,rel:`noopener noreferrer`,children:e.children})}if(!Ac(t))return(0,B.jsx)(B.Fragment,{children:e.children});let n=jc(t);return(0,B.jsx)(`a`,{...e,href:t,rel:n?`noopener noreferrer`:e.rel,target:n?`_blank`:e.target})},img(e){if(i===`visitor`)return(0,B.jsx)(`span`,{className:`text-dim`,children:`Image removed`});let t=e.src??``;return Mc(t)?n?.img?(0,V.createElement)(n.img,e):(0,B.jsx)(`img`,{alt:e.alt??``,className:`max-w-full`,src:t}):(0,B.jsx)(B.Fragment,{children:e.alt??``})}}),[n,i]),l=(0,B.jsx)(Jo,{allowHtml:!1,components:c,highlighter:Dc,children:s}),u=a(`min-w-0 break-words`,t);return o===`prose`?(0,B.jsx)(Oc,{className:u,children:l}):(0,B.jsx)(`div`,{className:u,children:l})}function Pc(e){return e.replace(/^\uFEFF/u,``).replace(/\r\n?/gu,`
|
|
554
|
-
`)}function Fc({document:e,theme:t,sourceLabel:n,savedConflict:r=!1}){if(!e.conflict)return null;let i=e.saving||e.resolving;return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`div`,{className:`inkcap-conflict`,role:`region`,"aria-label":`File conflict`,children:[(0,B.jsx)(Te,{tone:`warning`,title:n?`The repository changed since you opened this file`:`This file changed on the Computer since you opened it`,description:r?`Your file is saved in Bonsai. Your saved text and any newer edits stay here.`:`Your edits are still here and have not been saved.`}),(0,B.jsxs)(`div`,{className:`flex flex-wrap gap-xs`,children:[(0,B.jsx)(h,{size:`sm`,disabled:i,onClick:()=>{e.keepMine()},children:`Keep mine`}),(0,B.jsx)(h,{size:`sm`,variant:`outline`,disabled:i,onClick:()=>{e.reloadTheirs()},children:`Reload theirs`}),(0,B.jsx)(h,{size:`sm`,variant:`ghost`,disabled:i,onClick:()=>{e.compare()},children:e.resolving?`Loading…`:`Compare`})]}),(0,B.jsxs)(`p`,{className:`text-xs text-dim`,children:[`Keep mine`,` `,n?`saves your file in Bonsai and retries sync`:`overwrites the Computer file`,`. Reload theirs replaces your edits.`]})]}),(0,B.jsx)(d,{open:e.comparison!==null,onOpenChange:t=>{t||e.closeComparison()},children:(0,B.jsxs)(C,{className:`inkcap-compare-dialog`,children:[(0,B.jsxs)(T,{children:[(0,B.jsx)(m,{children:`Compare file versions`}),(0,B.jsxs)(p,{children:[`Removed lines are from `,n??`the Computer`,`. Added lines are your edits. Nothing is saved by comparing.`]})]}),(0,B.jsx)(`div`,{className:`inkcap-conflict-diff`,role:`region`,"aria-label":`File comparison`,children:e.comparison===null?null:(0,B.jsx)(pn,{oldFile:{name:e.currentPath,contents:Pc(e.comparison)},newFile:{name:e.currentPath,contents:Pc(e.contents)},options:{diffStyle:`unified`,disableFileHeader:!0,themeType:t===`mocha`?`dark`:`light`,theme:{dark:`catppuccin-mocha`,light:`catppuccin-latte`}}})}),(0,B.jsx)(v,{children:(0,B.jsx)(h,{variant:`ghost`,onClick:e.closeComparison,children:`Back to editing`})})]})})]})}function Ic(e,t){return{...e,contents:t}}function Lc(e,t){return{...e,saved:t}}function Rc(e){return e.contents!==e.saved}function zc({path:e,initial:t,local:n,onSaveAs:r,onPathChange:i,onStatus:a,write:s,overwrite:c,readCurrent:l,target:u,syncConflict:d=!1}){let f=(0,V.useRef)({saved:t,contents:t}),p=(0,V.useRef)(e),m=(0,V.useRef)(s),h=(0,V.useRef)(c),g=(0,V.useRef)(l),_=(0,V.useRef)(r),v=(0,V.useRef)(i),y=(0,V.useRef)(a),b=(0,V.useRef)(u);m.current=s,h.current=c,g.current=l,_.current=r,v.current=i,y.current=a,b.current=u;let[x,S]=(0,V.useState)(!1),[C,w]=(0,V.useState)(t),[T,E]=(0,V.useState)(!1),[ee,D]=(0,V.useState)(``),[O,k]=(0,V.useState)(!1),A=(0,V.useRef)(!1),j=(0,V.useRef)(d);j.current=d;function M(e){A.current=e,k(e)}let[N,P]=(0,V.useState)(null),[F,I]=(0,V.useState)(!1),[te,ne]=(0,V.useState)(0),[re,ie]=(0,V.useState)(!1),L=(0,V.useRef)(!1),R=(0,V.useRef)({dirty:!1,saving:!1});function z(e,t){S(e),E(t);let n=b.current;n&&(n.revision+=1,n.dirty=e,n.saving=t),(R.current.dirty!==e||R.current.saving!==t)&&(R.current={dirty:e,saving:t},y.current(e,t))}function ae(e){f.current=Ic(f.current,e),w(e),z(Rc(f.current)||A.current,R.current.saving)}async function oe(){if(L.current||O||j.current)return!1;if(!Rc(f.current))return!0;L.current=!0,z(!0,!0),D(``);let e=f.current.contents;try{return await m.current(e,f.current.saved),f.current=Lc(f.current,e),z(Rc(f.current)||A.current,!0),!0}catch(e){if(e instanceof o&&e.code===`CANCELLED`)return!1;if(e instanceof o&&e.code===`CONFLICT`)return M(!0),P(null),!1;console.error(`Inkcap save failed`,e);let t=n?`Download could not start. Your edits remain in this tab.`:`Save was denied or failed. Your edits remain in this tab; retry with the same or another path.`;throw D(t),Error(t,{cause:e})}finally{L.current=!1,z(Rc(f.current)||A.current,!1)}}async function se(){if(!O&&!j.current||L.current)return!1;L.current=!0,z(!0,!0),D(``);let e=f.current.contents;try{return await h.current(e),f.current=Lc(f.current,e),M(!1),P(null),!0}catch(e){return e instanceof o&&e.code===`CANCELLED`?!1:(console.error(`Inkcap explicit overwrite failed`,e),D(`Could not overwrite the file. Your edits remain in this tab.`),!1)}finally{L.current=!1,z(Rc(f.current)||A.current,!1)}}async function ce(e){if(!O&&!j.current||L.current)return!1;L.current=!0,I(!0),D(``);let t=b.current?.revision,n=f.current.contents;try{let r=await g.current(e);return b.current?.closed?!1:e?f.current.contents!==n||b.current?.revision!==t?(D(`Your edits changed while reloading. They remain in this tab; compare or reload again.`),!1):(f.current={saved:r,contents:r},w(r),M(!1),P(null),ne(e=>e+1),z(!1,!1),!0):(P(r),!0)}catch(e){return console.error(`Inkcap conflict read failed`,e),D(`Could not read the file. Your edits remain in this tab.`),!1}finally{L.current=!1,I(!1)}}async function le(e){let t=e.trim();if(!n&&t===p.current)return oe();if(!t||t.endsWith(`/`)||L.current)return!1;L.current=!0,z(!0,!0),D(``);let r=f.current.contents;try{if(!_.current)throw Error(`Save As is unavailable`);let e=await _.current(t,r);return f.current=Lc(f.current,r),p.current=e,M(!1),P(null),v.current?.(e),z(Rc(f.current)||A.current,!0),!0}catch(e){return e instanceof o&&e.code===`CANCELLED`?!1:(console.error(`Inkcap save failed`,e),D(`Save As was denied or failed. Your edits remain in this tab; retry with the same or another path.`),!1)}finally{L.current=!1,z(Rc(f.current)||A.current,!1)}}return{currentPath:p.current,contents:C,dirty:x,saving:T,error:ee,conflict:O||d,comparison:N,resolving:F,reloadVersion:te,keepMine:se,compare:()=>ce(!1),reloadTheirs:()=>ce(!0),closeComparison:()=>{P(null)},imageError:re,setImageError:ie,edit:ae,save:oe,saveAs:le}}function Bc({path:e,initial:t,active:n,menuSlot:r,narrow:i,tabKey:a,savable:o,local:s,sourceLabel:c,activityNotice:l,onDismissActivityNotice:u,previewUrl:d,previewKind:f,onReopen:p,onSaveAs:m,pathExists:h,onPathChange:g,target:_,write:v,overwrite:y,readCurrent:b,onStatus:x,onSaveBinding:S,saveAsDirectory:C,downloads:w=!1,onSaved:T,syncConflict:E=!1}){let[ee,D]=(0,V.useState)(()=>ae()??`latte`),O=(0,V.useRef)(null),[k,A]=(0,V.useState)(!1),[j,M]=(0,V.useState)(!1);(0,V.useEffect)(()=>{let e=O.current?.closest(`[data-theme]`);return D(ae(e??void 0)??`latte`),lt(D,e??void 0)},[]);let N=zc({path:e,initial:t,local:s,onSaveAs:m,onPathChange:g,onStatus:x,target:_,write:v,overwrite:y,readCurrent:b,syncConflict:E}),P=(0,V.useRef)(N.save),F=(0,V.useRef)(s),I=(0,V.useRef)(N.currentPath),te=(0,V.useRef)(T),ne=(0,V.useRef)(w),re=(0,V.useRef)(N.saving),ie=(0,V.useRef)(o),L=(0,V.useRef)(!1),R=(0,V.useRef)(!1),z=(0,V.useRef)(!1),oe=(0,V.useRef)(null),se=(0,V.useRef)(n);se.current=n,(0,V.useEffect)(()=>{n&&oe.current?.focus()},[n]);let ce=(0,V.useRef)(N.edit),le=(0,V.useRef)(N.contents);ce.current=N.edit,le.current=N.contents;let ue=()=>{let e=oe.current?.getFile()?.contents;return e!==void 0&&e!==le.current?e:null};P.current=N.save,F.current=s,I.current=N.currentPath,te.current=T,ne.current=w,re.current=N.saving,ie.current=o&&!N.conflict&&!N.resolving,L.current=N.dirty,R.current=_?.closed??!1,z.current=!!(m&&!d);let de=async()=>{if(F.current)return A(!0),!0;let e=ue();e!==null&&ce.current(e);let t=await P.current();return t&&te.current?.(Wc(I.current),ne.current),t},fe=async e=>{let t=await N.saveAs(e);return t&&te.current?.(Wc(e),ne.current),t},pe=(0,V.useMemo)(()=>({availability:()=>mn({local:F.current,closed:R.current,savable:ie.current,saving:_?.saving??re.current,dirty:L.current}),save:()=>de(),saveAsAvailability:()=>R.current||!z.current?{status:`unavailable`,reason:`This file cannot be saved as.`}:ie.current?_?.saving??re.current?{status:`unavailable`,reason:`A save is already running.`}:{status:`available`}:{status:`unavailable`,reason:`No focused savable document.`},saveAs:()=>{A(!0)}}),[]);(0,V.useEffect)(()=>(S(a,pe),()=>{S(a,void 0)}),[S,pe,a,N.dirty,N.saving,N.conflict,N.resolving,o,_?.closed]);let me=(0,V.useMemo)(()=>({name:N.currentPath,contents:N.contents}),[N.currentPath,N.contents]),he=(0,V.useMemo)(()=>({onAttach:e=>{oe.current=e,se.current&&e.focus({lineNumber:1,character:0})},onChange:e=>{ce.current(e.contents)}}),[]),ge=Ce(N.currentPath);return(0,B.jsx)(Vc,{themeRoot:O,menuSlot:n?r:null,tabKey:a,savable:o,narrow:i,local:s,sourceLabel:c,savedConflict:E,activityNotice:l,onDismissActivityNotice:u,previewUrl:d,previewKind:f,onSaveAs:m,pathExists:w?void 0:h,onSave:de,onSubmitSaveAs:fe,saveAsDirectory:w?null:C??null,downloads:w,onReopen:p,document:N,file:me,editorOptions:he,theme:ee,saveAsOpen:k,setSaveAsOpen:A,canPreviewMarkdown:ge,markdownPreview:ge&&j,onToggleMarkdownPreview:()=>{M(e=>!e)}})}function Vc({themeRoot:e,menuSlot:n,tabKey:r,savable:i,narrow:a,local:o,sourceLabel:s,savedConflict:c,activityNotice:l,onDismissActivityNotice:u,previewUrl:d,previewKind:f,onSaveAs:p,pathExists:m,onSave:h,onSubmitSaveAs:g,saveAsDirectory:_,downloads:v,onReopen:b,document:S,file:C,editorOptions:w,theme:T,saveAsOpen:E,setSaveAsOpen:ee,canPreviewMarkdown:D,markdownPreview:O,onToggleMarkdownPreview:k}){return(0,B.jsxs)(L,{ref:e,className:`inkcap-editor mt-0`,value:String(r),forceMount:!0,"aria-label":S.currentPath,children:[n?(0,ro.createPortal)((0,B.jsx)(Hc,{savable:i&&!S.conflict&&!S.resolving,path:S.currentPath,dirty:S.dirty,saving:S.saving,local:o,canSaveAs:!!(p&&!d),canPreviewMarkdown:D,markdownPreview:O,onToggleMarkdownPreview:k,onSave:()=>{h().catch(e=>{console.error(`Inkcap save failed`,e)})},onSaveAs:()=>{ee(!0)},onReopen:b}),n):null,l?(0,B.jsx)(Te,{className:`inkcap-notice`,tone:`warning`,role:`status`,title:`Recent files didn't update`,description:`${Uc(o,S.dirty,S.saving)} worked; the Recent Files list could not record it.`,action:(0,B.jsx)(t,{icon:(0,B.jsx)(y,{}),"aria-label":`Dismiss Recent Files notice`,title:`Dismiss Recent Files notice`,variant:`ghost`,size:`responsive`,onClick:u})}):null,(0,B.jsx)(Fc,{document:S,theme:T,sourceLabel:s,savedConflict:c}),S.error?(0,B.jsx)(Te,{className:`inkcap-notice`,tone:`error`,title:S.conflict?`Couldn't resolve the file conflict`:`Couldn't save`,description:S.error}):null,(0,B.jsx)(Kc,{previewUrl:d,previewKind:f,path:S.currentPath,imageError:S.imageError,setImageError:S.setImageError,file:C,editorOptions:w,theme:T,narrow:a,markdownPreview:O},`${String(S.reloadVersion)}:${S.currentPath}`),(0,B.jsx)(Yc,{sourceLabel:s,error:S.error,path:o&&!S.currentPath.startsWith(`/`)?x(_,S.currentPath,S.contents):S.currentPath,selectName:o,downloads:v,open:E,busy:S.saving,pathExists:m,onSubmit:g,onOpenChange:ee})]})}function Hc({savable:e,path:n,dirty:r,saving:i,local:a,canSaveAs:o,canPreviewMarkdown:s,markdownPreview:c,onToggleMarkdownPreview:l,onSave:u,onSaveAs:d,onReopen:f}){return(0,B.jsxs)(mt,{children:[(0,B.jsx)(it,{render:(0,B.jsx)(t,{variant:`ghost`,size:`responsive`,icon:(0,B.jsx)(At,{}),"aria-label":`More`,title:`More`})}),(0,B.jsxs)(ut,{align:`end`,children:[(0,B.jsx)(Ke,{disabled:!e||!a&&!r||i,onSelect:u,children:Uc(a,r,i)}),o?(0,B.jsx)(Ke,{disabled:!e||i,onSelect:d,children:`Save file as`}):null,f?(0,B.jsx)(Ke,{disabled:!e||r||i,onSelect:f,children:`Reload from disk`}):null,s?(0,B.jsx)(nt,{checked:c,onSelect:l,children:`Preview Markdown`}):null,(0,B.jsx)(je,{}),(0,B.jsx)(Ke,{onSelect:()=>{globalThis.navigator.clipboard.writeText(n).catch(e=>{console.error(`Inkcap could not copy the path`,e)})},children:`Copy path`})]})]})}function Uc(e,t,n){return n?`Saving…`:e||t?`Save`:`Saved`}function Wc(e){return e.trim().split(`/`).at(-1)??e}function Gc(e){let t=e.lastIndexOf(`/`)+1,n=e.lastIndexOf(`.`);return[t,n>t?n:e.length]}function Kc({previewUrl:e,previewKind:t,path:n,imageError:r,setImageError:i,file:a,editorOptions:o,theme:s,narrow:c,markdownPreview:l}){return e?t===`video`?(0,B.jsx)(Jc,{path:n,url:e}):(0,B.jsx)(qc,{path:n,url:e,failed:r,onFailed:i}):l?(0,B.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto`,children:(0,B.jsx)(Nc,{className:`max-w-none p-lg`,children:a.contents})}):(0,B.jsx)(`div`,{className:`inkcap-code`,children:(0,B.jsx)(ce,{createEditor:e=>new no(e),children:(0,B.jsx)(fn,{file:a,edit:!0,editorOptions:o,options:{disableFileHeader:!0,overflow:c?`wrap`:`scroll`,themeType:s===`mocha`?`dark`:`light`,theme:{dark:`catppuccin-mocha`,light:`catppuccin-latte`}}})})})}function qc({path:e,url:t,failed:n,onFailed:r}){let i=A(e)===`image/svg+xml`;return(0,B.jsx)(`div`,{className:`inkcap-preview`,children:n?(0,B.jsxs)(`div`,{role:`alert`,children:[(0,B.jsx)(`strong`,{children:`Preview unavailable`}),(0,B.jsx)(`span`,{children:e})]}):(0,B.jsx)(`img`,{src:t,alt:e,draggable:!i&&void 0,onContextMenu:e=>{i&&e.preventDefault()},onError:()=>{i&&URL.revokeObjectURL(t),r(!0)},onLoad:()=>{i&&URL.revokeObjectURL(t),r(!1)}})})}function Jc({path:e,url:t}){return(0,B.jsx)(`div`,{className:`inkcap-preview`,children:(0,B.jsx)(`video`,{src:t,controls:!0,"aria-label":e})})}function Yc({sourceLabel:e,error:t,path:n,selectName:r,downloads:i,open:a,busy:o,pathExists:s,onSubmit:c,onOpenChange:l}){let[u,f]=(0,V.useState)(null),g=(0,V.useRef)(null),_=(0,V.useRef)(null),y=(0,V.useRef)(!1),x=kt({defaultValues:{path:n},onSubmit:async({value:e})=>{if(_.current!==e.path&&s){let t=await s(e.path);if(t===`unchecked`)return;if(t===`exists`){f(e.path);return}}_.current=null,await c(e.path)&&l(!1)}}),S=Ot(x.store,e=>e.isSubmitting),w=o||S,E=(0,V.useRef)(n);return E.current=n,(0,V.useEffect)(()=>{a&&(_.current=null,f(null),x.setFieldValue(`path`,E.current))},[a]),(0,V.useEffect)(()=>{if(u!==null||!y.current)return;y.current=!1;let e=g.current;if(!e)return;e.focus();let[t,n]=Gc(e.value);e.setSelectionRange(t,n)},[u]),(0,B.jsx)(d,{open:a&&!(e&&o),onOpenChange:e=>{o||l(e)},children:(0,B.jsxs)(C,{children:[(0,B.jsxs)(T,{className:`mb-4`,children:[(0,B.jsx)(m,{children:i?`Download file`:`Save file`}),(0,B.jsx)(p,{children:i?`Choose a name for the file. It goes to your Downloads folder.`:e?`Choose a path in ${e}.`:`Choose where to save it on your Computer.`})]}),(0,B.jsxs)(`div`,{className:`space-y-4`,children:[(0,B.jsx)(x.Field,{name:`path`,validators:{onChange:({value:e})=>e.trim()?e.trim().endsWith(`/`)?`Save As needs a file path.`:void 0:`A file path is required.`},children:n=>(0,B.jsx)(Et,{label:i?`File name`:e?`Path`:`Location`,required:!0,error:n.state.meta.errors[0]??t,children:(0,B.jsx)(Dt,{value:n.state.value,onBlur:n.handleBlur,onChange:e=>{n.handleChange(e.target.value)},onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&(e.preventDefault(),w||x.handleSubmit())},ref:g,autoFocus:!0,onFocus:e=>{if(!r)return;let t=e.currentTarget,[n,i]=Gc(t.value);t.setSelectionRange(n,i)},disabled:w||u!==null,required:!0})})}),u===null?(0,B.jsxs)(v,{children:[(0,B.jsx)(b,{disabled:w,children:`Cancel`}),(0,B.jsx)(h,{type:`button`,disabled:w,onClick:()=>{x.handleSubmit()},children:i?w?`Downloading…`:`Download`:w?`Saving…`:`Save`})]}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(Te,{tone:`warning`,role:`alert`,title:`${Wc(u)} already exists. Replace it?`}),(0,B.jsxs)(v,{children:[(0,B.jsx)(h,{type:`button`,variant:`ghost`,onClick:()=>{_.current=null,y.current=!0,f(null)},children:`Cancel`}),(0,B.jsx)(h,{type:`button`,onClick:()=>{_.current=u,f(null),x.handleSubmit()},children:`Replace`})]})]})]})]})})}export{Bc as FileTab};
|
|
554
|
+
`)}function Fc({document:e,theme:t,sourceLabel:n,savedConflict:r=!1}){if(!e.conflict)return null;let i=e.saving||e.resolving;return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`div`,{className:`inkcap-conflict`,role:`region`,"aria-label":`File conflict`,children:[(0,B.jsx)(Te,{tone:`warning`,title:n?`The repository changed since you opened this file`:`This file changed on the Computer since you opened it`,description:r?`Your file is saved in Bonsai. Your saved text and any newer edits stay here.`:`Your edits are still here and have not been saved.`}),(0,B.jsxs)(`div`,{className:`flex flex-wrap gap-xs`,children:[(0,B.jsx)(h,{size:`sm`,disabled:i,onClick:()=>{e.keepMine()},children:`Keep mine`}),(0,B.jsx)(h,{size:`sm`,variant:`outline`,disabled:i,onClick:()=>{e.reloadTheirs()},children:`Reload theirs`}),(0,B.jsx)(h,{size:`sm`,variant:`ghost`,disabled:i,onClick:()=>{e.compare()},children:e.resolving?`Loading…`:`Compare`})]}),(0,B.jsxs)(`p`,{className:`text-xs text-dim`,children:[`Keep mine`,` `,n?`saves your file in Bonsai and retries sync`:`overwrites the Computer file`,`. Reload theirs replaces your edits.`]})]}),(0,B.jsx)(d,{open:e.comparison!==null,onOpenChange:t=>{t||e.closeComparison()},children:(0,B.jsxs)(C,{className:`inkcap-compare-dialog`,children:[(0,B.jsxs)(T,{children:[(0,B.jsx)(m,{children:`Compare file versions`}),(0,B.jsxs)(p,{children:[`Removed lines are from `,n??`the Computer`,`. Added lines are your edits. Nothing is saved by comparing.`]})]}),(0,B.jsx)(`div`,{className:`inkcap-conflict-diff`,role:`region`,"aria-label":`File comparison`,children:e.comparison===null?null:(0,B.jsx)(pn,{oldFile:{name:e.currentPath,contents:Pc(e.comparison)},newFile:{name:e.currentPath,contents:Pc(e.contents)},options:{diffStyle:`unified`,disableFileHeader:!0,themeType:t===`mocha`?`dark`:`light`,theme:{dark:`catppuccin-mocha`,light:`catppuccin-latte`}}})}),(0,B.jsx)(v,{children:(0,B.jsx)(h,{variant:`ghost`,onClick:e.closeComparison,children:`Back to editing`})})]})})]})}function Ic(e,t){return{...e,contents:t}}function Lc(e,t){return{...e,saved:t}}function Rc(e){return e.contents!==e.saved}function zc({path:e,initial:t,local:n,onSaveAs:r,onPathChange:i,onStatus:a,write:s,overwrite:c,readCurrent:l,target:u,syncConflict:d=!1}){let f=(0,V.useRef)({saved:t,contents:t}),p=(0,V.useRef)(e),m=(0,V.useRef)(s),h=(0,V.useRef)(c),g=(0,V.useRef)(l),_=(0,V.useRef)(r),v=(0,V.useRef)(i),y=(0,V.useRef)(a),b=(0,V.useRef)(u);m.current=s,h.current=c,g.current=l,_.current=r,v.current=i,y.current=a,b.current=u;let[x,S]=(0,V.useState)(!1),[C,w]=(0,V.useState)(t),[T,E]=(0,V.useState)(!1),[ee,D]=(0,V.useState)(``),[O,k]=(0,V.useState)(!1),A=(0,V.useRef)(!1),j=(0,V.useRef)(d);j.current=d;function M(e){A.current=e,k(e)}let[N,P]=(0,V.useState)(null),[F,I]=(0,V.useState)(!1),[te,ne]=(0,V.useState)(0),[re,ie]=(0,V.useState)(!1),L=(0,V.useRef)(!1),R=(0,V.useRef)({dirty:!1,saving:!1});function z(e,t){S(e),E(t);let n=b.current;n&&(n.revision+=1,n.dirty=e,n.saving=t),(R.current.dirty!==e||R.current.saving!==t)&&(R.current={dirty:e,saving:t},y.current(e,t))}function ae(e){f.current=Ic(f.current,e),w(e),z(Rc(f.current)||A.current,R.current.saving)}async function oe(){if(L.current||O||j.current)return!1;if(!Rc(f.current))return!0;L.current=!0,z(!0,!0),D(``);let e=f.current.contents;try{return await m.current(e,f.current.saved),f.current=Lc(f.current,e),z(Rc(f.current)||A.current,!0),!0}catch(e){if(e instanceof o&&e.code===`CANCELLED`)return!1;if(e instanceof o&&e.code===`CONFLICT`)return M(!0),P(null),!1;console.error(`Inkcap save failed`,e);let t=n?`Download could not start. Your edits remain in this tab.`:`Save was denied or failed. Your edits remain in this tab; retry with the same or another path.`;throw D(t),Error(t,{cause:e})}finally{L.current=!1,z(Rc(f.current)||A.current,!1)}}async function se(){if(!O&&!j.current||L.current)return!1;L.current=!0,z(!0,!0),D(``);let e=f.current.contents;try{return await h.current(e),f.current=Lc(f.current,e),M(!1),P(null),!0}catch(e){return e instanceof o&&e.code===`CANCELLED`?!1:(console.error(`Inkcap explicit overwrite failed`,e),D(`Could not overwrite the file. Your edits remain in this tab.`),!1)}finally{L.current=!1,z(Rc(f.current)||A.current,!1)}}async function ce(e){if(!O&&!j.current||L.current)return!1;L.current=!0,I(!0),D(``);let t=b.current?.revision,n=f.current.contents;try{let r=await g.current(e);return b.current?.closed?!1:e?f.current.contents!==n||b.current?.revision!==t?(D(`Your edits changed while reloading. They remain in this tab; compare or reload again.`),!1):(f.current={saved:r,contents:r},w(r),M(!1),P(null),ne(e=>e+1),z(!1,!1),!0):(P(r),!0)}catch(e){return console.error(`Inkcap conflict read failed`,e),D(`Could not read the file. Your edits remain in this tab.`),!1}finally{L.current=!1,I(!1)}}async function le(e){let t=e.trim();if(!n&&t===p.current)return oe();if(!t||t.endsWith(`/`)||L.current)return!1;L.current=!0,z(!0,!0),D(``);let r=f.current.contents;try{if(!_.current)throw Error(`Save As is unavailable`);let e=await _.current(t,r);return f.current=Lc(f.current,r),p.current=e,M(!1),P(null),v.current?.(e),z(Rc(f.current)||A.current,!0),!0}catch(e){return e instanceof o&&e.code===`CANCELLED`?!1:(console.error(`Inkcap save failed`,e),D(`Save As was denied or failed. Your edits remain in this tab; retry with the same or another path.`),!1)}finally{L.current=!1,z(Rc(f.current)||A.current,!1)}}return{currentPath:p.current,contents:C,dirty:x,saving:T,error:ee,conflict:O||d,comparison:N,resolving:F,reloadVersion:te,keepMine:se,compare:()=>ce(!1),reloadTheirs:()=>ce(!0),closeComparison:()=>{P(null)},imageError:re,setImageError:ie,edit:ae,save:oe,saveAs:le}}function Bc({path:e,initial:t,active:n,menuSlot:r,narrow:i,tabKey:a,savable:o,local:s,sourceLabel:c,activityNotice:l,onDismissActivityNotice:u,previewUrl:d,previewKind:f,onReopen:p,onSaveAs:m,pathExists:h,onPathChange:g,target:_,write:v,overwrite:y,readCurrent:b,onStatus:x,onSaveBinding:S,saveAsDirectory:C,downloads:w=!1,onSaved:T,syncConflict:E=!1}){let[ee,D]=(0,V.useState)(()=>ae()??`latte`),O=(0,V.useRef)(null),[k,A]=(0,V.useState)(!1),[j,M]=(0,V.useState)(!1);(0,V.useEffect)(()=>{let e=O.current?.closest(`[data-theme]`);return D(ae(e??void 0)??`latte`),lt(D,e??void 0)},[]);let N=zc({path:e,initial:t,local:s,onSaveAs:m,onPathChange:g,onStatus:x,target:_,write:v,overwrite:y,readCurrent:b,syncConflict:E}),P=(0,V.useRef)(N.save),F=(0,V.useRef)(s),I=(0,V.useRef)(N.currentPath),te=(0,V.useRef)(T),ne=(0,V.useRef)(w),re=(0,V.useRef)(N.saving),ie=(0,V.useRef)(o),L=(0,V.useRef)(!1),R=(0,V.useRef)(!1),z=(0,V.useRef)(!1),oe=(0,V.useRef)(null),se=(0,V.useRef)(n);se.current=n,(0,V.useEffect)(()=>{n&&oe.current?.focus()},[n]);let ce=(0,V.useRef)(N.edit),le=(0,V.useRef)(N.contents);ce.current=N.edit,le.current=N.contents;let ue=()=>{let e=oe.current?.getFile()?.contents;return e!==void 0&&e!==le.current?e:null};P.current=N.save,F.current=s,I.current=N.currentPath,te.current=T,ne.current=w,re.current=N.saving,ie.current=o&&!N.conflict&&!N.resolving,L.current=N.dirty,R.current=_?.closed??!1,z.current=!!(m&&!d);let de=async()=>{if(F.current)return A(!0),!0;let e=ue();e!==null&&ce.current(e);let t=await P.current();return t&&te.current?.(Wc(I.current),ne.current),t},fe=async e=>{let t=await N.saveAs(e);return t&&te.current?.(Wc(e),ne.current),t},pe=(0,V.useMemo)(()=>({availability:()=>mn({local:F.current,closed:R.current,savable:ie.current,saving:_?.saving??re.current,dirty:L.current}),save:()=>de(),saveAsAvailability:()=>R.current||!z.current?{status:`unavailable`,reason:`This file cannot be saved as.`}:ie.current?_?.saving??re.current?{status:`unavailable`,reason:`A save is already running.`}:{status:`available`}:{status:`unavailable`,reason:`No focused savable document.`},saveAs:()=>{A(!0)}}),[]);(0,V.useEffect)(()=>(S(a,pe),()=>{S(a,void 0)}),[S,pe,a,N.dirty,N.saving,N.conflict,N.resolving,o,_?.closed]);let me=(0,V.useMemo)(()=>({name:N.currentPath,contents:N.contents}),[N.currentPath,N.contents]),he=(0,V.useMemo)(()=>({onAttach:e=>{oe.current=e,se.current&&e.focus({lineNumber:1,character:0})},onChange:e=>{ce.current(e.contents)}}),[]),ge=Ce(N.currentPath);return(0,B.jsx)(Vc,{themeRoot:O,menuSlot:n?r:null,tabKey:a,savable:o,saveAvailability:pe.availability(),narrow:i,local:s,sourceLabel:c,savedConflict:E,activityNotice:l,onDismissActivityNotice:u,previewUrl:d,previewKind:f,onSaveAs:m,pathExists:w?void 0:h,onSave:de,onSubmitSaveAs:fe,saveAsDirectory:w?null:C??null,downloads:w,onReopen:p,document:N,file:me,editorOptions:he,theme:ee,saveAsOpen:k,setSaveAsOpen:A,canPreviewMarkdown:ge,markdownPreview:ge&&j,onToggleMarkdownPreview:()=>{M(e=>!e)}})}function Vc({themeRoot:e,menuSlot:n,tabKey:r,savable:i,saveAvailability:a,narrow:o,local:s,sourceLabel:c,savedConflict:l,activityNotice:u,onDismissActivityNotice:d,previewUrl:f,previewKind:p,onSaveAs:m,pathExists:h,onSave:g,onSubmitSaveAs:_,saveAsDirectory:v,downloads:b,onReopen:S,document:C,file:w,editorOptions:T,theme:E,saveAsOpen:ee,setSaveAsOpen:D,canPreviewMarkdown:O,markdownPreview:k,onToggleMarkdownPreview:A}){return(0,B.jsxs)(L,{ref:e,className:`inkcap-editor mt-0`,value:String(r),forceMount:!0,"aria-label":C.currentPath,children:[n?(0,ro.createPortal)((0,B.jsx)(Hc,{savable:i&&!C.conflict&&!C.resolving,path:C.currentPath,dirty:C.dirty,saving:C.saving,local:s,saveAvailability:a,canSaveAs:!!(m&&!f),canPreviewMarkdown:O,markdownPreview:k,onToggleMarkdownPreview:A,onSave:()=>{g().catch(e=>{console.error(`Inkcap save failed`,e)})},onSaveAs:()=>{D(!0)},onReopen:S}),n):null,u?(0,B.jsx)(Te,{className:`inkcap-notice`,tone:`warning`,role:`status`,title:`Recent files didn't update`,description:`${Uc(s,C.dirty,C.saving)} worked; the Recent Files list could not record it.`,action:(0,B.jsx)(t,{icon:(0,B.jsx)(y,{}),"aria-label":`Dismiss Recent Files notice`,title:`Dismiss Recent Files notice`,variant:`ghost`,size:`responsive`,onClick:d})}):null,(0,B.jsx)(Fc,{document:C,theme:E,sourceLabel:c,savedConflict:l}),C.error?(0,B.jsx)(Te,{className:`inkcap-notice`,tone:`error`,title:C.conflict?`Couldn't resolve the file conflict`:`Couldn't save`,description:C.error}):null,(0,B.jsx)(Kc,{previewUrl:f,previewKind:p,path:C.currentPath,imageError:C.imageError,setImageError:C.setImageError,file:w,editorOptions:T,theme:E,narrow:o,markdownPreview:k},`${String(C.reloadVersion)}:${C.currentPath}`),(0,B.jsx)(Yc,{sourceLabel:c,error:C.error,path:s&&!C.currentPath.startsWith(`/`)?x(v,C.currentPath,C.contents):C.currentPath,selectName:s,downloads:b,open:ee,busy:C.saving,pathExists:h,onSubmit:_,onOpenChange:D})]})}function Hc({savable:e,saveAvailability:n,path:r,dirty:i,saving:a,local:o,canSaveAs:s,canPreviewMarkdown:c,markdownPreview:l,onToggleMarkdownPreview:u,onSave:d,onSaveAs:f,onReopen:p}){return(0,B.jsxs)(mt,{children:[(0,B.jsx)(it,{render:(0,B.jsx)(t,{variant:`ghost`,size:`responsive`,icon:(0,B.jsx)(At,{}),"aria-label":`More`,title:`More`})}),(0,B.jsxs)(ut,{align:`end`,children:[(0,B.jsx)(Ke,{disabled:n.status===`unavailable`,onSelect:d,children:Uc(o,i,a)}),s?(0,B.jsx)(Ke,{disabled:!e||a,onSelect:f,children:`Save file as`}):null,p?(0,B.jsx)(Ke,{disabled:!e||i||a,onSelect:p,children:`Reload from disk`}):null,c?(0,B.jsx)(nt,{checked:l,onSelect:u,children:`Preview Markdown`}):null,(0,B.jsx)(je,{}),(0,B.jsx)(Ke,{onSelect:()=>{globalThis.navigator.clipboard.writeText(r).catch(e=>{console.error(`Inkcap could not copy the path`,e)})},children:`Copy path`})]})]})}function Uc(e,t,n){return n?`Saving…`:e||t?`Save`:`Saved`}function Wc(e){return e.trim().split(`/`).at(-1)??e}function Gc(e){let t=e.lastIndexOf(`/`)+1,n=e.lastIndexOf(`.`);return[t,n>t?n:e.length]}function Kc({previewUrl:e,previewKind:t,path:n,imageError:r,setImageError:i,file:a,editorOptions:o,theme:s,narrow:c,markdownPreview:l}){return e?t===`video`?(0,B.jsx)(Jc,{path:n,url:e}):(0,B.jsx)(qc,{path:n,url:e,failed:r,onFailed:i}):l?(0,B.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto`,children:(0,B.jsx)(Nc,{className:`max-w-none p-lg`,children:a.contents})}):(0,B.jsx)(`div`,{className:`inkcap-code`,children:(0,B.jsx)(ce,{createEditor:e=>new no(e),children:(0,B.jsx)(fn,{file:a,edit:!0,editorOptions:o,options:{disableFileHeader:!0,overflow:c?`wrap`:`scroll`,themeType:s===`mocha`?`dark`:`light`,theme:{dark:`catppuccin-mocha`,light:`catppuccin-latte`}}})})})}function qc({path:e,url:t,failed:n,onFailed:r}){let i=A(e)===`image/svg+xml`;return(0,B.jsx)(`div`,{className:`inkcap-preview`,children:n?(0,B.jsxs)(`div`,{role:`alert`,children:[(0,B.jsx)(`strong`,{children:`Preview unavailable`}),(0,B.jsx)(`span`,{children:e})]}):(0,B.jsx)(`img`,{src:t,alt:e,draggable:!i&&void 0,onContextMenu:e=>{i&&e.preventDefault()},onError:()=>{i&&URL.revokeObjectURL(t),r(!0)},onLoad:()=>{i&&URL.revokeObjectURL(t),r(!1)}})})}function Jc({path:e,url:t}){return(0,B.jsx)(`div`,{className:`inkcap-preview`,children:(0,B.jsx)(`video`,{src:t,controls:!0,"aria-label":e})})}function Yc({sourceLabel:e,error:t,path:n,selectName:r,downloads:i,open:a,busy:o,pathExists:s,onSubmit:c,onOpenChange:l}){let[u,f]=(0,V.useState)(null),g=(0,V.useRef)(null),_=(0,V.useRef)(null),y=(0,V.useRef)(!1),x=kt({defaultValues:{path:n},onSubmit:async({value:e})=>{if(_.current!==e.path&&s){let t=await s(e.path);if(t===`unchecked`)return;if(t===`exists`){f(e.path);return}}_.current=null,await c(e.path)&&l(!1)}}),S=Ot(x.store,e=>e.isSubmitting),w=o||S,E=(0,V.useRef)(n);return E.current=n,(0,V.useEffect)(()=>{a&&(_.current=null,f(null),x.setFieldValue(`path`,E.current))},[a]),(0,V.useEffect)(()=>{if(u!==null||!y.current)return;y.current=!1;let e=g.current;if(!e)return;e.focus();let[t,n]=Gc(e.value);e.setSelectionRange(t,n)},[u]),(0,B.jsx)(d,{open:a&&!(e&&o),onOpenChange:e=>{o||l(e)},children:(0,B.jsxs)(C,{children:[(0,B.jsxs)(T,{className:`mb-4`,children:[(0,B.jsx)(m,{children:i?`Download file`:`Save file`}),(0,B.jsx)(p,{children:i?`Choose a name for the file. It goes to your Downloads folder.`:e?`Choose a path in ${e}.`:`Choose where to save it on your Computer.`})]}),(0,B.jsxs)(`div`,{className:`space-y-4`,children:[(0,B.jsx)(x.Field,{name:`path`,validators:{onChange:({value:e})=>e.trim()?e.trim().endsWith(`/`)?`Save As needs a file path.`:void 0:`A file path is required.`},children:n=>(0,B.jsx)(Et,{label:i?`File name`:e?`Path`:`Location`,required:!0,error:n.state.meta.errors[0]??t,children:(0,B.jsx)(Dt,{value:n.state.value,onBlur:n.handleBlur,onChange:e=>{n.handleChange(e.target.value)},onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&(e.preventDefault(),w||x.handleSubmit())},ref:g,autoFocus:!0,onFocus:e=>{if(!r)return;let t=e.currentTarget,[n,i]=Gc(t.value);t.setSelectionRange(n,i)},disabled:w||u!==null,required:!0})})}),u===null?(0,B.jsxs)(v,{children:[(0,B.jsx)(b,{disabled:w,children:`Cancel`}),(0,B.jsx)(h,{type:`button`,disabled:w,onClick:()=>{x.handleSubmit()},children:i?w?`Downloading…`:`Download`:w?`Saving…`:`Save`})]}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(Te,{tone:`warning`,role:`alert`,title:`${Wc(u)} already exists. Replace it?`}),(0,B.jsxs)(v,{children:[(0,B.jsx)(h,{type:`button`,variant:`ghost`,onClick:()=>{_.current=null,y.current=!0,f(null)},children:`Cancel`}),(0,B.jsx)(h,{type:`button`,onClick:()=>{_.current=u,f(null),x.handleSubmit()},children:`Replace`})]})]})]})]})})}export{Bc as FileTab};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Bn as t,Ji as n,Qr as r,Xr as i,Yi as a,a as o,c as s,d as c,dr as l,s as u,u as d,ur as f}from"./tree-path-CkzAyob4.js";import{Mt as p,Pt as m,h,o as g}from"./changes-patch-D9K9yYqR.js";import{Wt as _}from"./dropdown-menu-B4O2bVad.js";import{n as v,r as y,t as b}from"./useFileTree-BoH_lGwC.js";import{a as x,c as S,d as C,f as w,h as T,i as E,l as D,m as O,n as k,o as A,p as j,r as M,s as N,t as P,u as F}from"./index-HgxZcM-A.js";var I=f(`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=f(`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(a(),1),z=256;async function B(e,t,n,r,a){r.throwIfAborted();let o=await n(e,t);if(!j.safeParse(o).success)return o;a(!0);try{let a=null,o=!1;for(let e=0;e<z&&!o;e++){r.throwIfAborted();let e=x.parse(await n(`rebuildCopies`,{cursor:a}));o=e.done,a=e.cursor}if(!o)throw new i(`Bonsai is still preparing this repository. Try again shortly.`,{code:`TIMEOUT`,retryable:!0});r.throwIfAborted();let s=await n(e,t);if(j.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:r,onSaveState:a}){let o=new Map;async function s(r,a){a.throwIfAborted();let o=A.parse(await n(`files.read`,{repo:e,ref:t,path:r}));if(a.throwIfAborted(),o.binary)throw Error(`This Bonsai file is not a text document.`);if(o.text===null&&o.blob!==null)throw new i(`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 i(`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 i(`Your saved file changed. Compare before syncing.`,{code:`CONFLICT`,retryable:!0});a(s,u.result)}r()}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 i(`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 i(`The file changed. Compare before saving.`,{code:`CONFLICT`,retryable:!0});e.pending===void 0&&(p.file=e)}let m=F.parse({repo:e,branch:t,path:l,baseCommit:p.file.commit,baseBlob:p.file.blob,text:u,revision:p.version}),h=C.parse(await n(`files.save`,m));if(h.kind===`refused`)throw new i(`Bonsai refused this save: ${h.reason}`,{code:`CAPABILITY_DENIED`,retryable:h.reason===`background-unavailable`});if(a(l,h),h.kind===`conflict`)throw new i(`Your saved file changed. Compare before saving.`,{code:`CONFLICT`,retryable:!0});o.set(l,{file:p.file,contents:u,version:h.revision}),r(),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),async exists(r,i){i.throwIfAborted();let a=D.parse(await n(`files.list`,{repo:e,ref:t}));if(i.throwIfAborted(),a.paths.includes(r))return!0;if(a.truncated)throw Error(`The repository file list is incomplete.`);return!1},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=N.parse({repo:e,branch:t,path:s,revision:l.version}),d=S.parse(await n(`files.discard`,u));if(c.throwIfAborted(),d.kind===`conflict`)throw new i(`Your saved file changed. Refresh before discarding.`,{code:`CONFLICT`,retryable:!0});o.delete(s),a(s,null),r()},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=O.parse(await e(`files.tree`,{...r,path:``})),a=D.parse(await e(`files.list`,r)),o=E.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=n();function W({files:e,rowHeight:n,dirtyPaths:r,activePath:i,busy:a,onRefresh:o,onOpenFile:s}){let c=(0,R.useRef)({files:e,onOpenFile:s});c.current={files:e,onOpenFile:s};let{model:l}=b({paths:[],initialExpansion:`open`,itemHeight:n,onSelectionChange(e){let t=e[0];t&&!t.endsWith(`/`)&&c.current.files.some(e=>e.path===t)&&c.current.onOpenFile(t)}}),u=(0,R.useMemo)(()=>{let t=new Set(r);return e.flatMap(e=>t.has(e.path)?[{path:e.path,status:`modified`}]:[])},[e,r]);(0,R.useEffect)(()=>{l.resetPaths(e.map(e=>e.path))},[l,e]),(0,R.useEffect)(()=>{l.setGitStatus(u)},[l,u]),(0,R.useEffect)(()=>{for(let e of l.getSelectedPaths())e!==i&&l.getItem(e)?.deselect();i&&l.getItem(i)?.select()},[l,i]);let d={flex:`1`,"--trees-item-height":`${String(n)}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)(g,{"aria-hidden":`true`}),` Explorer`]}),(0,U.jsx)(t,{icon:(0,U.jsx)(y,{}),"aria-label":`Refresh repository`,variant:`ghost`,size:`responsive`,disabled:a,onClick:o})]}),(0,U.jsx)(`p`,{className:`inkcap-repository-legend`,children:`Changes in latest commit · drafts marked modified`}),(0,U.jsx)(v,{model:l,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:n,initialPath:i,openRequestId:a,transport:f,onReady:g}){let v=m(),[y,b]=(0,R.useState)(!1),[x,S]=(0,R.useState)(0),[C,w]=(0,R.useState)(new Map),[E,D]=(0,R.useState)(``),O=(0,R.useRef)(new AbortController);(0,R.useEffect)(()=>{let e=new AbortController;return O.current=e,()=>{e.abort()}},[]);let A=(0,R.useCallback)((t,n)=>f?f(t,n):e.app.capabilities.require(T).call(`app_bonsai`,t,JSON.stringify(n)),[e.app,f]),j=(0,R.useCallback)((e,t)=>B(e,t,A,O.current.signal,e=>{S(t=>t+(e?1:-1))}),[A]),N=(0,R.useCallback)(()=>{v.invalidateQueries({queryKey:G.all(e.app.identity.surfaceId,t)})},[v,e.app,t]),F=(0,R.useRef)(new Map),z=(0,R.useMemo)(()=>{let r=`${e.app.identity.surfaceId}:${t}:${n}`,i=F.current.get(r);if(i?.app===e.app)return i;let a=V({repository:t,branch:n,request:j,onSaved:N,onSaveState:(e,r)=>{O.current.signal.aborted||w(i=>{let a=new Map(i),o=`${t}:${n}:${e}`;return r===null?a.delete(o):a.set(o,r),a})}}),o={app:e.app,source:a};return F.current.set(r,o),o},[t,n,j,N,e.app]),q=P({connection:z}),J=p({queryKey:G.branch(e.app.identity.surfaceId,t,n),queryFn:()=>H(j,t,n),refetchInterval:15e3});(0,R.useEffect)(()=>e.app.window.onBeforeClose(q.requestWindowClose),[e.app,q.requestWindowClose]),(0,R.useEffect)(()=>{g?.({requestWindowClose:q.requestWindowClose})},[g,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}:${a}`;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,a,q]);let Q=q.tabs.find(e=>e.tabKey===q.active),$=Q?.connection?.source?C.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,O.current.signal)}catch(e){console.error(`Bonsai sync retry failed`,e),D(`${r(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,O.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,O.current.signal)}catch(e){console.error(`Bonsai explicit re-save failed`,e),D(`${r(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,` · `,n]}),(0,U.jsxs)(l,{size:`sm`,variant:`outline`,onClick:()=>{b(!0)},children:[(0,U.jsx)(L,{"aria-hidden":`true`,className:`size-[var(--stipe-icon-size-sm)]`}),` `,`History`]})]}),x>0&&(0,U.jsx)(M,{message:`Loading this repository…`}),J.data?.truncated&&(0,U.jsx)(_,{tone:`info`,title:`Only the indexed files are shown`}),E&&(0,U.jsx)(h,{message:E,onDismiss:()=>{D(``)}}),$?.kind===`failed`&&!E&&(0,U.jsx)(_,{tone:`warning`,title:$.reason===`permanent_material`?`Sync needs a new save`:`Sync failed`,description:K[$.reason],action:(0,U.jsx)(l,{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)(k,{model:{...q,repositoryStatus:ee,repositoryStates:C,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,O.current.signal),n.source.readCommitted(e.path,O.current.signal)},error:J.error?`${r(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:N,onOpenFile:e},t?`phone`:`desktop`)}}),(0,U.jsx)(o,{open:y,onOpenChange:b,children:(0,U.jsxs)(u,{children:[(0,U.jsxs)(d,{children:[(0,U.jsx)(c,{children:`Commit history`}),(0,U.jsxs)(s,{children:[t,` · `,n]})]}),(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{Bn as t,Ji as n,Qr as r,Xr as i,Yi as a,a as o,c as s,d as c,dr as l,s as u,u as d,ur as f}from"./tree-path-CkzAyob4.js";import{Mt as p,Pt as m,h,o as g}from"./changes-patch-D9K9yYqR.js";import{Wt as _}from"./dropdown-menu-B4O2bVad.js";import{n as v,r as y,t as b}from"./useFileTree-BoH_lGwC.js";import{a as x,c as S,d as C,f as w,h as T,i as E,l as D,m as O,n as k,o as A,p as j,r as M,s as N,t as P,u as F}from"./index-1TT7jjTY.js";var I=f(`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=f(`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(a(),1),z=256;async function B(e,t,n,r,a){r.throwIfAborted();let o=await n(e,t);if(!j.safeParse(o).success)return o;a(!0);try{let a=null,o=!1;for(let e=0;e<z&&!o;e++){r.throwIfAborted();let e=x.parse(await n(`rebuildCopies`,{cursor:a}));o=e.done,a=e.cursor}if(!o)throw new i(`Bonsai is still preparing this repository. Try again shortly.`,{code:`TIMEOUT`,retryable:!0});r.throwIfAborted();let s=await n(e,t);if(j.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:r,onSaveState:a}){let o=new Map;async function s(r,a){a.throwIfAborted();let o=A.parse(await n(`files.read`,{repo:e,ref:t,path:r}));if(a.throwIfAborted(),o.binary)throw Error(`This Bonsai file is not a text document.`);if(o.text===null&&o.blob!==null)throw new i(`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 i(`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 i(`Your saved file changed. Compare before syncing.`,{code:`CONFLICT`,retryable:!0});a(s,u.result)}r()}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 i(`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 i(`The file changed. Compare before saving.`,{code:`CONFLICT`,retryable:!0});e.pending===void 0&&(p.file=e)}let m=F.parse({repo:e,branch:t,path:l,baseCommit:p.file.commit,baseBlob:p.file.blob,text:u,revision:p.version}),h=C.parse(await n(`files.save`,m));if(h.kind===`refused`)throw new i(`Bonsai refused this save: ${h.reason}`,{code:`CAPABILITY_DENIED`,retryable:h.reason===`background-unavailable`});if(a(l,h),h.kind===`conflict`)throw new i(`Your saved file changed. Compare before saving.`,{code:`CONFLICT`,retryable:!0});o.set(l,{file:p.file,contents:u,version:h.revision}),r(),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),async exists(r,i){i.throwIfAborted();let a=D.parse(await n(`files.list`,{repo:e,ref:t}));if(i.throwIfAborted(),a.paths.includes(r))return!0;if(a.truncated)throw Error(`The repository file list is incomplete.`);return!1},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=N.parse({repo:e,branch:t,path:s,revision:l.version}),d=S.parse(await n(`files.discard`,u));if(c.throwIfAborted(),d.kind===`conflict`)throw new i(`Your saved file changed. Refresh before discarding.`,{code:`CONFLICT`,retryable:!0});o.delete(s),a(s,null),r()},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=O.parse(await e(`files.tree`,{...r,path:``})),a=D.parse(await e(`files.list`,r)),o=E.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=n();function W({files:e,rowHeight:n,dirtyPaths:r,activePath:i,busy:a,onRefresh:o,onOpenFile:s}){let c=(0,R.useRef)({files:e,onOpenFile:s});c.current={files:e,onOpenFile:s};let{model:l}=b({paths:[],initialExpansion:`open`,itemHeight:n,onSelectionChange(e){let t=e[0];t&&!t.endsWith(`/`)&&c.current.files.some(e=>e.path===t)&&c.current.onOpenFile(t)}}),u=(0,R.useMemo)(()=>{let t=new Set(r);return e.flatMap(e=>t.has(e.path)?[{path:e.path,status:`modified`}]:[])},[e,r]);(0,R.useEffect)(()=>{l.resetPaths(e.map(e=>e.path))},[l,e]),(0,R.useEffect)(()=>{l.setGitStatus(u)},[l,u]),(0,R.useEffect)(()=>{for(let e of l.getSelectedPaths())e!==i&&l.getItem(e)?.deselect();i&&l.getItem(i)?.select()},[l,i]);let d={flex:`1`,"--trees-item-height":`${String(n)}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)(g,{"aria-hidden":`true`}),` Explorer`]}),(0,U.jsx)(t,{icon:(0,U.jsx)(y,{}),"aria-label":`Refresh repository`,variant:`ghost`,size:`responsive`,disabled:a,onClick:o})]}),(0,U.jsx)(`p`,{className:`inkcap-repository-legend`,children:`Changes in latest commit · drafts marked modified`}),(0,U.jsx)(v,{model:l,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:n,initialPath:i,openRequestId:a,transport:f,onReady:g}){let v=m(),[y,b]=(0,R.useState)(!1),[x,S]=(0,R.useState)(0),[C,w]=(0,R.useState)(new Map),[E,D]=(0,R.useState)(``),O=(0,R.useRef)(new AbortController);(0,R.useEffect)(()=>{let e=new AbortController;return O.current=e,()=>{e.abort()}},[]);let A=(0,R.useCallback)((t,n)=>f?f(t,n):e.app.capabilities.require(T).call(`app_bonsai`,t,JSON.stringify(n)),[e.app,f]),j=(0,R.useCallback)((e,t)=>B(e,t,A,O.current.signal,e=>{S(t=>t+(e?1:-1))}),[A]),N=(0,R.useCallback)(()=>{v.invalidateQueries({queryKey:G.all(e.app.identity.surfaceId,t)})},[v,e.app,t]),F=(0,R.useRef)(new Map),z=(0,R.useMemo)(()=>{let r=`${e.app.identity.surfaceId}:${t}:${n}`,i=F.current.get(r);if(i?.app===e.app)return i;let a=V({repository:t,branch:n,request:j,onSaved:N,onSaveState:(e,r)=>{O.current.signal.aborted||w(i=>{let a=new Map(i),o=`${t}:${n}:${e}`;return r===null?a.delete(o):a.set(o,r),a})}}),o={app:e.app,source:a};return F.current.set(r,o),o},[t,n,j,N,e.app]),q=P({connection:z}),J=p({queryKey:G.branch(e.app.identity.surfaceId,t,n),queryFn:()=>H(j,t,n),refetchInterval:15e3});(0,R.useEffect)(()=>e.app.window.onBeforeClose(q.requestWindowClose),[e.app,q.requestWindowClose]),(0,R.useEffect)(()=>{g?.({requestWindowClose:q.requestWindowClose})},[g,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}:${a}`;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,a,q]);let Q=q.tabs.find(e=>e.tabKey===q.active),$=Q?.connection?.source?C.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,O.current.signal)}catch(e){console.error(`Bonsai sync retry failed`,e),D(`${r(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,O.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,O.current.signal)}catch(e){console.error(`Bonsai explicit re-save failed`,e),D(`${r(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,` · `,n]}),(0,U.jsxs)(l,{size:`sm`,variant:`outline`,onClick:()=>{b(!0)},children:[(0,U.jsx)(L,{"aria-hidden":`true`,className:`size-[var(--stipe-icon-size-sm)]`}),` `,`History`]})]}),x>0&&(0,U.jsx)(M,{message:`Loading this repository…`}),J.data?.truncated&&(0,U.jsx)(_,{tone:`info`,title:`Only the indexed files are shown`}),E&&(0,U.jsx)(h,{message:E,onDismiss:()=>{D(``)}}),$?.kind===`failed`&&!E&&(0,U.jsx)(_,{tone:`warning`,title:$.reason===`permanent_material`?`Sync needs a new save`:`Sync failed`,description:K[$.reason],action:(0,U.jsx)(l,{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)(k,{model:{...q,repositoryStatus:ee,repositoryStates:C,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,O.current.signal),n.source.readCommitted(e.path,O.current.signal)},error:J.error?`${r(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:N,onOpenFile:e},t?`phone`:`desktop`)}}),(0,U.jsx)(o,{open:y,onOpenChange:b,children:(0,U.jsxs)(u,{children:[(0,U.jsxs)(d,{children:[(0,U.jsx)(c,{children:`Commit history`}),(0,U.jsxs)(s,{children:[t,` · `,n]})]}),(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};
|