@augmentd-labs/canvas-web 2.15.6 → 2.15.9

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.
@@ -0,0 +1 @@
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{wt as t,xt as n}from"./react-DQazvoR7.js";import{Ct as r}from"./ui-BX_B5WCf.js";import{x as i}from"./alert-dialog-CI8w9egc.js";import{o as a}from"./blobs-mOyU1Lbg.js";import{Mn as o,Tn as s,pn as c}from"./workspace-CCv1ZeWe.js";import{a as l,c as u,i as d,n as f,o as p,r as m,t as h}from"./text-documents-CizV3tXk.js";import{t as g}from"./EditorOverlay-Dqn7acGf.js";var _=e(t(),1),v=n();function y({doc:e,workspaceName:t,onSaved:n,onClose:y,onDetails:b}){let{showSuccessToast:x,showErrorToast:S}=a(),C=e.schema===o,w=d(e),T=w&&l(e),E=m(e)??`markdown`,D=u(t,e.id,{mode:`text`,enabled:w&&!T,maxTextLength:f,version:e.checksumArray?.[0]??null}),[O,k]=(0,_.useState)(C?String(e.data?.content??``):``),[A,j]=(0,_.useState)(null),M=`${e.id}:${e.checksumArray?.[0]??``}`;w&&D.text!=null&&A!==M&&(j(M),k(D.text));let[N,P]=(0,_.useState)(!1),F=C||D.text!=null&&!D.loading,I=async()=>{P(!0);try{C?await c(t,{id:e.id,schema:e.schema,schemaVersion:e.schemaVersion,data:{...e.data,content:O}}):await h(t,e,O),x(`Document saved`),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),n()}catch(e){S(e instanceof Error?e.message:`Failed to save document`)}finally{P(!1)}},L=C?String(e.data?.title??`Note`):s(e)||`document-${e.id}`;return(0,v.jsx)(g,{onClose:y,onDetails:b,title:(0,v.jsx)(`span`,{className:`truncate text-sm font-medium`,children:L}),actions:(0,v.jsxs)(i,{size:`sm`,onClick:I,disabled:N||!F||T,children:[(0,v.jsx)(r,{className:`mr-1.5 h-4 w-4`}),N?`Saving…`:`Save`]}),children:(0,v.jsx)(`div`,{className:`flex h-full min-h-0 flex-col px-4 py-4 md:px-8`,children:(0,v.jsx)(`div`,{className:`mx-auto flex min-h-0 w-full max-w-full flex-1 flex-col overflow-auto md:w-[700px] md:min-w-[320px] md:resize-x`,children:T?(0,v.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`This file is too large to edit here (`,`>`,Math.round(f/1e3),` kB) — download it instead.`]}):D.error?(0,v.jsx)(`p`,{className:`text-sm text-destructive`,children:D.error}):F?(0,v.jsx)(p,{kind:C?`markdown`:E,value:O,onChange:k,placeholder:C?`Write your note…`:void 0,fill:!0}):(0,v.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading content…`})})})})}export{y as default};
@@ -0,0 +1 @@
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{wt as t}from"./react-DQazvoR7.js";import{_ as n,u as r}from"./alert-dialog-CI8w9egc.js";var i=e(t(),1),a=(0,i.createContext)(void 0);function o(){let e=(0,i.useContext)(a);if(e===void 0)throw Error(`useToast must be used within a ToastContainer`);return e}function s(){let{showToast:e}=o();return{showErrorToast:(t,n=`Error`)=>e({title:n,description:t,variant:`destructive`}),showSuccessToast:(t,n=`Success`)=>e({title:n,description:t})}}async function c(e,t){return r.post(`${n.workspaces}/${e}/blobs`,t,{headers:{"Content-Type":`application/octet-stream`}})}async function l(e,t){return r.post(`${n.workspaces}/${e}/blobs/exists`,{checksums:t})}async function u(e,t,i,{ifMatch:a,contentType:o}={}){let s=t.key.split(`/`).map(encodeURIComponent).join(`/`),c=`${n.workspaces}/${encodeURIComponent(e)}/backends/${encodeURIComponent(t.driver)}/${encodeURIComponent(t.address)}/objects/${s}`;return r.put(c,i,{headers:{"Content-Type":o||`application/octet-stream`,"X-Canvas-Mtime":String(Date.now()),...a?{"If-Match":`"${a}"`}:{"If-None-Match":`*`}}})}function d(e,t,{onProgress:r,signal:i}={}){return p(`${n.workspaces}/${e}/blobs`,`POST`,t,{onProgress:r,signal:i})}function f(e,t,r,i={}){let a=t.key.split(`/`).map(encodeURIComponent).join(`/`);return p(`${n.workspaces}/${encodeURIComponent(e)}/backends/${encodeURIComponent(t.driver)}/${encodeURIComponent(t.address)}/objects/${a}`,`PUT`,r,i,{"If-None-Match":`*`,"X-Canvas-Mtime":String(r.lastModified)})}function p(e,t,n,{onProgress:r,signal:i},a={}){return new Promise((o,s)=>{if(i?.aborted){s(new DOMException(`Upload aborted`,`AbortError`));return}let c=new XMLHttpRequest;c.open(t,e),c.withCredentials=!0,c.responseType=`json`,c.setRequestHeader(`Content-Type`,`application/octet-stream`);for(let[e,t]of Object.entries(a))c.setRequestHeader(e,t);let l=localStorage.getItem(`authToken`);l&&c.setRequestHeader(`Authorization`,`Bearer ${l}`),r&&c.upload.addEventListener(`progress`,e=>{e.lengthComputable&&r(e.loaded,e.total)});let u=()=>c.abort();i?.addEventListener(`abort`,u,{once:!0}),c.addEventListener(`load`,()=>{i?.removeEventListener(`abort`,u);let e=c.response;c.status>=200&&c.status<300&&e?.payload?o(e.payload):s(Error(c.status===412?`A file with this name already exists. Rename the file before uploading; nothing was overwritten.`:e?.message||`Upload failed (HTTP ${c.status})`))}),c.addEventListener(`error`,()=>{i?.removeEventListener(`abort`,u),s(Error(`Network error during upload`))}),c.addEventListener(`abort`,()=>{i?.removeEventListener(`abort`,u),s(new DOMException(`Upload aborted`,`AbortError`))}),c.send(n)})}export{u as a,o as c,d as i,f as n,s as o,c as r,a as s,l as t};