@upstep/js 0.10.0 → 0.11.0
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 +24 -0
- package/dist/index.cjs +42 -42
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +53 -47
- package/dist/react.cjs +1 -1
- package/dist/react.d.ts +9 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +334 -295
- package/dist/upstep.global.js +4 -4
- package/dist/widget.d.ts +3 -0
- package/dist/widget.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/upstep.global.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(){"use strict";const L="#C9481F",A="#FF7A50";function x(e){return e==="dark"?A:L}const y=12,O=32,z=/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i,f="(\\d{1,3}(?:\\.\\d+)?)",k="(\\d*\\.?\\d+%?)",N=new RegExp(`^rgba?\\(\\s*${f}\\s*(?:,\\s*${f}\\s*,\\s*${f}\\s*(?:,\\s*${k}\\s*)?|\\s+${f}\\s+${f}\\s*(?:\\/\\s*${k}\\s*)?)\\)$`,"i");function b(e){if(typeof e!="string"||e.length>64)return null;const t=e.trim();if(z.test(t)){let u=t.slice(1);u.length<=4&&(u=u.split("").map(l=>l+l).join(""));const h=l=>parseInt(u.slice(l,l+2),16);return[h(0),h(2),h(4),u.length===8?Math.round(h(6)/255*1e3)/1e3:1]}const s=N.exec(t);if(!s)return null;const[o,i,n,a]=[s[1],s[2]??s[5],s[3]??s[6],s[4]??s[7]],r=[o,i,n].map(Number);if(r.some(u=>!(u>=0&&u<=255)))return null;let c=1;return a!==void 0&&(c=a.endsWith("%")?Number(a.slice(0,-1))/100:Number(a),!(c>=0&&c<=1))?null:[r[0],r[1],r[2],c]}function R(e){return b(e)!==null}function
|
|
1
|
+
(function(){"use strict";const L="#C9481F",A="#FF7A50";function x(e){return e==="dark"?A:L}const y=12,O=32,z=/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i,f="(\\d{1,3}(?:\\.\\d+)?)",k="(\\d*\\.?\\d+%?)",N=new RegExp(`^rgba?\\(\\s*${f}\\s*(?:,\\s*${f}\\s*,\\s*${f}\\s*(?:,\\s*${k}\\s*)?|\\s+${f}\\s+${f}\\s*(?:\\/\\s*${k}\\s*)?)\\)$`,"i");function b(e){if(typeof e!="string"||e.length>64)return null;const t=e.trim();if(z.test(t)){let u=t.slice(1);u.length<=4&&(u=u.split("").map(l=>l+l).join(""));const h=l=>parseInt(u.slice(l,l+2),16);return[h(0),h(2),h(4),u.length===8?Math.round(h(6)/255*1e3)/1e3:1]}const s=N.exec(t);if(!s)return null;const[o,i,n,a]=[s[1],s[2]??s[5],s[3]??s[6],s[4]??s[7]],r=[o,i,n].map(Number);if(r.some(u=>!(u>=0&&u<=255)))return null;let c=1;return a!==void 0&&(c=a.endsWith("%")?Number(a.slice(0,-1))/100:Number(a),!(c>=0&&c<=1))?null:[r[0],r[1],r[2],c]}function R(e){return b(e)!==null}function v([e,t,s,o]){const i=n=>Math.round(Math.min(255,Math.max(0,n))).toString(16).padStart(2,"0");return`#${i(e)}${i(t)}${i(s)}${o<1?i(o*255):""}`}function B(e,t,s){const o=b(e),i=b(t);if(!o||!i)return null;const n=Math.min(1,Math.max(0,s));return v([o[0]+(i[0]-o[0])*n,o[1]+(i[1]-o[1])*n,o[2]+(i[2]-o[2])*n,o[3]+(i[3]-o[3])*n])}function j(e,t){const s=b(e);return s?v([s[0],s[1],s[2],s[3]*t]):null}function $([e,t,s]){const o=i=>{const n=i/255;return n<=.03928?n/12.92:((n+.055)/1.055)**2.4};return .2126*o(e)+.7152*o(t)+.0722*o(s)}function w(e,t){const s=b(e),o=b(t);if(!s||!o)return null;const[i,n]=[$(s),$(o)].sort((a,r)=>r-a);return(i+.05)/(n+.05)}const m="#ffffff",S="#1a1915";function H(e){const t=w(e,m);return t===null||t>=3?m:(w(e,S)??0)>t?S:m}function I(e){const t=typeof e=="number"?e:Number(e);return e==null||e===""||!Number.isFinite(t)?y:Math.round(Math.min(O,Math.max(0,t)))}function V(e,t){return Math.round(e*t/y)}const E=["background","surface","border","text","textMuted","accentText"];function U(e,t){const s={};if(!e)return s;for(const o of[e,e[t]])if(o)for(const i of E){const n=o[i];typeof n=="string"&&n.trim()&&(s[i]=n.trim())}return s}const q={bg:"#ffffff",bgSoft:"#f5f5f5",bgHover:"#ededed",text:"#1a1915",textSoft:"#56544d",textFaint:"#9b9890",border:"#e8e6df",overlay:"rgba(26,25,21,.45)"},D={bg:"#000000",bgSoft:"#171717",bgHover:"#262626",text:"#f5f4f0",textSoft:"#b4b1a8",textFaint:"#7d7a72",border:"#33312c",overlay:"rgba(0,0,0,.6)"};function F(e,t,s){return B(e,t,s)??`color-mix(in srgb, ${e} ${Math.round((1-s)*100)}%, ${t})`}function P(e){var r;const t=e.mode==="dark"?D:q,s=U(e.colors,e.mode),o=((r=e.accentColor)==null?void 0:r.trim())||x(e.mode),i=s.background??t.bg,n=s.text??t.text,a=s.surface??t.bgSoft;return{dark:e.mode==="dark",bg:i,bgSoft:a,bgHover:s.surface||s.text?F(a,n,.06):t.bgHover,text:n,textSoft:s.textMuted??t.textSoft,textFaint:s.textMuted||s.background?F(s.textMuted??t.textSoft,i,.4):t.textFaint,border:s.border??t.border,overlay:t.overlay,accent:o,accentText:s.accentText??H(o),accentTint:j(o,.1)??`color-mix(in srgb, ${o} 10%, transparent)`,radius:I(e.radius)}}function G(e){var i;const t=U(e.colors,e.mode),s={},o={background:"bg",surface:"surface",border:"border",text:"text",textMuted:"muted",accentText:"accentText"};for(const n of E){const a=t[n];R(a)&&(s[o[n]]=a)}return e.radius!==void 0&&(s.radius=String(I(e.radius))),(i=e.fontFamily)!=null&&i.trim()&&(s.font=e.fontFamily.trim()),s}const M="upstep-anonymous-id";function K(){const e=typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;if(typeof window>"u")return e;try{const t=window.localStorage.getItem(M);return t||(window.localStorage.setItem(M,e),e)}catch{return e}}class W{constructor(t){this.baseUrl=(t.baseUrl??"https://upstep.dev").replace(/\/$/,""),this.apiKey=t.apiKey,this.supportIdentityToken=t.supportIdentityToken,this.chat=t.chat!==!1,t.userId!==void 0&&(this.userId=t.userId),this.anonymousId=K()}setUserId(t){this.userId=t}headers(){return{"Content-Type":"application/json","x-api-key":this.apiKey}}async supportEnabled(){if(!this.chat)return!1;try{const t=await fetch(`${this.baseUrl}/api/sdk/support`,{headers:this.headers()});return t.ok&&(await t.json()).enabled===!0}catch{return!1}}supportFrameUrl(t,s,o={}){const i=new URLSearchParams({theme:t,accent:s||x(t==="dark"?"dark":"light")}),n=G({mode:t==="dark"?"dark":"light",...o});for(const[a,r]of Object.entries(n))i.set(a,r);return`${this.baseUrl}/support/${encodeURIComponent(this.apiKey)}?${i}`}connectSupportFrame(t,s={}){const o=new URL(this.baseUrl).origin,i=()=>{var a;return(a=t.contentWindow)==null?void 0:a.postMessage({type:"upstep:support:identity",token:this.supportIdentityToken,accentColor:getComputedStyle(t).color,...s.isVisible?{visible:s.isVisible()}:{}},o)},n=a=>{if(a.origin!==o||a.source!==t.contentWindow)return;const r=a.data;if((r==null?void 0:r.type)==="upstep:support:ready")i();else if((r==null?void 0:r.type)==="upstep:support:unread"&&s.onUnread){const c=Number(r.count);s.onUnread({count:Number.isFinite(c)?Math.max(0,Math.floor(c)):0,newMessage:r.newMessage===!0,author:String(r.author??"").slice(0,80),preview:String(r.preview??"").slice(0,200),sound:r.sound!==!1})}};return t.addEventListener("load",i),window.addEventListener("message",n),()=>{t.removeEventListener("load",i),window.removeEventListener("message",n)}}notifySupportVisibility(t,s){var o;(o=t.contentWindow)==null||o.postMessage({type:"upstep:support:visible",visible:s},new URL(this.baseUrl).origin)}async listFeedback(t){const s=new URLSearchParams;t!=null&&t.cursor&&s.set("cursor",t.cursor),t!=null&&t.limit&&s.set("limit",String(t.limit)),t!=null&&t.type&&s.set("type",t.type),t!=null&&t.status&&s.set("status",t.status),t!=null&&t.sort&&s.set("sort",t.sort),this.userId&&s.set("endUserId",this.userId),this.anonymousId&&s.set("anonymousId",this.anonymousId);const o=await fetch(`${this.baseUrl}/api/sdk/feedback?${s}`,{headers:this.headers()});if(!o.ok)throw new Error(`Upstep: ${o.status}`);return o.json()}async submitFeedback(t){const s=await fetch(`${this.baseUrl}/api/sdk/feedback`,{method:"POST",headers:this.headers(),body:JSON.stringify({...t,endUserId:t.endUserId??this.userId,anonymousId:t.anonymousId??this.anonymousId})});if(!s.ok)throw new Error(`Upstep: ${s.status}`);return s.json()}async vote(t,s){const o=await fetch(`${this.baseUrl}/api/sdk/feedback/${t}/vote`,{method:"POST",headers:this.headers(),body:JSON.stringify({value:s,endUserId:this.userId,anonymousId:this.anonymousId})});if(!o.ok)throw new Error(`Upstep: ${o.status}`)}async getItem(t){const s=new URLSearchParams;this.userId&&s.set("endUserId",this.userId),this.anonymousId&&s.set("anonymousId",this.anonymousId);const o=await fetch(`${this.baseUrl}/api/sdk/feedback/${t}?${s}`,{headers:this.headers()});if(!o.ok)throw new Error(`Upstep: ${o.status}`);return o.json()}async removeVote(t){if(!this.userId&&!this.anonymousId)return;const s=new URLSearchParams;this.userId&&s.set("endUserId",this.userId),this.anonymousId&&s.set("anonymousId",this.anonymousId);const o=await fetch(`${this.baseUrl}/api/sdk/feedback/${t}/vote?${s}`,{method:"DELETE",headers:this.headers()});if(!o.ok)throw new Error(`Upstep: ${o.status}`)}}function _(e){const t=e==null?void 0:e.trim();return t&&/^[\w\s,"'.-]{1,200}$/.test(t)?t:""}function T(e){if(e==="light"||e==="dark")return e;if(typeof document<"u"){const t=document.documentElement;return t.classList.contains("dark")||t.getAttribute("data-theme")==="dark"?"dark":"light"}return typeof window<"u"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function Y(e,t){const s="right:24px;left:auto",o=e.accent,i=e.accentText,n=a=>`${V(a,e.radius)}px`;return`
|
|
2
2
|
#upstep-root *{box-sizing:border-box;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif}${t?`
|
|
3
3
|
#upstep-btn,#upstep-btn *,#upstep-backdrop,#upstep-backdrop *,#upstep-toast,#upstep-toast *{font-family:${t}}`:""}
|
|
4
4
|
#upstep-btn{position:fixed;bottom:24px;${s};z-index:9998;display:inline-flex;align-items:center;gap:7px;background:${o};color:${i};border:none;border-radius:${n(9999)};padding:12px 18px;font-size:14px;font-weight:600;cursor:pointer;box-shadow:0 6px 20px rgba(26,25,21,.18);transition:transform .15s,box-shadow .15s}
|
|
@@ -62,9 +62,9 @@
|
|
|
62
62
|
@media(prefers-reduced-motion:reduce){.upstep-unread,#upstep-toast{animation:none}}
|
|
63
63
|
.upstep-empty{text-align:center;color:${e.textFaint};font-size:14px;padding:40px 0}
|
|
64
64
|
.upstep-empty strong{display:block;color:${e.textSoft};font-size:15px;margin-bottom:4px}
|
|
65
|
-
`}const J='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>';class X{constructor(t,s={}){this.isOpen=!1,this.tab="submit",this.feedItems=[],this.selectedType="GENERAL",this.loading=!1,this.hasSupport=!1,this.disconnectSupport=null,this.unread=0,this.audio=null,this.frameTheme=null,this.unreadListeners=new Set,this.client=t,this.options=s,this.position="right",this.showLauncher=s.launcher!==!1,this.themeMode=s.theme??"auto",this.palette=this.buildPalette(T(this.themeMode))}buildPalette(t){return P({mode:t,accentColor:this.options.accentColor,colors:this.options.colors,radius:this.options.radius})}get accent(){return this.palette.accent}supportFrameSrc(){return this.client.supportFrameUrl(this.palette.dark?"dark":"light",this.accent,{colors:this.options.colors,radius:this.options.radius,fontFamily:this.options.fontFamily})}mount(){this.injectStyles(),this.showLauncher&&this.renderButton(),this.client.supportEnabled().then(t=>{if(this.hasSupport=t,t){const s=document.querySelector("#upstep-btn span");s&&(s.textContent="Help & feedback"),this.isOpen?this.renderModal():this.hasOpenedSupport()&&this.preloadSupport()}})}openWidget(){this.openModal()}closeWidget(){this.closeModal()}isChatVisible(){return this.isOpen}onUnread(t){return this.unreadListeners.add(t),t(this.unread),()=>{this.unreadListeners.delete(t)}}injectStyles(){var s;(s=document.getElementById("upstep-styles"))==null||s.remove();const t=document.createElement("style");t.id="upstep-styles",t.textContent=Y(this.palette,_(this.options.fontFamily)),document.head.appendChild(t)}renderButton(){const t=document.createElement("button");t.id="upstep-btn",t.setAttribute("aria-label","Open help and feedback"),t.innerHTML=`${J}<span
|
|
65
|
+
`}const J='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>';class X{constructor(t,s={}){this.isOpen=!1,this.tab="submit",this.feedItems=[],this.selectedType="GENERAL",this.loading=!1,this.hasSupport=!1,this.disconnectSupport=null,this.unread=0,this.audio=null,this.frameTheme=null,this.unreadListeners=new Set,this.client=t,this.options=s,this.position="right",this.showLauncher=s.launcher!==!1,this.feedback=s.feedback!==!1,this.themeMode=s.theme??"auto",this.palette=this.buildPalette(T(this.themeMode))}buildPalette(t){return P({mode:t,accentColor:this.options.accentColor,colors:this.options.colors,radius:this.options.radius})}get accent(){return this.palette.accent}supportFrameSrc(){return this.client.supportFrameUrl(this.palette.dark?"dark":"light",this.accent,{colors:this.options.colors,radius:this.options.radius,fontFamily:this.options.fontFamily})}mount(){this.injectStyles(),this.showLauncher&&this.feedback&&this.renderButton(),this.client.supportEnabled().then(t=>{if(this.hasSupport=t,t){this.showLauncher&&!this.feedback&&this.renderButton();const s=document.querySelector("#upstep-btn span");s&&(s.textContent=this.feedback?"Help & feedback":"Help"),this.isOpen?this.renderModal():this.hasOpenedSupport()&&this.preloadSupport()}})}openWidget(){this.openModal()}closeWidget(){this.closeModal()}isChatVisible(){return this.isOpen}onUnread(t){return this.unreadListeners.add(t),t(this.unread),()=>{this.unreadListeners.delete(t)}}injectStyles(){var s;(s=document.getElementById("upstep-styles"))==null||s.remove();const t=document.createElement("style");t.id="upstep-styles",t.textContent=Y(this.palette,_(this.options.fontFamily)),document.head.appendChild(t)}renderButton(){const t=document.createElement("button");t.id="upstep-btn",t.setAttribute("aria-label",this.feedback?"Open help and feedback":"Open support chat"),t.innerHTML=`${J}<span>${this.feedback?"Feedback":"Help"}</span>`,t.addEventListener("click",()=>{this.openModal()}),document.body.appendChild(t)}supportFrame(){return document.querySelector("#upstep-support-frame")}get usedKey(){return`upstep:support-opened:${this.client.baseUrl}`}hasOpenedSupport(){try{return localStorage.getItem(this.usedKey)==="1"}catch{return!1}}preloadSupport(){this.tab="support",this.renderModal(!0)}openModal(){if(!this.feedback&&!this.hasSupport)return;if(this.unlockAudio(),!this.isOpen&&this.hasSupport){this.tab="support";try{localStorage.setItem(this.usedKey,"1")}catch{}}const t=T(this.themeMode),s=document.getElementById("upstep-backdrop"),o=this.supportFrame();if(!this.isOpen&&s&&o&&s.style.display==="none"&&this.frameTheme===t){this.isOpen=!0,s.style.display="",this.client.notifySupportVisibility(o,!0),this.setUnread(0),this.fetchFeed();return}this.isOpen=!0,this.palette=this.buildPalette(t),this.injectStyles(),this.fetchFeed(),this.renderModal(),this.setUnread(0)}closeModal(){var t,s;if(this.isOpen=!1,this.hasSupport){const o=this.supportFrame(),i=document.getElementById("upstep-backdrop");o&&i?(i.style.display="none",this.client.notifySupportVisibility(o,!1)):this.preloadSupport();return}(t=this.disconnectSupport)==null||t.call(this),this.disconnectSupport=null,(s=document.getElementById("upstep-backdrop"))==null||s.remove()}setUnread(t){this.unread=t;const s=document.getElementById("upstep-btn"),o=s==null?void 0:s.querySelector(".upstep-unread");if(s){if(t>0){const n=o??document.createElement("span");n.className="upstep-unread",n.textContent=t>9?"9+":String(t),o||s.appendChild(n)}else o==null||o.remove();s.setAttribute("aria-label",t>0?`Open help and feedback, ${t} unread ${t===1?"message":"messages"}`:"Open help and feedback")}const i=document.title.replace(/^\(\d+\)\s/,"");document.title=t>0?`(${t}) ${i}`:i,t===0&&this.hideToast(),this.unreadListeners.forEach(n=>n(t))}onSupportUnread(t){if(this.isOpen)return this.setUnread(0);this.setUnread(t.count),t.newMessage&&t.count>0&&(this.showToast(t),t.sound&&this.chime())}showToast(t){this.hideToast();const s=document.createElement("button");s.id="upstep-toast",s.type="button",s.setAttribute("role","status");const o=document.createElement("b");o.textContent=t.author||"New message";const i=document.createElement("span");i.textContent=t.preview;const n=document.createElement("em");n.textContent=t.count>1?`${t.count} new messages`:"Tap to reply",s.append(o,i,n),s.addEventListener("click",()=>this.openModal()),document.body.appendChild(s),this.toastTimer=setTimeout(()=>this.hideToast(),9e3)}hideToast(){var t;clearTimeout(this.toastTimer),(t=document.getElementById("upstep-toast"))==null||t.remove()}unlockAudio(){try{const t=window.AudioContext||window.webkitAudioContext;if(!t)return;this.audio=this.audio??new t,this.audio.state==="suspended"&&this.audio.resume()}catch{}}chime(){const t=this.audio;if(!t||t.state!=="running")return;const s=t.currentTime;for(const[o,i]of[[880,0],[1318,.12]]){const n=t.createOscillator(),a=t.createGain();n.type="sine",n.frequency.value=o,a.gain.setValueAtTime(1e-4,s+i),a.gain.exponentialRampToValueAtTime(.14,s+i+.02),a.gain.exponentialRampToValueAtTime(1e-4,s+i+.5),n.connect(a),a.connect(t.destination),n.start(s+i),n.stop(s+i+.55)}}async fetchFeed(){if(this.feedback)try{const t=await this.client.listFeedback({sort:"votes",limit:20});this.feedItems=t.items,this.renderFeedList()}catch{}}renderModal(t=!1){var i,n,a;(i=this.disconnectSupport)==null||i.call(this),this.disconnectSupport=null;const s=document.createElement("div");s.id="upstep-backdrop",s.addEventListener("click",r=>{r.target===s&&this.closeModal()}),s.innerHTML=`
|
|
66
66
|
<div id="upstep-modal" style="max-width:${this.hasSupport?"460px":"440px"}">
|
|
67
|
-
${this.hasSupport?`<div class="upstep-mode" style="display:flex;align-items:center;gap:14px;padding:10px 14px;border-bottom:1px solid ${this.palette.border}"><div id="upstep-tabs" style="margin:0;padding:0;background:transparent;flex:1"><button class="upstep-tab ${this.tab==="support"?"active":""}" data-tab="support">Support</button><button class="upstep-tab ${this.tab!=="support"?"active":""}" data-tab="feed">Ideas</button></div><button id="upstep-close" aria-label="Close" style="flex-shrink:0;background:transparent">✕</button></div>`:`<div id="upstep-header"><div><h2>Share your feedback</h2><p>Tell us what to build next, or vote on ideas.</p></div><button id="upstep-close" aria-label="Close">✕</button></div><div id="upstep-tabs"><button class="upstep-tab ${this.tab==="submit"?"active":""}" data-tab="submit">Give feedback</button><button class="upstep-tab ${this.tab==="feed"?"active":""}" data-tab="feed">Vote on ideas</button></div>`}
|
|
67
|
+
${this.hasSupport&&!this.feedback?`<div class="upstep-mode" style="display:flex;align-items:center;gap:14px;padding:14px 16px 14px 20px;border-bottom:1px solid ${this.palette.border}"><h2 style="flex:1;margin:0;font-size:16px">Support</h2><button id="upstep-close" aria-label="Close" style="flex-shrink:0;background:transparent">✕</button></div>`:this.hasSupport?`<div class="upstep-mode" style="display:flex;align-items:center;gap:14px;padding:10px 14px;border-bottom:1px solid ${this.palette.border}"><div id="upstep-tabs" style="margin:0;padding:0;background:transparent;flex:1"><button class="upstep-tab ${this.tab==="support"?"active":""}" data-tab="support">Support</button><button class="upstep-tab ${this.tab!=="support"?"active":""}" data-tab="feed">Ideas</button></div><button id="upstep-close" aria-label="Close" style="flex-shrink:0;background:transparent">✕</button></div>`:`<div id="upstep-header"><div><h2>Share your feedback</h2><p>Tell us what to build next, or vote on ideas.</p></div><button id="upstep-close" aria-label="Close">✕</button></div><div id="upstep-tabs"><button class="upstep-tab ${this.tab==="submit"?"active":""}" data-tab="submit">Give feedback</button><button class="upstep-tab ${this.tab==="feed"?"active":""}" data-tab="feed">Vote on ideas</button></div>`}
|
|
68
68
|
<div id="upstep-body" style="${this.tab==="support"?"padding:0;overflow:hidden":""}">
|
|
69
69
|
${this.tab==="support"?`<iframe id="upstep-support-frame" title="Customer support" src="${g(this.supportFrameSrc())}" style="width:100%;height:min(560px,calc(100dvh - 168px));min-height:300px;border:0;display:block"></iframe>`:this.tab==="submit"?this.renderSubmitForm():this.renderFeed()}
|
|
70
70
|
</div>
|
|
@@ -100,4 +100,4 @@
|
|
|
100
100
|
<span class="upstep-feedback-date">${new Date(s.createdAt).toLocaleDateString()}</span>
|
|
101
101
|
</div>
|
|
102
102
|
</div>
|
|
103
|
-
</div>`}).join(""):`${t}<div class="upstep-empty"><strong>No ideas yet</strong>Be the first to share one.</div>`}renderFeedList(){const t=document.getElementById("upstep-body");!t||this.tab!=="feed"||(t.innerHTML=this.renderFeed(),this.bindFeed())}bindSubmitForm(){var t;document.querySelectorAll(".upstep-type-btn").forEach(s=>{s.addEventListener("click",()=>{this.selectedType=s.dataset.type,document.querySelectorAll(".upstep-type-btn").forEach(o=>o.classList.remove("selected")),s.classList.add("selected")})}),(t=document.getElementById("upstep-submit-btn"))==null||t.addEventListener("click",async()=>{const s=document.getElementById("upstep-textarea"),o=document.getElementById("upstep-form-msg"),i=document.getElementById("upstep-submit-btn");if(!s||this.loading)return;const n=s.value.trim();if(n){this.loading=!0,i&&(i.disabled=!0,i.textContent="Sending…");try{await this.client.submitFeedback({content:n,type:this.hasSupport?"FEATURE":this.selectedType}),s.value="",o&&(o.textContent=this.hasSupport?"Idea received. Thank you.":"Feedback received. Thank you."),await this.fetchFeed()}catch{o&&(o.textContent="Something went wrong. Please try again.")}finally{this.loading=!1,i&&(i.disabled=!1,i.textContent=this.hasSupport?"Suggest idea":"Send feedback")}}})}bindFeed(){this.bindVoteButtons(),document.querySelectorAll("#upstep-body [data-goto]").forEach(t=>{t.addEventListener("click",()=>{this.tab=t.dataset.goto,this.renderModal()})})}bindVoteButtons(){document.querySelectorAll(".upstep-vote").forEach(t=>{t.addEventListener("click",async()=>{const s=t.dataset.feedback;try{await this.client.vote(s,"UP"),await this.fetchFeed()}catch{}})})}}function g(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}let p=null,d=null;const C={init(e){if(p=new W(e),typeof window<"u"){const t={};e.accentColor!==void 0&&(t.accentColor=e.accentColor),e.position!==void 0&&(t.position=e.position),e.theme!==void 0&&(t.theme=e.theme),e.launcher!==void 0&&(t.launcher=e.launcher),e.colors!==void 0&&(t.colors=e.colors),e.radius!==void 0&&(t.radius=e.radius),e.fontFamily!==void 0&&(t.fontFamily=e.fontFamily);const s=()=>{d=new X(p,t),d.mount()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",s):s()}return p},open(){d==null||d.openWidget()},close(){d==null||d.closeWidget()},identify(e){p==null||p.setUserId(e)},identifySupport(e){var s;p&&(p.supportIdentityToken=e);const t=document.querySelector("#upstep-support-frame");t&&p&&((s=t.contentWindow)==null||s.postMessage({type:"upstep:support:identity",token:e,visible:(d==null?void 0:d.isChatVisible())??!0},new URL(p.baseUrl).origin))},onUnread(e){return(d==null?void 0:d.onUnread(e))??(()=>{})},get client(){if(!p)throw new Error("Upstep.init() must be called first");return p}};if(typeof document<"u"){const e=document.currentScript,t=e==null?void 0:e.dataset.apiKey,s=e==null?void 0:e.dataset.userId,o=e==null?void 0:e.dataset.baseUrl,i=e==null?void 0:e.dataset.accentColor,n=e==null?void 0:e.dataset.position,a=e==null?void 0:e.dataset.theme;if(t){const r={apiKey:t};s&&(r.userId=s),(e==null?void 0:e.dataset.chat)!==void 0&&(r.chat=e.dataset.chat!=="false"),o&&(r.baseUrl=o),i&&(r.accentColor=i),(n==="left"||n==="right")&&(r.position=n),(a==="light"||a==="dark"||a==="auto")&&(r.theme=a);const c=e==null?void 0:e.dataset.colors;if(c)try{const l=JSON.parse(c);l&&typeof l=="object"&&(r.colors=l)}catch{console.warn("Upstep: data-colors must be JSON")}const u=e==null?void 0:e.dataset.radius;u&&Number.isFinite(Number(u))&&(r.radius=Number(u));const h=e==null?void 0:e.dataset.fontFamily;h&&(r.fontFamily=h),C.init(r)}}window.Upstep=C})();
|
|
103
|
+
</div>`}).join(""):`${t}<div class="upstep-empty"><strong>No ideas yet</strong>Be the first to share one.</div>`}renderFeedList(){const t=document.getElementById("upstep-body");!t||this.tab!=="feed"||(t.innerHTML=this.renderFeed(),this.bindFeed())}bindSubmitForm(){var t;document.querySelectorAll(".upstep-type-btn").forEach(s=>{s.addEventListener("click",()=>{this.selectedType=s.dataset.type,document.querySelectorAll(".upstep-type-btn").forEach(o=>o.classList.remove("selected")),s.classList.add("selected")})}),(t=document.getElementById("upstep-submit-btn"))==null||t.addEventListener("click",async()=>{const s=document.getElementById("upstep-textarea"),o=document.getElementById("upstep-form-msg"),i=document.getElementById("upstep-submit-btn");if(!s||this.loading)return;const n=s.value.trim();if(n){this.loading=!0,i&&(i.disabled=!0,i.textContent="Sending…");try{await this.client.submitFeedback({content:n,type:this.hasSupport?"FEATURE":this.selectedType}),s.value="",o&&(o.textContent=this.hasSupport?"Idea received. Thank you.":"Feedback received. Thank you."),await this.fetchFeed()}catch{o&&(o.textContent="Something went wrong. Please try again.")}finally{this.loading=!1,i&&(i.disabled=!1,i.textContent=this.hasSupport?"Suggest idea":"Send feedback")}}})}bindFeed(){this.bindVoteButtons(),document.querySelectorAll("#upstep-body [data-goto]").forEach(t=>{t.addEventListener("click",()=>{this.tab=t.dataset.goto,this.renderModal()})})}bindVoteButtons(){document.querySelectorAll(".upstep-vote").forEach(t=>{t.addEventListener("click",async()=>{const s=t.dataset.feedback;try{await this.client.vote(s,"UP"),await this.fetchFeed()}catch{}})})}}function g(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}let p=null,d=null;const C={init(e){if(p=new W(e),typeof window<"u"){const t={};e.accentColor!==void 0&&(t.accentColor=e.accentColor),e.position!==void 0&&(t.position=e.position),e.theme!==void 0&&(t.theme=e.theme),e.launcher!==void 0&&(t.launcher=e.launcher),e.feedback!==void 0&&(t.feedback=e.feedback),e.colors!==void 0&&(t.colors=e.colors),e.radius!==void 0&&(t.radius=e.radius),e.fontFamily!==void 0&&(t.fontFamily=e.fontFamily);const s=()=>{d=new X(p,t),d.mount()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",s):s()}return p},open(){d==null||d.openWidget()},close(){d==null||d.closeWidget()},identify(e){p==null||p.setUserId(e)},identifySupport(e){var s;p&&(p.supportIdentityToken=e);const t=document.querySelector("#upstep-support-frame");t&&p&&((s=t.contentWindow)==null||s.postMessage({type:"upstep:support:identity",token:e,visible:(d==null?void 0:d.isChatVisible())??!0},new URL(p.baseUrl).origin))},onUnread(e){return(d==null?void 0:d.onUnread(e))??(()=>{})},get client(){if(!p)throw new Error("Upstep.init() must be called first");return p}};if(typeof document<"u"){const e=document.currentScript,t=e==null?void 0:e.dataset.apiKey,s=e==null?void 0:e.dataset.userId,o=e==null?void 0:e.dataset.baseUrl,i=e==null?void 0:e.dataset.accentColor,n=e==null?void 0:e.dataset.position,a=e==null?void 0:e.dataset.theme;if(t){const r={apiKey:t};s&&(r.userId=s),(e==null?void 0:e.dataset.chat)!==void 0&&(r.chat=e.dataset.chat!=="false"),(e==null?void 0:e.dataset.feedback)!==void 0&&(r.feedback=e.dataset.feedback!=="false"),o&&(r.baseUrl=o),i&&(r.accentColor=i),(n==="left"||n==="right")&&(r.position=n),(a==="light"||a==="dark"||a==="auto")&&(r.theme=a);const c=e==null?void 0:e.dataset.colors;if(c)try{const l=JSON.parse(c);l&&typeof l=="object"&&(r.colors=l)}catch{console.warn("Upstep: data-colors must be JSON")}const u=e==null?void 0:e.dataset.radius;u&&Number.isFinite(Number(u))&&(r.radius=Number(u));const h=e==null?void 0:e.dataset.fontFamily;h&&(r.fontFamily=h),C.init(r)}}window.Upstep=C})();
|
package/dist/widget.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ export interface WidgetOptions {
|
|
|
14
14
|
theme?: ThemeMode;
|
|
15
15
|
/** Render the floating launcher button. Defaults to true. */
|
|
16
16
|
launcher?: boolean;
|
|
17
|
+
/** Show the feedback and ideas board. False makes a support-chat-only widget. Defaults to true. */
|
|
18
|
+
feedback?: boolean;
|
|
17
19
|
}
|
|
18
20
|
export declare class UpstepWidget {
|
|
19
21
|
private client;
|
|
@@ -24,6 +26,7 @@ export declare class UpstepWidget {
|
|
|
24
26
|
private loading;
|
|
25
27
|
private position;
|
|
26
28
|
private showLauncher;
|
|
29
|
+
private feedback;
|
|
27
30
|
private themeMode;
|
|
28
31
|
private options;
|
|
29
32
|
private palette;
|
package/dist/widget.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../src/widget.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAsB,MAAM,OAAO,CAAC;AAG5D,KAAK,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;AA6G3C,MAAM,WAAW,aAAa;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kEAAkE;IAClE,MAAM,CAAC,EAAE,oBAAoB,CAAC;IAC9B,gDAAgD;IAChD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,sCAAsC;IACtC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC5B,yEAAyE;IACzE,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,GAAG,CAAiB;IAC5B,OAAO,CAAC,SAAS,CAAkB;IACnC,OAAO,CAAC,YAAY,CAA2B;IAC/C,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AAO,CAAC,WAAW;IA+CnB,OAAO,CAAC,gBAAgB;IAqCxB,OAAO,CAAC,UAAU;IA+BlB,OAAO,CAAC,cAAc;IAOtB,OAAO,CAAC,cAAc;IA2DtB,OAAO,CAAC,QAAQ;IAYhB,OAAO,CAAC,eAAe;CAaxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@upstep/js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "UpStep feedback, voting and AI support widgets for web apps",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://upstep.dev",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"dist"
|
|
48
48
|
],
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@upstep/types": "0.
|
|
50
|
+
"@upstep/types": "0.11.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"react": ">=18",
|