revojs 0.0.54 → 0.0.56

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/index.js CHANGED
@@ -163,7 +163,7 @@ var Handler = class Handler {
163
163
  }
164
164
  const value = Reflect.get(target, key);
165
165
  if (value) {
166
- if (typeof value === "function") return value.bind(target);
166
+ if (typeof value === "function" && !value.prototype) return value.bind(target);
167
167
  if (typeof value === "object") return new Proxy(value, new Handler());
168
168
  }
169
169
  return value;
@@ -386,10 +386,10 @@ const defineComponent = (options) => {
386
386
  const toCustomElement = (Component) => {
387
387
  return class extends HTMLElement {
388
388
  static formAssociated = true;
389
- component;
390
- internals;
391
- constructor() {
392
- super();
389
+ component = new Component();
390
+ internals = this.attachInternals();
391
+ async connectedCallback() {
392
+ let rootNode = this;
393
393
  const findParent = (node) => {
394
394
  if (node) {
395
395
  if ("component" in node) return node;
@@ -397,11 +397,8 @@ const toCustomElement = (Component) => {
397
397
  return findParent(node.parentNode);
398
398
  }
399
399
  };
400
- this.component = new Component(void 0, findParent(this.parentNode)?.component.scope);
401
- this.internals = this.attachInternals();
402
- }
403
- async connectedCallback() {
404
- let rootNode = this;
400
+ const parentNode = findParent(this.parentNode);
401
+ if (parentNode) this.component.scope.parentScope = parentNode.component.scope;
405
402
  if (this.component.shadowRoot) rootNode = this.shadowRoot ?? this.attachShadow(this.component.shadowRoot);
406
403
  for (const [name, event] of Object.entries(Component.$events)) Reflect.set(this.component.events, name, (value) => {
407
404
  if (value instanceof Event) return;
@@ -752,15 +749,15 @@ const createRouter = (options) => {
752
749
  }
753
750
  const registerRouterContext = async (scope) => {
754
751
  const fetch$1 = async () => {
752
+ const { inputs } = useRoute(scope);
755
753
  const { request } = useRuntime(scope);
756
754
  url.value = new URL(request?.url ?? window?.location.href);
757
755
  const match = radix.match(url.value.pathname);
758
- scope.setContext(ROUTE_CONTEXT, { inputs: createState(match.inputs) });
759
- const Page$1 = await match.value?.();
760
- if (Page$1) route.value = /* @__PURE__ */ h(Page$1, null);
756
+ inputs.value = match.inputs;
757
+ route.value = await match.value?.();
761
758
  };
762
759
  if (isClient()) useEvent(scope, window, "popstate", () => navigator.dispatchEvent(new NavigateEvent()));
763
- await fetch$1().then(() => useEvent(scope, navigator, "navigate", fetch$1));
760
+ scope.setContext(ROUTE_CONTEXT, { inputs: createState() });
764
761
  scope.setContext(ROUTER_CONTEXT, {
765
762
  options,
766
763
  navigator,
@@ -768,6 +765,7 @@ const createRouter = (options) => {
768
765
  radix,
769
766
  route
770
767
  });
768
+ await fetch$1().then(() => useEvent(scope, navigator, "navigate", fetch$1));
771
769
  return useRouter(scope);
772
770
  };
773
771
  return {
@@ -799,7 +797,10 @@ const Page = defineComponent({
799
797
  name: "x-page",
800
798
  setup: ({ scope }) => {
801
799
  const { route } = useRouter(scope);
802
- return () => route.value;
800
+ return () => {
801
+ const Page$1 = route.value;
802
+ if (Page$1) return /* @__PURE__ */ h(Page$1, null);
803
+ };
803
804
  }
804
805
  });
805
806
 
@@ -840,13 +841,9 @@ const useLocale = (scope, context) => {
840
841
  const $ = (key) => {
841
842
  return () => messages.value?.[key] ?? key;
842
843
  };
843
- const prefix = (input) => {
844
- return () => `/${locale.value}` + (input ?? "");
845
- };
846
844
  return {
847
845
  locale,
848
846
  messages,
849
- prefix,
850
847
  $
851
848
  };
852
849
  };
@@ -16,13 +16,11 @@ export declare const createLocale: <T extends LocaleOptions>(options: T) => {
16
16
  registerLocaleContext: (scope: Scope) => Promise<{
17
17
  locale: State<string | undefined>;
18
18
  messages: State<Record<string, string> | undefined>;
19
- prefix: (input?: string) => () => string;
20
19
  $: (key: never) => () => string | number | symbol;
21
20
  }>;
22
21
  };
23
22
  export declare const useLocale: <T extends LocaleContext>(scope: Scope, context?: Descriptor<T>) => {
24
23
  locale: State<string | undefined>;
25
24
  messages: State<Record<string, string> | undefined>;
26
- prefix: (input?: string) => () => string;
27
25
  $: (key: keyof T["options"]["locales"][keyof T["options"]["locales"]]) => () => string | number | symbol;
28
26
  };
@@ -1,4 +1,4 @@
1
- import { type Attributes, type ComponentConstructor, type Events, type Slot } from "../html";
1
+ import { type Attributes, type ComponentConstructor, type Events } from "../html";
2
2
  import { Radix } from "../radix";
3
3
  import { type Descriptor, Scope, type State } from "../signals";
4
4
  export type Routes = Record<string, () => Promise<ComponentConstructor<Events, Attributes>>>;
@@ -10,7 +10,7 @@ export type RouterContext<T extends RouterOptions = RouterOptions> = {
10
10
  navigator: EventTarget;
11
11
  url: State<URL | undefined>;
12
12
  radix: Radix<() => Promise<ComponentConstructor<Events, Attributes>>>;
13
- route: State<Slot | undefined>;
13
+ route: State<ComponentConstructor<Events, Attributes> | undefined>;
14
14
  };
15
15
  export declare class NavigateEvent extends Event {
16
16
  constructor();
@@ -20,7 +20,7 @@ export declare const createRouter: <T extends RouterOptions>(options: T) => {
20
20
  ROUTER_CONTEXT: Descriptor<RouterContext<T>>;
21
21
  registerRouterContext: (scope: Scope) => Promise<{
22
22
  url: State<URL | undefined>;
23
- route: State<unknown>;
23
+ route: State<ComponentConstructor<Events, Attributes> | undefined>;
24
24
  navigator: EventTarget;
25
25
  navigate: (path: string) => void;
26
26
  anchorNavigate: (event: Event) => void;
@@ -28,7 +28,7 @@ export declare const createRouter: <T extends RouterOptions>(options: T) => {
28
28
  };
29
29
  export declare const useRouter: <T extends RouterContext>(scope: Scope, context?: Descriptor<T>) => {
30
30
  url: State<URL | undefined>;
31
- route: State<unknown>;
31
+ route: State<ComponentConstructor<Events, Attributes> | undefined>;
32
32
  navigator: EventTarget;
33
33
  navigate: (path: string) => void;
34
34
  anchorNavigate: (event: Event) => void;
@@ -10,7 +10,7 @@ export declare class StopEvent extends Event {
10
10
  constructor();
11
11
  }
12
12
  export declare class Scope extends EventTarget {
13
- readonly parentScope?: Scope;
13
+ parentScope?: Scope;
14
14
  readonly context: Map<string, unknown>;
15
15
  constructor(parentScope?: Scope);
16
16
  getContext<T>(input: Descriptor<T>): T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "revojs",
3
- "version": "0.0.54",
3
+ "version": "0.0.56",
4
4
  "type": "module",
5
5
  "repository": "coverbase/revojs",
6
6
  "license": "MIT",