@augmentd-labs/canvas-web 2.26.9 → 2.26.10

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,3 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/MarkdownEditor-By8nDUtG.js","assets/rolldown-runtime-C0FnF6B9.js","assets/code-editor-BQnKd3jw.js","assets/react-BzqgEMSQ.js","assets/ui-NWo4bzrd.js","assets/utils-2pl1SbIp.js","assets/utils-BxVxyehK.js","assets/punycode.es6-ZbLrB_Dn.js","assets/use-theme-Bd8sb5Ox.js","assets/MarkdownEditor-DWa37grk.css"])))=>i.map(i=>d[i]);
2
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BQnKd3jw.js";import{t as r}from"./preload-helper-Czpn1I53.js";import{t as i}from"./utils-2pl1SbIp.js";import{v as a}from"./alert-dialog-CDKOX-MP.js";import{i as o,o as s}from"./blobs-B3DY8Rsp.js";import{B as c,In as l,Kn as u,N as d,P as f,nt as p,rn as m,wn as h,z as g}from"./workspace-BYMC2sfI.js";var _=e(n(),1);function v(e){let t=new Set;for(let n of e){let e=n.trim();e&&t.add(`tag/${e}`)}return Array.from(t)}function y(e){return(e||[]).filter(e=>e.startsWith(`tag/`)).map(e=>e.slice(4))}var b=(0,_.createContext)(null);function x(){return(0,_.useContext)(b)}function S(e,t,n={}){let r=new URLSearchParams;n.download&&r.set(`download`,`1`),n.url&&r.set(`url`,n.url),n.format&&r.set(`format`,n.format),n.version&&r.set(`v`,n.version);let i=r.toString();return`${a}/pub/c/${encodeURIComponent(e)}/documents/${t}/content${i?`?${i}`:``}`}async function C(e,t,n=256){let r=await fetch(`${a}/pub/c/${encodeURIComponent(e)}/documents/${t}/thumbnail?size=${n}`);if(!r.ok)throw Error(`HTTP ${r.status}`);let i=r.headers.get(`content-type`)||`image/webp`;return{blob:await r.blob(),mime:i}}async function w(e,t,n={}){let r=await fetch(S(e,t,n),{signal:n.signal});if(!r.ok)throw Error(`HTTP ${r.status}`);let i=r.headers.get(`content-type`)||`application/octet-stream`;return{blob:await r.blob(),mime:i}}async function T(e,t,n,r={}){let{blob:i}=await w(e,t,{...r}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=n,document.body.appendChild(o),o.click(),o.remove(),setTimeout(()=>URL.revokeObjectURL(a),3e4)}function E(e){let t=x();return(0,_.useMemo)(()=>({isPublic:t!=null,fetchBlob:(n,r={})=>t?w(t,n,r):g(e,n,r),fetchThumbnail:(n,r=256,i)=>t?C(t,n,r):c(e,n,r,i),download:(n,r,i={})=>t?T(t,n,r,i):f(e,n,r,i),streamUrl:(n,r={})=>t?S(t,n,r):d(e,n,r),mintTicket:n=>t?Promise.resolve(!0):m(e,n)}),[e,t])}var D=e=>({blobUrl:null,blob:null,text:null,mime:null,error:null,loading:e});function O(e,t,{url:n,mode:r=`blob`,enabled:i=!0,maxTextLength:a=2e5,typeHint:o,version:s=null}={}){let{isPublic:c,fetchBlob:l}=E(e),u=`${c?`pub`:`ws`}:${e}:${t}:${n??``}:${r}:${i}:${o??``}:${s??``}`,[d,f]=(0,_.useState)(D(i)),[p,m]=(0,_.useState)(u);return u!==p&&(m(u),f(D(i))),(0,_.useEffect)(()=>{if(!i)return;let e=!1,c=null;return l(t,{...n?{url:n}:{},...s?{version:s}:{}}).then(async({blob:t,mime:n})=>{if(!e){if(r===`text`){let r=await t.text();e||f({blobUrl:null,blob:null,text:r.slice(0,a),mime:n,error:null,loading:!1})}else{let r=o&&(!t.type||t.type===`application/octet-stream`),i=r?t.slice(0,t.size,o):t;if(c=URL.createObjectURL(i),e){URL.revokeObjectURL(c),c=null;return}f({blobUrl:c,blob:i,text:null,mime:r?o:n,error:null,loading:!1})}}}).catch(t=>{e||f({blobUrl:null,blob:null,text:null,mime:null,error:String(t instanceof Error?t.message:t),loading:!1})}),()=>{e=!0,c&&URL.revokeObjectURL(c)}},[u]),d}function k(e,t,{url:n,enabled:r=!0}={}){let{isPublic:i,streamUrl:a,mintTicket:o}=E(e),s=`${i?`pub`:`ws`}:${e}:${t}:${n||``}:${r}`,[c,l]=(0,_.useState)({src:null,error:null,loading:!0}),[u,d]=(0,_.useState)(s);return s!==u&&(d(s),l({src:null,error:null,loading:!0})),(0,_.useEffect)(()=>{if(!r)return;let e=!1;return o(t).then(r=>{e||l(r?{src:a(t,{url:n}),error:null,loading:!1}:{src:null,error:`Could not authorize stream`,loading:!1})}).catch(t=>{e||l({src:null,error:t instanceof Error?t.message:String(t),loading:!1})}),()=>{e=!0}},[s]),c}var A=t(),j=(0,_.lazy)(()=>r(()=>import(`./MarkdownEditor-By8nDUtG.js`).then(e=>({default:e.MarkdownEditor})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]))),M=(0,A.jsx)(`div`,{className:`rounded-md border border-input p-3 text-sm text-muted-foreground`,children:`Loading editor…`});function N(e){return(0,A.jsx)(_.Suspense,{fallback:M,children:(0,A.jsx)(j,{...e})})}var P=class{snapshot;listeners=new Set;timer;running;forcedSave;options;key;constructor(e,t,n={}){this.key=e,this.options=n;let r={value:t,saved:JSON.stringify(t),meta:{}};try{let t=JSON.parse(n.storage?.getItem(e)||`null`);t?.version===1&&t.value&&typeof t.saved==`string`&&(r=t)}catch{}this.snapshot={...r,status:JSON.stringify(r.value)===r.saved?`idle`:`draft`,error:``,storageError:!1}}configure=e=>{this.options={...e,storage:this.options.storage}};getSnapshot=()=>this.snapshot;subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});emit(e){this.snapshot={...this.snapshot,...e},this.listeners.forEach(e=>e())}persist(){try{if(!this.options.storage)throw Error(`Storage unavailable`);this.options.storage.setItem(this.key,JSON.stringify({version:1,value:this.snapshot.value,saved:this.snapshot.saved,meta:this.snapshot.meta})),this.snapshot.storageError&&this.emit({storageError:!1})}catch{this.snapshot.storageError||this.emit({storageError:!0})}}update=e=>{let t={...this.snapshot.value,...e};JSON.stringify(t)!==JSON.stringify(this.snapshot.value)&&(this.emit({value:t,status:`draft`,error:``}),this.persist(),this.schedule())};schedule=()=>{this.cancelTimer(),this.options.save&&(this.timer=setTimeout(()=>{this.flush().catch(()=>{})},this.options.delay??650))};cancelTimer=()=>{clearTimeout(this.timer),this.timer=void 0};flush=()=>(this.cancelTimer(),this.running||=this.drain().finally(()=>{this.running=void 0,this.forcedSave=void 0}),this.running);async drain(){for(;JSON.stringify(this.snapshot.value)!==this.snapshot.saved;){let e=this.snapshot.value,t=this.forcedSave??this.options.save;if(!t||this.options.valid&&!this.options.valid(e))return;this.emit({status:`saving`,error:``});try{await t(e,this.snapshot.meta,e=>{this.emit({meta:e}),this.persist()}),this.emit({saved:JSON.stringify(e)}),this.persist()}catch(e){throw this.emit({status:`error`,error:e instanceof Error?e.message:`Save failed`}),this.persist(),e}}if(this.snapshot.status!==`idle`&&this.emit({status:`saved`}),!this.options.retainAfterSave)try{this.options.storage?.removeItem(this.key)}catch{}}saveWith=e=>(this.forcedSave=e,this.flush());clear=()=>{this.cancelTimer();try{this.options.storage?.removeItem(this.key)}catch{}}};function F(e){let t=`local`;try{let e=localStorage.getItem(`authToken`)||``,n=JSON.parse(atob(e.split(`.`)[1].replace(/-/g,`+`).replace(/_/g,`/`)));t=String(n.sub||n.userId||n.id||n.email||e)}catch{}let n=2166136261;for(let e of t)n=Math.imul(n^e.charCodeAt(0),16777619);return`canvas:note-draft:${n>>>0}:${e}`}var I=class{users=0;draft;constructor(e){this.draft=e}attach(){this.users++}release(){this.users--}},L=new Map;function R(e,t,n={}){let r=(0,_.useMemo)(()=>{let r=L.get(e);if(r)return r;let i;try{i=localStorage}catch{}let a=new I(new P(e,t,{...n,storage:i}));return L.set(e,a),a},[e]),{draft:i}=r;return(0,_.useEffect)(()=>{i.configure(n)}),(0,_.useEffect)(()=>{r.attach();let t=()=>{i.flush().catch(()=>{})},n=()=>{document.visibilityState===`hidden`&&t()};return i.schedule(),window.addEventListener(`online`,t),window.addEventListener(`pagehide`,t),document.addEventListener(`visibilitychange`,n),()=>{window.removeEventListener(`online`,t),window.removeEventListener(`pagehide`,t),document.removeEventListener(`visibilitychange`,n),r.release(),i.flush().catch(()=>{}).finally(()=>{r.users===0&&L.get(e)===r&&L.delete(e)})}},[i,r,e]),{...(0,_.useSyncExternalStore)(i.subscribe,i.getSnapshot),update:i.update,flush:i.flush,clear:i.clear,saveWith:i.saveWith,getSnapshot:i.getSnapshot}}function z(e,t,n=!0){let r=e.features??e.metadata?.features??[],i={title:String(e.data?.title??``),content:String(e.data?.content??``),comment:String(e.comment??``),tags:y(r),geo:e.metadata?.geo??null},a=R(F(`document:${t}:${e.id}`),i,{save:n?async n=>{await h(t,{id:e.id,schema:e.schema,schemaVersion:e.schemaVersion,data:{...e.data,title:n.title.trim(),content:n.content},comment:n.comment,metadata:{features:[...r.filter(e=>!e.startsWith(`tag/`)),...v(n.tags)],geo:n.geo}}),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`))}:void 0});return{...a.value,status:a.status,error:a.error,storageError:a.storageError,setTitle:e=>a.update({title:e}),setContent:e=>a.update({content:e}),setComment:e=>a.update({comment:e}),setTags:e=>a.update({tags:e}),setGeo:e=>a.update({geo:e}),saving:a.status===`saving`,canSave:a.status!==`saving`,save:a.flush}}function B({status:e,storageError:t,error:n,onRetry:r}){return(0,A.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground`,children:e===`error`?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(`span`,{title:n,children:[`Couldn’t sync. `,t?`Keep this editor open.`:`Draft saved on this device.`]}),` `,(0,A.jsx)(`button`,{type:`button`,className:`underline`,onClick:()=>void r().catch(()=>{}),children:`Retry`})]}):e===`saving`?`Saving…`:e===`saved`?`Saved`:e===`draft`?t?`Draft recovery unavailable. Keep this editor open until saved.`:`Draft saved on this device`:`Changes save automatically`})}function V({kind:e,value:t,onChange:n,placeholder:r,rows:a=16,fill:o=!1}){return e===`markdown`?(0,A.jsx)(N,{value:t,onChange:n,placeholder:r,fill:o}):(0,A.jsx)(`textarea`,{value:t,onChange:e=>n(e.target.value),rows:o?void 0:a,placeholder:r,spellCheck:!1,className:i(`flex w-full rounded-md border border-input bg-transparent px-3 py-2 font-mono text-xs leading-relaxed shadow-elevation-1 transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,o&&`h-full min-h-0 resize-none`)})}var H=1e6;function U(e){if(e.schema===`data/schema/note`)return`markdown`;if(e.schema!==`data/schema/file`)return null;let t=u(String(e.metadata?.contentType??``),l(e));return t===`markdown`?`markdown`:t===`text`?`text`:null}function W(e){return e.schema===`data/schema/file`&&U(e)!=null}function G(e){let t=Number(e.metadata?.size??0);return Number.isFinite(t)&&t>1e6}var K=`workspace:data`;function q(e){for(let t of e.locations||[]){let e=/^stored:\/\/([^/]+)\/(.+)$/.exec(String(t?.url||``));if(!(!e||e[1]===K))return{backend:e[1],key:e[2]}}return null}async function J(e,t,n,r={}){let i=l(t)||`document-${t.id}.txt`,a=String(t.metadata?.contentType??``)||(U(t)===`markdown`?`text/markdown`:`text/plain`),c=n.endsWith(`
3
- `)?n:`${n}\n`,u=new Blob([c],{type:a}),d=q(t);if(d){let n=String(t.checksumArray?.[0]??``).replace(/^sha256\//,``),i=await s(e,{driver:`file`,address:d.backend,key:d.key},u,{ifMatch:n||void 0,contentType:a});return(r.comment!==void 0&&r.comment!==(t.comment??``)||r.metadata!==void 0)&&await h(e,{id:i.docId??t.id,schema:t.schema,schemaVersion:t.schemaVersion,...r.comment===void 0?{}:{comment:r.comment},...r.metadata===void 0?{}:{metadata:r.metadata}}),p(e,i.docId??t.id)}let f=await o(e,u);return await h(e,{id:t.id,schema:t.schema,schemaVersion:t.schemaVersion,...r.comment===void 0?{}:{comment:r.comment},checksumArray:[`sha256/${f.checksum}`],locations:[{url:f.url,metadata:{filename:i}}],metadata:{contentType:a,size:f.size,...r.metadata??{}}}),p(e,t.id)}export{x as _,G as a,z as c,N as d,O as f,E as g,S as h,W as i,R as l,b as m,H as n,V as o,k as p,U as r,B as s,J as t,F as u,y as v,v as y};