@revojs/vue 0.1.9 → 0.1.11
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.ts +2 -1
- package/dist/client/index.js +7 -2
- package/dist/{dist-DM3hv3cX.js → dist-iR83EkEu.js} +20 -1
- package/dist/index.js +1 -1
- package/dist/module/app.ts +2 -0
- package/dist/module/main.vue +0 -1
- package/dist/module/routes/[...]/index.get.ts +10 -1
- package/package.json +1 -1
package/dist/client/index.d.ts
CHANGED
|
@@ -18,5 +18,6 @@ declare function useFetch<T, TError = Error>(scope: Scope, input: string | URL,
|
|
|
18
18
|
isLoading: Ref<boolean, boolean>;
|
|
19
19
|
execute: (options?: AsyncOptions<TError> | undefined) => Promise<T | undefined>;
|
|
20
20
|
};
|
|
21
|
+
declare function navigate(scope: Scope, path: string): void;
|
|
21
22
|
//#endregion
|
|
22
|
-
export { AsyncOptions, useAsync, useFetch, useScope, useState };
|
|
23
|
+
export { AsyncOptions, navigate, useAsync, useFetch, useScope, useState };
|
package/dist/client/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { $fetch, getState, setState } from "../dist-
|
|
1
|
+
import { $fetch, getState, sendRedirect, setState } from "../dist-iR83EkEu.js";
|
|
2
2
|
import { inject, onServerPrefetch, ref, watch } from "vue";
|
|
3
|
+
import { useRouter } from "vue-router";
|
|
3
4
|
|
|
4
5
|
//#region src/client/index.ts
|
|
5
6
|
function useScope() {
|
|
@@ -38,6 +39,10 @@ function useAsync(scope, name, invoke, defaultOptions) {
|
|
|
38
39
|
function useFetch(scope, input, options) {
|
|
39
40
|
return useAsync(scope, input.toString(), () => $fetch(scope, input, options), options);
|
|
40
41
|
}
|
|
42
|
+
function navigate(scope, path) {
|
|
43
|
+
if (import.meta.server) throw sendRedirect(scope, path);
|
|
44
|
+
else useRouter().push(path);
|
|
45
|
+
}
|
|
41
46
|
|
|
42
47
|
//#endregion
|
|
43
|
-
export { useAsync, useFetch, useScope, useState };
|
|
48
|
+
export { navigate, useAsync, useFetch, useScope, useState };
|
|
@@ -26,6 +26,12 @@ function setState(scope, name, value) {
|
|
|
26
26
|
STATES[name] = value;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
+
function sendRedirect(scope, path, config) {
|
|
30
|
+
const { response } = useServer(scope);
|
|
31
|
+
response.status = 302;
|
|
32
|
+
response.headers.set("Location", path);
|
|
33
|
+
return new Response(null, mergeObjects(response, config));
|
|
34
|
+
}
|
|
29
35
|
const ROUTER_CONTEXT = defineContext("ROUTER_CONTEXT");
|
|
30
36
|
const SERVER_CONTEXT = defineContext("SERVER_CONTEXT");
|
|
31
37
|
let STATES;
|
|
@@ -64,6 +70,19 @@ var Scope = class extends EventTarget {
|
|
|
64
70
|
function defineContext(name) {
|
|
65
71
|
return name;
|
|
66
72
|
}
|
|
73
|
+
function mergeObjects(base, input) {
|
|
74
|
+
if (input === null || input === void 0) return mergeObjects(base, {});
|
|
75
|
+
const object = Object.assign({}, input);
|
|
76
|
+
for (const key in base) {
|
|
77
|
+
if (key === "__proto__" || key === "constructor") continue;
|
|
78
|
+
const value = base[key];
|
|
79
|
+
if (value === null || value === void 0) continue;
|
|
80
|
+
if (Array.isArray(value) && Array.isArray(object[key])) object[key] = [...value, ...object[key]];
|
|
81
|
+
else if (typeof value === "object" && typeof object[key] === "object") object[key] = mergeObjects(value, object[key]);
|
|
82
|
+
else object[key] = value;
|
|
83
|
+
}
|
|
84
|
+
return object;
|
|
85
|
+
}
|
|
67
86
|
async function $fetch(scope, input, options) {
|
|
68
87
|
let response;
|
|
69
88
|
if (import.meta.server) {
|
|
@@ -86,4 +105,4 @@ async function $fetch(scope, input, options) {
|
|
|
86
105
|
}
|
|
87
106
|
|
|
88
107
|
//#endregion
|
|
89
|
-
export { $fetch, getState, setState };
|
|
108
|
+
export { $fetch, getState, sendRedirect, setState };
|
package/dist/index.js
CHANGED
package/dist/module/app.ts
CHANGED
package/dist/module/main.vue
CHANGED
|
@@ -7,13 +7,22 @@ export default defineRoute({
|
|
|
7
7
|
async fetch(scope) {
|
|
8
8
|
const { states } = useServer(scope);
|
|
9
9
|
|
|
10
|
+
const app = await createApp(scope);
|
|
11
|
+
|
|
12
|
+
let exception;
|
|
13
|
+
app.config.errorHandler = (value) => (exception = value);
|
|
14
|
+
|
|
10
15
|
const content = client
|
|
11
|
-
.replace("<!-- MAIN -->", await renderToString(
|
|
16
|
+
.replace("<!-- MAIN -->", await renderToString(app))
|
|
12
17
|
.replace(
|
|
13
18
|
"<!-- STATES -->",
|
|
14
19
|
"<script id='STATES' type='application/json'>" + JSON.stringify(states) + "</script>"
|
|
15
20
|
);
|
|
16
21
|
|
|
22
|
+
if (exception) {
|
|
23
|
+
throw exception;
|
|
24
|
+
}
|
|
25
|
+
|
|
17
26
|
return sendHtml(scope, content);
|
|
18
27
|
},
|
|
19
28
|
});
|