@upstep/js 0.9.0 → 0.10.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/dist/index.cjs +25 -12
- package/dist/index.js +175 -154
- package/dist/react.cjs +1 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +354 -348
- package/dist/support.cjs +1 -1
- package/dist/support.d.ts +10 -1
- package/dist/support.d.ts.map +1 -1
- package/dist/support.js +50 -33
- package/dist/upstep.global.js +26 -13
- package/dist/widget.d.ts +1 -0
- package/dist/widget.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const g=require("./api-j3GMTEE7.js"),l=require("./theme.cjs");function y(t){const e=t==null?void 0:t.trim();return e&&/^[\w\s,"'.-]{1,200}$/.test(e)?e:""}function f(t){if(t==="light"||t==="dark")return t;if(typeof document<"u"){const e=document.documentElement;return e.classList.contains("dark")||e.getAttribute("data-theme")==="dark"?"dark":"light"}return typeof window<"u"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function v(t,e){const s="right:24px;left:auto",o=t.accent,n=t.accentText,i=r=>`${l.scaleRadius(r,t.radius)}px`;return`
|
|
2
2
|
#upstep-root *{box-sizing:border-box;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif}${e?`
|
|
3
3
|
#upstep-btn,#upstep-btn *,#upstep-backdrop,#upstep-backdrop *,#upstep-toast,#upstep-toast *{font-family:${e}}`:""}
|
|
4
4
|
#upstep-btn{position:fixed;bottom:24px;${s};z-index:9998;display:inline-flex;align-items:center;gap:7px;background:${o};color:${n};border:none;border-radius:${i(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}
|
|
@@ -31,6 +31,11 @@
|
|
|
31
31
|
.upstep-submit{width:100%;padding:12px;background:${o};color:${n};border:none;border-radius:${i(11)};font-size:14px;font-weight:600;cursor:pointer;margin-top:14px;transition:filter .15s}
|
|
32
32
|
.upstep-submit:hover{filter:brightness(.94)}
|
|
33
33
|
.upstep-submit:disabled{opacity:.5;cursor:not-allowed}
|
|
34
|
+
.upstep-suggest{width:100%;display:flex;align-items:center;justify-content:center;gap:6px;padding:10px;margin-bottom:12px;background:${t.bg};color:${t.text};border:1px dashed ${t.border};border-radius:${i(11)};font-size:14px;font-weight:600;cursor:pointer;transition:border-color .15s}
|
|
35
|
+
.upstep-suggest:hover{border-color:${o}}
|
|
36
|
+
.upstep-back{background:none;border:none;padding:0;margin-bottom:10px;color:${t.textSoft};font-size:13px;font-weight:600;cursor:pointer}
|
|
37
|
+
.upstep-hint{font-size:13px;color:${t.textFaint};margin:10px 0 0;text-align:center}
|
|
38
|
+
.upstep-hint button{background:none;border:none;padding:0;color:${o};font:inherit;font-weight:600;cursor:pointer}
|
|
34
39
|
#upstep-form-msg{font-size:14px;text-align:center;margin-top:12px;color:${o};font-weight:500}
|
|
35
40
|
.upstep-feedback-item{display:flex;gap:12px;padding:14px;border:1px solid ${t.border};border-radius:${i(14)};margin-bottom:10px;background:${t.bg};transition:border-color .15s}
|
|
36
41
|
.upstep-feedback-item:hover{border-color:${t.textFaint}}
|
|
@@ -59,12 +64,20 @@
|
|
|
59
64
|
.upstep-empty strong{display:block;color:${t.textSoft};font-size:15px;margin-bottom:4px}
|
|
60
65
|
`}const k='<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 ${constructor(e,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=e,this.options=s,this.position="right",this.showLauncher=s.launcher!==!1,this.themeMode=s.theme??"auto",this.palette=this.buildPalette(f(this.themeMode))}buildPalette(e){return l.buildWidgetPalette({mode:e,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(e=>{if(this.hasSupport=e,e){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(e){return this.unreadListeners.add(e),e(this.unread),()=>{this.unreadListeners.delete(e)}}injectStyles(){var s;(s=document.getElementById("upstep-styles"))==null||s.remove();const e=document.createElement("style");e.id="upstep-styles",e.textContent=v(this.palette,y(this.options.fontFamily)),document.head.appendChild(e)}renderButton(){const e=document.createElement("button");e.id="upstep-btn",e.setAttribute("aria-label","Open help and feedback"),e.innerHTML=`${k}<span>Feedback</span>`,e.addEventListener("click",()=>{this.openModal()}),document.body.appendChild(e)}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.unlockAudio(),!this.isOpen&&this.hasSupport){this.tab="support";try{localStorage.setItem(this.usedKey,"1")}catch{}}const e=f(this.themeMode),s=document.getElementById("upstep-backdrop"),o=this.supportFrame();if(!this.isOpen&&s&&o&&s.style.display==="none"&&this.frameTheme===e){this.isOpen=!0,s.style.display="",this.client.notifySupportVisibility(o,!0),this.setUnread(0),this.fetchFeed();return}this.isOpen=!0,this.palette=this.buildPalette(e),this.injectStyles(),this.fetchFeed(),this.renderModal(),this.setUnread(0)}closeModal(){var e,s;if(this.isOpen=!1,this.hasSupport){const o=this.supportFrame(),n=document.getElementById("upstep-backdrop");o&&n?(n.style.display="none",this.client.notifySupportVisibility(o,!1)):this.preloadSupport();return}(e=this.disconnectSupport)==null||e.call(this),this.disconnectSupport=null,(s=document.getElementById("upstep-backdrop"))==null||s.remove()}setUnread(e){this.unread=e;const s=document.getElementById("upstep-btn"),o=s==null?void 0:s.querySelector(".upstep-unread");if(s){if(e>0){const i=o??document.createElement("span");i.className="upstep-unread",i.textContent=e>9?"9+":String(e),o||s.appendChild(i)}else o==null||o.remove();s.setAttribute("aria-label",e>0?`Open help and feedback, ${e} unread ${e===1?"message":"messages"}`:"Open help and feedback")}const n=document.title.replace(/^\(\d+\)\s/,"");document.title=e>0?`(${e}) ${n}`:n,e===0&&this.hideToast(),this.unreadListeners.forEach(i=>i(e))}onSupportUnread(e){if(this.isOpen)return this.setUnread(0);this.setUnread(e.count),e.newMessage&&e.count>0&&(this.showToast(e),e.sound&&this.chime())}showToast(e){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=e.author||"New message";const n=document.createElement("span");n.textContent=e.preview;const i=document.createElement("em");i.textContent=e.count>1?`${e.count} new messages`:"Tap to reply",s.append(o,n,i),s.addEventListener("click",()=>this.openModal()),document.body.appendChild(s),this.toastTimer=setTimeout(()=>this.hideToast(),9e3)}hideToast(){var e;clearTimeout(this.toastTimer),(e=document.getElementById("upstep-toast"))==null||e.remove()}unlockAudio(){try{const e=window.AudioContext||window.webkitAudioContext;if(!e)return;this.audio=this.audio??new e,this.audio.state==="suspended"&&this.audio.resume()}catch{}}chime(){const e=this.audio;if(!e||e.state!=="running")return;const s=e.currentTime;for(const[o,n]of[[880,0],[1318,.12]]){const i=e.createOscillator(),r=e.createGain();i.type="sine",i.frequency.value=o,r.gain.setValueAtTime(1e-4,s+n),r.gain.exponentialRampToValueAtTime(.14,s+n+.02),r.gain.exponentialRampToValueAtTime(1e-4,s+n+.5),i.connect(r),r.connect(e.destination),i.start(s+n),i.stop(s+n+.55)}}async fetchFeed(){try{const e=await this.client.listFeedback({sort:"votes",limit:20});this.feedItems=e.items,this.renderFeedList()}catch{}}renderModal(e=!1){var n,i,r;(n=this.disconnectSupport)==null||n.call(this),this.disconnectSupport=null;const s=document.createElement("div");s.id="upstep-backdrop",s.addEventListener("click",a=>{a.target===s&&this.closeModal()}),s.innerHTML=`
|
|
61
66
|
<div id="upstep-modal" style="max-width:${this.hasSupport?"460px":"440px"}">
|
|
62
|
-
${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
|
|
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>`}
|
|
63
68
|
<div id="upstep-body" style="${this.tab==="support"?"padding:0;overflow:hidden":""}">
|
|
64
69
|
${this.tab==="support"?`<iframe id="upstep-support-frame" title="Customer support" src="${h(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()}
|
|
65
70
|
</div>
|
|
66
71
|
</div>
|
|
67
|
-
`,(i=document.getElementById("upstep-backdrop"))==null||i.remove(),e&&(s.style.display="none"),document.body.appendChild(s),(r=s.querySelector("#upstep-close"))==null||r.addEventListener("click",()=>this.closeModal()),s.querySelectorAll(".upstep-tab").forEach(a=>{a.addEventListener("click",()=>{this.tab=a.dataset.tab,this.renderModal()})});const o=s.querySelector("#upstep-support-frame");o&&(o.style.color=this.accent,this.frameTheme=this.palette.dark?"dark":"light",this.disconnectSupport=this.client.connectSupportFrame(o,{isVisible:()=>this.isOpen,onUnread:a=>this.onSupportUnread(a)})),this.bindSubmitForm(),this.
|
|
72
|
+
`,(i=document.getElementById("upstep-backdrop"))==null||i.remove(),e&&(s.style.display="none"),document.body.appendChild(s),(r=s.querySelector("#upstep-close"))==null||r.addEventListener("click",()=>this.closeModal()),s.querySelectorAll(".upstep-tab").forEach(a=>{a.addEventListener("click",()=>{this.tab=a.dataset.tab,this.renderModal()})});const o=s.querySelector("#upstep-support-frame");o&&(o.style.color=this.accent,this.frameTheme=this.palette.dark?"dark":"light",this.disconnectSupport=this.client.connectSupportFrame(o,{isVisible:()=>this.isOpen,onUnread:a=>this.onSupportUnread(a)})),this.bindSubmitForm(),this.bindFeed()}renderSubmitForm(){const e=["BUG","FEATURE","GENERAL"],s={BUG:"Bug",FEATURE:"Feature",GENERAL:"General"},o={BUG:'<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><ellipse cx="8" cy="10" rx="3.5" ry="4.5"/><path d="M8 5.5V4M5.5 6.5 3.5 5M10.5 6.5 12.5 5M4.5 10.5 2.5 10M11.5 10.5 13.5 10"/></svg>',FEATURE:'<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M8 2v1.5M8 12.5V14M2 8h1.5M12.5 8H14M4.1 4.1l1 1M10.9 10.9l1 1M11.9 4.1l-1 1M5.1 10.9l-1 1"/><circle cx="8" cy="8" r="2.5"/></svg>',GENERAL:'<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M14 9a2 2 0 0 1-2 2H5L2 14V4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v5z"/></svg>'};return this.hasSupport?`
|
|
73
|
+
<div class="upstep-form">
|
|
74
|
+
<button class="upstep-back" data-goto="feed">← Ideas</button>
|
|
75
|
+
<textarea id="upstep-textarea" placeholder="What would you like us to build?" maxlength="2000"></textarea>
|
|
76
|
+
<button class="upstep-submit" id="upstep-submit-btn">Suggest idea</button>
|
|
77
|
+
<div id="upstep-form-msg"></div>
|
|
78
|
+
<p class="upstep-hint">Something not working? <button data-goto="support">Ask support</button></p>
|
|
79
|
+
</div>
|
|
80
|
+
`:`
|
|
68
81
|
<div class="upstep-form">
|
|
69
82
|
<textarea id="upstep-textarea" placeholder="What's on your mind?" maxlength="2000"></textarea>
|
|
70
83
|
<div class="upstep-type-row">
|
|
@@ -73,18 +86,18 @@
|
|
|
73
86
|
<button class="upstep-submit" id="upstep-submit-btn">Send feedback</button>
|
|
74
87
|
<div id="upstep-form-msg"></div>
|
|
75
88
|
</div>
|
|
76
|
-
`}renderFeed(){return this.feedItems.length?this.feedItems.map(
|
|
77
|
-
<div class="upstep-feedback-item" data-id="${
|
|
78
|
-
<button class="upstep-vote${
|
|
89
|
+
`}renderFeed(){const e=this.hasSupport?'<button class="upstep-suggest" data-goto="submit"><span aria-hidden="true">+</span> Suggest an idea</button>':"";return this.feedItems.length?e+this.feedItems.map(s=>{var o;return`
|
|
90
|
+
<div class="upstep-feedback-item" data-id="${s.id}">
|
|
91
|
+
<button class="upstep-vote${s.userVote==="UP"?" voted":""}" data-vote="UP" data-feedback="${s.id}">
|
|
79
92
|
<span class="upstep-vote-arrow">▲</span>
|
|
80
|
-
<span class="upstep-vote-count">${
|
|
93
|
+
<span class="upstep-vote-count">${s.upvotes}</span>
|
|
81
94
|
</button>
|
|
82
95
|
<div class="upstep-feedback-main">
|
|
83
|
-
<p class="upstep-feedback-content">${h(
|
|
96
|
+
<p class="upstep-feedback-content">${h(s.content)}</p>
|
|
84
97
|
<div class="upstep-feedback-meta">
|
|
85
|
-
<span class="upstep-badge upstep-badge-${
|
|
86
|
-
<span class="upstep-badge upstep-badge-general">${h(((s
|
|
87
|
-
<span class="upstep-feedback-date">${new Date(
|
|
98
|
+
<span class="upstep-badge upstep-badge-${s.type.toLowerCase()}">${s.type}</span>
|
|
99
|
+
<span class="upstep-badge upstep-badge-general">${h(((o=s.boardStatus)==null?void 0:o.name)??s.status.replace("_"," "))}</span>
|
|
100
|
+
<span class="upstep-feedback-date">${new Date(s.createdAt).toLocaleDateString()}</span>
|
|
88
101
|
</div>
|
|
89
102
|
</div>
|
|
90
|
-
</div>`}).join("")
|
|
103
|
+
</div>`}).join(""):`${e}<div class="upstep-empty"><strong>No ideas yet</strong>Be the first to share one.</div>`}renderFeedList(){const e=document.getElementById("upstep-body");!e||this.tab!=="feed"||(e.innerHTML=this.renderFeed(),this.bindFeed())}bindSubmitForm(){var e;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")})}),(e=document.getElementById("upstep-submit-btn"))==null||e.addEventListener("click",async()=>{const s=document.getElementById("upstep-textarea"),o=document.getElementById("upstep-form-msg"),n=document.getElementById("upstep-submit-btn");if(!s||this.loading)return;const i=s.value.trim();if(i){this.loading=!0,n&&(n.disabled=!0,n.textContent="Sending…");try{await this.client.submitFeedback({content:i,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,n&&(n.disabled=!1,n.textContent=this.hasSupport?"Suggest idea":"Send feedback")}}})}bindFeed(){this.bindVoteButtons(),document.querySelectorAll("#upstep-body [data-goto]").forEach(e=>{e.addEventListener("click",()=>{this.tab=e.dataset.goto,this.renderModal()})})}bindVoteButtons(){document.querySelectorAll(".upstep-vote").forEach(e=>{e.addEventListener("click",async()=>{const s=e.dataset.feedback;try{await this.client.vote(s,"UP"),await this.fetchFeed()}catch{}})})}}function h(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}let d=null,p=null;const x={init(t){if(d=new g.UpstepApiClient(t),typeof window<"u"){const e={};t.accentColor!==void 0&&(e.accentColor=t.accentColor),t.position!==void 0&&(e.position=t.position),t.theme!==void 0&&(e.theme=t.theme),t.launcher!==void 0&&(e.launcher=t.launcher),t.colors!==void 0&&(e.colors=t.colors),t.radius!==void 0&&(e.radius=t.radius),t.fontFamily!==void 0&&(e.fontFamily=t.fontFamily);const s=()=>{p=new $(d,e),p.mount()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",s):s()}return d},open(){p==null||p.openWidget()},close(){p==null||p.closeWidget()},identify(t){d==null||d.setUserId(t)},identifySupport(t){var s;d&&(d.supportIdentityToken=t);const e=document.querySelector("#upstep-support-frame");e&&d&&((s=e.contentWindow)==null||s.postMessage({type:"upstep:support:identity",token:t,visible:(p==null?void 0:p.isChatVisible())??!0},new URL(d.baseUrl).origin))},onUnread(t){return(p==null?void 0:p.onUnread(t))??(()=>{})},get client(){if(!d)throw new Error("Upstep.init() must be called first");return d}};if(typeof document<"u"){const t=document.currentScript,e=t==null?void 0:t.dataset.apiKey,s=t==null?void 0:t.dataset.userId,o=t==null?void 0:t.dataset.baseUrl,n=t==null?void 0:t.dataset.accentColor,i=t==null?void 0:t.dataset.position,r=t==null?void 0:t.dataset.theme;if(e){const a={apiKey:e};s&&(a.userId=s),(t==null?void 0:t.dataset.chat)!==void 0&&(a.chat=t.dataset.chat!=="false"),o&&(a.baseUrl=o),n&&(a.accentColor=n),(i==="left"||i==="right")&&(a.position=i),(r==="light"||r==="dark"||r==="auto")&&(a.theme=r);const b=t==null?void 0:t.dataset.colors;if(b)try{const c=JSON.parse(b);c&&typeof c=="object"&&(a.colors=c)}catch{console.warn("Upstep: data-colors must be JSON")}const u=t==null?void 0:t.dataset.radius;u&&Number.isFinite(Number(u))&&(a.radius=Number(u));const m=t==null?void 0:t.dataset.fontFamily;m&&(a.fontFamily=m),x.init(a)}}exports.UpstepApiClient=g.UpstepApiClient;exports.buildWidgetPalette=l.buildWidgetPalette;exports.readableTextOn=l.readableTextOn;exports.default=x;
|