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