juxscript 1.1.125 → 1.1.127
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/dom-structure-map.json +1 -1
- package/machinery/compiler3.js +56 -23
- package/package.json +1 -1
package/dom-structure-map.json
CHANGED
package/machinery/compiler3.js
CHANGED
|
@@ -289,9 +289,36 @@ export class JuxCompiler {
|
|
|
289
289
|
_generateRouter(views) {
|
|
290
290
|
let routeMap = '';
|
|
291
291
|
views.forEach(v => {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
292
|
+
// ✅ Sanitize function name (same as above)
|
|
293
|
+
const sanitizedName = v.name
|
|
294
|
+
.replace(/[\/\\.\\-\s]/g, '_')
|
|
295
|
+
.replace(/[^a-zA-Z0-9_]/g, '_')
|
|
296
|
+
.replace(/_+/g, '_')
|
|
297
|
+
.replace(/^_|_$/g, '');
|
|
298
|
+
|
|
299
|
+
const cap = sanitizedName.charAt(0).toUpperCase() + sanitizedName.slice(1);
|
|
300
|
+
|
|
301
|
+
// ✅ Generate URL-safe route path from original name
|
|
302
|
+
// Convert: 'menus/main' → '/menus/main'
|
|
303
|
+
// Convert: 'about-us' → '/about-us'
|
|
304
|
+
// Convert: 'blog.post' → '/blog-post' (dots become dashes for URLs)
|
|
305
|
+
const routePath = v.name
|
|
306
|
+
.toLowerCase()
|
|
307
|
+
.replace(/\\/g, '/') // Normalize backslashes to forward slashes
|
|
308
|
+
.replace(/\.jux$/i, '') // Remove .jux extension if present
|
|
309
|
+
.replace(/\./g, '-') // Convert dots to dashes (blog.post → blog-post)
|
|
310
|
+
.replace(/\s+/g, '-') // Convert spaces to dashes
|
|
311
|
+
.replace(/[^a-z0-9\/_-]/g, '') // Remove any other unsafe URL chars
|
|
312
|
+
.replace(/-+/g, '-') // Collapse multiple dashes
|
|
313
|
+
.replace(/^-|-$/g, ''); // Remove leading/trailing dashes
|
|
314
|
+
|
|
315
|
+
// ✅ Handle index route
|
|
316
|
+
if (routePath === 'index' || routePath === '') {
|
|
317
|
+
routeMap += ` '/': render${cap},\n`;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// ✅ Add regular route
|
|
321
|
+
routeMap += ` '/${routePath}': render${cap},\n`;
|
|
295
322
|
});
|
|
296
323
|
|
|
297
324
|
return `
|
|
@@ -419,29 +446,34 @@ window.addEventListener('unhandledrejection', function(e) { __juxErrorOverlay.sh
|
|
|
419
446
|
// --- JUX ROUTER ---
|
|
420
447
|
const routes = {\n${routeMap}};
|
|
421
448
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
449
|
+
// Simple router
|
|
450
|
+
function route(path) {
|
|
451
|
+
const renderFn = routes[path] || routes['/'];
|
|
452
|
+
if (renderFn) {
|
|
453
|
+
document.getElementById('app').innerHTML = '';
|
|
454
|
+
renderFn();
|
|
455
|
+
} else {
|
|
456
|
+
document.getElementById('app').innerHTML = '<h1>404 - Page Not Found</h1>';
|
|
427
457
|
}
|
|
428
|
-
document.getElementById('app').innerHTML = '';
|
|
429
|
-
var overlay = document.getElementById('__jux-error-overlay');
|
|
430
|
-
if (overlay) overlay.remove();
|
|
431
|
-
try { await view(); } catch (err) { __juxErrorOverlay.show(err, 'Jux Render Error'); }
|
|
432
458
|
}
|
|
433
459
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
if (!a || a.dataset.router === 'false') return;
|
|
437
|
-
try { if (new URL(a.href, location.origin).origin !== location.origin) return; } catch { return; }
|
|
438
|
-
e.preventDefault();
|
|
439
|
-
history.pushState({}, '', a.href);
|
|
440
|
-
navigate(new URL(a.href, location.origin).pathname);
|
|
441
|
-
});
|
|
460
|
+
// Initial route
|
|
461
|
+
route(window.location.pathname);
|
|
442
462
|
|
|
443
|
-
|
|
444
|
-
|
|
463
|
+
// Handle navigation
|
|
464
|
+
window.addEventListener('popstate', () => route(window.location.pathname));
|
|
465
|
+
|
|
466
|
+
// Intercept link clicks
|
|
467
|
+
document.addEventListener('click', (e) => {
|
|
468
|
+
if (e.target.matches('a[href]')) {
|
|
469
|
+
const href = e.target.getAttribute('href');
|
|
470
|
+
if (href.startsWith('/') && !href.startsWith('//')) {
|
|
471
|
+
e.preventDefault();
|
|
472
|
+
window.history.pushState({}, '', href);
|
|
473
|
+
route(href);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
});
|
|
445
477
|
`;
|
|
446
478
|
}
|
|
447
479
|
|
|
@@ -519,7 +551,7 @@ navigate(location.pathname);
|
|
|
519
551
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
520
552
|
<title>JUX Application</title>
|
|
521
553
|
<script type="module" src="./bundle.js"></script>
|
|
522
|
-
<script src="
|
|
554
|
+
<script src="./entry.js"></script>
|
|
523
555
|
</head>
|
|
524
556
|
<body>
|
|
525
557
|
<div id="app"></div>
|
|
@@ -533,6 +565,7 @@ navigate(location.pathname);
|
|
|
533
565
|
);
|
|
534
566
|
|
|
535
567
|
console.log(' ✅ Generated index.html');
|
|
568
|
+
return { success: true, errors: [], warnings: validation.warnings };
|
|
536
569
|
}
|
|
537
570
|
|
|
538
571
|
/**
|