extended-dynamic-forms 0.2.1 → 0.3.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.
Files changed (50) hide show
  1. package/README.md +387 -1392
  2. package/dist/events/FormEventContext.d.ts +3 -0
  3. package/dist/index.es.js +22516 -14517
  4. package/dist/index.umd.js +63 -36
  5. package/dist/style.css +1 -1
  6. package/dist/widgets/base/index.d.ts +2 -0
  7. package/dist/widgets/base/types.d.ts +135 -0
  8. package/dist/widgets/base/utils.d.ts +63 -0
  9. package/dist/widgets/choice/ChoiceWidget.d.ts +30 -0
  10. package/dist/widgets/choice/ChoiceWidget.types.d.ts +496 -0
  11. package/dist/widgets/choice/examples/ChoiceWidget.example.d.ts +7 -0
  12. package/dist/widgets/choice/hooks/__tests__/useChoiceWidget.test.d.ts +1 -0
  13. package/dist/widgets/choice/hooks/__tests__/useDataSource.test.d.ts +1 -0
  14. package/dist/widgets/choice/hooks/examples/useChoiceWidget.example.d.ts +18 -0
  15. package/dist/widgets/choice/hooks/examples/useDataSourceExample.d.ts +22 -0
  16. package/dist/widgets/choice/hooks/index.d.ts +6 -0
  17. package/dist/widgets/choice/hooks/useChoiceWidget.d.ts +65 -0
  18. package/dist/widgets/choice/hooks/useDataSource.d.ts +69 -0
  19. package/dist/widgets/choice/index.d.ts +59 -0
  20. package/dist/widgets/choice/presenters/CheckboxPresenter.d.ts +70 -0
  21. package/dist/widgets/choice/presenters/DropdownPresenter.d.ts +37 -0
  22. package/dist/widgets/choice/presenters/PresenterStrategy.d.ts +230 -0
  23. package/dist/widgets/choice/presenters/RadioPresenter.d.ts +39 -0
  24. package/dist/widgets/choice/presenters/examples/RadioPresenterExample.d.ts +7 -0
  25. package/dist/widgets/choice/presenters/index.d.ts +20 -0
  26. package/dist/widgets/choice/providers/ApiDataSource.d.ts +241 -0
  27. package/dist/widgets/choice/providers/DataSourceProvider.d.ts +260 -0
  28. package/dist/widgets/choice/providers/StaticDataSource.d.ts +258 -0
  29. package/dist/widgets/choice/providers/WebSocketDataSource.d.ts +310 -0
  30. package/dist/widgets/choice/providers/index.d.ts +12 -0
  31. package/dist/widgets/choice/utils/index.d.ts +1 -0
  32. package/dist/widgets/choice/utils/responseMappers.d.ts +342 -0
  33. package/dist/widgets/date/DateTimeWidget.d.ts +26 -0
  34. package/dist/widgets/date/EnhancedDateWidget.d.ts +26 -0
  35. package/dist/widgets/date/index.d.ts +13 -0
  36. package/dist/widgets/file/FileUploadWidget.d.ts +40 -0
  37. package/dist/widgets/file/index.d.ts +2 -0
  38. package/dist/widgets/index.d.ts +33 -17
  39. package/dist/widgets/input/EmailWidget.d.ts +34 -0
  40. package/dist/widgets/input/NumberWidget.d.ts +39 -0
  41. package/dist/widgets/input/TelephoneWidget.d.ts +34 -0
  42. package/dist/widgets/input/URLWidget.d.ts +34 -0
  43. package/dist/widgets/input/index.d.ts +7 -0
  44. package/dist/widgets/text/PasswordWidget.d.ts +45 -0
  45. package/dist/widgets/text/TextWidget.d.ts +40 -0
  46. package/dist/widgets/text/TextareaWidget.d.ts +38 -0
  47. package/dist/widgets/text/index.d.ts +20 -0
  48. package/package.json +5 -5
  49. package/dist/vanilla-entry.d.ts +0 -232
  50. package/dist/widgets/enhanced/EnhancedWidgets.d.ts +0 -37
