juxscript 1.1.364 → 1.1.366
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 +6 -37
- package/dist/components/routes.d.ts.map +1 -1
- package/dist/components/routes.js +30 -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,13 @@ export interface RouteInfo {
|
|
|
3
3
|
name: string;
|
|
4
4
|
file: string;
|
|
5
5
|
}
|
|
6
|
-
declare
|
|
7
|
-
private _srcDir;
|
|
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: {
|
|
33
7
|
all(): RouteInfo[];
|
|
34
|
-
/**
|
|
35
|
-
* Get just the route paths
|
|
36
|
-
*/
|
|
37
8
|
paths(): string[];
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
export declare function routes(): Router;
|
|
44
|
-
export { Router };
|
|
9
|
+
current(): string;
|
|
10
|
+
isActive(path: string): boolean;
|
|
11
|
+
navigate(path: string): void;
|
|
12
|
+
onNavigate(callback: (path: string) => void): () => void;
|
|
13
|
+
};
|
|
45
14
|
export default routes;
|
|
46
15
|
//# 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;AAQD,eAAO,MAAM,MAAM;WACR,SAAS,EAAE;aAGT,MAAM,EAAE;eAGN,MAAM;mBAGF,MAAM,GAAG,OAAO;mBAGhB,MAAM,GAAG,IAAI;yBAIP,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,IAAI;CAM3D,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -1,113 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
*/
|
|
1
|
+
function _getData() {
|
|
2
|
+
const w = typeof window !== 'undefined' ? window : null;
|
|
3
|
+
if (!w?.__juxRouteIndex)
|
|
4
|
+
return [];
|
|
5
|
+
return w.__juxRouteIndex;
|
|
6
|
+
}
|
|
7
|
+
export const routes = {
|
|
86
8
|
all() {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
return this._routes;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Get just the route paths
|
|
94
|
-
*/
|
|
9
|
+
return _getData();
|
|
10
|
+
},
|
|
95
11
|
paths() {
|
|
96
|
-
return
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
12
|
+
return _getData().map(r => r.path);
|
|
13
|
+
},
|
|
14
|
+
current() {
|
|
15
|
+
return typeof window !== 'undefined' ? window.location.pathname : '/';
|
|
16
|
+
},
|
|
17
|
+
isActive(path) {
|
|
18
|
+
return routes.current() === path;
|
|
19
|
+
},
|
|
20
|
+
navigate(path) {
|
|
21
|
+
const w = typeof window !== 'undefined' ? window : null;
|
|
22
|
+
if (w?.navigateTo)
|
|
23
|
+
w.navigateTo(path);
|
|
24
|
+
},
|
|
25
|
+
onNavigate(callback) {
|
|
26
|
+
if (typeof window === 'undefined')
|
|
27
|
+
return () => { };
|
|
28
|
+
const handler = () => callback(window.location.pathname);
|
|
29
|
+
window.addEventListener('popstate', handler);
|
|
30
|
+
return () => window.removeEventListener('popstate', handler);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
112
33
|
export default routes;
|
|
113
34
|
//# 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,QAAQ;IACb,MAAM,CAAC,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAE,MAAc,CAAC,CAAC,CAAC,IAAI,CAAC;IACjE,IAAI,CAAC,CAAC,EAAE,eAAe;QAAE,OAAO,EAAE,CAAC;IACnC,OAAO,CAAC,CAAC,eAAe,CAAC;AAC7B,CAAC;AAED,MAAM,CAAC,MAAM,MAAM,GAAG;IAClB,GAAG;QACC,OAAO,QAAQ,EAAE,CAAC;IACtB,CAAC;IACD,KAAK;QACD,OAAO,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;IACD,OAAO;QACH,OAAO,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC;IAC1E,CAAC;IACD,QAAQ,CAAC,IAAY;QACjB,OAAO,MAAM,CAAC,OAAO,EAAE,KAAK,IAAI,CAAC;IACrC,CAAC;IACD,QAAQ,CAAC,IAAY;QACjB,MAAM,CAAC,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAE,MAAc,CAAC,CAAC,CAAC,IAAI,CAAC;QACjE,IAAI,CAAC,EAAE,UAAU;YAAE,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;IACD,UAAU,CAAC,QAAgC;QACvC,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO,GAAG,EAAE,GAAG,CAAC,CAAC;QACpD,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,EAAE,MAA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AE,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) {
|