-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpwa-app.html
More file actions
445 lines (377 loc) · 12.7 KB
/
Copy pathpwa-app.html
File metadata and controls
445 lines (377 loc) · 12.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
<!--
Generated by WhyML - WhyML Test App
Description: Test application to verify WhyML functionality
Generated on: 2025-09-19 13:11:13.314125
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Test application to verify WhyML functionality">
<meta name="author" content="WhyML Team">
<meta property="og:title" content="WhyML Test App">
<meta property="og:description" content="Test application to verify WhyML functionality">
<meta property="og:type" content="website">
<title>WhyML Test App</title>
<style>
.container {
width: 100%;
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
.main-title {
color: #007acc;
font-family: Helvetica, Arial, sans-serif;
font-size: 32px;
}
.intro {
font-family: Arial, sans-serif;
color: #333;
margin: 16px 0;
}
.section-title {
color: #007acc;
font-family: Helvetica, Arial, sans-serif;
font-size: 24px;
margin-top: 24px;
}
.feature-list {
font-family: Arial, sans-serif;
color: #333;
padding-left: 20px;
}
.features-section {
margin-top: 20px;
}
</style>
<link rel="manifest" href="/manifest.json">
<meta name="theme-color" content="#000000">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="default">
<meta name="apple-mobile-web-app-title" content="WhyML Test App">
</head>
<body>
<div>
<div class="container">
<h1> <div class="main-title">Welcome to WhyML Test App</div></h1>
<p> <div class="intro">This is a test application to verify WhyML CLI functionality works correctly.</div></p>
<div>
<div class="features-section">
<h2> <div class="section-title">Features</div></h2>
<ul>
<div class="feature-list">
<li> <div>CLI Commands</div></li>
<li> <div>Natural Language Conversion</div></li>
<li> <div>Application Generators</div></li>
<li> <div>Development Server</div></li>
</div>
</ul>
</div>
</div>
</div>
</div>
<script>
// SPA Router Configuration
const routes = {};
class Router {
constructor() {
this.routes = new Map();
this.currentPath = '/';
this.init();
}
init() {
// Load routes from configuration
Object.entries(routes).forEach(([path, component]) => {
this.addRoute(path, component);
});
// Handle browser navigation
window.addEventListener('popstate', () => this.handleRoute());
// Handle initial load
document.addEventListener('DOMContentLoaded', () => this.handleRoute());
// Handle navigation clicks
document.addEventListener('click', this.handleClick.bind(this));
}
addRoute(path, component) {
this.routes.set(path, component);
}
handleClick(event) {
if (event.target.matches('a[href^="/"]')) {
event.preventDefault();
this.navigateTo(event.target.getAttribute('href'));
}
}
navigateTo(path, replace = false) {
if (replace) {
history.replaceState(null, null, path);
} else {
history.pushState(null, null, path);
}
this.handleRoute();
}
handleRoute() {
const path = window.location.pathname;
this.currentPath = path;
const route = this.routes.get(path) || this.routes.get('*') || this.routes.get('/');
if (route) {
this.renderRoute(route, path);
} else {
this.render404();
}
}
renderRoute(route, path) {
const container = document.getElementById('app') || document.body;
if (typeof route === 'string') {
container.innerHTML = route;
} else if (typeof route === 'function') {
route(container, path);
} else if (route.template) {
container.innerHTML = route.template;
}
// Trigger route change event
window.dispatchEvent(new CustomEvent('routechange', {
detail: { path, route }
}));
}
render404() {
const container = document.getElementById('app') || document.body;
container.innerHTML = `
<div style="text-align: center; padding: 2rem;">
<h1>404 - Page Not Found</h1>
<p>The page you're looking for doesn't exist.</p>
<a href="/">Go Home</a>
</div>
`;
}
}
// Initialize router
const router = new Router();
// Export for use in other modules
if (typeof module !== 'undefined' && module.exports) {
module.exports = router;
}
// SPA Enhancements for WhyML Test App
class SPAApp {
constructor() {
this.currentRoute = '/';
this.routes = {};
this.init();
}
init() {
window.addEventListener('popstate', () => {
this.handleRouteChange();
});
// Handle initial route
this.handleRouteChange();
// Setup navigation links
this.setupNavigationLinks();
}
setupNavigationLinks() {
document.addEventListener('click', (e) => {
if (e.target.tagName === 'A' && e.target.getAttribute('href')) {
const href = e.target.getAttribute('href');
if (href.startsWith('/') || href.startsWith('#')) {
e.preventDefault();
this.navigateTo(href);
}
}
});
}
navigateTo(path) {
if (path !== this.currentRoute) {
history.pushState(null, '', path);
this.currentRoute = path;
this.handleRouteChange();
}
}
handleRouteChange() {
const path = window.location.pathname || '/';
this.currentRoute = path;
// Trigger route change event
const event = new CustomEvent('spa-route-change', {
detail: { path, route: this.currentRoute }
});
document.dispatchEvent(event);
}
// Add page transition effects
transitionTo(newContent) {
const main = document.querySelector('main') || document.body;
main.style.opacity = '0';
setTimeout(() => {
main.innerHTML = newContent;
main.style.opacity = '1';
}, 150);
}
}
// Initialize SPA
if (typeof window !== 'undefined') {
window.spaApp = new SPAApp();
}
</script>
<script>
// PWA Enhancements for WhyML Test App
class PWAApp {
constructor() {
this.isOnline = navigator.onLine;
this.init();
}
init() {
// Register service worker
this.registerServiceWorker();
// Setup online/offline detection
this.setupConnectivityDetection();
// Setup install prompt
this.setupInstallPrompt();
// Setup update notifications
this.setupUpdateNotifications();
}
async registerServiceWorker() {
if ('serviceWorker' in navigator) {
try {
const registration = await navigator.serviceWorker.register('/sw.js');
console.log('Service Worker registered:', registration);
// Listen for updates
registration.addEventListener('updatefound', () => {
this.handleServiceWorkerUpdate(registration);
});
} catch (error) {
console.error('Service Worker registration failed:', error);
}
}
}
handleServiceWorkerUpdate(registration) {
const newWorker = registration.installing;
if (newWorker) {
newWorker.addEventListener('statechange', () => {
if (newWorker.state === 'installed' && navigator.serviceWorker.controller) {
this.showUpdateNotification();
}
});
}
}
setupConnectivityDetection() {
window.addEventListener('online', () => {
this.isOnline = true;
this.showConnectivityStatus('online');
});
window.addEventListener('offline', () => {
this.isOnline = false;
this.showConnectivityStatus('offline');
});
}
setupInstallPrompt() {
let deferredPrompt;
window.addEventListener('beforeinstallprompt', (e) => {
e.preventDefault();
deferredPrompt = e;
this.showInstallButton();
});
// Handle install button click
document.addEventListener('click', async (e) => {
if (e.target.id === 'pwa-install-btn') {
if (deferredPrompt) {
deferredPrompt.prompt();
const { outcome } = await deferredPrompt.userChoice;
console.log('Install prompt outcome:', outcome);
deferredPrompt = null;
this.hideInstallButton();
}
}
});
}
showInstallButton() {
if (!document.getElementById('pwa-install-btn')) {
const button = document.createElement('button');
button.id = 'pwa-install-btn';
button.textContent = 'Install App';
button.style.cssText = `
position: fixed;
bottom: 20px;
right: 20px;
background: #007acc;
color: white;
border: none;
padding: 12px 20px;
border-radius: 6px;
cursor: pointer;
z-index: 1000;
font-family: Arial, sans-serif;
`;
document.body.appendChild(button);
}
}
hideInstallButton() {
const button = document.getElementById('pwa-install-btn');
if (button) {
button.remove();
}
}
showConnectivityStatus(status) {
const existing = document.getElementById('connectivity-status');
if (existing) existing.remove();
const statusDiv = document.createElement('div');
statusDiv.id = 'connectivity-status';
statusDiv.textContent = status === 'online' ? 'Back online!' : 'You are offline';
statusDiv.style.cssText = `
position: fixed;
top: 20px;
left: 50%;
transform: translateX(-50%);
padding: 10px 20px;
border-radius: 6px;
color: white;
background: ${status === 'online' ? '#4CAF50' : '#f44336'};
z-index: 1000;
font-family: Arial, sans-serif;
`;
document.body.appendChild(statusDiv);
setTimeout(() => {
if (statusDiv && statusDiv.parentNode) {
statusDiv.parentNode.removeChild(statusDiv);
}
}, 3000);
}
showUpdateNotification() {
const notification = document.createElement('div');
notification.style.cssText = `
position: fixed;
bottom: 20px;
left: 20px;
background: #333;
color: white;
padding: 15px;
border-radius: 6px;
z-index: 1000;
font-family: Arial, sans-serif;
`;
notification.innerHTML = `
<div>New version available!</div>
<button onclick="window.location.reload()" style="
background: #007acc;
color: white;
border: none;
padding: 8px 15px;
border-radius: 4px;
cursor: pointer;
margin-top: 10px;
">Refresh</button>
`;
document.body.appendChild(notification);
}
setupUpdateNotifications() {
// Check for updates periodically
setInterval(() => {
if ('serviceWorker' in navigator && navigator.serviceWorker.controller) {
navigator.serviceWorker.controller.postMessage({ type: 'CHECK_FOR_UPDATES' });
}
}, 60000); // Check every minute
}
}
// Initialize PWA
if (typeof window !== 'undefined') {
window.pwaApp = new PWAApp();
}
</script>
</body>
</html>