vite-plugin-vanjs 0.0.5 → 0.0.7
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/README.md +32 -34
- package/client/global.d.ts +5 -1
- package/client/index.mjs +99 -5
- package/client/types.d.ts +5 -1
- package/jsx/global.d.ts +3 -2
- package/jsx/jsx.d.ts +42 -9
- package/jsx/jsx.mjs +10 -10
- package/meta/Head.mjs +3 -3
- package/meta/global.d.ts +24 -12
- package/meta/helpers.mjs +5 -3
- package/meta/tags.mjs +5 -7
- package/meta/types.d.ts +7 -7
- package/package.json +8 -7
- package/router/a.mjs +14 -8
- package/router/global.d.ts +75 -16
- package/router/helpers.mjs +26 -7
- package/router/lazy.mjs +1 -1
- package/router/router.mjs +17 -10
- package/router/state.mjs +3 -2
- package/router/types.d.ts +86 -22
- package/server/global.d.ts +1 -0
- package/server/index.mjs +3 -3
- package/server/types.d.ts +1 -1
- package/setup/index-debug.mjs +21 -0
- package/setup/van-debug.mjs +2 -0
- package/src/index.mjs +18 -2
- package/src/types.d.ts +1 -1
- package/tsconfig.json +1 -1
package/meta/types.d.ts
CHANGED
|
@@ -7,10 +7,10 @@ export const createHeadTags: () => Map<
|
|
|
7
7
|
SupportedTags | TagFunc<SupportedTags>
|
|
8
8
|
>;
|
|
9
9
|
|
|
10
|
-
export const getHeadTags =
|
|
11
|
-
Map<string, SupportedTags | TagFunc<SupportedTags
|
|
10
|
+
export const getHeadTags =
|
|
11
|
+
() => (Map<string, SupportedTags | TagFunc<SupportedTags>>);
|
|
12
12
|
export const resetHeadTags: () => void;
|
|
13
|
-
export const initializeHeadTags: () => void;
|
|
13
|
+
export const initializeHeadTags: () => void | (() => Promise<void>);
|
|
14
14
|
|
|
15
15
|
export type SupportedTags =
|
|
16
16
|
| HTMLTitleElement
|
|
@@ -21,13 +21,13 @@ export type SupportedTags =
|
|
|
21
21
|
|
|
22
22
|
export type TagProps = SupportedTags | PropsWithKnownKeys<SupportedTags>;
|
|
23
23
|
|
|
24
|
-
export type HeadTags = SupportedTags[] | TagFunc
|
|
24
|
+
export type HeadTags = SupportedTags[] | TagFunc[];
|
|
25
25
|
|
|
26
|
-
export
|
|
26
|
+
export const addMeta = (_tag: string | TagProps) => null;
|
|
27
27
|
|
|
28
|
-
export
|
|
28
|
+
export const Head: () => HeadTags;
|
|
29
29
|
|
|
30
|
-
export
|
|
30
|
+
export const parseAttributes: (
|
|
31
31
|
attributeString: string,
|
|
32
32
|
) => Record<string, string>;
|
|
33
33
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-vanjs",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"author": "thednp",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "A mini meta-framework for VanJS powered by Vite",
|
|
@@ -87,13 +87,14 @@
|
|
|
87
87
|
"vanjs-ext": "^0.6.2"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|
|
90
|
-
"@
|
|
91
|
-
"@vitest/
|
|
92
|
-
"@vitest/
|
|
93
|
-
"
|
|
90
|
+
"@types/node": "^22.13.10",
|
|
91
|
+
"@vitest/browser": "^3.0.9",
|
|
92
|
+
"@vitest/coverage-istanbul": "^3.0.9",
|
|
93
|
+
"@vitest/ui": "^3.0.9",
|
|
94
|
+
"happy-dom": "^16.8.1",
|
|
94
95
|
"typescript": "5.6.2",
|
|
95
|
-
"vite": "^6.
|
|
96
|
-
"vitest": "^3.0.
|
|
96
|
+
"vite": "^6.2.2",
|
|
97
|
+
"vitest": "^3.0.9"
|
|
97
98
|
},
|
|
98
99
|
"engines": {
|
|
99
100
|
"node": ">=20",
|
package/router/a.mjs
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
// router/a.mjs
|
|
2
2
|
import van from "vanjs-core";
|
|
3
|
-
import setup from "
|
|
3
|
+
import setup from "../setup/index.mjs";
|
|
4
4
|
import { matchRoute } from "./routes.mjs";
|
|
5
5
|
import { executeLifecycle, isCurrentPage, navigate } from "./helpers.mjs";
|
|
6
6
|
|
|
7
|
+
/** @typedef {typeof import("./types").A} A */
|
|
8
|
+
|
|
7
9
|
/**
|
|
8
|
-
* @
|
|
9
|
-
* @param {...(Element | Node)[]} children
|
|
10
|
-
* @returns {HTMLAnchorElement}
|
|
10
|
+
* @type {A}
|
|
11
11
|
*/
|
|
12
|
-
export const A = (
|
|
13
|
-
|
|
12
|
+
export const A = (
|
|
13
|
+
/* istanbul ignore next */ { href, children, ...rest } = {},
|
|
14
|
+
...otherChildren
|
|
15
|
+
) => {
|
|
16
|
+
/* istanbul ignore next - try again later */
|
|
17
|
+
const props = Object.fromEntries(
|
|
18
|
+
Object.entries(rest || {}).filter(([_, val]) => val),
|
|
19
|
+
);
|
|
14
20
|
const newProps = {
|
|
15
21
|
href,
|
|
16
|
-
...
|
|
22
|
+
...props,
|
|
17
23
|
};
|
|
18
24
|
|
|
19
25
|
van.derive(() => {
|
|
@@ -22,7 +28,7 @@ export const A = (props, ...children) => {
|
|
|
22
28
|
}
|
|
23
29
|
});
|
|
24
30
|
|
|
25
|
-
const anchor = van.tags.a(newProps, ...children);
|
|
31
|
+
const anchor = van.tags.a(newProps, [...(children || []), ...otherChildren]);
|
|
26
32
|
/* istanbul ignore else */
|
|
27
33
|
if (!setup.isServer) {
|
|
28
34
|
anchor.addEventListener("click", async (e) => {
|
package/router/global.d.ts
CHANGED
|
@@ -1,10 +1,54 @@
|
|
|
1
1
|
declare module "@vanjs/router" {
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
Element as VElement,
|
|
4
|
+
TagFunc as IsoTagFunc,
|
|
5
|
+
} from "mini-van-plate/van-plate";
|
|
3
6
|
import van from "vanjs-core";
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
import type {
|
|
8
|
+
ChildDom,
|
|
9
|
+
Primitive,
|
|
10
|
+
Props,
|
|
11
|
+
PropsWithKnownKeys,
|
|
12
|
+
PropValueOrDerived,
|
|
13
|
+
State,
|
|
14
|
+
} from "vanjs-core";
|
|
15
|
+
|
|
16
|
+
// type VanElement = VElement | Exclude<Primitive, boolean | undefined>;
|
|
17
|
+
type DOMElement = globalThis.Element;
|
|
18
|
+
type PrimitiveChild = Primitive | State<Primitive | undefined | null>;
|
|
19
|
+
|
|
20
|
+
type VanElement =
|
|
21
|
+
| SVGElement
|
|
22
|
+
| HTMLElement
|
|
23
|
+
| DOMElement
|
|
24
|
+
| Node
|
|
25
|
+
| VElement
|
|
26
|
+
| PrimitiveChild;
|
|
27
|
+
export type VanNode =
|
|
28
|
+
| VanElement
|
|
29
|
+
| VanNode[]
|
|
30
|
+
| (() => VanNode)
|
|
31
|
+
| null
|
|
32
|
+
| undefined;
|
|
33
|
+
|
|
34
|
+
type ComponentProps1<T> =
|
|
35
|
+
& Props
|
|
36
|
+
& PropsWithKnownKeys<T>;
|
|
37
|
+
|
|
38
|
+
type ComponentProps<K extends keyof HTMLElementTagNameMap> =
|
|
39
|
+
& Props
|
|
40
|
+
& PropsWithKnownKeys<HTMLElementTagNameMap[K]>;
|
|
41
|
+
|
|
42
|
+
export type VanComponent<
|
|
43
|
+
K extends keyof HTMLElementTagNameMap = "div",
|
|
44
|
+
O extends (Record<string, PropValueOrDerived> | undefined) = undefined,
|
|
45
|
+
> = {
|
|
46
|
+
(
|
|
47
|
+
props?: O extends object ? ComponentProps<K> & Partial<O>
|
|
48
|
+
: ComponentProps<K>,
|
|
49
|
+
...children: ChildDom[]
|
|
50
|
+
): HTMLElementTagNameMap[K];
|
|
51
|
+
};
|
|
8
52
|
|
|
9
53
|
// router.mjs
|
|
10
54
|
/**
|
|
@@ -18,7 +62,14 @@ declare module "@vanjs/router" {
|
|
|
18
62
|
* return Router(); // or <Router /> for JSX
|
|
19
63
|
* }
|
|
20
64
|
*/
|
|
21
|
-
export const Router:
|
|
65
|
+
// export const Router: JSX.Component<HTMLElement> & VanComponent<HTMLElement>;
|
|
66
|
+
// export function Router(props?: ComponentProps<HTMLElement>): HTMLElement;
|
|
67
|
+
// export function Router(
|
|
68
|
+
// props?: JSX.IntrinsicElements["main"] & { children: null },
|
|
69
|
+
// ): HTMLElement;
|
|
70
|
+
export const Router:
|
|
71
|
+
& VanComponent<"main">
|
|
72
|
+
& JSX.Component<"main">;
|
|
22
73
|
|
|
23
74
|
// a.mjs
|
|
24
75
|
/**
|
|
@@ -38,10 +89,9 @@ declare module "@vanjs/router" {
|
|
|
38
89
|
* );
|
|
39
90
|
* }
|
|
40
91
|
*/
|
|
41
|
-
export const A:
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
) => HTMLAnchorElement;
|
|
92
|
+
export const A:
|
|
93
|
+
& VanComponent<"a">
|
|
94
|
+
& JSX.Component<"a">;
|
|
45
95
|
|
|
46
96
|
// helpers.mjs
|
|
47
97
|
/**
|
|
@@ -69,8 +119,6 @@ declare module "@vanjs/router" {
|
|
|
69
119
|
*/
|
|
70
120
|
export const redirect: (href?: string) => void | (() => void);
|
|
71
121
|
|
|
72
|
-
export type VanComponent = () => VanNode | VanNode[];
|
|
73
|
-
|
|
74
122
|
// routes.mjs
|
|
75
123
|
export type RouteEntry = {
|
|
76
124
|
path: string;
|
|
@@ -137,18 +185,23 @@ declare module "@vanjs/router" {
|
|
|
137
185
|
* @param {...VanNode[]} children
|
|
138
186
|
*/
|
|
139
187
|
export const unwrap: (
|
|
140
|
-
source:
|
|
188
|
+
source:
|
|
189
|
+
| VanNode
|
|
190
|
+
| IsoTagFunc
|
|
191
|
+
| VanNode[]
|
|
192
|
+
| IsoTagFunc[]
|
|
193
|
+
| (() => IsoTagFunc | IsoTagFunc[] | VanNode | VanNode[]),
|
|
141
194
|
...children: VanNode[]
|
|
142
195
|
) => VanNode;
|
|
143
196
|
|
|
144
197
|
export type ComponentModule = {
|
|
145
|
-
component: VanComponent;
|
|
198
|
+
component: VanComponent | JSX.Element;
|
|
146
199
|
route: Pick<RouteEntry, "load" | "preload">;
|
|
147
200
|
};
|
|
148
201
|
|
|
149
202
|
export type DynamicModule = {
|
|
150
|
-
Page: VanComponent;
|
|
151
|
-
default?: VanComponent;
|
|
203
|
+
Page: VanComponent | JSX.Element;
|
|
204
|
+
default?: VanComponent | JSX.Element;
|
|
152
205
|
route?: Pick<RouteEntry, "load" | "preload">;
|
|
153
206
|
};
|
|
154
207
|
|
|
@@ -159,4 +212,10 @@ declare module "@vanjs/router" {
|
|
|
159
212
|
* @param importFn
|
|
160
213
|
*/
|
|
161
214
|
export const lazy: (importFn: () => LazyComponent) => () => ComponentModule;
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Fixes the URL of a route.
|
|
218
|
+
* @param url
|
|
219
|
+
*/
|
|
220
|
+
export const fixRouteUrl: (url: string) => string;
|
|
162
221
|
}
|
package/router/helpers.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
// import van from "vanjs-core";
|
|
2
|
+
import setup from "../setup/index.mjs";
|
|
3
3
|
import { routerState, setRouterState } from "./state.mjs";
|
|
4
4
|
import { matchRoute } from "./routes.mjs";
|
|
5
5
|
|
|
@@ -32,14 +32,20 @@ export const unwrap = (source, ...children) => {
|
|
|
32
32
|
? [...source()?.children || source()]
|
|
33
33
|
: typeof HTMLElement !== "undefined" && source instanceof HTMLElement
|
|
34
34
|
? [...source.children]
|
|
35
|
-
: Array.isArray(source)
|
|
35
|
+
: /* istanbul ignore next */ Array.isArray(source)
|
|
36
36
|
? source
|
|
37
37
|
: [source];
|
|
38
38
|
|
|
39
|
-
return van.tags.fragment(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
);
|
|
39
|
+
// return van.tags.fragment(
|
|
40
|
+
// ...(children || /* istanbul ignore next */ []),
|
|
41
|
+
// ...pageChildren,
|
|
42
|
+
// );
|
|
43
|
+
return {
|
|
44
|
+
children: [
|
|
45
|
+
...(children || /* istanbul ignore next */ []),
|
|
46
|
+
...pageChildren,
|
|
47
|
+
],
|
|
48
|
+
};
|
|
43
49
|
};
|
|
44
50
|
return layout();
|
|
45
51
|
};
|
|
@@ -138,6 +144,19 @@ export const extractParams = (pattern, path) => {
|
|
|
138
144
|
return params;
|
|
139
145
|
};
|
|
140
146
|
|
|
147
|
+
/**
|
|
148
|
+
* Fix the URL of a route
|
|
149
|
+
* @param {string=} url
|
|
150
|
+
* @returns
|
|
151
|
+
*/
|
|
152
|
+
export const fixRouteUrl = (url) => {
|
|
153
|
+
if (!url) return "/";
|
|
154
|
+
if (url.startsWith("/")) {
|
|
155
|
+
return url;
|
|
156
|
+
}
|
|
157
|
+
return `/${url}`;
|
|
158
|
+
};
|
|
159
|
+
|
|
141
160
|
/**
|
|
142
161
|
* Client only reload utility
|
|
143
162
|
* WORK IN PROGRESS
|
package/router/lazy.mjs
CHANGED
package/router/router.mjs
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import van from "vanjs-core";
|
|
2
|
-
import setup from "
|
|
2
|
+
import setup from "../setup/index.mjs";
|
|
3
3
|
import { routerState } from "./state.mjs";
|
|
4
4
|
import { matchRoute } from "./routes.mjs";
|
|
5
5
|
import { executeLifecycle, unwrap } from "./helpers.mjs";
|
|
6
6
|
|
|
7
|
-
export const Router = () => {
|
|
8
|
-
const { div } = van.tags;
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
export const Router = (initialProps = /* istanbul ignore next */ {}) => {
|
|
8
|
+
const { div, main } = van.tags;
|
|
9
|
+
/* istanbul ignore next - try again later */
|
|
10
|
+
const props = Object.fromEntries(
|
|
11
|
+
Object.entries(initialProps).filter(([_, val]) => val),
|
|
12
|
+
);
|
|
13
|
+
const wrapper = main(props);
|
|
11
14
|
const mainLayout = () => {
|
|
12
15
|
const route = matchRoute(routerState.pathname.val);
|
|
13
16
|
/* istanbul ignore else */
|
|
14
|
-
if (!route) return div("404 - Not Found");
|
|
17
|
+
if (!route) return van.add(wrapper, div("404 - Not Found"));
|
|
15
18
|
|
|
16
19
|
routerState.params.val = route.params || {};
|
|
17
20
|
// Server-side or async component: use renderComponent
|
|
@@ -20,23 +23,27 @@ export const Router = () => {
|
|
|
20
23
|
try {
|
|
21
24
|
const module = await route.component();
|
|
22
25
|
const component = module.component();
|
|
26
|
+
|
|
23
27
|
await executeLifecycle(module, route.params);
|
|
24
|
-
return unwrap(component).children;
|
|
28
|
+
return van.add(wrapper, unwrap(component).children);
|
|
25
29
|
} catch (error) {
|
|
26
30
|
/* istanbul ignore next */
|
|
27
31
|
console.error("Router error:", error);
|
|
28
32
|
/* istanbul ignore next */
|
|
29
|
-
return div("Error loading page");
|
|
33
|
+
return van.add(wrapper, div("Error loading page"));
|
|
30
34
|
}
|
|
31
35
|
};
|
|
32
36
|
|
|
33
37
|
return renderComponent();
|
|
34
38
|
}
|
|
35
39
|
|
|
36
|
-
const module = route.component();
|
|
37
40
|
// Client-side lazy component, lifeCycle is already executed on the server
|
|
38
41
|
// or when A component has been clicked in the client
|
|
39
|
-
|
|
42
|
+
const module = route.component();
|
|
43
|
+
const children = module.component
|
|
44
|
+
? Array.from(unwrap(module.component).children)
|
|
45
|
+
: [];
|
|
46
|
+
return children.length ? van.add(wrapper, ...children) : wrapper;
|
|
40
47
|
};
|
|
41
48
|
|
|
42
49
|
return mainLayout();
|
package/router/state.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// router/state.js
|
|
2
2
|
import van from "vanjs-core";
|
|
3
|
-
import setup from "
|
|
3
|
+
import setup from "../setup/index.mjs";
|
|
4
|
+
import { fixRouteUrl } from "./helpers.mjs";
|
|
4
5
|
|
|
5
6
|
const initialPath = !setup.isServer ? globalThis.location.pathname : "/";
|
|
6
7
|
const initialSearch = !setup.isServer ? globalThis.location.search : "";
|
|
@@ -18,7 +19,7 @@ export const routerState = {
|
|
|
18
19
|
* @type {typeof import("./types.d.ts").setRouterState}
|
|
19
20
|
*/
|
|
20
21
|
export const setRouterState = (path, search = undefined, params) => {
|
|
21
|
-
const [pathname, searchParams] = path.split("?");
|
|
22
|
+
const [pathname, searchParams] = fixRouteUrl(path).split("?");
|
|
22
23
|
routerState.pathname.val = pathname;
|
|
23
24
|
routerState.searchParams.val = new URLSearchParams(
|
|
24
25
|
search || searchParams || "",
|
package/router/types.d.ts
CHANGED
|
@@ -1,10 +1,54 @@
|
|
|
1
1
|
/// <reference path="global.d.ts" />
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
Element as VElement,
|
|
4
|
+
TagFunc as IsoTagFunc,
|
|
5
|
+
} from "mini-van-plate/van-plate";
|
|
3
6
|
import van from "vanjs-core";
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
import type {
|
|
8
|
+
ChildDom,
|
|
9
|
+
Primitive,
|
|
10
|
+
Props,
|
|
11
|
+
PropsWithKnownKeys,
|
|
12
|
+
PropValueOrDerived,
|
|
13
|
+
State,
|
|
14
|
+
} from "vanjs-core";
|
|
15
|
+
|
|
16
|
+
// type VanElement = VElement | Exclude<Primitive, boolean | undefined>;
|
|
17
|
+
type DOMElement = globalThis.Element;
|
|
18
|
+
type PrimitiveChild = Primitive | State<Primitive | undefined | null>;
|
|
19
|
+
|
|
20
|
+
type VanElement =
|
|
21
|
+
| SVGElement
|
|
22
|
+
| HTMLElement
|
|
23
|
+
| DOMElement
|
|
24
|
+
| Node
|
|
25
|
+
| VElement
|
|
26
|
+
| PrimitiveChild;
|
|
27
|
+
export type VanNode =
|
|
28
|
+
| VanElement
|
|
29
|
+
| VanNode[]
|
|
30
|
+
| (() => VanNode)
|
|
31
|
+
| null
|
|
32
|
+
| undefined;
|
|
33
|
+
|
|
34
|
+
type ComponentProps1<T> =
|
|
35
|
+
& Props
|
|
36
|
+
& PropsWithKnownKeys<T>;
|
|
37
|
+
|
|
38
|
+
type ComponentProps<K extends keyof HTMLElementTagNameMap> =
|
|
39
|
+
& Props
|
|
40
|
+
& PropsWithKnownKeys<HTMLElementTagNameMap[K]>;
|
|
41
|
+
|
|
42
|
+
export type VanComponent<
|
|
43
|
+
K extends keyof HTMLElementTagNameMap = "div",
|
|
44
|
+
O extends (Record<string, PropValueOrDerived> | undefined) = undefined,
|
|
45
|
+
> = {
|
|
46
|
+
(
|
|
47
|
+
props?: O extends object ? ComponentProps<K> & Partial<O>
|
|
48
|
+
: ComponentProps<K>,
|
|
49
|
+
...children: ChildDom[]
|
|
50
|
+
): HTMLElementTagNameMap[K];
|
|
51
|
+
};
|
|
8
52
|
|
|
9
53
|
// router.mjs
|
|
10
54
|
/**
|
|
@@ -18,7 +62,14 @@ type VanNode = SVGElement | HTMLElement | VanElement;
|
|
|
18
62
|
* return Router(); // or <Router /> for JSX
|
|
19
63
|
* }
|
|
20
64
|
*/
|
|
21
|
-
export const Router:
|
|
65
|
+
// export const Router: JSX.Component<HTMLElement> & VanComponent<HTMLElement>;
|
|
66
|
+
// export function Router(props?: ComponentProps<HTMLElement>): HTMLElement;
|
|
67
|
+
// export function Router(
|
|
68
|
+
// props?: JSX.IntrinsicElements["main"] & { children: null },
|
|
69
|
+
// ): HTMLElement;
|
|
70
|
+
export const Router:
|
|
71
|
+
& VanComponent<"main">
|
|
72
|
+
& JSX.Component<"main">;
|
|
22
73
|
|
|
23
74
|
// a.mjs
|
|
24
75
|
/**
|
|
@@ -38,10 +89,9 @@ export const Router: () => VanNode | VanNode[];
|
|
|
38
89
|
* );
|
|
39
90
|
* }
|
|
40
91
|
*/
|
|
41
|
-
export const A:
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
) => HTMLAnchorElement;
|
|
92
|
+
export const A:
|
|
93
|
+
& VanComponent<"a">
|
|
94
|
+
& JSX.Component<"a">;
|
|
45
95
|
|
|
46
96
|
// helpers.mjs
|
|
47
97
|
/**
|
|
@@ -51,7 +101,10 @@ export const A: (
|
|
|
51
101
|
* @param href the URL to navigate to
|
|
52
102
|
* @param options when true, will replace the current history entry
|
|
53
103
|
*/
|
|
54
|
-
export const navigate: (
|
|
104
|
+
export const navigate: (
|
|
105
|
+
href: string,
|
|
106
|
+
options?: { replace?: boolean },
|
|
107
|
+
) => void;
|
|
55
108
|
|
|
56
109
|
/**
|
|
57
110
|
* A client only helper function that reloads the current page.
|
|
@@ -66,8 +119,6 @@ export const reload: () => void;
|
|
|
66
119
|
*/
|
|
67
120
|
export const redirect: (href?: string) => void | (() => void);
|
|
68
121
|
|
|
69
|
-
export type VanComponent = () => VanNode | VanNode[];
|
|
70
|
-
|
|
71
122
|
// routes.mjs
|
|
72
123
|
export type RouteEntry = {
|
|
73
124
|
path: string;
|
|
@@ -103,7 +154,7 @@ export const Route: (route: RouteProps) => void;
|
|
|
103
154
|
export type RouterState = {
|
|
104
155
|
pathname: string;
|
|
105
156
|
searchParams: URLSearchParams;
|
|
106
|
-
params
|
|
157
|
+
params: Record<string, string>;
|
|
107
158
|
};
|
|
108
159
|
/**
|
|
109
160
|
* A reactive object that holds the current router state.
|
|
@@ -131,26 +182,39 @@ export const setRouterState: (
|
|
|
131
182
|
* Merge the children of an Element or an array of elements with an optional array of children
|
|
132
183
|
* into the childen of a single HTMLFragmentElement element.
|
|
133
184
|
* @param source
|
|
134
|
-
* @param children
|
|
185
|
+
* @param {...VanNode[]} children
|
|
135
186
|
*/
|
|
136
187
|
export const unwrap: (
|
|
137
|
-
source:
|
|
188
|
+
source:
|
|
189
|
+
| VanNode
|
|
190
|
+
| IsoTagFunc
|
|
191
|
+
| VanNode[]
|
|
192
|
+
| IsoTagFunc[]
|
|
193
|
+
| (() => IsoTagFunc | IsoTagFunc[] | VanNode | VanNode[]),
|
|
138
194
|
...children: VanNode[]
|
|
139
195
|
) => VanNode;
|
|
140
196
|
|
|
141
197
|
export type ComponentModule = {
|
|
142
|
-
component: VanComponent;
|
|
198
|
+
component: VanComponent | JSX.Element;
|
|
143
199
|
route: Pick<RouteEntry, "load" | "preload">;
|
|
144
200
|
};
|
|
145
201
|
|
|
146
202
|
export type DynamicModule = {
|
|
147
|
-
Page: VanComponent;
|
|
148
|
-
default?: VanComponent;
|
|
203
|
+
Page: VanComponent | JSX.Element;
|
|
204
|
+
default?: VanComponent | JSX.Element;
|
|
149
205
|
route?: Pick<RouteEntry, "load" | "preload">;
|
|
150
206
|
};
|
|
151
207
|
|
|
152
|
-
export type LazyComponent =
|
|
153
|
-
| Promise<DynamicModule>
|
|
154
|
-
| (() => Promise<DynamicModule>);
|
|
208
|
+
export type LazyComponent = Promise<DynamicModule>;
|
|
155
209
|
|
|
210
|
+
/**
|
|
211
|
+
* Registers a lazy component.
|
|
212
|
+
* @param importFn
|
|
213
|
+
*/
|
|
156
214
|
export const lazy: (importFn: () => LazyComponent) => () => ComponentModule;
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Fixes the URL of a route.
|
|
218
|
+
* @param url
|
|
219
|
+
*/
|
|
220
|
+
export const fixRouteUrl: (url: string) => string;
|
package/server/global.d.ts
CHANGED
package/server/index.mjs
CHANGED
|
@@ -43,10 +43,10 @@ export const renderToString = async (inputSource) => {
|
|
|
43
43
|
* @returns {string}
|
|
44
44
|
*/
|
|
45
45
|
function renderPreloadLink(file) {
|
|
46
|
-
if (file.endsWith(".js")
|
|
47
|
-
return `<link rel="
|
|
46
|
+
if (file.endsWith(".js")) {
|
|
47
|
+
return `<link rel="preload" href="${file}" as="script" crossorigin>`;
|
|
48
48
|
} else if (file.endsWith(".css")) {
|
|
49
|
-
return `<link rel="
|
|
49
|
+
return `<link rel="preload" href="${file}" as="style" crossorigin>`;
|
|
50
50
|
} else if (file.endsWith(".woff")) {
|
|
51
51
|
return ` <link rel="preload" href="${file}" as="font" type="font/woff" crossorigin>`;
|
|
52
52
|
} else if (file.endsWith(".woff2")) {
|
package/server/types.d.ts
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { dummyVanX, registerEnv } from "mini-van-plate/shared";
|
|
2
|
+
import vanPlate from "mini-van-plate/van-plate";
|
|
3
|
+
import vanCore from "vanjs-core/debug";
|
|
4
|
+
import * as vanX from "vanjs-ext";
|
|
5
|
+
|
|
6
|
+
const vanXObject = { ...vanX, default: vanX };
|
|
7
|
+
const dummyObject = { ...dummyVanX, default: dummyVanX };
|
|
8
|
+
|
|
9
|
+
const setup = {
|
|
10
|
+
isServer: typeof window === "undefined",
|
|
11
|
+
get van() {
|
|
12
|
+
return this.isServer ? vanPlate : vanCore;
|
|
13
|
+
},
|
|
14
|
+
get vanX() {
|
|
15
|
+
return this.isServer ? dummyObject : vanXObject;
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
registerEnv(setup);
|
|
20
|
+
|
|
21
|
+
export default setup;
|
package/src/index.mjs
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { fileURLToPath } from "node:url";
|
|
2
2
|
import { dirname, resolve } from "node:path";
|
|
3
|
+
import process from "node:process";
|
|
3
4
|
|
|
4
5
|
const __filename = fileURLToPath(import.meta.url);
|
|
5
6
|
const __dirname = dirname(__filename);
|
|
7
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
6
8
|
|
|
7
9
|
export default function VitePluginVanJS() {
|
|
8
10
|
return {
|
|
@@ -10,16 +12,30 @@ export default function VitePluginVanJS() {
|
|
|
10
12
|
enforce: "pre",
|
|
11
13
|
config() {
|
|
12
14
|
return {
|
|
15
|
+
ssr: {
|
|
16
|
+
noExternal: ["vanjs-*", "*-vanjs", "@vanjs/*"],
|
|
17
|
+
},
|
|
13
18
|
resolve: {
|
|
14
19
|
alias: {
|
|
15
|
-
"@vanjs/setup": resolve(
|
|
16
|
-
|
|
20
|
+
"@vanjs/setup": resolve(
|
|
21
|
+
__dirname,
|
|
22
|
+
isProduction
|
|
23
|
+
? /* istanbul ignore next */ "../setup/index"
|
|
24
|
+
: "../setup/index-debug",
|
|
25
|
+
),
|
|
26
|
+
"@vanjs/van": resolve(
|
|
27
|
+
__dirname,
|
|
28
|
+
isProduction
|
|
29
|
+
? /* istanbul ignore next */ "../setup/van"
|
|
30
|
+
: "../setup/van-debug",
|
|
31
|
+
),
|
|
17
32
|
"@vanjs/vanX": resolve(__dirname, "../setup/vanX"),
|
|
18
33
|
"@vanjs/client": resolve(__dirname, "../client"),
|
|
19
34
|
"@vanjs/server": resolve(__dirname, "../server"),
|
|
20
35
|
"@vanjs/meta": resolve(__dirname, "../meta"),
|
|
21
36
|
"@vanjs/router": resolve(__dirname, "../router"),
|
|
22
37
|
"@vanjs/jsx": resolve(__dirname, "../jsx"),
|
|
38
|
+
"@vanjs/parser": resolve(__dirname, "../parser"),
|
|
23
39
|
},
|
|
24
40
|
},
|
|
25
41
|
esbuild: {
|
package/src/types.d.ts
CHANGED
|
@@ -4,11 +4,11 @@ export * from "../router/types";
|
|
|
4
4
|
export * from "../meta/types";
|
|
5
5
|
export * from "../server/types";
|
|
6
6
|
export * from "../client/types";
|
|
7
|
+
export * from "../parser/types";
|
|
7
8
|
|
|
8
9
|
declare const VitePluginVanJS: () => {
|
|
9
10
|
name: "string";
|
|
10
11
|
enforce: "pre" | "post" | undefined;
|
|
11
|
-
apply: "build";
|
|
12
12
|
config(): {
|
|
13
13
|
resolve: {
|
|
14
14
|
alias: Record<string, string>;
|