@prosdevlab/experience-sdk-plugins 0.1.4 → 0.3.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.
Files changed (43) hide show
  1. package/.turbo/turbo-build.log +6 -6
  2. package/CHANGELOG.md +150 -0
  3. package/README.md +141 -79
  4. package/dist/index.d.ts +813 -35
  5. package/dist/index.js +1910 -66
  6. package/dist/index.js.map +1 -1
  7. package/package.json +1 -1
  8. package/src/banner/banner.ts +63 -62
  9. package/src/exit-intent/exit-intent.test.ts +423 -0
  10. package/src/exit-intent/exit-intent.ts +371 -0
  11. package/src/exit-intent/index.ts +6 -0
  12. package/src/exit-intent/types.ts +59 -0
  13. package/src/index.ts +7 -0
  14. package/src/inline/index.ts +3 -0
  15. package/src/inline/inline.test.ts +620 -0
  16. package/src/inline/inline.ts +269 -0
  17. package/src/inline/insertion.ts +66 -0
  18. package/src/inline/types.ts +52 -0
  19. package/src/integration.test.ts +421 -0
  20. package/src/modal/form-rendering.ts +262 -0
  21. package/src/modal/form-styles.ts +212 -0
  22. package/src/modal/form-validation.test.ts +413 -0
  23. package/src/modal/form-validation.ts +126 -0
  24. package/src/modal/index.ts +3 -0
  25. package/src/modal/modal-styles.ts +204 -0
  26. package/src/modal/modal.browser.test.ts +164 -0
  27. package/src/modal/modal.test.ts +1294 -0
  28. package/src/modal/modal.ts +685 -0
  29. package/src/modal/types.ts +114 -0
  30. package/src/page-visits/index.ts +6 -0
  31. package/src/page-visits/page-visits.test.ts +562 -0
  32. package/src/page-visits/page-visits.ts +314 -0
  33. package/src/page-visits/types.ts +119 -0
  34. package/src/scroll-depth/index.ts +6 -0
  35. package/src/scroll-depth/scroll-depth.test.ts +580 -0
  36. package/src/scroll-depth/scroll-depth.ts +398 -0
  37. package/src/scroll-depth/types.ts +122 -0
  38. package/src/time-delay/index.ts +6 -0
  39. package/src/time-delay/time-delay.test.ts +477 -0
  40. package/src/time-delay/time-delay.ts +296 -0
  41. package/src/time-delay/types.ts +89 -0
  42. package/src/types.ts +20 -36
  43. package/src/utils/sanitize.ts +5 -2
@@ -1,5 +1,5 @@
1
1
 
2
- > @prosdevlab/experience-sdk-plugins@0.1.4 build /home/runner/work/experience-sdk/experience-sdk/packages/plugins
2
+ > @prosdevlab/experience-sdk-plugins@0.3.0 build /home/runner/work/experience-sdk/experience-sdk/packages/plugins
3
3
  > tsup
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -9,9 +9,9 @@
9
9
  CLI Target: es2024
10
10
  CLI Cleaning output folder
11
11
  ESM Build start
