notemend 0.1.17 → 0.1.20
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/.claude-plugin/plugin.json +1 -1
- package/README.md +9 -5
- package/bin/notemend.mjs +14 -14
- package/package.json +1 -1
- package/src/client/anchor.js +1 -1
- package/src/client/api.js +1 -1
- package/src/client/canvas.js +1 -1
- package/src/client/notemend.css +1 -1
- package/src/client/run.js +42 -43
- package/src/client/toplayer.js +1 -1
- package/src/hosted-app.js +1 -0
- package/src/next.mjs +1 -1
- package/src/server/middleware.mjs +1 -1
- package/src/store/comments.mjs +3 -3
- package/src/store/thread.mjs +1 -1
- package/store.d.ts +30 -5
- package/thread.d.ts +12 -3
package/src/client/run.js
CHANGED
|
@@ -1,74 +1,73 @@
|
|
|
1
|
-
import{categoryIcon as As,categoryOf as de}from"../store/categories.mjs";import{stateOf as P}from"../store/status.mjs";import{DOCS as Dt,agentHandles as Hs,agentMentioned as Ns,agentName as lo,agentOwner as co,agentStep as Z,docOf as Cs,docSlug as uo,handleOf as po,held as mo,stageOf as U,threadOf as It,toAgent as j,workingOn as Ge}from"../store/thread.mjs";import{api as L,canvasCopy as go,host as fo,imageUrl as ho}from"./api";import{recentLogs as bo}from"./logs";import{inspectors as yo}from"./inspect";import{anchors as vo,clean as wt}from"./anchor";import{bars as $o,fieldMenus as wo}from"./field-menu";import{AGENT_MARK as Rs,CLAUDE_MARK as Et,CROSS as Xe,PENCIL as Os,TICK as St,TRASH as Qe,UNDO as Ze,esc as p,stamp as qs}from"./markup";import{canvas as Eo}from"./canvas";import{historyHtml as So}from"./panel";import{review as To}from"./review";import{turbo as Mo}from"./turbo";function Ko(c){const pt=c.breakpoints,tn=c.categories,ce=(pt.find(t=>!Number.isFinite(t.max))??pt[0]).id,en=t=>pt.find(e=>t>=e.min&&t<=e.max)?.id??ce,tt=t=>t.breakpoint||ce,Bs=t=>c.devices.find(e=>e.id===t),E=go,O=(t,e)=>{E||localStorage.setItem(t,e)},ue=t=>t.replace(/\/+$/,"")||"/";let z=ue(location.pathname);for(const t of document.querySelectorAll(".devtools .dt-icon[title]"))t.dataset.tip=t.title,t.getAttribute("aria-label")||t.setAttribute("aria-label",t.title),t.removeAttribute("title");const nn=document.querySelector(".dt-grid-btn"),Pt=document.querySelector(".dt-grid-overlay"),sn="dt-grid",pe=t=>{Pt.hidden=!t,nn.setAttribute("aria-pressed",String(t)),O(sn,t?"1":"0"),D({grid:t})};nn.addEventListener("click",()=>pe(Pt.hidden===!0));const an=document.querySelector(".dt-pages-name"),on=()=>{let t=null;for(const s of document.querySelectorAll(".dt-pages a"))ue(new URL(s.href).pathname)===z?(s.setAttribute("aria-current","page"),t=s):s.removeAttribute("aria-current");const e=document.title.split("\u2014").pop()?.trim(),n=t?.querySelector(".dt-menu-label")?.textContent?.trim();an.textContent=n||e||an.textContent};on();const rn=[...document.querySelectorAll(".devtools details")];let me=!1;const Tt=()=>{const t=rn.filter(e=>e.open);for(const e of t)e.open=!1;return t};document.addEventListener("keydown",t=>{if(t.key!=="Escape")return;const[e]=Tt();e&&(e.querySelector("summary")?.focus(),t.preventDefault(),t.stopImmediatePropagation())},!0),document.addEventListener("pointerdown",t=>{me=rn.some(e=>e.open&&!e.contains(t.target))&&Tt().length>0},!0),addEventListener("blur",Tt);const mt=document.querySelector(".dt-pad-overlay"),ln="dt-inspect",Ds=[".devtools",".dt-pad-overlay",".dt-grid-overlay",".dt-frame",".dt-history",".dt-review",".dt-field-menu",...c.ignore].join(", "),ge=[".devtools",".dt-notes-overlay",".dt-history",".dt-frame",".dt-review",".dt-field-menu",'[aria-modal="true"]',...c.ignore].join(", "),fe={pads:document.querySelector(".dt-pad-btn"),sizes:document.querySelector(".dt-size-btn"),type:document.querySelector(".dt-type-btn"),color:document.querySelector(".dt-color-btn"),border:document.querySelector(".dt-border-btn")};let Y="",he=0;const{spacer:Is,drawPads:Ps,drawSize:js,drawType:Fs,drawColor:_s,drawBorder:Ks}=yo(mt),dn=t=>{he||(he=requestAnimationFrame(()=>{he=0,mt.hidden=!0;let e=document.elementFromPoint(t.clientX,t.clientY);if(mt.hidden=!1,!e||e.closest(Ds)){mt.innerHTML="";return}t.altKey&&e.parentElement&&e.parentElement!==document.body&&(e=e.parentElement),Y==="sizes"?js(e):Y==="type"?Fs(e):Y==="color"?_s(e):Y==="border"?Ks(e):Ps(t.altKey?e:Is(e))}))},jt=t=>{Y=t;for(const[e,n]of Object.entries(fe))n.setAttribute("aria-pressed",String(e===t));O(ln,t),D({inspect:t}),mt.hidden=!t,mt.innerHTML="",t?document.addEventListener("mousemove",dn):document.removeEventListener("mousemove",dn)};for(const[t,e]of Object.entries(fe))e.addEventListener("click",()=>{t!==Y&&nt(!1),jt(Y===t?"":t)});const cn=document.querySelector(".dt-notes-btn"),be=[...document.querySelectorAll(".dt-bp")],Ft=document.querySelector(".dt-history-btn"),x=document.querySelector(".dt-history"),ye=document.querySelector(".dt-studio-btn"),ve=document.querySelector(".dt-devices"),ot=document.querySelector(".dt-notes-hi"),Ws=ot.querySelector(".dt-hi-box"),un=ot.querySelector(".dt-hi-tag"),it=document.querySelector(".dt-frame"),_t=it.querySelector("iframe"),$e=document.querySelector(".dt-notes-count"),b=document.querySelector(".dt-notes-overlay"),pn=".devtools, .dt-tab, .dt-notes-overlay, .dt-history, .dt-frame",mn=t=>{for(const e of["pointerdown","mousedown","pointerup","mouseup","touchstart","touchend","click","focusin","focusout"])t.addEventListener(e,n=>n.stopPropagation())};document.querySelectorAll(pn).forEach(mn);const gn="dt-notes";let y=[],H=!1,$=null,d=null,we=0,q="",B=[],T=null,N=[];const Kt=(t=d)=>!!(t&&(t.text?.trim()||t.images?.length)),V=()=>{d&&Kt()&&N.push(d),d=null};let Mt=null,Ee=null;const fn=()=>`dt-draft:${z}${E?":canvas":""}`;let gt=fn(),Wt=0;const Se=()=>{if(!d&&!N.length&&!q){localStorage.removeItem(gt);return}const t={draft:d,parked:N,reply:q?{for:Mt,text:q}:null};try{localStorage.setItem(gt,JSON.stringify(t))}catch{const e=n=>({...n,images:void 0});try{localStorage.setItem(gt,JSON.stringify({...t,draft:d&&e(d),parked:N.map(e)}))}catch{}}},rt=()=>{clearTimeout(Wt),Wt=setTimeout(Se,200)};addEventListener("pagehide",()=>{clearTimeout(Wt),Se()});let J=localStorage.getItem("dt-resolved")!=="0";const C={q:"",menu:!1,view:["me","agent"].includes(localStorage.getItem("dt-view")??"")?localStorage.getItem("dt-view"):"all",sort:localStorage.getItem("dt-sort")==="unread"?"unread":"new"},Us=[[/Edg\/(\d+)/,"Edge"],[/OPR\/(\d+)/,"Opera"],[/Firefox\/(\d+)/,"Firefox"],[/Chrome\/(\d+)/,"Chrome"],[/Version\/(\d+).*Safari/,"Safari"]],zs=[[/iPhone|iPad/,"iOS"],[/Android/,"Android"],[/Mac OS X/,"macOS"],[/Windows/,"Windows"],[/Linux/,"Linux"]],Ys=()=>{const t=navigator.userAgent,e=o=>o.find(([i])=>i.test(t)),n=e(Us),s=e(zs),a=n?n[0].exec(t)?.[1]:null;return[n?`${n[1]}${a?" "+a:""}`:"unknown browser",s?.[1]].filter(Boolean).join(" \xB7 ")},Te=()=>en(innerWidth),lt=()=>Ee??Te(),hn=()=>{const t=lt();for(const e of be)e.setAttribute("aria-pressed",String(e.dataset.bp===t))},{cssPath:Vs,poolOf:Js,contextOf:Gs,resolveEl:F,anchorOf:Xs}=vo(),Ut=new Map,_=t=>{Ut.size||requestAnimationFrame(()=>Ut.clear());let e=Ut.get(t);return e===void 0&&(e=Xs(t),Ut.set(t,e)),e},bn=t=>{for(let e=t;e&&e!==document.body;e=e.parentElement)if(e.getAnimations().some(n=>n.playState==="running"))return!0;return!1};let zt=[];const Me=t=>{for(const e of zt)e.play();zt=[];for(let e=t;e&&e!==document.body;e=e.parentElement)for(const n of e.getAnimations())n.playState==="running"&&(n.pause(),zt.push(n))},yn=()=>{if(d)return F(d);const t=$!=null?y.find(n=>n.id===$):null;if(!t)return null;const e=_(t);return e&&!e.off?F(t):null},Qs="claude",Zs=()=>(c.team??[]).filter(t=>t.email!==c.me?.email),Lt=()=>[...c.me?(c.team??[]).filter(t=>t.email===c.me.email):[],...Zs()],vn='<svg viewBox="0 0 20 20" width="14" height="14" aria-hidden="true"><circle cx="10" cy="10" r="6.5" stroke-dasharray="2.4 2.4"/></svg>',ta=(t,e,n=!1)=>{const s=j(t)?"agent":t?"person":"nobody",a=xt(s==="person"?t:$n());return`<span class="dt-hand" role="radiogroup" aria-label="Who takes it">${[["person",a?Vt(a.avatar_url,a.name||a.email):At,s==="person"?`${Yt(t)==="you"?"You":Yt(t)} \u2014 pick someone else`:a?`Give it to ${a.email===c.me?.email?"me":a.name||a.email}`:"A person"],["nobody",vn,"Anyone \u2014 nobody has taken it yet"],["agent",Et(12),n?"Waits for the studio to approve it":s==="agent"?"Claude does it":"Give it to Claude"]].map(([i,l,u])=>i===s?`<span class="dt-hand-stop dt-hand-stop--${i} is-on" role="radio" aria-checked="true" data-tip="${p(u)}" aria-label="${p(u)}">${i==="person"?ia(t,e):l}</span>`:`<button type="button" class="dt-hand-stop dt-hand-stop--${i}" role="radio" aria-checked="false" data-act="hand" data-v="${i}"${e?` data-id="${e}"`:""} data-tip="${p(u)}" aria-label="${p(u)}"${i==="agent"&&n?" disabled":""}>${l}</button>`).join("")}</span>`},$n=()=>{const t=sa();return t&&!j(t)&&Lt().some(e=>e.email===t)?t:Lt()[0]?.email??""},ea=()=>{const t=b.querySelector(".dt-hand .dt-hand-stop.is-on");return t?{rect:t.getBoundingClientRect(),ghost:t.cloneNode(!0)}:void 0},wn="cubic-bezier(0.32, 0.72, 0, 1)",En=t=>{const e=b.querySelector(".dt-hand .dt-hand-stop.is-on");if(!t||!e||matchMedia("(prefers-reduced-motion: reduce)").matches)return;const n=e.getBoundingClientRect(),s=document.createElement("span");s.className="dt-hand dt-hand-ghost",s.style.cssText=`left:${t.rect.left}px;top:${t.rect.top}px;width:${t.rect.width}px;height:${t.rect.height}px`,t.ghost.querySelectorAll("select").forEach(a=>a.tabIndex=-1),s.append(t.ghost),b.append(s),s.animate([{opacity:1,filter:"blur(0)"},{opacity:0,filter:"blur(2px)"}],{duration:120,easing:"ease-out",fill:"forwards"}).finished.then(()=>s.remove(),()=>s.remove()),qe=performance.now()+480,e.animate([{transform:`translateX(${t.rect.left-n.left}px)`,width:`${t.rect.width}px`},{transform:"none",width:`${n.width}px`}],{duration:460,easing:wn});for(const a of e.children)a.animate([{opacity:0,transform:"scale(0.92)",filter:"blur(3px)"},{opacity:0,transform:"scale(0.92)",filter:"blur(3px)",offset:.4},{opacity:1,transform:"none",filter:"blur(0)"}],{duration:460,easing:wn});for(const a of e.parentElement?.querySelectorAll("button.dt-hand-stop")??[])a.animate([{opacity:0},{opacity:1}],{duration:300,delay:140,easing:"ease-out",fill:"backwards"})},na=(t,e)=>{const n=qe>performance.now()?void 0:ea(),s=e==="agent"?Qs:e==="person"?$n():e==="me"?c.me?.email??"":"";if(!t){if(!d)return;if(d.assignee=s,d.stage=j(s)?"approved":!d.stage||d.stage==="approved"?"new":d.stage,e==="person")try{localStorage.setItem("nm-for",s)}catch{}rt(),f(),En(n);return}const a=y.find(l=>l.id===t);if(a&&Ge(a)&&!j(s)&&!confirm("Claude is still working on this \u2014 it may finish its changes after you take it. Take it anyway?"))return;const o=a?U(a):"new",i=j(s)?"approved":o==="approved"?"new":o;K(l=>l.map(u=>u.id===t?{...u,assignee:s||void 0,stage:i}:u),()=>L("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:t,assignee:s||null,stage:i})}),j(s)?"Approving it for the agent":"Reassigning"),En(n)},sa=()=>{try{return localStorage.getItem("nm-for")??""}catch{return""}},kt=t=>j(t)?"#d97757":t?"#0d99ff":"#717171",Yt=t=>t===c.me?.email?"you":c.team?.find(e=>e.email===t)?.name||t.split("@")[0],xt=t=>t?c.team?.find(e=>e.email===t):void 0,Sn=t=>{const e=wt(t??"").split(/\s+/).filter(Boolean);return p(((e[0]?.[0]??"?")+(e.length>1?e[e.length-1][0]:"")).toUpperCase())},Vt=(t,e,n="dt-face")=>t?`<img class="${n}" src="${p(t)}" alt="">`:`<b class="${n}" aria-hidden="true">${Sn(e)}</b>`,Tn=t=>{const e=xt(t.by);return e||t.byName?Vt(e?.avatar_url,e?.name||t.byName||t.by):""},Mn=t=>`var(--dt-avatar-${[...t].reduce((e,n)=>e*31+n.charCodeAt(0)>>>0,7)%8+1})`,Ln={queued:"var(--dt-new)",working:"var(--dt-progress)",asks:"var(--dt-waiting)",stuck:"var(--dt-stuck)",review:"var(--dt-review)",done:"var(--dt-accepted)"},ft=(()=>{try{return JSON.parse(localStorage.getItem("dt-seen")||"{}")}catch{return{}}})(),kn=()=>{try{O("dt-seen",JSON.stringify(ft))}catch{}},xn=t=>{const e=It(t);if(!(t.id in ft))return ft[t.id]=e.length,kn(),!1;const n=e[e.length-1];return e.length>ft[t.id]&&!(n?.author==="you"&&(!n.by||n.by===c.me?.email))},aa=t=>{const e=It(t).length;ft[t.id]!==e&&(ft[t.id]=e,kn())},Le=t=>{const e=xt(t);return e?` data-face="${p(e.avatar_url??"")}" data-initial="${Sn(e.name||e.email)}"`:""},dt=(t,e)=>lo(t),An=t=>{const e=xt(t);return e?Vt(e.avatar_url,e.name||e.email):""},oa=t=>{const e=xt(t)?.agent_avatar_url;return e?`<img class="dt-face" src="${p(e)}" alt="">`:`<b class="dt-face dt-face--ai" aria-hidden="true">${Et(12)}</b>`},ia=(t,e)=>{const n=(a,o)=>`<option value="${p(a)}" data-c="${kt(a)}"${Le(a||null)}${t===a?" selected":""}>${p(o)}</option>`,s=(c.team??[]).filter(a=>a.email!==c.me?.email);return`<label class="dt-field dt-field--knob"><span class="dt-field-box dt-field-box--face" style="--cat:${kt(t)}">${An(t||null)||At}<select class="dt-for-select"${e?` data-id="${e}"`:""} aria-label="Who does it">
|
|
1
|
+
import{categoryIcon as As,categoryOf as le}from"../store/categories.mjs";import{stateOf as B}from"../store/status.mjs";import{DOCS as Rt,agentHandles as Hs,agentMentioned as Ns,agentName as ro,agentOwner as lo,agentStep as V,docOf as Cs,docSlug as co,handleOf as uo,held as po,stageOf as G,threadOf as Bt,toAgent as I,workingOn as Qe}from"../store/thread.mjs";import{api as ot,canvasCopy as mo,host as go,imageUrl as fo,local as M}from"./api";import{recentLogs as ho}from"./logs";import{inspectors as bo}from"./inspect";import{anchors as yo,clean as It}from"./anchor";import{bars as vo,fieldMenus as $o}from"./field-menu";import{AGENT_MARK as qs,CLAUDE_MARK as ut,CROSS as Ze,PENCIL as Os,TICK as Tt,TRASH as tn,UNDO as en,esc as p,stamp as Rs}from"./markup";import{canvas as wo}from"./canvas";import{historyHtml as Eo}from"./panel";import{review as So}from"./review";import{turbo as To}from"./turbo";function Do(c){const pt=c.breakpoints,nn=c.categories,de=(pt.find(t=>!Number.isFinite(t.max))??pt[0]).id,sn=t=>pt.find(e=>t>=e.min&&t<=e.max)?.id??de,tt=t=>t.breakpoint||de,Bs=t=>c.devices.find(e=>e.id===t),S=mo,q=(t,e)=>{S||M.setItem(t,e)},D=t=>ot("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify(t)}),ce=t=>t.replace(/\/+$/,"")||"/";let P=ce(location.pathname);for(const t of document.querySelectorAll(".devtools .dt-icon[title]"))t.dataset.tip=t.title,t.getAttribute("aria-label")||t.setAttribute("aria-label",t.title),t.removeAttribute("title");const an=document.querySelector(".dt-grid-btn"),Dt=document.querySelector(".dt-grid-overlay"),on="dt-grid",ue=t=>{Dt.hidden=!t,an.setAttribute("aria-pressed",String(t)),q(on,t?"1":"0"),R({grid:t})};an.addEventListener("click",()=>ue(Dt.hidden===!0));const rn=document.querySelector(".dt-pages-name"),ln=()=>{let t=null;for(const s of document.querySelectorAll(".dt-pages a"))ce(new URL(s.href).pathname)===P?(s.setAttribute("aria-current","page"),t=s):s.removeAttribute("aria-current");const e=document.title.split("\u2014").pop()?.trim(),n=t?.querySelector(".dt-menu-label")?.textContent?.trim();rn.textContent=n||e||rn.textContent};ln();const dn=[...document.querySelectorAll(".devtools details")];let pe=!1;const Lt=()=>{const t=dn.filter(e=>e.open);for(const e of t)e.open=!1;return t};document.addEventListener("keydown",t=>{if(t.key!=="Escape")return;const[e]=Lt();e&&(e.querySelector("summary")?.focus(),t.preventDefault(),t.stopImmediatePropagation())},!0),document.addEventListener("pointerdown",t=>{pe=dn.some(e=>e.open&&!e.contains(t.target))&&Lt().length>0},!0),addEventListener("blur",Lt);const Pt=document.querySelector(".dt-pad-overlay"),cn="dt-inspect",Is=[".devtools",".dt-pad-overlay",".dt-grid-overlay",".dt-frame",".dt-history",".dt-review",".dt-field-menu",...c.ignore].join(", "),me=[".devtools",".dt-notes-overlay",".dt-history",".dt-frame",".dt-review",".dt-field-menu",'[aria-modal="true"]',...c.ignore].join(", "),ge={pads:document.querySelector(".dt-pad-btn"),sizes:document.querySelector(".dt-size-btn"),type:document.querySelector(".dt-type-btn"),color:document.querySelector(".dt-color-btn"),border:document.querySelector(".dt-border-btn")};let X="",fe=0;const{spacer:Ds,drawPads:Ps,drawSize:Fs,drawType:js,drawColor:_s,drawBorder:Ks}=bo(Pt),un=t=>{fe||(fe=requestAnimationFrame(()=>{fe=0;let e=document.elementFromPoint(t.clientX,t.clientY);if(!e||e.closest(Is)){Pt.innerHTML="";return}t.altKey&&e.parentElement&&e.parentElement!==document.body&&(e=e.parentElement),X==="sizes"?Fs(e):X==="type"?js(e):X==="color"?_s(e):X==="border"?Ks(e):Ps(t.altKey?e:Ds(e))}))},Ft=t=>{X=t;for(const[e,n]of Object.entries(ge))n.setAttribute("aria-pressed",String(e===t));q(cn,t),R({inspect:t}),Pt.hidden=!t,Pt.innerHTML="",t?document.addEventListener("mousemove",un):document.removeEventListener("mousemove",un)};for(const[t,e]of Object.entries(ge))e.addEventListener("click",()=>{t!==X&&nt(!1),Ft(X===t?"":t)});const pn=document.querySelector(".dt-notes-btn"),he=[...document.querySelectorAll(".dt-bp")],jt=document.querySelector(".dt-history-btn"),x=document.querySelector(".dt-history"),be=document.querySelector(".dt-studio-btn"),ye=document.querySelector(".dt-devices"),mt=document.querySelector(".dt-notes-hi"),Ws=mt.querySelector(".dt-hi-box"),mn=mt.querySelector(".dt-hi-tag"),it=document.querySelector(".dt-frame"),_t=it.querySelector("iframe"),ve=document.querySelector(".dt-notes-count"),b=document.querySelector(".dt-notes-overlay"),$e=".devtools, .dt-tab, .dt-notes-overlay, .dt-history, .dt-frame",gn=t=>{for(const e of["pointerdown","mousedown","pointerup","mouseup","touchstart","touchend","click","focusin","focusout"])t.addEventListener(e,n=>n.stopPropagation())};document.querySelectorAll($e).forEach(gn);const fn="dt-notes";let y=[],A=!1,$=null,d=null,we=0,O="",F=[],T=null,H=[];const Kt=(t=d)=>!!(t&&(t.text?.trim()||t.images?.length)),j=()=>{d&&Kt()&&H.push(d),d=null};let Mt=null,Ee=null;const hn=()=>`dt-draft:${P}${S?":canvas":""}`;let gt=hn(),Wt=0;const Se=()=>{if(!d&&!H.length&&!O){M.removeItem(gt);return}const t={draft:d,parked:H,reply:O?{for:Mt,text:O}:null};try{localStorage.setItem(gt,JSON.stringify(t))}catch{const e=n=>({...n,images:void 0});try{localStorage.setItem(gt,JSON.stringify({...t,draft:d&&e(d),parked:H.map(e)}))}catch{}}},rt=()=>{clearTimeout(Wt),Wt=setTimeout(Se,200)};addEventListener("pagehide",()=>{clearTimeout(Wt),Se()});let J=M.getItem("dt-resolved")!=="0";const N={q:"",menu:!1,view:["me","agent"].includes(M.getItem("dt-view")??"")?M.getItem("dt-view"):"all",sort:M.getItem("dt-sort")==="unread"?"unread":"new"},Us=[[/Edg\/(\d+)/,"Edge"],[/OPR\/(\d+)/,"Opera"],[/Firefox\/(\d+)/,"Firefox"],[/Chrome\/(\d+)/,"Chrome"],[/Version\/(\d+).*Safari/,"Safari"]],zs=[[/iPhone|iPad/,"iOS"],[/Android/,"Android"],[/Mac OS X/,"macOS"],[/Windows/,"Windows"],[/Linux/,"Linux"]],Ys=()=>{const t=navigator.userAgent,e=i=>i.find(([o])=>o.test(t)),n=e(Us),s=e(zs),a=n?n[0].exec(t)?.[1]:null;return[n?`${n[1]}${a?" "+a:""}`:"unknown browser",s?.[1]].filter(Boolean).join(" \xB7 ")},Te=()=>sn(innerWidth),lt=()=>Ee??Te(),bn=()=>{const t=lt();for(const e of he)e.setAttribute("aria-pressed",String(e.dataset.bp===t))},{cssPath:Vs,poolOf:Gs,contextOf:Xs,resolveEl:Js,anchorOf:Qs}=yo();let Le=new WeakMap;const yn=()=>{Le=new WeakMap},Q=t=>{let e=Le.get(t);return(e===void 0||e&&!e.isConnected)&&(e=Js(t),Le.set(t,e)),e},Ut=new Map,_=t=>{Ut.size||requestAnimationFrame(()=>Ut.clear());let e=Ut.get(t);return e===void 0&&(e=Qs(t,Q(t)),Ut.set(t,e)),e},vn=t=>{for(let e=t;e&&e!==document.body;e=e.parentElement)if(e.getAnimations().some(n=>n.playState==="running"))return!0;return!1};let zt=[];const Me=t=>{for(const e of zt)e.play();zt=[];for(let e=t;e&&e!==document.body;e=e.parentElement)for(const n of e.getAnimations())n.playState==="running"&&(n.pause(),zt.push(n))},$n=()=>{if(d)return Q(d);const t=$!=null?y.find(n=>n.id===$):null;if(!t)return null;const e=_(t);return e&&!e.off?Q(t):null},Zs="claude",ta=()=>(c.team??[]).filter(t=>t.email!==c.me?.email),ft=()=>[...c.me?(c.team??[]).filter(t=>t.email===c.me.email):[],...ta()],wn='<svg viewBox="0 0 20 20" width="14" height="14" aria-hidden="true"><circle cx="10" cy="10" r="6.5" stroke-dasharray="2.4 2.4"/></svg>',ea=(t,e,n=!1)=>{const s=I(t)?"agent":t?"person":"nobody",a=xt(s==="person"?t:En()),i=[["person",a?Vt(a.avatar_url,a.name||a.email):Zt,s==="person"?`${Yt(t)==="you"?"You":Yt(t)} \u2014 pick someone else`:a?`Give it to ${a.email===c.me?.email?"me":a.name||a.email}`:"A person"],["nobody",wn,"Anyone \u2014 nobody has taken it yet"],["agent",ut(12),n?"Waits for the studio to approve it":s==="agent"?"Claude does it":"Give it to Claude"]],o=e!=null?y.find(u=>u.id===e):void 0,l=s==="agent"&&o?ke[V(o)??""]:"";return`<span class="dt-hand" role="radiogroup" aria-label="Who takes it"${l?` style="--step-c:${l}"`:""}>${i.filter(([u])=>u!=="person"||s==="person"||ft().length).map(([u,m,r])=>u===s?`<span class="dt-hand-stop dt-hand-stop--${u} is-on" role="radio" aria-checked="true" data-tip="${p(r)}" aria-label="${p(r)}">${u==="person"?ra(t,e):m}</span>`:`<button type="button" class="dt-hand-stop dt-hand-stop--${u}" role="radio" aria-checked="false" data-act="hand" data-v="${u}"${e?` data-id="${e}"`:""} data-tip="${p(r)}" aria-label="${p(r)}"${u==="agent"&&n?" disabled":""}>${m}</button>`).join("")}</span>`},En=()=>{const t=aa();return t&&!I(t)&&ft().some(e=>e.email===t)?t:ft()[0]?.email??""},na=()=>{const t=b.querySelector(".dt-hand .dt-hand-stop.is-on");return t?{rect:t.getBoundingClientRect(),ghost:t.cloneNode(!0)}:void 0},Sn="cubic-bezier(0.32, 0.72, 0, 1)",Tn=t=>{const e=b.querySelector(".dt-hand .dt-hand-stop.is-on");if(!t||!e||matchMedia("(prefers-reduced-motion: reduce)").matches)return;const n=e.getBoundingClientRect(),s=document.createElement("span");s.className="dt-hand dt-hand-ghost",s.style.cssText=`left:${t.rect.left}px;top:${t.rect.top}px;width:${t.rect.width}px;height:${t.rect.height}px`,t.ghost.querySelectorAll("select").forEach(a=>a.tabIndex=-1),s.append(t.ghost),b.append(s),s.animate([{opacity:1,filter:"blur(0)"},{opacity:0,filter:"blur(2px)"}],{duration:120,easing:"ease-out",fill:"forwards"}).finished.then(()=>s.remove(),()=>s.remove()),Ie=performance.now()+480,e.animate([{transform:`translateX(${t.rect.left-n.left}px)`,width:`${t.rect.width}px`},{transform:"none",width:`${n.width}px`}],{duration:460,easing:Sn});for(const a of e.children)a.animate([{opacity:0,transform:"scale(0.92)",filter:"blur(3px)"},{opacity:0,transform:"scale(0.92)",filter:"blur(3px)",offset:.4},{opacity:1,transform:"none",filter:"blur(0)"}],{duration:460,easing:Sn});for(const a of e.parentElement?.querySelectorAll("button.dt-hand-stop")??[])a.animate([{opacity:0},{opacity:1}],{duration:300,delay:140,easing:"ease-out",fill:"backwards"})},sa=(t,e)=>{const n=Ie>performance.now()?void 0:na(),s=e==="agent"?Zs:e==="person"?En():e==="me"?c.me?.email??"":"";if(!t){if(!d)return;d.assignee=s,d.stage=I(s)?"approved":!d.stage||d.stage==="approved"?"new":d.stage,e==="person"&&M.setItem("nm-for",s),rt(),f(),Tn(n);return}const a=y.find(l=>l.id===t);if(a&&Qe(a)&&!I(s)&&!confirm("Claude is still working on this \u2014 it may finish its changes after you take it. Take it anyway?"))return;const i=a?G(a):"new",o=I(s)?"approved":i==="approved"?"new":i;W(l=>l.map(u=>u.id===t?{...u,assignee:s||void 0,stage:o}:u),()=>D({id:t,assignee:s||null,stage:o}),I(s)?"Approving it for the agent":"Reassigning"),Tn(n)},aa=()=>M.getItem("nm-for")??"",kt=t=>I(t)?"#d97757":t?"#0d99ff":"#717171",Yt=t=>t===c.me?.email?"you":c.team?.find(e=>e.email===t)?.name||t.split("@")[0],xt=t=>t?c.team?.find(e=>e.email===t):void 0,Ln=t=>{const e=It(t??"").split(/\s+/).filter(Boolean);return p(((e[0]?.[0]??"?")+(e.length>1?e[e.length-1][0]:"")).toUpperCase())},Vt=(t,e,n="dt-face")=>t?`<img class="${n}" src="${p(t)}" alt="">`:`<b class="${n}" aria-hidden="true">${Ln(e)}</b>`,Mn=t=>{const e=xt(t.by);return e||t.byName?Vt(e?.avatar_url,e?.name||t.byName||t.by):""},kn=t=>`var(--dt-avatar-${[...t].reduce((e,n)=>e*31+n.charCodeAt(0)>>>0,7)%8+1})`,ke={queued:"var(--dt-new)",working:"var(--dt-progress)",asks:"var(--dt-waiting)",stuck:"var(--dt-stuck)",review:"var(--dt-review)",done:"var(--dt-accepted)"},ht=(()=>{try{return JSON.parse(M.getItem("dt-seen")||"{}")}catch{return{}}})(),xn=()=>q("dt-seen",JSON.stringify(ht)),An=t=>{const e=Bt(t);if(!(t.id in ht))return ht[t.id]=e.length,xn(),!1;const n=e[e.length-1];return e.length>ht[t.id]&&!(n?.author==="you"&&(!n.by||n.by===c.me?.email))},oa=t=>{const e=Bt(t).length;ht[t.id]!==e&&(ht[t.id]=e,xn())},xe=t=>{const e=xt(t);return e?` data-face="${p(e.avatar_url??"")}" data-initial="${Ln(e.name||e.email)}"`:""},dt=(t,e)=>ro(t),Hn=t=>{const e=xt(t);return e?Vt(e.avatar_url,e.name||e.email):""},ia=t=>{const e=xt(t)?.agent_avatar_url;return e?`<img class="dt-face" src="${p(e)}" alt="">`:`<b class="dt-face dt-face--ai" aria-hidden="true">${ut(12)}</b>`},ra=(t,e)=>{const n=(a,i)=>`<option value="${p(a)}" data-c="${kt(a)}"${xe(a||null)}${t===a?" selected":""}>${p(i)}</option>`,s=(c.team??[]).filter(a=>a.email!==c.me?.email);return`<label class="dt-field dt-field--knob"><span class="dt-field-box dt-field-box--face" style="--cat:${kt(t)}">${Hn(t||null)||Zt}<select class="dt-for-select"${e?` data-id="${e}"`:""} aria-label="Who does it">
|
|
2
2
|
${c.me?n(c.me.email,`Me \xB7 ${c.me.name||c.me.email}`):""}
|
|
3
3
|
${s.map(a=>n(a.email,a.name||a.email)).join("")}${t&&t!==c.me?.email&&!s.some(a=>a.email===t)?n(t,Yt(t)):""}
|
|
4
|
-
</select></span></label>`},
|
|
4
|
+
</select></span></label>`},la=t=>`<div class="dt-suggest dt-suggest--read"><del>${p(t.from)}</del><ins>${p(t.to)}</ins></div>`,Nn=(t,e)=>{const n=String(t??"").replace(/\s*>\s*/g," \u203A ").slice(-160);return p([n,It(e??"")&&`\u201C${It(e).slice(0,80)}\u201D`].filter(Boolean).join(" \xB7 "))},da='<svg class="dt-chev" viewBox="0 0 12 12" width="9" height="9" aria-hidden="true"><path d="M3 4.5 6 7.5 9 4.5"/></svg>',ca=(t,e)=>{const n=le(t);return`<label class="dt-field dt-field--bare" data-tip="Type: ${p(n.label)}"><span class="dt-field-box">${As(n)}<span class="dt-field-label">${p(n.label)}</span>${da}<select class="dt-cat-select"${e?` data-id="${e}"`:""} aria-label="Type">${nn.map(s=>`<option value="${s.id}" data-c="${s.color}" data-icon="${p(As(s))}"${s.id===t?" selected":""}>${s.label}</option>`).join("")}</select></span></label>`},Ae=[["new","New","#0d99ff",.25],["progress","In progress","#f5a623",.5],["review","Needs review","#8e4ec6",.75],["waiting","Waiting","#e93d82",.875],["accepted","Accepted","#30a46c",.95]],Cn=(t,e)=>{const s=2*Math.PI*e,a=8+3.3*Math.sin(s),i=8-3.3*Math.cos(s),o=`<path d="M8 8V${8-3.3}A${3.3} ${3.3} 0 ${e>.5?1:0} 1 ${a.toFixed(2)} ${i.toFixed(2)}Z" fill="${t}"/>`;return`<svg class="dt-stage-icon" viewBox="0 0 16 16" width="14" height="14" aria-hidden="true"><rect x="3.2" y="3.2" width="9.6" height="9.6" rx="2.4" transform="rotate(45 8 8)" fill="none" stroke="${t}" stroke-width="1.5"/>${o}</svg>`},Gt=t=>G(t)==="accepted"?"accepted":Qe(t)||G(t)==="progress"?"progress":G(t)==="review"?"review":G(t)==="waiting"?"waiting":"new",Xt={queued:"new",working:"progress",stuck:"progress",asks:"waiting",review:"review",held:"new",done:"accepted"},qn=[...Ae,["done","Resolved","#30a46c",1]],ua=t=>{const e=V(t),n=t.status==="done"&&e!=="review"?"done":e&&Xt[e]?Xt[e]:Gt(t),[,,s,a]=qn.find(i=>i[0]===n);return`<label class="dt-field" data-tip="${e&&Xt[e]?"Follows Claude \u2014 or pick one":"Status"}"><span class="dt-field-box dt-field-box--icon" style="--cat:${s}">${Cn(s,a)}<select class="dt-status-select" data-id="${t.id}" aria-label="Status">${qn.map(([i,o,l,u])=>`<option value="${i}" data-c="${l}" data-icon="${p(Cn(l,u))}"${i===n?" selected":""}>${o}</option>`).join("")}</select></span></label>`},On=(t,e)=>{const n=y.find(i=>i.id===t);if(!n)return;if(e==="done"){bt(t,!0);return}const s=e==="new"?I(n.assignee)?"approved":"new":e,a=n.status==="done"?{status:"open",doneBy:null}:{};W(i=>i.map(o=>o.id===t?{...o,...a,stage:s}:o),()=>D({id:t,...a,stage:s}),"Setting the status")},Jt=[["low","Low","#30a46c",1],["normal","Mid","#f5c451",2],["high","High","#ff5a00",3],["urgent","Urgent","#e5484d",4]],pa=(t,e)=>{const n=Math.max(0,Jt.findIndex(l=>l[0]===t)),[,s,a,i]=Jt[n],o=Jt[(n+1)%Jt.length];return`<button type="button" class="dt-prio" style="--cat:${a}" data-act="prio" data-v="${o[0]}"${e?` data-id="${e}"`:""} data-tip="Priority: ${s} \u2014 click for ${o[1]}" aria-label="Priority ${s}">${vo(i,a)}<span>${s}</span></button>`},Qt=()=>!!c.me&&/@guest\.notemend\.com$/i.test(c.me.email),Rn=(t,e,n,s,a=!1)=>`<div class="dt-prio-row"><span class="dt-meta">${c.client?"":pa(t,n)}${ca(le(e).id,n)}</span>${c.client||Qt()?"":ea(s,n,a)}</div>`,Zt='<svg viewBox="0 0 20 20" width="13" height="13" aria-hidden="true"><circle cx="10" cy="6.8" r="3"/><path d="M4.2 16.5c.6-3 3-4.8 5.8-4.8s5.2 1.8 5.8 4.8" stroke-linejoin="round"/></svg>',ma='<svg viewBox="0 0 20 20" width="13" height="13" aria-hidden="true"><circle cx="8.5" cy="6.8" r="3"/><path d="M2.8 16.5c.6-3 3-4.8 5.7-4.8 1.3 0 2.5.4 3.5 1.1M15.5 11v5M13 13.5h5" stroke-linejoin="round"/></svg>',ga='<svg viewBox="0 0 20 20" width="13" height="13" aria-hidden="true"><circle cx="10" cy="6.8" r="3"/><path d="M4.2 16.5c.6-3 3-4.8 5.8-4.8s5.2 1.8 5.8 4.8" stroke-linejoin="round"/><path d="M3.5 3.5l13 13"/></svg>',fa='<svg viewBox="0 0 20 20" width="14" height="14" aria-hidden="true"><circle cx="5" cy="10" r="1.1" fill="currentColor" stroke="none"/><circle cx="10" cy="10" r="1.1" fill="currentColor" stroke="none"/><circle cx="15" cy="10" r="1.1" fill="currentColor" stroke="none"/></svg>',Bn=(t,e)=>`<label class="dt-more" data-tip="More"><span aria-hidden="true">${fa}</span><select class="dt-more-select"${e?` data-id="${e}"`:""} aria-label="More">
|
|
5
5
|
<option value="" hidden selected></option>
|
|
6
|
-
${c.client?"":`<option value="team" data-icon="${p(
|
|
7
|
-
<option value="client" data-icon="${p(
|
|
8
|
-
<option value="${e?"rm":"discard"}" data-icon="${p(
|
|
9
|
-
</select></label>`,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
</select></span></label>`},xe='<svg viewBox="0 0 20 20" width="9" height="9" aria-hidden="true"><path d="M5.5 5.5l9 9M14.5 5.5l-9 9"/></svg>',ha=!1,ba=!1,In='<svg viewBox="0 0 12 12" width="10" height="10" aria-hidden="true"><path d="M3 1.8v8.4L10 6z"/></svg>',ya='<svg viewBox="0 0 12 12" width="10" height="10" aria-hidden="true"><path d="M2.5 1.5h2.5v9H2.5zM7 1.5h2.5v9H7z"/></svg>',va=t=>`${Math.floor(t/60)}:${String(Math.floor(t%60)).padStart(2,"0")}`,$a=(t,e)=>{const n=t.closest(".dt-voice"),s=n.querySelector("audio"),a=n.querySelector(".dt-voice-play");if(!s.dataset.wired){s.dataset.wired="1";const l=n.querySelector(".dt-voice-track i"),u=n.querySelector(".dt-voice-time"),m=()=>Number.isFinite(s.duration)?s.duration:0;s.addEventListener("timeupdate",()=>{l.style.transform=`scaleX(${m()?Math.min(1,s.currentTime/m()):0})`,u.textContent=va(s.currentTime)}),s.addEventListener("play",()=>{a.innerHTML=ya,a.setAttribute("aria-label","Pause"),n.classList.add("is-playing")}),s.addEventListener("pause",()=>{a.innerHTML=In,a.setAttribute("aria-label","Play the voice note"),n.classList.remove("is-playing")}),s.addEventListener("ended",()=>{s.currentTime=0})}const o=()=>{if(e){const l=n.querySelector(".dt-voice-track").getBoundingClientRect();Number.isFinite(s.duration)&&(s.currentTime=Math.max(0,Math.min(1,(e.clientX-l.left)/l.width))*s.duration);return}if(!s.paused){s.pause();return}b.querySelectorAll(".dt-voice audio").forEach(l=>{l!==s&&l.pause()}),s.play().catch(()=>{})};if(Number.isFinite(s.duration)||s.readyState<1){s.readyState<1?s.addEventListener("loadedmetadata",()=>Number.isFinite(s.duration)?o():i(),{once:!0}):o();return}i();function i(){s.addEventListener("timeupdate",()=>{s.currentTime=0,o()},{once:!0}),s.currentTime=1e9}},Ae=t=>t.startsWith("data:audio/")||/(^|\/)voice-[^/?]*\.(webm|m4a)(\?|$)/i.test(t),Pn=t=>t.startsWith("data:video/")||/\.webm(\?|$)/i.test(t),Ht=new Map,wa=t=>{if(!t.startsWith("data:"))return t;let e=Ht.get(t);if(!e){const[n,s]=t.split(",",2);if(e=URL.createObjectURL(new Blob([Uint8Array.from(atob(s),a=>a.charCodeAt(0))],{type:n.slice(5).split(";")[0]})),Ht.set(t,e),Ht.size>8){const[a,o]=Ht.entries().next().value;URL.revokeObjectURL(o),Ht.delete(a)}}return e},Ea=(t,e)=>`<span class="dt-voice"><button type="button" class="dt-voice-play" data-act="voice" aria-label="Play the voice note">${In}</button><button type="button" class="dt-voice-track" data-act="voice-seek" aria-label="Jump"><i></i></button><span class="dt-voice-time">0:00</span><audio src="${wa(t)}" preload="metadata"></audio>${e===void 0?"":`<button class="dt-voice-rm" data-act="voice-write" ${e} aria-label="Write it out" title="Write it out \u2014 its words go in the box">${Ra}</button>`}${e===void 0?"":`<button class="dt-voice-rm" data-act="unshot" ${e} aria-label="Remove the recording" title="Remove the recording">${xe}</button>`}</span>`,Sa=(t,e,n)=>`<span class="dt-shot dt-doc">${t.startsWith("data:")?`<span class="dt-doc-name">${_n}${p(e)}</span>`:`<a class="dt-doc-name" href="${t}" target="_blank" rel="noreferrer">${_n}${p(e)}</a>`}${n===void 0?"":`<button class="dt-shot-rm" data-act="unshot" ${n} aria-label="Remove">${xe}</button>`}</span>`,jn=(t,e,n=t)=>Cs(n)?Sa(t,Cs(n),e):Ae(n)?Ea(t,e):`<span class="dt-shot${Pn(n)?" dt-shot--video":""}">${Pn(n)?`<video src="${t}" controls preload="metadata" playsinline></video>`:`<a href="${t}" target="_blank"><img src="${t}" alt="" loading="lazy" /></a>`}${e===void 0?"":`<button class="dt-shot-rm" data-act="unshot" ${e} aria-label="Remove">${xe}</button>`}</span>`,He=(t=[],e)=>t.length?`<div class="dt-note-shots">${t.map(n=>{const s=n.split("/").pop(),a=ho(s);return jn(a,e===void 0?void 0:`data-id="${e}" data-img="${p(s)}"`,s)}).join("")}</div>`:"",Fn=(t=[])=>t.length?`<div class="dt-note-shots">${t.map((e,n)=>jn(e,`data-i="${n}"`)).join("")}</div>`:"",_n='<svg viewBox="0 0 20 20" width="14" height="14" aria-hidden="true"><path d="M11.5 2.5H6a1.5 1.5 0 0 0-1.5 1.5v12A1.5 1.5 0 0 0 6 17.5h8a1.5 1.5 0 0 0 1.5-1.5V6.5z"/><path d="M11.5 2.5v4h4"/></svg>',Ta='<svg viewBox="0 0 20 20" width="15" height="15" aria-hidden="true"><rect x="2.5" y="5.5" width="11" height="9" rx="2"/><path d="m13.5 9 4-2.5v7l-4-2.5"/></svg>',Ma='<svg viewBox="0 0 20 20" width="15" height="15" aria-hidden="true"><path d="M3.5 5.5h8M7.5 5.5v10M11 15.5l5-5 1.5 1.5-5 5H11z" stroke-linejoin="round"/></svg>',La=!!navigator.mediaDevices?.getDisplayMedia&&typeof MediaRecorder<"u";let ct=null;const ka=async t=>{if(ct){ct.stop();return}let e;try{e=await navigator.mediaDevices.getDisplayMedia({video:{frameRate:12},audio:!1})}catch{return}const n=await navigator.mediaDevices.getUserMedia({audio:!0}).catch(()=>null),s=new MediaStream([...e.getVideoTracks(),...n?.getAudioTracks()??[]]),a=["video/webm;codecs=vp9,opus","video/webm;codecs=vp8,opus","video/webm"].find(m=>MediaRecorder.isTypeSupported(m));if(!a){for(const m of e.getTracks())m.stop();A("This browser cannot record WebM video.");return}const o=new MediaRecorder(s,{mimeType:a,videoBitsPerSecond:6e5,audioBitsPerSecond:32e3}),i=[],l=!!Number(t?.dataset.id);o.ondataavailable=m=>{m.data.size&&i.push(m.data)};const u=setTimeout(()=>{o.state!=="inactive"&&o.stop()},3e4);o.onstop=async()=>{clearTimeout(u);for(const h of[...e.getTracks(),...n?.getTracks()??[]])h.stop();ct=null;const m=new Blob(i,{type:"video/webm"});if(m.size>32e5){A("That recording is too big to send \u2014 keep it shorter."),f();return}const r=await new Promise(h=>{const g=new FileReader;g.onload=()=>h(String(g.result)),g.readAsDataURL(m)});l?B.push(r):d&&(d.images??=[]).push(r),f()},e.getVideoTracks()[0]?.addEventListener("ended",()=>{o.state!=="inactive"&&o.stop()}),ct=o,o.start(1e3),f()},xa='<svg viewBox="0 0 20 20" width="15" height="15" aria-hidden="true"><rect x="7.5" y="3" width="5" height="9" rx="2.5"/><path d="M5 9.5a5 5 0 0 0 10 0M10 14.5V17"/></svg>',Aa='<svg viewBox="0 0 20 20" width="14" height="14" aria-hidden="true"><path d="m5 10.5 3.2 3L15 6.5"/></svg>',Ha=90,Ne=32,Na=()=>!!c.voice&&!!navigator.mediaDevices?.getUserMedia&&typeof MediaRecorder<"u";let te=!1;const Ca=async(t,e)=>{if(te||!t)return;const n=Number(t.dataset.id)||0;te=!0,e.classList.add("is-asking"),e.title="Waiting for the microphone \u2014 allow it in the browser";let s;try{s=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(S){te=!1,e.classList.remove("is-asking");const k=S?.name;A(k==="NotAllowedError"?"The microphone is blocked for this site \u2014 allow it from the icon left of the address, then try again.":k==="NotFoundError"?"No microphone found \u2014 plug one in or pick it in the system settings.":k==="NotReadableError"?"The microphone is busy in another app \u2014 close it there and try again.":`The microphone did not start: ${S?.message||k||"unknown error"}`);return}e.classList.remove("is-asking");const a=()=>b.querySelector(n?`.dt-note[data-id="${n}"] .dt-compose`:".dt-note[data-draft] .dt-compose"),o=document.createElement("div");o.className="dt-rec",o.innerHTML=`<button type="button" class="dt-rec-x" title="Discard (Esc)" aria-label="Discard">${Qe}</button><span class="dt-rec-time"><i></i><b>0:00</b></span><span class="dt-rec-wave">${"<i></i>".repeat(Ne)}</span><button type="button" class="dt-rec-done" title="Done \u2014 write it out" aria-label="Done">${Aa}</button>`;const i=o.querySelector("b"),l=[...o.querySelectorAll(".dt-rec-wave i")],u=new AudioContext,m=u.createAnalyser();m.fftSize=512,u.createMediaStreamSource(s).connect(m);const r=new Uint8Array(m.fftSize),h=[],g=new MediaRecorder(s,{audioBitsPerSecond:32e3}),w=[],M=Date.now();let R=!0;const st=setInterval(()=>{const S=a();S&&o.parentElement!==S&&S.appendChild(o),m.getByteTimeDomainData(r);let k=0;for(const v of r)k+=((v-128)/128)**2;h.push(Math.min(1,Math.sqrt(k/r.length)*4));const I=h.slice(-Ne);l.forEach((v,qt)=>{const ut=I[qt-(Ne-I.length)];v.style.transform=`scaleY(${Math.max(.1,ut??0).toFixed(2)})`,v.classList.toggle("is-empty",ut===void 0)});const Q=Math.floor((Date.now()-M)/1e3);i.textContent=`${Math.floor(Q/60)}:${String(Q%60).padStart(2,"0")}`,Q>=Ha&&g.state!=="inactive"&&g.stop()},90),at=S=>{R=S,g.state!=="inactive"&&g.stop()};o.querySelector(".dt-rec-x").addEventListener("click",S=>{S.stopPropagation(),at(!1)}),o.querySelector(".dt-rec-done").addEventListener("click",S=>{S.stopPropagation(),at(!0)}),o.addEventListener("keydown",S=>{S.key==="Escape"&&(S.stopPropagation(),at(!1))}),g.ondataavailable=S=>{S.data.size&&w.push(S.data)},g.onstop=async()=>{if(clearInterval(st),s.getTracks().forEach(I=>I.stop()),u.close().catch(()=>{}),o.remove(),te=!1,!R)return;const S=new Blob(w,{type:g.mimeType||"audio/webm"}),k=await new Promise(I=>{const Q=new FileReader;Q.onload=()=>I(String(Q.result)),Q.readAsDataURL(S)});n?B.push(k):d&&(d.images??=[]).push(k),f(),a()?.querySelector("textarea")?.focus()},g.start(1e3),a()?.appendChild(o),o.querySelector(".dt-rec-done").focus()},Kn="\u{1F3A4} Voice note",Ra='<svg viewBox="0 0 20 20" width="12" height="12" aria-hidden="true"><rect x="2.5" y="4.5" width="15" height="11" rx="2"/><path d="M6 11.5h3M11 11.5h3M6 8.5h8"/></svg>',Oa=async t=>{const e=t.closest(".dt-note"),s=(e?.hasAttribute("data-draft")?d?.images??[]:B)[Number(t.dataset.i)];if(!s||t.classList.contains("is-asking"))return;t.classList.add("is-asking");const a=await L("transcribe",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({audio:s})}).catch(()=>null),o=a?await a.json().catch(()=>({})):{};if(t.classList.remove("is-asking"),!a?.ok||!o.text){A(o.error||(a?.ok?"Didn't hear any words in it.":"Could not make out the words \u2014 try again, or type it."));return}const i=e?.querySelector("textarea.dt-note-input, textarea.dt-note-reply-input");i&&(i.value=i.value.trim()?`${i.value.trimEnd()} ${o.text}`:o.text,i.dispatchEvent(new Event("input",{bubbles:!0})),i.focus())},G=new Map,qa=async(t,e)=>{const n=`${t}:${e}`;if(G.has(n)){G.delete(n),f();return}const s=y.find(l=>l.id===t),a=s&&It(s).find(l=>(l.at??"0")===e);if(!a?.text)return;G.set(n,null),f();const o=await L("translate",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({text:a.text,to:navigator.language||"en"})}).catch(()=>null),i=o?await o.json().catch(()=>({})):{};G.has(n)&&(o?.ok&&i.text?G.set(n,i.text):(G.delete(n),A(i.error||"Could not translate it \u2014 try again.")),f())},Ba='<svg viewBox="0 0 20 20" width="13" height="13" aria-hidden="true"><path d="M3 5h8M7 3v2m2 0c-.6 3.2-2.8 6-6 7.5M5.5 8.5c.8 1.6 2.2 2.9 4 3.8M10.5 17l3.25-7.5L17 17m-5.5-2h4.5"/></svg>',Da='<svg viewBox="0 0 20 20" width="15" height="15" aria-hidden="true"><rect x="3" y="4" width="14" height="12" rx="2"/><circle cx="7.5" cy="8.5" r="1.4"/><path d="m3.5 14.5 4-4 3 3 2-2 4 4"/></svg>',Wn=(t,e,n,s,a="",o="")=>`<div class="dt-note-foot"><div class="dt-compose">
|
|
6
|
+
${c.client?"":`<option value="team" data-icon="${p(ga)}"${t?"":" data-on"}>Team only</option>
|
|
7
|
+
<option value="client" data-icon="${p(Zt)}"${t?" data-on":""}>Team and client</option>`}
|
|
8
|
+
<option value="${e?"rm":"discard"}" data-icon="${p(tn)}" data-danger${c.client?"":" data-sep"}>${e?"Delete thread":"Discard draft"}</option>
|
|
9
|
+
</select></label>`,In='<svg viewBox="0 0 20 20" width="14" height="14" aria-hidden="true"><path d="M2 10s3-5.5 8-5.5S18 10 18 10s-3 5.5-8 5.5S2 10 2 10z"/><circle cx="10" cy="10" r="2.3"/></svg>',ha=()=>(c.team??[]).filter(t=>!c.studio||c.studio.includes(t.email)),ba=t=>{const e=t||c.lead||"",n=ha();if(!n.length)return"";const s=Hn(e);return`<label class="dt-field" title="Who it is for"><span class="dt-field-box${s?" dt-field-box--face":""}" style="--cat:${kt(e||"x@x")}">${s}<select class="dt-for-select" aria-label="Who this is for">
|
|
10
|
+
${n.map(a=>`<option value="${p(a.email)}" data-c="${kt(a.email)}"${xe(a.email)}${e===a.email?" selected":""}>${p(a.name||a.email)}</option>`).join("")}
|
|
11
|
+
</select></span></label>`},He='<svg viewBox="0 0 20 20" width="9" height="9" aria-hidden="true"><path d="M5.5 5.5l9 9M14.5 5.5l-9 9"/></svg>',Dn='<svg viewBox="0 0 12 12" width="10" height="10" aria-hidden="true"><path d="M3 1.8v8.4L10 6z"/></svg>',ya='<svg viewBox="0 0 12 12" width="10" height="10" aria-hidden="true"><path d="M2.5 1.5h2.5v9H2.5zM7 1.5h2.5v9H7z"/></svg>',va=t=>`${Math.floor(t/60)}:${String(Math.floor(t%60)).padStart(2,"0")}`,$a=(t,e)=>{const n=t.closest(".dt-voice"),s=n.querySelector("audio"),a=n.querySelector(".dt-voice-play");if(!s.dataset.wired){s.dataset.wired="1";const l=n.querySelector(".dt-voice-track i"),u=n.querySelector(".dt-voice-time"),m=()=>Number.isFinite(s.duration)?s.duration:0;s.addEventListener("timeupdate",()=>{l.style.transform=`scaleX(${m()?Math.min(1,s.currentTime/m()):0})`,u.textContent=va(s.currentTime)}),s.addEventListener("play",()=>{a.innerHTML=ya,a.setAttribute("aria-label","Pause"),n.classList.add("is-playing")}),s.addEventListener("pause",()=>{a.innerHTML=Dn,a.setAttribute("aria-label","Play the voice note"),n.classList.remove("is-playing")}),s.addEventListener("ended",()=>{s.currentTime=0})}const i=()=>{if(e){const l=n.querySelector(".dt-voice-track").getBoundingClientRect();Number.isFinite(s.duration)&&(s.currentTime=Math.max(0,Math.min(1,(e.clientX-l.left)/l.width))*s.duration);return}if(!s.paused){s.pause();return}b.querySelectorAll(".dt-voice audio").forEach(l=>{l!==s&&l.pause()}),s.play().catch(()=>{})};if(Number.isFinite(s.duration)||s.readyState<1){s.readyState<1?s.addEventListener("loadedmetadata",()=>Number.isFinite(s.duration)?i():o(),{once:!0}):i();return}o();function o(){s.addEventListener("timeupdate",()=>{s.currentTime=0,i()},{once:!0}),s.currentTime=1e9}},Ne=t=>t.startsWith("data:audio/")||/(^|\/)voice-[^/?]*\.(webm|m4a)(\?|$)/i.test(t),Pn=t=>t.startsWith("data:video/")||/\.webm(\?|$)/i.test(t),At=new Map,wa=t=>{if(!t.startsWith("data:"))return t;let e=At.get(t);if(!e){const[n,s]=t.split(",",2);if(e=URL.createObjectURL(new Blob([Uint8Array.from(atob(s),a=>a.charCodeAt(0))],{type:n.slice(5).split(";")[0]})),At.set(t,e),At.size>8){const[a,i]=At.entries().next().value;URL.revokeObjectURL(i),At.delete(a)}}return e},Ea=(t,e)=>`<span class="dt-voice"><button type="button" class="dt-voice-play" data-act="voice" aria-label="Play the voice note">${Dn}</button><button type="button" class="dt-voice-track" data-act="voice-seek" aria-label="Jump"><i></i></button><span class="dt-voice-time">0:00</span><audio src="${wa(t)}" preload="metadata"></audio>${e===void 0?"":`<button class="dt-voice-rm" data-act="voice-write" ${e} aria-label="Write it out" title="Write it out \u2014 its words go in the box">${Aa}</button>`}${e===void 0?"":`<button class="dt-voice-rm" data-act="unshot" ${e} aria-label="Remove the recording" title="Remove the recording">${He}</button>`}</span>`,Sa=(t,e,n)=>`<span class="dt-shot dt-doc">${t.startsWith("data:")?`<span class="dt-doc-name">${_n}${p(e)}</span>`:`<a class="dt-doc-name" href="${t}" target="_blank" rel="noreferrer">${_n}${p(e)}</a>`}${n===void 0?"":`<button class="dt-shot-rm" data-act="unshot" ${n} aria-label="Remove">${He}</button>`}</span>`,Fn=(t,e,n=t)=>Cs(n)?Sa(t,Cs(n),e):Ne(n)?Ea(t,e):`<span class="dt-shot${Pn(n)?" dt-shot--video":""}">${Pn(n)?`<video src="${t}" controls preload="metadata" playsinline></video>`:`<a href="${t}" target="_blank"><img src="${t}" alt="" loading="lazy" /></a>`}${e===void 0?"":`<button class="dt-shot-rm" data-act="unshot" ${e} aria-label="Remove">${He}</button>`}</span>`,Ce=(t=[],e)=>t.length?`<div class="dt-note-shots">${t.map(n=>{const s=n.split("/").pop(),a=fo(s);return Fn(a,e===void 0?void 0:`data-id="${e}" data-img="${p(s)}"`,s)}).join("")}</div>`:"",jn=(t=[])=>t.length?`<div class="dt-note-shots">${t.map((e,n)=>Fn(e,`data-i="${n}"`)).join("")}</div>`:"",_n='<svg viewBox="0 0 20 20" width="14" height="14" aria-hidden="true"><path d="M11.5 2.5H6a1.5 1.5 0 0 0-1.5 1.5v12A1.5 1.5 0 0 0 6 17.5h8a1.5 1.5 0 0 0 1.5-1.5V6.5z"/><path d="M11.5 2.5v4h4"/></svg>',Ta='<svg viewBox="0 0 20 20" width="15" height="15" aria-hidden="true"><rect x="7.5" y="3" width="5" height="9" rx="2.5"/><path d="M5 9.5a5 5 0 0 0 10 0M10 14.5V17"/></svg>',La='<svg viewBox="0 0 20 20" width="14" height="14" aria-hidden="true"><path d="m5 10.5 3.2 3L15 6.5"/></svg>',Ma=90,qe=32,ka=()=>!!c.voice&&!!navigator.mediaDevices?.getUserMedia&&typeof MediaRecorder<"u";let te=!1;const xa=async(t,e)=>{if(te||!t)return;const n=Number(t.dataset.id)||0;te=!0,e.classList.add("is-asking"),e.title="Waiting for the microphone \u2014 allow it in the browser";let s;try{s=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(E){te=!1,e.classList.remove("is-asking");const k=E?.name;C(k==="NotAllowedError"?"The microphone is blocked for this site \u2014 allow it from the icon left of the address, then try again.":k==="NotFoundError"?"No microphone found \u2014 plug one in or pick it in the system settings.":k==="NotReadableError"?"The microphone is busy in another app \u2014 close it there and try again.":`The microphone did not start: ${E?.message||k||"unknown error"}`);return}e.classList.remove("is-asking");const a=()=>b.querySelector(n?`.dt-note[data-id="${n}"] .dt-compose`:".dt-note[data-draft] .dt-compose"),i=document.createElement("div");i.className="dt-rec",i.innerHTML=`<button type="button" class="dt-rec-x" title="Discard (Esc)" aria-label="Discard">${tn}</button><span class="dt-rec-time"><i></i><b>0:00</b></span><span class="dt-rec-wave">${"<i></i>".repeat(qe)}</span><button type="button" class="dt-rec-done" title="Done \u2014 write it out" aria-label="Done">${La}</button>`;const o=i.querySelector("b"),l=[...i.querySelectorAll(".dt-rec-wave i")],u=new AudioContext,m=u.createAnalyser();m.fftSize=512,u.createMediaStreamSource(s).connect(m);const r=new Uint8Array(m.fftSize),h=[],g=new MediaRecorder(s,{audioBitsPerSecond:32e3}),w=[],L=Date.now();let z=!0;const Y=setInterval(()=>{const E=a();E&&i.parentElement!==E&&E.appendChild(i),m.getByteTimeDomainData(r);let k=0;for(const at of r)k+=((at-128)/128)**2;h.push(Math.min(1,Math.sqrt(k/r.length)*4));const st=h.slice(-qe);l.forEach((at,St)=>{const ct=st[St-(qe-st.length)];at.style.transform=`scaleY(${Math.max(.1,ct??0).toFixed(2)})`,at.classList.toggle("is-empty",ct===void 0)});const v=Math.floor((Date.now()-L)/1e3);o.textContent=`${Math.floor(v/60)}:${String(v%60).padStart(2,"0")}`,v>=Ma&&g.state!=="inactive"&&g.stop()},90),Et=E=>{z=E,g.state!=="inactive"&&g.stop()};i.querySelector(".dt-rec-x").addEventListener("click",E=>{E.stopPropagation(),Et(!1)}),i.querySelector(".dt-rec-done").addEventListener("click",E=>{E.stopPropagation(),Et(!0)}),i.addEventListener("keydown",E=>{E.key==="Escape"&&(E.stopPropagation(),Et(!1))}),g.ondataavailable=E=>{E.data.size&&w.push(E.data)},g.onstop=async()=>{if(clearInterval(Y),s.getTracks().forEach(st=>st.stop()),u.close().catch(()=>{}),i.remove(),te=!1,!z)return;const E=new Blob(w,{type:g.mimeType||"audio/webm"}),k=await new Promise(st=>{const v=new FileReader;v.onload=()=>st(String(v.result)),v.readAsDataURL(E)});n?F.push(k):d&&(d.images??=[]).push(k),f(),a()?.querySelector("textarea")?.focus()},g.start(1e3),a()?.appendChild(i),i.querySelector(".dt-rec-done").focus()},Kn="\u{1F3A4} Voice note",Aa='<svg viewBox="0 0 20 20" width="12" height="12" aria-hidden="true"><rect x="2.5" y="4.5" width="15" height="11" rx="2"/><path d="M6 11.5h3M11 11.5h3M6 8.5h8"/></svg>',Ha=async t=>{const e=t.closest(".dt-note"),s=(e?.hasAttribute("data-draft")?d?.images??[]:F)[Number(t.dataset.i)];if(!s||t.classList.contains("is-asking"))return;t.classList.add("is-asking");const a=await ot("transcribe",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({audio:s})}).catch(()=>null),i=a?await a.json().catch(()=>({})):{};if(t.classList.remove("is-asking"),!a?.ok||!i.text){C(i.error||(a?.ok?"Didn't hear any words in it.":"Could not make out the words \u2014 try again, or type it."));return}const o=e?.querySelector("textarea.dt-note-input, textarea.dt-note-reply-input");o&&(o.value=o.value.trim()?`${o.value.trimEnd()} ${i.text}`:i.text,o.dispatchEvent(new Event("input",{bubbles:!0})),o.focus())},Z=new Map,Na=async(t,e)=>{const n=`${t}:${e}`;if(Z.has(n)){Z.delete(n),f();return}const s=y.find(l=>l.id===t),a=s&&Bt(s).find(l=>(l.at??"0")===e);if(!a?.text)return;Z.set(n,null),f();const i=await ot("translate",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({text:a.text,to:navigator.language||"en"})}).catch(()=>null),o=i?await i.json().catch(()=>({})):{};Z.has(n)&&(i?.ok&&o.text?Z.set(n,o.text):(Z.delete(n),C(o.error||"Could not translate it \u2014 try again.")),f())},Ca='<svg viewBox="0 0 20 20" width="13" height="13" aria-hidden="true"><path d="M3 5h8M7 3v2m2 0c-.6 3.2-2.8 6-6 7.5M5.5 8.5c.8 1.6 2.2 2.9 4 3.8M10.5 17l3.25-7.5L17 17m-5.5-2h4.5"/></svg>',qa='<svg viewBox="0 0 20 20" width="15" height="15" aria-hidden="true"><rect x="3" y="4" width="14" height="12" rx="2"/><circle cx="7.5" cy="8.5" r="1.4"/><path d="m3.5 14.5 4-4 3 3 2-2 4 4"/></svg>',Wn=(t,e,n,s,a="")=>`<div class="dt-note-foot"><div class="dt-compose">
|
|
13
12
|
<textarea class="${t}" rows="1" placeholder="${e}">${p(n)}</textarea>
|
|
14
13
|
${a}
|
|
15
14
|
<div class="dt-compose-bar">
|
|
16
|
-
<span class="dt-compose-tools"><button class="dt-attach" data-act="attach" title="Attach a screenshot, a PDF or a Word file \u2014 or paste or drop one">${
|
|
17
|
-
${
|
|
15
|
+
<span class="dt-compose-tools"><button class="dt-attach" data-act="attach" title="Attach a screenshot, a PDF or a Word file \u2014 or paste or drop one">${qa}</button>
|
|
16
|
+
${ka()?`<button class="dt-attach" data-act="speak" title="Speak \u2014 sent with its words as a voice note">${Ta}</button>`:""}</span>
|
|
18
17
|
<button class="dt-send${n.trim()?" is-ready":""}" ${s} title="Send (Enter)"
|
|
19
18
|
><svg viewBox="0 0 20 20" width="14" height="14" aria-hidden="true"><path d="M10 15.5v-11M5.5 9 10 4.5 14.5 9"/></svg></button>
|
|
20
19
|
</div>
|
|
21
|
-
</div></div>`,
|
|
22
|
-
class="dt-note-resolve${n?" is-on":""}" title="${n?"Reopen":e==="claude"?"Looks right \u2014 mark it resolved":"Resolve"}">${
|
|
23
|
-
style="left:${
|
|
24
|
-
title="${p(r.text.slice(0,80))} \xB7 ${
|
|
25
|
-
style="left:${
|
|
20
|
+
</div></div>`,Oe=(t,e)=>(t||"element")+(e?.[0]?"."+e[0]:""),Un=()=>H.map((t,e)=>({i:e,el:Oe(t.tag,t.classes),text:It(t.text??""),shots:t.images?.length??0,orphan:!_(t)}));let Re=[],zn="";const K=t=>{const e=t.working;return dt(e?.agent,e?.by??lo(t.assignee))},Yn=t=>{const e=Math.max(1,Math.round((Date.now()-Date.parse(t??""))/6e4)||1);return e<60?`${e} min`:`${Math.round(e/60)} h`},ee=(t,e)=>{const n=t.working;return{held:"From a guest \u2014 waits for the studio to approve it",queued:`Queued for ${K(t)} \u2014 it takes it on its next run`,asks:`${K(t)} is waiting for your answer`,working:`${K(t)} is on it \xB7 ${Yn(n?.at)}`,stuck:`${K(t)} went quiet \u2014 its next run takes it again`,review:`Resolved by ${dt(t.doneAgent,t.doneFor)} \u2014 click to clear`,done:"Resolved"}[e]},Oa=t=>{const e=V(t);if(!e)return c.client||Qt()||t.status==="done"?"":`<button class="dt-note-state dt-step--none" data-act="hand" data-v="agent" data-id="${t.id}" data-tip="Hand to Claude" aria-label="Hand to Claude">${qs(13,0)}</button>`;const n=qs(13,12);return e==="review"?`<button class="dt-note-state dt-step--review" data-act="reopen" data-id="${t.id}" data-tip="${p(ee(t,e))}" aria-label="${p(ee(t,e))}">${n}</button>`:`<span class="dt-note-state dt-step--${e}" data-tip="${p(ee(t,e))}" role="img" aria-label="${p(ee(t,e))}">${n}</span>`},Vn=t=>{const e=B(t),n=e==="done";return`${Oa(t)}<button data-act="${n?"reopen":"done"}" data-id="${t.id}"
|
|
21
|
+
class="dt-note-resolve${n?" is-on":""}" title="${n?"Reopen":e==="claude"?"Looks right \u2014 mark it resolved":"Resolve"}">${Tt}</button>`},Ra=t=>t?new Date(t).toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"}):"",Ba=t=>{if(c.client)return"";const e=V(t),n={act:"hand",v:"me",icon:Zt,tip:c.me?"Take it myself":"Take it off Claude"},s={act:"reopen",icon:en,tip:"Reopen"},a=[{act:"accept",icon:Tt,tip:"Looks right \u2014 accept it",main:!0},{act:"sendback",icon:en,tip:"Send it back \u2014 say what is wrong below"}],i=t.working,o=!I(t.assignee)&&t.assignee?t.assignee===c.me?.email?"You":Yt(t.assignee):"",l=e==="queued"?{step:e,title:`Queued for ${K(t)}`,acts:[n]}:e==="working"?{step:e,title:`${K(t)} is working`,acts:[n],live:!0}:e==="asks"?{step:e,title:`${K(t)} asks`,acts:[]}:e==="stuck"?{step:e,title:`${K(t)} silent for ${Yn(i?.at)}`,acts:[n]}:e==="review"?null:t.status!=="done"&&G(t)==="accepted"?{step:"done",title:`Accepted${t.acceptedAt?` \xB7 ${Ra(t.acceptedAt)}`:""}`,acts:[{...s,act:"sendback",tip:"Send it back"}]}:G(t)==="review"&&o?{step:"review",title:`${o} ${o==="You"?"say":"says"} done \u2014 check it`,acts:a}:!e&&!t.assignee&&t.status!=="done"&&c.me&&!Qt()?{step:"anyone",title:"Unassigned",acts:[{act:"hand",v:"me",icon:Tt,tip:"Take it myself"},{act:"hand",v:"agent",icon:ut(13),tip:`Give it to ${K(t)}`},{act:"give",icon:ma,tip:"Give it to someone",pick:!0}]}:null;return l?`<div class="dt-step dt-step--${l.step}">${l.step==="anyone"?wn:""}<span class="dt-step-text"><b>${p(l.title)}</b></span>${l.acts.map(u=>u.pick?`<label class="dt-step-act" data-tip="${p(u.tip)}">${u.icon}<select class="dt-for-select" data-id="${t.id}" aria-label="${p(u.tip)}"><option value="" selected hidden></option>${ft().map(m=>`<option value="${p(m.email)}"${xe(m.email)}>${p(m.email===c.me?.email?`Me \xB7 ${m.name||m.email}`:m.name||m.email)}</option>`).join("")}</select></label>`:`<button type="button" class="dt-step-act${u.main?" is-main":""}" data-act="${u.act}" data-id="${t.id}"${u.v?` data-v="${u.v}"`:""} data-tip="${p(u.tip)}" aria-label="${p(u.tip)}">${u.icon}</button>`).join("")}${l.live?'<i class="dt-step-live" aria-hidden="true"></i>':""}</div>`:""},Ia=async(t,e)=>{const n=e?y.find(a=>a.id===t):void 0,s=n?await ze(Q(n)):null;return D(e?{id:t,status:"done",doneBy:"you",...s?{after:s}:{}}:{id:t,status:"open",doneBy:null,stage:Gn(y.find(a=>a.id===t))})},W=async(t,e,n)=>{const s=y,a=vt;y=t(y),vt=t(vt),f();const i=await e().catch(()=>null);if(!i?.ok){y=s,vt=a,f(),C(`${n} did not go through${i?` (${i.status})`:""}.`);return}oe()},Gn=t=>t?I(t.assignee)?"approved":t.assignee?"progress":"new":"new",bt=(t,e)=>W(n=>n.map(s=>s.id===t?{...s,status:e?"done":"open",doneBy:e?"you":null,...e?{}:{stage:Gn(s),reopenedAt:new Date().toISOString()}}:s),()=>Ia(t,e),e?"Resolving":"Reopening"),Be=t=>W(e=>e.filter(n=>n.id!==t),()=>ot(`comments?id=${t}`,{method:"DELETE"}),"Deleting"),Da=t=>{const e=y.filter(a=>tt(a)===t),n=e.filter(a=>B(a)==="open").length,s=e.filter(a=>B(a)==="claude").length;ve.innerHTML=n?String(n):s?ut(9):"\u2713",ve.dataset.state=n?"open":s?"claude":"done",ve.hidden=e.length===0};let Ie=0,Xn;const f=()=>{const t=Ie-performance.now();if(t>0){clearTimeout(Xn),Xn=setTimeout(f,t);return}if(rt(),S){const r=Un(),h=JSON.stringify(r);h!==zn&&(zn=h,parent.postMessage({dt:!0,drafts:r},location.origin))}bn(),$!==Mt&&(O="",F=[],Mt=$),T&&T.id!==$&&(T=null);const e=lt();if(Da(e),!A){b.innerHTML="",Me(null);return}const n=e;let s="";const a=y.filter(r=>tt(r)===n&&(J||B(r)!=="done"||r.id===$));for(const r of a){const h=_(r);if(!h&&$!==r.id)continue;const g=B(r),w=!h,L=h??{x:0,y:0},z=le(r.category),Y=Qe(r),Et=g==="done"?null:V(r),E=Et?ke[Et]??"":"";if($===r.id&&oa(r),w||(s+=`<button class="dt-pin dt-pin--${g}${E?" dt-pin--agent":""}${Y?" dt-pin--working":""}${g==="open"&&G(r)==="review"?" dt-pin--review":""}" data-id="${r.id}"${h?.off?` data-off="${h.off}"`:""} aria-label="Comment ${r.id}, ${g==="open"?"open":g==="claude"?`resolved by ${p(dt(r.doneAgent,r.doneFor))}`:"resolved"}" aria-expanded="${$===r.id}"
|
|
22
|
+
style="left:${L.x}px;top:${L.y}px;--cat:${z.color};--ring:${Ae.find(k=>k[0]===Gt(r))[2]};--hue:${kn(r.by||r.byName||"")}${E?`;--step-c:${E}`:""}"
|
|
23
|
+
title="${p(r.text.slice(0,80))} \xB7 ${z.label}${Y?` \xB7 ${p(dt(Y.agent,Y.by))} is on it`:""}${g==="claude"?` \xB7 resolved by ${p(dt(r.doneAgent,r.doneFor))} \u2014 tick to confirm`:g==="done"?" \xB7 resolved":""}">${g==="done"?"\u2713":E?ut(11):Mn(r)}${g!=="done"&&$!==r.id&&An(r)?'<i class="dt-pin-new" aria-label="New messages"></i>':""}</button>`),$===r.id){const k=Bt(r),st=V(r)==="review"&&!c.client?k.map(v=>v.author).lastIndexOf("claude"):-1;s+=`<div class="dt-note${w?" dt-note--orphan":""}" data-id="${r.id}" role="dialog" aria-label="Comment ${r.id}"
|
|
24
|
+
style="left:${L.x}px;top:${L.y}px">
|
|
26
25
|
<div class="dt-note-bar">
|
|
27
|
-
<span class="dt-note-el"${c.client?"":` data-tip="${Nn(r.selector,r.label)}"`}>${c.client?`Comment #${
|
|
26
|
+
<span class="dt-note-el"${c.client?"":` data-tip="${Nn(r.selector,r.label)}"`}>${c.client?`Comment #${Fa(r)}`:p(Oe(r.tag,r.classes))}</span>
|
|
28
27
|
<span class="dt-note-tools">
|
|
29
|
-
${!c.client&&r.shared?`<span class="dt-note-eye" data-tip="The client sees this thread" role="img" aria-label="The client sees this thread">${
|
|
28
|
+
${!c.client&&r.shared?`<span class="dt-note-eye" data-tip="The client sees this thread" role="img" aria-label="The client sees this thread">${In}</span>`:""}
|
|
30
29
|
${Vn(r)}
|
|
31
30
|
<i class="dt-note-sep"></i>
|
|
32
31
|
${Bn(r.shared,r.id)}
|
|
33
|
-
<button data-act="close" data-id="${r.id}" data-tip="Close" aria-label="Close">${
|
|
32
|
+
<button data-act="close" data-id="${r.id}" data-tip="Close" aria-label="Close">${Ze}</button>
|
|
34
33
|
</span>
|
|
35
34
|
</div>
|
|
36
|
-
${
|
|
37
|
-
${(()=>{const v=(c.client?"":
|
|
35
|
+
${w?'<p class="dt-note-orphan">The element this was pinned to is not on the page right now.</p>':""}
|
|
36
|
+
${(()=>{const v=(c.client?"":ua(r))+(r.host&&r.host!==location.host?`<span class="dt-note-host" title="Written on ${p(r.host)}">${p(r.host)}</span>`:"");return v?`<div class="dt-note-meta">${v}</div>`:""})()}
|
|
38
37
|
<div class="dt-note-thread">
|
|
39
|
-
${
|
|
40
|
-
<div class="dt-done-acts"><button type="button" class="dt-done-act is-main" data-act="accept" data-id="${r.id}">${
|
|
38
|
+
${k.map((v,at)=>{const St=at===0?null:v.at??null,ct=v.author==="you"&&(!v.by||v.by===c.me?.email),Ts=ct&&T?.id===r.id&&T.at===St,Ot=c.team?.find(Je=>Je.email===v.by),Ls=v.author==="claude"?dt(v.agent,v.by):ct?"You":Ot?.name||v.byName||v.by||"You",Ms=v.author==="claude"?Ot?.agent_avatar_url?`<img class="dt-msg-face" src="${p(Ot.agent_avatar_url)}" alt="">`:`<span class="dt-msg-face dt-msg-ai">${ut(11)}</span>`:Ot?.avatar_url?`<img class="dt-msg-face" src="${p(Ot.avatar_url)}" alt="">`:"",Xe=`${r.id}:${v.at??"0"}`,re=Z.get(Xe),ks=!ct&&c.voice&&v.text?`<button class="dt-msg-edit${Z.has(Xe)?" is-on":""}" data-act="translate" data-id="${r.id}" data-at="${p(v.at??"0")}" title="${Z.has(Xe)?"Show the original":"Translate into your language"}">${Ca}</button>`:"",xs=`<div class="dt-msg-head">${Ms}<b>${p(Ls)}</b><time>${Rs(v.at)}</time>${ks}${ct&&!Ts?`<button class="dt-msg-edit" data-act="edit" data-id="${r.id}" data-at="${p(St??"")}" title="Edit">${Os}</button>${St?`<button class="dt-msg-edit" data-act="unsay" data-id="${r.id}" data-at="${p(St)}" title="Delete">${tn}</button>`:""}`:""}</div>`;return at===st?`<div class="dt-msg dt-msg--done" data-msg="${r.id}:${p(v.at??"0")}"><div class="dt-msg-head">${Ms}<b>${p(Ls)} fixed it</b><time>${Rs(v.at)}</time>${ks}</div><p${re===null?' class="is-asking"':""}>${ps(re||v.text)}</p>${Ce(v.images)}
|
|
39
|
+
<div class="dt-done-acts"><button type="button" class="dt-done-act is-main" data-act="accept" data-id="${r.id}">${Tt}Looks right</button><button type="button" class="dt-done-act" data-act="sendback" data-id="${r.id}">${en}Send back</button></div></div>`:Ts?`<div class="dt-msg">${xs}<div class="dt-compose">
|
|
41
40
|
<textarea class="dt-note-edit-input" rows="1">${p(T.text)}</textarea>
|
|
42
|
-
${
|
|
41
|
+
${Ce(v.images.filter(Je=>!T.drop.includes(Je.split("/").pop())),r.id)}
|
|
43
42
|
<div class="dt-compose-bar">
|
|
44
43
|
<button class="dt-edit-cancel" data-act="edit-cancel">Cancel</button>
|
|
45
|
-
<button class="dt-send${T.text.trim()?" is-ready":""}" data-act="edit-save" title="Save (Enter)">${
|
|
44
|
+
<button class="dt-send${T.text.trim()?" is-ready":""}" data-act="edit-save" title="Save (Enter)">${Tt}</button>
|
|
46
45
|
</div>
|
|
47
|
-
</div></div>`:`<div class="dt-msg" data-msg="${r.id}:${p(v.at??"0")}">${xs}<p${
|
|
46
|
+
</div></div>`:`<div class="dt-msg" data-msg="${r.id}:${p(v.at??"0")}">${xs}<p${re===null?' class="is-asking"':""}>${ps(re||v.text)}</p>${at===0&&r.suggest?la(r.suggest):""}${Ce(v.images)}</div>`}).join("")}
|
|
48
47
|
</div>
|
|
49
|
-
${
|
|
50
|
-
${Wn("dt-note-reply-input",
|
|
51
|
-
${
|
|
52
|
-
</div>`}}
|
|
53
|
-
style="left:${g.x}px;top:${g.y}px" title="Draft, not sent \u2014 click to finish it">${Os}</button>`)});const
|
|
54
|
-
<div class="dt-note${
|
|
48
|
+
${Ba(r)}
|
|
49
|
+
${Wn("dt-note-reply-input",V(r)==="asks"?`Answer ${p(K(r))}`:"Reply",O,`data-act="reply" data-id="${r.id}"`,jn(F))}
|
|
50
|
+
${Rn(r.priority,r.category,r.id,r.assignee??"",po(r))}
|
|
51
|
+
</div>`}}H.forEach((r,h)=>{const g=_(r);g&&(s+=`<button class="dt-pin dt-pin--draft" data-parked="${h}" data-act="draft-open" data-i="${h}"
|
|
52
|
+
style="left:${g.x}px;top:${g.y}px" title="Draft, not sent \u2014 click to finish it">${Os}</button>`)});const i=d&&_(d);if(d){const r=i?.x??0,h=i?.y??0;s+=`${i?`<span class="dt-pin dt-pin--draft" data-draft style="left:${r}px;top:${h}px"></span>`:""}
|
|
53
|
+
<div class="dt-note${i?"":" dt-note--orphan"}" data-draft style="left:${r}px;top:${h}px">
|
|
55
54
|
<div class="dt-note-bar">
|
|
56
|
-
<span class="dt-note-el"${c.client?"":` data-tip="${Nn(d.selector,d.label)}"`}>${c.client?"New comment":p(
|
|
55
|
+
<span class="dt-note-el"${c.client?"":` data-tip="${Nn(d.selector,d.label)}"`}>${c.client?"New comment":p(Oe(d.tag,d.classes))}</span>
|
|
57
56
|
${Kt()?'<span class="dt-note-draft">Draft</span>':""}
|
|
58
57
|
<span class="dt-note-tools">
|
|
59
|
-
${!c.client&&d.shared?`<span class="dt-note-eye" data-tip="The client will see this thread" role="img" aria-label="The client will see this thread">${
|
|
58
|
+
${!c.client&&d.shared?`<span class="dt-note-eye" data-tip="The client will see this thread" role="img" aria-label="The client will see this thread">${In}</span>`:""}
|
|
60
59
|
${Bn(d.shared)}
|
|
61
|
-
<button data-act="cancel" data-tip="Close \u2014 the draft stays" aria-label="Close">${
|
|
60
|
+
<button data-act="cancel" data-tip="Close \u2014 the draft stays" aria-label="Close">${Ze}</button>
|
|
62
61
|
</span>
|
|
63
62
|
</div>
|
|
64
|
-
${
|
|
65
|
-
${(()=>{const g=
|
|
66
|
-
${c.client?`<div class="dt-note-meta">${
|
|
67
|
-
${d.suggest?`<div class="dt-suggest"><span class="dt-suggest-head">New wording for this text<button data-act="unsuggest" title="Keep the text as it is">${
|
|
63
|
+
${i?"":'<p class="dt-note-orphan">The element this was pinned to is not on the page right now.</p>'}
|
|
64
|
+
${(()=>{const g=i?Q(d):null,w=g&&y.find(L=>L.id>0&&B(L)==="open"&&Q(L)===g);return w?`<p class="dt-note-twin">Already open here: \u201C${p(w.text.slice(0,60))}${w.text.length>60?"\u2026":""}\u201D <button data-act="twin" data-id="${w.id}">Open it</button></p>`:""})()}
|
|
65
|
+
${c.client?`<div class="dt-note-meta">${ba(d.assignee)}</div>`:""}
|
|
66
|
+
${d.suggest?`<div class="dt-suggest"><span class="dt-suggest-head">New wording for this text<button data-act="unsuggest" title="Keep the text as it is">${Ze}</button></span>
|
|
68
67
|
<span class="dt-suggest-was">Now: <del>${p(d.suggest.from.slice(0,160))}${d.suggest.from.length>160?"\u2026":""}</del></span>
|
|
69
68
|
<textarea class="dt-suggest-input" rows="2" placeholder="Type how it should read" aria-label="How it should read">${p(d.suggest.to)}</textarea>
|
|
70
69
|
<span class="dt-suggest-hint">Change the words in the box \u2014 the agent puts in exactly what you write.</span></div>`:""}
|
|
71
|
-
${Wn("dt-note-input",d.suggest?"Why (optional)":"Comment",d.text??"",'data-act="save"',
|
|
72
|
-
${
|
|
73
|
-
</div>`}const
|
|
74
|
-
${h}`:""}},Ct=t=>(Array.isArray(t)?t:[]).filter(e=>e&&Number.isInteger(Number(e.id))&&typeof e.text=="string").map(e=>({...e,id:Number(e.id),rx:Number(e.rx)||0,ry:Number(e.ry)||0,route:typeof e.route=="string"&&/^\/(?![\/\\])/.test(e.route)?e.route:"/",replies:Array.isArray(e.replies)?e.replies.filter(n=>typeof n?.text=="string"):[],images:Array.isArray(e.images)?e.images.filter(n=>typeof n=="string"):[]})),ne=async()=>{try{ts(Ct((await(await L("comments")).json()).comments)),!x.hidden&&!E&&f()}catch{}},es=Mo(E,t=>A(t));let se="",_e=!1;const Rt=async()=>{if(!(document.hidden||_e)){_e=!0;try{const t=await L(`comments${se?`?since=${se}`:""}`);if(t.status!==200)return;const e=await t.json();se=e.version??"",es(e);const n=Ct(e.comments);ts(n);const s=n.filter(a=>a.route===z);if(JSON.stringify(s)===JSON.stringify(y))return;if(b.contains(document.activeElement)&&document.activeElement.matches("textarea, input")){se="",setTimeout(Rt,5e3);return}y=s,f(),D({reload:!0})}catch{}finally{_e=!1}}},vt=async()=>{try{const e=await(await L(`comments?route=${encodeURIComponent(z)}`)).json();y=Ct(e.comments),es(e)}catch{y=[]}f()};let Ke=0;const ns=t=>{Ke||(Ke=requestAnimationFrame(()=>{Ke=0;const e=t.target;if(!H||e.closest(ge)){ot.hidden=!0;return}ot.hidden=!0;const n=document.elementFromPoint(t.clientX,t.clientY);if(ot.hidden=!1,!n)return;const s=n.getBoundingClientRect();Ws.style.cssText=`left:${s.left}px;top:${s.top}px;width:${s.width}px;height:${s.height}px`,un.textContent=n.tagName.toLowerCase()+([...n.classList].find(a=>!/^(astro|svelte)-/.test(a))?"."+[...n.classList].find(a=>!/^(astro|svelte)-/.test(a)):"")+` ${Math.round(s.width)}\xD7${Math.round(s.height)}`,un.style.cssText=`left:${s.left}px;top:${Math.max(2,s.top-20)}px`}))},ss=t=>{if(!(t.key!=="Escape"||t.isComposing)){if(t.preventDefault(),T){T=null,f();return}if(d){V(),f();return}if($!==null){$=null,f();return}nt(!1)}},as=["pointerdown","mousedown","pointerup","mouseup","touchstart","touchend"],os=t=>{t.target.closest?.(ge)||t.stopPropagation()},is=t=>{if(t.target.closest(ge))return;if(t.preventDefault(),t.stopPropagation(),me){me=!1;return}if(!getSelection()?.isCollapsed)return;b.hidden=!0;const n=document.elementFromPoint(t.clientX,t.clientY);if(b.hidden=!1,!n)return;V();const s=n.getBoundingClientRect(),a=n.tagName.toLowerCase(),o=[...n.classList].filter(i=>!/^(astro|svelte|css)-/.test(i)).slice(0,2);d={selector:Vs(n),tag:a,classes:o,nth:Js({tag:a,classes:o}).indexOf(n),rx:s.width?(t.clientX-s.left)/s.width:.5,ry:s.height?(t.clientY-s.top)/s.height:.5,label:wt(n.textContent||"").slice(0,60),ctx:Gs(n),category:tn[0].id},ls.set(d,We(n)),$=null,ot.hidden=!0,f()},Va=2200,Ja=900*1024,rs=8*1024*1024,Ga=3*1024*1024,Xa=1200,Qa=1600,We=async t=>{let e=t instanceof HTMLElement?t:null;for(let a=0;e&&a<4&&e.parentElement&&e.parentElement!==document.body;a++){const o=e.getBoundingClientRect();if(o.width>=360&&o.height>=140)break;e=e.parentElement}const n=e?.getBoundingClientRect();if(!e||!n?.width||!n.height)return null;let s="";for(let a=e;a&&!s;a=a.parentElement){const o=getComputedStyle(a).backgroundColor;o&&o!=="transparent"&&!/rgba\(.*,\s*0\)$/.test(o)&&(s=o)}if(!s){const[a,o,i]=(getComputedStyle(e).color.match(/[\d.]+/g)??["0","0","0"]).map(Number);s=.299*a+.587*o+.114*i>140?"#111":"#fff"}try{const{domToWebp:a}=await import("modern-screenshot"),o=Math.min(devicePixelRatio||1,2,Xa/n.width,Qa/n.height),i=await Promise.race([a(e,{scale:o,quality:.8,timeout:4e3,backgroundColor:s,filter:l=>!(l instanceof Element&&l.closest(pn))}),new Promise(l=>setTimeout(()=>l(null),8e3))]);return i&&i.length<rs?i:null}catch{return null}},ls=new WeakMap,A=t=>{const e=document.createElement("div");e.className="dt-toast",e.textContent=t,document.body.append(e),setTimeout(()=>e.remove(),2800)},Za=t=>new Promise(e=>{const n=new FileReader;n.onload=()=>e(String(n.result)),n.readAsDataURL(t)}),to=async t=>{const e=await createImageBitmap(t),n=Math.min(1,Va/Math.max(e.width,e.height));if(n===1&&t.size<=Ja)return e.close(),Za(t);const s=document.createElement("canvas");return s.width=Math.round(e.width*n),s.height=Math.round(e.height*n),s.getContext("2d").drawImage(e,0,0,s.width,s.height),e.close(),s.toDataURL("image/jpeg",.85)},Ue=async(t,e)=>{const n=[];for(const s of t){let a;const o=Object.keys(Dt).find(i=>Dt[i]===s.type||s.name.toLowerCase().endsWith(`.${i}`));if(o){if(s.size>Ga){A(`${s.name} is over 3 MB \u2014 send a link to it instead.`);continue}const i=await new Promise((l,u)=>{const m=new FileReader;m.onload=()=>l(String(m.result).split(",")[1]),m.onerror=u,m.readAsDataURL(s)}).catch(()=>"");i?n.push(`data:${Dt[o]};name=${uo(s.name)||"document"};base64,${i}`):A(`${s.name} could not be read.`);continue}try{a=await to(s)}catch{A("That image could not be read.");continue}if(a.length>rs){A("Screenshot is too large even after shrinking.");continue}n.push(a)}if(n.length){if(!Number(e?.dataset.id)){d&&((d.images??=[]).push(...n),f());return}B.push(...n),f(),ae(".dt-note-reply-input")}},ds=t=>[...t??[]].filter(e=>e.kind==="file"&&(e.type.startsWith("image/")||Object.values(Dt).includes(e.type))).map(e=>e.getAsFile()).filter(Boolean);b.addEventListener("paste",t=>{const e=ds(t.clipboardData?.items);e.length&&(t.preventDefault(),Ue(e,t.target.closest(".dt-note")))}),b.addEventListener("dragover",t=>{t.target.closest(".dt-note")&&(t.preventDefault(),t.target.closest(".dt-note").querySelector(".dt-compose")?.setAttribute("data-drop",""))}),b.addEventListener("dragleave",t=>{t.target.closest(".dt-note")?.querySelector(".dt-compose")?.removeAttribute("data-drop")}),b.addEventListener("drop",t=>{const e=t.target.closest(".dt-note");if(!e)return;t.preventDefault(),e.querySelector(".dt-compose")?.removeAttribute("data-drop");const n=ds(t.dataTransfer?.items);n.length&&Ue(n,e)});const ae=t=>{const e=b.querySelector(t);e?.focus(),e?.setSelectionRange(e.value.length,e.value.length)},cs=()=>{ae(".dt-note-edit-input"),b.querySelector(".dt-msg .dt-compose")?.scrollIntoView({block:"nearest"})},ze=t=>{t.style.overflowY="hidden",t.style.height="auto",t.style.height=`${t.scrollHeight}px`,t.style.overflowY=t.scrollHeight>t.clientHeight?"auto":"hidden"},eo=t=>/(?:^|\s)@([^\s@]*)$/.exec(t.value.slice(0,t.selectionStart??t.value.length)),no=()=>c.client||Zt()?[]:Hs(),so=t=>{t.closest(".dt-compose").querySelector(".dt-mentions")?.remove();const n=eo(t);if(!n)return;const s=n[1].toLowerCase(),a=(c.team??[]).filter(i=>[i.name,i.nickname,i.email].some(l=>l?.toLowerCase().startsWith(s))).slice(0,5),o=no().filter(i=>i.handle.toLowerCase().startsWith(s)||!!s&&"agent".startsWith(s)||!!s&&"claude".startsWith(s)).slice(0,4);!a.length&&!o.length||t.insertAdjacentHTML("afterend",`<div class="dt-mentions" role="listbox" aria-label="Mention someone">${[...a.map(i=>`<button type="button" role="option" data-act="mention" data-handle="${p(po(i))}">${Vt(i.avatar_url,i.name||i.email)}<span class="dt-mention-who"><b>${p(i.name||i.email)}</b>${i.name?`<span>${p(i.email)}</span>`:""}</span></button>`),...o.map(i=>`<button type="button" role="option" data-act="mention" data-handle="${p(i.handle)}">${oa(i.owner)}<span class="dt-mention-who"><b>${p(i.handle)}</b><span>${i.owner?"Hands it to this agent":"The shared queue \u2014 any agent takes it"}</span></span></button>`)].map((i,l)=>i.replace('role="option"',`role="option" aria-selected="${l===0}"`)).join("")}</div>`)},us=t=>{const e=[...(c.team??[]).flatMap(s=>[s.name,s.nickname,s.email]),...Hs().map(s=>s.handle)].filter(s=>!!s).sort((s,a)=>a.length-s.length).map(s=>p(s).replace(/[.*+?^${}()|[\]\\]/g,"\\$&")),n=p(t);return e.length?n.replace(new RegExp(`@(?:${e.join("|")})(?![\\p{L}\\p{N}_.-])`,"giu"),s=>`<span class="dt-at">${s}</span>`):n},ps=(t,e)=>{const n=t.selectionStart??t.value.length,s=t.value.slice(0,n).lastIndexOf("@");t.value=`${t.value.slice(0,s)}@${e} ${t.value.slice(n)}`,t.selectionStart=t.selectionEnd=s+e.length+2,t.closest(".dt-compose")?.querySelector(".dt-mentions")?.remove(),t.dispatchEvent(new Event("input",{bubbles:!0})),t.focus()},ao=(t,e)=>{if(!t){d&&(d.category=e),f();return}K(n=>n.map(s=>s.id===t?{...s,category:e}:s),()=>L("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:t,category:e})}),"Changing the type")};wo(b,p,St);const ms=(t,e)=>{t?K(n=>n.map(s=>s.id===t?{...s,shared:e||void 0}:s),()=>L("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:t,shared:e})}),e?"Sharing with the client":"Keeping it to the team"):d&&(d.shared=e||void 0,rt(),f())};b.addEventListener("change",t=>{const e=t.target.closest(".dt-more-select");if(e){const i=e.value,l=Number(e.dataset.id)||0;e.value="",i==="team"||i==="client"?ms(l,i==="client"):i==="rm"&&confirm("Delete this thread and its replies? This cannot be undone.")?($=null,Oe(l)):i==="discard"&&(d=null,f());return}const n=t.target.closest(".dt-cat-select");if(n){ao(Number(n.dataset.id)||0,n.value);return}const s=t.target.closest(".dt-status-select");if(s){Rn(Number(s.dataset.id),s.value);return}const a=t.target.closest(".dt-for-select");if(!a)return;a.parentElement?.style.setProperty("--cat",kt(a.value));const o=Number(a.dataset.id);if(o){const i=a.value||null;K(l=>l.map(u=>u.id===o?{...u,assignee:i??void 0}:u),()=>L("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:o,assignee:i})}),"Reassigning");return}if(d){d.assignee=a.value;try{localStorage.setItem("nm-for",a.value)}catch{}rt()}}),b.addEventListener("input",t=>{const e=t.target.closest(".dt-suggest-input");if(e&&d?.suggest){d.suggest.to=e.value,rt(),ze(e);return}const n=t.target.closest(".dt-note-input, .dt-note-reply-input, .dt-note-edit-input");n&&(so(n),n.classList.contains("dt-note-input")?d&&(d.text=n.value):n.classList.contains("dt-note-edit-input")?T&&(T.text=n.value):q=n.value,rt(),n.closest(".dt-compose")?.querySelector(".dt-send")?.classList.toggle("is-ready",n.value.trim()!==""),ze(n))}),b.addEventListener("keydown",t=>{const e=t.target.closest(".dt-note-input, .dt-note-reply-input, .dt-note-edit-input");if(!e)return;const n=e.closest(".dt-compose")?.querySelector(".dt-mentions button");if(n&&(t.key==="Enter"||t.key==="Tab")&&!t.isComposing){t.preventDefault(),ps(e,n.dataset.handle);return}if(n&&t.key==="Escape"){t.stopPropagation(),n.parentElement.remove();return}t.key!=="Enter"||t.shiftKey||t.isComposing||(t.preventDefault(),e.closest(".dt-compose")?.querySelector(".dt-send")?.click())}),b.addEventListener("click",async t=>{const e=t.target.closest("button");if(!e)return;const n=e.dataset.act,s=Number(e.dataset.id);if(n==="share"){ms(s,e.dataset.v==="1");return}if(n==="prio"){const a=e.dataset.v||null;s?K(o=>o.map(i=>i.id===s?{...i,priority:a??void 0}:i),()=>L("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:s,priority:a})}),"Setting the priority"):d&&(d.priority=a??void 0,rt(),f());return}if(n==="mention"){const a=e.closest(".dt-compose")?.querySelector("textarea");a&&ps(a,e.dataset.handle);return}if(!n){if($=$===s?null:s,$!=null&&e.dataset.off){const a=y.find(i=>i.id===s);(a&&F(a))?.scrollIntoView({block:"nearest",inline:"center",behavior:"smooth"})}V(),f();return}if(n==="record"){ka(e.closest(".dt-note"));return}if(n==="speak"){Ca(e.closest(".dt-note"),e);return}if(n==="voice-write"){Oa(e);return}if(n==="voice"||n==="voice-seek"){$a(e,n==="voice-seek"?t:null);return}if(n==="attach"){const a=Object.assign(document.createElement("input"),{type:"file",accept:`image/*,.pdf,.doc,.docx,${Object.values(Dt)}`,multiple:!0}),o=e.closest(".dt-note");a.addEventListener("change",()=>{a.files?.length&&Ue([...a.files],o)}),a.click();return}if(n==="unshot"){s?T&&T.drop.push(e.dataset.img):(e.closest("[data-draft]")?d?.images??[]:B).splice(Number(e.dataset.i),1),f(),T&&cs();return}if(n==="edit"){const a=y.find(l=>l.id===s),o=e.dataset.at||null,i=o?a?.replies?.find(l=>l.at===o)?.text:a?.text;if(i===void 0)return;T={id:s,at:o,text:i,drop:[]},f(),cs();return}if(n==="edit-cancel"){T=null,f();return}if(n==="translate"){qa(s,e.dataset.at);return}if(n==="unsay"){const a=e.dataset.at;if(!confirm("Delete this reply?"))return;await K(o=>o.map(i=>i.id!==s?i:{...i,replies:(i.replies??[]).map(l=>l.at===a?{...l,text:"",deleted:!0}:l)}),()=>L("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:s,unsay:a})}),"Deleting the reply");return}if(n==="edit-save"){const a=T;if(!a)return;const o=a.text.trim();if(!o){b.querySelector(".dt-note-edit-input")?.focus();return}T=null;const i=l=>a.drop.includes(l.split("/").pop());await K(l=>l.map(u=>u.id!==a.id?u:{...u,...a.at==null?{text:o}:{replies:(u.replies??[]).map(m=>m.at===a.at?{...m,text:o}:m)},images:(u.images??[]).filter(m=>!i(m))}),()=>L("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:a.id,edit:{at:a.at,text:o},...a.drop.length?{removeImage:a.drop}:{}})}).then(l=>(l.ok||(T=a),l)),"Saving the edit");return}if(n==="cancel"){V(),f();return}if(n==="twin"){V(),$=Number(e.dataset.id),f();return}if(n==="discard"){d=null,f();return}if(n==="draft-open"){Ie(Number(e.dataset.i));return}if(n==="close"){$=null,f();return}if(n==="suggest"&&d){const a=Hn(F(d));d.suggest={from:a,to:a},f();const o=b.querySelector(".dt-suggest-input");o?.focus(),o?.select();return}if(n==="unsuggest"&&d){d.suggest=null,f();return}if(n==="save"){if(!d)return;const a=d.suggest&&d.suggest.to.trim()!==d.suggest.from?{from:d.suggest.from,to:d.suggest.to.trim()}:null,o=b.querySelector(".dt-note-input").value.trim()||(a?"Change the text":"")||(d.images?.some(Ae)?Kn:"");if(!o){b.querySelector(".dt-note-input")?.focus();return}const i=d,l=c.client?null:Ns(o,Lt()),u=ls.get(i)??We(F(i)),m={...i,route:z,text:o,suggest:a,assignee:c.client?i.assignee||c.lead||void 0:l??(i.assignee||void 0),shared:c.client?!0:i.shared===!0,stage:c.client?"new":l?"approved":i.stage??(j(i.assignee)?"approved":"new"),breakpoint:Te(),browser:Ys(),device:E?gs:"",viewport:{w:innerWidth,h:innerHeight},logs:bo(),host:location.host},r={...i,id:-Date.now(),text:o,route:z,status:"open",note:"",doneBy:null,breakpoint:m.breakpoint,replies:[],images:[],createdAt:new Date().toISOString(),...a?{suggest:a}:{},by:c.me?.email,byName:c.me?.name};y=[...y,r],d=null,f();const h=await u,g=await L("comments",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({...m,...h?{before:h}:{}})});if(!g.ok){y=y.filter(M=>M!==r),d=i,f(),A(`Comment was not saved (${g.status}).`);return}const w=Ct([await g.json().catch(()=>null)])[0];y=y.map(M=>M===r&&w?w:M),f(),oe();return}if(n==="reply"){const a=b.querySelector(".dt-note-reply-input"),o=a.value.trim()||(B.some(Ae)?Kn:"");if(!o){a.focus();return}const i=B;q="",B=[];const l=y,u=c.client?null:Ns(o,Lt()),m=y.find(w=>w.id===s),r=u&&m&&(u!==m.assignee||U(m)!=="approved"||m.status==="done")?{assignee:u,stage:"approved",...m.status==="done"?{status:"open",doneBy:null}:{}}:{};y=y.map(w=>w.id===s?{...w,...r,replies:[...w.replies??[],{author:"you",text:o,at:new Date().toISOString(),by:c.me?.email}]}:w),f();const h=await L("comments",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({id:s,reply:o,images:i,...r})});if(!h.ok){y=l,q=o,B=i,f(),A(`Reply was not sent (${h.status}).`);return}const g=Ct([await h.json().catch(()=>null)])[0];g&&(y=y.map(w=>w.id===g.id?g:w),f()),oe();return}if(n==="hand"){na(s,e.dataset.v);return}if(n==="sendback"){await ht(s,!1),ae(".dt-note-reply-input");return}if(n==="accept"){Rn(s,"accepted");return}e.classList.contains("dt-step-act")||($=null),n==="rm"?await Oe(s):await ht(s,n==="done")});let gs="";const D=t=>{it.hidden||_t.contentWindow?.postMessage({dt:!0,...t},location.origin)},oo=()=>({notes:H,grid:!Pt.hidden,inspect:Y,resolved:J,...hs.look()});addEventListener("message",t=>{if(t.origin!==location.origin||!t.data?.dt)return;const e=t.data;if(!E&&t.source===_t.contentWindow){if(e.key){ws(e.key[0],e.key[1])?.run();return}if(e.closeMenus){Tt();return}if(e.drafts){Re=e.drafts,Nt(lt());return}}if(E&&typeof e.openDraft=="number"){Ie(e.openDraft);return}if(E&&typeof e.dropDraft=="number"){Xn(e.dropDraft);return}if(E&&typeof e.device=="string"&&(gs=e.device),E&&e.scrollbar&&document.documentElement.classList.toggle("dt-sb-classic",e.scrollbar==="classic"),e.hello&&t.source===_t.contentWindow){D(oo());return}typeof e.notes=="boolean"&&e.notes!==H&&nt(e.notes,!1),typeof e.open=="number"&&De(e.open),typeof e.grid=="boolean"&&e.grid===Pt.hidden&&pe(e.grid),typeof e.inspect=="string"&&e.inspect!==Y&&jt(e.inspect),typeof e.resolved=="boolean"&&e.resolved!==J&&Fe(e.resolved),e.reload&&(vt(),ne())});const oe=async()=>{await vt(),ne(),D({reload:!0}),E&&parent.postMessage({dt:!0,reload:!0},location.origin)},nt=(t,e=!0)=>{if(H=t,cn.setAttribute("aria-pressed",String(t)),t?!E&&x.hidden&&localStorage.getItem("dt-history")!=="0"&&(x.hidden=!1,Ft.setAttribute("aria-pressed","true")):(x.hidden=!0,Ft.setAttribute("aria-pressed","false")),O(gn,t?"1":"0"),D({notes:t}),E&&e&&parent.postMessage({dt:!0,notes:t},location.origin),b.hidden=!t||!it.hidden,document.documentElement.classList.toggle("dt-noting",t),t){jt(""),document.addEventListener("click",is,!0);for(const n of as)document.addEventListener(n,os,!0);document.addEventListener("keydown",ss),document.addEventListener("mousemove",ns),addEventListener("scroll",et,!0),addEventListener("resize",et),Qn.observe(document.body,{childList:!0,subtree:!0,characterData:!0}),Zn.observe(document.body),vt()}else{V(),$=null,document.removeEventListener("click",is,!0);for(const n of as)document.removeEventListener(n,os,!0);document.removeEventListener("keydown",ss),document.removeEventListener("mousemove",ns),ot.hidden=!0,removeEventListener("scroll",et,!0),removeEventListener("resize",et),Qn.disconnect(),Zn.disconnect(),b.innerHTML=""}},{pickBp:fs,...hs}=Eo({cfg:c,inFrame:E,persist:O,frame:it,frameEl:_t,devicesMenu:ve,bpBtns:be,notesOverlay:b,WIDE:ce,bpOf:en,currentBp:Te,deviceById:Bs,notesOn:()=>H,filter:()=>Ee,filterTo:t=>{Ee=t},dropFrameDrafts:()=>{Re=[]},putAway:()=>{$=null,V()},tellFrame:D,syncBpButtons:hn,render:()=>f(),reread:()=>{H?vt():f()}}),bs="dt-studio",ys=t=>{ye.setAttribute("aria-pressed",String(t)),document.documentElement.classList.toggle("dt-no-studio",!t),O(bs,t?"1":"0")};ye.addEventListener("click",()=>ys(ye.getAttribute("aria-pressed")!=="true")),ys(localStorage.getItem(bs)!=="0"),cn.addEventListener("click",()=>nt(!H));const $t=document.querySelector(".devtools"),Ot=document.querySelector(".dt-tab"),vs=t=>{$t.toggleAttribute("data-collapsed",t),Ot.toggleAttribute("data-collapsed",t),Ot.setAttribute("aria-expanded",String(!t)),Ot.setAttribute("aria-label",t?"Show the bar":"Hide the bar");for(const e of $t.querySelectorAll(".dt-group"))e.inert=t;t&&Tt(),O("dt-collapsed",t?"1":"0")};Ot.addEventListener("click",()=>vs(!$t.hasAttribute("data-collapsed")));const Ye=document.querySelector(".dt-keys"),W=t=>()=>$t.querySelector(t)?.click(),$s=t=>()=>{const e=[...document.querySelectorAll(".dt-pages a")];e[e.findIndex(n=>n.hasAttribute("aria-current"))+t]?.click()},ie=[{group:"Comments",code:"KeyC",hint:"C",label:"Comment mode",el:".dt-notes-btn",run:W(".dt-notes-btn")},{group:"Comments",code:"KeyC",shift:!0,hint:"\u21E7C",label:"Comments panel",el:".dt-history-btn",run:W(".dt-history-btn")},{group:"Comments",code:"KeyR",hint:"R",label:"Show resolved",el:".dt-resolved-btn",run:W(".dt-resolved-btn")},{group:"Inspect",code:"KeyG",hint:"G",label:"Grid",el:".dt-grid-btn",run:W(".dt-grid-btn")},{group:"Inspect",code:"KeyP",hint:"P",label:"Spacing",el:".dt-pad-btn",run:W(".dt-pad-btn")},{group:"Inspect",code:"KeyS",hint:"S",label:"Size",el:".dt-size-btn",run:W(".dt-size-btn")},{group:"Inspect",code:"KeyT",hint:"T",label:"Typography",el:".dt-type-btn",run:W(".dt-type-btn")},{group:"Inspect",code:"KeyO",hint:"O",label:"Color",el:".dt-color-btn",run:W(".dt-color-btn")},{group:"Inspect",code:"KeyB",hint:"B",label:"Border & radius",el:".dt-border-btn",run:W(".dt-border-btn")},...c.sanity?[{group:"Inspect",code:"KeyE",hint:"E",label:"Sanity overlay",el:".dt-studio-btn",run:W(".dt-studio-btn")}]:[],...be.slice(0,9).map((t,e)=>({group:"Breakpoints",code:`Digit${e+1}`,hint:String(e+1),label:t.dataset.tip??t.title,el:`.dt-bp[data-bp="${t.dataset.bp}"]`,run:()=>t.click()})),{group:"View",code:"KeyD",hint:"D",label:"Devices",run:()=>{ve.open=!ve.open}},{group:"View",code:"BracketLeft",hint:"[",label:"Previous page",run:$s(-1)},{group:"View",code:"BracketRight",hint:"]",label:"Next page",run:$s(1)},{group:"View",code:"Backslash",hint:"\\",label:"Hide the bar",run:()=>Ot.click()},{group:"View",code:"Slash",shift:!0,hint:"?",label:"This list",el:".dt-keys summary",run:()=>{Ye.open=!Ye.open}}].filter(t=>!c.client||t.group!=="Inspect"),ws=(t,e)=>ie.find(n=>n.code===t&&!n.shift==!e),io=t=>t instanceof HTMLElement&&(t.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName)||!!t.closest('[role="menu"], [role="listbox"], [role="dialog"][aria-modal="true"], [role="combobox"]'));if(c.shortcuts){for(const e of ie){const n=e.el&&$t.querySelector(e.el);n&&(n.dataset.tip=`${n.dataset.tip??e.label} \xB7 ${e.hint}`,n.setAttribute("aria-keyshortcuts",e.hint.startsWith("\u21E7")?`Shift+${e.hint.slice(1)}`:e.hint))}const t=(e,n)=>`<div class="dt-key-row"><span>${p(e)}</span><kbd>${p(n)}</kbd></div>`;if(Ye.querySelector(".dt-keys-menu").innerHTML='<p class="dt-menu-note">One key, no modifier, in any keyboard layout. Not while you type.</p>'+[...new Set(ie.map(e=>e.group))].map(e=>`<p class="dt-devices-group">${e}</p>`+ie.filter(n=>n.group===e).map(n=>t(n.label,n.hint)).join("")).join("")+'<p class="dt-devices-group">In a comment</p>'+t("Send","Enter")+t("New line","\u21E7Enter")+t("Close, cancel, back out","Esc"),document.addEventListener("keydown",e=>{if(e.repeat||e.isComposing||e.metaKey||e.ctrlKey||e.altKey||e.defaultPrevented||io(e.target))return;const n=ws(e.code,e.shiftKey);n&&(e.preventDefault(),E?parent.postMessage({dt:!0,key:[e.code,e.shiftKey]},location.origin):n.run())}),E){const e=()=>parent.postMessage({dt:!0,closeMenus:!0},location.origin);document.addEventListener("pointerdown",e,!0),document.addEventListener("keydown",n=>{n.key==="Escape"&&e()})}}if(!E){vs(localStorage.getItem("dt-collapsed")==="1"),requestAnimationFrame(()=>requestAnimationFrame(()=>$t.setAttribute("data-ready",""))),hs.restore(),pe(localStorage.getItem(sn)==="1");const t=localStorage.getItem(ln);t&&t in fe&&jt(t),nt(localStorage.getItem(gn)==="1")}const Es=()=>{try{const t=JSON.parse(localStorage.getItem(gt)||"null");N=(t?.parked??[]).filter(e=>Kt(e)),t?.draft&&document.querySelector(t.draft.selector)?(d=t.draft,!H&&!E&&nt(!0)):Kt(t?.draft)&&N.push(t.draft),t?.reply?.text&&(q=t.reply.text,Mt=$=t.reply.for??null),(d||N.length||q)&&f()}catch{localStorage.removeItem(gt)}};Es();const Ss=()=>setTimeout(()=>{const t=ue(location.pathname);t!==z&&(clearTimeout(Wt),Se(),z=t,gt=fn(),d=null,N=[],q="",Mt=null,$=null,T=null,y=[],on(),Es(),vt())});for(const t of["pushState","replaceState"]){const e=window.history[t];window.history[t]=function(...n){e.apply(this,n),Ss()}}addEventListener("popstate",Ss),H||vt(),ne().then(Pe.resume),document.addEventListener("visibilitychange",()=>{document.hidden||Rt()}),addEventListener("focus",Rt),addEventListener("notemend:changed",()=>{E||Rt()});let ro=0;E||setInterval(()=>{(!fo.live||++ro%6===0)&&Rt()},2e4),E&&parent.postMessage({dt:!0,hello:!0},location.origin)}export{Ko as run};
|
|
70
|
+
${Wn("dt-note-input",d.suggest?"Why (optional)":"Comment",d.text??"",'data-act="save"',jn(d.images))}
|
|
71
|
+
${Rn(d.priority,d.category,void 0,d.assignee??"")}
|
|
72
|
+
</div>`}const o=new Map([...b.querySelectorAll(".dt-note[data-id] .dt-note-thread")].map(r=>[r.closest(".dt-note").dataset.id,{top:r.scrollTop,end:r.scrollTop+r.clientHeight>=r.scrollHeight-4}])),l=new Set([...b.querySelectorAll("[data-msg]")].map(r=>r.dataset.msg)),u=b.contains(document.activeElement)&&document.activeElement.matches(".dt-note-reply-input");b.innerHTML=s,u&&ae(".dt-note-reply-input");for(const r of b.querySelectorAll(".dt-note[data-id] .dt-note-thread")){const h=r.closest(".dt-note").dataset.id,g=o.get(h);if(!g)continue;const w=[...r.querySelectorAll("[data-msg]")].filter(L=>!l.has(L.dataset.msg));for(const L of w)L.classList.add("dt-msg--new");r.scrollTop=g.end&&w.length?r.scrollHeight:g.top}for(const r of b.querySelectorAll(".dt-note")){const h=r.getBoundingClientRect();h.bottom>innerHeight-8&&(r.dataset.flip="1"),h.right>innerWidth-8&&(r.dataset.flipx="1")}Ht(n),Me($n()),et();for(const r of b.querySelectorAll(".dt-note-input, .dt-note-reply-input, .dt-note-edit-input"))Ve(r);const m=b.querySelector(".dt-note-input");m&&(m.focus(),m.setSelectionRange(m.value.length,m.value.length))},Pa=()=>{let t=!1;const e=[];for(const n of b.querySelectorAll(".dt-pin[data-id], .dt-note[data-id]")){if(n.classList.contains("dt-note--orphan"))continue;const s=y.find(i=>i.id===Number(n.dataset.id)),a=s&&_(s);e.push([n,a]),a&&vn(a.el)&&(t=!0)}for(const n of b.querySelectorAll("[data-draft], [data-parked]")){if(n.classList.contains("dt-note--orphan"))continue;const s=n.dataset.parked?H[Number(n.dataset.parked)]:d;e.push([n,s?_(s):null])}for(const[n,s]of e){if(!s){n.style.visibility="hidden";continue}n.style.visibility="",n.style.left=`${s.x}px`,n.style.top=`${s.y}px`,n.matches(".dt-pin[data-id]")&&(s.off?n.dataset.off=s.off:delete n.dataset.off)}if(!zt.length&&(d||$!=null)){const n=$n();n&&vn(n)&&Me(n)}t&&et()},Fa=t=>y.filter(e=>tt(e)===tt(t)).findIndex(e=>e.id===t.id)+1,Ht=t=>{if(!x.hidden&&(x.innerHTML=Eo({bp:t,notes:y,breakpoints:pt,bandOfNote:tt,orphan:e=>!_(e),whoseAgent:dt,statusTools:Vn,showResolved:J,drafts:it.hidden?Un():Re,checks:S?0:je.toCheck().length,marker:_a,find:N,forMe:ja,forAgent:e=>!!V(e)&&B(e)!=="done",unread:An}),yt)){const e=x.querySelector("[data-hist-q]");e?.focus(),e?.setSelectionRange(yt.at,yt.at),yt=null}};let yt=null;const ja=t=>{if(B(t)==="done"||!c.me)return!1;if(t.assignee===c.me.email||B(t)==="claude"||G(t)==="review"&&t.assignee!==c.me.email)return!0;const e=(c.me.name||c.me.email).split(/[\s@]/)[0].toLowerCase();return Bt(t).some(n=>n.text.toLowerCase().includes("@"+e))},_a=t=>{if(B(t)==="done")return'<span class="dt-hist-n"></span>';const n=ke[V(t)??""];if(n)return`<span class="dt-hist-face dt-hist-face--agent" style="--step-c:${n}">${ut(10)}</span>`;const s=Mn(t);return s?`<span class="dt-hist-face" style="--ring:${Ae.find(a=>a[0]===Gt(t))[2]};--hue:${kn(t.by||t.byName||"")}">${s}</span>`:`<span class="dt-hist-n" style="--cat:${le(t.category).color}"></span>`},De=t=>x.toggleAttribute("data-collapsed",t);x.addEventListener("input",t=>{const e=t.target.closest("[data-hist-q]");e&&(N.q=e.value,yt={at:e.selectionStart??e.value.length},Ht(lt()))}),x.addEventListener("click",async t=>{const e=t.target.closest("[data-refresh]");if(e){e.dataset.spin="1",await oe(),setTimeout(()=>delete e.dataset.spin,500);return}if(x.hasAttribute("data-collapsed")&&t.target.closest(".dt-hist-head")){De(!1);return}if(t.target.closest("[data-fold]")){De(!x.hasAttribute("data-collapsed"));return}const n=t.target.closest(".dt-hist-bands [data-bp]");if(n){fs(n.dataset.bp);return}const s=t.target.closest("[data-hist-filter], [data-hist-view], [data-hist-sort], [data-hist-clear]");if(s){s.dataset.histView?(N.view=s.dataset.histView,q("dt-view",N.view),N.menu=!1):s.dataset.histSort?(N.sort=s.dataset.histSort,q("dt-sort",N.sort),N.menu=!1):s.hasAttribute("data-hist-clear")?(N.q="",yt={at:0}):N.menu=!N.menu,Ht(lt());return}N.menu&&!t.target.closest(".dt-hist-menu")&&(N.menu=!1,Ht(lt()));const a=t.target.closest("[data-draft-go], [data-draft-rm]");if(a){const r=a.dataset.draftRm!==void 0,h=Number(r?a.dataset.draftRm:a.dataset.draftGo);it.hidden?r?Jn(h):Fe(h):R(r?{dropDraft:h}:{openDraft:h});return}const i=t.target.closest("[data-unmark]");if(i){t.stopPropagation(),await bt(Number(i.dataset.unmark),!1);return}const o=t.target.closest(".dt-hist-tools [data-act]");if(o){await bt(Number(o.dataset.id),o.dataset.act==="done");return}const l=t.target.closest("[data-rm]");if(l){$=null,await Be(Number(l.dataset.rm));return}if(t.target.closest("[data-review]")){je.start();return}if(t.target.closest("[data-resolved]")){Ke(!J);return}const u=t.target.closest("[data-go]");if(!u)return;const m=Number(u.dataset.go);if(!it.hidden){R({open:m});return}Pe(m)});const Pe=t=>{$=t,j(),f();const e=y.find(s=>s.id===t),n=e&&_(e);n?scrollTo({top:scrollY+n.y-innerHeight/2,behavior:"smooth"}):e&&Q(e)?.scrollIntoView({block:"center",behavior:"smooth"}),matchMedia("(prefers-reduced-motion: reduce)").matches||b.querySelector(`.dt-pin[data-id="${t}"]`)?.animate([{transform:"scale(1)"},{transform:"scale(1.5)"},{transform:"scale(1)"}],400)},Fe=t=>{const[e]=H.splice(t,1);if(!e)return;j(),d=e,$=null;const n=_(e);n&&(n.y<0||n.y>innerHeight)&&scrollTo({top:scrollY+n.y-innerHeight/3,behavior:"instant"}),f()},Jn=t=>{H.splice(t,1),f()},je=So({inFrame:S,everything:()=>vt,route:()=>P,settle:bt,keepIn:gn,toast:t=>C(t),open:t=>{if(A||nt(!0),tt(t)!==lt()){fs(tt(t));for(const e of[600,1500])setTimeout(()=>R({open:t.id}),e)}else Pe(t.id)}}),Ka=t=>{x.hidden=!t,jt.setAttribute("aria-pressed",String(t)),q("dt-history",t?"1":"0"),f()},_e=document.querySelector(".dt-resolved-btn"),Ke=t=>{J=t,_e.setAttribute("aria-pressed",String(t)),q("dt-resolved",t?"1":"0"),R({resolved:t}),f(),ne()};_e.addEventListener("click",()=>Ke(!J)),_e.setAttribute("aria-pressed",String(J)),jt.addEventListener("click",()=>{const t=x.hidden===!0;t&&!A&&nt(!0),t&&De(!1),Ka(t)});const et=()=>{we||!A||(we=requestAnimationFrame(()=>{we=0,Pa()}))},Qn=`${$e}, .dt-notes-hi, .dt-pad-overlay, .dt-grid-overlay, .dt-review, .dt-field-menu, .dt-toast`,Wa=t=>{if((t.target instanceof Element?t.target:t.target.parentElement)?.closest(Qn))return!0;const n=[...t.addedNodes,...t.removedNodes];return n.length>0&&n.every(s=>s instanceof Element&&s.matches(Qn))},Zn=new MutationObserver(t=>{t.every(Wa)||(yn(),et())}),ts=new ResizeObserver(()=>et());let vt=[];const es=t=>{vt=t;const e=()=>({new:0,progress:0,review:0,waiting:0,accepted:0,done:0}),n={};for(const l of t){const u=B(l),m=V(l),r=u==="done"?"done":u==="claude"?"review":m&&Xt[m]||Gt(l),h=n[l.route??""]??={...e(),bands:{}};h[r]++;const g=tt(l);(h.bands[g]??=e())[r]++}const s=["new","progress","review","waiting","accepted","done"],a={new:"new",progress:"in progress",review:"to review",waiting:"waiting",accepted:"accepted",done:"resolved"},i=l=>s.map(u=>[u,u==="done"&&!J?0:l[u]]),o=l=>i(l).reduce((u,[,m])=>u+m,0);for(const l of document.querySelectorAll(".dt-pages a")){const u=l.querySelector(".dt-pages-n");if(!u)continue;const m=n[new URL(l.href).pathname.replace(/\/+$/,"")||"/"];for(const g of pt){const w=m?.bands[g.id];for(const[L,z]of i(w??e())){const Y=u.querySelector(`[data-bp="${g.id}"][data-state="${L}"]`);Y.hidden=!z,z&&(Y.querySelector("i").textContent=String(z),Y.title=`${g.label}: ${z} ${a[L]}`)}}const r=m?o(m):0;u.hidden=!r;const h=m?pt.filter(g=>m.bands[g.id]&&o(m.bands[g.id])).map(g=>`${g.label} ${o(m.bands[g.id])}`).join(" \xB7 "):"";u.title=r?`${s.filter(g=>m[g]).map(g=>`${m[g]} ${a[g]}`).join(" \xB7 ")}
|
|
73
|
+
${h}`:""}},Nt=t=>(Array.isArray(t)?t:[]).filter(e=>e&&Number.isInteger(Number(e.id))&&typeof e.text=="string").map(e=>({...e,id:Number(e.id),rx:Number(e.rx)||0,ry:Number(e.ry)||0,route:typeof e.route=="string"&&/^\/(?![\/\\])/.test(e.route)?e.route:"/",replies:Array.isArray(e.replies)?e.replies.filter(n=>typeof n?.text=="string"):[],images:Array.isArray(e.images)?e.images.filter(n=>typeof n=="string"):[]})),ne=async()=>{try{es(Nt((await(await ot("comments")).json()).comments)),!x.hidden&&!S&&f()}catch{}},ns=To(S,t=>C(t));let se="",We=!1;const Ct=async()=>{if(!(document.hidden||We)){We=!0;try{const t=await ot(`comments${se?`?since=${se}`:""}`);if(t.status!==200)return;const e=await t.json();se=e.version??"",ns(e);const n=Nt(e.comments);es(n);const s=n.filter(a=>a.route===P);if(JSON.stringify(s)===JSON.stringify(y))return;if(b.contains(document.activeElement)&&document.activeElement.matches("textarea, input")){se="",setTimeout(Ct,5e3);return}y=s,f(),R({reload:!0})}catch{}finally{We=!1}}},$t=async()=>{const t=P;let e=[];try{const s=await(await ot(`comments?route=${encodeURIComponent(t)}`)).json();e=Nt(s.comments),ns(s)}catch{}t===P&&(y=e,f())};let Ue=0;const ss=t=>{Ue||(Ue=requestAnimationFrame(()=>{Ue=0;const e=t.target;if(!A||e.closest(me)){mt.hidden=!0;return}const n=document.elementFromPoint(t.clientX,t.clientY);if(mt.hidden=!1,!n)return;const s=n.getBoundingClientRect();Ws.style.cssText=`left:${s.left}px;top:${s.top}px;width:${s.width}px;height:${s.height}px`,mn.textContent=n.tagName.toLowerCase()+([...n.classList].find(a=>!/^(astro|svelte)-/.test(a))?"."+[...n.classList].find(a=>!/^(astro|svelte)-/.test(a)):"")+` ${Math.round(s.width)}\xD7${Math.round(s.height)}`,mn.style.cssText=`left:${s.left}px;top:${Math.max(2,s.top-20)}px`}))},as=t=>{if(!(t.key!=="Escape"||t.isComposing)){if(t.preventDefault(),T){T=null,f();return}if(d){j(),f();return}if($!==null){$=null,f();return}nt(!1)}},os=["pointerdown","mousedown","pointerup","mouseup","touchstart","touchend"],is=t=>{t.target.closest?.(me)||t.stopPropagation()},rs=t=>{if(t.target.closest(me))return;if(t.preventDefault(),t.stopPropagation(),pe){pe=!1;return}if(!getSelection()?.isCollapsed)return;b.hidden=!0;const n=document.elementFromPoint(t.clientX,t.clientY);if(b.hidden=!1,!n)return;j();const s=n.getBoundingClientRect(),a=n.tagName.toLowerCase(),i=[...n.classList].filter(o=>!/^(astro|svelte|css)-/.test(o)).slice(0,2);d={selector:Vs(n),tag:a,classes:i,nth:Gs({tag:a,classes:i}).indexOf(n),rx:s.width?(t.clientX-s.left)/s.width:.5,ry:s.height?(t.clientY-s.top)/s.height:.5,label:It(n.textContent||"").slice(0,60),ctx:Xs(n),category:nn[0].id},ds.set(d,Xa().then(()=>ze(n))),$=null,mt.hidden=!0,f()},Ua=2200,za=900*1024,ls=8*1024*1024,Ya=3*1024*1024,Va=1200,Ga=1600,ze=async t=>{let e=t instanceof HTMLElement?t:null;for(let a=0;e&&a<4&&e.parentElement&&e.parentElement!==document.body;a++){const i=e.getBoundingClientRect();if(i.width>=360&&i.height>=140)break;e=e.parentElement}const n=e?.getBoundingClientRect();if(!e||!n?.width||!n.height)return null;let s="";for(let a=e;a&&!s;a=a.parentElement){const i=getComputedStyle(a).backgroundColor;i&&i!=="transparent"&&!/rgba\(.*,\s*0\)$/.test(i)&&(s=i)}if(!s){const[a,i,o]=(getComputedStyle(e).color.match(/[\d.]+/g)??["0","0","0"]).map(Number);s=.299*a+.587*i+.114*o>140?"#111":"#fff"}try{const{domToWebp:a}=await import("modern-screenshot"),i=Math.min(1,Va/n.width,Ga/n.height),o=await Promise.race([a(e,{scale:i,quality:.8,timeout:4e3,backgroundColor:s,filter:l=>!(l instanceof Element&&l.closest($e))}),new Promise(l=>setTimeout(()=>l(null),8e3))]);return o&&o.length<ls?o:null}catch{return null}},ds=new WeakMap,Xa=()=>new Promise(t=>requestAnimationFrame(()=>"requestIdleCallback"in window?requestIdleCallback(()=>t(),{timeout:1500}):setTimeout(t,50))),C=t=>{const e=document.createElement("div");e.className="dt-toast",e.textContent=t,document.body.append(e),setTimeout(()=>e.remove(),2800)},Ja=t=>new Promise(e=>{const n=new FileReader;n.onload=()=>e(String(n.result)),n.readAsDataURL(t)}),Qa=async t=>{const e=await createImageBitmap(t),n=Math.min(1,Ua/Math.max(e.width,e.height));if(n===1&&t.size<=za)return e.close(),Ja(t);const s=document.createElement("canvas");return s.width=Math.round(e.width*n),s.height=Math.round(e.height*n),s.getContext("2d").drawImage(e,0,0,s.width,s.height),e.close(),s.toDataURL("image/jpeg",.85)},Ye=async(t,e)=>{const n=[];for(const s of t){let a;const i=Object.keys(Rt).find(o=>Rt[o]===s.type||s.name.toLowerCase().endsWith(`.${o}`));if(i){if(s.size>Ya){C(`${s.name} is over 3 MB \u2014 send a link to it instead.`);continue}const o=await new Promise((l,u)=>{const m=new FileReader;m.onload=()=>l(String(m.result).split(",")[1]),m.onerror=u,m.readAsDataURL(s)}).catch(()=>"");o?n.push(`data:${Rt[i]};name=${co(s.name)||"document"};base64,${o}`):C(`${s.name} could not be read.`);continue}try{a=await Qa(s)}catch{C("That image could not be read.");continue}if(a.length>ls){C("Screenshot is too large even after shrinking.");continue}n.push(a)}if(n.length){if(!Number(e?.dataset.id)){d&&((d.images??=[]).push(...n),f());return}F.push(...n),f(),ae(".dt-note-reply-input")}},cs=t=>[...t??[]].filter(e=>e.kind==="file"&&(e.type.startsWith("image/")||Object.values(Rt).includes(e.type))).map(e=>e.getAsFile()).filter(Boolean);b.addEventListener("paste",t=>{const e=cs(t.clipboardData?.items);e.length&&(t.preventDefault(),Ye(e,t.target.closest(".dt-note")))}),b.addEventListener("dragover",t=>{t.target.closest(".dt-note")&&(t.preventDefault(),t.target.closest(".dt-note").querySelector(".dt-compose")?.setAttribute("data-drop",""))}),b.addEventListener("dragleave",t=>{t.target.closest(".dt-note")?.querySelector(".dt-compose")?.removeAttribute("data-drop")}),b.addEventListener("drop",t=>{const e=t.target.closest(".dt-note");if(!e)return;t.preventDefault(),e.querySelector(".dt-compose")?.removeAttribute("data-drop");const n=cs(t.dataTransfer?.items);n.length&&Ye(n,e)});const ae=t=>{const e=b.querySelector(t);e?.focus(),e?.setSelectionRange(e.value.length,e.value.length)},us=()=>{ae(".dt-note-edit-input"),b.querySelector(".dt-msg .dt-compose")?.scrollIntoView({block:"nearest"})},Ve=t=>{t.style.overflowY="hidden",t.style.height="auto",t.style.height=`${t.scrollHeight}px`,t.style.overflowY=t.scrollHeight>t.clientHeight?"auto":"hidden"},Za=t=>/(?:^|\s)@([^\s@]*)$/.exec(t.value.slice(0,t.selectionStart??t.value.length)),to=()=>c.client||Qt()?[]:Hs(),eo=t=>{t.closest(".dt-compose").querySelector(".dt-mentions")?.remove();const n=Za(t);if(!n)return;const s=n[1].toLowerCase(),a=(c.team??[]).filter(o=>[o.name,o.nickname,o.email].some(l=>l?.toLowerCase().startsWith(s))).slice(0,5),i=to().filter(o=>o.handle.toLowerCase().startsWith(s)||!!s&&"agent".startsWith(s)||!!s&&"claude".startsWith(s)).slice(0,4);!a.length&&!i.length||t.insertAdjacentHTML("afterend",`<div class="dt-mentions" role="listbox" aria-label="Mention someone">${[...a.map(o=>`<button type="button" role="option" data-act="mention" data-handle="${p(uo(o))}">${Vt(o.avatar_url,o.name||o.email)}<span class="dt-mention-who"><b>${p(o.name||o.email)}</b>${o.name?`<span>${p(o.email)}</span>`:""}</span></button>`),...i.map(o=>`<button type="button" role="option" data-act="mention" data-handle="${p(o.handle)}">${ia(o.owner)}<span class="dt-mention-who"><b>${p(o.handle)}</b><span>${o.owner?"Hands it to this agent":"The shared queue \u2014 any agent takes it"}</span></span></button>`)].map((o,l)=>o.replace('role="option"',`role="option" aria-selected="${l===0}"`)).join("")}</div>`)},ps=t=>{const e=[...(c.team??[]).flatMap(s=>[s.name,s.nickname,s.email]),...Hs().map(s=>s.handle)].filter(s=>!!s).sort((s,a)=>a.length-s.length).map(s=>p(s).replace(/[.*+?^${}()|[\]\\]/g,"\\$&")),n=p(t);return e.length?n.replace(new RegExp(`@(?:${e.join("|")})(?![\\p{L}\\p{N}_.-])`,"giu"),s=>`<span class="dt-at">${s}</span>`):n},ms=(t,e)=>{const n=t.selectionStart??t.value.length,s=t.value.slice(0,n).lastIndexOf("@");t.value=`${t.value.slice(0,s)}@${e} ${t.value.slice(n)}`,t.selectionStart=t.selectionEnd=s+e.length+2,t.closest(".dt-compose")?.querySelector(".dt-mentions")?.remove(),t.dispatchEvent(new Event("input",{bubbles:!0})),t.focus()},no=(t,e)=>{if(!t){d&&(d.category=e),f();return}W(n=>n.map(s=>s.id===t?{...s,category:e}:s),()=>D({id:t,category:e}),"Changing the type")};$o(b,p,Tt);const so=(t,e)=>{t?W(n=>n.map(s=>s.id===t?{...s,shared:e||void 0}:s),()=>D({id:t,shared:e}),e?"Sharing with the client":"Keeping it to the team"):d&&(d.shared=e||void 0,rt(),f())};b.addEventListener("change",t=>{const e=t.target.closest(".dt-more-select");if(e){const o=e.value,l=Number(e.dataset.id)||0;e.value="",o==="team"||o==="client"?so(l,o==="client"):o==="rm"&&confirm("Delete this thread and its replies? This cannot be undone.")?($=null,Be(l)):o==="discard"&&(d=null,f());return}const n=t.target.closest(".dt-cat-select");if(n){no(Number(n.dataset.id)||0,n.value);return}const s=t.target.closest(".dt-status-select");if(s){On(Number(s.dataset.id),s.value);return}const a=t.target.closest(".dt-for-select");if(!a)return;a.parentElement?.style.setProperty("--cat",kt(a.value));const i=Number(a.dataset.id);if(i){const o=a.value||null;W(l=>l.map(u=>u.id===i?{...u,assignee:o??void 0}:u),()=>D({id:i,assignee:o}),"Reassigning");return}d&&(d.assignee=a.value,M.setItem("nm-for",a.value),rt())}),b.addEventListener("input",t=>{const e=t.target.closest(".dt-suggest-input");if(e&&d?.suggest){d.suggest.to=e.value,rt(),Ve(e);return}const n=t.target.closest(".dt-note-input, .dt-note-reply-input, .dt-note-edit-input");n&&(eo(n),n.classList.contains("dt-note-input")?d&&(d.text=n.value):n.classList.contains("dt-note-edit-input")?T&&(T.text=n.value):O=n.value,rt(),n.closest(".dt-compose")?.querySelector(".dt-send")?.classList.toggle("is-ready",n.value.trim()!==""),Ve(n))}),b.addEventListener("keydown",t=>{const e=t.target.closest(".dt-note-input, .dt-note-reply-input, .dt-note-edit-input");if(!e)return;const n=e.closest(".dt-compose")?.querySelector(".dt-mentions button");if(n&&(t.key==="Enter"||t.key==="Tab")&&!t.isComposing){t.preventDefault(),ms(e,n.dataset.handle);return}if(n&&t.key==="Escape"){t.stopPropagation(),n.parentElement.remove();return}t.key!=="Enter"||t.shiftKey||t.isComposing||(t.preventDefault(),e.closest(".dt-compose")?.querySelector(".dt-send")?.click())}),b.addEventListener("click",async t=>{const e=t.target.closest("button");if(!e)return;const n=e.dataset.act,s=Number(e.dataset.id);if(n==="prio"){const a=e.dataset.v||null;s?W(i=>i.map(o=>o.id===s?{...o,priority:a??void 0}:o),()=>D({id:s,priority:a}),"Setting the priority"):d&&(d.priority=a??void 0,rt(),f());return}if(n==="mention"){const a=e.closest(".dt-compose")?.querySelector("textarea");a&&ms(a,e.dataset.handle);return}if(!n){if($=$===s?null:s,$!=null&&e.dataset.off){const a=y.find(o=>o.id===s);(a&&Q(a))?.scrollIntoView({block:"nearest",inline:"center",behavior:"smooth"})}j(),f();return}if(n==="speak"){xa(e.closest(".dt-note"),e);return}if(n==="voice-write"){Ha(e);return}if(n==="voice"||n==="voice-seek"){$a(e,n==="voice-seek"?t:null);return}if(n==="attach"){const a=Object.assign(document.createElement("input"),{type:"file",accept:`image/*,.pdf,.doc,.docx,${Object.values(Rt)}`,multiple:!0}),i=e.closest(".dt-note");a.addEventListener("change",()=>{a.files?.length&&Ye([...a.files],i)}),a.click();return}if(n==="unshot"){s?T&&T.drop.push(e.dataset.img):(e.closest("[data-draft]")?d?.images??[]:F).splice(Number(e.dataset.i),1),f(),T&&us();return}if(n==="edit"){const a=y.find(l=>l.id===s),i=e.dataset.at||null,o=i?a?.replies?.find(l=>l.at===i)?.text:a?.text;if(o===void 0)return;T={id:s,at:i,text:o,drop:[]},f(),us();return}if(n==="edit-cancel"){T=null,f();return}if(n==="translate"){Na(s,e.dataset.at);return}if(n==="unsay"){const a=e.dataset.at;if(!confirm("Delete this reply?"))return;await W(i=>i.map(o=>o.id!==s?o:{...o,replies:(o.replies??[]).map(l=>l.at===a?{...l,text:"",deleted:!0}:l)}),()=>D({id:s,unsay:a}),"Deleting the reply");return}if(n==="edit-save"){const a=T;if(!a)return;const i=a.text.trim();if(!i){b.querySelector(".dt-note-edit-input")?.focus();return}T=null;const o=l=>a.drop.includes(l.split("/").pop());await W(l=>l.map(u=>u.id!==a.id?u:{...u,...a.at==null?{text:i}:{replies:(u.replies??[]).map(m=>m.at===a.at?{...m,text:i}:m)},images:(u.images??[]).filter(m=>!o(m))}),()=>D({id:a.id,edit:{at:a.at,text:i},...a.drop.length?{removeImage:a.drop}:{}}).then(l=>(l.ok||(T=a),l),l=>{throw T=a,l}),"Saving the edit");return}if(n==="cancel"){j(),f();return}if(n==="twin"){j(),$=Number(e.dataset.id),f();return}if(n==="discard"){d=null,f();return}if(n==="draft-open"){Fe(Number(e.dataset.i));return}if(n==="close"){$=null,f();return}if(n==="unsuggest"&&d){d.suggest=null,f();return}if(n==="save"){if(!d)return;const a=d.suggest&&d.suggest.to.trim()!==d.suggest.from?{from:d.suggest.from,to:d.suggest.to.trim()}:null,i=b.querySelector(".dt-note-input").value.trim()||(a?"Change the text":"")||(d.images?.some(Ne)?Kn:"");if(!i){b.querySelector(".dt-note-input")?.focus();return}const o=d,l=c.client?null:Ns(i,ft()),u=ds.get(o)??ze(Q(o)),m={...o,route:P,text:i,suggest:a,assignee:c.client?o.assignee||c.lead||void 0:l??(o.assignee||void 0),shared:c.client?!0:o.shared===!0,stage:c.client?"new":l?"approved":o.stage??(I(o.assignee)?"approved":"new"),breakpoint:Te(),browser:Ys(),device:S?gs:"",viewport:{w:innerWidth,h:innerHeight},logs:ho(),host:location.host},r={...o,id:-Date.now(),text:i,route:P,status:"open",note:"",doneBy:null,breakpoint:m.breakpoint,replies:[],images:[],createdAt:new Date().toISOString(),...a?{suggest:a}:{},by:c.me?.email,byName:c.me?.name};y=[...y,r],d=null,f();const h=await u,g=await ot("comments",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({...m,...h?{before:h}:{}})}).catch(()=>null);if(!g?.ok){y=y.filter(L=>L!==r),j(),d=o,f(),C(`Comment was not saved${g?` (${g.status})`:""}.`);return}const w=Nt([await g.json().catch(()=>null)])[0];y=y.map(L=>L===r&&w?w:L),f(),oe();return}if(n==="reply"){const a=b.querySelector(".dt-note-reply-input"),i=a.value.trim()||(F.some(Ne)?Kn:"");if(!i){a.focus();return}const o=F;O="",F=[];const l=y,u=c.client?null:Ns(i,ft()),m=y.find(w=>w.id===s),r=u&&m&&(u!==m.assignee||G(m)!=="approved"||m.status==="done")?{assignee:u,stage:"approved",...m.status==="done"?{status:"open",doneBy:null}:{}}:{};y=y.map(w=>w.id===s?{...w,...r,replies:[...w.replies??[],{author:"you",text:i,at:new Date().toISOString(),by:c.me?.email}]}:w),f();const h=await D({id:s,reply:i,images:o,...r}).catch(()=>null);if(!h?.ok){y=l,O=i,F=o,f(),C(`Reply was not sent${h?` (${h.status})`:""}.`);return}const g=Nt([await h.json().catch(()=>null)])[0];g&&(y=y.map(w=>w.id===g.id?g:w),f()),oe();return}if(n==="hand"){sa(s,e.dataset.v);return}if(n==="sendback"){await bt(s,!1),ae(".dt-note-reply-input");return}if(n==="accept"){On(s,"accepted");return}e.classList.contains("dt-step-act")||($=null),n==="rm"?await Be(s):await bt(s,n==="done")});let gs="";const R=t=>{it.hidden||_t.contentWindow?.postMessage({dt:!0,...t},location.origin)},ao=()=>({notes:A,grid:!Dt.hidden,inspect:X,resolved:J,...hs.look()});addEventListener("message",t=>{if(t.origin!==location.origin||!t.data?.dt)return;const e=t.data;if(!S&&t.source===_t.contentWindow){if(e.key){ws(e.key[0],e.key[1])?.run();return}if(e.closeMenus){Lt();return}if(e.drafts){Re=e.drafts,Ht(lt());return}}if(S&&typeof e.openDraft=="number"){Fe(e.openDraft);return}if(S&&typeof e.dropDraft=="number"){Jn(e.dropDraft);return}if(S&&typeof e.device=="string"&&(gs=e.device),S&&e.scrollbar&&document.documentElement.classList.toggle("dt-sb-classic",e.scrollbar==="classic"),e.hello&&t.source===_t.contentWindow){R(ao());return}typeof e.notes=="boolean"&&e.notes!==A&&nt(e.notes,!1),typeof e.open=="number"&&Pe(e.open),typeof e.grid=="boolean"&&e.grid===Dt.hidden&&ue(e.grid),typeof e.inspect=="string"&&e.inspect!==X&&Ft(e.inspect),typeof e.resolved=="boolean"&&e.resolved!==J&&Ke(e.resolved),e.reload&&($t(),ne())});const oe=async()=>{await $t(),ne(),R({reload:!0}),S&&parent.postMessage({dt:!0,reload:!0},location.origin)},nt=(t,e=!0)=>{if(A=t,pn.setAttribute("aria-pressed",String(t)),t?!S&&x.hidden&&M.getItem("dt-history")!=="0"&&(x.hidden=!1,jt.setAttribute("aria-pressed","true")):(x.hidden=!0,jt.setAttribute("aria-pressed","false")),q(fn,t?"1":"0"),R({notes:t}),S&&e&&parent.postMessage({dt:!0,notes:t},location.origin),b.hidden=!t||!it.hidden,document.documentElement.classList.toggle("dt-noting",t),t){Ft(""),document.addEventListener("click",rs,!0);for(const n of os)document.addEventListener(n,is,!0);document.addEventListener("keydown",as),document.addEventListener("mousemove",ss),addEventListener("scroll",et,!0),addEventListener("resize",et),yn(),Zn.observe(document.body,{childList:!0,subtree:!0,characterData:!0}),ts.observe(document.body),$t()}else{j(),$=null,document.removeEventListener("click",rs,!0);for(const n of os)document.removeEventListener(n,is,!0);document.removeEventListener("keydown",as),document.removeEventListener("mousemove",ss),mt.hidden=!0,removeEventListener("scroll",et,!0),removeEventListener("resize",et),Zn.disconnect(),ts.disconnect(),b.innerHTML=""}},{pickBp:fs,...hs}=wo({cfg:c,inFrame:S,persist:q,frame:it,frameEl:_t,devicesMenu:ye,bpBtns:he,notesOverlay:b,WIDE:de,bpOf:sn,currentBp:Te,deviceById:Bs,notesOn:()=>A,filter:()=>Ee,filterTo:t=>{Ee=t},dropFrameDrafts:()=>{Re=[]},putAway:()=>{$=null,j()},tellFrame:R,syncBpButtons:bn,render:()=>f(),reread:()=>{A?$t():f()}}),bs="dt-studio",ys=t=>{be.setAttribute("aria-pressed",String(t)),document.documentElement.classList.toggle("dt-no-studio",!t),q(bs,t?"1":"0")};be.addEventListener("click",()=>ys(be.getAttribute("aria-pressed")!=="true")),ys(M.getItem(bs)!=="0"),pn.addEventListener("click",()=>nt(!A));const wt=document.querySelector(".devtools"),qt=document.querySelector(".dt-tab"),vs=t=>{wt.toggleAttribute("data-collapsed",t),qt.toggleAttribute("data-collapsed",t),qt.setAttribute("aria-expanded",String(!t)),qt.setAttribute("aria-label",t?"Show the bar":"Hide the bar");for(const e of wt.querySelectorAll(".dt-group"))e.inert=t;t&&Lt(),q("dt-collapsed",t?"1":"0")};qt.addEventListener("click",()=>vs(!wt.hasAttribute("data-collapsed")));const Ge=document.querySelector(".dt-keys"),U=t=>()=>wt.querySelector(t)?.click(),$s=t=>()=>{const e=[...document.querySelectorAll(".dt-pages a")];e[e.findIndex(n=>n.hasAttribute("aria-current"))+t]?.click()},ie=[{group:"Comments",code:"KeyC",hint:"C",label:"Comment mode",el:".dt-notes-btn",run:U(".dt-notes-btn")},{group:"Comments",code:"KeyC",shift:!0,hint:"\u21E7C",label:"Comments panel",el:".dt-history-btn",run:U(".dt-history-btn")},{group:"Comments",code:"KeyR",hint:"R",label:"Show resolved",el:".dt-resolved-btn",run:U(".dt-resolved-btn")},{group:"Inspect",code:"KeyG",hint:"G",label:"Grid",el:".dt-grid-btn",run:U(".dt-grid-btn")},{group:"Inspect",code:"KeyP",hint:"P",label:"Spacing",el:".dt-pad-btn",run:U(".dt-pad-btn")},{group:"Inspect",code:"KeyS",hint:"S",label:"Size",el:".dt-size-btn",run:U(".dt-size-btn")},{group:"Inspect",code:"KeyT",hint:"T",label:"Typography",el:".dt-type-btn",run:U(".dt-type-btn")},{group:"Inspect",code:"KeyO",hint:"O",label:"Color",el:".dt-color-btn",run:U(".dt-color-btn")},{group:"Inspect",code:"KeyB",hint:"B",label:"Border & radius",el:".dt-border-btn",run:U(".dt-border-btn")},...c.sanity?[{group:"Inspect",code:"KeyE",hint:"E",label:"Sanity overlay",el:".dt-studio-btn",run:U(".dt-studio-btn")}]:[],...he.slice(0,9).map((t,e)=>({group:"Breakpoints",code:`Digit${e+1}`,hint:String(e+1),label:t.dataset.tip??t.title,el:`.dt-bp[data-bp="${t.dataset.bp}"]`,run:()=>t.click()})),{group:"View",code:"KeyD",hint:"D",label:"Devices",run:()=>{ye.open=!ye.open}},{group:"View",code:"BracketLeft",hint:"[",label:"Previous page",run:$s(-1)},{group:"View",code:"BracketRight",hint:"]",label:"Next page",run:$s(1)},{group:"View",code:"Backslash",hint:"\\",label:"Hide the bar",run:()=>qt.click()},{group:"View",code:"Slash",shift:!0,hint:"?",label:"This list",el:".dt-keys summary",run:()=>{Ge.open=!Ge.open}}].filter(t=>!c.client||t.group!=="Inspect"),ws=(t,e)=>ie.find(n=>n.code===t&&!n.shift==!e),oo=t=>t instanceof HTMLElement&&(t.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName)||!!t.closest('[role="menu"], [role="listbox"], [role="dialog"][aria-modal="true"], [role="combobox"]'));if(c.shortcuts){for(const e of ie){const n=e.el&&wt.querySelector(e.el);n&&(n.dataset.tip=`${n.dataset.tip??e.label} \xB7 ${e.hint}`,n.setAttribute("aria-keyshortcuts",e.hint.startsWith("\u21E7")?`Shift+${e.hint.slice(1)}`:e.hint))}const t=(e,n)=>`<div class="dt-key-row"><span>${p(e)}</span><kbd>${p(n)}</kbd></div>`;if(Ge.querySelector(".dt-keys-menu").innerHTML='<p class="dt-menu-note">One key, no modifier, in any keyboard layout. Not while you type.</p>'+[...new Set(ie.map(e=>e.group))].map(e=>`<p class="dt-devices-group">${e}</p>`+ie.filter(n=>n.group===e).map(n=>t(n.label,n.hint)).join("")).join("")+'<p class="dt-devices-group">In a comment</p>'+t("Send","Enter")+t("New line","\u21E7Enter")+t("Close, cancel, back out","Esc"),document.addEventListener("keydown",e=>{if(e.repeat||e.isComposing||e.metaKey||e.ctrlKey||e.altKey||e.defaultPrevented||oo(e.target))return;const n=ws(e.code,e.shiftKey);n&&(e.preventDefault(),S?parent.postMessage({dt:!0,key:[e.code,e.shiftKey]},location.origin):n.run())}),S){const e=()=>parent.postMessage({dt:!0,closeMenus:!0},location.origin);document.addEventListener("pointerdown",e,!0),document.addEventListener("keydown",n=>{n.key==="Escape"&&e()})}}if(!S){vs(M.getItem("dt-collapsed")==="1"),requestAnimationFrame(()=>requestAnimationFrame(()=>wt.setAttribute("data-ready",""))),hs.restore(),ue(M.getItem(on)==="1");const t=M.getItem(cn);t&&t in ge&&Ft(t),nt(M.getItem(fn)==="1")}const Es=()=>{try{const t=JSON.parse(M.getItem(gt)||"null");H=(t?.parked??[]).filter(e=>Kt(e)),t?.draft&&document.querySelector(t.draft.selector)?(d=t.draft,!A&&!S&&nt(!0)):Kt(t?.draft)&&H.push(t.draft),t?.reply?.text&&(O=t.reply.text,Mt=$=t.reply.for??null),(d||H.length||O)&&f()}catch{M.removeItem(gt)}};Es();const Ss=()=>setTimeout(()=>{const t=ce(location.pathname);t!==P&&(clearTimeout(Wt),Se(),P=t,gt=hn(),d=null,H=[],O="",Mt=null,$=null,T=null,y=[],ln(),Es(),$t())});for(const t of["pushState","replaceState"]){const e=window.history[t];window.history[t]=function(...n){e.apply(this,n),Ss()}}addEventListener("popstate",Ss),A||$t(),ne().then(je.resume),document.addEventListener("visibilitychange",()=>{document.hidden||Ct()}),addEventListener("focus",Ct),addEventListener("notemend:changed",()=>{S||Ct()});let io=0;S||setInterval(()=>{(!go.live||++io%6===0)&&Ct()},2e4),S&&parent.postMessage({dt:!0,hello:!0},location.origin)}export{Do as run};
|
package/src/client/toplayer.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function u(n){if(!("showPopover"in HTMLElement.prototype)||typeof HTMLDialogElement>"u")return;const l=HTMLDialogElement.prototype,c=l.showModal;let e=null,o=null;const s=()=>{if(e){o?.disconnect(),o=null;for(const t of n)document.body.append(t);try{e.hidePopover()}catch{}e.remove(),e=null}},r=()=>{s();const t=document.querySelector("dialog:modal");t&&i(t)},i=t=>{s(),e=document.createElement("div"),e.className="dt-host",e.setAttribute("popover","manual"),e.append(...n),t.append(e);try{e.showPopover()}catch{}t.addEventListener("close",r,{once:!0}),o=new MutationObserver(()=>{t.isConnected||r()}),o.observe(document.documentElement,{childList:!0,subtree:!0})};l.showModal=function(){c.call(this),this.isConnected&&i(this)}}export{u as keepAboveModals};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{host as a}from"./client/api";import{start as l}from"./client/boot";const s=window.__notemendHosted,{project:c,base:m,cabinet:p,bridge:d}=s;let g=0;const r=new Map;function _(t,e){const i=++g,u=typeof e.body=="string"?e.body:void 0;return d.contentWindow.postMessage({type:"notemend:call",id:i,path:t,init:{method:e.method,headers:e.headers,body:u}},p),new Promise(y=>r.set(i,n=>y(new Response(n.status===204?null:n.body,{status:n.status,headers:n.ctype?{"content-type":n.ctype}:{}}))))}addEventListener("message",t=>{const e=t.data;if(!(!d||t.source!==d.contentWindow||t.origin!==p||e?.project!==c)){if(e.type==="notemend:reply"){r.get(e.id)?.(e),r.delete(e.id);return}if(e.type==="notemend:changed"){dispatchEvent(new Event("notemend:changed"));return}e.type==="notemend:live"&&(a.live=!!e.on)}}),Object.assign(a,{base:m,via:s.outer?.via??_,live:s.live}),s.framed||(window.__notemendBar={project:c,via:_});const o=document.createElement("link");o.rel="stylesheet",o.href=`${m}/bar.css?v=${typeof __BAR_CSS_V__=="string"?__BAR_CSS_V__:""}`,o.onload=o.onerror=()=>l(),document.head.append(o);
|
package/src/next.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
let n;async function
|
|
1
|
+
let n;async function s(e){if(process.env.NODE_ENV!=="development")return new Response("Not found",{status:404});if(!n){const{notemendHandler:r,scanApp:c}=await import("./server/middleware.mjs"),a=process.cwd();n=r({root:a,options:{},routes:()=>c(a)})}const o=new URL(e.url),t=await n({method:e.method,url:o.pathname+o.search,headers:Object.fromEntries(e.headers),body:async()=>Buffer.from(await e.arrayBuffer())});return new Response(t.status===204||t.status===304?null:t.body,{status:t.status,headers:{"content-type":t.type,"cache-control":"no-store"}})}export{s as DELETE,s as GET,s as PATCH,s as POST};
|