@djangocfg/layouts 2.1.36 → 2.1.38
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 +204 -18
- package/package.json +5 -5
- package/src/components/errors/index.ts +9 -0
- package/src/components/errors/types.ts +38 -0
- package/src/layouts/AppLayout/AppLayout.tsx +33 -45
- package/src/layouts/AppLayout/BaseApp.tsx +105 -28
- package/src/layouts/AuthLayout/AuthContext.tsx +7 -1
- package/src/layouts/AuthLayout/OAuthProviders.tsx +1 -10
- package/src/layouts/AuthLayout/OTPForm.tsx +1 -0
- package/src/layouts/PrivateLayout/PrivateLayout.tsx +1 -1
- package/src/layouts/PublicLayout/PublicLayout.tsx +1 -1
- package/src/layouts/PublicLayout/components/PublicMobileDrawer.tsx +1 -1
- package/src/layouts/PublicLayout/components/PublicNavigation.tsx +1 -1
- package/src/layouts/_components/UserMenu.tsx +1 -1
- package/src/layouts/index.ts +1 -1
- package/src/layouts/types/index.ts +47 -0
- package/src/layouts/types/layout.types.ts +61 -0
- package/src/layouts/types/providers.types.ts +65 -0
- package/src/layouts/types/ui.types.ts +103 -0
- package/src/snippets/Analytics/index.ts +1 -0
- package/src/snippets/Analytics/types.ts +10 -0
- package/src/snippets/McpChat/context/ChatContext.tsx +9 -0
- package/src/snippets/PWAInstall/@docs/README.md +92 -0
- package/src/snippets/PWAInstall/@docs/research/ios-android-install-flows.md +576 -0
- package/src/snippets/PWAInstall/README.md +185 -0
- package/src/snippets/PWAInstall/components/A2HSHint.tsx +227 -0
- package/src/snippets/PWAInstall/components/DesktopGuide.tsx +229 -0
- package/src/snippets/PWAInstall/components/IOSGuide.tsx +29 -0
- package/src/snippets/PWAInstall/components/IOSGuideDrawer.tsx +101 -0
- package/src/snippets/PWAInstall/components/IOSGuideModal.tsx +101 -0
- package/src/snippets/PWAInstall/context/InstallContext.tsx +102 -0
- package/src/snippets/PWAInstall/hooks/useInstallPrompt.ts +167 -0
- package/src/snippets/PWAInstall/hooks/useIsPWA.ts +115 -0
- package/src/snippets/PWAInstall/index.ts +76 -0
- package/src/snippets/PWAInstall/types/components.ts +95 -0
- package/src/snippets/PWAInstall/types/config.ts +22 -0
- package/src/snippets/PWAInstall/types/index.ts +26 -0
- package/src/snippets/PWAInstall/types/install.ts +38 -0
- package/src/snippets/PWAInstall/types/platform.ts +29 -0
- package/src/snippets/PWAInstall/utils/localStorage.ts +181 -0
- package/src/snippets/PWAInstall/utils/logger.ts +149 -0
- package/src/snippets/PWAInstall/utils/platform.ts +151 -0
- package/src/snippets/PushNotifications/@docs/README.md +191 -0
- package/src/snippets/PushNotifications/@docs/guides/django-integration.md +648 -0
- package/src/snippets/PushNotifications/@docs/guides/service-worker.md +467 -0
- package/src/snippets/PushNotifications/@docs/guides/vapid-setup.md +352 -0
- package/src/snippets/PushNotifications/README.md +328 -0
- package/src/snippets/PushNotifications/components/PushPrompt.tsx +165 -0
- package/src/snippets/PushNotifications/config.ts +20 -0
- package/src/snippets/PushNotifications/context/DjangoPushContext.tsx +190 -0
- package/src/snippets/PushNotifications/hooks/useDjangoPush.ts +259 -0
- package/src/snippets/PushNotifications/hooks/usePushNotifications.ts +209 -0
- package/src/snippets/PushNotifications/index.ts +87 -0
- package/src/snippets/PushNotifications/types/config.ts +28 -0
- package/src/snippets/PushNotifications/types/index.ts +9 -0
- package/src/snippets/PushNotifications/types/push.ts +21 -0
- package/src/snippets/PushNotifications/utils/localStorage.ts +60 -0
- package/src/snippets/PushNotifications/utils/logger.ts +149 -0
- package/src/snippets/PushNotifications/utils/platform.ts +151 -0
- package/src/snippets/PushNotifications/utils/vapid.ts +226 -0
- package/src/snippets/index.ts +55 -0
- package/src/layouts/shared/index.ts +0 -21
- package/src/layouts/shared/types.ts +0 -211
- /package/src/layouts/{shared → types}/README.md +0 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# PushNotifications Documentation
|
|
2
|
+
|
|
3
|
+
Comprehensive documentation for the PushNotifications snippet.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
PushNotifications handles **Web Push Notifications** - subscribing, receiving, and managing push notifications.
|
|
8
|
+
|
|
9
|
+
**Responsibility**: Push notifications only (not PWA installation)
|
|
10
|
+
|
|
11
|
+
## Documentation Structure
|
|
12
|
+
|
|
13
|
+
### `/guides/`
|
|
14
|
+
Step-by-step guides:
|
|
15
|
+
- **[vapid-setup.md](./guides/vapid-setup.md)** - VAPID key generation and configuration
|
|
16
|
+
- **[django-integration.md](./guides/django-integration.md)** - Integrating with Django-CFG backend
|
|
17
|
+
- **[service-worker.md](./guides/service-worker.md)** - Service worker configuration
|
|
18
|
+
|
|
19
|
+
### `/architecture/`
|
|
20
|
+
Architecture and design:
|
|
21
|
+
- Coming soon: Push subscription flow, state management, Django integration
|
|
22
|
+
|
|
23
|
+
### `/legacy/`
|
|
24
|
+
Historical documentation:
|
|
25
|
+
- Old architecture (before snippet split)
|
|
26
|
+
|
|
27
|
+
## Quick Navigation
|
|
28
|
+
|
|
29
|
+
### For Users
|
|
30
|
+
Start here if you want to use PushNotifications:
|
|
31
|
+
- [Main README](../README.md) - Quick start and API reference
|
|
32
|
+
- [VAPID Setup Guide](./guides/vapid-setup.md) - Generate and configure VAPID keys
|
|
33
|
+
- [Django Integration](./guides/django-integration.md) - Backend integration
|
|
34
|
+
|
|
35
|
+
### For Contributors
|
|
36
|
+
Start here if you want to understand or modify PushNotifications:
|
|
37
|
+
- [Architecture](./architecture/) - How it's built
|
|
38
|
+
- [Service Worker Guide](./guides/service-worker.md) - SW integration
|
|
39
|
+
|
|
40
|
+
### For Django Developers
|
|
41
|
+
Start here if you're using Django-CFG backend:
|
|
42
|
+
- [Django Integration Guide](./guides/django-integration.md) - Backend setup
|
|
43
|
+
- [DjangoPushProvider API](../README.md#djangopushprovider) - Django-specific provider
|
|
44
|
+
|
|
45
|
+
## Key Concepts
|
|
46
|
+
|
|
47
|
+
### Push Subscription Flow
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
1. Request Permission
|
|
51
|
+
↓
|
|
52
|
+
2. Subscribe to Push Service
|
|
53
|
+
↓
|
|
54
|
+
3. Send Subscription to Backend
|
|
55
|
+
↓
|
|
56
|
+
4. Backend Sends Push → User Receives
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Components
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
PushPrompt (Permission prompt)
|
|
63
|
+
├── Check permission state
|
|
64
|
+
├── Request notification permission
|
|
65
|
+
└── Subscribe to push service
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### State Management
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
useDjangoPushContext() hook
|
|
72
|
+
├── Permission state (permission, isSupported)
|
|
73
|
+
├── Subscription state (isSubscribed, subscription)
|
|
74
|
+
├── Actions (subscribe, unsubscribe, sendTestPush)
|
|
75
|
+
└── Loading/Error states
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Providers
|
|
79
|
+
|
|
80
|
+
**Generic (PushProvider)**:
|
|
81
|
+
- For any backend
|
|
82
|
+
- Custom endpoints
|
|
83
|
+
- Manual subscription management
|
|
84
|
+
|
|
85
|
+
**Django-specific (DjangoPushProvider)**:
|
|
86
|
+
- Django-CFG integration
|
|
87
|
+
- Auto-configured endpoints
|
|
88
|
+
- Built-in error handling
|
|
89
|
+
|
|
90
|
+
## Browser Support
|
|
91
|
+
|
|
92
|
+
| Platform | Browser | Support |
|
|
93
|
+
|----------|---------|---------|
|
|
94
|
+
| iOS | Safari 16.4+ | ✅ Push supported |
|
|
95
|
+
| iOS | Chrome/Firefox | ❌ No push support |
|
|
96
|
+
| Android | Chrome | ✅ Full support |
|
|
97
|
+
| Android | Firefox | ✅ Full support |
|
|
98
|
+
| Desktop | Chrome/Edge/Firefox | ✅ Full support |
|
|
99
|
+
|
|
100
|
+
**Important**: iOS push requires Safari 16.4+ and PWA installation.
|
|
101
|
+
|
|
102
|
+
## Security: VAPID Keys
|
|
103
|
+
|
|
104
|
+
### What are VAPID keys?
|
|
105
|
+
|
|
106
|
+
**VAPID** (Voluntary Application Server Identification) authenticates your push notifications.
|
|
107
|
+
|
|
108
|
+
- **Public key**: Safe to expose in frontend
|
|
109
|
+
- **Private key**: ⚠️ **NEVER** expose (backend only)
|
|
110
|
+
|
|
111
|
+
### Generate VAPID Keys
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
npx web-push generate-vapid-keys
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Configuration
|
|
118
|
+
|
|
119
|
+
```env
|
|
120
|
+
# Frontend (PUBLIC)
|
|
121
|
+
NEXT_PUBLIC_VAPID_PUBLIC_KEY=BM8xT...
|
|
122
|
+
|
|
123
|
+
# Backend (PRIVATE - never expose!)
|
|
124
|
+
VAPID_PRIVATE_KEY=your_private_key
|
|
125
|
+
VAPID_MAILTO=mailto:you@example.com
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
**See**: [VAPID Setup Guide](./guides/vapid-setup.md) for details.
|
|
129
|
+
|
|
130
|
+
## Related Documentation
|
|
131
|
+
|
|
132
|
+
- **[PWAInstall Docs](../../PWAInstall/@docs/)** - PWA installation (separate concern)
|
|
133
|
+
- **[Refactoring Summary](../../REFACTORING_SUMMARY.md)** - Why snippets were split
|
|
134
|
+
- **[Migration Guide](../../MIGRATION.md)** - How to migrate from old PWA snippet
|
|
135
|
+
|
|
136
|
+
## Usage Examples
|
|
137
|
+
|
|
138
|
+
### Basic Usage
|
|
139
|
+
|
|
140
|
+
```tsx
|
|
141
|
+
import { DjangoPushProvider, PushPrompt } from '@/snippets/PushNotifications';
|
|
142
|
+
|
|
143
|
+
<DjangoPushProvider vapidPublicKey={VAPID_KEY}>
|
|
144
|
+
<PushPrompt requirePWA={true} />
|
|
145
|
+
</DjangoPushProvider>
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### With PWA Install
|
|
149
|
+
|
|
150
|
+
```tsx
|
|
151
|
+
import { PwaProvider, A2HSHint } from '@/snippets/PWAInstall';
|
|
152
|
+
import { DjangoPushProvider, PushPrompt } from '@/snippets/PushNotifications';
|
|
153
|
+
|
|
154
|
+
<PwaProvider>
|
|
155
|
+
<DjangoPushProvider vapidPublicKey={VAPID_KEY}>
|
|
156
|
+
<A2HSHint />
|
|
157
|
+
<PushPrompt requirePWA={true} delayMs={5000} />
|
|
158
|
+
</DjangoPushProvider>
|
|
159
|
+
</PwaProvider>
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Manual Control
|
|
163
|
+
|
|
164
|
+
```tsx
|
|
165
|
+
import { useDjangoPushContext } from '@/snippets/PushNotifications';
|
|
166
|
+
|
|
167
|
+
function NotifyButton() {
|
|
168
|
+
const { subscribe, isSubscribed, sendTestPush } = useDjangoPushContext();
|
|
169
|
+
|
|
170
|
+
return (
|
|
171
|
+
<button onClick={isSubscribed ? sendTestPush : subscribe}>
|
|
172
|
+
{isSubscribed ? 'Test' : 'Enable'} Notifications
|
|
173
|
+
</button>
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Contributing
|
|
179
|
+
|
|
180
|
+
When adding documentation:
|
|
181
|
+
1. **Guides** → `/guides/` - Step-by-step tutorials
|
|
182
|
+
2. **Architecture** → `/architecture/` - Design decisions, flows
|
|
183
|
+
3. **Historical** → `/legacy/` - Old docs (keep for reference)
|
|
184
|
+
|
|
185
|
+
## Questions?
|
|
186
|
+
|
|
187
|
+
- Implementation questions → See [Main README](../README.md)
|
|
188
|
+
- VAPID setup → See [VAPID Guide](./guides/vapid-setup.md)
|
|
189
|
+
- Django integration → See [Django Guide](./guides/django-integration.md)
|
|
190
|
+
- Service worker → See [SW Guide](./guides/service-worker.md)
|
|
191
|
+
- Migration questions → See [Migration Guide](../../MIGRATION.md)
|