revojs 0.0.78 → 0.0.80
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/html/index.d.ts +1 -1
- package/dist/http/index.d.ts +3 -0
- package/dist/index.js +20 -5
- package/dist/router/index.d.ts +4 -0
- package/dist/runtime/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/html/index.d.ts
CHANGED
|
@@ -88,7 +88,7 @@ export declare function useEvent<T extends keyof ElementEventMap>(scope: Scope,
|
|
|
88
88
|
export declare function useEvent<T extends keyof WindowEventMap>(scope: Scope, target: Window | undefined | null, event: T, input: EventListener<WindowEventMap[T]>, options?: AddEventListenerOptions): void;
|
|
89
89
|
export declare function useEvent<T extends keyof HTMLElementEventMap>(scope: Scope, target: Document | HTMLElement | undefined | null, event: T, input: EventListener<HTMLElementEventMap[T]>, options?: AddEventListenerOptions): void;
|
|
90
90
|
export declare function onMounted(scope: Scope, event: EventListener<MountedEvent>): void;
|
|
91
|
-
export declare function startViewTransition(invoke: ViewTransitionUpdateCallback):
|
|
91
|
+
export declare function startViewTransition(invoke: ViewTransitionUpdateCallback): Promise<void>;
|
|
92
92
|
export declare function isClient(): boolean;
|
|
93
93
|
export declare function isServer(): boolean;
|
|
94
94
|
export declare function preventDefault(event: Event): void;
|
package/dist/http/index.d.ts
CHANGED
|
@@ -29,6 +29,9 @@ export declare function sendRedirect(scope: Scope, path: string): Response;
|
|
|
29
29
|
export declare function sendBadRequest(scope: Scope, text: string): Response;
|
|
30
30
|
export declare function sendUnauthorized(scope: Scope): Response;
|
|
31
31
|
export declare function useUrl(scope: Scope, base?: string): URL;
|
|
32
|
+
export declare function useQuery(scope: Scope): {
|
|
33
|
+
[k: string]: string;
|
|
34
|
+
};
|
|
32
35
|
export declare function useCookies(scope: Scope): Record<string, string>;
|
|
33
36
|
export declare function useSetCookies(scope: Scope): Record<string, string>;
|
|
34
37
|
export declare function setCookie(scope: Scope, name: string, value: string, options?: CookieOptions): void;
|
package/dist/index.js
CHANGED
|
@@ -146,6 +146,10 @@ function useUrl(scope, base) {
|
|
|
146
146
|
const { request } = useRuntime(scope);
|
|
147
147
|
return new URL(request?.url ?? window?.location.href, base);
|
|
148
148
|
}
|
|
149
|
+
function useQuery(scope) {
|
|
150
|
+
const { searchParams } = useUrl(scope);
|
|
151
|
+
return Object.fromEntries(searchParams);
|
|
152
|
+
}
|
|
149
153
|
function useCookies(scope) {
|
|
150
154
|
const { request } = useRuntime(scope);
|
|
151
155
|
return (isClient() ? document.cookie : request.headers.get("Cookie") ?? "").split("; ").reduce((result, cookie) => {
|
|
@@ -434,12 +438,17 @@ async function $fetch(scope, input, options) {
|
|
|
434
438
|
function useAsync(scope, invoke, options) {
|
|
435
439
|
const { tasks } = useRuntime(scope);
|
|
436
440
|
const state = createState();
|
|
437
|
-
const isLoading = createState(
|
|
441
|
+
const isLoading = createState(false);
|
|
438
442
|
const execute = async () => {
|
|
443
|
+
isLoading.value = true;
|
|
439
444
|
try {
|
|
440
|
-
|
|
445
|
+
const result = await invoke();
|
|
446
|
+
if (options?.viewTransition) await startViewTransition(() => state.value = result);
|
|
447
|
+
else state.value = result;
|
|
441
448
|
} catch (error) {
|
|
442
449
|
options?.catch?.(error);
|
|
450
|
+
} finally {
|
|
451
|
+
isLoading.value = false;
|
|
443
452
|
}
|
|
444
453
|
return state.value;
|
|
445
454
|
};
|
|
@@ -791,7 +800,7 @@ function onMounted(scope, event) {
|
|
|
791
800
|
useEvent(scope, host, "mounted", event);
|
|
792
801
|
}
|
|
793
802
|
}
|
|
794
|
-
function startViewTransition(invoke) {
|
|
803
|
+
async function startViewTransition(invoke) {
|
|
795
804
|
if (isClient() && document.startViewTransition !== void 0) return document.startViewTransition(invoke).updateCallbackDone;
|
|
796
805
|
return invoke();
|
|
797
806
|
}
|
|
@@ -825,6 +834,11 @@ var AfterNavigateEvent = class extends Event {
|
|
|
825
834
|
super("afterNavigate");
|
|
826
835
|
}
|
|
827
836
|
};
|
|
837
|
+
var AfterNavigateTransitionEvent = class extends Event {
|
|
838
|
+
constructor() {
|
|
839
|
+
super("afterNavigateTransition");
|
|
840
|
+
}
|
|
841
|
+
};
|
|
828
842
|
function provideRouterContext(scope, options) {
|
|
829
843
|
const url = createState();
|
|
830
844
|
const route = createState();
|
|
@@ -859,7 +873,8 @@ function provideRouterContext(scope, options) {
|
|
|
859
873
|
route
|
|
860
874
|
});
|
|
861
875
|
fetch$1();
|
|
862
|
-
useEvent(scope, navigator, "navigate", () => startViewTransition(fetch$1));
|
|
876
|
+
useEvent(scope, navigator, "navigate", () => startViewTransition(fetch$1).finally(() => navigator.dispatchEvent(new AfterNavigateTransitionEvent())));
|
|
877
|
+
if (isClient()) requestAnimationFrame(() => navigator.dispatchEvent(new AfterNavigateTransitionEvent()));
|
|
863
878
|
return useRouter(scope);
|
|
864
879
|
}
|
|
865
880
|
function useRouter(scope, context) {
|
|
@@ -936,4 +951,4 @@ function useLocale(scope, context) {
|
|
|
936
951
|
const LOCALE_CONTEXT = defineContext("LOCALE_CONTEXT");
|
|
937
952
|
|
|
938
953
|
//#endregion
|
|
939
|
-
export { $fetch, AfterNavigateEvent, CLIENT, Compute, HOST_CONTEXT, Handler, LOCALE_CONTEXT, MountedEvent, NavigateEvent, Page, ROUTER_CONTEXT, ROUTE_CONTEXT, RUNTIME_CONTEXT, Radix, SERVER, Scope, StopEvent, activeCompute, components, createApp, createCompute, createElement, createMemo, createRuntime, createState, defineComponent, defineContext, defineMiddleware, defineRoute, fileName, fromValue, hydrate, isClient, isComponent, isCustomElement, isRoute, isServer, isTemplate, mergeObjects, mimeType, onMounted, preventDefault, provideLocaleContext, provideRouterContext, registerComponent, renderToString, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, startViewTransition, stopImmediatePropagation, stopPropagation, targets, toArray, toCustomElement, toFragment, toPath, toRange, toString, untrack, useAsync, useCookies, useEvent, useFetch, useHost, useLocale, useRoute, useRouter, useRuntime, useSetCookies, useUrl };
|
|
954
|
+
export { $fetch, AfterNavigateEvent, AfterNavigateTransitionEvent, CLIENT, Compute, HOST_CONTEXT, Handler, LOCALE_CONTEXT, MountedEvent, NavigateEvent, Page, ROUTER_CONTEXT, ROUTE_CONTEXT, RUNTIME_CONTEXT, Radix, SERVER, Scope, StopEvent, activeCompute, components, createApp, createCompute, createElement, createMemo, createRuntime, createState, defineComponent, defineContext, defineMiddleware, defineRoute, fileName, fromValue, hydrate, isClient, isComponent, isCustomElement, isRoute, isServer, isTemplate, mergeObjects, mimeType, onMounted, preventDefault, provideLocaleContext, provideRouterContext, registerComponent, renderToString, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, startViewTransition, stopImmediatePropagation, stopPropagation, targets, toArray, toCustomElement, toFragment, toPath, toRange, toString, untrack, useAsync, useCookies, useEvent, useFetch, useHost, useLocale, useQuery, useRoute, useRouter, useRuntime, useSetCookies, useUrl };
|
package/dist/router/index.d.ts
CHANGED
|
@@ -17,6 +17,9 @@ export declare class NavigateEvent extends Event {
|
|
|
17
17
|
export declare class AfterNavigateEvent extends Event {
|
|
18
18
|
constructor();
|
|
19
19
|
}
|
|
20
|
+
export declare class AfterNavigateTransitionEvent extends Event {
|
|
21
|
+
constructor();
|
|
22
|
+
}
|
|
20
23
|
export declare function provideRouterContext(scope: Scope, options: RouterOptions): {
|
|
21
24
|
url: State<URL | undefined>;
|
|
22
25
|
route: State<unknown>;
|
|
@@ -41,5 +44,6 @@ declare global {
|
|
|
41
44
|
interface ElementEventMap {
|
|
42
45
|
navigate: NavigateEvent;
|
|
43
46
|
afterNavigate: AfterNavigateEvent;
|
|
47
|
+
afterNavigateTransition: AfterNavigateTransitionEvent;
|
|
44
48
|
}
|
|
45
49
|
}
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export type RouteContext = {
|
|
|
22
22
|
inputs: State<Record<string, string>>;
|
|
23
23
|
};
|
|
24
24
|
export type AsyncOptions = {
|
|
25
|
+
viewTransition?: boolean;
|
|
25
26
|
catch?: (error: unknown) => void | Promise<void>;
|
|
26
27
|
};
|
|
27
28
|
export declare function isRoute<T>(value?: T): value is Route & T;
|