@upstep/js 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api-p1GbYq1j.js +1 -0
- package/dist/{api-DWhfFfYu.mjs → api-q50Qqen1.mjs} +4 -0
- package/dist/api.d.ts +3 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/index.cjs +13 -13
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +78 -51
- package/dist/react.cjs +1 -1
- package/dist/react.d.ts +16 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +81 -67
- package/dist/widget.d.ts +14 -1
- package/dist/widget.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/api-CwAgmJ0s.js +0 -1
|
@@ -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
|
-
|
|
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,
|
|
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,7 +1,7 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("./api-p1GbYq1j.js"),c="#6366f1";function u(t,e){return`
|
|
2
2
|
#upstep-root *{box-sizing:border-box;font-family:inherit}
|
|
3
|
-
#upstep-btn{position:fixed;bottom:24px
|
|
4
|
-
#upstep-btn:hover{
|
|
3
|
+
#upstep-btn{position:fixed;bottom:24px;${e==="left"?"left:24px":"right:24px"};z-index:9998;background:${t};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:filter .15s}
|
|
4
|
+
#upstep-btn:hover{filter:brightness(.92)}
|
|
5
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
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
7
|
#upstep-header{display:flex;align-items:center;justify-content:space-between;padding:16px 20px;border-bottom:1px solid #e5e7eb}
|
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
#upstep-close{background:none;border:none;font-size:20px;cursor:pointer;color:#6b7280;line-height:1}
|
|
10
10
|
#upstep-tabs{display:flex;border-bottom:1px solid #e5e7eb}
|
|
11
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
|
|
12
|
+
.upstep-tab.active{color:${t};border-bottom-color:${t}}
|
|
13
13
|
#upstep-body{flex:1;overflow-y:auto;padding:16px}
|
|
14
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
|
|
15
|
+
.upstep-form textarea:focus{border-color:${t}}
|
|
16
16
|
.upstep-type-row{display:flex;gap:8px;margin:10px 0}
|
|
17
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
|
|
19
|
-
.upstep-submit{width:100%;padding:10px;background
|
|
18
|
+
.upstep-type-btn.selected{background:${t};color:#fff;border-color:${t}}
|
|
19
|
+
.upstep-submit{width:100%;padding:10px;background:${t};color:#fff;border:none;border-radius:8px;font-size:14px;font-weight:600;cursor:pointer;margin-top:8px}
|
|
20
20
|
.upstep-submit:disabled{opacity:.5;cursor:not-allowed}
|
|
21
21
|
.upstep-feedback-item{padding:12px 0;border-bottom:1px solid #f3f4f6}
|
|
22
22
|
.upstep-feedback-item:last-child{border-bottom:none}
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
.upstep-feedback-meta{font-size:11px;color:#9ca3af;margin-bottom:8px}
|
|
25
25
|
.upstep-vote-row{display:flex;gap:8px}
|
|
26
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
|
|
27
|
+
.upstep-vote-btn:hover{border-color:${t};color:${t}}
|
|
28
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
29
|
.upstep-badge-bug{background:#fee2e2;color:#dc2626}
|
|
30
30
|
.upstep-badge-feature{background:#dbeafe;color:#2563eb}
|
|
31
31
|
.upstep-badge-general{background:#f3f4f6;color:#6b7280}
|
|
32
32
|
.upstep-empty{text-align:center;color:#9ca3af;font-size:14px;padding:32px 0}
|
|
33
|
-
|
|
33
|
+
`}class b{constructor(e,o={}){this.open=!1,this.tab="submit",this.feedItems=[],this.selectedType="GENERAL",this.loading=!1,this.client=e,this.accent=o.accentColor??c,this.position=o.position??"right",this.showLauncher=o.launcher!==!1}mount(){this.injectStyles(),this.showLauncher&&this.renderButton()}openWidget(){this.openModal()}closeWidget(){this.closeModal()}injectStyles(){if(document.getElementById("upstep-styles"))return;const e=document.createElement("style");e.id="upstep-styles",e.textContent=u(this.accent,this.position),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 o,s;const e=document.createElement("div");e.id="upstep-backdrop",e.addEventListener("click",i=>{i.target===e&&this.closeModal()}),e.innerHTML=`
|
|
34
34
|
<div id="upstep-modal">
|
|
35
35
|
<div id="upstep-header">
|
|
36
36
|
<h2>Share feedback</h2>
|
|
@@ -44,18 +44,18 @@
|
|
|
44
44
|
${this.tab==="submit"?this.renderSubmitForm():this.renderFeed()}
|
|
45
45
|
</div>
|
|
46
46
|
</div>
|
|
47
|
-
`,(
|
|
47
|
+
`,(o=document.getElementById("upstep-backdrop"))==null||o.remove(),document.body.appendChild(e),(s=e.querySelector("#upstep-close"))==null||s.addEventListener("click",()=>this.closeModal()),e.querySelectorAll(".upstep-tab").forEach(i=>{i.addEventListener("click",()=>{this.tab=i.dataset.tab,this.renderModal()})}),this.bindSubmitForm(),this.bindVoteButtons()}renderSubmitForm(){return`
|
|
48
48
|
<div class="upstep-form">
|
|
49
49
|
<textarea id="upstep-textarea" placeholder="What's on your mind?" maxlength="2000"></textarea>
|
|
50
50
|
<div class="upstep-type-row">
|
|
51
|
-
${["BUG","FEATURE","GENERAL"].map(
|
|
51
|
+
${["BUG","FEATURE","GENERAL"].map(o=>`<button class="upstep-type-btn${this.selectedType===o?" selected":""}" data-type="${o}">${o.charAt(0)+o.slice(1).toLowerCase()}</button>`).join("")}
|
|
52
52
|
</div>
|
|
53
53
|
<button class="upstep-submit" id="upstep-submit-btn">Send feedback</button>
|
|
54
54
|
<div id="upstep-form-msg" style="font-size:13px;text-align:center;margin-top:8px;color:#6b7280"></div>
|
|
55
55
|
</div>
|
|
56
56
|
`}renderFeed(){return this.feedItems.length?this.feedItems.map(e=>`
|
|
57
57
|
<div class="upstep-feedback-item" data-id="${e.id}">
|
|
58
|
-
<p class="upstep-feedback-content">${
|
|
58
|
+
<p class="upstep-feedback-content">${f(e.content)}</p>
|
|
59
59
|
<div class="upstep-feedback-meta">
|
|
60
60
|
<span class="upstep-badge upstep-badge-${e.type.toLowerCase()}">${e.type}</span>
|
|
61
61
|
${new Date(e.createdAt).toLocaleDateString()}
|
|
@@ -64,4 +64,4 @@
|
|
|
64
64
|
<button class="upstep-vote-btn" data-vote="UP" data-feedback="${e.id}">▲ ${e.upvotes}</button>
|
|
65
65
|
<button class="upstep-vote-btn" data-vote="DOWN" data-feedback="${e.id}">▼ ${e.downvotes}</button>
|
|
66
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(
|
|
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(o=>{o.addEventListener("click",()=>{this.selectedType=o.dataset.type,document.querySelectorAll(".upstep-type-btn").forEach(s=>s.classList.remove("selected")),o.classList.add("selected")})}),(e=document.getElementById("upstep-submit-btn"))==null||e.addEventListener("click",async()=>{const o=document.getElementById("upstep-textarea"),s=document.getElementById("upstep-form-msg"),i=document.getElementById("upstep-submit-btn");if(!o||this.loading)return;const a=o.value.trim();if(a){this.loading=!0,i&&(i.disabled=!0);try{await this.client.submitFeedback({content:a,type:this.selectedType}),o.value="",s&&(s.textContent="Thanks for your feedback!"),await this.fetchFeed()}catch{s&&(s.textContent="Something went wrong. Please try again.")}finally{this.loading=!1,i&&(i.disabled=!1)}}})}bindVoteButtons(){document.querySelectorAll(".upstep-vote-btn").forEach(e=>{e.addEventListener("click",async()=>{const o=e.dataset.feedback,s=e.dataset.vote;try{await this.client.vote(o,s),await this.fetchFeed()}catch{}})})}}function f(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}let d=null,n=null;const l={init(t){if(d=new r.UpstepApiClient(t),typeof window<"u"){const e={};t.accentColor!==void 0&&(e.accentColor=t.accentColor),t.position!==void 0&&(e.position=t.position),t.launcher!==void 0&&(e.launcher=t.launcher);const o=()=>{n=new b(d,e),n.mount()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",o):o()}return d},open(){n==null||n.openWidget()},close(){n==null||n.closeWidget()},identify(t){d==null||d.setUserId(t)},get client(){if(!d)throw new Error("Upstep.init() must be called first");return d}};if(typeof document<"u"){const t=document.currentScript,e=t==null?void 0:t.dataset.apiKey,o=t==null?void 0:t.dataset.userId,s=t==null?void 0:t.dataset.baseUrl,i=t==null?void 0:t.dataset.accentColor,a=t==null?void 0:t.dataset.position;if(e){const p={apiKey:e};o&&(p.userId=o),s&&(p.baseUrl=s),i&&(p.accentColor=i),(a==="left"||a==="right")&&(p.position=a),l.init(p)}}exports.UpstepApiClient=r.UpstepApiClient;exports.default=l;
|
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;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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;
|
|
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;IAoBzB,0EAA0E;;IAK1E,iCAAiC;;IAKjC,6EAA6E;qBAC5D,MAAM,GAAG,SAAS;qBAIrB,eAAe;CAI9B,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { U as
|
|
2
|
-
const
|
|
1
|
+
import { U as r } from "./api-q50Qqen1.mjs";
|
|
2
|
+
const l = "#6366f1";
|
|
3
|
+
function c(t, e) {
|
|
4
|
+
return `
|
|
3
5
|
#upstep-root *{box-sizing:border-box;font-family:inherit}
|
|
4
|
-
#upstep-btn{position:fixed;bottom:24px
|
|
5
|
-
#upstep-btn:hover{
|
|
6
|
+
#upstep-btn{position:fixed;bottom:24px;${e === "left" ? "left:24px" : "right:24px"};z-index:9998;background:${t};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:filter .15s}
|
|
7
|
+
#upstep-btn:hover{filter:brightness(.92)}
|
|
6
8
|
#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
9
|
#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
10
|
#upstep-header{display:flex;align-items:center;justify-content:space-between;padding:16px 20px;border-bottom:1px solid #e5e7eb}
|
|
@@ -10,14 +12,14 @@ const a = `
|
|
|
10
12
|
#upstep-close{background:none;border:none;font-size:20px;cursor:pointer;color:#6b7280;line-height:1}
|
|
11
13
|
#upstep-tabs{display:flex;border-bottom:1px solid #e5e7eb}
|
|
12
14
|
.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
|
|
15
|
+
.upstep-tab.active{color:${t};border-bottom-color:${t}}
|
|
14
16
|
#upstep-body{flex:1;overflow-y:auto;padding:16px}
|
|
15
17
|
.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
|
|
18
|
+
.upstep-form textarea:focus{border-color:${t}}
|
|
17
19
|
.upstep-type-row{display:flex;gap:8px;margin:10px 0}
|
|
18
20
|
.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
|
|
20
|
-
.upstep-submit{width:100%;padding:10px;background
|
|
21
|
+
.upstep-type-btn.selected{background:${t};color:#fff;border-color:${t}}
|
|
22
|
+
.upstep-submit{width:100%;padding:10px;background:${t};color:#fff;border:none;border-radius:8px;font-size:14px;font-weight:600;cursor:pointer;margin-top:8px}
|
|
21
23
|
.upstep-submit:disabled{opacity:.5;cursor:not-allowed}
|
|
22
24
|
.upstep-feedback-item{padding:12px 0;border-bottom:1px solid #f3f4f6}
|
|
23
25
|
.upstep-feedback-item:last-child{border-bottom:none}
|
|
@@ -25,24 +27,33 @@ const a = `
|
|
|
25
27
|
.upstep-feedback-meta{font-size:11px;color:#9ca3af;margin-bottom:8px}
|
|
26
28
|
.upstep-vote-row{display:flex;gap:8px}
|
|
27
29
|
.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
|
|
30
|
+
.upstep-vote-btn:hover{border-color:${t};color:${t}}
|
|
29
31
|
.upstep-badge{display:inline-flex;align-items:center;padding:2px 8px;border-radius:9999px;font-size:11px;font-weight:500;margin-right:6px}
|
|
30
32
|
.upstep-badge-bug{background:#fee2e2;color:#dc2626}
|
|
31
33
|
.upstep-badge-feature{background:#dbeafe;color:#2563eb}
|
|
32
34
|
.upstep-badge-general{background:#f3f4f6;color:#6b7280}
|
|
33
35
|
.upstep-empty{text-align:center;color:#9ca3af;font-size:14px;padding:32px 0}
|
|
34
36
|
`;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
}
|
|
38
|
+
class u {
|
|
39
|
+
constructor(e, o = {}) {
|
|
40
|
+
this.open = !1, this.tab = "submit", this.feedItems = [], this.selectedType = "GENERAL", this.loading = !1, this.client = e, this.accent = o.accentColor ?? l, this.position = o.position ?? "right", this.showLauncher = o.launcher !== !1;
|
|
38
41
|
}
|
|
39
42
|
mount() {
|
|
40
|
-
this.injectStyles(), this.renderButton();
|
|
43
|
+
this.injectStyles(), this.showLauncher && this.renderButton();
|
|
44
|
+
}
|
|
45
|
+
/** Open the feedback modal programmatically (e.g. from your own button). */
|
|
46
|
+
openWidget() {
|
|
47
|
+
this.openModal();
|
|
48
|
+
}
|
|
49
|
+
/** Close the feedback modal programmatically. */
|
|
50
|
+
closeWidget() {
|
|
51
|
+
this.closeModal();
|
|
41
52
|
}
|
|
42
53
|
injectStyles() {
|
|
43
54
|
if (document.getElementById("upstep-styles")) return;
|
|
44
55
|
const e = document.createElement("style");
|
|
45
|
-
e.id = "upstep-styles", e.textContent =
|
|
56
|
+
e.id = "upstep-styles", e.textContent = c(this.accent, this.position), document.head.appendChild(e);
|
|
46
57
|
}
|
|
47
58
|
renderButton() {
|
|
48
59
|
const e = document.createElement("button");
|
|
@@ -64,10 +75,10 @@ class r {
|
|
|
64
75
|
}
|
|
65
76
|
}
|
|
66
77
|
renderModal() {
|
|
67
|
-
var
|
|
78
|
+
var o, s;
|
|
68
79
|
const e = document.createElement("div");
|
|
69
|
-
e.id = "upstep-backdrop", e.addEventListener("click", (
|
|
70
|
-
|
|
80
|
+
e.id = "upstep-backdrop", e.addEventListener("click", (i) => {
|
|
81
|
+
i.target === e && this.closeModal();
|
|
71
82
|
}), e.innerHTML = `
|
|
72
83
|
<div id="upstep-modal">
|
|
73
84
|
<div id="upstep-header">
|
|
@@ -82,9 +93,9 @@ class r {
|
|
|
82
93
|
${this.tab === "submit" ? this.renderSubmitForm() : this.renderFeed()}
|
|
83
94
|
</div>
|
|
84
95
|
</div>
|
|
85
|
-
`, (
|
|
86
|
-
|
|
87
|
-
this.tab =
|
|
96
|
+
`, (o = document.getElementById("upstep-backdrop")) == null || o.remove(), document.body.appendChild(e), (s = e.querySelector("#upstep-close")) == null || s.addEventListener("click", () => this.closeModal()), e.querySelectorAll(".upstep-tab").forEach((i) => {
|
|
97
|
+
i.addEventListener("click", () => {
|
|
98
|
+
this.tab = i.dataset.tab, this.renderModal();
|
|
88
99
|
});
|
|
89
100
|
}), this.bindSubmitForm(), this.bindVoteButtons();
|
|
90
101
|
}
|
|
@@ -93,7 +104,7 @@ class r {
|
|
|
93
104
|
<div class="upstep-form">
|
|
94
105
|
<textarea id="upstep-textarea" placeholder="What's on your mind?" maxlength="2000"></textarea>
|
|
95
106
|
<div class="upstep-type-row">
|
|
96
|
-
${["BUG", "FEATURE", "GENERAL"].map((
|
|
107
|
+
${["BUG", "FEATURE", "GENERAL"].map((o) => `<button class="upstep-type-btn${this.selectedType === o ? " selected" : ""}" data-type="${o}">${o.charAt(0) + o.slice(1).toLowerCase()}</button>`).join("")}
|
|
97
108
|
</div>
|
|
98
109
|
<button class="upstep-submit" id="upstep-submit-btn">Send feedback</button>
|
|
99
110
|
<div id="upstep-form-msg" style="font-size:13px;text-align:center;margin-top:8px;color:#6b7280"></div>
|
|
@@ -104,7 +115,7 @@ class r {
|
|
|
104
115
|
return this.feedItems.length ? this.feedItems.map(
|
|
105
116
|
(e) => `
|
|
106
117
|
<div class="upstep-feedback-item" data-id="${e.id}">
|
|
107
|
-
<p class="upstep-feedback-content">${
|
|
118
|
+
<p class="upstep-feedback-content">${b(e.content)}</p>
|
|
108
119
|
<div class="upstep-feedback-meta">
|
|
109
120
|
<span class="upstep-badge upstep-badge-${e.type.toLowerCase()}">${e.type}</span>
|
|
110
121
|
${new Date(e.createdAt).toLocaleDateString()}
|
|
@@ -122,22 +133,22 @@ class r {
|
|
|
122
133
|
}
|
|
123
134
|
bindSubmitForm() {
|
|
124
135
|
var e;
|
|
125
|
-
document.querySelectorAll(".upstep-type-btn").forEach((
|
|
126
|
-
|
|
127
|
-
this.selectedType =
|
|
136
|
+
document.querySelectorAll(".upstep-type-btn").forEach((o) => {
|
|
137
|
+
o.addEventListener("click", () => {
|
|
138
|
+
this.selectedType = o.dataset.type, document.querySelectorAll(".upstep-type-btn").forEach((s) => s.classList.remove("selected")), o.classList.add("selected");
|
|
128
139
|
});
|
|
129
140
|
}), (e = document.getElementById("upstep-submit-btn")) == null || e.addEventListener("click", async () => {
|
|
130
|
-
const
|
|
131
|
-
if (!
|
|
132
|
-
const
|
|
133
|
-
if (
|
|
134
|
-
this.loading = !0,
|
|
141
|
+
const o = document.getElementById("upstep-textarea"), s = document.getElementById("upstep-form-msg"), i = document.getElementById("upstep-submit-btn");
|
|
142
|
+
if (!o || this.loading) return;
|
|
143
|
+
const a = o.value.trim();
|
|
144
|
+
if (a) {
|
|
145
|
+
this.loading = !0, i && (i.disabled = !0);
|
|
135
146
|
try {
|
|
136
|
-
await this.client.submitFeedback({ content:
|
|
147
|
+
await this.client.submitFeedback({ content: a, type: this.selectedType }), o.value = "", s && (s.textContent = "Thanks for your feedback!"), await this.fetchFeed();
|
|
137
148
|
} catch {
|
|
138
|
-
|
|
149
|
+
s && (s.textContent = "Something went wrong. Please try again.");
|
|
139
150
|
} finally {
|
|
140
|
-
this.loading = !1,
|
|
151
|
+
this.loading = !1, i && (i.disabled = !1);
|
|
141
152
|
}
|
|
142
153
|
}
|
|
143
154
|
});
|
|
@@ -145,40 +156,56 @@ class r {
|
|
|
145
156
|
bindVoteButtons() {
|
|
146
157
|
document.querySelectorAll(".upstep-vote-btn").forEach((e) => {
|
|
147
158
|
e.addEventListener("click", async () => {
|
|
148
|
-
const
|
|
159
|
+
const o = e.dataset.feedback, s = e.dataset.vote;
|
|
149
160
|
try {
|
|
150
|
-
await this.client.vote(
|
|
161
|
+
await this.client.vote(o, s), await this.fetchFeed();
|
|
151
162
|
} catch {
|
|
152
163
|
}
|
|
153
164
|
});
|
|
154
165
|
});
|
|
155
166
|
}
|
|
156
167
|
}
|
|
157
|
-
function
|
|
158
|
-
return
|
|
168
|
+
function b(t) {
|
|
169
|
+
return t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
159
170
|
}
|
|
160
|
-
let n = null;
|
|
161
|
-
const
|
|
162
|
-
init(
|
|
163
|
-
if (
|
|
164
|
-
const e =
|
|
165
|
-
|
|
171
|
+
let d = null, n = null;
|
|
172
|
+
const f = {
|
|
173
|
+
init(t) {
|
|
174
|
+
if (d = new r(t), typeof window < "u") {
|
|
175
|
+
const e = {};
|
|
176
|
+
t.accentColor !== void 0 && (e.accentColor = t.accentColor), t.position !== void 0 && (e.position = t.position), t.launcher !== void 0 && (e.launcher = t.launcher);
|
|
177
|
+
const o = () => {
|
|
178
|
+
n = new u(d, e), n.mount();
|
|
179
|
+
};
|
|
180
|
+
document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", o) : o();
|
|
166
181
|
}
|
|
167
|
-
return
|
|
182
|
+
return d;
|
|
183
|
+
},
|
|
184
|
+
/** Open the feedback widget — use this to trigger it from your own UI. */
|
|
185
|
+
open() {
|
|
186
|
+
n == null || n.openWidget();
|
|
187
|
+
},
|
|
188
|
+
/** Close the feedback widget. */
|
|
189
|
+
close() {
|
|
190
|
+
n == null || n.closeWidget();
|
|
191
|
+
},
|
|
192
|
+
/** Set / update the end-user id at runtime (e.g. after the user logs in). */
|
|
193
|
+
identify(t) {
|
|
194
|
+
d == null || d.setUserId(t);
|
|
168
195
|
},
|
|
169
196
|
get client() {
|
|
170
|
-
if (!
|
|
171
|
-
return
|
|
197
|
+
if (!d) throw new Error("Upstep.init() must be called first");
|
|
198
|
+
return d;
|
|
172
199
|
}
|
|
173
200
|
};
|
|
174
201
|
if (typeof document < "u") {
|
|
175
|
-
const
|
|
202
|
+
const t = document.currentScript, e = t == null ? void 0 : t.dataset.apiKey, o = t == null ? void 0 : t.dataset.userId, s = t == null ? void 0 : t.dataset.baseUrl, i = t == null ? void 0 : t.dataset.accentColor, a = t == null ? void 0 : t.dataset.position;
|
|
176
203
|
if (e) {
|
|
177
|
-
const
|
|
178
|
-
|
|
204
|
+
const p = { apiKey: e };
|
|
205
|
+
o && (p.userId = o), s && (p.baseUrl = s), i && (p.accentColor = i), (a === "left" || a === "right") && (p.position = a), f.init(p);
|
|
179
206
|
}
|
|
180
207
|
}
|
|
181
208
|
export {
|
|
182
|
-
|
|
183
|
-
|
|
209
|
+
r as UpstepApiClient,
|
|
210
|
+
f as default
|
|
184
211
|
};
|
package/dist/react.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("react"),E=require("./api-p1GbYq1j.js"),v=o.createContext(null);function z({children:d,...p}){const[n]=o.useState(()=>new E.UpstepApiClient(p)),[i,s]=o.useState([]),[c,b]=o.useState(!1);o.useEffect(()=>{n.setUserId(p.userId)},[n,p.userId]);const a=o.useCallback(async()=>{const r=await n.listFeedback({sort:"votes",limit:20});s(r.items)},[n]);o.useEffect(()=>{a()},[a]);const m=o.useCallback(async(r,l)=>{const g={content:r};l!==void 0&&(g.type=l),await n.submitFeedback(g),await a()},[n,a]),x=o.useCallback(async(r,l)=>{await n.vote(r,l),await a()},[n,a]),f=o.useCallback(()=>b(!0),[]),y=o.useCallback(()=>b(!1),[]),u=o.useCallback(r=>n.setUserId(r),[n]);return e.jsx(v.Provider,{value:{client:n,feedItems:i,loadFeed:a,submit:m,vote:x,isOpen:c,open:f,close:y,identify:u},children:d})}function C(){const d=o.useContext(v);if(!d)throw new Error("useUpstep must be used inside <UpstepProvider>");return d}function R({position:d="bottom-right",accentColor:p="#6366f1",hideLauncher:n=!1}){const i=p,{feedItems:s,submit:c,vote:b,isOpen:a,open:m,close:x}=C(),[f,y]=o.useState("submit"),[u,r]=o.useState(""),[l,g]=o.useState("GENERAL"),[k,S]=o.useState(""),[h,j]=o.useState(!1),w=d==="bottom-left"?{position:"fixed",bottom:24,left:24}:{position:"fixed",bottom:24,right:24};async function U(){if(!(!u.trim()||h)){j(!0);try{await c(u.trim(),l),r(""),S("Thanks for your feedback!")}catch{S("Something went wrong.")}finally{j(!1)}}}return e.jsxs(e.Fragment,{children:[!n&&e.jsx("button",{onClick:m,style:{...w,zIndex:9998,background:i,color:"#fff",border:"none",borderRadius:9999,padding:"12px 20px",fontSize:14,fontWeight:600,cursor:"pointer",boxShadow:"0 4px 12px rgba(0,0,0,.2)"},children:"Feedback"}),a&&e.jsx("div",{onClick:t=>t.target===t.currentTarget&&x(),style:{position:"fixed",inset:0,background:"rgba(0,0,0,.45)",zIndex:9999,display:"flex",alignItems:"flex-end",justifyContent:"center"},children:e.jsxs("div",{style:{background:"#fff",borderRadius:"16px 16px 0 0",width:"100%",maxWidth:480,maxHeight:"90vh",display:"flex",flexDirection:"column",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"16px 20px",borderBottom:"1px solid #e5e7eb"},children:[e.jsx("span",{style:{fontWeight:700,fontSize:16},children:"Share feedback"}),e.jsx("button",{onClick:x,style:{background:"none",border:"none",fontSize:20,cursor:"pointer",color:"#6b7280"},children:"✕"})]}),e.jsx("div",{style:{display:"flex",borderBottom:"1px solid #e5e7eb"},children:["submit","feed"].map(t=>e.jsx("button",{onClick:()=>y(t),style:{flex:1,padding:10,background:"none",border:"none",fontSize:13,fontWeight:500,cursor:"pointer",color:f===t?i:"#6b7280",borderBottom:f===t?`2px solid ${i}`:"2px solid transparent"},children:t==="submit"?"Submit":"Votes & Ideas"},t))}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:16},children:f==="submit"?e.jsxs("div",{children:[e.jsx("textarea",{value:u,onChange:t=>r(t.target.value),placeholder:"What's on your mind?",maxLength:2e3,style:{width:"100%",minHeight:100,border:"1px solid #d1d5db",borderRadius:8,padding:10,fontSize:14,resize:"vertical",outline:"none"}}),e.jsx("div",{style:{display:"flex",gap:8,margin:"10px 0"},children:["BUG","FEATURE","GENERAL"].map(t=>e.jsx("button",{onClick:()=>g(t),style:{padding:"5px 12px",borderRadius:9999,fontSize:12,cursor:"pointer",background:l===t?i:"#fff",color:l===t?"#fff":"#374151",border:`1px solid ${l===t?i:"#d1d5db"}`},children:t.charAt(0)+t.slice(1).toLowerCase()},t))}),e.jsx("button",{onClick:U,disabled:h||!u.trim(),style:{width:"100%",padding:10,background:i,color:"#fff",border:"none",borderRadius:8,fontSize:14,fontWeight:600,cursor:"pointer",opacity:h||!u.trim()?.5:1},children:h?"Sending…":"Send feedback"}),k&&e.jsx("p",{style:{textAlign:"center",fontSize:13,color:"#6b7280",marginTop:8},children:k})]}):e.jsx(I,{items:s,onVote:b})})]})})]})}function I({items:d,onVote:p}){if(!d.length)return e.jsx("p",{style:{textAlign:"center",color:"#9ca3af",fontSize:14,padding:"32px 0"},children:"No feedback yet. Be the first!"});const n={BUG:"#fee2e2",FEATURE:"#dbeafe",GENERAL:"#f3f4f6"},i={BUG:"#dc2626",FEATURE:"#2563eb",GENERAL:"#6b7280"};return e.jsx(e.Fragment,{children:d.map(s=>e.jsxs("div",{style:{padding:"12px 0",borderBottom:"1px solid #f3f4f6"},children:[e.jsx("p",{style:{fontSize:14,color:"#1f2937",margin:"0 0 8px"},children:s.content}),e.jsxs("div",{style:{fontSize:11,color:"#9ca3af",marginBottom:8},children:[e.jsx("span",{style:{background:n[s.type],color:i[s.type],borderRadius:9999,padding:"2px 8px",fontSize:11,fontWeight:500,marginRight:6},children:s.type}),new Date(s.createdAt).toLocaleDateString()]}),e.jsx("div",{style:{display:"flex",gap:8},children:["UP","DOWN"].map(c=>e.jsxs("button",{onClick:()=>p(s.id,c),style:{display:"flex",alignItems:"center",gap:4,padding:"4px 10px",borderRadius:9999,border:"1px solid #e5e7eb",background:"#fff",fontSize:12,cursor:"pointer"},children:[c==="UP"?"▲":"▼"," ",c==="UP"?s.upvotes:s.downvotes]},c))})]},s.id))})}exports.FeedbackWidget=R;exports.UpstepProvider=z;exports.useUpstep=C;
|
package/dist/react.d.ts
CHANGED
|
@@ -7,6 +7,14 @@ interface UpstepContextValue {
|
|
|
7
7
|
loadFeed: () => Promise<void>;
|
|
8
8
|
submit: (content: string, type?: FeedbackType) => Promise<void>;
|
|
9
9
|
vote: (feedbackId: string, value: "UP" | "DOWN") => Promise<void>;
|
|
10
|
+
/** Whether the feedback modal is currently open. */
|
|
11
|
+
isOpen: boolean;
|
|
12
|
+
/** Open the feedback modal — call from your own UI (settings, menu, etc.). */
|
|
13
|
+
open: () => void;
|
|
14
|
+
/** Close the feedback modal. */
|
|
15
|
+
close: () => void;
|
|
16
|
+
/** Set / update the end-user id at runtime (e.g. after the user logs in). */
|
|
17
|
+
identify: (userId: string | undefined) => void;
|
|
10
18
|
}
|
|
11
19
|
export declare function UpstepProvider({ children, ...config }: UpstepConfig & {
|
|
12
20
|
children: ReactNode;
|
|
@@ -15,7 +23,14 @@ export declare function useUpstep(): UpstepContextValue;
|
|
|
15
23
|
interface FeedbackWidgetProps {
|
|
16
24
|
/** Position of the trigger button */
|
|
17
25
|
position?: "bottom-right" | "bottom-left";
|
|
26
|
+
/** Accent color for the button, tabs, and highlights. Defaults to "#6366f1". */
|
|
27
|
+
accentColor?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Hide the floating launcher button and only show the modal when opened
|
|
30
|
+
* programmatically via `useUpstep().open()` — e.g. from a settings menu.
|
|
31
|
+
*/
|
|
32
|
+
hideLauncher?: boolean;
|
|
18
33
|
}
|
|
19
|
-
export declare function FeedbackWidget({ position }: FeedbackWidgetProps): React.JSX.Element;
|
|
34
|
+
export declare function FeedbackWidget({ position, accentColor, hideLauncher, }: FeedbackWidgetProps): React.JSX.Element;
|
|
20
35
|
export {};
|
|
21
36
|
//# sourceMappingURL=react.d.ts.map
|
package/dist/react.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAMZ,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAIxC,UAAU,kBAAkB;IAC1B,MAAM,EAAE,eAAe,CAAC;IACxB,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAChE,IAAI,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,GAAG,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAMZ,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAIxC,UAAU,kBAAkB;IAC1B,MAAM,EAAE,eAAe,CAAC;IACxB,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAChE,IAAI,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,GAAG,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAClE,oDAAoD;IACpD,MAAM,EAAE,OAAO,CAAC;IAChB,8EAA8E;IAC9E,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,gCAAgC;IAChC,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,6EAA6E;IAC7E,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,CAAC;CAChD;AAID,wBAAgB,cAAc,CAAC,EAC7B,QAAQ,EACR,GAAG,MAAM,EACV,EAAE,YAAY,GAAG;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,qBAyCxC;AAED,wBAAgB,SAAS,IAAI,kBAAkB,CAI9C;AAID,UAAU,mBAAmB;IAC3B,qCAAqC;IACrC,QAAQ,CAAC,EAAE,cAAc,GAAG,aAAa,CAAC;IAC1C,gFAAgF;IAChF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,wBAAgB,cAAc,CAAC,EAC7B,QAAyB,EACzB,WAAuB,EACvB,YAAoB,GACrB,EAAE,mBAAmB,qBAiJrB"}
|
package/dist/react.js
CHANGED
|
@@ -1,54 +1,68 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { createContext as
|
|
3
|
-
import { U as
|
|
4
|
-
const
|
|
5
|
-
function
|
|
1
|
+
import { jsxs as b, Fragment as z, jsx as e } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as A, useState as c, useEffect as U, useCallback as u, useContext as F } from "react";
|
|
3
|
+
import { U as W } from "./api-q50Qqen1.mjs";
|
|
4
|
+
const E = A(null);
|
|
5
|
+
function P({
|
|
6
6
|
children: d,
|
|
7
7
|
...p
|
|
8
8
|
}) {
|
|
9
|
-
const [
|
|
10
|
-
|
|
9
|
+
const [o] = c(() => new W(p)), [i, n] = c([]), [l, x] = c(!1);
|
|
10
|
+
U(() => {
|
|
11
|
+
o.setUserId(p.userId);
|
|
12
|
+
}, [o, p.userId]);
|
|
13
|
+
const s = u(async () => {
|
|
14
|
+
const r = await o.listFeedback({ sort: "votes", limit: 20 });
|
|
11
15
|
n(r.items);
|
|
12
|
-
}, [i]);
|
|
13
|
-
E(() => {
|
|
14
|
-
o();
|
|
15
16
|
}, [o]);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
U(() => {
|
|
18
|
+
s();
|
|
19
|
+
}, [s]);
|
|
20
|
+
const k = u(async (r, a) => {
|
|
21
|
+
const h = { content: r };
|
|
22
|
+
a !== void 0 && (h.type = a), await o.submitFeedback(h), await s();
|
|
23
|
+
}, [o, s]), m = u(async (r, a) => {
|
|
24
|
+
await o.vote(r, a), await s();
|
|
25
|
+
}, [o, s]), g = u(() => x(!0), []), v = u(() => x(!1), []), f = u((r) => o.setUserId(r), [o]);
|
|
26
|
+
return /* @__PURE__ */ e(
|
|
27
|
+
E.Provider,
|
|
28
|
+
{
|
|
29
|
+
value: { client: o, feedItems: i, loadFeed: s, submit: k, vote: m, isOpen: l, open: g, close: v, identify: f },
|
|
30
|
+
children: d
|
|
31
|
+
}
|
|
32
|
+
);
|
|
23
33
|
}
|
|
24
|
-
function
|
|
25
|
-
const d =
|
|
34
|
+
function B() {
|
|
35
|
+
const d = F(E);
|
|
26
36
|
if (!d) throw new Error("useUpstep must be used inside <UpstepProvider>");
|
|
27
37
|
return d;
|
|
28
38
|
}
|
|
29
|
-
function
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
39
|
+
function j({
|
|
40
|
+
position: d = "bottom-right",
|
|
41
|
+
accentColor: p = "#6366f1",
|
|
42
|
+
hideLauncher: o = !1
|
|
43
|
+
}) {
|
|
44
|
+
const i = p, { feedItems: n, submit: l, vote: x, isOpen: s, open: k, close: m } = B(), [g, v] = c("submit"), [f, r] = c(""), [a, h] = c("GENERAL"), [S, w] = c(""), [y, C] = c(!1), R = d === "bottom-left" ? { position: "fixed", bottom: 24, left: 24 } : { position: "fixed", bottom: 24, right: 24 };
|
|
45
|
+
async function I() {
|
|
46
|
+
if (!(!f.trim() || y)) {
|
|
47
|
+
C(!0);
|
|
34
48
|
try {
|
|
35
|
-
await
|
|
49
|
+
await l(f.trim(), a), r(""), w("Thanks for your feedback!");
|
|
36
50
|
} catch {
|
|
37
|
-
|
|
51
|
+
w("Something went wrong.");
|
|
38
52
|
} finally {
|
|
39
|
-
|
|
53
|
+
C(!1);
|
|
40
54
|
}
|
|
41
55
|
}
|
|
42
56
|
}
|
|
43
|
-
return /* @__PURE__ */
|
|
44
|
-
/* @__PURE__ */ e(
|
|
57
|
+
return /* @__PURE__ */ b(z, { children: [
|
|
58
|
+
!o && /* @__PURE__ */ e(
|
|
45
59
|
"button",
|
|
46
60
|
{
|
|
47
|
-
onClick:
|
|
61
|
+
onClick: k,
|
|
48
62
|
style: {
|
|
49
|
-
...
|
|
63
|
+
...R,
|
|
50
64
|
zIndex: 9998,
|
|
51
|
-
background:
|
|
65
|
+
background: i,
|
|
52
66
|
color: "#fff",
|
|
53
67
|
border: "none",
|
|
54
68
|
borderRadius: 9999,
|
|
@@ -61,10 +75,10 @@ function W({ position: d = "bottom-right" }) {
|
|
|
61
75
|
children: "Feedback"
|
|
62
76
|
}
|
|
63
77
|
),
|
|
64
|
-
|
|
78
|
+
s && /* @__PURE__ */ e(
|
|
65
79
|
"div",
|
|
66
80
|
{
|
|
67
|
-
onClick: (t) => t.target === t.currentTarget &&
|
|
81
|
+
onClick: (t) => t.target === t.currentTarget && m(),
|
|
68
82
|
style: {
|
|
69
83
|
position: "fixed",
|
|
70
84
|
inset: 0,
|
|
@@ -74,7 +88,7 @@ function W({ position: d = "bottom-right" }) {
|
|
|
74
88
|
alignItems: "flex-end",
|
|
75
89
|
justifyContent: "center"
|
|
76
90
|
},
|
|
77
|
-
children: /* @__PURE__ */
|
|
91
|
+
children: /* @__PURE__ */ b(
|
|
78
92
|
"div",
|
|
79
93
|
{
|
|
80
94
|
style: {
|
|
@@ -88,14 +102,14 @@ function W({ position: d = "bottom-right" }) {
|
|
|
88
102
|
overflow: "hidden"
|
|
89
103
|
},
|
|
90
104
|
children: [
|
|
91
|
-
/* @__PURE__ */
|
|
105
|
+
/* @__PURE__ */ b("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", padding: "16px 20px", borderBottom: "1px solid #e5e7eb" }, children: [
|
|
92
106
|
/* @__PURE__ */ e("span", { style: { fontWeight: 700, fontSize: 16 }, children: "Share feedback" }),
|
|
93
|
-
/* @__PURE__ */ e("button", { onClick:
|
|
107
|
+
/* @__PURE__ */ e("button", { onClick: m, style: { background: "none", border: "none", fontSize: 20, cursor: "pointer", color: "#6b7280" }, children: "✕" })
|
|
94
108
|
] }),
|
|
95
109
|
/* @__PURE__ */ e("div", { style: { display: "flex", borderBottom: "1px solid #e5e7eb" }, children: ["submit", "feed"].map((t) => /* @__PURE__ */ e(
|
|
96
110
|
"button",
|
|
97
111
|
{
|
|
98
|
-
onClick: () =>
|
|
112
|
+
onClick: () => v(t),
|
|
99
113
|
style: {
|
|
100
114
|
flex: 1,
|
|
101
115
|
padding: 10,
|
|
@@ -104,19 +118,19 @@ function W({ position: d = "bottom-right" }) {
|
|
|
104
118
|
fontSize: 13,
|
|
105
119
|
fontWeight: 500,
|
|
106
120
|
cursor: "pointer",
|
|
107
|
-
color:
|
|
108
|
-
borderBottom:
|
|
121
|
+
color: g === t ? i : "#6b7280",
|
|
122
|
+
borderBottom: g === t ? `2px solid ${i}` : "2px solid transparent"
|
|
109
123
|
},
|
|
110
124
|
children: t === "submit" ? "Submit" : "Votes & Ideas"
|
|
111
125
|
},
|
|
112
126
|
t
|
|
113
127
|
)) }),
|
|
114
|
-
/* @__PURE__ */ e("div", { style: { flex: 1, overflowY: "auto", padding: 16 }, children:
|
|
128
|
+
/* @__PURE__ */ e("div", { style: { flex: 1, overflowY: "auto", padding: 16 }, children: g === "submit" ? /* @__PURE__ */ b("div", { children: [
|
|
115
129
|
/* @__PURE__ */ e(
|
|
116
130
|
"textarea",
|
|
117
131
|
{
|
|
118
|
-
value:
|
|
119
|
-
onChange: (t) =>
|
|
132
|
+
value: f,
|
|
133
|
+
onChange: (t) => r(t.target.value),
|
|
120
134
|
placeholder: "What's on your mind?",
|
|
121
135
|
maxLength: 2e3,
|
|
122
136
|
style: { width: "100%", minHeight: 100, border: "1px solid #d1d5db", borderRadius: 8, padding: 10, fontSize: 14, resize: "vertical", outline: "none" }
|
|
@@ -125,15 +139,15 @@ function W({ position: d = "bottom-right" }) {
|
|
|
125
139
|
/* @__PURE__ */ e("div", { style: { display: "flex", gap: 8, margin: "10px 0" }, children: ["BUG", "FEATURE", "GENERAL"].map((t) => /* @__PURE__ */ e(
|
|
126
140
|
"button",
|
|
127
141
|
{
|
|
128
|
-
onClick: () =>
|
|
142
|
+
onClick: () => h(t),
|
|
129
143
|
style: {
|
|
130
144
|
padding: "5px 12px",
|
|
131
145
|
borderRadius: 9999,
|
|
132
146
|
fontSize: 12,
|
|
133
147
|
cursor: "pointer",
|
|
134
|
-
background:
|
|
135
|
-
color:
|
|
136
|
-
border: `1px solid ${
|
|
148
|
+
background: a === t ? i : "#fff",
|
|
149
|
+
color: a === t ? "#fff" : "#374151",
|
|
150
|
+
border: `1px solid ${a === t ? i : "#d1d5db"}`
|
|
137
151
|
},
|
|
138
152
|
children: t.charAt(0) + t.slice(1).toLowerCase()
|
|
139
153
|
},
|
|
@@ -142,14 +156,14 @@ function W({ position: d = "bottom-right" }) {
|
|
|
142
156
|
/* @__PURE__ */ e(
|
|
143
157
|
"button",
|
|
144
158
|
{
|
|
145
|
-
onClick:
|
|
146
|
-
disabled:
|
|
147
|
-
style: { width: "100%", padding: 10, background:
|
|
148
|
-
children:
|
|
159
|
+
onClick: I,
|
|
160
|
+
disabled: y || !f.trim(),
|
|
161
|
+
style: { width: "100%", padding: 10, background: i, color: "#fff", border: "none", borderRadius: 8, fontSize: 14, fontWeight: 600, cursor: "pointer", opacity: y || !f.trim() ? 0.5 : 1 },
|
|
162
|
+
children: y ? "Sending…" : "Send feedback"
|
|
149
163
|
}
|
|
150
164
|
),
|
|
151
|
-
|
|
152
|
-
] }) : /* @__PURE__ */ e(
|
|
165
|
+
S && /* @__PURE__ */ e("p", { style: { textAlign: "center", fontSize: 13, color: "#6b7280", marginTop: 8 }, children: S })
|
|
166
|
+
] }) : /* @__PURE__ */ e(L, { items: n, onVote: x }) })
|
|
153
167
|
]
|
|
154
168
|
}
|
|
155
169
|
)
|
|
@@ -157,41 +171,41 @@ function W({ position: d = "bottom-right" }) {
|
|
|
157
171
|
)
|
|
158
172
|
] });
|
|
159
173
|
}
|
|
160
|
-
function
|
|
174
|
+
function L({ items: d, onVote: p }) {
|
|
161
175
|
if (!d.length)
|
|
162
176
|
return /* @__PURE__ */ e("p", { style: { textAlign: "center", color: "#9ca3af", fontSize: 14, padding: "32px 0" }, children: "No feedback yet. Be the first!" });
|
|
163
|
-
const
|
|
177
|
+
const o = {
|
|
164
178
|
BUG: "#fee2e2",
|
|
165
179
|
FEATURE: "#dbeafe",
|
|
166
180
|
GENERAL: "#f3f4f6"
|
|
167
|
-
},
|
|
181
|
+
}, i = {
|
|
168
182
|
BUG: "#dc2626",
|
|
169
183
|
FEATURE: "#2563eb",
|
|
170
184
|
GENERAL: "#6b7280"
|
|
171
185
|
};
|
|
172
|
-
return /* @__PURE__ */ e(
|
|
186
|
+
return /* @__PURE__ */ e(z, { children: d.map((n) => /* @__PURE__ */ b("div", { style: { padding: "12px 0", borderBottom: "1px solid #f3f4f6" }, children: [
|
|
173
187
|
/* @__PURE__ */ e("p", { style: { fontSize: 14, color: "#1f2937", margin: "0 0 8px" }, children: n.content }),
|
|
174
|
-
/* @__PURE__ */
|
|
175
|
-
/* @__PURE__ */ e("span", { style: { background:
|
|
188
|
+
/* @__PURE__ */ b("div", { style: { fontSize: 11, color: "#9ca3af", marginBottom: 8 }, children: [
|
|
189
|
+
/* @__PURE__ */ e("span", { style: { background: o[n.type], color: i[n.type], borderRadius: 9999, padding: "2px 8px", fontSize: 11, fontWeight: 500, marginRight: 6 }, children: n.type }),
|
|
176
190
|
new Date(n.createdAt).toLocaleDateString()
|
|
177
191
|
] }),
|
|
178
|
-
/* @__PURE__ */ e("div", { style: { display: "flex", gap: 8 }, children: ["UP", "DOWN"].map((
|
|
192
|
+
/* @__PURE__ */ e("div", { style: { display: "flex", gap: 8 }, children: ["UP", "DOWN"].map((l) => /* @__PURE__ */ b(
|
|
179
193
|
"button",
|
|
180
194
|
{
|
|
181
|
-
onClick: () => p(n.id,
|
|
195
|
+
onClick: () => p(n.id, l),
|
|
182
196
|
style: { display: "flex", alignItems: "center", gap: 4, padding: "4px 10px", borderRadius: 9999, border: "1px solid #e5e7eb", background: "#fff", fontSize: 12, cursor: "pointer" },
|
|
183
197
|
children: [
|
|
184
|
-
|
|
198
|
+
l === "UP" ? "▲" : "▼",
|
|
185
199
|
" ",
|
|
186
|
-
|
|
200
|
+
l === "UP" ? n.upvotes : n.downvotes
|
|
187
201
|
]
|
|
188
202
|
},
|
|
189
|
-
|
|
203
|
+
l
|
|
190
204
|
)) })
|
|
191
205
|
] }, n.id)) });
|
|
192
206
|
}
|
|
193
207
|
export {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
208
|
+
j as FeedbackWidget,
|
|
209
|
+
P as UpstepProvider,
|
|
210
|
+
B as useUpstep
|
|
197
211
|
};
|
package/dist/widget.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { UpstepApiClient } from './api';
|
|
2
|
+
export interface WidgetOptions {
|
|
3
|
+
accentColor?: string;
|
|
4
|
+
position?: "left" | "right";
|
|
5
|
+
/** Render the floating launcher button. Defaults to true. */
|
|
6
|
+
launcher?: boolean;
|
|
7
|
+
}
|
|
2
8
|
export declare class UpstepWidget {
|
|
3
9
|
private client;
|
|
4
10
|
private open;
|
|
@@ -6,8 +12,15 @@ export declare class UpstepWidget {
|
|
|
6
12
|
private feedItems;
|
|
7
13
|
private selectedType;
|
|
8
14
|
private loading;
|
|
9
|
-
|
|
15
|
+
private accent;
|
|
16
|
+
private position;
|
|
17
|
+
private showLauncher;
|
|
18
|
+
constructor(client: UpstepApiClient, options?: WidgetOptions);
|
|
10
19
|
mount(): void;
|
|
20
|
+
/** Open the feedback modal programmatically (e.g. from your own button). */
|
|
21
|
+
openWidget(): void;
|
|
22
|
+
/** Close the feedback modal programmatically. */
|
|
23
|
+
closeWidget(): void;
|
|
11
24
|
private injectStyles;
|
|
12
25
|
private renderButton;
|
|
13
26
|
private openModal;
|
package/dist/widget.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../src/widget.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../src/widget.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AA4CxC,MAAM,WAAW,aAAa;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC5B,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,IAAI,CAAS;IACrB,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;gBAElB,MAAM,EAAE,eAAe,EAAE,OAAO,GAAE,aAAkB;IAOhE,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;YAMJ,SAAS;IAUvB,OAAO,CAAC,WAAW;IAsCnB,OAAO,CAAC,gBAAgB;IAcxB,OAAO,CAAC,UAAU;IAsBlB,OAAO,CAAC,cAAc;IAOtB,OAAO,CAAC,cAAc;IAmCtB,OAAO,CAAC,eAAe;CAcxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@upstep/js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Upstep feedback widget for web apps",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"dist"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@upstep/types": "0.0
|
|
24
|
+
"@upstep/types": "0.2.0"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"react": ">=18",
|
package/dist/api-CwAgmJ0s.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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)}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;
|