@revojs/vue 0.1.48 → 0.1.49
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/client/{index.d.mts → index.d.ts} +1 -1
- package/dist/{index.mjs → index.js} +4 -4
- package/dist/runtime/app.d.ts +7 -0
- package/dist/runtime/app.js +56 -0
- package/dist/runtime/entry.d.ts +1 -0
- package/dist/{module/entry.ts → runtime/entry.js} +3 -2
- package/dist/runtime/routes/[...]/get.d.ts +8 -0
- package/dist/runtime/routes/[...]/get.js +21 -0
- package/package.json +12 -15
- package/dist/module/app.ts +0 -97
- package/dist/module/routes/[...]/get.ts +0 -35
- /package/dist/client/{index.mjs → index.js} +0 -0
- /package/dist/{index.d.mts → index.d.ts} +0 -0
- /package/dist/{module → runtime}/main.vue +0 -0
- /package/{src → dist/runtime}/types/index.d.ts +0 -0
- /package/{src → dist/runtime}/types/pages.d.ts +0 -0
|
@@ -20,7 +20,7 @@ declare function useFetch<T, TError = Error>(scope: Scope, input: MaybeRefOrGett
|
|
|
20
20
|
refresh: (options?: AsyncOptions<TError> | undefined) => Promise<T | undefined>;
|
|
21
21
|
}>;
|
|
22
22
|
declare function refreshAsync(scope: Scope, input?: string | Array<string>): Promise<void[] | undefined>;
|
|
23
|
-
declare const isServerSideRendering:
|
|
23
|
+
declare const isServerSideRendering: any;
|
|
24
24
|
declare const REFRESH_ASYNC_HOOK: _$revojs.Descriptor<(names?: Array<string>) => Promise<void>>;
|
|
25
25
|
//#endregion
|
|
26
26
|
export { AsyncOptions, REFRESH_ASYNC_HOOK, isServerSideRendering, refreshAsync, useAsync, useFetch, useScope, useState };
|
|
@@ -10,7 +10,7 @@ function vue(options) {
|
|
|
10
10
|
app.config.template.head.children.push({
|
|
11
11
|
tagName: "script",
|
|
12
12
|
attributes: { type: "module" },
|
|
13
|
-
children: [`import "${fromModule("./
|
|
13
|
+
children: [`import "${fromModule("./runtime/entry.js")}"`]
|
|
14
14
|
}, {
|
|
15
15
|
tagName: "script",
|
|
16
16
|
attributes: {
|
|
@@ -24,7 +24,7 @@ function vue(options) {
|
|
|
24
24
|
attributes: { id: "app" },
|
|
25
25
|
children: ["<!-- APP -->"]
|
|
26
26
|
});
|
|
27
|
-
addRoutes(app, fromModule("./
|
|
27
|
+
addRoutes(app, fromModule("./runtime/routes"));
|
|
28
28
|
addTypes(app, "revojs-vue", () => `import "@revojs/vue/types"`);
|
|
29
29
|
return {
|
|
30
30
|
variables: { SERVER_SIDE_RENDERING: options?.serverSideRendering ?? true },
|
|
@@ -35,8 +35,8 @@ function vue(options) {
|
|
|
35
35
|
vite: {
|
|
36
36
|
plugins: [vueCompiler(options?.compilerOption)],
|
|
37
37
|
resolve: { alias: {
|
|
38
|
-
"#vue/app": fromModule("./
|
|
39
|
-
"#vue/main": fromModule("./
|
|
38
|
+
"#vue/app": fromModule("./runtime/app.js"),
|
|
39
|
+
"#vue/main": fromModule("./runtime/main.vue")
|
|
40
40
|
} }
|
|
41
41
|
}
|
|
42
42
|
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Radix, isServer, useUrl } from "revojs";
|
|
2
|
+
import { createApp, createSSRApp } from "vue";
|
|
3
|
+
import pages from "#pages";
|
|
4
|
+
import Main from "#vue/main";
|
|
5
|
+
import { RouterView, createMemoryHistory, createRouter, createWebHistory } from "vue-router";
|
|
6
|
+
import { isServerSideRendering } from "../client";
|
|
7
|
+
//#region src/runtime/app.ts
|
|
8
|
+
function toRoute(path, node, index) {
|
|
9
|
+
const layout = node.children["layout"];
|
|
10
|
+
if (layout) delete node.children["layout"];
|
|
11
|
+
const children = Object.entries(node.children).map(([path, node]) => toRoute(path, node, index + 1));
|
|
12
|
+
if (node.value && (children.length || layout)) children.push({
|
|
13
|
+
path: "",
|
|
14
|
+
component: node.value
|
|
15
|
+
});
|
|
16
|
+
if (node.type === "WILDCARD") path = ":" + node.parameter + "(.*)*";
|
|
17
|
+
if (node.type === "OPTIONAL-WILDCARD") path = ":" + node.parameter + "(.*)?";
|
|
18
|
+
if (node.type === "OPTIONAL-PARAMETER") path = ":" + node.parameter + "?";
|
|
19
|
+
if (node.type === "PARAMETER") path = ":" + node.parameter;
|
|
20
|
+
return {
|
|
21
|
+
path,
|
|
22
|
+
children,
|
|
23
|
+
component: children.length ? layout?.value ?? RouterView : node.value ?? RouterView
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
var app_default = async (scope) => {
|
|
27
|
+
const radix = new Radix();
|
|
28
|
+
for (const path in pages) {
|
|
29
|
+
const segments = path.split("/");
|
|
30
|
+
for (const attribute of segments.pop()?.split(".") ?? []) {
|
|
31
|
+
if (attribute === "page" || attribute === "vue") continue;
|
|
32
|
+
segments.push(attribute);
|
|
33
|
+
}
|
|
34
|
+
radix.use(segments, pages[path]);
|
|
35
|
+
}
|
|
36
|
+
const rootNode = toRoute("/", radix.rootNode, 0);
|
|
37
|
+
const optionalNode = rootNode.children?.find((route) => route.path.includes("?"));
|
|
38
|
+
if (optionalNode) rootNode.children?.push({
|
|
39
|
+
...optionalNode,
|
|
40
|
+
path: ""
|
|
41
|
+
});
|
|
42
|
+
const router = createRouter({
|
|
43
|
+
history: isServer ? createMemoryHistory() : createWebHistory(),
|
|
44
|
+
routes: [rootNode]
|
|
45
|
+
});
|
|
46
|
+
const app = (isServerSideRendering ? createSSRApp(Main) : createApp(Main)).use(router).provide("REVOJS_SCOPE", scope);
|
|
47
|
+
app.config.throwUnhandledErrorInProduction = true;
|
|
48
|
+
if (isServer) {
|
|
49
|
+
const { pathname } = useUrl(scope);
|
|
50
|
+
await router.push(pathname);
|
|
51
|
+
}
|
|
52
|
+
await router.isReady();
|
|
53
|
+
return app;
|
|
54
|
+
};
|
|
55
|
+
//#endregion
|
|
56
|
+
export { app_default as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineRoute, sendOk, useServer } from "revojs";
|
|
2
|
+
import { isServerSideRendering } from "../../../client";
|
|
3
|
+
import createApp from "#vue/app";
|
|
4
|
+
import client from "#client";
|
|
5
|
+
import { renderToString } from "vue/server-renderer";
|
|
6
|
+
//#region src/runtime/routes/[...]/get.ts
|
|
7
|
+
var get_default = defineRoute({ async fetch(scope) {
|
|
8
|
+
const { states } = useServer(scope);
|
|
9
|
+
let content = client;
|
|
10
|
+
if (isServerSideRendering) {
|
|
11
|
+
const app = await createApp(scope);
|
|
12
|
+
let exception;
|
|
13
|
+
app.config.errorHandler = (value) => exception = value;
|
|
14
|
+
content = content.replace("<!-- APP -->", await renderToString(app));
|
|
15
|
+
if (exception) throw exception;
|
|
16
|
+
}
|
|
17
|
+
const value = JSON.stringify(states).replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
18
|
+
return sendOk(scope, content.replace(`<!-- STATES -->`, value));
|
|
19
|
+
} });
|
|
20
|
+
//#endregion
|
|
21
|
+
export { get_default as default };
|
package/package.json
CHANGED
|
@@ -1,32 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revojs/vue",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.49",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": "tellua/revojs",
|
|
6
6
|
"files": [
|
|
7
|
-
"dist"
|
|
8
|
-
"src/types"
|
|
7
|
+
"dist"
|
|
9
8
|
],
|
|
10
9
|
"type": "module",
|
|
11
|
-
"main": "./dist/index.
|
|
12
|
-
"module": "./dist/index.
|
|
13
|
-
"types": "./dist/index.d.
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"module": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
14
13
|
"exports": {
|
|
15
14
|
".": {
|
|
16
|
-
"types": "./dist/index.d.
|
|
17
|
-
"import": "./dist/index.
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
18
17
|
},
|
|
19
18
|
"./client": {
|
|
20
|
-
"types": "./dist/client/index.d.
|
|
21
|
-
"import": "./dist/client/index.
|
|
19
|
+
"types": "./dist/client/index.d.ts",
|
|
20
|
+
"import": "./dist/client/index.js"
|
|
22
21
|
},
|
|
23
22
|
"./types": {
|
|
24
|
-
"types": "./
|
|
23
|
+
"types": "./dist/runtime/types/index.d.ts"
|
|
25
24
|
}
|
|
26
25
|
},
|
|
27
26
|
"scripts": {
|
|
28
|
-
"build": "
|
|
29
|
-
"watch": "tsdown -w"
|
|
27
|
+
"build": "revojs module build"
|
|
30
28
|
},
|
|
31
29
|
"dependencies": {
|
|
32
30
|
"@vitejs/plugin-vue": "^6.0.5",
|
|
@@ -35,7 +33,6 @@
|
|
|
35
33
|
"vue-router": "^5.0.4"
|
|
36
34
|
},
|
|
37
35
|
"devDependencies": {
|
|
38
|
-
"@revojs/tsconfig": "*"
|
|
39
|
-
"tsdown": "^0.21.7"
|
|
36
|
+
"@revojs/tsconfig": "*"
|
|
40
37
|
}
|
|
41
38
|
}
|
package/dist/module/app.ts
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import pages from "#pages";
|
|
2
|
-
import Main from "#vue/main";
|
|
3
|
-
import { isServer, Radix, Scope, useUrl, type Node } from "revojs";
|
|
4
|
-
import { createApp, createSSRApp, type Component } from "vue";
|
|
5
|
-
import {
|
|
6
|
-
createMemoryHistory,
|
|
7
|
-
createRouter,
|
|
8
|
-
createWebHistory,
|
|
9
|
-
RouteRecordSingleView,
|
|
10
|
-
RouterView,
|
|
11
|
-
type RouteRecordRaw,
|
|
12
|
-
} from "vue-router";
|
|
13
|
-
import { isServerSideRendering } from "../client";
|
|
14
|
-
|
|
15
|
-
function toRoute(path: string, node: Node<Component>, index: number): RouteRecordRaw {
|
|
16
|
-
const layout = node.children["layout"];
|
|
17
|
-
|
|
18
|
-
if (layout) {
|
|
19
|
-
delete node.children["layout"];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const children = Object.entries(node.children).map(([path, node]) => toRoute(path, node, index + 1));
|
|
23
|
-
|
|
24
|
-
if (node.value && (children.length || layout)) {
|
|
25
|
-
children.push({ path: "", component: node.value });
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (node.type === "WILDCARD") {
|
|
29
|
-
path = ":" + node.parameter + "(.*)*";
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (node.type === "OPTIONAL-WILDCARD") {
|
|
33
|
-
path = ":" + node.parameter + "(.*)?";
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (node.type === "OPTIONAL-PARAMETER") {
|
|
37
|
-
path = ":" + node.parameter + "?";
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (node.type === "PARAMETER") {
|
|
41
|
-
path = ":" + node.parameter;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const route = {
|
|
45
|
-
path,
|
|
46
|
-
children,
|
|
47
|
-
component: children.length ? (layout?.value ?? RouterView) : (node.value ?? RouterView),
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
return route;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export default async (scope: Scope) => {
|
|
54
|
-
const radix = new Radix<Component>();
|
|
55
|
-
|
|
56
|
-
for (const path in pages) {
|
|
57
|
-
const segments = path.split("/");
|
|
58
|
-
|
|
59
|
-
for (const attribute of segments.pop()?.split(".") ?? []) {
|
|
60
|
-
if (attribute === "page" || attribute === "vue") {
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
segments.push(attribute);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
radix.use(segments, pages[path]);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const rootNode = toRoute("/", radix.rootNode, 0);
|
|
71
|
-
|
|
72
|
-
const optionalNode = rootNode.children?.find((route) => route.path.includes("?")) as RouteRecordSingleView;
|
|
73
|
-
if (optionalNode) {
|
|
74
|
-
rootNode.children?.push({ ...optionalNode, path: "" });
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const router = createRouter({
|
|
78
|
-
history: isServer ? createMemoryHistory() : createWebHistory(),
|
|
79
|
-
routes: [rootNode],
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
const app = (isServerSideRendering ? createSSRApp(Main) : createApp(Main))
|
|
83
|
-
.use(router)
|
|
84
|
-
.provide("REVOJS_SCOPE", scope);
|
|
85
|
-
|
|
86
|
-
app.config.throwUnhandledErrorInProduction = true;
|
|
87
|
-
|
|
88
|
-
if (isServer) {
|
|
89
|
-
const { pathname } = useUrl(scope);
|
|
90
|
-
|
|
91
|
-
await router.push(pathname);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
await router.isReady();
|
|
95
|
-
|
|
96
|
-
return app;
|
|
97
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import client from "#client";
|
|
2
|
-
import createApp from "#vue/app";
|
|
3
|
-
import { defineRoute, sendOk, useServer } from "revojs";
|
|
4
|
-
import { renderToString } from "vue/server-renderer";
|
|
5
|
-
import { isServerSideRendering } from "../../../client";
|
|
6
|
-
|
|
7
|
-
export default defineRoute({
|
|
8
|
-
async fetch(scope) {
|
|
9
|
-
const { states } = useServer(scope);
|
|
10
|
-
|
|
11
|
-
let content = client;
|
|
12
|
-
|
|
13
|
-
if (isServerSideRendering) {
|
|
14
|
-
const app = await createApp(scope);
|
|
15
|
-
|
|
16
|
-
let exception;
|
|
17
|
-
app.config.errorHandler = (value) => (exception = value);
|
|
18
|
-
|
|
19
|
-
content = content.replace("<!-- APP -->", await renderToString(app));
|
|
20
|
-
|
|
21
|
-
if (exception) {
|
|
22
|
-
throw exception;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const value = JSON.stringify(states)
|
|
27
|
-
.replace(/</g, "\\u003c")
|
|
28
|
-
.replace(/>/g, "\\u003e")
|
|
29
|
-
.replace(/&/g, "\\u0026")
|
|
30
|
-
.replace(/\u2028/g, "\\u2028")
|
|
31
|
-
.replace(/\u2029/g, "\\u2029");
|
|
32
|
-
|
|
33
|
-
return sendOk(scope, content.replace(`<!-- STATES -->`, value));
|
|
34
|
-
},
|
|
35
|
-
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|