@upstep/js 0.1.0 → 0.4.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.
@@ -0,0 +1 @@
1
+ "use strict";class i{constructor(e){this.baseUrl=(e.baseUrl??"https://upstep.io").replace(/\/$/,""),this.apiKey=e.apiKey,e.userId!==void 0&&(this.userId=e.userId)}setUserId(e){this.userId=e}headers(){return{"Content-Type":"application/json","x-api-key":this.apiKey}}async listFeedback(e){const t=new URLSearchParams;e!=null&&e.cursor&&t.set("cursor",e.cursor),e!=null&&e.limit&&t.set("limit",String(e.limit)),e!=null&&e.type&&t.set("type",e.type),e!=null&&e.status&&t.set("status",e.status),e!=null&&e.sort&&t.set("sort",e.sort);const s=await fetch(`${this.baseUrl}/api/sdk/feedback?${t}`,{headers:this.headers()});if(!s.ok)throw new Error(`Upstep: ${s.status}`);return s.json()}async submitFeedback(e){const t=await fetch(`${this.baseUrl}/api/sdk/feedback`,{method:"POST",headers:this.headers(),body:JSON.stringify({...e,endUserId:e.endUserId??this.userId})});if(!t.ok)throw new Error(`Upstep: ${t.status}`);return t.json()}async vote(e,t){const s=await fetch(`${this.baseUrl}/api/sdk/feedback/${e}/vote`,{method:"POST",headers:this.headers(),body:JSON.stringify({value:t,endUserId:this.userId})});if(!s.ok)throw new Error(`Upstep: ${s.status}`)}async removeVote(e){if(!this.userId)return;const t=await fetch(`${this.baseUrl}/api/sdk/feedback/${e}/vote?endUserId=${encodeURIComponent(this.userId)}`,{method:"DELETE",headers:this.headers()});if(!t.ok)throw new Error(`Upstep: ${t.status}`)}}exports.UpstepApiClient=i;
@@ -2,6 +2,10 @@ class r {
2
2
  constructor(e) {
3
3
  this.baseUrl = (e.baseUrl ?? "https://upstep.io").replace(/\/$/, ""), this.apiKey = e.apiKey, e.userId !== void 0 && (this.userId = e.userId);
4
4
  }
5
+ /** Update the end-user id at runtime (e.g. after the user logs in). */
6
+ setUserId(e) {
7
+ this.userId = e;
8
+ }
5
9
  headers() {
6
10
  return {
7
11
  "Content-Type": "application/json",
package/dist/api.d.ts CHANGED
@@ -2,8 +2,10 @@ import { Feedback, FeedbackListResponse, SubmitFeedbackPayload, VotePayload, Ups
2
2
  export declare class UpstepApiClient {
3
3
  private readonly baseUrl;
4
4
  private readonly apiKey;
5
- readonly userId?: string;
5
+ userId: string | undefined;
6
6
  constructor(config: UpstepConfig);
7
+ /** Update the end-user id at runtime (e.g. after the user logs in). */
8
+ setUserId(userId: string | undefined): void;
7
9
  private headers;
8
10
  listFeedback(params?: {
9
11
  cursor?: string;
package/dist/api.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,oBAAoB,EACpB,qBAAqB,EACrB,WAAW,EACX,YAAY,EACb,MAAM,eAAe,CAAC;AAEvB,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;gBAEb,MAAM,EAAE,YAAY;IAMhC,OAAO,CAAC,OAAO;IAOT,YAAY,CAAC,MAAM,CAAC,EAAE;QAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;KACzB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAe3B,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAajE,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IASpE,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAQpD"}
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,oBAAoB,EACpB,qBAAqB,EACrB,WAAW,EACX,YAAY,EACb,MAAM,eAAe,CAAC;AAEvB,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;gBAEf,MAAM,EAAE,YAAY;IAMhC,uEAAuE;IACvE,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS;IAIpC,OAAO,CAAC,OAAO;IAOT,YAAY,CAAC,MAAM,CAAC,EAAE;QAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;KACzB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAe3B,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAajE,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IASpE,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAQpD"}
package/dist/index.cjs CHANGED
@@ -1,67 +1,86 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const p=require("./api-CwAgmJ0s.js"),r=`
2
- #upstep-root *{box-sizing:border-box;font-family:inherit}
3
- #upstep-btn{position:fixed;bottom:24px;right:24px;z-index:9998;background:#6366f1;color:#fff;border:none;border-radius:9999px;padding:12px 20px;font-size:14px;font-weight:600;cursor:pointer;box-shadow:0 4px 12px rgba(0,0,0,.2);transition:background .15s}
4
- #upstep-btn:hover{background:#4f46e5}
5
- #upstep-backdrop{position:fixed;inset:0;background:rgba(0,0,0,.45);z-index:9999;display:flex;align-items:flex-end;justify-content:center}
6
- #upstep-modal{background:#fff;border-radius:16px 16px 0 0;width:100%;max-width:480px;max-height:90vh;display:flex;flex-direction:column;overflow:hidden}
7
- #upstep-header{display:flex;align-items:center;justify-content:space-between;padding:16px 20px;border-bottom:1px solid #e5e7eb}
8
- #upstep-header h2{margin:0;font-size:16px;font-weight:700;color:#111827}
9
- #upstep-close{background:none;border:none;font-size:20px;cursor:pointer;color:#6b7280;line-height:1}
10
- #upstep-tabs{display:flex;border-bottom:1px solid #e5e7eb}
11
- .upstep-tab{flex:1;padding:10px;background:none;border:none;font-size:13px;font-weight:500;color:#6b7280;cursor:pointer;border-bottom:2px solid transparent}
12
- .upstep-tab.active{color:#6366f1;border-bottom-color:#6366f1}
13
- #upstep-body{flex:1;overflow-y:auto;padding:16px}
14
- .upstep-form textarea{width:100%;min-height:100px;border:1px solid #d1d5db;border-radius:8px;padding:10px;font-size:14px;resize:vertical;outline:none}
15
- .upstep-form textarea:focus{border-color:#6366f1}
16
- .upstep-type-row{display:flex;gap:8px;margin:10px 0}
17
- .upstep-type-btn{padding:5px 12px;border-radius:9999px;border:1px solid #d1d5db;background:#fff;font-size:12px;cursor:pointer}
18
- .upstep-type-btn.selected{background:#6366f1;color:#fff;border-color:#6366f1}
19
- .upstep-submit{width:100%;padding:10px;background:#6366f1;color:#fff;border:none;border-radius:8px;font-size:14px;font-weight:600;cursor:pointer;margin-top:8px}
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const l=require("./api-p1GbYq1j.js"),u="#D97757",b={bg:"#ffffff",bgSoft:"#f6f5f2",bgHover:"#efede8",text:"#1a1915",textSoft:"#56544d",textFaint:"#9b9890",border:"#e8e6df",overlay:"rgba(26,25,21,.45)"},f={bg:"#1c1b19",bgSoft:"#262522",bgHover:"#302e2a",text:"#f5f4f0",textSoft:"#b4b1a8",textFaint:"#7d7a72",border:"#33312c",overlay:"rgba(0,0,0,.6)"};function h(o){return o==="light"||o==="dark"?o:typeof window<"u"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function x(o,t,e){return`
2
+ #upstep-root *{box-sizing:border-box;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif}
3
+ #upstep-btn{position:fixed;bottom:24px;${t==="left"?"left:24px":"right:24px"};z-index:9998;display:inline-flex;align-items:center;gap:7px;background:${o};color:#fff;border:none;border-radius:9999px;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}
4
+ #upstep-btn:hover{transform:translateY(-1px);box-shadow:0 8px 26px rgba(26,25,21,.24)}
5
+ #upstep-btn svg{width:16px;height:16px}
6
+ #upstep-backdrop{position:fixed;inset:0;background:${e.overlay};backdrop-filter:blur(3px);z-index:9999;display:flex;align-items:center;justify-content:center;padding:16px;animation:upstep-fade .2s ease}
7
+ @keyframes upstep-fade{from{opacity:0}to{opacity:1}}
8
+ @keyframes upstep-rise{from{opacity:0;transform:translateY(14px)}to{opacity:1;transform:translateY(0)}}
9
+ #upstep-modal{background:${e.bg};border:1px solid ${e.border};border-radius:20px;width:100%;max-width:440px;max-height:88vh;display:flex;flex-direction:column;overflow:hidden;box-shadow:0 24px 64px rgba(0,0,0,.28);animation:upstep-rise .26s cubic-bezier(.16,1,.3,1)}
10
+ #upstep-header{display:flex;align-items:flex-start;justify-content:space-between;padding:20px 20px 0}
11
+ #upstep-header h2{margin:0;font-size:16px;font-weight:700;color:${e.text};letter-spacing:-.01em}
12
+ #upstep-header p{margin:2px 0 0;font-size:12.5px;color:${e.textFaint}}
13
+ #upstep-close{background:${e.bgSoft};border:none;width:28px;height:28px;border-radius:8px;font-size:14px;cursor:pointer;color:${e.textSoft};line-height:1;display:flex;align-items:center;justify-content:center;transition:background .15s}
14
+ #upstep-close:hover{background:${e.bgHover};color:${e.text}}
15
+ #upstep-tabs{display:flex;gap:4px;margin:16px 20px 0;padding:4px;background:${e.bgSoft};border-radius:11px}
16
+ .upstep-tab{flex:1;padding:8px;background:none;border:none;border-radius:8px;font-size:13px;font-weight:600;color:${e.textSoft};cursor:pointer;transition:all .15s}
17
+ .upstep-tab.active{background:${e.bg};color:${e.text};box-shadow:0 1px 3px rgba(0,0,0,.08)}
18
+ #upstep-body{flex:1;overflow-y:auto;padding:18px 20px 22px}
19
+ .upstep-form textarea{width:100%;min-height:104px;border:1px solid ${e.border};border-radius:12px;padding:12px;font-size:14px;line-height:1.5;resize:vertical;outline:none;background:${e.bgSoft};color:${e.text};transition:border-color .15s}
20
+ .upstep-form textarea::placeholder{color:${e.textFaint}}
21
+ .upstep-form textarea:focus{border-color:${o};background:${e.bg}}
22
+ .upstep-type-row{display:flex;gap:7px;margin:12px 0 4px}
23
+ .upstep-type-btn{flex:1;padding:8px 10px;border-radius:9px;border:1px solid ${e.border};background:${e.bg};color:${e.textSoft};font-size:12.5px;font-weight:600;cursor:pointer;transition:all .15s}
24
+ .upstep-type-btn:hover{border-color:${e.textFaint}}
25
+ .upstep-type-btn.selected{background:${o};color:#fff;border-color:${o}}
26
+ .upstep-submit{width:100%;padding:12px;background:${o};color:#fff;border:none;border-radius:11px;font-size:14px;font-weight:600;cursor:pointer;margin-top:14px;transition:filter .15s}
27
+ .upstep-submit:hover{filter:brightness(.94)}
20
28
  .upstep-submit:disabled{opacity:.5;cursor:not-allowed}
21
- .upstep-feedback-item{padding:12px 0;border-bottom:1px solid #f3f4f6}
22
- .upstep-feedback-item:last-child{border-bottom:none}
23
- .upstep-feedback-content{font-size:14px;color:#1f2937;margin:0 0 8px}
24
- .upstep-feedback-meta{font-size:11px;color:#9ca3af;margin-bottom:8px}
25
- .upstep-vote-row{display:flex;gap:8px}
26
- .upstep-vote-btn{display:flex;align-items:center;gap:4px;padding:4px 10px;border-radius:9999px;border:1px solid #e5e7eb;background:#fff;font-size:12px;cursor:pointer}
27
- .upstep-vote-btn:hover{border-color:#6366f1;color:#6366f1}
28
- .upstep-badge{display:inline-flex;align-items:center;padding:2px 8px;border-radius:9999px;font-size:11px;font-weight:500;margin-right:6px}
29
- .upstep-badge-bug{background:#fee2e2;color:#dc2626}
30
- .upstep-badge-feature{background:#dbeafe;color:#2563eb}
31
- .upstep-badge-general{background:#f3f4f6;color:#6b7280}
32
- .upstep-empty{text-align:center;color:#9ca3af;font-size:14px;padding:32px 0}
33
- `;class c{constructor(e){this.open=!1,this.tab="submit",this.feedItems=[],this.selectedType="GENERAL",this.loading=!1,this.client=e}mount(){this.injectStyles(),this.renderButton()}injectStyles(){if(document.getElementById("upstep-styles"))return;const e=document.createElement("style");e.id="upstep-styles",e.textContent=r,document.head.appendChild(e)}renderButton(){const e=document.createElement("button");e.id="upstep-btn",e.textContent="Feedback",e.addEventListener("click",()=>this.openModal()),document.body.appendChild(e)}openModal(){this.open=!0,this.fetchFeed(),this.renderModal()}closeModal(){this.open=!1;const e=document.getElementById("upstep-backdrop");e==null||e.remove()}async fetchFeed(){try{const e=await this.client.listFeedback({sort:"votes",limit:20});this.feedItems=e.items,this.renderFeedList()}catch{}}renderModal(){var t,o;const e=document.createElement("div");e.id="upstep-backdrop",e.addEventListener("click",d=>{d.target===e&&this.closeModal()}),e.innerHTML=`
29
+ #upstep-form-msg{font-size:13px;text-align:center;margin-top:12px;color:${o};font-weight:500}
30
+ .upstep-feedback-item{display:flex;gap:12px;padding:14px;border:1px solid ${e.border};border-radius:14px;margin-bottom:10px;background:${e.bg};transition:border-color .15s}
31
+ .upstep-feedback-item:hover{border-color:${e.textFaint}}
32
+ .upstep-vote{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;min-width:46px;padding:7px 0;border-radius:11px;border:1px solid ${e.border};background:${e.bgSoft};cursor:pointer;transition:all .15s}
33
+ .upstep-vote:hover{border-color:${o}}
34
+ .upstep-vote.voted{border-color:${o};background:${o}1a}
35
+ .upstep-vote-arrow{font-size:11px;line-height:1;color:${o}}
36
+ .upstep-vote-count{font-size:14px;font-weight:700;color:${e.text};line-height:1.1}
37
+ .upstep-feedback-main{flex:1;min-width:0}
38
+ .upstep-feedback-content{font-size:13.5px;line-height:1.5;color:${e.text};margin:0 0 8px;word-break:break-word}
39
+ .upstep-feedback-meta{display:flex;align-items:center;gap:7px}
40
+ .upstep-badge{display:inline-flex;align-items:center;padding:2px 8px;border-radius:9999px;font-size:10.5px;font-weight:700;letter-spacing:.02em}
41
+ .upstep-badge-bug{background:#fdecec;color:#d6453d}
42
+ .upstep-badge-feature{background:#e9f0fd;color:#3b76d6}
43
+ .upstep-badge-general{background:${e.bgSoft};color:${e.textSoft}}
44
+ .upstep-feedback-date{font-size:11px;color:${e.textFaint}}
45
+ .upstep-empty{text-align:center;color:${e.textFaint};font-size:14px;padding:40px 0}
46
+ .upstep-empty strong{display:block;color:${e.textSoft};font-size:15px;margin-bottom:4px}
47
+ `}const g='<svg 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 m{constructor(t,e={}){this.isOpen=!1,this.tab="submit",this.feedItems=[],this.selectedType="GENERAL",this.loading=!1,this.client=t,this.accent=e.accentColor??u,this.position=e.position??"right",this.showLauncher=e.launcher!==!1,this.palette=h(e.theme??"auto")==="dark"?f:b}mount(){this.injectStyles(),this.showLauncher&&this.renderButton()}openWidget(){this.openModal()}closeWidget(){this.closeModal()}injectStyles(){var e;(e=document.getElementById("upstep-styles"))==null||e.remove();const t=document.createElement("style");t.id="upstep-styles",t.textContent=x(this.accent,this.position,this.palette),document.head.appendChild(t)}renderButton(){const t=document.createElement("button");t.id="upstep-btn",t.innerHTML=`${g}<span>Feedback</span>`,t.addEventListener("click",()=>this.openModal()),document.body.appendChild(t)}openModal(){this.isOpen=!0,this.fetchFeed(),this.renderModal()}closeModal(){var t;this.isOpen=!1,(t=document.getElementById("upstep-backdrop"))==null||t.remove()}async fetchFeed(){try{const t=await this.client.listFeedback({sort:"votes",limit:20});this.feedItems=t.items,this.renderFeedList()}catch{}}renderModal(){var e,s;const t=document.createElement("div");t.id="upstep-backdrop",t.addEventListener("click",i=>{i.target===t&&this.closeModal()}),t.innerHTML=`
34
48
  <div id="upstep-modal">
35
49
  <div id="upstep-header">
36
- <h2>Share feedback</h2>
37
- <button id="upstep-close">✕</button>
50
+ <div>
51
+ <h2>Share your feedback</h2>
52
+ <p>Tell us what to build next, or vote on ideas.</p>
53
+ </div>
54
+ <button id="upstep-close" aria-label="Close">✕</button>
38
55
  </div>
39
56
  <div id="upstep-tabs">
40
- <button class="upstep-tab ${this.tab==="submit"?"active":""}" data-tab="submit">Submit</button>
41
- <button class="upstep-tab ${this.tab==="feed"?"active":""}" data-tab="feed">Votes &amp; Ideas</button>
57
+ <button class="upstep-tab ${this.tab==="submit"?"active":""}" data-tab="submit">Give feedback</button>
58
+ <button class="upstep-tab ${this.tab==="feed"?"active":""}" data-tab="feed">Vote on ideas</button>
42
59
  </div>
43
60
  <div id="upstep-body">
44
61
  ${this.tab==="submit"?this.renderSubmitForm():this.renderFeed()}
45
62
  </div>
46
63
  </div>
47
- `,(t=document.getElementById("upstep-backdrop"))==null||t.remove(),document.body.appendChild(e),(o=e.querySelector("#upstep-close"))==null||o.addEventListener("click",()=>this.closeModal()),e.querySelectorAll(".upstep-tab").forEach(d=>{d.addEventListener("click",()=>{this.tab=d.dataset.tab,this.renderModal()})}),this.bindSubmitForm(),this.bindVoteButtons()}renderSubmitForm(){return`
64
+ `,(e=document.getElementById("upstep-backdrop"))==null||e.remove(),document.body.appendChild(t),(s=t.querySelector("#upstep-close"))==null||s.addEventListener("click",()=>this.closeModal()),t.querySelectorAll(".upstep-tab").forEach(i=>{i.addEventListener("click",()=>{this.tab=i.dataset.tab,this.renderModal()})}),this.bindSubmitForm(),this.bindVoteButtons()}renderSubmitForm(){const t=["BUG","FEATURE","GENERAL"],e={BUG:"🐞 Bug",FEATURE:"✨ Feature",GENERAL:"💬 General"};return`
48
65
  <div class="upstep-form">
49
66
  <textarea id="upstep-textarea" placeholder="What's on your mind?" maxlength="2000"></textarea>
50
67
  <div class="upstep-type-row">
51
- ${["BUG","FEATURE","GENERAL"].map(t=>`<button class="upstep-type-btn${this.selectedType===t?" selected":""}" data-type="${t}">${t.charAt(0)+t.slice(1).toLowerCase()}</button>`).join("")}
68
+ ${t.map(s=>`<button class="upstep-type-btn${this.selectedType===s?" selected":""}" data-type="${s}">${e[s]}</button>`).join("")}
52
69
  </div>
53
70
  <button class="upstep-submit" id="upstep-submit-btn">Send feedback</button>
54
- <div id="upstep-form-msg" style="font-size:13px;text-align:center;margin-top:8px;color:#6b7280"></div>
71
+ <div id="upstep-form-msg"></div>
55
72
  </div>
56
- `}renderFeed(){return this.feedItems.length?this.feedItems.map(e=>`
57
- <div class="upstep-feedback-item" data-id="${e.id}">
58
- <p class="upstep-feedback-content">${u(e.content)}</p>
59
- <div class="upstep-feedback-meta">
60
- <span class="upstep-badge upstep-badge-${e.type.toLowerCase()}">${e.type}</span>
61
- ${new Date(e.createdAt).toLocaleDateString()}
73
+ `}renderFeed(){return this.feedItems.length?this.feedItems.map(t=>`
74
+ <div class="upstep-feedback-item" data-id="${t.id}">
75
+ <button class="upstep-vote${t.userVote==="UP"?" voted":""}" data-vote="UP" data-feedback="${t.id}">
76
+ <span class="upstep-vote-arrow">▲</span>
77
+ <span class="upstep-vote-count">${t.upvotes}</span>
78
+ </button>
79
+ <div class="upstep-feedback-main">
80
+ <p class="upstep-feedback-content">${y(t.content)}</p>
81
+ <div class="upstep-feedback-meta">
82
+ <span class="upstep-badge upstep-badge-${t.type.toLowerCase()}">${t.type}</span>
83
+ <span class="upstep-feedback-date">${new Date(t.createdAt).toLocaleDateString()}</span>
84
+ </div>
62
85
  </div>
63
- <div class="upstep-vote-row">
64
- <button class="upstep-vote-btn" data-vote="UP" data-feedback="${e.id}">▲ ${e.upvotes}</button>
65
- <button class="upstep-vote-btn" data-vote="DOWN" data-feedback="${e.id}">▼ ${e.downvotes}</button>
66
- </div>
67
- </div>`).join(""):'<div class="upstep-empty">No feedback yet. Be the first!</div>'}renderFeedList(){const e=document.getElementById("upstep-body");!e||this.tab!=="feed"||(e.innerHTML=this.renderFeed(),this.bindVoteButtons())}bindSubmitForm(){var e;document.querySelectorAll(".upstep-type-btn").forEach(t=>{t.addEventListener("click",()=>{this.selectedType=t.dataset.type,document.querySelectorAll(".upstep-type-btn").forEach(o=>o.classList.remove("selected")),t.classList.add("selected")})}),(e=document.getElementById("upstep-submit-btn"))==null||e.addEventListener("click",async()=>{const t=document.getElementById("upstep-textarea"),o=document.getElementById("upstep-form-msg"),d=document.getElementById("upstep-submit-btn");if(!t||this.loading)return;const i=t.value.trim();if(i){this.loading=!0,d&&(d.disabled=!0);try{await this.client.submitFeedback({content:i,type:this.selectedType}),t.value="",o&&(o.textContent="Thanks for your feedback!"),await this.fetchFeed()}catch{o&&(o.textContent="Something went wrong. Please try again.")}finally{this.loading=!1,d&&(d.disabled=!1)}}})}bindVoteButtons(){document.querySelectorAll(".upstep-vote-btn").forEach(e=>{e.addEventListener("click",async()=>{const t=e.dataset.feedback,o=e.dataset.vote;try{await this.client.vote(t,o),await this.fetchFeed()}catch{}})})}}function u(s){return s.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}let n=null;const a={init(s){if(n=new p.UpstepApiClient(s),typeof window<"u"){const e=()=>new c(n).mount();document.readyState==="loading"?document.addEventListener("DOMContentLoaded",e):e()}return n},get client(){if(!n)throw new Error("Upstep.init() must be called first");return n}};if(typeof document<"u"){const s=document.currentScript,e=s==null?void 0:s.dataset.apiKey,t=s==null?void 0:s.dataset.userId;if(e){const o={apiKey:e};t&&(o.userId=t),a.init(o)}}exports.UpstepApiClient=p.UpstepApiClient;exports.default=a;
86
+ </div>`).join(""):'<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.bindVoteButtons())}bindSubmitForm(){var t;document.querySelectorAll(".upstep-type-btn").forEach(e=>{e.addEventListener("click",()=>{this.selectedType=e.dataset.type,document.querySelectorAll(".upstep-type-btn").forEach(s=>s.classList.remove("selected")),e.classList.add("selected")})}),(t=document.getElementById("upstep-submit-btn"))==null||t.addEventListener("click",async()=>{const e=document.getElementById("upstep-textarea"),s=document.getElementById("upstep-form-msg"),i=document.getElementById("upstep-submit-btn");if(!e||this.loading)return;const d=e.value.trim();if(d){this.loading=!0,i&&(i.disabled=!0,i.textContent="Sending…");try{await this.client.submitFeedback({content:d,type:this.selectedType}),e.value="",s&&(s.textContent="Thanks — we got your feedback! 🎉"),await this.fetchFeed()}catch{s&&(s.textContent="Something went wrong. Please try again.")}finally{this.loading=!1,i&&(i.disabled=!1,i.textContent="Send feedback")}}})}bindVoteButtons(){document.querySelectorAll(".upstep-vote").forEach(t=>{t.addEventListener("click",async()=>{const e=t.dataset.feedback;try{await this.client.vote(e,"UP"),await this.fetchFeed()}catch{}})})}}function y(o){return o.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}let n=null,a=null;const c={init(o){if(n=new l.UpstepApiClient(o),typeof window<"u"){const t={};o.accentColor!==void 0&&(t.accentColor=o.accentColor),o.position!==void 0&&(t.position=o.position),o.theme!==void 0&&(t.theme=o.theme),o.launcher!==void 0&&(t.launcher=o.launcher);const e=()=>{a=new m(n,t),a.mount()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",e):e()}return n},open(){a==null||a.openWidget()},close(){a==null||a.closeWidget()},identify(o){n==null||n.setUserId(o)},get client(){if(!n)throw new Error("Upstep.init() must be called first");return n}};if(typeof document<"u"){const o=document.currentScript,t=o==null?void 0:o.dataset.apiKey,e=o==null?void 0:o.dataset.userId,s=o==null?void 0:o.dataset.baseUrl,i=o==null?void 0:o.dataset.accentColor,d=o==null?void 0:o.dataset.position,p=o==null?void 0:o.dataset.theme;if(t){const r={apiKey:t};e&&(r.userId=e),s&&(r.baseUrl=s),i&&(r.accentColor=i),(d==="left"||d==="right")&&(r.position=d),(p==="light"||p==="dark"||p==="auto")&&(r.theme=p),c.init(r)}}exports.UpstepApiClient=l.UpstepApiClient;exports.default=c;
package/dist/index.d.ts CHANGED
@@ -4,6 +4,12 @@ export type { UpstepConfig };
4
4
  export { UpstepApiClient };
5
5
  declare const Upstep: {
6
6
  init(config: UpstepConfig): UpstepApiClient;
7
+ /** Open the feedback widget — use this to trigger it from your own UI. */
8
+ open(): void;
9
+ /** Close the feedback widget. */
10
+ close(): void;
11
+ /** Set / update the end-user id at runtime (e.g. after the user logs in). */
12
+ identify(userId: string | undefined): void;
7
13
  readonly client: UpstepApiClient;
8
14
  };
9
15
  export default Upstep;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAGxC,YAAY,EAAE,YAAY,EAAE,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,CAAC;AAI3B,QAAA,MAAM,MAAM;iBACG,YAAY;qBAaX,eAAe;CAI9B,CAAC;AAEF,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAGxC,YAAY,EAAE,YAAY,EAAE,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,CAAC;AAK3B,QAAA,MAAM,MAAM;iBACG,YAAY;IAqBzB,0EAA0E;;IAK1E,iCAAiC;;IAKjC,6EAA6E;qBAC5D,MAAM,GAAG,SAAS;qBAIrB,eAAe;CAI9B,CAAC;AAEF,eAAe,MAAM,CAAC"}
package/dist/index.js CHANGED
@@ -1,184 +1,253 @@
1
- import { U as p } from "./api-DWhfFfYu.mjs";
2
- const a = `
3
- #upstep-root *{box-sizing:border-box;font-family:inherit}
4
- #upstep-btn{position:fixed;bottom:24px;right:24px;z-index:9998;background:#6366f1;color:#fff;border:none;border-radius:9999px;padding:12px 20px;font-size:14px;font-weight:600;cursor:pointer;box-shadow:0 4px 12px rgba(0,0,0,.2);transition:background .15s}
5
- #upstep-btn:hover{background:#4f46e5}
6
- #upstep-backdrop{position:fixed;inset:0;background:rgba(0,0,0,.45);z-index:9999;display:flex;align-items:flex-end;justify-content:center}
7
- #upstep-modal{background:#fff;border-radius:16px 16px 0 0;width:100%;max-width:480px;max-height:90vh;display:flex;flex-direction:column;overflow:hidden}
8
- #upstep-header{display:flex;align-items:center;justify-content:space-between;padding:16px 20px;border-bottom:1px solid #e5e7eb}
9
- #upstep-header h2{margin:0;font-size:16px;font-weight:700;color:#111827}
10
- #upstep-close{background:none;border:none;font-size:20px;cursor:pointer;color:#6b7280;line-height:1}
11
- #upstep-tabs{display:flex;border-bottom:1px solid #e5e7eb}
12
- .upstep-tab{flex:1;padding:10px;background:none;border:none;font-size:13px;font-weight:500;color:#6b7280;cursor:pointer;border-bottom:2px solid transparent}
13
- .upstep-tab.active{color:#6366f1;border-bottom-color:#6366f1}
14
- #upstep-body{flex:1;overflow-y:auto;padding:16px}
15
- .upstep-form textarea{width:100%;min-height:100px;border:1px solid #d1d5db;border-radius:8px;padding:10px;font-size:14px;resize:vertical;outline:none}
16
- .upstep-form textarea:focus{border-color:#6366f1}
17
- .upstep-type-row{display:flex;gap:8px;margin:10px 0}
18
- .upstep-type-btn{padding:5px 12px;border-radius:9999px;border:1px solid #d1d5db;background:#fff;font-size:12px;cursor:pointer}
19
- .upstep-type-btn.selected{background:#6366f1;color:#fff;border-color:#6366f1}
20
- .upstep-submit{width:100%;padding:10px;background:#6366f1;color:#fff;border:none;border-radius:8px;font-size:14px;font-weight:600;cursor:pointer;margin-top:8px}
1
+ import { U as l } from "./api-q50Qqen1.mjs";
2
+ const c = "#D97757", u = {
3
+ bg: "#ffffff",
4
+ bgSoft: "#f6f5f2",
5
+ bgHover: "#efede8",
6
+ text: "#1a1915",
7
+ textSoft: "#56544d",
8
+ textFaint: "#9b9890",
9
+ border: "#e8e6df",
10
+ overlay: "rgba(26,25,21,.45)"
11
+ }, b = {
12
+ bg: "#1c1b19",
13
+ bgSoft: "#262522",
14
+ bgHover: "#302e2a",
15
+ text: "#f5f4f0",
16
+ textSoft: "#b4b1a8",
17
+ textFaint: "#7d7a72",
18
+ border: "#33312c",
19
+ overlay: "rgba(0,0,0,.6)"
20
+ };
21
+ function f(o) {
22
+ return o === "light" || o === "dark" ? o : typeof window < "u" && window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
23
+ }
24
+ function h(o, t, e) {
25
+ return `
26
+ #upstep-root *{box-sizing:border-box;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif}
27
+ #upstep-btn{position:fixed;bottom:24px;${t === "left" ? "left:24px" : "right:24px"};z-index:9998;display:inline-flex;align-items:center;gap:7px;background:${o};color:#fff;border:none;border-radius:9999px;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}
28
+ #upstep-btn:hover{transform:translateY(-1px);box-shadow:0 8px 26px rgba(26,25,21,.24)}
29
+ #upstep-btn svg{width:16px;height:16px}
30
+ #upstep-backdrop{position:fixed;inset:0;background:${e.overlay};backdrop-filter:blur(3px);z-index:9999;display:flex;align-items:center;justify-content:center;padding:16px;animation:upstep-fade .2s ease}
31
+ @keyframes upstep-fade{from{opacity:0}to{opacity:1}}
32
+ @keyframes upstep-rise{from{opacity:0;transform:translateY(14px)}to{opacity:1;transform:translateY(0)}}
33
+ #upstep-modal{background:${e.bg};border:1px solid ${e.border};border-radius:20px;width:100%;max-width:440px;max-height:88vh;display:flex;flex-direction:column;overflow:hidden;box-shadow:0 24px 64px rgba(0,0,0,.28);animation:upstep-rise .26s cubic-bezier(.16,1,.3,1)}
34
+ #upstep-header{display:flex;align-items:flex-start;justify-content:space-between;padding:20px 20px 0}
35
+ #upstep-header h2{margin:0;font-size:16px;font-weight:700;color:${e.text};letter-spacing:-.01em}
36
+ #upstep-header p{margin:2px 0 0;font-size:12.5px;color:${e.textFaint}}
37
+ #upstep-close{background:${e.bgSoft};border:none;width:28px;height:28px;border-radius:8px;font-size:14px;cursor:pointer;color:${e.textSoft};line-height:1;display:flex;align-items:center;justify-content:center;transition:background .15s}
38
+ #upstep-close:hover{background:${e.bgHover};color:${e.text}}
39
+ #upstep-tabs{display:flex;gap:4px;margin:16px 20px 0;padding:4px;background:${e.bgSoft};border-radius:11px}
40
+ .upstep-tab{flex:1;padding:8px;background:none;border:none;border-radius:8px;font-size:13px;font-weight:600;color:${e.textSoft};cursor:pointer;transition:all .15s}
41
+ .upstep-tab.active{background:${e.bg};color:${e.text};box-shadow:0 1px 3px rgba(0,0,0,.08)}
42
+ #upstep-body{flex:1;overflow-y:auto;padding:18px 20px 22px}
43
+ .upstep-form textarea{width:100%;min-height:104px;border:1px solid ${e.border};border-radius:12px;padding:12px;font-size:14px;line-height:1.5;resize:vertical;outline:none;background:${e.bgSoft};color:${e.text};transition:border-color .15s}
44
+ .upstep-form textarea::placeholder{color:${e.textFaint}}
45
+ .upstep-form textarea:focus{border-color:${o};background:${e.bg}}
46
+ .upstep-type-row{display:flex;gap:7px;margin:12px 0 4px}
47
+ .upstep-type-btn{flex:1;padding:8px 10px;border-radius:9px;border:1px solid ${e.border};background:${e.bg};color:${e.textSoft};font-size:12.5px;font-weight:600;cursor:pointer;transition:all .15s}
48
+ .upstep-type-btn:hover{border-color:${e.textFaint}}
49
+ .upstep-type-btn.selected{background:${o};color:#fff;border-color:${o}}
50
+ .upstep-submit{width:100%;padding:12px;background:${o};color:#fff;border:none;border-radius:11px;font-size:14px;font-weight:600;cursor:pointer;margin-top:14px;transition:filter .15s}
51
+ .upstep-submit:hover{filter:brightness(.94)}
21
52
  .upstep-submit:disabled{opacity:.5;cursor:not-allowed}
22
- .upstep-feedback-item{padding:12px 0;border-bottom:1px solid #f3f4f6}
23
- .upstep-feedback-item:last-child{border-bottom:none}
24
- .upstep-feedback-content{font-size:14px;color:#1f2937;margin:0 0 8px}
25
- .upstep-feedback-meta{font-size:11px;color:#9ca3af;margin-bottom:8px}
26
- .upstep-vote-row{display:flex;gap:8px}
27
- .upstep-vote-btn{display:flex;align-items:center;gap:4px;padding:4px 10px;border-radius:9999px;border:1px solid #e5e7eb;background:#fff;font-size:12px;cursor:pointer}
28
- .upstep-vote-btn:hover{border-color:#6366f1;color:#6366f1}
29
- .upstep-badge{display:inline-flex;align-items:center;padding:2px 8px;border-radius:9999px;font-size:11px;font-weight:500;margin-right:6px}
30
- .upstep-badge-bug{background:#fee2e2;color:#dc2626}
31
- .upstep-badge-feature{background:#dbeafe;color:#2563eb}
32
- .upstep-badge-general{background:#f3f4f6;color:#6b7280}
33
- .upstep-empty{text-align:center;color:#9ca3af;font-size:14px;padding:32px 0}
53
+ #upstep-form-msg{font-size:13px;text-align:center;margin-top:12px;color:${o};font-weight:500}
54
+ .upstep-feedback-item{display:flex;gap:12px;padding:14px;border:1px solid ${e.border};border-radius:14px;margin-bottom:10px;background:${e.bg};transition:border-color .15s}
55
+ .upstep-feedback-item:hover{border-color:${e.textFaint}}
56
+ .upstep-vote{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;min-width:46px;padding:7px 0;border-radius:11px;border:1px solid ${e.border};background:${e.bgSoft};cursor:pointer;transition:all .15s}
57
+ .upstep-vote:hover{border-color:${o}}
58
+ .upstep-vote.voted{border-color:${o};background:${o}1a}
59
+ .upstep-vote-arrow{font-size:11px;line-height:1;color:${o}}
60
+ .upstep-vote-count{font-size:14px;font-weight:700;color:${e.text};line-height:1.1}
61
+ .upstep-feedback-main{flex:1;min-width:0}
62
+ .upstep-feedback-content{font-size:13.5px;line-height:1.5;color:${e.text};margin:0 0 8px;word-break:break-word}
63
+ .upstep-feedback-meta{display:flex;align-items:center;gap:7px}
64
+ .upstep-badge{display:inline-flex;align-items:center;padding:2px 8px;border-radius:9999px;font-size:10.5px;font-weight:700;letter-spacing:.02em}
65
+ .upstep-badge-bug{background:#fdecec;color:#d6453d}
66
+ .upstep-badge-feature{background:#e9f0fd;color:#3b76d6}
67
+ .upstep-badge-general{background:${e.bgSoft};color:${e.textSoft}}
68
+ .upstep-feedback-date{font-size:11px;color:${e.textFaint}}
69
+ .upstep-empty{text-align:center;color:${e.textFaint};font-size:14px;padding:40px 0}
70
+ .upstep-empty strong{display:block;color:${e.textSoft};font-size:15px;margin-bottom:4px}
34
71
  `;
35
- class r {
36
- constructor(e) {
37
- this.open = !1, this.tab = "submit", this.feedItems = [], this.selectedType = "GENERAL", this.loading = !1, this.client = e;
72
+ }
73
+ const x = '<svg 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>';
74
+ class g {
75
+ constructor(t, e = {}) {
76
+ this.isOpen = !1, this.tab = "submit", this.feedItems = [], this.selectedType = "GENERAL", this.loading = !1, this.client = t, this.accent = e.accentColor ?? c, this.position = e.position ?? "right", this.showLauncher = e.launcher !== !1, this.palette = f(e.theme ?? "auto") === "dark" ? b : u;
38
77
  }
39
78
  mount() {
40
- this.injectStyles(), this.renderButton();
79
+ this.injectStyles(), this.showLauncher && this.renderButton();
80
+ }
81
+ /** Open the feedback modal programmatically (e.g. from your own button). */
82
+ openWidget() {
83
+ this.openModal();
84
+ }
85
+ /** Close the feedback modal programmatically. */
86
+ closeWidget() {
87
+ this.closeModal();
41
88
  }
42
89
  injectStyles() {
43
- if (document.getElementById("upstep-styles")) return;
44
- const e = document.createElement("style");
45
- e.id = "upstep-styles", e.textContent = a, document.head.appendChild(e);
90
+ var e;
91
+ (e = document.getElementById("upstep-styles")) == null || e.remove();
92
+ const t = document.createElement("style");
93
+ t.id = "upstep-styles", t.textContent = h(this.accent, this.position, this.palette), document.head.appendChild(t);
46
94
  }
47
95
  renderButton() {
48
- const e = document.createElement("button");
49
- e.id = "upstep-btn", e.textContent = "Feedback", e.addEventListener("click", () => this.openModal()), document.body.appendChild(e);
96
+ const t = document.createElement("button");
97
+ t.id = "upstep-btn", t.innerHTML = `${x}<span>Feedback</span>`, t.addEventListener("click", () => this.openModal()), document.body.appendChild(t);
50
98
  }
51
99
  openModal() {
52
- this.open = !0, this.fetchFeed(), this.renderModal();
100
+ this.isOpen = !0, this.fetchFeed(), this.renderModal();
53
101
  }
54
102
  closeModal() {
55
- this.open = !1;
56
- const e = document.getElementById("upstep-backdrop");
57
- e == null || e.remove();
103
+ var t;
104
+ this.isOpen = !1, (t = document.getElementById("upstep-backdrop")) == null || t.remove();
58
105
  }
59
106
  async fetchFeed() {
60
107
  try {
61
- const e = await this.client.listFeedback({ sort: "votes", limit: 20 });
62
- this.feedItems = e.items, this.renderFeedList();
108
+ const t = await this.client.listFeedback({ sort: "votes", limit: 20 });
109
+ this.feedItems = t.items, this.renderFeedList();
63
110
  } catch {
64
111
  }
65
112
  }
66
113
  renderModal() {
67
- var t, o;
68
- const e = document.createElement("div");
69
- e.id = "upstep-backdrop", e.addEventListener("click", (d) => {
70
- d.target === e && this.closeModal();
71
- }), e.innerHTML = `
114
+ var e, s;
115
+ const t = document.createElement("div");
116
+ t.id = "upstep-backdrop", t.addEventListener("click", (i) => {
117
+ i.target === t && this.closeModal();
118
+ }), t.innerHTML = `
72
119
  <div id="upstep-modal">
73
120
  <div id="upstep-header">
74
- <h2>Share feedback</h2>
75
- <button id="upstep-close">✕</button>
121
+ <div>
122
+ <h2>Share your feedback</h2>
123
+ <p>Tell us what to build next, or vote on ideas.</p>
124
+ </div>
125
+ <button id="upstep-close" aria-label="Close">✕</button>
76
126
  </div>
77
127
  <div id="upstep-tabs">
78
- <button class="upstep-tab ${this.tab === "submit" ? "active" : ""}" data-tab="submit">Submit</button>
79
- <button class="upstep-tab ${this.tab === "feed" ? "active" : ""}" data-tab="feed">Votes &amp; Ideas</button>
128
+ <button class="upstep-tab ${this.tab === "submit" ? "active" : ""}" data-tab="submit">Give feedback</button>
129
+ <button class="upstep-tab ${this.tab === "feed" ? "active" : ""}" data-tab="feed">Vote on ideas</button>
80
130
  </div>
81
131
  <div id="upstep-body">
82
132
  ${this.tab === "submit" ? this.renderSubmitForm() : this.renderFeed()}
83
133
  </div>
84
134
  </div>
85
- `, (t = document.getElementById("upstep-backdrop")) == null || t.remove(), document.body.appendChild(e), (o = e.querySelector("#upstep-close")) == null || o.addEventListener("click", () => this.closeModal()), e.querySelectorAll(".upstep-tab").forEach((d) => {
86
- d.addEventListener("click", () => {
87
- this.tab = d.dataset.tab, this.renderModal();
135
+ `, (e = document.getElementById("upstep-backdrop")) == null || e.remove(), document.body.appendChild(t), (s = t.querySelector("#upstep-close")) == null || s.addEventListener("click", () => this.closeModal()), t.querySelectorAll(".upstep-tab").forEach((i) => {
136
+ i.addEventListener("click", () => {
137
+ this.tab = i.dataset.tab, this.renderModal();
88
138
  });
89
139
  }), this.bindSubmitForm(), this.bindVoteButtons();
90
140
  }
91
141
  renderSubmitForm() {
142
+ const t = ["BUG", "FEATURE", "GENERAL"], e = { BUG: "🐞 Bug", FEATURE: "✨ Feature", GENERAL: "💬 General" };
92
143
  return `
93
144
  <div class="upstep-form">
94
145
  <textarea id="upstep-textarea" placeholder="What's on your mind?" maxlength="2000"></textarea>
95
146
  <div class="upstep-type-row">
96
- ${["BUG", "FEATURE", "GENERAL"].map((t) => `<button class="upstep-type-btn${this.selectedType === t ? " selected" : ""}" data-type="${t}">${t.charAt(0) + t.slice(1).toLowerCase()}</button>`).join("")}
147
+ ${t.map((s) => `<button class="upstep-type-btn${this.selectedType === s ? " selected" : ""}" data-type="${s}">${e[s]}</button>`).join("")}
97
148
  </div>
98
149
  <button class="upstep-submit" id="upstep-submit-btn">Send feedback</button>
99
- <div id="upstep-form-msg" style="font-size:13px;text-align:center;margin-top:8px;color:#6b7280"></div>
150
+ <div id="upstep-form-msg"></div>
100
151
  </div>
101
152
  `;
102
153
  }
103
154
  renderFeed() {
104
155
  return this.feedItems.length ? this.feedItems.map(
105
- (e) => `
106
- <div class="upstep-feedback-item" data-id="${e.id}">
107
- <p class="upstep-feedback-content">${c(e.content)}</p>
108
- <div class="upstep-feedback-meta">
109
- <span class="upstep-badge upstep-badge-${e.type.toLowerCase()}">${e.type}</span>
110
- ${new Date(e.createdAt).toLocaleDateString()}
111
- </div>
112
- <div class="upstep-vote-row">
113
- <button class="upstep-vote-btn" data-vote="UP" data-feedback="${e.id}">▲ ${e.upvotes}</button>
114
- <button class="upstep-vote-btn" data-vote="DOWN" data-feedback="${e.id}">▼ ${e.downvotes}</button>
156
+ (t) => `
157
+ <div class="upstep-feedback-item" data-id="${t.id}">
158
+ <button class="upstep-vote${t.userVote === "UP" ? " voted" : ""}" data-vote="UP" data-feedback="${t.id}">
159
+ <span class="upstep-vote-arrow">▲</span>
160
+ <span class="upstep-vote-count">${t.upvotes}</span>
161
+ </button>
162
+ <div class="upstep-feedback-main">
163
+ <p class="upstep-feedback-content">${m(t.content)}</p>
164
+ <div class="upstep-feedback-meta">
165
+ <span class="upstep-badge upstep-badge-${t.type.toLowerCase()}">${t.type}</span>
166
+ <span class="upstep-feedback-date">${new Date(t.createdAt).toLocaleDateString()}</span>
167
+ </div>
115
168
  </div>
116
169
  </div>`
117
- ).join("") : '<div class="upstep-empty">No feedback yet. Be the first!</div>';
170
+ ).join("") : '<div class="upstep-empty"><strong>No ideas yet</strong>Be the first to share one.</div>';
118
171
  }
119
172
  renderFeedList() {
120
- const e = document.getElementById("upstep-body");
121
- !e || this.tab !== "feed" || (e.innerHTML = this.renderFeed(), this.bindVoteButtons());
173
+ const t = document.getElementById("upstep-body");
174
+ !t || this.tab !== "feed" || (t.innerHTML = this.renderFeed(), this.bindVoteButtons());
122
175
  }
123
176
  bindSubmitForm() {
124
- var e;
125
- document.querySelectorAll(".upstep-type-btn").forEach((t) => {
126
- t.addEventListener("click", () => {
127
- this.selectedType = t.dataset.type, document.querySelectorAll(".upstep-type-btn").forEach((o) => o.classList.remove("selected")), t.classList.add("selected");
177
+ var t;
178
+ document.querySelectorAll(".upstep-type-btn").forEach((e) => {
179
+ e.addEventListener("click", () => {
180
+ this.selectedType = e.dataset.type, document.querySelectorAll(".upstep-type-btn").forEach((s) => s.classList.remove("selected")), e.classList.add("selected");
128
181
  });
129
- }), (e = document.getElementById("upstep-submit-btn")) == null || e.addEventListener("click", async () => {
130
- const t = document.getElementById("upstep-textarea"), o = document.getElementById("upstep-form-msg"), d = document.getElementById("upstep-submit-btn");
131
- if (!t || this.loading) return;
132
- const i = t.value.trim();
133
- if (i) {
134
- this.loading = !0, d && (d.disabled = !0);
182
+ }), (t = document.getElementById("upstep-submit-btn")) == null || t.addEventListener("click", async () => {
183
+ const e = document.getElementById("upstep-textarea"), s = document.getElementById("upstep-form-msg"), i = document.getElementById("upstep-submit-btn");
184
+ if (!e || this.loading) return;
185
+ const d = e.value.trim();
186
+ if (d) {
187
+ this.loading = !0, i && (i.disabled = !0, i.textContent = "Sending…");
135
188
  try {
136
- await this.client.submitFeedback({ content: i, type: this.selectedType }), t.value = "", o && (o.textContent = "Thanks for your feedback!"), await this.fetchFeed();
189
+ await this.client.submitFeedback({ content: d, type: this.selectedType }), e.value = "", s && (s.textContent = "Thanks — we got your feedback! 🎉"), await this.fetchFeed();
137
190
  } catch {
138
- o && (o.textContent = "Something went wrong. Please try again.");
191
+ s && (s.textContent = "Something went wrong. Please try again.");
139
192
  } finally {
140
- this.loading = !1, d && (d.disabled = !1);
193
+ this.loading = !1, i && (i.disabled = !1, i.textContent = "Send feedback");
141
194
  }
142
195
  }
143
196
  });
144
197
  }
145
198
  bindVoteButtons() {
146
- document.querySelectorAll(".upstep-vote-btn").forEach((e) => {
147
- e.addEventListener("click", async () => {
148
- const t = e.dataset.feedback, o = e.dataset.vote;
199
+ document.querySelectorAll(".upstep-vote").forEach((t) => {
200
+ t.addEventListener("click", async () => {
201
+ const e = t.dataset.feedback;
149
202
  try {
150
- await this.client.vote(t, o), await this.fetchFeed();
203
+ await this.client.vote(e, "UP"), await this.fetchFeed();
151
204
  } catch {
152
205
  }
153
206
  });
154
207
  });
155
208
  }
156
209
  }
157
- function c(s) {
158
- return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
210
+ function m(o) {
211
+ return o.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
159
212
  }
160
- let n = null;
161
- const u = {
162
- init(s) {
163
- if (n = new p(s), typeof window < "u") {
164
- const e = () => new r(n).mount();
213
+ let n = null, a = null;
214
+ const y = {
215
+ init(o) {
216
+ if (n = new l(o), typeof window < "u") {
217
+ const t = {};
218
+ o.accentColor !== void 0 && (t.accentColor = o.accentColor), o.position !== void 0 && (t.position = o.position), o.theme !== void 0 && (t.theme = o.theme), o.launcher !== void 0 && (t.launcher = o.launcher);
219
+ const e = () => {
220
+ a = new g(n, t), a.mount();
221
+ };
165
222
  document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", e) : e();
166
223
  }
167
224
  return n;
168
225
  },
226
+ /** Open the feedback widget — use this to trigger it from your own UI. */
227
+ open() {
228
+ a == null || a.openWidget();
229
+ },
230
+ /** Close the feedback widget. */
231
+ close() {
232
+ a == null || a.closeWidget();
233
+ },
234
+ /** Set / update the end-user id at runtime (e.g. after the user logs in). */
235
+ identify(o) {
236
+ n == null || n.setUserId(o);
237
+ },
169
238
  get client() {
170
239
  if (!n) throw new Error("Upstep.init() must be called first");
171
240
  return n;
172
241
  }
173
242
  };
174
243
  if (typeof document < "u") {
175
- const s = document.currentScript, e = s == null ? void 0 : s.dataset.apiKey, t = s == null ? void 0 : s.dataset.userId;
176
- if (e) {
177
- const o = { apiKey: e };
178
- t && (o.userId = t), u.init(o);
244
+ const o = document.currentScript, t = o == null ? void 0 : o.dataset.apiKey, e = o == null ? void 0 : o.dataset.userId, s = o == null ? void 0 : o.dataset.baseUrl, i = o == null ? void 0 : o.dataset.accentColor, d = o == null ? void 0 : o.dataset.position, p = o == null ? void 0 : o.dataset.theme;
245
+ if (t) {
246
+ const r = { apiKey: t };
247
+ e && (r.userId = e), s && (r.baseUrl = s), i && (r.accentColor = i), (d === "left" || d === "right") && (r.position = d), (p === "light" || p === "dark" || p === "auto") && (r.theme = p), y.init(r);
179
248
  }
180
249
  }
181
250
  export {
182
- p as UpstepApiClient,
183
- u as default
251
+ l as UpstepApiClient,
252
+ y as default
184
253
  };