@okyrychenko-dev/react-action-guard 0.3.3 → 0.5.0
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 +1 -1
- package/README.md +255 -62
- package/dist/index.cjs +131 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +139 -3
- package/dist/index.d.ts +139 -3
- package/dist/index.js +124 -23
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
package/dist/index.d.cts
CHANGED
|
@@ -1,18 +1,33 @@
|
|
|
1
1
|
import * as zustand from 'zustand';
|
|
2
|
+
import { StoreApi } from 'zustand';
|
|
3
|
+
export { ShallowStoreBindings, createShallowStore } from '@okyrychenko-dev/react-zustand-toolkit';
|
|
4
|
+
import { ReactNode } from 'react';
|
|
2
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Options for useAsyncAction hook
|
|
8
|
+
*/
|
|
9
|
+
interface UseAsyncActionOptions {
|
|
10
|
+
/** Timeout in milliseconds after which the blocker will be automatically removed */
|
|
11
|
+
timeout?: number;
|
|
12
|
+
/** Callback invoked when the blocker is automatically removed due to timeout */
|
|
13
|
+
onTimeout?: (blockerId: string) => void;
|
|
14
|
+
}
|
|
3
15
|
/**
|
|
4
16
|
* Hook to wrap async functions with automatic blocking/unblocking
|
|
5
17
|
*
|
|
6
18
|
* Creates a wrapper function that automatically adds a blocker before executing
|
|
7
19
|
* the async function and removes it after completion (success or failure).
|
|
8
20
|
*
|
|
21
|
+
* Supports both global store and context store (via UIBlockingProvider).
|
|
22
|
+
*
|
|
9
23
|
* @template T - The return type of the async function
|
|
10
24
|
* @param actionId - Unique identifier for the action (used in blocker ID and reason)
|
|
11
25
|
* @param scope - Scope(s) to block during execution (default: "global")
|
|
26
|
+
* @param options - Optional configuration including timeout
|
|
12
27
|
* @returns Function that wraps async functions with blocking behavior
|
|
13
28
|
*
|
|
14
29
|
*/
|
|
15
|
-
declare const useAsyncAction: <T = unknown>(actionId: string, scope?: string | ReadonlyArray<string
|
|
30
|
+
declare const useAsyncAction: <T = unknown>(actionId: string, scope?: string | ReadonlyArray<string>, options?: UseAsyncActionOptions) => ((asyncFn: () => Promise<T>) => Promise<T>);
|
|
16
31
|
|
|
17
32
|
type AnalyticsEventData = Record<string, string | number | ReadonlyArray<string> | undefined>;
|
|
18
33
|
type AnalyticsProvider = "ga" | "mixpanel" | "amplitude";
|
|
@@ -71,6 +86,10 @@ interface BlockerConfig {
|
|
|
71
86
|
reason?: string;
|
|
72
87
|
priority?: number;
|
|
73
88
|
timestamp?: number;
|
|
89
|
+
/** Automatically remove the blocker after N milliseconds */
|
|
90
|
+
timeout?: number;
|
|
91
|
+
/** Callback invoked when the blocker is automatically removed due to timeout */
|
|
92
|
+
onTimeout?: (blockerId: string) => void;
|
|
74
93
|
}
|
|
75
94
|
/**
|
|
76
95
|
* Stored blocker with all required fields
|
|
@@ -80,6 +99,12 @@ interface StoredBlocker {
|
|
|
80
99
|
reason: string;
|
|
81
100
|
priority: number;
|
|
82
101
|
timestamp: number;
|
|
102
|
+
/** Timeout duration in milliseconds (if set) */
|
|
103
|
+
timeout?: number;
|
|
104
|
+
/** Internal timeout ID for cleanup */
|
|
105
|
+
timeoutId?: ReturnType<typeof setTimeout>;
|
|
106
|
+
/** Callback invoked when the blocker is automatically removed due to timeout */
|
|
107
|
+
onTimeout?: (blockerId: string) => void;
|
|
83
108
|
}
|
|
84
109
|
/**
|
|
85
110
|
* Blocker information including its ID
|
|
@@ -126,7 +151,10 @@ type UIBlockingStore = UIBlockingStoreState & UIBlockingStoreActions;
|
|
|
126
151
|
* - Automatic shallow comparison for selectors
|
|
127
152
|
*
|
|
128
153
|
*/
|
|
129
|
-
declare const useUIBlockingStore:
|
|
154
|
+
declare const useUIBlockingStore: {
|
|
155
|
+
(): UIBlockingStore;
|
|
156
|
+
<T>(selector: (state: UIBlockingStore) => T): T;
|
|
157
|
+
};
|
|
130
158
|
declare const uiBlockingStoreApi: zustand.StoreApi<UIBlockingStore>;
|
|
131
159
|
|
|
132
160
|
/**
|
|
@@ -135,6 +163,8 @@ declare const uiBlockingStoreApi: zustand.StoreApi<UIBlockingStore>;
|
|
|
135
163
|
* Automatically adds a blocker when the component mounts (or when activated)
|
|
136
164
|
* and removes it when the component unmounts (or when deactivated).
|
|
137
165
|
*
|
|
166
|
+
* Supports both global store and context store (via UIBlockingProvider).
|
|
167
|
+
*
|
|
138
168
|
* @param blockerId - Unique identifier for the blocker
|
|
139
169
|
* @param config - Blocker configuration (scope, reason, priority)
|
|
140
170
|
* @param isActive - Whether the blocker is currently active (default: true)
|
|
@@ -151,6 +181,8 @@ declare const useBlocker: (blockerId: string, config: BlockerConfig, isActive?:
|
|
|
151
181
|
* Uses a stable reference - only re-renders when the actual blocker list changes,
|
|
152
182
|
* not on every store update.
|
|
153
183
|
*
|
|
184
|
+
* Supports both global store and context store (via UIBlockingProvider).
|
|
185
|
+
*
|
|
154
186
|
* @param scope - Scope to get blocking information for (default: "global")
|
|
155
187
|
* @returns Array of blocker information objects, sorted by priority
|
|
156
188
|
*
|
|
@@ -181,6 +213,8 @@ interface ConditionalBlockerConfig<TState = unknown> extends Omit<BlockerConfig,
|
|
|
181
213
|
* Periodically checks a condition and blocks/unblocks based on the result.
|
|
182
214
|
* The condition is evaluated at the specified interval (default 1000ms).
|
|
183
215
|
*
|
|
216
|
+
* Supports both global store and context store (via UIBlockingProvider).
|
|
217
|
+
*
|
|
184
218
|
* @param blockerId - Unique identifier for this blocker
|
|
185
219
|
* @param config - Configuration including condition function and check interval
|
|
186
220
|
*
|
|
@@ -240,6 +274,8 @@ declare const useConfirmableBlocker: (blockerId: string, config: ConfirmableBloc
|
|
|
240
274
|
* Returns a boolean indicating whether the specified scope(s) are blocked.
|
|
241
275
|
* Automatically re-renders when the blocking state changes.
|
|
242
276
|
*
|
|
277
|
+
* Supports both global store and context store (via UIBlockingProvider).
|
|
278
|
+
*
|
|
243
279
|
* @param scope - Scope or array of scopes to check (default: "global")
|
|
244
280
|
* @returns True if any of the specified scopes are blocked
|
|
245
281
|
*
|
|
@@ -282,10 +318,110 @@ interface ScheduledBlockerConfig extends BlockerConfig {
|
|
|
282
318
|
* Supports start/end times as Date objects, ISO strings, or timestamps.
|
|
283
319
|
* If both duration and end are provided, duration takes precedence.
|
|
284
320
|
*
|
|
321
|
+
* Supports both global store and context store (via UIBlockingProvider).
|
|
322
|
+
*
|
|
285
323
|
* @param blockerId - Unique identifier for this blocker
|
|
286
324
|
* @param config - Configuration including schedule and callbacks
|
|
287
325
|
*
|
|
288
326
|
*/
|
|
289
327
|
declare const useScheduledBlocker: (blockerId: string, config: ScheduledBlockerConfig) => void;
|
|
290
328
|
|
|
291
|
-
|
|
329
|
+
/**
|
|
330
|
+
* Default scope type
|
|
331
|
+
*/
|
|
332
|
+
type DefaultScopes = "global";
|
|
333
|
+
/**
|
|
334
|
+
* Utility type for scope values - can be a single scope or array of scopes
|
|
335
|
+
*/
|
|
336
|
+
type ScopeValue<TScope extends string = string> = TScope | ReadonlyArray<TScope>;
|
|
337
|
+
/**
|
|
338
|
+
* Type-safe blocker configuration with generic scope type
|
|
339
|
+
*/
|
|
340
|
+
interface BlockerConfigTyped<TScope extends string> {
|
|
341
|
+
/** Scope(s) to block */
|
|
342
|
+
scope?: ScopeValue<TScope>;
|
|
343
|
+
/** Human-readable reason for blocking */
|
|
344
|
+
reason?: string;
|
|
345
|
+
/** Priority level (higher priority blockers take precedence) */
|
|
346
|
+
priority?: number;
|
|
347
|
+
/** Timestamp when the blocker was created */
|
|
348
|
+
timestamp?: number;
|
|
349
|
+
/** Timeout in milliseconds after which the blocker will be automatically removed */
|
|
350
|
+
timeout?: number;
|
|
351
|
+
/** Callback invoked when the blocker is automatically removed due to timeout */
|
|
352
|
+
onTimeout?: (blockerId: string) => void;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Return type for createTypedHooks factory
|
|
357
|
+
*/
|
|
358
|
+
interface TypedHooks<TScope extends string> {
|
|
359
|
+
/**
|
|
360
|
+
* Type-safe version of useBlocker hook
|
|
361
|
+
*/
|
|
362
|
+
useBlocker: (blockerId: string, config: BlockerConfigTyped<TScope>, isActive?: boolean) => void;
|
|
363
|
+
/**
|
|
364
|
+
* Type-safe version of useIsBlocked hook
|
|
365
|
+
*/
|
|
366
|
+
useIsBlocked: (scope?: ScopeValue<TScope>) => boolean;
|
|
367
|
+
/**
|
|
368
|
+
* Type-safe version of useAsyncAction hook
|
|
369
|
+
*/
|
|
370
|
+
useAsyncAction: <T = unknown>(actionId: string, scope?: ScopeValue<TScope>, options?: UseAsyncActionOptions) => (asyncFn: () => Promise<T>) => Promise<T>;
|
|
371
|
+
/**
|
|
372
|
+
* Type-safe version of useBlockingInfo hook
|
|
373
|
+
*/
|
|
374
|
+
useBlockingInfo: (scope: TScope) => ReturnType<typeof useBlockingInfo>;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Creates type-safe versions of all blocking hooks with your custom scope types
|
|
378
|
+
*
|
|
379
|
+
* @template TScope - Union type of allowed scope strings
|
|
380
|
+
* @returns Object with type-safe hook functions
|
|
381
|
+
*
|
|
382
|
+
* @example
|
|
383
|
+
* ```typescript
|
|
384
|
+
* // Define your app's scopes
|
|
385
|
+
* type AppScopes = "global" | "form" | "navigation" | "checkout";
|
|
386
|
+
*
|
|
387
|
+
* // Create typed hooks
|
|
388
|
+
* const { useBlocker, useIsBlocked, useAsyncAction } = createTypedHooks<AppScopes>();
|
|
389
|
+
*
|
|
390
|
+
* // Now TypeScript will catch typos
|
|
391
|
+
* useBlocker("id", { scope: "form" }); // ✓ OK
|
|
392
|
+
* useBlocker("id", { scope: "typo" }); // ✗ Type error!
|
|
393
|
+
* ```
|
|
394
|
+
*/
|
|
395
|
+
declare function createTypedHooks<TScope extends string>(): TypedHooks<TScope>;
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Props for UIBlockingProvider component
|
|
399
|
+
*/
|
|
400
|
+
interface UIBlockingProviderProps {
|
|
401
|
+
children: ReactNode;
|
|
402
|
+
/** Enable Redux DevTools integration (default: true in development) */
|
|
403
|
+
enableDevtools?: boolean;
|
|
404
|
+
/** Name for Redux DevTools (default: "UIBlocking") */
|
|
405
|
+
devtoolsName?: string;
|
|
406
|
+
/** Initial middlewares to register */
|
|
407
|
+
middlewares?: ReadonlyArray<Middleware>;
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Base provider created using toolkit's createStoreProvider
|
|
411
|
+
* This creates isolated store instances for SSR, testing, and micro-frontends
|
|
412
|
+
*/
|
|
413
|
+
declare const useUIBlockingContext: () => StoreApi<UIBlockingStore>;
|
|
414
|
+
declare const useUIBlockingStoreFromContext: {
|
|
415
|
+
(): UIBlockingStore;
|
|
416
|
+
<T>(selector: (state: UIBlockingStore) => T): T;
|
|
417
|
+
};
|
|
418
|
+
declare const useIsInsideUIBlockingProvider: () => boolean;
|
|
419
|
+
/**
|
|
420
|
+
* Provider component for isolated UI blocking state
|
|
421
|
+
*
|
|
422
|
+
* Uses toolkit's createStoreProvider with built-in DevTools support
|
|
423
|
+
* and onStoreCreate callback for middleware registration.
|
|
424
|
+
*/
|
|
425
|
+
declare function UIBlockingProvider({ children, enableDevtools, devtoolsName, middlewares, }: UIBlockingProviderProps): ReactNode;
|
|
426
|
+
|
|
427
|
+
export { type AmplitudeConfig, type AnalyticsConfig, type AnalyticsEventData, type AnalyticsProvider, type BlockerConfig, type BlockerConfigTyped, type BlockerInfo, type BlockingAction, type BlockingSchedule, type ConditionalBlockerConfig, type ConfirmDialogConfig, type ConfirmableBlockerConfig, type CustomAnalyticsConfig, type DefaultScopes, type GoogleAnalyticsConfig, type Middleware, type MiddlewareContext, type MixpanelConfig, type PerformanceConfig, type ScheduledBlockerConfig, type ScopeValue, type StoredBlocker, type TypedHooks, UIBlockingProvider, type UIBlockingProviderProps, type UIBlockingStore, type UIBlockingStoreActions, type UIBlockingStoreState, type UseAsyncActionOptions, type UseConfirmableBlockerReturn, configureMiddleware, createAnalyticsMiddleware, createPerformanceMiddleware, createTypedHooks, loggerMiddleware, uiBlockingStoreApi, useAsyncAction, useBlocker, useBlockingInfo, useConditionalBlocker, useConfirmableBlocker, useIsBlocked, useIsInsideUIBlockingProvider, useScheduledBlocker, useUIBlockingContext, useUIBlockingStore, useUIBlockingStoreFromContext };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,33 @@
|
|
|
1
1
|
import * as zustand from 'zustand';
|
|
2
|
+
import { StoreApi } from 'zustand';
|
|
3
|
+
export { ShallowStoreBindings, createShallowStore } from '@okyrychenko-dev/react-zustand-toolkit';
|
|
4
|
+
import { ReactNode } from 'react';
|
|
2
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Options for useAsyncAction hook
|
|
8
|
+
*/
|
|
9
|
+
interface UseAsyncActionOptions {
|
|
10
|
+
/** Timeout in milliseconds after which the blocker will be automatically removed */
|
|
11
|
+
timeout?: number;
|
|
12
|
+
/** Callback invoked when the blocker is automatically removed due to timeout */
|
|
13
|
+
onTimeout?: (blockerId: string) => void;
|
|
14
|
+
}
|
|
3
15
|
/**
|
|
4
16
|
* Hook to wrap async functions with automatic blocking/unblocking
|
|
5
17
|
*
|
|
6
18
|
* Creates a wrapper function that automatically adds a blocker before executing
|
|
7
19
|
* the async function and removes it after completion (success or failure).
|
|
8
20
|
*
|
|
21
|
+
* Supports both global store and context store (via UIBlockingProvider).
|
|
22
|
+
*
|
|
9
23
|
* @template T - The return type of the async function
|
|
10
24
|
* @param actionId - Unique identifier for the action (used in blocker ID and reason)
|
|
11
25
|
* @param scope - Scope(s) to block during execution (default: "global")
|
|
26
|
+
* @param options - Optional configuration including timeout
|
|
12
27
|
* @returns Function that wraps async functions with blocking behavior
|
|
13
28
|
*
|
|
14
29
|
*/
|
|
15
|
-
declare const useAsyncAction: <T = unknown>(actionId: string, scope?: string | ReadonlyArray<string
|
|
30
|
+
declare const useAsyncAction: <T = unknown>(actionId: string, scope?: string | ReadonlyArray<string>, options?: UseAsyncActionOptions) => ((asyncFn: () => Promise<T>) => Promise<T>);
|
|
16
31
|
|
|
17
32
|
type AnalyticsEventData = Record<string, string | number | ReadonlyArray<string> | undefined>;
|
|
18
33
|
type AnalyticsProvider = "ga" | "mixpanel" | "amplitude";
|
|
@@ -71,6 +86,10 @@ interface BlockerConfig {
|
|
|
71
86
|
reason?: string;
|
|
72
87
|
priority?: number;
|
|
73
88
|
timestamp?: number;
|
|
89
|
+
/** Automatically remove the blocker after N milliseconds */
|
|
90
|
+
timeout?: number;
|
|
91
|
+
/** Callback invoked when the blocker is automatically removed due to timeout */
|
|
92
|
+
onTimeout?: (blockerId: string) => void;
|
|
74
93
|
}
|
|
75
94
|
/**
|
|
76
95
|
* Stored blocker with all required fields
|
|
@@ -80,6 +99,12 @@ interface StoredBlocker {
|
|
|
80
99
|
reason: string;
|
|
81
100
|
priority: number;
|
|
82
101
|
timestamp: number;
|
|
102
|
+
/** Timeout duration in milliseconds (if set) */
|
|
103
|
+
timeout?: number;
|
|
104
|
+
/** Internal timeout ID for cleanup */
|
|
105
|
+
timeoutId?: ReturnType<typeof setTimeout>;
|
|
106
|
+
/** Callback invoked when the blocker is automatically removed due to timeout */
|
|
107
|
+
onTimeout?: (blockerId: string) => void;
|
|
83
108
|
}
|
|
84
109
|
/**
|
|
85
110
|
* Blocker information including its ID
|
|
@@ -126,7 +151,10 @@ type UIBlockingStore = UIBlockingStoreState & UIBlockingStoreActions;
|
|
|
126
151
|
* - Automatic shallow comparison for selectors
|
|
127
152
|
*
|
|
128
153
|
*/
|
|
129
|
-
declare const useUIBlockingStore:
|
|
154
|
+
declare const useUIBlockingStore: {
|
|
155
|
+
(): UIBlockingStore;
|
|
156
|
+
<T>(selector: (state: UIBlockingStore) => T): T;
|
|
157
|
+
};
|
|
130
158
|
declare const uiBlockingStoreApi: zustand.StoreApi<UIBlockingStore>;
|
|
131
159
|
|
|
132
160
|
/**
|
|
@@ -135,6 +163,8 @@ declare const uiBlockingStoreApi: zustand.StoreApi<UIBlockingStore>;
|
|
|
135
163
|
* Automatically adds a blocker when the component mounts (or when activated)
|
|
136
164
|
* and removes it when the component unmounts (or when deactivated).
|
|
137
165
|
*
|
|
166
|
+
* Supports both global store and context store (via UIBlockingProvider).
|
|
167
|
+
*
|
|
138
168
|
* @param blockerId - Unique identifier for the blocker
|
|
139
169
|
* @param config - Blocker configuration (scope, reason, priority)
|
|
140
170
|
* @param isActive - Whether the blocker is currently active (default: true)
|
|
@@ -151,6 +181,8 @@ declare const useBlocker: (blockerId: string, config: BlockerConfig, isActive?:
|
|
|
151
181
|
* Uses a stable reference - only re-renders when the actual blocker list changes,
|
|
152
182
|
* not on every store update.
|
|
153
183
|
*
|
|
184
|
+
* Supports both global store and context store (via UIBlockingProvider).
|
|
185
|
+
*
|
|
154
186
|
* @param scope - Scope to get blocking information for (default: "global")
|
|
155
187
|
* @returns Array of blocker information objects, sorted by priority
|
|
156
188
|
*
|
|
@@ -181,6 +213,8 @@ interface ConditionalBlockerConfig<TState = unknown> extends Omit<BlockerConfig,
|
|
|
181
213
|
* Periodically checks a condition and blocks/unblocks based on the result.
|
|
182
214
|
* The condition is evaluated at the specified interval (default 1000ms).
|
|
183
215
|
*
|
|
216
|
+
* Supports both global store and context store (via UIBlockingProvider).
|
|
217
|
+
*
|
|
184
218
|
* @param blockerId - Unique identifier for this blocker
|
|
185
219
|
* @param config - Configuration including condition function and check interval
|
|
186
220
|
*
|
|
@@ -240,6 +274,8 @@ declare const useConfirmableBlocker: (blockerId: string, config: ConfirmableBloc
|
|
|
240
274
|
* Returns a boolean indicating whether the specified scope(s) are blocked.
|
|
241
275
|
* Automatically re-renders when the blocking state changes.
|
|
242
276
|
*
|
|
277
|
+
* Supports both global store and context store (via UIBlockingProvider).
|
|
278
|
+
*
|
|
243
279
|
* @param scope - Scope or array of scopes to check (default: "global")
|
|
244
280
|
* @returns True if any of the specified scopes are blocked
|
|
245
281
|
*
|
|
@@ -282,10 +318,110 @@ interface ScheduledBlockerConfig extends BlockerConfig {
|
|
|
282
318
|
* Supports start/end times as Date objects, ISO strings, or timestamps.
|
|
283
319
|
* If both duration and end are provided, duration takes precedence.
|
|
284
320
|
*
|
|
321
|
+
* Supports both global store and context store (via UIBlockingProvider).
|
|
322
|
+
*
|
|
285
323
|
* @param blockerId - Unique identifier for this blocker
|
|
286
324
|
* @param config - Configuration including schedule and callbacks
|
|
287
325
|
*
|
|
288
326
|
*/
|
|
289
327
|
declare const useScheduledBlocker: (blockerId: string, config: ScheduledBlockerConfig) => void;
|
|
290
328
|
|
|
291
|
-
|
|
329
|
+
/**
|
|
330
|
+
* Default scope type
|
|
331
|
+
*/
|
|
332
|
+
type DefaultScopes = "global";
|
|
333
|
+
/**
|
|
334
|
+
* Utility type for scope values - can be a single scope or array of scopes
|
|
335
|
+
*/
|
|
336
|
+
type ScopeValue<TScope extends string = string> = TScope | ReadonlyArray<TScope>;
|
|
337
|
+
/**
|
|
338
|
+
* Type-safe blocker configuration with generic scope type
|
|
339
|
+
*/
|
|
340
|
+
interface BlockerConfigTyped<TScope extends string> {
|
|
341
|
+
/** Scope(s) to block */
|
|
342
|
+
scope?: ScopeValue<TScope>;
|
|
343
|
+
/** Human-readable reason for blocking */
|
|
344
|
+
reason?: string;
|
|
345
|
+
/** Priority level (higher priority blockers take precedence) */
|
|
346
|
+
priority?: number;
|
|
347
|
+
/** Timestamp when the blocker was created */
|
|
348
|
+
timestamp?: number;
|
|
349
|
+
/** Timeout in milliseconds after which the blocker will be automatically removed */
|
|
350
|
+
timeout?: number;
|
|
351
|
+
/** Callback invoked when the blocker is automatically removed due to timeout */
|
|
352
|
+
onTimeout?: (blockerId: string) => void;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Return type for createTypedHooks factory
|
|
357
|
+
*/
|
|
358
|
+
interface TypedHooks<TScope extends string> {
|
|
359
|
+
/**
|
|
360
|
+
* Type-safe version of useBlocker hook
|
|
361
|
+
*/
|
|
362
|
+
useBlocker: (blockerId: string, config: BlockerConfigTyped<TScope>, isActive?: boolean) => void;
|
|
363
|
+
/**
|
|
364
|
+
* Type-safe version of useIsBlocked hook
|
|
365
|
+
*/
|
|
366
|
+
useIsBlocked: (scope?: ScopeValue<TScope>) => boolean;
|
|
367
|
+
/**
|
|
368
|
+
* Type-safe version of useAsyncAction hook
|
|
369
|
+
*/
|
|
370
|
+
useAsyncAction: <T = unknown>(actionId: string, scope?: ScopeValue<TScope>, options?: UseAsyncActionOptions) => (asyncFn: () => Promise<T>) => Promise<T>;
|
|
371
|
+
/**
|
|
372
|
+
* Type-safe version of useBlockingInfo hook
|
|
373
|
+
*/
|
|
374
|
+
useBlockingInfo: (scope: TScope) => ReturnType<typeof useBlockingInfo>;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Creates type-safe versions of all blocking hooks with your custom scope types
|
|
378
|
+
*
|
|
379
|
+
* @template TScope - Union type of allowed scope strings
|
|
380
|
+
* @returns Object with type-safe hook functions
|
|
381
|
+
*
|
|
382
|
+
* @example
|
|
383
|
+
* ```typescript
|
|
384
|
+
* // Define your app's scopes
|
|
385
|
+
* type AppScopes = "global" | "form" | "navigation" | "checkout";
|
|
386
|
+
*
|
|
387
|
+
* // Create typed hooks
|
|
388
|
+
* const { useBlocker, useIsBlocked, useAsyncAction } = createTypedHooks<AppScopes>();
|
|
389
|
+
*
|
|
390
|
+
* // Now TypeScript will catch typos
|
|
391
|
+
* useBlocker("id", { scope: "form" }); // ✓ OK
|
|
392
|
+
* useBlocker("id", { scope: "typo" }); // ✗ Type error!
|
|
393
|
+
* ```
|
|
394
|
+
*/
|
|
395
|
+
declare function createTypedHooks<TScope extends string>(): TypedHooks<TScope>;
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Props for UIBlockingProvider component
|
|
399
|
+
*/
|
|
400
|
+
interface UIBlockingProviderProps {
|
|
401
|
+
children: ReactNode;
|
|
402
|
+
/** Enable Redux DevTools integration (default: true in development) */
|
|
403
|
+
enableDevtools?: boolean;
|
|
404
|
+
/** Name for Redux DevTools (default: "UIBlocking") */
|
|
405
|
+
devtoolsName?: string;
|
|
406
|
+
/** Initial middlewares to register */
|
|
407
|
+
middlewares?: ReadonlyArray<Middleware>;
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Base provider created using toolkit's createStoreProvider
|
|
411
|
+
* This creates isolated store instances for SSR, testing, and micro-frontends
|
|
412
|
+
*/
|
|
413
|
+
declare const useUIBlockingContext: () => StoreApi<UIBlockingStore>;
|
|
414
|
+
declare const useUIBlockingStoreFromContext: {
|
|
415
|
+
(): UIBlockingStore;
|
|
416
|
+
<T>(selector: (state: UIBlockingStore) => T): T;
|
|
417
|
+
};
|
|
418
|
+
declare const useIsInsideUIBlockingProvider: () => boolean;
|
|
419
|
+
/**
|
|
420
|
+
* Provider component for isolated UI blocking state
|
|
421
|
+
*
|
|
422
|
+
* Uses toolkit's createStoreProvider with built-in DevTools support
|
|
423
|
+
* and onStoreCreate callback for middleware registration.
|
|
424
|
+
*/
|
|
425
|
+
declare function UIBlockingProvider({ children, enableDevtools, devtoolsName, middlewares, }: UIBlockingProviderProps): ReactNode;
|
|
426
|
+
|
|
427
|
+
export { type AmplitudeConfig, type AnalyticsConfig, type AnalyticsEventData, type AnalyticsProvider, type BlockerConfig, type BlockerConfigTyped, type BlockerInfo, type BlockingAction, type BlockingSchedule, type ConditionalBlockerConfig, type ConfirmDialogConfig, type ConfirmableBlockerConfig, type CustomAnalyticsConfig, type DefaultScopes, type GoogleAnalyticsConfig, type Middleware, type MiddlewareContext, type MixpanelConfig, type PerformanceConfig, type ScheduledBlockerConfig, type ScopeValue, type StoredBlocker, type TypedHooks, UIBlockingProvider, type UIBlockingProviderProps, type UIBlockingStore, type UIBlockingStoreActions, type UIBlockingStoreState, type UseAsyncActionOptions, type UseConfirmableBlockerReturn, configureMiddleware, createAnalyticsMiddleware, createPerformanceMiddleware, createTypedHooks, loggerMiddleware, uiBlockingStoreApi, useAsyncAction, useBlocker, useBlockingInfo, useConditionalBlocker, useConfirmableBlocker, useIsBlocked, useIsInsideUIBlockingProvider, useScheduledBlocker, useUIBlockingContext, useUIBlockingStore, useUIBlockingStoreFromContext };
|