@upstep/js 0.7.2 → 0.9.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 +20 -2
- package/dist/{api-DSXEYv9R.mjs → api-CROQwfAo.mjs} +58 -23
- package/dist/api-j3GMTEE7.js +1 -0
- package/dist/api.d.ts +28 -3
- package/dist/api.d.ts.map +1 -1
- package/dist/index.cjs +52 -43
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +253 -110
- package/dist/react.cjs +1 -1
- package/dist/react.d.ts +14 -2
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +439 -423
- 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/theme.cjs +1 -0
- package/dist/theme.d.ts +76 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +177 -0
- package/dist/upstep.global.js +55 -46
- package/dist/widget.d.ts +31 -1
- package/dist/widget.d.ts.map +1 -1
- package/package.json +7 -2
- package/dist/api-ZqVkOuh0.js +0 -1
package/dist/index.js
CHANGED
|
@@ -1,35 +1,24 @@
|
|
|
1
|
-
import { U as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
overlay: "rgba(26,25,21,.45)"
|
|
11
|
-
}, c = {
|
|
12
|
-
bg: "#000000",
|
|
13
|
-
bgSoft: "#171717",
|
|
14
|
-
bgHover: "#262626",
|
|
15
|
-
text: "#f5f4f0",
|
|
16
|
-
textSoft: "#b4b1a8",
|
|
17
|
-
textFaint: "#7d7a72",
|
|
18
|
-
border: "#33312c",
|
|
19
|
-
overlay: "rgba(0,0,0,.6)"
|
|
20
|
-
};
|
|
21
|
-
function u(o) {
|
|
22
|
-
if (o === "light" || o === "dark") return o;
|
|
1
|
+
import { U as f } from "./api-CROQwfAo.mjs";
|
|
2
|
+
import { buildWidgetPalette as x, scaleRadius as g } from "./theme.js";
|
|
3
|
+
import { readableTextOn as M } from "./theme.js";
|
|
4
|
+
function y(e) {
|
|
5
|
+
const t = e == null ? void 0 : e.trim();
|
|
6
|
+
return t && /^[\w\s,"'.-]{1,200}$/.test(t) ? t : "";
|
|
7
|
+
}
|
|
8
|
+
function m(e) {
|
|
9
|
+
if (e === "light" || e === "dark") return e;
|
|
23
10
|
if (typeof document < "u") {
|
|
24
11
|
const t = document.documentElement;
|
|
25
12
|
return t.classList.contains("dark") || t.getAttribute("data-theme") === "dark" ? "dark" : "light";
|
|
26
13
|
}
|
|
27
14
|
return typeof window < "u" && window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
28
15
|
}
|
|
29
|
-
function
|
|
16
|
+
function v(e, t) {
|
|
17
|
+
const s = "right:24px;left:auto", o = e.accent, a = e.accentText, i = (r) => `${g(r, e.radius)}px`;
|
|
30
18
|
return `
|
|
31
|
-
#upstep-root *{box-sizing:border-box;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif}
|
|
32
|
-
#upstep-btn
|
|
19
|
+
#upstep-root *{box-sizing:border-box;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif}${t ? `
|
|
20
|
+
#upstep-btn,#upstep-btn *,#upstep-backdrop,#upstep-backdrop *,#upstep-toast,#upstep-toast *{font-family:${t}}` : ""}
|
|
21
|
+
#upstep-btn{position:fixed;bottom:24px;${s};z-index:9998;display:inline-flex;align-items:center;gap:7px;background:${o};color:${a};border:none;border-radius:${i(9999)};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
22
|
#upstep-btn svg{width:16px;height:16px;flex-shrink:0}
|
|
34
23
|
#upstep-btn:hover{transform:translateY(-1px);box-shadow:0 8px 26px rgba(26,25,21,.24)}
|
|
35
24
|
@media(max-width:639px){#upstep-btn{padding:12px}#upstep-btn span{display:none}}
|
|
@@ -37,58 +26,88 @@ function x(o, t, e) {
|
|
|
37
26
|
#upstep-backdrop{position:fixed;inset:0;background:transparent;z-index:9999;display:flex;align-items:flex-end;justify-content:flex-end;padding:0 24px 88px;animation:upstep-fade .2s ease}
|
|
38
27
|
@keyframes upstep-fade{from{opacity:0}to{opacity:1}}
|
|
39
28
|
@keyframes upstep-rise{from{opacity:0;transform:translateY(14px)}to{opacity:1;transform:translateY(0)}}
|
|
40
|
-
#upstep-modal{background:${e.bg};border:1px solid ${e.border};border-radius
|
|
29
|
+
#upstep-modal{background:${e.bg};border:1px solid ${e.border};border-radius:${i(20)};width:100%;max-width:440px;max-height:calc(100dvh - 112px);display:flex;flex-direction:column;overflow:hidden;box-shadow:0 24px 64px rgba(0,0,0,.28);animation:upstep-rise .26s cubic-bezier(.16,1,.3,1)}
|
|
41
30
|
#upstep-header{display:flex;align-items:flex-start;justify-content:space-between;padding:20px 20px 0}
|
|
42
31
|
#upstep-header h2{margin:0;font-size:16px;font-weight:700;color:${e.text};letter-spacing:-.01em}
|
|
43
32
|
#upstep-header p{margin:2px 0 0;font-size:14px;color:${e.textFaint}}
|
|
44
|
-
#upstep-close{background:${e.bgSoft};border:none;width:28px;height:28px;border-radius
|
|
33
|
+
#upstep-close{background:${e.bgSoft};border:none;width:28px;height:28px;border-radius:${i(8)};font-size:14px;cursor:pointer;color:${e.textSoft};line-height:1;display:flex;align-items:center;justify-content:center;transition:background .15s}
|
|
45
34
|
#upstep-close:hover{background:${e.bgHover};color:${e.text}}
|
|
46
|
-
#upstep-tabs{display:flex;gap:4px;margin:16px 20px 0;padding:4px;background:${e.bgSoft};border-radius
|
|
47
|
-
.upstep-tab{flex:1;padding:8px;background:none;border:none;border-radius
|
|
35
|
+
#upstep-tabs{display:flex;gap:4px;margin:16px 20px 0;padding:4px;background:${e.bgSoft};border-radius:${i(11)}}
|
|
36
|
+
.upstep-tab{flex:1;padding:8px;background:none;border:none;border-radius:${i(8)};font-size:14px;font-weight:600;color:${e.textSoft};cursor:pointer;transition:all .15s}
|
|
48
37
|
.upstep-mode .upstep-tab.active{background:${e.bgSoft};box-shadow:none}
|
|
49
38
|
.upstep-tab.active{background:${e.bg};color:${e.text};box-shadow:0 1px 3px rgba(0,0,0,.08)}
|
|
50
39
|
#upstep-body{flex:1;overflow-y:auto;padding:18px 20px 22px}
|
|
51
|
-
.upstep-form textarea{width:100%;min-height:104px;border:1px solid ${e.border};border-radius
|
|
40
|
+
.upstep-form textarea{width:100%;min-height:104px;border:1px solid ${e.border};border-radius:${i(12)};padding:12px;font-size:16px;line-height:1.6;resize:vertical;outline:none;background:${e.bgSoft};color:${e.text};transition:border-color .15s}
|
|
52
41
|
.upstep-form textarea::placeholder{color:${e.textFaint}}
|
|
53
42
|
.upstep-form textarea:focus{border-color:${o};background:${e.bg}}
|
|
54
43
|
.upstep-type-row{display:flex;gap:7px;margin:12px 0 4px}
|
|
55
|
-
.upstep-type-btn{flex:1;display:flex;align-items:center;justify-content:center;gap:5px;padding:8px 10px;border-radius
|
|
44
|
+
.upstep-type-btn{flex:1;display:flex;align-items:center;justify-content:center;gap:5px;padding:8px 10px;border-radius:${i(9)};border:1px solid ${e.border};background:${e.bg};color:${e.textSoft};font-size:14px;font-weight:600;cursor:pointer;transition:all .15s}
|
|
56
45
|
.upstep-type-btn svg{width:12px;height:12px;flex-shrink:0}
|
|
57
46
|
.upstep-type-btn:hover{border-color:${e.textFaint}}
|
|
58
|
-
.upstep-type-btn.selected{background:${o};color
|
|
59
|
-
.upstep-submit{width:100%;padding:12px;background:${o};color
|
|
47
|
+
.upstep-type-btn.selected{background:${o};color:${a};border-color:${o}}
|
|
48
|
+
.upstep-submit{width:100%;padding:12px;background:${o};color:${a};border:none;border-radius:${i(11)};font-size:14px;font-weight:600;cursor:pointer;margin-top:14px;transition:filter .15s}
|
|
60
49
|
.upstep-submit:hover{filter:brightness(.94)}
|
|
61
50
|
.upstep-submit:disabled{opacity:.5;cursor:not-allowed}
|
|
62
51
|
#upstep-form-msg{font-size:14px;text-align:center;margin-top:12px;color:${o};font-weight:500}
|
|
63
|
-
.upstep-feedback-item{display:flex;gap:12px;padding:14px;border:1px solid ${e.border};border-radius
|
|
52
|
+
.upstep-feedback-item{display:flex;gap:12px;padding:14px;border:1px solid ${e.border};border-radius:${i(14)};margin-bottom:10px;background:${e.bg};transition:border-color .15s}
|
|
64
53
|
.upstep-feedback-item:hover{border-color:${e.textFaint}}
|
|
65
|
-
.upstep-vote{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;min-width:46px;padding:7px 0;border-radius
|
|
54
|
+
.upstep-vote{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;min-width:46px;padding:7px 0;border-radius:${i(11)};border:1px solid ${e.border};background:${e.bgSoft};cursor:pointer;transition:all .15s}
|
|
66
55
|
.upstep-vote:hover{border-color:${o}}
|
|
67
|
-
.upstep-vote.voted{border-color:${o};background:${
|
|
56
|
+
.upstep-vote.voted{border-color:${o};background:${e.accentTint}}
|
|
68
57
|
.upstep-vote-arrow{font-size:11px;line-height:1;color:${o}}
|
|
69
58
|
.upstep-vote-count{font-size:14px;font-weight:700;color:${e.text};line-height:1.1}
|
|
70
59
|
.upstep-feedback-main{flex:1;min-width:0}
|
|
71
60
|
.upstep-feedback-content{font-size:16px;line-height:1.5;color:${e.text};margin:0 0 8px;word-break:break-word}
|
|
72
61
|
.upstep-feedback-meta{display:flex;align-items:center;gap:7px}
|
|
73
|
-
.upstep-badge{display:inline-flex;align-items:center;padding:2px 8px;border-radius
|
|
62
|
+
.upstep-badge{display:inline-flex;align-items:center;padding:2px 8px;border-radius:${i(9999)};font-size:10.5px;font-weight:700;letter-spacing:.02em}
|
|
74
63
|
.upstep-badge-bug{background:#fdecec;color:#d6453d}
|
|
75
64
|
.upstep-badge-feature{background:#e9f0fd;color:#3b76d6}
|
|
76
65
|
.upstep-badge-general{background:${e.bgSoft};color:${e.textSoft}}
|
|
77
66
|
.upstep-feedback-date{font-size:11px;color:${e.textFaint}}
|
|
67
|
+
#upstep-btn{position:fixed}
|
|
68
|
+
.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)}
|
|
69
|
+
@keyframes upstep-pop{from{transform:scale(.4)}to{transform:scale(1)}}
|
|
70
|
+
#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:${i(14)} ${i(14)} ${i(4)} ${i(14)};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)}
|
|
71
|
+
#upstep-toast b{font-size:12px}
|
|
72
|
+
#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}
|
|
73
|
+
#upstep-toast em{font-style:normal;font-size:11px;font-weight:600;color:${o}}
|
|
74
|
+
@media(prefers-reduced-motion:reduce){.upstep-unread,#upstep-toast{animation:none}}
|
|
78
75
|
.upstep-empty{text-align:center;color:${e.textFaint};font-size:14px;padding:40px 0}
|
|
79
76
|
.upstep-empty strong{display:block;color:${e.textSoft};font-size:15px;margin-bottom:4px}
|
|
80
77
|
`;
|
|
81
78
|
}
|
|
82
|
-
const
|
|
83
|
-
class
|
|
84
|
-
constructor(t,
|
|
85
|
-
this.isOpen = !1, this.tab = "submit", this.feedItems = [], this.selectedType = "GENERAL", this.loading = !1, this.hasSupport = !1, this.disconnectSupport = null, this.
|
|
79
|
+
const k = '<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>';
|
|
80
|
+
class $ {
|
|
81
|
+
constructor(t, s = {}) {
|
|
82
|
+
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.options = s, this.position = "right", this.showLauncher = s.launcher !== !1, this.themeMode = s.theme ?? "auto", this.palette = this.buildPalette(m(this.themeMode));
|
|
83
|
+
}
|
|
84
|
+
buildPalette(t) {
|
|
85
|
+
return x({
|
|
86
|
+
mode: t,
|
|
87
|
+
accentColor: this.options.accentColor,
|
|
88
|
+
colors: this.options.colors,
|
|
89
|
+
radius: this.options.radius
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
get accent() {
|
|
93
|
+
return this.palette.accent;
|
|
94
|
+
}
|
|
95
|
+
supportFrameSrc() {
|
|
96
|
+
return this.client.supportFrameUrl(
|
|
97
|
+
this.palette.dark ? "dark" : "light",
|
|
98
|
+
this.accent,
|
|
99
|
+
{
|
|
100
|
+
colors: this.options.colors,
|
|
101
|
+
radius: this.options.radius,
|
|
102
|
+
fontFamily: this.options.fontFamily
|
|
103
|
+
}
|
|
104
|
+
);
|
|
86
105
|
}
|
|
87
106
|
mount() {
|
|
88
107
|
this.injectStyles(), this.showLauncher && this.renderButton(), this.client.supportEnabled().then((t) => {
|
|
89
108
|
if (this.hasSupport = t, t) {
|
|
90
|
-
const
|
|
91
|
-
|
|
109
|
+
const s = document.querySelector("#upstep-btn span");
|
|
110
|
+
s && (s.textContent = "Help & feedback"), this.isOpen ? this.renderModal() : this.hasOpenedSupport() && this.preloadSupport();
|
|
92
111
|
}
|
|
93
112
|
});
|
|
94
113
|
}
|
|
@@ -100,24 +119,126 @@ class g {
|
|
|
100
119
|
closeWidget() {
|
|
101
120
|
this.closeModal();
|
|
102
121
|
}
|
|
122
|
+
/** Whether the chat window is currently on screen. */
|
|
123
|
+
isChatVisible() {
|
|
124
|
+
return this.isOpen;
|
|
125
|
+
}
|
|
126
|
+
/** Number of unread support messages. Subscribe to drive your own launcher or badge. */
|
|
127
|
+
onUnread(t) {
|
|
128
|
+
return this.unreadListeners.add(t), t(this.unread), () => {
|
|
129
|
+
this.unreadListeners.delete(t);
|
|
130
|
+
};
|
|
131
|
+
}
|
|
103
132
|
injectStyles() {
|
|
104
|
-
var
|
|
105
|
-
(
|
|
133
|
+
var s;
|
|
134
|
+
(s = document.getElementById("upstep-styles")) == null || s.remove();
|
|
106
135
|
const t = document.createElement("style");
|
|
107
|
-
t.id = "upstep-styles", t.textContent =
|
|
136
|
+
t.id = "upstep-styles", t.textContent = v(
|
|
137
|
+
this.palette,
|
|
138
|
+
y(this.options.fontFamily)
|
|
139
|
+
), document.head.appendChild(t);
|
|
108
140
|
}
|
|
109
141
|
renderButton() {
|
|
110
142
|
const t = document.createElement("button");
|
|
111
|
-
t.id = "upstep-btn", t.setAttribute("aria-label", "Open help and feedback"), t.innerHTML = `${
|
|
143
|
+
t.id = "upstep-btn", t.setAttribute("aria-label", "Open help and feedback"), t.innerHTML = `${k}<span>Feedback</span>`, t.addEventListener("click", () => {
|
|
112
144
|
this.openModal();
|
|
113
145
|
}), document.body.appendChild(t);
|
|
114
146
|
}
|
|
147
|
+
supportFrame() {
|
|
148
|
+
return document.querySelector("#upstep-support-frame");
|
|
149
|
+
}
|
|
150
|
+
get usedKey() {
|
|
151
|
+
return `upstep:support-opened:${this.client.baseUrl}`;
|
|
152
|
+
}
|
|
153
|
+
hasOpenedSupport() {
|
|
154
|
+
try {
|
|
155
|
+
return localStorage.getItem(this.usedKey) === "1";
|
|
156
|
+
} catch {
|
|
157
|
+
return !1;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
preloadSupport() {
|
|
161
|
+
this.tab = "support", this.renderModal(!0);
|
|
162
|
+
}
|
|
115
163
|
openModal() {
|
|
116
|
-
|
|
164
|
+
if (this.unlockAudio(), !this.isOpen && this.hasSupport) {
|
|
165
|
+
this.tab = "support";
|
|
166
|
+
try {
|
|
167
|
+
localStorage.setItem(this.usedKey, "1");
|
|
168
|
+
} catch {
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
const t = m(this.themeMode), s = document.getElementById("upstep-backdrop"), o = this.supportFrame();
|
|
172
|
+
if (!this.isOpen && s && o && s.style.display === "none" && this.frameTheme === t) {
|
|
173
|
+
this.isOpen = !0, s.style.display = "", this.client.notifySupportVisibility(o, !0), this.setUnread(0), this.fetchFeed();
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
this.isOpen = !0, this.palette = this.buildPalette(t), this.injectStyles(), this.fetchFeed(), this.renderModal(), this.setUnread(0);
|
|
117
177
|
}
|
|
118
178
|
closeModal() {
|
|
119
|
-
var t,
|
|
120
|
-
|
|
179
|
+
var t, s;
|
|
180
|
+
if (this.isOpen = !1, this.hasSupport) {
|
|
181
|
+
const o = this.supportFrame(), a = document.getElementById("upstep-backdrop");
|
|
182
|
+
o && a ? (a.style.display = "none", this.client.notifySupportVisibility(o, !1)) : this.preloadSupport();
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
(t = this.disconnectSupport) == null || t.call(this), this.disconnectSupport = null, (s = document.getElementById("upstep-backdrop")) == null || s.remove();
|
|
186
|
+
}
|
|
187
|
+
setUnread(t) {
|
|
188
|
+
this.unread = t;
|
|
189
|
+
const s = document.getElementById("upstep-btn"), o = s == null ? void 0 : s.querySelector(".upstep-unread");
|
|
190
|
+
if (s) {
|
|
191
|
+
if (t > 0) {
|
|
192
|
+
const i = o ?? document.createElement("span");
|
|
193
|
+
i.className = "upstep-unread", i.textContent = t > 9 ? "9+" : String(t), o || s.appendChild(i);
|
|
194
|
+
} else o == null || o.remove();
|
|
195
|
+
s.setAttribute(
|
|
196
|
+
"aria-label",
|
|
197
|
+
t > 0 ? `Open help and feedback, ${t} unread ${t === 1 ? "message" : "messages"}` : "Open help and feedback"
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
const a = document.title.replace(/^\(\d+\)\s/, "");
|
|
201
|
+
document.title = t > 0 ? `(${t}) ${a}` : a, t === 0 && this.hideToast(), this.unreadListeners.forEach((i) => i(t));
|
|
202
|
+
}
|
|
203
|
+
onSupportUnread(t) {
|
|
204
|
+
if (this.isOpen) return this.setUnread(0);
|
|
205
|
+
this.setUnread(t.count), t.newMessage && t.count > 0 && (this.showToast(t), t.sound && this.chime());
|
|
206
|
+
}
|
|
207
|
+
showToast(t) {
|
|
208
|
+
this.hideToast();
|
|
209
|
+
const s = document.createElement("button");
|
|
210
|
+
s.id = "upstep-toast", s.type = "button", s.setAttribute("role", "status");
|
|
211
|
+
const o = document.createElement("b");
|
|
212
|
+
o.textContent = t.author || "New message";
|
|
213
|
+
const a = document.createElement("span");
|
|
214
|
+
a.textContent = t.preview;
|
|
215
|
+
const i = document.createElement("em");
|
|
216
|
+
i.textContent = t.count > 1 ? `${t.count} new messages` : "Tap to reply", s.append(o, a, i), s.addEventListener("click", () => this.openModal()), document.body.appendChild(s), this.toastTimer = setTimeout(() => this.hideToast(), 9e3);
|
|
217
|
+
}
|
|
218
|
+
hideToast() {
|
|
219
|
+
var t;
|
|
220
|
+
clearTimeout(this.toastTimer), (t = document.getElementById("upstep-toast")) == null || t.remove();
|
|
221
|
+
}
|
|
222
|
+
/** Browsers only allow sound after a click, so prepare audio when the chat is first opened. */
|
|
223
|
+
unlockAudio() {
|
|
224
|
+
try {
|
|
225
|
+
const t = window.AudioContext || window.webkitAudioContext;
|
|
226
|
+
if (!t) return;
|
|
227
|
+
this.audio = this.audio ?? new t(), this.audio.state === "suspended" && this.audio.resume();
|
|
228
|
+
} catch {
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
chime() {
|
|
232
|
+
const t = this.audio;
|
|
233
|
+
if (!t || t.state !== "running") return;
|
|
234
|
+
const s = t.currentTime;
|
|
235
|
+
for (const [o, a] of [
|
|
236
|
+
[880, 0],
|
|
237
|
+
[1318, 0.12]
|
|
238
|
+
]) {
|
|
239
|
+
const i = t.createOscillator(), r = t.createGain();
|
|
240
|
+
i.type = "sine", i.frequency.value = o, r.gain.setValueAtTime(1e-4, s + a), r.gain.exponentialRampToValueAtTime(0.14, s + a + 0.02), r.gain.exponentialRampToValueAtTime(1e-4, s + a + 0.5), i.connect(r), r.connect(t.destination), i.start(s + a), i.stop(s + a + 0.55);
|
|
241
|
+
}
|
|
121
242
|
}
|
|
122
243
|
async fetchFeed() {
|
|
123
244
|
try {
|
|
@@ -126,35 +247,38 @@ class g {
|
|
|
126
247
|
} catch {
|
|
127
248
|
}
|
|
128
249
|
}
|
|
129
|
-
renderModal() {
|
|
130
|
-
var
|
|
131
|
-
(
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}),
|
|
250
|
+
renderModal(t = !1) {
|
|
251
|
+
var a, i, r;
|
|
252
|
+
(a = this.disconnectSupport) == null || a.call(this), this.disconnectSupport = null;
|
|
253
|
+
const s = document.createElement("div");
|
|
254
|
+
s.id = "upstep-backdrop", s.addEventListener("click", (n) => {
|
|
255
|
+
n.target === s && this.closeModal();
|
|
256
|
+
}), s.innerHTML = `
|
|
136
257
|
<div id="upstep-modal" style="max-width:${this.hasSupport ? "460px" : "440px"}">
|
|
137
258
|
${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
259
|
<div id="upstep-body" style="${this.tab === "support" ? "padding:0;overflow:hidden" : ""}">
|
|
139
|
-
${this.tab === "support" ? `<iframe id="upstep-support-frame" title="Customer support" src="${this.
|
|
260
|
+
${this.tab === "support" ? `<iframe id="upstep-support-frame" title="Customer support" src="${c(this.supportFrameSrc())}" 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
261
|
</div>
|
|
141
262
|
</div>
|
|
142
|
-
`, (
|
|
143
|
-
|
|
144
|
-
this.tab =
|
|
263
|
+
`, (i = document.getElementById("upstep-backdrop")) == null || i.remove(), t && (s.style.display = "none"), document.body.appendChild(s), (r = s.querySelector("#upstep-close")) == null || r.addEventListener("click", () => this.closeModal()), s.querySelectorAll(".upstep-tab").forEach((n) => {
|
|
264
|
+
n.addEventListener("click", () => {
|
|
265
|
+
this.tab = n.dataset.tab, this.renderModal();
|
|
145
266
|
});
|
|
146
267
|
});
|
|
147
|
-
const
|
|
268
|
+
const o = s.querySelector(
|
|
148
269
|
"#upstep-support-frame"
|
|
149
270
|
);
|
|
150
|
-
|
|
271
|
+
o && (o.style.color = this.accent, this.frameTheme = this.palette.dark ? "dark" : "light", this.disconnectSupport = this.client.connectSupportFrame(o, {
|
|
272
|
+
isVisible: () => this.isOpen,
|
|
273
|
+
onUnread: (n) => this.onSupportUnread(n)
|
|
274
|
+
})), this.bindSubmitForm(), this.bindVoteButtons();
|
|
151
275
|
}
|
|
152
276
|
renderSubmitForm() {
|
|
153
|
-
const t = ["BUG", "FEATURE", "GENERAL"],
|
|
277
|
+
const t = ["BUG", "FEATURE", "GENERAL"], s = {
|
|
154
278
|
BUG: "Bug",
|
|
155
279
|
FEATURE: "Feature",
|
|
156
280
|
GENERAL: "General"
|
|
157
|
-
},
|
|
281
|
+
}, o = {
|
|
158
282
|
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
283
|
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
284
|
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 +287,7 @@ class g {
|
|
|
163
287
|
<div class="upstep-form">
|
|
164
288
|
<textarea id="upstep-textarea" placeholder="What's on your mind?" maxlength="2000"></textarea>
|
|
165
289
|
<div class="upstep-type-row">
|
|
166
|
-
${t.map((
|
|
290
|
+
${t.map((a) => `<button class="upstep-type-btn${this.selectedType === a ? " selected" : ""}" data-type="${a}">${o[a]}${s[a]}</button>`).join("")}
|
|
167
291
|
</div>
|
|
168
292
|
<button class="upstep-submit" id="upstep-submit-btn">Send feedback</button>
|
|
169
293
|
<div id="upstep-form-msg"></div>
|
|
@@ -173,7 +297,7 @@ class g {
|
|
|
173
297
|
renderFeed() {
|
|
174
298
|
return this.feedItems.length ? this.feedItems.map(
|
|
175
299
|
(t) => {
|
|
176
|
-
var
|
|
300
|
+
var s;
|
|
177
301
|
return `
|
|
178
302
|
<div class="upstep-feedback-item" data-id="${t.id}">
|
|
179
303
|
<button class="upstep-vote${t.userVote === "UP" ? " voted" : ""}" data-vote="UP" data-feedback="${t.id}">
|
|
@@ -181,10 +305,10 @@ class g {
|
|
|
181
305
|
<span class="upstep-vote-count">${t.upvotes}</span>
|
|
182
306
|
</button>
|
|
183
307
|
<div class="upstep-feedback-main">
|
|
184
|
-
<p class="upstep-feedback-content">${
|
|
308
|
+
<p class="upstep-feedback-content">${c(t.content)}</p>
|
|
185
309
|
<div class="upstep-feedback-meta">
|
|
186
310
|
<span class="upstep-badge upstep-badge-${t.type.toLowerCase()}">${t.type}</span>
|
|
187
|
-
<span class="upstep-badge upstep-badge-general">${
|
|
311
|
+
<span class="upstep-badge upstep-badge-general">${c(((s = t.boardStatus) == null ? void 0 : s.name) ?? t.status.replace("_", " "))}</span>
|
|
188
312
|
<span class="upstep-feedback-date">${new Date(t.createdAt).toLocaleDateString()}</span>
|
|
189
313
|
</div>
|
|
190
314
|
</div>
|
|
@@ -198,29 +322,29 @@ class g {
|
|
|
198
322
|
}
|
|
199
323
|
bindSubmitForm() {
|
|
200
324
|
var t;
|
|
201
|
-
document.querySelectorAll(".upstep-type-btn").forEach((
|
|
202
|
-
|
|
203
|
-
this.selectedType =
|
|
325
|
+
document.querySelectorAll(".upstep-type-btn").forEach((s) => {
|
|
326
|
+
s.addEventListener("click", () => {
|
|
327
|
+
this.selectedType = s.dataset.type, document.querySelectorAll(".upstep-type-btn").forEach((o) => o.classList.remove("selected")), s.classList.add("selected");
|
|
204
328
|
});
|
|
205
329
|
}), (t = document.getElementById("upstep-submit-btn")) == null || t.addEventListener("click", async () => {
|
|
206
|
-
const
|
|
330
|
+
const s = document.getElementById(
|
|
207
331
|
"upstep-textarea"
|
|
208
|
-
),
|
|
332
|
+
), o = document.getElementById("upstep-form-msg"), a = document.getElementById(
|
|
209
333
|
"upstep-submit-btn"
|
|
210
334
|
);
|
|
211
|
-
if (!
|
|
212
|
-
const
|
|
213
|
-
if (
|
|
214
|
-
this.loading = !0,
|
|
335
|
+
if (!s || this.loading) return;
|
|
336
|
+
const i = s.value.trim();
|
|
337
|
+
if (i) {
|
|
338
|
+
this.loading = !0, a && (a.disabled = !0, a.textContent = "Sending…");
|
|
215
339
|
try {
|
|
216
340
|
await this.client.submitFeedback({
|
|
217
|
-
content:
|
|
341
|
+
content: i,
|
|
218
342
|
type: this.selectedType
|
|
219
|
-
}),
|
|
343
|
+
}), s.value = "", o && (o.textContent = "Feedback received. Thank you."), await this.fetchFeed();
|
|
220
344
|
} catch {
|
|
221
|
-
|
|
345
|
+
o && (o.textContent = "Something went wrong. Please try again.");
|
|
222
346
|
} finally {
|
|
223
|
-
this.loading = !1,
|
|
347
|
+
this.loading = !1, a && (a.disabled = !1, a.textContent = "Send feedback");
|
|
224
348
|
}
|
|
225
349
|
}
|
|
226
350
|
});
|
|
@@ -228,63 +352,82 @@ class g {
|
|
|
228
352
|
bindVoteButtons() {
|
|
229
353
|
document.querySelectorAll(".upstep-vote").forEach((t) => {
|
|
230
354
|
t.addEventListener("click", async () => {
|
|
231
|
-
const
|
|
355
|
+
const s = t.dataset.feedback;
|
|
232
356
|
try {
|
|
233
|
-
await this.client.vote(
|
|
357
|
+
await this.client.vote(s, "UP"), await this.fetchFeed();
|
|
234
358
|
} catch {
|
|
235
359
|
}
|
|
236
360
|
});
|
|
237
361
|
});
|
|
238
362
|
}
|
|
239
363
|
}
|
|
240
|
-
function
|
|
241
|
-
return
|
|
364
|
+
function c(e) {
|
|
365
|
+
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
242
366
|
}
|
|
243
|
-
let
|
|
244
|
-
const
|
|
245
|
-
init(
|
|
246
|
-
if (
|
|
367
|
+
let d = null, p = null;
|
|
368
|
+
const w = {
|
|
369
|
+
init(e) {
|
|
370
|
+
if (d = new f(e), typeof window < "u") {
|
|
247
371
|
const t = {};
|
|
248
|
-
|
|
249
|
-
const
|
|
250
|
-
|
|
372
|
+
e.accentColor !== void 0 && (t.accentColor = e.accentColor), e.position !== void 0 && (t.position = e.position), e.theme !== void 0 && (t.theme = e.theme), e.launcher !== void 0 && (t.launcher = e.launcher), e.colors !== void 0 && (t.colors = e.colors), e.radius !== void 0 && (t.radius = e.radius), e.fontFamily !== void 0 && (t.fontFamily = e.fontFamily);
|
|
373
|
+
const s = () => {
|
|
374
|
+
p = new $(d, t), p.mount();
|
|
251
375
|
};
|
|
252
|
-
document.readyState === "loading" ? document.addEventListener("DOMContentLoaded",
|
|
376
|
+
document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", s) : s();
|
|
253
377
|
}
|
|
254
|
-
return
|
|
378
|
+
return d;
|
|
255
379
|
},
|
|
256
380
|
/** Open the feedback widget — use this to trigger it from your own UI. */
|
|
257
381
|
open() {
|
|
258
|
-
|
|
382
|
+
p == null || p.openWidget();
|
|
259
383
|
},
|
|
260
384
|
/** Close the feedback widget. */
|
|
261
385
|
close() {
|
|
262
|
-
|
|
386
|
+
p == null || p.closeWidget();
|
|
263
387
|
},
|
|
264
388
|
/** Set / update the end-user id at runtime (e.g. after the user logs in). */
|
|
265
|
-
identify(
|
|
266
|
-
|
|
389
|
+
identify(e) {
|
|
390
|
+
d == null || d.setUserId(e);
|
|
267
391
|
},
|
|
268
392
|
/** Change or clear verified support identity after login/logout. */
|
|
269
|
-
identifySupport(
|
|
270
|
-
var
|
|
271
|
-
|
|
393
|
+
identifySupport(e) {
|
|
394
|
+
var s;
|
|
395
|
+
d && (d.supportIdentityToken = e);
|
|
272
396
|
const t = document.querySelector("#upstep-support-frame");
|
|
273
|
-
t &&
|
|
397
|
+
t && d && ((s = t.contentWindow) == null || s.postMessage({ type: "upstep:support:identity", token: e, visible: (p == null ? void 0 : p.isChatVisible()) ?? !0 }, new URL(d.baseUrl).origin));
|
|
398
|
+
},
|
|
399
|
+
/** Subscribe to the number of unread support messages, e.g. to drive your own launcher badge. */
|
|
400
|
+
onUnread(e) {
|
|
401
|
+
return (p == null ? void 0 : p.onUnread(e)) ?? (() => {
|
|
402
|
+
});
|
|
274
403
|
},
|
|
275
404
|
get client() {
|
|
276
|
-
if (!
|
|
277
|
-
return
|
|
405
|
+
if (!d) throw new Error("Upstep.init() must be called first");
|
|
406
|
+
return d;
|
|
278
407
|
}
|
|
279
408
|
};
|
|
280
409
|
if (typeof document < "u") {
|
|
281
|
-
const
|
|
410
|
+
const e = document.currentScript, t = e == null ? void 0 : e.dataset.apiKey, s = e == null ? void 0 : e.dataset.userId, o = e == null ? void 0 : e.dataset.baseUrl, a = e == null ? void 0 : e.dataset.accentColor, i = e == null ? void 0 : e.dataset.position, r = e == null ? void 0 : e.dataset.theme;
|
|
282
411
|
if (t) {
|
|
283
|
-
const
|
|
284
|
-
|
|
412
|
+
const n = { apiKey: t };
|
|
413
|
+
s && (n.userId = s), (e == null ? void 0 : e.dataset.chat) !== void 0 && (n.chat = e.dataset.chat !== "false"), o && (n.baseUrl = o), a && (n.accentColor = a), (i === "left" || i === "right") && (n.position = i), (r === "light" || r === "dark" || r === "auto") && (n.theme = r);
|
|
414
|
+
const h = e == null ? void 0 : e.dataset.colors;
|
|
415
|
+
if (h)
|
|
416
|
+
try {
|
|
417
|
+
const u = JSON.parse(h);
|
|
418
|
+
u && typeof u == "object" && (n.colors = u);
|
|
419
|
+
} catch {
|
|
420
|
+
console.warn("Upstep: data-colors must be JSON");
|
|
421
|
+
}
|
|
422
|
+
const l = e == null ? void 0 : e.dataset.radius;
|
|
423
|
+
l && Number.isFinite(Number(l)) && (n.radius = Number(l));
|
|
424
|
+
const b = e == null ? void 0 : e.dataset.fontFamily;
|
|
425
|
+
b && (n.fontFamily = b), w.init(n);
|
|
285
426
|
}
|
|
286
427
|
}
|
|
287
428
|
export {
|
|
288
|
-
|
|
289
|
-
|
|
429
|
+
f as UpstepApiClient,
|
|
430
|
+
x as buildWidgetPalette,
|
|
431
|
+
w as default,
|
|
432
|
+
M as readableTextOn
|
|
290
433
|
};
|