@jasonshimmy/custom-elements-runtime 0.1.3 → 0.1.5

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/router.d.ts CHANGED
@@ -4,16 +4,46 @@
4
4
  * - Integrates with createStore and lib/index.ts
5
5
  */
6
6
  import { type Store } from './store';
7
+ export interface RouteComponent {
8
+ new (...args: any[]): any;
9
+ (...args: any[]): any;
10
+ }
11
+ export interface RouteState {
12
+ path: string;
13
+ params: Record<string, string>;
14
+ query: Record<string, string>;
15
+ }
16
+ export type GuardResult = boolean | string | Promise<boolean | string>;
7
17
  export interface Route {
8
18
  path: string;
19
+ /**
20
+ * Statically available component (already imported)
21
+ */
9
22
  component?: string;
23
+ /**
24
+ * Lazy loader that resolves to something renderable
25
+ */
10
26
  load?: () => Promise<{
11
27
  default: string | HTMLElement | Function;
12
28
  }>;
29
+ /**
30
+ * Runs before matching — return false to cancel,
31
+ * or a string to redirect
32
+ */
33
+ beforeEnter?: (to: RouteState, from: RouteState) => GuardResult;
34
+ /**
35
+ * Runs right before navigation commits — can cancel or redirect
36
+ */
37
+ onEnter?: (to: RouteState, from: RouteState) => GuardResult;
38
+ /**
39
+ * Runs after navigation completes — cannot cancel
40
+ */
41
+ afterEnter?: (to: RouteState, from: RouteState) => void;
13
42
  }
14
43
  export interface RouterConfig {
15
44
  routes: Route[];
16
45
  base?: string;
46
+ initialUrl?: string;
17
47
  }
18
48
  export interface RouteState {
19
49
  path: string;
@@ -33,8 +63,8 @@ export declare const matchRoute: (routes: Route[], path: string) => {
33
63
  export declare function resolveRouteComponent(route: Route): Promise<any>;
34
64
  export declare function useRouter(config: RouterConfig): {
35
65
  store: Store<RouteState>;
36
- push: (path: string) => void;
37
- replace: (path: string) => void;
66
+ push: (path: string) => Promise<void>;
67
+ replace: (path: string) => Promise<void>;
38
68
  back: () => void;
39
69
  subscribe: (listener: (state: RouteState) => void) => void;
40
70
  matchRoute: (path: string) => {
@@ -56,8 +86,8 @@ export declare function matchRouteSSR(routes: Route[], path: string): {
56
86
  */
57
87
  export declare function initRouter(config: RouterConfig): {
58
88
  store: Store<RouteState>;
59
- push: (path: string) => void;
60
- replace: (path: string) => void;
89
+ push: (path: string) => Promise<void>;
90
+ replace: (path: string) => Promise<void>;
61
91
  back: () => void;
62
92
  subscribe: (listener: (state: RouteState) => void) => void;
63
93
  matchRoute: (path: string) => {
package/dist/store.d.ts CHANGED
@@ -2,9 +2,7 @@ type Listener<T> = (state: T) => void;
2
2
  export interface Store<T extends object> {
3
3
  subscribe(listener: Listener<T>): void;
4
4
  getState(): T;
5
+ setState(partial: Partial<T> | ((prev: T) => Partial<T>)): void;
5
6
  }
6
- export declare function createStore<T extends object>(initial: T): {
7
- subscribe: (listener: Listener<T>) => void;
8
- getState: () => T;
9
- };
7
+ export declare function createStore<T extends object>(initial: T): Store<T>;
10
8
  export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jasonshimmy/custom-elements-runtime",
3
3
  "description": "A powerful, modern, and lightweight runtime for creating reactive web components with TypeScript",
4
- "version": "0.1.3",
4
+ "version": "0.1.5",
5
5
  "type": "module",
6
6
  "keywords": [
7
7
  "web-components",