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