@shiva004/surveys 0.1.7 → 0.1.8
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/App.d.ts +2 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +552 -0
- package/dist/journey/JourneyApp.d.ts +2 -0
- package/dist/journey/analytics.d.ts +29 -0
- package/dist/main.d.ts +1 -0
- package/dist/survey/SurveyApp.d.ts +2 -0
- package/dist/survey/data.d.ts +3 -0
- package/dist/survey/nps.d.ts +12 -0
- package/dist/types.d.ts +40 -0
- package/dist/ui.d.ts +26 -0
- package/package.json +18 -5
- package/dist/assets/index-BPe2owrS.js +0 -40
- package/dist/index.html +0 -13
- /package/dist/{assets/index-Chkvn1aI.css → style.css} +0 -0
package/dist/App.d.ts
ADDED
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),j=require("react"),b=({label:s,value:n,color:a="#7c3aed"})=>e.jsxs("div",{className:"stat",style:{borderTopColor:a},children:[e.jsx("div",{className:"stat-label",children:s}),e.jsx("div",{className:"stat-value",children:n})]}),O=({items:s,value:n,onChange:a})=>e.jsx("div",{className:"tabs",children:s.map(t=>e.jsx("button",{type:"button",className:t.id===n?"tab active":"tab",onClick:()=>a(t.id),children:t.label},t.id))}),N=({pct:s,color:n="#7c3aed"})=>e.jsx("div",{className:"bar",children:e.jsx("div",{className:"bar-fill",style:{width:`${Math.max(0,Math.min(100,s))}%`,background:n}})}),w=({title:s,subtitle:n,actions:a,children:t})=>e.jsxs("section",{children:[e.jsxs("div",{className:"page-head",children:[e.jsxs("div",{children:[e.jsx("h2",{children:s}),n&&e.jsx("p",{className:"muted",children:n})]}),e.jsx("div",{className:"actions",children:a})]}),t]}),E=s=>()=>{s|=0,s=s+1831565813|0;let n=Math.imul(s^s>>>15,1|s);return n=n+Math.imul(n^n>>>7,61|n)^n,((n^n>>>14)>>>0)/4294967296},y=s=>`${s}_${Math.random().toString(36).slice(2,8)}`,D=["/home","/pricing","/features","/docs","/signup","/dashboard","/checkout"],F=[["/home",.55],["/pricing",.15],["/features",.15],["/docs",.15]],B={"/home":[["/pricing",.3],["/features",.3],["/docs",.1],["/signup",.1],["EXIT",.2]],"/pricing":[["/signup",.3],["/features",.15],["/home",.1],["EXIT",.45]],"/features":[["/pricing",.3],["/signup",.15],["/docs",.15],["EXIT",.4]],"/docs":[["/features",.2],["/signup",.15],["/home",.1],["EXIT",.55]],"/signup":[["/dashboard",.6],["EXIT",.4]],"/dashboard":[["/checkout",.25],["/docs",.15],["/features",.1],["EXIT",.5]],"/checkout":[["EXIT",1]]},M=(s,n)=>{let a=0;for(const[t,l]of s)if(a+=l,n<a)return t;return s[s.length-1][0]};function P(s,n){return Array.from({length:s},()=>{let a=M(F,n());const t=[a];for(;t.length<8;){const l=M(B[a],n());if(l==="EXIT")break;t.push(l),a=l}return t})}const X=()=>P(400,E(42));function Q(s){const n=new Map,a=t=>(n.has(t)||n.set(t,{views:0,entries:0,bounces:0,exits:0}),n.get(t));for(const t of s)t.forEach(l=>{a(l).views+=1}),a(t[0]).entries+=1,t.length===1&&(a(t[0]).bounces+=1),a(t[t.length-1]).exits+=1;return[...n.entries()].map(([t,l])=>({page:t,views:l.views,bounceRate:l.entries?l.bounces/l.entries*100:0,exitRate:l.views?l.exits/l.views*100:0})).sort((t,l)=>l.views-t.views)}function L(s,n=8){const a=new Map;for(const t of s){const l=t.slice(0,4),h=l.join(">"),p=a.get(h)??{steps:l,users:0,conv:0};p.users+=1,t.includes("/signup")&&(p.conv+=1),a.set(h,p)}return[...a.values()].map(t=>({steps:t.steps,users:t.users,convRate:t.conv/t.users*100})).sort((t,l)=>l.users-t.users).slice(0,n)}function H(s){const n=new Map;for(const a of s)for(let t=0;t<a.length-1;t++){const l=n.get(a[t])??new Map;l.set(a[t+1],(l.get(a[t+1])??0)+1),n.set(a[t],l)}return[...n.entries()].map(([a,t])=>{const l=[...t.values()].reduce((h,p)=>h+p,0);return{from:a,total:l,destinations:[...t.entries()].map(([h,p])=>({to:h,pct:p/l*100})).sort((h,p)=>p.pct-h.pct)}}).sort((a,t)=>t.total-a.total)}const J=(s,n)=>s.length?s.filter(a=>a.some(t=>n.includes(t))).length/s.length*100:0,W={id:"jm1",name:"New customer journey",stages:[{id:"st1",name:"Awareness",emotion:"curious",pages:["/home"]},{id:"st2",name:"Consideration",emotion:"analytical",pages:["/pricing","/features"]},{id:"st3",name:"Sign up",emotion:"confident",pages:["/signup"]},{id:"st4",name:"Activation",emotion:"engaged",pages:["/dashboard"]},{id:"st5",name:"Purchase",emotion:"satisfied",pages:["/checkout"]}]},U=[{id:"nav",label:"Navigation Analysis"},{id:"paths",label:"Paths"},{id:"flows",label:"Userflows"},{id:"maps",label:"Journey Maps"}],A={curious:"#adc6ff",analytical:"#7c3aed",confident:"#4edea3",engaged:"#d2bbff",satisfied:"#ffcc6b",cautious:"#ffb4ab"},V=s=>s.split("/").filter(Boolean).pop()??s,G=s=>s>25?"#ffb4ab":s>15?"#ffcc6b":"#4edea3",Y=()=>{var o;const[s,n]=j.useState("nav"),[a,t]=j.useState(X),[l,h]=j.useState(W),p=j.useMemo(()=>Q(a),[a]),m=j.useMemo(()=>L(a),[a]),g=j.useMemo(()=>H(a),[a]),d=p.reduce((c,r)=>c+r.views,0),u=a.length,i=a.filter(c=>c.length===1).length;return e.jsxs(w,{title:"User Journey",subtitle:"One stream of page views feeds every view below.",actions:e.jsx("button",{className:"btn primary",onClick:()=>t(c=>[...c,...P(50,Math.random)]),children:"+ Simulate 50 sessions"}),children:[e.jsxs("div",{className:"stats",children:[e.jsx(b,{label:"Sessions",value:u.toLocaleString(),color:"#6366f1"}),e.jsx(b,{label:"Page views",value:d.toLocaleString(),color:"#0ea5e9"}),e.jsx(b,{label:"Bounce rate",value:`${u?(i/u*100).toFixed(1):0}%`,color:"#f59e0b"}),e.jsx(b,{label:"Top page",value:((o=p[0])==null?void 0:o.page)??"—",color:"#10b981"})]}),e.jsx(O,{items:U,value:s,onChange:n}),s==="nav"&&e.jsxs("table",{className:"table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Page"}),e.jsx("th",{children:"Views"}),e.jsx("th",{children:"Share"}),e.jsx("th",{children:"Bounce rate"}),e.jsx("th",{children:"Exit rate"})]})}),e.jsx("tbody",{children:p.map(c=>e.jsxs("tr",{children:[e.jsx("td",{className:"mono",children:c.page}),e.jsx("td",{className:"mono",children:c.views}),e.jsx("td",{style:{minWidth:120},children:e.jsx(N,{pct:c.views/d*100})}),e.jsxs("td",{className:"mono",style:{color:G(c.bounceRate)},children:[c.bounceRate.toFixed(1),"%"]}),e.jsxs("td",{className:"mono",children:[c.exitRate.toFixed(1),"%"]})]},c.page))})]}),s==="paths"&&e.jsx("div",{className:"grid",children:m.map((c,r)=>e.jsxs("div",{className:"card",children:[e.jsxs("div",{className:"row",children:[e.jsxs("span",{className:"pill passive",children:["#",r+1]}),e.jsx("span",{className:"grow"}),e.jsxs("span",{className:"mono small",children:[c.convRate.toFixed(1),"% reach signup"]})]}),e.jsx("div",{className:"steps",title:c.steps.join(" → "),children:c.steps.map((v,x)=>e.jsxs(j.Fragment,{children:[x>0&&e.jsx("span",{className:"muted",children:"→"}),e.jsx("span",{className:"chip static",children:V(v)})]},x))}),e.jsxs("div",{className:"small muted",children:[c.users," users"]}),e.jsx(N,{pct:c.convRate,color:"#10b981"})]},c.steps.join(">")))}),s==="flows"&&e.jsx("div",{className:"grid",children:g.map(c=>e.jsxs("div",{className:"card",children:[e.jsxs("div",{className:"row",children:[e.jsx("strong",{className:"mono",children:c.from}),e.jsx("span",{className:"grow"}),e.jsxs("span",{className:"small muted",children:[c.total," transitions"]})]}),c.destinations.slice(0,4).map(r=>e.jsxs("div",{children:[e.jsxs("div",{className:"row small",children:[e.jsxs("span",{className:"mono",children:["→ ",r.to]}),e.jsx("span",{className:"grow"}),e.jsxs("span",{className:"mono",children:[r.pct.toFixed(0),"%"]})]}),e.jsx(N,{pct:r.pct})]},r.to))]},c.from))}),s==="maps"&&e.jsx(z,{map:l,setMap:h,sessions:a})]})},z=({map:s,setMap:n,sessions:a})=>{const[t,l]=j.useState(""),[h,p]=j.useState("curious"),[m,g]=j.useState([]),[d,u]=j.useState(""),i=()=>{if(!t.trim())return u("Stage name is required.");if(m.length===0)return u("Pick at least one touchpoint page.");const o={id:y("st"),name:t.trim(),emotion:h,pages:m};n({...s,stages:[...s.stages,o]}),l(""),g([]),u("")};return e.jsxs("div",{className:"stack",children:[e.jsx("input",{className:"input",value:s.name,onChange:o=>n({...s,name:o.target.value}),"aria-label":"Journey name"}),e.jsxs("div",{className:"stages",children:[s.stages.map((o,c)=>{const r=J(a,o.pages),v=A[o.emotion]??"#7c3aed";return e.jsxs("div",{className:"card stage",children:[e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"badge",style:{background:`${v}30`,color:v},children:c+1}),e.jsx("strong",{children:o.name}),e.jsx("span",{className:"grow"}),e.jsx("button",{className:"btn danger","aria-label":`Remove ${o.name}`,onClick:()=>n({...s,stages:s.stages.filter(x=>x.id!==o.id)}),children:"✕"})]}),o.pages.map(x=>e.jsxs("div",{className:"small mono muted",children:["✓ ",x]},x)),e.jsxs("div",{className:"small",style:{color:v},children:["Emotion: ",o.emotion]}),e.jsx(N,{pct:r}),e.jsxs("div",{className:"small mono muted",children:[r.toFixed(0),"% reach"]})]},o.id)}),s.stages.length===0&&e.jsx("div",{className:"muted",children:"No stages yet. Add one below."})]}),e.jsxs("div",{className:"card form",children:[e.jsx("strong",{children:"Add stage"}),e.jsxs("div",{className:"row",children:[e.jsx("input",{className:"input",placeholder:"Stage name",value:t,onChange:o=>l(o.target.value)}),e.jsx("select",{className:"input slim",value:h,onChange:o=>p(o.target.value),children:Object.keys(A).map(o=>e.jsx("option",{children:o},o))})]}),e.jsx("div",{className:"scale",children:D.map(o=>e.jsx("button",{type:"button",className:m.includes(o)?"chip active":"chip",onClick:()=>g(c=>c.includes(o)?c.filter(r=>r!==o):[...c,o]),children:o},o))}),e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"grow"}),d&&e.jsx("span",{className:"error",children:d}),e.jsx("button",{className:"btn primary",onClick:i,children:"+ Add stage"})]})]})]})},C=s=>new Date(Date.UTC(2026,10,6)-s*864e5).toISOString(),K=[{id:"s1",name:"Q4 Product Satisfaction",description:"How do users feel about the product right now?",status:"active",target:100,createdAt:C(30),questions:[{id:"s1q1",type:"nps",text:"How likely are you to recommend us to a colleague?",required:!0},{id:"s1q2",type:"rating",text:"How satisfied are you with the product?",required:!0},{id:"s1q3",type:"multiple_choice",text:"Which feature do you use most?",required:!1,options:["Feature Flags","Experiments","Segments","Audit Log"]},{id:"s1q4",type:"open_text",text:"What is one thing we should improve?",required:!1}]},{id:"s2",name:"Onboarding Experience",description:"First-week feedback from new accounts.",status:"draft",target:50,createdAt:C(5),questions:[{id:"s2q1",type:"nps",text:"How likely are you to recommend our onboarding?",required:!0},{id:"s2q2",type:"open_text",text:"What was confusing?",required:!1}]}],T=["Love the rollout controls","Dashboards load slowly","Needs better docs","Great support","Too many clicks to create a flag"];function Z(){const s=E(7);return Array.from({length:36},(n,a)=>{const t=Math.min(10,Math.floor(s()*s()*4+s()*8+3));return{id:`r${a}`,surveyId:"s1",userId:`user_${100+a}`,createdAt:C(Math.floor(s()*28)),answers:[{questionId:"s1q1",value:t},{questionId:"s1q2",value:Math.max(1,Math.min(5,Math.round(t/2)))},{questionId:"s1q3",value:["Feature Flags","Experiments","Segments","Audit Log"][Math.floor(s()*4)]},{questionId:"s1q4",value:T[Math.floor(s()*T.length)]}]}})}const I=s=>s>=9?"promoter":s>=7?"passive":"detractor";function S(s){if(s.length===0)return null;const n=s.filter(t=>t>=9).length,a=s.filter(t=>t<=6).length;return{score:Math.round((n-a)/s.length*100),promoters:n,passives:s.length-n-a,detractors:a,total:s.length}}function k(s,n){const a=s.questions.find(t=>t.type==="nps");return a?n.filter(t=>t.surveyId===s.id).map(t=>{var l;return(l=t.answers.find(h=>h.questionId===a.id))==null?void 0:l.value}).filter(t=>typeof t=="number"):[]}const ee=["nps","rating","multiple_choice","open_text"],R=s=>new Date(s).toLocaleDateString(void 0,{day:"2-digit",month:"short",year:"numeric"}),se=()=>{const[s,n]=j.useState(K),[a,t]=j.useState(Z),[l,h]=j.useState({name:"list"}),p=i=>s.find(o=>o.id===i),m=()=>h({name:"list"});if(l.name==="create")return e.jsx(te,{onCancel:m,onSave:i=>{n(o=>[i,...o]),m()}});if(l.name==="take"){const i=p(l.id);return i?e.jsx(ae,{survey:i,onCancel:m,onSubmit:o=>{t(c=>[{id:y("r"),surveyId:i.id,userId:`user_${900+c.length}`,createdAt:new Date().toISOString(),answers:o},...c]),h({name:"results",id:i.id})}}):null}if(l.name==="results"){const i=p(l.id);return i?e.jsx(ne,{survey:i,responses:a.filter(o=>o.surveyId===i.id),onBack:m,onTake:()=>h({name:"take",id:i.id})}):null}const g=a.length,d=s.filter(i=>i.status==="active").length,u=S(s.flatMap(i=>k(i,a)));return e.jsxs(w,{title:"Surveys",subtitle:"Create, run and measure user surveys.",actions:e.jsx("button",{className:"btn primary",onClick:()=>h({name:"create"}),children:"+ Create Survey"}),children:[e.jsxs("div",{className:"stats",children:[e.jsx(b,{label:"Total surveys",value:s.length,color:"#6366f1"}),e.jsx(b,{label:"Active",value:d,color:"#10b981"}),e.jsx(b,{label:"Total responses",value:g}),e.jsx(b,{label:"Overall NPS",value:u?u.score:"—",color:"#f59e0b"})]}),e.jsxs("table",{className:"table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Survey"}),e.jsx("th",{children:"Status"}),e.jsx("th",{children:"Progress"}),e.jsx("th",{children:"NPS"}),e.jsx("th",{children:"Created"}),e.jsx("th",{})]})}),e.jsx("tbody",{children:s.map(i=>{const o=a.filter(r=>r.surveyId===i.id).length,c=S(k(i,a));return e.jsxs("tr",{children:[e.jsxs("td",{children:[e.jsx("strong",{children:i.name}),e.jsxs("div",{className:"muted small",children:[i.questions.length," questions"]})]}),e.jsx("td",{children:e.jsx("select",{className:"input slim",value:i.status,onChange:r=>n(v=>v.map(x=>x.id===i.id?{...x,status:r.target.value}:x)),children:["draft","active","paused","closed"].map(r=>e.jsx("option",{children:r},r))})}),e.jsxs("td",{style:{minWidth:140},children:[e.jsxs("div",{className:"small mono",children:[o," / ",i.target]}),e.jsx(N,{pct:o/i.target*100})]}),e.jsx("td",{className:"mono",children:c?c.score:"—"}),e.jsx("td",{className:"muted small",children:R(i.createdAt)}),e.jsxs("td",{className:"right",children:[e.jsx("button",{className:"btn",onClick:()=>h({name:"results",id:i.id}),children:"Results"})," ",e.jsx("button",{className:"btn",disabled:i.status!=="active",title:i.status!=="active"?"Set status to active to collect answers":"",onClick:()=>h({name:"take",id:i.id}),children:"Take"})," ",e.jsx("button",{className:"btn danger",onClick:()=>{window.confirm(`Delete "${i.name}" and its responses?`)&&(n(r=>r.filter(v=>v.id!==i.id)),t(r=>r.filter(v=>v.surveyId!==i.id)))},children:"Delete"})]})]},i.id)})})]})]})},te=({onSave:s,onCancel:n})=>{const[a,t]=j.useState(""),[l,h]=j.useState(""),[p,m]=j.useState(100),[g,d]=j.useState([{id:y("q"),type:"nps",text:"How likely are you to recommend us?",required:!0}]),[u,i]=j.useState(""),o=(r,v)=>d(x=>x.map(f=>f.id===r?{...f,...v}:f)),c=()=>{if(!a.trim())return i("Survey name is required.");if(g.length===0)return i("Add at least one question.");if(g.some(r=>!r.text.trim()))return i("Every question needs text.");if(g.some(r=>r.type==="multiple_choice"&&(r.options??[]).filter(v=>v.trim()).length<2))return i("Multiple choice needs at least two options.");s({id:y("s"),name:a.trim(),description:l.trim(),status:"active",target:p,createdAt:new Date().toISOString(),questions:g.map(r=>({...r,text:r.text.trim(),options:r.type==="multiple_choice"?(r.options??[]).filter(v=>v.trim()):void 0}))})};return e.jsxs(w,{title:"Create Survey",subtitle:"Build a new survey.",actions:e.jsx("button",{className:"btn",onClick:n,children:"Back"}),children:[e.jsxs("div",{className:"card form",children:[e.jsxs("label",{children:["Name",e.jsx("input",{className:"input",value:a,onChange:r=>t(r.target.value),placeholder:"e.g. Q1 Product Satisfaction"})]}),e.jsxs("label",{children:["Description",e.jsx("input",{className:"input",value:l,onChange:r=>h(r.target.value)})]}),e.jsxs("label",{children:["Target responses",e.jsx("input",{className:"input narrow",type:"number",min:1,value:p,onChange:r=>m(Math.max(1,parseInt(r.target.value,10)||1))})]})]}),e.jsxs("h3",{children:["Questions (",g.length,")"]}),g.map((r,v)=>e.jsxs("div",{className:"card form",children:[e.jsxs("div",{className:"row",children:[e.jsxs("strong",{children:["Q",v+1]}),e.jsx("select",{className:"input slim",value:r.type,onChange:x=>o(r.id,{type:x.target.value,options:x.target.value==="multiple_choice"?["Option 1","Option 2"]:void 0}),children:ee.map(x=>e.jsx("option",{value:x,children:x.replace("_"," ")},x))}),e.jsxs("label",{className:"inline",children:[e.jsx("input",{type:"checkbox",checked:r.required,onChange:x=>o(r.id,{required:x.target.checked})})," required"]}),e.jsx("span",{className:"grow"}),e.jsx("button",{className:"btn danger",onClick:()=>d(x=>x.filter(f=>f.id!==r.id)),children:"Remove"})]}),e.jsx("input",{className:"input",value:r.text,onChange:x=>o(r.id,{text:x.target.value}),placeholder:"Enter your question…"}),r.type==="multiple_choice"&&e.jsxs("div",{className:"stack",children:[(r.options??[]).map((x,f)=>e.jsx("input",{className:"input slim",value:x,onChange:_=>o(r.id,{options:(r.options??[]).map(($,q)=>q===f?_.target.value:$)})},f)),e.jsx("button",{className:"btn",onClick:()=>o(r.id,{options:[...r.options??[],`Option ${(r.options??[]).length+1}`]}),children:"+ Add option"})]})]},r.id)),e.jsxs("div",{className:"row",children:[e.jsx("button",{className:"btn",onClick:()=>d(r=>[...r,{id:y("q"),type:"rating",text:"",required:!1}]),children:"+ Add question"}),e.jsx("span",{className:"grow"}),u&&e.jsx("span",{className:"error",children:u}),e.jsx("button",{className:"btn primary",onClick:c,children:"Create Survey"})]})]})},ae=({survey:s,onSubmit:n,onCancel:a})=>{const[t,l]=j.useState({}),[h,p]=j.useState(""),m=(d,u)=>l(i=>({...i,[d]:u})),g=()=>{const d=s.questions.find(u=>u.required&&(t[u.id]===void 0||t[u.id]===""));if(d)return p(`"${d.text}" is required.`);p(""),n(s.questions.filter(u=>t[u.id]!==void 0&&t[u.id]!=="").map(u=>({questionId:u.id,value:t[u.id]})))};return e.jsxs(w,{title:s.name,subtitle:s.description||"Answer the questions below.",actions:e.jsx("button",{className:"btn",onClick:a,children:"Cancel"}),children:[s.questions.map((d,u)=>e.jsxs("div",{className:"card form",children:[e.jsxs("strong",{children:[u+1,". ",d.text,d.required&&e.jsx("span",{className:"error",children:" *"})]}),d.type==="nps"&&e.jsx("div",{className:"scale",children:Array.from({length:11},(i,o)=>e.jsx("button",{className:t[d.id]===o?"chip active":"chip",onClick:()=>m(d.id,o),children:o},o))}),d.type==="rating"&&e.jsx("div",{className:"scale",children:[1,2,3,4,5].map(i=>e.jsxs("button",{className:t[d.id]===i?"chip active":"chip",onClick:()=>m(d.id,i),children:[i," ★"]},i))}),d.type==="multiple_choice"&&e.jsx("div",{className:"scale",children:(d.options??[]).map(i=>e.jsx("button",{className:t[d.id]===i?"chip active":"chip",onClick:()=>m(d.id,i),children:i},i))}),d.type==="open_text"&&e.jsx("textarea",{className:"input",rows:2,value:String(t[d.id]??""),onChange:i=>m(d.id,i.target.value)})]},d.id)),e.jsxs("div",{className:"row",children:[e.jsx("span",{className:"grow"}),h&&e.jsx("span",{className:"error",children:h}),e.jsx("button",{className:"btn primary",onClick:g,children:"Submit response"})]})]})},ne=({survey:s,responses:n,onBack:a,onTake:t})=>{const l=j.useMemo(()=>S(k(s,n)),[s,n]),h=s.questions.find(m=>m.type==="nps"),p=m=>l?Math.round(m/l.total*100):0;return e.jsxs(w,{title:s.name,subtitle:`${n.length} responses`,actions:e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"btn",onClick:a,children:"Back"}),e.jsx("button",{className:"btn primary",disabled:s.status!=="active",onClick:t,children:"Take survey"})]}),children:[e.jsxs("div",{className:"stats",children:[e.jsx(b,{label:"NPS",value:l?l.score:"—",color:"#f59e0b"}),e.jsx(b,{label:"Promoters",value:l?`${p(l.promoters)}%`:"—",color:"#4edea3"}),e.jsx(b,{label:"Passives",value:l?`${p(l.passives)}%`:"—",color:"#ffcc6b"}),e.jsx(b,{label:"Detractors",value:l?`${p(l.detractors)}%`:"—",color:"#ffb4ab"})]}),e.jsxs("table",{className:"table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"User"}),e.jsx("th",{children:"NPS"}),s.questions.filter(m=>m.type!=="nps").map(m=>e.jsx("th",{children:m.text},m.id)),e.jsx("th",{children:"Date"})]})}),e.jsxs("tbody",{children:[n.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:9,className:"muted",children:"No responses yet."})}),n.map(m=>{var d;const g=h?(d=m.answers.find(u=>u.questionId===h.id))==null?void 0:d.value:void 0;return e.jsxs("tr",{children:[e.jsx("td",{className:"mono",children:m.userId}),e.jsx("td",{children:typeof g=="number"?e.jsxs("span",{className:`pill ${I(g)}`,children:[g," · ",I(g)]}):"—"}),s.questions.filter(u=>u.type!=="nps").map(u=>{var i;return e.jsx("td",{children:String(((i=m.answers.find(o=>o.questionId===u.id))==null?void 0:i.value)??"—")},u.id)}),e.jsx("td",{className:"muted small",children:R(m.createdAt)})]},m.id)})]})]})]})};exports.JourneyApp=Y;exports.SurveyApp=se;exports.npsCategory=I;exports.npsOf=S;exports.npsScores=k;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,552 @@
|
|
|
1
|
+
import { jsxs as n, jsx as e, Fragment as B } from "react/jsx-runtime";
|
|
2
|
+
import X, { useState as N, useMemo as x } from "react";
|
|
3
|
+
const y = ({ label: t, value: i, color: a = "#7c3aed" }) => /* @__PURE__ */ n("div", { className: "stat", style: { borderTopColor: a }, children: [
|
|
4
|
+
/* @__PURE__ */ e("div", { className: "stat-label", children: t }),
|
|
5
|
+
/* @__PURE__ */ e("div", { className: "stat-value", children: i })
|
|
6
|
+
] }), j = ({ items: t, value: i, onChange: a }) => /* @__PURE__ */ e("div", { className: "tabs", children: t.map((s) => /* @__PURE__ */ e("button", { type: "button", className: s.id === i ? "tab active" : "tab", onClick: () => a(s.id), children: s.label }, s.id)) }), S = ({ pct: t, color: i = "#7c3aed" }) => /* @__PURE__ */ e("div", { className: "bar", children: /* @__PURE__ */ e("div", { className: "bar-fill", style: { width: `${Math.max(0, Math.min(100, t))}%`, background: i } }) }), C = ({ title: t, subtitle: i, actions: a, children: s }) => /* @__PURE__ */ n("section", { children: [
|
|
7
|
+
/* @__PURE__ */ n("div", { className: "page-head", children: [
|
|
8
|
+
/* @__PURE__ */ n("div", { children: [
|
|
9
|
+
/* @__PURE__ */ e("h2", { children: t }),
|
|
10
|
+
i && /* @__PURE__ */ e("p", { className: "muted", children: i })
|
|
11
|
+
] }),
|
|
12
|
+
/* @__PURE__ */ e("div", { className: "actions", children: a })
|
|
13
|
+
] }),
|
|
14
|
+
s
|
|
15
|
+
] }), _ = (t) => () => {
|
|
16
|
+
t |= 0, t = t + 1831565813 | 0;
|
|
17
|
+
let i = Math.imul(t ^ t >>> 15, 1 | t);
|
|
18
|
+
return i = i + Math.imul(i ^ i >>> 7, 61 | i) ^ i, ((i ^ i >>> 14) >>> 0) / 4294967296;
|
|
19
|
+
}, k = (t) => `${t}_${Math.random().toString(36).slice(2, 8)}`, Q = ["/home", "/pricing", "/features", "/docs", "/signup", "/dashboard", "/checkout"], L = [["/home", 0.55], ["/pricing", 0.15], ["/features", 0.15], ["/docs", 0.15]], H = {
|
|
20
|
+
"/home": [["/pricing", 0.3], ["/features", 0.3], ["/docs", 0.1], ["/signup", 0.1], ["EXIT", 0.2]],
|
|
21
|
+
"/pricing": [["/signup", 0.3], ["/features", 0.15], ["/home", 0.1], ["EXIT", 0.45]],
|
|
22
|
+
"/features": [["/pricing", 0.3], ["/signup", 0.15], ["/docs", 0.15], ["EXIT", 0.4]],
|
|
23
|
+
"/docs": [["/features", 0.2], ["/signup", 0.15], ["/home", 0.1], ["EXIT", 0.55]],
|
|
24
|
+
"/signup": [["/dashboard", 0.6], ["EXIT", 0.4]],
|
|
25
|
+
"/dashboard": [["/checkout", 0.25], ["/docs", 0.15], ["/features", 0.1], ["EXIT", 0.5]],
|
|
26
|
+
"/checkout": [["EXIT", 1]]
|
|
27
|
+
}, T = (t, i) => {
|
|
28
|
+
let a = 0;
|
|
29
|
+
for (const [s, o] of t)
|
|
30
|
+
if (a += o, i < a) return s;
|
|
31
|
+
return t[t.length - 1][0];
|
|
32
|
+
};
|
|
33
|
+
function $(t, i) {
|
|
34
|
+
return Array.from({ length: t }, () => {
|
|
35
|
+
let a = T(L, i());
|
|
36
|
+
const s = [a];
|
|
37
|
+
for (; s.length < 8; ) {
|
|
38
|
+
const o = T(H[a], i());
|
|
39
|
+
if (o === "EXIT") break;
|
|
40
|
+
s.push(o), a = o;
|
|
41
|
+
}
|
|
42
|
+
return s;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const W = () => $(400, _(42));
|
|
46
|
+
function J(t) {
|
|
47
|
+
const i = /* @__PURE__ */ new Map(), a = (s) => (i.has(s) || i.set(s, { views: 0, entries: 0, bounces: 0, exits: 0 }), i.get(s));
|
|
48
|
+
for (const s of t)
|
|
49
|
+
s.forEach((o) => {
|
|
50
|
+
a(o).views += 1;
|
|
51
|
+
}), a(s[0]).entries += 1, s.length === 1 && (a(s[0]).bounces += 1), a(s[s.length - 1]).exits += 1;
|
|
52
|
+
return [...i.entries()].map(([s, o]) => ({
|
|
53
|
+
page: s,
|
|
54
|
+
views: o.views,
|
|
55
|
+
bounceRate: o.entries ? o.bounces / o.entries * 100 : 0,
|
|
56
|
+
exitRate: o.views ? o.exits / o.views * 100 : 0
|
|
57
|
+
})).sort((s, o) => o.views - s.views);
|
|
58
|
+
}
|
|
59
|
+
function U(t, i = 8) {
|
|
60
|
+
const a = /* @__PURE__ */ new Map();
|
|
61
|
+
for (const s of t) {
|
|
62
|
+
const o = s.slice(0, 4), p = o.join(">"), g = a.get(p) ?? { steps: o, users: 0, conv: 0 };
|
|
63
|
+
g.users += 1, s.includes("/signup") && (g.conv += 1), a.set(p, g);
|
|
64
|
+
}
|
|
65
|
+
return [...a.values()].map((s) => ({ steps: s.steps, users: s.users, convRate: s.conv / s.users * 100 })).sort((s, o) => o.users - s.users).slice(0, i);
|
|
66
|
+
}
|
|
67
|
+
function V(t) {
|
|
68
|
+
const i = /* @__PURE__ */ new Map();
|
|
69
|
+
for (const a of t)
|
|
70
|
+
for (let s = 0; s < a.length - 1; s++) {
|
|
71
|
+
const o = i.get(a[s]) ?? /* @__PURE__ */ new Map();
|
|
72
|
+
o.set(a[s + 1], (o.get(a[s + 1]) ?? 0) + 1), i.set(a[s], o);
|
|
73
|
+
}
|
|
74
|
+
return [...i.entries()].map(([a, s]) => {
|
|
75
|
+
const o = [...s.values()].reduce((p, g) => p + g, 0);
|
|
76
|
+
return {
|
|
77
|
+
from: a,
|
|
78
|
+
total: o,
|
|
79
|
+
destinations: [...s.entries()].map(([p, g]) => ({ to: p, pct: g / o * 100 })).sort((p, g) => g.pct - p.pct)
|
|
80
|
+
};
|
|
81
|
+
}).sort((a, s) => s.total - a.total);
|
|
82
|
+
}
|
|
83
|
+
const G = (t, i) => t.length ? t.filter((a) => a.some((s) => i.includes(s))).length / t.length * 100 : 0, Y = {
|
|
84
|
+
id: "jm1",
|
|
85
|
+
name: "New customer journey",
|
|
86
|
+
stages: [
|
|
87
|
+
{ id: "st1", name: "Awareness", emotion: "curious", pages: ["/home"] },
|
|
88
|
+
{ id: "st2", name: "Consideration", emotion: "analytical", pages: ["/pricing", "/features"] },
|
|
89
|
+
{ id: "st3", name: "Sign up", emotion: "confident", pages: ["/signup"] },
|
|
90
|
+
{ id: "st4", name: "Activation", emotion: "engaged", pages: ["/dashboard"] },
|
|
91
|
+
{ id: "st5", name: "Purchase", emotion: "satisfied", pages: ["/checkout"] }
|
|
92
|
+
]
|
|
93
|
+
}, z = [
|
|
94
|
+
{ id: "nav", label: "Navigation Analysis" },
|
|
95
|
+
{ id: "paths", label: "Paths" },
|
|
96
|
+
{ id: "flows", label: "Userflows" },
|
|
97
|
+
{ id: "maps", label: "Journey Maps" }
|
|
98
|
+
], E = { curious: "#adc6ff", analytical: "#7c3aed", confident: "#4edea3", engaged: "#d2bbff", satisfied: "#ffcc6b", cautious: "#ffb4ab" }, K = (t) => t.split("/").filter(Boolean).pop() ?? t, Z = (t) => t > 25 ? "#ffb4ab" : t > 15 ? "#ffcc6b" : "#4edea3", ce = () => {
|
|
99
|
+
var c;
|
|
100
|
+
const [t, i] = N("nav"), [a, s] = N(W), [o, p] = N(Y), g = x(() => J(a), [a]), h = x(() => U(a), [a]), f = x(() => V(a), [a]), u = g.reduce((d, l) => d + l.views, 0), m = a.length, r = a.filter((d) => d.length === 1).length;
|
|
101
|
+
return /* @__PURE__ */ n(
|
|
102
|
+
C,
|
|
103
|
+
{
|
|
104
|
+
title: "User Journey",
|
|
105
|
+
subtitle: "One stream of page views feeds every view below.",
|
|
106
|
+
actions: /* @__PURE__ */ e("button", { className: "btn primary", onClick: () => s((d) => [...d, ...$(50, Math.random)]), children: "+ Simulate 50 sessions" }),
|
|
107
|
+
children: [
|
|
108
|
+
/* @__PURE__ */ n("div", { className: "stats", children: [
|
|
109
|
+
/* @__PURE__ */ e(y, { label: "Sessions", value: m.toLocaleString(), color: "#6366f1" }),
|
|
110
|
+
/* @__PURE__ */ e(y, { label: "Page views", value: u.toLocaleString(), color: "#0ea5e9" }),
|
|
111
|
+
/* @__PURE__ */ e(y, { label: "Bounce rate", value: `${m ? (r / m * 100).toFixed(1) : 0}%`, color: "#f59e0b" }),
|
|
112
|
+
/* @__PURE__ */ e(y, { label: "Top page", value: ((c = g[0]) == null ? void 0 : c.page) ?? "—", color: "#10b981" })
|
|
113
|
+
] }),
|
|
114
|
+
/* @__PURE__ */ e(j, { items: z, value: t, onChange: i }),
|
|
115
|
+
t === "nav" && /* @__PURE__ */ n("table", { className: "table", children: [
|
|
116
|
+
/* @__PURE__ */ e("thead", { children: /* @__PURE__ */ n("tr", { children: [
|
|
117
|
+
/* @__PURE__ */ e("th", { children: "Page" }),
|
|
118
|
+
/* @__PURE__ */ e("th", { children: "Views" }),
|
|
119
|
+
/* @__PURE__ */ e("th", { children: "Share" }),
|
|
120
|
+
/* @__PURE__ */ e("th", { children: "Bounce rate" }),
|
|
121
|
+
/* @__PURE__ */ e("th", { children: "Exit rate" })
|
|
122
|
+
] }) }),
|
|
123
|
+
/* @__PURE__ */ e("tbody", { children: g.map((d) => /* @__PURE__ */ n("tr", { children: [
|
|
124
|
+
/* @__PURE__ */ e("td", { className: "mono", children: d.page }),
|
|
125
|
+
/* @__PURE__ */ e("td", { className: "mono", children: d.views }),
|
|
126
|
+
/* @__PURE__ */ e("td", { style: { minWidth: 120 }, children: /* @__PURE__ */ e(S, { pct: d.views / u * 100 }) }),
|
|
127
|
+
/* @__PURE__ */ n("td", { className: "mono", style: { color: Z(d.bounceRate) }, children: [
|
|
128
|
+
d.bounceRate.toFixed(1),
|
|
129
|
+
"%"
|
|
130
|
+
] }),
|
|
131
|
+
/* @__PURE__ */ n("td", { className: "mono", children: [
|
|
132
|
+
d.exitRate.toFixed(1),
|
|
133
|
+
"%"
|
|
134
|
+
] })
|
|
135
|
+
] }, d.page)) })
|
|
136
|
+
] }),
|
|
137
|
+
t === "paths" && /* @__PURE__ */ e("div", { className: "grid", children: h.map((d, l) => /* @__PURE__ */ n("div", { className: "card", children: [
|
|
138
|
+
/* @__PURE__ */ n("div", { className: "row", children: [
|
|
139
|
+
/* @__PURE__ */ n("span", { className: "pill passive", children: [
|
|
140
|
+
"#",
|
|
141
|
+
l + 1
|
|
142
|
+
] }),
|
|
143
|
+
/* @__PURE__ */ e("span", { className: "grow" }),
|
|
144
|
+
/* @__PURE__ */ n("span", { className: "mono small", children: [
|
|
145
|
+
d.convRate.toFixed(1),
|
|
146
|
+
"% reach signup"
|
|
147
|
+
] })
|
|
148
|
+
] }),
|
|
149
|
+
/* @__PURE__ */ e("div", { className: "steps", title: d.steps.join(" → "), children: d.steps.map((b, v) => /* @__PURE__ */ n(X.Fragment, { children: [
|
|
150
|
+
v > 0 && /* @__PURE__ */ e("span", { className: "muted", children: "→" }),
|
|
151
|
+
/* @__PURE__ */ e("span", { className: "chip static", children: K(b) })
|
|
152
|
+
] }, v)) }),
|
|
153
|
+
/* @__PURE__ */ n("div", { className: "small muted", children: [
|
|
154
|
+
d.users,
|
|
155
|
+
" users"
|
|
156
|
+
] }),
|
|
157
|
+
/* @__PURE__ */ e(S, { pct: d.convRate, color: "#10b981" })
|
|
158
|
+
] }, d.steps.join(">"))) }),
|
|
159
|
+
t === "flows" && /* @__PURE__ */ e("div", { className: "grid", children: f.map((d) => /* @__PURE__ */ n("div", { className: "card", children: [
|
|
160
|
+
/* @__PURE__ */ n("div", { className: "row", children: [
|
|
161
|
+
/* @__PURE__ */ e("strong", { className: "mono", children: d.from }),
|
|
162
|
+
/* @__PURE__ */ e("span", { className: "grow" }),
|
|
163
|
+
/* @__PURE__ */ n("span", { className: "small muted", children: [
|
|
164
|
+
d.total,
|
|
165
|
+
" transitions"
|
|
166
|
+
] })
|
|
167
|
+
] }),
|
|
168
|
+
d.destinations.slice(0, 4).map((l) => /* @__PURE__ */ n("div", { children: [
|
|
169
|
+
/* @__PURE__ */ n("div", { className: "row small", children: [
|
|
170
|
+
/* @__PURE__ */ n("span", { className: "mono", children: [
|
|
171
|
+
"→ ",
|
|
172
|
+
l.to
|
|
173
|
+
] }),
|
|
174
|
+
/* @__PURE__ */ e("span", { className: "grow" }),
|
|
175
|
+
/* @__PURE__ */ n("span", { className: "mono", children: [
|
|
176
|
+
l.pct.toFixed(0),
|
|
177
|
+
"%"
|
|
178
|
+
] })
|
|
179
|
+
] }),
|
|
180
|
+
/* @__PURE__ */ e(S, { pct: l.pct })
|
|
181
|
+
] }, l.to))
|
|
182
|
+
] }, d.from)) }),
|
|
183
|
+
t === "maps" && /* @__PURE__ */ e(ee, { map: o, setMap: p, sessions: a })
|
|
184
|
+
]
|
|
185
|
+
}
|
|
186
|
+
);
|
|
187
|
+
}, ee = ({ map: t, setMap: i, sessions: a }) => {
|
|
188
|
+
const [s, o] = N(""), [p, g] = N("curious"), [h, f] = N([]), [u, m] = N(""), r = () => {
|
|
189
|
+
if (!s.trim()) return m("Stage name is required.");
|
|
190
|
+
if (h.length === 0) return m("Pick at least one touchpoint page.");
|
|
191
|
+
const c = { id: k("st"), name: s.trim(), emotion: p, pages: h };
|
|
192
|
+
i({ ...t, stages: [...t.stages, c] }), o(""), f([]), m("");
|
|
193
|
+
};
|
|
194
|
+
return /* @__PURE__ */ n("div", { className: "stack", children: [
|
|
195
|
+
/* @__PURE__ */ e("input", { className: "input", value: t.name, onChange: (c) => i({ ...t, name: c.target.value }), "aria-label": "Journey name" }),
|
|
196
|
+
/* @__PURE__ */ n("div", { className: "stages", children: [
|
|
197
|
+
t.stages.map((c, d) => {
|
|
198
|
+
const l = G(a, c.pages), b = E[c.emotion] ?? "#7c3aed";
|
|
199
|
+
return /* @__PURE__ */ n("div", { className: "card stage", children: [
|
|
200
|
+
/* @__PURE__ */ n("div", { className: "row", children: [
|
|
201
|
+
/* @__PURE__ */ e("span", { className: "badge", style: { background: `${b}30`, color: b }, children: d + 1 }),
|
|
202
|
+
/* @__PURE__ */ e("strong", { children: c.name }),
|
|
203
|
+
/* @__PURE__ */ e("span", { className: "grow" }),
|
|
204
|
+
/* @__PURE__ */ e("button", { className: "btn danger", "aria-label": `Remove ${c.name}`, onClick: () => i({ ...t, stages: t.stages.filter((v) => v.id !== c.id) }), children: "✕" })
|
|
205
|
+
] }),
|
|
206
|
+
c.pages.map((v) => /* @__PURE__ */ n("div", { className: "small mono muted", children: [
|
|
207
|
+
"✓ ",
|
|
208
|
+
v
|
|
209
|
+
] }, v)),
|
|
210
|
+
/* @__PURE__ */ n("div", { className: "small", style: { color: b }, children: [
|
|
211
|
+
"Emotion: ",
|
|
212
|
+
c.emotion
|
|
213
|
+
] }),
|
|
214
|
+
/* @__PURE__ */ e(S, { pct: l }),
|
|
215
|
+
/* @__PURE__ */ n("div", { className: "small mono muted", children: [
|
|
216
|
+
l.toFixed(0),
|
|
217
|
+
"% reach"
|
|
218
|
+
] })
|
|
219
|
+
] }, c.id);
|
|
220
|
+
}),
|
|
221
|
+
t.stages.length === 0 && /* @__PURE__ */ e("div", { className: "muted", children: "No stages yet. Add one below." })
|
|
222
|
+
] }),
|
|
223
|
+
/* @__PURE__ */ n("div", { className: "card form", children: [
|
|
224
|
+
/* @__PURE__ */ e("strong", { children: "Add stage" }),
|
|
225
|
+
/* @__PURE__ */ n("div", { className: "row", children: [
|
|
226
|
+
/* @__PURE__ */ e("input", { className: "input", placeholder: "Stage name", value: s, onChange: (c) => o(c.target.value) }),
|
|
227
|
+
/* @__PURE__ */ e("select", { className: "input slim", value: p, onChange: (c) => g(c.target.value), children: Object.keys(E).map((c) => /* @__PURE__ */ e("option", { children: c }, c)) })
|
|
228
|
+
] }),
|
|
229
|
+
/* @__PURE__ */ e("div", { className: "scale", children: Q.map((c) => /* @__PURE__ */ e("button", { type: "button", className: h.includes(c) ? "chip active" : "chip", onClick: () => f((d) => d.includes(c) ? d.filter((l) => l !== c) : [...d, c]), children: c }, c)) }),
|
|
230
|
+
/* @__PURE__ */ n("div", { className: "row", children: [
|
|
231
|
+
/* @__PURE__ */ e("span", { className: "grow" }),
|
|
232
|
+
u && /* @__PURE__ */ e("span", { className: "error", children: u }),
|
|
233
|
+
/* @__PURE__ */ e("button", { className: "btn primary", onClick: r, children: "+ Add stage" })
|
|
234
|
+
] })
|
|
235
|
+
] })
|
|
236
|
+
] });
|
|
237
|
+
}, I = (t) => new Date(Date.UTC(2026, 10, 6) - t * 864e5).toISOString(), te = [
|
|
238
|
+
{
|
|
239
|
+
id: "s1",
|
|
240
|
+
name: "Q4 Product Satisfaction",
|
|
241
|
+
description: "How do users feel about the product right now?",
|
|
242
|
+
status: "active",
|
|
243
|
+
target: 100,
|
|
244
|
+
createdAt: I(30),
|
|
245
|
+
questions: [
|
|
246
|
+
{ id: "s1q1", type: "nps", text: "How likely are you to recommend us to a colleague?", required: !0 },
|
|
247
|
+
{ id: "s1q2", type: "rating", text: "How satisfied are you with the product?", required: !0 },
|
|
248
|
+
{ id: "s1q3", type: "multiple_choice", text: "Which feature do you use most?", required: !1, options: ["Feature Flags", "Experiments", "Segments", "Audit Log"] },
|
|
249
|
+
{ id: "s1q4", type: "open_text", text: "What is one thing we should improve?", required: !1 }
|
|
250
|
+
]
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
id: "s2",
|
|
254
|
+
name: "Onboarding Experience",
|
|
255
|
+
description: "First-week feedback from new accounts.",
|
|
256
|
+
status: "draft",
|
|
257
|
+
target: 50,
|
|
258
|
+
createdAt: I(5),
|
|
259
|
+
questions: [
|
|
260
|
+
{ id: "s2q1", type: "nps", text: "How likely are you to recommend our onboarding?", required: !0 },
|
|
261
|
+
{ id: "s2q2", type: "open_text", text: "What was confusing?", required: !1 }
|
|
262
|
+
]
|
|
263
|
+
}
|
|
264
|
+
], P = ["Love the rollout controls", "Dashboards load slowly", "Needs better docs", "Great support", "Too many clicks to create a flag"];
|
|
265
|
+
function se() {
|
|
266
|
+
const t = _(7);
|
|
267
|
+
return Array.from({ length: 36 }, (i, a) => {
|
|
268
|
+
const s = Math.min(10, Math.floor(t() * t() * 4 + t() * 8 + 3));
|
|
269
|
+
return {
|
|
270
|
+
id: `r${a}`,
|
|
271
|
+
surveyId: "s1",
|
|
272
|
+
userId: `user_${100 + a}`,
|
|
273
|
+
createdAt: I(Math.floor(t() * 28)),
|
|
274
|
+
answers: [
|
|
275
|
+
{ questionId: "s1q1", value: s },
|
|
276
|
+
{ questionId: "s1q2", value: Math.max(1, Math.min(5, Math.round(s / 2))) },
|
|
277
|
+
{ questionId: "s1q3", value: ["Feature Flags", "Experiments", "Segments", "Audit Log"][Math.floor(t() * 4)] },
|
|
278
|
+
{ questionId: "s1q4", value: P[Math.floor(t() * P.length)] }
|
|
279
|
+
]
|
|
280
|
+
};
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
const R = (t) => t >= 9 ? "promoter" : t >= 7 ? "passive" : "detractor";
|
|
284
|
+
function A(t) {
|
|
285
|
+
if (t.length === 0) return null;
|
|
286
|
+
const i = t.filter((s) => s >= 9).length, a = t.filter((s) => s <= 6).length;
|
|
287
|
+
return {
|
|
288
|
+
score: Math.round((i - a) / t.length * 100),
|
|
289
|
+
promoters: i,
|
|
290
|
+
passives: t.length - i - a,
|
|
291
|
+
detractors: a,
|
|
292
|
+
total: t.length
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
function M(t, i) {
|
|
296
|
+
const a = t.questions.find((s) => s.type === "nps");
|
|
297
|
+
return a ? i.filter((s) => s.surveyId === t.id).map((s) => {
|
|
298
|
+
var o;
|
|
299
|
+
return (o = s.answers.find((p) => p.questionId === a.id)) == null ? void 0 : o.value;
|
|
300
|
+
}).filter((s) => typeof s == "number") : [];
|
|
301
|
+
}
|
|
302
|
+
const ae = ["nps", "rating", "multiple_choice", "open_text"], q = (t) => new Date(t).toLocaleDateString(void 0, { day: "2-digit", month: "short", year: "numeric" }), de = () => {
|
|
303
|
+
const [t, i] = N(te), [a, s] = N(se), [o, p] = N({ name: "list" }), g = (r) => t.find((c) => c.id === r), h = () => p({ name: "list" });
|
|
304
|
+
if (o.name === "create")
|
|
305
|
+
return /* @__PURE__ */ e(
|
|
306
|
+
ne,
|
|
307
|
+
{
|
|
308
|
+
onCancel: h,
|
|
309
|
+
onSave: (r) => {
|
|
310
|
+
i((c) => [r, ...c]), h();
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
);
|
|
314
|
+
if (o.name === "take") {
|
|
315
|
+
const r = g(o.id);
|
|
316
|
+
return r ? /* @__PURE__ */ e(
|
|
317
|
+
ie,
|
|
318
|
+
{
|
|
319
|
+
survey: r,
|
|
320
|
+
onCancel: h,
|
|
321
|
+
onSubmit: (c) => {
|
|
322
|
+
s((d) => [{ id: k("r"), surveyId: r.id, userId: `user_${900 + d.length}`, createdAt: (/* @__PURE__ */ new Date()).toISOString(), answers: c }, ...d]), p({ name: "results", id: r.id });
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
) : null;
|
|
326
|
+
}
|
|
327
|
+
if (o.name === "results") {
|
|
328
|
+
const r = g(o.id);
|
|
329
|
+
return r ? /* @__PURE__ */ e(re, { survey: r, responses: a.filter((c) => c.surveyId === r.id), onBack: h, onTake: () => p({ name: "take", id: r.id }) }) : null;
|
|
330
|
+
}
|
|
331
|
+
const f = a.length, u = t.filter((r) => r.status === "active").length, m = A(t.flatMap((r) => M(r, a)));
|
|
332
|
+
return /* @__PURE__ */ n(
|
|
333
|
+
C,
|
|
334
|
+
{
|
|
335
|
+
title: "Surveys",
|
|
336
|
+
subtitle: "Create, run and measure user surveys.",
|
|
337
|
+
actions: /* @__PURE__ */ e("button", { className: "btn primary", onClick: () => p({ name: "create" }), children: "+ Create Survey" }),
|
|
338
|
+
children: [
|
|
339
|
+
/* @__PURE__ */ n("div", { className: "stats", children: [
|
|
340
|
+
/* @__PURE__ */ e(y, { label: "Total surveys", value: t.length, color: "#6366f1" }),
|
|
341
|
+
/* @__PURE__ */ e(y, { label: "Active", value: u, color: "#10b981" }),
|
|
342
|
+
/* @__PURE__ */ e(y, { label: "Total responses", value: f }),
|
|
343
|
+
/* @__PURE__ */ e(y, { label: "Overall NPS", value: m ? m.score : "—", color: "#f59e0b" })
|
|
344
|
+
] }),
|
|
345
|
+
/* @__PURE__ */ n("table", { className: "table", children: [
|
|
346
|
+
/* @__PURE__ */ e("thead", { children: /* @__PURE__ */ n("tr", { children: [
|
|
347
|
+
/* @__PURE__ */ e("th", { children: "Survey" }),
|
|
348
|
+
/* @__PURE__ */ e("th", { children: "Status" }),
|
|
349
|
+
/* @__PURE__ */ e("th", { children: "Progress" }),
|
|
350
|
+
/* @__PURE__ */ e("th", { children: "NPS" }),
|
|
351
|
+
/* @__PURE__ */ e("th", { children: "Created" }),
|
|
352
|
+
/* @__PURE__ */ e("th", {})
|
|
353
|
+
] }) }),
|
|
354
|
+
/* @__PURE__ */ e("tbody", { children: t.map((r) => {
|
|
355
|
+
const c = a.filter((l) => l.surveyId === r.id).length, d = A(M(r, a));
|
|
356
|
+
return /* @__PURE__ */ n("tr", { children: [
|
|
357
|
+
/* @__PURE__ */ n("td", { children: [
|
|
358
|
+
/* @__PURE__ */ e("strong", { children: r.name }),
|
|
359
|
+
/* @__PURE__ */ n("div", { className: "muted small", children: [
|
|
360
|
+
r.questions.length,
|
|
361
|
+
" questions"
|
|
362
|
+
] })
|
|
363
|
+
] }),
|
|
364
|
+
/* @__PURE__ */ e("td", { children: /* @__PURE__ */ e(
|
|
365
|
+
"select",
|
|
366
|
+
{
|
|
367
|
+
className: "input slim",
|
|
368
|
+
value: r.status,
|
|
369
|
+
onChange: (l) => i((b) => b.map((v) => v.id === r.id ? { ...v, status: l.target.value } : v)),
|
|
370
|
+
children: ["draft", "active", "paused", "closed"].map((l) => /* @__PURE__ */ e("option", { children: l }, l))
|
|
371
|
+
}
|
|
372
|
+
) }),
|
|
373
|
+
/* @__PURE__ */ n("td", { style: { minWidth: 140 }, children: [
|
|
374
|
+
/* @__PURE__ */ n("div", { className: "small mono", children: [
|
|
375
|
+
c,
|
|
376
|
+
" / ",
|
|
377
|
+
r.target
|
|
378
|
+
] }),
|
|
379
|
+
/* @__PURE__ */ e(S, { pct: c / r.target * 100 })
|
|
380
|
+
] }),
|
|
381
|
+
/* @__PURE__ */ e("td", { className: "mono", children: d ? d.score : "—" }),
|
|
382
|
+
/* @__PURE__ */ e("td", { className: "muted small", children: q(r.createdAt) }),
|
|
383
|
+
/* @__PURE__ */ n("td", { className: "right", children: [
|
|
384
|
+
/* @__PURE__ */ e("button", { className: "btn", onClick: () => p({ name: "results", id: r.id }), children: "Results" }),
|
|
385
|
+
" ",
|
|
386
|
+
/* @__PURE__ */ e("button", { className: "btn", disabled: r.status !== "active", title: r.status !== "active" ? "Set status to active to collect answers" : "", onClick: () => p({ name: "take", id: r.id }), children: "Take" }),
|
|
387
|
+
" ",
|
|
388
|
+
/* @__PURE__ */ e(
|
|
389
|
+
"button",
|
|
390
|
+
{
|
|
391
|
+
className: "btn danger",
|
|
392
|
+
onClick: () => {
|
|
393
|
+
window.confirm(`Delete "${r.name}" and its responses?`) && (i((l) => l.filter((b) => b.id !== r.id)), s((l) => l.filter((b) => b.surveyId !== r.id)));
|
|
394
|
+
},
|
|
395
|
+
children: "Delete"
|
|
396
|
+
}
|
|
397
|
+
)
|
|
398
|
+
] })
|
|
399
|
+
] }, r.id);
|
|
400
|
+
}) })
|
|
401
|
+
] })
|
|
402
|
+
]
|
|
403
|
+
}
|
|
404
|
+
);
|
|
405
|
+
}, ne = ({ onSave: t, onCancel: i }) => {
|
|
406
|
+
const [a, s] = N(""), [o, p] = N(""), [g, h] = N(100), [f, u] = N([{ id: k("q"), type: "nps", text: "How likely are you to recommend us?", required: !0 }]), [m, r] = N(""), c = (l, b) => u((v) => v.map((w) => w.id === l ? { ...w, ...b } : w)), d = () => {
|
|
407
|
+
if (!a.trim()) return r("Survey name is required.");
|
|
408
|
+
if (f.length === 0) return r("Add at least one question.");
|
|
409
|
+
if (f.some((l) => !l.text.trim())) return r("Every question needs text.");
|
|
410
|
+
if (f.some((l) => l.type === "multiple_choice" && (l.options ?? []).filter((b) => b.trim()).length < 2)) return r("Multiple choice needs at least two options.");
|
|
411
|
+
t({
|
|
412
|
+
id: k("s"),
|
|
413
|
+
name: a.trim(),
|
|
414
|
+
description: o.trim(),
|
|
415
|
+
status: "active",
|
|
416
|
+
target: g,
|
|
417
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
418
|
+
questions: f.map((l) => ({ ...l, text: l.text.trim(), options: l.type === "multiple_choice" ? (l.options ?? []).filter((b) => b.trim()) : void 0 }))
|
|
419
|
+
});
|
|
420
|
+
};
|
|
421
|
+
return /* @__PURE__ */ n(C, { title: "Create Survey", subtitle: "Build a new survey.", actions: /* @__PURE__ */ e("button", { className: "btn", onClick: i, children: "Back" }), children: [
|
|
422
|
+
/* @__PURE__ */ n("div", { className: "card form", children: [
|
|
423
|
+
/* @__PURE__ */ n("label", { children: [
|
|
424
|
+
"Name",
|
|
425
|
+
/* @__PURE__ */ e("input", { className: "input", value: a, onChange: (l) => s(l.target.value), placeholder: "e.g. Q1 Product Satisfaction" })
|
|
426
|
+
] }),
|
|
427
|
+
/* @__PURE__ */ n("label", { children: [
|
|
428
|
+
"Description",
|
|
429
|
+
/* @__PURE__ */ e("input", { className: "input", value: o, onChange: (l) => p(l.target.value) })
|
|
430
|
+
] }),
|
|
431
|
+
/* @__PURE__ */ n("label", { children: [
|
|
432
|
+
"Target responses",
|
|
433
|
+
/* @__PURE__ */ e("input", { className: "input narrow", type: "number", min: 1, value: g, onChange: (l) => h(Math.max(1, parseInt(l.target.value, 10) || 1)) })
|
|
434
|
+
] })
|
|
435
|
+
] }),
|
|
436
|
+
/* @__PURE__ */ n("h3", { children: [
|
|
437
|
+
"Questions (",
|
|
438
|
+
f.length,
|
|
439
|
+
")"
|
|
440
|
+
] }),
|
|
441
|
+
f.map((l, b) => /* @__PURE__ */ n("div", { className: "card form", children: [
|
|
442
|
+
/* @__PURE__ */ n("div", { className: "row", children: [
|
|
443
|
+
/* @__PURE__ */ n("strong", { children: [
|
|
444
|
+
"Q",
|
|
445
|
+
b + 1
|
|
446
|
+
] }),
|
|
447
|
+
/* @__PURE__ */ e("select", { className: "input slim", value: l.type, onChange: (v) => c(l.id, { type: v.target.value, options: v.target.value === "multiple_choice" ? ["Option 1", "Option 2"] : void 0 }), children: ae.map((v) => /* @__PURE__ */ e("option", { value: v, children: v.replace("_", " ") }, v)) }),
|
|
448
|
+
/* @__PURE__ */ n("label", { className: "inline", children: [
|
|
449
|
+
/* @__PURE__ */ e("input", { type: "checkbox", checked: l.required, onChange: (v) => c(l.id, { required: v.target.checked }) }),
|
|
450
|
+
" required"
|
|
451
|
+
] }),
|
|
452
|
+
/* @__PURE__ */ e("span", { className: "grow" }),
|
|
453
|
+
/* @__PURE__ */ e("button", { className: "btn danger", onClick: () => u((v) => v.filter((w) => w.id !== l.id)), children: "Remove" })
|
|
454
|
+
] }),
|
|
455
|
+
/* @__PURE__ */ e("input", { className: "input", value: l.text, onChange: (v) => c(l.id, { text: v.target.value }), placeholder: "Enter your question…" }),
|
|
456
|
+
l.type === "multiple_choice" && /* @__PURE__ */ n("div", { className: "stack", children: [
|
|
457
|
+
(l.options ?? []).map((v, w) => /* @__PURE__ */ e("input", { className: "input slim", value: v, onChange: (D) => c(l.id, { options: (l.options ?? []).map((F, O) => O === w ? D.target.value : F) }) }, w)),
|
|
458
|
+
/* @__PURE__ */ e("button", { className: "btn", onClick: () => c(l.id, { options: [...l.options ?? [], `Option ${(l.options ?? []).length + 1}`] }), children: "+ Add option" })
|
|
459
|
+
] })
|
|
460
|
+
] }, l.id)),
|
|
461
|
+
/* @__PURE__ */ n("div", { className: "row", children: [
|
|
462
|
+
/* @__PURE__ */ e("button", { className: "btn", onClick: () => u((l) => [...l, { id: k("q"), type: "rating", text: "", required: !1 }]), children: "+ Add question" }),
|
|
463
|
+
/* @__PURE__ */ e("span", { className: "grow" }),
|
|
464
|
+
m && /* @__PURE__ */ e("span", { className: "error", children: m }),
|
|
465
|
+
/* @__PURE__ */ e("button", { className: "btn primary", onClick: d, children: "Create Survey" })
|
|
466
|
+
] })
|
|
467
|
+
] });
|
|
468
|
+
}, ie = ({ survey: t, onSubmit: i, onCancel: a }) => {
|
|
469
|
+
const [s, o] = N({}), [p, g] = N(""), h = (u, m) => o((r) => ({ ...r, [u]: m })), f = () => {
|
|
470
|
+
const u = t.questions.find((m) => m.required && (s[m.id] === void 0 || s[m.id] === ""));
|
|
471
|
+
if (u) return g(`"${u.text}" is required.`);
|
|
472
|
+
g(""), i(t.questions.filter((m) => s[m.id] !== void 0 && s[m.id] !== "").map((m) => ({ questionId: m.id, value: s[m.id] })));
|
|
473
|
+
};
|
|
474
|
+
return /* @__PURE__ */ n(C, { title: t.name, subtitle: t.description || "Answer the questions below.", actions: /* @__PURE__ */ e("button", { className: "btn", onClick: a, children: "Cancel" }), children: [
|
|
475
|
+
t.questions.map((u, m) => /* @__PURE__ */ n("div", { className: "card form", children: [
|
|
476
|
+
/* @__PURE__ */ n("strong", { children: [
|
|
477
|
+
m + 1,
|
|
478
|
+
". ",
|
|
479
|
+
u.text,
|
|
480
|
+
u.required && /* @__PURE__ */ e("span", { className: "error", children: " *" })
|
|
481
|
+
] }),
|
|
482
|
+
u.type === "nps" && /* @__PURE__ */ e("div", { className: "scale", children: Array.from({ length: 11 }, (r, c) => /* @__PURE__ */ e("button", { className: s[u.id] === c ? "chip active" : "chip", onClick: () => h(u.id, c), children: c }, c)) }),
|
|
483
|
+
u.type === "rating" && /* @__PURE__ */ e("div", { className: "scale", children: [1, 2, 3, 4, 5].map((r) => /* @__PURE__ */ n("button", { className: s[u.id] === r ? "chip active" : "chip", onClick: () => h(u.id, r), children: [
|
|
484
|
+
r,
|
|
485
|
+
" ★"
|
|
486
|
+
] }, r)) }),
|
|
487
|
+
u.type === "multiple_choice" && /* @__PURE__ */ e("div", { className: "scale", children: (u.options ?? []).map((r) => /* @__PURE__ */ e("button", { className: s[u.id] === r ? "chip active" : "chip", onClick: () => h(u.id, r), children: r }, r)) }),
|
|
488
|
+
u.type === "open_text" && /* @__PURE__ */ e("textarea", { className: "input", rows: 2, value: String(s[u.id] ?? ""), onChange: (r) => h(u.id, r.target.value) })
|
|
489
|
+
] }, u.id)),
|
|
490
|
+
/* @__PURE__ */ n("div", { className: "row", children: [
|
|
491
|
+
/* @__PURE__ */ e("span", { className: "grow" }),
|
|
492
|
+
p && /* @__PURE__ */ e("span", { className: "error", children: p }),
|
|
493
|
+
/* @__PURE__ */ e("button", { className: "btn primary", onClick: f, children: "Submit response" })
|
|
494
|
+
] })
|
|
495
|
+
] });
|
|
496
|
+
}, re = ({ survey: t, responses: i, onBack: a, onTake: s }) => {
|
|
497
|
+
const o = x(() => A(M(t, i)), [t, i]), p = t.questions.find((h) => h.type === "nps"), g = (h) => o ? Math.round(h / o.total * 100) : 0;
|
|
498
|
+
return /* @__PURE__ */ n(
|
|
499
|
+
C,
|
|
500
|
+
{
|
|
501
|
+
title: t.name,
|
|
502
|
+
subtitle: `${i.length} responses`,
|
|
503
|
+
actions: /* @__PURE__ */ n(B, { children: [
|
|
504
|
+
/* @__PURE__ */ e("button", { className: "btn", onClick: a, children: "Back" }),
|
|
505
|
+
/* @__PURE__ */ e("button", { className: "btn primary", disabled: t.status !== "active", onClick: s, children: "Take survey" })
|
|
506
|
+
] }),
|
|
507
|
+
children: [
|
|
508
|
+
/* @__PURE__ */ n("div", { className: "stats", children: [
|
|
509
|
+
/* @__PURE__ */ e(y, { label: "NPS", value: o ? o.score : "—", color: "#f59e0b" }),
|
|
510
|
+
/* @__PURE__ */ e(y, { label: "Promoters", value: o ? `${g(o.promoters)}%` : "—", color: "#4edea3" }),
|
|
511
|
+
/* @__PURE__ */ e(y, { label: "Passives", value: o ? `${g(o.passives)}%` : "—", color: "#ffcc6b" }),
|
|
512
|
+
/* @__PURE__ */ e(y, { label: "Detractors", value: o ? `${g(o.detractors)}%` : "—", color: "#ffb4ab" })
|
|
513
|
+
] }),
|
|
514
|
+
/* @__PURE__ */ n("table", { className: "table", children: [
|
|
515
|
+
/* @__PURE__ */ e("thead", { children: /* @__PURE__ */ n("tr", { children: [
|
|
516
|
+
/* @__PURE__ */ e("th", { children: "User" }),
|
|
517
|
+
/* @__PURE__ */ e("th", { children: "NPS" }),
|
|
518
|
+
t.questions.filter((h) => h.type !== "nps").map((h) => /* @__PURE__ */ e("th", { children: h.text }, h.id)),
|
|
519
|
+
/* @__PURE__ */ e("th", { children: "Date" })
|
|
520
|
+
] }) }),
|
|
521
|
+
/* @__PURE__ */ n("tbody", { children: [
|
|
522
|
+
i.length === 0 && /* @__PURE__ */ e("tr", { children: /* @__PURE__ */ e("td", { colSpan: 9, className: "muted", children: "No responses yet." }) }),
|
|
523
|
+
i.map((h) => {
|
|
524
|
+
var u;
|
|
525
|
+
const f = p ? (u = h.answers.find((m) => m.questionId === p.id)) == null ? void 0 : u.value : void 0;
|
|
526
|
+
return /* @__PURE__ */ n("tr", { children: [
|
|
527
|
+
/* @__PURE__ */ e("td", { className: "mono", children: h.userId }),
|
|
528
|
+
/* @__PURE__ */ e("td", { children: typeof f == "number" ? /* @__PURE__ */ n("span", { className: `pill ${R(f)}`, children: [
|
|
529
|
+
f,
|
|
530
|
+
" · ",
|
|
531
|
+
R(f)
|
|
532
|
+
] }) : "—" }),
|
|
533
|
+
t.questions.filter((m) => m.type !== "nps").map((m) => {
|
|
534
|
+
var r;
|
|
535
|
+
return /* @__PURE__ */ e("td", { children: String(((r = h.answers.find((c) => c.questionId === m.id)) == null ? void 0 : r.value) ?? "—") }, m.id);
|
|
536
|
+
}),
|
|
537
|
+
/* @__PURE__ */ e("td", { className: "muted small", children: q(h.createdAt) })
|
|
538
|
+
] }, h.id);
|
|
539
|
+
})
|
|
540
|
+
] })
|
|
541
|
+
] })
|
|
542
|
+
]
|
|
543
|
+
}
|
|
544
|
+
);
|
|
545
|
+
};
|
|
546
|
+
export {
|
|
547
|
+
ce as JourneyApp,
|
|
548
|
+
de as SurveyApp,
|
|
549
|
+
R as npsCategory,
|
|
550
|
+
A as npsOf,
|
|
551
|
+
M as npsScores
|
|
552
|
+
};
|