@inputbuffer/feedback 0.2.0 → 0.3.1

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/dist/bar.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";(()=>{var C=class extends Error{constructor(i){super(i.detail),this.name="ApiError",this.type=i.type,this.status=i.status,this.detail=i.detail,this.category=i.category,this.field=i.field}};var N="0.2.0",ee="https://inputbuffer.io/api/v0/inputs";async function W(t,i,s,g,d,h){var p,u,v,n;let l={description:i};if(g&&(l.title=g),s&&(l.contact_email=s),d!=null&&d.source&&(l.source=d.source),d!=null&&d.target){let o=d.target;l.targets=[{type:o.type,metadata:o.metadata}]}let a=new AbortController,x=setTimeout(()=>a.abort(),1e4),r;try{r=await fetch(h!=null?h:ee,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json","X-IB-Client":`inputbuffer-widget/${N} (javascript)`},body:JSON.stringify(l),credentials:"omit",signal:a.signal})}finally{clearTimeout(x)}if(!r.ok){let o=await r.json().catch(()=>({}));throw new C({type:(p=o.type)!=null?p:"https://inputbuffer.io/problems/internal-error",title:(u=o.title)!=null?u:"Error",detail:(v=o.detail)!=null?v:"Submission failed. Please try again.",status:(n=o.status)!=null?n:r.status,category:o.category,field:o.field})}let{data:c}=await r.json();return{id:c.id}}var te="https://inputbuffer.io/api/v0/reactions";async function U(t,i,s,g,d){var c,p,u,v;let h=d?d.replace(/\/inputs$/,"/reactions"):te,l={reaction_value:i,target:{type:s.type,metadata:s.metadata}};g&&(l.user_id=g);let a=new AbortController,x=setTimeout(()=>a.abort(),1e4),r;try{r=await fetch(h,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json","X-IB-Client":`inputbuffer-widget/${N} (javascript)`},body:JSON.stringify(l),credentials:"omit",signal:a.signal})}finally{clearTimeout(x)}if(!r.ok){let n=await r.json().catch(()=>({}));throw new C({type:(c=n.type)!=null?c:"https://inputbuffer.io/problems/internal-error",title:(p=n.title)!=null?p:"Error",detail:(u=n.detail)!=null?u:"Submission failed. Please try again.",status:(v=n.status)!=null?v:r.status,category:n.category,field:n.field})}}function V(t){let i=document.createElementNS("http://www.w3.org/2000/svg","svg");i.setAttribute("viewBox","0 0 24 24"),i.setAttribute("width","18"),i.setAttribute("height","18"),i.setAttribute("fill","currentColor"),i.setAttribute("aria-hidden","true"),i.style.display="block";let s=document.createElementNS("http://www.w3.org/2000/svg","path");return s.setAttribute("d",t),i.appendChild(s),i}var re="M9 21h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-2c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.59 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2zM9 9l4.34-4.34L12 10h9v2l-3 7H9V9zM1 9h2v12H1z",ie="M15 3H6c-.83 0-1.54.5-1.84 1.22l-3.02 7.05c-.09.23-.14.47-.14.73v2c0 1.1.9 2 2 2h6.31l-.95 4.57-.03.32c0 .41.17.79.44 1.06L10.83 23l6.59-6.59c.36-.36.58-.86.58-1.41V5c0-1.1-.9-2-2-2zm0 12l-4.34 4.34L12 14H3v-2l3-7h9v10zm4-12h2v12h-2z",ae=24*60*60*1e3;function O(t){var $,K;let i;function s(){let e=t.target;return e?`ib:reaction:${t.apiKey}:${e.type}:${JSON.stringify(e.metadata)}`:`ib:reaction:${t.apiKey}:${window.location.pathname}`}function g(){try{let e=localStorage.getItem(s());if(!e)return null;let{sentiment:f,ts:m}=JSON.parse(e);return Date.now()-m>ae?(localStorage.removeItem(s()),null):f}catch{return null}}function d(e){try{localStorage.setItem(s(),JSON.stringify({sentiment:e,ts:Date.now()}))}catch{}}let h={vote:[],open:[],submit:[],close:[],error:[]};function l(e,f){var m;(m=h[e])==null||m.forEach(B=>B(f))}let a=document.createElement("div"),x=t.colorScheme==="dark"?" ib-theme-dark":t.colorScheme==="light"?" ib-theme-light":"";a.className="ib-bar-wrapper"+(t.placement==="fixed"?" ib-bar-wrapper--fixed":"")+x;let{theme:r={}}=t;r.primary&&a.style.setProperty("--ib-primary",r.primary),r.background&&a.style.setProperty("--ib-background",r.background),r.surface&&a.style.setProperty("--ib-surface",r.surface),r.text&&a.style.setProperty("--ib-text",r.text),r.selected&&a.style.setProperty("--ib-selected",r.selected),r.selectedColor&&a.style.setProperty("--ib-selected-color",r.selectedColor);let c=document.createElement("div");c.className="ib-bar";let p=document.createElement("div");p.className="ib-bar-label-area";let u=document.createElement("span");u.className="ib-bar-label",u.textContent=($=t.label)!=null?$:"Was this helpful?",p.appendChild(u);let v=document.createElement("div");v.className="ib-bar-actions"+(t.showLabel===!1?" ib-bar-actions--no-label":"");let n=document.createElement("button");n.type="button",n.className="ib-bar-btn ib-bar-btn--up",n.setAttribute("aria-label","Yes"),n.appendChild(V(re));let o=document.createElement("button");o.type="button",o.className="ib-bar-btn ib-bar-btn--down",o.setAttribute("aria-label","No"),o.appendChild(V(ie)),v.appendChild(n),v.appendChild(o),t.showLabel!==!1&&c.appendChild(p),c.appendChild(v);let b=document.createElement("div");b.className="ib-bar-popover",b.setAttribute("role","dialog"),b.setAttribute("aria-modal","false");let F=document.createElement("div");if(F.className="ib-bar-header",t.modalTitle){b.setAttribute("aria-labelledby","ib-bar-title");let e=document.createElement("p");e.id="ib-bar-title",e.className="ib-bar-title",e.textContent=t.modalTitle,F.appendChild(e)}else b.setAttribute("aria-label","Feedback");let w=document.createElement("div");w.className="ib-bar-body";let k=document.createElement("textarea");k.className="ib-bar-textarea",k.placeholder=(K=t.modalPlaceholder)!=null?K:"What's on your mind?",k.setAttribute("aria-label","Feedback");let S=document.createElement("p");S.className="ib-bar-error";let I=document.createElement("p");I.className="ib-bar-success";let y=document.createElement("button");if(y.type="button",y.className="ib-bar-submit",y.textContent="Send feedback",t.showTitleField===!0){let e=document.createElement("input");e.type="text",e.className="ib-bar-title-input",e.placeholder="Title (optional)",e.setAttribute("aria-label","Feedback title"),w.appendChild(e)}if(w.appendChild(k),t.showEmailField===!0){let e=document.createElement("input");e.type="email",e.className="ib-bar-email",e.placeholder="Your email (optional)",e.setAttribute("aria-label","Email address"),w.appendChild(e)}w.appendChild(S),w.appendChild(I);let L=document.createElement("div");L.className="ib-bar-footer",L.appendChild(y);let P=document.createElement("div");P.className="ib-branding";let T=document.createElement("a");T.href="https://inputbuffer.io",T.target="_blank",T.rel="noopener noreferrer",T.textContent="Powered by inputbuffer.io",P.appendChild(T),L.appendChild(P),w.appendChild(L),b.appendChild(F),b.appendChild(w),a.appendChild(b),a.appendChild(c);function A(){let e=c.getBoundingClientRect();b.style.top=`${e.top-b.offsetHeight-8}px`,b.style.left=`${e.right-320}px`}function q(e){i=e,b.classList.add("ib-bar-popover--visible"),requestAnimationFrame(A),S.textContent="",I.textContent="",k.focus(),setTimeout(()=>document.addEventListener("click",j),0),document.addEventListener("keydown",D),window.addEventListener("scroll",A,{passive:!0}),window.addEventListener("resize",A,{passive:!0}),l("open",{sentiment:e})}function _(){b.classList.contains("ib-bar-popover--visible")&&(b.classList.remove("ib-bar-popover--visible"),document.removeEventListener("click",j),document.removeEventListener("keydown",D),window.removeEventListener("scroll",A),window.removeEventListener("resize",A),k.value="",l("close"))}function X(){n.classList.remove("ib-bar-btn--active"),o.classList.remove("ib-bar-btn--active"),i=void 0}function j(e){a.contains(e.target)||_()}function D(e){e.key==="Escape"&&_()}async function Y(){let e=k.value.trim();if(e.length<10){S.textContent="Please enter at least 10 characters.";return}S.textContent="",y.disabled=!0,y.textContent="Sending\u2026";let f=b.querySelector(".ib-bar-title-input"),m=(f==null?void 0:f.value.trim())||null,B=b.querySelector(".ib-bar-email"),Q=(B==null?void 0:B.value.trim())||null;try{let E=await W(t.apiKey,e,Q,m,{sentiment:i,target:t.target,source:t.source},t.apiUrl);l("submit",E),I.textContent="Thanks for your feedback!",y.textContent="Send feedback",setTimeout(()=>{_(),X()},2e3)}catch(E){l("error",E instanceof Error?E:new Error("Something went wrong."));let Z=E instanceof C&&E.category==="user"?E.detail:"Something went wrong. Please try again.";S.textContent=Z,y.disabled=!1,y.textContent="Send feedback"}}function M(e){n.classList.remove("ib-bar-btn--active"),o.classList.remove("ib-bar-btn--active"),e.classList.add("ib-bar-btn--active")}let z=g();z&&(i=z,M(z==="positive"?n:o));function H(e,f){var m;d(e),M(f),q(e),l("vote",{sentiment:e}),t.target&&U(t.apiKey,e==="positive"?1:-1,t.target,(m=t.userId)!=null?m:null,t.apiUrl).catch(()=>{})}return n.addEventListener("click",()=>H("positive",n)),o.addEventListener("click",()=>H("negative",o)),y.addEventListener("click",Y),{element:a,on(e,f){var m;(m=h[e])==null||m.push(f)},destroy(){_(),a.remove()}}}var G=`/* InputBuffer Feedback Bar Styles
1
+ "use strict";(()=>{var x=class extends Error{constructor(t){super(t.detail),this.name="ApiError",this.type=t.type,this.title=t.title,this.status=t.status,this.detail=t.detail,this.category=t.category,this.field=t.field}};var K="Something went wrong. Please try again.";function V(e){return e instanceof x?e.category==="user"?e.detail:(e.category==="integration"&&w(`${e.title}: ${e.detail}`,e.type),K):K}function w(e,t){typeof console!="undefined"&&console.warn(`[inputbuffer] ${e}`,t!=null?t:"")}var z="0.3.1",ae="https://inputbuffer.io",se="/api/v0/feedback",de="/api/v0/reactions",ce=1e4,le=5e3,be=500,pe=300;function q(e,t){return`${(e!=null?e:ae).replace(/\/+$/,"")}${t}`}async function G(e,t,i){var b,a,p,d;let n=new AbortController,l=setTimeout(()=>n.abort(),ce),s;try{s=await fetch(e,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json","X-IB-Client":`inputbuffer-widget/${z} (javascript)`},body:JSON.stringify(i),credentials:"omit",signal:n.signal})}finally{clearTimeout(l)}if(!s.ok){let u=await s.json().catch(()=>({}));throw new x({type:(b=u.type)!=null?b:"https://inputbuffer.io/docs/api/problems/internal-error",title:(a=u.title)!=null?a:"Error",detail:(p=u.detail)!=null?p:"Submission failed. Please try again.",status:(d=u.status)!=null?d:s.status,category:u.category,field:u.field})}return s}async function J(e,t,i,n,l){let s={description:t.slice(0,le)};if(i&&(s.title=i.slice(0,be)),n!=null&&n.submittedBy&&(s.submitted_by=n.submittedBy.slice(0,pe)),n!=null&&n.target){let p=n.target;s.targets=[{type:p.type,metadata:p.metadata}]}let b=await G(q(l,se),e,s),{data:a}=await b.json();return{id:a.id}}async function X(e,t,i,n,l){let s={reaction_value:t,target:{type:i.type,metadata:i.metadata}};n&&(s.user_id=n);let b;try{b=await G(q(l,de),e,s)}catch(p){throw p instanceof x&&p.status===422&&p.field==="user_id"&&w("Reaction rejected: no user_id and no client IP. Set the `userId` option (or the `user-id` attribute)."),p}let{data:a}=await b.json();return a}function Y(e){let t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("viewBox","0 0 24 24"),t.setAttribute("width","18"),t.setAttribute("height","18"),t.setAttribute("fill","currentColor"),t.setAttribute("aria-hidden","true"),t.style.display="block";let i=document.createElementNS("http://www.w3.org/2000/svg","path");return i.setAttribute("d",e),t.appendChild(i),t}var ue="M9 21h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-2c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.59 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2zM9 9l4.34-4.34L12 10h9v2l-3 7H9V9zM1 9h2v12H1z",me="M15 3H6c-.83 0-1.54.5-1.84 1.22l-3.02 7.05c-.09.23-.14.47-.14.73v2c0 1.1.9 2 2 2h6.31l-.95 4.57-.03.32c0 .41.17.79.44 1.06L10.83 23l6.59-6.59c.36-.36.58-.86.58-1.41V5c0-1.1-.9-2-2-2zm0 12l-4.34 4.34L12 14H3v-2l3-7h9v10zm4-12h2v12h-2z",fe=1440*60*1e3;function O(e){var $,W;let t;function i(){let r=e.target;return r?`ib:reaction:${e.apiKey}:${r.type}:${JSON.stringify(r.metadata)}`:`ib:reaction:${e.apiKey}:${window.location.pathname}`}function n(){try{let r=localStorage.getItem(i());if(!r)return null;let{sentiment:f,ts:m}=JSON.parse(r);return Date.now()-m>fe?(localStorage.removeItem(i()),null):f}catch{return null}}function l(r){try{localStorage.setItem(i(),JSON.stringify({sentiment:r,ts:Date.now()}))}catch{}}let s={vote:[],open:[],submit:[],close:[],error:[]};function b(r,f){var m;(m=s[r])==null||m.forEach(E=>E(f))}let a=document.createElement("div"),p=e.colorScheme==="dark"?" ib-theme-dark":e.colorScheme==="light"?" ib-theme-light":"";a.className="ib-bar-wrapper"+(e.placement==="fixed"?" ib-bar-wrapper--fixed":"")+p;let{theme:d={}}=e;d.primary&&a.style.setProperty("--ib-primary",d.primary),d.background&&a.style.setProperty("--ib-background",d.background),d.surface&&a.style.setProperty("--ib-surface",d.surface),d.text&&a.style.setProperty("--ib-text",d.text),d.selected&&a.style.setProperty("--ib-selected",d.selected),d.selectedColor&&a.style.setProperty("--ib-selected-color",d.selectedColor);let u=document.createElement("div");u.className="ib-bar";let F=document.createElement("div");F.className="ib-bar-label-area";let L=document.createElement("span");L.className="ib-bar-label",L.textContent=($=e.label)!=null?$:"Was this helpful?",F.appendChild(L);let B=document.createElement("div");B.className="ib-bar-actions"+(e.showLabel===!1?" ib-bar-actions--no-label":"");let g=document.createElement("button");g.type="button",g.className="ib-bar-btn ib-bar-btn--up",g.setAttribute("aria-label","Yes"),g.appendChild(Y(ue));let h=document.createElement("button");h.type="button",h.className="ib-bar-btn ib-bar-btn--down",h.setAttribute("aria-label","No"),h.appendChild(Y(me)),B.appendChild(g),B.appendChild(h),e.showLabel!==!1&&u.appendChild(F),u.appendChild(B);let c=document.createElement("div");c.className="ib-bar-popover",c.setAttribute("role","dialog"),c.setAttribute("aria-modal","false");let P=document.createElement("div");if(P.className="ib-bar-header",e.modalTitle){c.setAttribute("aria-labelledby","ib-bar-title");let r=document.createElement("p");r.id="ib-bar-title",r.className="ib-bar-title",r.textContent=e.modalTitle,P.appendChild(r)}else c.setAttribute("aria-label","Feedback");let k=document.createElement("div");k.className="ib-bar-body";let y=document.createElement("textarea");y.className="ib-bar-textarea",y.placeholder=(W=e.modalPlaceholder)!=null?W:"What's on your mind?",y.maxLength=5e3,y.setAttribute("aria-label","Feedback");let C=document.createElement("p");C.className="ib-bar-error";let _=document.createElement("p");_.className="ib-bar-success";let v=document.createElement("button");if(v.type="button",v.className="ib-bar-submit",v.textContent="Send feedback",e.showTitleField===!0){let r=document.createElement("input");r.type="text",r.className="ib-bar-title-input",r.placeholder="Title (optional)",r.maxLength=500,r.setAttribute("aria-label","Feedback title"),k.appendChild(r)}k.appendChild(y),k.appendChild(C),k.appendChild(_);let A=document.createElement("div");A.className="ib-bar-footer",A.appendChild(v);let R=document.createElement("div");R.className="ib-branding";let T=document.createElement("a");T.href="https://inputbuffer.io",T.target="_blank",T.rel="noopener noreferrer",T.textContent="Powered by inputbuffer.io",R.appendChild(T),A.appendChild(R),k.appendChild(A),c.appendChild(P),c.appendChild(k),a.appendChild(c),a.appendChild(u);function S(){let r=u.getBoundingClientRect();c.style.top=`${r.top-c.offsetHeight-8}px`,c.style.left=`${r.right-320}px`}function ie(r){t=r,c.classList.add("ib-bar-popover--visible"),requestAnimationFrame(S),C.textContent="",_.textContent="",y.focus(),setTimeout(()=>document.addEventListener("click",M),0),document.addEventListener("keydown",D),window.addEventListener("scroll",S,{passive:!0}),window.addEventListener("resize",S,{passive:!0}),b("open",{sentiment:r})}function I(){c.classList.contains("ib-bar-popover--visible")&&(c.classList.remove("ib-bar-popover--visible"),document.removeEventListener("click",M),document.removeEventListener("keydown",D),window.removeEventListener("scroll",S),window.removeEventListener("resize",S),y.value="",b("close"))}function ne(){g.classList.remove("ib-bar-btn--active"),h.classList.remove("ib-bar-btn--active"),t=void 0}function M(r){a.contains(r.target)||I()}function D(r){r.key==="Escape"&&I()}async function oe(){let r=y.value.trim();if(r.length<10){C.textContent="Please enter at least 10 characters.";return}C.textContent="",v.disabled=!0,v.textContent="Sending\u2026";let f=c.querySelector(".ib-bar-title-input"),m=(f==null?void 0:f.value.trim())||null;try{let E=await J(e.apiKey,r,m,{sentiment:t,target:e.target,submittedBy:e.submittedBy},e.apiUrl);b("submit",E),_.textContent="Thanks for your feedback!",v.textContent="Send feedback",setTimeout(()=>{I(),ne()},2e3)}catch(E){b("error",E instanceof Error?E:new Error("Something went wrong.")),C.textContent=V(E),v.disabled=!1,v.textContent="Send feedback"}}function H(r){g.classList.remove("ib-bar-btn--active"),h.classList.remove("ib-bar-btn--active"),r.classList.add("ib-bar-btn--active")}let N=n();N&&(t=N,H(N==="positive"?g:h));function U(r,f){var m;l(r),H(f),ie(r),b("vote",{sentiment:r}),e.target&&X(e.apiKey,r==="positive"?1:-1,e.target,(m=e.userId)!=null?m:null,e.apiUrl).catch(()=>{})}return g.addEventListener("click",()=>U("positive",g)),h.addEventListener("click",()=>U("negative",h)),v.addEventListener("click",oe),{element:a,on(r,f){var m;(m=s[r])==null||m.push(f)},destroy(){I(),a.remove()}}}function o(e,t){var i;return(i=e.getAttribute(t))!=null?i:void 0}function Q(e,t){let i=e.getAttribute(t);return i===null?void 0:i==="true"}function ge(e){return{primary:o(e,"theme-primary"),background:o(e,"theme-background"),text:o(e,"theme-text"),selected:o(e,"theme-selected"),selectedColor:o(e,"theme-selected-color")}}function he(e){var i;let t=e.getAttribute("target-type");if(t)switch(t){case"documentation":{let n=(i=o(e,"target-page-url"))!=null?i:typeof window!="undefined"?window.location.href:void 0;if(!n){w('target-type="documentation" needs target-page-url. Ignoring the target.');return}return{type:"documentation",metadata:{page_url:n,section_heading:o(e,"target-section-heading"),doc_version:o(e,"target-doc-version")}}}case"rest_endpoint":{let n=o(e,"target-method"),l=o(e,"target-path");if(!n||!l){w('target-type="rest_endpoint" needs target-method and target-path. Ignoring the target.');return}return{type:"rest_endpoint",metadata:{method:n,path:l,host:o(e,"target-host"),api_version:o(e,"target-api-version")}}}case"cli_command":{let n=o(e,"target-command");if(!n){w('target-type="cli_command" needs target-command. Ignoring the target.');return}let l=o(e,"target-args");return{type:"cli_command",metadata:{command:n,subcommand:o(e,"target-subcommand"),cli_version:o(e,"target-cli-version"),args:l?l.split(",").map(s=>s.trim()).filter(Boolean):void 0}}}default:w(`Unknown target-type "${t}". Expected documentation, rest_endpoint, or cli_command.`);return}}function Z(e,t){return{apiKey:t,apiUrl:o(e,"api-url"),label:o(e,"label"),showLabel:Q(e,"show-label"),placement:e.getAttribute("placement")==="fixed"?"fixed":"inline",colorScheme:o(e,"color-scheme"),modalTitle:o(e,"modal-title"),modalPlaceholder:o(e,"modal-placeholder"),showTitleField:Q(e,"show-title-field"),submittedBy:o(e,"submitted-by"),userId:o(e,"user-id"),target:he(e),theme:ge(e)}}function ee(e){return e.getAttribute("inject-styles")!=="false"}var te=`/* InputBuffer Feedback Bar Styles
2
2
  * .ib-bar-* and .ib-bar-popover* classes are stable public API \u2014 do not rename them.
3
3
  * Developers may target these classes from their own stylesheets to customize the widget.
4
4
  */
@@ -106,8 +106,7 @@
106
106
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--ib-focus-color) 15%, transparent);
107
107
  }
108
108
 
109
- .ib-bar-wrapper .ib-bar-body .ib-bar-title-input,
110
- .ib-bar-wrapper .ib-bar-body .ib-bar-email {
109
+ .ib-bar-wrapper .ib-bar-body .ib-bar-title-input {
111
110
  width: 100%;
112
111
  background: var(--ib-background);
113
112
  border: 1px solid var(--ib-border);
@@ -125,17 +124,11 @@
125
124
  margin-bottom: 8px;
126
125
  }
127
126
 
128
- .ib-bar-email {
129
- margin-top: 8px;
130
- }
131
-
132
- .ib-bar-wrapper .ib-bar-body .ib-bar-title-input:hover,
133
- .ib-bar-wrapper .ib-bar-body .ib-bar-email:hover {
127
+ .ib-bar-wrapper .ib-bar-body .ib-bar-title-input:hover {
134
128
  border-color: var(--ib-input-hover-border);
135
129
  }
136
130
 
137
- .ib-bar-wrapper .ib-bar-body .ib-bar-title-input:focus,
138
- .ib-bar-wrapper .ib-bar-body .ib-bar-email:focus {
131
+ .ib-bar-wrapper .ib-bar-body .ib-bar-title-input:focus {
139
132
  border-color: var(--ib-focus-color);
140
133
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--ib-focus-color) 15%, transparent);
141
134
  }
@@ -319,4 +312,4 @@
319
312
  --ib-radius: 8px;
320
313
  --ib-radius-input: 4px;
321
314
  }
322
- `;function J(){if(typeof document=="undefined"||document.getElementById("ib-bar-styles"))return;let t=document.createElement("style");t.id="ib-bar-styles",t.textContent=G,document.head.appendChild(t)}function oe(t){return t.injectStyles!==!1&&J(),O(t)}var R=class extends HTMLElement{constructor(){super(...arguments);this._bar=null}connectedCallback(){var l,a,x,r,c,p,u;let s=this.getAttribute("api-key");if(!s)return;let g=this.getAttribute("inject-styles");(g===null?!0:g!=="false")&&J();let h=this.getAttribute("placement");this._bar=O({apiKey:s,apiUrl:(l=this.getAttribute("api-url"))!=null?l:void 0,label:(a=this.getAttribute("label"))!=null?a:void 0,placement:h==="fixed"?"fixed":"inline",theme:{primary:(x=this.getAttribute("theme-primary"))!=null?x:void 0,background:(r=this.getAttribute("theme-background"))!=null?r:void 0,text:(c=this.getAttribute("theme-text"))!=null?c:void 0,selected:(p=this.getAttribute("theme-selected"))!=null?p:void 0,selectedColor:(u=this.getAttribute("theme-selected-color"))!=null?u:void 0}}),this.appendChild(this._bar.element)}disconnectedCallback(){var s;(s=this._bar)==null||s.destroy(),this._bar=null}};typeof customElements!="undefined"&&!customElements.get("inputbuffer-feedback")&&customElements.define("inputbuffer-feedback",R);var se={createBar:oe,version:N};typeof window!="undefined"&&(window.InputBufferIO=se);})();
315
+ `;function re(){if(typeof document=="undefined"||document.getElementById("ib-bar-styles"))return;let e=document.createElement("style");e.id="ib-bar-styles",e.textContent=te,document.head.appendChild(e)}function ye(e){return e.injectStyles!==!1&&re(),O(e)}var j=class extends HTMLElement{constructor(){super(...arguments);this._bar=null}connectedCallback(){let i=this.getAttribute("api-key");i&&(ee(this)&&re(),this._bar=O(Z(this,i)),this.appendChild(this._bar.element))}disconnectedCallback(){var i;(i=this._bar)==null||i.destroy(),this._bar=null}};typeof customElements!="undefined"&&!customElements.get("inputbuffer-feedback")&&customElements.define("inputbuffer-feedback",j);var xe={createBar:ye,version:z};typeof window!="undefined"&&(window.InputBufferIO=xe);})();
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Picks the message to show the person filling in the form.
3
+ *
4
+ * `category: 'user'` means they sent something the API rejected (a too-long field, too many
5
+ * requests), so `detail` is written for them. `category: 'integration'` means the embed is
6
+ * misconfigured — a full-access token in a browser, an origin that isn't allowlisted, an
7
+ * exhausted plan. Showing that to an end user is noise, but swallowing it leaves the developer
8
+ * with no way to diagnose the form, so it goes to the console instead.
9
+ */
10
+ export declare function userFacingMessage(err: unknown): string;
11
+ export declare function warn(message: string, detail?: string): void;
package/dist/index.d.ts CHANGED
@@ -15,4 +15,6 @@ declare global {
15
15
  }
