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