revojs 0.0.72 → 0.0.74

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.
@@ -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): Promise<void>;
91
+ export declare function startViewTransition(invoke: ViewTransitionUpdateCallback): void | 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/index.js CHANGED
@@ -859,8 +859,9 @@ function useRouter(scope, context) {
859
859
  const navigate = (path) => {
860
860
  if (isClient()) {
861
861
  if (window.location.pathname != path) window.history.pushState(window.history.state, "", path);
862
+ return navigator.dispatchEvent(new NavigateEvent());
862
863
  }
863
- navigator.dispatchEvent(new NavigateEvent());
864
+ throw sendRedirect(scope, path);
864
865
  };
865
866
  const anchorNavigate = (event) => {
866
867
  event.preventDefault();
@@ -887,18 +888,14 @@ const ROUTER_CONTEXT = defineContext("ROUTER_CONTEXT");
887
888
  //#region src/locale/index.ts
888
889
  function provideLocaleContext(scope, options) {
889
890
  const { inputs } = useRoute(scope);
890
- const { navigator } = useRouter(scope);
891
+ const { navigator, navigate } = useRouter(scope);
891
892
  const locale = createState(options.defaultLocale);
892
893
  const messages = createState();
893
894
  const fetch$1 = () => {
894
- if (options.input) {
895
- const input = inputs.value[options.input];
896
- if (input && input in options.locales) locale.value = input;
897
- }
898
- if (locale.value) {
899
- const target = options.locales[locale.value];
900
- messages.value = target;
901
- }
895
+ const input = inputs.value[options.input];
896
+ if (input && input in options.locales) locale.value = input;
897
+ else navigate(`/${options.defaultLocale}`);
898
+ if (locale.value) messages.value = options.locales[locale.value];
902
899
  };
903
900
  fetch$1();
904
901
  useEvent(scope, navigator, "afterNavigate", fetch$1);
@@ -1,8 +1,8 @@
1
1
  import { type Descriptor, Scope, type State } from "../signals";
2
2
  export type LocaleOptions = {
3
3
  locales: Record<string, Record<string, string>>;
4
- defaultLocale?: string;
5
- input?: string;
4
+ defaultLocale: string;
5
+ input: string;
6
6
  };
7
7
  export type LocaleContext = {
8
8
  locale: State<string | undefined>;
@@ -21,14 +21,14 @@ export declare function provideRouterContext(scope: Scope, options: RouterOption
21
21
  url: State<URL | undefined>;
22
22
  route: State<unknown>;
23
23
  navigator: EventTarget;
24
- navigate: (path: string) => void;
24
+ navigate: (path: string) => boolean;
25
25
  anchorNavigate: (event: Event) => void;
26
26
  };
27
27
  export declare function useRouter<T extends RouterContext>(scope: Scope, context?: Descriptor<T>): {
28
28
  url: State<URL | undefined>;
29
29
  route: State<unknown>;
30
30
  navigator: EventTarget;
31
- navigate: (path: string) => void;
31
+ navigate: (path: string) => boolean;
32
32
  anchorNavigate: (event: Event) => void;
33
33
  };
34
34
  export declare const Page: import("..").ComponentConstructor<import("..").Events, import("..").Attributes>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "revojs",
3
- "version": "0.0.72",
3
+ "version": "0.0.74",
4
4
  "type": "module",
5
5
  "repository": "coverbase/revojs",
6
6
  "license": "MIT",