@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/upstep.global.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
(function(){"use strict";const u="upstep-anonymous-id";function
|
|
2
|
-
#upstep-root *{box-sizing:border-box;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif}
|
|
3
|
-
#upstep-btn
|
|
1
|
+
(function(){"use strict";const L="#C9481F",A="#FF7A50";function x(e){return e==="dark"?A:L}const y=12,O=32,z=/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i,f="(\\d{1,3}(?:\\.\\d+)?)",k="(\\d*\\.?\\d+%?)",N=new RegExp(`^rgba?\\(\\s*${f}\\s*(?:,\\s*${f}\\s*,\\s*${f}\\s*(?:,\\s*${k}\\s*)?|\\s+${f}\\s+${f}\\s*(?:\\/\\s*${k}\\s*)?)\\)$`,"i");function b(e){if(typeof e!="string"||e.length>64)return null;const t=e.trim();if(z.test(t)){let u=t.slice(1);u.length<=4&&(u=u.split("").map(l=>l+l).join(""));const h=l=>parseInt(u.slice(l,l+2),16);return[h(0),h(2),h(4),u.length===8?Math.round(h(6)/255*1e3)/1e3:1]}const s=N.exec(t);if(!s)return null;const[o,i,n,a]=[s[1],s[2]??s[5],s[3]??s[6],s[4]??s[7]],r=[o,i,n].map(Number);if(r.some(u=>!(u>=0&&u<=255)))return null;let c=1;return a!==void 0&&(c=a.endsWith("%")?Number(a.slice(0,-1))/100:Number(a),!(c>=0&&c<=1))?null:[r[0],r[1],r[2],c]}function R(e){return b(e)!==null}function $([e,t,s,o]){const i=n=>Math.round(Math.min(255,Math.max(0,n))).toString(16).padStart(2,"0");return`#${i(e)}${i(t)}${i(s)}${o<1?i(o*255):""}`}function B(e,t,s){const o=b(e),i=b(t);if(!o||!i)return null;const n=Math.min(1,Math.max(0,s));return $([o[0]+(i[0]-o[0])*n,o[1]+(i[1]-o[1])*n,o[2]+(i[2]-o[2])*n,o[3]+(i[3]-o[3])*n])}function j(e,t){const s=b(e);return s?$([s[0],s[1],s[2],s[3]*t]):null}function v([e,t,s]){const o=i=>{const n=i/255;return n<=.03928?n/12.92:((n+.055)/1.055)**2.4};return .2126*o(e)+.7152*o(t)+.0722*o(s)}function w(e,t){const s=b(e),o=b(t);if(!s||!o)return null;const[i,n]=[v(s),v(o)].sort((a,r)=>r-a);return(i+.05)/(n+.05)}const m="#ffffff",S="#1a1915";function H(e){const t=w(e,m);return t===null||t>=3?m:(w(e,S)??0)>t?S:m}function I(e){const t=typeof e=="number"?e:Number(e);return e==null||e===""||!Number.isFinite(t)?y:Math.round(Math.min(O,Math.max(0,t)))}function V(e,t){return Math.round(e*t/y)}const E=["background","surface","border","text","textMuted","accentText"];function U(e,t){const s={};if(!e)return s;for(const o of[e,e[t]])if(o)for(const i of E){const n=o[i];typeof n=="string"&&n.trim()&&(s[i]=n.trim())}return s}const q={bg:"#ffffff",bgSoft:"#f5f5f5",bgHover:"#ededed",text:"#1a1915",textSoft:"#56544d",textFaint:"#9b9890",border:"#e8e6df",overlay:"rgba(26,25,21,.45)"},D={bg:"#000000",bgSoft:"#171717",bgHover:"#262626",text:"#f5f4f0",textSoft:"#b4b1a8",textFaint:"#7d7a72",border:"#33312c",overlay:"rgba(0,0,0,.6)"};function F(e,t,s){return B(e,t,s)??`color-mix(in srgb, ${e} ${Math.round((1-s)*100)}%, ${t})`}function P(e){var r;const t=e.mode==="dark"?D:q,s=U(e.colors,e.mode),o=((r=e.accentColor)==null?void 0:r.trim())||x(e.mode),i=s.background??t.bg,n=s.text??t.text,a=s.surface??t.bgSoft;return{dark:e.mode==="dark",bg:i,bgSoft:a,bgHover:s.surface||s.text?F(a,n,.06):t.bgHover,text:n,textSoft:s.textMuted??t.textSoft,textFaint:s.textMuted||s.background?F(s.textMuted??t.textSoft,i,.4):t.textFaint,border:s.border??t.border,overlay:t.overlay,accent:o,accentText:s.accentText??H(o),accentTint:j(o,.1)??`color-mix(in srgb, ${o} 10%, transparent)`,radius:I(e.radius)}}function G(e){var i;const t=U(e.colors,e.mode),s={},o={background:"bg",surface:"surface",border:"border",text:"text",textMuted:"muted",accentText:"accentText"};for(const n of E){const a=t[n];R(a)&&(s[o[n]]=a)}return e.radius!==void 0&&(s.radius=String(I(e.radius))),(i=e.fontFamily)!=null&&i.trim()&&(s.font=e.fontFamily.trim()),s}const M="upstep-anonymous-id";function K(){const e=typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;if(typeof window>"u")return e;try{const t=window.localStorage.getItem(M);return t||(window.localStorage.setItem(M,e),e)}catch{return e}}class W{constructor(t){this.baseUrl=(t.baseUrl??"https://upstep.dev").replace(/\/$/,""),this.apiKey=t.apiKey,this.supportIdentityToken=t.supportIdentityToken,this.chat=t.chat!==!1,t.userId!==void 0&&(this.userId=t.userId),this.anonymousId=K()}setUserId(t){this.userId=t}headers(){return{"Content-Type":"application/json","x-api-key":this.apiKey}}async supportEnabled(){if(!this.chat)return!1;try{const t=await fetch(`${this.baseUrl}/api/sdk/support`,{headers:this.headers()});return t.ok&&(await t.json()).enabled===!0}catch{return!1}}supportFrameUrl(t,s,o={}){const i=new URLSearchParams({theme:t,accent:s||x(t==="dark"?"dark":"light")}),n=G({mode:t==="dark"?"dark":"light",...o});for(const[a,r]of Object.entries(n))i.set(a,r);return`${this.baseUrl}/support/${encodeURIComponent(this.apiKey)}?${i}`}connectSupportFrame(t,s={}){const o=new URL(this.baseUrl).origin,i=()=>{var a;return(a=t.contentWindow)==null?void 0:a.postMessage({type:"upstep:support:identity",token:this.supportIdentityToken,accentColor:getComputedStyle(t).color,...s.isVisible?{visible:s.isVisible()}:{}},o)},n=a=>{if(a.origin!==o||a.source!==t.contentWindow)return;const r=a.data;if((r==null?void 0:r.type)==="upstep:support:ready")i();else if((r==null?void 0:r.type)==="upstep:support:unread"&&s.onUnread){const c=Number(r.count);s.onUnread({count:Number.isFinite(c)?Math.max(0,Math.floor(c)):0,newMessage:r.newMessage===!0,author:String(r.author??"").slice(0,80),preview:String(r.preview??"").slice(0,200),sound:r.sound!==!1})}};return t.addEventListener("load",i),window.addEventListener("message",n),()=>{t.removeEventListener("load",i),window.removeEventListener("message",n)}}notifySupportVisibility(t,s){var o;(o=t.contentWindow)==null||o.postMessage({type:"upstep:support:visible",visible:s},new URL(this.baseUrl).origin)}async listFeedback(t){const s=new URLSearchParams;t!=null&&t.cursor&&s.set("cursor",t.cursor),t!=null&&t.limit&&s.set("limit",String(t.limit)),t!=null&&t.type&&s.set("type",t.type),t!=null&&t.status&&s.set("status",t.status),t!=null&&t.sort&&s.set("sort",t.sort),this.userId&&s.set("endUserId",this.userId),this.anonymousId&&s.set("anonymousId",this.anonymousId);const o=await fetch(`${this.baseUrl}/api/sdk/feedback?${s}`,{headers:this.headers()});if(!o.ok)throw new Error(`Upstep: ${o.status}`);return o.json()}async submitFeedback(t){const s=await fetch(`${this.baseUrl}/api/sdk/feedback`,{method:"POST",headers:this.headers(),body:JSON.stringify({...t,endUserId:t.endUserId??this.userId,anonymousId:t.anonymousId??this.anonymousId})});if(!s.ok)throw new Error(`Upstep: ${s.status}`);return s.json()}async vote(t,s){const o=await fetch(`${this.baseUrl}/api/sdk/feedback/${t}/vote`,{method:"POST",headers:this.headers(),body:JSON.stringify({value:s,endUserId:this.userId,anonymousId:this.anonymousId})});if(!o.ok)throw new Error(`Upstep: ${o.status}`)}async getItem(t){const s=new URLSearchParams;this.userId&&s.set("endUserId",this.userId),this.anonymousId&&s.set("anonymousId",this.anonymousId);const o=await fetch(`${this.baseUrl}/api/sdk/feedback/${t}?${s}`,{headers:this.headers()});if(!o.ok)throw new Error(`Upstep: ${o.status}`);return o.json()}async removeVote(t){if(!this.userId&&!this.anonymousId)return;const s=new URLSearchParams;this.userId&&s.set("endUserId",this.userId),this.anonymousId&&s.set("anonymousId",this.anonymousId);const o=await fetch(`${this.baseUrl}/api/sdk/feedback/${t}/vote?${s}`,{method:"DELETE",headers:this.headers()});if(!o.ok)throw new Error(`Upstep: ${o.status}`)}}function _(e){const t=e==null?void 0:e.trim();return t&&/^[\w\s,"'.-]{1,200}$/.test(t)?t:""}function T(e){if(e==="light"||e==="dark")return e;if(typeof document<"u"){const t=document.documentElement;return t.classList.contains("dark")||t.getAttribute("data-theme")==="dark"?"dark":"light"}return typeof window<"u"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function Y(e,t){const s="right:24px;left:auto",o=e.accent,i=e.accentText,n=a=>`${V(a,e.radius)}px`;return`
|
|
2
|
+
#upstep-root *{box-sizing:border-box;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif}${t?`
|
|
3
|
+
#upstep-btn,#upstep-btn *,#upstep-backdrop,#upstep-backdrop *,#upstep-toast,#upstep-toast *{font-family:${t}}`:""}
|
|
4
|
+
#upstep-btn{position:fixed;bottom:24px;${s};z-index:9998;display:inline-flex;align-items:center;gap:7px;background:${o};color:${i};border:none;border-radius:${n(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}
|
|
4
5
|
#upstep-btn svg{width:16px;height:16px;flex-shrink:0}
|
|
5
6
|
#upstep-btn:hover{transform:translateY(-1px);box-shadow:0 8px 26px rgba(26,25,21,.24)}
|
|
6
7
|
@media(max-width:639px){#upstep-btn{padding:12px}#upstep-btn span{display:none}}
|
|
@@ -8,82 +9,95 @@
|
|
|
8
9
|
#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}
|
|
9
10
|
@keyframes upstep-fade{from{opacity:0}to{opacity:1}}
|
|
10
11
|
@keyframes upstep-rise{from{opacity:0;transform:translateY(14px)}to{opacity:1;transform:translateY(0)}}
|
|
11
|
-
#upstep-modal{background:${
|
|
12
|
+
#upstep-modal{background:${e.bg};border:1px solid ${e.border};border-radius:${n(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)}
|
|
12
13
|
#upstep-header{display:flex;align-items:flex-start;justify-content:space-between;padding:20px 20px 0}
|
|
13
|
-
#upstep-header h2{margin:0;font-size:16px;font-weight:700;color:${
|
|
14
|
-
#upstep-header p{margin:2px 0 0;font-size:14px;color:${
|
|
15
|
-
#upstep-close{background:${
|
|
16
|
-
#upstep-close:hover{background:${
|
|
17
|
-
#upstep-tabs{display:flex;gap:4px;margin:16px 20px 0;padding:4px;background:${
|
|
18
|
-
.upstep-tab{flex:1;padding:8px;background:none;border:none;border-radius
|
|
19
|
-
.upstep-mode .upstep-tab.active{background:${
|
|
20
|
-
.upstep-tab.active{background:${
|
|
14
|
+
#upstep-header h2{margin:0;font-size:16px;font-weight:700;color:${e.text};letter-spacing:-.01em}
|
|
15
|
+
#upstep-header p{margin:2px 0 0;font-size:14px;color:${e.textFaint}}
|
|
16
|
+
#upstep-close{background:${e.bgSoft};border:none;width:28px;height:28px;border-radius:${n(8)};font-size:14px;cursor:pointer;color:${e.textSoft};line-height:1;display:flex;align-items:center;justify-content:center;transition:background .15s}
|
|
17
|
+
#upstep-close:hover{background:${e.bgHover};color:${e.text}}
|
|
18
|
+
#upstep-tabs{display:flex;gap:4px;margin:16px 20px 0;padding:4px;background:${e.bgSoft};border-radius:${n(11)}}
|
|
19
|
+
.upstep-tab{flex:1;padding:8px;background:none;border:none;border-radius:${n(8)};font-size:14px;font-weight:600;color:${e.textSoft};cursor:pointer;transition:all .15s}
|
|
20
|
+
.upstep-mode .upstep-tab.active{background:${e.bgSoft};box-shadow:none}
|
|
21
|
+
.upstep-tab.active{background:${e.bg};color:${e.text};box-shadow:0 1px 3px rgba(0,0,0,.08)}
|
|
21
22
|
#upstep-body{flex:1;overflow-y:auto;padding:18px 20px 22px}
|
|
22
|
-
.upstep-form textarea{width:100%;min-height:104px;border:1px solid ${
|
|
23
|
-
.upstep-form textarea::placeholder{color:${
|
|
24
|
-
.upstep-form textarea:focus{border-color:${
|
|
23
|
+
.upstep-form textarea{width:100%;min-height:104px;border:1px solid ${e.border};border-radius:${n(12)};padding:12px;font-size:16px;line-height:1.6;resize:vertical;outline:none;background:${e.bgSoft};color:${e.text};transition:border-color .15s}
|
|
24
|
+
.upstep-form textarea::placeholder{color:${e.textFaint}}
|
|
25
|
+
.upstep-form textarea:focus{border-color:${o};background:${e.bg}}
|
|
25
26
|
.upstep-type-row{display:flex;gap:7px;margin:12px 0 4px}
|
|
26
|
-
.upstep-type-btn{flex:1;display:flex;align-items:center;justify-content:center;gap:5px;padding:8px 10px;border-radius
|
|
27
|
+
.upstep-type-btn{flex:1;display:flex;align-items:center;justify-content:center;gap:5px;padding:8px 10px;border-radius:${n(9)};border:1px solid ${e.border};background:${e.bg};color:${e.textSoft};font-size:14px;font-weight:600;cursor:pointer;transition:all .15s}
|
|
27
28
|
.upstep-type-btn svg{width:12px;height:12px;flex-shrink:0}
|
|
28
|
-
.upstep-type-btn:hover{border-color:${
|
|
29
|
-
.upstep-type-btn.selected{background:${
|
|
30
|
-
.upstep-submit{width:100%;padding:12px;background:${
|
|
29
|
+
.upstep-type-btn:hover{border-color:${e.textFaint}}
|
|
30
|
+
.upstep-type-btn.selected{background:${o};color:${i};border-color:${o}}
|
|
31
|
+
.upstep-submit{width:100%;padding:12px;background:${o};color:${i};border:none;border-radius:${n(11)};font-size:14px;font-weight:600;cursor:pointer;margin-top:14px;transition:filter .15s}
|
|
31
32
|
.upstep-submit:hover{filter:brightness(.94)}
|
|
32
33
|
.upstep-submit:disabled{opacity:.5;cursor:not-allowed}
|
|
33
|
-
|
|
34
|
-
.upstep-
|
|
35
|
-
.upstep-
|
|
36
|
-
.upstep-
|
|
37
|
-
.upstep-
|
|
38
|
-
|
|
39
|
-
.upstep-
|
|
40
|
-
.upstep-
|
|
34
|
+
.upstep-suggest{width:100%;display:flex;align-items:center;justify-content:center;gap:6px;padding:10px;margin-bottom:12px;background:${e.bg};color:${e.text};border:1px dashed ${e.border};border-radius:${n(11)};font-size:14px;font-weight:600;cursor:pointer;transition:border-color .15s}
|
|
35
|
+
.upstep-suggest:hover{border-color:${o}}
|
|
36
|
+
.upstep-back{background:none;border:none;padding:0;margin-bottom:10px;color:${e.textSoft};font-size:13px;font-weight:600;cursor:pointer}
|
|
37
|
+
.upstep-hint{font-size:13px;color:${e.textFaint};margin:10px 0 0;text-align:center}
|
|
38
|
+
.upstep-hint button{background:none;border:none;padding:0;color:${o};font:inherit;font-weight:600;cursor:pointer}
|
|
39
|
+
#upstep-form-msg{font-size:14px;text-align:center;margin-top:12px;color:${o};font-weight:500}
|
|
40
|
+
.upstep-feedback-item{display:flex;gap:12px;padding:14px;border:1px solid ${e.border};border-radius:${n(14)};margin-bottom:10px;background:${e.bg};transition:border-color .15s}
|
|
41
|
+
.upstep-feedback-item:hover{border-color:${e.textFaint}}
|
|
42
|
+
.upstep-vote{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;min-width:46px;padding:7px 0;border-radius:${n(11)};border:1px solid ${e.border};background:${e.bgSoft};cursor:pointer;transition:all .15s}
|
|
43
|
+
.upstep-vote:hover{border-color:${o}}
|
|
44
|
+
.upstep-vote.voted{border-color:${o};background:${e.accentTint}}
|
|
45
|
+
.upstep-vote-arrow{font-size:11px;line-height:1;color:${o}}
|
|
46
|
+
.upstep-vote-count{font-size:14px;font-weight:700;color:${e.text};line-height:1.1}
|
|
41
47
|
.upstep-feedback-main{flex:1;min-width:0}
|
|
42
|
-
.upstep-feedback-content{font-size:16px;line-height:1.5;color:${
|
|
48
|
+
.upstep-feedback-content{font-size:16px;line-height:1.5;color:${e.text};margin:0 0 8px;word-break:break-word}
|
|
43
49
|
.upstep-feedback-meta{display:flex;align-items:center;gap:7px}
|
|
44
|
-
.upstep-badge{display:inline-flex;align-items:center;padding:2px 8px;border-radius
|
|
50
|
+
.upstep-badge{display:inline-flex;align-items:center;padding:2px 8px;border-radius:${n(9999)};font-size:10.5px;font-weight:700;letter-spacing:.02em}
|
|
45
51
|
.upstep-badge-bug{background:#fdecec;color:#d6453d}
|
|
46
52
|
.upstep-badge-feature{background:#e9f0fd;color:#3b76d6}
|
|
47
|
-
.upstep-badge-general{background:${
|
|
48
|
-
.upstep-feedback-date{font-size:11px;color:${
|
|
53
|
+
.upstep-badge-general{background:${e.bgSoft};color:${e.textSoft}}
|
|
54
|
+
.upstep-feedback-date{font-size:11px;color:${e.textFaint}}
|
|
49
55
|
#upstep-btn{position:fixed}
|
|
50
|
-
.upstep-unread{position:absolute;top:-7px;right:-5px;min-width:22px;height:22px;padding:0 6px;border-radius:11px;background:${
|
|
56
|
+
.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)}
|
|
51
57
|
@keyframes upstep-pop{from{transform:scale(.4)}to{transform:scale(1)}}
|
|
52
|
-
#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:${
|
|
58
|
+
#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:${n(14)} ${n(14)} ${n(4)} ${n(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)}
|
|
53
59
|
#upstep-toast b{font-size:12px}
|
|
54
|
-
#upstep-toast span{font-size:14px;line-height:1.4;color:${
|
|
55
|
-
#upstep-toast em{font-style:normal;font-size:11px;font-weight:600;color:${
|
|
60
|
+
#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}
|
|
61
|
+
#upstep-toast em{font-style:normal;font-size:11px;font-weight:600;color:${o}}
|
|
56
62
|
@media(prefers-reduced-motion:reduce){.upstep-unread,#upstep-toast{animation:none}}
|
|
57
|
-
.upstep-empty{text-align:center;color:${
|
|
58
|
-
.upstep-empty strong{display:block;color:${
|
|
59
|
-
`}const
|
|
63
|
+
.upstep-empty{text-align:center;color:${e.textFaint};font-size:14px;padding:40px 0}
|
|
64
|
+
.upstep-empty strong{display:block;color:${e.textSoft};font-size:15px;margin-bottom:4px}
|
|
65
|
+
`}const J='<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>';class X{constructor(t,s={}){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=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(T(this.themeMode))}buildPalette(t){return P({mode:t,accentColor:this.options.accentColor,colors:this.options.colors,radius:this.options.radius})}get accent(){return this.palette.accent}supportFrameSrc(){return this.client.supportFrameUrl(this.palette.dark?"dark":"light",this.accent,{colors:this.options.colors,radius:this.options.radius,fontFamily:this.options.fontFamily})}mount(){this.injectStyles(),this.showLauncher&&this.renderButton(),this.client.supportEnabled().then(t=>{if(this.hasSupport=t,t){const s=document.querySelector("#upstep-btn span");s&&(s.textContent="Help & feedback"),this.isOpen?this.renderModal():this.hasOpenedSupport()&&this.preloadSupport()}})}openWidget(){this.openModal()}closeWidget(){this.closeModal()}isChatVisible(){return this.isOpen}onUnread(t){return this.unreadListeners.add(t),t(this.unread),()=>{this.unreadListeners.delete(t)}}injectStyles(){var s;(s=document.getElementById("upstep-styles"))==null||s.remove();const t=document.createElement("style");t.id="upstep-styles",t.textContent=Y(this.palette,_(this.options.fontFamily)),document.head.appendChild(t)}renderButton(){const t=document.createElement("button");t.id="upstep-btn",t.setAttribute("aria-label","Open help and feedback"),t.innerHTML=`${J}<span>Feedback</span>`,t.addEventListener("click",()=>{this.openModal()}),document.body.appendChild(t)}supportFrame(){return document.querySelector("#upstep-support-frame")}get usedKey(){return`upstep:support-opened:${this.client.baseUrl}`}hasOpenedSupport(){try{return localStorage.getItem(this.usedKey)==="1"}catch{return!1}}preloadSupport(){this.tab="support",this.renderModal(!0)}openModal(){if(this.unlockAudio(),!this.isOpen&&this.hasSupport){this.tab="support";try{localStorage.setItem(this.usedKey,"1")}catch{}}const t=T(this.themeMode),s=document.getElementById("upstep-backdrop"),o=this.supportFrame();if(!this.isOpen&&s&&o&&s.style.display==="none"&&this.frameTheme===t){this.isOpen=!0,s.style.display="",this.client.notifySupportVisibility(o,!0),this.setUnread(0),this.fetchFeed();return}this.isOpen=!0,this.palette=this.buildPalette(t),this.injectStyles(),this.fetchFeed(),this.renderModal(),this.setUnread(0)}closeModal(){var t,s;if(this.isOpen=!1,this.hasSupport){const o=this.supportFrame(),i=document.getElementById("upstep-backdrop");o&&i?(i.style.display="none",this.client.notifySupportVisibility(o,!1)):this.preloadSupport();return}(t=this.disconnectSupport)==null||t.call(this),this.disconnectSupport=null,(s=document.getElementById("upstep-backdrop"))==null||s.remove()}setUnread(t){this.unread=t;const s=document.getElementById("upstep-btn"),o=s==null?void 0:s.querySelector(".upstep-unread");if(s){if(t>0){const n=o??document.createElement("span");n.className="upstep-unread",n.textContent=t>9?"9+":String(t),o||s.appendChild(n)}else o==null||o.remove();s.setAttribute("aria-label",t>0?`Open help and feedback, ${t} unread ${t===1?"message":"messages"}`:"Open help and feedback")}const i=document.title.replace(/^\(\d+\)\s/,"");document.title=t>0?`(${t}) ${i}`:i,t===0&&this.hideToast(),this.unreadListeners.forEach(n=>n(t))}onSupportUnread(t){if(this.isOpen)return this.setUnread(0);this.setUnread(t.count),t.newMessage&&t.count>0&&(this.showToast(t),t.sound&&this.chime())}showToast(t){this.hideToast();const s=document.createElement("button");s.id="upstep-toast",s.type="button",s.setAttribute("role","status");const o=document.createElement("b");o.textContent=t.author||"New message";const i=document.createElement("span");i.textContent=t.preview;const n=document.createElement("em");n.textContent=t.count>1?`${t.count} new messages`:"Tap to reply",s.append(o,i,n),s.addEventListener("click",()=>this.openModal()),document.body.appendChild(s),this.toastTimer=setTimeout(()=>this.hideToast(),9e3)}hideToast(){var t;clearTimeout(this.toastTimer),(t=document.getElementById("upstep-toast"))==null||t.remove()}unlockAudio(){try{const t=window.AudioContext||window.webkitAudioContext;if(!t)return;this.audio=this.audio??new t,this.audio.state==="suspended"&&this.audio.resume()}catch{}}chime(){const t=this.audio;if(!t||t.state!=="running")return;const s=t.currentTime;for(const[o,i]of[[880,0],[1318,.12]]){const n=t.createOscillator(),a=t.createGain();n.type="sine",n.frequency.value=o,a.gain.setValueAtTime(1e-4,s+i),a.gain.exponentialRampToValueAtTime(.14,s+i+.02),a.gain.exponentialRampToValueAtTime(1e-4,s+i+.5),n.connect(a),a.connect(t.destination),n.start(s+i),n.stop(s+i+.55)}}async fetchFeed(){try{const t=await this.client.listFeedback({sort:"votes",limit:20});this.feedItems=t.items,this.renderFeedList()}catch{}}renderModal(t=!1){var i,n,a;(i=this.disconnectSupport)==null||i.call(this),this.disconnectSupport=null;const s=document.createElement("div");s.id="upstep-backdrop",s.addEventListener("click",r=>{r.target===s&&this.closeModal()}),s.innerHTML=`
|
|
60
66
|
<div id="upstep-modal" style="max-width:${this.hasSupport?"460px":"440px"}">
|
|
61
|
-
${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
|
|
67
|
+
${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>`}
|
|
62
68
|
<div id="upstep-body" style="${this.tab==="support"?"padding:0;overflow:hidden":""}">
|
|
63
|
-
${this.tab==="support"?`<iframe id="upstep-support-frame" title="Customer support" src="${this.
|
|
69
|
+
${this.tab==="support"?`<iframe id="upstep-support-frame" title="Customer support" src="${g(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()}
|
|
64
70
|
</div>
|
|
65
71
|
</div>
|
|
66
|
-
`,(n=document.getElementById("upstep-backdrop"))==null||n.remove(),
|
|
72
|
+
`,(n=document.getElementById("upstep-backdrop"))==null||n.remove(),t&&(s.style.display="none"),document.body.appendChild(s),(a=s.querySelector("#upstep-close"))==null||a.addEventListener("click",()=>this.closeModal()),s.querySelectorAll(".upstep-tab").forEach(r=>{r.addEventListener("click",()=>{this.tab=r.dataset.tab,this.renderModal()})});const o=s.querySelector("#upstep-support-frame");o&&(o.style.color=this.accent,this.frameTheme=this.palette.dark?"dark":"light",this.disconnectSupport=this.client.connectSupportFrame(o,{isVisible:()=>this.isOpen,onUnread:r=>this.onSupportUnread(r)})),this.bindSubmitForm(),this.bindFeed()}renderSubmitForm(){const t=["BUG","FEATURE","GENERAL"],s={BUG:"Bug",FEATURE:"Feature",GENERAL:"General"},o={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>',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>',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>'};return this.hasSupport?`
|
|
73
|
+
<div class="upstep-form">
|
|
74
|
+
<button class="upstep-back" data-goto="feed">← Ideas</button>
|
|
75
|
+
<textarea id="upstep-textarea" placeholder="What would you like us to build?" maxlength="2000"></textarea>
|
|
76
|
+
<button class="upstep-submit" id="upstep-submit-btn">Suggest idea</button>
|
|
77
|
+
<div id="upstep-form-msg"></div>
|
|
78
|
+
<p class="upstep-hint">Something not working? <button data-goto="support">Ask support</button></p>
|
|
79
|
+
</div>
|
|
80
|
+
`:`
|
|
67
81
|
<div class="upstep-form">
|
|
68
82
|
<textarea id="upstep-textarea" placeholder="What's on your mind?" maxlength="2000"></textarea>
|
|
69
83
|
<div class="upstep-type-row">
|
|
70
|
-
${
|
|
84
|
+
${t.map(i=>`<button class="upstep-type-btn${this.selectedType===i?" selected":""}" data-type="${i}">${o[i]}${s[i]}</button>`).join("")}
|
|
71
85
|
</div>
|
|
72
86
|
<button class="upstep-submit" id="upstep-submit-btn">Send feedback</button>
|
|
73
87
|
<div id="upstep-form-msg"></div>
|
|
74
88
|
</div>
|
|
75
|
-
`}renderFeed(){return this.feedItems.length?this.feedItems.map(
|
|
76
|
-
<div class="upstep-feedback-item" data-id="${
|
|
77
|
-
<button class="upstep-vote${
|
|
89
|
+
`}renderFeed(){const t=this.hasSupport?'<button class="upstep-suggest" data-goto="submit"><span aria-hidden="true">+</span> Suggest an idea</button>':"";return this.feedItems.length?t+this.feedItems.map(s=>{var o;return`
|
|
90
|
+
<div class="upstep-feedback-item" data-id="${s.id}">
|
|
91
|
+
<button class="upstep-vote${s.userVote==="UP"?" voted":""}" data-vote="UP" data-feedback="${s.id}">
|
|
78
92
|
<span class="upstep-vote-arrow">▲</span>
|
|
79
|
-
<span class="upstep-vote-count">${
|
|
93
|
+
<span class="upstep-vote-count">${s.upvotes}</span>
|
|
80
94
|
</button>
|
|
81
95
|
<div class="upstep-feedback-main">
|
|
82
|
-
<p class="upstep-feedback-content">${
|
|
96
|
+
<p class="upstep-feedback-content">${g(s.content)}</p>
|
|
83
97
|
<div class="upstep-feedback-meta">
|
|
84
|
-
<span class="upstep-badge upstep-badge-${
|
|
85
|
-
<span class="upstep-badge upstep-badge-general">${
|
|
86
|
-
<span class="upstep-feedback-date">${new Date(
|
|
98
|
+
<span class="upstep-badge upstep-badge-${s.type.toLowerCase()}">${s.type}</span>
|
|
99
|
+
<span class="upstep-badge upstep-badge-general">${g(((o=s.boardStatus)==null?void 0:o.name)??s.status.replace("_"," "))}</span>
|
|
100
|
+
<span class="upstep-feedback-date">${new Date(s.createdAt).toLocaleDateString()}</span>
|
|
87
101
|
</div>
|
|
88
102
|
</div>
|
|
89
|
-
</div>`}).join("")
|
|
103
|
+
</div>`}).join(""):`${t}<div class="upstep-empty"><strong>No ideas yet</strong>Be the first to share one.</div>`}renderFeedList(){const t=document.getElementById("upstep-body");!t||this.tab!=="feed"||(t.innerHTML=this.renderFeed(),this.bindFeed())}bindSubmitForm(){var t;document.querySelectorAll(".upstep-type-btn").forEach(s=>{s.addEventListener("click",()=>{this.selectedType=s.dataset.type,document.querySelectorAll(".upstep-type-btn").forEach(o=>o.classList.remove("selected")),s.classList.add("selected")})}),(t=document.getElementById("upstep-submit-btn"))==null||t.addEventListener("click",async()=>{const s=document.getElementById("upstep-textarea"),o=document.getElementById("upstep-form-msg"),i=document.getElementById("upstep-submit-btn");if(!s||this.loading)return;const n=s.value.trim();if(n){this.loading=!0,i&&(i.disabled=!0,i.textContent="Sending…");try{await this.client.submitFeedback({content:n,type:this.hasSupport?"FEATURE":this.selectedType}),s.value="",o&&(o.textContent=this.hasSupport?"Idea received. Thank you.":"Feedback received. Thank you."),await this.fetchFeed()}catch{o&&(o.textContent="Something went wrong. Please try again.")}finally{this.loading=!1,i&&(i.disabled=!1,i.textContent=this.hasSupport?"Suggest idea":"Send feedback")}}})}bindFeed(){this.bindVoteButtons(),document.querySelectorAll("#upstep-body [data-goto]").forEach(t=>{t.addEventListener("click",()=>{this.tab=t.dataset.goto,this.renderModal()})})}bindVoteButtons(){document.querySelectorAll(".upstep-vote").forEach(t=>{t.addEventListener("click",async()=>{const s=t.dataset.feedback;try{await this.client.vote(s,"UP"),await this.fetchFeed()}catch{}})})}}function g(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}let p=null,d=null;const C={init(e){if(p=new W(e),typeof window<"u"){const t={};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);const s=()=>{d=new X(p,t),d.mount()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",s):s()}return p},open(){d==null||d.openWidget()},close(){d==null||d.closeWidget()},identify(e){p==null||p.setUserId(e)},identifySupport(e){var s;p&&(p.supportIdentityToken=e);const t=document.querySelector("#upstep-support-frame");t&&p&&((s=t.contentWindow)==null||s.postMessage({type:"upstep:support:identity",token:e,visible:(d==null?void 0:d.isChatVisible())??!0},new URL(p.baseUrl).origin))},onUnread(e){return(d==null?void 0:d.onUnread(e))??(()=>{})},get client(){if(!p)throw new Error("Upstep.init() must be called first");return p}};if(typeof document<"u"){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,i=e==null?void 0:e.dataset.accentColor,n=e==null?void 0:e.dataset.position,a=e==null?void 0:e.dataset.theme;if(t){const r={apiKey:t};s&&(r.userId=s),(e==null?void 0:e.dataset.chat)!==void 0&&(r.chat=e.dataset.chat!=="false"),o&&(r.baseUrl=o),i&&(r.accentColor=i),(n==="left"||n==="right")&&(r.position=n),(a==="light"||a==="dark"||a==="auto")&&(r.theme=a);const c=e==null?void 0:e.dataset.colors;if(c)try{const l=JSON.parse(c);l&&typeof l=="object"&&(r.colors=l)}catch{console.warn("Upstep: data-colors must be JSON")}const u=e==null?void 0:e.dataset.radius;u&&Number.isFinite(Number(u))&&(r.radius=Number(u));const h=e==null?void 0:e.dataset.fontFamily;h&&(r.fontFamily=h),C.init(r)}}window.Upstep=C})();
|
package/dist/widget.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
+
import { UpstepColorOverrides } from '@upstep/types';
|
|
1
2
|
import { UpstepApiClient } from './api';
|
|
2
3
|
type ThemeMode = "light" | "dark" | "auto";
|
|
3
4
|
export interface WidgetOptions {
|
|
4
5
|
accentColor?: string;
|
|
6
|
+
/** Panel color overrides. Unset keys keep the default palette. */
|
|
7
|
+
colors?: UpstepColorOverrides;
|
|
8
|
+
/** Base corner radius in px. Defaults to 12. */
|
|
9
|
+
radius?: number;
|
|
10
|
+
/** CSS font-family for the widget. */
|
|
11
|
+
fontFamily?: string;
|
|
5
12
|
position?: "left" | "right";
|
|
6
13
|
/** Color theme. "auto" follows the OS preference. Defaults to "auto". */
|
|
7
14
|
theme?: ThemeMode;
|
|
@@ -15,10 +22,10 @@ export declare class UpstepWidget {
|
|
|
15
22
|
private feedItems;
|
|
16
23
|
private selectedType;
|
|
17
24
|
private loading;
|
|
18
|
-
private accent;
|
|
19
25
|
private position;
|
|
20
26
|
private showLauncher;
|
|
21
27
|
private themeMode;
|
|
28
|
+
private options;
|
|
22
29
|
private palette;
|
|
23
30
|
private hasSupport;
|
|
24
31
|
private disconnectSupport;
|
|
@@ -28,6 +35,9 @@ export declare class UpstepWidget {
|
|
|
28
35
|
private frameTheme;
|
|
29
36
|
private unreadListeners;
|
|
30
37
|
constructor(client: UpstepApiClient, options?: WidgetOptions);
|
|
38
|
+
private buildPalette;
|
|
39
|
+
private get accent();
|
|
40
|
+
private supportFrameSrc;
|
|
31
41
|
mount(): void;
|
|
32
42
|
/** Open the feedback modal programmatically (e.g. from your own button). */
|
|
33
43
|
openWidget(): void;
|
|
@@ -58,6 +68,7 @@ export declare class UpstepWidget {
|
|
|
58
68
|
private renderFeed;
|
|
59
69
|
private renderFeedList;
|
|
60
70
|
private bindSubmitForm;
|
|
71
|
+
private bindFeed;
|
|
61
72
|
private bindVoteButtons;
|
|
62
73
|
}
|
|
63
74
|
export {};
|
package/dist/widget.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../src/widget.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAsB,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../src/widget.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAsB,MAAM,OAAO,CAAC;AAG5D,KAAK,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;AA6G3C,MAAM,WAAW,aAAa;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kEAAkE;IAClE,MAAM,CAAC,EAAE,oBAAoB,CAAC;IAC9B,gDAAgD;IAChD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,sCAAsC;IACtC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC5B,yEAAyE;IACzE,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,GAAG,CAAiB;IAC5B,OAAO,CAAC,SAAS,CAAkB;IACnC,OAAO,CAAC,YAAY,CAA2B;IAC/C,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAmB;IACnC,OAAO,CAAC,YAAY,CAAU;IAC9B,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,iBAAiB,CAA6B;IACtD,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,UAAU,CAA4C;IAC9D,OAAO,CAAC,KAAK,CAA6B;IAC1C,OAAO,CAAC,UAAU,CAAiC;IACnD,OAAO,CAAC,eAAe,CAAsC;gBAEjD,MAAM,EAAE,eAAe,EAAE,OAAO,GAAE,aAAkB;IAShE,OAAO,CAAC,YAAY;IASpB,OAAO,KAAK,MAAM,GAEjB;IAED,OAAO,CAAC,eAAe;IAYvB,KAAK;IAgBL,4EAA4E;IAC5E,UAAU;IAIV,iDAAiD;IACjD,WAAW;IAIX,sDAAsD;IACtD,aAAa;IAIb,wFAAwF;IACxF,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI;IAQ1C,OAAO,CAAC,YAAY;IAWpB,OAAO,CAAC,YAAY;IAWpB,OAAO,CAAC,YAAY;IAIpB,OAAO,KAAK,OAAO,GAElB;IAED,OAAO,CAAC,gBAAgB;IAQxB,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,SAAS;IAsCjB,OAAO,CAAC,UAAU;IAkBlB,OAAO,CAAC,SAAS;IAwBjB,OAAO,CAAC,eAAe;IASvB,OAAO,CAAC,SAAS;IAmBjB,OAAO,CAAC,SAAS;IAKjB,+FAA+F;IAC/F,OAAO,CAAC,WAAW;IAcnB,OAAO,CAAC,KAAK;YAsBC,SAAS;IAUvB,OAAO,CAAC,WAAW;IA+CnB,OAAO,CAAC,gBAAgB;IAqCxB,OAAO,CAAC,UAAU;IA+BlB,OAAO,CAAC,cAAc;IAOtB,OAAO,CAAC,cAAc;IA2DtB,OAAO,CAAC,QAAQ;IAYhB,OAAO,CAAC,eAAe;CAaxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@upstep/js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "UpStep feedback, voting and AI support widgets for web apps",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://upstep.dev",
|
|
@@ -36,18 +36,18 @@
|
|
|
36
36
|
"types": "./dist/support.d.ts",
|
|
37
37
|
"import": "./dist/support.js",
|
|
38
38
|
"require": "./dist/support.cjs"
|
|
39
|
+
},
|
|
40
|
+
"./theme": {
|
|
41
|
+
"types": "./dist/theme.d.ts",
|
|
42
|
+
"import": "./dist/theme.js",
|
|
43
|
+
"require": "./dist/theme.cjs"
|
|
39
44
|
}
|
|
40
45
|
},
|
|
41
46
|
"files": [
|
|
42
47
|
"dist"
|
|
43
48
|
],
|
|
44
|
-
"scripts": {
|
|
45
|
-
"build": "vite build && vite build --config vite.embed.config.ts",
|
|
46
|
-
"dev": "vite build --watch",
|
|
47
|
-
"type-check": "tsc --noEmit"
|
|
48
|
-
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@upstep/types": "
|
|
50
|
+
"@upstep/types": "0.10.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"react": ">=18",
|
|
@@ -69,5 +69,10 @@
|
|
|
69
69
|
"vite-plugin-dts": "^4.4.0"
|
|
70
70
|
},
|
|
71
71
|
"unpkg": "./dist/upstep.global.js",
|
|
72
|
-
"jsdelivr": "./dist/upstep.global.js"
|
|
73
|
-
|
|
72
|
+
"jsdelivr": "./dist/upstep.global.js",
|
|
73
|
+
"scripts": {
|
|
74
|
+
"build": "vite build && vite build --config vite.embed.config.ts",
|
|
75
|
+
"dev": "vite build --watch",
|
|
76
|
+
"type-check": "tsc --noEmit"
|
|
77
|
+
}
|
|
78
|
+
}
|
package/dist/api-BdOCiCLM.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const h="upstep-anonymous-id";function c(){const i=typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;if(typeof window>"u")return i;try{const e=window.localStorage.getItem(h);return e||(window.localStorage.setItem(h,i),i)}catch{return i}}class a{constructor(e){this.baseUrl=(e.baseUrl??"https://upstep.dev").replace(/\/$/,""),this.apiKey=e.apiKey,this.supportIdentityToken=e.supportIdentityToken,this.chat=e.chat!==!1,e.userId!==void 0&&(this.userId=e.userId),this.anonymousId=c()}setUserId(e){this.userId=e}headers(){return{"Content-Type":"application/json","x-api-key":this.apiKey}}async supportEnabled(){if(!this.chat)return!1;try{const e=await fetch(`${this.baseUrl}/api/sdk/support`,{headers:this.headers()});return e.ok&&(await e.json()).enabled===!0}catch{return!1}}supportFrameUrl(e,t="#D97757"){return`${this.baseUrl}/support/${encodeURIComponent(this.apiKey)}?theme=${encodeURIComponent(e)}&accent=${encodeURIComponent(t)}`}connectSupportFrame(e,t={}){const s=new URL(this.baseUrl).origin,r=()=>{var o;return(o=e.contentWindow)==null?void 0:o.postMessage({type:"upstep:support:identity",token:this.supportIdentityToken,accentColor:getComputedStyle(e).color,...t.isVisible?{visible:t.isVisible()}:{}},s)},d=o=>{if(o.origin!==s||o.source!==e.contentWindow)return;const n=o.data;if((n==null?void 0:n.type)==="upstep:support:ready")r();else if((n==null?void 0:n.type)==="upstep:support:unread"&&t.onUnread){const u=Number(n.count);t.onUnread({count:Number.isFinite(u)?Math.max(0,Math.floor(u)):0,newMessage:n.newMessage===!0,author:String(n.author??"").slice(0,80),preview:String(n.preview??"").slice(0,200),sound:n.sound!==!1})}};return e.addEventListener("load",r),window.addEventListener("message",d),()=>{e.removeEventListener("load",r),window.removeEventListener("message",d)}}notifySupportVisibility(e,t){var s;(s=e.contentWindow)==null||s.postMessage({type:"upstep:support:visible",visible:t},new URL(this.baseUrl).origin)}async listFeedback(e){const t=new URLSearchParams;e!=null&&e.cursor&&t.set("cursor",e.cursor),e!=null&&e.limit&&t.set("limit",String(e.limit)),e!=null&&e.type&&t.set("type",e.type),e!=null&&e.status&&t.set("status",e.status),e!=null&&e.sort&&t.set("sort",e.sort),this.userId&&t.set("endUserId",this.userId),this.anonymousId&&t.set("anonymousId",this.anonymousId);const s=await fetch(`${this.baseUrl}/api/sdk/feedback?${t}`,{headers:this.headers()});if(!s.ok)throw new Error(`Upstep: ${s.status}`);return s.json()}async submitFeedback(e){const t=await fetch(`${this.baseUrl}/api/sdk/feedback`,{method:"POST",headers:this.headers(),body:JSON.stringify({...e,endUserId:e.endUserId??this.userId,anonymousId:e.anonymousId??this.anonymousId})});if(!t.ok)throw new Error(`Upstep: ${t.status}`);return t.json()}async vote(e,t){const s=await fetch(`${this.baseUrl}/api/sdk/feedback/${e}/vote`,{method:"POST",headers:this.headers(),body:JSON.stringify({value:t,endUserId:this.userId,anonymousId:this.anonymousId})});if(!s.ok)throw new Error(`Upstep: ${s.status}`)}async getItem(e){const t=new URLSearchParams;this.userId&&t.set("endUserId",this.userId),this.anonymousId&&t.set("anonymousId",this.anonymousId);const s=await fetch(`${this.baseUrl}/api/sdk/feedback/${e}?${t}`,{headers:this.headers()});if(!s.ok)throw new Error(`Upstep: ${s.status}`);return s.json()}async removeVote(e){if(!this.userId&&!this.anonymousId)return;const t=new URLSearchParams;this.userId&&t.set("endUserId",this.userId),this.anonymousId&&t.set("anonymousId",this.anonymousId);const s=await fetch(`${this.baseUrl}/api/sdk/feedback/${e}/vote?${t}`,{method:"DELETE",headers:this.headers()});if(!s.ok)throw new Error(`Upstep: ${s.status}`)}}exports.UpstepApiClient=a;
|