@shiva004/surveys 0.1.8 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -1
- package/dist/App.d.ts +1 -1
- package/dist/index.d.ts +8 -3
- package/dist/index.js +918 -296
- package/dist/journey/JourneyApp.d.ts +1 -1
- package/dist/journey/analytics.d.ts +1 -1
- package/dist/style.css +1 -1
- package/dist/survey/SurveyApp.d.ts +1 -1
- package/dist/survey/data.d.ts +1 -1
- package/dist/survey/nps.d.ts +1 -1
- package/dist/ui.d.ts +1 -1
- package/dist/walkthrough/JourneyProvider.d.ts +27 -0
- package/dist/walkthrough/TourOverlay.d.ts +23 -0
- package/dist/walkthrough/WalkthroughDemo.d.ts +11 -0
- package/dist/walkthrough/index.d.ts +7 -0
- package/dist/walkthrough/tour.d.ts +39 -0
- package/dist/walkthrough/tracker.d.ts +83 -0
- package/package.json +13 -14
- package/dist/index.cjs +0 -1
- package/dist/main.d.ts +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from 'react';
|
|
2
2
|
export declare const JourneyApp: React.FC;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JourneyMap } from '../types';
|
|
1
|
+
import type { JourneyMap } from '../types';
|
|
2
2
|
export declare const PAGES: string[];
|
|
3
3
|
/** Simulated sessions: each session is the ordered list of pages one visitor saw. */
|
|
4
4
|
export declare function simulate(count: number, rand: () => number): string[][];
|
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
:root{--bg:#0f1117;--card:#171a23;--line:#262b3a;--text:#e6e8ef;--muted:#8b93a7;--accent:#7c3aed;--good:#4edea3;--warn:#ffcc6b;--bad:#ffb4ab;color-scheme:dark}@media (prefers-color-scheme: light){:root{--bg:#f6f7fb;--card:#ffffff;--line:#dfe2ec;--text:#1f2433;--muted:#667085;color-scheme:light}}*{box-sizing:border-box}body{margin:0;background:var(--bg);color:var(--text);font:14px/1.45 system-ui,-apple-system,Segoe UI,sans-serif}h2{margin:0;font-size:22px}h3{margin:18px 0 8px}.shell{max-width:1100px;margin:0 auto;padding:16px 20px 48px}.topbar{display:flex;align-items:center;gap:16px;padding-bottom:12px;border-bottom:1px solid var(--line);margin-bottom:18px}.page-head{display:flex;justify-content:space-between;align-items:flex-start;gap:12px;margin-bottom:16px}.actions{display:flex;gap:8px}.muted{color:var(--muted)}.small{font-size:12px}.mono{font-family:ui-monospace,Menlo,Consolas,monospace}.right{text-align:right;white-space:nowrap}.stats{display:grid;grid-template-columns:repeat(auto-fit,minmax(190px,1fr));gap:12px;margin-bottom:16px}.stat{background:var(--card);border:1px solid var(--line);border-top:3px solid var(--accent);border-radius:10px;padding:12px 14px}.stat-label{color:var(--muted);font-size:12px}.stat-value{font-size:24px;font-weight:700;margin-top:2px;overflow-wrap:anywhere}.tabs{display:inline-flex;gap:4px;background:var(--card);border:1px solid var(--line);border-radius:10px;padding:3px;margin-bottom:14px}.tab{border:0;background:none;color:var(--muted);padding:6px 12px;border-radius:7px;cursor:pointer;font:inherit}.tab.active{background:var(--accent);color:#fff}.table{width:100%;border-collapse:collapse;background:var(--card);border:1px solid var(--line);border-radius:10px;overflow:hidden}.table th,.table td{padding:10px 12px;text-align:left;border-bottom:1px solid var(--line);vertical-align:middle}.table th{font-size:12px;color:var(--muted);font-weight:600}.card{background:var(--card);border:1px solid var(--line);border-radius:10px;padding:14px;display:flex;flex-direction:column;gap:8px}.grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(270px,1fr));gap:12px}.stack{display:flex;flex-direction:column;gap:10px}.row{display:flex;align-items:center;gap:8px;flex-wrap:wrap}.grow{flex:1}.form{margin-bottom:10px}.form label{display:flex;flex-direction:column;gap:4px;font-size:12px;color:var(--muted)}.form label.inline{flex-direction:row;align-items:center}.input{width:100%;background:var(--bg);color:var(--text);border:1px solid var(--line);border-radius:8px;padding:8px 10px;font:inherit}.input:focus{outline:none;border-color:var(--accent)}.input.slim{width:auto;padding:5px 8px}.input.narrow{width:130px}.btn{background:var(--card);color:var(--text);border:1px solid var(--line);border-radius:8px;padding:6px 12px;cursor:pointer;font:inherit}.btn:hover:not(:disabled){border-color:var(--accent)}.btn:disabled{opacity:.45;cursor:not-allowed}.btn.primary{background:var(--accent);border-color:var(--accent);color:#fff}.btn.danger:hover:not(:disabled){border-color:var(--bad);color:var(--bad)}.bar{height:6px;border-radius:99px;background:#7f7f7f2e;overflow:hidden}.bar-fill{height:100%;border-radius:99px;transition:width .3s}.scale{display:flex;flex-wrap:wrap;gap:6px}.chip{border:1px solid var(--line);background:var(--bg);color:var(--text);border-radius:8px;padding:5px 10px;cursor:pointer;font:inherit;font-size:12.5px}.chip.active{background:var(--accent);border-color:var(--accent);color:#fff}.chip.static{cursor:default;font-family:ui-monospace,Menlo,monospace}.steps{display:flex;flex-wrap:wrap;align-items:center;gap:6px}.pill{display:inline-block;border-radius:99px;padding:2px 9px;font-size:11px;background:#7f7f7f2e}.pill.promoter{background:#4edea32e;color:var(--good)}.pill.passive{background:#ffcc6b2e;color:var(--warn)}.pill.detractor{background:#ffb4ab2e;color:var(--bad)}.stages{display:flex;gap:12px;overflow-x:auto;padding-bottom:6px}.stage{min-width:190px;width:190px}.badge{width:24px;height:24px;border-radius:50%;display:inline-flex;align-items:center;justify-content:center;font-size:11px;font-weight:700}.error{color:var(--bad);font-size:12.5px}
|
|
1
|
+
:root{--bg:#0f1117;--card:#171a23;--line:#262b3a;--text:#e6e8ef;--muted:#8b93a7;--accent:#7c3aed;--good:#4edea3;--warn:#ffcc6b;--bad:#ffb4ab;color-scheme:dark}@media (prefers-color-scheme: light){:root{--bg:#f6f7fb;--card:#ffffff;--line:#dfe2ec;--text:#1f2433;--muted:#667085;color-scheme:light}}*{box-sizing:border-box}body{margin:0;background:var(--bg);color:var(--text);font:14px/1.45 system-ui,-apple-system,Segoe UI,sans-serif}h2{margin:0;font-size:22px}h3{margin:18px 0 8px}.shell{max-width:1100px;margin:0 auto;padding:16px 20px 48px}.topbar{display:flex;align-items:center;gap:16px;padding-bottom:12px;border-bottom:1px solid var(--line);margin-bottom:18px}.page-head{display:flex;justify-content:space-between;align-items:flex-start;gap:12px;margin-bottom:16px}.actions{display:flex;gap:8px}.muted{color:var(--muted)}.small{font-size:12px}.mono{font-family:ui-monospace,Menlo,Consolas,monospace}.right{text-align:right;white-space:nowrap}.stats{display:grid;grid-template-columns:repeat(auto-fit,minmax(190px,1fr));gap:12px;margin-bottom:16px}.stat{background:var(--card);border:1px solid var(--line);border-top:3px solid var(--accent);border-radius:10px;padding:12px 14px}.stat-label{color:var(--muted);font-size:12px}.stat-value{font-size:24px;font-weight:700;margin-top:2px;overflow-wrap:anywhere}.tabs{display:inline-flex;gap:4px;background:var(--card);border:1px solid var(--line);border-radius:10px;padding:3px;margin-bottom:14px}.tab{border:0;background:none;color:var(--muted);padding:6px 12px;border-radius:7px;cursor:pointer;font:inherit}.tab.active{background:var(--accent);color:#fff}.table{width:100%;border-collapse:collapse;background:var(--card);border:1px solid var(--line);border-radius:10px;overflow:hidden}.table th,.table td{padding:10px 12px;text-align:left;border-bottom:1px solid var(--line);vertical-align:middle}.table th{font-size:12px;color:var(--muted);font-weight:600}.card{background:var(--card);border:1px solid var(--line);border-radius:10px;padding:14px;display:flex;flex-direction:column;gap:8px}.grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(270px,1fr));gap:12px}.stack{display:flex;flex-direction:column;gap:10px}.row{display:flex;align-items:center;gap:8px;flex-wrap:wrap}.grow{flex:1}.form{margin-bottom:10px}.form label{display:flex;flex-direction:column;gap:4px;font-size:12px;color:var(--muted)}.form label.inline{flex-direction:row;align-items:center}.input{width:100%;background:var(--bg);color:var(--text);border:1px solid var(--line);border-radius:8px;padding:8px 10px;font:inherit}.input:focus{outline:none;border-color:var(--accent)}.input.slim{width:auto;padding:5px 8px}.input.narrow{width:130px}.btn{background:var(--card);color:var(--text);border:1px solid var(--line);border-radius:8px;padding:6px 12px;cursor:pointer;font:inherit}.btn:hover:not(:disabled){border-color:var(--accent)}.btn:disabled{opacity:.45;cursor:not-allowed}.btn.primary{background:var(--accent);border-color:var(--accent);color:#fff}.btn.danger:hover:not(:disabled){border-color:var(--bad);color:var(--bad)}.bar{height:6px;border-radius:99px;background:#7f7f7f2e;overflow:hidden}.bar-fill{height:100%;border-radius:99px;transition:width .3s}.scale{display:flex;flex-wrap:wrap;gap:6px}.chip{border:1px solid var(--line);background:var(--bg);color:var(--text);border-radius:8px;padding:5px 10px;cursor:pointer;font:inherit;font-size:12.5px}.chip.active{background:var(--accent);border-color:var(--accent);color:#fff}.chip.static{cursor:default;font-family:ui-monospace,Menlo,monospace}.steps{display:flex;flex-wrap:wrap;align-items:center;gap:6px}.pill{display:inline-block;border-radius:99px;padding:2px 9px;font-size:11px;background:#7f7f7f2e}.pill.promoter{background:#4edea32e;color:var(--good)}.pill.passive{background:#ffcc6b2e;color:var(--warn)}.pill.detractor{background:#ffb4ab2e;color:var(--bad)}.stages{display:flex;gap:12px;overflow-x:auto;padding-bottom:6px}.stage{min-width:190px;width:190px}.badge{width:24px;height:24px;border-radius:50%;display:inline-flex;align-items:center;justify-content:center;font-size:11px;font-weight:700}.error{color:var(--bad);font-size:12.5px}.sj{--bg:#fff;--tx:#12141c;--mu:#5f6677;--bd:#e4e6ee;--ac:#7c3aed;--btn:#6d28d9;--ov:rgba(15,17,30,.55);--sh:0 16px 48px rgba(20,20,50,.28);position:fixed;top:0;right:0;bottom:0;left:0;z-index:2147483000;visibility:hidden;pointer-events:none;font:14px/1.5 Inter,system-ui,-apple-system,Segoe UI,sans-serif}.sj[data-theme=dark]{--bg:#181b26;--tx:#eceef6;--mu:#a0a7bb;--bd:rgba(255,255,255,.16);--ac:#a78bfa;--ov:rgba(3,4,10,.68);--sh:0 16px 48px rgba(0,0,0,.7)}.sj.on{visibility:visible}.sj *{box-sizing:border-box}.sj-p{position:fixed;background:var(--ov);-webkit-backdrop-filter:blur(5px);backdrop-filter:blur(5px);pointer-events:auto;opacity:0;transition:opacity .3s}.sj.on .sj-p{opacity:1}.sj.anim .sj-p,.sj.anim .sj-ring{transition:all .45s cubic-bezier(.4,0,.2,1)}.sj-ring{position:fixed;border-radius:12px;border:2px solid var(--ac);box-shadow:0 0 0 4px color-mix(in srgb,var(--ac) 25%,transparent),0 0 32px color-mix(in srgb,var(--ac) 50%,transparent);pointer-events:none}.sj-pop{position:fixed;left:0;top:0;width:min(360px,calc(100vw - 24px));background:var(--bg);color:var(--tx);border:1px solid var(--bd);border-radius:16px;padding:1rem 1.1rem;box-shadow:var(--sh);pointer-events:auto;opacity:0}.sj.on .sj-pop{opacity:1}.sj.anim .sj-pop{transition:transform .45s cubic-bezier(.4,0,.2,1),opacity .3s}.sj-pop h3{margin:.25rem 0 .35rem;font-size:17px;line-height:1.3;color:var(--tx)}.sj-pop p{margin:0 0 1rem;color:var(--mu)}.sj-bar{height:4px;border-radius:9px;background:var(--bd);overflow:hidden;margin-bottom:.7rem}.sj-bar b{display:block;height:100%;background:var(--ac);transition:width .4s}.sj-hd{display:flex;justify-content:space-between;align-items:center;font-size:12px;color:var(--mu)}.sj-hd span:last-child{display:flex;gap:.2rem}.sj-x{background:none;border:0;color:var(--mu);font-size:18px;line-height:1;cursor:pointer;padding:.15rem .4rem;border-radius:6px}.sj-x:hover{color:var(--tx);background:var(--bd)}.sj-ft{display:flex;justify-content:space-between;align-items:center}.sj-b{background:var(--btn);color:#fff;border:0;border-radius:10px;padding:.5rem 1rem;font:600 14px inherit;cursor:pointer}.sj-b:hover{filter:brightness(1.1)}.sj-g{background:none;border:0;color:var(--mu);padding:.5rem .6rem;cursor:pointer;font:inherit}.sj-g:hover{color:var(--tx)}.sj button:focus-visible{outline:2px solid var(--ac);outline-offset:2px}.sj-arr{position:absolute;width:12px;height:12px;background:var(--bg);border:1px solid var(--bd);transform:rotate(45deg);display:none}.sj-pop[data-side=top] .sj-arr{display:block;bottom:-7px;left:calc(var(--ax) - 6px);border-top:0;border-left:0}.sj-pop[data-side=bottom] .sj-arr{display:block;top:-7px;left:calc(var(--ax) - 6px);border-bottom:0;border-right:0}.sj-pop[data-side=left] .sj-arr{display:block;right:-7px;top:calc(var(--ay) - 6px);border-bottom:0;border-left:0}.sj-pop[data-side=right] .sj-arr{display:block;left:-7px;top:calc(var(--ay) - 6px);border-top:0;border-right:0}.sj-heat{position:fixed;top:0;right:0;bottom:0;left:0;pointer-events:none;z-index:2147482000}@media (prefers-reduced-motion:reduce){.sj *{transition:none!important}}.nw{--bg:#f4f5f9;--sf:#fff;--tx:#12141c;--mu:#5f6677;--bd:#e4e6ee;--ac:#6d28d9;box-sizing:border-box;min-height:100vh;background:var(--bg);color:var(--tx);font:15px/1.55 Inter,system-ui,-apple-system,Segoe UI,sans-serif}[data-sj-theme=dark] .nw{--bg:#0f1117;--sf:#161922;--tx:#e8eaf1;--mu:#9aa1b6;--bd:rgba(255,255,255,.12);--ac:#a78bfa;color-scheme:dark}.nw *{box-sizing:border-box}.nw a{color:inherit;text-decoration:none}.nw-head{position:sticky;top:0;z-index:10;display:flex;align-items:center;gap:1rem;padding:.8rem 1.25rem;background:var(--sf);border-bottom:1px solid var(--bd)}.nw-logo{font-weight:700;margin-right:auto}.nw-logo i{color:var(--ac);font-style:normal}.nw-nav{display:flex;gap:1.1rem;color:var(--mu)}.nw-nav a:hover{color:var(--tx)}@media (max-width:640px){.nw-nav{display:none}}.nw-btn{display:inline-block;border:1px solid var(--bd);background:var(--sf);color:var(--tx);border-radius:10px;padding:.5rem .95rem;font:600 14px inherit;cursor:pointer}.nw-btn.p{background:#6d28d9;border-color:#6d28d9;color:#fff}.nw-wrap{max-width:68rem;margin:auto;padding:0 1.25rem}.nw-hero{padding:4.5rem 0 3.5rem}.nw-hero h1{font-size:clamp(2rem,5vw,3.4rem);line-height:1.1;margin:0 0 1rem;max-width:16ch}.nw-hero p{color:var(--mu);max-width:46ch;font-size:1.1rem}.nw-acts{display:flex;gap:.6rem;margin-top:1.5rem}.nw h2{font-size:1.6rem;margin:3.5rem 0 1rem}.nw section{scroll-margin-top:5rem}.nw-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(15rem,1fr));gap:1rem}.nw-card{background:var(--sf);border:1px solid var(--bd);border-radius:14px;padding:1.2rem}.nw-card h3{margin:.2rem 0 .4rem;font-size:1.05rem}.nw-card p{margin:0;color:var(--mu)}.nw-big{font-size:2rem;font-weight:700}.nw-card.hot{border-color:var(--ac)}.nw-foot{margin-top:4rem;padding:2rem 1.25rem 7rem;border-top:1px solid var(--bd);background:var(--sf);color:var(--mu)}.nw-dock{position:fixed;right:1rem;bottom:calc(1rem + env(safe-area-inset-bottom,0px));z-index:50;display:flex;gap:.3rem;background:var(--sf);border:1px solid var(--bd);border-radius:999px;padding:.3rem;box-shadow:0 8px 28px #0003}.nw-dock button{border:0;background:none;color:var(--tx);padding:.5rem .8rem;border-radius:999px;font:600 13px inherit;cursor:pointer}.nw-dock button:hover{background:var(--bg)}.nw-ins{position:fixed;top:0;right:0;bottom:0;width:min(400px,100vw);transform:translate(105%);transition:transform .3s;z-index:60;background:var(--sf);color:var(--tx);border-left:1px solid var(--bd);overflow:auto;padding:1rem;visibility:hidden}.nw-ins.open{transform:none;visibility:visible}.nw-ins h4{margin:1.1rem 0 .4rem;font-size:12px;color:var(--mu);text-transform:uppercase;letter-spacing:.05em}.nw-x{background:none;border:0;color:var(--mu);font-size:22px;cursor:pointer}.nw-tabs{display:flex;gap:.3rem;margin:.6rem 0}.nw-tabs button{flex:1;padding:.4rem;border:1px solid var(--bd);background:none;color:var(--tx);border-radius:8px;cursor:pointer;font:inherit}.nw-tabs button.on{background:#6d28d9;color:#fff;border-color:#6d28d9}.nw-kpis{display:grid;grid-template-columns:repeat(3,1fr);gap:.5rem}.nw-kpi{background:var(--bg);border:1px solid var(--bd);border-radius:10px;padding:.5rem .6rem}.nw-kpi b{display:block;font-size:1.05rem}.nw-kpi small{color:var(--mu)}.nw-row{display:flex;justify-content:space-between;gap:.6rem;font-size:13px;padding:.3rem 0;border-bottom:1px solid var(--bd)}.nw-row span:last-child{color:var(--mu);text-align:right}.nw-meter{height:5px;background:var(--bd);border-radius:9px;overflow:hidden;margin:.2rem 0 .3rem}.nw-meter i{display:block;height:100%;background:var(--ac)}.nw-warn{color:#d97706}.nw pre{background:var(--bg);border:1px solid var(--bd);border-radius:10px;padding:.7rem;overflow-x:auto;font-size:12px}.nw-ins input{width:100%;padding:.5rem;border-radius:8px;border:1px solid var(--bd);background:var(--bg);color:var(--tx);font:inherit}.nw-ins p{color:var(--mu);font-size:13px}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from 'react';
|
|
2
2
|
export declare const SurveyApp: React.FC;
|
package/dist/survey/data.d.ts
CHANGED
package/dist/survey/nps.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Survey, SurveyResponse } from '../types';
|
|
1
|
+
import type { Survey, SurveyResponse } from '../types';
|
|
2
2
|
export type NpsCategory = 'promoter' | 'passive' | 'detractor';
|
|
3
3
|
export declare const npsCategory: (s: number) => NpsCategory;
|
|
4
4
|
/** NPS = % promoters (9-10) minus % detractors (0-6). Passives (7-8) only count in the total. */
|
package/dist/ui.d.ts
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { JourneyTracker, type Theme, type TrackerConfig, type TrackerState } from './tracker';
|
|
3
|
+
import { type TourConfig } from './tour';
|
|
4
|
+
export interface JourneyConfig extends TrackerConfig, TourConfig {
|
|
5
|
+
theme?: Theme;
|
|
6
|
+
}
|
|
7
|
+
export interface JourneyApi {
|
|
8
|
+
tracker: JourneyTracker;
|
|
9
|
+
theme: Theme;
|
|
10
|
+
resolvedTheme: 'light' | 'dark';
|
|
11
|
+
setTheme: (t: Theme) => void;
|
|
12
|
+
open: boolean;
|
|
13
|
+
start: () => void;
|
|
14
|
+
stop: () => void;
|
|
15
|
+
next: () => void;
|
|
16
|
+
back: () => void;
|
|
17
|
+
heat: boolean;
|
|
18
|
+
toggleHeat: () => void;
|
|
19
|
+
configure: (o: Partial<TrackerConfig>) => void;
|
|
20
|
+
}
|
|
21
|
+
export declare function useJourney(): JourneyApi;
|
|
22
|
+
/** Live tracker state; re-renders about twice a second and on tour events. */
|
|
23
|
+
export declare function useJourneyStats(): TrackerState;
|
|
24
|
+
export declare const JourneyProvider: React.FC<{
|
|
25
|
+
config?: JourneyConfig;
|
|
26
|
+
children?: React.ReactNode;
|
|
27
|
+
}>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { JourneyTracker } from './tracker';
|
|
3
|
+
import { type ResolvedStep } from './tour';
|
|
4
|
+
import './walkthrough.css';
|
|
5
|
+
interface Props {
|
|
6
|
+
open: boolean;
|
|
7
|
+
anim: boolean;
|
|
8
|
+
theme: 'light' | 'dark';
|
|
9
|
+
steps: ResolvedStep[];
|
|
10
|
+
index: number;
|
|
11
|
+
startLabel?: string;
|
|
12
|
+
tracker: JourneyTracker;
|
|
13
|
+
onNext: () => void;
|
|
14
|
+
onBack: () => void;
|
|
15
|
+
onSkip: () => void;
|
|
16
|
+
onTheme: () => void;
|
|
17
|
+
}
|
|
18
|
+
export declare const TourOverlay: React.FC<Props>;
|
|
19
|
+
/** Heatmap overlay drawn from the tracker's mouse and click bins. */
|
|
20
|
+
export declare const HeatCanvas: React.FC<{
|
|
21
|
+
tracker: JourneyTracker;
|
|
22
|
+
}>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type JourneyConfig } from './JourneyProvider';
|
|
3
|
+
import './demo.css';
|
|
4
|
+
export interface WalkthroughDemoProps {
|
|
5
|
+
/** POST target for events. Defaults to the ?api= query parameter, else dry-run. */
|
|
6
|
+
endpoint?: string;
|
|
7
|
+
config?: JourneyConfig;
|
|
8
|
+
}
|
|
9
|
+
/** Self-contained Northwind demo: sample site + tour + Insights panel. */
|
|
10
|
+
export declare const WalkthroughDemo: React.FC<WalkthroughDemoProps>;
|
|
11
|
+
export default WalkthroughDemo;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { JourneyProvider, useJourney, useJourneyStats } from './JourneyProvider';
|
|
2
|
+
export type { JourneyConfig, JourneyApi } from './JourneyProvider';
|
|
3
|
+
export { WalkthroughDemo } from './WalkthroughDemo';
|
|
4
|
+
export type { WalkthroughDemoProps } from './WalkthroughDemo';
|
|
5
|
+
export { JourneyTracker } from './tracker';
|
|
6
|
+
export type { Theme, Placement, TrackerConfig, TrackerState, JourneyEvent } from './tracker';
|
|
7
|
+
export type { TourStep, TourConfig } from './tour';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Placement } from './tracker';
|
|
2
|
+
export interface TourStep {
|
|
3
|
+
target?: string;
|
|
4
|
+
page?: string;
|
|
5
|
+
title: string;
|
|
6
|
+
body: string;
|
|
7
|
+
placement?: Placement;
|
|
8
|
+
}
|
|
9
|
+
export interface ResolvedStep {
|
|
10
|
+
el: HTMLElement | null;
|
|
11
|
+
title: string;
|
|
12
|
+
body: string;
|
|
13
|
+
placement: Placement;
|
|
14
|
+
page?: string;
|
|
15
|
+
target?: string;
|
|
16
|
+
wait?: boolean;
|
|
17
|
+
welcome?: boolean;
|
|
18
|
+
outro?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface TourConfig {
|
|
21
|
+
steps?: TourStep[];
|
|
22
|
+
welcome?: {
|
|
23
|
+
title: string;
|
|
24
|
+
body: string;
|
|
25
|
+
};
|
|
26
|
+
outro?: {
|
|
27
|
+
title: string;
|
|
28
|
+
body: string;
|
|
29
|
+
};
|
|
30
|
+
startLabel?: string;
|
|
31
|
+
/** How long to wait for a step's target to appear before skipping it. */
|
|
32
|
+
waitMs?: number;
|
|
33
|
+
autoStart?: boolean;
|
|
34
|
+
/** Only auto-start until the visitor has finished or skipped the tour once. */
|
|
35
|
+
once?: boolean;
|
|
36
|
+
}
|
|
37
|
+
export declare const vis: (el: Element | null | undefined) => el is HTMLElement;
|
|
38
|
+
/** Steps come from config, else from data-sj-* attributes, else from the page's header, nav, sections and footer. */
|
|
39
|
+
export declare function collect(cfg: TourConfig): ResolvedStep[];
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
export type Placement = 'auto' | 'top' | 'bottom' | 'left' | 'right';
|
|
2
|
+
export type Theme = 'auto' | 'light' | 'dark';
|
|
3
|
+
export interface TrackerConfig {
|
|
4
|
+
/** POST target for event batches. Without it the tracker runs in dry-run mode. */
|
|
5
|
+
endpoint?: string;
|
|
6
|
+
headers?: Record<string, string>;
|
|
7
|
+
flushMs?: number;
|
|
8
|
+
tourId?: string;
|
|
9
|
+
onEvent?: (e: JourneyEvent) => void;
|
|
10
|
+
}
|
|
11
|
+
export interface PageStat {
|
|
12
|
+
ms: number;
|
|
13
|
+
scrollMs: number;
|
|
14
|
+
depth: number;
|
|
15
|
+
clicks: number;
|
|
16
|
+
views: number;
|
|
17
|
+
m: Record<number, 1>;
|
|
18
|
+
}
|
|
19
|
+
export interface StepStat {
|
|
20
|
+
views: number;
|
|
21
|
+
ms: number;
|
|
22
|
+
title: string;
|
|
23
|
+
}
|
|
24
|
+
export interface LogEntry {
|
|
25
|
+
type: string;
|
|
26
|
+
t: number;
|
|
27
|
+
[k: string]: unknown;
|
|
28
|
+
}
|
|
29
|
+
export interface JourneyEvent extends LogEntry {
|
|
30
|
+
sid: string;
|
|
31
|
+
uid: string;
|
|
32
|
+
page: string;
|
|
33
|
+
}
|
|
34
|
+
export interface TrackerState {
|
|
35
|
+
pages: Record<string, PageStat>;
|
|
36
|
+
scrollMs: number;
|
|
37
|
+
clicks: number;
|
|
38
|
+
nav: number;
|
|
39
|
+
heat: Record<string, Record<string, number>>;
|
|
40
|
+
steps: Record<number, StepStat>;
|
|
41
|
+
started: number;
|
|
42
|
+
completed: number;
|
|
43
|
+
skipped: number;
|
|
44
|
+
drops: Record<number, number>;
|
|
45
|
+
log: LogEntry[];
|
|
46
|
+
}
|
|
47
|
+
export declare const pageKey: () => string;
|
|
48
|
+
/** Passive analytics: time on page, scroll depth, clicks, navigation, heat bins and tour funnel. No DOM rendering. */
|
|
49
|
+
export declare class JourneyTracker {
|
|
50
|
+
private getCfg;
|
|
51
|
+
readonly uid: string;
|
|
52
|
+
readonly sid: string;
|
|
53
|
+
state: TrackerState;
|
|
54
|
+
/** Set by the tour while a step is showing so time is credited to it. */
|
|
55
|
+
activeStep: number | null;
|
|
56
|
+
private q;
|
|
57
|
+
private version;
|
|
58
|
+
private subs;
|
|
59
|
+
private navSubs;
|
|
60
|
+
private overrides;
|
|
61
|
+
private prev;
|
|
62
|
+
private booted;
|
|
63
|
+
private scrolling;
|
|
64
|
+
private scrollTimer;
|
|
65
|
+
private lastMove;
|
|
66
|
+
constructor(getCfg: () => TrackerConfig);
|
|
67
|
+
get cfg(): TrackerConfig;
|
|
68
|
+
configure(o: Partial<TrackerConfig>): void;
|
|
69
|
+
subscribe: (fn: () => void) => () => void;
|
|
70
|
+
getVersion: () => number;
|
|
71
|
+
private emit;
|
|
72
|
+
onNavigate(fn: () => void): () => void;
|
|
73
|
+
page(k?: string): PageStat;
|
|
74
|
+
private save;
|
|
75
|
+
private bin;
|
|
76
|
+
track(type: string, d?: Record<string, unknown>): void;
|
|
77
|
+
private payload;
|
|
78
|
+
flush(hide?: boolean): void;
|
|
79
|
+
tourStart(steps: number, resume: boolean): void;
|
|
80
|
+
stepView(n: number, title: string, total: number): void;
|
|
81
|
+
tourEnd(kind: 'complete' | 'skip', i: number, title: string, total: number): void;
|
|
82
|
+
attach(): () => void;
|
|
83
|
+
}
|
package/package.json
CHANGED
|
@@ -1,37 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shiva004/surveys",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Survey and User Journey POC components for React",
|
|
4
5
|
"type": "module",
|
|
5
|
-
"main": "./dist/index.
|
|
6
|
+
"main": "./dist/index.js",
|
|
6
7
|
"module": "./dist/index.js",
|
|
7
8
|
"types": "./dist/index.d.ts",
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
10
11
|
"types": "./dist/index.d.ts",
|
|
11
|
-
"import": "./dist/index.js"
|
|
12
|
-
"require": "./dist/index.cjs"
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
13
|
},
|
|
14
14
|
"./style.css": "./dist/style.css"
|
|
15
15
|
},
|
|
16
|
-
"files": [
|
|
17
|
-
|
|
18
|
-
],
|
|
16
|
+
"files": ["dist"],
|
|
17
|
+
"sideEffects": ["**/*.css"],
|
|
19
18
|
"scripts": {
|
|
20
19
|
"dev": "vite",
|
|
21
|
-
"build": "
|
|
22
|
-
"
|
|
20
|
+
"build": "vite build && tsc -p tsconfig.build.json",
|
|
21
|
+
"prepublishOnly": "npm run build"
|
|
23
22
|
},
|
|
24
23
|
"peerDependencies": {
|
|
25
|
-
"react": "
|
|
26
|
-
"react-dom": "
|
|
24
|
+
"react": ">=18",
|
|
25
|
+
"react-dom": ">=18"
|
|
27
26
|
},
|
|
28
27
|
"devDependencies": {
|
|
29
|
-
"@types/node": "^26.6.6",
|
|
30
28
|
"@types/react": "^18.3.3",
|
|
31
29
|
"@types/react-dom": "^18.3.0",
|
|
32
30
|
"@vitejs/plugin-react": "^4.3.1",
|
|
31
|
+
"react": "^18.3.1",
|
|
32
|
+
"react-dom": "^18.3.1",
|
|
33
33
|
"typescript": "^5.5.4",
|
|
34
|
-
"vite": "^5.4.2"
|
|
35
|
-
"vite-plugin-dts": "^5.1.2"
|
|
34
|
+
"vite": "^5.4.2"
|
|
36
35
|
}
|
|
37
36
|
}
|
package/dist/index.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
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/main.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|