@upstep/js 0.5.5 → 0.5.6

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 CHANGED
@@ -1,53 +1,53 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const l=require("./api-BvhrcMKU.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`
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const x=require("./api-BvhrcMKU.js"),w="#D97757",$={bg:"#ffffff",bgSoft:"#f6f5f2",bgHover:"#efede8",text:"#1a1915",textSoft:"#56544d",textFaint:"#9b9890",border:"#e8e6df",overlay:"rgba(26,25,21,.45)"},M={bg:"#1c1b19",bgSoft:"#262522",bgHover:"#302e2a",text:"#f5f4f0",textSoft:"#b4b1a8",textFaint:"#7d7a72",border:"#33312c",overlay:"rgba(0,0,0,.6)"};function E(o){return o==="light"||o==="dark"?o:typeof window<"u"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function L(o,e,t){return`
2
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}
3
+ #upstep-btn{position:fixed;bottom:24px;${e==="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:grab;touch-action:none;box-shadow:0 6px 20px rgba(26,25,21,.18);transition:transform .15s,box-shadow .15s}
4
4
  #upstep-btn svg{width:16px;height:16px;flex-shrink:0}
5
5
  #upstep-btn:hover{transform:translateY(-1px);box-shadow:0 8px 26px rgba(26,25,21,.24)}
6
- #upstep-btn svg{width:16px;height:16px}
6
+ #upstep-btn.upstep-dragging{cursor:grabbing;transform:scale(1.06);box-shadow:0 10px 32px rgba(26,25,21,.28);transition:transform .08s,box-shadow .08s}
7
7
  @media(max-width:639px){#upstep-btn{padding:12px}#upstep-btn span{display:none}}
8
- #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}
8
+ #upstep-backdrop{position:fixed;inset:0;background:${t.overlay};backdrop-filter:blur(3px);z-index:9999;display:flex;align-items:center;justify-content:center;padding:16px;animation:upstep-fade .2s ease}
9
9
  @keyframes upstep-fade{from{opacity:0}to{opacity:1}}
10
10
  @keyframes upstep-rise{from{opacity:0;transform:translateY(14px)}to{opacity:1;transform:translateY(0)}}
11
- #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)}
11
+ #upstep-modal{background:${t.bg};border:1px solid ${t.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)}
12
12
  #upstep-header{display:flex;align-items:flex-start;justify-content:space-between;padding:20px 20px 0}
13
- #upstep-header h2{margin:0;font-size:16px;font-weight:700;color:${e.text};letter-spacing:-.01em}
14
- #upstep-header p{margin:2px 0 0;font-size:12.5px;color:${e.textFaint}}
15
- #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}
16
- #upstep-close:hover{background:${e.bgHover};color:${e.text}}
17
- #upstep-tabs{display:flex;gap:4px;margin:16px 20px 0;padding:4px;background:${e.bgSoft};border-radius:11px}
18
- .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}
19
- .upstep-tab.active{background:${e.bg};color:${e.text};box-shadow:0 1px 3px rgba(0,0,0,.08)}
13
+ #upstep-header h2{margin:0;font-size:16px;font-weight:700;color:${t.text};letter-spacing:-.01em}
14
+ #upstep-header p{margin:2px 0 0;font-size:12.5px;color:${t.textFaint}}
15
+ #upstep-close{background:${t.bgSoft};border:none;width:28px;height:28px;border-radius:8px;font-size:14px;cursor:pointer;color:${t.textSoft};line-height:1;display:flex;align-items:center;justify-content:center;transition:background .15s}
16
+ #upstep-close:hover{background:${t.bgHover};color:${t.text}}
17
+ #upstep-tabs{display:flex;gap:4px;margin:16px 20px 0;padding:4px;background:${t.bgSoft};border-radius:11px}
18
+ .upstep-tab{flex:1;padding:8px;background:none;border:none;border-radius:8px;font-size:13px;font-weight:600;color:${t.textSoft};cursor:pointer;transition:all .15s}
19
+ .upstep-tab.active{background:${t.bg};color:${t.text};box-shadow:0 1px 3px rgba(0,0,0,.08)}
20
20
  #upstep-body{flex:1;overflow-y:auto;padding:18px 20px 22px}
21
- .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}
22
- .upstep-form textarea::placeholder{color:${e.textFaint}}
23
- .upstep-form textarea:focus{border-color:${o};background:${e.bg}}
21
+ .upstep-form textarea{width:100%;min-height:104px;border:1px solid ${t.border};border-radius:12px;padding:12px;font-size:14px;line-height:1.5;resize:vertical;outline:none;background:${t.bgSoft};color:${t.text};transition:border-color .15s}
22
+ .upstep-form textarea::placeholder{color:${t.textFaint}}
23
+ .upstep-form textarea:focus{border-color:${o};background:${t.bg}}
24
24
  .upstep-type-row{display:flex;gap:7px;margin:12px 0 4px}
25
- .upstep-type-btn{flex:1;display:flex;align-items:center;justify-content:center;gap:5px;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}
25
+ .upstep-type-btn{flex:1;display:flex;align-items:center;justify-content:center;gap:5px;padding:8px 10px;border-radius:9px;border:1px solid ${t.border};background:${t.bg};color:${t.textSoft};font-size:12.5px;font-weight:600;cursor:pointer;transition:all .15s}
26
26
  .upstep-type-btn svg{width:12px;height:12px;flex-shrink:0}
27
- .upstep-type-btn:hover{border-color:${e.textFaint}}
27
+ .upstep-type-btn:hover{border-color:${t.textFaint}}
28
28
  .upstep-type-btn.selected{background:${o};color:#fff;border-color:${o}}
29
29
  .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}
30
30
  .upstep-submit:hover{filter:brightness(.94)}
31
31
  .upstep-submit:disabled{opacity:.5;cursor:not-allowed}
32
32
  #upstep-form-msg{font-size:13px;text-align:center;margin-top:12px;color:${o};font-weight:500}
33
- .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}
34
- .upstep-feedback-item:hover{border-color:${e.textFaint}}
35
- .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-feedback-item{display:flex;gap:12px;padding:14px;border:1px solid ${t.border};border-radius:14px;margin-bottom:10px;background:${t.bg};transition:border-color .15s}
34
+ .upstep-feedback-item:hover{border-color:${t.textFaint}}
35
+ .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 ${t.border};background:${t.bgSoft};cursor:pointer;transition:all .15s}
36
36
  .upstep-vote:hover{border-color:${o}}
37
37
  .upstep-vote.voted{border-color:${o};background:${o}1a}
38
38
  .upstep-vote-arrow{font-size:11px;line-height:1;color:${o}}
39
- .upstep-vote-count{font-size:14px;font-weight:700;color:${e.text};line-height:1.1}
39
+ .upstep-vote-count{font-size:14px;font-weight:700;color:${t.text};line-height:1.1}
40
40
  .upstep-feedback-main{flex:1;min-width:0}
41
- .upstep-feedback-content{font-size:13.5px;line-height:1.5;color:${e.text};margin:0 0 8px;word-break:break-word}
41
+ .upstep-feedback-content{font-size:13.5px;line-height:1.5;color:${t.text};margin:0 0 8px;word-break:break-word}
42
42
  .upstep-feedback-meta{display:flex;align-items:center;gap:7px}
43
43
  .upstep-badge{display:inline-flex;align-items:center;padding:2px 8px;border-radius:9999px;font-size:10.5px;font-weight:700;letter-spacing:.02em}
44
44
  .upstep-badge-bug{background:#fdecec;color:#d6453d}
45
45
  .upstep-badge-feature{background:#e9f0fd;color:#3b76d6}
46
- .upstep-badge-general{background:${e.bgSoft};color:${e.textSoft}}
47
- .upstep-feedback-date{font-size:11px;color:${e.textFaint}}
48
- .upstep-empty{text-align:center;color:${e.textFaint};font-size:14px;padding:40px 0}
49
- .upstep-empty strong{display:block;color:${e.textSoft};font-size:15px;margin-bottom:4px}
50
- `}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,i;const t=document.createElement("div");t.id="upstep-backdrop",t.addEventListener("click",s=>{s.target===t&&this.closeModal()}),t.innerHTML=`
46
+ .upstep-badge-general{background:${t.bgSoft};color:${t.textSoft}}
47
+ .upstep-feedback-date{font-size:11px;color:${t.textFaint}}
48
+ .upstep-empty{text-align:center;color:${t.textFaint};font-size:14px;padding:40px 0}
49
+ .upstep-empty strong{display:block;color:${t.textSoft};font-size:15px;margin-bottom:4px}
50
+ `}const S='<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 C{constructor(e,t={}){this.isOpen=!1,this.tab="submit",this.feedItems=[],this.selectedType="GENERAL",this.loading=!1,this.dragMoved=!1,this.client=e,this.accent=t.accentColor??w,this.position=t.position??"right",this.showLauncher=t.launcher!==!1,this.palette=E(t.theme??"auto")==="dark"?M:$}mount(){this.injectStyles(),this.showLauncher&&this.renderButton()}openWidget(){this.openModal()}closeWidget(){this.closeModal()}injectStyles(){var t;(t=document.getElementById("upstep-styles"))==null||t.remove();const e=document.createElement("style");e.id="upstep-styles",e.textContent=L(this.accent,this.position,this.palette),document.head.appendChild(e)}renderButton(){const e=document.createElement("button");e.id="upstep-btn",e.innerHTML=`${S}<span>Feedback</span>`,e.addEventListener("click",()=>{this.dragMoved||this.openModal()}),document.body.appendChild(e),this.makeDraggable(e)}makeDraggable(e){const s="upstep-btn-pos";try{const i=localStorage.getItem(s);if(i){const{side:a,bottom:u}=JSON.parse(i);e.style.left=a==="left"?"24px":"auto",e.style.right=a==="right"?"24px":"auto",e.style.top="auto",e.style.bottom=`${u}px`}}catch{}let r=0,c=0,d=0,f=0,b=!1;const y=()=>{const i=e.getBoundingClientRect(),a=i.left+i.width/2<window.innerWidth/2?"left":"right",u=Math.max(24,Math.min(window.innerHeight-i.height-24,i.top)),g=window.innerHeight-u-i.height;e.style.transition="left .25s cubic-bezier(.16,1,.3,1),right .25s cubic-bezier(.16,1,.3,1),top .25s cubic-bezier(.16,1,.3,1),bottom .25s cubic-bezier(.16,1,.3,1),transform .15s,box-shadow .15s",e.style.left=a==="left"?"24px":"auto",e.style.right=a==="right"?"24px":"auto",e.style.top="auto",e.style.bottom=`${g}px`;try{localStorage.setItem(s,JSON.stringify({side:a,bottom:g}))}catch{}},v=i=>{if(i.pointerType==="mouse"&&i.button!==0)return;this.dragMoved=!1,b=!0;const a=e.getBoundingClientRect();r=i.clientX,c=i.clientY,d=a.left,f=a.top,e.setPointerCapture(i.pointerId),e.style.transition="none"},k=i=>{if(!b)return;const a=i.clientX-r,u=i.clientY-c;!this.dragMoved&&Math.hypot(a,u)<6||(this.dragMoved||e.classList.add("upstep-dragging"),this.dragMoved=!0,e.style.left=`${d+a}px`,e.style.right="auto",e.style.top=`${f+u}px`,e.style.bottom="auto")},h=()=>{b&&(b=!1,e.classList.remove("upstep-dragging"),this.dragMoved&&y())};e.addEventListener("pointerdown",v),e.addEventListener("pointermove",k),e.addEventListener("pointerup",h),e.addEventListener("pointercancel",h)}openModal(){this.isOpen=!0,this.fetchFeed(),this.renderModal()}closeModal(){var e;this.isOpen=!1,(e=document.getElementById("upstep-backdrop"))==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,n;const e=document.createElement("div");e.id="upstep-backdrop",e.addEventListener("click",s=>{s.target===e&&this.closeModal()}),e.innerHTML=`
51
51
  <div id="upstep-modal">
52
52
  <div id="upstep-header">
53
53
  <div>
@@ -64,26 +64,26 @@
64
64
  ${this.tab==="submit"?this.renderSubmitForm():this.renderFeed()}
65
65
  </div>
66
66
  </div>
67
- `,(e=document.getElementById("upstep-backdrop"))==null||e.remove(),document.body.appendChild(t),(i=t.querySelector("#upstep-close"))==null||i.addEventListener("click",()=>this.closeModal()),t.querySelectorAll(".upstep-tab").forEach(s=>{s.addEventListener("click",()=>{this.tab=s.dataset.tab,this.renderModal()})}),this.bindSubmitForm(),this.bindVoteButtons()}renderSubmitForm(){const t=["BUG","FEATURE","GENERAL"],e={BUG:"Bug",FEATURE:"Feature",GENERAL:"General"},i={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`
67
+ `,(t=document.getElementById("upstep-backdrop"))==null||t.remove(),document.body.appendChild(e),(n=e.querySelector("#upstep-close"))==null||n.addEventListener("click",()=>this.closeModal()),e.querySelectorAll(".upstep-tab").forEach(s=>{s.addEventListener("click",()=>{this.tab=s.dataset.tab,this.renderModal()})}),this.bindSubmitForm(),this.bindVoteButtons()}renderSubmitForm(){const e=["BUG","FEATURE","GENERAL"],t={BUG:"Bug",FEATURE:"Feature",GENERAL:"General"},n={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`
68
68
  <div class="upstep-form">
69
69
  <textarea id="upstep-textarea" placeholder="What's on your mind?" maxlength="2000"></textarea>
70
70
  <div class="upstep-type-row">
71
- ${t.map(s=>`<button class="upstep-type-btn${this.selectedType===s?" selected":""}" data-type="${s}">${i[s]}${e[s]}</button>`).join("")}
71
+ ${e.map(s=>`<button class="upstep-type-btn${this.selectedType===s?" selected":""}" data-type="${s}">${n[s]}${t[s]}</button>`).join("")}
72
72
  </div>
73
73
  <button class="upstep-submit" id="upstep-submit-btn">Send feedback</button>
74
74
  <div id="upstep-form-msg"></div>
75
75
  </div>
76
- `}renderFeed(){return this.feedItems.length?this.feedItems.map(t=>`
77
- <div class="upstep-feedback-item" data-id="${t.id}">
78
- <button class="upstep-vote${t.userVote==="UP"?" voted":""}" data-vote="UP" data-feedback="${t.id}">
76
+ `}renderFeed(){return this.feedItems.length?this.feedItems.map(e=>`
77
+ <div class="upstep-feedback-item" data-id="${e.id}">
78
+ <button class="upstep-vote${e.userVote==="UP"?" voted":""}" data-vote="UP" data-feedback="${e.id}">
79
79
  <span class="upstep-vote-arrow">▲</span>
80
- <span class="upstep-vote-count">${t.upvotes}</span>
80
+ <span class="upstep-vote-count">${e.upvotes}</span>
81
81
  </button>
82
82
  <div class="upstep-feedback-main">
83
- <p class="upstep-feedback-content">${y(t.content)}</p>
83
+ <p class="upstep-feedback-content">${F(e.content)}</p>
84
84
  <div class="upstep-feedback-meta">
85
- <span class="upstep-badge upstep-badge-${t.type.toLowerCase()}">${t.type}</span>
86
- <span class="upstep-feedback-date">${new Date(t.createdAt).toLocaleDateString()}</span>
85
+ <span class="upstep-badge upstep-badge-${e.type.toLowerCase()}">${e.type}</span>
86
+ <span class="upstep-feedback-date">${new Date(e.createdAt).toLocaleDateString()}</span>
87
87
  </div>
88
88
  </div>
89
- </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(i=>i.classList.remove("selected")),e.classList.add("selected")})}),(t=document.getElementById("upstep-submit-btn"))==null||t.addEventListener("click",async()=>{const e=document.getElementById("upstep-textarea"),i=document.getElementById("upstep-form-msg"),s=document.getElementById("upstep-submit-btn");if(!e||this.loading)return;const r=e.value.trim();if(r){this.loading=!0,s&&(s.disabled=!0,s.textContent="Sending…");try{await this.client.submitFeedback({content:r,type:this.selectedType}),e.value="",i&&(i.textContent="Feedback received. Thank you."),await this.fetchFeed()}catch{i&&(i.textContent="Something went wrong. Please try again.")}finally{this.loading=!1,s&&(s.disabled=!1,s.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,i=o==null?void 0:o.dataset.baseUrl,s=o==null?void 0:o.dataset.accentColor,r=o==null?void 0:o.dataset.position,p=o==null?void 0:o.dataset.theme;if(t){const d={apiKey:t};e&&(d.userId=e),i&&(d.baseUrl=i),s&&(d.accentColor=s),(r==="left"||r==="right")&&(d.position=r),(p==="light"||p==="dark"||p==="auto")&&(d.theme=p),c.init(d)}}exports.UpstepApiClient=l.UpstepApiClient;exports.default=c;
89
+ </div>`).join(""):'<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.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(n=>n.classList.remove("selected")),t.classList.add("selected")})}),(e=document.getElementById("upstep-submit-btn"))==null||e.addEventListener("click",async()=>{const t=document.getElementById("upstep-textarea"),n=document.getElementById("upstep-form-msg"),s=document.getElementById("upstep-submit-btn");if(!t||this.loading)return;const r=t.value.trim();if(r){this.loading=!0,s&&(s.disabled=!0,s.textContent="Sending…");try{await this.client.submitFeedback({content:r,type:this.selectedType}),t.value="",n&&(n.textContent="Feedback received. Thank you."),await this.fetchFeed()}catch{n&&(n.textContent="Something went wrong. Please try again.")}finally{this.loading=!1,s&&(s.disabled=!1,s.textContent="Send feedback")}}})}bindVoteButtons(){document.querySelectorAll(".upstep-vote").forEach(e=>{e.addEventListener("click",async()=>{const t=e.dataset.feedback;try{await this.client.vote(t,"UP"),await this.fetchFeed()}catch{}})})}}function F(o){return o.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}let p=null,l=null;const m={init(o){if(p=new x.UpstepApiClient(o),typeof window<"u"){const e={};o.accentColor!==void 0&&(e.accentColor=o.accentColor),o.position!==void 0&&(e.position=o.position),o.theme!==void 0&&(e.theme=o.theme),o.launcher!==void 0&&(e.launcher=o.launcher);const t=()=>{l=new C(p,e),l.mount()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",t):t()}return p},open(){l==null||l.openWidget()},close(){l==null||l.closeWidget()},identify(o){p==null||p.setUserId(o)},get client(){if(!p)throw new Error("Upstep.init() must be called first");return p}};if(typeof document<"u"){const o=document.currentScript,e=o==null?void 0:o.dataset.apiKey,t=o==null?void 0:o.dataset.userId,n=o==null?void 0:o.dataset.baseUrl,s=o==null?void 0:o.dataset.accentColor,r=o==null?void 0:o.dataset.position,c=o==null?void 0:o.dataset.theme;if(e){const d={apiKey:e};t&&(d.userId=t),n&&(d.baseUrl=n),s&&(d.accentColor=s),(r==="left"||r==="right")&&(d.position=r),(c==="light"||c==="dark"||c==="auto")&&(d.theme=c),m.init(d)}}exports.UpstepApiClient=x.UpstepApiClient;exports.default=m;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { U as l } from "./api-B-umoNRf.mjs";
2
- const c = "#D97757", u = {
1
+ import { U as v } from "./api-B-umoNRf.mjs";
2
+ const k = "#D97757", w = {
3
3
  bg: "#ffffff",
4
4
  bgSoft: "#f6f5f2",
5
5
  bgHover: "#efede8",
@@ -8,7 +8,7 @@ const c = "#D97757", u = {
8
8
  textFaint: "#9b9890",
9
9
  border: "#e8e6df",
10
10
  overlay: "rgba(26,25,21,.45)"
11
- }, b = {
11
+ }, $ = {
12
12
  bg: "#1c1b19",
13
13
  bgSoft: "#262522",
14
14
  bgHover: "#302e2a",
@@ -18,65 +18,65 @@ const c = "#D97757", u = {
18
18
  border: "#33312c",
19
19
  overlay: "rgba(0,0,0,.6)"
20
20
  };
21
- function f(o) {
21
+ function M(o) {
22
22
  return o === "light" || o === "dark" ? o : typeof window < "u" && window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
23
23
  }
24
- function h(o, t, e) {
24
+ function E(o, e, t) {
25
25
  return `
26
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}
27
+ #upstep-btn{position:fixed;bottom:24px;${e === "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:grab;touch-action:none;box-shadow:0 6px 20px rgba(26,25,21,.18);transition:transform .15s,box-shadow .15s}
28
28
  #upstep-btn svg{width:16px;height:16px;flex-shrink:0}
29
29
  #upstep-btn:hover{transform:translateY(-1px);box-shadow:0 8px 26px rgba(26,25,21,.24)}
30
- #upstep-btn svg{width:16px;height:16px}
30
+ #upstep-btn.upstep-dragging{cursor:grabbing;transform:scale(1.06);box-shadow:0 10px 32px rgba(26,25,21,.28);transition:transform .08s,box-shadow .08s}
31
31
  @media(max-width:639px){#upstep-btn{padding:12px}#upstep-btn span{display:none}}
32
- #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}
32
+ #upstep-backdrop{position:fixed;inset:0;background:${t.overlay};backdrop-filter:blur(3px);z-index:9999;display:flex;align-items:center;justify-content:center;padding:16px;animation:upstep-fade .2s ease}
33
33
  @keyframes upstep-fade{from{opacity:0}to{opacity:1}}
34
34
  @keyframes upstep-rise{from{opacity:0;transform:translateY(14px)}to{opacity:1;transform:translateY(0)}}
35
- #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)}
35
+ #upstep-modal{background:${t.bg};border:1px solid ${t.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)}
36
36
  #upstep-header{display:flex;align-items:flex-start;justify-content:space-between;padding:20px 20px 0}
37
- #upstep-header h2{margin:0;font-size:16px;font-weight:700;color:${e.text};letter-spacing:-.01em}
38
- #upstep-header p{margin:2px 0 0;font-size:12.5px;color:${e.textFaint}}
39
- #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}
40
- #upstep-close:hover{background:${e.bgHover};color:${e.text}}
41
- #upstep-tabs{display:flex;gap:4px;margin:16px 20px 0;padding:4px;background:${e.bgSoft};border-radius:11px}
42
- .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}
43
- .upstep-tab.active{background:${e.bg};color:${e.text};box-shadow:0 1px 3px rgba(0,0,0,.08)}
37
+ #upstep-header h2{margin:0;font-size:16px;font-weight:700;color:${t.text};letter-spacing:-.01em}
38
+ #upstep-header p{margin:2px 0 0;font-size:12.5px;color:${t.textFaint}}
39
+ #upstep-close{background:${t.bgSoft};border:none;width:28px;height:28px;border-radius:8px;font-size:14px;cursor:pointer;color:${t.textSoft};line-height:1;display:flex;align-items:center;justify-content:center;transition:background .15s}
40
+ #upstep-close:hover{background:${t.bgHover};color:${t.text}}
41
+ #upstep-tabs{display:flex;gap:4px;margin:16px 20px 0;padding:4px;background:${t.bgSoft};border-radius:11px}
42
+ .upstep-tab{flex:1;padding:8px;background:none;border:none;border-radius:8px;font-size:13px;font-weight:600;color:${t.textSoft};cursor:pointer;transition:all .15s}
43
+ .upstep-tab.active{background:${t.bg};color:${t.text};box-shadow:0 1px 3px rgba(0,0,0,.08)}
44
44
  #upstep-body{flex:1;overflow-y:auto;padding:18px 20px 22px}
45
- .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}
46
- .upstep-form textarea::placeholder{color:${e.textFaint}}
47
- .upstep-form textarea:focus{border-color:${o};background:${e.bg}}
45
+ .upstep-form textarea{width:100%;min-height:104px;border:1px solid ${t.border};border-radius:12px;padding:12px;font-size:14px;line-height:1.5;resize:vertical;outline:none;background:${t.bgSoft};color:${t.text};transition:border-color .15s}
46
+ .upstep-form textarea::placeholder{color:${t.textFaint}}
47
+ .upstep-form textarea:focus{border-color:${o};background:${t.bg}}
48
48
  .upstep-type-row{display:flex;gap:7px;margin:12px 0 4px}
49
- .upstep-type-btn{flex:1;display:flex;align-items:center;justify-content:center;gap:5px;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}
49
+ .upstep-type-btn{flex:1;display:flex;align-items:center;justify-content:center;gap:5px;padding:8px 10px;border-radius:9px;border:1px solid ${t.border};background:${t.bg};color:${t.textSoft};font-size:12.5px;font-weight:600;cursor:pointer;transition:all .15s}
50
50
  .upstep-type-btn svg{width:12px;height:12px;flex-shrink:0}
51
- .upstep-type-btn:hover{border-color:${e.textFaint}}
51
+ .upstep-type-btn:hover{border-color:${t.textFaint}}
52
52
  .upstep-type-btn.selected{background:${o};color:#fff;border-color:${o}}
53
53
  .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}
54
54
  .upstep-submit:hover{filter:brightness(.94)}
55
55
  .upstep-submit:disabled{opacity:.5;cursor:not-allowed}
56
56
  #upstep-form-msg{font-size:13px;text-align:center;margin-top:12px;color:${o};font-weight:500}
57
- .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}
58
- .upstep-feedback-item:hover{border-color:${e.textFaint}}
59
- .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-feedback-item{display:flex;gap:12px;padding:14px;border:1px solid ${t.border};border-radius:14px;margin-bottom:10px;background:${t.bg};transition:border-color .15s}
58
+ .upstep-feedback-item:hover{border-color:${t.textFaint}}
59
+ .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 ${t.border};background:${t.bgSoft};cursor:pointer;transition:all .15s}
60
60
  .upstep-vote:hover{border-color:${o}}
