juxscript 1.1.364 → 1.1.365
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/dist/components/routes.d.ts +12 -37
- package/dist/components/routes.d.ts.map +1 -1
- package/dist/components/routes.js +42 -109
- package/dist/components/routes.js.map +1 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/machinery/compiler4.js +15 -0
- package/package.json +1 -1
|
@@ -3,44 +3,19 @@ export interface RouteInfo {
|
|
|
3
3
|
name: string;
|
|
4
4
|
file: string;
|
|
5
5
|
}
|
|
6
|
-
declare
|
|
7
|
-
|
|
8
|
-
private _routes;
|
|
9
|
-
constructor();
|
|
10
|
-
/**
|
|
11
|
-
* Try juxconfig.js for srcDir, default to 'jux'
|
|
12
|
-
*/
|
|
13
|
-
private _resolveSrcDir;
|
|
14
|
-
/**
|
|
15
|
-
* Recursively scan srcDir for .jux files
|
|
16
|
-
*/
|
|
17
|
-
private _scan;
|
|
18
|
-
/**
|
|
19
|
-
* Convert file path to route path
|
|
20
|
-
* index.jux -> /
|
|
21
|
-
* about.jux -> /about
|
|
22
|
-
* blog/post.jux -> /blog/post
|
|
23
|
-
* settings/index.jux -> /settings
|
|
24
|
-
*/
|
|
25
|
-
private _fileToRoute;
|
|
26
|
-
/**
|
|
27
|
-
* Derive display name from route path
|
|
28
|
-
*/
|
|
29
|
-
private _nameFromRoute;
|
|
30
|
-
/**
|
|
31
|
-
* Get ALL .jux file routes from the source directory
|
|
32
|
-
*/
|
|
6
|
+
export declare const routes: {
|
|
7
|
+
/** All .jux file routes from the source directory */
|
|
33
8
|
all(): RouteInfo[];
|
|
34
|
-
/**
|
|
35
|
-
* Get just the route paths
|
|
36
|
-
*/
|
|
9
|
+
/** Just the route paths */
|
|
37
10
|
paths(): string[];
|
|
38
|
-
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
11
|
+
/** Current browser path */
|
|
12
|
+
current(): string;
|
|
13
|
+
/** Is this path active? */
|
|
14
|
+
isActive(path: string): boolean;
|
|
15
|
+
/** SPA navigate */
|
|
16
|
+
navigate(path: string): void;
|
|
17
|
+
/** Listen for route changes */
|
|
18
|
+
onNavigate(callback: (path: string) => void): () => void;
|
|
19
|
+
};
|
|
45
20
|
export default routes;
|
|
46
21
|
//# sourceMappingURL=routes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../lib/components/routes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../lib/components/routes.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CAChB;AAcD,eAAO,MAAM,MAAM;IACf,qDAAqD;WAC9C,SAAS,EAAE;IAIlB,2BAA2B;aAClB,MAAM,EAAE;IAIjB,2BAA2B;eAChB,MAAM;IAIjB,2BAA2B;mBACZ,MAAM,GAAG,OAAO;IAI/B,mBAAmB;mBACJ,MAAM,GAAG,IAAI;IAK5B,+BAA+B;yBACV,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,IAAI;CAM3D,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -1,113 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
this._srcDir = this._resolveSrcDir();
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Try juxconfig.js for srcDir, default to 'jux'
|
|
10
|
-
*/
|
|
11
|
-
_resolveSrcDir() {
|
|
12
|
-
const projectRoot = process.cwd();
|
|
13
|
-
const configPath = path.resolve(projectRoot, 'juxconfig.js');
|
|
14
|
-
if (fs.existsSync(configPath)) {
|
|
15
|
-
try {
|
|
16
|
-
const configContent = fs.readFileSync(configPath, 'utf8');
|
|
17
|
-
const srcDirMatch = configContent.match(/srcDir\s*:\s*['"]([^'"]+)['"]/);
|
|
18
|
-
if (srcDirMatch) {
|
|
19
|
-
return path.resolve(projectRoot, srcDirMatch[1]);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
catch (_) { }
|
|
23
|
-
}
|
|
24
|
-
return path.resolve(projectRoot, 'jux');
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Recursively scan srcDir for .jux files
|
|
28
|
-
*/
|
|
29
|
-
_scan(dir, routes = []) {
|
|
30
|
-
if (!fs.existsSync(dir))
|
|
31
|
-
return routes;
|
|
32
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
33
|
-
for (const entry of entries) {
|
|
34
|
-
const fullPath = path.join(dir, entry.name);
|
|
35
|
-
if (entry.isDirectory()) {
|
|
36
|
-
this._scan(fullPath, routes);
|
|
37
|
-
}
|
|
38
|
-
else if (entry.isFile() && entry.name.endsWith('.jux')) {
|
|
39
|
-
const relativePath = path.relative(this._srcDir, fullPath).replace(/\\/g, '/');
|
|
40
|
-
const routePath = this._fileToRoute(relativePath);
|
|
41
|
-
const name = this._nameFromRoute(routePath);
|
|
42
|
-
routes.push({ path: routePath, name, file: relativePath });
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return routes;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Convert file path to route path
|
|
49
|
-
* index.jux -> /
|
|
50
|
-
* about.jux -> /about
|
|
51
|
-
* blog/post.jux -> /blog/post
|
|
52
|
-
* settings/index.jux -> /settings
|
|
53
|
-
*/
|
|
54
|
-
_fileToRoute(filePath) {
|
|
55
|
-
let route = filePath
|
|
56
|
-
.replace(/\.jux$/, '')
|
|
57
|
-
.toLowerCase()
|
|
58
|
-
.replace(/\s+/g, '-')
|
|
59
|
-
.replace(/[^a-z0-9\/_-]/g, '')
|
|
60
|
-
.replace(/-+/g, '-')
|
|
61
|
-
.replace(/^-|-$/g, '');
|
|
62
|
-
// folder/index -> /folder
|
|
63
|
-
if (route.endsWith('/index')) {
|
|
64
|
-
route = route.slice(0, -6);
|
|
65
|
-
}
|
|
66
|
-
if (route === 'index' || route === '') {
|
|
67
|
-
return '/';
|
|
68
|
-
}
|
|
69
|
-
return '/' + route;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Derive display name from route path
|
|
73
|
-
*/
|
|
74
|
-
_nameFromRoute(routePath) {
|
|
75
|
-
if (routePath === '/')
|
|
76
|
-
return 'Home';
|
|
77
|
-
const seg = routePath.split('/').filter(Boolean).pop() || 'Home';
|
|
78
|
-
return seg
|
|
79
|
-
.split('-')
|
|
80
|
-
.map(s => s.charAt(0).toUpperCase() + s.slice(1))
|
|
81
|
-
.join(' ');
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Get ALL .jux file routes from the source directory
|
|
85
|
-
*/
|
|
86
|
-
all() {
|
|
87
|
-
if (!this._routes) {
|
|
88
|
-
this._routes = this._scan(this._srcDir);
|
|
89
|
-
}
|
|
90
|
-
return this._routes;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Get just the route paths
|
|
94
|
-
*/
|
|
95
|
-
paths() {
|
|
96
|
-
return this.all().map(r => r.path);
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Force rescan (e.g. after files change)
|
|
100
|
-
*/
|
|
101
|
-
refresh() {
|
|
102
|
-
this._routes = null;
|
|
103
|
-
return this;
|
|
104
|
-
}
|
|
1
|
+
function _nameFromPath(p) {
|
|
2
|
+
if (p === '/')
|
|
3
|
+
return 'Home';
|
|
4
|
+
const seg = p.split('/').filter(Boolean).pop() || 'Home';
|
|
5
|
+
return seg.split('-').map(s => s.charAt(0).toUpperCase() + s.slice(1)).join(' ');
|
|
105
6
|
}
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
7
|
+
function _getData() {
|
|
8
|
+
const w = typeof window !== 'undefined' ? window : null;
|
|
9
|
+
if (!w?.__juxRouteIndex)
|
|
10
|
+
return [];
|
|
11
|
+
return w.__juxRouteIndex;
|
|
110
12
|
}
|
|
111
|
-
export
|
|
13
|
+
export const routes = {
|
|
14
|
+
/** All .jux file routes from the source directory */
|
|
15
|
+
all() {
|
|
16
|
+
return _getData();
|
|
17
|
+
},
|
|
18
|
+
/** Just the route paths */
|
|
19
|
+
paths() {
|
|
20
|
+
return _getData().map(r => r.path);
|
|
21
|
+
},
|
|
22
|
+
/** Current browser path */
|
|
23
|
+
current() {
|
|
24
|
+
return typeof window !== 'undefined' ? window.location.pathname : '/';
|
|
25
|
+
},
|
|
26
|
+
/** Is this path active? */
|
|
27
|
+
isActive(path) {
|
|
28
|
+
return routes.current() === path;
|
|
29
|
+
},
|
|
30
|
+
/** SPA navigate */
|
|
31
|
+
navigate(path) {
|
|
32
|
+
const w = typeof window !== 'undefined' ? window : null;
|
|
33
|
+
if (w?.navigateTo)
|
|
34
|
+
w.navigateTo(path);
|
|
35
|
+
},
|
|
36
|
+
/** Listen for route changes */
|
|
37
|
+
onNavigate(callback) {
|
|
38
|
+
if (typeof window === 'undefined')
|
|
39
|
+
return () => { };
|
|
40
|
+
const handler = () => callback(window.location.pathname);
|
|
41
|
+
window.addEventListener('popstate', handler);
|
|
42
|
+
return () => window.removeEventListener('popstate', handler);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
112
45
|
export default routes;
|
|
113
46
|
//# sourceMappingURL=routes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../../lib/components/routes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../../lib/components/routes.ts"],"names":[],"mappings":"AAMA,SAAS,aAAa,CAAC,CAAS;IAC5B,IAAI,CAAC,KAAK,GAAG;QAAE,OAAO,MAAM,CAAC;IAC7B,MAAM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AAI,CAAC,EAAE,UAAU;YAAE,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED,+BAA+B;IAC/B,UAAU,CAAC,QAAgC;QACvC,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;QACnD,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACzD,MAAM,CAAC,gBAAgB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAC7C,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACjE,CAAC;CACJ,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -64,7 +64,14 @@ export declare const jux: {
|
|
|
64
64
|
a: typeof a;
|
|
65
65
|
container: typeof container;
|
|
66
66
|
grid: typeof grid;
|
|
67
|
-
routes:
|
|
67
|
+
routes: {
|
|
68
|
+
all(): import("./components/routes.js").RouteInfo[];
|
|
69
|
+
paths(): string[];
|
|
70
|
+
current(): string;
|
|
71
|
+
isActive(path: string): boolean;
|
|
72
|
+
navigate(path: string): void;
|
|
73
|
+
onNavigate(callback: (path: string) => void): () => void;
|
|
74
|
+
};
|
|
68
75
|
};
|
|
69
76
|
export { pageState };
|
|
70
77
|
export { routes };
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3F,OAAO,EAAE,OAAO,E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SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAEhD,eAAO,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0Cf,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,CAAC;AACrB,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
package/machinery/compiler4.js
CHANGED
|
@@ -644,6 +644,21 @@ export class JuxCompiler {
|
|
|
644
644
|
|
|
645
645
|
router += `};\n\n`;
|
|
646
646
|
|
|
647
|
+
// Build route index for jux.routes.all()
|
|
648
|
+
const routeIndex = [];
|
|
649
|
+
routeToFunctionMap.forEach((functionName, routePath) => {
|
|
650
|
+
const name = routePath === '/'
|
|
651
|
+
? 'Home'
|
|
652
|
+
: routePath.split('/').filter(Boolean).pop()
|
|
653
|
+
.split('-').map(s => s.charAt(0).toUpperCase() + s.slice(1)).join(' ');
|
|
654
|
+
// Find matching source file from snapshot
|
|
655
|
+
const sourceFile = this._sourceSnapshot
|
|
656
|
+
? Object.values(this._sourceSnapshot).find(s => s.functionName === functionName)
|
|
657
|
+
: null;
|
|
658
|
+
routeIndex.push({ path: routePath, name, file: sourceFile?.file || '' });
|
|
659
|
+
});
|
|
660
|
+
router += `window.__juxRouteIndex = ${JSON.stringify(routeIndex)};\n\n`;
|
|
661
|
+
|
|
647
662
|
router += `function route(path) {
|
|
648
663
|
const renderFn = routes[path] || routes['/'];
|
|
649
664
|
if (renderFn) {
|