@vistagenic/vista 0.1.0-alpha.1
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/bin/vista.js +98 -0
- package/dist/auth/index.d.ts +8 -0
- package/dist/auth/index.js +16 -0
- package/dist/bin/build-rsc.d.ts +17 -0
- package/dist/bin/build-rsc.js +320 -0
- package/dist/bin/build.d.ts +4 -0
- package/dist/bin/build.js +336 -0
- package/dist/bin/file-scanner.d.ts +66 -0
- package/dist/bin/file-scanner.js +399 -0
- package/dist/bin/server-component-plugin.d.ts +17 -0
- package/dist/bin/server-component-plugin.js +133 -0
- package/dist/bin/webpack.config.d.ts +6 -0
- package/dist/bin/webpack.config.js +138 -0
- package/dist/build/manifest.d.ts +95 -0
- package/dist/build/manifest.js +168 -0
- package/dist/build/rsc/client-manifest.d.ts +48 -0
- package/dist/build/rsc/client-manifest.js +191 -0
- package/dist/build/rsc/client-reference-plugin.d.ts +37 -0
- package/dist/build/rsc/client-reference-plugin.js +185 -0
- package/dist/build/rsc/compiler.d.ts +36 -0
- package/dist/build/rsc/compiler.js +311 -0
- package/dist/build/rsc/index.d.ts +16 -0
- package/dist/build/rsc/index.js +32 -0
- package/dist/build/rsc/native-scanner.d.ts +123 -0
- package/dist/build/rsc/native-scanner.js +165 -0
- package/dist/build/rsc/rsc-renderer.d.ts +99 -0
- package/dist/build/rsc/rsc-renderer.js +269 -0
- package/dist/build/rsc/server-component-loader.d.ts +19 -0
- package/dist/build/rsc/server-component-loader.js +147 -0
- package/dist/build/rsc/server-manifest.d.ts +63 -0
- package/dist/build/rsc/server-manifest.js +268 -0
- package/dist/build/webpack/loaders/vista-flight-loader.d.ts +17 -0
- package/dist/build/webpack/loaders/vista-flight-loader.js +93 -0
- package/dist/build/webpack/plugins/vista-flight-plugin.d.ts +36 -0
- package/dist/build/webpack/plugins/vista-flight-plugin.js +133 -0
- package/dist/client/dynamic.d.ts +25 -0
- package/dist/client/dynamic.js +68 -0
- package/dist/client/font.d.ts +98 -0
- package/dist/client/font.js +109 -0
- package/dist/client/head.d.ts +79 -0
- package/dist/client/head.js +261 -0
- package/dist/client/hydration.d.ts +45 -0
- package/dist/client/hydration.js +291 -0
- package/dist/client/link.d.ts +30 -0
- package/dist/client/link.js +188 -0
- package/dist/client/navigation.d.ts +28 -0
- package/dist/client/navigation.js +116 -0
- package/dist/client/router.d.ts +41 -0
- package/dist/client/router.js +190 -0
- package/dist/client/script.d.ts +51 -0
- package/dist/client/script.js +118 -0
- package/dist/components/client-island.d.ts +34 -0
- package/dist/components/client-island.js +75 -0
- package/dist/components/client.d.ts +29 -0
- package/dist/components/client.js +102 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +8 -0
- package/dist/components/link.d.ts +6 -0
- package/dist/components/link.js +13 -0
- package/dist/config.d.ts +10 -0
- package/dist/config.js +31 -0
- package/dist/dev-error.d.ts +35 -0
- package/dist/dev-error.js +310 -0
- package/dist/image/get-img-props.d.ts +28 -0
- package/dist/image/get-img-props.js +49 -0
- package/dist/image/image-config.d.ts +20 -0
- package/dist/image/image-config.js +20 -0
- package/dist/image/image-loader.d.ts +7 -0
- package/dist/image/image-loader.js +14 -0
- package/dist/image/index.d.ts +6 -0
- package/dist/image/index.js +110 -0
- package/dist/image.d.ts +10 -0
- package/dist/image.js +7 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +53 -0
- package/dist/metadata/generate.d.ts +22 -0
- package/dist/metadata/generate.js +324 -0
- package/dist/metadata/index.d.ts +7 -0
- package/dist/metadata/index.js +26 -0
- package/dist/metadata/types.d.ts +325 -0
- package/dist/metadata/types.js +15 -0
- package/dist/router/context.d.ts +8 -0
- package/dist/router/context.js +13 -0
- package/dist/router/index.d.ts +2 -0
- package/dist/router/index.js +18 -0
- package/dist/router/provider.d.ts +5 -0
- package/dist/router/provider.js +31 -0
- package/dist/server/client-boundary.d.ts +48 -0
- package/dist/server/client-boundary.js +133 -0
- package/dist/server/engine.d.ts +4 -0
- package/dist/server/engine.js +651 -0
- package/dist/server/index.d.ts +95 -0
- package/dist/server/index.js +177 -0
- package/dist/server/rsc-engine.d.ts +20 -0
- package/dist/server/rsc-engine.js +588 -0
- package/dist/server/rsc-module-system.d.ts +33 -0
- package/dist/server/rsc-module-system.js +119 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.js +2 -0
- package/package.json +103 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.useIsActive = exports.useLinkStatus = exports.Link = void 0;
|
|
38
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
39
|
+
const react_1 = __importStar(require("react"));
|
|
40
|
+
const router_1 = require("./router");
|
|
41
|
+
// Normalize href (string or object) to string
|
|
42
|
+
const formatUrl = (url) => {
|
|
43
|
+
if (typeof url === 'string')
|
|
44
|
+
return url;
|
|
45
|
+
if (typeof url === 'object' && url !== null) {
|
|
46
|
+
let result = url.href || '';
|
|
47
|
+
if (url.query) {
|
|
48
|
+
const params = new URLSearchParams(url.query).toString();
|
|
49
|
+
result += (result.includes('?') ? '&' : '?') + params;
|
|
50
|
+
}
|
|
51
|
+
if (url.hash) {
|
|
52
|
+
result += url.hash.startsWith('#') ? url.hash : `#${url.hash}`;
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
return '';
|
|
57
|
+
};
|
|
58
|
+
// Set of URLs that have been prefetched
|
|
59
|
+
const prefetchedUrls = new Set();
|
|
60
|
+
// Prefetch a URL by creating a hidden link element
|
|
61
|
+
const prefetchUrl = (url) => {
|
|
62
|
+
if (prefetchedUrls.has(url))
|
|
63
|
+
return;
|
|
64
|
+
if (typeof window === 'undefined')
|
|
65
|
+
return;
|
|
66
|
+
// Don't prefetch external URLs
|
|
67
|
+
if (url.startsWith('http://') || url.startsWith('https://')) {
|
|
68
|
+
if (!url.startsWith(window.location.origin))
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
prefetchedUrls.add(url);
|
|
72
|
+
// Create prefetch link
|
|
73
|
+
const link = document.createElement('link');
|
|
74
|
+
link.rel = 'prefetch';
|
|
75
|
+
link.href = url;
|
|
76
|
+
link.as = 'document';
|
|
77
|
+
document.head.appendChild(link);
|
|
78
|
+
};
|
|
79
|
+
exports.Link = react_1.default.forwardRef(({ href, as, replace, scroll = true, shallow, passHref, prefetch = true, legacyBehavior, children, onClick, onMouseEnter, onNavigate, ...props }, ref) => {
|
|
80
|
+
const router = (0, router_1.useRouter)();
|
|
81
|
+
const pathname = (0, router_1.usePathname)();
|
|
82
|
+
const linkRef = (0, react_1.useRef)(null);
|
|
83
|
+
const targetPath = formatUrl(as || href);
|
|
84
|
+
const [isActive, setIsActive] = (0, react_1.useState)(false);
|
|
85
|
+
// Combine refs
|
|
86
|
+
const setRefs = (0, react_1.useCallback)((node) => {
|
|
87
|
+
linkRef.current = node;
|
|
88
|
+
if (typeof ref === 'function') {
|
|
89
|
+
ref(node);
|
|
90
|
+
}
|
|
91
|
+
else if (ref) {
|
|
92
|
+
ref.current = node;
|
|
93
|
+
}
|
|
94
|
+
}, [ref]);
|
|
95
|
+
// Check if link is active (current route)
|
|
96
|
+
(0, react_1.useEffect)(() => {
|
|
97
|
+
if (typeof window !== 'undefined') {
|
|
98
|
+
setIsActive(pathname === targetPath);
|
|
99
|
+
}
|
|
100
|
+
}, [targetPath, pathname]);
|
|
101
|
+
// Prefetch on viewport intersection
|
|
102
|
+
(0, react_1.useEffect)(() => {
|
|
103
|
+
if (!prefetch || prefetch === null)
|
|
104
|
+
return;
|
|
105
|
+
if (typeof window === 'undefined')
|
|
106
|
+
return;
|
|
107
|
+
const element = linkRef.current;
|
|
108
|
+
if (!element)
|
|
109
|
+
return;
|
|
110
|
+
// Only prefetch visible links
|
|
111
|
+
const observer = new IntersectionObserver((entries) => {
|
|
112
|
+
entries.forEach((entry) => {
|
|
113
|
+
if (entry.isIntersecting) {
|
|
114
|
+
prefetchUrl(targetPath);
|
|
115
|
+
observer.disconnect();
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}, {
|
|
119
|
+
rootMargin: '200px',
|
|
120
|
+
threshold: 0,
|
|
121
|
+
});
|
|
122
|
+
observer.observe(element);
|
|
123
|
+
return () => observer.disconnect();
|
|
124
|
+
}, [prefetch, targetPath]);
|
|
125
|
+
// Prefetch on hover
|
|
126
|
+
const handleMouseEnter = (0, react_1.useCallback)((e) => {
|
|
127
|
+
if (onMouseEnter)
|
|
128
|
+
onMouseEnter(e);
|
|
129
|
+
if (prefetch !== false && prefetch !== null) {
|
|
130
|
+
prefetchUrl(targetPath);
|
|
131
|
+
}
|
|
132
|
+
}, [onMouseEnter, prefetch, targetPath]);
|
|
133
|
+
// Handle navigation
|
|
134
|
+
const handleClick = (0, react_1.useCallback)((e) => {
|
|
135
|
+
if (onClick)
|
|
136
|
+
onClick(e);
|
|
137
|
+
// Standard link behavior checks
|
|
138
|
+
if (e.defaultPrevented)
|
|
139
|
+
return;
|
|
140
|
+
if (e.button !== 0)
|
|
141
|
+
return; // ignore right clicks
|
|
142
|
+
if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey)
|
|
143
|
+
return; // ignore open in new tab
|
|
144
|
+
if (!href)
|
|
145
|
+
return;
|
|
146
|
+
// Check for external links
|
|
147
|
+
if (targetPath.startsWith('http://') || targetPath.startsWith('https://')) {
|
|
148
|
+
if (!targetPath.startsWith(window.location.origin)) {
|
|
149
|
+
return; // Let browser handle external links
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
e.preventDefault();
|
|
153
|
+
// Call onNavigate callback
|
|
154
|
+
if (onNavigate)
|
|
155
|
+
onNavigate();
|
|
156
|
+
// Navigate
|
|
157
|
+
if (replace) {
|
|
158
|
+
router.replace(targetPath, { scroll });
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
router.push(targetPath, { scroll });
|
|
162
|
+
}
|
|
163
|
+
}, [onClick, href, targetPath, replace, scroll, router, onNavigate]);
|
|
164
|
+
// Data attributes for styling active links
|
|
165
|
+
const dataProps = {
|
|
166
|
+
'data-active': isActive ? 'true' : undefined,
|
|
167
|
+
};
|
|
168
|
+
return ((0, jsx_runtime_1.jsx)("a", { href: targetPath, onClick: handleClick, onMouseEnter: handleMouseEnter, ref: setRefs, ...dataProps, ...props, children: children }));
|
|
169
|
+
});
|
|
170
|
+
exports.Link.displayName = 'Link';
|
|
171
|
+
/**
|
|
172
|
+
* Hook to check link navigation status
|
|
173
|
+
*/
|
|
174
|
+
const useLinkStatus = () => {
|
|
175
|
+
// In a real implementation, this would track navigation state
|
|
176
|
+
const [pending, setPending] = (0, react_1.useState)(false);
|
|
177
|
+
return { pending };
|
|
178
|
+
};
|
|
179
|
+
exports.useLinkStatus = useLinkStatus;
|
|
180
|
+
/**
|
|
181
|
+
* Hook to check if a path is active
|
|
182
|
+
*/
|
|
183
|
+
const useIsActive = (path) => {
|
|
184
|
+
const pathname = (0, router_1.usePathname)();
|
|
185
|
+
return pathname === path;
|
|
186
|
+
};
|
|
187
|
+
exports.useIsActive = useIsActive;
|
|
188
|
+
exports.default = exports.Link;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vista Navigation Hooks
|
|
3
|
+
*
|
|
4
|
+
* Provides hooks for reading route information.
|
|
5
|
+
* Similar to Next.js navigation hooks.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Returns the current pathname
|
|
9
|
+
*/
|
|
10
|
+
export declare function usePathname(): string;
|
|
11
|
+
/**
|
|
12
|
+
* Returns the current search params
|
|
13
|
+
*/
|
|
14
|
+
export declare function useSearchParams(): URLSearchParams;
|
|
15
|
+
/**
|
|
16
|
+
* Returns dynamic route parameters
|
|
17
|
+
* For route /users/[id]/posts/[postId], returns { id: '123', postId: '456' }
|
|
18
|
+
*/
|
|
19
|
+
export declare function useParams<T extends Record<string, string> = Record<string, string>>(): T;
|
|
20
|
+
/**
|
|
21
|
+
* Returns the currently active segment of the layout
|
|
22
|
+
*/
|
|
23
|
+
export declare function useSelectedLayoutSegment(): string | null;
|
|
24
|
+
/**
|
|
25
|
+
* Returns all active segments of the layout
|
|
26
|
+
*/
|
|
27
|
+
export declare function useSelectedLayoutSegments(): string[];
|
|
28
|
+
export { useRouter } from './router';
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vista Navigation Hooks
|
|
3
|
+
*
|
|
4
|
+
* Provides hooks for reading route information.
|
|
5
|
+
* Similar to Next.js navigation hooks.
|
|
6
|
+
*/
|
|
7
|
+
'client load';
|
|
8
|
+
"use strict";
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(o, k2, desc);
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
26
|
+
var ownKeys = function(o) {
|
|
27
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
28
|
+
var ar = [];
|
|
29
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
30
|
+
return ar;
|
|
31
|
+
};
|
|
32
|
+
return ownKeys(o);
|
|
33
|
+
};
|
|
34
|
+
return function (mod) {
|
|
35
|
+
if (mod && mod.__esModule) return mod;
|
|
36
|
+
var result = {};
|
|
37
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
38
|
+
__setModuleDefault(result, mod);
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
})();
|
|
42
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
+
exports.useRouter = void 0;
|
|
44
|
+
exports.usePathname = usePathname;
|
|
45
|
+
exports.useSearchParams = useSearchParams;
|
|
46
|
+
exports.useParams = useParams;
|
|
47
|
+
exports.useSelectedLayoutSegment = useSelectedLayoutSegment;
|
|
48
|
+
exports.useSelectedLayoutSegments = useSelectedLayoutSegments;
|
|
49
|
+
const React = __importStar(require("react"));
|
|
50
|
+
const context_1 = require("../router/context");
|
|
51
|
+
/**
|
|
52
|
+
* Returns the current pathname
|
|
53
|
+
*/
|
|
54
|
+
function usePathname() {
|
|
55
|
+
const [pathname, setPathname] = React.useState(() => typeof window !== 'undefined' ? window.location.pathname : '/');
|
|
56
|
+
React.useEffect(() => {
|
|
57
|
+
const handlePopState = () => {
|
|
58
|
+
setPathname(window.location.pathname);
|
|
59
|
+
};
|
|
60
|
+
window.addEventListener('popstate', handlePopState);
|
|
61
|
+
return () => window.removeEventListener('popstate', handlePopState);
|
|
62
|
+
}, []);
|
|
63
|
+
return pathname;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Returns the current search params
|
|
67
|
+
*/
|
|
68
|
+
function useSearchParams() {
|
|
69
|
+
const [searchParams, setSearchParams] = React.useState(() => typeof window !== 'undefined'
|
|
70
|
+
? new URLSearchParams(window.location.search)
|
|
71
|
+
: new URLSearchParams());
|
|
72
|
+
React.useEffect(() => {
|
|
73
|
+
const handlePopState = () => {
|
|
74
|
+
setSearchParams(new URLSearchParams(window.location.search));
|
|
75
|
+
};
|
|
76
|
+
window.addEventListener('popstate', handlePopState);
|
|
77
|
+
return () => window.removeEventListener('popstate', handlePopState);
|
|
78
|
+
}, []);
|
|
79
|
+
return searchParams;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Returns dynamic route parameters
|
|
83
|
+
* For route /users/[id]/posts/[postId], returns { id: '123', postId: '456' }
|
|
84
|
+
*/
|
|
85
|
+
function useParams() {
|
|
86
|
+
const context = (0, context_1.useRouterContext)();
|
|
87
|
+
const pathname = usePathname();
|
|
88
|
+
// Basic param extraction (simplified)
|
|
89
|
+
// In a full implementation, this would match against route patterns
|
|
90
|
+
const params = {};
|
|
91
|
+
// Extract dynamic segments from URL
|
|
92
|
+
const pathParts = pathname.split('/').filter(Boolean);
|
|
93
|
+
pathParts.forEach((part, index) => {
|
|
94
|
+
if (part.match(/^\d+$/)) {
|
|
95
|
+
params[`param${index}`] = part;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
return params;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Returns the currently active segment of the layout
|
|
102
|
+
*/
|
|
103
|
+
function useSelectedLayoutSegment() {
|
|
104
|
+
const pathname = usePathname();
|
|
105
|
+
const segments = pathname.split('/').filter(Boolean);
|
|
106
|
+
return segments[segments.length - 1] || null;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Returns all active segments of the layout
|
|
110
|
+
*/
|
|
111
|
+
function useSelectedLayoutSegments() {
|
|
112
|
+
const pathname = usePathname();
|
|
113
|
+
return pathname.split('/').filter(Boolean);
|
|
114
|
+
}
|
|
115
|
+
var router_1 = require("./router");
|
|
116
|
+
Object.defineProperty(exports, "useRouter", { enumerable: true, get: function () { return router_1.useRouter; } });
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export declare const RouterContext: React.Context<{
|
|
3
|
+
push: (url: string, options?: RouterOptions) => void;
|
|
4
|
+
replace: (url: string, options?: RouterOptions) => void;
|
|
5
|
+
back: () => void;
|
|
6
|
+
forward: () => void;
|
|
7
|
+
prefetch: (url: string) => void;
|
|
8
|
+
refresh: () => void;
|
|
9
|
+
params: Record<string, string>;
|
|
10
|
+
pathname: string;
|
|
11
|
+
}>;
|
|
12
|
+
export interface RouterOptions {
|
|
13
|
+
scroll?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface AppRouterInstance {
|
|
16
|
+
push(url: string, options?: RouterOptions): void;
|
|
17
|
+
replace(url: string, options?: RouterOptions): void;
|
|
18
|
+
back(): void;
|
|
19
|
+
forward(): void;
|
|
20
|
+
prefetch(url: string): void;
|
|
21
|
+
refresh(): void;
|
|
22
|
+
}
|
|
23
|
+
interface RouteNode {
|
|
24
|
+
segment: string;
|
|
25
|
+
kind: 'static' | 'dynamic' | 'catch-all';
|
|
26
|
+
index?: React.ComponentType<any>;
|
|
27
|
+
layout?: React.ComponentType<any>;
|
|
28
|
+
loading?: React.ComponentType<any>;
|
|
29
|
+
error?: React.ComponentType<any>;
|
|
30
|
+
notFound?: React.ComponentType<any>;
|
|
31
|
+
children?: RouteNode[];
|
|
32
|
+
}
|
|
33
|
+
interface RouterProps {
|
|
34
|
+
routeTree: RouteNode;
|
|
35
|
+
initialPath?: string;
|
|
36
|
+
}
|
|
37
|
+
export declare function Router({ routeTree, initialPath }: RouterProps): import("react/jsx-runtime").JSX.Element;
|
|
38
|
+
export declare function useRouter(): AppRouterInstance;
|
|
39
|
+
export declare function useParams(): Record<string, string>;
|
|
40
|
+
export declare function usePathname(): string;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
'client load';
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.RouterContext = void 0;
|
|
38
|
+
exports.Router = Router;
|
|
39
|
+
exports.useRouter = useRouter;
|
|
40
|
+
exports.useParams = useParams;
|
|
41
|
+
exports.usePathname = usePathname;
|
|
42
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
43
|
+
const React = __importStar(require("react"));
|
|
44
|
+
// --- Context ---
|
|
45
|
+
exports.RouterContext = React.createContext(null);
|
|
46
|
+
function Router({ routeTree, initialPath }) {
|
|
47
|
+
const [currentPath, setCurrentPath] = React.useState(initialPath || (typeof window !== 'undefined' ? window.location.pathname : '/'));
|
|
48
|
+
React.useEffect(() => {
|
|
49
|
+
const onPopState = () => setCurrentPath(window.location.pathname);
|
|
50
|
+
window.addEventListener('popstate', onPopState);
|
|
51
|
+
return () => window.removeEventListener('popstate', onPopState);
|
|
52
|
+
}, []);
|
|
53
|
+
// Match Route
|
|
54
|
+
const match = React.useMemo(() => matchRoute(routeTree, currentPath), [routeTree, currentPath]);
|
|
55
|
+
const routerValue = React.useMemo(() => ({
|
|
56
|
+
push: (url, options) => {
|
|
57
|
+
window.history.pushState({}, '', url);
|
|
58
|
+
window.dispatchEvent(new PopStateEvent('popstate'));
|
|
59
|
+
if (options?.scroll !== false)
|
|
60
|
+
window.scrollTo(0, 0);
|
|
61
|
+
},
|
|
62
|
+
replace: (url, options) => {
|
|
63
|
+
window.history.replaceState({}, '', url);
|
|
64
|
+
window.dispatchEvent(new PopStateEvent('popstate'));
|
|
65
|
+
if (options?.scroll !== false)
|
|
66
|
+
window.scrollTo(0, 0);
|
|
67
|
+
},
|
|
68
|
+
back: () => window.history.back(),
|
|
69
|
+
forward: () => window.history.forward(),
|
|
70
|
+
prefetch: (url) => {
|
|
71
|
+
const link = document.createElement('link');
|
|
72
|
+
link.rel = 'prefetch';
|
|
73
|
+
link.href = url;
|
|
74
|
+
document.head.appendChild(link);
|
|
75
|
+
},
|
|
76
|
+
refresh: () => window.dispatchEvent(new PopStateEvent('popstate')),
|
|
77
|
+
params: match.params,
|
|
78
|
+
pathname: currentPath
|
|
79
|
+
}), [currentPath, match.params]);
|
|
80
|
+
// Render Component Tree
|
|
81
|
+
// Stack: [RootLayout, Layout2, Layout3, Page]
|
|
82
|
+
let content = match.PageComponent ? (0, jsx_runtime_1.jsx)(match.PageComponent, { ...match.params }) : null;
|
|
83
|
+
if (!content && match.NotFoundComponent) {
|
|
84
|
+
content = (0, jsx_runtime_1.jsx)(match.NotFoundComponent, {});
|
|
85
|
+
}
|
|
86
|
+
// Wrap in layouts (reverse order)
|
|
87
|
+
for (let i = match.layouts.length - 1; i >= 0; i--) {
|
|
88
|
+
const Layout = match.layouts[i];
|
|
89
|
+
if (Layout) {
|
|
90
|
+
content = (0, jsx_runtime_1.jsx)(Layout, { params: match.params, children: content });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return ((0, jsx_runtime_1.jsx)(exports.RouterContext.Provider, { value: routerValue, children: content }));
|
|
94
|
+
}
|
|
95
|
+
function matchRoute(root, path) {
|
|
96
|
+
const segments = path.split('/').filter(Boolean);
|
|
97
|
+
const params = {};
|
|
98
|
+
const layouts = [];
|
|
99
|
+
// Nearest NotFound found during traversal (propagates down)
|
|
100
|
+
let nearestNotFound = root.notFound || null;
|
|
101
|
+
// Helper to traverse
|
|
102
|
+
function traverse(node, segmentIndex) {
|
|
103
|
+
// Collect Layout
|
|
104
|
+
if (node.layout)
|
|
105
|
+
layouts.push(node.layout);
|
|
106
|
+
if (node.notFound)
|
|
107
|
+
nearestNotFound = node.notFound;
|
|
108
|
+
// If we processed all segments, check for index page
|
|
109
|
+
if (segmentIndex === segments.length) {
|
|
110
|
+
if (node.index) {
|
|
111
|
+
return {
|
|
112
|
+
PageComponent: node.index,
|
|
113
|
+
NotFoundComponent: nearestNotFound,
|
|
114
|
+
layouts,
|
|
115
|
+
params
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
// No index page here -> 404
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
const currentSegment = segments[segmentIndex];
|
|
122
|
+
// Find matching child
|
|
123
|
+
if (node.children) {
|
|
124
|
+
for (const child of node.children) {
|
|
125
|
+
let isMatch = false;
|
|
126
|
+
if (child.kind === 'static' && child.segment === currentSegment) {
|
|
127
|
+
isMatch = true;
|
|
128
|
+
}
|
|
129
|
+
else if (child.kind === 'dynamic') {
|
|
130
|
+
isMatch = true;
|
|
131
|
+
params[child.segment] = currentSegment;
|
|
132
|
+
}
|
|
133
|
+
else if (child.kind === 'catch-all') {
|
|
134
|
+
isMatch = true;
|
|
135
|
+
const catchAll = segments.slice(segmentIndex).join('/');
|
|
136
|
+
params[child.segment] = catchAll;
|
|
137
|
+
// Catch-all consumes 'rest'
|
|
138
|
+
// Recursively match index of catch-all node??
|
|
139
|
+
// Simplified: just match if it has a page
|
|
140
|
+
if (child.index) {
|
|
141
|
+
if (child.layout)
|
|
142
|
+
layouts.push(child.layout);
|
|
143
|
+
return {
|
|
144
|
+
PageComponent: child.index,
|
|
145
|
+
NotFoundComponent: nearestNotFound,
|
|
146
|
+
layouts,
|
|
147
|
+
params
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (isMatch) {
|
|
152
|
+
const result = traverse(child, segmentIndex + 1);
|
|
153
|
+
if (result)
|
|
154
|
+
return result;
|
|
155
|
+
// Backtrack params if needed (simple implementation ignores backtracking cleanup for now)
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
const result = traverse(root, 0);
|
|
162
|
+
if (result)
|
|
163
|
+
return result;
|
|
164
|
+
// 404
|
|
165
|
+
return {
|
|
166
|
+
PageComponent: null,
|
|
167
|
+
NotFoundComponent: nearestNotFound,
|
|
168
|
+
layouts,
|
|
169
|
+
params
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
// --- Hooks ---
|
|
173
|
+
function useRouter() {
|
|
174
|
+
const context = React.useContext(exports.RouterContext);
|
|
175
|
+
if (!context)
|
|
176
|
+
throw new Error('useRouter must be used within a RouterProvider/Router');
|
|
177
|
+
return context;
|
|
178
|
+
}
|
|
179
|
+
function useParams() {
|
|
180
|
+
const context = React.useContext(exports.RouterContext);
|
|
181
|
+
if (!context)
|
|
182
|
+
return {};
|
|
183
|
+
return context.params;
|
|
184
|
+
}
|
|
185
|
+
function usePathname() {
|
|
186
|
+
const context = React.useContext(exports.RouterContext);
|
|
187
|
+
if (!context)
|
|
188
|
+
return '';
|
|
189
|
+
return context.pathname;
|
|
190
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vista Script Component
|
|
3
|
+
*
|
|
4
|
+
* Optimized script loading with different strategies.
|
|
5
|
+
* Similar to Next.js Script component.
|
|
6
|
+
*/
|
|
7
|
+
export type ScriptStrategy = 'beforeInteractive' | 'afterInteractive' | 'lazyOnload' | 'worker';
|
|
8
|
+
export interface ScriptProps {
|
|
9
|
+
/**
|
|
10
|
+
* URL of the script
|
|
11
|
+
*/
|
|
12
|
+
src?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Inline script content
|
|
15
|
+
*/
|
|
16
|
+
dangerouslySetInnerHTML?: {
|
|
17
|
+
__html: string;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Loading strategy
|
|
21
|
+
* - beforeInteractive: Load before page becomes interactive
|
|
22
|
+
* - afterInteractive: Load after hydration (default)
|
|
23
|
+
* - lazyOnload: Load during idle time
|
|
24
|
+
* - worker: Load in a web worker (experimental)
|
|
25
|
+
*/
|
|
26
|
+
strategy?: ScriptStrategy;
|
|
27
|
+
/**
|
|
28
|
+
* Callback when script loads
|
|
29
|
+
*/
|
|
30
|
+
onLoad?: () => void;
|
|
31
|
+
/**
|
|
32
|
+
* Callback when script errors
|
|
33
|
+
*/
|
|
34
|
+
onError?: () => void;
|
|
35
|
+
/**
|
|
36
|
+
* Callback when script is ready (for inline scripts)
|
|
37
|
+
*/
|
|
38
|
+
onReady?: () => void;
|
|
39
|
+
/**
|
|
40
|
+
* Script ID for deduplication
|
|
41
|
+
*/
|
|
42
|
+
id?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Additional script attributes
|
|
45
|
+
*/
|
|
46
|
+
[key: string]: any;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Script component for optimized script loading
|
|
50
|
+
*/
|
|
51
|
+
export default function Script({ src, dangerouslySetInnerHTML, strategy, onLoad, onError, onReady, id, ...rest }: ScriptProps): import("react/jsx-runtime").JSX.Element;
|