@malto/sdk 0.1.0 → 0.1.1
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/dist/index.cjs +2 -2
- package/dist/index.js +2 -2
- package/dist/malto.umd.js +15 -15
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
// src/client.ts
|
|
4
|
-
var DEFAULT_API_URL = "https://api.
|
|
4
|
+
var DEFAULT_API_URL = "https://malto-api-production.up.railway.app";
|
|
5
5
|
var MaltoClient = class {
|
|
6
6
|
constructor(opts) {
|
|
7
7
|
this.apiKey = opts.apiKey;
|
|
@@ -844,7 +844,7 @@ var MaltoWidget = class {
|
|
|
844
844
|
this.apiKeyPrefix = config.apiKey.slice(0, 16);
|
|
845
845
|
this.config = {
|
|
846
846
|
apiKey: config.apiKey,
|
|
847
|
-
apiUrl: config.apiUrl ?? "https://api.
|
|
847
|
+
apiUrl: config.apiUrl ?? "https://malto-api-production.up.railway.app",
|
|
848
848
|
mode: config.mode ?? "auto",
|
|
849
849
|
position: config.position ?? "bottom-right",
|
|
850
850
|
triggerLabel: config.triggerLabel ?? "Feedback",
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/client.ts
|
|
2
|
-
var DEFAULT_API_URL = "https://api.
|
|
2
|
+
var DEFAULT_API_URL = "https://malto-api-production.up.railway.app";
|
|
3
3
|
var MaltoClient = class {
|
|
4
4
|
constructor(opts) {
|
|
5
5
|
this.apiKey = opts.apiKey;
|
|
@@ -842,7 +842,7 @@ var MaltoWidget = class {
|
|
|
842
842
|
this.apiKeyPrefix = config.apiKey.slice(0, 16);
|
|
843
843
|
this.config = {
|
|
844
844
|
apiKey: config.apiKey,
|
|
845
|
-
apiUrl: config.apiUrl ?? "https://api.
|
|
845
|
+
apiUrl: config.apiUrl ?? "https://malto-api-production.up.railway.app",
|
|
846
846
|
mode: config.mode ?? "auto",
|
|
847
847
|
position: config.position ?? "bottom-right",
|
|
848
848
|
triggerLabel: config.triggerLabel ?? "Feedback",
|
package/dist/malto.umd.js
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
var Malto=(function(exports){'use strict';var F="https://api.
|
|
1
|
+
var Malto=(function(exports){'use strict';var F="https://malto-api-production.up.railway.app",h=class{constructor(t){this.apiKey=t.apiKey,this.apiUrl=(t.apiUrl??F).replace(/\/$/,""),this.getSessionToken=t.getSessionToken;}async request(t,e={}){let a={"Content-Type":"application/json",Authorization:`Bearer ${this.apiKey}`};if(e.headers){let s=e.headers;for(let[d,l]of Object.entries(s))a[d]=l;}if(e.auth){let s=this.getSessionToken();s&&(a["X-Malto-Session"]=s);}let o=await fetch(`${this.apiUrl}${t}`,{...e,headers:a}),r=await o.text(),n=r?A(r):null;if(!o.ok){let s=n&&(n.message||n.error)||`Request failed (${o.status})`;throw new b(Array.isArray(s)?s.join(", "):String(s),o.status)}return n}board(){return this.request("/v1/sdk/board")}listFeedbacks(){return this.request("/v1/sdk/feedbacks",{auth:true})}feedback(t){return this.request(`/v1/sdk/feedbacks/${t}`,{auth:true})}createFeedback(t){return this.request("/v1/sdk/feedbacks",{method:"POST",auth:true,body:JSON.stringify(t)})}vote(t){return this.request(`/v1/sdk/feedbacks/${t}/vote`,{method:"POST",auth:true})}comments(t){return this.request(`/v1/sdk/feedbacks/${t}/comments`,{auth:true})}addComment(t,e,a){return this.request(`/v1/sdk/feedbacks/${t}/comments`,{method:"POST",auth:true,body:JSON.stringify({body:e,parentId:a})})}roadmap(){return this.request("/v1/sdk/roadmap")}releases(){return this.request("/v1/sdk/releases")}startMagicLink(t){return this.request("/v1/sdk/auth/magic-link",{method:"POST",body:JSON.stringify(t)})}verifyMagicLink(t){return this.request("/v1/sdk/auth/verify",{method:"POST",body:JSON.stringify({token:t})})}identify(t){return this.request("/v1/sdk/auth/identify",{method:"POST",body:JSON.stringify(t)})}},b=class extends Error{constructor(e,a){super(e);this.status=a;this.name="MaltoApiError";}};function A(i){try{return JSON.parse(i)}catch{return null}}var x="malto:session:";function E(i){if(typeof window>"u")return null;try{let t=window.localStorage.getItem(x+i);if(!t)return null;let e=JSON.parse(t);return !e?.token||!e?.expiresAt?null:new Date(e.expiresAt).getTime()<Date.now()?(window.localStorage.removeItem(x+i),null):e}catch{return null}}function S(i,t){if(!(typeof window>"u"))try{window.localStorage.setItem(x+i,JSON.stringify(t));}catch{}}function g(i){if(!(typeof window>"u"))try{window.localStorage.removeItem(x+i);}catch{}}var H="malto-sdk-styles",P="malto-sdk-styles-custom";function R(i){if(typeof document>"u")return;let t=B(i);I(H,t),i.customCss?I(P,O(i.customCss)):document.getElementById(P)?.remove();}function O(i){return i.replace(/<\/style/gi,"<\\/style").replace(/<\/script/gi,"<\\/script").replace(/expression\s*\(/gi,"expr\\(").replace(/javascript\s*:/gi,"javascript\\:")}function I(i,t){let e=document.getElementById(i);if(e){e.textContent=t;return}let a=document.createElement("style");a.id=i,a.textContent=t,document.head.appendChild(a);}function B(i){let t=i.primary,e=D(t),a=i.radius==="sm"?"10px":i.radius==="lg"?"22px":"16px",o=i.appearance??"auto",r=i.cssVars??{};return `
|
|
2
2
|
:where(.malto-root, .malto-root *) {
|
|
3
3
|
box-sizing: border-box;
|
|
4
4
|
}
|
|
5
5
|
.malto-root {
|
|
6
|
-
--malto-primary: ${
|
|
7
|
-
--malto-primary-contrast: ${
|
|
6
|
+
--malto-primary: ${r.primary??t};
|
|
7
|
+
--malto-primary-contrast: ${r.primaryContrast??e.contrast};
|
|
8
8
|
--malto-primary-50: ${e.tint50};
|
|
9
9
|
--malto-primary-100: ${e.tint100};
|
|
10
10
|
--malto-primary-200: ${e.tint200};
|
|
11
11
|
--malto-primary-600: ${e.shade600};
|
|
12
12
|
--malto-primary-rgb: ${e.rgb};
|
|
13
|
-
--malto-surface: ${
|
|
14
|
-
--malto-surface-muted: ${
|
|
13
|
+
--malto-surface: ${r.surface??"#ffffff"};
|
|
14
|
+
--malto-surface-muted: ${r.surfaceMuted??"#fbfaff"};
|
|
15
15
|
--malto-surface-elevated: rgba(255,255,255,0.85);
|
|
16
|
-
--malto-border: ${
|
|
16
|
+
--malto-border: ${r.border??"rgba(15, 13, 35, 0.06)"};
|
|
17
17
|
--malto-border-strong: rgba(15, 13, 35, 0.1);
|
|
18
|
-
--malto-text: ${
|
|
19
|
-
--malto-text-muted: ${
|
|
18
|
+
--malto-text: ${r.text??"#0f0d23"};
|
|
19
|
+
--malto-text-muted: ${r.textMuted??"#5b5871"};
|
|
20
20
|
--malto-text-subtle: rgba(15, 13, 35, 0.45);
|
|
21
|
-
--malto-radius: ${
|
|
21
|
+
--malto-radius: ${r.radius??a};
|
|
22
22
|
--malto-radius-sm: 10px;
|
|
23
23
|
--malto-radius-pill: 999px;
|
|
24
|
-
--malto-shadow-sm: ${
|
|
24
|
+
--malto-shadow-sm: ${r.shadow??"0 4px 12px -4px rgba(15, 13, 35, 0.08)"};
|
|
25
25
|
--malto-shadow-md: 0 12px 32px -8px rgba(15, 13, 35, 0.16);
|
|
26
26
|
--malto-shadow-lg: 0 30px 60px -20px rgba(15, 13, 35, 0.28);
|
|
27
27
|
--malto-shadow-glow: 0 12px 24px -8px rgba(var(--malto-primary-rgb), 0.45);
|
|
28
|
-
--malto-font: ${
|
|
28
|
+
--malto-font: ${r.font??"-apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, system-ui, sans-serif"};
|
|
29
29
|
--malto-ease-spring: cubic-bezier(0.34, 1.4, 0.5, 1);
|
|
30
30
|
--malto-ease-smooth: cubic-bezier(0.32, 0.72, 0, 1);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
${
|
|
34
|
-
${
|
|
33
|
+
${o==="dark"?T():""}
|
|
34
|
+
${o==="auto"?`@media (prefers-color-scheme: dark) { ${T()} }`:""}
|
|
35
35
|
|
|
36
36
|
.malto-root, .malto-root *, .malto-root *::before, .malto-root *::after {
|
|
37
37
|
font-family: var(--malto-font);
|
|
@@ -603,5 +603,5 @@ var Malto=(function(exports){'use strict';var F="https://api.malto.io",h=class{c
|
|
|
603
603
|
--malto-text-muted: #a09cc7;
|
|
604
604
|
--malto-text-subtle: rgba(230, 227, 245, 0.5);
|
|
605
605
|
}
|
|
606
|
-
`}function D(i){let{r:t,g:e,b:a}=U(i);return {rgb:`${t}, ${e}, ${a}`,contrast:j(t,e,a),tint50:N(t,e,a,.06),tint100:N(t,e,a,.12),tint200:N(t,e,a,.18),shade600:V(t,e,a,-0.18)}}function U(i){let t=i.trim().replace(/^#/,"");return t.length===3&&(t=t.split("").map(e=>e+e).join("")),/^[0-9a-fA-F]{6}$/.test(t)?{r:parseInt(t.slice(0,2),16),g:parseInt(t.slice(2,4),16),b:parseInt(t.slice(4,6),16)}:{r:69,g:47,b:223}}function j(i,t,e){return (.2126*i+.7152*t+.0722*e)/255>.65?"#0f0d23":"#ffffff"}function N(i,t,e,a,r){return `rgba(${i}, ${t}, ${e}, ${a})`}function V(i,t,e,a){let r=n=>Math.max(0,Math.min(255,Math.round(n+255*a))),o=n=>r(n).toString(16).padStart(2,"0");return `#${o(i)}${o(t)}${o(e)}`}var q={"bottom-right":{right:"24px",bottom:"24px"},"bottom-left":{left:"24px",bottom:"24px"},"top-right":{right:"24px",top:"24px"},"top-left":{left:"24px",top:"24px"}},v=class{constructor(t){this.resolvedMode="bubble";this.root=null;this.container=null;this.trigger=null;this.board=null;if(!t.apiKey)throw new Error("Malto: apiKey is required");this.apiKeyPrefix=t.apiKey.slice(0,16),this.config={apiKey:t.apiKey,apiUrl:t.apiUrl??"https://api.malto.io",mode:t.mode??"auto",position:t.position??"bottom-right",triggerLabel:t.triggerLabel??"Feedback",primaryColor:t.primaryColor,cssVars:t.cssVars,customCss:t.customCss,radius:t.radius??"md",appearance:t.appearance??"auto",zIndex:t.zIndex??2147483600,views:t.views,identify:t.identify,target:t.target,onReady:t.onReady,onError:t.onError};let e=E(this.apiKeyPrefix);this.state={open:false,view:"list",loading:false,error:null,feedbacks:[],roadmap:{},releases:[],selectedFeedback:null,comments:[],authEmail:"",authStatus:"idle",email:e?.email??null,name:e?.name??null},this.client=new h({apiKey:this.config.apiKey,apiUrl:this.config.apiUrl,getSessionToken:()=>E(this.apiKeyPrefix)?.token??null});}async mount(){try{let t=await this.client.board();this.board=t;let e=this.config.primaryColor||t.widget.primaryColor||t.board.boardThemeColor||"#452fdf";R({primary:e,cssVars:this.config.cssVars,customCss:this.config.customCss,radius:this.config.radius,appearance:this.config.appearance}),this.resolvedMode=this.config.mode==="auto"?t.widget.defaultMode:this.config.mode,this.config.identify&&await this.runIdentify(this.config.identify),this.renderHost(this.resolvedMode),this.config.onReady?.();}catch(t){this.config.onError?.(t);}}unmount(){this.root?.parentElement?.removeChild(this.root),this.trigger?.parentElement?.removeChild(this.trigger),this.root=null,this.trigger=null,this.container=null;}open(){this.state.open=true,this.render();}close(){this.state.open=false,this.render();}setIdentify(t){if(!t){g(this.apiKeyPrefix),this.state.email=null,this.state.name=null,this.render();return}this.runIdentify(t);}async runIdentify(t){try{let e=await this.client.identify(t);S(this.apiKeyPrefix,{token:e.sessionToken,expiresAt:e.expiresAt,email:e.user.email,name:e.user.name}),this.state.email=e.user.email,this.state.name=e.user.name,this.render();}catch(e){this.config.onError?.(e);}}renderHost(t){let e=document.createElement("div");if(e.className="malto-root",e.style.setProperty("--malto-z",String(this.config.zIndex)),document.body.appendChild(e),this.root=e,t==="inline"){let a=this.resolveTarget();if(!a){this.config.onError?.(new Error("Malto: inline target not found"));return}let r=document.createElement("div");r.className="malto-root malto-inline",r.style.setProperty("--malto-z",String(this.config.zIndex)),a.appendChild(r),this.container=r,this.state.open=true,this.render();return}if(t==="bubble"){let a=this.buildBubble(),r=q[this.config.position];Object.assign(a.style,r);let o=document.createElement("div");o.className="malto-root",o.style.setProperty("--malto-z",String(this.config.zIndex)),o.appendChild(a),document.body.appendChild(o),this.trigger=o;}else if(t==="trigger"){let a=this.resolveTarget();if(!a){this.config.onError?.(new Error("Malto: trigger target not found"));return}let r=document.createElement("span");r.className="malto-root",r.style.setProperty("--malto-z",String(this.config.zIndex));let o=document.createElement("button");o.className="malto-trigger",o.innerHTML=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.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><span>${L(this.config.triggerLabel)}</span>`,o.addEventListener("click",()=>this.open()),r.appendChild(o),a.appendChild(r),this.trigger=r;}else t==="modal"&&(this.state.open=true);this.render();}buildBubble(){let t=document.createElement("button");return t.className="malto-bubble",t.setAttribute("aria-label",this.config.triggerLabel),t.innerHTML='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.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>',t.addEventListener("click",()=>{this.state.open?this.close():this.open();}),t}resolveTarget(){return this.config.target?typeof this.config.target=="string"?document.querySelector(this.config.target):this.config.target:null}render(){if(!this.root)return;if(this.resolvedMode==="inline"){if(!this.container)return;this.container.innerHTML="",this.container.appendChild(this.buildPanelBody());return}if(this.root.innerHTML="",!this.state.open)return;let t=document.createElement("div");t.className="malto-overlay",t.addEventListener("click",a=>{a.target===t&&this.close();});let e=document.createElement("div");e.className="malto-modal",e.appendChild(this.buildPanelBody()),t.appendChild(e),this.root.appendChild(t);}buildPanelBody(){let t=document.createElement("div");t.style.display="flex",t.style.flexDirection="column",t.style.height="100%",t.style.minHeight="0",t.appendChild(this.buildHeader()),t.appendChild(this.buildTabs());let e=document.createElement("div");if(e.className="malto-body",e.appendChild(this.buildView()),t.appendChild(e),this.state.view!=="auth"&&!this.state.email){let a=document.createElement("div");a.className="malto-footer-banner";let r=document.createElement("span");r.innerHTML="Sign in to vote, comment, or submit ideas.";let o=document.createElement("button");o.className="malto-link",o.textContent="Sign in",o.addEventListener("click",()=>this.go("auth")),a.appendChild(r),a.appendChild(o),t.appendChild(a);}return t}buildHeader(){let t=document.createElement("div");t.className="malto-header";let e=document.createElement("div");e.className="malto-header-meta";let a=document.createElement("div");a.className="malto-board-logo";let r=$(this.board?.board.companyLogoUrl);if(r){let n=document.createElement("img");n.src=r,n.alt="",n.referrerPolicy="no-referrer",n.crossOrigin="anonymous",a.appendChild(n);}else a.textContent=(this.board?.board.companyName??this.board?.board.boardName??"M").charAt(0).toUpperCase();let o=document.createElement("h3");if(o.textContent=this.board?.board.boardName??this.board?.board.companyName??"Feedback",e.appendChild(a),e.appendChild(o),t.appendChild(e),this.resolvedMode!=="inline"){let n=document.createElement("button");n.className="malto-close",n.setAttribute("aria-label","Close"),n.innerHTML='<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',n.addEventListener("click",()=>this.close()),t.appendChild(n);}return t}buildTabs(){let t=document.createElement("div");t.className="malto-tabs";let e=this.allowedViews();return e.includes("list")&&t.appendChild(this.tabBtn("Feed","list")),e.includes("submit")&&t.appendChild(this.tabBtn("New","submit")),e.includes("roadmap")&&t.appendChild(this.tabBtn("Roadmap","roadmap")),e.includes("changelog")&&t.appendChild(this.tabBtn("Updates","changelog")),t}tabBtn(t,e){let a=document.createElement("button");return a.className="malto-tab",a.setAttribute("aria-selected",this.state.view===e?"true":"false"),a.textContent=t,a.addEventListener("click",()=>this.go(e)),a}go(t){this.state.view=t,this.state.error=null,this.render(),t==="list"&&this.loadFeedbacks(),t==="roadmap"&&this.loadRoadmap(),t==="changelog"&&this.loadReleases(),t==="detail"&&this.state.selectedFeedback&&this.loadComments(this.state.selectedFeedback.id);}allowedViews(){let t=this.board?.widget.enabledFeatures??["list","submit","vote","comment","roadmap","changelog"];return (this.config.views??["list","submit","roadmap","changelog"]).filter(a=>t.includes(a))}buildView(){let t=document.createElement("div");if(this.state.error){let e=document.createElement("div");e.className="malto-error",e.textContent=this.state.error,t.appendChild(e);}switch(this.state.view){case "list":t.appendChild(this.viewList()),this.state.feedbacks.length===0&&!this.state.loading&&this.loadFeedbacks();break;case "submit":t.appendChild(this.viewSubmit());break;case "auth":t.appendChild(this.viewAuth());break;case "roadmap":t.appendChild(this.viewRoadmap()),Object.keys(this.state.roadmap).length===0&&!this.state.loading&&this.loadRoadmap();break;case "changelog":t.appendChild(this.viewChangelog()),this.state.releases.length===0&&!this.state.loading&&this.loadReleases();break;case "detail":t.appendChild(this.viewDetail());break}return t}viewList(){let t=document.createElement("div");if(this.state.loading)return t.appendChild(this.skeletonList(4)),t;if(this.state.feedbacks.length===0)return t.appendChild(this.emptyState("\u{1F4A1}","No requests yet","Be the first to share an idea or report something.")),t;let e=document.createElement("div");e.className="malto-list";for(let a of this.state.feedbacks)e.appendChild(this.feedbackRow(a));return t.appendChild(e),t}feedbackRow(t){let e=document.createElement("div");e.className="malto-item";let a=document.createElement("button");a.className="malto-vote",a.setAttribute("aria-pressed",t.hasVoted?"true":"false");let r=document.createElement("span");r.className="malto-vote-arrow",r.textContent="\u25B2";let o=document.createElement("span");o.className="malto-vote-count",o.textContent=_(t.votes??0),a.appendChild(r),a.appendChild(o),a.addEventListener("click",m=>{m.stopPropagation(),this.handleVote(t);});let n=document.createElement("div");n.className="malto-item-content";let s=document.createElement("h4");if(s.textContent=t.title,n.appendChild(s),t.description){let m=document.createElement("p");m.textContent=t.description,n.appendChild(m);}let d=document.createElement("div");if(d.className="malto-item-meta",t.status&&t.status!=="BACKLOG"){let m=K(t.status);d.appendChild(m);}let l=document.createElement("span");return l.textContent=z(t.createdAt),d.appendChild(l),n.appendChild(d),e.appendChild(a),e.appendChild(n),e.addEventListener("click",()=>{this.state.selectedFeedback=t,this.go("detail");}),e}viewSubmit(){let t=document.createElement("form");t.className="malto-form";let e=document.createElement("input");e.className="malto-input",e.required=true,e.maxLength=200,e.placeholder="What would you like?";let a=document.createElement("textarea");a.className="malto-textarea",a.maxLength=5e3,a.placeholder="Add some context (optional)";let r=document.createElement("button");return r.className="malto-button",r.textContent="Submit feedback",r.type="submit",t.appendChild(e),t.appendChild(a),t.appendChild(r),t.addEventListener("submit",async o=>{if(o.preventDefault(),!this.state.email){this.go("auth");return}r.setAttribute("disabled","true");try{await this.client.createFeedback({title:e.value.trim(),description:a.value.trim()||void 0}),e.value="",a.value="",await this.loadFeedbacks(),this.go("list");}catch(n){this.state.error=n.message,r.removeAttribute("disabled"),this.render();}}),t}viewAuth(){let t=document.createElement("div");if(this.state.email){let n=document.createElement("p");n.style.fontSize="13px",n.style.color="var(--malto-text)",n.style.marginBottom="10px",n.innerHTML=`Signed in as <strong>${L(this.state.email)}</strong>`;let s=document.createElement("button");return s.className="malto-secondary",s.textContent="Sign out",s.addEventListener("click",()=>{g(this.apiKeyPrefix),this.state.email=null,this.state.name=null,this.go("list");}),t.appendChild(n),t.appendChild(s),t}if(this.state.authStatus==="sent"){let n=document.createElement("p");n.style.fontSize="13px",n.style.color="var(--malto-text)",n.style.marginBottom="12px",n.style.lineHeight="1.5",n.innerHTML=`We sent a sign-in link to <strong>${L(this.state.authEmail)}</strong>. Open the email and paste the token below.`;let s=document.createElement("input");s.className="malto-input",s.placeholder="Paste token from email";let d=document.createElement("button");d.className="malto-button",d.style.marginTop="8px",d.textContent="Verify",d.addEventListener("click",async()=>{d.setAttribute("disabled","true");try{let m=await this.client.verifyMagicLink(s.value.trim());S(this.apiKeyPrefix,{token:m.sessionToken,expiresAt:m.expiresAt,email:m.user.email,name:m.user.name}),this.state.email=m.user.email,this.state.name=m.user.name,this.state.authStatus="idle",this.go("list");}catch(m){this.state.error=m.message,d.removeAttribute("disabled"),this.render();}});let l=document.createElement("button");return l.className="malto-link",l.style.marginTop="12px",l.style.display="block",l.textContent="Use a different email",l.addEventListener("click",()=>{this.state.authStatus="idle",this.render();}),t.appendChild(n),t.appendChild(s),t.appendChild(d),t.appendChild(l),t}let e=document.createElement("form");e.className="malto-form";let a=document.createElement("p");a.style.fontSize="13px",a.style.color="var(--malto-text-muted)",a.style.marginBottom="4px",a.style.lineHeight="1.5",a.textContent="Enter your email to receive a one-click sign-in link.";let r=document.createElement("input");r.className="malto-input",r.type="email",r.required=true,r.placeholder="you@company.com",r.value=this.state.authEmail;let o=document.createElement("button");return o.className="malto-button",o.type="submit",o.textContent="Send sign-in link",e.appendChild(a),e.appendChild(r),e.appendChild(o),e.addEventListener("submit",async n=>{n.preventDefault(),o.setAttribute("disabled","true");try{await this.client.startMagicLink({email:r.value.trim()}),this.state.authEmail=r.value.trim(),this.state.authStatus="sent",this.render();}catch(s){this.state.error=s.message,o.removeAttribute("disabled"),this.render();}}),e}viewRoadmap(){let t=document.createElement("div");if(this.state.loading)return t.appendChild(this.skeletonList(3)),t;let e={PLANNED:"Planned",IN_PROGRESS:"In Progress",COMPLETED:"Done"},a=false;for(let r of ["PLANNED","IN_PROGRESS","COMPLETED"]){let o=this.state.roadmap[r]??[],n=document.createElement("div");n.className="malto-roadmap-col";let s=document.createElement("h5");s.textContent=e[r]??r;let d=document.createElement("span");if(d.className="malto-roadmap-count",d.textContent=String(o.length),s.appendChild(d),n.appendChild(s),o.length===0){let l=document.createElement("div");l.className="malto-empty-desc",l.style.padding="8px 0 12px",l.textContent="Nothing here yet.",n.appendChild(l);}else {a=true;for(let l of o)n.appendChild(this.feedbackRow(l));}t.appendChild(n);}return !a&&Object.keys(this.state.roadmap).length===0&&(t.innerHTML="",t.appendChild(this.emptyState("\u{1F5FA}\uFE0F","Empty roadmap","Once admins move items into Planned, In Progress or Done, you'll see them here."))),t}viewChangelog(){let t=document.createElement("div");if(this.state.loading)return t.appendChild(this.skeletonList(2)),t;if(this.state.releases.length===0)return t.appendChild(this.emptyState("\u2728","No updates yet","Check back soon.")),t;for(let e of this.state.releases){let a=document.createElement("div");if(a.className="malto-release",e.publishedAt){let n=document.createElement("span");n.className="malto-release-date",n.textContent=Y(e.publishedAt),a.appendChild(n);}let r=document.createElement("h4");r.textContent=e.title;let o=document.createElement("p");o.textContent=e.body,a.appendChild(r),a.appendChild(o),t.appendChild(a);}return t}viewDetail(){let t=document.createElement("div"),e=this.state.selectedFeedback;if(!e)return t.appendChild(this.emptyState("\u{1F4ED}","Nothing selected","Pick a request from Feed.")),t;let a=document.createElement("button");if(a.className="malto-back",a.innerHTML='<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 18 9 12 15 6"/></svg> Back',a.addEventListener("click",()=>this.go("list")),t.appendChild(a),t.appendChild(this.feedbackRow(e)),this.allowedViews().includes("comment")){let o=document.createElement("h5");if(o.textContent="Comments",o.style.cssText="margin: 16px 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--malto-text-muted); font-weight: 600;",t.appendChild(o),this.state.loading)t.appendChild(this.skeletonList(2));else if(this.state.comments.length===0){let l=document.createElement("div");l.className="malto-empty-desc",l.style.padding="8px 0 12px",l.textContent="No comments yet \u2014 start the conversation.",t.appendChild(l);}else for(let l of this.state.comments){let m=document.createElement("div");m.className="malto-comment";let f=document.createElement("div");f.className="malto-avatar";let M=$(l.author?.avatarUrl);if(M){let u=document.createElement("img");u.src=M,u.alt="",u.referrerPolicy="no-referrer",u.crossOrigin="anonymous",f.appendChild(u);}else f.textContent=(l.author?.name??"?").charAt(0).toUpperCase();let p=document.createElement("div");p.style.flex="1",p.style.minWidth="0";let y=document.createElement("div"),k=document.createElement("span");k.className="malto-comment-author",k.textContent=l.author?.name??"User";let w=document.createElement("span");w.className="malto-comment-time",w.textContent=z(l.createdAt),y.appendChild(k),y.appendChild(w);let C=document.createElement("div");C.className="malto-comment-body",C.textContent=l.body,p.appendChild(y),p.appendChild(C),m.appendChild(f),m.appendChild(p),t.appendChild(m);}let n=document.createElement("form");n.className="malto-form",n.style.marginTop="12px";let s=document.createElement("textarea");s.className="malto-textarea",s.placeholder="Write a comment",s.required=true;let d=document.createElement("button");d.className="malto-button",d.type="submit",d.textContent="Post comment",n.appendChild(s),n.appendChild(d),n.addEventListener("submit",async l=>{if(l.preventDefault(),!this.state.email){this.go("auth");return}d.setAttribute("disabled","true");try{await this.client.addComment(e.id,s.value.trim()),s.value="",await this.loadComments(e.id);}catch(m){this.state.error=m.message;}finally{d.removeAttribute("disabled"),this.render();}}),t.appendChild(n);}return t}skeletonList(t){let e=document.createElement("div");for(let a=0;a<t;a++){let r=document.createElement("div");r.className="malto-skeleton-row";let o=document.createElement("div");o.className="malto-skeleton",o.style.width="44px",o.style.height="48px",o.style.flex="none";let n=document.createElement("div");n.style.flex="1";let s=document.createElement("div");s.className="malto-skeleton",s.style.height="12px",s.style.width="70%",s.style.marginBottom="6px";let d=document.createElement("div");d.className="malto-skeleton",d.style.height="10px",d.style.width="90%",n.appendChild(s),n.appendChild(d),r.appendChild(o),r.appendChild(n),e.appendChild(r);}return e}emptyState(t,e,a){let r=document.createElement("div");r.className="malto-empty";let o=document.createElement("div");o.className="malto-empty-icon",o.style.fontSize="20px",o.textContent=t;let n=document.createElement("div");n.className="malto-empty-title",n.textContent=e;let s=document.createElement("div");return s.className="malto-empty-desc",s.textContent=a,r.appendChild(o),r.appendChild(n),r.appendChild(s),r}async loadFeedbacks(){this.state.loading=true,this.render();try{this.state.feedbacks=await this.client.listFeedbacks();}catch(t){this.state.error=t.message;}finally{this.state.loading=false,this.render();}}async loadRoadmap(){this.state.loading=true,this.render();try{this.state.roadmap=await this.client.roadmap();}catch(t){this.state.error=t.message;}finally{this.state.loading=false,this.render();}}async loadReleases(){this.state.loading=true,this.render();try{this.state.releases=await this.client.releases();}catch(t){this.state.error=t.message;}finally{this.state.loading=false,this.render();}}async loadComments(t){this.state.loading=true,this.render();try{this.state.comments=await this.client.comments(t);}catch(e){this.state.error=e.message;}finally{this.state.loading=false,this.render();}}async handleVote(t){if(!this.state.email){this.go("auth");return}try{let e=await this.client.vote(t.id);t.hasVoted=e.voted,t.votes=e.votes,this.render();}catch(e){this.state.error=e.message,this.render();}}};function K(i){let t=document.createElement("span");t.className=`malto-status malto-status-${i}`;let e=document.createElement("span");e.className="malto-status-dot",t.appendChild(e);let a=document.createElement("span"),r={PLANNED:"Planned",IN_PROGRESS:"In progress",COMPLETED:"Done",DECLINED:"Declined",UNDER_REVIEW:"Under review",BACKLOG:"Backlog"};return a.textContent=r[i]??i,t.appendChild(a),t}function _(i){return i<1e3?String(i):i<1e4?(i/1e3).toFixed(1).replace(/\.0$/,"")+"k":Math.floor(i/1e3)+"k"}function z(i){let t=Date.now()-new Date(i).getTime(),e=Math.floor(t/1e3);if(e<60)return "just now";let a=Math.floor(e/60);if(a<60)return `${a}m`;let r=Math.floor(a/60);if(r<24)return `${r}h`;let o=Math.floor(r/24);if(o<30)return `${o}d`;let n=Math.floor(o/30);return n<12?`${n}mo`:`${Math.floor(n/12)}y`}function Y(i){try{return new Date(i).toLocaleDateString(void 0,{day:"numeric",month:"short",year:"numeric"})}catch{return i}}function L(i){return i.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function $(i){if(!i||typeof i!="string")return null;let t;try{t=new URL(i,typeof location<"u"?location.href:"https://x");}catch{return null}return t.protocol!=="https:"&&t.protocol!=="http:"?null:t.toString()}var c=null;function rt(i){c&&c.unmount();let t=new v(i);return c=t,t.mount(),t}function nt(){c?.open();}function it(){c?.close();}function st(i){c?.setIdentify(i);}function lt(i){g(i.slice(0,16)),c?.setIdentify(null);}function dt(){c?.unmount(),c=null;}
|
|
607
|
-
exports.MaltoApiError=b;exports.MaltoClient=h;exports.MaltoWidget=v;exports.close=it;exports.destroy=dt;exports.identify=st;exports.init=
|
|
606
|
+
`}function D(i){let{r:t,g:e,b:a}=U(i);return {rgb:`${t}, ${e}, ${a}`,contrast:j(t,e,a),tint50:N(t,e,a,.06),tint100:N(t,e,a,.12),tint200:N(t,e,a,.18),shade600:V(t,e,a,-0.18)}}function U(i){let t=i.trim().replace(/^#/,"");return t.length===3&&(t=t.split("").map(e=>e+e).join("")),/^[0-9a-fA-F]{6}$/.test(t)?{r:parseInt(t.slice(0,2),16),g:parseInt(t.slice(2,4),16),b:parseInt(t.slice(4,6),16)}:{r:69,g:47,b:223}}function j(i,t,e){return (.2126*i+.7152*t+.0722*e)/255>.65?"#0f0d23":"#ffffff"}function N(i,t,e,a,o){return `rgba(${i}, ${t}, ${e}, ${a})`}function V(i,t,e,a){let o=n=>Math.max(0,Math.min(255,Math.round(n+255*a))),r=n=>o(n).toString(16).padStart(2,"0");return `#${r(i)}${r(t)}${r(e)}`}var q={"bottom-right":{right:"24px",bottom:"24px"},"bottom-left":{left:"24px",bottom:"24px"},"top-right":{right:"24px",top:"24px"},"top-left":{left:"24px",top:"24px"}},v=class{constructor(t){this.resolvedMode="bubble";this.root=null;this.container=null;this.trigger=null;this.board=null;if(!t.apiKey)throw new Error("Malto: apiKey is required");this.apiKeyPrefix=t.apiKey.slice(0,16),this.config={apiKey:t.apiKey,apiUrl:t.apiUrl??"https://malto-api-production.up.railway.app",mode:t.mode??"auto",position:t.position??"bottom-right",triggerLabel:t.triggerLabel??"Feedback",primaryColor:t.primaryColor,cssVars:t.cssVars,customCss:t.customCss,radius:t.radius??"md",appearance:t.appearance??"auto",zIndex:t.zIndex??2147483600,views:t.views,identify:t.identify,target:t.target,onReady:t.onReady,onError:t.onError};let e=E(this.apiKeyPrefix);this.state={open:false,view:"list",loading:false,error:null,feedbacks:[],roadmap:{},releases:[],selectedFeedback:null,comments:[],authEmail:"",authStatus:"idle",email:e?.email??null,name:e?.name??null},this.client=new h({apiKey:this.config.apiKey,apiUrl:this.config.apiUrl,getSessionToken:()=>E(this.apiKeyPrefix)?.token??null});}async mount(){try{let t=await this.client.board();this.board=t;let e=this.config.primaryColor||t.widget.primaryColor||t.board.boardThemeColor||"#452fdf";R({primary:e,cssVars:this.config.cssVars,customCss:this.config.customCss,radius:this.config.radius,appearance:this.config.appearance}),this.resolvedMode=this.config.mode==="auto"?t.widget.defaultMode:this.config.mode,this.config.identify&&await this.runIdentify(this.config.identify),this.renderHost(this.resolvedMode),this.config.onReady?.();}catch(t){this.config.onError?.(t);}}unmount(){this.root?.parentElement?.removeChild(this.root),this.trigger?.parentElement?.removeChild(this.trigger),this.root=null,this.trigger=null,this.container=null;}open(){this.state.open=true,this.render();}close(){this.state.open=false,this.render();}setIdentify(t){if(!t){g(this.apiKeyPrefix),this.state.email=null,this.state.name=null,this.render();return}this.runIdentify(t);}async runIdentify(t){try{let e=await this.client.identify(t);S(this.apiKeyPrefix,{token:e.sessionToken,expiresAt:e.expiresAt,email:e.user.email,name:e.user.name}),this.state.email=e.user.email,this.state.name=e.user.name,this.render();}catch(e){this.config.onError?.(e);}}renderHost(t){let e=document.createElement("div");if(e.className="malto-root",e.style.setProperty("--malto-z",String(this.config.zIndex)),document.body.appendChild(e),this.root=e,t==="inline"){let a=this.resolveTarget();if(!a){this.config.onError?.(new Error("Malto: inline target not found"));return}let o=document.createElement("div");o.className="malto-root malto-inline",o.style.setProperty("--malto-z",String(this.config.zIndex)),a.appendChild(o),this.container=o,this.state.open=true,this.render();return}if(t==="bubble"){let a=this.buildBubble(),o=q[this.config.position];Object.assign(a.style,o);let r=document.createElement("div");r.className="malto-root",r.style.setProperty("--malto-z",String(this.config.zIndex)),r.appendChild(a),document.body.appendChild(r),this.trigger=r;}else if(t==="trigger"){let a=this.resolveTarget();if(!a){this.config.onError?.(new Error("Malto: trigger target not found"));return}let o=document.createElement("span");o.className="malto-root",o.style.setProperty("--malto-z",String(this.config.zIndex));let r=document.createElement("button");r.className="malto-trigger",r.innerHTML=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.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><span>${L(this.config.triggerLabel)}</span>`,r.addEventListener("click",()=>this.open()),o.appendChild(r),a.appendChild(o),this.trigger=o;}else t==="modal"&&(this.state.open=true);this.render();}buildBubble(){let t=document.createElement("button");return t.className="malto-bubble",t.setAttribute("aria-label",this.config.triggerLabel),t.innerHTML='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.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>',t.addEventListener("click",()=>{this.state.open?this.close():this.open();}),t}resolveTarget(){return this.config.target?typeof this.config.target=="string"?document.querySelector(this.config.target):this.config.target:null}render(){if(!this.root)return;if(this.resolvedMode==="inline"){if(!this.container)return;this.container.innerHTML="",this.container.appendChild(this.buildPanelBody());return}if(this.root.innerHTML="",!this.state.open)return;let t=document.createElement("div");t.className="malto-overlay",t.addEventListener("click",a=>{a.target===t&&this.close();});let e=document.createElement("div");e.className="malto-modal",e.appendChild(this.buildPanelBody()),t.appendChild(e),this.root.appendChild(t);}buildPanelBody(){let t=document.createElement("div");t.style.display="flex",t.style.flexDirection="column",t.style.height="100%",t.style.minHeight="0",t.appendChild(this.buildHeader()),t.appendChild(this.buildTabs());let e=document.createElement("div");if(e.className="malto-body",e.appendChild(this.buildView()),t.appendChild(e),this.state.view!=="auth"&&!this.state.email){let a=document.createElement("div");a.className="malto-footer-banner";let o=document.createElement("span");o.innerHTML="Sign in to vote, comment, or submit ideas.";let r=document.createElement("button");r.className="malto-link",r.textContent="Sign in",r.addEventListener("click",()=>this.go("auth")),a.appendChild(o),a.appendChild(r),t.appendChild(a);}return t}buildHeader(){let t=document.createElement("div");t.className="malto-header";let e=document.createElement("div");e.className="malto-header-meta";let a=document.createElement("div");a.className="malto-board-logo";let o=$(this.board?.board.companyLogoUrl);if(o){let n=document.createElement("img");n.src=o,n.alt="",n.referrerPolicy="no-referrer",n.crossOrigin="anonymous",a.appendChild(n);}else a.textContent=(this.board?.board.companyName??this.board?.board.boardName??"M").charAt(0).toUpperCase();let r=document.createElement("h3");if(r.textContent=this.board?.board.boardName??this.board?.board.companyName??"Feedback",e.appendChild(a),e.appendChild(r),t.appendChild(e),this.resolvedMode!=="inline"){let n=document.createElement("button");n.className="malto-close",n.setAttribute("aria-label","Close"),n.innerHTML='<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',n.addEventListener("click",()=>this.close()),t.appendChild(n);}return t}buildTabs(){let t=document.createElement("div");t.className="malto-tabs";let e=this.allowedViews();return e.includes("list")&&t.appendChild(this.tabBtn("Feed","list")),e.includes("submit")&&t.appendChild(this.tabBtn("New","submit")),e.includes("roadmap")&&t.appendChild(this.tabBtn("Roadmap","roadmap")),e.includes("changelog")&&t.appendChild(this.tabBtn("Updates","changelog")),t}tabBtn(t,e){let a=document.createElement("button");return a.className="malto-tab",a.setAttribute("aria-selected",this.state.view===e?"true":"false"),a.textContent=t,a.addEventListener("click",()=>this.go(e)),a}go(t){this.state.view=t,this.state.error=null,this.render(),t==="list"&&this.loadFeedbacks(),t==="roadmap"&&this.loadRoadmap(),t==="changelog"&&this.loadReleases(),t==="detail"&&this.state.selectedFeedback&&this.loadComments(this.state.selectedFeedback.id);}allowedViews(){let t=this.board?.widget.enabledFeatures??["list","submit","vote","comment","roadmap","changelog"];return (this.config.views??["list","submit","roadmap","changelog"]).filter(a=>t.includes(a))}buildView(){let t=document.createElement("div");if(this.state.error){let e=document.createElement("div");e.className="malto-error",e.textContent=this.state.error,t.appendChild(e);}switch(this.state.view){case "list":t.appendChild(this.viewList()),this.state.feedbacks.length===0&&!this.state.loading&&this.loadFeedbacks();break;case "submit":t.appendChild(this.viewSubmit());break;case "auth":t.appendChild(this.viewAuth());break;case "roadmap":t.appendChild(this.viewRoadmap()),Object.keys(this.state.roadmap).length===0&&!this.state.loading&&this.loadRoadmap();break;case "changelog":t.appendChild(this.viewChangelog()),this.state.releases.length===0&&!this.state.loading&&this.loadReleases();break;case "detail":t.appendChild(this.viewDetail());break}return t}viewList(){let t=document.createElement("div");if(this.state.loading)return t.appendChild(this.skeletonList(4)),t;if(this.state.feedbacks.length===0)return t.appendChild(this.emptyState("\u{1F4A1}","No requests yet","Be the first to share an idea or report something.")),t;let e=document.createElement("div");e.className="malto-list";for(let a of this.state.feedbacks)e.appendChild(this.feedbackRow(a));return t.appendChild(e),t}feedbackRow(t){let e=document.createElement("div");e.className="malto-item";let a=document.createElement("button");a.className="malto-vote",a.setAttribute("aria-pressed",t.hasVoted?"true":"false");let o=document.createElement("span");o.className="malto-vote-arrow",o.textContent="\u25B2";let r=document.createElement("span");r.className="malto-vote-count",r.textContent=_(t.votes??0),a.appendChild(o),a.appendChild(r),a.addEventListener("click",m=>{m.stopPropagation(),this.handleVote(t);});let n=document.createElement("div");n.className="malto-item-content";let s=document.createElement("h4");if(s.textContent=t.title,n.appendChild(s),t.description){let m=document.createElement("p");m.textContent=t.description,n.appendChild(m);}let d=document.createElement("div");if(d.className="malto-item-meta",t.status&&t.status!=="BACKLOG"){let m=K(t.status);d.appendChild(m);}let l=document.createElement("span");return l.textContent=z(t.createdAt),d.appendChild(l),n.appendChild(d),e.appendChild(a),e.appendChild(n),e.addEventListener("click",()=>{this.state.selectedFeedback=t,this.go("detail");}),e}viewSubmit(){let t=document.createElement("form");t.className="malto-form";let e=document.createElement("input");e.className="malto-input",e.required=true,e.maxLength=200,e.placeholder="What would you like?";let a=document.createElement("textarea");a.className="malto-textarea",a.maxLength=5e3,a.placeholder="Add some context (optional)";let o=document.createElement("button");return o.className="malto-button",o.textContent="Submit feedback",o.type="submit",t.appendChild(e),t.appendChild(a),t.appendChild(o),t.addEventListener("submit",async r=>{if(r.preventDefault(),!this.state.email){this.go("auth");return}o.setAttribute("disabled","true");try{await this.client.createFeedback({title:e.value.trim(),description:a.value.trim()||void 0}),e.value="",a.value="",await this.loadFeedbacks(),this.go("list");}catch(n){this.state.error=n.message,o.removeAttribute("disabled"),this.render();}}),t}viewAuth(){let t=document.createElement("div");if(this.state.email){let n=document.createElement("p");n.style.fontSize="13px",n.style.color="var(--malto-text)",n.style.marginBottom="10px",n.innerHTML=`Signed in as <strong>${L(this.state.email)}</strong>`;let s=document.createElement("button");return s.className="malto-secondary",s.textContent="Sign out",s.addEventListener("click",()=>{g(this.apiKeyPrefix),this.state.email=null,this.state.name=null,this.go("list");}),t.appendChild(n),t.appendChild(s),t}if(this.state.authStatus==="sent"){let n=document.createElement("p");n.style.fontSize="13px",n.style.color="var(--malto-text)",n.style.marginBottom="12px",n.style.lineHeight="1.5",n.innerHTML=`We sent a sign-in link to <strong>${L(this.state.authEmail)}</strong>. Open the email and paste the token below.`;let s=document.createElement("input");s.className="malto-input",s.placeholder="Paste token from email";let d=document.createElement("button");d.className="malto-button",d.style.marginTop="8px",d.textContent="Verify",d.addEventListener("click",async()=>{d.setAttribute("disabled","true");try{let m=await this.client.verifyMagicLink(s.value.trim());S(this.apiKeyPrefix,{token:m.sessionToken,expiresAt:m.expiresAt,email:m.user.email,name:m.user.name}),this.state.email=m.user.email,this.state.name=m.user.name,this.state.authStatus="idle",this.go("list");}catch(m){this.state.error=m.message,d.removeAttribute("disabled"),this.render();}});let l=document.createElement("button");return l.className="malto-link",l.style.marginTop="12px",l.style.display="block",l.textContent="Use a different email",l.addEventListener("click",()=>{this.state.authStatus="idle",this.render();}),t.appendChild(n),t.appendChild(s),t.appendChild(d),t.appendChild(l),t}let e=document.createElement("form");e.className="malto-form";let a=document.createElement("p");a.style.fontSize="13px",a.style.color="var(--malto-text-muted)",a.style.marginBottom="4px",a.style.lineHeight="1.5",a.textContent="Enter your email to receive a one-click sign-in link.";let o=document.createElement("input");o.className="malto-input",o.type="email",o.required=true,o.placeholder="you@company.com",o.value=this.state.authEmail;let r=document.createElement("button");return r.className="malto-button",r.type="submit",r.textContent="Send sign-in link",e.appendChild(a),e.appendChild(o),e.appendChild(r),e.addEventListener("submit",async n=>{n.preventDefault(),r.setAttribute("disabled","true");try{await this.client.startMagicLink({email:o.value.trim()}),this.state.authEmail=o.value.trim(),this.state.authStatus="sent",this.render();}catch(s){this.state.error=s.message,r.removeAttribute("disabled"),this.render();}}),e}viewRoadmap(){let t=document.createElement("div");if(this.state.loading)return t.appendChild(this.skeletonList(3)),t;let e={PLANNED:"Planned",IN_PROGRESS:"In Progress",COMPLETED:"Done"},a=false;for(let o of ["PLANNED","IN_PROGRESS","COMPLETED"]){let r=this.state.roadmap[o]??[],n=document.createElement("div");n.className="malto-roadmap-col";let s=document.createElement("h5");s.textContent=e[o]??o;let d=document.createElement("span");if(d.className="malto-roadmap-count",d.textContent=String(r.length),s.appendChild(d),n.appendChild(s),r.length===0){let l=document.createElement("div");l.className="malto-empty-desc",l.style.padding="8px 0 12px",l.textContent="Nothing here yet.",n.appendChild(l);}else {a=true;for(let l of r)n.appendChild(this.feedbackRow(l));}t.appendChild(n);}return !a&&Object.keys(this.state.roadmap).length===0&&(t.innerHTML="",t.appendChild(this.emptyState("\u{1F5FA}\uFE0F","Empty roadmap","Once admins move items into Planned, In Progress or Done, you'll see them here."))),t}viewChangelog(){let t=document.createElement("div");if(this.state.loading)return t.appendChild(this.skeletonList(2)),t;if(this.state.releases.length===0)return t.appendChild(this.emptyState("\u2728","No updates yet","Check back soon.")),t;for(let e of this.state.releases){let a=document.createElement("div");if(a.className="malto-release",e.publishedAt){let n=document.createElement("span");n.className="malto-release-date",n.textContent=Y(e.publishedAt),a.appendChild(n);}let o=document.createElement("h4");o.textContent=e.title;let r=document.createElement("p");r.textContent=e.body,a.appendChild(o),a.appendChild(r),t.appendChild(a);}return t}viewDetail(){let t=document.createElement("div"),e=this.state.selectedFeedback;if(!e)return t.appendChild(this.emptyState("\u{1F4ED}","Nothing selected","Pick a request from Feed.")),t;let a=document.createElement("button");if(a.className="malto-back",a.innerHTML='<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 18 9 12 15 6"/></svg> Back',a.addEventListener("click",()=>this.go("list")),t.appendChild(a),t.appendChild(this.feedbackRow(e)),this.allowedViews().includes("comment")){let r=document.createElement("h5");if(r.textContent="Comments",r.style.cssText="margin: 16px 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--malto-text-muted); font-weight: 600;",t.appendChild(r),this.state.loading)t.appendChild(this.skeletonList(2));else if(this.state.comments.length===0){let l=document.createElement("div");l.className="malto-empty-desc",l.style.padding="8px 0 12px",l.textContent="No comments yet \u2014 start the conversation.",t.appendChild(l);}else for(let l of this.state.comments){let m=document.createElement("div");m.className="malto-comment";let f=document.createElement("div");f.className="malto-avatar";let M=$(l.author?.avatarUrl);if(M){let u=document.createElement("img");u.src=M,u.alt="",u.referrerPolicy="no-referrer",u.crossOrigin="anonymous",f.appendChild(u);}else f.textContent=(l.author?.name??"?").charAt(0).toUpperCase();let p=document.createElement("div");p.style.flex="1",p.style.minWidth="0";let y=document.createElement("div"),k=document.createElement("span");k.className="malto-comment-author",k.textContent=l.author?.name??"User";let w=document.createElement("span");w.className="malto-comment-time",w.textContent=z(l.createdAt),y.appendChild(k),y.appendChild(w);let C=document.createElement("div");C.className="malto-comment-body",C.textContent=l.body,p.appendChild(y),p.appendChild(C),m.appendChild(f),m.appendChild(p),t.appendChild(m);}let n=document.createElement("form");n.className="malto-form",n.style.marginTop="12px";let s=document.createElement("textarea");s.className="malto-textarea",s.placeholder="Write a comment",s.required=true;let d=document.createElement("button");d.className="malto-button",d.type="submit",d.textContent="Post comment",n.appendChild(s),n.appendChild(d),n.addEventListener("submit",async l=>{if(l.preventDefault(),!this.state.email){this.go("auth");return}d.setAttribute("disabled","true");try{await this.client.addComment(e.id,s.value.trim()),s.value="",await this.loadComments(e.id);}catch(m){this.state.error=m.message;}finally{d.removeAttribute("disabled"),this.render();}}),t.appendChild(n);}return t}skeletonList(t){let e=document.createElement("div");for(let a=0;a<t;a++){let o=document.createElement("div");o.className="malto-skeleton-row";let r=document.createElement("div");r.className="malto-skeleton",r.style.width="44px",r.style.height="48px",r.style.flex="none";let n=document.createElement("div");n.style.flex="1";let s=document.createElement("div");s.className="malto-skeleton",s.style.height="12px",s.style.width="70%",s.style.marginBottom="6px";let d=document.createElement("div");d.className="malto-skeleton",d.style.height="10px",d.style.width="90%",n.appendChild(s),n.appendChild(d),o.appendChild(r),o.appendChild(n),e.appendChild(o);}return e}emptyState(t,e,a){let o=document.createElement("div");o.className="malto-empty";let r=document.createElement("div");r.className="malto-empty-icon",r.style.fontSize="20px",r.textContent=t;let n=document.createElement("div");n.className="malto-empty-title",n.textContent=e;let s=document.createElement("div");return s.className="malto-empty-desc",s.textContent=a,o.appendChild(r),o.appendChild(n),o.appendChild(s),o}async loadFeedbacks(){this.state.loading=true,this.render();try{this.state.feedbacks=await this.client.listFeedbacks();}catch(t){this.state.error=t.message;}finally{this.state.loading=false,this.render();}}async loadRoadmap(){this.state.loading=true,this.render();try{this.state.roadmap=await this.client.roadmap();}catch(t){this.state.error=t.message;}finally{this.state.loading=false,this.render();}}async loadReleases(){this.state.loading=true,this.render();try{this.state.releases=await this.client.releases();}catch(t){this.state.error=t.message;}finally{this.state.loading=false,this.render();}}async loadComments(t){this.state.loading=true,this.render();try{this.state.comments=await this.client.comments(t);}catch(e){this.state.error=e.message;}finally{this.state.loading=false,this.render();}}async handleVote(t){if(!this.state.email){this.go("auth");return}try{let e=await this.client.vote(t.id);t.hasVoted=e.voted,t.votes=e.votes,this.render();}catch(e){this.state.error=e.message,this.render();}}};function K(i){let t=document.createElement("span");t.className=`malto-status malto-status-${i}`;let e=document.createElement("span");e.className="malto-status-dot",t.appendChild(e);let a=document.createElement("span"),o={PLANNED:"Planned",IN_PROGRESS:"In progress",COMPLETED:"Done",DECLINED:"Declined",UNDER_REVIEW:"Under review",BACKLOG:"Backlog"};return a.textContent=o[i]??i,t.appendChild(a),t}function _(i){return i<1e3?String(i):i<1e4?(i/1e3).toFixed(1).replace(/\.0$/,"")+"k":Math.floor(i/1e3)+"k"}function z(i){let t=Date.now()-new Date(i).getTime(),e=Math.floor(t/1e3);if(e<60)return "just now";let a=Math.floor(e/60);if(a<60)return `${a}m`;let o=Math.floor(a/60);if(o<24)return `${o}h`;let r=Math.floor(o/24);if(r<30)return `${r}d`;let n=Math.floor(r/30);return n<12?`${n}mo`:`${Math.floor(n/12)}y`}function Y(i){try{return new Date(i).toLocaleDateString(void 0,{day:"numeric",month:"short",year:"numeric"})}catch{return i}}function L(i){return i.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function $(i){if(!i||typeof i!="string")return null;let t;try{t=new URL(i,typeof location<"u"?location.href:"https://x");}catch{return null}return t.protocol!=="https:"&&t.protocol!=="http:"?null:t.toString()}var c=null;function ot(i){c&&c.unmount();let t=new v(i);return c=t,t.mount(),t}function nt(){c?.open();}function it(){c?.close();}function st(i){c?.setIdentify(i);}function lt(i){g(i.slice(0,16)),c?.setIdentify(null);}function dt(){c?.unmount(),c=null;}
|
|
607
|
+
exports.MaltoApiError=b;exports.MaltoClient=h;exports.MaltoWidget=v;exports.close=it;exports.destroy=dt;exports.identify=st;exports.init=ot;exports.open=nt;exports.reset=lt;return exports;})({});
|
package/package.json
CHANGED