12
- ESM dist/index.js 19.53 KB
13
- ESM dist/index.js.map 48.09 KB
14
- ESM ⚡️ Build success in 140ms
12
+ ESM dist/index.js 79.10 KB
13
+ ESM dist/index.js.map 191.96 KB
14
+ ESM ⚡️ Build success in 304ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 857ms
17
- DTS dist/index.d.ts 5.46 KB
16
+ DTS ⚡️ Build success in 1228ms
17
+ DTS dist/index.d.ts 28.79 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,155 @@
1
1
  # @prosdevlab/experience-sdk-plugins
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 2fc279c: **Phase 2: Presentation Layer - Modal & Inline Plugins**
8
+
9
+ This release introduces two powerful new rendering plugins with built-in form support, completing the presentation layer for the Experience SDK.
10
+
11
+ ## 🎉 New Features
12
+
13
+ ### Modal Plugin
14
+
15
+ - **Rich Content Modals**: Display announcements, promotions, and interactive content
16
+ - **Built-in Forms**: Email capture, surveys, and feedback forms with validation
17
+ - **Size Variants**: Small, medium, large, and extra-large sizes
18
+ - **Hero Images**: Full-width images for visual impact
19
+ - **Responsive Design**: Mobile fullscreen mode for optimal UX
20
+ - **Keyboard Navigation**: Focus trap, Escape key, Tab navigation
21
+ - **Animations**: Smooth fade-in/fade-out transitions
22
+ - **Form States**: Success, error, and loading states
23
+ - **API Methods**: `show()`, `remove()`, `isShowing()`, `showFormState()`, `resetForm()`, `getFormData()`
24
+
25
+ ### Inline Plugin
26
+
27
+ - **DOM Insertion**: Embed content anywhere in your page
28
+ - **5 Insertion Methods**: `replace`, `append`, `prepend`, `before`, `after`
29
+ - **CSS Selector Targeting**: Use any valid selector to target elements
30
+ - **Dismissal with Persistence**: Users can dismiss and it persists in localStorage
31
+ - **No Layout Disruption**: Seamlessly integrates with existing page structure
32
+ - **API Methods**: `show()`, `remove()`, `isShowing()`
33
+
34
+ ### Forms (Built into Modal)
35
+
36
+ - **Field Types**: text, email, url, tel, number, textarea, select, checkbox, radio
37
+ - **Validation**: Required, email, URL, pattern, custom validation, min/max length
38
+ - **Real-time Feedback**: Validates on blur, shows errors inline
39
+ - **Submission Handling**: Emits `experiences:modal:form:submit` event
40
+ - **Success/Error States**: Built-in UI for post-submission states
41
+ - **Pure Functions**: Validation and rendering logic easily extractable
42
+
43
+ ## 🎨 Theming & Customization
44
+
45
+ ### CSS Variables
46
+
47
+ All plugins now support CSS variable theming:
48
+
49
+ - **Modal**: `--xp-modal-*` variables for backdrop, dialog, title, content, buttons
50
+ - **Forms**: `--xp-form-*` variables for inputs, labels, errors, submit button
51
+ - **Banner**: `--xp-banner-*` variables (refactored from inline styles)
52
+ - **Inline**: `--xp-inline-*` variables for custom styling
53
+
54
+ See the [Theming Guide](https://prosdevlab.github.io/experience-sdk/guides/theming) for full reference.
55
+
56
+ ## 🔧 API Improvements
57
+
58
+ ### Runtime
59
+
60
+ - **Auto-registration**: Modal and inline plugins are automatically registered
61
+ - **Plugin API Access**: Expose plugin APIs via singleton (`experiences.modal.show()`)
62
+ - **Trigger Event Handling**: Explicit listeners for each trigger type (exit intent, scroll depth, time delay)
63
+
64
+ ### Display Conditions
65
+
66
+ Seamless integration with existing display condition plugins:
67
+
68
+ - **Exit Intent + Modal**: Capture emails before users leave
69
+ - **Scroll Depth + Inline**: Progressive feature discovery
70
+ - **Time Delay + Modal**: Time-sensitive promotions
71
+ - **Page Visits + Banner**: Returning user messages
72
+
73
+ ## 📦 Bundle Size
74
+
75
+ - **Core SDK**: 13.4 KB gzipped (under 15 KB target ✅)
76
+ - **All Plugins**: ~26 KB gzipped total (smaller than competitors like Pathfora at ~47 KB)
77
+ - **Excellent Compression**: CSS-in-JS with CSS variables maintains small footprint
78
+
79
+ ## 🧪 Testing
80
+
81
+ - **432 tests passing** (unit, integration, browser tests)
82
+ - **Modal Plugin**: 56 tests for core functionality, forms, keyboard nav, accessibility
83
+ - **Inline Plugin**: 24 tests for DOM insertion, dismissal, persistence
84
+ - **Form Validation**: 35 tests for all field types and edge cases
85
+ - **Integration Tests**: 10 tests for plugin interactions
86
+ - **Exit Intent**: 21 tests with timing and sensitivity validation
87
+
88
+ ## 📚 Documentation
89
+
90
+ - **Modal Plugin Reference**: Complete API docs with examples
91
+ - **Inline Plugin Reference**: Full insertion method documentation
92
+ - **Theming Guide**: CSS variable reference with examples
93
+ - **Use Case Examples**: 4 complete implementation guides in playground
94
+
95
+ ## 🚀 Playground Enhancements
96
+
97
+ - **Layout Gallery Hub**: Visual directory for banner, modal, and inline layouts
98
+ - **Navigation System**: Breadcrumbs and sub-navigation tabs
99
+ - **Use Case Examples**:
100
+ - Exit Intent Email Capture (exit intent + modal forms)
101
+ - Feature Discovery Journey (scroll depth + inline + modal)
102
+ - Time-Delayed Promotions (time delay + hero image modal)
103
+ - Promotions & Announcements (banner examples)
104
+ - **Interactive Demos**: Live examples with SDK integration
105
+
106
+ ## ⚠️ Breaking Changes
107
+
108
+ None. This is a **minor** release with backward compatibility.
109
+
110
+ ## 🔜 Next Steps (Phase 3+)
111
+
112
+ - Browser tests for form focus management
113
+ - Composable form plugin (separate from modal)
114
+ - Additional layout plugins (tooltip, slideout, sticky bar)
115
+ - Multi-instance support with `instanceId` tracking
116
+
117
+ ***
118
+
119
+ **Migration Guide**: No migration needed. Simply upgrade and start using the new plugins!
120
+
121
+ **Full Changelog**: See [Phase 2 Spec](https://github.com/prosdevlab/experience-sdk/blob/main/specs/phase-2-presentation-layer/spec.md)
122
+
123
+ ## 0.2.0
124
+
125
+ ### Minor Changes
126
+
127
+ - 02de640: feat: add display condition plugins with event-driven architecture
128
+
129
+ Add 4 new display condition plugins with comprehensive testing and documentation:
130
+
131
+ **New Plugins:**
132
+
133
+ - Exit Intent: Velocity-based mouse tracking with session awareness
134
+ - Scroll Depth: Multiple thresholds with advanced engagement metrics
135
+ - Page Visits: Session and lifetime counters with first-visit detection
136
+ - Time Delay: Millisecond-precision delays with visibility API integration
137
+
138
+ **Core Enhancements:**
139
+
140
+ - Event-driven trigger architecture (`trigger:*` events)
141
+ - Composable display conditions (AND/OR/NOT logic)
142
+ - TriggerState interface for type-safe context updates
143
+
144
+ **Developer Experience:**
145
+
146
+ - 101 new tests across 4 plugins (314 total)
147
+ - 12 integration tests for plugin composition
148
+ - Complete API documentation with examples
149
+ - Pure functions for easier testing
150
+
151
+ All plugins are backward compatible and work independently or together.
152
+
3
153
  ## 0.1.4
4
154
 
5
155
  ### Patch Changes
package/README.md CHANGED
@@ -2,100 +2,90 @@
2
2
 
3
3
  Official plugins for [Experience SDK](https://github.com/prosdevlab/experience-sdk).
4
4
 
5
- **Size:** 13.4 KB (ESM)
5
+ **Size:** 12.7 KB gzipped (all plugins)
6
6
 
7
7
  ## Included Plugins
8
8
 
9
- ### Banner Plugin
9
+ ### Layout Plugins
10
10
 
11
- Renders banner experiences in the DOM with automatic positioning, theming, and responsive layout.
11
+ **Banner Plugin** - Top/bottom notification bars with push-down support
12
12
 
13
13
  **Features:**
14
14
  - Multiple buttons with variants (primary, secondary, link)
15
15
  - Responsive layout (desktop inline, mobile stack)
16
- - Automatic theme detection (light/dark mode)
17
- - Top/bottom positioning
18
- - Dismissable with close button
19
- - **CSS customization** via `className` and `style` props
20
- - Stable `.xp-*` CSS classes for styling
16
+ - Top/bottom positioning with optional push-down
17
+ - HTML sanitization for XSS protection
18
+ - CSS variables for full theming
21
19
 
22
- ```typescript
23
- import { createInstance, bannerPlugin } from '@prosdevlab/experience-sdk-plugins';
24
-
25
- const sdk = createInstance();
26
- sdk.use(bannerPlugin);
20
+ **Modal Plugin** - Overlay dialogs with forms and rich content
27
21
 
28
- sdk.banner.show({
29
- id: 'welcome',
30
- type: 'banner',
31
- content: {
32
- title: 'Welcome!',
33
- message: 'Thanks for visiting.',
34
- buttons: [
35
- { text: 'Get Started', url: '/start', variant: 'primary' }
36
- ],
37
- position: 'top',
38
- dismissable: true
39
- }
40
- });
41
- ```
22
+ **Features:**
23
+ - Multiple sizes (sm, md, lg, fullscreen, auto)
24
+ - Mobile fullscreen for large modals
25
+ - Hero images with max height
26
+ - Animations (fade, slide-up, none)
27
+ - Built-in form support with validation
28
+ - Focus trap and keyboard support (Escape)
29
+ - CSS variables for full theming
42
30
 
43
- **Customization:**
31
+ **Inline Plugin** - In-content experiences using CSS selectors
44
32
 
45
- The banner plugin uses `.xp-*` CSS classes and supports custom styling:
33
+ **Features:**
34
+ - 5 insertion methods (replace, append, prepend, before, after)
35
+ - Dismissal with persistence
36
+ - Multi-instance support
37
+ - HTML sanitization
38
+ - Custom styling (className, style props)
39
+ - CSS variables for theming
46
40
 
47
- ```typescript
48
- // With Tailwind
49
- content: {
50
- message: 'Flash Sale!',
51
- className: 'bg-gradient-to-r from-blue-600 to-purple-600 text-white',
52
- buttons: [{
53
- text: 'Shop Now',
54
- className: 'bg-white text-blue-600 hover:bg-gray-100'
55
- }]
56
- }
57
-
58
- // With inline styles
59
- content: {
60
- message: 'Flash Sale!',
61
- style: {
62
- background: 'linear-gradient(90deg, #667eea 0%, #764ba2 100%)',
63
- color: 'white'
64
- }
65
- }
66
- ```
41
+ ### Display Condition Plugins
67
42
 
68
- See the [Plugins documentation](https://prosdevlab.github.io/experience-sdk/reference/plugins#customization) for more customization examples.
43
+ **Exit Intent Plugin** - Detect when users are leaving
69
44
 
70
- ### Frequency Plugin
45
+ **Features:**
46
+ - Mouse movement tracking
47
+ - Configurable sensitivity
48
+ - Min time on page
49
+ - Delay before triggering
50
+ - Session persistence
71
51
 
72
- Manages impression tracking and frequency capping with persistent storage.
52
+ **Scroll Depth Plugin** - Track scroll engagement
73
53
 
74
54
  **Features:**
75
- - Session/day/week impression tracking
76
- - Automatic storage management
77
- - Manual impression recording
78
- - Reset capabilities
55
+ - Multiple thresholds (25%, 50%, 75%, 100%)
56
+ - Max scroll tracking
57
+ - Velocity and direction tracking
58
+ - Time-to-threshold metrics
59
+ - Throttling and resize handling
79
60
 
80
- ```typescript
81
- import { createInstance, frequencyPlugin } from '@prosdevlab/experience-sdk-plugins';
61
+ **Page Visits Plugin** - Session and lifetime counters
82
62
 
83
- const sdk = createInstance();
84
- sdk.use(frequencyPlugin);
63
+ **Features:**
64
+ - Session-scoped visits (sessionStorage)
65
+ - Lifetime visits (localStorage)
66
+ - First-visit detection
67
+ - DNT (Do Not Track) support
68
+ - Expiration and cross-tab safety
85
69
 
86
- // Check impression count
87
- const count = sdk.frequency.getImpressionCount('welcome', 'session');
70
+ **Time Delay Plugin** - Show after time elapsed
88
71
 
89
- // Record impression
90
- sdk.frequency.recordImpression('welcome');
72
+ **Features:**
73
+ - Configurable show delay
74
+ - Auto-hide after duration
75
+ - Pause when page hidden (Page Visibility API)
76
+ - Timer management
91
77
 
92
- // Reset counts
93
- sdk.frequency.reset('welcome');
94
- ```
78
+ ### Utility Plugins
95
79
 
96
- ### Debug Plugin
80
+ **Frequency Plugin** - Impression tracking and capping
97
81
 
98
- Provides console logging and window event emission for debugging and Chrome extension integration.
82
+ **Features:**
83
+ - Session/day/week impression tracking
84
+ - Automatic storage management
85
+ - Manual impression recording
86
+ - Reset capabilities
87
+
88
+ **Debug Plugin** - Logging and window events
99
89
 
100
90
  **Features:**
101
91
  - Console logging with prefix
@@ -103,18 +93,87 @@ Provides console logging and window event emission for debugging and Chrome exte
103
93
  - Automatic decision logging
104
94
  - Configurable logging levels
105
95
 
96
+ ## Quick Examples
97
+
98
+ ### Banner
99
+
106
100
  ```typescript
107
- import { createInstance, debugPlugin } from '@prosdevlab/experience-sdk-plugins';
101
+ import { createInstance, bannerPlugin } from '@prosdevlab/experience-sdk-plugins';
108
102
 
109
- const sdk = createInstance({ debug: true });
110
- sdk.use(debugPlugin);
103
+ const sdk = createInstance();
104
+ sdk.use(bannerPlugin);
111
105
 
112
- // Manual logging
113
- sdk.debug.log('Custom message', { foo: 'bar' });
106
+ sdk.banner.show({
107
+ id: 'welcome',
108
+ type: 'banner',
109
+ content: {
110
+ message: 'Welcome! Get 20% off today.',
111
+ buttons: [
112
+ { text: 'Shop Now', url: '/shop', variant: 'primary' }
113
+ ],
114
+ position: 'top'
115
+ }
116
+ });
117
+ ```
114
118
 
115
- // Listen to debug events
116
- window.addEventListener('experiences:debug', (event) => {
117
- console.log(event.detail);
119
+ ### Modal with Form
120
+
121
+ ```typescript
122
+ sdk.modal.show({
123
+ id: 'newsletter',
124
+ type: 'modal',
125
+ content: {
126
+ title: 'Stay Updated',
127
+ message: 'Subscribe for exclusive offers.',
128
+ size: 'sm',
129
+ form: {
130
+ fields: [
131
+ { name: 'email', type: 'email', required: true }
132
+ ],
133
+ submitButton: { text: 'Subscribe', variant: 'primary' },
134
+ successState: {
135
+ title: '✓ Subscribed!',
136
+ message: 'Check your inbox.'
137
+ }
138
+ }
139
+ }
140
+ });
141
+ ```
142
+
143
+ ### Inline Experience
144
+
145
+ ```typescript
146
+ sdk.inline.show({
147
+ id: 'promo',
148
+ type: 'inline',
149
+ content: {
150
+ selector: '#sidebar',
151
+ position: 'prepend',
152
+ message: '<p><strong>Special Offer!</strong> Get 20% off with SAVE20.</p>',
153
+ buttons: [
154
+ { text: 'Shop Now', url: '/shop', variant: 'primary' }
155
+ ],
156
+ dismissable: true,
157
+ persist: true
158
+ }
159
+ });
160
+ ```
161
+
162
+ ### Exit Intent
163
+
164
+ ```typescript
165
+ // Trigger modal on exit intent
166
+ sdk.on('trigger:exitIntent', () => {
167
+ sdk.modal.show({
168
+ id: 'exit-offer',
169
+ content: {
170
+ title: 'Wait! Before You Go...',
171
+ message: 'Get 15% off your first order.',
172
+ buttons: [
173
+ { text: 'Claim Discount', variant: 'primary', url: '/checkout?code=EXIT15' }
174
+ ]
175
+ }
176
+ });
118
177
  });
119
178
  ```
120
179
 
@@ -145,8 +204,11 @@ experiences.register('banner', { ... });
145
204
  ## Documentation
146
205
 
147
206
  - [Full Documentation](https://prosdevlab.github.io/experience-sdk)
148
- - [Plugins Guide](https://prosdevlab.github.io/experience-sdk/reference/plugins)
149
- - [Banner Examples](https://prosdevlab.github.io/experience-sdk/demo/banner)
207
+ - [Banner Plugin](https://prosdevlab.github.io/experience-sdk/reference/plugins/banner)
208
+ - [Modal Plugin](https://prosdevlab.github.io/experience-sdk/reference/plugins/modal)
209
+ - [Inline Plugin](https://prosdevlab.github.io/experience-sdk/reference/plugins/inline)
210
+ - [Display Conditions](https://prosdevlab.github.io/experience-sdk/reference/plugins/exit-intent)
211
+ - [All Plugins](https://prosdevlab.github.io/experience-sdk/reference/plugins)
150
212
 
151
213
  ## License
152
214