@trailguide/runtime 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,105 @@
1
+ # @trailguide/runtime
2
+
3
+ React wrapper for Trailguide. Provides hooks and components for React apps.
4
+
5
+ > **Note:** For non-React apps, use `@trailguide/core` directly.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @trailguide/runtime @trailguide/core
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```tsx
16
+ import { useState } from 'react';
17
+ import { Trailguide } from '@trailguide/runtime';
18
+ import '@trailguide/core/dist/style.css';
19
+ import myTour from './tours/my-tour.json';
20
+
21
+ function App() {
22
+ const [showTour, setShowTour] = useState(true);
23
+
24
+ return (
25
+ <>
26
+ <YourApp />
27
+ {showTour && (
28
+ <Trailguide
29
+ trail={myTour}
30
+ onComplete={() => setShowTour(false)}
31
+ onSkip={() => setShowTour(false)}
32
+ onStepChange={(step, index) => console.log(`Step ${index}:`, step)}
33
+ />
34
+ )}
35
+ </>
36
+ );
37
+ }
38
+ ```
39
+
40
+ ## API
41
+
42
+ ### `<Trailguide>`
43
+
44
+ Main component that renders the tour.
45
+
46
+ | Prop | Type | Description |
47
+ |------|------|-------------|
48
+ | `trail` | `Trail` | The trail JSON object |
49
+ | `onComplete` | `() => void` | Called when user finishes all steps |
50
+ | `onSkip` | `() => void` | Called when user skips the tour |
51
+ | `onStepChange` | `(step, index) => void` | Called on each step change |
52
+
53
+ ### `useTrail(options)`
54
+
55
+ Hook for programmatic control.
56
+
57
+ ```tsx
58
+ import { useTrail } from '@trailguide/runtime';
59
+
60
+ const {
61
+ currentStep,
62
+ currentStepIndex,
63
+ totalSteps,
64
+ isActive,
65
+ next,
66
+ prev,
67
+ skip,
68
+ goToStep,
69
+ start,
70
+ stop,
71
+ } = useTrail({
72
+ trail,
73
+ onComplete,
74
+ onStepChange,
75
+ autoStart: false, // set true to start immediately
76
+ });
77
+ ```
78
+
79
+ ## Types
80
+
81
+ Types are re-exported from `@trailguide/core`:
82
+
83
+ ```typescript
84
+ import type { Trail, Step, Placement } from '@trailguide/runtime';
85
+ ```
86
+
87
+ ## Keyboard Navigation
88
+
89
+ - `→` or `Enter` - Next step
90
+ - `←` - Previous step
91
+ - `Escape` - Skip tour
92
+
93
+ ## Styling
94
+
95
+ Import styles from the core package:
96
+
97
+ ```tsx
98
+ import '@trailguide/core/dist/style.css';
99
+ ```
100
+
101
+ CSS classes available for customization:
102
+ - `.trailguide-overlay` - Main overlay container
103
+ - `.trailguide-spotlight` - The darkened backdrop
104
+ - `.trailguide-highlight` - Border around target element
105
+ - `.trailguide-tooltip` - The tooltip container
@@ -0,0 +1,10 @@
1
+ import { Trail, Step } from '@trailguide/core';
2
+
3
+ export interface TrailguideProps {
4
+ trail: Trail;
5
+ onComplete?: () => void;
6
+ onStepChange?: (step: Step, index: number) => void;
7
+ onSkip?: () => void;
8
+ }
9
+ export declare function Trailguide({ trail, onComplete, onStepChange, onSkip, }: TrailguideProps): null;
10
+ //# sourceMappingURL=Trailguide.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Trailguide.d.ts","sourceRoot":"","sources":["../../src/components/Trailguide.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAIpD,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,KAAK,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnD,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,wBAAgB,UAAU,CAAC,EACzB,KAAK,EACL,UAAU,EACV,YAAY,EACZ,MAAM,GACP,EAAE,eAAe,QAqBjB"}
@@ -0,0 +1,23 @@
1
+ import { Trail, Step } from '@trailguide/core';
2
+
3
+ export interface UseTrailOptions {
4
+ trail: Trail;
5
+ onComplete?: () => void;
6
+ onStepChange?: (step: Step, index: number) => void;
7
+ onSkip?: () => void;
8
+ autoStart?: boolean;
9
+ }
10
+ export interface UseTrailReturn {
11
+ currentStep: Step | null;
12
+ currentStepIndex: number;
13
+ totalSteps: number;
14
+ isActive: boolean;
15
+ next: () => void;
16
+ prev: () => void;
17
+ skip: () => void;
18
+ goToStep: (index: number) => void;
19
+ start: () => void;
20
+ stop: () => void;
21
+ }
22
+ export declare function useTrail({ trail, onComplete, onStepChange, onSkip, autoStart, }: UseTrailOptions): UseTrailReturn;
23
+ //# sourceMappingURL=useTrail.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTrail.d.ts","sourceRoot":"","sources":["../../src/hooks/useTrail.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAEpD,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,KAAK,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnD,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,IAAI,GAAG,IAAI,CAAC;IACzB,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,IAAI,EAAE,MAAM,IAAI,CAAC;CAClB;AAED,wBAAgB,QAAQ,CAAC,EACvB,KAAK,EACL,UAAU,EACV,YAAY,EACZ,MAAM,EACN,SAAiB,GAClB,EAAE,eAAe,GAAG,cAAc,CA+ElC"}
@@ -0,0 +1,7 @@
1
+ export type { Trail, Step, Placement, StepAction, NextTrigger, TrailguideOptions, } from '@trailguide/core';
2
+ export { findElement, isElementVisible, scrollToElement, } from '@trailguide/core';
3
+ export { Trailguide } from './components/Trailguide';
4
+ export type { TrailguideProps } from './components/Trailguide';
5
+ export { useTrail } from './hooks/useTrail';
6
+ export type { UseTrailOptions, UseTrailReturn } from './hooks/useTrail';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,KAAK,EACL,IAAI,EACJ,SAAS,EACT,UAAU,EACV,WAAW,EACX,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,eAAe,GAChB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,YAAY,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,79 @@
1
+ import { Trailguide as d } from "@trailguide/core";
2
+ import { findElement as B, isElementVisible as D, scrollToElement as F } from "@trailguide/core";
3
+ import { useRef as x, useEffect as v, useState as p, useCallback as l } from "react";
4
+ function j({
5
+ trail: e,
6
+ onComplete: s,
7
+ onStepChange: c,
8
+ onSkip: u
9
+ }) {
10
+ const n = x(null);
11
+ return v(() => (n.current = new d({
12
+ onComplete: s,
13
+ onStepChange: c,
14
+ onSkip: u
15
+ }), n.current.start(e), () => {
16
+ var f;
17
+ (f = n.current) == null || f.stop();
18
+ }), [e, s, c, u]), null;
19
+ }
20
+ function q({
21
+ trail: e,
22
+ onComplete: s,
23
+ onStepChange: c,
24
+ onSkip: u,
25
+ autoStart: n = !1
26
+ }) {
27
+ const [f, T] = p(0), [a, i] = p(!1), r = x(null), E = a && e.steps[f] ? e.steps[f] : null, m = e.steps.length;
28
+ v(() => (r.current = new d({
29
+ onComplete: () => {
30
+ i(!1), s == null || s();
31
+ },
32
+ onStepChange: (t, o) => {
33
+ T(o), c == null || c(t, o);
34
+ },
35
+ onSkip: () => {
36
+ i(!1), u == null || u();
37
+ }
38
+ }), n && (r.current.start(e), i(!0)), () => {
39
+ var t;
40
+ (t = r.current) == null || t.stop();
41
+ }), [e, s, c, u, n]);
42
+ const I = l(() => {
43
+ r.current && (r.current.start(e), i(!0), T(0));
44
+ }, [e]), R = l(() => {
45
+ var t;
46
+ (t = r.current) == null || t.stop(), i(!1);
47
+ }, []), b = l(() => {
48
+ var t;
49
+ (t = r.current) == null || t.next();
50
+ }, []), w = l(() => {
51
+ var t;
52
+ (t = r.current) == null || t.prev();
53
+ }, []), A = l(() => {
54
+ var t;
55
+ (t = r.current) == null || t.skip();
56
+ }, []), g = l((t) => {
57
+ var o;
58
+ (o = r.current) == null || o.goToStep(t);
59
+ }, []);
60
+ return {
61
+ currentStep: E,
62
+ currentStepIndex: f,
63
+ totalSteps: m,
64
+ isActive: a,
65
+ next: b,
66
+ prev: w,
67
+ skip: A,
68
+ goToStep: g,
69
+ start: I,
70
+ stop: R
71
+ };
72
+ }
73
+ export {
74
+ j as Trailguide,
75
+ B as findElement,
76
+ D as isElementVisible,
77
+ F as scrollToElement,
78
+ q as useTrail
79
+ };
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@trailguide/runtime",
3
+ "version": "0.0.1",
4
+ "description": "React hooks and components for Trailguide product tours.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "dev": "vite build --watch",
20
+ "build": "vite build && tsc --emitDeclarationOnly",
21
+ "typecheck": "tsc --noEmit"
22
+ },
23
+ "keywords": [
24
+ "react",
25
+ "product-tour",
26
+ "onboarding",
27
+ "walkthrough",
28
+ "tutorial",
29
+ "trailguide"
30
+ ],
31
+ "author": "Branden Langhals",
32
+ "license": "MIT",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/brandenlanghals/trailguide.git",
36
+ "directory": "packages/runtime"
37
+ },
38
+ "homepage": "https://github.com/brandenlanghals/trailguide#readme",
39
+ "bugs": {
40
+ "url": "https://github.com/brandenlanghals/trailguide/issues"
41
+ },
42
+ "peerDependencies": {
43
+ "react": "^18.0.0",
44
+ "react-dom": "^18.0.0"
45
+ },
46
+ "dependencies": {
47
+ "@trailguide/core": "^0.0.1"
48
+ },
49
+ "devDependencies": {
50
+ "@types/react": "^18.2.0",
51
+ "@types/react-dom": "^18.2.0",
52
+ "@vitejs/plugin-react": "^4.2.0",
53
+ "react": "^18.2.0",
54
+ "react-dom": "^18.2.0",
55
+ "typescript": "^5.4.0",
56
+ "vite": "^5.2.0",
57
+ "vite-plugin-dts": "^3.8.0"
58
+ }
59
+ }