@daybook/feedback 1.1.1 → 1.1.2
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/README.md +7 -0
- package/dist/feedback.js +37 -8
- package/dist/index.d.ts +1 -0
- package/dist/index.js +15 -1
- package/dist/widget.d.ts +20 -3
- package/dist/widget.js +104 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -119,6 +119,13 @@ permits: it cannot grant anyone access to anything.
|
|
|
119
119
|
`localhost` is an origin like any other. Put it on the **development** environment and you are
|
|
120
120
|
working in a minute.
|
|
121
121
|
|
|
122
|
+
**Or let your assistant do all of it.** If you have Daybook connected as an MCP server in the
|
|
123
|
+
project you are adding the widget to, `get_feedback_install` returns the package, the snippet for
|
|
124
|
+
your framework, the components you can file against, and — most usefully — a `blockers` list saying
|
|
125
|
+
what is still unconfigured. `allow_feedback_domain` and `create_feedback_key` do the two steps that
|
|
126
|
+
need doing. That path exists because the SDK fails quietly by design: without it an assistant sets
|
|
127
|
+
everything up, sees no error, and has no way to tell a working install from a silent one.
|
|
128
|
+
|
|
122
129
|
On a domain that is not listed, the handshake returns `403 origin_not_allowed` and the widget quietly
|
|
123
130
|
does not appear — which is also what it does on a revoked key and on a dead network. A feedback
|
|
124
131
|
button must never break the page it is on.
|
package/dist/feedback.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
"use strict";var DaybookFeedback=(()=>{var I=Object.defineProperty;var ae=Object.getOwnPropertyDescriptor;var ce=Object.getOwnPropertyNames;var le=Object.prototype.hasOwnProperty;var de=(n,e)=>{for(var t in e)I(n,t,{get:e[t],enumerable:!0})},pe=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ce(e))!le.call(n,o)&&o!==t&&I(n,o,{get:()=>e[o],enumerable:!(r=ae(e,o))||r.enumerable});return n};var he=n=>pe(I({},"__esModule",{value:!0}),n);var _e={};de(_e,{DEFAULT_API_URL:()=>se,DaybookFeedback:()=>$,captureAnchor:()=>L,init:()=>Le,resolveAnchor:()=>te});function g(n){var e;try{let t=new URL(n,location.href);return t.origin===location.origin?t.pathname:`${t.origin}${t.pathname}`}catch{return(e=n.split("?")[0])!=null?e:n}}function M(n){var r,o,i,a,s,c;let e=n.tagName.toLowerCase();if(!n.getAttribute("aria-label")&&!n.getAttribute("data-testid")&&!((r=n.textContent)!=null?r:"").trim()){let d=n.closest("button, a, [role=button], [data-testid], label");if(d&&d!==n)return M(d)}if(n instanceof HTMLInputElement||n instanceof HTMLTextAreaElement||n instanceof HTMLSelectElement){let d=(i=(o=n.getAttribute("name"))!=null?o:n.id)!=null?i:"",p=n instanceof HTMLInputElement?n.type:e;return`${e}[${p}]${d?` name=${d}`:""}`}let t=(c=(a=n.getAttribute("aria-label"))!=null?a:n.getAttribute("data-testid"))!=null?c:((s=n.textContent)!=null?s:"").replace(/\s+/g," ").trim().slice(0,40);return t?`${e} "${t}"`:e}function X(n){return n.replace(/[\w.+-]+@[\w-]+\.[\w.]+/g,"[email]").replace(/\b[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\b/g,"[jwt]").replace(/\bBearer\s+[\w.-]+/gi,"Bearer [redacted]").replace(/\b\d{12,19}\b/g,"[number]").slice(0,500)}var W="data-daybook-private";var x=class{constructor(e=40,t=!0){this.limit=e;this.redact=t;this.entries=[];this.detach=[]}list(){return[...this.entries]}add(e,t){for(this.entries.push({at:new Date().toISOString(),type:e,message:this.redact?X(t):t.slice(0,500)});this.entries.length>this.limit;)this.entries.shift()}start(){let e=s=>{let c=s.target;c instanceof Element&&(c.closest("[data-daybook-feedback]")||this.add("click",M(c)))};document.addEventListener("click",e,{capture:!0,passive:!0}),this.detach.push(()=>document.removeEventListener("click",e,{capture:!0}));let t=history.pushState,r=history.replaceState,o=()=>this.add("nav",g(location.href));history.pushState=(...s)=>{t.apply(history,s),o()},history.replaceState=(...s)=>{r.apply(history,s),o()},window.addEventListener("popstate",o),this.detach.push(()=>{history.pushState=t,history.replaceState=r,window.removeEventListener("popstate",o)});for(let s of["error","warn"]){let c=console[s];console[s]=(...d)=>{this.add("console",`${s}: ${d.map(C).join(" ")}`),c.apply(console,d)},this.detach.push(()=>{console[s]=c})}let i=s=>this.add("console",`uncaught: ${s.message}`),a=s=>this.add("console",`unhandled rejection: ${C(s.reason)}`);window.addEventListener("error",i),window.addEventListener("unhandledrejection",a),this.detach.push(()=>{window.removeEventListener("error",i),window.removeEventListener("unhandledrejection",a)}),this.watchFetch()}stop(){for(let e of this.detach.splice(0))e()}watchFetch(){if(typeof window.fetch!="function")return;let e=window.fetch;window.fetch=async(...t)=>{let r=performance.now();try{let o=await e.apply(window,t),i=Math.round(performance.now()-r);return(!o.ok||i>3e3)&&this.add("network",`${o.status} ${g(V(t[0]))} ${i}ms`),o}catch(o){throw this.add("network",`failed ${g(V(t[0]))}: ${C(o)}`),o}},this.detach.push(()=>{window.fetch=e})}};function V(n){return typeof n=="string"?n:n instanceof URL?n.href:n.url}function C(n){var e,t;if(typeof n=="string")return n;if(n instanceof Error)return`${n.name}: ${n.message}`;try{return(t=(e=JSON.stringify(n))==null?void 0:e.slice(0,200))!=null?t:String(n)}catch{return String(n)}}var H="pm.feedback.queue";var E=class{constructor(e,t){this.apiUrl=e;this.ingestKey=t;this.session=null;this.identityToken=null}setSession(e){this.session=e}async send(e,t=[]){var a,s;let r={idempotencyKey:(a=e.idempotencyKey)!=null?a:Y(),...e,attachments:[...(s=e.attachments)!=null?s:[],...t.map(c=>({filename:c.filename,contentType:c.contentType,size:c.blob.size}))]},o=await this.post("/ingest/v1",r);if(!o.ok)throw await k(o);let i=await o.json();return await Promise.all(t.map((c,d)=>{let p=i.attachments[d];return p?this.upload(p,c).catch(()=>{}):Promise.resolve()})),i}async flush(){let e=Q();if(e.length!==0){Z([]);for(let t of e)try{let r=await this.post("/ingest/v1",t);!r.ok&&(r.status===429||r.status>=500)&&F(t)}catch{F(t)}}}queue(e){var t;F({...e,idempotencyKey:(t=e.idempotencyKey)!=null?t:Y(),attachments:void 0})}async signIn(){let e=J(64),t=await ue(e),r=J(16),o=`${this.base()}/ingest/v1/authorize?key=${encodeURIComponent(this.ingestKey)}&origin=${encodeURIComponent(location.origin)}&code_challenge=${encodeURIComponent(t)}&state=${encodeURIComponent(r)}`,i=window.open(o,"daybook-feedback","width=460,height=640");if(!i)throw Object.assign(new Error("Popup blocked"),{code:"popup_blocked"});let a=await new Promise((d,p)=>{let b=setInterval(()=>{i.closed&&(w(),p(Object.assign(new Error("Sign-in cancelled"),{code:"cancelled"})))},400),y=m=>{if(m.origin!==new URL(this.base()).origin)return;let h=m.data;if((h==null?void 0:h.source)==="daybook-feedback"&&h.state===r){if(w(),h.error||!h.code){p(Object.assign(new Error("Sign-in was refused"),{code:h.error||"refused"}));return}d(h.code)}},w=()=>{clearInterval(b),window.removeEventListener("message",y)};window.addEventListener("message",y)}),s=await this.post("/ingest/v1/token",{code:a,codeVerifier:e});if(!s.ok)throw await k(s);let{identityToken:c}=await s.json();return this.identityToken=c,c}base(){return this.apiUrl.replace(/\/$/,"")}async handshake(e){var o,i;let t=await this.post("/ingest/v1/session",{...e,identityToken:(o=this.identityToken)!=null?o:void 0});if(!t.ok)throw await k(t);let r=await t.json();return this.session=(i=r.sessionToken)!=null?i:null,r}post(e,t){let r={"Content-Type":"application/json","X-Ingest-Key":this.ingestKey};return this.session&&(r["X-Feedback-Session"]=this.session),fetch(`${this.base()}${e}`,{method:"POST",headers:r,body:JSON.stringify(t),credentials:"omit"})}async upload(e,t){let r=await fetch(e.uploadUrl,{method:e.method,headers:{"Content-Type":e.contentType,"X-Ingest-Key":this.ingestKey},body:t.blob,credentials:"omit"});if(!r.ok)throw await k(r);await this.post(`/ingest/v1/attachments/${e.id}/confirm`,{})}};function F(n){let e=Q();e.push(n),Z(e.slice(-20))}function Q(){try{let n=localStorage.getItem(H);return n?JSON.parse(n):[]}catch{return[]}}function Z(n){try{n.length===0?localStorage.removeItem(H):localStorage.setItem(H,JSON.stringify(n))}catch{}}async function k(n){let e=`http_${n.status}`;try{let t=await n.json();if(t.code&&(e=t.code),t.message)return Object.assign(new Error(t.message),{code:e})}catch{}return Object.assign(new Error(`Ingest failed (${n.status})`),{code:e})}function Y(){return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function J(n){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~",t=new Uint8Array(n);return crypto.getRandomValues(t),Array.from(t,r=>e[r%e.length]).join("")}async function ue(n){let e=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(n));return btoa(String.fromCharCode(...new Uint8Array(e))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function U(n){var t;let e={platform:"web",route:location.pathname,title:document.title.slice(0,200),locale:navigator.language,timezone:me(),viewport:{width:window.innerWidth,height:window.innerHeight,dpr:(t=window.devicePixelRatio)!=null?t:1},device:fe()};return document.referrer&&(e.referrer=g(document.referrer)),n.app&&(e.app=n.app),n.anchor&&(e.anchor=n.anchor),n.breadcrumbs&&n.breadcrumbs.length>0&&(e.breadcrumbs=n.breadcrumbs),e}function fe(){var o;let n=navigator.userAgent,e=/Edg\//.test(n)?"Edge":/OPR\//.test(n)?"Opera":/Firefox\//.test(n)?"Firefox":/Chrome\//.test(n)?"Chrome":/Safari\//.test(n)?"Safari":"Unknown",t=/Windows NT/.test(n)?"Windows":/iPhone|iPad|iPod/.test(n)?"iOS":/Mac OS X/.test(n)?"macOS":/Android/.test(n)?"Android":/Linux/.test(n)?"Linux":"Unknown",r=(o=n.match(/(?:Edg|OPR|Firefox|Chrome|Version)\/(\d+)/))==null?void 0:o[1];return{browser:r?`${e} ${r}`:e,os:t,touch:navigator.maxTouchPoints>0,userAgent:n.slice(0,300)}}function me(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return`UTC${-new Date().getTimezoneOffset()/60}`}}async function G(n){var r;if(typeof((r=navigator.mediaDevices)==null?void 0:r.getDisplayMedia)!="function")return null;let e=n?be():()=>{},t=null;try{if(t=await navigator.mediaDevices.getDisplayMedia({video:!0,audio:!1,preferCurrentTab:!0}),!t.getVideoTracks()[0])return null;await new Promise(a=>setTimeout(a,250));let i=await ge(t);return i?{blob:i,filename:"screenshot.png",contentType:"image/png"}:null}catch{return null}finally{t==null||t.getTracks().forEach(o=>o.stop()),e()}}async function ge(n){let e=document.createElement("video");e.srcObject=n,e.muted=!0,await e.play().catch(()=>{});let t=document.createElement("canvas");t.width=e.videoWidth||window.innerWidth,t.height=e.videoHeight||window.innerHeight;let r=t.getContext("2d");return r?(r.drawImage(e,0,0,t.width,t.height),e.pause(),e.srcObject=null,new Promise(o=>t.toBlob(i=>o(i),"image/png"))):null}function be(){let n=[...document.querySelectorAll(`[${W}]`),...document.querySelectorAll('input[type="password"]')],e=n.map(t=>t.style.filter);return n.forEach(t=>{t.style.filter="blur(12px)"}),()=>{n.forEach((t,r)=>{var o;t.style.filter=(o=e[r])!=null?o:""})}}function L(n,e){let t=document.elementFromPoint(n,e);if(!(t instanceof HTMLElement))return{selector:null,offsetX:S(n/window.innerWidth),offsetY:S(e/window.innerHeight),elementText:null};let r=t.getBoundingClientRect();return{selector:ye(t),offsetX:r.width>0?S((n-r.left)/r.width):0,offsetY:r.height>0?S((e-r.top)/r.height):0,elementText:we(t)}}function te(n){if(!n.selector)return{x:n.offsetX*window.innerWidth,y:n.offsetY*window.innerHeight};let e=null;try{e=document.querySelector(n.selector)}catch{return null}if(!e)return null;let t=e.getBoundingClientRect();return{x:t.left+n.offsetX*t.width,y:t.top+n.offsetY*t.height}}function ye(n){if(n===document.body)return"body";for(let o of["data-testid","data-test","data-daybook-id","data-cy"]){let i=n.getAttribute(o);if(i){let a=`[${o}="${P(i)}"]`;if(T(a))return a}}if(n.id&&!ee(n.id)){let o=`#${P(n.id)}`;if(T(o))return o}let e=[],t=n;for(;t&&t!==document.body&&e.length<8;){let o=t.tagName.toLowerCase(),i=Array.from(t.classList).filter(c=>!ee(c)).slice(0,2);i.length>0&&(o+=i.map(c=>`.${P(c)}`).join(""));let a=t.parentElement;if(a){let c=Array.from(a.children).filter(d=>d.tagName===t.tagName);c.length>1&&(o+=`:nth-of-type(${c.indexOf(t)+1})`)}e.unshift(o);let s=e.join(" > ");if(T(s))return s;t=a}let r=e.length>0?`body > ${e.join(" > ")}`:null;return r&&T(r)?r:null}function T(n){try{return document.querySelectorAll(n).length===1}catch{return!1}}function ee(n){return/^[a-z]{1,3}[0-9a-f]{5,}$/i.test(n)||/--[0-9a-f]{5,}$/i.test(n)||/^_[0-9a-z]{5,}/i.test(n)||/^v-[0-9a-f]{6,}$/i.test(n)||/^ng-/.test(n)||/[0-9a-f]{8,}/i.test(n)}function we(n){var r,o,i;let t=((o=(r=n.innerText)!=null?r:n.textContent)!=null?o:"").replace(/\s+/g," ").trim();if(!t){let a=(i=n.getAttribute("aria-label"))!=null?i:n.getAttribute("title");return(a==null?void 0:a.trim())||null}return t.length>80?`${t.slice(0,77)}\u2026`:t}function S(n){return Number.isFinite(n)?Math.max(0,Math.min(1,n)):0}function P(n){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(n):n.replace(/([^\w-])/g,"\\$1")}var ve=/^(image\/(png|jpeg|gif|webp)|video\/(mp4|quicktime|webm))$/;function ne(n,e){let t=[];for(let r of n){if(e+t.length>=5)break;let o=ve.test(r.type)?r.size>26214400?`Too large (${(r.size/1048576).toFixed(1)} MB, max 25).`:null:"Only images and short videos.";t.push({blob:r,filename:r.name||`pasted-${t.length+1}.${xe(r.type)}`,contentType:r.type,preview:o?null:URL.createObjectURL(r),error:o})}return t}function re(n){var r;let e=(r=n.clipboardData)==null?void 0:r.items;if(!e)return[];let t=[];for(let o of e){if(o.kind!=="file")continue;let i=o.getAsFile();i&&t.push(i)}return t}function R(n){for(let e of n)e.preview&&URL.revokeObjectURL(e.preview)}function xe(n){var e,t;return(t=(e=n.split("/")[1])==null?void 0:e.replace("quicktime","mov"))!=null?t:"bin"}function oe(n){var r;let t=(r=(typeof n.composedPath=="function"?n.composedPath():[])[0])!=null?r:n.target;return!t||t.nodeType!==1?!1:/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName)?!0:typeof t.closest=="function"&&t.closest('[contenteditable=""], [contenteditable="true"]')!==null}var _=class{constructor(e,t){this.options=e;this.onSubmit=t;this.mode="idle";this.anchor=null;this.detach=[];this.state="ready";this.reference=null;this.host=document.createElement("div"),this.host.setAttribute("data-daybook-feedback",""),this.host.style.cssText="position:fixed;inset:0;z-index:2147483000;pointer-events:none",this.root=this.host.attachShadow({mode:"open"}),this.root.innerHTML=`<style>${Se}</style><style id="theme"></style><div id="layer"></div>`}setTheme(e){var a,s;let t=this.root.getElementById("theme");if(!t)return;if(!e){t.textContent="";return}let r=[];Te(e.accent)&&r.push(`--pm-accent: ${e.accent}`);let o={none:"0",sm:"6px",md:"12px",lg:"18px"}[(a=e.cornerRadius)!=null?a:"md"];o&&r.push(`--pm-radius: ${o}`);let i=Ee[(s=e.position)!=null?s:"bottom-right"];i&&r.push(i),t.textContent=r.length>0?`:host { ${r.join("; ")} }`:"",this.launcherLabel=typeof e.launcherLabel=="string"&&e.launcherLabel.length>0?e.launcherLabel.slice(0,24):void 0}setState(e){this.state=e,this.host.isConnected&&this.render()}mount(){var e;if(document.body.appendChild(this.host),this.render(),this.options.hotkey!==null){let t=((e=this.options.hotkey)!=null?e:"f").toLowerCase(),r=o=>{if(o.key==="Escape"){this.mode="idle",this.anchor=null,this.render();return}o.metaKey||o.ctrlKey||o.altKey||oe(o)||this.mode!=="composing"&&o.key.toLowerCase()===t&&(this.mode=this.mode==="picking"?"idle":"picking",this.render())};window.addEventListener("keydown",r),this.detach.push(()=>window.removeEventListener("keydown",r))}}unmount(){for(let e of this.detach.splice(0))e();this.host.remove()}open(){this.mode="picking",this.render()}setReporter(e){this.reporter=e}render(){let e=this.root.getElementById("layer");if(e.innerHTML="",this.mode==="idle"){e.appendChild(this.state==="pending"?this.pending():this.launcher());return}if(this.mode==="sent"){e.appendChild(this.sent());return}if(this.mode==="picking"){e.appendChild(this.picker());return}e.appendChild(this.composer())}pending(){let e=document.createElement("div");return e.className="launcher launcher--pending",e.setAttribute("role","status"),e.textContent="Feedback access pending approval",e}sent(){let e=document.createElement("div");e.className="panel panel--sent",e.setAttribute("role","status"),e.innerHTML=`
|
|
1
|
+
"use strict";var DaybookFeedback=(()=>{var C=Object.defineProperty;var ae=Object.getOwnPropertyDescriptor;var ce=Object.getOwnPropertyNames;var le=Object.prototype.hasOwnProperty;var de=(n,e)=>{for(var t in e)C(n,t,{get:e[t],enumerable:!0})},pe=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of ce(e))!le.call(n,r)&&r!==t&&C(n,r,{get:()=>e[r],enumerable:!(o=ae(e,r))||o.enumerable});return n};var he=n=>pe(C({},"__esModule",{value:!0}),n);var $e={};de($e,{DEFAULT_API_URL:()=>se,DaybookFeedback:()=>$,captureAnchor:()=>L,init:()=>_e,resolveAnchor:()=>te});function g(n){var e;try{let t=new URL(n,location.href);return t.origin===location.origin?t.pathname:`${t.origin}${t.pathname}`}catch{return(e=n.split("?")[0])!=null?e:n}}function I(n){var o,r,i,a,s,c;let e=n.tagName.toLowerCase();if(!n.getAttribute("aria-label")&&!n.getAttribute("data-testid")&&!((o=n.textContent)!=null?o:"").trim()){let d=n.closest("button, a, [role=button], [data-testid], label");if(d&&d!==n)return I(d)}if(n instanceof HTMLInputElement||n instanceof HTMLTextAreaElement||n instanceof HTMLSelectElement){let d=(i=(r=n.getAttribute("name"))!=null?r:n.id)!=null?i:"",p=n instanceof HTMLInputElement?n.type:e;return`${e}[${p}]${d?` name=${d}`:""}`}let t=(c=(a=n.getAttribute("aria-label"))!=null?a:n.getAttribute("data-testid"))!=null?c:((s=n.textContent)!=null?s:"").replace(/\s+/g," ").trim().slice(0,40);return t?`${e} "${t}"`:e}function X(n){return n.replace(/[\w.+-]+@[\w-]+\.[\w.]+/g,"[email]").replace(/\b[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\b/g,"[jwt]").replace(/\bBearer\s+[\w.-]+/gi,"Bearer [redacted]").replace(/\b\d{12,19}\b/g,"[number]").slice(0,500)}var W="data-daybook-private";var x=class{constructor(e=40,t=!0){this.limit=e;this.redact=t;this.entries=[];this.detach=[]}list(){return[...this.entries]}add(e,t){for(this.entries.push({at:new Date().toISOString(),type:e,message:this.redact?X(t):t.slice(0,500)});this.entries.length>this.limit;)this.entries.shift()}start(){let e=s=>{let c=s.target;c instanceof Element&&(c.closest("[data-daybook-feedback]")||this.add("click",I(c)))};document.addEventListener("click",e,{capture:!0,passive:!0}),this.detach.push(()=>document.removeEventListener("click",e,{capture:!0}));let t=history.pushState,o=history.replaceState,r=()=>this.add("nav",g(location.href));history.pushState=(...s)=>{t.apply(history,s),r()},history.replaceState=(...s)=>{o.apply(history,s),r()},window.addEventListener("popstate",r),this.detach.push(()=>{history.pushState=t,history.replaceState=o,window.removeEventListener("popstate",r)});for(let s of["error","warn"]){let c=console[s];console[s]=(...d)=>{this.add("console",`${s}: ${d.map(M).join(" ")}`),c.apply(console,d)},this.detach.push(()=>{console[s]=c})}let i=s=>this.add("console",`uncaught: ${s.message}`),a=s=>this.add("console",`unhandled rejection: ${M(s.reason)}`);window.addEventListener("error",i),window.addEventListener("unhandledrejection",a),this.detach.push(()=>{window.removeEventListener("error",i),window.removeEventListener("unhandledrejection",a)}),this.watchFetch()}stop(){for(let e of this.detach.splice(0))e()}watchFetch(){if(typeof window.fetch!="function")return;let e=window.fetch;window.fetch=async(...t)=>{let o=performance.now();try{let r=await e.apply(window,t),i=Math.round(performance.now()-o);return(!r.ok||i>3e3)&&this.add("network",`${r.status} ${g(V(t[0]))} ${i}ms`),r}catch(r){throw this.add("network",`failed ${g(V(t[0]))}: ${M(r)}`),r}},this.detach.push(()=>{window.fetch=e})}};function V(n){return typeof n=="string"?n:n instanceof URL?n.href:n.url}function M(n){var e,t;if(typeof n=="string")return n;if(n instanceof Error)return`${n.name}: ${n.message}`;try{return(t=(e=JSON.stringify(n))==null?void 0:e.slice(0,200))!=null?t:String(n)}catch{return String(n)}}var H="pm.feedback.queue";var E=class{constructor(e,t){this.apiUrl=e;this.ingestKey=t;this.session=null;this.identityToken=null}setSession(e){this.session=e}async send(e,t=[]){var a,s;let o={idempotencyKey:(a=e.idempotencyKey)!=null?a:Y(),...e,attachments:[...(s=e.attachments)!=null?s:[],...t.map(c=>({filename:c.filename,contentType:c.contentType,size:c.blob.size}))]},r=await this.post("/ingest/v1",o);if(!r.ok)throw await k(r);let i=await r.json();return await Promise.all(t.map((c,d)=>{let p=i.attachments[d];return p?this.upload(p,c).catch(()=>{}):Promise.resolve()})),i}async flush(){let e=Q();if(e.length!==0){Z([]);for(let t of e)try{let o=await this.post("/ingest/v1",t);!o.ok&&(o.status===429||o.status>=500)&&F(t)}catch{F(t)}}}queue(e){var t;F({...e,idempotencyKey:(t=e.idempotencyKey)!=null?t:Y(),attachments:void 0})}async signIn(){let e=J(64),t=await ue(e),o=J(16),r=`${this.base()}/ingest/v1/authorize?key=${encodeURIComponent(this.ingestKey)}&origin=${encodeURIComponent(location.origin)}&code_challenge=${encodeURIComponent(t)}&state=${encodeURIComponent(o)}`,i=window.open(r,"daybook-feedback","width=460,height=640");if(!i)throw Object.assign(new Error("Popup blocked"),{code:"popup_blocked"});let a=await new Promise((d,p)=>{let y=setInterval(()=>{i.closed&&(w(),p(Object.assign(new Error("Sign-in cancelled"),{code:"cancelled"})))},400),b=m=>{if(m.origin!==new URL(this.base()).origin)return;let h=m.data;if((h==null?void 0:h.source)==="daybook-feedback"&&h.state===o){if(w(),h.error||!h.code){p(Object.assign(new Error("Sign-in was refused"),{code:h.error||"refused"}));return}d(h.code)}},w=()=>{clearInterval(y),window.removeEventListener("message",b)};window.addEventListener("message",b)}),s=await this.post("/ingest/v1/token",{code:a,codeVerifier:e});if(!s.ok)throw await k(s);let{identityToken:c}=await s.json();return this.identityToken=c,c}base(){return this.apiUrl.replace(/\/$/,"")}async handshake(e){var r,i;let t=await this.post("/ingest/v1/session",{...e,identityToken:(r=this.identityToken)!=null?r:void 0});if(!t.ok)throw await k(t);let o=await t.json();return this.session=(i=o.sessionToken)!=null?i:null,o}post(e,t){let o={"Content-Type":"application/json","X-Ingest-Key":this.ingestKey};return this.session&&(o["X-Feedback-Session"]=this.session),fetch(`${this.base()}${e}`,{method:"POST",headers:o,body:JSON.stringify(t),credentials:"omit"})}async upload(e,t){let o=await fetch(e.uploadUrl,{method:e.method,headers:{"Content-Type":e.contentType,"X-Ingest-Key":this.ingestKey},body:t.blob,credentials:"omit"});if(!o.ok)throw await k(o);await this.post(`/ingest/v1/attachments/${e.id}/confirm`,{})}};function F(n){let e=Q();e.push(n),Z(e.slice(-20))}function Q(){try{let n=localStorage.getItem(H);return n?JSON.parse(n):[]}catch{return[]}}function Z(n){try{n.length===0?localStorage.removeItem(H):localStorage.setItem(H,JSON.stringify(n))}catch{}}async function k(n){let e=`http_${n.status}`;try{let t=await n.json();if(t.code&&(e=t.code),t.message)return Object.assign(new Error(t.message),{code:e})}catch{}return Object.assign(new Error(`Ingest failed (${n.status})`),{code:e})}function Y(){return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function J(n){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~",t=new Uint8Array(n);return crypto.getRandomValues(t),Array.from(t,o=>e[o%e.length]).join("")}async function ue(n){let e=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(n));return btoa(String.fromCharCode(...new Uint8Array(e))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function U(n){var t;let e={platform:"web",route:location.pathname,title:document.title.slice(0,200),locale:navigator.language,timezone:me(),viewport:{width:window.innerWidth,height:window.innerHeight,dpr:(t=window.devicePixelRatio)!=null?t:1},device:fe()};return document.referrer&&(e.referrer=g(document.referrer)),n.app&&(e.app=n.app),n.anchor&&(e.anchor=n.anchor),n.breadcrumbs&&n.breadcrumbs.length>0&&(e.breadcrumbs=n.breadcrumbs),e}function fe(){var r;let n=navigator.userAgent,e=/Edg\//.test(n)?"Edge":/OPR\//.test(n)?"Opera":/Firefox\//.test(n)?"Firefox":/Chrome\//.test(n)?"Chrome":/Safari\//.test(n)?"Safari":"Unknown",t=/Windows NT/.test(n)?"Windows":/iPhone|iPad|iPod/.test(n)?"iOS":/Mac OS X/.test(n)?"macOS":/Android/.test(n)?"Android":/Linux/.test(n)?"Linux":"Unknown",o=(r=n.match(/(?:Edg|OPR|Firefox|Chrome|Version)\/(\d+)/))==null?void 0:r[1];return{browser:o?`${e} ${o}`:e,os:t,touch:navigator.maxTouchPoints>0,userAgent:n.slice(0,300)}}function me(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return`UTC${-new Date().getTimezoneOffset()/60}`}}async function G(n){var o;if(typeof((o=navigator.mediaDevices)==null?void 0:o.getDisplayMedia)!="function")return null;let e=n?ye():()=>{},t=null;try{if(t=await navigator.mediaDevices.getDisplayMedia({video:!0,audio:!1,preferCurrentTab:!0}),!t.getVideoTracks()[0])return null;await new Promise(a=>setTimeout(a,250));let i=await ge(t);return i?{blob:i,filename:"screenshot.png",contentType:"image/png"}:null}catch{return null}finally{t==null||t.getTracks().forEach(r=>r.stop()),e()}}async function ge(n){let e=document.createElement("video");e.srcObject=n,e.muted=!0,await e.play().catch(()=>{});let t=document.createElement("canvas");t.width=e.videoWidth||window.innerWidth,t.height=e.videoHeight||window.innerHeight;let o=t.getContext("2d");return o?(o.drawImage(e,0,0,t.width,t.height),e.pause(),e.srcObject=null,new Promise(r=>t.toBlob(i=>r(i),"image/png"))):null}function ye(){let n=[...document.querySelectorAll(`[${W}]`),...document.querySelectorAll('input[type="password"]')],e=n.map(t=>t.style.filter);return n.forEach(t=>{t.style.filter="blur(12px)"}),()=>{n.forEach((t,o)=>{var r;t.style.filter=(r=e[o])!=null?r:""})}}function L(n,e){let t=document.elementFromPoint(n,e);if(!(t instanceof HTMLElement))return{selector:null,offsetX:S(n/window.innerWidth),offsetY:S(e/window.innerHeight),elementText:null};let o=t.getBoundingClientRect();return{selector:be(t),offsetX:o.width>0?S((n-o.left)/o.width):0,offsetY:o.height>0?S((e-o.top)/o.height):0,elementText:we(t)}}function te(n){if(!n.selector)return{x:n.offsetX*window.innerWidth,y:n.offsetY*window.innerHeight};let e=null;try{e=document.querySelector(n.selector)}catch{return null}if(!e)return null;let t=e.getBoundingClientRect();return{x:t.left+n.offsetX*t.width,y:t.top+n.offsetY*t.height}}function be(n){if(n===document.body)return"body";for(let r of["data-testid","data-test","data-daybook-id","data-cy"]){let i=n.getAttribute(r);if(i){let a=`[${r}="${P(i)}"]`;if(T(a))return a}}if(n.id&&!ee(n.id)){let r=`#${P(n.id)}`;if(T(r))return r}let e=[],t=n;for(;t&&t!==document.body&&e.length<8;){let r=t.tagName.toLowerCase(),i=Array.from(t.classList).filter(c=>!ee(c)).slice(0,2);i.length>0&&(r+=i.map(c=>`.${P(c)}`).join(""));let a=t.parentElement;if(a){let c=Array.from(a.children).filter(d=>d.tagName===t.tagName);c.length>1&&(r+=`:nth-of-type(${c.indexOf(t)+1})`)}e.unshift(r);let s=e.join(" > ");if(T(s))return s;t=a}let o=e.length>0?`body > ${e.join(" > ")}`:null;return o&&T(o)?o:null}function T(n){try{return document.querySelectorAll(n).length===1}catch{return!1}}function ee(n){return/^[a-z]{1,3}[0-9a-f]{5,}$/i.test(n)||/--[0-9a-f]{5,}$/i.test(n)||/^_[0-9a-z]{5,}/i.test(n)||/^v-[0-9a-f]{6,}$/i.test(n)||/^ng-/.test(n)||/[0-9a-f]{8,}/i.test(n)}function we(n){var o,r,i;let t=((r=(o=n.innerText)!=null?o:n.textContent)!=null?r:"").replace(/\s+/g," ").trim();if(!t){let a=(i=n.getAttribute("aria-label"))!=null?i:n.getAttribute("title");return(a==null?void 0:a.trim())||null}return t.length>80?`${t.slice(0,77)}\u2026`:t}function S(n){return Number.isFinite(n)?Math.max(0,Math.min(1,n)):0}function P(n){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(n):n.replace(/([^\w-])/g,"\\$1")}var ve=/^(image\/(png|jpeg|gif|webp)|video\/(mp4|quicktime|webm))$/;function ne(n,e){let t=[];for(let o of n){if(e+t.length>=5)break;let r=ve.test(o.type)?o.size>26214400?`Too large (${(o.size/1048576).toFixed(1)} MB, max 25).`:null:"Only images and short videos.";t.push({blob:o,filename:o.name||`pasted-${t.length+1}.${xe(o.type)}`,contentType:o.type,preview:r?null:URL.createObjectURL(o),error:r})}return t}function oe(n){var o;let e=(o=n.clipboardData)==null?void 0:o.items;if(!e)return[];let t=[];for(let r of e){if(r.kind!=="file")continue;let i=r.getAsFile();i&&t.push(i)}return t}function _(n){for(let e of n)e.preview&&URL.revokeObjectURL(e.preview)}function xe(n){var e,t;return(t=(e=n.split("/")[1])==null?void 0:e.replace("quicktime","mov"))!=null?t:"bin"}function re(n){var o;let t=(o=(typeof n.composedPath=="function"?n.composedPath():[])[0])!=null?o:n.target;return!t||t.nodeType!==1?!1:/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName)?!0:typeof t.closest=="function"&&t.closest('[contenteditable=""], [contenteditable="true"]')!==null}var R=class{constructor(e,t){this.options=e;this.onSubmit=t;this.mode="idle";this.anchor=null;this.detach=[];this.state="ready";this.reference=null;this.host=document.createElement("div"),this.host.setAttribute("data-daybook-feedback",""),this.host.style.cssText="position:fixed;inset:0;z-index:2147483000;pointer-events:none",this.root=this.host.attachShadow({mode:"open"}),this.root.innerHTML=`<style>${Le}</style><style id="theme"></style><div id="layer"></div>`}setTheme(e){var a,s;let t=this.root.getElementById("theme");if(!t)return;if(!e){t.textContent="";return}let o=[];Se(e.accent)&&o.push(`--pm-accent: ${e.accent}`);let r={none:"0",sm:"6px",md:"12px",lg:"18px"}[(a=e.cornerRadius)!=null?a:"md"];r&&o.push(`--pm-radius: ${r}`);let i=Te[(s=e.position)!=null?s:"bottom-right"];i&&o.push(i),t.textContent=o.length>0?`:host { ${o.join("; ")} }`:"",this.launcherLabel=typeof e.launcherLabel=="string"&&e.launcherLabel.length>0?e.launcherLabel.slice(0,24):void 0}setState(e){this.state=e,this.host.isConnected&&this.render()}mount(){var e;if(document.body.appendChild(this.host),this.render(),this.options.hotkey!==null){let t=((e=this.options.hotkey)!=null?e:"f").toLowerCase(),o=r=>{if(r.key==="Escape"){this.mode="idle",this.anchor=null,this.render();return}r.metaKey||r.ctrlKey||r.altKey||re(r)||this.mode!=="composing"&&r.key.toLowerCase()===t&&(this.mode=this.mode==="picking"?"idle":"picking",this.render())};window.addEventListener("keydown",o),this.detach.push(()=>window.removeEventListener("keydown",o))}}unmount(){for(let e of this.detach.splice(0))e();this.host.remove()}open(){this.mode="picking",this.render()}setReporter(e){this.reporter=e}render(){let e=this.root.getElementById("layer");if(e.innerHTML="",this.mode==="idle"){e.appendChild(this.state==="pending"?this.pending():this.launcher());return}if(this.mode==="sent"){e.appendChild(this.sent());return}if(this.mode==="picking"){e.appendChild(this.picker());return}e.appendChild(this.composer())}pending(){let e=document.createElement("div");return e.className="launcher launcher--pending",e.setAttribute("role","status"),e.textContent="Feedback access pending approval",e}sent(){var s;let e=document.createElement("div");e.className="panel panel--sent",e.setAttribute("role","status");let t=this.reference;e.innerHTML=`
|
|
2
2
|
<div class="sent__tick" aria-hidden="true">✓</div>
|
|
3
|
-
<div>
|
|
3
|
+
<div class="sent__body">
|
|
4
4
|
<div class="panel__title">Thank you \u2014 that is on its way.</div>
|
|
5
|
-
${
|
|
6
|
-
|
|
5
|
+
${t?`<div class="sent__ref">
|
|
6
|
+
<code class="sent__id">${ie(t)}</code>
|
|
7
|
+
<button type="button" class="sent__copy" data-copy>Copy</button>
|
|
8
|
+
</div>
|
|
9
|
+
<div class="panel__anchor">Quote it if you follow it up.</div>`:""}
|
|
10
|
+
</div>
|
|
11
|
+
${t?'<button type="button" class="panel__close" data-dismiss aria-label="Dismiss">×</button>':""}`;let o=()=>{this.mode==="sent"&&(this.mode="idle",this.render())},r=window.setTimeout(o,t?12e3:6e3),i=()=>window.clearTimeout(r);if(this.detach.push(()=>window.clearTimeout(r)),!t)return e;e.addEventListener("pointerenter",i),e.addEventListener("focusin",i),(s=e.querySelector("[data-dismiss]"))==null||s.addEventListener("click",o);let a=e.querySelector("[data-copy]");return a&&(a.onclick=async()=>{i();let c=await Ee(t);a.textContent=c?"Copied":"Copy failed",a.classList.toggle("sent__copy--done",c)}),e}launcher(){var t,o;let e=document.createElement("button");return e.className="launcher",e.textContent=(t=this.launcherLabel)!=null?t:"Feedback",e.title=this.options.hotkey===null?"Report a problem":`Report a problem (${((o=this.options.hotkey)!=null?o:"f").toUpperCase()})`,e.onclick=()=>{this.mode="picking",this.render()},e}picker(){let e=document.createElement("div");return e.className="mask",e.innerHTML='<div class="hint">Click the thing that is wrong \xB7 <kbd>Esc</kbd> to cancel</div>',e.onclick=t=>{e.style.pointerEvents="none",this.anchor=L(t.clientX,t.clientY),e.style.pointerEvents="",this.mode="composing",this.render()},e}composer(){var j,z,B,K,N;let e=document.createElement("div");e.className="panel";let t=(j=this.anchor)!=null&&j.elementText?`on \u201C${this.anchor.elementText}\u201D`:(z=this.anchor)!=null&&z.selector?`on ${this.anchor.selector}`:"on this page";e.innerHTML=`
|
|
7
12
|
<div class="panel__head">
|
|
8
13
|
<div>
|
|
9
14
|
<div class="panel__anchor">${ie(t)}</div>
|
|
@@ -42,7 +47,7 @@
|
|
|
42
47
|
<span class="panel__note">Sends the page, your browser, and recent errors.</span>
|
|
43
48
|
<button id="cancel" class="ghost">Cancel</button>
|
|
44
49
|
<button id="send" class="primary">Send</button>
|
|
45
|
-
</div>`;let
|
|
50
|
+
</div>`;let o=[],r=e.querySelector("#files"),i=e.querySelector("#drop"),a=e.querySelector("#file"),s=()=>{r.innerHTML="",o.forEach((l,u)=>{var D;let f=document.createElement("div");f.className=l.error?"file file--bad":"file",f.innerHTML=l.preview?`<img src="${l.preview}" alt="" />`:'<span class="file__icon">\u25A6</span>';let A=document.createElement("span");A.className="file__name",A.textContent=(D=l.error)!=null?D:l.filename,f.appendChild(A);let v=document.createElement("button");v.className="link",v.textContent="\xD7",v.onclick=()=>{_([l]),o.splice(u,1),s()},f.appendChild(v),r.appendChild(f)}),i.style.display=o.length>=5?"none":""},c=l=>{o.push(...ne(l,o.length)),s()};a.onchange=()=>{a.files&&c(a.files)},e.querySelector("#browse").onclick=()=>a.click(),e.addEventListener("paste",l=>{let u=oe(l);u.length>0&&(l.preventDefault(),c(u))}),i.addEventListener("dragover",l=>{l.preventDefault(),i.classList.add("drop--over")}),i.addEventListener("dragleave",()=>i.classList.remove("drop--over")),i.addEventListener("drop",l=>{var u,f;l.preventDefault(),i.classList.remove("drop--over"),c(Array.from((f=(u=l.dataTransfer)==null?void 0:u.files)!=null?f:[]))});let d="bug";e.querySelectorAll(".kind").forEach(l=>{l.onclick=()=>{var u;d=(u=l.dataset.kind)!=null?u:"bug",e.querySelectorAll(".kind").forEach(f=>f.classList.remove("kind--on")),l.classList.add("kind--on")}});let p=e.querySelector("#message"),y=e.querySelector("#email"),b=(N=(B=this.reporter)==null?void 0:B.email)!=null?N:(K=this.options.reporter)==null?void 0:K.email;b&&!y.value&&(y.value=b);let w=e.querySelector("#shot"),m=e.querySelector("#status"),h=e.querySelector("#send"),q=()=>{_(o),this.mode="idle",this.anchor=null,this.render()};e.querySelector("#cancel").onclick=q,e.querySelector("#close").onclick=q;let O=async()=>{if(!p.value.trim()){m.textContent="Say what happened first.";return}h.disabled=!0,m.textContent="Sending\u2026";try{this.reference=await this.onSubmit({message:p.value.trim(),kind:d,email:y.value.trim()||void 0,anchor:this.anchor,withScreenshot:w.checked,files:o.filter(l=>!l.error)})||null,_(o),this.mode="sent",this.anchor=null,this.render()}catch(l){h.disabled=!1,m.textContent=l instanceof Error?`${l.message} \u2014 saved, will retry.`:"Failed, saved and will retry."}};return h.onclick=O,p.onkeydown=l=>{(l.metaKey||l.ctrlKey)&&l.key==="Enter"&&O()},setTimeout(()=>p.focus(),0),e}};async function Ee(n){var t;try{if((t=navigator.clipboard)!=null&&t.writeText)return await navigator.clipboard.writeText(n),!0}catch{}let e=document.createElement("textarea");e.value=n,e.setAttribute("readonly",""),e.style.cssText="position:fixed;top:0;left:0;width:1px;height:1px;opacity:0",document.body.appendChild(e);try{return e.select(),document.execCommand("copy")}catch{return!1}finally{e.remove()}}function ie(n){return n.replace(/[&<>"']/g,e=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[e])}var Te={"bottom-right":"--pm-left: auto; --pm-right: 16px; --pm-top: auto; --pm-bottom: 16px","bottom-left":"--pm-left: 16px; --pm-right: auto; --pm-top: auto; --pm-bottom: 16px","top-right":"--pm-left: auto; --pm-right: 16px; --pm-top: 16px; --pm-bottom: auto","top-left":"--pm-left: 16px; --pm-right: auto; --pm-top: 16px; --pm-bottom: auto"};function Se(n){return typeof n=="string"&&/^(#[0-9a-f]{3,8}|rgba?\([\d\s.,%/]+\)|hsla?\([\d\s.,%/deg]+\)|[a-z]{3,20})$/i.test(n.trim())}var Le=`
|
|
46
51
|
:host {
|
|
47
52
|
all: initial;
|
|
48
53
|
|
|
@@ -73,8 +78,17 @@
|
|
|
73
78
|
position: fixed; inset: 0; pointer-events: auto; cursor: crosshair;
|
|
74
79
|
background: rgba(23,23,23,.12);
|
|
75
80
|
}
|
|
81
|
+
/*
|
|
82
|
+
Bottom, not top.
|
|
83
|
+
|
|
84
|
+
At top:16px this landed on whatever the host puts at the top centre of their page \u2014 a logo, a
|
|
85
|
+
nav bar, a search field. We are a guest here and we do not know what is up there; on our own app
|
|
86
|
+
it covered the project switcher. The bottom centre is beside the launcher the reporter just
|
|
87
|
+
clicked, which is space the widget already owns, and it keeps their eyes near the thing they are
|
|
88
|
+
about to point at rather than sending them to the far edge of the screen and back.
|
|
89
|
+
*/
|
|
76
90
|
.hint {
|
|
77
|
-
position: fixed; left: 50%;
|
|
91
|
+
position: fixed; left: 50%; bottom: 76px; transform: translateX(-50%);
|
|
78
92
|
padding: 7px 12px; border-radius: 8px; background: #171717; color: #fafafa;
|
|
79
93
|
font-size: 12px; white-space: nowrap;
|
|
80
94
|
}
|
|
@@ -104,12 +118,27 @@ kbd {
|
|
|
104
118
|
.panel__close:hover { color: #171717 }
|
|
105
119
|
|
|
106
120
|
/* A confirmation, not a form. */
|
|
107
|
-
.panel--sent { display: flex; align-items:
|
|
121
|
+
.panel--sent { display: flex; align-items: flex-start; gap: 10px }
|
|
108
122
|
.sent__tick {
|
|
109
123
|
flex: none; width: 24px; height: 24px; border-radius: 999px;
|
|
110
124
|
background: #ecfdf5; color: #047857;
|
|
111
125
|
display: grid; place-items: center; font-size: 14px;
|
|
112
126
|
}
|
|
127
|
+
.sent__body { min-width: 0 }
|
|
128
|
+
|
|
129
|
+
/* The reference on its own line, at its own weight: it is the one thing here to take away. */
|
|
130
|
+
.sent__ref { display: flex; align-items: center; gap: 6px; margin: 4px 0 2px }
|
|
131
|
+
.sent__id {
|
|
132
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
|
|
133
|
+
color: #171717; background: #f5f5f5; border-radius: 5px; padding: 2px 6px;
|
|
134
|
+
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
|
135
|
+
}
|
|
136
|
+
.sent__copy {
|
|
137
|
+
flex: none; border: 1px solid #e5e5e5; border-radius: 6px; background: #fff;
|
|
138
|
+
color: #525252; cursor: pointer; font-size: 11px; padding: 3px 8px;
|
|
139
|
+
}
|
|
140
|
+
.sent__copy:hover { border-color: #a3a3a3; color: #171717 }
|
|
141
|
+
.sent__copy--done { border-color: #a7f3d0; background: #ecfdf5; color: #047857 }
|
|
113
142
|
|
|
114
143
|
.panel__kinds { display: flex; gap: 6px; margin: 8px 0 }
|
|
115
144
|
.kind {
|
|
@@ -159,4 +188,4 @@ textarea:focus, input:focus { outline: 2px solid #171717; outline-offset: -1px }
|
|
|
159
188
|
.file__icon { width: 28px; text-align: center }
|
|
160
189
|
.file__name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
|
|
161
190
|
.link { border: 0; background: transparent; color: #525252; cursor: pointer; font-size: 11px; text-decoration: underline }
|
|
162
|
-
`;var se="https://api.daybook.team",$=class{constructor(e){this.options=e;this.widget=null;this.started=!1;this.inFlight=null;this.epoch=0;this.ready=null;var t;if(!e.ingestKey)throw new Error("ingestKey is required");this.client=new E((t=e.apiUrl)!=null?t:se,e.ingestKey),this.trail=e.breadcrumbs===!1?null:new x(40,e.redact!==!1)}start(){var e;return(e=this.trail)==null||e.start(),this.mount(),this.started||(this.started=!0,this.client.flush()),this.handshake(),this}mount(){this.widget||(this.widget=new
|
|
191
|
+
`;var se="https://api.daybook.team",$=class{constructor(e){this.options=e;this.widget=null;this.started=!1;this.inFlight=null;this.epoch=0;this.ready=null;this.stopped=!1;var t;if(!e.ingestKey)throw new Error("ingestKey is required");this.client=new E((t=e.apiUrl)!=null?t:se,e.ingestKey),this.trail=e.breadcrumbs===!1?null:new x(40,e.redact!==!1)}start(){var e;return this.stopped=!1,(e=this.trail)==null||e.start(),this.mount(),this.started||(this.started=!0,this.client.flush()),this.handshake(),this}mount(){this.widget||this.stopped||(this.widget=new R(this.options,e=>this.submit(e)),this.widget.setReporter(this.options.reporter),this.widget.mount())}handshake(){var o,r,i;let e=JSON.stringify([(o=this.options.reporter)!=null?o:null,(r=this.options.signature)!=null?r:null,this.epoch]);if(((i=this.inFlight)==null?void 0:i.key)===e)return this.inFlight.promise;let t=this.runHandshake().finally(()=>{var a;((a=this.inFlight)==null?void 0:a.promise)===t&&(this.inFlight=null)});return this.inFlight={key:e,promise:t},t}async runHandshake(){var e,t,o,r,i,a;try{let s=await this.client.handshake({identity:this.options.reporter,signature:this.options.signature,locale:typeof navigator!="undefined"?navigator.language:void 0});if(this.ready=s,(t=(e=this.options).onReady)==null||t.call(e,s),s.reporterStatus==="Blocked"){(o=this.widget)==null||o.unmount(),this.widget=null;return}this.mount(),this.widget.setTheme(Re(s.theme)),this.widget.setState(s.reporterStatus==="Pending"?"pending":"ready")}catch(s){(i=(r=this.options).onError)==null||i.call(r,s),console.warn("[feedback] handshake failed; the widget will not appear",s),(a=this.widget)==null||a.unmount(),this.widget=null}}identify(e){var t;this.options={...this.options,reporter:e?{...this.options.reporter,...e}:void 0},(t=this.widget)==null||t.setReporter(this.options.reporter),this.widget&&this.handshake()}async signIn(){await this.client.signIn(),this.epoch++,await this.handshake()}authenticate(e){this.options={...this.options,signature:e!=null?e:void 0},this.widget&&this.handshake()}stop(){var e,t;this.started=!1,this.stopped=!0,(e=this.trail)==null||e.stop(),(t=this.widget)==null||t.unmount(),this.widget=null}open(){var e;(e=this.widget)==null||e.open()}async report(e,t={}){var o,r,i;return this.client.send({message:e,surface:this.options.surface,...t,context:{...U({breadcrumbs:(o=this.trail)==null?void 0:o.list(),app:this.options.app}),...(r=t.context)!=null?r:{}},reporter:(i=t.reporter)!=null?i:this.options.reporter})}async submit(e){var i,a,s,c,d;let t=e.withScreenshot&&this.options.screenshots!==!1?await G(this.options.redact!==!1):null,o=[...e.files,...t?[t]:[]],r={message:e.message,kind:e.kind,app:this.options.app,surface:this.options.surface,reporter:e.email?{...this.options.reporter,email:e.email}:this.options.reporter,context:U({anchor:e.anchor,breadcrumbs:(i=this.trail)==null?void 0:i.list(),app:this.options.app})};try{let p=await this.client.send(r,o);return(s=(a=this.options).onSent)==null||s.call(a,p),p.reference}catch(p){throw this.client.queue(r),(d=(c=this.options).onError)==null||d.call(c,p),p}}};function _e(n){return new $(n).start()}function Re(n){if(!n)return null;try{let e=JSON.parse(n);return e&&typeof e=="object"?e:null}catch{return null}}return he($e);})();
|
package/dist/index.d.ts
CHANGED
|
@@ -107,6 +107,7 @@ export declare class DaybookFeedback {
|
|
|
107
107
|
*/
|
|
108
108
|
authenticate(signature: string | null): void;
|
|
109
109
|
stop(): void;
|
|
110
|
+
private stopped;
|
|
110
111
|
/** Opens the picker programmatically, for a host app's own "Report a problem" menu item. */
|
|
111
112
|
open(): void;
|
|
112
113
|
/**
|
package/dist/index.js
CHANGED
|
@@ -60,6 +60,7 @@ export class DaybookFeedback {
|
|
|
60
60
|
this.epoch = 0;
|
|
61
61
|
/** The last handshake, for a host app that wants to explain a state in its own words. */
|
|
62
62
|
this.ready = null;
|
|
63
|
+
this.stopped = false;
|
|
63
64
|
if (!options.ingestKey)
|
|
64
65
|
throw new Error('ingestKey is required');
|
|
65
66
|
this.client = new IngestClient(options.apiUrl ?? DEFAULT_API_URL, options.ingestKey);
|
|
@@ -76,6 +77,7 @@ export class DaybookFeedback {
|
|
|
76
77
|
* running, not that there are two of them.
|
|
77
78
|
*/
|
|
78
79
|
start() {
|
|
80
|
+
this.stopped = false;
|
|
79
81
|
this.trail?.start();
|
|
80
82
|
this.mount();
|
|
81
83
|
// Once per session, not once per call. start() is called again by hosts that gate the widget on
|
|
@@ -99,7 +101,7 @@ export class DaybookFeedback {
|
|
|
99
101
|
* widget on it, which is the one flow that mode exists for.
|
|
100
102
|
*/
|
|
101
103
|
mount() {
|
|
102
|
-
if (this.widget)
|
|
104
|
+
if (this.widget || this.stopped)
|
|
103
105
|
return;
|
|
104
106
|
this.widget = new FeedbackWidget(this.options, input => this.submit(input));
|
|
105
107
|
this.widget.setReporter(this.options.reporter);
|
|
@@ -199,6 +201,18 @@ export class DaybookFeedback {
|
|
|
199
201
|
}
|
|
200
202
|
stop() {
|
|
201
203
|
this.started = false;
|
|
204
|
+
// Stopped means stopped, including against a handshake already in flight.
|
|
205
|
+
//
|
|
206
|
+
// A host that hides the widget from signed-out visitors calls init() and stop() within the same
|
|
207
|
+
// tick — init mounts and starts a handshake, the host's auth check then stops it, and the
|
|
208
|
+
// handshake resolved a moment later and called mount() again. The launcher came back on a page
|
|
209
|
+
// the host had deliberately taken it off, which on a public page means showing a stranger a
|
|
210
|
+
// control that was never meant for them.
|
|
211
|
+
//
|
|
212
|
+
// Not the same as the widget being unmounted by a REFUSED handshake: that path leaves this flag
|
|
213
|
+
// alone, so signIn() can still bring the widget back, which is the whole point of the Daybook
|
|
214
|
+
// identity mode.
|
|
215
|
+
this.stopped = true;
|
|
202
216
|
this.trail?.stop();
|
|
203
217
|
this.widget?.unmount();
|
|
204
218
|
this.widget = null;
|
package/dist/widget.d.ts
CHANGED
|
@@ -70,12 +70,29 @@ export declare class FeedbackWidget {
|
|
|
70
70
|
* What a reporter sees after Send.
|
|
71
71
|
*
|
|
72
72
|
* Closing silently answered "did that work?" with nothing, which is the one question everybody has
|
|
73
|
-
* — and it threw away the reference the wire contract deliberately makes human-quotable.
|
|
74
|
-
*
|
|
75
|
-
*
|
|
73
|
+
* — and it threw away the reference the wire contract deliberately makes human-quotable.
|
|
74
|
+
*
|
|
75
|
+
* The reference is quotable but it was not takeable: reading `PM-F-0033` off a toast and typing it
|
|
76
|
+
* into a chat window is transcription, and the reporter routinely wants to hand it straight to an
|
|
77
|
+
* assistant. So it comes with a copy button — which changes what the panel is. A bare
|
|
78
|
+
* acknowledgement should clear itself, because dismissing it is a chore for having done somebody a
|
|
79
|
+
* favour; a panel with something to press should not vanish while you are reaching for it. So it
|
|
80
|
+
* lingers longer, stops counting down the moment it is touched, and grows a close button so a
|
|
81
|
+
* stopped timer is never a trap.
|
|
76
82
|
*/
|
|
77
83
|
private sent;
|
|
78
84
|
private launcher;
|
|
79
85
|
private picker;
|
|
80
86
|
private composer;
|
|
81
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Copy, on the pages a widget actually runs on.
|
|
90
|
+
*
|
|
91
|
+
* navigator.clipboard is not there on http, in some embedded webviews, and in any context the host
|
|
92
|
+
* page has not marked secure — which is a fair description of where a bug gets reported from. The
|
|
93
|
+
* textarea fallback is the old way and still the only one that works in those places.
|
|
94
|
+
*
|
|
95
|
+
* The scratch textarea goes in the document, not the shadow root: execCommand copies the document's
|
|
96
|
+
* selection, and a selection made inside a shadow root is not the document's.
|
|
97
|
+
*/
|
|
98
|
+
export declare function copyText(text: string): Promise<boolean>;
|
package/dist/widget.js
CHANGED
|
@@ -149,29 +149,62 @@ export class FeedbackWidget {
|
|
|
149
149
|
* What a reporter sees after Send.
|
|
150
150
|
*
|
|
151
151
|
* Closing silently answered "did that work?" with nothing, which is the one question everybody has
|
|
152
|
-
* — and it threw away the reference the wire contract deliberately makes human-quotable.
|
|
153
|
-
*
|
|
154
|
-
*
|
|
152
|
+
* — and it threw away the reference the wire contract deliberately makes human-quotable.
|
|
153
|
+
*
|
|
154
|
+
* The reference is quotable but it was not takeable: reading `PM-F-0033` off a toast and typing it
|
|
155
|
+
* into a chat window is transcription, and the reporter routinely wants to hand it straight to an
|
|
156
|
+
* assistant. So it comes with a copy button — which changes what the panel is. A bare
|
|
157
|
+
* acknowledgement should clear itself, because dismissing it is a chore for having done somebody a
|
|
158
|
+
* favour; a panel with something to press should not vanish while you are reaching for it. So it
|
|
159
|
+
* lingers longer, stops counting down the moment it is touched, and grows a close button so a
|
|
160
|
+
* stopped timer is never a trap.
|
|
155
161
|
*/
|
|
156
162
|
sent() {
|
|
157
163
|
const note = document.createElement('div');
|
|
158
164
|
note.className = 'panel panel--sent';
|
|
159
165
|
note.setAttribute('role', 'status');
|
|
166
|
+
const reference = this.reference;
|
|
160
167
|
note.innerHTML = `
|
|
161
168
|
<div class="sent__tick" aria-hidden="true">✓</div>
|
|
162
|
-
<div>
|
|
169
|
+
<div class="sent__body">
|
|
163
170
|
<div class="panel__title">Thank you — that is on its way.</div>
|
|
164
|
-
${
|
|
165
|
-
? `<div class="
|
|
171
|
+
${reference
|
|
172
|
+
? `<div class="sent__ref">
|
|
173
|
+
<code class="sent__id">${escapeHtml(reference)}</code>
|
|
174
|
+
<button type="button" class="sent__copy" data-copy>Copy</button>
|
|
175
|
+
</div>
|
|
176
|
+
<div class="panel__anchor">Quote it if you follow it up.</div>`
|
|
166
177
|
: ''}
|
|
167
|
-
</div
|
|
168
|
-
|
|
178
|
+
</div>
|
|
179
|
+
${reference
|
|
180
|
+
? '<button type="button" class="panel__close" data-dismiss aria-label="Dismiss">×</button>'
|
|
181
|
+
: ''}`;
|
|
182
|
+
const dismiss = () => {
|
|
169
183
|
if (this.mode !== 'sent')
|
|
170
184
|
return;
|
|
171
185
|
this.mode = 'idle';
|
|
172
186
|
this.render();
|
|
173
|
-
}
|
|
187
|
+
};
|
|
188
|
+
const close = window.setTimeout(dismiss, reference ? 12000 : 6000);
|
|
189
|
+
const hold = () => window.clearTimeout(close);
|
|
174
190
|
this.detach.push(() => window.clearTimeout(close));
|
|
191
|
+
if (!reference)
|
|
192
|
+
return note;
|
|
193
|
+
note.addEventListener('pointerenter', hold);
|
|
194
|
+
note.addEventListener('focusin', hold);
|
|
195
|
+
note.querySelector('[data-dismiss]')?.addEventListener('click', dismiss);
|
|
196
|
+
const copy = note.querySelector('[data-copy]');
|
|
197
|
+
if (copy) {
|
|
198
|
+
copy.onclick = async () => {
|
|
199
|
+
hold();
|
|
200
|
+
// Said either way. A copy button that reports nothing leaves the reporter pressing it
|
|
201
|
+
// twice to find out, and one that claims success it did not have is worse than one that
|
|
202
|
+
// admits the page would not allow it — the reference is still on screen to read.
|
|
203
|
+
const ok = await copyText(reference);
|
|
204
|
+
copy.textContent = ok ? 'Copied' : 'Copy failed';
|
|
205
|
+
copy.classList.toggle('sent__copy--done', ok);
|
|
206
|
+
};
|
|
207
|
+
}
|
|
175
208
|
return note;
|
|
176
209
|
}
|
|
177
210
|
launcher() {
|
|
@@ -384,6 +417,42 @@ export class FeedbackWidget {
|
|
|
384
417
|
return panel;
|
|
385
418
|
}
|
|
386
419
|
}
|
|
420
|
+
/**
|
|
421
|
+
* Copy, on the pages a widget actually runs on.
|
|
422
|
+
*
|
|
423
|
+
* navigator.clipboard is not there on http, in some embedded webviews, and in any context the host
|
|
424
|
+
* page has not marked secure — which is a fair description of where a bug gets reported from. The
|
|
425
|
+
* textarea fallback is the old way and still the only one that works in those places.
|
|
426
|
+
*
|
|
427
|
+
* The scratch textarea goes in the document, not the shadow root: execCommand copies the document's
|
|
428
|
+
* selection, and a selection made inside a shadow root is not the document's.
|
|
429
|
+
*/
|
|
430
|
+
export async function copyText(text) {
|
|
431
|
+
try {
|
|
432
|
+
if (navigator.clipboard?.writeText) {
|
|
433
|
+
await navigator.clipboard.writeText(text);
|
|
434
|
+
return true;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
catch {
|
|
438
|
+
// Denied by permissions policy or not focused. The fallback below still often works.
|
|
439
|
+
}
|
|
440
|
+
const scratch = document.createElement('textarea');
|
|
441
|
+
scratch.value = text;
|
|
442
|
+
scratch.setAttribute('readonly', '');
|
|
443
|
+
scratch.style.cssText = 'position:fixed;top:0;left:0;width:1px;height:1px;opacity:0';
|
|
444
|
+
document.body.appendChild(scratch);
|
|
445
|
+
try {
|
|
446
|
+
scratch.select();
|
|
447
|
+
return document.execCommand('copy');
|
|
448
|
+
}
|
|
449
|
+
catch {
|
|
450
|
+
return false;
|
|
451
|
+
}
|
|
452
|
+
finally {
|
|
453
|
+
scratch.remove();
|
|
454
|
+
}
|
|
455
|
+
}
|
|
387
456
|
function escapeHtml(value) {
|
|
388
457
|
return value.replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]);
|
|
389
458
|
}
|
|
@@ -446,8 +515,17 @@ const STYLES = `
|
|
|
446
515
|
position: fixed; inset: 0; pointer-events: auto; cursor: crosshair;
|
|
447
516
|
background: rgba(23,23,23,.12);
|
|
448
517
|
}
|
|
518
|
+
/*
|
|
519
|
+
Bottom, not top.
|
|
520
|
+
|
|
521
|
+
At top:16px this landed on whatever the host puts at the top centre of their page — a logo, a
|
|
522
|
+
nav bar, a search field. We are a guest here and we do not know what is up there; on our own app
|
|
523
|
+
it covered the project switcher. The bottom centre is beside the launcher the reporter just
|
|
524
|
+
clicked, which is space the widget already owns, and it keeps their eyes near the thing they are
|
|
525
|
+
about to point at rather than sending them to the far edge of the screen and back.
|
|
526
|
+
*/
|
|
449
527
|
.hint {
|
|
450
|
-
position: fixed; left: 50%;
|
|
528
|
+
position: fixed; left: 50%; bottom: 76px; transform: translateX(-50%);
|
|
451
529
|
padding: 7px 12px; border-radius: 8px; background: #171717; color: #fafafa;
|
|
452
530
|
font-size: 12px; white-space: nowrap;
|
|
453
531
|
}
|
|
@@ -477,12 +555,27 @@ kbd {
|
|
|
477
555
|
.panel__close:hover { color: #171717 }
|
|
478
556
|
|
|
479
557
|
/* A confirmation, not a form. */
|
|
480
|
-
.panel--sent { display: flex; align-items:
|
|
558
|
+
.panel--sent { display: flex; align-items: flex-start; gap: 10px }
|
|
481
559
|
.sent__tick {
|
|
482
560
|
flex: none; width: 24px; height: 24px; border-radius: 999px;
|
|
483
561
|
background: #ecfdf5; color: #047857;
|
|
484
562
|
display: grid; place-items: center; font-size: 14px;
|
|
485
563
|
}
|
|
564
|
+
.sent__body { min-width: 0 }
|
|
565
|
+
|
|
566
|
+
/* The reference on its own line, at its own weight: it is the one thing here to take away. */
|
|
567
|
+
.sent__ref { display: flex; align-items: center; gap: 6px; margin: 4px 0 2px }
|
|
568
|
+
.sent__id {
|
|
569
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
|
|
570
|
+
color: #171717; background: #f5f5f5; border-radius: 5px; padding: 2px 6px;
|
|
571
|
+
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
|
572
|
+
}
|
|
573
|
+
.sent__copy {
|
|
574
|
+
flex: none; border: 1px solid #e5e5e5; border-radius: 6px; background: #fff;
|
|
575
|
+
color: #525252; cursor: pointer; font-size: 11px; padding: 3px 8px;
|
|
576
|
+
}
|
|
577
|
+
.sent__copy:hover { border-color: #a3a3a3; color: #171717 }
|
|
578
|
+
.sent__copy--done { border-color: #a7f3d0; background: #ecfdf5; color: #047857 }
|
|
486
579
|
|
|
487
580
|
.panel__kinds { display: flex; gap: 6px; margin: 8px 0 }
|
|
488
581
|
.kind {
|
package/package.json
CHANGED