@upstep/js 0.1.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-CwAgmJ0s.js +1 -0
- package/dist/api-DWhfFfYu.mjs +51 -0
- package/dist/api.d.ts +19 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/index.cjs +67 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +184 -0
- package/dist/react.cjs +1 -0
- package/dist/react.d.ts +21 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +197 -0
- package/dist/widget.d.ts +23 -0
- package/dist/widget.d.ts.map +1 -0
- package/package.json +50 -0
|
@@ -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)}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;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
class r {
|
|
2
|
+
constructor(e) {
|
|
3
|
+
this.baseUrl = (e.baseUrl ?? "https://upstep.io").replace(/\/$/, ""), this.apiKey = e.apiKey, e.userId !== void 0 && (this.userId = e.userId);
|
|
4
|
+
}
|
|
5
|
+
headers() {
|
|
6
|
+
return {
|
|
7
|
+
"Content-Type": "application/json",
|
|
8
|
+
"x-api-key": this.apiKey
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
async listFeedback(e) {
|
|
12
|
+
const t = new URLSearchParams();
|
|
13
|
+
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);
|
|
14
|
+
const s = await fetch(`${this.baseUrl}/api/sdk/feedback?${t}`, {
|
|
15
|
+
headers: this.headers()
|
|
16
|
+
});
|
|
17
|
+
if (!s.ok) throw new Error(`Upstep: ${s.status}`);
|
|
18
|
+
return s.json();
|
|
19
|
+
}
|
|
20
|
+
async submitFeedback(e) {
|
|
21
|
+
const t = await fetch(`${this.baseUrl}/api/sdk/feedback`, {
|
|
22
|
+
method: "POST",
|
|
23
|
+
headers: this.headers(),
|
|
24
|
+
body: JSON.stringify({
|
|
25
|
+
...e,
|
|
26
|
+
endUserId: e.endUserId ?? this.userId
|
|
27
|
+
})
|
|
28
|
+
});
|
|
29
|
+
if (!t.ok) throw new Error(`Upstep: ${t.status}`);
|
|
30
|
+
return t.json();
|
|
31
|
+
}
|
|
32
|
+
async vote(e, t) {
|
|
33
|
+
const s = await fetch(`${this.baseUrl}/api/sdk/feedback/${e}/vote`, {
|
|
34
|
+
method: "POST",
|
|
35
|
+
headers: this.headers(),
|
|
36
|
+
body: JSON.stringify({ value: t, endUserId: this.userId })
|
|
37
|
+
});
|
|
38
|
+
if (!s.ok) throw new Error(`Upstep: ${s.status}`);
|
|
39
|
+
}
|
|
40
|
+
async removeVote(e) {
|
|
41
|
+
if (!this.userId) return;
|
|
42
|
+
const t = await fetch(
|
|
43
|
+
`${this.baseUrl}/api/sdk/feedback/${e}/vote?endUserId=${encodeURIComponent(this.userId)}`,
|
|
44
|
+
{ method: "DELETE", headers: this.headers() }
|
|
45
|
+
);
|
|
46
|
+
if (!t.ok) throw new Error(`Upstep: ${t.status}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
r as U
|
|
51
|
+
};
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Feedback, FeedbackListResponse, SubmitFeedbackPayload, VotePayload, UpstepConfig } from '@upstep/types';
|
|
2
|
+
export declare class UpstepApiClient {
|
|
3
|
+
private readonly baseUrl;
|
|
4
|
+
private readonly apiKey;
|
|
5
|
+
readonly userId?: string;
|
|
6
|
+
constructor(config: UpstepConfig);
|
|
7
|
+
private headers;
|
|
8
|
+
listFeedback(params?: {
|
|
9
|
+
cursor?: string;
|
|
10
|
+
limit?: number;
|
|
11
|
+
type?: string;
|
|
12
|
+
status?: string;
|
|
13
|
+
sort?: "date" | "votes";
|
|
14
|
+
}): Promise<FeedbackListResponse>;
|
|
15
|
+
submitFeedback(payload: SubmitFeedbackPayload): Promise<Feedback>;
|
|
16
|
+
vote(feedbackId: string, value: VotePayload["value"]): Promise<void>;
|
|
17
|
+
removeVote(feedbackId: string): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,oBAAoB,EACpB,qBAAqB,EACrB,WAAW,EACX,YAAY,EACb,MAAM,eAAe,CAAC;AAEvB,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;gBAEb,MAAM,EAAE,YAAY;IAMhC,OAAO,CAAC,OAAO;IAOT,YAAY,CAAC,MAAM,CAAC,EAAE;QAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;KACzB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAe3B,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAajE,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IASpE,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAQpD"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const p=require("./api-CwAgmJ0s.js"),r=`
|
|
2
|
+
#upstep-root *{box-sizing:border-box;font-family:inherit}
|
|
3
|
+
#upstep-btn{position:fixed;bottom:24px;right:24px;z-index:9998;background:#6366f1;color:#fff;border:none;border-radius:9999px;padding:12px 20px;font-size:14px;font-weight:600;cursor:pointer;box-shadow:0 4px 12px rgba(0,0,0,.2);transition:background .15s}
|
|
4
|
+
#upstep-btn:hover{background:#4f46e5}
|
|
5
|
+
#upstep-backdrop{position:fixed;inset:0;background:rgba(0,0,0,.45);z-index:9999;display:flex;align-items:flex-end;justify-content:center}
|
|
6
|
+
#upstep-modal{background:#fff;border-radius:16px 16px 0 0;width:100%;max-width:480px;max-height:90vh;display:flex;flex-direction:column;overflow:hidden}
|
|
7
|
+
#upstep-header{display:flex;align-items:center;justify-content:space-between;padding:16px 20px;border-bottom:1px solid #e5e7eb}
|
|
8
|
+
#upstep-header h2{margin:0;font-size:16px;font-weight:700;color:#111827}
|
|
9
|
+
#upstep-close{background:none;border:none;font-size:20px;cursor:pointer;color:#6b7280;line-height:1}
|
|
10
|
+
#upstep-tabs{display:flex;border-bottom:1px solid #e5e7eb}
|
|
11
|
+
.upstep-tab{flex:1;padding:10px;background:none;border:none;font-size:13px;font-weight:500;color:#6b7280;cursor:pointer;border-bottom:2px solid transparent}
|
|
12
|
+
.upstep-tab.active{color:#6366f1;border-bottom-color:#6366f1}
|
|
13
|
+
#upstep-body{flex:1;overflow-y:auto;padding:16px}
|
|
14
|
+
.upstep-form textarea{width:100%;min-height:100px;border:1px solid #d1d5db;border-radius:8px;padding:10px;font-size:14px;resize:vertical;outline:none}
|
|
15
|
+
.upstep-form textarea:focus{border-color:#6366f1}
|
|
16
|
+
.upstep-type-row{display:flex;gap:8px;margin:10px 0}
|
|
17
|
+
.upstep-type-btn{padding:5px 12px;border-radius:9999px;border:1px solid #d1d5db;background:#fff;font-size:12px;cursor:pointer}
|
|
18
|
+
.upstep-type-btn.selected{background:#6366f1;color:#fff;border-color:#6366f1}
|
|
19
|
+
.upstep-submit{width:100%;padding:10px;background:#6366f1;color:#fff;border:none;border-radius:8px;font-size:14px;font-weight:600;cursor:pointer;margin-top:8px}
|
|
20
|
+
.upstep-submit:disabled{opacity:.5;cursor:not-allowed}
|
|
21
|
+
.upstep-feedback-item{padding:12px 0;border-bottom:1px solid #f3f4f6}
|
|
22
|
+
.upstep-feedback-item:last-child{border-bottom:none}
|
|
23
|
+
.upstep-feedback-content{font-size:14px;color:#1f2937;margin:0 0 8px}
|
|
24
|
+
.upstep-feedback-meta{font-size:11px;color:#9ca3af;margin-bottom:8px}
|
|
25
|
+
.upstep-vote-row{display:flex;gap:8px}
|
|
26
|
+
.upstep-vote-btn{display:flex;align-items:center;gap:4px;padding:4px 10px;border-radius:9999px;border:1px solid #e5e7eb;background:#fff;font-size:12px;cursor:pointer}
|
|
27
|
+
.upstep-vote-btn:hover{border-color:#6366f1;color:#6366f1}
|
|
28
|
+
.upstep-badge{display:inline-flex;align-items:center;padding:2px 8px;border-radius:9999px;font-size:11px;font-weight:500;margin-right:6px}
|
|
29
|
+
.upstep-badge-bug{background:#fee2e2;color:#dc2626}
|
|
30
|
+
.upstep-badge-feature{background:#dbeafe;color:#2563eb}
|
|
31
|
+
.upstep-badge-general{background:#f3f4f6;color:#6b7280}
|
|
32
|
+
.upstep-empty{text-align:center;color:#9ca3af;font-size:14px;padding:32px 0}
|
|
33
|
+
`;class c{constructor(e){this.open=!1,this.tab="submit",this.feedItems=[],this.selectedType="GENERAL",this.loading=!1,this.client=e}mount(){this.injectStyles(),this.renderButton()}injectStyles(){if(document.getElementById("upstep-styles"))return;const e=document.createElement("style");e.id="upstep-styles",e.textContent=r,document.head.appendChild(e)}renderButton(){const e=document.createElement("button");e.id="upstep-btn",e.textContent="Feedback",e.addEventListener("click",()=>this.openModal()),document.body.appendChild(e)}openModal(){this.open=!0,this.fetchFeed(),this.renderModal()}closeModal(){this.open=!1;const e=document.getElementById("upstep-backdrop");e==null||e.remove()}async fetchFeed(){try{const e=await this.client.listFeedback({sort:"votes",limit:20});this.feedItems=e.items,this.renderFeedList()}catch{}}renderModal(){var t,o;const e=document.createElement("div");e.id="upstep-backdrop",e.addEventListener("click",d=>{d.target===e&&this.closeModal()}),e.innerHTML=`
|
|
34
|
+
<div id="upstep-modal">
|
|
35
|
+
<div id="upstep-header">
|
|
36
|
+
<h2>Share feedback</h2>
|
|
37
|
+
<button id="upstep-close">✕</button>
|
|
38
|
+
</div>
|
|
39
|
+
<div id="upstep-tabs">
|
|
40
|
+
<button class="upstep-tab ${this.tab==="submit"?"active":""}" data-tab="submit">Submit</button>
|
|
41
|
+
<button class="upstep-tab ${this.tab==="feed"?"active":""}" data-tab="feed">Votes & Ideas</button>
|
|
42
|
+
</div>
|
|
43
|
+
<div id="upstep-body">
|
|
44
|
+
${this.tab==="submit"?this.renderSubmitForm():this.renderFeed()}
|
|
45
|
+
</div>
|
|
46
|
+
</div>
|
|
47
|
+
`,(t=document.getElementById("upstep-backdrop"))==null||t.remove(),document.body.appendChild(e),(o=e.querySelector("#upstep-close"))==null||o.addEventListener("click",()=>this.closeModal()),e.querySelectorAll(".upstep-tab").forEach(d=>{d.addEventListener("click",()=>{this.tab=d.dataset.tab,this.renderModal()})}),this.bindSubmitForm(),this.bindVoteButtons()}renderSubmitForm(){return`
|
|
48
|
+
<div class="upstep-form">
|
|
49
|
+
<textarea id="upstep-textarea" placeholder="What's on your mind?" maxlength="2000"></textarea>
|
|
50
|
+
<div class="upstep-type-row">
|
|
51
|
+
${["BUG","FEATURE","GENERAL"].map(t=>`<button class="upstep-type-btn${this.selectedType===t?" selected":""}" data-type="${t}">${t.charAt(0)+t.slice(1).toLowerCase()}</button>`).join("")}
|
|
52
|
+
</div>
|
|
53
|
+
<button class="upstep-submit" id="upstep-submit-btn">Send feedback</button>
|
|
54
|
+
<div id="upstep-form-msg" style="font-size:13px;text-align:center;margin-top:8px;color:#6b7280"></div>
|
|
55
|
+
</div>
|
|
56
|
+
`}renderFeed(){return this.feedItems.length?this.feedItems.map(e=>`
|
|
57
|
+
<div class="upstep-feedback-item" data-id="${e.id}">
|
|
58
|
+
<p class="upstep-feedback-content">${u(e.content)}</p>
|
|
59
|
+
<div class="upstep-feedback-meta">
|
|
60
|
+
<span class="upstep-badge upstep-badge-${e.type.toLowerCase()}">${e.type}</span>
|
|
61
|
+
${new Date(e.createdAt).toLocaleDateString()}
|
|
62
|
+
</div>
|
|
63
|
+
<div class="upstep-vote-row">
|
|
64
|
+
<button class="upstep-vote-btn" data-vote="UP" data-feedback="${e.id}">▲ ${e.upvotes}</button>
|
|
65
|
+
<button class="upstep-vote-btn" data-vote="DOWN" data-feedback="${e.id}">▼ ${e.downvotes}</button>
|
|
66
|
+
</div>
|
|
67
|
+
</div>`).join(""):'<div class="upstep-empty">No feedback yet. Be the first!</div>'}renderFeedList(){const e=document.getElementById("upstep-body");!e||this.tab!=="feed"||(e.innerHTML=this.renderFeed(),this.bindVoteButtons())}bindSubmitForm(){var e;document.querySelectorAll(".upstep-type-btn").forEach(t=>{t.addEventListener("click",()=>{this.selectedType=t.dataset.type,document.querySelectorAll(".upstep-type-btn").forEach(o=>o.classList.remove("selected")),t.classList.add("selected")})}),(e=document.getElementById("upstep-submit-btn"))==null||e.addEventListener("click",async()=>{const t=document.getElementById("upstep-textarea"),o=document.getElementById("upstep-form-msg"),d=document.getElementById("upstep-submit-btn");if(!t||this.loading)return;const i=t.value.trim();if(i){this.loading=!0,d&&(d.disabled=!0);try{await this.client.submitFeedback({content:i,type:this.selectedType}),t.value="",o&&(o.textContent="Thanks for your feedback!"),await this.fetchFeed()}catch{o&&(o.textContent="Something went wrong. Please try again.")}finally{this.loading=!1,d&&(d.disabled=!1)}}})}bindVoteButtons(){document.querySelectorAll(".upstep-vote-btn").forEach(e=>{e.addEventListener("click",async()=>{const t=e.dataset.feedback,o=e.dataset.vote;try{await this.client.vote(t,o),await this.fetchFeed()}catch{}})})}}function u(s){return s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}let n=null;const a={init(s){if(n=new p.UpstepApiClient(s),typeof window<"u"){const e=()=>new c(n).mount();document.readyState==="loading"?document.addEventListener("DOMContentLoaded",e):e()}return n},get client(){if(!n)throw new Error("Upstep.init() must be called first");return n}};if(typeof document<"u"){const s=document.currentScript,e=s==null?void 0:s.dataset.apiKey,t=s==null?void 0:s.dataset.userId;if(e){const o={apiKey:e};t&&(o.userId=t),a.init(o)}}exports.UpstepApiClient=p.UpstepApiClient;exports.default=a;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { UpstepConfig } from '@upstep/types';
|
|
2
|
+
import { UpstepApiClient } from './api';
|
|
3
|
+
export type { UpstepConfig };
|
|
4
|
+
export { UpstepApiClient };
|
|
5
|
+
declare const Upstep: {
|
|
6
|
+
init(config: UpstepConfig): UpstepApiClient;
|
|
7
|
+
readonly client: UpstepApiClient;
|
|
8
|
+
};
|
|
9
|
+
export default Upstep;
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAGxC,YAAY,EAAE,YAAY,EAAE,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,CAAC;AAI3B,QAAA,MAAM,MAAM;iBACG,YAAY;qBAaX,eAAe;CAI9B,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { U as p } from "./api-DWhfFfYu.mjs";
|
|
2
|
+
const a = `
|
|
3
|
+
#upstep-root *{box-sizing:border-box;font-family:inherit}
|
|
4
|
+
#upstep-btn{position:fixed;bottom:24px;right:24px;z-index:9998;background:#6366f1;color:#fff;border:none;border-radius:9999px;padding:12px 20px;font-size:14px;font-weight:600;cursor:pointer;box-shadow:0 4px 12px rgba(0,0,0,.2);transition:background .15s}
|
|
5
|
+
#upstep-btn:hover{background:#4f46e5}
|
|
6
|
+
#upstep-backdrop{position:fixed;inset:0;background:rgba(0,0,0,.45);z-index:9999;display:flex;align-items:flex-end;justify-content:center}
|
|
7
|
+
#upstep-modal{background:#fff;border-radius:16px 16px 0 0;width:100%;max-width:480px;max-height:90vh;display:flex;flex-direction:column;overflow:hidden}
|
|
8
|
+
#upstep-header{display:flex;align-items:center;justify-content:space-between;padding:16px 20px;border-bottom:1px solid #e5e7eb}
|
|
9
|
+
#upstep-header h2{margin:0;font-size:16px;font-weight:700;color:#111827}
|
|
10
|
+
#upstep-close{background:none;border:none;font-size:20px;cursor:pointer;color:#6b7280;line-height:1}
|
|
11
|
+
#upstep-tabs{display:flex;border-bottom:1px solid #e5e7eb}
|
|
12
|
+
.upstep-tab{flex:1;padding:10px;background:none;border:none;font-size:13px;font-weight:500;color:#6b7280;cursor:pointer;border-bottom:2px solid transparent}
|
|
13
|
+
.upstep-tab.active{color:#6366f1;border-bottom-color:#6366f1}
|
|
14
|
+
#upstep-body{flex:1;overflow-y:auto;padding:16px}
|
|
15
|
+
.upstep-form textarea{width:100%;min-height:100px;border:1px solid #d1d5db;border-radius:8px;padding:10px;font-size:14px;resize:vertical;outline:none}
|
|
16
|
+
.upstep-form textarea:focus{border-color:#6366f1}
|
|
17
|
+
.upstep-type-row{display:flex;gap:8px;margin:10px 0}
|
|
18
|
+
.upstep-type-btn{padding:5px 12px;border-radius:9999px;border:1px solid #d1d5db;background:#fff;font-size:12px;cursor:pointer}
|
|
19
|
+
.upstep-type-btn.selected{background:#6366f1;color:#fff;border-color:#6366f1}
|
|
20
|
+
.upstep-submit{width:100%;padding:10px;background:#6366f1;color:#fff;border:none;border-radius:8px;font-size:14px;font-weight:600;cursor:pointer;margin-top:8px}
|
|
21
|
+
.upstep-submit:disabled{opacity:.5;cursor:not-allowed}
|
|
22
|
+
.upstep-feedback-item{padding:12px 0;border-bottom:1px solid #f3f4f6}
|
|
23
|
+
.upstep-feedback-item:last-child{border-bottom:none}
|
|
24
|
+
.upstep-feedback-content{font-size:14px;color:#1f2937;margin:0 0 8px}
|
|
25
|
+
.upstep-feedback-meta{font-size:11px;color:#9ca3af;margin-bottom:8px}
|
|
26
|
+
.upstep-vote-row{display:flex;gap:8px}
|
|
27
|
+
.upstep-vote-btn{display:flex;align-items:center;gap:4px;padding:4px 10px;border-radius:9999px;border:1px solid #e5e7eb;background:#fff;font-size:12px;cursor:pointer}
|
|
28
|
+
.upstep-vote-btn:hover{border-color:#6366f1;color:#6366f1}
|
|
29
|
+
.upstep-badge{display:inline-flex;align-items:center;padding:2px 8px;border-radius:9999px;font-size:11px;font-weight:500;margin-right:6px}
|
|
30
|
+
.upstep-badge-bug{background:#fee2e2;color:#dc2626}
|
|
31
|
+
.upstep-badge-feature{background:#dbeafe;color:#2563eb}
|
|
32
|
+
.upstep-badge-general{background:#f3f4f6;color:#6b7280}
|
|
33
|
+
.upstep-empty{text-align:center;color:#9ca3af;font-size:14px;padding:32px 0}
|
|
34
|
+
`;
|
|
35
|
+
class r {
|
|
36
|
+
constructor(e) {
|
|
37
|
+
this.open = !1, this.tab = "submit", this.feedItems = [], this.selectedType = "GENERAL", this.loading = !1, this.client = e;
|
|
38
|
+
}
|
|
39
|
+
mount() {
|
|
40
|
+
this.injectStyles(), this.renderButton();
|
|
41
|
+
}
|
|
42
|
+
injectStyles() {
|
|
43
|
+
if (document.getElementById("upstep-styles")) return;
|
|
44
|
+
const e = document.createElement("style");
|
|
45
|
+
e.id = "upstep-styles", e.textContent = a, document.head.appendChild(e);
|
|
46
|
+
}
|
|
47
|
+
renderButton() {
|
|
48
|
+
const e = document.createElement("button");
|
|
49
|
+
e.id = "upstep-btn", e.textContent = "Feedback", e.addEventListener("click", () => this.openModal()), document.body.appendChild(e);
|
|
50
|
+
}
|
|
51
|
+
openModal() {
|
|
52
|
+
this.open = !0, this.fetchFeed(), this.renderModal();
|
|
53
|
+
}
|
|
54
|
+
closeModal() {
|
|
55
|
+
this.open = !1;
|
|
56
|
+
const e = document.getElementById("upstep-backdrop");
|
|
57
|
+
e == null || e.remove();
|
|
58
|
+
}
|
|
59
|
+
async fetchFeed() {
|
|
60
|
+
try {
|
|
61
|
+
const e = await this.client.listFeedback({ sort: "votes", limit: 20 });
|
|
62
|
+
this.feedItems = e.items, this.renderFeedList();
|
|
63
|
+
} catch {
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
renderModal() {
|
|
67
|
+
var t, o;
|
|
68
|
+
const e = document.createElement("div");
|
|
69
|
+
e.id = "upstep-backdrop", e.addEventListener("click", (d) => {
|
|
70
|
+
d.target === e && this.closeModal();
|
|
71
|
+
}), e.innerHTML = `
|
|
72
|
+
<div id="upstep-modal">
|
|
73
|
+
<div id="upstep-header">
|
|
74
|
+
<h2>Share feedback</h2>
|
|
75
|
+
<button id="upstep-close">✕</button>
|
|
76
|
+
</div>
|
|
77
|
+
<div id="upstep-tabs">
|
|
78
|
+
<button class="upstep-tab ${this.tab === "submit" ? "active" : ""}" data-tab="submit">Submit</button>
|
|
79
|
+
<button class="upstep-tab ${this.tab === "feed" ? "active" : ""}" data-tab="feed">Votes & Ideas</button>
|
|
80
|
+
</div>
|
|
81
|
+
<div id="upstep-body">
|
|
82
|
+
${this.tab === "submit" ? this.renderSubmitForm() : this.renderFeed()}
|
|
83
|
+
</div>
|
|
84
|
+
</div>
|
|
85
|
+
`, (t = document.getElementById("upstep-backdrop")) == null || t.remove(), document.body.appendChild(e), (o = e.querySelector("#upstep-close")) == null || o.addEventListener("click", () => this.closeModal()), e.querySelectorAll(".upstep-tab").forEach((d) => {
|
|
86
|
+
d.addEventListener("click", () => {
|
|
87
|
+
this.tab = d.dataset.tab, this.renderModal();
|
|
88
|
+
});
|
|
89
|
+
}), this.bindSubmitForm(), this.bindVoteButtons();
|
|
90
|
+
}
|
|
91
|
+
renderSubmitForm() {
|
|
92
|
+
return `
|
|
93
|
+
<div class="upstep-form">
|
|
94
|
+
<textarea id="upstep-textarea" placeholder="What's on your mind?" maxlength="2000"></textarea>
|
|
95
|
+
<div class="upstep-type-row">
|
|
96
|
+
${["BUG", "FEATURE", "GENERAL"].map((t) => `<button class="upstep-type-btn${this.selectedType === t ? " selected" : ""}" data-type="${t}">${t.charAt(0) + t.slice(1).toLowerCase()}</button>`).join("")}
|
|
97
|
+
</div>
|
|
98
|
+
<button class="upstep-submit" id="upstep-submit-btn">Send feedback</button>
|
|
99
|
+
<div id="upstep-form-msg" style="font-size:13px;text-align:center;margin-top:8px;color:#6b7280"></div>
|
|
100
|
+
</div>
|
|
101
|
+
`;
|
|
102
|
+
}
|
|
103
|
+
renderFeed() {
|
|
104
|
+
return this.feedItems.length ? this.feedItems.map(
|
|
105
|
+
(e) => `
|
|
106
|
+
<div class="upstep-feedback-item" data-id="${e.id}">
|
|
107
|
+
<p class="upstep-feedback-content">${c(e.content)}</p>
|
|
108
|
+
<div class="upstep-feedback-meta">
|
|
109
|
+
<span class="upstep-badge upstep-badge-${e.type.toLowerCase()}">${e.type}</span>
|
|
110
|
+
${new Date(e.createdAt).toLocaleDateString()}
|
|
111
|
+
</div>
|
|
112
|
+
<div class="upstep-vote-row">
|
|
113
|
+
<button class="upstep-vote-btn" data-vote="UP" data-feedback="${e.id}">▲ ${e.upvotes}</button>
|
|
114
|
+
<button class="upstep-vote-btn" data-vote="DOWN" data-feedback="${e.id}">▼ ${e.downvotes}</button>
|
|
115
|
+
</div>
|
|
116
|
+
</div>`
|
|
117
|
+
).join("") : '<div class="upstep-empty">No feedback yet. Be the first!</div>';
|
|
118
|
+
}
|
|
119
|
+
renderFeedList() {
|
|
120
|
+
const e = document.getElementById("upstep-body");
|
|
121
|
+
!e || this.tab !== "feed" || (e.innerHTML = this.renderFeed(), this.bindVoteButtons());
|
|
122
|
+
}
|
|
123
|
+
bindSubmitForm() {
|
|
124
|
+
var e;
|
|
125
|
+
document.querySelectorAll(".upstep-type-btn").forEach((t) => {
|
|
126
|
+
t.addEventListener("click", () => {
|
|
127
|
+
this.selectedType = t.dataset.type, document.querySelectorAll(".upstep-type-btn").forEach((o) => o.classList.remove("selected")), t.classList.add("selected");
|
|
128
|
+
});
|
|
129
|
+
}), (e = document.getElementById("upstep-submit-btn")) == null || e.addEventListener("click", async () => {
|
|
130
|
+
const t = document.getElementById("upstep-textarea"), o = document.getElementById("upstep-form-msg"), d = document.getElementById("upstep-submit-btn");
|
|
131
|
+
if (!t || this.loading) return;
|
|
132
|
+
const i = t.value.trim();
|
|
133
|
+
if (i) {
|
|
134
|
+
this.loading = !0, d && (d.disabled = !0);
|
|
135
|
+
try {
|
|
136
|
+
await this.client.submitFeedback({ content: i, type: this.selectedType }), t.value = "", o && (o.textContent = "Thanks for your feedback!"), await this.fetchFeed();
|
|
137
|
+
} catch {
|
|
138
|
+
o && (o.textContent = "Something went wrong. Please try again.");
|
|
139
|
+
} finally {
|
|
140
|
+
this.loading = !1, d && (d.disabled = !1);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
bindVoteButtons() {
|
|
146
|
+
document.querySelectorAll(".upstep-vote-btn").forEach((e) => {
|
|
147
|
+
e.addEventListener("click", async () => {
|
|
148
|
+
const t = e.dataset.feedback, o = e.dataset.vote;
|
|
149
|
+
try {
|
|
150
|
+
await this.client.vote(t, o), await this.fetchFeed();
|
|
151
|
+
} catch {
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function c(s) {
|
|
158
|
+
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
159
|
+
}
|
|
160
|
+
let n = null;
|
|
161
|
+
const u = {
|
|
162
|
+
init(s) {
|
|
163
|
+
if (n = new p(s), typeof window < "u") {
|
|
164
|
+
const e = () => new r(n).mount();
|
|
165
|
+
document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", e) : e();
|
|
166
|
+
}
|
|
167
|
+
return n;
|
|
168
|
+
},
|
|
169
|
+
get client() {
|
|
170
|
+
if (!n) throw new Error("Upstep.init() must be called first");
|
|
171
|
+
return n;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
if (typeof document < "u") {
|
|
175
|
+
const s = document.currentScript, e = s == null ? void 0 : s.dataset.apiKey, t = s == null ? void 0 : s.dataset.userId;
|
|
176
|
+
if (e) {
|
|
177
|
+
const o = { apiKey: e };
|
|
178
|
+
t && (o.userId = t), u.init(o);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
export {
|
|
182
|
+
p as UpstepApiClient,
|
|
183
|
+
u as default
|
|
184
|
+
};
|
package/dist/react.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),n=require("react"),v=require("./api-CwAgmJ0s.js"),m=n.createContext(null);function w({children:d,...c}){const[s]=n.useState(()=>new v.UpstepApiClient(c)),[p,i]=n.useState([]),o=n.useCallback(async()=>{const r=await s.listFeedback({sort:"votes",limit:20});i(r.items)},[s]);n.useEffect(()=>{o()},[o]);const f=n.useCallback(async(r,a)=>{const l={content:r};a!==void 0&&(l.type=a),await s.submitFeedback(l),await o()},[s,o]),b=n.useCallback(async(r,a)=>{await s.vote(r,a),await o()},[s,o]);return e.jsx(m.Provider,{value:{client:s,feedItems:p,loadFeed:o,submit:f,vote:b},children:d})}function y(){const d=n.useContext(m);if(!d)throw new Error("useUpstep must be used inside <UpstepProvider>");return d}function C({position:d="bottom-right"}){const{feedItems:c,submit:s,vote:p}=y(),[i,o]=n.useState(!1),[f,b]=n.useState("submit"),[r,a]=n.useState(""),[l,S]=n.useState("GENERAL"),[x,g]=n.useState(""),[u,h]=n.useState(!1),j=d==="bottom-left"?{position:"fixed",bottom:24,left:24}:{position:"fixed",bottom:24,right:24};async function k(){if(!(!r.trim()||u)){h(!0);try{await s(r.trim(),l),a(""),g("Thanks for your feedback!")}catch{g("Something went wrong.")}finally{h(!1)}}}return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>o(!0),style:{...j,zIndex:9998,background:"#6366f1",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"}),i&&e.jsx("div",{onClick:t=>t.target===t.currentTarget&&o(!1),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:()=>o(!1),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:()=>b(t),style:{flex:1,padding:10,background:"none",border:"none",fontSize:13,fontWeight:500,cursor:"pointer",color:f===t?"#6366f1":"#6b7280",borderBottom:f===t?"2px solid #6366f1":"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:r,onChange:t=>a(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:()=>S(t),style:{padding:"5px 12px",borderRadius:9999,fontSize:12,cursor:"pointer",background:l===t?"#6366f1":"#fff",color:l===t?"#fff":"#374151",border:`1px solid ${l===t?"#6366f1":"#d1d5db"}`},children:t.charAt(0)+t.slice(1).toLowerCase()},t))}),e.jsx("button",{onClick:k,disabled:u||!r.trim(),style:{width:"100%",padding:10,background:"#6366f1",color:"#fff",border:"none",borderRadius:8,fontSize:14,fontWeight:600,cursor:"pointer",opacity:u||!r.trim()?.5:1},children:u?"Sending…":"Send feedback"}),x&&e.jsx("p",{style:{textAlign:"center",fontSize:13,color:"#6b7280",marginTop:8},children:x})]}):e.jsx(U,{items:c,onVote:p})})]})})]})}function U({items:d,onVote:c}){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 s={BUG:"#fee2e2",FEATURE:"#dbeafe",GENERAL:"#f3f4f6"},p={BUG:"#dc2626",FEATURE:"#2563eb",GENERAL:"#6b7280"};return e.jsx(e.Fragment,{children:d.map(i=>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:i.content}),e.jsxs("div",{style:{fontSize:11,color:"#9ca3af",marginBottom:8},children:[e.jsx("span",{style:{background:s[i.type],color:p[i.type],borderRadius:9999,padding:"2px 8px",fontSize:11,fontWeight:500,marginRight:6},children:i.type}),new Date(i.createdAt).toLocaleDateString()]}),e.jsx("div",{style:{display:"flex",gap:8},children:["UP","DOWN"].map(o=>e.jsxs("button",{onClick:()=>c(i.id,o),style:{display:"flex",alignItems:"center",gap:4,padding:"4px 10px",borderRadius:9999,border:"1px solid #e5e7eb",background:"#fff",fontSize:12,cursor:"pointer"},children:[o==="UP"?"▲":"▼"," ",o==="UP"?i.upvotes:i.downvotes]},o))})]},i.id))})}exports.FeedbackWidget=C;exports.UpstepProvider=w;exports.useUpstep=y;
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { default as React, ReactNode } from 'react';
|
|
2
|
+
import { Feedback, FeedbackType, UpstepConfig } from '@upstep/types';
|
|
3
|
+
import { UpstepApiClient } from './api';
|
|
4
|
+
interface UpstepContextValue {
|
|
5
|
+
client: UpstepApiClient;
|
|
6
|
+
feedItems: Feedback[];
|
|
7
|
+
loadFeed: () => Promise<void>;
|
|
8
|
+
submit: (content: string, type?: FeedbackType) => Promise<void>;
|
|
9
|
+
vote: (feedbackId: string, value: "UP" | "DOWN") => Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export declare function UpstepProvider({ children, ...config }: UpstepConfig & {
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
}): React.JSX.Element;
|
|
14
|
+
export declare function useUpstep(): UpstepContextValue;
|
|
15
|
+
interface FeedbackWidgetProps {
|
|
16
|
+
/** Position of the trigger button */
|
|
17
|
+
position?: "bottom-right" | "bottom-left";
|
|
18
|
+
}
|
|
19
|
+
export declare function FeedbackWidget({ position }: FeedbackWidgetProps): React.JSX.Element;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=react.d.ts.map
|
|
@@ -0,0 +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;CACnE;AAID,wBAAgB,cAAc,CAAC,EAC7B,QAAQ,EACR,GAAG,MAAM,EACV,EAAE,YAAY,GAAG;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,qBA4BxC;AAED,wBAAgB,SAAS,IAAI,kBAAkB,CAI9C;AAID,UAAU,mBAAmB;IAC3B,qCAAqC;IACrC,QAAQ,CAAC,EAAE,cAAc,GAAG,aAAa,CAAC;CAC3C;AAED,wBAAgB,cAAc,CAAC,EAAE,QAAyB,EAAE,EAAE,mBAAmB,qBA+IhF"}
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { jsxs as c, Fragment as k, jsx as e } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as z, useState as s, useCallback as x, useEffect as E, useContext as U } from "react";
|
|
3
|
+
import { U as R } from "./api-DWhfFfYu.mjs";
|
|
4
|
+
const v = z(null);
|
|
5
|
+
function T({
|
|
6
|
+
children: d,
|
|
7
|
+
...p
|
|
8
|
+
}) {
|
|
9
|
+
const [i] = s(() => new R(p)), [f, n] = s([]), o = x(async () => {
|
|
10
|
+
const r = await i.listFeedback({ sort: "votes", limit: 20 });
|
|
11
|
+
n(r.items);
|
|
12
|
+
}, [i]);
|
|
13
|
+
E(() => {
|
|
14
|
+
o();
|
|
15
|
+
}, [o]);
|
|
16
|
+
const b = x(async (r, a) => {
|
|
17
|
+
const l = { content: r };
|
|
18
|
+
a !== void 0 && (l.type = a), await i.submitFeedback(l), await o();
|
|
19
|
+
}, [i, o]), g = x(async (r, a) => {
|
|
20
|
+
await i.vote(r, a), await o();
|
|
21
|
+
}, [i, o]);
|
|
22
|
+
return /* @__PURE__ */ e(v.Provider, { value: { client: i, feedItems: f, loadFeed: o, submit: b, vote: g }, children: d });
|
|
23
|
+
}
|
|
24
|
+
function A() {
|
|
25
|
+
const d = U(v);
|
|
26
|
+
if (!d) throw new Error("useUpstep must be used inside <UpstepProvider>");
|
|
27
|
+
return d;
|
|
28
|
+
}
|
|
29
|
+
function W({ position: d = "bottom-right" }) {
|
|
30
|
+
const { feedItems: p, submit: i, vote: f } = A(), [n, o] = s(!1), [b, g] = s("submit"), [r, a] = s(""), [l, S] = s("GENERAL"), [m, h] = s(""), [u, y] = s(!1), w = d === "bottom-left" ? { position: "fixed", bottom: 24, left: 24 } : { position: "fixed", bottom: 24, right: 24 };
|
|
31
|
+
async function C() {
|
|
32
|
+
if (!(!r.trim() || u)) {
|
|
33
|
+
y(!0);
|
|
34
|
+
try {
|
|
35
|
+
await i(r.trim(), l), a(""), h("Thanks for your feedback!");
|
|
36
|
+
} catch {
|
|
37
|
+
h("Something went wrong.");
|
|
38
|
+
} finally {
|
|
39
|
+
y(!1);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return /* @__PURE__ */ c(k, { children: [
|
|
44
|
+
/* @__PURE__ */ e(
|
|
45
|
+
"button",
|
|
46
|
+
{
|
|
47
|
+
onClick: () => o(!0),
|
|
48
|
+
style: {
|
|
49
|
+
...w,
|
|
50
|
+
zIndex: 9998,
|
|
51
|
+
background: "#6366f1",
|
|
52
|
+
color: "#fff",
|
|
53
|
+
border: "none",
|
|
54
|
+
borderRadius: 9999,
|
|
55
|
+
padding: "12px 20px",
|
|
56
|
+
fontSize: 14,
|
|
57
|
+
fontWeight: 600,
|
|
58
|
+
cursor: "pointer",
|
|
59
|
+
boxShadow: "0 4px 12px rgba(0,0,0,.2)"
|
|
60
|
+
},
|
|
61
|
+
children: "Feedback"
|
|
62
|
+
}
|
|
63
|
+
),
|
|
64
|
+
n && /* @__PURE__ */ e(
|
|
65
|
+
"div",
|
|
66
|
+
{
|
|
67
|
+
onClick: (t) => t.target === t.currentTarget && o(!1),
|
|
68
|
+
style: {
|
|
69
|
+
position: "fixed",
|
|
70
|
+
inset: 0,
|
|
71
|
+
background: "rgba(0,0,0,.45)",
|
|
72
|
+
zIndex: 9999,
|
|
73
|
+
display: "flex",
|
|
74
|
+
alignItems: "flex-end",
|
|
75
|
+
justifyContent: "center"
|
|
76
|
+
},
|
|
77
|
+
children: /* @__PURE__ */ c(
|
|
78
|
+
"div",
|
|
79
|
+
{
|
|
80
|
+
style: {
|
|
81
|
+
background: "#fff",
|
|
82
|
+
borderRadius: "16px 16px 0 0",
|
|
83
|
+
width: "100%",
|
|
84
|
+
maxWidth: 480,
|
|
85
|
+
maxHeight: "90vh",
|
|
86
|
+
display: "flex",
|
|
87
|
+
flexDirection: "column",
|
|
88
|
+
overflow: "hidden"
|
|
89
|
+
},
|
|
90
|
+
children: [
|
|
91
|
+
/* @__PURE__ */ c("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", padding: "16px 20px", borderBottom: "1px solid #e5e7eb" }, children: [
|
|
92
|
+
/* @__PURE__ */ e("span", { style: { fontWeight: 700, fontSize: 16 }, children: "Share feedback" }),
|
|
93
|
+
/* @__PURE__ */ e("button", { onClick: () => o(!1), style: { background: "none", border: "none", fontSize: 20, cursor: "pointer", color: "#6b7280" }, children: "✕" })
|
|
94
|
+
] }),
|
|
95
|
+
/* @__PURE__ */ e("div", { style: { display: "flex", borderBottom: "1px solid #e5e7eb" }, children: ["submit", "feed"].map((t) => /* @__PURE__ */ e(
|
|
96
|
+
"button",
|
|
97
|
+
{
|
|
98
|
+
onClick: () => g(t),
|
|
99
|
+
style: {
|
|
100
|
+
flex: 1,
|
|
101
|
+
padding: 10,
|
|
102
|
+
background: "none",
|
|
103
|
+
border: "none",
|
|
104
|
+
fontSize: 13,
|
|
105
|
+
fontWeight: 500,
|
|
106
|
+
cursor: "pointer",
|
|
107
|
+
color: b === t ? "#6366f1" : "#6b7280",
|
|
108
|
+
borderBottom: b === t ? "2px solid #6366f1" : "2px solid transparent"
|
|
109
|
+
},
|
|
110
|
+
children: t === "submit" ? "Submit" : "Votes & Ideas"
|
|
111
|
+
},
|
|
112
|
+
t
|
|
113
|
+
)) }),
|
|
114
|
+
/* @__PURE__ */ e("div", { style: { flex: 1, overflowY: "auto", padding: 16 }, children: b === "submit" ? /* @__PURE__ */ c("div", { children: [
|
|
115
|
+
/* @__PURE__ */ e(
|
|
116
|
+
"textarea",
|
|
117
|
+
{
|
|
118
|
+
value: r,
|
|
119
|
+
onChange: (t) => a(t.target.value),
|
|
120
|
+
placeholder: "What's on your mind?",
|
|
121
|
+
maxLength: 2e3,
|
|
122
|
+
style: { width: "100%", minHeight: 100, border: "1px solid #d1d5db", borderRadius: 8, padding: 10, fontSize: 14, resize: "vertical", outline: "none" }
|
|
123
|
+
}
|
|
124
|
+
),
|
|
125
|
+
/* @__PURE__ */ e("div", { style: { display: "flex", gap: 8, margin: "10px 0" }, children: ["BUG", "FEATURE", "GENERAL"].map((t) => /* @__PURE__ */ e(
|
|
126
|
+
"button",
|
|
127
|
+
{
|
|
128
|
+
onClick: () => S(t),
|
|
129
|
+
style: {
|
|
130
|
+
padding: "5px 12px",
|
|
131
|
+
borderRadius: 9999,
|
|
132
|
+
fontSize: 12,
|
|
133
|
+
cursor: "pointer",
|
|
134
|
+
background: l === t ? "#6366f1" : "#fff",
|
|
135
|
+
color: l === t ? "#fff" : "#374151",
|
|
136
|
+
border: `1px solid ${l === t ? "#6366f1" : "#d1d5db"}`
|
|
137
|
+
},
|
|
138
|
+
children: t.charAt(0) + t.slice(1).toLowerCase()
|
|
139
|
+
},
|
|
140
|
+
t
|
|
141
|
+
)) }),
|
|
142
|
+
/* @__PURE__ */ e(
|
|
143
|
+
"button",
|
|
144
|
+
{
|
|
145
|
+
onClick: C,
|
|
146
|
+
disabled: u || !r.trim(),
|
|
147
|
+
style: { width: "100%", padding: 10, background: "#6366f1", color: "#fff", border: "none", borderRadius: 8, fontSize: 14, fontWeight: 600, cursor: "pointer", opacity: u || !r.trim() ? 0.5 : 1 },
|
|
148
|
+
children: u ? "Sending…" : "Send feedback"
|
|
149
|
+
}
|
|
150
|
+
),
|
|
151
|
+
m && /* @__PURE__ */ e("p", { style: { textAlign: "center", fontSize: 13, color: "#6b7280", marginTop: 8 }, children: m })
|
|
152
|
+
] }) : /* @__PURE__ */ e(F, { items: p, onVote: f }) })
|
|
153
|
+
]
|
|
154
|
+
}
|
|
155
|
+
)
|
|
156
|
+
}
|
|
157
|
+
)
|
|
158
|
+
] });
|
|
159
|
+
}
|
|
160
|
+
function F({ items: d, onVote: p }) {
|
|
161
|
+
if (!d.length)
|
|
162
|
+
return /* @__PURE__ */ e("p", { style: { textAlign: "center", color: "#9ca3af", fontSize: 14, padding: "32px 0" }, children: "No feedback yet. Be the first!" });
|
|
163
|
+
const i = {
|
|
164
|
+
BUG: "#fee2e2",
|
|
165
|
+
FEATURE: "#dbeafe",
|
|
166
|
+
GENERAL: "#f3f4f6"
|
|
167
|
+
}, f = {
|
|
168
|
+
BUG: "#dc2626",
|
|
169
|
+
FEATURE: "#2563eb",
|
|
170
|
+
GENERAL: "#6b7280"
|
|
171
|
+
};
|
|
172
|
+
return /* @__PURE__ */ e(k, { children: d.map((n) => /* @__PURE__ */ c("div", { style: { padding: "12px 0", borderBottom: "1px solid #f3f4f6" }, children: [
|
|
173
|
+
/* @__PURE__ */ e("p", { style: { fontSize: 14, color: "#1f2937", margin: "0 0 8px" }, children: n.content }),
|
|
174
|
+
/* @__PURE__ */ c("div", { style: { fontSize: 11, color: "#9ca3af", marginBottom: 8 }, children: [
|
|
175
|
+
/* @__PURE__ */ e("span", { style: { background: i[n.type], color: f[n.type], borderRadius: 9999, padding: "2px 8px", fontSize: 11, fontWeight: 500, marginRight: 6 }, children: n.type }),
|
|
176
|
+
new Date(n.createdAt).toLocaleDateString()
|
|
177
|
+
] }),
|
|
178
|
+
/* @__PURE__ */ e("div", { style: { display: "flex", gap: 8 }, children: ["UP", "DOWN"].map((o) => /* @__PURE__ */ c(
|
|
179
|
+
"button",
|
|
180
|
+
{
|
|
181
|
+
onClick: () => p(n.id, o),
|
|
182
|
+
style: { display: "flex", alignItems: "center", gap: 4, padding: "4px 10px", borderRadius: 9999, border: "1px solid #e5e7eb", background: "#fff", fontSize: 12, cursor: "pointer" },
|
|
183
|
+
children: [
|
|
184
|
+
o === "UP" ? "▲" : "▼",
|
|
185
|
+
" ",
|
|
186
|
+
o === "UP" ? n.upvotes : n.downvotes
|
|
187
|
+
]
|
|
188
|
+
},
|
|
189
|
+
o
|
|
190
|
+
)) })
|
|
191
|
+
] }, n.id)) });
|
|
192
|
+
}
|
|
193
|
+
export {
|
|
194
|
+
W as FeedbackWidget,
|
|
195
|
+
T as UpstepProvider,
|
|
196
|
+
A as useUpstep
|
|
197
|
+
};
|
package/dist/widget.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { UpstepApiClient } from './api';
|
|
2
|
+
export declare class UpstepWidget {
|
|
3
|
+
private client;
|
|
4
|
+
private open;
|
|
5
|
+
private tab;
|
|
6
|
+
private feedItems;
|
|
7
|
+
private selectedType;
|
|
8
|
+
private loading;
|
|
9
|
+
constructor(client: UpstepApiClient);
|
|
10
|
+
mount(): void;
|
|
11
|
+
private injectStyles;
|
|
12
|
+
private renderButton;
|
|
13
|
+
private openModal;
|
|
14
|
+
private closeModal;
|
|
15
|
+
private fetchFeed;
|
|
16
|
+
private renderModal;
|
|
17
|
+
private renderSubmitForm;
|
|
18
|
+
private renderFeed;
|
|
19
|
+
private renderFeedList;
|
|
20
|
+
private bindSubmitForm;
|
|
21
|
+
private bindVoteButtons;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=widget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../src/widget.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAsCxC,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;gBAEZ,MAAM,EAAE,eAAe;IAInC,KAAK;IAKL,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
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@upstep/js",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Upstep feedback widget for web apps",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
13
|
+
},
|
|
14
|
+
"./react": {
|
|
15
|
+
"types": "./dist/react.d.ts",
|
|
16
|
+
"import": "./dist/react.js",
|
|
17
|
+
"require": "./dist/react.cjs"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@upstep/types": "0.0.1"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"react": ">=18",
|
|
28
|
+
"react-dom": ">=18"
|
|
29
|
+
},
|
|
30
|
+
"peerDependenciesMeta": {
|
|
31
|
+
"react": {
|
|
32
|
+
"optional": true
|
|
33
|
+
},
|
|
34
|
+
"react-dom": {
|
|
35
|
+
"optional": true
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/react": "^19.0.7",
|
|
40
|
+
"@vitejs/plugin-react": "^4.3.4",
|
|
41
|
+
"typescript": "^5.7.3",
|
|
42
|
+
"vite": "^6.0.7",
|
|
43
|
+
"vite-plugin-dts": "^4.4.0"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "vite build",
|
|
47
|
+
"dev": "vite build --watch",
|
|
48
|
+
"type-check": "tsc --noEmit"
|
|
49
|
+
}
|
|
50
|
+
}
|