61
61
  .upstep-vote.voted{border-color:${o};background:${o}1a}
62
62
  .upstep-vote-arrow{font-size:11px;line-height:1;color:${o}}
63
- .upstep-vote-count{font-size:14px;font-weight:700;color:${e.text};line-height:1.1}
63
+ .upstep-vote-count{font-size:14px;font-weight:700;color:${t.text};line-height:1.1}
64
64
  .upstep-feedback-main{flex:1;min-width:0}
65
- .upstep-feedback-content{font-size:13.5px;line-height:1.5;color:${e.text};margin:0 0 8px;word-break:break-word}
65
+ .upstep-feedback-content{font-size:13.5px;line-height:1.5;color:${t.text};margin:0 0 8px;word-break:break-word}
66
66
  .upstep-feedback-meta{display:flex;align-items:center;gap:7px}
67
67
  .upstep-badge{display:inline-flex;align-items:center;padding:2px 8px;border-radius:9999px;font-size:10.5px;font-weight:700;letter-spacing:.02em}
68
68
  .upstep-badge-bug{background:#fdecec;color:#d6453d}
69
69
  .upstep-badge-feature{background:#e9f0fd;color:#3b76d6}
70
- .upstep-badge-general{background:${e.bgSoft};color:${e.textSoft}}
71
- .upstep-feedback-date{font-size:11px;color:${e.textFaint}}
72
- .upstep-empty{text-align:center;color:${e.textFaint};font-size:14px;padding:40px 0}
73
- .upstep-empty strong{display:block;color:${e.textSoft};font-size:15px;margin-bottom:4px}
70
+ .upstep-badge-general{background:${t.bgSoft};color:${t.textSoft}}
71
+ .upstep-feedback-date{font-size:11px;color:${t.textFaint}}
72
+ .upstep-empty{text-align:center;color:${t.textFaint};font-size:14px;padding:40px 0}
73
+ .upstep-empty strong{display:block;color:${t.textSoft};font-size:15px;margin-bottom:4px}
74
74
  `;
75
75
  }
76
- 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>';
77
- class g {
78
- constructor(t, e = {}) {
79
- 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;
76
+ const L = '<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>';
77
+ class F {
78
+ constructor(e, t = {}) {
79
+ this.isOpen = !1, this.tab = "submit", this.feedItems = [], this.selectedType = "GENERAL", this.loading = !1, this.dragMoved = !1, this.client = e, this.accent = t.accentColor ?? k, this.position = t.position ?? "right", this.showLauncher = t.launcher !== !1, this.palette = M(t.theme ?? "auto") === "dark" ? $ : w;
80
80
  }
81
81
  mount() {
82
82
  this.injectStyles(), this.showLauncher && this.renderButton();
@@ -90,35 +90,69 @@ class g {
90
90
  this.closeModal();
91
91
  }
92
92
  injectStyles() {
93
- var e;
94
- (e = document.getElementById("upstep-styles")) == null || e.remove();
95
- const t = document.createElement("style");
96
- t.id = "upstep-styles", t.textContent = h(this.accent, this.position, this.palette), document.head.appendChild(t);
93
+ var t;
94
+ (t = document.getElementById("upstep-styles")) == null || t.remove();
95
+ const e = document.createElement("style");
96
+ e.id = "upstep-styles", e.textContent = E(this.accent, this.position, this.palette), document.head.appendChild(e);
97
97
  }
98
98
  renderButton() {
99
- const t = document.createElement("button");
100
- t.id = "upstep-btn", t.innerHTML = `${x}<span>Feedback</span>`, t.addEventListener("click", () => this.openModal()), document.body.appendChild(t);
99
+ const e = document.createElement("button");
100
+ e.id = "upstep-btn", e.innerHTML = `${L}<span>Feedback</span>`, e.addEventListener("click", () => {
101
+ this.dragMoved || this.openModal();
102
+ }), document.body.appendChild(e), this.makeDraggable(e);
103
+ }
104
+ makeDraggable(e) {
105
+ const s = "upstep-btn-pos";
106
+ try {
107
+ const i = localStorage.getItem(s);
108
+ if (i) {
109
+ const { side: a, bottom: u } = JSON.parse(i);
110
+ e.style.left = a === "left" ? "24px" : "auto", e.style.right = a === "right" ? "24px" : "auto", e.style.top = "auto", e.style.bottom = `${u}px`;
111
+ }
112
+ } catch {
113
+ }
114
+ let r = 0, c = 0, d = 0, f = 0, b = !1;
115
+ const x = () => {
116
+ const i = e.getBoundingClientRect(), a = i.left + i.width / 2 < window.innerWidth / 2 ? "left" : "right", u = Math.max(24, Math.min(window.innerHeight - i.height - 24, i.top)), g = window.innerHeight - u - i.height;
117
+ e.style.transition = "left .25s cubic-bezier(.16,1,.3,1),right .25s cubic-bezier(.16,1,.3,1),top .25s cubic-bezier(.16,1,.3,1),bottom .25s cubic-bezier(.16,1,.3,1),transform .15s,box-shadow .15s", e.style.left = a === "left" ? "24px" : "auto", e.style.right = a === "right" ? "24px" : "auto", e.style.top = "auto", e.style.bottom = `${g}px`;
118
+ try {
119
+ localStorage.setItem(s, JSON.stringify({ side: a, bottom: g }));
120
+ } catch {
121
+ }
122
+ }, m = (i) => {
123
+ if (i.pointerType === "mouse" && i.button !== 0) return;
124
+ this.dragMoved = !1, b = !0;
125
+ const a = e.getBoundingClientRect();
126
+ r = i.clientX, c = i.clientY, d = a.left, f = a.top, e.setPointerCapture(i.pointerId), e.style.transition = "none";
127
+ }, y = (i) => {
128
+ if (!b) return;
129
+ const a = i.clientX - r, u = i.clientY - c;
130
+ !this.dragMoved && Math.hypot(a, u) < 6 || (this.dragMoved || e.classList.add("upstep-dragging"), this.dragMoved = !0, e.style.left = `${d + a}px`, e.style.right = "auto", e.style.top = `${f + u}px`, e.style.bottom = "auto");
131
+ }, h = () => {
132
+ b && (b = !1, e.classList.remove("upstep-dragging"), this.dragMoved && x());
133
+ };
134
+ e.addEventListener("pointerdown", m), e.addEventListener("pointermove", y), e.addEventListener("pointerup", h), e.addEventListener("pointercancel", h);
101
135
  }
102
136
  openModal() {
103
137
  this.isOpen = !0, this.fetchFeed(), this.renderModal();
104
138
  }
105
139
  closeModal() {
106
- var t;
107
- this.isOpen = !1, (t = document.getElementById("upstep-backdrop")) == null || t.remove();
140
+ var e;
141
+ this.isOpen = !1, (e = document.getElementById("upstep-backdrop")) == null || e.remove();
108
142
  }
109
143
  async fetchFeed() {
110
144
  try {
111
- const t = await this.client.listFeedback({ sort: "votes", limit: 20 });
112
- this.feedItems = t.items, this.renderFeedList();
145
+ const e = await this.client.listFeedback({ sort: "votes", limit: 20 });
146
+ this.feedItems = e.items, this.renderFeedList();
113
147
  } catch {
114
148
  }
115
149
  }
116
150
  renderModal() {
117
- var e, i;
118
- const t = document.createElement("div");
119
- t.id = "upstep-backdrop", t.addEventListener("click", (s) => {
120
- s.target === t && this.closeModal();
121
- }), t.innerHTML = `
151
+ var t, n;
152
+ const e = document.createElement("div");
153
+ e.id = "upstep-backdrop", e.addEventListener("click", (s) => {
154
+ s.target === e && this.closeModal();
155
+ }), e.innerHTML = `
122
156
  <div id="upstep-modal">
123
157
  <div id="upstep-header">
124
158
  <div>
@@ -135,14 +169,14 @@ class g {
135
169
  ${this.tab === "submit" ? this.renderSubmitForm() : this.renderFeed()}
136
170
  </div>
137
171
  </div>
138
- `, (e = document.getElementById("upstep-backdrop")) == null || e.remove(), document.body.appendChild(t), (i = t.querySelector("#upstep-close")) == null || i.addEventListener("click", () => this.closeModal()), t.querySelectorAll(".upstep-tab").forEach((s) => {
172
+ `, (t = document.getElementById("upstep-backdrop")) == null || t.remove(), document.body.appendChild(e), (n = e.querySelector("#upstep-close")) == null || n.addEventListener("click", () => this.closeModal()), e.querySelectorAll(".upstep-tab").forEach((s) => {
139
173
  s.addEventListener("click", () => {
140
174
  this.tab = s.dataset.tab, this.renderModal();
141
175
  });
142
176
  }), this.bindSubmitForm(), this.bindVoteButtons();
143
177
  }
144
178
  renderSubmitForm() {
145
- const t = ["BUG", "FEATURE", "GENERAL"], e = { BUG: "Bug", FEATURE: "Feature", GENERAL: "General" }, i = {
179
+ const e = ["BUG", "FEATURE", "GENERAL"], t = { BUG: "Bug", FEATURE: "Feature", GENERAL: "General" }, n = {
146
180
  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>',
147
181
  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>',
148
182
  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>'
@@ -151,7 +185,7 @@ class g {
151
185
  <div class="upstep-form">
152
186
  <textarea id="upstep-textarea" placeholder="What's on your mind?" maxlength="2000"></textarea>
153
187
  <div class="upstep-type-row">
154
- ${t.map((s) => `<button class="upstep-type-btn${this.selectedType === s ? " selected" : ""}" data-type="${s}">${i[s]}${e[s]}</button>`).join("")}
188
+ ${e.map((s) => `<button class="upstep-type-btn${this.selectedType === s ? " selected" : ""}" data-type="${s}">${n[s]}${t[s]}</button>`).join("")}
155
189
  </div>
156
190
  <button class="upstep-submit" id="upstep-submit-btn">Send feedback</button>
157
191
  <div id="upstep-form-msg"></div>
@@ -160,42 +194,42 @@ class g {
160
194
  }
161
195
  renderFeed() {
162
196
  return this.feedItems.length ? this.feedItems.map(
163
- (t) => `
164
- <div class="upstep-feedback-item" data-id="${t.id}">
165
- <button class="upstep-vote${t.userVote === "UP" ? " voted" : ""}" data-vote="UP" data-feedback="${t.id}">
197
+ (e) => `
198
+ <div class="upstep-feedback-item" data-id="${e.id}">
199
+ <button class="upstep-vote${e.userVote === "UP" ? " voted" : ""}" data-vote="UP" data-feedback="${e.id}">
166
200
  <span class="upstep-vote-arrow">▲</span>
167
- <span class="upstep-vote-count">${t.upvotes}</span>
201
+ <span class="upstep-vote-count">${e.upvotes}</span>
168
202
  </button>
169
203
  <div class="upstep-feedback-main">
170
- <p class="upstep-feedback-content">${m(t.content)}</p>
204
+ <p class="upstep-feedback-content">${S(e.content)}</p>
171
205
  <div class="upstep-feedback-meta">
172
- <span class="upstep-badge upstep-badge-${t.type.toLowerCase()}">${t.type}</span>
173
- <span class="upstep-feedback-date">${new Date(t.createdAt).toLocaleDateString()}</span>
206
+ <span class="upstep-badge upstep-badge-${e.type.toLowerCase()}">${e.type}</span>
207
+ <span class="upstep-feedback-date">${new Date(e.createdAt).toLocaleDateString()}</span>
174
208
  </div>
175
209
  </div>
176
210
  </div>`
177
211
  ).join("") : '<div class="upstep-empty"><strong>No ideas yet</strong>Be the first to share one.</div>';
178
212
  }
179
213
  renderFeedList() {
180
- const t = document.getElementById("upstep-body");
181
- !t || this.tab !== "feed" || (t.innerHTML = this.renderFeed(), this.bindVoteButtons());
214
+ const e = document.getElementById("upstep-body");
215
+ !e || this.tab !== "feed" || (e.innerHTML = this.renderFeed(), this.bindVoteButtons());
182
216
  }
183
217
  bindSubmitForm() {
184
- var t;
185
- document.querySelectorAll(".upstep-type-btn").forEach((e) => {
186
- e.addEventListener("click", () => {
187
- this.selectedType = e.dataset.type, document.querySelectorAll(".upstep-type-btn").forEach((i) => i.classList.remove("selected")), e.classList.add("selected");
218
+ var e;
219
+ document.querySelectorAll(".upstep-type-btn").forEach((t) => {
220
+ t.addEventListener("click", () => {
221
+ this.selectedType = t.dataset.type, document.querySelectorAll(".upstep-type-btn").forEach((n) => n.classList.remove("selected")), t.classList.add("selected");
188
222
  });
189
- }), (t = document.getElementById("upstep-submit-btn")) == null || t.addEventListener("click", async () => {
190
- const e = document.getElementById("upstep-textarea"), i = document.getElementById("upstep-form-msg"), s = document.getElementById("upstep-submit-btn");
191
- if (!e || this.loading) return;
192
- const r = e.value.trim();
223
+ }), (e = document.getElementById("upstep-submit-btn")) == null || e.addEventListener("click", async () => {
224
+ const t = document.getElementById("upstep-textarea"), n = document.getElementById("upstep-form-msg"), s = document.getElementById("upstep-submit-btn");
225
+ if (!t || this.loading) return;
226
+ const r = t.value.trim();
193
227
  if (r) {
194
228
  this.loading = !0, s && (s.disabled = !0, s.textContent = "Sending…");
195
229
  try {
196
- await this.client.submitFeedback({ content: r, type: this.selectedType }), e.value = "", i && (i.textContent = "Feedback received. Thank you."), await this.fetchFeed();
230
+ await this.client.submitFeedback({ content: r, type: this.selectedType }), t.value = "", n && (n.textContent = "Feedback received. Thank you."), await this.fetchFeed();
197
231
  } catch {
198
- i && (i.textContent = "Something went wrong. Please try again.");
232
+ n && (n.textContent = "Something went wrong. Please try again.");
199
233
  } finally {
200
234
  this.loading = !1, s && (s.disabled = !1, s.textContent = "Send feedback");
201
235
  }
@@ -203,58 +237,58 @@ class g {
203
237
  });
204
238
  }
205
239
  bindVoteButtons() {
206
- document.querySelectorAll(".upstep-vote").forEach((t) => {
207
- t.addEventListener("click", async () => {
208
- const e = t.dataset.feedback;
240
+ document.querySelectorAll(".upstep-vote").forEach((e) => {
241
+ e.addEventListener("click", async () => {
242
+ const t = e.dataset.feedback;
209
243
  try {
210
- await this.client.vote(e, "UP"), await this.fetchFeed();
244
+ await this.client.vote(t, "UP"), await this.fetchFeed();
211
245
  } catch {
212
246
  }
213
247
  });
214
248
  });
215
249
  }
216
250
  }
217
- function m(o) {
251
+ function S(o) {
218
252
  return o.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
219
253
  }
220
- let n = null, a = null;
221
- const y = {
254
+ let p = null, l = null;
255
+ const C = {
222
256
  init(o) {
223
- if (n = new l(o), typeof window < "u") {
224
- const t = {};
225
- 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);
226
- const e = () => {
227
- a = new g(n, t), a.mount();
257
+ if (p = new v(o), typeof window < "u") {
258
+ const e = {};
259
+ o.accentColor !== void 0 && (e.accentColor = o.accentColor), o.position !== void 0 && (e.position = o.position), o.theme !== void 0 && (e.theme = o.theme), o.launcher !== void 0 && (e.launcher = o.launcher);
260
+ const t = () => {
261
+ l = new F(p, e), l.mount();
228
262
  };
229
- document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", e) : e();
263
+ document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", t) : t();
230
264
  }
231
- return n;
265
+ return p;
232
266
  },
233
267
  /** Open the feedback widget — use this to trigger it from your own UI. */
234
268
  open() {
235
- a == null || a.openWidget();
269
+ l == null || l.openWidget();
236
270
  },
237
271
  /** Close the feedback widget. */
238
272
  close() {
239
- a == null || a.closeWidget();
273
+ l == null || l.closeWidget();
240
274
  },
241
275
  /** Set / update the end-user id at runtime (e.g. after the user logs in). */
242
276
  identify(o) {
243
- n == null || n.setUserId(o);
277
+ p == null || p.setUserId(o);
244
278
  },
245
279
  get client() {
246
- if (!n) throw new Error("Upstep.init() must be called first");
247
- return n;
280
+ if (!p) throw new Error("Upstep.init() must be called first");
281
+ return p;
248
282
  }
249
283
  };
250
284
  if (typeof document < "u") {
251
- const o = document.currentScript, t = o == null ? void 0 : o.dataset.apiKey, e = o == null ? void 0 : o.dataset.userId, i = o == null ? void 0 : o.dataset.baseUrl, s = o == null ? void 0 : o.dataset.accentColor, r = o == null ? void 0 : o.dataset.position, p = o == null ? void 0 : o.dataset.theme;
252
- if (t) {
253
- const d = { apiKey: t };
254
- e && (d.userId = e), i && (d.baseUrl = i), s && (d.accentColor = s), (r === "left" || r === "right") && (d.position = r), (p === "light" || p === "dark" || p === "auto") && (d.theme = p), y.init(d);
285
+ const o = document.currentScript, e = o == null ? void 0 : o.dataset.apiKey, t = o == null ? void 0 : o.dataset.userId, n = o == null ? void 0 : o.dataset.baseUrl, s = o == null ? void 0 : o.dataset.accentColor, r = o == null ? void 0 : o.dataset.position, c = o == null ? void 0 : o.dataset.theme;
286
+ if (e) {
287
+ const d = { apiKey: e };
288
+ t && (d.userId = t), n && (d.baseUrl = n), s && (d.accentColor = s), (r === "left" || r === "right") && (d.position = r), (c === "light" || c === "dark" || c === "auto") && (d.theme = c), C.init(d);
255
289
  }
256
290
  }
257
291
  export {
258
- l as UpstepApiClient,
259
- y as default
292
+ v as UpstepApiClient,
293
+ C as default
260
294
  };
package/dist/widget.d.ts CHANGED
@@ -19,6 +19,7 @@ export declare class UpstepWidget {
19
19
  private position;
20
20
  private showLauncher;
21
21
  private palette;
22
+ private dragMoved;
22
23
  constructor(client: UpstepApiClient, options?: WidgetOptions);
23
24
  mount(): void;
24
25
  /** Open the feedback modal programmatically (e.g. from your own button). */
@@ -27,6 +28,7 @@ export declare class UpstepWidget {
27
28
  closeWidget(): void;
28
29
  private injectStyles;
29
30
  private renderButton;
31
+ private makeDraggable;
30
32
  private openModal;
31
33
  private closeModal;
32
34
  private fetchFeed;
@@ -1 +1 @@
1
- {"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../src/widget.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAIxC,KAAK,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;AAuG3C,MAAM,WAAW,aAAa;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,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,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAmB;IACnC,OAAO,CAAC,YAAY,CAAU;IAC9B,OAAO,CAAC,OAAO,CAAU;gBAEb,MAAM,EAAE,eAAe,EAAE,OAAO,GAAE,aAAkB;IAQhE,KAAK;IAKL,4EAA4E;IAC5E,UAAU;IAIV,iDAAiD;IACjD,WAAW;IAIX,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,SAAS;IAMjB,OAAO,CAAC,UAAU;YAKJ,SAAS;IAUvB,OAAO,CAAC,WAAW;IAyCnB,OAAO,CAAC,gBAAgB;IAoBxB,OAAO,CAAC,UAAU;IAwBlB,OAAO,CAAC,cAAc;IAOtB,OAAO,CAAC,cAAc;IAyCtB,OAAO,CAAC,eAAe;CAaxB"}
1
+ {"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../src/widget.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAIxC,KAAK,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;AAuG3C,MAAM,WAAW,aAAa;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,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,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAmB;IACnC,OAAO,CAAC,YAAY,CAAU;IAC9B,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,SAAS,CAAS;gBAEd,MAAM,EAAE,eAAe,EAAE,OAAO,GAAE,aAAkB;IAQhE,KAAK;IAKL,4EAA4E;IAC5E,UAAU;IAIV,iDAAiD;IACjD,WAAW;IAIX,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,YAAY;IAWpB,OAAO,CAAC,aAAa;IA4ErB,OAAO,CAAC,SAAS;IAMjB,OAAO,CAAC,UAAU;YAKJ,SAAS;IAUvB,OAAO,CAAC,WAAW;IAyCnB,OAAO,CAAC,gBAAgB;IAoBxB,OAAO,CAAC,UAAU;IAwBlB,OAAO,CAAC,cAAc;IAOtB,OAAO,CAAC,cAAc;IAyCtB,OAAO,CAAC,eAAe;CAaxB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@upstep/js",
3
- "version": "0.5.5",
3
+ "version": "0.5.6",
4
4
  "description": "Upstep feedback widget for web apps",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",