pulse-js-framework 1.4.2 → 1.4.4

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.
@@ -0,0 +1,197 @@
1
+ /**
2
+ * Pulse Framework - Router Type Definitions
3
+ * @module pulse-js-framework/runtime/router
4
+ */
5
+
6
+ import { Pulse } from './pulse';
7
+
8
+ /** Route parameters object */
9
+ export type RouteParams = Record<string, string>;
10
+
11
+ /** Query parameters object */
12
+ export type QueryParams = Record<string, string | string[]>;
13
+
14
+ /** Route meta information */
15
+ export type RouteMeta = Record<string, unknown>;
16
+
17
+ /** Navigation target (to/from) */
18
+ export interface NavigationTarget {
19
+ path: string;
20
+ params: RouteParams;
21
+ query: QueryParams;
22
+ meta: RouteMeta;
23
+ matched?: RouteDefinition[];
24
+ }
25
+
26
+ /** Navigation guard return type */
27
+ export type NavigationGuardReturn = boolean | string | void | Promise<boolean | string | void>;
28
+
29
+ /** Navigation guard function */
30
+ export type NavigationGuard = (
31
+ to: NavigationTarget,
32
+ from: NavigationTarget
33
+ ) => NavigationGuardReturn;
34
+
35
+ /** After navigation hook */
36
+ export type AfterNavigationHook = (to: NavigationTarget) => void | Promise<void>;
37
+
38
+ /** Scroll position */
39
+ export interface ScrollPosition {
40
+ x?: number;
41
+ y?: number;
42
+ selector?: string;
43
+ behavior?: ScrollBehavior;
44
+ }
45
+
46
+ /** Scroll behavior function */
47
+ export type ScrollBehaviorFn = (
48
+ to: NavigationTarget,
49
+ from: NavigationTarget,
50
+ savedPosition: ScrollPosition | null
51
+ ) => ScrollPosition | null | void;
52
+
53
+ /** Route handler (component) */
54
+ export type RouteHandler =
55
+ | (() => Node)
56
+ | (() => Promise<{ default: () => Node }>)
57
+ | { render: () => Node };
58
+
59
+ /** Route definition */
60
+ export interface RouteDefinition {
61
+ handler?: RouteHandler;
62
+ meta?: RouteMeta;
63
+ beforeEnter?: NavigationGuard;
64
+ children?: Routes;
65
+ }
66
+
67
+ /** Routes configuration object */
68
+ export interface Routes {
69
+ [path: string]: RouteHandler | RouteDefinition;
70
+ }
71
+
72
+ /** Router options */
73
+ export interface RouterOptions {
74
+ routes?: Routes;
75
+ mode?: 'history' | 'hash';
76
+ base?: string;
77
+ scrollBehavior?: ScrollBehaviorFn;
78
+ }
79
+
80
+ /** Navigation options */
81
+ export interface NavigateOptions {
82
+ replace?: boolean;
83
+ query?: Record<string, string | number>;
84
+ state?: unknown;
85
+ }
86
+
87
+ /** Link options */
88
+ export interface LinkOptions {
89
+ exact?: boolean;
90
+ activeClass?: string;
91
+ }
92
+
93
+ /** Matched route */
94
+ export interface MatchedRoute {
95
+ route: RouteDefinition;
96
+ params: RouteParams;
97
+ }
98
+
99
+ /** Router instance */
100
+ export interface Router {
101
+ /** Current path (reactive) */
102
+ path: Pulse<string>;
103
+
104
+ /** Current route object (reactive) */
105
+ route: Pulse<NavigationTarget | null>;
106
+
107
+ /** Current route parameters (reactive) */
108
+ params: Pulse<RouteParams>;
109
+
110
+ /** Current query parameters (reactive) */
111
+ query: Pulse<QueryParams>;
112
+
113
+ /** Current route meta (reactive) */
114
+ meta: Pulse<RouteMeta>;
115
+
116
+ /** Loading state for async components (reactive) */
117
+ loading: Pulse<boolean>;
118
+
119
+ /**
120
+ * Navigate to path
121
+ * @returns Promise resolving to navigation success
122
+ */
123
+ navigate(path: string, options?: NavigateOptions): Promise<boolean>;
124
+
125
+ /**
126
+ * Create router link element
127
+ */
128
+ link(path: string, content: Node | string, options?: LinkOptions): HTMLAnchorElement;
129
+
130
+ /**
131
+ * Render current route component
132
+ */
133
+ outlet(container: string | HTMLElement): HTMLElement;
134
+
135
+ /** Navigate back in history */
136
+ back(): void;
137
+
138
+ /** Navigate forward in history */
139
+ forward(): void;
140
+
141
+ /** Go to specific history entry */
142
+ go(delta: number): void;
143
+
144
+ /**
145
+ * Add global before-navigation guard
146
+ * @returns Unregister function
147
+ */
148
+ beforeEach(hook: NavigationGuard): () => void;
149
+
150
+ /**
151
+ * Add before-resolve hook (after per-route guards)
152
+ * @returns Unregister function
153
+ */
154
+ beforeResolve(hook: NavigationGuard): () => void;
155
+
156
+ /**
157
+ * Add after-navigation hook
158
+ * @returns Unregister function
159
+ */
160
+ afterEach(hook: AfterNavigationHook): () => void;
161
+
162
+ /**
163
+ * Check if route matches
164
+ */
165
+ isActive(path: string, exact?: boolean): boolean;
166
+
167
+ /**
168
+ * Get all matched routes (for nested routes)
169
+ */
170
+ getMatchedRoutes(path: string): MatchedRoute[];
171
+
172
+ /**
173
+ * Start listening to navigation events
174
+ * @returns Stop function
175
+ */
176
+ start(): () => void;
177
+
178
+ /**
179
+ * Match path against pattern
180
+ */
181
+ matchRoute(pattern: string, path: string): RouteParams | null;
182
+
183
+ /**
184
+ * Parse query string to object
185
+ */
186
+ parseQuery(search: string): QueryParams;
187
+ }
188
+
189
+ /**
190
+ * Create router instance
191
+ */
192
+ export declare function createRouter(options?: RouterOptions): Router;
193
+
194
+ /**
195
+ * Quick router setup (creates, starts, and mounts)
196
+ */
197
+ export declare function simpleRouter(routes: Routes, target?: string): Router;
@@ -0,0 +1,170 @@
1
+ /**
2
+ * Pulse Framework - Store Type Definitions
3
+ * @module pulse-js-framework/runtime/store
4
+ */
5
+
6
+ import { Pulse } from './pulse';
7
+
8
+ /** Store options */
9
+ export interface StoreOptions {
10
+ persist?: boolean;
11
+ storageKey?: string;
12
+ }
13
+
14
+ /** Base store type - maps state keys to Pulse values */
15
+ export type StoreState<T extends Record<string, unknown>> = {
16
+ [K in keyof T]: Pulse<T[K]>;
17
+ };
18
+
19
+ /** Store methods */
20
+ export interface StoreMethods<T extends Record<string, unknown>> {
21
+ /** Get current state snapshot */
22
+ $getState(): T;
23
+
24
+ /** Set multiple values at once (batched) */
25
+ $setState(updates: Partial<T>): void;
26
+
27
+ /** Reset to initial state */
28
+ $reset(): void;
29
+
30
+ /** Subscribe to all changes, returns unsubscribe */
31
+ $subscribe(callback: (state: T) => void): () => void;
32
+
33
+ /** Access raw Pulse instances */
34
+ $pulses: StoreState<T>;
35
+ }
36
+
37
+ /** Complete store type */
38
+ export type Store<T extends Record<string, unknown>> = StoreState<T> & StoreMethods<T>;
39
+
40
+ /**
41
+ * Create global store
42
+ */
43
+ export declare function createStore<T extends Record<string, unknown>>(
44
+ initialState: T,
45
+ options?: StoreOptions
46
+ ): Store<T>;
47
+
48
+ /** Action function signature */
49
+ export type ActionFn<T extends Record<string, unknown>, Args extends unknown[] = unknown[], R = void> =
50
+ (store: Store<T>, ...args: Args) => R;
51
+
52
+ /** Actions definition object */
53
+ export type ActionsDef<T extends Record<string, unknown>> = {
54
+ [name: string]: ActionFn<T, unknown[], unknown>;
55
+ };
56
+
57
+ /** Bound actions (without store parameter) */
58
+ export type BoundActions<T extends Record<string, unknown>, A extends ActionsDef<T>> = {
59
+ [K in keyof A]: A[K] extends ActionFn<T, infer Args, infer R>
60
+ ? (...args: Args) => R
61
+ : never;
62
+ };
63
+
64
+ /**
65
+ * Create action functions bound to store
66
+ */
67
+ export declare function createActions<
68
+ T extends Record<string, unknown>,
69
+ A extends ActionsDef<T>
70
+ >(store: Store<T>, actions: A): BoundActions<T, A>;
71
+
72
+ /** Getter function signature */
73
+ export type GetterFn<T extends Record<string, unknown>, R = unknown> = (store: Store<T>) => R;
74
+
75
+ /** Getters definition object */
76
+ export type GettersDef<T extends Record<string, unknown>> = {
77
+ [name: string]: GetterFn<T, unknown>;
78
+ };
79
+
80
+ /** Computed getters (as Pulse values) */
81
+ export type ComputedGetters<T extends Record<string, unknown>, G extends GettersDef<T>> = {
82
+ [K in keyof G]: G[K] extends GetterFn<T, infer R> ? Pulse<R> : never;
83
+ };
84
+
85
+ /**
86
+ * Create computed values for store
87
+ */
88
+ export declare function createGetters<
89
+ T extends Record<string, unknown>,
90
+ G extends GettersDef<T>
91
+ >(store: Store<T>, getters: G): ComputedGetters<T, G>;
92
+
93
+ /** Combined stores type */
94
+ export type CombinedStores<S extends Record<string, Store<Record<string, unknown>>>> = {
95
+ [K in keyof S]: S[K];
96
+ };
97
+
98
+ /**
99
+ * Combine multiple stores under namespaces
100
+ */
101
+ export declare function combineStores<S extends Record<string, Store<Record<string, unknown>>>>(
102
+ stores: S
103
+ ): CombinedStores<S>;
104
+
105
+ /** Module definition */
106
+ export interface ModuleDef<T extends Record<string, unknown>> {
107
+ state: T;
108
+ actions?: ActionsDef<T>;
109
+ getters?: GettersDef<T>;
110
+ }
111
+
112
+ /** Modules configuration */
113
+ export type ModulesDef = {
114
+ [namespace: string]: ModuleDef<Record<string, unknown>>;
115
+ };
116
+
117
+ /** Module store type */
118
+ export type ModuleStore<M extends ModuleDef<Record<string, unknown>>> =
119
+ Store<M['state']> &
120
+ (M['actions'] extends ActionsDef<M['state']> ? BoundActions<M['state'], M['actions']> : {}) &
121
+ (M['getters'] extends GettersDef<M['state']> ? ComputedGetters<M['state'], M['getters']> : {});
122
+
123
+ /** Root module store type */
124
+ export type RootModuleStore<D extends ModulesDef> = {
125
+ [K in keyof D]: ModuleStore<D[K]>;
126
+ } & {
127
+ $getState(): { [K in keyof D]: D[K]['state'] };
128
+ $reset(): void;
129
+ };
130
+
131
+ /**
132
+ * Create module-based store (Vuex-like)
133
+ */
134
+ export declare function createModuleStore<D extends ModulesDef>(
135
+ modules: D
136
+ ): RootModuleStore<D>;
137
+
138
+ /** Plugin function */
139
+ export type StorePlugin<T extends Record<string, unknown>> = (store: Store<T>) => Store<T>;
140
+
141
+ /**
142
+ * Apply plugin to store
143
+ */
144
+ export declare function usePlugin<T extends Record<string, unknown>>(
145
+ store: Store<T>,
146
+ plugin: StorePlugin<T>
147
+ ): Store<T>;
148
+
149
+ /** Store with history plugin */
150
+ export interface HistoryStore<T extends Record<string, unknown>> extends Store<T> {
151
+ $undo(): void;
152
+ $redo(): void;
153
+ $canUndo(): boolean;
154
+ $canRedo(): boolean;
155
+ }
156
+
157
+ /**
158
+ * Logger plugin - logs state changes to console
159
+ */
160
+ export declare function loggerPlugin<T extends Record<string, unknown>>(
161
+ store: Store<T>
162
+ ): Store<T>;
163
+
164
+ /**
165
+ * History plugin - enables undo/redo
166
+ */
167
+ export declare function historyPlugin<T extends Record<string, unknown>>(
168
+ store: Store<T>,
169
+ maxHistory?: number
170
+ ): HistoryStore<T>;