@je-es/client 0.0.1
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/LICENSE +21 -0
- package/README.md +770 -0
- package/dist/main.cjs +173 -0
- package/dist/main.cjs.map +1 -0
- package/dist/main.d.cts +825 -0
- package/dist/main.d.ts +825 -0
- package/dist/main.js +173 -0
- package/dist/main.js.map +1 -0
- package/package.json +55 -0
package/dist/main.d.cts
ADDED
|
@@ -0,0 +1,825 @@
|
|
|
1
|
+
import { VNode } from '@je-es/vdom';
|
|
2
|
+
export { VNode, VNodeChild, VNodeProps, createDOMElement, createElement, html, patch } from '@je-es/vdom';
|
|
3
|
+
import { ApiInterceptors } from '@je-es/capi';
|
|
4
|
+
export { ApiError, ApiInterceptors, ApiOptions, ApiResponse, HttpMethod, api, configureApi, getApiConfig, http, resetApiConfig } from '@je-es/capi';
|
|
5
|
+
|
|
6
|
+
interface BuildConfig {
|
|
7
|
+
entry: string;
|
|
8
|
+
output: string;
|
|
9
|
+
minify?: boolean;
|
|
10
|
+
sourcemap?: boolean;
|
|
11
|
+
optimization?: {
|
|
12
|
+
splitChunks?: boolean;
|
|
13
|
+
treeShaking?: boolean;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
interface AppConfig {
|
|
17
|
+
root: string;
|
|
18
|
+
routes?: RouteConfig[];
|
|
19
|
+
mode?: 'spa' | 'ssr';
|
|
20
|
+
}
|
|
21
|
+
interface StateConfig {
|
|
22
|
+
persist?: boolean;
|
|
23
|
+
storage?: 'localStorage' | 'sessionStorage';
|
|
24
|
+
}
|
|
25
|
+
interface FormsConfig {
|
|
26
|
+
autoValidate?: boolean;
|
|
27
|
+
csrfProtection?: boolean;
|
|
28
|
+
}
|
|
29
|
+
interface RouterConfig {
|
|
30
|
+
mode?: 'history' | 'hash';
|
|
31
|
+
base?: string;
|
|
32
|
+
scrollBehavior?: 'auto' | 'smooth' | 'instant';
|
|
33
|
+
beforeEach?: NavigationGuard;
|
|
34
|
+
afterEach?: (to: Route, from: Route) => void;
|
|
35
|
+
}
|
|
36
|
+
interface ApiConfig {
|
|
37
|
+
baseURL?: string;
|
|
38
|
+
timeout?: number;
|
|
39
|
+
headers?: Record<string, string>;
|
|
40
|
+
interceptors?: ApiInterceptors;
|
|
41
|
+
}
|
|
42
|
+
interface DevToolsConfig {
|
|
43
|
+
enabled?: boolean;
|
|
44
|
+
showRouterInfo?: boolean;
|
|
45
|
+
showStateChanges?: boolean;
|
|
46
|
+
}
|
|
47
|
+
interface ClientConfig {
|
|
48
|
+
build?: BuildConfig;
|
|
49
|
+
app?: AppConfig;
|
|
50
|
+
state?: StateConfig;
|
|
51
|
+
forms?: FormsConfig;
|
|
52
|
+
router?: RouterConfig;
|
|
53
|
+
api?: ApiConfig;
|
|
54
|
+
devTools?: DevToolsConfig;
|
|
55
|
+
}
|
|
56
|
+
interface Route {
|
|
57
|
+
path: string;
|
|
58
|
+
params: Record<string, string>;
|
|
59
|
+
query: Record<string, string>;
|
|
60
|
+
meta: Record<string, unknown>;
|
|
61
|
+
hash: string;
|
|
62
|
+
name?: string;
|
|
63
|
+
}
|
|
64
|
+
type NavigationGuard = (to: Route, from: Route, next: (path?: string | false) => void) => void | Promise<void>;
|
|
65
|
+
interface RouteConfig {
|
|
66
|
+
path: string;
|
|
67
|
+
name?: string;
|
|
68
|
+
component: ComponentConstructor | (() => Promise<{
|
|
69
|
+
default?: ComponentConstructor;
|
|
70
|
+
[key: string]: unknown;
|
|
71
|
+
}>);
|
|
72
|
+
meta?: Record<string, unknown>;
|
|
73
|
+
beforeEnter?: NavigationGuard;
|
|
74
|
+
children?: RouteConfig[];
|
|
75
|
+
}
|
|
76
|
+
type StoreSubscriber<T> = (state: T) => void;
|
|
77
|
+
type StoreMiddleware<T> = (state: T, action?: string) => void;
|
|
78
|
+
interface StoreOptions<T> {
|
|
79
|
+
state: T;
|
|
80
|
+
persist?: boolean;
|
|
81
|
+
storage?: 'localStorage' | 'sessionStorage';
|
|
82
|
+
storageKey?: string;
|
|
83
|
+
middleware?: StoreMiddleware<T>[];
|
|
84
|
+
}
|
|
85
|
+
interface ValidationRule {
|
|
86
|
+
required?: boolean;
|
|
87
|
+
minLength?: number;
|
|
88
|
+
maxLength?: number;
|
|
89
|
+
min?: number;
|
|
90
|
+
max?: number;
|
|
91
|
+
pattern?: RegExp;
|
|
92
|
+
email?: boolean;
|
|
93
|
+
url?: boolean;
|
|
94
|
+
custom?: (value: unknown) => boolean | string;
|
|
95
|
+
message?: string;
|
|
96
|
+
}
|
|
97
|
+
interface FormFieldOption {
|
|
98
|
+
label: string;
|
|
99
|
+
value: string | number;
|
|
100
|
+
}
|
|
101
|
+
interface FormFieldConfig {
|
|
102
|
+
name: string;
|
|
103
|
+
label?: string;
|
|
104
|
+
type?: string;
|
|
105
|
+
placeholder?: string;
|
|
106
|
+
value?: unknown;
|
|
107
|
+
options?: FormFieldOption[];
|
|
108
|
+
validation?: ValidationRule;
|
|
109
|
+
disabled?: boolean;
|
|
110
|
+
className?: string;
|
|
111
|
+
}
|
|
112
|
+
type FormSubmitHandler = (data: Record<string, unknown>, event: Event) => void | Promise<void>;
|
|
113
|
+
type ClassValue = string | Record<string, boolean> | undefined | null | false;
|
|
114
|
+
|
|
115
|
+
declare abstract class Component<P = Record<string, unknown>, S = Record<string, unknown>> {
|
|
116
|
+
props: P;
|
|
117
|
+
state: S;
|
|
118
|
+
_isMounted: boolean;
|
|
119
|
+
private _isUnmounting;
|
|
120
|
+
private _element;
|
|
121
|
+
private _vnode;
|
|
122
|
+
private _styleId;
|
|
123
|
+
private _isScheduledForUpdate;
|
|
124
|
+
private _updateBatch;
|
|
125
|
+
private _refs;
|
|
126
|
+
private _subscriptions;
|
|
127
|
+
private _memoCache;
|
|
128
|
+
constructor(props?: P, initialState?: S);
|
|
129
|
+
onBeforeMount?(): void | Promise<void>;
|
|
130
|
+
onMount?(): void | Promise<void>;
|
|
131
|
+
onBeforeUpdate?(prevProps: P, prevState: S): void | Promise<void>;
|
|
132
|
+
onUpdate?(prevProps: P, prevState: S): void;
|
|
133
|
+
onBeforeUnmount?(): void;
|
|
134
|
+
onUnmount?(): void;
|
|
135
|
+
onError?(error: Error, errorInfo: {
|
|
136
|
+
componentStack?: string;
|
|
137
|
+
}): void;
|
|
138
|
+
onPropsChange?(prevProps: P, newProps: P): void;
|
|
139
|
+
onStateChange?(prevState: S, newState: S): void;
|
|
140
|
+
shouldUpdate?(prevProps: P, prevState: S): boolean;
|
|
141
|
+
abstract render(): VNode;
|
|
142
|
+
styles?(): string;
|
|
143
|
+
setState(partialState: Partial<S> | ((prevState: S) => Partial<S>), callback?: () => void): void;
|
|
144
|
+
setProps(newProps: Partial<P>): void;
|
|
145
|
+
batchUpdate(updater: () => void): void;
|
|
146
|
+
update(key?: string): void;
|
|
147
|
+
forceUpdate(): void;
|
|
148
|
+
mount(container: HTMLElement): Promise<void>;
|
|
149
|
+
unmount(): void;
|
|
150
|
+
getRef(name: string): HTMLElement | undefined;
|
|
151
|
+
createRef(name: string): (el: HTMLElement | null) => void;
|
|
152
|
+
memo<T>(key: string, compute: () => T, deps: unknown[]): T;
|
|
153
|
+
subscribe(subscription: () => void): void;
|
|
154
|
+
debounce<T extends (...args: unknown[]) => unknown>(fn: T, delay: number): (...args: Parameters<T>) => void;
|
|
155
|
+
throttle<T extends (...args: unknown[]) => unknown>(fn: T, delay: number): (...args: Parameters<T>) => void;
|
|
156
|
+
get element(): HTMLElement | null;
|
|
157
|
+
get isMounted(): boolean;
|
|
158
|
+
get isUnmounting(): boolean;
|
|
159
|
+
private _performUpdate;
|
|
160
|
+
private _convertToVDomNode;
|
|
161
|
+
private _createElementFromVNode;
|
|
162
|
+
private _setElementProperty;
|
|
163
|
+
private _handleError;
|
|
164
|
+
private _areDepsEqual;
|
|
165
|
+
/**
|
|
166
|
+
* Invalidate all computed property caches (called by decorators)
|
|
167
|
+
*/
|
|
168
|
+
_invalidateAllComputed(): void;
|
|
169
|
+
/**
|
|
170
|
+
* Trigger watchers for a property (called by decorators)
|
|
171
|
+
*/
|
|
172
|
+
_triggerWatchers(propertyName: string, newValue: unknown, oldValue: unknown): void;
|
|
173
|
+
}
|
|
174
|
+
interface ComponentConstructor {
|
|
175
|
+
__watchers__?: Record<string, string[]>;
|
|
176
|
+
__reactiveProps__?: string[];
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
declare class Router {
|
|
180
|
+
private routes;
|
|
181
|
+
private currentRoute;
|
|
182
|
+
private mode;
|
|
183
|
+
private base;
|
|
184
|
+
private beforeEachHooks;
|
|
185
|
+
private afterEachHooks;
|
|
186
|
+
private currentComponent;
|
|
187
|
+
private routerOutlet;
|
|
188
|
+
private isNavigating;
|
|
189
|
+
private scrollBehavior;
|
|
190
|
+
private notFoundHandler;
|
|
191
|
+
private _internalPath;
|
|
192
|
+
/**
|
|
193
|
+
* Initialize router
|
|
194
|
+
*/
|
|
195
|
+
init(routes: RouteConfig[], mode?: 'history' | 'hash', base?: string, scrollBehavior?: 'auto' | 'smooth' | 'instant'): void;
|
|
196
|
+
/**
|
|
197
|
+
* Navigate to a path
|
|
198
|
+
*/
|
|
199
|
+
push(path: string, state?: Record<string, unknown>): Promise<void>;
|
|
200
|
+
/**
|
|
201
|
+
* Replace current route
|
|
202
|
+
*/
|
|
203
|
+
replace(path: string, state?: Record<string, unknown>): Promise<void>;
|
|
204
|
+
back(): void;
|
|
205
|
+
forward(): void;
|
|
206
|
+
go(delta: number): void;
|
|
207
|
+
/**
|
|
208
|
+
* Navigation guards
|
|
209
|
+
*/
|
|
210
|
+
beforeEach(hook: NavigationGuard): void;
|
|
211
|
+
afterEach(hook: (to: Route, from: Route) => void): void;
|
|
212
|
+
onNotFound(handler: () => void): void;
|
|
213
|
+
/**
|
|
214
|
+
* Route utilities
|
|
215
|
+
*/
|
|
216
|
+
getCurrentRoute(): Route | null;
|
|
217
|
+
isActive(path: string, exact?: boolean): boolean;
|
|
218
|
+
outlet(): VNode;
|
|
219
|
+
getRoute(name: string): RouteConfig | undefined;
|
|
220
|
+
pushNamed(name: string, params?: Record<string, string>): Promise<void>;
|
|
221
|
+
resolve(path: string): Route | null;
|
|
222
|
+
/**
|
|
223
|
+
* Initialize routing handlers
|
|
224
|
+
*/
|
|
225
|
+
private _initializeRouting;
|
|
226
|
+
private _shouldInterceptLink;
|
|
227
|
+
/**
|
|
228
|
+
* Handle route change
|
|
229
|
+
*/
|
|
230
|
+
private _handleRoute;
|
|
231
|
+
/**
|
|
232
|
+
* Handle 404 not found
|
|
233
|
+
*/
|
|
234
|
+
private _handleNotFound;
|
|
235
|
+
/**
|
|
236
|
+
* Build route object
|
|
237
|
+
*/
|
|
238
|
+
private _buildRouteObject;
|
|
239
|
+
private _buildEmptyRoute;
|
|
240
|
+
/**
|
|
241
|
+
* Run navigation guards
|
|
242
|
+
*/
|
|
243
|
+
private _runNavigationGuards;
|
|
244
|
+
private _runGuard;
|
|
245
|
+
/**
|
|
246
|
+
* Render component - simplified component resolution
|
|
247
|
+
*/
|
|
248
|
+
private _renderComponent;
|
|
249
|
+
/**
|
|
250
|
+
* Resolve component (handle lazy loading)
|
|
251
|
+
*/
|
|
252
|
+
private _resolveComponent;
|
|
253
|
+
/**
|
|
254
|
+
* Render error fallback
|
|
255
|
+
*/
|
|
256
|
+
private _renderError;
|
|
257
|
+
/**
|
|
258
|
+
* Handle scroll behavior
|
|
259
|
+
*/
|
|
260
|
+
private _handleScrollBehavior;
|
|
261
|
+
/**
|
|
262
|
+
* Get current path (handles test environments)
|
|
263
|
+
*/
|
|
264
|
+
private _getCurrentPath;
|
|
265
|
+
private _buildFullPath;
|
|
266
|
+
/**
|
|
267
|
+
* Match route pattern to path
|
|
268
|
+
*/
|
|
269
|
+
private _matchRoute;
|
|
270
|
+
private _matchPath;
|
|
271
|
+
/**
|
|
272
|
+
* Parse query string
|
|
273
|
+
*/
|
|
274
|
+
private _parseQuery;
|
|
275
|
+
}
|
|
276
|
+
declare const router: Router;
|
|
277
|
+
|
|
278
|
+
declare global {
|
|
279
|
+
interface Window {
|
|
280
|
+
__JEES_DEV__?: {
|
|
281
|
+
router: typeof router;
|
|
282
|
+
config: ClientConfig;
|
|
283
|
+
version: string;
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Client builder
|
|
289
|
+
* Handles build process and runtime configuration
|
|
290
|
+
*/
|
|
291
|
+
declare function client(config: ClientConfig): {
|
|
292
|
+
/**
|
|
293
|
+
* Build the client application
|
|
294
|
+
* This compiles TypeScript components to vanilla JavaScript
|
|
295
|
+
*/
|
|
296
|
+
build(): Promise<void>;
|
|
297
|
+
/**
|
|
298
|
+
* Initialize the client runtime
|
|
299
|
+
* This runs in the browser
|
|
300
|
+
*/
|
|
301
|
+
init(): void;
|
|
302
|
+
/**
|
|
303
|
+
* Enable development tools
|
|
304
|
+
*/
|
|
305
|
+
_enableDevTools(): void;
|
|
306
|
+
/**
|
|
307
|
+
* Get configuration
|
|
308
|
+
*/
|
|
309
|
+
getConfig(): ClientConfig;
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Store - Global state management with improved features
|
|
314
|
+
*/
|
|
315
|
+
declare class Store<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
316
|
+
private _state;
|
|
317
|
+
private _subscribers;
|
|
318
|
+
private _persist;
|
|
319
|
+
private _storage;
|
|
320
|
+
private _storageKey;
|
|
321
|
+
private _middleware;
|
|
322
|
+
private _isHydrating;
|
|
323
|
+
constructor(options: StoreOptions<T>);
|
|
324
|
+
/**
|
|
325
|
+
* Get current state (readonly)
|
|
326
|
+
*/
|
|
327
|
+
get state(): Readonly<T>;
|
|
328
|
+
/**
|
|
329
|
+
* Set entire state (replaces state)
|
|
330
|
+
*/
|
|
331
|
+
set state(newState: T);
|
|
332
|
+
/**
|
|
333
|
+
* Update state (merges with existing state)
|
|
334
|
+
*/
|
|
335
|
+
setState(update: Partial<T> | ((prevState: T) => Partial<T>), action?: string): void;
|
|
336
|
+
/**
|
|
337
|
+
* Get a specific value from state
|
|
338
|
+
*/
|
|
339
|
+
get<K extends keyof T>(key: K): T[K];
|
|
340
|
+
/**
|
|
341
|
+
* Set a specific value in state
|
|
342
|
+
*/
|
|
343
|
+
set<K extends keyof T>(key: K, value: T[K], action?: string): void;
|
|
344
|
+
/**
|
|
345
|
+
* Subscribe to state changes
|
|
346
|
+
* Returns unsubscribe function
|
|
347
|
+
*/
|
|
348
|
+
subscribe(listener: StoreSubscriber<T>): () => void;
|
|
349
|
+
/**
|
|
350
|
+
* Subscribe to specific key changes
|
|
351
|
+
*/
|
|
352
|
+
subscribeToKey<K extends keyof T>(key: K, listener: (value: T[K]) => void): () => void;
|
|
353
|
+
/**
|
|
354
|
+
* Add middleware
|
|
355
|
+
*/
|
|
356
|
+
use(middleware: (state: T, action?: string) => void): void;
|
|
357
|
+
/**
|
|
358
|
+
* Clear all state
|
|
359
|
+
*/
|
|
360
|
+
clear(): void;
|
|
361
|
+
/**
|
|
362
|
+
* Reset state to initial value
|
|
363
|
+
*/
|
|
364
|
+
reset(initialState: T): void;
|
|
365
|
+
/**
|
|
366
|
+
* Hydrate state from storage
|
|
367
|
+
*/
|
|
368
|
+
hydrate(): void;
|
|
369
|
+
/**
|
|
370
|
+
* Get store snapshot for debugging
|
|
371
|
+
*/
|
|
372
|
+
getSnapshot(): {
|
|
373
|
+
state: T;
|
|
374
|
+
subscribers: number;
|
|
375
|
+
storageKey: string;
|
|
376
|
+
};
|
|
377
|
+
/**
|
|
378
|
+
* Batch multiple updates
|
|
379
|
+
*/
|
|
380
|
+
batch(updates: () => void): void;
|
|
381
|
+
/**
|
|
382
|
+
* Notify all subscribers
|
|
383
|
+
*/
|
|
384
|
+
private _notify;
|
|
385
|
+
/**
|
|
386
|
+
* Load state from storage
|
|
387
|
+
*/
|
|
388
|
+
private _loadFromStorage;
|
|
389
|
+
/**
|
|
390
|
+
* Save state to storage
|
|
391
|
+
*/
|
|
392
|
+
private _saveToStorage;
|
|
393
|
+
/**
|
|
394
|
+
* Destroy store and cleanup
|
|
395
|
+
*/
|
|
396
|
+
destroy(): void;
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Create a store with type inference
|
|
400
|
+
*/
|
|
401
|
+
declare function createStore<T extends Record<string, unknown>>(options: StoreOptions<T>): Store<T>;
|
|
402
|
+
/**
|
|
403
|
+
* Create a computed store that derives from other stores
|
|
404
|
+
*/
|
|
405
|
+
declare function createComputedStore<T, S extends Store<Record<string, unknown>>[]>(stores: S, computer: (...states: unknown[]) => T): Store<{
|
|
406
|
+
value: T;
|
|
407
|
+
}>;
|
|
408
|
+
/**
|
|
409
|
+
* Connect a component to a store
|
|
410
|
+
*/
|
|
411
|
+
declare function connect<T extends Record<string, unknown>, C extends {
|
|
412
|
+
update?: () => void;
|
|
413
|
+
}>(store: Store<T>, component: C, mapStateToProps: (state: T) => Partial<C>): () => void;
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Style Manager - handles CSS injection and scoping
|
|
417
|
+
*/
|
|
418
|
+
declare class StyleManager {
|
|
419
|
+
private static styles;
|
|
420
|
+
private static scopeCounter;
|
|
421
|
+
/**
|
|
422
|
+
* Inject styles into document
|
|
423
|
+
*/
|
|
424
|
+
static inject(css: string, componentName?: string): string;
|
|
425
|
+
/**
|
|
426
|
+
* Remove styles from document
|
|
427
|
+
*/
|
|
428
|
+
static remove(id: string): void;
|
|
429
|
+
/**
|
|
430
|
+
* Scope CSS selectors
|
|
431
|
+
*/
|
|
432
|
+
private static scopeStyles;
|
|
433
|
+
/**
|
|
434
|
+
* Clear all styles
|
|
435
|
+
*/
|
|
436
|
+
static clear(): void;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* CSS template literal tag
|
|
440
|
+
* Usage: css`.class { color: red; }`
|
|
441
|
+
*/
|
|
442
|
+
declare function css(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
443
|
+
|
|
444
|
+
interface ClassFieldDecoratorContext<This = unknown, Value = unknown> {
|
|
445
|
+
kind: 'field';
|
|
446
|
+
name: string | symbol;
|
|
447
|
+
access: {
|
|
448
|
+
get(object: This): Value;
|
|
449
|
+
set(object: This, value: Value): void;
|
|
450
|
+
};
|
|
451
|
+
addInitializer(initializer: (this: This) => void): void;
|
|
452
|
+
}
|
|
453
|
+
interface ClassGetterDecoratorContext<This = unknown, Value = unknown> {
|
|
454
|
+
kind: 'getter';
|
|
455
|
+
name: string | symbol;
|
|
456
|
+
access: {
|
|
457
|
+
get(object: This): Value;
|
|
458
|
+
};
|
|
459
|
+
addInitializer(initializer: (this: This) => void): void;
|
|
460
|
+
}
|
|
461
|
+
interface ClassMethodDecoratorContext<This = unknown, Value = unknown> {
|
|
462
|
+
kind: 'method';
|
|
463
|
+
name: string | symbol;
|
|
464
|
+
access: {
|
|
465
|
+
get(object: This): Value;
|
|
466
|
+
};
|
|
467
|
+
addInitializer(initializer: (this: This) => void): void;
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* State decorator - makes property reactive
|
|
471
|
+
* Usage: @state fields = [];
|
|
472
|
+
*
|
|
473
|
+
* Supports both TypeScript 5 decorators and legacy decorators
|
|
474
|
+
*/
|
|
475
|
+
declare function state<This, Value>(target: undefined, context: ClassFieldDecoratorContext<This, Value>): (this: This, initialValue: Value) => Value;
|
|
476
|
+
declare function state(target: Record<string, unknown>, context: string): void;
|
|
477
|
+
/**
|
|
478
|
+
* Computed decorator - creates computed property
|
|
479
|
+
* Usage: @computed get fullName() { return this.firstName + ' ' + this.lastName; }
|
|
480
|
+
*/
|
|
481
|
+
declare function computed<This, Value>(originalGetter: (this: This) => Value, context: ClassGetterDecoratorContext<This, Value>): (this: This) => Value;
|
|
482
|
+
declare function computed(target: Record<string, unknown>, context: string, descriptor: PropertyDescriptor): PropertyDescriptor;
|
|
483
|
+
declare function computed(targetOrGetter: unknown, context: unknown): never;
|
|
484
|
+
/**
|
|
485
|
+
* Watch decorator - watches for property changes
|
|
486
|
+
* Usage: @watch('propertyName') onPropertyChange(newValue, oldValue) {}
|
|
487
|
+
*/
|
|
488
|
+
declare function watch(propertyName: string): {
|
|
489
|
+
<This, Args extends unknown[], Return>(originalMethod: (this: This, ...args: Args) => Return, context: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>): void;
|
|
490
|
+
(target: Record<string, unknown>, context: string, descriptor: PropertyDescriptor): PropertyDescriptor;
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
interface FormConfig {
|
|
494
|
+
fields: FormFieldConfig[];
|
|
495
|
+
endpoint?: string;
|
|
496
|
+
method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
497
|
+
onSubmit?: (data: Record<string, unknown>, event: Event) => void | Promise<void>;
|
|
498
|
+
onSuccess?: (data: unknown) => void;
|
|
499
|
+
onError?: (error: unknown) => void;
|
|
500
|
+
submitButton?: {
|
|
501
|
+
label?: string;
|
|
502
|
+
loadingLabel?: string;
|
|
503
|
+
className?: string;
|
|
504
|
+
};
|
|
505
|
+
className?: string;
|
|
506
|
+
autoValidate?: boolean;
|
|
507
|
+
}
|
|
508
|
+
interface FormField extends FormFieldConfig {
|
|
509
|
+
error?: string;
|
|
510
|
+
touched?: boolean;
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* SmartForm Component
|
|
514
|
+
* Auto-validation, CSRF protection, API submission
|
|
515
|
+
*/
|
|
516
|
+
declare class SmartFormComponent extends Component<FormConfig> {
|
|
517
|
+
fields: FormField[];
|
|
518
|
+
formData: Record<string, unknown>;
|
|
519
|
+
isSubmitting: boolean;
|
|
520
|
+
submitError: string;
|
|
521
|
+
submitSuccess: boolean;
|
|
522
|
+
constructor(props: FormConfig);
|
|
523
|
+
onMount(): void;
|
|
524
|
+
/**
|
|
525
|
+
* Handle field change
|
|
526
|
+
*/
|
|
527
|
+
handleChange(fieldName: string, value: unknown): void;
|
|
528
|
+
/**
|
|
529
|
+
* Handle field blur
|
|
530
|
+
*/
|
|
531
|
+
handleBlur(fieldName: string): void;
|
|
532
|
+
/**
|
|
533
|
+
* Validate single field
|
|
534
|
+
*/
|
|
535
|
+
validateField(field: FormField, value: unknown): string | undefined;
|
|
536
|
+
/**
|
|
537
|
+
* Validate all fields
|
|
538
|
+
*/
|
|
539
|
+
validateForm(): boolean;
|
|
540
|
+
/**
|
|
541
|
+
* Handle form submission
|
|
542
|
+
*/
|
|
543
|
+
handleSubmit(event: Event): Promise<void>;
|
|
544
|
+
/**
|
|
545
|
+
* Render form field
|
|
546
|
+
*/
|
|
547
|
+
renderField(field: FormField): VNode;
|
|
548
|
+
render(): VNode;
|
|
549
|
+
styles(): string;
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* SmartForm helper function
|
|
553
|
+
*/
|
|
554
|
+
declare function SmartForm(config: FormConfig): VNode;
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* Debounce function
|
|
558
|
+
* Delays function execution until after wait time
|
|
559
|
+
*/
|
|
560
|
+
declare function debounce<T extends (...args: never[]) => unknown>(fn: T, delay: number): (...args: Parameters<T>) => void;
|
|
561
|
+
/**
|
|
562
|
+
* Throttle function
|
|
563
|
+
* Limits function execution to once per time period
|
|
564
|
+
*/
|
|
565
|
+
declare function throttle<T extends (...args: never[]) => unknown>(fn: T, delay: number): (...args: Parameters<T>) => void;
|
|
566
|
+
/**
|
|
567
|
+
* Class names utility
|
|
568
|
+
* Combines class names conditionally
|
|
569
|
+
*/
|
|
570
|
+
declare function classNames(...classes: ClassValue[]): string;
|
|
571
|
+
/**
|
|
572
|
+
* Format date
|
|
573
|
+
* Simple date formatting utility with validation
|
|
574
|
+
*/
|
|
575
|
+
declare function formatDate(date: Date | string | number, format?: string): string;
|
|
576
|
+
/**
|
|
577
|
+
* Deep clone object
|
|
578
|
+
* Handles Date, Array, and nested objects
|
|
579
|
+
*/
|
|
580
|
+
declare function deepClone<T>(obj: T): T;
|
|
581
|
+
/**
|
|
582
|
+
* Merge objects deeply
|
|
583
|
+
* Properly handles nested objects and arrays
|
|
584
|
+
*/
|
|
585
|
+
declare function deepMerge<T extends Record<string, unknown>>(target: T, ...sources: Partial<T>[]): T;
|
|
586
|
+
declare function uniqueId(prefix?: string): string;
|
|
587
|
+
/**
|
|
588
|
+
* Sleep/delay utility
|
|
589
|
+
*/
|
|
590
|
+
declare function sleep(ms: number): Promise<void>;
|
|
591
|
+
/**
|
|
592
|
+
* Check if value is empty
|
|
593
|
+
*/
|
|
594
|
+
declare function isEmpty(value: unknown): boolean;
|
|
595
|
+
/**
|
|
596
|
+
* Capitalize first letter
|
|
597
|
+
*/
|
|
598
|
+
declare function capitalize(str: string): string;
|
|
599
|
+
/**
|
|
600
|
+
* Convert to kebab-case
|
|
601
|
+
*/
|
|
602
|
+
declare function kebabCase(str: string): string;
|
|
603
|
+
/**
|
|
604
|
+
* Convert to camelCase
|
|
605
|
+
*/
|
|
606
|
+
declare function camelCase(str: string): string;
|
|
607
|
+
/**
|
|
608
|
+
* Convert to PascalCase
|
|
609
|
+
*/
|
|
610
|
+
declare function pascalCase(str: string): string;
|
|
611
|
+
/**
|
|
612
|
+
* Truncate string
|
|
613
|
+
*/
|
|
614
|
+
declare function truncate(str: string, length: number, suffix?: string): string;
|
|
615
|
+
/**
|
|
616
|
+
* Parse query string
|
|
617
|
+
*/
|
|
618
|
+
declare function parseQuery(queryString: string): Record<string, string | string[]>;
|
|
619
|
+
/**
|
|
620
|
+
* Stringify object to query string
|
|
621
|
+
*/
|
|
622
|
+
declare function stringifyQuery(obj: Record<string, unknown>): string;
|
|
623
|
+
/**
|
|
624
|
+
* Clamp a number between min and max
|
|
625
|
+
*/
|
|
626
|
+
declare function clamp(value: number, min: number, max: number): number;
|
|
627
|
+
/**
|
|
628
|
+
* Check if code is running in browser
|
|
629
|
+
*/
|
|
630
|
+
declare function isBrowser(): boolean;
|
|
631
|
+
/**
|
|
632
|
+
* Safe JSON parse with fallback
|
|
633
|
+
*/
|
|
634
|
+
declare function safeJsonParse<T = unknown>(json: string, fallback: T): T;
|
|
635
|
+
/**
|
|
636
|
+
* Export all utilities
|
|
637
|
+
*/
|
|
638
|
+
declare const utils: {
|
|
639
|
+
debounce: typeof debounce;
|
|
640
|
+
throttle: typeof throttle;
|
|
641
|
+
classNames: typeof classNames;
|
|
642
|
+
formatDate: typeof formatDate;
|
|
643
|
+
deepClone: typeof deepClone;
|
|
644
|
+
deepMerge: typeof deepMerge;
|
|
645
|
+
uniqueId: typeof uniqueId;
|
|
646
|
+
sleep: typeof sleep;
|
|
647
|
+
isEmpty: typeof isEmpty;
|
|
648
|
+
capitalize: typeof capitalize;
|
|
649
|
+
kebabCase: typeof kebabCase;
|
|
650
|
+
camelCase: typeof camelCase;
|
|
651
|
+
pascalCase: typeof pascalCase;
|
|
652
|
+
truncate: typeof truncate;
|
|
653
|
+
parseQuery: typeof parseQuery;
|
|
654
|
+
stringifyQuery: typeof stringifyQuery;
|
|
655
|
+
clamp: typeof clamp;
|
|
656
|
+
isBrowser: typeof isBrowser;
|
|
657
|
+
safeJsonParse: typeof safeJsonParse;
|
|
658
|
+
};
|
|
659
|
+
|
|
660
|
+
type ContextSubscriber<T> = (value: T) => void;
|
|
661
|
+
interface ProviderProps<T> {
|
|
662
|
+
context: Context<T>;
|
|
663
|
+
value: T;
|
|
664
|
+
children: VNode | VNode[];
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* Context class for sharing data across component tree
|
|
668
|
+
*/
|
|
669
|
+
declare class Context<T = unknown> {
|
|
670
|
+
private _value;
|
|
671
|
+
private _subscribers;
|
|
672
|
+
private _defaultValue;
|
|
673
|
+
constructor(defaultValue: T);
|
|
674
|
+
get value(): T;
|
|
675
|
+
set value(newValue: T);
|
|
676
|
+
subscribe(subscriber: ContextSubscriber<T>): () => void;
|
|
677
|
+
reset(): void;
|
|
678
|
+
update(updater: (prev: T) => T): void;
|
|
679
|
+
private _notify;
|
|
680
|
+
get subscriberCount(): number;
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
* Create a new context
|
|
684
|
+
*/
|
|
685
|
+
declare function createContext<T>(defaultValue: T): Context<T>;
|
|
686
|
+
declare class Provider<T> extends Component<ProviderProps<T>> {
|
|
687
|
+
onMount(): void;
|
|
688
|
+
onUpdate(): void;
|
|
689
|
+
onUnmount(): void;
|
|
690
|
+
render(): VNode;
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* Hook-like function to use context in components
|
|
694
|
+
* Call this in your component to get context value
|
|
695
|
+
*/
|
|
696
|
+
declare function useContext<T>(context: Context<T>, component: Component): T;
|
|
697
|
+
/**
|
|
698
|
+
* Combined context for complex state management
|
|
699
|
+
*/
|
|
700
|
+
declare class CombinedContext<T extends Record<string, unknown>> {
|
|
701
|
+
private contexts;
|
|
702
|
+
constructor(initialValues: T);
|
|
703
|
+
get<K extends keyof T>(key: K): Context<T[K]>;
|
|
704
|
+
set<K extends keyof T>(key: K, value: T[K]): void;
|
|
705
|
+
subscribe<K extends keyof T>(key: K, subscriber: ContextSubscriber<T[K]>): () => void;
|
|
706
|
+
reset(): void;
|
|
707
|
+
}
|
|
708
|
+
/**
|
|
709
|
+
* Create combined context
|
|
710
|
+
*/
|
|
711
|
+
declare function createCombinedContext<T extends Record<string, unknown>>(initialValues: T): CombinedContext<T>;
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* Set current component context for hooks
|
|
715
|
+
*/
|
|
716
|
+
declare function setHookContext(component: Component): void;
|
|
717
|
+
/**
|
|
718
|
+
* Clear hook context
|
|
719
|
+
*/
|
|
720
|
+
declare function clearHookContext(): void;
|
|
721
|
+
/**
|
|
722
|
+
* useState hook - manages component state
|
|
723
|
+
*/
|
|
724
|
+
declare function useState<T>(initialValue: T | (() => T)): [T, (newValue: T | ((prev: T) => T)) => void];
|
|
725
|
+
/**
|
|
726
|
+
* useEffect hook - side effects
|
|
727
|
+
*/
|
|
728
|
+
declare function useEffect(effect: () => void | (() => void), deps?: unknown[]): void;
|
|
729
|
+
/**
|
|
730
|
+
* useMemo hook - memoize expensive computations
|
|
731
|
+
*/
|
|
732
|
+
declare function useMemo<T>(factory: () => T, deps: unknown[]): T;
|
|
733
|
+
/**
|
|
734
|
+
* useCallback hook - memoize callbacks
|
|
735
|
+
*/
|
|
736
|
+
declare function useCallback<T extends (...args: unknown[]) => unknown>(callback: T, deps: unknown[]): T;
|
|
737
|
+
/**
|
|
738
|
+
* useRef hook - persistent value across renders
|
|
739
|
+
*/
|
|
740
|
+
declare function useRef<T>(initialValue: T): {
|
|
741
|
+
current: T;
|
|
742
|
+
};
|
|
743
|
+
/**
|
|
744
|
+
* useReducer hook - complex state management
|
|
745
|
+
*/
|
|
746
|
+
declare function useReducer<S, A>(reducer: (state: S, action: A) => S, initialState: S): [S, (action: A) => void];
|
|
747
|
+
/**
|
|
748
|
+
* useLocalStorage hook - sync state with localStorage
|
|
749
|
+
*/
|
|
750
|
+
declare function useLocalStorage<T>(key: string, initialValue: T): [T, (value: T | ((prev: T) => T)) => void];
|
|
751
|
+
/**
|
|
752
|
+
* useDebounce hook - debounce value changes
|
|
753
|
+
*/
|
|
754
|
+
declare function useDebounce<T>(value: T, delay: number): T;
|
|
755
|
+
/**
|
|
756
|
+
* usePrevious hook - get previous value
|
|
757
|
+
*/
|
|
758
|
+
declare function usePrevious<T>(value: T): T | undefined;
|
|
759
|
+
/**
|
|
760
|
+
* useToggle hook - boolean toggle
|
|
761
|
+
*/
|
|
762
|
+
declare function useToggle(initialValue?: boolean): [boolean, () => void];
|
|
763
|
+
/**
|
|
764
|
+
* useInterval hook - setInterval with cleanup
|
|
765
|
+
*/
|
|
766
|
+
declare function useInterval(callback: () => void, delay: number | null): void;
|
|
767
|
+
/**
|
|
768
|
+
* useFetch hook - data fetching
|
|
769
|
+
*/
|
|
770
|
+
declare function useFetch<T>(url: string, options?: RequestInit): {
|
|
771
|
+
data: T | null;
|
|
772
|
+
loading: boolean;
|
|
773
|
+
error: Error | null;
|
|
774
|
+
refetch: () => void;
|
|
775
|
+
};
|
|
776
|
+
/**
|
|
777
|
+
* useWindowSize hook - track window dimensions
|
|
778
|
+
*/
|
|
779
|
+
declare function useWindowSize(): {
|
|
780
|
+
width: number;
|
|
781
|
+
height: number;
|
|
782
|
+
};
|
|
783
|
+
/**
|
|
784
|
+
* useEventListener hook - add event listener
|
|
785
|
+
*/
|
|
786
|
+
declare function useEventListener<K extends keyof WindowEventMap>(eventName: K, handler: (event: WindowEventMap[K]) => void, element?: HTMLElement | Window): void;
|
|
787
|
+
/**
|
|
788
|
+
* Create a functional component with hooks
|
|
789
|
+
* Returns a component class that can be instantiated
|
|
790
|
+
*/
|
|
791
|
+
declare function createFunctionalComponent<P extends Record<string, unknown> = Record<string, unknown>>(fn: (props: P) => VNode, displayName?: string): new (props?: P) => Component<P>;
|
|
792
|
+
|
|
793
|
+
type UpdateCallback = () => void;
|
|
794
|
+
/**
|
|
795
|
+
* Update Scheduler
|
|
796
|
+
* Batches multiple state changes into a single render
|
|
797
|
+
*/
|
|
798
|
+
declare class UpdateScheduler {
|
|
799
|
+
private queue;
|
|
800
|
+
private isFlushScheduled;
|
|
801
|
+
private isFlushing;
|
|
802
|
+
/**
|
|
803
|
+
* Schedule a component update
|
|
804
|
+
*/
|
|
805
|
+
schedule(callback: UpdateCallback): void;
|
|
806
|
+
/**
|
|
807
|
+
* Force immediate flush (for urgent updates)
|
|
808
|
+
*/
|
|
809
|
+
flushSync(callback: UpdateCallback): void;
|
|
810
|
+
/**
|
|
811
|
+
* Flush all pending updates
|
|
812
|
+
*/
|
|
813
|
+
private flush;
|
|
814
|
+
/**
|
|
815
|
+
* Clear all pending updates
|
|
816
|
+
*/
|
|
817
|
+
clear(): void;
|
|
818
|
+
/**
|
|
819
|
+
* Get queue size (for debugging)
|
|
820
|
+
*/
|
|
821
|
+
get size(): number;
|
|
822
|
+
}
|
|
823
|
+
declare const scheduler: UpdateScheduler;
|
|
824
|
+
|
|
825
|
+
export { type ApiConfig, type AppConfig, type BuildConfig, type ClientConfig, CombinedContext, Component, type ComponentConstructor, Context, type DevToolsConfig, type FormConfig, type FormFieldConfig, type FormFieldOption, type FormSubmitHandler, type FormsConfig, type NavigationGuard, Provider, type Route, type RouteConfig, Router, type RouterConfig, SmartForm, SmartFormComponent, type StateConfig, Store, type StoreMiddleware, type StoreOptions, type StoreSubscriber, StyleManager, type ValidationRule, camelCase, capitalize, clamp, classNames, clearHookContext, client, computed, connect, createCombinedContext, createComputedStore, createContext, createFunctionalComponent, createStore, css, debounce, deepClone, deepMerge, formatDate, isBrowser, isEmpty, kebabCase, parseQuery, pascalCase, router, safeJsonParse, scheduler, setHookContext, sleep, state, stringifyQuery, throttle, truncate, uniqueId, useCallback, useContext, useDebounce, useEffect, useEventListener, useFetch, useInterval, useLocalStorage, useMemo, usePrevious, useReducer, useRef, useState, useToggle, useWindowSize, utils, watch };
|