@revojs/vue 0.1.50 → 0.1.52
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 +4 -2
- package/dist/client/index.js +6 -2
- package/dist/runtime/app.js +5 -1
- package/dist/runtime/main.vue +19 -6
- package/dist/runtime/routes/[...]/get.js +3 -4
- package/dist/runtime/types/index.d.ts +25 -0
- package/dist/runtime/types/pages.d.ts +7 -0
- package/package.json +2 -2
package/dist/client/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ interface AsyncOptions<T> {
|
|
|
7
7
|
catch?: (error: T) => void | Promise<void>;
|
|
8
8
|
}
|
|
9
9
|
declare function useScope(): Scope;
|
|
10
|
+
declare function useError(scope?: Scope): ShallowRef<Error>;
|
|
10
11
|
declare function useRouter(): {
|
|
11
12
|
context: ShallowRef<RouterContext<Component>>;
|
|
12
13
|
navigate: (path: string) => void;
|
|
@@ -26,8 +27,9 @@ declare function useFetch<T, TError = Error>(input: MaybeRefOrGetter<string>, op
|
|
|
26
27
|
}>;
|
|
27
28
|
declare function refreshAsync(input?: string | Array<string>): Promise<void[] | undefined>;
|
|
28
29
|
declare const isServerSideRendering: any;
|
|
29
|
-
declare const REFRESH_ASYNC_HOOK: _$revojs.Descriptor<(names?: Array<string>) => Promise<void>>;
|
|
30
30
|
declare const NAVIGATE_HOOK: _$revojs.Descriptor<_$revojs.Invoke>;
|
|
31
|
+
declare const REFRESH_ASYNC_HOOK: _$revojs.Descriptor<(names?: Array<string>) => Promise<void>>;
|
|
32
|
+
declare const CLIENT_ERROR_CONTEXT: _$revojs.Descriptor<ShallowRef<Error>>;
|
|
31
33
|
declare const CLIENT_ROUTER_CONTEXT: _$revojs.Descriptor<ShallowRef<RouterContext<Component>>>;
|
|
32
34
|
//#endregion
|
|
33
|
-
export { AsyncOptions, CLIENT_ROUTER_CONTEXT, NAVIGATE_HOOK, REFRESH_ASYNC_HOOK, isServerSideRendering, refreshAsync, useAsync, useFetch, useRouter, useScope, useState };
|
|
35
|
+
export { AsyncOptions, CLIENT_ERROR_CONTEXT, CLIENT_ROUTER_CONTEXT, NAVIGATE_HOOK, REFRESH_ASYNC_HOOK, isServerSideRendering, refreshAsync, useAsync, useError, useFetch, useRouter, useScope, useState };
|
package/dist/client/index.js
CHANGED
|
@@ -6,6 +6,9 @@ function useScope() {
|
|
|
6
6
|
if (scope) return scope;
|
|
7
7
|
throw new Error();
|
|
8
8
|
}
|
|
9
|
+
function useError(scope = useScope()) {
|
|
10
|
+
return scope.getContext(CLIENT_ERROR_CONTEXT);
|
|
11
|
+
}
|
|
9
12
|
function useRouter() {
|
|
10
13
|
const scope = useScope();
|
|
11
14
|
const context = scope.getContext(CLIENT_ROUTER_CONTEXT);
|
|
@@ -84,8 +87,9 @@ async function refreshAsync(input) {
|
|
|
84
87
|
if (isClient) return await scope.dispatchHook(REFRESH_ASYNC_HOOK, input === void 0 ? void 0 : Array.isArray(input) ? input : [input]);
|
|
85
88
|
}
|
|
86
89
|
const isServerSideRendering = import.meta.SERVER_SIDE_RENDERING ?? globalThis?.import?.meta?.SERVER_SIDE_RENDERING;
|
|
87
|
-
const REFRESH_ASYNC_HOOK = defineHook("REFRESH_ASYNC_HOOK");
|
|
88
90
|
const NAVIGATE_HOOK = defineHook("NAVIGATE_HOOK");
|
|
91
|
+
const REFRESH_ASYNC_HOOK = defineHook("REFRESH_ASYNC_HOOK");
|
|
92
|
+
const CLIENT_ERROR_CONTEXT = defineContext("CLIENT_ERROR_CONTEXT");
|
|
89
93
|
const CLIENT_ROUTER_CONTEXT = defineContext("CLIENT_ROUTER_CONTEXT");
|
|
90
94
|
//#endregion
|
|
91
|
-
export { CLIENT_ROUTER_CONTEXT, NAVIGATE_HOOK, REFRESH_ASYNC_HOOK, isServerSideRendering, refreshAsync, useAsync, useFetch, useRouter, useScope, useState };
|
|
95
|
+
export { CLIENT_ERROR_CONTEXT, CLIENT_ROUTER_CONTEXT, NAVIGATE_HOOK, REFRESH_ASYNC_HOOK, isServerSideRendering, refreshAsync, useAsync, useError, useFetch, useRouter, useScope, useState };
|
package/dist/runtime/app.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import Main from "#vue/main";
|
|
2
|
-
import { createApp, createSSRApp } from "vue";
|
|
2
|
+
import { createApp, createSSRApp, warn } from "vue";
|
|
3
3
|
import { isServerSideRendering } from "../client";
|
|
4
4
|
//#region src/runtime/app.ts
|
|
5
5
|
var app_default = async (scope) => {
|
|
6
6
|
const app = (isServerSideRendering ? createSSRApp(Main) : createApp(Main)).provide("REVOJS_SCOPE", scope);
|
|
7
|
+
app.config.warnHandler = (message, instance, trace) => {
|
|
8
|
+
if (message.includes("Invalid vnode type when creating vnode") || message.includes("Component <Anonymous> is missing template or render function")) return;
|
|
9
|
+
warn(message, instance, trace);
|
|
10
|
+
};
|
|
7
11
|
app.config.throwUnhandledErrorInProduction = true;
|
|
8
12
|
return app;
|
|
9
13
|
};
|
package/dist/runtime/main.vue
CHANGED
|
@@ -7,11 +7,12 @@
|
|
|
7
7
|
<script setup lang="ts">
|
|
8
8
|
import pages from "#pages";
|
|
9
9
|
import { isClient, Router, RouterContext, useUrl } from "revojs";
|
|
10
|
-
import { computed, h, onScopeDispose, shallowRef, type Component } from "vue";
|
|
11
|
-
import { CLIENT_ROUTER_CONTEXT, NAVIGATE_HOOK, useScope } from "../client";
|
|
10
|
+
import { computed, h, onErrorCaptured, onScopeDispose, shallowRef, type Component } from "vue";
|
|
11
|
+
import { CLIENT_ERROR_CONTEXT, CLIENT_ROUTER_CONTEXT, NAVIGATE_HOOK, useScope } from "../client";
|
|
12
12
|
|
|
13
13
|
const scope = useScope();
|
|
14
14
|
|
|
15
|
+
const error = shallowRef<Error>();
|
|
15
16
|
const context = shallowRef<RouterContext<Component>>();
|
|
16
17
|
|
|
17
18
|
const router = new Router<Component>();
|
|
@@ -27,14 +28,21 @@ for (const path in pages) {
|
|
|
27
28
|
segments.push(attribute);
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
for (const page of pages[path]) {
|
|
32
|
+
router.use(segments, page);
|
|
33
|
+
}
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
const route = computed(() => {
|
|
34
|
-
if (context.value?.route
|
|
37
|
+
if (context.value?.route) {
|
|
38
|
+
const route = h(context.value.route);
|
|
39
|
+
|
|
35
40
|
return context.value.hooks.reduceRight(
|
|
36
|
-
(previous, hook) =>
|
|
37
|
-
|
|
41
|
+
(previous, hook) =>
|
|
42
|
+
h(hook, null, {
|
|
43
|
+
default: () => (error.value === undefined ? previous : undefined),
|
|
44
|
+
}),
|
|
45
|
+
route,
|
|
38
46
|
);
|
|
39
47
|
}
|
|
40
48
|
});
|
|
@@ -54,5 +62,10 @@ if (isClient) {
|
|
|
54
62
|
|
|
55
63
|
fetch();
|
|
56
64
|
|
|
65
|
+
scope.setContext(CLIENT_ERROR_CONTEXT, error);
|
|
57
66
|
scope.setContext(CLIENT_ROUTER_CONTEXT, context);
|
|
67
|
+
|
|
68
|
+
onErrorCaptured((value) => {
|
|
69
|
+
error.value ??= value;
|
|
70
|
+
});
|
|
58
71
|
</script>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isServerSideRendering } from "../../../client";
|
|
1
|
+
import { isServerSideRendering, useError } from "../../../client";
|
|
2
2
|
import createApp from "#vue/app";
|
|
3
3
|
import { defineRoute, sendOk, useServer } from "revojs";
|
|
4
4
|
import client from "#client";
|
|
@@ -9,10 +9,9 @@ var get_default = defineRoute({ async fetch(scope) {
|
|
|
9
9
|
let content = client;
|
|
10
10
|
if (isServerSideRendering) {
|
|
11
11
|
const app = await createApp(scope);
|
|
12
|
-
let exception;
|
|
13
|
-
app.config.errorHandler = (value) => exception = value;
|
|
14
12
|
content = content.replace("<!-- APP -->", await renderToString(app));
|
|
15
|
-
|
|
13
|
+
const error = useError(scope);
|
|
14
|
+
if (error.value) throw error.value;
|
|
16
15
|
}
|
|
17
16
|
const value = JSON.stringify(states).replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
18
17
|
return sendOk(scope, content.replace(`<!-- STATES -->`, value));
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
declare module "#vue/app" {
|
|
2
|
+
import type { Scope } from "revojs";
|
|
3
|
+
import type { App } from "vue";
|
|
4
|
+
|
|
5
|
+
export default function createApp(scope: Scope): Promise<App>;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
declare module "#vue/main" {
|
|
9
|
+
import type { Component } from "vue";
|
|
10
|
+
|
|
11
|
+
const main: Component;
|
|
12
|
+
|
|
13
|
+
export default app;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare module "*.vue" {
|
|
17
|
+
import type { DefineComponent } from "vue";
|
|
18
|
+
|
|
19
|
+
const component: DefineComponent<Record<string, never>, Record<string, never>, any>;
|
|
20
|
+
export default component;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface ImportMeta {
|
|
24
|
+
readonly SERVER_SIDE_RENDERING: boolean;
|
|
25
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revojs/vue",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.52",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": "tellua/revojs",
|
|
6
6
|
"files": [
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"build": "revojs module build"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@vitejs/plugin-vue": "^6.0.
|
|
30
|
+
"@vitejs/plugin-vue": "^6.0.6",
|
|
31
31
|
"revojs": "*",
|
|
32
32
|
"vue": "^3.5.32"
|
|
33
33
|
},
|