@revojs/vue 0.1.49 → 0.1.50
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 +15 -8
- package/dist/client/index.js +34 -8
- package/dist/index.js +3 -2
- package/dist/runtime/app.d.ts +1 -1
- package/dist/runtime/app.js +2 -47
- package/dist/runtime/entry.js +1 -1
- package/dist/runtime/main.vue +51 -2
- package/dist/runtime/routes/[...]/get.js +1 -1
- package/package.json +2 -3
- package/dist/runtime/types/index.d.ts +0 -25
- package/dist/runtime/types/pages.d.ts +0 -7
package/dist/client/index.d.ts
CHANGED
|
@@ -1,26 +1,33 @@
|
|
|
1
|
+
import { Component, MaybeRefOrGetter, Ref, ShallowRef } from "vue";
|
|
1
2
|
import * as _$revojs from "revojs";
|
|
2
|
-
import { Scope } from "revojs";
|
|
3
|
-
import { MaybeRefOrGetter, Ref } from "vue";
|
|
3
|
+
import { RouterContext, Scope } from "revojs";
|
|
4
4
|
|
|
5
5
|
//#region src/client/index.d.ts
|
|
6
6
|
interface AsyncOptions<T> {
|
|
7
7
|
catch?: (error: T) => void | Promise<void>;
|
|
8
8
|
}
|
|
9
9
|
declare function useScope(): Scope;
|
|
10
|
-
declare function
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
declare function useRouter(): {
|
|
11
|
+
context: ShallowRef<RouterContext<Component>>;
|
|
12
|
+
navigate: (path: string) => void;
|
|
13
|
+
anchorNavigate: (event: Event) => void;
|
|
14
|
+
};
|
|
15
|
+
declare function useState<T>(name: MaybeRefOrGetter<string>): Ref<T | undefined>;
|
|
16
|
+
declare function useState<T>(name: MaybeRefOrGetter<string>, value: T): Ref<T>;
|
|
17
|
+
declare function useAsync<T, TError = Error>(name: MaybeRefOrGetter<string>, invoke: () => Promise<T>, defaultOptions?: AsyncOptions<TError>): Promise<{
|
|
13
18
|
state: Ref<T | undefined, T | undefined>;
|
|
14
19
|
isLoading: Ref<boolean, boolean>;
|
|
15
20
|
refresh: (options?: AsyncOptions<TError>) => Promise<T | undefined>;
|
|
16
21
|
}>;
|
|
17
|
-
declare function useFetch<T, TError = Error>(
|
|
22
|
+
declare function useFetch<T, TError = Error>(input: MaybeRefOrGetter<string>, options?: RequestInit & AsyncOptions<TError>): Promise<{
|
|
18
23
|
state: Ref<T | undefined, T | undefined>;
|
|
19
24
|
isLoading: Ref<boolean, boolean>;
|
|
20
25
|
refresh: (options?: AsyncOptions<TError> | undefined) => Promise<T | undefined>;
|
|
21
26
|
}>;
|
|
22
|
-
declare function refreshAsync(
|
|
27
|
+
declare function refreshAsync(input?: string | Array<string>): Promise<void[] | undefined>;
|
|
23
28
|
declare const isServerSideRendering: any;
|
|
24
29
|
declare const REFRESH_ASYNC_HOOK: _$revojs.Descriptor<(names?: Array<string>) => Promise<void>>;
|
|
30
|
+
declare const NAVIGATE_HOOK: _$revojs.Descriptor<_$revojs.Invoke>;
|
|
31
|
+
declare const CLIENT_ROUTER_CONTEXT: _$revojs.Descriptor<ShallowRef<RouterContext<Component>>>;
|
|
25
32
|
//#endregion
|
|
26
|
-
export { AsyncOptions, REFRESH_ASYNC_HOOK, isServerSideRendering, refreshAsync, useAsync, useFetch, useScope, useState };
|
|
33
|
+
export { AsyncOptions, CLIENT_ROUTER_CONTEXT, NAVIGATE_HOOK, REFRESH_ASYNC_HOOK, isServerSideRendering, refreshAsync, useAsync, useFetch, useRouter, useScope, useState };
|
package/dist/client/index.js
CHANGED
|
@@ -1,12 +1,33 @@
|
|
|
1
|
-
import { $fetch, defineHook, getState, isClient, isServer, setState } from "revojs";
|
|
2
1
|
import { customRef, inject, isRef, onScopeDispose, ref, toValue, watch } from "vue";
|
|
2
|
+
import { defineContext, defineHook, fetch, getState, isClient, isServer, sendRedirect, setState } from "revojs";
|
|
3
3
|
//#region src/client/index.ts
|
|
4
4
|
function useScope() {
|
|
5
5
|
const scope = inject("REVOJS_SCOPE");
|
|
6
6
|
if (scope) return scope;
|
|
7
7
|
throw new Error();
|
|
8
8
|
}
|
|
9
|
-
function
|
|
9
|
+
function useRouter() {
|
|
10
|
+
const scope = useScope();
|
|
11
|
+
const context = scope.getContext(CLIENT_ROUTER_CONTEXT);
|
|
12
|
+
const navigate = (path) => {
|
|
13
|
+
if (isClient) {
|
|
14
|
+
if (window.location.pathname != path) window.history.pushState(window.history.state, "", path);
|
|
15
|
+
scope.dispatchHook(NAVIGATE_HOOK);
|
|
16
|
+
}
|
|
17
|
+
if (isServer) throw sendRedirect(scope, path);
|
|
18
|
+
};
|
|
19
|
+
const anchorNavigate = (event) => {
|
|
20
|
+
event.preventDefault();
|
|
21
|
+
navigate(event.currentTarget?.getAttribute("href") ?? "/");
|
|
22
|
+
};
|
|
23
|
+
return {
|
|
24
|
+
context,
|
|
25
|
+
navigate,
|
|
26
|
+
anchorNavigate
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function useState(name, value) {
|
|
30
|
+
const scope = useScope();
|
|
10
31
|
return customRef((track, trigger) => ({
|
|
11
32
|
get() {
|
|
12
33
|
track();
|
|
@@ -18,8 +39,9 @@ function useState(scope, name, value) {
|
|
|
18
39
|
}
|
|
19
40
|
}));
|
|
20
41
|
}
|
|
21
|
-
async function useAsync(
|
|
22
|
-
const
|
|
42
|
+
async function useAsync(name, invoke, defaultOptions) {
|
|
43
|
+
const scope = useScope();
|
|
44
|
+
const state = useState(name);
|
|
23
45
|
const isLoading = ref(false);
|
|
24
46
|
const refresh = async (options) => {
|
|
25
47
|
const onCatch = options?.catch ?? defaultOptions?.catch;
|
|
@@ -45,8 +67,9 @@ async function useAsync(scope, name, invoke, defaultOptions) {
|
|
|
45
67
|
refresh
|
|
46
68
|
};
|
|
47
69
|
}
|
|
48
|
-
async function useFetch(
|
|
49
|
-
const
|
|
70
|
+
async function useFetch(input, options) {
|
|
71
|
+
const scope = useScope();
|
|
72
|
+
const { state, isLoading, refresh } = await useAsync(input, () => fetch(scope, toValue(input), options), options);
|
|
50
73
|
if (isClient && (isRef(input) || typeof input === "function")) watch(input, async (next, previous) => {
|
|
51
74
|
if (next !== previous) await refresh();
|
|
52
75
|
});
|
|
@@ -56,10 +79,13 @@ async function useFetch(scope, input, options) {
|
|
|
56
79
|
refresh
|
|
57
80
|
};
|
|
58
81
|
}
|
|
59
|
-
async function refreshAsync(
|
|
82
|
+
async function refreshAsync(input) {
|
|
83
|
+
const scope = useScope();
|
|
60
84
|
if (isClient) return await scope.dispatchHook(REFRESH_ASYNC_HOOK, input === void 0 ? void 0 : Array.isArray(input) ? input : [input]);
|
|
61
85
|
}
|
|
62
86
|
const isServerSideRendering = import.meta.SERVER_SIDE_RENDERING ?? globalThis?.import?.meta?.SERVER_SIDE_RENDERING;
|
|
63
87
|
const REFRESH_ASYNC_HOOK = defineHook("REFRESH_ASYNC_HOOK");
|
|
88
|
+
const NAVIGATE_HOOK = defineHook("NAVIGATE_HOOK");
|
|
89
|
+
const CLIENT_ROUTER_CONTEXT = defineContext("CLIENT_ROUTER_CONTEXT");
|
|
64
90
|
//#endregion
|
|
65
|
-
export { REFRESH_ASYNC_HOOK, isServerSideRendering, refreshAsync, useAsync, useFetch, useScope, useState };
|
|
91
|
+
export { CLIENT_ROUTER_CONTEXT, NAVIGATE_HOOK, REFRESH_ASYNC_HOOK, isServerSideRendering, refreshAsync, useAsync, useFetch, useRouter, useScope, useState };
|
package/dist/index.js
CHANGED
|
@@ -29,7 +29,7 @@ function vue(options) {
|
|
|
29
29
|
return {
|
|
30
30
|
variables: { SERVER_SIDE_RENDERING: options?.serverSideRendering ?? true },
|
|
31
31
|
sources: { pages: {
|
|
32
|
-
match: "**/
|
|
32
|
+
match: ["**/page.vue", "**/+layout.vue"],
|
|
33
33
|
entries: ["./routes"]
|
|
34
34
|
} },
|
|
35
35
|
vite: {
|
|
@@ -37,7 +37,8 @@ function vue(options) {
|
|
|
37
37
|
resolve: { alias: {
|
|
38
38
|
"#vue/app": fromModule("./runtime/app.js"),
|
|
39
39
|
"#vue/main": fromModule("./runtime/main.vue")
|
|
40
|
-
} }
|
|
40
|
+
} },
|
|
41
|
+
optimizeDeps: { exclude: ["vue"] }
|
|
41
42
|
}
|
|
42
43
|
};
|
|
43
44
|
} };
|
package/dist/runtime/app.d.ts
CHANGED
package/dist/runtime/app.js
CHANGED
|
@@ -1,55 +1,10 @@
|
|
|
1
|
-
import { Radix, isServer, useUrl } from "revojs";
|
|
2
|
-
import { createApp, createSSRApp } from "vue";
|
|
3
|
-
import pages from "#pages";
|
|
4
1
|
import Main from "#vue/main";
|
|
5
|
-
import {
|
|
2
|
+
import { createApp, createSSRApp } from "vue";
|
|
6
3
|
import { isServerSideRendering } from "../client";
|
|
7
4
|
//#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
5
|
var app_default = async (scope) => {
|
|
27
|
-
const
|
|
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);
|
|
6
|
+
const app = (isServerSideRendering ? createSSRApp(Main) : createApp(Main)).provide("REVOJS_SCOPE", scope);
|
|
47
7
|
app.config.throwUnhandledErrorInProduction = true;
|
|
48
|
-
if (isServer) {
|
|
49
|
-
const { pathname } = useUrl(scope);
|
|
50
|
-
await router.push(pathname);
|
|
51
|
-
}
|
|
52
|
-
await router.isReady();
|
|
53
8
|
return app;
|
|
54
9
|
};
|
|
55
10
|
//#endregion
|
package/dist/runtime/entry.js
CHANGED
package/dist/runtime/main.vue
CHANGED
|
@@ -1,9 +1,58 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<Suspense>
|
|
3
|
-
<
|
|
3
|
+
<component :is="route" v-if="route" />
|
|
4
4
|
</Suspense>
|
|
5
5
|
</template>
|
|
6
6
|
|
|
7
7
|
<script setup lang="ts">
|
|
8
|
-
import
|
|
8
|
+
import pages from "#pages";
|
|
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";
|
|
12
|
+
|
|
13
|
+
const scope = useScope();
|
|
14
|
+
|
|
15
|
+
const context = shallowRef<RouterContext<Component>>();
|
|
16
|
+
|
|
17
|
+
const router = new Router<Component>();
|
|
18
|
+
|
|
19
|
+
for (const path in pages) {
|
|
20
|
+
const segments = path.split("/");
|
|
21
|
+
|
|
22
|
+
for (const attribute of segments.pop()?.split(".") ?? []) {
|
|
23
|
+
if (attribute === "page" || attribute === "vue") {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
segments.push(attribute);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
router.use(segments, pages[path]);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const route = computed(() => {
|
|
34
|
+
if (context.value?.route.value) {
|
|
35
|
+
return context.value.hooks.reduceRight(
|
|
36
|
+
(previous, hook) => h(hook, null, { default: () => previous }),
|
|
37
|
+
h(context.value.route.value),
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const fetch = () => {
|
|
43
|
+
const next = useUrl(scope);
|
|
44
|
+
|
|
45
|
+
context.value = router.match(next.pathname.slice(1).split("/"));
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
scope.registerHook(NAVIGATE_HOOK, fetch);
|
|
49
|
+
|
|
50
|
+
if (isClient) {
|
|
51
|
+
window.addEventListener("popstate", fetch);
|
|
52
|
+
onScopeDispose(() => window.removeEventListener("popstate", fetch));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
fetch();
|
|
56
|
+
|
|
57
|
+
scope.setContext(CLIENT_ROUTER_CONTEXT, context);
|
|
9
58
|
</script>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { defineRoute, sendOk, useServer } from "revojs";
|
|
2
1
|
import { isServerSideRendering } from "../../../client";
|
|
3
2
|
import createApp from "#vue/app";
|
|
3
|
+
import { defineRoute, sendOk, useServer } from "revojs";
|
|
4
4
|
import client from "#client";
|
|
5
5
|
import { renderToString } from "vue/server-renderer";
|
|
6
6
|
//#region src/runtime/routes/[...]/get.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revojs/vue",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.50",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": "tellua/revojs",
|
|
6
6
|
"files": [
|
|
@@ -29,8 +29,7 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@vitejs/plugin-vue": "^6.0.5",
|
|
31
31
|
"revojs": "*",
|
|
32
|
-
"vue": "^3.5.
|
|
33
|
-
"vue-router": "^5.0.4"
|
|
32
|
+
"vue": "^3.5.32"
|
|
34
33
|
},
|
|
35
34
|
"devDependencies": {
|
|
36
35
|
"@revojs/tsconfig": "*"
|
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
}
|