@@ -0,0 +1,496 @@
1
+ import { WidgetProps } from '@rjsf/utils';
2
+
3
+ /**
4
+ * Presentation modes for the Choice Widget
5
+ */
6
+ export declare enum PresentationMode {
7
+ /** Dropdown/Select presentation */
8
+ DROPDOWN = "dropdown",
9
+ /** Radio button presentation */
10
+ RADIO = "radio",
11
+ /** Checkbox presentation (multi-select) */
12
+ CHECKBOX = "checkbox"
13
+ }
14
+ /**
15
+ * Loading states for async data operations
16
+ */
17
+ export interface LoadingState {
18
+ /** Whether the widget is currently loading */
19
+ isLoading: boolean;
20
+ /** Loading message to display to users */
21
+ message?: string;
22
+ /** Progress percentage (0-100) for long operations */
23
+ progress?: number;
24
+ }
25
+ /**
26
+ * Error states for data operations
27
+ */
28
+ export interface ErrorState {
29
+ /** Whether an error has occurred */
30
+ hasError: boolean;
31
+ /** Error message to display to users */
32
+ message: string;
33
+ /** Error code for programmatic handling */
34
+ code?: string | number;
35
+ /** Stack trace for debugging (development only) */
36
+ stack?: string;
37
+ /** Whether the error is recoverable */
38
+ recoverable?: boolean;
39
+ /** Timestamp when the error occurred */
40
+ timestamp?: number;
41
+ }
42
+ /**
43
+ * Represents a single choice option
44
+ */
45
+ export interface ChoiceOption {
46
+ /** Display text for the option */
47
+ label: string;
48
+ /** Value to be stored when selected */
49
+ value: string | number | boolean;
50
+ /** Whether this option is disabled */
51
+ disabled?: boolean;
52
+ /** Additional metadata for the option */
53
+ metadata?: {
54
+ /** Optional description or help text */
55
+ description?: string;
56
+ /** CSS class names for styling */
57
+ className?: string;
58
+ /** Icon identifier for display */
59
+ icon?: string;
60
+ /** Group or category identifier for organizing options */
61
+ group?: string;
62
+ /** Display order for sorting */
63
+ order?: number;
64
+ /** Additional data attributes */
65
+ data?: Record<string, unknown>;
66
+ /** Accessibility attributes */
67
+ a11y?: {
68
+ /** ARIA label for screen readers */
69
+ ariaLabel?: string;
70
+ /** ARIA description */
71
+ ariaDescription?: string;
72
+ /** Whether this option has a popup */
73
+ ariaHasPopup?: boolean;
74
+ };
75
+ /** Internal properties for system use */
76
+ _index?: number;
77
+ _active?: boolean;
78
+ _originalData?: any;
79
+ };
80
+ }
81
+ /**
82
+ * Configuration for static data sources
83
+ */
84
+ export interface StaticDataSourceConfig {
85
+ /** Type identifier for static data source */
86
+ type: 'static';
87
+ /** Array of choice options */
88
+ options: ChoiceOption[];
89
+ }
90
+ /**
91
+ * HTTP method types for API requests
92
+ */
93
+ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH';
94
+ /**
95
+ * Response mapper function to transform API data into ChoiceOption[]
96
+ */
97
+ export type ResponseMapper = (data: unknown) => ChoiceOption[];
98
+ /**
99
+ * Built-in response mapper configurations
100
+ */
101
+ export interface ResponseMapperConfig {
102
+ /** Type of built-in mapper */
103
+ type: 'simple' | 'nested' | 'custom';
104
+ /** Configuration for simple mapper */
105
+ simple?: {
106
+ /** Path to the array in response (e.g., 'data.items') */
107
+ arrayPath?: string;
108
+ /** Field name for label (default: 'label') */
109
+ labelField?: string;
110
+ /** Field name for value (default: 'value') */
111
+ valueField?: string;
112
+ /** Field name for disabled state (default: 'disabled') */
113
+ disabledField?: string;
114
+ };
115
+ /** Configuration for nested mapper */
116
+ nested?: {
117
+ /** Path to the array in response */
118
+ arrayPath: string;
119
+ /** Nested paths for extracting data */
120
+ paths: {
121
+ label: string;
122
+ value: string;
123
+ disabled?: string;
124
+ description?: string;
125
+ };
126
+ };
127
+ /** Custom mapper function */
128
+ custom?: ResponseMapper;
129
+ }
130
+ /**
131
+ * Cache configuration for API responses
132
+ */
133
+ export interface CacheConfig {
134
+ /** Cache duration in milliseconds (default: 300000 = 5 minutes) */
135
+ ttl?: number;
136
+ /** Cache key for storage (auto-generated if not provided) */
137
+ key?: string;
138
+ /** Whether to use browser storage for persistence */
139
+ persistent?: boolean;
140
+ /** Cache storage type */
141
+ storageType?: 'memory' | 'sessionStorage' | 'localStorage';
142
+ }
143
+ /**
144
+ * Configuration for API data sources
145
+ */
146
+ export interface ApiDataSourceConfig {
147
+ /** Type identifier for API data source */
148
+ type: 'api';
149
+ /** API endpoint URL */
150
+ url: string;
151
+ /** HTTP method (default: 'GET') */
152
+ method?: HttpMethod;
153
+ /** Request headers */
154
+ headers?: Record<string, string>;
155
+ /** Request body for POST/PUT/PATCH */
156
+ body?: unknown;
157
+ /** Query parameters */
158
+ params?: Record<string, string | number | boolean>;
159
+ /** Response mapper configuration */
160
+ responseMapper: ResponseMapperConfig;
161
+ /** Cache configuration */
162
+ cache?: CacheConfig;
163
+ /** Request timeout in milliseconds (default: 30000) */
164
+ timeout?: number;
165
+ /** Number of retry attempts on failure (default: 0) */
166
+ retries?: number;
167
+ /** Authentication configuration */
168
+ auth?: {
169
+ /** Authentication type */
170
+ type: 'bearer' | 'basic' | 'apiKey';
171
+ /** Token or credentials */
172
+ credentials: string | {
173
+ username: string;
174
+ password: string;
175
+ };
176
+ /** Header name for API key auth */
177
+ headerName?: string;
178
+ };
179
+ }
180
+ /**
181
+ * WebSocket message types for real-time communication
182
+ */
183
+ export type WebSocketMessageType = 'options-update' | 'options-add' | 'options-remove' | 'options-patch' | 'search-request' | 'search-response' | 'connection-ready' | 'error' | 'heartbeat';
184
+ /**
185
+ * WebSocket message structure
186
+ */
187
+ export interface WebSocketMessage<T = unknown> {
188
+ /** Message type identifier */
189
+ type: WebSocketMessageType;
190
+ /** Message payload */
191
+ data?: T;
192
+ /** Unique message ID for correlation */
193
+ messageId?: string;
194
+ /** Timestamp when message was created */
195
+ timestamp?: number;
196
+ /** Error details for error messages */
197
+ error?: {
198
+ code: string;
199
+ message: string;
200
+ details?: unknown;
201
+ };
202
+ }
203
+ /**
204
+ * Configuration for WebSocket data sources
205
+ */
206
+ export interface WebSocketDataSourceConfig {
207
+ /** Type identifier for WebSocket data source */
208
+ type: 'websocket';
209
+ /** WebSocket server URL */
210
+ url: string;
211
+ /** WebSocket protocols */
212
+ protocols?: string | string[];
213
+ /** Authentication configuration */
214
+ auth?: {
215
+ /** Authentication type */
216
+ type: 'bearer' | 'query' | 'header';
217
+ /** Token or credentials */
218
+ credentials: string;
219
+ /** Parameter/header name for auth */
220
+ paramName?: string;
221
+ };
222
+ /** Connection configuration */
223
+ connection?: {
224
+ /** Connection timeout in milliseconds (default: 30000) */
225
+ connectTimeout?: number;
226
+ /** Auto-reconnect on connection loss (default: true) */
227
+ autoReconnect?: boolean;
228
+ /** Max reconnection attempts (default: 5) */
229
+ maxReconnectAttempts?: number;
230
+ /** Reconnection delay in milliseconds (default: 1000) */
231
+ reconnectDelay?: number;
232
+ /** Heartbeat interval in milliseconds (default: 30000) */
233
+ heartbeatInterval?: number;
234
+ /** Response timeout for requests in milliseconds (default: 10000) */
235
+ responseTimeout?: number;
236
+ };
237
+ /** Message handling configuration */
238
+ messageHandling?: {
239
+ /** Whether to request initial options on connect (default: true) */
240
+ requestInitialOptions?: boolean;
241
+ /** Initial message to send after connection */
242
+ initialMessage?: WebSocketMessage;
243
+ /** Whether to enable real-time search (default: false) */
244
+ enableRealtimeSearch?: boolean;
245
+ /** Search debounce delay in milliseconds (default: 300) */
246
+ searchDebounceMs?: number;
247
+ };
248
+ /** Response transformation */
249
+ responseMapper?: ResponseMapperConfig;
250
+ /** Cache configuration (for offline support) */
251
+ cache?: CacheConfig;
252
+ }
253
+ /**
254
+ * Union type for all data source configurations
255
+ */
256
+ export type DataSourceConfig = StaticDataSourceConfig | ApiDataSourceConfig | WebSocketDataSourceConfig;
257
+ /**
258
+ * Validation configuration for selected values
259
+ */
260
+ export interface ValidationConfig {
261
+ /** Custom validation function */
262
+ validator?: (value: unknown, options: ChoiceOption[]) => string | null;
263
+ /** Whether to validate on change (default: true) */
264
+ validateOnChange?: boolean;
265
+ /** Whether to validate on blur (default: true) */
266
+ validateOnBlur?: boolean;
267
+ /** Custom error messages */
268
+ messages?: {
269
+ required?: string;
270
+ invalid?: string;
271
+ custom?: string;
272
+ };
273
+ }
274
+ /**
275
+ * Search and filtering configuration
276
+ */
277
+ export interface SearchConfig {
278
+ /** Whether search is enabled */
279
+ enabled: boolean;
280
+ /** Search placeholder text */
281
+ placeholder?: string;
282
+ /** Minimum characters before search activates */
283
+ minLength?: number;
284
+ /** Search debounce delay in milliseconds */
285
+ debounceMs?: number;
286
+ /** Whether search is case-sensitive */
287
+ caseSensitive?: boolean;
288
+ /** Fields to search in */
289
+ searchFields?: ('label' | 'value' | 'description')[];
290
+ /** Custom search function */
291
+ customFilter?: (option: ChoiceOption, searchTerm: string) => boolean;
292
+ }
293
+ /**
294
+ * Accessibility configuration
295
+ */
296
+ export interface AccessibilityConfig {
297
+ /** ARIA label for the widget */
298
+ ariaLabel?: string;
299
+ /** ARIA description */
300
+ ariaDescription?: string;
301
+ /** Whether to announce changes to screen readers */
302
+ announceChanges?: boolean;
303
+ /** Custom ARIA attributes */
304
+ ariaAttributes?: Record<string, string>;
305
+ /** Keyboard navigation configuration */
306
+ keyboard?: {
307
+ /** Whether to enable arrow key navigation */
308
+ arrowKeys?: boolean;
309
+ /** Whether to enable type-ahead search */
310
+ typeAhead?: boolean;
311
+ /** Whether to enable home/end keys */
312
+ homeEnd?: boolean;
313
+ };
314
+ }
315
+ /**
316
+ * Main configuration interface for the Choice Widget
317
+ */
318
+ export interface ChoiceWidgetConfig {
319
+ /** Presentation mode for the widget */
320
+ presentationMode?: PresentationMode;
321
+ /** Data source configuration */
322
+ dataSource?: DataSourceConfig;
323
+ /** Whether multiple selections are allowed */
324
+ multiple?: boolean;
325
+ /** Whether to allow clearing the selection */
326
+ allowClear?: boolean;
327
+ /** Placeholder text when no option is selected */
328
+ placeholder?: string;
329
+ /** Whether the widget is disabled */
330
+ disabled?: boolean;
331
+ /** Whether the widget is read-only */
332
+ readonly?: boolean;
333
+ /** Maximum number of selections (for multiple mode) */
334
+ maxSelections?: number;
335
+ /** Minimum number of selections (for multiple mode) */
336
+ minSelections?: number;
337
+ /** Search and filtering configuration */
338
+ search?: SearchConfig;
339
+ /** Validation configuration */
340
+ validation?: ValidationConfig;
341
+ /** Accessibility configuration */
342
+ accessibility?: AccessibilityConfig;
343
+ /** Custom CSS class names */
344
+ className?: string;
345
+ /** Custom inline styles */
346
+ style?: React.CSSProperties;
347
+ /** Size variant for Ant Design components */
348
+ size?: 'small' | 'middle' | 'large';
349
+ /** Whether to show option counts in multi-select */
350
+ showOptionCount?: boolean;
351
+ /** Custom loading component */
352
+ loadingComponent?: React.ComponentType<LoadingState>;
353
+ /** Custom error component */
354
+ errorComponent?: React.ComponentType<ErrorState>;
355
+ /** Custom empty state component */
356
+ emptyComponent?: React.ComponentType<{
357
+ message?: string;
358
+ }>;
359
+ }
360
+ /**
361
+ * Internal state interface for the Choice Widget
362
+ */
363
+ export interface ChoiceWidgetState {
364
+ /** Available options */
365
+ options: ChoiceOption[];
366
+ /** Currently selected values */
367
+ selectedValues: (string | number | boolean)[];
368
+ /** Loading state */
369
+ loading: LoadingState;
370
+ /** Error state */
371
+ error: ErrorState;
372
+ /** Search term */
373
+ searchTerm: string;
374
+ /** Filtered options based on search */
375
+ filteredOptions: ChoiceOption[];
376
+ /** Whether the dropdown/menu is open */
377
+ isOpen: boolean;
378
+ /** Focused option index for keyboard navigation */
379
+ focusedOptionIndex: number;
380
+ }
381
+ /**
382
+ * Event handlers for the Choice Widget
383
+ */
384
+ export interface ChoiceWidgetEventHandlers {
385
+ /** Called when selection changes */
386
+ onSelectionChange?: (values: (string | number | boolean)[], options: ChoiceOption[]) => void;
387
+ /** Called when search term changes */
388
+ onSearchChange?: (searchTerm: string) => void;
389
+ /** Called when widget receives focus */
390
+ onFocus?: (event: React.FocusEvent) => void;
391
+ /** Called when widget loses focus */
392
+ onBlur?: (event: React.FocusEvent) => void;
393
+ /** Called when dropdown opens */
394
+ onOpen?: () => void;
395
+ /** Called when dropdown closes */
396
+ onClose?: () => void;
397
+ /** Called when data loading starts */
398
+ onLoadingStart?: () => void;
399
+ /** Called when data loading completes */
400
+ onLoadingComplete?: (options: ChoiceOption[]) => void;
401
+ /** Called when an error occurs */
402
+ onError?: (error: ErrorState) => void;
403
+ /** Called when error is cleared */
404
+ onErrorClear?: () => void;
405
+ }
406
+ /**
407
+ * Props interface for the Choice Widget component
408
+ * Extends RJSF WidgetProps and adds Choice Widget specific properties
409
+ */
410
+ export interface ChoiceWidgetProps extends WidgetProps {
411
+ /** Choice Widget configuration from ui:options */
412
+ options: WidgetProps['options'] & {
413
+ /** Choice Widget specific configuration */
414
+ choiceConfig?: ChoiceWidgetConfig;
415
+ /** Legacy support for enum options */
416
+ enumOptions?: {
417
+ label: string;
418
+ value: unknown;
419
+ }[];
420
+ };
421
+ /** Event handlers */
422
+ eventHandlers?: ChoiceWidgetEventHandlers;
423
+ /** Current widget state (for controlled usage) */
424
+ state?: Partial<ChoiceWidgetState>;
425
+ /** State change handler (for controlled usage) */
426
+ onStateChange?: (state: Partial<ChoiceWidgetState>) => void;
427
+ }
428
+ /**
429
+ * Data provider interface for abstracting data sources
430
+ */
431
+ export interface ChoiceDataProvider {
432
+ /** Fetch options from the data source */
433
+ fetchOptions(): Promise<ChoiceOption[]>;
434
+ /** Whether this provider supports caching */
435
+ supportsCaching: boolean;
436
+ /** Whether this provider supports real-time updates */
437
+ supportsRealTime: boolean;
438
+ /** Cleanup resources */
439
+ cleanup(): void;
440
+ }
441
+ /**
442
+ * Cache interface for storing fetched data
443
+ */
444
+ export interface ChoiceCache {
445
+ /** Get cached data */
446
+ get(key: string): ChoiceOption[] | null;
447
+ /** Set cached data */
448
+ set(key: string, data: ChoiceOption[], ttl?: number): void;
449
+ /** Clear specific cache entry */
450
+ clear(key: string): void;
451
+ /** Clear all cache entries */
452
+ clearAll(): void;
453
+ /** Check if cache entry exists and is valid */
454
+ has(key: string): boolean;
455
+ }
456
+ /**
457
+ * Strategy interface for different presentation modes
458
+ */
459
+ export interface PresentationStrategy {
460
+ /** Render the widget */
461
+ render(props: ChoiceWidgetProps, state: ChoiceWidgetState): React.ReactElement;
462
+ /** Handle selection change */
463
+ handleSelectionChange(value: unknown, props: ChoiceWidgetProps, state: ChoiceWidgetState): (string | number | boolean)[];
464
+ /** Get default props for this presentation mode */
465
+ getDefaultProps(): Partial<ChoiceWidgetConfig>;
466
+ /** Validate props for this presentation mode */
467
+ validateProps(config: ChoiceWidgetConfig): string[] | null;
468
+ }
469
+ /**
470
+ * Type guard to check if a data source is static
471
+ */
472
+ export declare function isStaticDataSource(dataSource: DataSourceConfig): dataSource is StaticDataSourceConfig;
473
+ /**
474
+ * Type guard to check if a data source is API-based
475
+ */
476
+ export declare function isApiDataSource(dataSource: DataSourceConfig): dataSource is ApiDataSourceConfig;
477
+ /**
478
+ * Type guard to check if a data source is WebSocket-based
479
+ */
480
+ export declare function isWebSocketDataSource(dataSource: DataSourceConfig): dataSource is WebSocketDataSourceConfig;
481
+ /**
482
+ * Type guard to check if widget supports multiple selections
483
+ */
484
+ export declare function supportsMultipleSelections(mode: PresentationMode): boolean;
485
+ /**
486
+ * Default configuration values
487
+ */
488
+ export declare const DEFAULT_CHOICE_CONFIG: Partial<ChoiceWidgetConfig>;
489
+ /**
490
+ * Default cache configuration
491
+ */
492
+ export declare const DEFAULT_CACHE_CONFIG: CacheConfig;
493
+ /**
494
+ * Default response mapper for simple API responses
495
+ */
496
+ export declare const DEFAULT_RESPONSE_MAPPER: ResponseMapperConfig;
@@ -0,0 +1,7 @@
1
+ import { default as React } from 'react';
2
+
3
+ /**
4
+ * Main Examples Container
5
+ */
6
+ declare const ChoiceWidgetExamples: React.FC;
7
+ export default ChoiceWidgetExamples;
@@ -0,0 +1,18 @@
1
+ import { default as React } from 'react';
2
+
3
+ /**
4
+ * Example: Basic Choice Widget Hook Usage
5
+ */
6
+ export declare const BasicChoiceWidgetExample: React.FC;
7
+ /**
8
+ * Example: Choice Widget with Error Boundary
9
+ */
10
+ export declare const ErrorBoundaryChoiceWidgetExample: React.FC;
11
+ /**
12
+ * Example: Choice Widget with Performance Metrics
13
+ */
14
+ export declare const PerformanceChoiceWidgetExample: React.FC;
15
+ /**
16
+ * Example: Advanced Choice Widget Configuration
17
+ */
18
+ export declare const AdvancedChoiceWidgetExample: React.FC;
@@ -0,0 +1,22 @@
1
+ import { default as React } from 'react';
2
+
3
+ /**
4
+ * Example demonstrating basic useDataSource usage
5
+ */
6
+ export declare const BasicDataSourceExample: React.FC;
7
+ /**
8
+ * Example demonstrating API data source with dynamic configuration
9
+ */
10
+ export declare const ApiDataSourceExample: React.FC;
11
+ /**
12
+ * Example demonstrating retry functionality
13
+ */
14
+ export declare const RetryDataSourceExample: React.FC;
15
+ /**
16
+ * Example demonstrating WebSocket real-time updates
17
+ */
18
+ export declare const WebSocketDataSourceExample: React.FC;
19
+ /**
20
+ * Example demonstrating presentation mode switching
21
+ */
22
+ export declare const PresentationModeSwitchExample: React.FC;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @module hooks
3
+ * @description React hooks for the Choice Widget
4
+ */
5
+ export { useDataSource, useDataSourceWithRetry, useMultipleDataSources, type UseDataSourceReturn, } from './useDataSource';
6
+ export { useChoiceWidget, useChoiceWidgetWithErrorBoundary, useChoiceWidgetWithMetrics, type UseChoiceWidgetReturn, } from './useChoiceWidget';
@@ -0,0 +1,65 @@
1
+ import { default as React } from 'react';
2
+ import { ChoiceWidgetProps, ChoiceWidgetState, ChoiceOption } from '../ChoiceWidget.types';
3
+ import { PresenterStrategy } from '../presenters/PresenterStrategy';
4
+ import { DataSourceMetrics } from '../providers/DataSourceProvider';
5
+
6
+ /**
7
+ * Interface for the hook return value
8
+ */
9
+ export interface UseChoiceWidgetReturn {
10
+ options: ChoiceOption[];
11
+ presenter: PresenterStrategy;
12
+ state: ChoiceWidgetState;
13
+ setState: (updates: Partial<ChoiceWidgetState>) => void;
14
+ value: unknown;
15
+ handleChange: (newValue: unknown) => void;
16
+ eventHandlers: {
17
+ onFocus: (event: React.FocusEvent) => void;
18
+ onBlur: (event: React.FocusEvent) => void;
19
+ onChange: (value: unknown) => void;
20
+ onSearch: (searchTerm: string) => void;
21
+ };
22
+ isMultiSelect: boolean;
23
+ isLoading: boolean;
24
+ hasError: boolean;
25
+ metrics: DataSourceMetrics;
26
+ }
27
+ /**
28
+ * Core business logic hook for Choice Widget
29
+ *
30
+ * This hook orchestrates all Choice Widget functionality including:
31
+ * - Data source management via useDataSource
32
+ * - Presenter strategy selection and coordination
33
+ * - Value transformation between widget and RJSF formats
34
+ * - Event system integration via FormEventHub
35
+ * - Schema-based behavior detection
36
+ * - Performance optimization with memoization
37
+ *
38
+ * @param props - RJSF-compatible widget props
39
+ * @returns Complete widget state and handlers
40
+ */
41
+ export declare function useChoiceWidget(props: ChoiceWidgetProps): UseChoiceWidgetReturn;
42
+ /**
43
+ * Hook for using Choice Widget with custom error handling
44
+ * Note: This hook catches runtime errors but not hook call errors.
45
+ * Hook call errors should be handled at the component level with Error Boundaries.
46
+ */
47
+ export declare function useChoiceWidgetWithErrorBoundary(props: ChoiceWidgetProps, onError?: (error: Error) => void): UseChoiceWidgetReturn | {
48
+ error: Error;
49
+ };
50
+ /**
51
+ * Hook for using Choice Widget with performance monitoring
52
+ */
53
+ export declare function useChoiceWidgetWithMetrics(props: ChoiceWidgetProps, onMetricsUpdate?: (metrics: DataSourceMetrics) => void): UseChoiceWidgetReturn & {
54
+ performanceMetrics: PerformanceMetrics;
55
+ };
56
+ /**
57
+ * Performance metrics interface
58
+ */
59
+ interface PerformanceMetrics {
60
+ initialLoadTime: number;
61
+ renderCount: number;
62
+ averageRenderTime: number;
63
+ lastRenderTime: number;
64
+ }
65
+ export {};
@@ -0,0 +1,69 @@
1
+ import { DataSourceConfig, ChoiceOption, LoadingState, ErrorState } from '../ChoiceWidget.types';
2
+ import { DataSourceEventCallbacks, DataSourceMetrics } from '../providers/DataSourceProvider';
3
+
4
+ /**
5
+ * Hook return type for useDataSource
6
+ */
7
+ export interface UseDataSourceReturn {
8
+ /** Available choice options */
9
+ options: ChoiceOption[];
10
+ /** Loading state information */
11
+ loading: LoadingState;
12
+ /** Error state information */
13
+ error: ErrorState;
14
+ /** Refetch data from the source (bypasses cache) */
15
+ refetch: () => Promise<void>;
16
+ /** Refresh data (uses cache if available) */
17
+ refresh: () => Promise<void>;
18
+ /** Update the data source configuration */
19
+ updateConfig: (config: DataSourceConfig) => void;
20
+ /** Performance metrics for monitoring */
21
+ metrics: DataSourceMetrics;
22
+ /** Whether the cached data is stale */
23
+ isStale: boolean;
24
+ }
25
+ /**
26
+ * Custom React hook for managing data source lifecycle
27
+ *
28
+ * Features:
29
+ * - Manages loading, success, and error states
30
+ * - Handles provider switching and configuration changes
31
+ * - Implements caching coordination with providers
32
+ * - Provides refetch and refresh capabilities
33
+ * - Prevents race conditions with request cancellation
34
+ * - Includes performance monitoring
35
+ * - Ensures proper cleanup on unmount
36
+ *
37
+ * @param config - Data source configuration
38
+ * @param eventCallbacks - Optional event callbacks for monitoring
39
+ * @returns Data source state and control functions
40
+ *
41
+ * @example
42
+ * ```tsx
43
+ * const { options, loading, error, refetch } = useDataSource({
44
+ * type: 'api',
45
+ * url: '/api/options',
46
+ * responseMapper: { type: 'simple' }
47
+ * });
48
+ * ```
49
+ */
50
+ export declare function useDataSource(config: DataSourceConfig, eventCallbacks?: DataSourceEventCallbacks): UseDataSourceReturn;
51
+ /**
52
+ * Helper hook for managing data source with automatic error retry
53
+ *
54
+ * @param config - Data source configuration
55
+ * @param options - Hook options
56
+ * @returns Data source state with automatic retry
57
+ */
58
+ export declare function useDataSourceWithRetry(config: DataSourceConfig, options?: {
59
+ maxRetries?: number;
60
+ retryDelayMs?: number;
61
+ onRetry?: (attempt: number, error: Error) => void;
62
+ }): UseDataSourceReturn;
63
+ /**
64
+ * Helper hook for managing multiple data sources
65
+ *
66
+ * @param configs - Array of data source configurations
67
+ * @returns Array of data source states
68
+ */
69
+ export declare function useMultipleDataSources(configs: DataSourceConfig[]): UseDataSourceReturn[];