@upstep/js 0.7.1 → 0.8.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/README.md +4 -2
- package/dist/api-BdOCiCLM.js +1 -0
- package/dist/{api-DSXEYv9R.mjs → api-ZTIiZxlg.mjs} +42 -21
- package/dist/api.d.ts +17 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/index.cjs +23 -15
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +175 -60
- package/dist/react.cjs +1 -1
- package/dist/react.js +1 -1
- package/dist/support.cjs +1 -1
- package/dist/support.d.ts +31 -0
- package/dist/support.d.ts.map +1 -1
- package/dist/support.js +136 -48
- package/dist/upstep.global.js +12 -4
- package/dist/widget.d.ts +20 -0
- package/dist/widget.d.ts.map +1 -1
- package/package.json +9 -9
- package/dist/api-ZqVkOuh0.js +0 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { U as
|
|
1
|
+
import { U as b } from "./api-ZTIiZxlg.mjs";
|
|
2
2
|
const f = "#D97757", l = {
|
|
3
3
|
bg: "#ffffff",
|
|
4
4
|
bgSoft: "#f5f5f5",
|
|
@@ -8,7 +8,7 @@ const f = "#D97757", l = {
|
|
|
8
8
|
textFaint: "#9b9890",
|
|
9
9
|
border: "#e8e6df",
|
|
10
10
|
overlay: "rgba(26,25,21,.45)"
|
|
11
|
-
},
|
|
11
|
+
}, u = {
|
|
12
12
|
bg: "#000000",
|
|
13
13
|
bgSoft: "#171717",
|
|
14
14
|
bgHover: "#262626",
|
|
@@ -18,18 +18,18 @@ const f = "#D97757", l = {
|
|
|
18
18
|
border: "#33312c",
|
|
19
19
|
overlay: "rgba(0,0,0,.6)"
|
|
20
20
|
};
|
|
21
|
-
function
|
|
22
|
-
if (
|
|
21
|
+
function c(s) {
|
|
22
|
+
if (s === "light" || s === "dark") return s;
|
|
23
23
|
if (typeof document < "u") {
|
|
24
24
|
const t = document.documentElement;
|
|
25
25
|
return t.classList.contains("dark") || t.getAttribute("data-theme") === "dark" ? "dark" : "light";
|
|
26
26
|
}
|
|
27
27
|
return typeof window < "u" && window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
28
28
|
}
|
|
29
|
-
function
|
|
29
|
+
function m(s, t, e) {
|
|
30
30
|
return `
|
|
31
31
|
#upstep-root *{box-sizing:border-box;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif}
|
|
32
|
-
#upstep-btn{position:fixed;bottom:24px;right:24px;left:auto;z-index:9998;display:inline-flex;align-items:center;gap:7px;background:${
|
|
32
|
+
#upstep-btn{position:fixed;bottom:24px;right:24px;left:auto;z-index:9998;display:inline-flex;align-items:center;gap:7px;background:${s};color:#fff;border:none;border-radius:9999px;padding:12px 18px;font-size:14px;font-weight:600;cursor:pointer;box-shadow:0 6px 20px rgba(26,25,21,.18);transition:transform .15s,box-shadow .15s}
|
|
33
33
|
#upstep-btn svg{width:16px;height:16px;flex-shrink:0}
|
|
34
34
|
#upstep-btn:hover{transform:translateY(-1px);box-shadow:0 8px 26px rgba(26,25,21,.24)}
|
|
35
35
|
@media(max-width:639px){#upstep-btn{padding:12px}#upstep-btn span{display:none}}
|
|
@@ -50,22 +50,22 @@ function x(o, t, e) {
|
|
|
50
50
|
#upstep-body{flex:1;overflow-y:auto;padding:18px 20px 22px}
|
|
51
51
|
.upstep-form textarea{width:100%;min-height:104px;border:1px solid ${e.border};border-radius:12px;padding:12px;font-size:16px;line-height:1.6;resize:vertical;outline:none;background:${e.bgSoft};color:${e.text};transition:border-color .15s}
|
|
52
52
|
.upstep-form textarea::placeholder{color:${e.textFaint}}
|
|
53
|
-
.upstep-form textarea:focus{border-color:${
|
|
53
|
+
.upstep-form textarea:focus{border-color:${s};background:${e.bg}}
|
|
54
54
|
.upstep-type-row{display:flex;gap:7px;margin:12px 0 4px}
|
|
55
55
|
.upstep-type-btn{flex:1;display:flex;align-items:center;justify-content:center;gap:5px;padding:8px 10px;border-radius:9px;border:1px solid ${e.border};background:${e.bg};color:${e.textSoft};font-size:14px;font-weight:600;cursor:pointer;transition:all .15s}
|
|
56
56
|
.upstep-type-btn svg{width:12px;height:12px;flex-shrink:0}
|
|
57
57
|
.upstep-type-btn:hover{border-color:${e.textFaint}}
|
|
58
|
-
.upstep-type-btn.selected{background:${
|
|
59
|
-
.upstep-submit{width:100%;padding:12px;background:${
|
|
58
|
+
.upstep-type-btn.selected{background:${s};color:#fff;border-color:${s}}
|
|
59
|
+
.upstep-submit{width:100%;padding:12px;background:${s};color:#fff;border:none;border-radius:11px;font-size:14px;font-weight:600;cursor:pointer;margin-top:14px;transition:filter .15s}
|
|
60
60
|
.upstep-submit:hover{filter:brightness(.94)}
|
|
61
61
|
.upstep-submit:disabled{opacity:.5;cursor:not-allowed}
|
|
62
|
-
#upstep-form-msg{font-size:14px;text-align:center;margin-top:12px;color:${
|
|
62
|
+
#upstep-form-msg{font-size:14px;text-align:center;margin-top:12px;color:${s};font-weight:500}
|
|
63
63
|
.upstep-feedback-item{display:flex;gap:12px;padding:14px;border:1px solid ${e.border};border-radius:14px;margin-bottom:10px;background:${e.bg};transition:border-color .15s}
|
|
64
64
|
.upstep-feedback-item:hover{border-color:${e.textFaint}}
|
|
65
65
|
.upstep-vote{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;min-width:46px;padding:7px 0;border-radius:11px;border:1px solid ${e.border};background:${e.bgSoft};cursor:pointer;transition:all .15s}
|
|
66
|
-
.upstep-vote:hover{border-color:${
|
|
67
|
-
.upstep-vote.voted{border-color:${
|
|
68
|
-
.upstep-vote-arrow{font-size:11px;line-height:1;color:${
|
|
66
|
+
.upstep-vote:hover{border-color:${s}}
|
|
67
|
+
.upstep-vote.voted{border-color:${s};background:${s}1a}
|
|
68
|
+
.upstep-vote-arrow{font-size:11px;line-height:1;color:${s}}
|
|
69
69
|
.upstep-vote-count{font-size:14px;font-weight:700;color:${e.text};line-height:1.1}
|
|
70
70
|
.upstep-feedback-main{flex:1;min-width:0}
|
|
71
71
|
.upstep-feedback-content{font-size:16px;line-height:1.5;color:${e.text};margin:0 0 8px;word-break:break-word}
|
|
@@ -75,20 +75,28 @@ function x(o, t, e) {
|
|
|
75
75
|
.upstep-badge-feature{background:#e9f0fd;color:#3b76d6}
|
|
76
76
|
.upstep-badge-general{background:${e.bgSoft};color:${e.textSoft}}
|
|
77
77
|
.upstep-feedback-date{font-size:11px;color:${e.textFaint}}
|
|
78
|
+
#upstep-btn{position:fixed}
|
|
79
|
+
.upstep-unread{position:absolute;top:-7px;right:-5px;min-width:22px;height:22px;padding:0 6px;border-radius:11px;background:${e.text};color:${e.bg};border:2px solid ${e.bg};font-size:12px;font-weight:700;line-height:18px;text-align:center;font-variant-numeric:tabular-nums;animation:upstep-pop .45s cubic-bezier(.3,1.6,.5,1)}
|
|
80
|
+
@keyframes upstep-pop{from{transform:scale(.4)}to{transform:scale(1)}}
|
|
81
|
+
#upstep-toast{position:fixed;bottom:84px;right:24px;z-index:9998;max-width:min(300px,calc(100vw - 48px));display:grid;gap:2px;text-align:left;background:${e.bg};color:${e.text};border:1px solid ${e.border};border-radius:14px 14px 4px 14px;padding:10px 12px;box-shadow:0 10px 32px rgba(0,0,0,.2);cursor:pointer;animation:upstep-rise .26s cubic-bezier(.16,1,.3,1)}
|
|
82
|
+
#upstep-toast b{font-size:12px}
|
|
83
|
+
#upstep-toast span{font-size:14px;line-height:1.4;color:${e.textSoft};display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
|
|
84
|
+
#upstep-toast em{font-style:normal;font-size:11px;font-weight:600;color:${s}}
|
|
85
|
+
@media(prefers-reduced-motion:reduce){.upstep-unread,#upstep-toast{animation:none}}
|
|
78
86
|
.upstep-empty{text-align:center;color:${e.textFaint};font-size:14px;padding:40px 0}
|
|
79
87
|
.upstep-empty strong{display:block;color:${e.textSoft};font-size:15px;margin-bottom:4px}
|
|
80
88
|
`;
|
|
81
89
|
}
|
|
82
|
-
const
|
|
90
|
+
const x = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>';
|
|
83
91
|
class g {
|
|
84
92
|
constructor(t, e = {}) {
|
|
85
|
-
this.isOpen = !1, this.tab = "submit", this.feedItems = [], this.selectedType = "GENERAL", this.loading = !1, this.hasSupport = !1, this.disconnectSupport = null, this.client = t, this.accent = e.accentColor ?? f, this.position = "right", this.showLauncher = e.launcher !== !1, this.themeMode = e.theme ?? "auto", this.palette =
|
|
93
|
+
this.isOpen = !1, this.tab = "submit", this.feedItems = [], this.selectedType = "GENERAL", this.loading = !1, this.hasSupport = !1, this.disconnectSupport = null, this.unread = 0, this.audio = null, this.frameTheme = null, this.unreadListeners = /* @__PURE__ */ new Set(), this.client = t, this.accent = e.accentColor ?? f, this.position = "right", this.showLauncher = e.launcher !== !1, this.themeMode = e.theme ?? "auto", this.palette = c(this.themeMode) === "dark" ? u : l;
|
|
86
94
|
}
|
|
87
95
|
mount() {
|
|
88
96
|
this.injectStyles(), this.showLauncher && this.renderButton(), this.client.supportEnabled().then((t) => {
|
|
89
97
|
if (this.hasSupport = t, t) {
|
|
90
98
|
const e = document.querySelector("#upstep-btn span");
|
|
91
|
-
e && (e.textContent = "Help & feedback"), this.isOpen
|
|
99
|
+
e && (e.textContent = "Help & feedback"), this.isOpen ? this.renderModal() : this.hasOpenedSupport() && this.preloadSupport();
|
|
92
100
|
}
|
|
93
101
|
});
|
|
94
102
|
}
|
|
@@ -100,24 +108,123 @@ class g {
|
|
|
100
108
|
closeWidget() {
|
|
101
109
|
this.closeModal();
|
|
102
110
|
}
|
|
111
|
+
/** Whether the chat window is currently on screen. */
|
|
112
|
+
isChatVisible() {
|
|
113
|
+
return this.isOpen;
|
|
114
|
+
}
|
|
115
|
+
/** Number of unread support messages. Subscribe to drive your own launcher or badge. */
|
|
116
|
+
onUnread(t) {
|
|
117
|
+
return this.unreadListeners.add(t), t(this.unread), () => {
|
|
118
|
+
this.unreadListeners.delete(t);
|
|
119
|
+
};
|
|
120
|
+
}
|
|
103
121
|
injectStyles() {
|
|
104
122
|
var e;
|
|
105
123
|
(e = document.getElementById("upstep-styles")) == null || e.remove();
|
|
106
124
|
const t = document.createElement("style");
|
|
107
|
-
t.id = "upstep-styles", t.textContent =
|
|
125
|
+
t.id = "upstep-styles", t.textContent = m(this.accent, this.position, this.palette), document.head.appendChild(t);
|
|
108
126
|
}
|
|
109
127
|
renderButton() {
|
|
110
128
|
const t = document.createElement("button");
|
|
111
|
-
t.id = "upstep-btn", t.setAttribute("aria-label", "Open help and feedback"), t.innerHTML = `${
|
|
129
|
+
t.id = "upstep-btn", t.setAttribute("aria-label", "Open help and feedback"), t.innerHTML = `${x}<span>Feedback</span>`, t.addEventListener("click", () => {
|
|
112
130
|
this.openModal();
|
|
113
131
|
}), document.body.appendChild(t);
|
|
114
132
|
}
|
|
133
|
+
supportFrame() {
|
|
134
|
+
return document.querySelector("#upstep-support-frame");
|
|
135
|
+
}
|
|
136
|
+
get usedKey() {
|
|
137
|
+
return `upstep:support-opened:${this.client.baseUrl}`;
|
|
138
|
+
}
|
|
139
|
+
hasOpenedSupport() {
|
|
140
|
+
try {
|
|
141
|
+
return localStorage.getItem(this.usedKey) === "1";
|
|
142
|
+
} catch {
|
|
143
|
+
return !1;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
preloadSupport() {
|
|
147
|
+
this.tab = "support", this.renderModal(!0);
|
|
148
|
+
}
|
|
115
149
|
openModal() {
|
|
116
|
-
|
|
150
|
+
if (this.unlockAudio(), !this.isOpen && this.hasSupport) {
|
|
151
|
+
this.tab = "support";
|
|
152
|
+
try {
|
|
153
|
+
localStorage.setItem(this.usedKey, "1");
|
|
154
|
+
} catch {
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const t = c(this.themeMode), e = document.getElementById("upstep-backdrop"), o = this.supportFrame();
|
|
158
|
+
if (!this.isOpen && e && o && e.style.display === "none" && this.frameTheme === t) {
|
|
159
|
+
this.isOpen = !0, e.style.display = "", this.client.notifySupportVisibility(o, !0), this.setUnread(0), this.fetchFeed();
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
this.isOpen = !0, this.palette = t === "dark" ? u : l, this.injectStyles(), this.fetchFeed(), this.renderModal(), this.setUnread(0);
|
|
117
163
|
}
|
|
118
164
|
closeModal() {
|
|
119
165
|
var t, e;
|
|
120
|
-
|
|
166
|
+
if (this.isOpen = !1, this.hasSupport) {
|
|
167
|
+
const o = this.supportFrame(), i = document.getElementById("upstep-backdrop");
|
|
168
|
+
o && i ? (i.style.display = "none", this.client.notifySupportVisibility(o, !1)) : this.preloadSupport();
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
(t = this.disconnectSupport) == null || t.call(this), this.disconnectSupport = null, (e = document.getElementById("upstep-backdrop")) == null || e.remove();
|
|
172
|
+
}
|
|
173
|
+
setUnread(t) {
|
|
174
|
+
this.unread = t;
|
|
175
|
+
const e = document.getElementById("upstep-btn"), o = e == null ? void 0 : e.querySelector(".upstep-unread");
|
|
176
|
+
if (e) {
|
|
177
|
+
if (t > 0) {
|
|
178
|
+
const n = o ?? document.createElement("span");
|
|
179
|
+
n.className = "upstep-unread", n.textContent = t > 9 ? "9+" : String(t), o || e.appendChild(n);
|
|
180
|
+
} else o == null || o.remove();
|
|
181
|
+
e.setAttribute(
|
|
182
|
+
"aria-label",
|
|
183
|
+
t > 0 ? `Open help and feedback, ${t} unread ${t === 1 ? "message" : "messages"}` : "Open help and feedback"
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
const i = document.title.replace(/^\(\d+\)\s/, "");
|
|
187
|
+
document.title = t > 0 ? `(${t}) ${i}` : i, t === 0 && this.hideToast(), this.unreadListeners.forEach((n) => n(t));
|
|
188
|
+
}
|
|
189
|
+
onSupportUnread(t) {
|
|
190
|
+
if (this.isOpen) return this.setUnread(0);
|
|
191
|
+
this.setUnread(t.count), t.newMessage && t.count > 0 && (this.showToast(t), t.sound && this.chime());
|
|
192
|
+
}
|
|
193
|
+
showToast(t) {
|
|
194
|
+
this.hideToast();
|
|
195
|
+
const e = document.createElement("button");
|
|
196
|
+
e.id = "upstep-toast", e.type = "button", e.setAttribute("role", "status");
|
|
197
|
+
const o = document.createElement("b");
|
|
198
|
+
o.textContent = t.author || "New message";
|
|
199
|
+
const i = document.createElement("span");
|
|
200
|
+
i.textContent = t.preview;
|
|
201
|
+
const n = document.createElement("em");
|
|
202
|
+
n.textContent = t.count > 1 ? `${t.count} new messages` : "Tap to reply", e.append(o, i, n), e.addEventListener("click", () => this.openModal()), document.body.appendChild(e), this.toastTimer = setTimeout(() => this.hideToast(), 9e3);
|
|
203
|
+
}
|
|
204
|
+
hideToast() {
|
|
205
|
+
var t;
|
|
206
|
+
clearTimeout(this.toastTimer), (t = document.getElementById("upstep-toast")) == null || t.remove();
|
|
207
|
+
}
|
|
208
|
+
/** Browsers only allow sound after a click, so prepare audio when the chat is first opened. */
|
|
209
|
+
unlockAudio() {
|
|
210
|
+
try {
|
|
211
|
+
const t = window.AudioContext || window.webkitAudioContext;
|
|
212
|
+
if (!t) return;
|
|
213
|
+
this.audio = this.audio ?? new t(), this.audio.state === "suspended" && this.audio.resume();
|
|
214
|
+
} catch {
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
chime() {
|
|
218
|
+
const t = this.audio;
|
|
219
|
+
if (!t || t.state !== "running") return;
|
|
220
|
+
const e = t.currentTime;
|
|
221
|
+
for (const [o, i] of [
|
|
222
|
+
[880, 0],
|
|
223
|
+
[1318, 0.12]
|
|
224
|
+
]) {
|
|
225
|
+
const n = t.createOscillator(), p = t.createGain();
|
|
226
|
+
n.type = "sine", n.frequency.value = o, p.gain.setValueAtTime(1e-4, e + i), p.gain.exponentialRampToValueAtTime(0.14, e + i + 0.02), p.gain.exponentialRampToValueAtTime(1e-4, e + i + 0.5), n.connect(p), p.connect(t.destination), n.start(e + i), n.stop(e + i + 0.55);
|
|
227
|
+
}
|
|
121
228
|
}
|
|
122
229
|
async fetchFeed() {
|
|
123
230
|
try {
|
|
@@ -126,35 +233,38 @@ class g {
|
|
|
126
233
|
} catch {
|
|
127
234
|
}
|
|
128
235
|
}
|
|
129
|
-
renderModal() {
|
|
130
|
-
var i,
|
|
236
|
+
renderModal(t = !1) {
|
|
237
|
+
var i, n, p;
|
|
131
238
|
(i = this.disconnectSupport) == null || i.call(this), this.disconnectSupport = null;
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}),
|
|
239
|
+
const e = document.createElement("div");
|
|
240
|
+
e.id = "upstep-backdrop", e.addEventListener("click", (a) => {
|
|
241
|
+
a.target === e && this.closeModal();
|
|
242
|
+
}), e.innerHTML = `
|
|
136
243
|
<div id="upstep-modal" style="max-width:${this.hasSupport ? "460px" : "440px"}">
|
|
137
244
|
${this.hasSupport ? `<div class="upstep-mode" style="display:flex;align-items:center;gap:14px;padding:10px 14px;border-bottom:1px solid ${this.palette.border}"><div id="upstep-tabs" style="margin:0;padding:0;background:transparent;flex:1"><button class="upstep-tab ${this.tab === "support" ? "active" : ""}" data-tab="support">Support</button><button class="upstep-tab ${this.tab === "submit" ? "active" : ""}" data-tab="submit">Feedback</button><button class="upstep-tab ${this.tab === "feed" ? "active" : ""}" data-tab="feed">Ideas</button></div><button id="upstep-close" aria-label="Close" style="flex-shrink:0;background:transparent">✕</button></div>` : `<div id="upstep-header"><div><h2>Share your feedback</h2><p>Tell us what to build next, or vote on ideas.</p></div><button id="upstep-close" aria-label="Close">✕</button></div><div id="upstep-tabs"><button class="upstep-tab ${this.tab === "submit" ? "active" : ""}" data-tab="submit">Give feedback</button><button class="upstep-tab ${this.tab === "feed" ? "active" : ""}" data-tab="feed">Vote on ideas</button></div>`}
|
|
138
245
|
<div id="upstep-body" style="${this.tab === "support" ? "padding:0;overflow:hidden" : ""}">
|
|
139
246
|
${this.tab === "support" ? `<iframe id="upstep-support-frame" title="Customer support" src="${this.client.supportFrameUrl(this.palette.bg === "#000000" ? "dark" : "light", this.accent)}" style="width:100%;height:min(560px,calc(100dvh - 168px));min-height:300px;border:0;display:block"></iframe>` : this.tab === "submit" ? this.renderSubmitForm() : this.renderFeed()}
|
|
140
247
|
</div>
|
|
141
248
|
</div>
|
|
142
|
-
`, (
|
|
143
|
-
|
|
144
|
-
this.tab =
|
|
249
|
+
`, (n = document.getElementById("upstep-backdrop")) == null || n.remove(), t && (e.style.display = "none"), document.body.appendChild(e), (p = e.querySelector("#upstep-close")) == null || p.addEventListener("click", () => this.closeModal()), e.querySelectorAll(".upstep-tab").forEach((a) => {
|
|
250
|
+
a.addEventListener("click", () => {
|
|
251
|
+
this.tab = a.dataset.tab, this.renderModal();
|
|
145
252
|
});
|
|
146
253
|
});
|
|
147
|
-
const
|
|
254
|
+
const o = e.querySelector(
|
|
148
255
|
"#upstep-support-frame"
|
|
149
256
|
);
|
|
150
|
-
|
|
257
|
+
o && (o.style.color = this.accent, this.frameTheme = this.palette.bg === "#000000" ? "dark" : "light", this.disconnectSupport = this.client.connectSupportFrame(o, {
|
|
258
|
+
isVisible: () => this.isOpen,
|
|
259
|
+
onUnread: (a) => this.onSupportUnread(a)
|
|
260
|
+
})), this.bindSubmitForm(), this.bindVoteButtons();
|
|
151
261
|
}
|
|
152
262
|
renderSubmitForm() {
|
|
153
263
|
const t = ["BUG", "FEATURE", "GENERAL"], e = {
|
|
154
264
|
BUG: "Bug",
|
|
155
265
|
FEATURE: "Feature",
|
|
156
266
|
GENERAL: "General"
|
|
157
|
-
},
|
|
267
|
+
}, o = {
|
|
158
268
|
BUG: '<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><ellipse cx="8" cy="10" rx="3.5" ry="4.5"/><path d="M8 5.5V4M5.5 6.5 3.5 5M10.5 6.5 12.5 5M4.5 10.5 2.5 10M11.5 10.5 13.5 10"/></svg>',
|
|
159
269
|
FEATURE: '<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M8 2v1.5M8 12.5V14M2 8h1.5M12.5 8H14M4.1 4.1l1 1M10.9 10.9l1 1M11.9 4.1l-1 1M5.1 10.9l-1 1"/><circle cx="8" cy="8" r="2.5"/></svg>',
|
|
160
270
|
GENERAL: '<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M14 9a2 2 0 0 1-2 2H5L2 14V4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v5z"/></svg>'
|
|
@@ -163,7 +273,7 @@ class g {
|
|
|
163
273
|
<div class="upstep-form">
|
|
164
274
|
<textarea id="upstep-textarea" placeholder="What's on your mind?" maxlength="2000"></textarea>
|
|
165
275
|
<div class="upstep-type-row">
|
|
166
|
-
${t.map((
|
|
276
|
+
${t.map((i) => `<button class="upstep-type-btn${this.selectedType === i ? " selected" : ""}" data-type="${i}">${o[i]}${e[i]}</button>`).join("")}
|
|
167
277
|
</div>
|
|
168
278
|
<button class="upstep-submit" id="upstep-submit-btn">Send feedback</button>
|
|
169
279
|
<div id="upstep-form-msg"></div>
|
|
@@ -181,10 +291,10 @@ class g {
|
|
|
181
291
|
<span class="upstep-vote-count">${t.upvotes}</span>
|
|
182
292
|
</button>
|
|
183
293
|
<div class="upstep-feedback-main">
|
|
184
|
-
<p class="upstep-feedback-content">${
|
|
294
|
+
<p class="upstep-feedback-content">${h(t.content)}</p>
|
|
185
295
|
<div class="upstep-feedback-meta">
|
|
186
296
|
<span class="upstep-badge upstep-badge-${t.type.toLowerCase()}">${t.type}</span>
|
|
187
|
-
<span class="upstep-badge upstep-badge-general">${
|
|
297
|
+
<span class="upstep-badge upstep-badge-general">${h(((e = t.boardStatus) == null ? void 0 : e.name) ?? t.status.replace("_", " "))}</span>
|
|
188
298
|
<span class="upstep-feedback-date">${new Date(t.createdAt).toLocaleDateString()}</span>
|
|
189
299
|
</div>
|
|
190
300
|
</div>
|
|
@@ -200,27 +310,27 @@ class g {
|
|
|
200
310
|
var t;
|
|
201
311
|
document.querySelectorAll(".upstep-type-btn").forEach((e) => {
|
|
202
312
|
e.addEventListener("click", () => {
|
|
203
|
-
this.selectedType = e.dataset.type, document.querySelectorAll(".upstep-type-btn").forEach((
|
|
313
|
+
this.selectedType = e.dataset.type, document.querySelectorAll(".upstep-type-btn").forEach((o) => o.classList.remove("selected")), e.classList.add("selected");
|
|
204
314
|
});
|
|
205
315
|
}), (t = document.getElementById("upstep-submit-btn")) == null || t.addEventListener("click", async () => {
|
|
206
316
|
const e = document.getElementById(
|
|
207
317
|
"upstep-textarea"
|
|
208
|
-
),
|
|
318
|
+
), o = document.getElementById("upstep-form-msg"), i = document.getElementById(
|
|
209
319
|
"upstep-submit-btn"
|
|
210
320
|
);
|
|
211
321
|
if (!e || this.loading) return;
|
|
212
322
|
const n = e.value.trim();
|
|
213
323
|
if (n) {
|
|
214
|
-
this.loading = !0,
|
|
324
|
+
this.loading = !0, i && (i.disabled = !0, i.textContent = "Sending…");
|
|
215
325
|
try {
|
|
216
326
|
await this.client.submitFeedback({
|
|
217
327
|
content: n,
|
|
218
328
|
type: this.selectedType
|
|
219
|
-
}), e.value = "",
|
|
329
|
+
}), e.value = "", o && (o.textContent = "Feedback received. Thank you."), await this.fetchFeed();
|
|
220
330
|
} catch {
|
|
221
|
-
|
|
331
|
+
o && (o.textContent = "Something went wrong. Please try again.");
|
|
222
332
|
} finally {
|
|
223
|
-
this.loading = !1,
|
|
333
|
+
this.loading = !1, i && (i.disabled = !1, i.textContent = "Send feedback");
|
|
224
334
|
}
|
|
225
335
|
}
|
|
226
336
|
});
|
|
@@ -237,21 +347,21 @@ class g {
|
|
|
237
347
|
});
|
|
238
348
|
}
|
|
239
349
|
}
|
|
240
|
-
function
|
|
241
|
-
return
|
|
350
|
+
function h(s) {
|
|
351
|
+
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
242
352
|
}
|
|
243
|
-
let
|
|
353
|
+
let d = null, r = null;
|
|
244
354
|
const y = {
|
|
245
|
-
init(
|
|
246
|
-
if (
|
|
355
|
+
init(s) {
|
|
356
|
+
if (d = new b(s), typeof window < "u") {
|
|
247
357
|
const t = {};
|
|
248
|
-
|
|
358
|
+
s.accentColor !== void 0 && (t.accentColor = s.accentColor), s.position !== void 0 && (t.position = s.position), s.theme !== void 0 && (t.theme = s.theme), s.launcher !== void 0 && (t.launcher = s.launcher);
|
|
249
359
|
const e = () => {
|
|
250
|
-
r = new g(
|
|
360
|
+
r = new g(d, t), r.mount();
|
|
251
361
|
};
|
|
252
362
|
document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", e) : e();
|
|
253
363
|
}
|
|
254
|
-
return
|
|
364
|
+
return d;
|
|
255
365
|
},
|
|
256
366
|
/** Open the feedback widget — use this to trigger it from your own UI. */
|
|
257
367
|
open() {
|
|
@@ -262,29 +372,34 @@ const y = {
|
|
|
262
372
|
r == null || r.closeWidget();
|
|
263
373
|
},
|
|
264
374
|
/** Set / update the end-user id at runtime (e.g. after the user logs in). */
|
|
265
|
-
identify(
|
|
266
|
-
|
|
375
|
+
identify(s) {
|
|
376
|
+
d == null || d.setUserId(s);
|
|
267
377
|
},
|
|
268
378
|
/** Change or clear verified support identity after login/logout. */
|
|
269
|
-
identifySupport(
|
|
379
|
+
identifySupport(s) {
|
|
270
380
|
var e;
|
|
271
|
-
|
|
381
|
+
d && (d.supportIdentityToken = s);
|
|
272
382
|
const t = document.querySelector("#upstep-support-frame");
|
|
273
|
-
t &&
|
|
383
|
+
t && d && ((e = t.contentWindow) == null || e.postMessage({ type: "upstep:support:identity", token: s, visible: (r == null ? void 0 : r.isChatVisible()) ?? !0 }, new URL(d.baseUrl).origin));
|
|
384
|
+
},
|
|
385
|
+
/** Subscribe to the number of unread support messages, e.g. to drive your own launcher badge. */
|
|
386
|
+
onUnread(s) {
|
|
387
|
+
return (r == null ? void 0 : r.onUnread(s)) ?? (() => {
|
|
388
|
+
});
|
|
274
389
|
},
|
|
275
390
|
get client() {
|
|
276
|
-
if (!
|
|
277
|
-
return
|
|
391
|
+
if (!d) throw new Error("Upstep.init() must be called first");
|
|
392
|
+
return d;
|
|
278
393
|
}
|
|
279
394
|
};
|
|
280
395
|
if (typeof document < "u") {
|
|
281
|
-
const
|
|
396
|
+
const s = document.currentScript, t = s == null ? void 0 : s.dataset.apiKey, e = s == null ? void 0 : s.dataset.userId, o = s == null ? void 0 : s.dataset.baseUrl, i = s == null ? void 0 : s.dataset.accentColor, n = s == null ? void 0 : s.dataset.position, p = s == null ? void 0 : s.dataset.theme;
|
|
282
397
|
if (t) {
|
|
283
|
-
const
|
|
284
|
-
e && (
|
|
398
|
+
const a = { apiKey: t };
|
|
399
|
+
e && (a.userId = e), (s == null ? void 0 : s.dataset.chat) !== void 0 && (a.chat = s.dataset.chat !== "false"), o && (a.baseUrl = o), i && (a.accentColor = i), (n === "left" || n === "right") && (a.position = n), (p === "light" || p === "dark" || p === "auto") && (a.theme = p), y.init(a);
|
|
285
400
|
}
|
|
286
401
|
}
|
|
287
402
|
export {
|
|
288
|
-
|
|
403
|
+
b as UpstepApiClient,
|
|
289
404
|
y as default
|
|
290
405
|
};
|
package/dist/react.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),i=require("react"),A=require("./api-ZqVkOuh0.js"),D="#D97757",H={bg:"#ffffff",bgSoft:"#f5f5f5",bgHover:"#ededed",text:"#1a1915",textSoft:"#56544d",textFaint:"#9b9890",border:"#e8e6df",overlay:"rgba(26,25,21,.45)"},N={bg:"#000000",bgSoft:"#171717",bgHover:"#262626",text:"#f5f4f0",textSoft:"#b4b1a8",textFaint:"#7d7a72",border:"#33312c",overlay:"rgba(0,0,0,.6)"};function z(){if(typeof document>"u")return!1;const o=document.documentElement;return o.classList.contains("dark")||o.getAttribute("data-theme")==="dark"}function O(o){const[n,t]=i.useState(()=>o==="dark");return i.useEffect(()=>{if(o!=="auto"){t(o==="dark");return}if(t(z()),typeof MutationObserver>"u")return;const d=new MutationObserver(()=>t(z()));return d.observe(document.documentElement,{attributes:!0,attributeFilter:["class","data-theme"]}),()=>d.disconnect()},[o]),n?N:H}const B=i.createContext(null);function $({children:o,...n}){const[t]=i.useState(()=>new A.UpstepApiClient(n)),[d,c]=i.useState([]),[s,r]=i.useState(!1),[l,h]=i.useState(!0);i.useEffect(()=>{t.setUserId(n.userId)},[t,n.userId]),i.useEffect(()=>{t.supportIdentityToken=n.supportIdentityToken,document.querySelectorAll("iframe[data-upstep-support]").forEach(u=>{var m;return(m=u.contentWindow)==null?void 0:m.postMessage({type:"upstep:support:identity",token:n.supportIdentityToken},new URL(t.baseUrl).origin)})},[t,n.supportIdentityToken]);const p=i.useCallback(async()=>{try{const u=await t.listFeedback({sort:"votes",limit:20});c(u.items),h(u.showBranding??!0)}catch{}},[t]);i.useEffect(()=>{p()},[p]);const j=i.useCallback(async(u,m,S)=>{const x={content:m};u.trim()&&(x.title=u.trim()),S!==void 0&&(x.type=S),await t.submitFeedback(x),await p()},[t,p]),b=i.useCallback(async(u,m)=>{try{await t.vote(u,m),await p()}catch{}},[t,p]),a=i.useCallback(u=>t.getItem(u),[t]),g=i.useCallback(()=>r(!0),[]),y=i.useCallback(()=>r(!1),[]),k=i.useCallback(u=>t.setUserId(u),[t]);return e.jsx(B.Provider,{value:{client:t,feedItems:d,loadFeed:p,submit:j,vote:b,getItem:a,isOpen:s,open:g,close:y,identify:k,accentColor:n.accentColor??D,theme:n.theme??"auto",showBranding:l,chat:n.chat!==!1},children:o})}function w(){const o=i.useContext(B);if(!o)throw new Error("useUpstep must be used inside <UpstepProvider>");return o}function G({position:o="bottom-right",accentColor:n,theme:t,hideLauncher:d=!1,chat:c=!0}){const s=w(),r=n??s.accentColor,l=O(t??s.theme),{isOpen:h,open:p,close:j,showBranding:b}=s,[a,g]=i.useState("list"),[y,k]=i.useState(!1);i.useEffect(()=>{let f=!0;if(s.client.chat=s.chat,!s.chat||!c){k(!1);return}return s.client.supportEnabled().then(v=>{f&&k(v)}),()=>{f=!1}},[s.client,s.chat,c]),i.useEffect(()=>{(!s.chat||!c)&&a==="support"&&g("list")},[s.chat,c,a]),i.useEffect(()=>{h&&g(y&&c&&s.chat?"support":"list")},[h,y,c,s.chat]);const[u,m]=i.useState(null),[S,x]=i.useState(!1);i.useEffect(()=>{const f=window.matchMedia("(max-width: 639px)");x(f.matches);const v=P=>x(P.matches);return f.addEventListener("change",v),()=>f.removeEventListener("change",v)},[]);const L={position:"fixed",bottom:24,right:24},C='-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif';function F(){j(),m(null)}function M(f){m(f),g("detail")}return e.jsxs(e.Fragment,{children:[!d&&e.jsxs("button",{"aria-label":"Open help and feedback",onClick:p,style:{...L,zIndex:9998,display:"inline-flex",alignItems:"center",gap:7,background:r,color:"#fff",border:"none",borderRadius:9999,padding:S?"12px":"12px 18px",fontSize:14,fontWeight:600,cursor:"pointer",fontFamily:C,boxShadow:"0 6px 20px rgba(26,25,21,.18)"},children:[e.jsx(Z,{size:16}),!S&&(y&&c&&s.chat?"Help & feedback":"Feedback")]}),h&&e.jsx("div",{onClick:f=>f.target===f.currentTarget&&F(),style:{position:"fixed",inset:0,background:"transparent",zIndex:9999,display:"flex",alignItems:"flex-end",justifyContent:"flex-end",padding:S?"0 12px 80px":"0 24px 88px",fontFamily:C},children:e.jsxs("div",{style:{background:l.bg,border:`1px solid ${l.border}`,borderRadius:20,width:"100%",maxWidth:y&&c&&s.chat?460:440,maxHeight:"calc(100dvh - 112px)",display:"flex",flexDirection:"column",overflow:"hidden",boxShadow:"0 24px 64px rgba(0,0,0,.28)"},children:[y&&c&&s.chat?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:14,padding:"10px 14px",borderBottom:`1px solid ${l.border}`,flexShrink:0},children:[e.jsx("div",{style:{display:"flex",flex:1,gap:4},children:[["support","Support"],["list","Feedback"]].map(([f,v])=>e.jsx("button",{onClick:()=>g(f),style:{flex:1,border:0,borderRadius:8,padding:"9px 12px",background:(a==="support"?f==="support":f==="list")?l.bgSoft:"transparent",color:(a==="support"?f==="support":f==="list")?l.text:l.textSoft,fontSize:14,fontWeight:600,cursor:"pointer"},children:v},f))}),e.jsx("button",{"aria-label":"Close",onClick:F,style:{border:0,background:"transparent",color:l.textSoft,padding:6,cursor:"pointer",fontSize:14},children:"✕"})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"16px 20px",borderBottom:`1px solid ${l.border}`,flexShrink:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[a!=="list"&&e.jsx("button",{onClick:()=>g("list"),style:{background:"none",border:"none",cursor:"pointer",color:r,fontSize:14,fontWeight:600,padding:0},children:"← Back"}),a==="list"&&e.jsx("span",{style:{fontWeight:700,fontSize:16,color:l.text,letterSpacing:"-.01em"},children:"Feedback"}),a==="create"&&e.jsx("span",{style:{fontWeight:700,fontSize:16,color:l.text,letterSpacing:"-.01em"},children:"New feedback"})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[a==="list"&&e.jsx("button",{onClick:()=>g("create"),style:{background:r,color:"#fff",border:"none",borderRadius:20,padding:"6px 14px",fontSize:14,fontWeight:700,cursor:"pointer"},children:"+ New"}),e.jsx("button",{onClick:F,style:{background:l.bgSoft,border:"none",width:28,height:28,borderRadius:8,fontSize:14,cursor:"pointer",color:l.textSoft,display:"flex",alignItems:"center",justifyContent:"center"},children:"✕"})]})]}),e.jsxs("div",{style:{flex:1,overflowY:"auto",padding:a==="support"?0:"16px 20px 24px"},children:[a==="support"&&c&&s.chat&&e.jsx(V,{client:s.client,accentColor:r,theme:l.bg==="#000000"?"dark":"light"}),y&&c&&s.chat&&a!=="support"&&e.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:16},children:a==="list"?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{fontSize:14,fontWeight:600,color:l.text},children:"Feedback & ideas"}),e.jsx("button",{onClick:()=>g("create"),style:{border:0,borderRadius:8,background:r,color:"white",fontSize:14,padding:"7px 10px",cursor:"pointer"},children:"+ New"})]}):e.jsx("button",{onClick:()=>g("list"),style:{border:0,background:"none",padding:0,color:l.textSoft,fontSize:14,cursor:"pointer"},children:"← Back to feedback"})}),a==="list"&&e.jsx(_,{onSelect:M,accent:r,p:l}),a==="detail"&&u&&e.jsx(q,{feedbackId:u,accent:r,p:l,font:C}),a==="create"&&e.jsx(K,{accent:r,p:l,font:C,onDone:()=>g("list")})]}),b&&a!=="support"&&e.jsxs("a",{href:"https://upstep.dev",target:"_blank",rel:"noopener noreferrer",style:{display:"block",textAlign:"center",padding:"8px 0",borderTop:`1px solid ${l.border}`,fontSize:11,color:l.textFaint,textDecoration:"none",flexShrink:0},children:["Powered by"," ",e.jsx("strong",{style:{fontWeight:700},children:"Upstep.dev"})]})]})})]})}function V({client:o,theme:n,accentColor:t}){const d=i.useRef(null);return i.useEffect(()=>{if(d.current)return o.connectSupportFrame(d.current)},[o]),e.jsx("iframe",{ref:d,"data-upstep-support":!0,title:"Customer support",src:o.supportFrameUrl(n,t),style:{color:t,width:"100%",height:"min(560px, calc(100dvh - 168px))",minHeight:300,border:0,display:"block"}})}function _({onSelect:o,accent:n,p:t}){const{feedItems:d,vote:c}=w(),s=d.filter(r=>r.status!=="CLOSED");return s.length?e.jsx(e.Fragment,{children:s.map(r=>{const l=r.userVote==="UP",h=r.title??r.content;return e.jsxs("div",{onClick:()=>o(r.id),style:{display:"flex",gap:12,padding:14,border:`1px solid ${t.border}`,borderRadius:14,marginBottom:10,background:t.bg,cursor:"pointer"},children:[e.jsxs("button",{onClick:p=>{p.stopPropagation(),c(r.id,"UP")},style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:2,minWidth:46,padding:"7px 0",borderRadius:11,cursor:"pointer",flexShrink:0,border:`1px solid ${l?n:t.border}`,background:l?`${n}1a`:t.bgSoft},children:[e.jsx(U,{color:n}),e.jsx("span",{style:{fontSize:14,fontWeight:700,color:t.text,lineHeight:1.1},children:r.upvotes})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("p",{style:{fontSize:14,fontWeight:600,lineHeight:1.4,color:t.text,margin:"0 0 6px",overflow:"hidden",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:h}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[e.jsx(I,{type:r.type,p:t}),r.status==="PENDING"?e.jsx(W,{}):e.jsx(T,{status:r.status,boardStatus:r.boardStatus,p:t}),e.jsx("span",{style:{fontSize:11,color:t.textFaint},children:R(r.createdAt)})]})]}),e.jsx("span",{style:{color:t.textFaint,fontSize:18,alignSelf:"center",flexShrink:0},children:"›"})]},r.id)})}):e.jsxs("div",{style:{textAlign:"center",padding:"40px 0"},children:[e.jsx("div",{style:{color:t.textSoft,fontSize:15,fontWeight:600,marginBottom:4},children:"No open feedback yet"}),e.jsx("div",{style:{color:t.textFaint,fontSize:14},children:"Be the first to share one."})]})}function q({feedbackId:o,accent:n,p:t,font:d}){const{vote:c,getItem:s}=w(),[r,l]=i.useState(null),[h,p]=i.useState(!1);i.useEffect(()=>{let a=!1;return s(o).then(g=>{a||l(g)}).catch(()=>{}),()=>{a=!0}},[o,s]);async function j(){if(!(!r||h)){p(!0);try{await c(r.id,"UP");const a=await s(o);l(a)}catch{}finally{p(!1)}}}if(!r)return e.jsx("div",{style:{textAlign:"center",padding:"40px 0",color:t.textFaint,fontSize:14},children:"Loading…"});const b=r.title;return e.jsxs("div",{children:[b&&e.jsx("div",{style:{fontSize:20,fontWeight:700,color:t.text,letterSpacing:"-.02em",marginBottom:10,lineHeight:1.3},children:b}),e.jsxs("div",{style:{display:"flex",gap:6,marginBottom:14,flexWrap:"wrap"},children:[e.jsx(I,{type:r.type,p:t}),r.status==="PENDING"?e.jsx(W,{}):e.jsx(T,{status:r.status,boardStatus:r.boardStatus,p:t})]}),e.jsx("p",{style:{fontSize:15,lineHeight:1.6,color:t.textSoft,marginBottom:20},children:r.content}),e.jsxs("button",{onClick:j,disabled:h,style:{display:"inline-flex",alignItems:"center",gap:8,border:`1px solid ${r.userVote==="UP"?n:t.border}`,background:r.userVote==="UP"?`${n}15`:t.bgSoft,borderRadius:12,padding:"10px 16px",cursor:"pointer",fontFamily:d},children:[e.jsx(U,{color:n,size:13}),e.jsx("span",{style:{fontSize:18,fontWeight:700,color:t.text},children:r.upvotes}),e.jsx("span",{style:{fontSize:14,color:t.textFaint},children:r.userVote==="UP"?"Upvoted":"Upvote"})]}),r.comments.length>0&&e.jsxs("div",{style:{marginTop:28,borderTop:`1px solid ${t.border}`,paddingTop:20},children:[e.jsx("div",{style:{fontSize:10,fontWeight:700,letterSpacing:".08em",color:t.textFaint,marginBottom:12,textTransform:"uppercase"},children:"Comments"}),r.comments.map(a=>e.jsx(Y,{comment:a,p:t,accent:n},a.id))]})]})}function Y({comment:o,p:n,accent:t}){var d;return e.jsxs("div",{style:{background:n.bgSoft,border:`1px solid ${n.border}`,borderRadius:12,padding:14,marginBottom:10},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:8},children:[e.jsx("span",{style:{background:`${t}20`,color:t,fontSize:11,fontWeight:700,borderRadius:20,padding:"2px 8px"},children:((d=o.authorName)==null?void 0:d.trim())||"UpStep Team"}),e.jsx("span",{style:{fontSize:11,color:n.textFaint},children:R(o.createdAt)})]}),e.jsx("p",{style:{fontSize:16,lineHeight:1.6,color:n.textSoft,margin:0},children:o.content})]})}function K({accent:o,p:n,font:t,onDone:d}){const{submit:c}=w(),[s,r]=i.useState(""),[l,h]=i.useState(""),[p,j]=i.useState("GENERAL"),[b,a]=i.useState(!1),[g,y]=i.useState(!1),[k,u]=i.useState("");async function m(){if(!(!s.trim()||b)){a(!0),u("");try{await c(s.trim(),l.trim()||s.trim(),p),y(!0),setTimeout(d,1200)}catch{u("Something went wrong. Please try again.")}finally{a(!1)}}}if(g)return e.jsxs("div",{style:{textAlign:"center",paddingTop:40},children:[e.jsx("div",{style:{fontSize:18,fontWeight:700,color:n.text,marginBottom:6},children:"Submitted"}),e.jsx("div",{style:{fontSize:14,color:n.textFaint},children:"Feedback received. Thank you."})]});const S={width:"100%",border:`1px solid ${n.border}`,borderRadius:12,padding:"10px 12px",fontSize:16,lineHeight:1.6,outline:"none",background:n.bgSoft,color:n.text,fontFamily:t,boxSizing:"border-box"};return e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:10,fontWeight:700,letterSpacing:".08em",color:n.textFaint,marginBottom:8,textTransform:"uppercase"},children:"Type"}),e.jsx("div",{style:{display:"flex",gap:7,marginBottom:16},children:["BUG","FEATURE","GENERAL"].map(x=>e.jsxs("button",{onClick:()=>j(x),style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:"8px 10px",borderRadius:9,fontSize:14,fontWeight:600,cursor:"pointer",background:p===x?o:n.bg,color:p===x?"#fff":n.textSoft,border:`1px solid ${p===x?o:n.border}`,fontFamily:t},children:[E[x].icon,E[x].label]},x))}),e.jsx("div",{style:{fontSize:10,fontWeight:700,letterSpacing:".08em",color:n.textFaint,marginBottom:8,textTransform:"uppercase"},children:"Title"}),e.jsx("input",{value:s,onChange:x=>r(x.target.value),placeholder:"Short summary of the issue or idea",maxLength:200,style:{...S,marginBottom:16,display:"block"}}),e.jsxs("div",{style:{fontSize:10,fontWeight:700,letterSpacing:".08em",color:n.textFaint,marginBottom:8,textTransform:"uppercase"},children:["Description"," ",e.jsx("span",{style:{fontWeight:400,textTransform:"none",letterSpacing:0},children:"(optional)"})]}),e.jsx("textarea",{value:l,onChange:x=>h(x.target.value),placeholder:"Steps to reproduce, expected behaviour, or more context",maxLength:2e3,rows:4,style:{...S,resize:"vertical",marginBottom:16}}),k&&e.jsx("p",{style:{fontSize:14,color:"#d6453d",marginBottom:12},children:k}),e.jsx("button",{onClick:m,disabled:b||!s.trim(),style:{width:"100%",padding:12,background:o,color:"#fff",border:"none",borderRadius:11,fontSize:14,fontWeight:600,cursor:"pointer",opacity:b||!s.trim()?.5:1,fontFamily:t},children:b?"Submitting…":"Submit feedback"})]})}const E={BUG:{label:"Bug",icon:e.jsxs("svg",{width:12,height:12,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:1.8,strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("ellipse",{cx:"8",cy:"10",rx:"3.5",ry:"4.5"}),e.jsx("path",{d:"M8 5.5V4M5.5 6.5 3.5 5M10.5 6.5 12.5 5M4.5 10.5 2.5 10M11.5 10.5 13.5 10"})]})},FEATURE:{label:"Feature",icon:e.jsxs("svg",{width:12,height:12,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:1.8,strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M8 2v1.5M8 12.5V14M2 8h1.5M12.5 8H14M4.1 4.1l1 1M10.9 10.9l1 1M11.9 4.1l-1 1M5.1 10.9l-1 1"}),e.jsx("circle",{cx:"8",cy:"8",r:"2.5"})]})},GENERAL:{label:"General",icon:e.jsx("svg",{width:12,height:12,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:1.8,strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M14 9a2 2 0 0 1-2 2H5L2 14V4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v5z"})})}},J={BUG:"#fdecec",FEATURE:"#e9f0fd"},Q={BUG:"#d6453d",FEATURE:"#3b76d6"};function I({type:o,p:n}){return e.jsx("span",{style:{padding:"2px 8px",borderRadius:9999,fontSize:10.5,fontWeight:700,letterSpacing:".02em",background:J[o]??n.bgSoft,color:Q[o]??n.textSoft},children:o})}const X={OPEN:"#b45309",IN_PROGRESS:"#1d4ed8",DONE:"#15803d",CLOSED:"#6b7280"};function W(){return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,background:"#fff7ed",border:"1px solid #fed7aa",borderRadius:6,padding:"1px 6px",fontSize:10,fontWeight:700,color:"#ea580c"},children:[e.jsx("span",{style:{width:5,height:5,borderRadius:"50%",background:"#ea580c",display:"inline-block"}}),"Pending review"]})}function T({status:o,boardStatus:n,p:t}){const d=(n==null?void 0:n.color)??X[o]??"#9ca3af";return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:5,background:t.bgSoft,border:`1px solid ${t.border}`,borderRadius:6,padding:"2px 8px",fontSize:10,fontWeight:600,color:t.textSoft},children:[e.jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:d,display:"inline-block",flexShrink:0}}),(n==null?void 0:n.name)??o.replace("_"," ")]})}function Z({size:o=16,color:n="currentColor"}){return e.jsx("svg",{width:o,height:o,viewBox:"0 0 24 24",fill:"none",stroke:n,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function U({color:o="currentColor",size:n=11}){return e.jsx("svg",{width:n,height:n,viewBox:"0 0 16 16",fill:"none",stroke:o,strokeWidth:2.2,strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M8 13V3M3 8l5-5 5 5"})})}function R(o){return new Date(o).toLocaleDateString(void 0,{month:"short",day:"numeric"})}exports.FeedbackWidget=G;exports.UpstepProvider=$;exports.useUpstep=w;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),i=require("react"),A=require("./api-BdOCiCLM.js"),D="#D97757",H={bg:"#ffffff",bgSoft:"#f5f5f5",bgHover:"#ededed",text:"#1a1915",textSoft:"#56544d",textFaint:"#9b9890",border:"#e8e6df",overlay:"rgba(26,25,21,.45)"},N={bg:"#000000",bgSoft:"#171717",bgHover:"#262626",text:"#f5f4f0",textSoft:"#b4b1a8",textFaint:"#7d7a72",border:"#33312c",overlay:"rgba(0,0,0,.6)"};function z(){if(typeof document>"u")return!1;const o=document.documentElement;return o.classList.contains("dark")||o.getAttribute("data-theme")==="dark"}function O(o){const[n,t]=i.useState(()=>o==="dark");return i.useEffect(()=>{if(o!=="auto"){t(o==="dark");return}if(t(z()),typeof MutationObserver>"u")return;const d=new MutationObserver(()=>t(z()));return d.observe(document.documentElement,{attributes:!0,attributeFilter:["class","data-theme"]}),()=>d.disconnect()},[o]),n?N:H}const B=i.createContext(null);function $({children:o,...n}){const[t]=i.useState(()=>new A.UpstepApiClient(n)),[d,c]=i.useState([]),[s,r]=i.useState(!1),[l,h]=i.useState(!0);i.useEffect(()=>{t.setUserId(n.userId)},[t,n.userId]),i.useEffect(()=>{t.supportIdentityToken=n.supportIdentityToken,document.querySelectorAll("iframe[data-upstep-support]").forEach(u=>{var m;return(m=u.contentWindow)==null?void 0:m.postMessage({type:"upstep:support:identity",token:n.supportIdentityToken},new URL(t.baseUrl).origin)})},[t,n.supportIdentityToken]);const p=i.useCallback(async()=>{try{const u=await t.listFeedback({sort:"votes",limit:20});c(u.items),h(u.showBranding??!0)}catch{}},[t]);i.useEffect(()=>{p()},[p]);const j=i.useCallback(async(u,m,S)=>{const x={content:m};u.trim()&&(x.title=u.trim()),S!==void 0&&(x.type=S),await t.submitFeedback(x),await p()},[t,p]),b=i.useCallback(async(u,m)=>{try{await t.vote(u,m),await p()}catch{}},[t,p]),a=i.useCallback(u=>t.getItem(u),[t]),g=i.useCallback(()=>r(!0),[]),y=i.useCallback(()=>r(!1),[]),k=i.useCallback(u=>t.setUserId(u),[t]);return e.jsx(B.Provider,{value:{client:t,feedItems:d,loadFeed:p,submit:j,vote:b,getItem:a,isOpen:s,open:g,close:y,identify:k,accentColor:n.accentColor??D,theme:n.theme??"auto",showBranding:l,chat:n.chat!==!1},children:o})}function w(){const o=i.useContext(B);if(!o)throw new Error("useUpstep must be used inside <UpstepProvider>");return o}function G({position:o="bottom-right",accentColor:n,theme:t,hideLauncher:d=!1,chat:c=!0}){const s=w(),r=n??s.accentColor,l=O(t??s.theme),{isOpen:h,open:p,close:j,showBranding:b}=s,[a,g]=i.useState("list"),[y,k]=i.useState(!1);i.useEffect(()=>{let f=!0;if(s.client.chat=s.chat,!s.chat||!c){k(!1);return}return s.client.supportEnabled().then(v=>{f&&k(v)}),()=>{f=!1}},[s.client,s.chat,c]),i.useEffect(()=>{(!s.chat||!c)&&a==="support"&&g("list")},[s.chat,c,a]),i.useEffect(()=>{h&&g(y&&c&&s.chat?"support":"list")},[h,y,c,s.chat]);const[u,m]=i.useState(null),[S,x]=i.useState(!1);i.useEffect(()=>{const f=window.matchMedia("(max-width: 639px)");x(f.matches);const v=P=>x(P.matches);return f.addEventListener("change",v),()=>f.removeEventListener("change",v)},[]);const L={position:"fixed",bottom:24,right:24},C='-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif';function F(){j(),m(null)}function M(f){m(f),g("detail")}return e.jsxs(e.Fragment,{children:[!d&&e.jsxs("button",{"aria-label":"Open help and feedback",onClick:p,style:{...L,zIndex:9998,display:"inline-flex",alignItems:"center",gap:7,background:r,color:"#fff",border:"none",borderRadius:9999,padding:S?"12px":"12px 18px",fontSize:14,fontWeight:600,cursor:"pointer",fontFamily:C,boxShadow:"0 6px 20px rgba(26,25,21,.18)"},children:[e.jsx(Z,{size:16}),!S&&(y&&c&&s.chat?"Help & feedback":"Feedback")]}),h&&e.jsx("div",{onClick:f=>f.target===f.currentTarget&&F(),style:{position:"fixed",inset:0,background:"transparent",zIndex:9999,display:"flex",alignItems:"flex-end",justifyContent:"flex-end",padding:S?"0 12px 80px":"0 24px 88px",fontFamily:C},children:e.jsxs("div",{style:{background:l.bg,border:`1px solid ${l.border}`,borderRadius:20,width:"100%",maxWidth:y&&c&&s.chat?460:440,maxHeight:"calc(100dvh - 112px)",display:"flex",flexDirection:"column",overflow:"hidden",boxShadow:"0 24px 64px rgba(0,0,0,.28)"},children:[y&&c&&s.chat?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:14,padding:"10px 14px",borderBottom:`1px solid ${l.border}`,flexShrink:0},children:[e.jsx("div",{style:{display:"flex",flex:1,gap:4},children:[["support","Support"],["list","Feedback"]].map(([f,v])=>e.jsx("button",{onClick:()=>g(f),style:{flex:1,border:0,borderRadius:8,padding:"9px 12px",background:(a==="support"?f==="support":f==="list")?l.bgSoft:"transparent",color:(a==="support"?f==="support":f==="list")?l.text:l.textSoft,fontSize:14,fontWeight:600,cursor:"pointer"},children:v},f))}),e.jsx("button",{"aria-label":"Close",onClick:F,style:{border:0,background:"transparent",color:l.textSoft,padding:6,cursor:"pointer",fontSize:14},children:"✕"})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"16px 20px",borderBottom:`1px solid ${l.border}`,flexShrink:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[a!=="list"&&e.jsx("button",{onClick:()=>g("list"),style:{background:"none",border:"none",cursor:"pointer",color:r,fontSize:14,fontWeight:600,padding:0},children:"← Back"}),a==="list"&&e.jsx("span",{style:{fontWeight:700,fontSize:16,color:l.text,letterSpacing:"-.01em"},children:"Feedback"}),a==="create"&&e.jsx("span",{style:{fontWeight:700,fontSize:16,color:l.text,letterSpacing:"-.01em"},children:"New feedback"})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[a==="list"&&e.jsx("button",{onClick:()=>g("create"),style:{background:r,color:"#fff",border:"none",borderRadius:20,padding:"6px 14px",fontSize:14,fontWeight:700,cursor:"pointer"},children:"+ New"}),e.jsx("button",{onClick:F,style:{background:l.bgSoft,border:"none",width:28,height:28,borderRadius:8,fontSize:14,cursor:"pointer",color:l.textSoft,display:"flex",alignItems:"center",justifyContent:"center"},children:"✕"})]})]}),e.jsxs("div",{style:{flex:1,overflowY:"auto",padding:a==="support"?0:"16px 20px 24px"},children:[a==="support"&&c&&s.chat&&e.jsx(V,{client:s.client,accentColor:r,theme:l.bg==="#000000"?"dark":"light"}),y&&c&&s.chat&&a!=="support"&&e.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:16},children:a==="list"?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{fontSize:14,fontWeight:600,color:l.text},children:"Feedback & ideas"}),e.jsx("button",{onClick:()=>g("create"),style:{border:0,borderRadius:8,background:r,color:"white",fontSize:14,padding:"7px 10px",cursor:"pointer"},children:"+ New"})]}):e.jsx("button",{onClick:()=>g("list"),style:{border:0,background:"none",padding:0,color:l.textSoft,fontSize:14,cursor:"pointer"},children:"← Back to feedback"})}),a==="list"&&e.jsx(_,{onSelect:M,accent:r,p:l}),a==="detail"&&u&&e.jsx(q,{feedbackId:u,accent:r,p:l,font:C}),a==="create"&&e.jsx(K,{accent:r,p:l,font:C,onDone:()=>g("list")})]}),b&&a!=="support"&&e.jsxs("a",{href:"https://upstep.dev",target:"_blank",rel:"noopener noreferrer",style:{display:"block",textAlign:"center",padding:"8px 0",borderTop:`1px solid ${l.border}`,fontSize:11,color:l.textFaint,textDecoration:"none",flexShrink:0},children:["Powered by"," ",e.jsx("strong",{style:{fontWeight:700},children:"Upstep.dev"})]})]})})]})}function V({client:o,theme:n,accentColor:t}){const d=i.useRef(null);return i.useEffect(()=>{if(d.current)return o.connectSupportFrame(d.current)},[o]),e.jsx("iframe",{ref:d,"data-upstep-support":!0,title:"Customer support",src:o.supportFrameUrl(n,t),style:{color:t,width:"100%",height:"min(560px, calc(100dvh - 168px))",minHeight:300,border:0,display:"block"}})}function _({onSelect:o,accent:n,p:t}){const{feedItems:d,vote:c}=w(),s=d.filter(r=>r.status!=="CLOSED");return s.length?e.jsx(e.Fragment,{children:s.map(r=>{const l=r.userVote==="UP",h=r.title??r.content;return e.jsxs("div",{onClick:()=>o(r.id),style:{display:"flex",gap:12,padding:14,border:`1px solid ${t.border}`,borderRadius:14,marginBottom:10,background:t.bg,cursor:"pointer"},children:[e.jsxs("button",{onClick:p=>{p.stopPropagation(),c(r.id,"UP")},style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:2,minWidth:46,padding:"7px 0",borderRadius:11,cursor:"pointer",flexShrink:0,border:`1px solid ${l?n:t.border}`,background:l?`${n}1a`:t.bgSoft},children:[e.jsx(U,{color:n}),e.jsx("span",{style:{fontSize:14,fontWeight:700,color:t.text,lineHeight:1.1},children:r.upvotes})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("p",{style:{fontSize:14,fontWeight:600,lineHeight:1.4,color:t.text,margin:"0 0 6px",overflow:"hidden",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:h}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[e.jsx(I,{type:r.type,p:t}),r.status==="PENDING"?e.jsx(W,{}):e.jsx(T,{status:r.status,boardStatus:r.boardStatus,p:t}),e.jsx("span",{style:{fontSize:11,color:t.textFaint},children:R(r.createdAt)})]})]}),e.jsx("span",{style:{color:t.textFaint,fontSize:18,alignSelf:"center",flexShrink:0},children:"›"})]},r.id)})}):e.jsxs("div",{style:{textAlign:"center",padding:"40px 0"},children:[e.jsx("div",{style:{color:t.textSoft,fontSize:15,fontWeight:600,marginBottom:4},children:"No open feedback yet"}),e.jsx("div",{style:{color:t.textFaint,fontSize:14},children:"Be the first to share one."})]})}function q({feedbackId:o,accent:n,p:t,font:d}){const{vote:c,getItem:s}=w(),[r,l]=i.useState(null),[h,p]=i.useState(!1);i.useEffect(()=>{let a=!1;return s(o).then(g=>{a||l(g)}).catch(()=>{}),()=>{a=!0}},[o,s]);async function j(){if(!(!r||h)){p(!0);try{await c(r.id,"UP");const a=await s(o);l(a)}catch{}finally{p(!1)}}}if(!r)return e.jsx("div",{style:{textAlign:"center",padding:"40px 0",color:t.textFaint,fontSize:14},children:"Loading…"});const b=r.title;return e.jsxs("div",{children:[b&&e.jsx("div",{style:{fontSize:20,fontWeight:700,color:t.text,letterSpacing:"-.02em",marginBottom:10,lineHeight:1.3},children:b}),e.jsxs("div",{style:{display:"flex",gap:6,marginBottom:14,flexWrap:"wrap"},children:[e.jsx(I,{type:r.type,p:t}),r.status==="PENDING"?e.jsx(W,{}):e.jsx(T,{status:r.status,boardStatus:r.boardStatus,p:t})]}),e.jsx("p",{style:{fontSize:15,lineHeight:1.6,color:t.textSoft,marginBottom:20},children:r.content}),e.jsxs("button",{onClick:j,disabled:h,style:{display:"inline-flex",alignItems:"center",gap:8,border:`1px solid ${r.userVote==="UP"?n:t.border}`,background:r.userVote==="UP"?`${n}15`:t.bgSoft,borderRadius:12,padding:"10px 16px",cursor:"pointer",fontFamily:d},children:[e.jsx(U,{color:n,size:13}),e.jsx("span",{style:{fontSize:18,fontWeight:700,color:t.text},children:r.upvotes}),e.jsx("span",{style:{fontSize:14,color:t.textFaint},children:r.userVote==="UP"?"Upvoted":"Upvote"})]}),r.comments.length>0&&e.jsxs("div",{style:{marginTop:28,borderTop:`1px solid ${t.border}`,paddingTop:20},children:[e.jsx("div",{style:{fontSize:10,fontWeight:700,letterSpacing:".08em",color:t.textFaint,marginBottom:12,textTransform:"uppercase"},children:"Comments"}),r.comments.map(a=>e.jsx(Y,{comment:a,p:t,accent:n},a.id))]})]})}function Y({comment:o,p:n,accent:t}){var d;return e.jsxs("div",{style:{background:n.bgSoft,border:`1px solid ${n.border}`,borderRadius:12,padding:14,marginBottom:10},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:8},children:[e.jsx("span",{style:{background:`${t}20`,color:t,fontSize:11,fontWeight:700,borderRadius:20,padding:"2px 8px"},children:((d=o.authorName)==null?void 0:d.trim())||"UpStep Team"}),e.jsx("span",{style:{fontSize:11,color:n.textFaint},children:R(o.createdAt)})]}),e.jsx("p",{style:{fontSize:16,lineHeight:1.6,color:n.textSoft,margin:0},children:o.content})]})}function K({accent:o,p:n,font:t,onDone:d}){const{submit:c}=w(),[s,r]=i.useState(""),[l,h]=i.useState(""),[p,j]=i.useState("GENERAL"),[b,a]=i.useState(!1),[g,y]=i.useState(!1),[k,u]=i.useState("");async function m(){if(!(!s.trim()||b)){a(!0),u("");try{await c(s.trim(),l.trim()||s.trim(),p),y(!0),setTimeout(d,1200)}catch{u("Something went wrong. Please try again.")}finally{a(!1)}}}if(g)return e.jsxs("div",{style:{textAlign:"center",paddingTop:40},children:[e.jsx("div",{style:{fontSize:18,fontWeight:700,color:n.text,marginBottom:6},children:"Submitted"}),e.jsx("div",{style:{fontSize:14,color:n.textFaint},children:"Feedback received. Thank you."})]});const S={width:"100%",border:`1px solid ${n.border}`,borderRadius:12,padding:"10px 12px",fontSize:16,lineHeight:1.6,outline:"none",background:n.bgSoft,color:n.text,fontFamily:t,boxSizing:"border-box"};return e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:10,fontWeight:700,letterSpacing:".08em",color:n.textFaint,marginBottom:8,textTransform:"uppercase"},children:"Type"}),e.jsx("div",{style:{display:"flex",gap:7,marginBottom:16},children:["BUG","FEATURE","GENERAL"].map(x=>e.jsxs("button",{onClick:()=>j(x),style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:"8px 10px",borderRadius:9,fontSize:14,fontWeight:600,cursor:"pointer",background:p===x?o:n.bg,color:p===x?"#fff":n.textSoft,border:`1px solid ${p===x?o:n.border}`,fontFamily:t},children:[E[x].icon,E[x].label]},x))}),e.jsx("div",{style:{fontSize:10,fontWeight:700,letterSpacing:".08em",color:n.textFaint,marginBottom:8,textTransform:"uppercase"},children:"Title"}),e.jsx("input",{value:s,onChange:x=>r(x.target.value),placeholder:"Short summary of the issue or idea",maxLength:200,style:{...S,marginBottom:16,display:"block"}}),e.jsxs("div",{style:{fontSize:10,fontWeight:700,letterSpacing:".08em",color:n.textFaint,marginBottom:8,textTransform:"uppercase"},children:["Description"," ",e.jsx("span",{style:{fontWeight:400,textTransform:"none",letterSpacing:0},children:"(optional)"})]}),e.jsx("textarea",{value:l,onChange:x=>h(x.target.value),placeholder:"Steps to reproduce, expected behaviour, or more context",maxLength:2e3,rows:4,style:{...S,resize:"vertical",marginBottom:16}}),k&&e.jsx("p",{style:{fontSize:14,color:"#d6453d",marginBottom:12},children:k}),e.jsx("button",{onClick:m,disabled:b||!s.trim(),style:{width:"100%",padding:12,background:o,color:"#fff",border:"none",borderRadius:11,fontSize:14,fontWeight:600,cursor:"pointer",opacity:b||!s.trim()?.5:1,fontFamily:t},children:b?"Submitting…":"Submit feedback"})]})}const E={BUG:{label:"Bug",icon:e.jsxs("svg",{width:12,height:12,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:1.8,strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("ellipse",{cx:"8",cy:"10",rx:"3.5",ry:"4.5"}),e.jsx("path",{d:"M8 5.5V4M5.5 6.5 3.5 5M10.5 6.5 12.5 5M4.5 10.5 2.5 10M11.5 10.5 13.5 10"})]})},FEATURE:{label:"Feature",icon:e.jsxs("svg",{width:12,height:12,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:1.8,strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M8 2v1.5M8 12.5V14M2 8h1.5M12.5 8H14M4.1 4.1l1 1M10.9 10.9l1 1M11.9 4.1l-1 1M5.1 10.9l-1 1"}),e.jsx("circle",{cx:"8",cy:"8",r:"2.5"})]})},GENERAL:{label:"General",icon:e.jsx("svg",{width:12,height:12,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:1.8,strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M14 9a2 2 0 0 1-2 2H5L2 14V4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v5z"})})}},J={BUG:"#fdecec",FEATURE:"#e9f0fd"},Q={BUG:"#d6453d",FEATURE:"#3b76d6"};function I({type:o,p:n}){return e.jsx("span",{style:{padding:"2px 8px",borderRadius:9999,fontSize:10.5,fontWeight:700,letterSpacing:".02em",background:J[o]??n.bgSoft,color:Q[o]??n.textSoft},children:o})}const X={OPEN:"#b45309",IN_PROGRESS:"#1d4ed8",DONE:"#15803d",CLOSED:"#6b7280"};function W(){return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,background:"#fff7ed",border:"1px solid #fed7aa",borderRadius:6,padding:"1px 6px",fontSize:10,fontWeight:700,color:"#ea580c"},children:[e.jsx("span",{style:{width:5,height:5,borderRadius:"50%",background:"#ea580c",display:"inline-block"}}),"Pending review"]})}function T({status:o,boardStatus:n,p:t}){const d=(n==null?void 0:n.color)??X[o]??"#9ca3af";return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:5,background:t.bgSoft,border:`1px solid ${t.border}`,borderRadius:6,padding:"2px 8px",fontSize:10,fontWeight:600,color:t.textSoft},children:[e.jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:d,display:"inline-block",flexShrink:0}}),(n==null?void 0:n.name)??o.replace("_"," ")]})}function Z({size:o=16,color:n="currentColor"}){return e.jsx("svg",{width:o,height:o,viewBox:"0 0 24 24",fill:"none",stroke:n,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function U({color:o="currentColor",size:n=11}){return e.jsx("svg",{width:n,height:n,viewBox:"0 0 16 16",fill:"none",stroke:o,strokeWidth:2.2,strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M8 13V3M3 8l5-5 5 5"})})}function R(o){return new Date(o).toLocaleDateString(void 0,{month:"short",day:"numeric"})}exports.FeedbackWidget=G;exports.UpstepProvider=$;exports.useUpstep=w;
|
package/dist/react.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsxs as d, Fragment as T, jsx as e } from "react/jsx-runtime";
|
|
2
2
|
import { createContext as G, useState as h, useEffect as k, useCallback as F, useContext as O, useRef as j } from "react";
|
|
3
|
-
import { U as V } from "./api-
|
|
3
|
+
import { U as V } from "./api-ZTIiZxlg.mjs";
|
|
4
4
|
const _ = "#D97757", Y = {
|
|
5
5
|
bg: "#ffffff",
|
|
6
6
|
bgSoft: "#f5f5f5",
|
package/dist/support.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function l(a,t){if(t===null)return[];const e=a.filter(n=>n.role!=="SYSTEM"),s=e.findIndex(n=>n.id===t);return s<0?[]:e.slice(s+1).filter(n=>n.role!=="CUSTOMER")}function d(a,t=120){const e=a.replace(/\s+/g," ").trim();return e.length>t?`${e.slice(0,t-1).trimEnd()}…`:e}class c extends Error{constructor(t,e){super(t),this.status=e}}function h(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,a=>{const t=Math.floor(Math.random()*16);return(a==="x"?t:t&3|8).toString(16)})}class y{constructor(t,e,s=fetch){this.storage=e,this.transport=s,this.token=null,this.session=null,this.epoch=0,this.baseUrl=(t.baseUrl||"https://upstep.dev").replace(/\/$/,""),this.key=t.apiKey,this.identityToken=t.supportIdentityToken,this.storageKey=`upstep:support:${this.baseUrl}:${this.key}`,this.seenKey=`upstep:support-seen:${this.baseUrl}:${this.key}`,this.soundKey=`upstep:support-sound:${this.baseUrl}:${this.key}`}async identify(t){var e;t!==this.identityToken&&(this.epoch++,this.identityToken=t,this.token=null,this.session=null,await((e=this.storage)==null?void 0:e.removeItem(this.storageKey).catch(()=>{})))}async request(t,e){var i;const s=new AbortController,n=setTimeout(()=>s.abort(),2e4);try{const o=await this.transport(`${this.baseUrl}/api/sdk/support${t}`,{method:e===void 0?"GET":"POST",headers:{"Content-Type":"application/json","x-api-key":this.key,...this.token?{Authorization:`Bearer ${this.token}`}:{}},...e===void 0?{}:{body:JSON.stringify(e)},credentials:"omit",redirect:"error",signal:s.signal}),r=await o.json();if(!o.ok)throw o.status===401&&t&&(this.token=null,await((i=this.storage)==null?void 0:i.removeItem(this.storageKey).catch(()=>{}))),new c(typeof r.error=="string"?r.error:"Could not connect to support.",o.status);return r}finally{clearTimeout(n)}}async configuration(){try{return await this.request("")}catch(t){if(t instanceof c&&[402,404].includes(t.status))return null;throw t}}async ensureSession(){if(!this.token){if(!this.session){const t=this.epoch,e=this.identityToken,s=(async()=>{var i,o;if(!e)try{const r=await((i=this.storage)==null?void 0:i.getItem(this.storageKey));if(r&&t===this.epoch){this.token=r;return}}catch{}if(t!==this.epoch)throw new Error("Customer identity changed.");const n=await this.request("",e?{identityToken:e}:{});if(t!==this.epoch)throw new Error("Customer identity changed.");this.token=n.token,e||await((o=this.storage)==null?void 0:o.setItem(this.storageKey,n.token).catch(()=>{}))})();this.session=s,s.finally(()=>{this.session===s&&(this.session=null)}).catch(()=>{})}await this.session}}async conversations(){return await this.ensureSession(),(await this.request("/conversations")).conversations}async startConversation(){return await this.ensureSession(),this.request("/conversations",{})}async conversation(t){return await this.ensureSession(),this.request(`/conversations/${encodeURIComponent(t)}`)}async send(t,e,s=h()){await this.ensureSession(),await this.request(`/conversations/${encodeURIComponent(t)}`,{action:"message",content:e,clientMessageId:s})}async details(t,e){await this.ensureSession(),await this.request(`/conversations/${encodeURIComponent(t)}`,{action:"details",...e,clientMessageId:e.clientMessageId||h()})}async handoff(t,e,s){await this.ensureSession(),await this.request(`/conversations/${encodeURIComponent(t)}`,{action:"handoff",name:e,email:s})}async hasSession(){var t;if(this.token||this.identityToken)return!0;try{return!!await((t=this.storage)==null?void 0:t.getItem(this.storageKey))}catch{return!1}}async seenId(t){var e;try{const s=JSON.parse(await((e=this.storage)==null?void 0:e.getItem(this.seenKey))||"null");return(s==null?void 0:s.chat)===t?s.id:null}catch{return null}}async markSeen(t){var n;const e=t.messages.filter(i=>i.role!=="SYSTEM").at(-1);if(!e)return;const s={chat:t.id,id:e.id};await((n=this.storage)==null?void 0:n.setItem(this.seenKey,JSON.stringify(s)).catch(()=>{}))}async unread(){var u;const t={count:0,chatId:null};if(!await this.hasSession())return t;const e=(await this.conversations())[0];if(!e)return t;const s=await this.conversation(e.id);if(!s.messages.filter(p=>p.role!=="SYSTEM").at(-1))return{count:0,chatId:s.id};let i=null;try{i=JSON.parse(await((u=this.storage)==null?void 0:u.getItem(this.seenKey))||"null")}catch{i=null}if((i==null?void 0:i.chat)!==s.id)return await this.markSeen(s),{count:0,chatId:s.id};const o=l(s.messages,i.id),r=o.at(-1);return{count:o.length,chatId:s.id,...r?{latest:{author:r.role==="ASSISTANT"?"AI":r.authorName,role:r.role,preview:d(r.content)}}:{}}}async soundEnabled(){var t;try{return await((t=this.storage)==null?void 0:t.getItem(this.soundKey))!=="off"}catch{return!0}}async setSoundEnabled(t){var e;await((e=this.storage)==null?void 0:e.setItem(this.soundKey,t?"on":"off").catch(()=>{}))}}exports.SupportApiError=c;exports.SupportClient=y;exports.supportMessageId=h;exports.supportPreview=d;exports.unreadSupportMessages=l;
|
package/dist/support.d.ts
CHANGED
|
@@ -4,6 +4,22 @@ export interface SupportStorage {
|
|
|
4
4
|
setItem(key: string, value: string): Promise<void>;
|
|
5
5
|
removeItem(key: string): Promise<void>;
|
|
6
6
|
}
|
|
7
|
+
/** What a customer has not read yet in their latest conversation. */
|
|
8
|
+
export interface SupportUnreadSummary {
|
|
9
|
+
count: number;
|
|
10
|
+
chatId: string | null;
|
|
11
|
+
latest?: {
|
|
12
|
+
author: string;
|
|
13
|
+
role: string;
|
|
14
|
+
preview: string;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/** Incoming AI or team messages after the given message. System notes and the customer's own messages never count. */
|
|
18
|
+
export declare function unreadSupportMessages<T extends {
|
|
19
|
+
id: string;
|
|
20
|
+
role: string;
|
|
21
|
+
}>(messages: T[], seenId: string | null): T[];
|
|
22
|
+
export declare function supportPreview(text: string, max?: number): string;
|
|
7
23
|
export declare class SupportApiError extends Error {
|
|
8
24
|
readonly status: number;
|
|
9
25
|
constructor(message: string, status: number);
|
|
@@ -20,6 +36,8 @@ export declare class SupportClient {
|
|
|
20
36
|
private readonly baseUrl;
|
|
21
37
|
private readonly key;
|
|
22
38
|
private readonly storageKey;
|
|
39
|
+
private readonly seenKey;
|
|
40
|
+
private readonly soundKey;
|
|
23
41
|
constructor(config: Pick<UpstepConfig, "apiKey" | "baseUrl" | "supportIdentityToken">, storage?: SupportStorage | undefined, transport?: typeof fetch);
|
|
24
42
|
identify(token: string | undefined): Promise<void>;
|
|
25
43
|
private request;
|
|
@@ -43,5 +61,18 @@ export declare class SupportClient {
|
|
|
43
61
|
clientMessageId?: string;
|
|
44
62
|
}): Promise<void>;
|
|
45
63
|
handoff(id: string, name: string, email: string): Promise<void>;
|
|
64
|
+
/** True when this customer already has a support session, so checking for replies creates nothing new. */
|
|
65
|
+
hasSession(): Promise<boolean>;
|
|
66
|
+
/** The last message the customer has read in a conversation, if one was recorded. */
|
|
67
|
+
seenId(chatId: string): Promise<string | null>;
|
|
68
|
+
/** Record that the customer has read everything in this conversation. */
|
|
69
|
+
markSeen(conversation: SupportConversation): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Unread AI or team messages in the latest conversation. A conversation with
|
|
72
|
+
* no saved record counts as read, so returning customers never see a stale count.
|
|
73
|
+
*/
|
|
74
|
+
unread(): Promise<SupportUnreadSummary>;
|
|
75
|
+
soundEnabled(): Promise<boolean>;
|
|
76
|
+
setSoundEnabled(enabled: boolean): Promise<void>;
|
|
46
77
|
}
|
|
47
78
|
//# sourceMappingURL=support.d.ts.map
|
package/dist/support.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"support.d.ts","sourceRoot":"","sources":["../src/support.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EACnB,YAAY,EACb,MAAM,eAAe,CAAC;AACvB,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC7C,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnD,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxC;AACD,qBAAa,eAAgB,SAAQ,KAAK;IAGtC,QAAQ,CAAC,MAAM,EAAE,MAAM;gBADvB,OAAO,EAAE,MAAM,EACN,MAAM,EAAE,MAAM;CAI1B;AACD,wBAAgB,gBAAgB,WAK/B;AACD,6EAA6E;AAC7E,qBAAa,aAAa;
|
|
1
|
+
{"version":3,"file":"support.d.ts","sourceRoot":"","sources":["../src/support.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EACnB,YAAY,EACb,MAAM,eAAe,CAAC;AACvB,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC7C,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnD,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxC;AACD,qEAAqE;AACrE,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CAC5D;AAED,sHAAsH;AACtH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAC1E,QAAQ,EAAE,CAAC,EAAE,EACb,MAAM,EAAE,MAAM,GAAG,IAAI,GACpB,CAAC,EAAE,CAML;AACD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,SAAM,UAGrD;AACD,qBAAa,eAAgB,SAAQ,KAAK;IAGtC,QAAQ,CAAC,MAAM,EAAE,MAAM;gBADvB,OAAO,EAAE,MAAM,EACN,MAAM,EAAE,MAAM;CAI1B;AACD,wBAAgB,gBAAgB,WAK/B;AACD,6EAA6E;AAC7E,qBAAa,aAAa;IAYtB,OAAO,CAAC,OAAO,CAAC;IAChB,OAAO,CAAC,SAAS;IAZnB,OAAO,CAAC,KAAK,CAAuB;IACpC,OAAO,CAAC,OAAO,CAA8B;IAC7C,OAAO,CAAC,aAAa,CAAqB;IAC1C,OAAO,CAAC,KAAK,CAAK;IAClB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;gBAEhC,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,QAAQ,GAAG,SAAS,GAAG,sBAAsB,CAAC,EACjE,OAAO,CAAC,EAAE,cAAc,YAAA,EACxB,SAAS,GAAE,OAAO,KAAa;IASnC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS;YAQ1B,OAAO;IAkCf,aAAa,IAAI,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;YAS7C,aAAa;IAsCrB,aAAa;YAG2B,MAAM;eAAS,MAAM;;IAK7D,iBAAiB;YAEK,MAAM;eAAS,MAAM;;IAE3C,YAAY,CAAC,EAAE,EAAE,MAAM;IAMvB,IAAI,CACR,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,MAAM,EACf,eAAe,SAAqB;IAShC,OAAO,CACX,EAAE,EAAE,MAAM,EACV,MAAM,EAAE;QACN,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B;IASG,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAQrD,0GAA0G;IACpG,UAAU;IAQhB,qFAAqF;IAC/E,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAUpD,yEAAyE;IACnE,QAAQ,CAAC,YAAY,EAAE,mBAAmB;IAUhD;;;OAGG;IACG,MAAM,IAAI,OAAO,CAAC,oBAAoB,CAAC;IAkCvC,YAAY;IAOZ,eAAe,CAAC,OAAO,EAAE,OAAO;CAKvC"}
|