16
16
  }
17
17
  export type { WidgetConfig, OpenOptions, WidgetInstance, FeedbackBarConfig, FeedbackBarInstance };
18
+ export type { TargetSpec, RestEndpointTarget, DocumentationTarget, CliCommandTarget, TargetRef, ReactionResult, ProblemDetails, ProblemType, } from './types.js';
19
+ export { ApiError } from './types.js';
18
20
  export { InputBufferIO };
@@ -5,4 +5,6 @@ declare const InputBufferIO: {
5
5
  version: string;
6
6
  };
7
7
  export type { WidgetConfig, OpenOptions, WidgetInstance };
8
+ export type { TargetSpec, RestEndpointTarget, DocumentationTarget, CliCommandTarget, ProblemDetails, ProblemType, } from './types.js';
9
+ export { ApiError } from './types.js';
8
10
  export { InputBufferIO, createModal };
package/dist/modal.css CHANGED
@@ -1 +1 @@
1
- #ib-overlay{position:fixed;inset:0;background:#00000080;z-index:2147483647;display:flex;align-items:center;justify-content:center}#ib-modal{--ib-primary: #6366f1;--ib-primary-hover: #4338ca;--ib-background: #f6f6f8;--ib-surface: #ffffff;--ib-text: #111827;--ib-muted: #8d99ae;--ib-border: var(--ib-primary);--ib-focus-color: var(--ib-primary);--ib-input-hover-border: var(--ib-border);--ib-selected: var(--ib-primary);--ib-selected-color: var(--ib-surface);--ib-radius: 2px;--ib-radius-input: 2px;color:var(--ib-text);border:1px solid var(--ib-border);border-radius:var(--ib-radius);width:100%;max-width:480px;margin:16px;position:relative;box-shadow:0 4px 24px #0000001f;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,sans-serif;font-size:14px;box-sizing:border-box;overflow:hidden}#ib-modal-header{background:var(--ib-surface);padding:12px 16px;border-bottom:1px solid var(--ib-border);display:flex;align-items:center;gap:8px}#ib-modal-body{background-color:var(--ib-background);padding:16px}#ib-title,.ib-modal-title{font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.1em;margin:0;color:var(--ib-muted);flex:1}#ib-textarea,.ib-modal-textarea{width:100%;background:var(--ib-background);border:1px solid var(--ib-border);border-radius:var(--ib-radius-input);padding:10px 12px;font-size:14px;font-family:inherit;color:var(--ib-text);resize:vertical;min-height:100px;box-sizing:border-box;outline:none;display:block}#ib-textarea:hover,.ib-modal-textarea:hover{border-color:var(--ib-input-hover-border)}#ib-textarea:focus,.ib-modal-textarea:focus{border-color:var(--ib-focus-color);box-shadow:0 0 0 2px color-mix(in srgb,var(--ib-focus-color) 15%,transparent)}#ib-modal-body #ib-title-input,#ib-modal-body .ib-modal-title-input,#ib-modal-body #ib-email,#ib-modal-body .ib-modal-email{width:100%;background:var(--ib-background);border:1px solid var(--ib-border);border-radius:var(--ib-radius-input);padding:8px 12px;font-size:14px;font-family:inherit;color:var(--ib-text);box-sizing:border-box;outline:none;display:block}#ib-title-input,.ib-modal-title-input{margin-bottom:10px}#ib-email,.ib-modal-email{margin-top:10px}#ib-modal-body #ib-title-input:hover,#ib-modal-body .ib-modal-title-input:hover,#ib-modal-body #ib-email:hover,#ib-modal-body .ib-modal-email:hover{border-color:var(--ib-input-hover-border)}#ib-modal-body #ib-title-input:focus,#ib-modal-body .ib-modal-title-input:focus,#ib-modal-body #ib-email:focus,#ib-modal-body .ib-modal-email:focus{border-color:var(--ib-focus-color);box-shadow:0 0 0 2px color-mix(in srgb,var(--ib-focus-color) 15%,transparent)}#ib-submit,.ib-modal-submit{background:var(--ib-primary);color:#fff;border:none;border-radius:var(--ib-radius-input);padding:8px 16px;font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.08em;font-family:inherit;cursor:pointer;display:inline-block;transition:background .15s}#ib-submit:hover,.ib-modal-submit:hover{background:var(--ib-primary-hover)}#ib-submit:disabled,.ib-modal-submit:disabled{opacity:.6;cursor:not-allowed}#ib-close,.ib-modal-close{background:none;border:none;font-size:18px;line-height:1;cursor:pointer;color:var(--ib-muted);padding:2px 6px;margin:0;border-radius:var(--ib-radius-input);flex-shrink:0}#ib-close:hover,.ib-modal-close:hover{color:var(--ib-primary)}#ib-success,.ib-modal-success{color:#16a34a;font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.08em;margin:8px 0 0;display:none}.ib-modal-footer{display:flex;align-items:center;justify-content:space-between;margin-top:12px}.ib-branding a{font-size:10px;color:var(--ib-muted);text-decoration:none;letter-spacing:.03em}.ib-branding a:hover{color:var(--ib-primary);text-decoration:underline}#ib-error,.ib-modal-error{color:#dc2626;font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.08em;margin:8px 0 0;display:none}.ib-modal-sentiment{display:flex;gap:4px}.ib-modal-thumb{width:30px;height:30px;display:flex;align-items:center;justify-content:center;background:var(--ib-background);border:1px solid var(--ib-border);border-radius:var(--ib-radius-input);color:var(--ib-primary);cursor:pointer;transition:background .15s,color .15s;padding:0;margin:0;flex-shrink:0;-webkit-appearance:none;appearance:none;box-sizing:border-box}.ib-modal-thumb:hover{background:var(--ib-primary);color:var(--ib-surface)}.ib-modal-thumb:focus{outline:1px solid var(--ib-primary);outline-offset:-1px}.ib-modal-thumb--active{background:var(--ib-selected);color:var(--ib-selected-color)}.ib-modal-thumb--active:hover{background:var(--ib-primary-hover)}@media (prefers-color-scheme: dark){#ib-modal:not(.ib-theme-light),#ib-modal.ib-theme-dark{--ib-primary: #3A5244;--ib-primary-hover: #4E6857;--ib-background: #25272B;--ib-surface: #2C3630;--ib-text: #E5E7EB;--ib-muted: #9CA3AF;--ib-border: #363840;--ib-focus-color: #7B9B82;--ib-input-hover-border: rgba(255, 255, 255, .2);--ib-radius: 8px;--ib-radius-input: 4px}}#ib-modal.ib-theme-dark{--ib-primary: #3A5244;--ib-primary-hover: #4E6857;--ib-background: #25272B;--ib-surface: #2C3630;--ib-text: #E5E7EB;--ib-muted: #9CA3AF;--ib-border: #363840;--ib-focus-color: #7B9B82;--ib-input-hover-border: rgba(255, 255, 255, .2);--ib-radius: 8px;--ib-radius-input: 4px}
1
+ #ib-overlay{position:fixed;inset:0;background:#00000080;z-index:2147483647;display:flex;align-items:center;justify-content:center}#ib-modal{--ib-primary: #6366f1;--ib-primary-hover: #4338ca;--ib-background: #f6f6f8;--ib-surface: #ffffff;--ib-text: #111827;--ib-muted: #8d99ae;--ib-border: var(--ib-primary);--ib-focus-color: var(--ib-primary);--ib-input-hover-border: var(--ib-border);--ib-selected: var(--ib-primary);--ib-selected-color: var(--ib-surface);--ib-radius: 2px;--ib-radius-input: 2px;color:var(--ib-text);border:1px solid var(--ib-border);border-radius:var(--ib-radius);width:100%;max-width:480px;margin:16px;position:relative;box-shadow:0 4px 24px #0000001f;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,sans-serif;font-size:14px;box-sizing:border-box;overflow:hidden}#ib-modal-header{background:var(--ib-surface);padding:12px 16px;border-bottom:1px solid var(--ib-border);display:flex;align-items:center;gap:8px}#ib-modal-body{background-color:var(--ib-background);padding:16px}#ib-title,.ib-modal-title{font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.1em;margin:0;color:var(--ib-muted);flex:1}#ib-textarea,.ib-modal-textarea{width:100%;background:var(--ib-background);border:1px solid var(--ib-border);border-radius:var(--ib-radius-input);padding:10px 12px;font-size:14px;font-family:inherit;color:var(--ib-text);resize:vertical;min-height:100px;box-sizing:border-box;outline:none;display:block}#ib-textarea:hover,.ib-modal-textarea:hover{border-color:var(--ib-input-hover-border)}#ib-textarea:focus,.ib-modal-textarea:focus{border-color:var(--ib-focus-color);box-shadow:0 0 0 2px color-mix(in srgb,var(--ib-focus-color) 15%,transparent)}#ib-modal-body #ib-title-input,#ib-modal-body .ib-modal-title-input{width:100%;background:var(--ib-background);border:1px solid var(--ib-border);border-radius:var(--ib-radius-input);padding:8px 12px;font-size:14px;font-family:inherit;color:var(--ib-text);box-sizing:border-box;outline:none;display:block}#ib-title-input,.ib-modal-title-input{margin-bottom:10px}#ib-modal-body #ib-title-input:hover,#ib-modal-body .ib-modal-title-input:hover{border-color:var(--ib-input-hover-border)}#ib-modal-body #ib-title-input:focus,#ib-modal-body .ib-modal-title-input:focus{border-color:var(--ib-focus-color);box-shadow:0 0 0 2px color-mix(in srgb,var(--ib-focus-color) 15%,transparent)}#ib-submit,.ib-modal-submit{background:var(--ib-primary);color:#fff;border:none;border-radius:var(--ib-radius-input);padding:8px 16px;font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.08em;font-family:inherit;cursor:pointer;display:inline-block;transition:background .15s}#ib-submit:hover,.ib-modal-submit:hover{background:var(--ib-primary-hover)}#ib-submit:disabled,.ib-modal-submit:disabled{opacity:.6;cursor:not-allowed}#ib-close,.ib-modal-close{background:none;border:none;font-size:18px;line-height:1;cursor:pointer;color:var(--ib-muted);padding:2px 6px;margin:0;border-radius:var(--ib-radius-input);flex-shrink:0}#ib-close:hover,.ib-modal-close:hover{color:var(--ib-primary)}#ib-success,.ib-modal-success{color:#16a34a;font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.08em;margin:8px 0 0;display:none}.ib-modal-footer{display:flex;align-items:center;justify-content:space-between;margin-top:12px}.ib-branding a{font-size:10px;color:var(--ib-muted);text-decoration:none;letter-spacing:.03em}.ib-branding a:hover{color:var(--ib-primary);text-decoration:underline}#ib-error,.ib-modal-error{color:#dc2626;font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.08em;margin:8px 0 0;display:none}.ib-modal-sentiment{display:flex;gap:4px}.ib-modal-thumb{width:30px;height:30px;display:flex;align-items:center;justify-content:center;background:var(--ib-background);border:1px solid var(--ib-border);border-radius:var(--ib-radius-input);color:var(--ib-primary);cursor:pointer;transition:background .15s,color .15s;padding:0;margin:0;flex-shrink:0;-webkit-appearance:none;appearance:none;box-sizing:border-box}.ib-modal-thumb:hover{background:var(--ib-primary);color:var(--ib-surface)}.ib-modal-thumb:focus{outline:1px solid var(--ib-primary);outline-offset:-1px}.ib-modal-thumb--active{background:var(--ib-selected);color:var(--ib-selected-color)}.ib-modal-thumb--active:hover{background:var(--ib-primary-hover)}@media(prefers-color-scheme:dark){#ib-modal:not(.ib-theme-light),#ib-modal.ib-theme-dark{--ib-primary: #3A5244;--ib-primary-hover: #4E6857;--ib-background: #25272B;--ib-surface: #2C3630;--ib-text: #E5E7EB;--ib-muted: #9CA3AF;--ib-border: #363840;--ib-focus-color: #7B9B82;--ib-input-hover-border: rgba(255, 255, 255, .2);--ib-radius: 8px;--ib-radius-input: 4px}}#ib-modal.ib-theme-dark{--ib-primary: #3A5244;--ib-primary-hover: #4E6857;--ib-background: #25272B;--ib-surface: #2C3630;--ib-text: #E5E7EB;--ib-muted: #9CA3AF;--ib-border: #363840;--ib-focus-color: #7B9B82;--ib-input-hover-border: rgba(255, 255, 255, .2);--ib-radius: 8px;--ib-radius-input: 4px}
package/dist/modal.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- var w=class extends Error{constructor(e){super(e.detail),this.name="ApiError",this.type=e.type,this.status=e.status,this.detail=e.detail,this.category=e.category,this.field=e.field}};function B(r){let e=document.getElementById("ib-modal");if(!e)return;let{theme:t={}}=r;t.primary&&e.style.setProperty("--ib-primary",t.primary),t.background&&e.style.setProperty("--ib-background",t.background),t.surface&&e.style.setProperty("--ib-surface",t.surface),t.text&&e.style.setProperty("--ib-text",t.text),t.selected&&e.style.setProperty("--ib-selected",t.selected),t.selectedColor&&e.style.setProperty("--ib-selected-color",t.selectedColor)}var I="0.2.0",K="https://inputbuffer.io/api/v0/inputs";async function P(r,e,t,d,c,l){var u,k,L,A;let b={description:e};if(d&&(b.title=d),t&&(b.contact_email=t),c!=null&&c.source&&(b.source=c.source),c!=null&&c.target){let h=c.target;b.targets=[{type:h.type,metadata:h.metadata}]}let m=new AbortController,g=setTimeout(()=>m.abort(),1e4),s;try{s=await fetch(l!=null?l:K,{method:"POST",headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json","X-IB-Client":`inputbuffer-widget/${I} (javascript)`},body:JSON.stringify(b),credentials:"omit",signal:m.signal})}finally{clearTimeout(g)}if(!s.ok){let h=await s.json().catch(()=>({}));throw new w({type:(u=h.type)!=null?u:"https://inputbuffer.io/problems/internal-error",title:(k=h.title)!=null?k:"Error",detail:(L=h.detail)!=null?L:"Submission failed. Please try again.",status:(A=h.status)!=null?A:s.status,category:h.category,field:h.field})}let{data:v}=await s.json();return{id:v.id}}function O(r){let e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 24 24"),e.setAttribute("width","18"),e.setAttribute("height","18"),e.setAttribute("fill","currentColor"),e.setAttribute("aria-hidden","true"),e.style.display="block";let t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d",r),e.appendChild(t),e}var V="M9 21h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-2c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.59 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2zM9 9l4.34-4.34L12 10h9v2l-3 7H9V9zM1 9h2v12H1z",q="M15 3H6c-.83 0-1.54.5-1.84 1.22l-3.02 7.05c-.09.23-.14.47-.14.73v2c0 1.1.9 2 2 2h6.31l-.95 4.57-.03.32c0 .41.17.79.44 1.06L10.83 23l6.59-6.59c.36-.36.58-.86.58-1.41V5c0-1.1-.9-2-2-2zm0 12l-4.34 4.34L12 14H3v-2l3-7h9v10zm4-12h2v12h-2z";function N(r){let e=null,t,d,c=null,l=null,b=null,m=null,g=null,s=null,v=null,u=null,k=null,L=[],A=[],h=[];function M(i){if(i.key==="Escape"){T();return}if(i.key==="Tab"&&e){let o=Array.from(e.querySelectorAll('button:not([disabled]), input:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'));if(o.length===0)return;let f=o[0],n=o[o.length-1];i.shiftKey?document.activeElement===f&&(i.preventDefault(),n.focus()):document.activeElement===n&&(i.preventDefault(),f.focus())}}async function W(){var o,f;if(!l||!g)return;let i=l.value.trim();if(i.length<10){s&&(s.textContent="Please enter at least 10 characters.",s.style.display="block");return}s&&(s.style.display="none"),g.disabled=!0,g.textContent="Sending\u2026";try{let n=(m==null?void 0:m.value.trim())||((o=t==null?void 0:t.prefill)==null?void 0:o.email)||null,p=(b==null?void 0:b.value.trim())||null,x=d!=null?d:t==null?void 0:t.sentiment,H=await P(r.apiKey,i,n||null,p,{...t,sentiment:x,source:(f=t==null?void 0:t.source)!=null?f:r.source},r.apiUrl);v&&(v.textContent="Thanks for your feedback!",v.style.display="block"),L.forEach(C=>C(H)),c=setTimeout(()=>T(),2e3)}catch(n){let p=n instanceof Error?n:new Error("Unknown error");if(s){let x=n instanceof w&&n.category==="user"?n.detail:"Something went wrong. Please try again.";s.textContent=x,s.style.display="block"}h.forEach(x=>x(p)),g.disabled=!1,g.textContent="Send feedback"}}function F(){let i=document.createElement("div");i.id="ib-overlay";let o=document.createElement("div");o.id="ib-modal",r.colorScheme==="dark"?o.classList.add("ib-theme-dark"):r.colorScheme==="light"&&o.classList.add("ib-theme-light"),o.setAttribute("role","dialog"),o.setAttribute("aria-modal","true");let f=document.createElement("div");if(f.id="ib-modal-header",k=f,r.title?(o.setAttribute("aria-labelledby","ib-title"),u=document.createElement("h2"),u.id="ib-title",u.className="ib-modal-title",u.textContent=r.title,f.appendChild(u)):o.setAttribute("aria-label","Feedback"),r.showSentiment){let y,E,S=document.createElement("div");S.className="ib-modal-sentiment",y=document.createElement("button"),y.type="button",y.className="ib-modal-thumb ib-modal-thumb--up",y.setAttribute("aria-label","Helpful"),y.appendChild(O(V)),E=document.createElement("button"),E.type="button",E.className="ib-modal-thumb ib-modal-thumb--down",E.setAttribute("aria-label","Not helpful"),E.appendChild(O(q)),y.addEventListener("click",()=>{y.classList.add("ib-modal-thumb--active"),E.classList.remove("ib-modal-thumb--active"),d="positive"}),E.addEventListener("click",()=>{E.classList.add("ib-modal-thumb--active"),y.classList.remove("ib-modal-thumb--active"),d="negative"}),S.appendChild(y),S.appendChild(E),f.appendChild(S)}let n=document.createElement("button");n.id="ib-close",n.className="ib-modal-close",n.textContent="\xD7",n.setAttribute("aria-label","Close feedback form"),n.addEventListener("click",T),f.appendChild(n);let p=document.createElement("div");p.id="ib-modal-body",l=document.createElement("textarea"),l.id="ib-textarea",l.className="ib-modal-textarea",l.placeholder=r.placeholder||"What's on your mind?",l.setAttribute("aria-label","Feedback"),g=document.createElement("button"),g.id="ib-submit",g.className="ib-modal-submit",g.textContent="Send feedback",g.addEventListener("click",W),v=document.createElement("p"),v.id="ib-success",v.className="ib-modal-success",s=document.createElement("p"),s.id="ib-error",s.className="ib-modal-error",r.showTitleField===!0&&(b=document.createElement("input"),b.id="ib-title-input",b.className="ib-modal-title-input",b.type="text",b.placeholder="Title (optional)",b.setAttribute("aria-label","Feedback title"),p.appendChild(b)),p.appendChild(l),r.showEmailField===!0&&(m=document.createElement("input"),m.id="ib-email",m.className="ib-modal-email",m.type="email",m.placeholder="Your email (optional)",m.setAttribute("aria-label","Email address"),p.appendChild(m)),p.appendChild(s),p.appendChild(v);let x=document.createElement("div");x.className="ib-modal-footer",x.appendChild(g);let H=document.createElement("div");H.className="ib-branding";let C=document.createElement("a");return C.href="https://inputbuffer.io",C.target="_blank",C.rel="noopener noreferrer",C.textContent="Powered by inputbuffer.io",H.appendChild(C),x.appendChild(H),p.appendChild(x),o.appendChild(f),o.appendChild(p),i.appendChild(o),i.addEventListener("click",y=>{y.target===i&&T()}),document.addEventListener("keydown",M),i}function R(i){var o,f;if(!e){if(t=i,e=F(),document.body.appendChild(e),B(r),i!=null&&i.title){if(u)u.textContent=i.title;else if(k){let n=e.querySelector("#ib-modal");n.removeAttribute("aria-label"),n.setAttribute("aria-labelledby","ib-title"),u=document.createElement("h2"),u.id="ib-title",u.className="ib-modal-title",u.textContent=i.title,k.prepend(u)}}if(i!=null&&i.sentiment){d=i.sentiment;let n=e.querySelector(".ib-modal-thumb--up"),p=e.querySelector(".ib-modal-thumb--down");i.sentiment==="positive"?n==null||n.classList.add("ib-modal-thumb--active"):i.sentiment==="negative"&&(p==null||p.classList.add("ib-modal-thumb--active"))}l&&((o=i==null?void 0:i.prefill)!=null&&o.description)&&(l.value=i.prefill.description),m&&((f=i==null?void 0:i.prefill)!=null&&f.email)&&(m.value=i.prefill.email),l==null||l.focus()}}function T(){e&&(c!==null&&(clearTimeout(c),c=null),document.removeEventListener("keydown",M),e.remove(),e=null,l=null,b=null,m=null,g=null,s=null,v=null,u=null,k=null,t=void 0,d=void 0,A.forEach(i=>i()))}function _(i,o){i==="submit"?L.push(o):i==="close"?A.push(o):i==="error"&&h.push(o)}function U(){T()}return{open:R,close:T,on:_,destroy:U}}var z=`/* InputBuffer Modal Styles
1
+ function H(i){let e=document.getElementById("ib-modal");if(!e)return;let{theme:t={}}=i;t.primary&&e.style.setProperty("--ib-primary",t.primary),t.background&&e.style.setProperty("--ib-background",t.background),t.surface&&e.style.setProperty("--ib-surface",t.surface),t.text&&e.style.setProperty("--ib-text",t.text),t.selected&&e.style.setProperty("--ib-selected",t.selected),t.selectedColor&&e.style.setProperty("--ib-selected-color",t.selectedColor)}var y=class extends Error{constructor(e){super(e.detail),this.name="ApiError",this.type=e.type,this.title=e.title,this.status=e.status,this.detail=e.detail,this.category=e.category,this.field=e.field}};var M="Something went wrong. Please try again.";function P(i){return i instanceof y?i.category==="user"?i.detail:(i.category==="integration"&&C(`${i.title}: ${i.detail}`,i.type),M):M}function C(i,e){typeof console!="undefined"&&console.warn(`[inputbuffer] ${i}`,e!=null?e:"")}var S="0.3.1",G="https://inputbuffer.io",V="/api/v0/feedback";var X=1e4,J=5e3,Y=500,Q=300;function Z(i,e){return`${(i!=null?i:G).replace(/\/+$/,"")}${e}`}async function ee(i,e,t){var c,u,d,p;let o=new AbortController,b=setTimeout(()=>o.abort(),X),n;try{n=await fetch(i,{method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json","X-IB-Client":`inputbuffer-widget/${S} (javascript)`},body:JSON.stringify(t),credentials:"omit",signal:o.signal})}finally{clearTimeout(b)}if(!n.ok){let s=await n.json().catch(()=>({}));throw new y({type:(c=s.type)!=null?c:"https://inputbuffer.io/docs/api/problems/internal-error",title:(u=s.title)!=null?u:"Error",detail:(d=s.detail)!=null?d:"Submission failed. Please try again.",status:(p=s.status)!=null?p:n.status,category:s.category,field:s.field})}return n}async function R(i,e,t,o,b){let n={description:e.slice(0,J)};if(t&&(n.title=t.slice(0,Y)),o!=null&&o.submittedBy&&(n.submitted_by=o.submittedBy.slice(0,Q)),o!=null&&o.target){let d=o.target;n.targets=[{type:d.type,metadata:d.metadata}]}let c=await ee(Z(b,V),i,n),{data:u}=await c.json();return{id:u.id}}function F(i){let e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 24 24"),e.setAttribute("width","18"),e.setAttribute("height","18"),e.setAttribute("fill","currentColor"),e.setAttribute("aria-hidden","true"),e.style.display="block";let t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d",i),e.appendChild(t),e}var te="M9 21h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-2c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.59 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2zM9 9l4.34-4.34L12 10h9v2l-3 7H9V9zM1 9h2v12H1z",ie="M15 3H6c-.83 0-1.54.5-1.84 1.22l-3.02 7.05c-.09.23-.14.47-.14.73v2c0 1.1.9 2 2 2h6.31l-.95 4.57-.03.32c0 .41.17.79.44 1.06L10.83 23l6.59-6.59c.36-.36.58-.86.58-1.41V5c0-1.1-.9-2-2-2zm0 12l-4.34 4.34L12 14H3v-2l3-7h9v10zm4-12h2v12h-2z";function O(i){let e=null,t,o,b=null,n=null,c=null,u=null,d=null,p=null,s=null,T=null,A=[],B=[],L=[];function I(r){if(r.key==="Escape"){v();return}if(r.key==="Tab"&&e){let a=Array.from(e.querySelectorAll('button:not([disabled]), input:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'));if(a.length===0)return;let l=a[0],m=a[a.length-1];r.shiftKey?document.activeElement===l&&(r.preventDefault(),m.focus()):document.activeElement===m&&(r.preventDefault(),l.focus())}}async function W(){var a;if(!n||!u)return;let r=n.value.trim();if(r.length<10){d&&(d.textContent="Please enter at least 10 characters.",d.style.display="block");return}d&&(d.style.display="none"),u.disabled=!0,u.textContent="Sending\u2026";try{let l=(c==null?void 0:c.value.trim())||null,m=o!=null?o:t==null?void 0:t.sentiment,f=await R(i.apiKey,r,l,{...t,sentiment:m,submittedBy:(a=t==null?void 0:t.submittedBy)!=null?a:i.submittedBy},i.apiUrl);p&&(p.textContent="Thanks for your feedback!",p.style.display="block"),A.forEach(x=>x(f)),b=setTimeout(()=>v(),2e3)}catch(l){let m=l instanceof Error?l:new Error("Unknown error");d&&(d.textContent=P(l),d.style.display="block"),L.forEach(f=>f(m)),u.disabled=!1,u.textContent="Send feedback"}}function U(){let r=document.createElement("div");r.id="ib-overlay";let a=document.createElement("div");a.id="ib-modal",i.colorScheme==="dark"?a.classList.add("ib-theme-dark"):i.colorScheme==="light"&&a.classList.add("ib-theme-light"),a.setAttribute("role","dialog"),a.setAttribute("aria-modal","true");let l=document.createElement("div");if(l.id="ib-modal-header",T=l,i.title?(a.setAttribute("aria-labelledby","ib-title"),s=document.createElement("h2"),s.id="ib-title",s.className="ib-modal-title",s.textContent=i.title,l.appendChild(s)):a.setAttribute("aria-label","Feedback"),i.showSentiment){let g,h,k=document.createElement("div");k.className="ib-modal-sentiment",g=document.createElement("button"),g.type="button",g.className="ib-modal-thumb ib-modal-thumb--up",g.setAttribute("aria-label","Helpful"),g.appendChild(F(te)),h=document.createElement("button"),h.type="button",h.className="ib-modal-thumb ib-modal-thumb--down",h.setAttribute("aria-label","Not helpful"),h.appendChild(F(ie)),g.addEventListener("click",()=>{g.classList.add("ib-modal-thumb--active"),h.classList.remove("ib-modal-thumb--active"),o="positive"}),h.addEventListener("click",()=>{h.classList.add("ib-modal-thumb--active"),g.classList.remove("ib-modal-thumb--active"),o="negative"}),k.appendChild(g),k.appendChild(h),l.appendChild(k)}let m=document.createElement("button");m.id="ib-close",m.className="ib-modal-close",m.textContent="\xD7",m.setAttribute("aria-label","Close feedback form"),m.addEventListener("click",v),l.appendChild(m);let f=document.createElement("div");f.id="ib-modal-body",n=document.createElement("textarea"),n.id="ib-textarea",n.className="ib-modal-textarea",n.placeholder=i.placeholder||"What's on your mind?",n.maxLength=5e3,n.setAttribute("aria-label","Feedback"),u=document.createElement("button"),u.id="ib-submit",u.className="ib-modal-submit",u.textContent="Send feedback",u.addEventListener("click",W),p=document.createElement("p"),p.id="ib-success",p.className="ib-modal-success",d=document.createElement("p"),d.id="ib-error",d.className="ib-modal-error",i.showTitleField===!0&&(c=document.createElement("input"),c.id="ib-title-input",c.className="ib-modal-title-input",c.type="text",c.placeholder="Title (optional)",c.maxLength=500,c.setAttribute("aria-label","Feedback title"),f.appendChild(c)),f.appendChild(n),f.appendChild(d),f.appendChild(p);let x=document.createElement("div");x.className="ib-modal-footer",x.appendChild(u);let w=document.createElement("div");w.className="ib-branding";let E=document.createElement("a");return E.href="https://inputbuffer.io",E.target="_blank",E.rel="noopener noreferrer",E.textContent="Powered by inputbuffer.io",w.appendChild(E),x.appendChild(w),f.appendChild(x),a.appendChild(l),a.appendChild(f),r.appendChild(a),r.addEventListener("click",g=>{g.target===r&&v()}),document.addEventListener("keydown",I),r}function q(r){var a;if(!e){if(t=r,e=U(),document.body.appendChild(e),H(i),r!=null&&r.title){if(s)s.textContent=r.title;else if(T){let l=e.querySelector("#ib-modal");l.removeAttribute("aria-label"),l.setAttribute("aria-labelledby","ib-title"),s=document.createElement("h2"),s.id="ib-title",s.className="ib-modal-title",s.textContent=r.title,T.prepend(s)}}if(r!=null&&r.sentiment){o=r.sentiment;let l=e.querySelector(".ib-modal-thumb--up"),m=e.querySelector(".ib-modal-thumb--down");r.sentiment==="positive"?l==null||l.classList.add("ib-modal-thumb--active"):r.sentiment==="negative"&&(m==null||m.classList.add("ib-modal-thumb--active"))}n&&((a=r==null?void 0:r.prefill)!=null&&a.description)&&(n.value=r.prefill.description),n==null||n.focus()}}function v(){e&&(b!==null&&(clearTimeout(b),b=null),document.removeEventListener("keydown",I),e.remove(),e=null,n=null,c=null,u=null,d=null,p=null,s=null,T=null,t=void 0,o=void 0,B.forEach(r=>r()))}function K(r,a){r==="submit"?A.push(a):r==="close"?B.push(a):r==="error"&&L.push(a)}function $(){v()}return{open:q,close:v,on:K,destroy:$}}function N(i,e){let t=i.dataset;return{apiKey:e,apiUrl:t.apiUrl,attachTo:t.attachTo,injectStyles:t.injectStyles===void 0?!0:t.injectStyles!=="false",colorScheme:t.colorScheme,title:t.title,placeholder:t.placeholder,showTitleField:t.showTitleField===void 0?void 0:t.showTitleField==="true",showSentiment:t.showSentiment===void 0?void 0:t.showSentiment==="true",submittedBy:t.submittedBy,theme:{primary:t.themePrimary,background:t.themeBackground,text:t.themeText,selected:t.themeSelected,selectedColor:t.themeSelectedColor}}}var j=`/* InputBuffer Modal Styles
2
2
  * All #ib-* IDs are stable public API \u2014 do not rename them.
3
3
  * Developers may target these IDs from their own stylesheets to customize the widget.
4
4
  */
@@ -99,9 +99,7 @@ var w=class extends Error{constructor(e){super(e.detail),this.name="ApiError",th
99
99
  }
100
100
 
101
101
  #ib-modal-body #ib-title-input,
102
- #ib-modal-body .ib-modal-title-input,
103
- #ib-modal-body #ib-email,
104
- #ib-modal-body .ib-modal-email {
102
+ #ib-modal-body .ib-modal-title-input {
105
103
  width: 100%;
106
104
  background: var(--ib-background);
107
105
  border: 1px solid var(--ib-border);
@@ -120,22 +118,13 @@ var w=class extends Error{constructor(e){super(e.detail),this.name="ApiError",th
120
118
  margin-bottom: 10px;
121
119
  }
122
120
 
123
- #ib-email,
124
- .ib-modal-email {
125
- margin-top: 10px;
126
- }
127
-
128
121
  #ib-modal-body #ib-title-input:hover,
129
- #ib-modal-body .ib-modal-title-input:hover,
130
- #ib-modal-body #ib-email:hover,
131
- #ib-modal-body .ib-modal-email:hover {
122
+ #ib-modal-body .ib-modal-title-input:hover {
132
123
  border-color: var(--ib-input-hover-border);
133
124
  }
134
125
 
135
126
  #ib-modal-body #ib-title-input:focus,
136
- #ib-modal-body .ib-modal-title-input:focus,
137
- #ib-modal-body #ib-email:focus,
138
- #ib-modal-body .ib-modal-email:focus {
127
+ #ib-modal-body .ib-modal-title-input:focus {
139
128
  border-color: var(--ib-focus-color);
140
129
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--ib-focus-color) 15%, transparent);
141
130
  }
@@ -306,4 +295,4 @@ var w=class extends Error{constructor(e){super(e.detail),this.name="ApiError",th
306
295
  --ib-radius: 8px;
307
296
  --ib-radius-input: 4px;
308
297
  }
309
- `;var a=document.currentScript;function $(){if(document.getElementById("ib-modal-styles"))return;let r=document.createElement("style");r.id="ib-modal-styles",r.textContent=z,document.head.appendChild(r)}function j(r){r.injectStyles!==!1&&$();let e=N(r),t=null,d=null;return r.attachTo&&(t=document.querySelector(r.attachTo),t&&(d=()=>e.open(),t.addEventListener("click",d))),{open:c=>e.open(c),close:()=>e.close(),on:(c,l)=>e.on(c,l),destroy:()=>{t&&d&&(t.removeEventListener("click",d),t=null,d=null),e.destroy()}}}var D={createModal:j,version:I};window.InputBufferIO=D;(function(){let e=a==null?void 0:a.dataset.apiKey;if(!e)return;let t=a==null?void 0:a.dataset.injectStyles,d=j({apiKey:e,apiUrl:a==null?void 0:a.dataset.apiUrl,attachTo:a==null?void 0:a.dataset.attachTo,injectStyles:t===void 0?!0:t!=="false",theme:{primary:a==null?void 0:a.dataset.themePrimary,background:a==null?void 0:a.dataset.themeBackground,text:a==null?void 0:a.dataset.themeText,selected:a==null?void 0:a.dataset.themeSelected,selectedColor:a==null?void 0:a.dataset.themeSelectedColor}});D._defaultInstance=d})();export{D as InputBufferIO,j as createModal};
298
+ `;var _=document.currentScript;function ne(){if(document.getElementById("ib-modal-styles"))return;let i=document.createElement("style");i.id="ib-modal-styles",i.textContent=j,document.head.appendChild(i)}function z(i){i.injectStyles!==!1&&ne();let e=O(i),t=null,o=null;return i.attachTo&&(t=document.querySelector(i.attachTo),t&&(o=()=>e.open(),t.addEventListener("click",o))),{open:b=>e.open(b),close:()=>e.close(),on:(b,n)=>e.on(b,n),destroy:()=>{t&&o&&(t.removeEventListener("click",o),t=null,o=null),e.destroy()}}}var D={createModal:z,version:S};window.InputBufferIO=D;(function(){if(!_)return;let e=_.dataset.apiKey;if(!e)return;let t=z(N(_,e));D._defaultInstance=t})();export{y as ApiError,D as InputBufferIO,z as createModal};
package/dist/modal.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";(()=>{var w=class extends Error{constructor(e){super(e.detail),this.name="ApiError",this.type=e.type,this.status=e.status,this.detail=e.detail,this.category=e.category,this.field=e.field}};function B(r){let e=document.getElementById("ib-modal");if(!e)return;let{theme:t={}}=r;t.primary&&e.style.setProperty("--ib-primary",t.primary),t.background&&e.style.setProperty("--ib-background",t.background),t.surface&&e.style.setProperty("--ib-surface",t.surface),t.text&&e.style.setProperty("--ib-text",t.text),t.selected&&e.style.setProperty("--ib-selected",t.selected),t.selectedColor&&e.style.setProperty("--ib-selected-color",t.selectedColor)}var I="0.2.0",K="https://inputbuffer.io/api/v0/inputs";async function P(r,e,t,d,c,l){var u,k,L,A;let b={description:e};if(d&&(b.title=d),t&&(b.contact_email=t),c!=null&&c.source&&(b.source=c.source),c!=null&&c.target){let h=c.target;b.targets=[{type:h.type,metadata:h.metadata}]}let m=new AbortController,g=setTimeout(()=>m.abort(),1e4),s;try{s=await fetch(l!=null?l:K,{method:"POST",headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json","X-IB-Client":`inputbuffer-widget/${I} (javascript)`},body:JSON.stringify(b),credentials:"omit",signal:m.signal})}finally{clearTimeout(g)}if(!s.ok){let h=await s.json().catch(()=>({}));throw new w({type:(u=h.type)!=null?u:"https://inputbuffer.io/problems/internal-error",title:(k=h.title)!=null?k:"Error",detail:(L=h.detail)!=null?L:"Submission failed. Please try again.",status:(A=h.status)!=null?A:s.status,category:h.category,field:h.field})}let{data:v}=await s.json();return{id:v.id}}function O(r){let e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 24 24"),e.setAttribute("width","18"),e.setAttribute("height","18"),e.setAttribute("fill","currentColor"),e.setAttribute("aria-hidden","true"),e.style.display="block";let t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d",r),e.appendChild(t),e}var V="M9 21h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-2c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.59 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2zM9 9l4.34-4.34L12 10h9v2l-3 7H9V9zM1 9h2v12H1z",q="M15 3H6c-.83 0-1.54.5-1.84 1.22l-3.02 7.05c-.09.23-.14.47-.14.73v2c0 1.1.9 2 2 2h6.31l-.95 4.57-.03.32c0 .41.17.79.44 1.06L10.83 23l6.59-6.59c.36-.36.58-.86.58-1.41V5c0-1.1-.9-2-2-2zm0 12l-4.34 4.34L12 14H3v-2l3-7h9v10zm4-12h2v12h-2z";function N(r){let e=null,t,d,c=null,l=null,b=null,m=null,g=null,s=null,v=null,u=null,k=null,L=[],A=[],h=[];function M(i){if(i.key==="Escape"){T();return}if(i.key==="Tab"&&e){let o=Array.from(e.querySelectorAll('button:not([disabled]), input:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'));if(o.length===0)return;let f=o[0],n=o[o.length-1];i.shiftKey?document.activeElement===f&&(i.preventDefault(),n.focus()):document.activeElement===n&&(i.preventDefault(),f.focus())}}async function W(){var o,f;if(!l||!g)return;let i=l.value.trim();if(i.length<10){s&&(s.textContent="Please enter at least 10 characters.",s.style.display="block");return}s&&(s.style.display="none"),g.disabled=!0,g.textContent="Sending\u2026";try{let n=(m==null?void 0:m.value.trim())||((o=t==null?void 0:t.prefill)==null?void 0:o.email)||null,p=(b==null?void 0:b.value.trim())||null,x=d!=null?d:t==null?void 0:t.sentiment,H=await P(r.apiKey,i,n||null,p,{...t,sentiment:x,source:(f=t==null?void 0:t.source)!=null?f:r.source},r.apiUrl);v&&(v.textContent="Thanks for your feedback!",v.style.display="block"),L.forEach(C=>C(H)),c=setTimeout(()=>T(),2e3)}catch(n){let p=n instanceof Error?n:new Error("Unknown error");if(s){let x=n instanceof w&&n.category==="user"?n.detail:"Something went wrong. Please try again.";s.textContent=x,s.style.display="block"}h.forEach(x=>x(p)),g.disabled=!1,g.textContent="Send feedback"}}function F(){let i=document.createElement("div");i.id="ib-overlay";let o=document.createElement("div");o.id="ib-modal",r.colorScheme==="dark"?o.classList.add("ib-theme-dark"):r.colorScheme==="light"&&o.classList.add("ib-theme-light"),o.setAttribute("role","dialog"),o.setAttribute("aria-modal","true");let f=document.createElement("div");if(f.id="ib-modal-header",k=f,r.title?(o.setAttribute("aria-labelledby","ib-title"),u=document.createElement("h2"),u.id="ib-title",u.className="ib-modal-title",u.textContent=r.title,f.appendChild(u)):o.setAttribute("aria-label","Feedback"),r.showSentiment){let y,E,S=document.createElement("div");S.className="ib-modal-sentiment",y=document.createElement("button"),y.type="button",y.className="ib-modal-thumb ib-modal-thumb--up",y.setAttribute("aria-label","Helpful"),y.appendChild(O(V)),E=document.createElement("button"),E.type="button",E.className="ib-modal-thumb ib-modal-thumb--down",E.setAttribute("aria-label","Not helpful"),E.appendChild(O(q)),y.addEventListener("click",()=>{y.classList.add("ib-modal-thumb--active"),E.classList.remove("ib-modal-thumb--active"),d="positive"}),E.addEventListener("click",()=>{E.classList.add("ib-modal-thumb--active"),y.classList.remove("ib-modal-thumb--active"),d="negative"}),S.appendChild(y),S.appendChild(E),f.appendChild(S)}let n=document.createElement("button");n.id="ib-close",n.className="ib-modal-close",n.textContent="\xD7",n.setAttribute("aria-label","Close feedback form"),n.addEventListener("click",T),f.appendChild(n);let p=document.createElement("div");p.id="ib-modal-body",l=document.createElement("textarea"),l.id="ib-textarea",l.className="ib-modal-textarea",l.placeholder=r.placeholder||"What's on your mind?",l.setAttribute("aria-label","Feedback"),g=document.createElement("button"),g.id="ib-submit",g.className="ib-modal-submit",g.textContent="Send feedback",g.addEventListener("click",W),v=document.createElement("p"),v.id="ib-success",v.className="ib-modal-success",s=document.createElement("p"),s.id="ib-error",s.className="ib-modal-error",r.showTitleField===!0&&(b=document.createElement("input"),b.id="ib-title-input",b.className="ib-modal-title-input",b.type="text",b.placeholder="Title (optional)",b.setAttribute("aria-label","Feedback title"),p.appendChild(b)),p.appendChild(l),r.showEmailField===!0&&(m=document.createElement("input"),m.id="ib-email",m.className="ib-modal-email",m.type="email",m.placeholder="Your email (optional)",m.setAttribute("aria-label","Email address"),p.appendChild(m)),p.appendChild(s),p.appendChild(v);let x=document.createElement("div");x.className="ib-modal-footer",x.appendChild(g);let H=document.createElement("div");H.className="ib-branding";let C=document.createElement("a");return C.href="https://inputbuffer.io",C.target="_blank",C.rel="noopener noreferrer",C.textContent="Powered by inputbuffer.io",H.appendChild(C),x.appendChild(H),p.appendChild(x),o.appendChild(f),o.appendChild(p),i.appendChild(o),i.addEventListener("click",y=>{y.target===i&&T()}),document.addEventListener("keydown",M),i}function R(i){var o,f;if(!e){if(t=i,e=F(),document.body.appendChild(e),B(r),i!=null&&i.title){if(u)u.textContent=i.title;else if(k){let n=e.querySelector("#ib-modal");n.removeAttribute("aria-label"),n.setAttribute("aria-labelledby","ib-title"),u=document.createElement("h2"),u.id="ib-title",u.className="ib-modal-title",u.textContent=i.title,k.prepend(u)}}if(i!=null&&i.sentiment){d=i.sentiment;let n=e.querySelector(".ib-modal-thumb--up"),p=e.querySelector(".ib-modal-thumb--down");i.sentiment==="positive"?n==null||n.classList.add("ib-modal-thumb--active"):i.sentiment==="negative"&&(p==null||p.classList.add("ib-modal-thumb--active"))}l&&((o=i==null?void 0:i.prefill)!=null&&o.description)&&(l.value=i.prefill.description),m&&((f=i==null?void 0:i.prefill)!=null&&f.email)&&(m.value=i.prefill.email),l==null||l.focus()}}function T(){e&&(c!==null&&(clearTimeout(c),c=null),document.removeEventListener("keydown",M),e.remove(),e=null,l=null,b=null,m=null,g=null,s=null,v=null,u=null,k=null,t=void 0,d=void 0,A.forEach(i=>i()))}function _(i,o){i==="submit"?L.push(o):i==="close"?A.push(o):i==="error"&&h.push(o)}function U(){T()}return{open:R,close:T,on:_,destroy:U}}var z=`/* InputBuffer Modal Styles
1
+ "use strict";(()=>{function H(i){let e=document.getElementById("ib-modal");if(!e)return;let{theme:t={}}=i;t.primary&&e.style.setProperty("--ib-primary",t.primary),t.background&&e.style.setProperty("--ib-background",t.background),t.surface&&e.style.setProperty("--ib-surface",t.surface),t.text&&e.style.setProperty("--ib-text",t.text),t.selected&&e.style.setProperty("--ib-selected",t.selected),t.selectedColor&&e.style.setProperty("--ib-selected-color",t.selectedColor)}var y=class extends Error{constructor(e){super(e.detail),this.name="ApiError",this.type=e.type,this.title=e.title,this.status=e.status,this.detail=e.detail,this.category=e.category,this.field=e.field}};var M="Something went wrong. Please try again.";function P(i){return i instanceof y?i.category==="user"?i.detail:(i.category==="integration"&&C(`${i.title}: ${i.detail}`,i.type),M):M}function C(i,e){typeof console!="undefined"&&console.warn(`[inputbuffer] ${i}`,e!=null?e:"")}var S="0.3.1",G="https://inputbuffer.io",V="/api/v0/feedback";var X=1e4,J=5e3,Y=500,Q=300;function Z(i,e){return`${(i!=null?i:G).replace(/\/+$/,"")}${e}`}async function ee(i,e,t){var c,u,d,p;let o=new AbortController,b=setTimeout(()=>o.abort(),X),n;try{n=await fetch(i,{method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json","X-IB-Client":`inputbuffer-widget/${S} (javascript)`},body:JSON.stringify(t),credentials:"omit",signal:o.signal})}finally{clearTimeout(b)}if(!n.ok){let s=await n.json().catch(()=>({}));throw new y({type:(c=s.type)!=null?c:"https://inputbuffer.io/docs/api/problems/internal-error",title:(u=s.title)!=null?u:"Error",detail:(d=s.detail)!=null?d:"Submission failed. Please try again.",status:(p=s.status)!=null?p:n.status,category:s.category,field:s.field})}return n}async function R(i,e,t,o,b){let n={description:e.slice(0,J)};if(t&&(n.title=t.slice(0,Y)),o!=null&&o.submittedBy&&(n.submitted_by=o.submittedBy.slice(0,Q)),o!=null&&o.target){let d=o.target;n.targets=[{type:d.type,metadata:d.metadata}]}let c=await ee(Z(b,V),i,n),{data:u}=await c.json();return{id:u.id}}function F(i){let e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 24 24"),e.setAttribute("width","18"),e.setAttribute("height","18"),e.setAttribute("fill","currentColor"),e.setAttribute("aria-hidden","true"),e.style.display="block";let t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d",i),e.appendChild(t),e}var te="M9 21h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-2c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.59 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2zM9 9l4.34-4.34L12 10h9v2l-3 7H9V9zM1 9h2v12H1z",ie="M15 3H6c-.83 0-1.54.5-1.84 1.22l-3.02 7.05c-.09.23-.14.47-.14.73v2c0 1.1.9 2 2 2h6.31l-.95 4.57-.03.32c0 .41.17.79.44 1.06L10.83 23l6.59-6.59c.36-.36.58-.86.58-1.41V5c0-1.1-.9-2-2-2zm0 12l-4.34 4.34L12 14H3v-2l3-7h9v10zm4-12h2v12h-2z";function O(i){let e=null,t,o,b=null,n=null,c=null,u=null,d=null,p=null,s=null,T=null,A=[],B=[],L=[];function I(r){if(r.key==="Escape"){v();return}if(r.key==="Tab"&&e){let a=Array.from(e.querySelectorAll('button:not([disabled]), input:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'));if(a.length===0)return;let l=a[0],m=a[a.length-1];r.shiftKey?document.activeElement===l&&(r.preventDefault(),m.focus()):document.activeElement===m&&(r.preventDefault(),l.focus())}}async function W(){var a;if(!n||!u)return;let r=n.value.trim();if(r.length<10){d&&(d.textContent="Please enter at least 10 characters.",d.style.display="block");return}d&&(d.style.display="none"),u.disabled=!0,u.textContent="Sending\u2026";try{let l=(c==null?void 0:c.value.trim())||null,m=o!=null?o:t==null?void 0:t.sentiment,f=await R(i.apiKey,r,l,{...t,sentiment:m,submittedBy:(a=t==null?void 0:t.submittedBy)!=null?a:i.submittedBy},i.apiUrl);p&&(p.textContent="Thanks for your feedback!",p.style.display="block"),A.forEach(x=>x(f)),b=setTimeout(()=>v(),2e3)}catch(l){let m=l instanceof Error?l:new Error("Unknown error");d&&(d.textContent=P(l),d.style.display="block"),L.forEach(f=>f(m)),u.disabled=!1,u.textContent="Send feedback"}}function U(){let r=document.createElement("div");r.id="ib-overlay";let a=document.createElement("div");a.id="ib-modal",i.colorScheme==="dark"?a.classList.add("ib-theme-dark"):i.colorScheme==="light"&&a.classList.add("ib-theme-light"),a.setAttribute("role","dialog"),a.setAttribute("aria-modal","true");let l=document.createElement("div");if(l.id="ib-modal-header",T=l,i.title?(a.setAttribute("aria-labelledby","ib-title"),s=document.createElement("h2"),s.id="ib-title",s.className="ib-modal-title",s.textContent=i.title,l.appendChild(s)):a.setAttribute("aria-label","Feedback"),i.showSentiment){let g,h,k=document.createElement("div");k.className="ib-modal-sentiment",g=document.createElement("button"),g.type="button",g.className="ib-modal-thumb ib-modal-thumb--up",g.setAttribute("aria-label","Helpful"),g.appendChild(F(te)),h=document.createElement("button"),h.type="button",h.className="ib-modal-thumb ib-modal-thumb--down",h.setAttribute("aria-label","Not helpful"),h.appendChild(F(ie)),g.addEventListener("click",()=>{g.classList.add("ib-modal-thumb--active"),h.classList.remove("ib-modal-thumb--active"),o="positive"}),h.addEventListener("click",()=>{h.classList.add("ib-modal-thumb--active"),g.classList.remove("ib-modal-thumb--active"),o="negative"}),k.appendChild(g),k.appendChild(h),l.appendChild(k)}let m=document.createElement("button");m.id="ib-close",m.className="ib-modal-close",m.textContent="\xD7",m.setAttribute("aria-label","Close feedback form"),m.addEventListener("click",v),l.appendChild(m);let f=document.createElement("div");f.id="ib-modal-body",n=document.createElement("textarea"),n.id="ib-textarea",n.className="ib-modal-textarea",n.placeholder=i.placeholder||"What's on your mind?",n.maxLength=5e3,n.setAttribute("aria-label","Feedback"),u=document.createElement("button"),u.id="ib-submit",u.className="ib-modal-submit",u.textContent="Send feedback",u.addEventListener("click",W),p=document.createElement("p"),p.id="ib-success",p.className="ib-modal-success",d=document.createElement("p"),d.id="ib-error",d.className="ib-modal-error",i.showTitleField===!0&&(c=document.createElement("input"),c.id="ib-title-input",c.className="ib-modal-title-input",c.type="text",c.placeholder="Title (optional)",c.maxLength=500,c.setAttribute("aria-label","Feedback title"),f.appendChild(c)),f.appendChild(n),f.appendChild(d),f.appendChild(p);let x=document.createElement("div");x.className="ib-modal-footer",x.appendChild(u);let w=document.createElement("div");w.className="ib-branding";let E=document.createElement("a");return E.href="https://inputbuffer.io",E.target="_blank",E.rel="noopener noreferrer",E.textContent="Powered by inputbuffer.io",w.appendChild(E),x.appendChild(w),f.appendChild(x),a.appendChild(l),a.appendChild(f),r.appendChild(a),r.addEventListener("click",g=>{g.target===r&&v()}),document.addEventListener("keydown",I),r}function q(r){var a;if(!e){if(t=r,e=U(),document.body.appendChild(e),H(i),r!=null&&r.title){if(s)s.textContent=r.title;else if(T){let l=e.querySelector("#ib-modal");l.removeAttribute("aria-label"),l.setAttribute("aria-labelledby","ib-title"),s=document.createElement("h2"),s.id="ib-title",s.className="ib-modal-title",s.textContent=r.title,T.prepend(s)}}if(r!=null&&r.sentiment){o=r.sentiment;let l=e.querySelector(".ib-modal-thumb--up"),m=e.querySelector(".ib-modal-thumb--down");r.sentiment==="positive"?l==null||l.classList.add("ib-modal-thumb--active"):r.sentiment==="negative"&&(m==null||m.classList.add("ib-modal-thumb--active"))}n&&((a=r==null?void 0:r.prefill)!=null&&a.description)&&(n.value=r.prefill.description),n==null||n.focus()}}function v(){e&&(b!==null&&(clearTimeout(b),b=null),document.removeEventListener("keydown",I),e.remove(),e=null,n=null,c=null,u=null,d=null,p=null,s=null,T=null,t=void 0,o=void 0,B.forEach(r=>r()))}function K(r,a){r==="submit"?A.push(a):r==="close"?B.push(a):r==="error"&&L.push(a)}function $(){v()}return{open:q,close:v,on:K,destroy:$}}function N(i,e){let t=i.dataset;return{apiKey:e,apiUrl:t.apiUrl,attachTo:t.attachTo,injectStyles:t.injectStyles===void 0?!0:t.injectStyles!=="false",colorScheme:t.colorScheme,title:t.title,placeholder:t.placeholder,showTitleField:t.showTitleField===void 0?void 0:t.showTitleField==="true",showSentiment:t.showSentiment===void 0?void 0:t.showSentiment==="true",submittedBy:t.submittedBy,theme:{primary:t.themePrimary,background:t.themeBackground,text:t.themeText,selected:t.themeSelected,selectedColor:t.themeSelectedColor}}}var j=`/* InputBuffer Modal Styles
2
2
  * All #ib-* IDs are stable public API \u2014 do not rename them.
3
3
  * Developers may target these IDs from their own stylesheets to customize the widget.
4
4
  */
@@ -99,9 +99,7 @@
99
99
  }
100
100
 
101
101
  #ib-modal-body #ib-title-input,
102
- #ib-modal-body .ib-modal-title-input,
103
- #ib-modal-body #ib-email,
104
- #ib-modal-body .ib-modal-email {
102
+ #ib-modal-body .ib-modal-title-input {
105
103
  width: 100%;
106
104
  background: var(--ib-background);
107
105
  border: 1px solid var(--ib-border);
@@ -120,22 +118,13 @@
120
118
  margin-bottom: 10px;
121
119
  }
122
120
 
123
- #ib-email,
124
- .ib-modal-email {
125
- margin-top: 10px;
126
- }
127
-
128
121
  #ib-modal-body #ib-title-input:hover,
129
- #ib-modal-body .ib-modal-title-input:hover,
130
- #ib-modal-body #ib-email:hover,
131
- #ib-modal-body .ib-modal-email:hover {
122
+ #ib-modal-body .ib-modal-title-input:hover {
132
123
  border-color: var(--ib-input-hover-border);
133
124
  }
134
125
 
135
126
  #ib-modal-body #ib-title-input:focus,
136
- #ib-modal-body .ib-modal-title-input:focus,
137
- #ib-modal-body #ib-email:focus,
138
- #ib-modal-body .ib-modal-email:focus {
127
+ #ib-modal-body .ib-modal-title-input:focus {
139
128
  border-color: var(--ib-focus-color);
140
129
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--ib-focus-color) 15%, transparent);
141
130
  }
@@ -306,4 +295,4 @@
306
295
  --ib-radius: 8px;
307
296
  --ib-radius-input: 4px;
308
297
  }
309
- `;var a=document.currentScript;function $(){if(document.getElementById("ib-modal-styles"))return;let r=document.createElement("style");r.id="ib-modal-styles",r.textContent=z,document.head.appendChild(r)}function j(r){r.injectStyles!==!1&&$();let e=N(r),t=null,d=null;return r.attachTo&&(t=document.querySelector(r.attachTo),t&&(d=()=>e.open(),t.addEventListener("click",d))),{open:c=>e.open(c),close:()=>e.close(),on:(c,l)=>e.on(c,l),destroy:()=>{t&&d&&(t.removeEventListener("click",d),t=null,d=null),e.destroy()}}}var D={createModal:j,version:I};window.InputBufferIO=D;(function(){let e=a==null?void 0:a.dataset.apiKey;if(!e)return;let t=a==null?void 0:a.dataset.injectStyles,d=j({apiKey:e,apiUrl:a==null?void 0:a.dataset.apiUrl,attachTo:a==null?void 0:a.dataset.attachTo,injectStyles:t===void 0?!0:t!=="false",theme:{primary:a==null?void 0:a.dataset.themePrimary,background:a==null?void 0:a.dataset.themeBackground,text:a==null?void 0:a.dataset.themeText,selected:a==null?void 0:a.dataset.themeSelected,selectedColor:a==null?void 0:a.dataset.themeSelectedColor}});D._defaultInstance=d})();})();
298
+ `;var _=document.currentScript;function ne(){if(document.getElementById("ib-modal-styles"))return;let i=document.createElement("style");i.id="ib-modal-styles",i.textContent=j,document.head.appendChild(i)}function z(i){i.injectStyles!==!1&&ne();let e=O(i),t=null,o=null;return i.attachTo&&(t=document.querySelector(i.attachTo),t&&(o=()=>e.open(),t.addEventListener("click",o))),{open:b=>e.open(b),close:()=>e.close(),on:(b,n)=>e.on(b,n),destroy:()=>{t&&o&&(t.removeEventListener("click",o),t=null,o=null),e.destroy()}}}var D={createModal:z,version:S};window.InputBufferIO=D;(function(){if(!_)return;let e=_.dataset.apiKey;if(!e)return;let t=z(N(_,e));D._defaultInstance=t})();})();
package/dist/types.d.ts CHANGED
@@ -1,22 +1,41 @@
1
+ /**
2
+ * The problem type URIs the API can return. The spec is explicit that these are stable
3
+ * across releases and that clients should switch on `type` rather than `status`, because
4
+ * several types share a status code.
5
+ */
6
+ export type ProblemType = 'https://inputbuffer.io/docs/api/problems/unauthorized' | 'https://inputbuffer.io/docs/api/problems/invalid-token-format' | 'https://inputbuffer.io/docs/api/problems/invalid-token' | 'https://inputbuffer.io/docs/api/problems/forbidden' | 'https://inputbuffer.io/docs/api/problems/forbidden-origin' | 'https://inputbuffer.io/docs/api/problems/widget-token-restricted' | 'https://inputbuffer.io/docs/api/problems/admin-required' | 'https://inputbuffer.io/docs/api/problems/org-required' | 'https://inputbuffer.io/docs/api/problems/feedback-not-found' | 'https://inputbuffer.io/docs/api/problems/buffer-not-found' | 'https://inputbuffer.io/docs/api/problems/target-not-found' | 'https://inputbuffer.io/docs/api/problems/member-not-found' | 'https://inputbuffer.io/docs/api/problems/research-query-not-found' | 'https://inputbuffer.io/docs/api/problems/missing-required-field' | 'https://inputbuffer.io/docs/api/problems/invalid-field-value' | 'https://inputbuffer.io/docs/api/problems/unsupported-media-type' | 'https://inputbuffer.io/docs/api/problems/rate-limited' | 'https://inputbuffer.io/docs/api/problems/usage-limit-reached' | 'https://inputbuffer.io/docs/api/problems/conflict' | 'https://inputbuffer.io/docs/api/problems/internal-error';
7
+ /**
8
+ * RFC 7807 Problem Details, returned by every API error with
9
+ * `Content-Type: application/problem+json`.
10
+ */
1
11
  export interface ProblemDetails {
2
- type: string;
12
+ /** Widened to `string` because a future release may add a type this version doesn't know. */
13
+ type: ProblemType | (string & {});
3
14
  title: string;
4
15
  detail: string;
5
16
  status: number;
6
- category?: 'config' | 'user';
17
+ /**
18
+ * Who caused the problem. `user` means the person filling in the form sent something the
19
+ * API rejected, so `detail` is safe to show them. `integration` means the embed itself is
20
+ * misconfigured, so show something generic and surface `detail` to the developer.
21
+ * Omitted on `internal-error`.
22
+ */
23
+ category?: 'user' | 'integration';
24
+ /** Present only on `missing-required-field` and `invalid-field-value`. */
7
25
  field?: string;
8
26
  }
9
27
  export declare class ApiError extends Error {
10
- type: string;
28
+ type: ProblemType | (string & {});
29
+ title: string;
11
30
  status: number;
12
31
  detail: string;
13
- category?: 'config' | 'user';
32
+ category?: 'user' | 'integration';
14
33
  field?: string;
15
34
  constructor(problem: ProblemDetails);
16
35
  }
17
36
  export interface RestEndpointTarget {
18
37
  type: 'rest_endpoint';
19
- metadata?: {
38
+ metadata: {
20
39
  method: string;
21
40
  path: string;
22
41
  host?: string;
@@ -25,7 +44,7 @@ export interface RestEndpointTarget {
25
44
  }
26
45
  export interface DocumentationTarget {
27
46
  type: 'documentation';
28
- metadata?: {
47
+ metadata: {
29
48
  page_url: string;
30
49
  section_heading?: string;
31
50
  doc_version?: string;
@@ -33,7 +52,7 @@ export interface DocumentationTarget {
33
52
  }
34
53
  export interface CliCommandTarget {
35
54
  type: 'cli_command';
36
- metadata?: {
55
+ metadata: {
37
56
  command: string;
38
57
  subcommand?: string;
39
58
  cli_version?: string;
@@ -41,15 +60,33 @@ export interface CliCommandTarget {
41
60
  };
42
61
  }
43
62
  export type TargetSpec = RestEndpointTarget | DocumentationTarget | CliCommandTarget;
63
+ /** A target as the API echoes it back, resolved to a stored record with an id. */
64
+ export interface TargetRef {
65
+ id: string;
66
+ type: TargetSpec['type'];
67
+ display_name: string;
68
+ metadata: TargetSpec['metadata'];
69
+ }
70
+ /** The reaction the API recorded, including the target it resolved or created. */
71
+ export interface ReactionResult {
72
+ id: string;
73
+ target: TargetRef;
74
+ reaction_value: 1 | -1;
75
+ created_at: string;
76
+ }
44
77
  export interface OpenOptions {
45
78
  target?: TargetSpec;
46
79
  prefill?: {
47
- email?: string;
48
80
  description?: string;
49
81
  };
50
82
  title?: string;
83
+ /**
84
+ * Drives the thumb selection in the UI only. The feedback API has no sentiment field,
85
+ * so this is never sent; thumbs are recorded through the reactions API instead.
86
+ */
51
87
  sentiment?: 'positive' | 'negative';
52
- source?: string;
88
+ /** Overrides the widget-level `submittedBy` for this submission. */
89
+ submittedBy?: string;
53
90
  }
54
91
  export interface FeedbackBarConfig {
55
92
  apiKey: string;
@@ -62,10 +99,11 @@ export interface FeedbackBarConfig {
62
99
  target?: TargetSpec;
63
100
  modalTitle?: string;
64
101
  modalPlaceholder?: string;
65
- showEmailField?: boolean;
66
102
  showTitleField?: boolean;
67
103
  injectStyles?: boolean;
68
- source?: string;
104
+ /** Opaque identifier for whoever submits feedback. Sent as `submitted_by`. */
105
+ submittedBy?: string;
106
+ /** Stable end-user id used to deduplicate reactions. Sent as `user_id`. */
69
107
  userId?: string;
70
108
  }
71
109
  export interface FeedbackBarInstance {
@@ -96,10 +134,10 @@ export interface WidgetConfig {
96
134
  injectStyles?: boolean;
97
135
  title?: string;
98
136
  placeholder?: string;
99
- showEmailField?: boolean;
100
137
  showTitleField?: boolean;
101
138
  showSentiment?: boolean;
102
- source?: string;
139
+ /** Opaque identifier for whoever submits feedback. Sent as `submitted_by`. */
140
+ submittedBy?: string;
103
141
  }
104
142
  export interface WidgetInstance {
105
143
  open(options?: OpenOptions): void;