@revojs/vue 0.1.22 → 0.1.24
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/index.js +10 -7
- package/dist/module/app.ts +32 -10
- package/dist/module/entry.ts +4 -0
- package/dist/module/routes/[...]/index.get.ts +4 -4
- package/package.json +1 -1
- package/dist/module/index.html +0 -18
package/dist/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { addRoutes, useKit } from "revojs/kit";
|
|
2
|
-
import "revojs";
|
|
1
|
+
import { addAlias, addRoutes, useKit } from "revojs/kit";
|
|
3
2
|
|
|
4
3
|
//#region src/index.ts
|
|
5
4
|
function addPages(app, path) {
|
|
@@ -12,11 +11,15 @@ function vue() {
|
|
|
12
11
|
entries: ["./routes"]
|
|
13
12
|
} } },
|
|
14
13
|
setup(app) {
|
|
15
|
-
const {
|
|
16
|
-
app.config.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
const { fromModule } = useKit(import.meta.url);
|
|
15
|
+
app.config.template.head.children.push({
|
|
16
|
+
tagName: "script",
|
|
17
|
+
attributes: { type: "module" },
|
|
18
|
+
children: [`import "${fromModule("./module/entry.ts")}"`]
|
|
19
|
+
});
|
|
20
|
+
addRoutes(app, fromModule("./module/routes"));
|
|
21
|
+
addAlias(app, "vue/app", fromModule("./module/app.ts"));
|
|
22
|
+
addAlias(app, "vue/main", fromModule("./module/main.vue"));
|
|
20
23
|
}
|
|
21
24
|
};
|
|
22
25
|
}
|
package/dist/module/app.ts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import { isServer, Radix, Scope, toRoutePath, useUrl, type Node } from "revojs";
|
|
2
|
-
import { type Component, createSSRApp } from "vue";
|
|
3
|
-
import { createMemoryHistory, createRouter, createWebHistory, RouterView, type RouteRecordRaw } from "vue-router";
|
|
4
1
|
import Main from "#alias/vue/main";
|
|
5
2
|
import pages from "#virtual/pages";
|
|
3
|
+
import { isServer, Radix, Scope, useUrl, type Node } from "revojs";
|
|
4
|
+
import { createSSRApp, type Component } from "vue";
|
|
5
|
+
import {
|
|
6
|
+
createMemoryHistory,
|
|
7
|
+
createRouter,
|
|
8
|
+
createWebHistory,
|
|
9
|
+
RouteRecordSingleView,
|
|
10
|
+
RouterView,
|
|
11
|
+
type RouteRecordRaw,
|
|
12
|
+
} from "vue-router";
|
|
6
13
|
|
|
7
14
|
function toRoute(path: string, node: Node<Component>, index: number): RouteRecordRaw {
|
|
8
15
|
const layout = node.children["+layout"];
|
|
@@ -17,8 +24,12 @@ function toRoute(path: string, node: Node<Component>, index: number): RouteRecor
|
|
|
17
24
|
children.push({ path: "", component: node.value });
|
|
18
25
|
}
|
|
19
26
|
|
|
27
|
+
if (node.type === "OPTIONAL-PARAMETER") {
|
|
28
|
+
path = ":" + node.parameter + "?";
|
|
29
|
+
}
|
|
30
|
+
|
|
20
31
|
if (node.type === "PARAMETER") {
|
|
21
|
-
path
|
|
32
|
+
path = ":" + node.parameter;
|
|
22
33
|
}
|
|
23
34
|
|
|
24
35
|
const route = {
|
|
@@ -33,19 +44,30 @@ function toRoute(path: string, node: Node<Component>, index: number): RouteRecor
|
|
|
33
44
|
export default async (scope: Scope) => {
|
|
34
45
|
const radix = new Radix<Component>();
|
|
35
46
|
|
|
36
|
-
for (const
|
|
37
|
-
const
|
|
47
|
+
for (const path in pages) {
|
|
48
|
+
const segments = path.toLowerCase().split("/");
|
|
38
49
|
|
|
39
|
-
|
|
40
|
-
|
|
50
|
+
for (const attribute of segments.pop()?.split(".") ?? []) {
|
|
51
|
+
if (attribute === "index" || attribute === "vue") {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
41
54
|
|
|
42
|
-
|
|
55
|
+
segments.push(attribute);
|
|
43
56
|
}
|
|
57
|
+
|
|
58
|
+
radix.use(segments, pages[path]);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const rootNode = toRoute("/", radix.rootNode, 0);
|
|
62
|
+
|
|
63
|
+
const optionalNode = rootNode.children?.find((route) => route.path.includes("?")) as RouteRecordSingleView;
|
|
64
|
+
if (optionalNode) {
|
|
65
|
+
rootNode.children?.push({ ...optionalNode, path: "" });
|
|
44
66
|
}
|
|
45
67
|
|
|
46
68
|
const router = createRouter({
|
|
47
69
|
history: isServer ? createMemoryHistory() : createWebHistory(),
|
|
48
|
-
routes: [
|
|
70
|
+
routes: [rootNode],
|
|
49
71
|
});
|
|
50
72
|
|
|
51
73
|
const app = createSSRApp(Main).use(router).provide("REVOJS_SCOPE", scope);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { defineRoute, sendHtml, useServer } from "revojs";
|
|
2
|
-
import { renderToString } from "vue/server-renderer";
|
|
3
1
|
import createApp from "#alias/vue/app";
|
|
4
2
|
import client from "#virtual/client";
|
|
3
|
+
import { defineRoute, sendHtml, useServer } from "revojs";
|
|
4
|
+
import { renderToString } from "vue/server-renderer";
|
|
5
5
|
|
|
6
6
|
export default defineRoute({
|
|
7
7
|
async fetch(scope) {
|
|
@@ -13,9 +13,9 @@ export default defineRoute({
|
|
|
13
13
|
app.config.errorHandler = (value) => (exception = value);
|
|
14
14
|
|
|
15
15
|
const content = client
|
|
16
|
-
.replace("<!--
|
|
16
|
+
.replace("<!-- BODY -->", await renderToString(app))
|
|
17
17
|
.replace(
|
|
18
|
-
"<!--
|
|
18
|
+
"<!-- HEAD -->",
|
|
19
19
|
"<script id='STATES' type='application/json'>" + JSON.stringify(states) + "</script>"
|
|
20
20
|
);
|
|
21
21
|
|
package/package.json
CHANGED
package/dist/module/index.html
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8" />
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
-
<title>Vue</title>
|
|
7
|
-
<!-- STATES -->
|
|
8
|
-
</head>
|
|
9
|
-
<body>
|
|
10
|
-
<div id="app"><!-- MAIN --></div>
|
|
11
|
-
<script type="module">
|
|
12
|
-
import { Scope } from "revojs";
|
|
13
|
-
import createApp from "#alias/vue/app";
|
|
14
|
-
|
|
15
|
-
await createApp(new Scope()).then((app) => app.mount("#app"));
|
|
16
|
-
</script>
|
|
17
|
-
</body>
|
|
18
|
-
</html>
|